db = &$db; $this->tpl = &$tpl; $this->error = &$error; } function viewAllAdvices($param = array()){ $search = array(); $sql = "select * from send_tpl where 1=1 "; if(count($search))$sql .= "AND " . implode(" AND ",$search)." "; $sql .= "order by id desc"; $pagerOptions = Array( 'mode' => 'Sliding', 'delta' => 6, 'perPage' => 10, 'spacesBeforeSeparator' => 1, 'spacesAfterSeparator' => 1 ); $this->tpl->assign('advicesAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array())); } function viewOneAdvices($id,&$row,$lang = "rus"){ $sql = "select * from send_tpl where id=? limit 1"; $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); $this->tpl->assign('advices',$row); } function admin_infoEditAdvicesOne($id){ $sql = "select * from send_tpl where id=? limit 1"; $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); $this->tpl->assign('advices',$row); } function viewLetterOne(){ $sql = "select * from send_letter where id=? limit 1"; $row = $this->db->getRow($sql,array(1),DB_FETCHMODE_ASSOC); $row['interest'] = explode(':',$row['interest']); $row['group'] = explode(':',$row['groups']); $this->tpl->assign('advices',$row); } function trim(&$data){ foreach($data as $key=>$value){ if(!is_array($data[$key]))$data[$key] = trim($value); } } function valid($data,$upload = null){ if(isset($data['rss_rubric'])){ if( !preg_match("/^([0-9]+)$/",$data['rss_rubric']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ðóáðèêà."; } if(isset($data['title'])){ if( !preg_match("/.{1,150}/i",$data['title']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ."; } if(isset($data['text'])){ if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Îïèñàíèå."; } if(isset($upload['pic']['name']) && $upload['pic']['name']!=null){ $type = substr(strrchr($upload['pic']['name'],"."),1); if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif."; } return ( count($this->error) ) ? true : false; } function SaveAdvices($data,$upload = null){ $table_name = "send_tpl"; if($data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$id = $data['update_id'];$where = "id=$id";}else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$id = $this->db->nextId('mySequenceAdvices');$where = null;} $fields_values = array("id"=>$id,"title"=>$data['title'],"text"=>$data['text']); $this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where); return $id; } function updateLetter($data){ $table_name = "send_letter"; $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; $where = "id=1"; $fields_values = array("title"=>$data['title'],"text"=>$data['text']); if(isset($data['cupon']))$fields_values['cupon'] = 1; else $fields_values['cupon'] = 0; if(isset($data['interest']))$fields_values['interest'] = implode(':',$data['interest']); else $fields_values['interest'] = ''; if(isset($data['group']))$fields_values['groups'] = implode(':',$data['group']); else $fields_values['groups'] = ''; $this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where); return $id; } function viewInterest(){ $sql = "select * from zlo_interest order by sort"; $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); $this->tpl->assign('interest',$res); } function viewGroup(){ $sql = "select * from zlo_users_group order by id"; $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); $this->tpl->assign('group',$res); } function deletePic($id){ $sql = "select pic,pic_big from send_tpl where id=?"; $advices = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); @unlink("./uploaded/pic/advices/{$advices['pic']}"); @unlink("./uploaded/pic/advices/big/{$advices['pic_big']}"); } function admin_deleteAdvicesOne($id){ // $this->deletePic($id); $sql = "delete from send_tpl where id=?"; $this->db->query($sql,array($id)); } function viewUserSendCount(){ $count = $this->db->getOne("SELECT count(*) FROM zlo_users WHERE `group`='2' AND `send`='1'",array()); $this->tpl->assign("user_send_count",$count); } function endSendUsers(){ $this->db->autoExecute("zlo_users", array('send'=>1), DB_AUTOQUERY_UPDATE,"`group`='2'"); } function startSendUsers(){ $r = $this->db->autoExecute("zlo_users", array('send'=>0), DB_AUTOQUERY_UPDATE,"`group`='2'"); if (PEAR::isError($r)) die($r->getMessage()); } function displayAdvicesSave(){ $this->tpl->assign("tpl","send_tpl_save.tpl"); } function displayAdvices(){ $this->tpl->assign("tpl","send_tpl.tpl"); } function displayLetter(){ $this->tpl->assign("tpl","send_letter.tpl"); } } ?>