db = &$db; $this->tpl = &$tpl; $this->error = &$error; } function viewCity () { $sql = "select * from vacancy where parent_id=? order by id asc"; $res = $this->db->getAll ($sql, array ( 0 ), DB_FETCHMODE_ASSOC); foreach ($res as $key => $row) { $res[$key]['child'] = $this->db->getAll ($sql, array ( $row['id'] ), DB_FETCHMODE_ASSOC); } $this->tpl->assign ('city', $res); } function viewAllNews ($param = array()) { $search = array (); // if(isset($_GET['parentID']) && $_GET['parentID']>0)$search[] = sprintf("parent_id='%d'",$_GET['parentID']); $sql = "select * from fon where 1=1 "; if (count ($search)) $sql .= "AND " . implode (" AND ", $search) . " "; $sql .= "order by id asc"; $pagerOptions = Array ( 'mode' => 'Sliding', 'delta' => 6, 'perPage' => 10, 'spacesBeforeSeparator' => 1, 'spacesAfterSeparator' => 1 ); $this->tpl->assign ('newsAllData', Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ())); } function getFonRand () { $count = $this->db->getOne ("select count(*) from fon", array ()); $limit = rand (0, $count - 1); return $this->db->getRow ("select * from fon limit $limit ,1", array (), DB_FETCHMODE_ASSOC); } function viewOneNews ($id, &$row) { $sql = "select * from fon where id=? limit 1"; $row = $this->db->getRow ($sql, array ( $id ), DB_FETCHMODE_ASSOC); $this->tpl->assign ('news', $row); } function admin_infoEditNewsOne ($id) { $sql = "select * from fon where id=? limit 1"; $row = $this->db->getRow ($sql, array ( $id ), DB_FETCHMODE_ASSOC); $this->tpl->assign ('news', $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['title'])) { if (! preg_match ("/.{1,150}/i", $data['title'])) $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ."; } 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 SaveNews ($data, $upload = null, $firm_id = 0) { $table_name = "fon"; if ($data['update_id'] > 0) { $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; $id = $data['update_id']; $where = "id=$id"; } else { $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; $where = null; } $fields_values = array ( "name" => $data['name'], "url" => $data['url'] ); if (isset ($data['delete_pic']) && $data['delete_pic'] == 1) { $this->deletePic ($id); $fields_values['pic'] = null; } if ($upload['pic']['tmp_name']) { $this->deletePic ($id); $uploadfile = "./uploaded/pic/fon/"; $type = substr (strrchr ($upload['pic']['name'], "."), 1); $uploadname = mktime () . "." . $type; if (! move_uploaded_file ($_FILES['pic']['tmp_name'], $uploadfile . $uploadname)) { print "Îøèáêà ïðè çàêà÷êå ôàéëà!"; } $fields_values['pic'] = $uploadname; } $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, $where); return $id; } function deletePic ($id) { $sql = "select pic from fon where id=?"; $news = $this->db->getRow ($sql, array ( $id ), DB_FETCHMODE_ASSOC); @unlink ("./uploaded/pic/fon/{$news['pic']}"); } function admin_deleteNewsOne ($id) { $this->deletePic ($id); $sql = "delete from fon where id=?"; $this->db->query ($sql, array ( $id )); } function displayNewsSave () { $this->tpl->assign ("tpl", "fon_save.tpl"); } function displayNews () { $this->tpl->assign ("tpl", "fon.tpl"); } function displayNewsOne () { $this->tpl->assign ("tpl", "fon_one.tpl"); } } ?>