promo.class.php
10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<?php
class Promo{
var $db = null;
var $tpl = null;
var $error = null;
//var $id = false;
function Promo(&$db,&$tpl,&$error){
$this->db = &$db;
$this->tpl = &$tpl;
$this->error = &$error;
}
function viewListNews($promo_id,$id){
$sql = "select * from promo where promo_id=? and id<>? order by id desc";
$row = $this->db->getAll($sql,array($promo_id,$id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('list',$row);
}
function viewListFoto($promo_id){
$sql = "select * from promo_foto where promo_id=? order by id desc";
$row = $this->db->getAll($sql,array($promo_id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('fotos',$row);
}
function viewAllFoto($param = array()){
$search = array();
if(isset($param['ID']) && $param['ID']>0)$search[] = "promo_id='".$param['ID']."'";
$sql = "select * from promo_foto 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('newsAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewAllNews($param = array()){
$search = array();
if(isset($param['ID']) && $param['ID']>0)$search[] = "promo_id='".$param['ID']."'";
$sql = "select * from promo 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('newsAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewAllAkcii($param = array()){
$search = array();
$sql = "select * from promo_akcii 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('newsAllData', Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()));
}
function viewOneNews($id,&$row){
$sql = "select * from promo where prefix=? limit 1";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('news',$row);
}
function viewOneFoto($id){
$sql = "select * from promo_foto where id=? limit 1";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('foto',$row);
}
function admin_infoEditNewsOne($id){
$sql = "select * from promo where id=? limit 1";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('news',$row);
}
function admin_infoEditAkciiOne($id){
$sql = "select * from promo_akcii where id=? limit 1";
$row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
$this->tpl->assign('news',$row);
}
function admin_infoEditFotoOne($id){
$sql = "select * from promo_foto 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['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 SaveAkcii($data,$upload = null){
$table_name = "promo_akcii";
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('mySequenceAkcii');$where = null;}
$fields_values = array("id"=>$id,"title"=>$data['title'],"about"=>$data['about']);
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
function SaveNews($data,$upload = null){
$table_name = "promo";
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('mySequenceAkcii');$where = null;}
$fields_values = array("id"=>$id,"promo_id"=>$data['promo_id'],"title"=>$data['title'],"about"=>$data['about'],"code"=>$data['code'],"prefix"=>$data['prefix'],
"cost_last"=>$data['cost_last'],
"cost"=>$data['cost'],
"link"=>$data['link'],
"meta_title"=>$data['meta_title'],"meta_description"=>$data['meta_description'],"meta_keywords"=>$data['meta_keywords'],"meta_about"=>$data['meta_about']);
// if(!$data['update_id']){$fields_values['mktime'] = mktime();}
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/promo/";
$type = substr(strrchr($upload['pic']['name'], "."), 1);
$uploadname = mktime() . "." . $type;
move_uploaded_file($upload['pic']['tmp_name'], $uploadfile . $uploadname);
$fields_values['pic'] = $uploadname;
}
if(isset($data['delete_pic2']) && $data['delete_pic2']==1){
$this->deletePic2($id);
$fields_values['bgpic'] = null;
}
if($upload['pic2']['tmp_name']){
$this->deletePic2($id);
$uploadfile = "./uploaded/pic/promo/bg/";
$type = substr(strrchr($upload['pic2']['name'], "."), 1);
$uploadname = mktime() . "." . $type;
move_uploaded_file($upload['pic2']['tmp_name'], $uploadfile . $uploadname);
$fields_values['bgpic'] = $uploadname;
}
if(isset($data['delete_ico']) && $data['delete_ico']==1){
$this->deletePicIco($id);
$fields_values['icopic'] = null;
}
if($upload['ico']['tmp_name']){
$this->deletePicIco($id);
$uploadfile = "./uploaded/pic/promo/ico/";
$type = substr(strrchr($upload['ico']['name'], "."), 1);
$uploadname = mktime() . "." . $type;
move_uploaded_file($upload['ico']['tmp_name'], $uploadfile . $uploadname);
$fields_values['icopic'] = $uploadname;
}
// print_r($fields_values); exit;
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
function SaveFoto($data,$upload = null){
$table_name = "promo_foto";
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('mySequenceAkcii');$where = null;}
$fields_values = array("id"=>$id,"promo_id"=>$data['promo_id'],"title"=>$data['title']);
if(isset($data['delete_pic']) && $data['delete_pic']==1){
$this->deletePicFoto($id);
$fields_values['pic'] = null;
}
if($upload['pic']['tmp_name']){
$this->deletePicFoto($id);
$uploadfile = "./uploaded/pic/promo/foto/";
$type = substr(strrchr($upload['pic']['name'], "."), 1);
$uploadname = mktime() . "." . $type;
move_uploaded_file($upload['pic']['tmp_name'], $uploadfile . $uploadname);
$fields_values['pic'] = $uploadname;
}
if(isset($data['delete_ico']) && $data['delete_ico']==1){
$this->deletePicIcoFoto($id);
$fields_values['icopic'] = null;
}
if($upload['ico']['tmp_name']){
$this->deletePicIcoFoto($id);
$uploadfile = "./uploaded/pic/promo/foto/ico/";
$type = substr(strrchr($upload['ico']['name'], "."), 1);
$uploadname = mktime() . "." . $type;
move_uploaded_file($upload['ico']['tmp_name'], $uploadfile . $uploadname);
$fields_values['icopic'] = $uploadname;
}
// print_r($fields_values); exit;
$this->db->autoExecute($table_name, $fields_values, $DB_AUTOQUERY,$where);
return $id;
}
function deletePicFoto($id){
$sql = "select pic from promo_foto where id=?";
$news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("./uploaded/pic/promo/foto/{$news['pic']}");
}
function deletePicIcoFoto($id){
$sql = "select icopic from promo_foto where id=?";
$news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("./uploaded/pic/promo/foto/ico/{$news['icopic']}");
}
function deletePic($id){
$sql = "select pic from promo where id=?";
$news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("./uploaded/pic/promo/{$news['pic']}");
}
function deletePic2($id){
$sql = "select bgpic from promo where id=?";
$news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("./uploaded/pic/promo/bg/{$news['bgpic']}");
}
function deletePicIco($id){
$sql = "select icopic from promo where id=?";
$news = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
@unlink("./uploaded/pic/promo/ico/{$news['icopic']}");
}
function admin_deleteNewsOne($id){
$this->deletePic($id);
$this->deletePic2($id);
$sql = "delete from promo where id=?";
$this->db->query($sql,array($id));
}
function admin_deleteAkciiOne($id){
$sql = "delete from promo_akcii where id=?";
$this->db->query($sql,array($id));
}
function admin_deleteFotoOne($id){
$this->deletePicFoto($id);
$this->deletePicIcoFoto($id);
$sql = "delete from promo_foto where id=?";
$this->db->query($sql,array($id));
}
function displayNewsSave(){
$this->tpl->assign("tpl","promo_save.tpl");
}
function displayNews(){
$this->tpl->assign("tpl","promo.tpl");
}
function displayNewsOne(){
$this->tpl->assign("tpl","promo_one.tpl");
}
function displayAkciiSave(){
$this->tpl->assign("tpl","promo_akcii_save.tpl");
}
function displayAkcii(){
$this->tpl->assign("tpl","promo_akcii.tpl");
}
function displayAkciiOne(){
$this->tpl->assign("tpl","promo_akcii_one.tpl");
}
function displayFotoSave(){
$this->tpl->assign("tpl","promo_foto_save.tpl");
}
function displayFoto(){
$this->tpl->assign("tpl","promo_foto.tpl");
}
function displayFotoOne(){
$this->tpl->assign("tpl","promo_foto_one.tpl");
}
}
?>