From f0d658fa36e735fb89ae76fdc946192db5b700d3 Mon Sep 17 00:00:00 2001 From: andryeyev Date: Mon, 14 Dec 2015 18:08:07 +0200 Subject: [PATCH] + upd fon --- libs/fon.class.php | 291 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 160 insertions(+), 131 deletions(-) diff --git a/libs/fon.class.php b/libs/fon.class.php index 90516e0..861c425 100644 --- a/libs/fon.class.php +++ b/libs/fon.class.php @@ -1,134 +1,163 @@ 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"); - } - +class Fon +{ + var $db = null; + var $tpl = null; + var $error = null; + // var $id = false; + function Fon (&$db, &$tpl, &$error) + { + $this->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"); + } } ?> -- libgit2 0.21.4