Commit f0d658fa36e735fb89ae76fdc946192db5b700d3
1 parent
a3deb67f
+ upd fon
Showing
1 changed file
with
160 additions
and
131 deletions
Show diff stats
libs/fon.class.php
1 | 1 | <?php |
2 | -class Fon{ | |
3 | - var $db = null; | |
4 | - var $tpl = null; | |
5 | - var $error = null; | |
6 | -//var $id = false; | |
7 | - | |
8 | - function Fon(&$db,&$tpl,&$error){ | |
9 | - $this->db = &$db; | |
10 | - $this->tpl = &$tpl; | |
11 | - $this->error = &$error; | |
12 | - } | |
13 | - | |
14 | - function viewCity(){ | |
15 | - $sql = "select * from vacancy where parent_id=? order by id asc"; | |
16 | - $res = $this->db->getAll($sql,array(0),DB_FETCHMODE_ASSOC); | |
17 | - foreach($res as $key=>$row){ | |
18 | - $res[$key]['child'] = $this->db->getAll($sql,array($row['id']),DB_FETCHMODE_ASSOC); | |
19 | - } | |
20 | - $this->tpl->assign('city',$res); | |
21 | - } | |
22 | - | |
23 | - function viewAllNews($param = array()){ | |
24 | - $search = array(); | |
25 | - //if(isset($_GET['parentID']) && $_GET['parentID']>0)$search[] = sprintf("parent_id='%d'",$_GET['parentID']); | |
26 | - | |
27 | - $sql = "select * from fon where 1=1 "; | |
28 | - if(count($search))$sql .= "AND " . implode(" AND ",$search)." "; | |
29 | - $sql .= "order by id asc"; | |
30 | - $pagerOptions = Array( | |
31 | - 'mode' => 'Sliding', | |
32 | - 'delta' => 6, | |
33 | - 'perPage' => 10, | |
34 | - 'spacesBeforeSeparator' => 1, | |
35 | - 'spacesAfterSeparator' => 1 | |
36 | - ); | |
37 | - $this->tpl->assign('newsAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array())); | |
38 | - } | |
39 | - | |
40 | - function getFonRand(){ | |
41 | - $count = $this->db->getOne("select count(*) from fon",array()); | |
42 | - $limit = rand(0,$count-1); | |
43 | - return $this->db->getRow("select * from fon limit $limit ,1",array(),DB_FETCHMODE_ASSOC); | |
44 | - } | |
45 | - | |
46 | - | |
47 | - function viewOneNews($id,&$row){ | |
48 | - $sql = "select * from fon where id=? limit 1"; | |
49 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | |
50 | - $this->tpl->assign('news',$row); | |
51 | - } | |
52 | - | |
53 | - | |
54 | - function admin_infoEditNewsOne($id){ | |
55 | - $sql = "select * from fon where id=? limit 1"; | |
56 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | |
57 | - $this->tpl->assign('news',$row); | |
58 | - } | |
59 | - | |
60 | - | |
61 | - function trim(&$data){ | |
62 | - foreach($data as $key=>$value){ | |
63 | - if(!is_array($data[$key]))$data[$key] = trim($value); | |
64 | - } | |
65 | - } | |
66 | - | |
67 | - function valid($data,$upload = null){ | |
68 | - | |
69 | - if(isset($data['title'])){ | |
70 | - if( !preg_match("/.{1,150}/i",$data['title']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ."; | |
71 | - } | |
72 | - | |
73 | - | |
74 | - if(isset($upload['pic']['name']) && $upload['pic']['name']!=null){ | |
75 | - $type = substr(strrchr($upload['pic']['name'],"."),1); | |
76 | - if( !preg_match("/^(jpeg|jpg|gif|png)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif."; | |
77 | - } | |
78 | - | |
79 | - return ( count($this->error) ) ? true : false; | |
80 | - } | |
81 | - | |
82 | - | |
83 | - function SaveNews($data,$upload = null,$firm_id = 0){ | |
84 | - $table_name = "fon"; | |
85 | - 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;} | |
86 | - | |
87 | - $fields_values = array("name"=>$data['name'],"url"=>$data['url']); | |
88 | - | |
89 | - if(isset($data['delete_pic']) && $data['delete_pic']==1){ | |
90 | - $this->deletePic($id); | |
91 | - $fields_values['pic'] = null; | |
92 | - } | |
93 | - if($upload['pic']['tmp_name']){ | |
94 | - $this->deletePic($id); | |
95 | - $uploadfile = "./uploaded/pic/fon/"; | |
96 | - $type = substr(strrchr($upload['pic']['name'], "."), 1); | |
97 | - $uploadname = mktime() . "." . $type; | |
98 | - if (!move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile . $uploadname)) { | |
99 | - print"Îøèáêà ïðè çàêà÷êå ôàéëà!"; | |
100 | - } | |
101 | - $fields_values['pic'] = $uploadname; | |
102 | - } | |
103 | - | |
104 | - $this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where); | |
105 | - return $id; | |
106 | - } | |
107 | - | |
108 | - function deletePic($id){ | |
109 | - $sql = "select pic from fon where id=?"; | |
110 | - $news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | |
111 | - @unlink("./uploaded/pic/fon/{$news['pic']}"); | |
112 | - } | |
113 | - | |
114 | - function admin_deleteNewsOne($id){ | |
115 | - $this->deletePic($id); | |
116 | - $sql = "delete from fon where id=?"; | |
117 | - $this->db->query($sql,array($id)); | |
118 | - } | |
119 | - | |
120 | - | |
121 | - function displayNewsSave(){ | |
122 | - $this->tpl->assign("tpl","fon_save.tpl"); | |
123 | - } | |
124 | - | |
125 | - function displayNews(){ | |
126 | - $this->tpl->assign("tpl","fon.tpl"); | |
127 | - } | |
128 | - | |
129 | - function displayNewsOne(){ | |
130 | - $this->tpl->assign("tpl","fon_one.tpl"); | |
131 | - } | |
132 | - | |
2 | +class Fon | |
3 | +{ | |
4 | + var $db = null; | |
5 | + var $tpl = null; | |
6 | + var $error = null; | |
7 | + // var $id = false; | |
8 | + function Fon (&$db, &$tpl, &$error) | |
9 | + { | |
10 | + $this->db = &$db; | |
11 | + $this->tpl = &$tpl; | |
12 | + $this->error = &$error; | |
13 | + } | |
14 | + function viewCity () | |
15 | + { | |
16 | + $sql = "select * from vacancy where parent_id=? order by id asc"; | |
17 | + $res = $this->db->getAll ($sql, array ( | |
18 | + 0 | |
19 | + ), DB_FETCHMODE_ASSOC); | |
20 | + foreach ($res as $key => $row) | |
21 | + { | |
22 | + $res[$key]['child'] = $this->db->getAll ($sql, array ( | |
23 | + $row['id'] | |
24 | + ), DB_FETCHMODE_ASSOC); | |
25 | + } | |
26 | + $this->tpl->assign ('city', $res); | |
27 | + } | |
28 | + function viewAllNews ($param = array()) | |
29 | + { | |
30 | + $search = array (); | |
31 | + // if(isset($_GET['parentID']) && $_GET['parentID']>0)$search[] = sprintf("parent_id='%d'",$_GET['parentID']); | |
32 | + | |
33 | + $sql = "select * from fon where 1=1 "; | |
34 | + if (count ($search)) | |
35 | + $sql .= "AND " . implode (" AND ", $search) . " "; | |
36 | + $sql .= "order by id asc"; | |
37 | + $pagerOptions = Array ( | |
38 | + 'mode' => 'Sliding', | |
39 | + 'delta' => 6, | |
40 | + 'perPage' => 10, | |
41 | + 'spacesBeforeSeparator' => 1, | |
42 | + 'spacesAfterSeparator' => 1 | |
43 | + ); | |
44 | + $this->tpl->assign ('newsAllData', Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ())); | |
45 | + } | |
46 | + function getFonRand () | |
47 | + { | |
48 | + $count = $this->db->getOne ("select count(*) from fon", array ()); | |
49 | + $limit = rand (0, $count - 1); | |
50 | + return $this->db->getRow ("select * from fon limit $limit ,1", array (), DB_FETCHMODE_ASSOC); | |
51 | + } | |
52 | + function viewOneNews ($id, &$row) | |
53 | + { | |
54 | + $sql = "select * from fon where id=? limit 1"; | |
55 | + $row = $this->db->getRow ($sql, array ( | |
56 | + $id | |
57 | + ), DB_FETCHMODE_ASSOC); | |
58 | + $this->tpl->assign ('news', $row); | |
59 | + } | |
60 | + function admin_infoEditNewsOne ($id) | |
61 | + { | |
62 | + $sql = "select * from fon where id=? limit 1"; | |
63 | + $row = $this->db->getRow ($sql, array ( | |
64 | + $id | |
65 | + ), DB_FETCHMODE_ASSOC); | |
66 | + $this->tpl->assign ('news', $row); | |
67 | + } | |
68 | + function trim (&$data) | |
69 | + { | |
70 | + foreach ($data as $key => $value) | |
71 | + { | |
72 | + if (! is_array ($data[$key])) | |
73 | + $data[$key] = trim ($value); | |
74 | + } | |
75 | + } | |
76 | + function valid ($data, $upload = null) | |
77 | + { | |
78 | + if (isset ($data['title'])) | |
79 | + { | |
80 | + if (! preg_match ("/.{1,150}/i", $data['title'])) | |
81 | + $this->error[] = "Îøèáêà ââîäà ïîëÿ Çàãëàâèå, îò 1-150 ñèìâîëîâ."; | |
82 | + } | |
83 | + | |
84 | + if (isset ($upload['pic']['name']) && $upload['pic']['name'] != null) | |
85 | + { | |
86 | + $type = substr (strrchr ($upload['pic']['name'], "."), 1); | |
87 | + if (! preg_match ("/^(jpeg|jpg|gif|png)$/i", $type)) | |
88 | + $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif."; | |
89 | + } | |
90 | + | |
91 | + return (count ($this->error)) ? true : false; | |
92 | + } | |
93 | + function SaveNews ($data, $upload = null, $firm_id = 0) | |
94 | + { | |
95 | + $table_name = "fon"; | |
96 | + if ($data['update_id'] > 0) | |
97 | + { | |
98 | + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | |
99 | + $id = $data['update_id']; | |
100 | + $where = "id=$id"; | |
101 | + } | |
102 | + else | |
103 | + { | |
104 | + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; | |
105 | + $where = null; | |
106 | + } | |
107 | + | |
108 | + $fields_values = array ( | |
109 | + "name" => $data['name'], | |
110 | + "url" => $data['url'] | |
111 | + ); | |
112 | + | |
113 | + if (isset ($data['delete_pic']) && $data['delete_pic'] == 1) | |
114 | + { | |
115 | + $this->deletePic ($id); | |
116 | + $fields_values['pic'] = null; | |
117 | + } | |
118 | + if ($upload['pic']['tmp_name']) | |
119 | + { | |
120 | + $this->deletePic ($id); | |
121 | + $uploadfile = "./uploaded/pic/fon/"; | |
122 | + $type = substr (strrchr ($upload['pic']['name'], "."), 1); | |
123 | + $uploadname = mktime () . "." . $type; | |
124 | + if (! move_uploaded_file ($_FILES['pic']['tmp_name'], $uploadfile . $uploadname)) | |
125 | + { | |
126 | + print "Îøèáêà ïðè çàêà÷êå ôàéëà!"; | |
127 | + } | |
128 | + $fields_values['pic'] = $uploadname; | |
129 | + } | |
130 | + | |
131 | + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, $where); | |
132 | + return $id; | |
133 | + } | |
134 | + function deletePic ($id) | |
135 | + { | |
136 | + $sql = "select pic from fon where id=?"; | |
137 | + $news = $this->db->getRow ($sql, array ( | |
138 | + $id | |
139 | + ), DB_FETCHMODE_ASSOC); | |
140 | + @unlink ("./uploaded/pic/fon/{$news['pic']}"); | |
141 | + } | |
142 | + function admin_deleteNewsOne ($id) | |
143 | + { | |
144 | + $this->deletePic ($id); | |
145 | + $sql = "delete from fon where id=?"; | |
146 | + $this->db->query ($sql, array ( | |
147 | + $id | |
148 | + )); | |
149 | + } | |
150 | + function displayNewsSave () | |
151 | + { | |
152 | + $this->tpl->assign ("tpl", "fon_save.tpl"); | |
153 | + } | |
154 | + function displayNews () | |
155 | + { | |
156 | + $this->tpl->assign ("tpl", "fon.tpl"); | |
157 | + } | |
158 | + function displayNewsOne () | |
159 | + { | |
160 | + $this->tpl->assign ("tpl", "fon_one.tpl"); | |
161 | + } | |
133 | 162 | } |
134 | 163 | ?> | ... | ... |