Commit 639b0c95c8d46d371ac4743dd62fa5f3426c6f4b
1 parent
abf79446
удалил мусор
Showing
2 changed files
with
0 additions
and
3558 deletions
Show diff stats
libs/catalogs.class_.php deleted
1 | -<?php | ||
2 | -class Catalogs{ | ||
3 | - var $db = null; | ||
4 | - var $tpl = null; | ||
5 | - var $error = null; | ||
6 | - var $photo_id = null; | ||
7 | - | ||
8 | - | ||
9 | - function Catalogs(&$db,&$tpl,&$error){ | ||
10 | - $this->db = &$db; | ||
11 | - $this->tpl = &$tpl; | ||
12 | - $this->error = &$error; | ||
13 | - } | ||
14 | - | ||
15 | - | ||
16 | - function trim(&$data){ | ||
17 | - foreach($data as $key=>$value){ | ||
18 | - if(is_array($value))$this->trim($value); | ||
19 | - else $data[$key] = stripslashes(trim($value)); | ||
20 | - } | ||
21 | - } | ||
22 | - | ||
23 | - | ||
24 | - function valid($data,$upload = null){ | ||
25 | - | ||
26 | - if(isset($data['name'])){ | ||
27 | - if( !preg_match("/.{1,100}/i",$data['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ."; | ||
28 | - } | ||
29 | - | ||
30 | - if(isset($data['about_min'])){ | ||
31 | - if( !preg_match("/.+/is",$data['about_min']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Êðàòêîå îïèñàíèå."; | ||
32 | - } | ||
33 | - /* | ||
34 | - if(isset($data['text'])){ | ||
35 | - if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ïîëíîå îïèñàíèå."; | ||
36 | - } */ | ||
37 | -/* | ||
38 | - if(isset($data['cine'])){ | ||
39 | - if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Öåíà, òîëüêî öèôðû."; | ||
40 | - } */ | ||
41 | - | ||
42 | - if(isset($upload['pic']['name']) && $upload['pic']['tmp_name']){ | ||
43 | - $type = substr(strrchr($upload['pic']['name'],"."),1); | ||
44 | - if( !preg_match("/^(jpeg|jpg|gif|png|bmp)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif."; | ||
45 | - } | ||
46 | - | ||
47 | - if(isset($upload['file']['name'])){ | ||
48 | - if( !preg_match("/\.csv$/i",$upload['file']['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ CSV ôàéë, òîëüêî csv."; | ||
49 | - } | ||
50 | - | ||
51 | - | ||
52 | - if(isset($data['order_name'])){ | ||
53 | - if( !preg_match("/.{1,100}/i",$data['order_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
54 | - } | ||
55 | - | ||
56 | - if(isset($data['order_adress'])){ | ||
57 | - if( !preg_match("/.{1,200}/i",$data['order_adress']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Àäðåñ (Ìàêñèìóì 200 ñèìâîëîâ)."; | ||
58 | - } | ||
59 | - | ||
60 | - if(isset($data['order_phone2'])&& strlen($data['order_phone2'])>0){ | ||
61 | - if( !preg_match("/.{1,20}/i",$data['order_phone2']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Òåëåôîí (Ìàêñèìóì 70 ñèìâîëîâ)."; | ||
62 | - } | ||
63 | - | ||
64 | - if(isset($data['order_phone'])){ | ||
65 | -if( trim($data['order_phone']) == "" ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX)."; | ||
66 | - } | ||
67 | - | ||
68 | - if(isset($data['delivery']) && $data['delivery']==0){ | ||
69 | - $this->error[] = "Îøèáêà ââîäà ïîëÿ Äîñòàâêà."; | ||
70 | - } | ||
71 | - | ||
72 | - if(isset($data['user_name'])){ | ||
73 | - if( !preg_match("/.{1,100}/i",$data['user_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
74 | - } | ||
75 | - | ||
76 | - if(isset($data['user_email'])){ | ||
77 | - if( !preg_match("/.{1,80}/i",$data['user_email']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø e-mail (Ìàêñèìóì 80 ñèìâîëîâ)."; | ||
78 | - } | ||
79 | - | ||
80 | - if(isset($data['user_login'])){ | ||
81 | - if( !preg_match("/.{1,100}/i",$data['user_login']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ëîãèí (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
82 | - elseif( $this->isLoginUser($data['user_login']) ) $this->error[] = "Îøèáêà òàêîé Ëîãèí óæå åñòü!"; | ||
83 | - } | ||
84 | - | ||
85 | - if(isset($data['you_login'])){ | ||
86 | - if( !$this->isLoginUser($data['you_login']) ) $this->error[] = "Òàêîãî ËÎÃÈÍÀ íåò â áàçå äàííûõ ñàéòà!"; | ||
87 | - } | ||
88 | - | ||
89 | - if(isset($data['user_psw'])){ | ||
90 | - if( !preg_match("/.{1,100}/i",$data['user_psw']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ïàðîëü (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
91 | - } | ||
92 | - | ||
93 | - return ( count($this->error) ) ? true : false; | ||
94 | - } | ||
95 | - | ||
96 | - function deleteRubric($id,$field="id"){ | ||
97 | - $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?"; | ||
98 | - $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); | ||
99 | - foreach($res as $row){ | ||
100 | - @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}"); | ||
101 | - $sql = "delete from catalogs_rubrics where id=?"; | ||
102 | - $this->db->query($sql,array($row['id'])); | ||
103 | - $this->deleteFiltersRubric_id($row['id']); | ||
104 | - $this->deleteYearsRubric_id($row['id']); | ||
105 | - $this->deleteProductsRubric($row['id']); | ||
106 | - $this->deleteRubric($row['id'],"parent_id"); | ||
107 | - } | ||
108 | - } | ||
109 | - | ||
110 | - function deleteProductPics($id,$pics = array('pic_big','pic')){ | ||
111 | - $sql = "select pic_big,pic from catalogs_products where id=?"; | ||
112 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
113 | - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}"); | ||
114 | - if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}"); | ||
115 | - } | ||
116 | - | ||
117 | - function deleteProduct($id){ | ||
118 | - $this->deleteProductPics($id); | ||
119 | - $sql = "delete from catalogs_products where id=?"; | ||
120 | - $this->db->query($sql,array($id)); | ||
121 | - $this->delete_keysProductsFilters($id); | ||
122 | - $this->delete_keysProductsAkcii($id); | ||
123 | - $this->delete_keysProductsYears($id); | ||
124 | - $this->delete_keysProductsCities($id); | ||
125 | - $this->deleteProductModifications($id); | ||
126 | - } | ||
127 | - | ||
128 | - function deleteProductsRubric($id){ | ||
129 | - $res = $this->db->getAll("select id from catalogs_products where rubric_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
130 | - foreach($res as $row){ | ||
131 | - $this->deleteProduct($row['id']); | ||
132 | - } | ||
133 | - } | ||
134 | - | ||
135 | - | ||
136 | - function PhotosCheck($id_s,$check_s = array()){ | ||
137 | - $sql = "UPDATE gallery SET active = ? WHERE id =?"; | ||
138 | - | ||
139 | - foreach($id_s as $id){ | ||
140 | - $this->db->query($sql,array(0,$id)); | ||
141 | - } | ||
142 | - if(count($check_s)){ | ||
143 | - foreach($check_s as $id){ | ||
144 | - $this->db->query($sql,array(1,$id)); | ||
145 | - } | ||
146 | - } | ||
147 | - } | ||
148 | - | ||
149 | - function viewRubrics($id = 0,$parent_id = 0){ // print $parent_id."<br />"; | ||
150 | - global $rubrics; | ||
151 | - //$sql = "select a.*,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? group by a.id order by a.sort asc"; | ||
152 | -$sql = "select a.*,(select b.translit from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid2,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? group by a.id order by a.sort asc"; | ||
153 | - | ||
154 | -$res = $this->db->query($sql,array($id)); | ||
155 | - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){ | ||
156 | - $rubrics[] = $row; //print $row['id']."<br />"; | ||
157 | - | ||
158 | - if(in_array($row['id'],$this->getParentIdRubric($parent_id))){$this->viewRubrics($row['id']);} | ||
159 | - // if($row['level']==0){$this->viewRubrics($row['id']);} | ||
160 | - } | ||
161 | - $this->tpl->assign("rubrics",$rubrics); | ||
162 | - } | ||
163 | - | ||
164 | - function getParentIdRubric($id){ | ||
165 | - //$ids = array(); | ||
166 | - global $ids; | ||
167 | - if(!count($ids))$ids = array(); | ||
168 | - while($id>0){ | ||
169 | - $row = $this->db->getRow('select id,parent_id from catalogs_rubrics where id=?',array($id),DB_FETCHMODE_ASSOC); | ||
170 | - //if(isset($row['id'])) | ||
171 | - $ids[] = $row['id']; | ||
172 | - $id = $row['parent_id']; | ||
173 | - } //print_r($ids); | ||
174 | - // sort($ids); | ||
175 | - return $ids; | ||
176 | - } | ||
177 | - | ||
178 | - function viewRubricsAll($id = 0){ | ||
179 | - global $rubrics; | ||
180 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
181 | - $res = $this->db->query($sql,array($id)); | ||
182 | - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){ | ||
183 | - $rubrics[] = $row; | ||
184 | - $this->viewRubricsAll($row['id']); | ||
185 | - } | ||
186 | - $this->tpl->assign("rubrics",$rubrics); | ||
187 | - } | ||
188 | - | ||
189 | - | ||
190 | - function viewRubrics_begin($item = 'parents'){ | ||
191 | - $sql = "select a.*,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? order by a.sort asc"; | ||
192 | - $row = $this->db->getAll($sql,array(0),DB_FETCHMODE_ASSOC); | ||
193 | - foreach($row as $key=>$value){ | ||
194 | - if($item=='parents'){ | ||
195 | - $row[$key]['parents'] = $this->db->getAll("select * from catalogs_rubrics where parent_id=? order by sort asc",array($value['id']),DB_FETCHMODE_ASSOC); | ||
196 | - }elseif($item=='brends'){ | ||
197 | - $row[$key]['brends'] = $this->db->getAll("select * from catalogs_brends where rubric_id in (select id from catalogs_rubrics where parent_id=? or id=?) group by name",array($value['id'],$value['id']),DB_FETCHMODE_ASSOC); | ||
198 | - } | ||
199 | - } | ||
200 | - $this->tpl->assign("catalogs_rubrics_begin",$row); | ||
201 | - } | ||
202 | - | ||
203 | - function viewRubrics_parent($parent_id = 0){ | ||
204 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
205 | - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); | ||
206 | - $this->tpl->assign("catalogs_rubrics_parent",$row); | ||
207 | - } | ||
208 | - | ||
209 | - function viewRubrics_parent2($rub_id){ | ||
210 | - $parent_id = $this->getRubricParent($rub_id); | ||
211 | - if($parent_id==0)$parent_id = $rub_id; | ||
212 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
213 | - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); | ||
214 | - $this->tpl->assign("catalogs_rubrics_parent2",$row); | ||
215 | - } | ||
216 | - | ||
217 | - function viewRubricOne($id,&$row){ | ||
218 | - $sql = "select * from catalogs_rubrics where id=?"; | ||
219 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
220 | - $this->tpl->assign('rubric',$row); | ||
221 | - } | ||
222 | - | ||
223 | - function getRubricName($id){ | ||
224 | - $sql = "select name from catalogs_rubrics where id=?"; | ||
225 | - return $this->db->getOne($sql,array($id)); | ||
226 | - } | ||
227 | - | ||
228 | - function getRubricParent($id){ | ||
229 | - $sql = "select parent_id from catalogs_rubrics where id=?"; | ||
230 | - return $this->db->getOne($sql,array($id)); | ||
231 | - } | ||
232 | - | ||
233 | - function SaveRubric($data,$upload){ | ||
234 | - $table_name = "catalogs_rubrics"; | ||
235 | - | ||
236 | -if(trim($data['translit']) == '') $data['translit'] = translit($data['name']); | ||
237 | - | ||
238 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
239 | - $parent_id = (isset($data['parent_id']) ? $data['parent_id'] : 0); | ||
240 | - $fields_values = array('parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1),'sort' => $data['sort'],'name' => $data['name'],'list_name' => $data['list_name'],'sort_cost' => $data['sort_cost'],'meta_title' => $data['meta_title'],'meta_description' => $data['meta_description'],'meta_keywords' => $data['meta_keywords'],'meta_about' => $data['meta_about'],'translit' => $data['translit']); | ||
241 | - /* | ||
242 | - if($upload['pic']['tmp_name']){ | ||
243 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/")); | ||
244 | - } */ | ||
245 | - | ||
246 | - if($upload['pic']['tmp_name']){ | ||
247 | - if($data['update_id']>0)$this->deletePicRubric($data['update_id']); | ||
248 | - $uploadfile = "./uploaded/pic/catalogs/rubrics/"; | ||
249 | - $type = substr(strrchr($upload['pic']['name'],"."),1); | ||
250 | - $uploadname = mktime() . "." . $type; | ||
251 | - if (!move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))print"Îøèáêà ïðè çàêà÷êå ôàéëà!"; | ||
252 | - $fields_values['pic'] = $uploadname; | ||
253 | - } | ||
254 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
255 | - } | ||
256 | - | ||
257 | - function deletePicRubric($id){ | ||
258 | - $sql = "select pic from catalogs_rubrics where id=?"; | ||
259 | - $rub = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
260 | - @unlink("./uploaded/pic/catalogs/rubrics/{$rub['pic']}"); | ||
261 | - } | ||
262 | - | ||
263 | - function getLevelRubric($id){ | ||
264 | - $level = $this->db->getOne("select level from catalogs_rubrics where id=?",array($id)); | ||
265 | - return ($level==null)? -1 : $level; | ||
266 | - } | ||
267 | - | ||
268 | - function saveUser($data){ | ||
269 | - $table_name = "catalogs_users"; | ||
270 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
271 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'login' => $data['user_login'],'psw' => $data['user_psw'],'about' => $data['user_about'],'mktime'=>mktime()); | ||
272 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
273 | - } | ||
274 | - | ||
275 | - function updateUser($data){ | ||
276 | - $table_name = "catalogs_users"; | ||
277 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
278 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'login' => $data['user_login'],'psw' => $data['user_psw'],'about' => $data['user_about'],'discount'=>$data['user_discount']); | ||
279 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
280 | - } | ||
281 | - | ||
282 | - function updateUserID($data,$id){ | ||
283 | - $table_name = "catalogs_users"; | ||
284 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
285 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'psw' => $data['user_psw'],'about' => $data['user_about'],'phone' => $data['user_phone'],'phonemob' => $data['user_phonemob'],'adress' => $data['user_adress']); | ||
286 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$id}"); | ||
287 | - } | ||
288 | - | ||
289 | - function deleteUser($id){ | ||
290 | - $this->db->query("delete from catalogs_users where id=?",array($id)); | ||
291 | - $res_order_id = $this->db->getRow("select id from catalogs_orders where user_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
292 | - if(count($res_order_id)){ | ||
293 | - foreach($res_order_id as $_id){ | ||
294 | - $this->db->query("delete from catalogs_orders where id=?",array($_id)); | ||
295 | - $this->db->query("delete from catalogs_orders_products where order_id=?",array($_id)); | ||
296 | - }} | ||
297 | - } | ||
298 | - | ||
299 | - function isLoginUser($login){ | ||
300 | - return $this->db->getOne("select id from catalogs_users where login=?",array($login)); | ||
301 | - } | ||
302 | - | ||
303 | - function sendLoginInfo($login){ | ||
304 | - $user = $this->db->getRow("select * from catalogs_users where login=?",array($login),DB_FETCHMODE_ASSOC); | ||
305 | - $mail = new PHPMailer(); | ||
306 | - $mail->CharSet = "windows-1251"; | ||
307 | - $mail->From = "shop@eltrade.com.ua"; | ||
308 | - $mail->FromName = "shop@eltrade.com.ua"; | ||
309 | - $mail->AddAddress($user['email'], $user['name']); | ||
310 | - $mail->Subject = "Àêêàóíò ýêñòðèì"; | ||
311 | - $msg = ""; | ||
312 | - $msg .= "Çäðàâñòâóéòå: ".$user['name']; | ||
313 | - $msg .= "<br />"; | ||
314 | - $msg .= "Âàø ëîãèí: ".$user['login']; | ||
315 | - $msg .= "<br>"; | ||
316 | - $msg .= "Âàø ïàðîëü: ".$user['psw']; | ||
317 | - $msg .= "<br>"; | ||
318 | - $msg .= "Ñ óâàæåíèåì, shop@eltrade.com.ua"; | ||
319 | - | ||
320 | - $mail->MsgHTML($msg); | ||
321 | - | ||
322 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
323 | - $mail->ClearAddresses(); | ||
324 | - $mail->ClearAttachments(); | ||
325 | - } | ||
326 | - | ||
327 | - function isUser($login,$psw){ | ||
328 | - $row = $this->db->getRow("select * from catalogs_users where login=? AND psw=?",array($login,$psw),DB_FETCHMODE_ASSOC); | ||
329 | - $this->tpl->assign('user_service',$row); | ||
330 | - return $row['id']; | ||
331 | - } | ||
332 | - | ||
333 | - function viewUser($id){ | ||
334 | - $sql = "select * from catalogs_users where id=?"; | ||
335 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
336 | - $this->tpl->assign('user',$row); | ||
337 | - } | ||
338 | - | ||
339 | - function getUserDiscount($id){ | ||
340 | - return $this->db->getOne("select discount from catalogs_users where id=?",array($id)); | ||
341 | - } | ||
342 | - | ||
343 | - function viewUsers(){ | ||
344 | - $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders | ||
345 | -FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id | ||
346 | -GROUP BY catalogs_users.id | ||
347 | -ORDER BY catalogs_users.mktime DESC"; | ||
348 | - | ||
349 | - $pagerOptions = Array( | ||
350 | - 'mode' => 'Sliding', | ||
351 | - 'delta' => 6, | ||
352 | - 'perPage' => 10, | ||
353 | - 'linkClass'=>"link_class", | ||
354 | - 'curPageLinkClassName'=>"link_class_active", | ||
355 | - 'spacesBeforeSeparator' => 1, | ||
356 | - 'spacesAfterSeparator' => 1 | ||
357 | - ); | ||
358 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
359 | - | ||
360 | - $this->tpl->assign('usersData', $res); | ||
361 | - } | ||
362 | - | ||
363 | - function viewModifications($product_id){ | ||
364 | - $sql = "select * from catalogs_modifications where product_id=? order by id desc"; | ||
365 | - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
366 | - $this->tpl->assign('modifications', $row); | ||
367 | - } | ||
368 | - | ||
369 | - function viewModificationsProduct($product_id){ | ||
370 | - $sql = "select * from catalogs_modifications where product_id=? and active>0 order by id desc"; | ||
371 | - // $sql = "select m.* from catalogs_keys_products_cities k left join catalogs_modifications m on m.code=k.mod_code where k.product_id=? and k.count>0 order by k.mod_code desc"; | ||
372 | - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
373 | - $this->tpl->assign('modifications', $row); | ||
374 | - } | ||
375 | - | ||
376 | - function viewModificationOne($id){ | ||
377 | - $sql = "select * from catalogs_modifications where id=?"; | ||
378 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
379 | - $this->tpl->assign('modification', $row); | ||
380 | - } | ||
381 | - | ||
382 | - function getModificationProduct_id($code){ | ||
383 | - return $this->db->getOne("select product_id from catalogs_modifications where code=?",array($code)); | ||
384 | - } | ||
385 | - | ||
386 | - function SaveModification($data,$upload){ | ||
387 | - $table_name = "catalogs_modifications"; | ||
388 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
389 | - $fields_values = array('product_id'=>$data['product_id'],'code'=>$data['code'],'size' => $data['size'],'color' => $data['color'],'active' => $data['active']); | ||
390 | - if(isset($data['delete_pic'])){if($data['update_id']>0){$this->deleteModificationPics($data['update_id']);}$fields_values['pic']=null;$fields_values['pic_big']=null;} | ||
391 | - if($upload['pic']['tmp_name']){ | ||
392 | - if($data['update_id']>0){ | ||
393 | - $delete_pics = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?array('pic'):array('pic','pic_big'); | ||
394 | - $this->deleteModificationPics($data['update_id'],$delete_pics); | ||
395 | - } | ||
396 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"144",'height'=>"144",'upload_path'=>"./uploaded/pic/catalogs/modifications/")); | ||
397 | - $fields_values['pic_big'] = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?$upload['pic']['name']:upload_ImageResize($upload['pic'],array('width'=>"500",'height'=>"500",'upload_path'=>"./uploaded/pic/catalogs/modifications/big/")); | ||
398 | - } | ||
399 | - | ||
400 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='{$data['update_id']}'"); | ||
401 | - return $id; | ||
402 | - } | ||
403 | - | ||
404 | - function deleteModification($id){ | ||
405 | - $this->deleteModificationPics($id); | ||
406 | - $this->db->query("delete from catalogs_modifications where id=?",array($id)); | ||
407 | - } | ||
408 | - | ||
409 | - function deleteProductModifications($product_id,$nopic = false){ | ||
410 | - IF($nopic==false){ | ||
411 | - $sql = "select * from catalogs_modifications where product_id=?"; | ||
412 | - $res = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
413 | - foreach($res as $row){ | ||
414 | - $this->deleteModificationPics($row['id']); | ||
415 | - } | ||
416 | - } | ||
417 | - $this->db->query("delete from catalogs_modifications where product_id=?",array($product_id)); | ||
418 | - } | ||
419 | - | ||
420 | - function deleteModificationPics($id,$pics = array('pic_big','pic')){ | ||
421 | - $sql = "select pic,pic_big from catalogs_modifications where id=?"; | ||
422 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
423 | - if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}"); | ||
424 | - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); | ||
425 | - } | ||
426 | - | ||
427 | - function ProductClick($id){ | ||
428 | - $this->db->query("update catalogs_products set click=click+1 where id='$id'"); | ||
429 | - } | ||
430 | - | ||
431 | - function SaveProduct($data,$upload){ | ||
432 | - $table_name = "catalogs_products"; | ||
433 | - | ||
434 | -if(trim(@$data['translit'])=="") $data['translit'] = @totranslit($data['name']); | ||
435 | - | ||
436 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
437 | - $id = ($data['update_id']>0) ? $data['update_id'] : $this->db->nextId('mySequence_'.$table_name); | ||
438 | - $fields_values = array('id'=>$id,'rubric_id'=>$data['rubric_id'],'rubric_parent_id'=>$this->getRubricParent($data['rubric_id']),'brend_id'=>$data['brend_id'],'name' => $data['name'],'about' => $data['about'],'text' => $data['text'],'strnumber' => $data['strnumber'],'cine'=>$data['cine'],'cine_last'=>$data['cine_last'],'sex'=>$data['sex'], 'mktime' => mktime(),'meta_title' => $data['meta_title'],'meta_description' => $data['meta_description'],'meta_keywords' => $data['meta_keywords'],'meta_about' => $data['meta_about'],'active' => $data['active'],'translit' => $data['translit']); | ||
439 | - if(isset($data['is_cost2']))$fields_values['is_cost2'] = 1;else $fields_values['is_cost2'] = 0; | ||
440 | - if(isset($data['cine2']))$fields_values['cine2'] = $data['cine2']; | ||
441 | - if(isset($data['params']))$fields_values['params'] = $data['params']; | ||
442 | - if(isset($data['doc']))$fields_values['doc'] = $data['doc']; | ||
443 | - if(isset($data['video_code']))$fields_values['video_code'] = $data['video_code']; | ||
444 | - if(isset($data['akcii_id']))$fields_values['akcii_id'] = $data['akcii_id']; | ||
445 | - | ||
446 | - if(isset($data['translit']))$fields_values['translit'] = $data['translit']; | ||
447 | - | ||
448 | - if($upload['pic']['tmp_name']){ | ||
449 | - $delete_pics = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?array('pic'):array('pic','pic_big'); | ||
450 | - $this->deleteProductPics($id,$delete_pics); | ||
451 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"144",'height'=>"144",'upload_path'=>"./uploaded/pic/catalogs/products/")); | ||
452 | - $fields_values['pic_big'] = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?$upload['pic']['name']:upload_ImageResize($upload['pic'],array('width'=>"500",'height'=>"500",'upload_path'=>"./uploaded/pic/catalogs/products/big/")); | ||
453 | - } | ||
454 | - | ||
455 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='$id'"); | ||
456 | - $this->save_keysProductsFilters($id,$data); | ||
457 | - $this->save_keysProductsYears($id,$data); | ||
458 | - //$this->save_keysProductsCities($id,$data); | ||
459 | - $this->save_keysProductsAkcii($id,$data); | ||
460 | - return $id; | ||
461 | - } | ||
462 | - | ||
463 | - function save_keysProductsFilters($id,$data){ | ||
464 | - $this->delete_keysProductsFilters($id); | ||
465 | - if(!isset($data['filter']))return false; | ||
466 | - $table_name = "catalogs_keys_products_filters"; | ||
467 | - foreach($data['filter'] as $filter_id){ | ||
468 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); | ||
469 | - } | ||
470 | - } | ||
471 | - | ||
472 | - function delete_keysProductsFilters($id){ | ||
473 | - $this->db->query("delete from catalogs_keys_products_filters where product_id=?",array($id)); | ||
474 | - } | ||
475 | - | ||
476 | - function save_keysProductsYears($id,$data){ | ||
477 | - $this->delete_keysProductsYears($id); | ||
478 | - if(!isset($data['years']))return false; | ||
479 | - $table_name = "catalogs_keys_products_years"; | ||
480 | - foreach($data['years'] as $filter_id){ | ||
481 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'year_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); | ||
482 | - } | ||
483 | - } | ||
484 | - | ||
485 | - function delete_keysProductsYears($id){ | ||
486 | - $this->db->query("delete from catalogs_keys_products_years where product_id=?",array($id)); | ||
487 | - } | ||
488 | - | ||
489 | - function save_keysProductsCities($id,$data){ | ||
490 | - $this->delete_keysProductsCities($id); | ||
491 | - if(!isset($data['city']))return false; | ||
492 | - $table_name = "catalogs_keys_products_cities"; | ||
493 | - foreach($data['city'] as $city_id){ | ||
494 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'city_id'=>$city_id),DB_AUTOQUERY_INSERT); | ||
495 | - } | ||
496 | - } | ||
497 | - | ||
498 | - function delete_keysProductsAkcii($id){ | ||
499 | - $this->db->query("delete from catalogs_keys_products_akcii where product_id=?",array($id)); | ||
500 | - } | ||
501 | - | ||
502 | - function save_keysProductsAkcii($id,$data){ | ||
503 | - $this->delete_keysProductsAkcii($id); | ||
504 | - if(!isset($data['akcii']))return false; | ||
505 | - $table_name = "catalogs_keys_products_akcii"; | ||
506 | - foreach($data['akcii'] as $rubric_id){ | ||
507 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'rubric_id'=>$rubric_id),DB_AUTOQUERY_INSERT); | ||
508 | - } | ||
509 | - } | ||
510 | - | ||
511 | - function delete_keysProductsCities($id){ | ||
512 | - $this->db->query("delete from catalogs_keys_products_cities where product_id=?",array($id)); | ||
513 | - } | ||
514 | - | ||
515 | - | ||
516 | - function saveProductSizeCine($id,$data){ | ||
517 | - $this->db->query("delete from catalogs_products_cine where product_id=?",array($id)); | ||
518 | - foreach($data['size'] as $key=>$size){ | ||
519 | - $this->db->autoExecute("catalogs_products_cine",array('product_id'=>$id,'size'=>$size,'cine'=>$data['cine'][$key],'metka'=>$data['size_metka'][$key],'n'=>$key),DB_AUTOQUERY_INSERT); | ||
520 | - } | ||
521 | - } | ||
522 | - | ||
523 | - | ||
524 | - function productsIsHits($products,$hits,$tops,$headers){ | ||
525 | - $sql = "update catalogs_products set hit=?,top=?,header=? where id=?"; | ||
526 | - foreach($products as $id){ | ||
527 | - if(@in_array($id,$hits))$hit = true; | ||
528 | - else $hit = false; | ||
529 | - if(@in_array($id,$tops))$top = true; | ||
530 | - else $top = false; | ||
531 | - if(@in_array($id,$headers))$header = true; | ||
532 | - else $header = false; | ||
533 | - $this->db->query($sql,array($hit,$top,$header, $id)); | ||
534 | - } | ||
535 | - } | ||
536 | - | ||
537 | - function productsIsHits2($data,$hits){ | ||
538 | - $sql = "update catalogs_products set hit=?,hit_sort=? where id=?"; | ||
539 | - foreach($data['product_id'] as $key=>$id){ | ||
540 | - if(@in_array($id,$hits))$hit = true; | ||
541 | - else $hit = false; | ||
542 | - $this->db->query($sql,array($hit,$data['hit_sort'][$key],$id)); | ||
543 | - } | ||
544 | - } | ||
545 | - | ||
546 | - function viewProductsRubrics($rubrics,$limit=20){ | ||
547 | - $data = array(); | ||
548 | - foreach($rubrics as $key=>$rubric_id){ | ||
549 | - $data[$key]['rubric']['name'] = $this->getRubricName($rubric_id); | ||
550 | - $data[$key]['rubric']['id'] = $rubric_id; | ||
551 | - | ||
552 | - $count = $this->db->getOne("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?",array($rubric_id)); | ||
553 | - $limit = 4; $round = ($count>$limit) ? rand(0,($count-$limit)) : $limit; | ||
554 | - $sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand(1,1000)%2) ? "asc" : "desc") . " limit $round,$limit"; | ||
555 | - $data[$key]['products'] = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); | ||
556 | - } | ||
557 | - /* print"<pre>"; | ||
558 | - print_r($data); | ||
559 | - print"</pre>"; */ | ||
560 | - $this->tpl->assign('products',$data); | ||
561 | - } | ||
562 | - | ||
563 | - function seralizeFilter($str){ | ||
564 | - $array = explode(';',$str); | ||
565 | - $filter = array(); | ||
566 | - foreach($array as $key=>$value){ | ||
567 | - $filter[substr($value,0,1)][] = substr($value,1, strpos($value,"_")-1 ); | ||
568 | - } | ||
569 | - return $filter; | ||
570 | - } | ||
571 | - | ||
572 | - function viewProducts($params,$rubricsP = false,$count_modf = true){ | ||
573 | - | ||
574 | - | ||
575 | - //exit; | ||
576 | - | ||
577 | - | ||
578 | - if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']); | ||
579 | - $search = array(); | ||
580 | - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; | ||
581 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){ | ||
582 | - $array_string = explode(" ",trim($params['search_str'])); | ||
583 | - $search_string = array(); | ||
584 | - $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'"; | ||
585 | - $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'"; | ||
586 | - /* foreach($array_string as $str){ | ||
587 | - $search_string[] = "catalogs_products.name like '$str'"; | ||
588 | - $search_string[] = "catalogs_products.name like'% $str %'"; | ||
589 | - $search_string[] = "catalogs_products.name like'%$str %'"; | ||
590 | - $search_string[] = "catalogs_products.name like'% $str%'"; | ||
591 | - | ||
592 | - $search_string[] = "catalogs_products.text like '$str'"; | ||
593 | - $search_string[] = "catalogs_products.text like'% $str %'"; | ||
594 | - $search_string[] = "catalogs_products.text like'%$str %'"; | ||
595 | - $search_string[] = "catalogs_products.text like'% $str%'"; | ||
596 | - } */ | ||
597 | - $search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")"; | ||
598 | - } | ||
599 | - // print_r($params); | ||
600 | - if(isset($params['brendID']) && $params['brendID']>0)$search[] = sprintf("catalogs_products.brend_id='%d'",$params['brendID']); | ||
601 | - if(isset($params['akciiID']) && $params['akciiID']>0)$search[] = sprintf("catalogs_products.akcii_id='%d'",$params['akciiID']); | ||
602 | - if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")"; | ||
603 | - if(isset($params['sex']) && strlen($params['sex'])>0){ | ||
604 | - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); | ||
605 | - $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); | ||
606 | - | ||
607 | - } | ||
608 | - //if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']); | ||
609 | - if($count_modf==true)$search[] = "catalogs_products.count_modifications>0"; | ||
610 | - if(isset($params['rubID']) && $params['rubID']>0){ | ||
611 | - $search[] = ($rubricsP==true)?sprintf("(catalogs_products.rubric_id='%d')",$params['rubID']):sprintf(" | ||
612 | - (catalogs_products.rubric_parent_id='%d' || | ||
613 | - catalogs_products.rubric_id='%d' || | ||
614 | - catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') || | ||
615 | - catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))",$params['rubID'],$params['rubID'],$params['rubID'],$params['rubID']); | ||
616 | - } | ||
617 | - | ||
618 | - /* if(isset($params['filterID'])){ | ||
619 | - //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']); | ||
620 | - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")"; | ||
621 | - }*/ | ||
622 | - if(isset($filter['f']) && count($filter['f'])>0){ | ||
623 | - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; | ||
624 | - } | ||
625 | -/* if(isset($params['yearID']) && $params['yearID']>0){ | ||
626 | - //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']); | ||
627 | - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")"; | ||
628 | - }*/ | ||
629 | - if(isset($filter['y']) && $filter['y']>0){ | ||
630 | - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; | ||
631 | - } | ||
632 | - $sql = "select catalogs_rubrics.translit as translit2,catalogs_products.*,catalogs_brends.name as brend_name,catalogs_rubrics.list_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id LEFT JOIN catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id "; | ||
633 | - if(isset($params['akcii']) && $params['akcii']>0)$sql .= "RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id "; | ||
634 | - if(isset($filter['f']) && count($filter['f'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; | ||
635 | - //if(isset($params['filterID']) && $params['filterID']>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; | ||
636 | -// if(isset($params['yearID']) && $params['yearID']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; | ||
637 | - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; | ||
638 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id ";} | ||
639 | - $sql .= "WHERE 1=1 "; | ||
640 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
641 | - if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";} | ||
642 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= " GROUP BY catalogs_products.id ";} | ||
643 | - $sql .= "order by "; | ||
644 | - if(isset($params['sort'])){ | ||
645 | - switch($params['sort']){ | ||
646 | - case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break; | ||
647 | - case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break; | ||
648 | - case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break; | ||
649 | - default : $sql .= " catalogs_products.mktime desc"; | ||
650 | - } | ||
651 | - }else $sql .= " catalogs_products.cine desc"; | ||
652 | - | ||
653 | - $pagerOptions = Array( | ||
654 | - 'mode' => 'Sliding', | ||
655 | - 'delta' => 5, | ||
656 | - 'perPage' => $perPage, | ||
657 | - 'linkClass'=>"link_class", | ||
658 | - 'curPageLinkClassName'=>"link_class_active", | ||
659 | - 'spacesBeforeSeparator' => 1, | ||
660 | - 'spacesAfterSeparator' => 1 | ||
661 | - ); | ||
662 | - //echo $sql; | ||
663 | - //$sql=""; | ||
664 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
665 | - | ||
666 | -if($_GET['test']=='1') | ||
667 | -for($i=0;$i<count($res['data']);$i++){ | ||
668 | - if( @$res['data'][$i]['rating'] ) $res['data'][$i]['rating'] = round( (@$res['data'][$i]['rating'] / @$res['data'][$i]['vote_num']), 0 ); | ||
669 | - else $res['data'][$i]['rating'] = 0; | ||
670 | - $res['data'][$i]['rating'] = @$res['data'][$i]['rating'] * 17; | ||
671 | -} | ||
672 | - | ||
673 | -//if($_GET['test']=='1') print_r($res); | ||
674 | - | ||
675 | - $this->tpl->assign('productsData', $res); | ||
676 | - return $res; | ||
677 | - } | ||
678 | - | ||
679 | - function getCineCurs($type_curs,$cine){ | ||
680 | - $curs = array(); | ||
681 | - | ||
682 | - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); | ||
683 | - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); | ||
684 | - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); | ||
685 | - | ||
686 | - switch($type_curs){ | ||
687 | - case 'uah' : | ||
688 | - $curs['uah'] = round($cine,2); | ||
689 | - $curs['uah_bank'] = round(($cine/$usd)*$uah_bank,2); | ||
690 | - $curs['usd'] = round($cine/$usd,2); | ||
691 | - break; | ||
692 | - case 'uah_bank' : | ||
693 | - $curs['uah'] = round(($cine/$uah_bank)*$uah,2); | ||
694 | - $curs['uah_bank'] = round($cine,2); | ||
695 | - $curs['usd'] = round($cine/$uah_bank,2); | ||
696 | - break; | ||
697 | - case 'usd' : | ||
698 | - $curs['uah'] = round($cine*$uah,2); | ||
699 | - $curs['uah_bank'] = round($cine*$uah_bank,2); | ||
700 | - $curs['usd'] = round($cine,2); | ||
701 | - break; | ||
702 | - } | ||
703 | - return $curs; | ||
704 | - } | ||
705 | - | ||
706 | - function viewProductsAkcii($rubric_id){ | ||
707 | - $sql = "select catalogs_products.* from catalogs_keys_products_akcii left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id where catalogs_keys_products_akcii.rubric_id=?"; | ||
708 | - $res = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); | ||
709 | - //print_r($res); | ||
710 | - $this->tpl->assign('products_akcii',$res); | ||
711 | - } | ||
712 | - | ||
713 | - function viewProductsHitsAll2(){ | ||
714 | - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; | ||
715 | - $sql = "select * from catalogs_products where hit=?"; | ||
716 | - $pagerOptions = Array( | ||
717 | - 'mode' => 'Sliding', | ||
718 | - 'delta' => 6, | ||
719 | - 'perPage' => $perPage, | ||
720 | - 'linkClass'=>"link_class", | ||
721 | - 'curPageLinkClassName'=>"link_class_active", | ||
722 | - 'spacesBeforeSeparator' => 1, | ||
723 | - 'spacesAfterSeparator' => 1 | ||
724 | - ); | ||
725 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array(true)); | ||
726 | - | ||
727 | - $this->tpl->assign('productsData', $res); | ||
728 | - } | ||
729 | - | ||
730 | - function viewProductsHits($params,$limit = 4,$curs = null){ | ||
731 | - $search = array(); | ||
732 | - if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("rubric_parent_id=%d",$params['rubID']); | ||
733 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 "; | ||
734 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
735 | - $sql .= "order by catalogs_products.mktime desc"; | ||
736 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
737 | - $this->tpl->assign('products_hits',$res); | ||
738 | - } | ||
739 | - | ||
740 | - function viewProductsTops($params,$limit = 4,$curs = null){ | ||
741 | - $search = array(); | ||
742 | - if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("rubric_parent_id=%d",$params['rubID']); | ||
743 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 "; | ||
744 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
745 | - $sql .= "order by catalogs_products.mktime desc"; | ||
746 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
747 | - $this->tpl->assign('products_top',$res); | ||
748 | - } | ||
749 | - | ||
750 | - function viewProductsTopOne(){ | ||
751 | - $count = $this->db->getOne("select count(*) from catalogs_products WHERE catalogs_products.header=?",array(true)); | ||
752 | - $limit = 1; $round = rand(0,($count-$limit)); | ||
753 | - $res = $this->db->getRow("select * from catalogs_products WHERE catalogs_products.header=? order by id " . ((rand(1,1000)%2) ? "asc" : "desc") . " LIMIT $round,$limit",array(true),DB_FETCHMODE_ASSOC); | ||
754 | - $this->tpl->assign('products_top_one',$res); | ||
755 | - } | ||
756 | - | ||
757 | - function viewProductsLast($limit = 1){ | ||
758 | - $search = array(); | ||
759 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.active=? "; | ||
760 | - $sql .= "order by catalogs_products.mktime desc LIMIT $limit"; | ||
761 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
762 | - $this->tpl->assign('products_last',$res); | ||
763 | - } | ||
764 | - | ||
765 | - function viewProductsHitsAll($limit = 4){ | ||
766 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE hit=? "; | ||
767 | - $sql .= "order by mktime desc LIMIT $limit"; | ||
768 | - $products_hits = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
769 | - $this->tpl->assign('products_hits_all',$products_hits); | ||
770 | - } | ||
771 | - | ||
772 | - function viewProductOne($id,&$row){ | ||
773 | - $sql = "select p.*,b.name as brend_name,b.text as brend_text,b.pic_s as brend_pic_s from catalogs_products p left join catalogs_brends b ON b.id=p.brend_id where p.id=?"; | ||
774 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
775 | - $this->tpl->assign('product',$row); | ||
776 | - } | ||
777 | - | ||
778 | - function deleteCompareProduct(&$compare,$id){ | ||
779 | - foreach($compare as $key=>$_id){ | ||
780 | - if($_id == $id)unset($compare[$key]); | ||
781 | - } | ||
782 | - } | ||
783 | - | ||
784 | - function viewCompareProducts($compare){ | ||
785 | - $products = array(); | ||
786 | - $i = 0; | ||
787 | - foreach($compare as $id){ | ||
788 | - $sql = "select p.* from catalogs_products p where p.id=?"; | ||
789 | - $products[$i] = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
790 | - $products[$i]['params'] = $this->getProductParams($id); | ||
791 | - $i++; | ||
792 | - } //print_r($products); | ||
793 | - $this->tpl->assign('products',$products); | ||
794 | - } | ||
795 | - | ||
796 | - function viewProductNembers($str_n){ | ||
797 | - $arr_id = explode(",",$str_n); | ||
798 | - $products = array(); | ||
799 | - foreach($arr_id as $id){ | ||
800 | - $count = $this->db->getOne("select count(*) from catalogs_keys_products_filters where filter_id=?",array(trim($id))); | ||
801 | - $limit = 1; $round = rand(0,($count-$limit)); //" LIMIT 0,$limit" | ||
802 | - $sql = "select catalogs_rubrics.translit as translit2, catalogs_products.*,catalogs_keys_products_filters.filter_id as prd from catalogs_keys_products_filters Left Join catalogs_products ON catalogs_products.id=catalogs_keys_products_filters.product_id Left Join catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id where catalogs_keys_products_filters.filter_id=? and catalogs_products.count_modifications>0 order by catalogs_keys_products_filters.product_id " . ((rand(1,1000)%2) ? "asc" : "desc") . " LIMIT $round,$limit"; | ||
803 | - $row = $this->db->getRow($sql ,array(trim($id)),DB_FETCHMODE_ASSOC); | ||
804 | - if(count($row)>0)$products[] = $row; | ||
805 | - } | ||
806 | - | ||
807 | -// $products = $this->db->getAll("select catalogs_rubrics.translit as translit2,catalogs_products.*,catalogs_keys_products_filters.filter_id as prd from catalogs_keys_products_filters Left Join catalogs_products ON catalogs_products.id=catalogs_keys_products_filters.product_id Left Join catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id where catalogs_keys_products_filters.filter_id in(".implode(',',$arr_id).") and catalogs_products.count_modifications>0 Group By catalogs_keys_products_filters.filter_id order by catalogs_keys_products_filters.product_id " . ((rand(1,1000)%2) ? "asc" : "desc") ,array(),DB_FETCHMODE_ASSOC); | ||
808 | - $this->tpl->assign('products_parent',$products); | ||
809 | - } | ||
810 | - | ||
811 | - function getProductSizeCine($id,&$products){ | ||
812 | - $res = $this->db->getAll("select * from catalogs_products_cine where product_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
813 | - $i = 0; | ||
814 | - foreach($res as $row){ | ||
815 | - $products['size_' . $row['n']] = $row['size']; | ||
816 | - $products['cine_' . $row['n']] = $row['cine']; | ||
817 | - $products['metka_' . $row['n']] = $row['metka']; | ||
818 | - $products['id_cine_' . $row['n']] = $row['id']; | ||
819 | - $i++; | ||
820 | - } //print_r($products); | ||
821 | - } | ||
822 | - /* | ||
823 | - function getProductCine($id,$curs = null){ | ||
824 | - $sql = "select cine from catalogs_products where id=?"; | ||
825 | - $row = $this->db->getOne($sql,array($id)); | ||
826 | - return $row; | ||
827 | - }*/ | ||
828 | - | ||
829 | - function getProductCine($id){ | ||
830 | - $sql = "select IF( catalogs_products.is_cost2 <1, catalogs_products.cine, catalogs_products.cine2 ) AS cine from catalogs_modifications left join catalogs_products on catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?"; | ||
831 | - return $this->db->getOne($sql,array($id)); | ||
832 | - } | ||
833 | - | ||
834 | - function viewProductCine($id){ | ||
835 | - $row = $this->db->getAll("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC",array($id),DB_FETCHMODE_ASSOC); | ||
836 | - $this->tpl->assign('product_cines',$row); | ||
837 | - } | ||
838 | - | ||
839 | - function viewCatalogsCurs(){ | ||
840 | - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); | ||
841 | - $this->tpl->assign('curs_uah',$uah); | ||
842 | - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); | ||
843 | - $this->tpl->assign('curs_uah_bank',$uah_bank); | ||
844 | - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); | ||
845 | - $this->tpl->assign('curs_usd',$usd); | ||
846 | - } | ||
847 | - | ||
848 | - function saveCurs($data){ | ||
849 | - $table_name = "catalogs_curs"; | ||
850 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
851 | - foreach($data as $key=>$value){ | ||
852 | - $this->db->autoExecute($table_name,array('curs'=>$value),$DB_AUTOQUERY,"type='$key'"); | ||
853 | - } | ||
854 | - } | ||
855 | - | ||
856 | - function viewVarCurs($curs){ | ||
857 | - $this->tpl->assign('curs',$curs); | ||
858 | - } | ||
859 | - | ||
860 | - function viewBasketProducts($session_basket,$curs = null,$discount = 0){ | ||
861 | - $products = array(); $i = 0; $cineAll = 0; | ||
862 | -// $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?"; | ||
863 | - $sql = "select catalogs_modifications.id,IF(catalogs_products.is_cost2<1,catalogs_products.cine,catalogs_products.cine2) as cine,catalogs_products.name,catalogs_modifications.code,catalogs_modifications.size,catalogs_modifications.color,catalogs_modifications.pic,catalogs_modifications.pic_big from catalogs_modifications Left Join catalogs_products On catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?"; | ||
864 | - | ||
865 | - foreach($session_basket as $id){ | ||
866 | - $products_count = 1; | ||
867 | - if(count($products)){ | ||
868 | - foreach($products as $key=>$value){ | ||
869 | - if($value['id']==$id){$products_count=$products[$key]['products_count']+$products_count;$products[$key]['products_count']=$products_count;$products[$key]['products_cine_all']=$products[$key]['cine']*$products_count;$cineAll = $cineAll+$products[$key]['cine'];} | ||
870 | - }} | ||
871 | - if($products_count==1){ | ||
872 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
873 | - $products[$i] = $row; | ||
874 | - $products[$i]['products_count']=$products_count; | ||
875 | - $products[$i]['products_cine_all']=$products[$i]['cine']*$products_count; | ||
876 | - $cineAll = $cineAll+$products[$i]['products_cine_all']; | ||
877 | - $i++; | ||
878 | - } | ||
879 | - | ||
880 | - } | ||
881 | - /*print"<pre>"; | ||
882 | - print_r($products); | ||
883 | - print"</pre>";*/ | ||
884 | - $this->tpl->assign('cineAll',$cineAll); | ||
885 | - $this->tpl->assign('cineAll_discount',$cineAll - (($cineAll*$discount)/100)); | ||
886 | - $this->tpl->assign('basket_products',$products); //print_r($products); | ||
887 | - } | ||
888 | - | ||
889 | - | ||
890 | - function BasketUpload(&$session_basket,$proructs_count){ | ||
891 | - | ||
892 | - // ========== ZLODEYEV ============ | ||
893 | - | ||
894 | - foreach($proructs_count as $key=>$value){ | ||
895 | - | ||
896 | - // ==== îáíîâëÿåì ==== | ||
897 | - | ||
898 | - // Âûáèðàåì èíôî î òîâàðå | ||
899 | - $sql4 = "SELECT * FROM catalogs_modifications as m | ||
900 | - LEFT JOIN catalogs_products as p | ||
901 | - ON p.id=m.product_id | ||
902 | - WHERE m.id='".$key."' "; | ||
903 | - $result4 = mysql_query($sql4) or die(mysql_error()); | ||
904 | - if (mysql_affected_rows()!=0) { | ||
905 | - $item=mysql_fetch_assoc($result4); | ||
906 | - } | ||
907 | - | ||
908 | - $f=0; | ||
909 | - | ||
910 | - if (isset($_SESSION['shopcart'])) { | ||
911 | - | ||
912 | - foreach ($_SESSION['shopcart'] as $i => $cart) { | ||
913 | - | ||
914 | - | ||
915 | - if ($cart['code']!='' && $cart['code']==$key) { | ||
916 | - $f=1; | ||
917 | - $_SESSION['shopcart'][$i]['count']=$value; | ||
918 | - $_SESSION['shopcart'][$i]['total']=$value*$_SESSION['shopcart'][$i]['price']; | ||
919 | - if ($_SESSION['shopcart'][$i]['total']==0) { | ||
920 | - unset($_SESSION['shopcart'][$i]); | ||
921 | - } | ||
922 | - break; | ||
923 | - } | ||
924 | - } | ||
925 | - } | ||
926 | - } | ||
927 | - | ||
928 | - // ========== ZLODEYEV ============ | ||
929 | - | ||
930 | - | ||
931 | - $session_basket = array(); | ||
932 | - foreach($proructs_count as $key=>$value){ | ||
933 | - for($i=0;$i<$value;$i++){ | ||
934 | - $session_basket[] = $key; | ||
935 | - } | ||
936 | - } | ||
937 | - } | ||
938 | - | ||
939 | - function sendOrder($data){ | ||
940 | - $mail = new PHPMailer(); | ||
941 | - $mail->CharSet = "windows-1251"; | ||
942 | - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
943 | - $mail->FromName = $data['order_name']; | ||
944 | - $mail->AddAddress("shop@eltrade.com.ua","shop"); | ||
945 | - $mail->Subject = "Îôîðìèòü çàêàç ñ ÝêñòðèìÑòèëü"; | ||
946 | - $title = Mail::str_rus("Îôîðìèòü çàêàç"); | ||
947 | - $msg = ""; | ||
948 | - foreach($data['product_id'] as $key=>$value){ | ||
949 | - $msg .= "ID: ".$value." "; | ||
950 | - $msg .= "Íàçâàíèå: <b>".$data['product_name'][$key]."</b> "; | ||
951 | - $msg .= "Öåíà çà îäèí: ".$data['product_cine'][$key]." "; | ||
952 | - $msg .= "Êîëè÷åñòâî: ".$data['product_count'][$key]." "; | ||
953 | - $msg .= "Çà âåñü òîâàð: ".$data['product_cine_all'][$key]." "; | ||
954 | - $msg .= "<br>"; | ||
955 | - } | ||
956 | - $msg .= "Îáùàÿ ñóìà: ".$data['cineAll']; | ||
957 | - $msg .= "<br>"; | ||
958 | - /* $msg .= "Ñêèäêà: ".$data['discount']." %"; | ||
959 | - $msg .= "<br>"; */ | ||
960 | - $msg .= "Èòîãî ê îïëàòå: ".$data['cineAll_discount']; | ||
961 | - $msg .= "<br><br><br>"; | ||
962 | - $msg .= "Êîíòàêòíûå äàííûå:"; | ||
963 | - $msg .= "<br>"; | ||
964 | - $msg .= "Èìÿ: ".$data['order_name']; | ||
965 | - $msg .= "<br>"; | ||
966 | - $msg .= "Àäðåñ: ".$data['order_adress']; | ||
967 | - $msg .= "<br>"; | ||
968 | - $msg .= "E-mail: ".$data['order_email']; | ||
969 | - $msg .= "<br>"; | ||
970 | - $msg .= "Êîíòàêòíûé òåëåôîí: ".$data['order_phone']; | ||
971 | -// $msg .= "<br>"; | ||
972 | -// $msg .= "Ìîáèëüíûé òåëåôîí: ".$data['order_phonemob']; | ||
973 | - $msg .= "<br>"; | ||
974 | - $msg .= "Êîììåíòàðèé: ".$data['order_comment']; | ||
975 | -// $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua"; | ||
976 | -// Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg)); | ||
977 | - $mail->MsgHTML($msg); | ||
978 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
979 | - $mail->ClearAddresses(); | ||
980 | - $mail->ClearAttachments(); | ||
981 | - | ||
982 | - $this->sendOrderXML($data); | ||
983 | - } | ||
984 | - | ||
985 | - | ||
986 | - function sendOrderXML($data){ | ||
987 | - | ||
988 | - | ||
989 | - | ||
990 | -$data['order_phone'] = str_replace("-","",$data['order_phone']); | ||
991 | -$data['order_phone'] = str_replace(")","",$data['order_phone']); | ||
992 | -$data['order_phone'] = str_replace("(","",$data['order_phone']); | ||
993 | -$data['order_phone'] = str_replace(" ","",$data['order_phone']); | ||
994 | -$data['order_phone'] = "+38".$data['order_phone']; | ||
995 | - | ||
996 | - | ||
997 | - | ||
998 | - $mail = new PHPMailer(); | ||
999 | - $mail->CharSet = "windows-1251"; | ||
1000 | - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
1001 | - $mail->FromName = $data['order_name']; | ||
1002 | - $mail->AddAddress("extremshop@portal.myoffice.biz.ua","extremshop"); | ||
1003 | - $mail->Subject = "xml çàêàç ñ ÝêñòðèìÑòèëü"; | ||
1004 | - $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
1005 | - $xml = '<?xml version="1.0" encoding="windows-1251" ?>'; | ||
1006 | - $xml .= '<Order orderNum="'.mktime().'">'; | ||
1007 | - foreach($data['product_id'] as $key=>$value){ | ||
1008 | - $xml .= "<OrderItem ID='".$data['product_code'][$key]."'>"; | ||
1009 | - $xml .= "<ProductName>".$data['product_name2'][$key]."</ProductName>"; | ||
1010 | - $xml .= "<Size>".$data['product_size'][$key]."</Size>"; | ||
1011 | - $xml .= "<Color>".$data['product_color'][$key]."</Color>"; | ||
1012 | - $xml .= "<Price>".$data['product_price'][$key]."</Price>"; | ||
1013 | - $xml .= "<Count>".$data['product_count'][$key]."</Count>"; | ||
1014 | - $xml .= "</OrderItem>"; | ||
1015 | - } | ||
1016 | - $xml .= '<CustomerInfo>'; | ||
1017 | - $xml .= '<Name>'.$data['order_name'].'</Name>'; | ||
1018 | - $xml .= '<Mobile>'.$data['order_phone'].'</Mobile>'; | ||
1019 | - $xml .= '<Email>'.$data['order_email'].'</Email>'; | ||
1020 | - $xml .= '</CustomerInfo>'; | ||
1021 | - $xml .= '<DeliveryInfo>'; | ||
1022 | - $xml .= '<City>Óêðàèíà</City>'; | ||
1023 | - $xml .= '<Address>'.$data['order_adress'].'</Address>'; | ||
1024 | - $xml .= '<DeliveryType>Äîñòàâêà</DeliveryType>'; | ||
1025 | - $xml .= '</DeliveryInfo>'; | ||
1026 | - $xml .= '<Comment>'.$data['order_comment'].'</Comment>'; | ||
1027 | - $xml .= '</Order>'; | ||
1028 | - $tmpfname = tempnam("tmp", "FOO"); | ||
1029 | - $handle = fopen($tmpfname, "w"); | ||
1030 | - fwrite($handle, $xml); | ||
1031 | - $mail->AddAttachment($tmpfname, 'order.xml'); | ||
1032 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
1033 | - fclose($handle); | ||
1034 | - unlink($tmpfname); | ||
1035 | - $mail->ClearAddresses(); | ||
1036 | - $mail->ClearAttachments(); | ||
1037 | - // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml)); | ||
1038 | - // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml)); | ||
1039 | - } | ||
1040 | - | ||
1041 | - function saveOrder($data,$userID = 0){ | ||
1042 | - | ||
1043 | - $table_name = "catalogs_orders"; | ||
1044 | - | ||
1045 | - if(isset($data['update_id']) && $data['update_id']>0){ | ||
1046 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
1047 | - $id = $data['update_id']; | ||
1048 | - $where = sprintf("id='%d'",$id); | ||
1049 | - } else { | ||
1050 | - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; | ||
1051 | - $id = $this->db->nextId('mySequence_'.$table_name); | ||
1052 | - $where = null; | ||
1053 | - } | ||
1054 | - | ||
1055 | - | ||
1056 | - | ||
1057 | - | ||
1058 | - $fields_values = array( | ||
1059 | - 'id'=>$id, | ||
1060 | - 'user_id'=>$userID, | ||
1061 | - 'name' => $data['order_name'], | ||
1062 | - 'email' => $data['order_email'], | ||
1063 | - 'adress' => $data['order_adress'], | ||
1064 | - //'phone' => phone_mobil($data['order_phone']), | ||
1065 | - 'phone' => $data['order_phone'], | ||
1066 | - 'comment' => $data['order_comment'], | ||
1067 | - 'delivery' => $data['delivery'], | ||
1068 | - 'total'=>$_SESSION['cart']['total'], | ||
1069 | - 'status' => '1', | ||
1070 | - 'mktime'=>mktime() | ||
1071 | - ); | ||
1072 | - $DB_AUTOQUERY; | ||
1073 | - | ||
1074 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where); | ||
1075 | - | ||
1076 | - if(isset($data['product_id'])){ $i=-1; | ||
1077 | - foreach($data['product_id'] as $key=>$value){ $i++; | ||
1078 | - $this->db->autoExecute("catalogs_orders_products",array( | ||
1079 | - 'order_id'=>$id, | ||
1080 | - 'product_id'=>$value, | ||
1081 | - 'product_cine_id'=>$_SESSION['cart'][$i]['price'], | ||
1082 | - 'count'=>$data['product_count'][$key]) | ||
1083 | - ,DB_AUTOQUERY_INSERT); | ||
1084 | - } | ||
1085 | - } | ||
1086 | - | ||
1087 | - | ||
1088 | - } | ||
1089 | - | ||
1090 | - function deleteOrder($id){ | ||
1091 | - $this->db->query("delete from catalogs_orders where id=?",array($id)); | ||
1092 | - $this->db->query("delete from catalogs_orders_products where order_id=?",array($id)); | ||
1093 | - } | ||
1094 | - | ||
1095 | - function updateOrder($data){ | ||
1096 | - $table_name = "catalogs_orders"; | ||
1097 | - $fields_values = array('name' => $data['order_name'],'email' => $data['order_email'],'adress' => $data['order_adress'],'phone' => $data['order_phone'],'comment' => $data['order_comment'],'mktime'=>mktime()); | ||
1098 | - if(isset($data['order_active']))$fields_values['active'] = 1; | ||
1099 | - else $fields_values['active'] = 0; | ||
1100 | - $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,sprintf("id='%d'",$data['update_id'])); | ||
1101 | - } | ||
1102 | - | ||
1103 | - function updateOrderProducts($data){ | ||
1104 | - foreach($data['product_id'] as $key=>$value){ | ||
1105 | - if($data['product_count'][$value]<1){$this->db->query("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");} | ||
1106 | - else{$this->db->autoExecute("catalogs_orders_products",array('count'=>$data['product_count'][$value]),DB_AUTOQUERY_UPDATE,"order_id='{$data['order_id']}' AND product_id='$value'");} | ||
1107 | - } | ||
1108 | - } | ||
1109 | - | ||
1110 | - function viewOrder($id){ | ||
1111 | - $row = $this->db->getRow("select * from catalogs_orders where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
1112 | - $this->tpl->assign('order', $row); | ||
1113 | - } | ||
1114 | - | ||
1115 | - function viewOrderProducts($order_id){ | ||
1116 | - $res = $this->db->getAll("select p.*,op.*,pr.name,pr.pic,pr.pic_big from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id Left join catalogs_products pr On pr.id=p.product_id where order_id=?",array($order_id),DB_FETCHMODE_ASSOC); | ||
1117 | - $sum = 0; | ||
1118 | - foreach($res as $key=>$row){ | ||
1119 | - $sum = $sum + ($row['cine']*$row['count']); | ||
1120 | - $res[$key]['cine_all'] = ($row['cine']*$row['count']); | ||
1121 | - } | ||
1122 | - $discount = $this->db->getOne('select catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id where catalogs_orders.id=?',array($order_id)); | ||
1123 | - $this->tpl->assign('cine', array('sum'=>$sum,'discount'=>$discount,'sum_discount'=>($sum - (($sum*$discount)/100)) )); | ||
1124 | - $this->tpl->assign('basket_products', $res); | ||
1125 | - } | ||
1126 | - | ||
1127 | - function viewOrders($params = array()){ | ||
1128 | - $search = array(); | ||
1129 | - if(isset($params['userID']) && $params['userID']>0)$search[] = sprintf("catalogs_orders.user_id='%d'",$params['userID']); | ||
1130 | - $sql = "select catalogs_orders.*,catalogs_users.login as user_login,catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id WHERE 1=1 "; | ||
1131 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
1132 | - $sql .= " order by mktime desc"; | ||
1133 | - $pagerOptions = Array( | ||
1134 | - 'mode' => 'Sliding', | ||
1135 | - 'delta' => 16, | ||
1136 | - 'perPage' => 50, | ||
1137 | - 'linkClass'=>"link_class", | ||
1138 | - 'curPageLinkClassName'=>"link_class_active", | ||
1139 | - 'spacesBeforeSeparator' => 1, | ||
1140 | - 'spacesAfterSeparator' => 1 | ||
1141 | - ); | ||
1142 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
1143 | - foreach($res['data'] as $key=>$value){ | ||
1144 | - $res['data'][$key]['sum'] = $this->getOrderProductsSum($value['id']); | ||
1145 | - $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum']*$value['discount'])/100); | ||
1146 | - } | ||
1147 | - $this->tpl->assign('ordersData', $res); | ||
1148 | - } | ||
1149 | - | ||
1150 | - function getOrderProductsSum($order_id){ | ||
1151 | - $res = $this->db->getAll("select op.*,p.cine from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id where op.order_id=?",array($order_id),DB_FETCHMODE_ASSOC); | ||
1152 | - // print_r($res); | ||
1153 | - $sum = 0; | ||
1154 | - foreach($res as $row){ | ||
1155 | - $sum = $sum + ($row['cine']*$row['count']); | ||
1156 | - } | ||
1157 | - return $sum; | ||
1158 | - } | ||
1159 | - | ||
1160 | - function SaveBrend($data,$upload){ | ||
1161 | - $table_name = "catalogs_brends"; | ||
1162 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
1163 | - $fields_values = array('rubric_id'=>$data['rubric_id'],'name'=>$data['brend'],'text'=>$data['text'],'youtube'=>$data['youtube'],'seo'=>$data['seo'],'sort'=>$data['sort'],'meta_title'=>$data['meta_title'],'meta_description'=>$data['meta_description'],'meta_keywords'=>$data['meta_keywords'],'active'=>$data['active'] ,'about'=>$data['about'],'link'=>$data['link'],'teh'=>$data['teh']); | ||
1164 | - | ||
1165 | - if(isset($data['delete_video']) && $data['delete_video']==1){ | ||
1166 | - $this->deleteBrendPic($data['update_id']); | ||
1167 | - $fields_values['pic'] = null; | ||
1168 | - } | ||
1169 | - if($upload['pic']['tmp_name']){ | ||
1170 | - if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic')); | ||
1171 | - $name_pic = mktime() . "." . substr(strrchr($_FILES['pic']['name'],"."),1); | ||
1172 | - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic"; | ||
1173 | - move_uploaded_file($_FILES["pic"]["tmp_name"], $file_name); | ||
1174 | - chmod($file_name,"0777"); | ||
1175 | - $fields_values['pic'] = $name_pic; | ||
1176 | - } | ||
1177 | - | ||
1178 | - if(isset($data['delete_pic_s']) && $data['delete_pic_s']==1){ | ||
1179 | - $this->deleteBrendPic($data['update_id'],array('pic_s')); | ||
1180 | - $fields_values['pic_s'] = null; | ||
1181 | - } | ||
1182 | - if($upload['pic_s']['tmp_name']){ | ||
1183 | - if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic_s')); | ||
1184 | - $name_pic = mktime() . "." . substr(strrchr($_FILES['pic_s']['name'],"."),1); | ||
1185 | - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic"; | ||
1186 | - move_uploaded_file($_FILES["pic_s"]["tmp_name"], $file_name); | ||
1187 | - chmod($file_name,"0777"); | ||
1188 | - $fields_values['pic_s'] = $name_pic; | ||
1189 | - } | ||
1190 | - | ||
1191 | - | ||
1192 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
1193 | - } | ||
1194 | - | ||
1195 | - function deleteBrendPic($id,$pics = array('pic','pic_s')){ | ||
1196 | - $sql = "select " . implode(',',$pics) . " from catalogs_brends where id=?"; | ||
1197 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
1198 | - if(isset($row['pic'])){ | ||
1199 | - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}"; | ||
1200 | - @unlink($file_name); | ||
1201 | - } | ||
1202 | - if(isset($row['pic_s'])){ | ||
1203 | - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}"; | ||
1204 | - @unlink($file_name); | ||
1205 | - } | ||
1206 | - } | ||
1207 | - | ||
1208 | - function viewBrends($type = false){ | ||
1209 | - $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id "; | ||
1210 | - if($type!=false)$sql .= "where b.type='$type'"; | ||
1211 | - $sql .= " Order by b.name Asc"; | ||
1212 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1213 | - $this->tpl->assign('brends',$row); | ||
1214 | - } | ||
1215 | - | ||
1216 | - function viewBrendsGroup($params = array()){ | ||
1217 | - $sql = "select * from catalogs_brends where 1=1 "; | ||
1218 | - if(isset($params['rubID'])){ | ||
1219 | - $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']); | ||
1220 | - $rubric_id = ($rubric_id==0)?$params['rubID']:$rubric_id; | ||
1221 | - $sql .= "and rubric_id='".$rubric_id."'"; | ||
1222 | - } | ||
1223 | - $sql .= " Group by name Order by sort Asc"; | ||
1224 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1225 | - $this->tpl->assign('brends',$row); | ||
1226 | - } | ||
1227 | - | ||
1228 | - function viewBrendsActive(){ | ||
1229 | - $sql = "select * from catalogs_brends where active=1 "; | ||
1230 | - $sql .= " Order by sort Asc"; | ||
1231 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1232 | - $this->tpl->assign('brends_a',$row); | ||
1233 | - } | ||
1234 | - | ||
1235 | - function SaveCity($data){ | ||
1236 | - $table_name = "catalogs_cities"; | ||
1237 | - $DB_AUTOQUERY = (isset($data['update_id']) && $data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
1238 | - $fields_values = array('name'=>$data['name']); | ||
1239 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
1240 | - return mysql_insert_id(); | ||
1241 | - } | ||
1242 | - | ||
1243 | - function is_city($name){ | ||
1244 | - return $this->db->getOne('select id from catalogs_cities where name=?',array($name)); | ||
1245 | - } | ||
1246 | - | ||
1247 | - function viewCityMod($code){ | ||
1248 | - $sql = "select c.name from catalogs_keys_products_cities k left join catalogs_cities c on c.id=k.city_id where k.mod_code=? and k.count>0"; | ||
1249 | - $row = $this->db->getCol($sql,"name",array($code)); | ||
1250 | - if(!count($row))return ""; | ||
1251 | - foreach($row as $key=>$value){if($value=="Èíòåðíåò ìàãàçèí" or $value=="Êèåâ(Îëèìïèéñêèé)")unset($row[$key]);} | ||
1252 | - return implode(', ',$row); | ||
1253 | - } | ||
1254 | - | ||
1255 | - function viewCitiesProductID($id){ | ||
1256 | - $sql = "select city_id from catalogs_keys_products_cities where product_id=?"; | ||
1257 | - $row = $this->db->getCol($sql,"city_id",array($id)); | ||
1258 | - $this->tpl->assign('product_cities',$row); | ||
1259 | - } | ||
1260 | - | ||
1261 | - function viewCities($type = false){ | ||
1262 | - $sql = "select * from catalogs_cities "; | ||
1263 | - $sql .= " Order by name Asc"; | ||
1264 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1265 | - $this->tpl->assign('cities',$row); | ||
1266 | - } | ||
1267 | - | ||
1268 | - function viewCitiesProduct($id){ | ||
1269 | - $sql = "select catalogs_cities.* from catalogs_keys_products_cities left join catalogs_cities on catalogs_cities.id=catalogs_keys_products_cities.city_id Where catalogs_keys_products_cities.product_id=? "; | ||
1270 | - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); | ||
1271 | - $this->tpl->assign('cities',$row); | ||
1272 | - } | ||
1273 | - | ||
1274 | - function viewCity($id){ | ||
1275 | - $row = $this->db->getRow("select * from catalogs_cities where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
1276 | - $this->tpl->assign('city', $row); | ||
1277 | - } | ||
1278 | - | ||
1279 | - function deleteCity($id){ | ||
1280 | - $this->db->query("delete from catalogs_cities where id=?",array($id)); | ||
1281 | - $this->delete_keysCitiesProduct($id); | ||
1282 | - } | ||
1283 | - | ||
1284 | - function delete_keysCitiesProduct($id){ | ||
1285 | - $sql = "delete from catalogs_keys_products_cities where city_id=?"; | ||
1286 | - $this->db->query($sql,array($id)); | ||
1287 | - } | ||
1288 | - | ||
1289 | - function SaveYears($data){ | ||
1290 | - $table_name = "catalogs_years"; | ||
1291 | - foreach($data['filter'] as $key=>$name){ | ||
1292 | - if(strlen($name)>0){ | ||
1293 | - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} | ||
1294 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} | ||
1295 | - $this->db->autoExecute($table_name,array('name'=>$name,'rubric_id'=>$data['rubric_id']),$DB_AUTOQUERY,$where); | ||
1296 | - } | ||
1297 | - } | ||
1298 | - } | ||
1299 | - | ||
1300 | - function viewYearsProductID($id){ | ||
1301 | - $sql = "select year_id from catalogs_keys_products_years where product_id=?"; | ||
1302 | - $row = $this->db->getCol($sql,"year_id",array($id)); | ||
1303 | - $this->tpl->assign('product_years',$row); | ||
1304 | - } | ||
1305 | - | ||
1306 | - function viewYears($rubric_id){ | ||
1307 | - $row = $this->db->getAll("select * from catalogs_years where rubric_id=? order by name",array($rubric_id),DB_FETCHMODE_ASSOC); | ||
1308 | - $this->tpl->assign('years', $row); | ||
1309 | - } | ||
1310 | - | ||
1311 | - function getYearsName_IDs($ids){ | ||
1312 | - //$sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name"; | ||
1313 | - //$row = $this->db->getCol($sql,"name",array()); | ||
1314 | - //return implode(", ",$row); | ||
1315 | - | ||
1316 | - $name = array(); | ||
1317 | - foreach($ids as $id){ | ||
1318 | - $name[] = $this->db->getOne("select name from catalogs_years where id=?",array($id)); | ||
1319 | - } | ||
1320 | - return implode(", ",$name); | ||
1321 | - } | ||
1322 | - | ||
1323 | - function deleteYearsRubric_id($id){ | ||
1324 | - $this->db->query("delete from catalogs_years where rubric_id=?",array($id)); | ||
1325 | - $this->delete_keysYearsRubric($id); | ||
1326 | - } | ||
1327 | - | ||
1328 | - function delete_keysYearsRubric($id){ | ||
1329 | - $sql = "delete from catalogs_keys_products_years where rubric_id=?"; | ||
1330 | - $this->db->query($sql,array($id)); | ||
1331 | - } | ||
1332 | - | ||
1333 | - function deleteYear($id){ | ||
1334 | - $this->db->query("delete from catalogs_years where id=?",array($id)); | ||
1335 | - $this->delete_keysYearsProduct($id); | ||
1336 | - } | ||
1337 | - | ||
1338 | - function delete_keysYearsProduct($id){ | ||
1339 | - $sql = "delete from catalogs_keys_products_years where year_id=?"; | ||
1340 | - $this->db->query($sql,array($id)); | ||
1341 | - } | ||
1342 | - | ||
1343 | - function SaveFilters($data){ | ||
1344 | - $table_name = "catalogs_filters"; | ||
1345 | - foreach($data['filter'] as $key=>$name){ | ||
1346 | - if(strlen($name)>0){ | ||
1347 | - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} | ||
1348 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} | ||
1349 | - $active = (isset($data['active'][$key])) ? 1 : 0; | ||
1350 | - $this->db->autoExecute($table_name,array('name'=>$name,'prefix'=>encodestring($name),'rubric_id'=>$data['rubric_id'],"sort"=>$data['sort'][$key],"active"=>$active),$DB_AUTOQUERY,$where); | ||
1351 | - } | ||
1352 | - } | ||
1353 | - } | ||
1354 | - | ||
1355 | - function viewFilterProductID($id){ | ||
1356 | - $sql = "select filter_id from catalogs_keys_products_filters where product_id=?"; | ||
1357 | - $row = $this->db->getCol($sql,"filter_id",array($id)); | ||
1358 | - $this->tpl->assign('product_filters',$row); | ||
1359 | - } | ||
1360 | - | ||
1361 | - function deleteFilter($id){ | ||
1362 | - $this->db->query("delete from catalogs_filters where id=?",array($id)); | ||
1363 | - $this->delete_keysFilterProduct($id); | ||
1364 | - } | ||
1365 | - | ||
1366 | - function deleteFiltersRubric_id($rubric_id){ | ||
1367 | - $this->db->query("delete from catalogs_filters where rubric_id=?",array($rubric_id)); | ||
1368 | - $this->delete_keysFilterRubric($rubric_id); | ||
1369 | - } | ||
1370 | - | ||
1371 | - function delete_keysFilterProduct($id){ | ||
1372 | - $sql = "delete from catalogs_keys_products_filters where filter_id=?"; | ||
1373 | - $this->db->query($sql,array($id)); | ||
1374 | - } | ||
1375 | - | ||
1376 | - function delete_keysFilterRubric($id){ | ||
1377 | - $sql = "delete from catalogs_keys_products_filters where rubric_id=?"; | ||
1378 | - $this->db->query($sql,array($id)); | ||
1379 | - } | ||
1380 | - | ||
1381 | - function viewFilters($rubric_id){ | ||
1382 | - $row = $this->db->getAll("select * from catalogs_filters where active='0' and rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC); | ||
1383 | - $this->tpl->assign('filters', $row); | ||
1384 | - } | ||
1385 | - | ||
1386 | - function getFiltersName_IDs($ids){ | ||
1387 | - //$sql = "select name from catalogs_filters where id in (".implode(",",$ids).")"; | ||
1388 | - //$row = $this->db->getCol($sql,"name",array()); | ||
1389 | - $name = array(); | ||
1390 | - foreach($ids as $id){ | ||
1391 | - $name[] = $this->db->getOne("select name from catalogs_filters where id=?",array($id)); | ||
1392 | - } | ||
1393 | - return implode(", ",$name); | ||
1394 | - } | ||
1395 | - | ||
1396 | - function viewBrend($id){ | ||
1397 | - $row = $this->db->getRow("select * from catalogs_brends where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
1398 | - $this->tpl->assign('brend', $row); | ||
1399 | - } | ||
1400 | - | ||
1401 | - function viewBrendName($name){ | ||
1402 | - $name = iconv("utf-8", "windows-1251", $name); | ||
1403 | - $sql = "select * from catalogs_brends where name=? and active=1 limit 1"; | ||
1404 | - $row = $this->db->getRow($sql,array($name),DB_FETCHMODE_ASSOC); | ||
1405 | - $this->tpl->assign('brend_seo', $row); | ||
1406 | - return $row; | ||
1407 | - } | ||
1408 | - | ||
1409 | - function getBrendIDs_name($name){ | ||
1410 | - //$name = iconv("utf-8", "windows-1251", $name); | ||
1411 | - $sql = "select id from catalogs_brends where name=?"; | ||
1412 | - return $this->db->getCol($sql,"id",array($name)); | ||
1413 | - } | ||
1414 | - | ||
1415 | - function deleteBrend($id){ | ||
1416 | - $this->db->query("delete from catalogs_brends where id=?",array($id)); | ||
1417 | - } | ||
1418 | - | ||
1419 | - function viewAkciiProductID($id){ | ||
1420 | - $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?"; | ||
1421 | - $row = $this->db->getCol($sql,"rubric_id",array($id)); | ||
1422 | - $this->tpl->assign('product_akcii',$row); | ||
1423 | - } | ||
1424 | - | ||
1425 | - function import_saveRubric($name,$parent_id){ | ||
1426 | - $id = $this->db->getOne("select id from catalogs_rubrics where name=? and parent_id=?",array($name,$parent_id)); | ||
1427 | - if( !$id ){ | ||
1428 | - $this->db->autoExecute("catalogs_rubrics",array('name'=>$name,'parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1)),DB_AUTOQUERY_INSERT); | ||
1429 | - return mysql_insert_id(); | ||
1430 | - } | ||
1431 | - return $id; | ||
1432 | - } | ||
1433 | - | ||
1434 | - function import_saveBrend($name,$rubric_id){ | ||
1435 | - //getRubricParent(); | ||
1436 | - $id = $this->db->getOne("select id from catalogs_brends where name=? and rubric_id=?",array($name,$rubric_id)); | ||
1437 | - if( !$id ){ | ||
1438 | - $this->db->autoExecute("catalogs_brends",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); | ||
1439 | - return mysql_insert_id(); | ||
1440 | - } | ||
1441 | - return $id; | ||
1442 | - } | ||
1443 | - | ||
1444 | - function import_saveFilters($rubric_id,$str){ | ||
1445 | - if(!$str)return array(); | ||
1446 | - $row_str = explode(",",trim($str)); | ||
1447 | - $arr_id = array(); | ||
1448 | - foreach($row_str as $str){ | ||
1449 | - $name = trim($str); | ||
1450 | - $name_r = explode('=',$name);$name = $name_r[0]; $active = (isset($name_r[1])) ? 1 : 0; | ||
1451 | - $id = $this->db->getOne("select id from catalogs_filters where rubric_id=? and name=?",array($rubric_id,$name)); | ||
1452 | - if( !$id ){ | ||
1453 | - $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_INSERT); | ||
1454 | - $id = mysql_insert_id(); | ||
1455 | - }else{ $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_UPDATE,"id=$id");} | ||
1456 | - $arr_id[] = $id; | ||
1457 | - } | ||
1458 | - return $arr_id; | ||
1459 | - } | ||
1460 | - | ||
1461 | - function import_saveYear($rubric_id,$name){ | ||
1462 | - $id = $this->db->getOne("select id from catalogs_years where rubric_id=? and name=?",array($rubric_id,$name)); | ||
1463 | - if( !$id ){ | ||
1464 | - $this->db->autoExecute("catalogs_years",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); | ||
1465 | - $id = mysql_insert_id(); | ||
1466 | - } | ||
1467 | - return ($id)?array($id):array(); | ||
1468 | - } | ||
1469 | - | ||
1470 | - function import_updateProductCine($product_id,$row,$line='',$mktime = 0){ // print"<pre>";print_r($row);print"</pre>"; | ||
1471 | - | ||
1472 | - IF($product_id>0){ | ||
1473 | - IF($row[3]>0){ | ||
1474 | - if($row[2]<1){$cine=$row[1];$cine_last=0;} | ||
1475 | - else {$cine=$row[2];$cine_last=(($row[1]>0)?$row[1]:$row[2]);} | ||
1476 | - $this->db->autoExecute("catalogs_products",array('cine'=>$cine,'cine_last'=>$cine_last),DB_AUTOQUERY_UPDATE,"id='$product_id'"); | ||
1477 | - } | ||
1478 | - | ||
1479 | - | ||
1480 | - $city = trim($row[4]); | ||
1481 | - if(!$city)$city = "Èíòåðíåò ìàãàçèí"; | ||
1482 | - //echo "OK(1) - <br/>"; | ||
1483 | - if(strlen($city)>0){ //print $city; | ||
1484 | - $city_id = $this->is_city($city); | ||
1485 | - //echo "OK(2) - <br/>"; | ||
1486 | - if(!$city_id){$city_id = $this->SaveCity(array('name'=>$city));} | ||
1487 | - $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array($product_id,$row[0],$mktime)); | ||
1488 | - | ||
1489 | - if($row[3]==0){ | ||
1490 | - | ||
1491 | - } | ||
1492 | - else{ | ||
1493 | - // $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array($product_id,$row[0],$mktime)); | ||
1494 | - //echo "OK(3) - <br/>"; | ||
1495 | - if($this->getKeysModificationCity($row[0], $city_id)){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "mod_code='".$row[0]."' and city_id='".$city_id."'";} | ||
1496 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;} | ||
1497 | - | ||
1498 | - // if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;} | ||
1499 | - //print $city_id .'--'.$where."<br>"; | ||
1500 | - $fields = array('count'=>$row[3],'product_id'=>$product_id,'mod_code'=>$row[0],'city_id'=>$city_id,'mktime'=>$mktime); | ||
1501 | - $s = $this->db->autoExecute("catalogs_keys_products_cities",$fields,$DB_AUTOQUERY,$where); | ||
1502 | - if (PEAR::isError($s)) die($s->getMessage()); | ||
1503 | - }} | ||
1504 | - //echo "OK(4) - <br/>"; | ||
1505 | - $active = $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0",array($row[0])); | ||
1506 | - //$active = true; | ||
1507 | - if($this->db->getOne("select count(*) from catalogs_modifications where code=?",array($row[0]))>0){ | ||
1508 | - $this->db->autoExecute("catalogs_modifications",array('active'=>$active,'is_update'=>1,'prefix'=>$row[4]),DB_AUTOQUERY_UPDATE,"code='".$row[0]."'"); | ||
1509 | - //echo "OK(5) - <br/>"; | ||
1510 | - }else{ | ||
1511 | - //echo "OK(6) - <br/>"; | ||
1512 | - $this->saveCsvMod($line); | ||
1513 | - } | ||
1514 | - } | ||
1515 | - } | ||
1516 | - | ||
1517 | - function saveCsvMod($line){ | ||
1518 | - echo "OK1 - <br/>"; | ||
1519 | - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv"; | ||
1520 | - $handle = @fopen($tmpfname, "a"); | ||
1521 | -// $row = explode(";",$line); | ||
1522 | -// File_FGetCSV::fputcsv($handle,$row,';'); | ||
1523 | - echo "OK2 - <br/>"; | ||
1524 | - echo $line; | ||
1525 | - echo "OK3 - <br/>"; | ||
1526 | - fwrite($handle,$line); | ||
1527 | - fclose($handle); | ||
1528 | - } | ||
1529 | - | ||
1530 | - function getKeysModificationCity($code, $city_id){ | ||
1531 | - return $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id)); | ||
1532 | - } | ||
1533 | - | ||
1534 | - function getKeysModificationCity_count($code, $city_id){ | ||
1535 | - return $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id)); | ||
1536 | - } | ||
1537 | - | ||
1538 | - function getKeysModificationCityMktime_count($code, $city_id, $mktime){ | ||
1539 | - $r = $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array($code, $city_id, $mktime)); | ||
1540 | - return $r; | ||
1541 | - } | ||
1542 | - | ||
1543 | - function getProductID($name){ | ||
1544 | - $id = $this->db->getOne("select id from catalogs_products where name=?",array($name)); | ||
1545 | - return $id; | ||
1546 | - } | ||
1547 | - | ||
1548 | - function getProductID_R($name,$rubric_parent_id){ | ||
1549 | - $id = $this->db->getOne("select id from catalogs_products where name=? and rubric_id=?",array($name,$rubric_parent_id)); | ||
1550 | - return $id; | ||
1551 | - } | ||
1552 | - | ||
1553 | - function getModificationActive($code){ | ||
1554 | - return $this->db->getOne("select active from catalogs_modifications where code=?",array($code)); | ||
1555 | - } | ||
1556 | - | ||
1557 | - function updateProduct_countModification($product_id,$count){ | ||
1558 | - $this->db->autoExecute("catalogs_products",array('count_modifications'=>$count),DB_AUTOQUERY_UPDATE,"id='$product_id'"); | ||
1559 | - } | ||
1560 | - | ||
1561 | - function updateProductModificationCountPrefix($product_id,$prefix = "+"){ | ||
1562 | -// print $product_id; | ||
1563 | - $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?"; | ||
1564 | - $this->db->query($sql,array($product_id)); | ||
1565 | - } | ||
1566 | - | ||
1567 | - function exportCSV(){ | ||
1568 | - $tmpfname = "tmp/price.csv"; | ||
1569 | - $handle = fopen($tmpfname, "w"); | ||
1570 | - // fwrite($handle, $xml); | ||
1571 | - $res = $this->db->getAll('select p.id,p.rubric_id,r2.name,r.name,b.name as brend,p.name,p.about,p.text,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big from catalogs_products p left join catalogs_rubrics r on r.id=p.rubric_id left join catalogs_rubrics r2 on r2.id=p.rubric_parent_id left join catalogs_brends b on b.id=p.brend_id',array()); | ||
1572 | - foreach($res as $key=>$row){ | ||
1573 | - $list = $row; | ||
1574 | - $mod_res = $this->db->getAll('select code,size,color,pic_big,active from catalogs_modifications where product_id=?',array($row[0])); | ||
1575 | - foreach($mod_res as $mod_row){$list[] = implode('=',$mod_row);} | ||
1576 | - | ||
1577 | - $f_row = $this->db->getCol("select f.name from catalogs_keys_products_filters k Left Join catalogs_filters f ON f.id=k.filter_id where k.product_id=?",'name',array($list[0])); | ||
1578 | - $list[8]=implode(',',$f_row); | ||
1579 | - | ||
1580 | - switch($list[9]){ | ||
1581 | - case 1 : $list[9] = 'ìóæñêîé'; break; | ||
1582 | - case 2 : $list[9] = 'æåíñêèé'; break; | ||
1583 | - case 3 : $list[9] = 'äåòñêèé'; break; | ||
1584 | - case 4 : $list[9] = 'óíèñåêñ'; break; | ||
1585 | - default : $list[9] = 'ìóæñêîé'; break; | ||
1586 | - } | ||
1587 | - | ||
1588 | - $y_row = $this->db->getCol("select y.name from catalogs_keys_products_years k Left Join catalogs_years y ON y.id=k.year_id where k.product_id=?",'name',array($list[0])); | ||
1589 | - $list[10]=implode(',',$y_row); | ||
1590 | - | ||
1591 | - | ||
1592 | - //print_r($list);exit; | ||
1593 | - $p_res = $this->db->getAll("select name,size,metka from catalogs_products_params where product_id=?",array($list[0])); | ||
1594 | - $param = array(); | ||
1595 | - foreach($p_res as $row_p){ | ||
1596 | - $param[] = implode('*',$row_p); | ||
1597 | - } | ||
1598 | - $list[15] = implode('=',$param); | ||
1599 | - | ||
1600 | - unset($list[0]);unset($list[1]); | ||
1601 | - | ||
1602 | - File_FGetCSV::fputcsv($handle,$list,';'); | ||
1603 | - | ||
1604 | - | ||
1605 | - | ||
1606 | - } | ||
1607 | - | ||
1608 | - fclose($handle); | ||
1609 | - | ||
1610 | - $params = array( | ||
1611 | - 'file' => $tmpfname, | ||
1612 | - 'contenttype' => 'application/xls', | ||
1613 | - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'), | ||
1614 | - 'cache' => false | ||
1615 | - ); | ||
1616 | - $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë | ||
1617 | - if ($error === true) { | ||
1618 | - //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè | ||
1619 | - } | ||
1620 | - | ||
1621 | - unlink($tmpfname); | ||
1622 | - } | ||
1623 | - | ||
1624 | - function exportModCSV(){ | ||
1625 | - $tmpfname = "tmp/price_mod.csv"; | ||
1626 | - $handle = fopen($tmpfname, "w"); | ||
1627 | - $res = $this->db->getAll('select m.code,p.cine,p.cine_last,m.active,null,m.prefix,m.is_update From catalogs_modifications m Left join catalogs_products p on p.id=m.product_id'); | ||
1628 | - foreach($res as $key=>$row){ | ||
1629 | - File_FGetCSV::fputcsv($handle,$row,';'); | ||
1630 | - } | ||
1631 | - fclose($handle); | ||
1632 | - $params = array( | ||
1633 | - 'file' => $tmpfname, | ||
1634 | - 'contenttype' => 'application/xls', | ||
1635 | - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'file_1.csv'), | ||
1636 | - 'cache' => false | ||
1637 | - ); | ||
1638 | - $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë | ||
1639 | - if ($error === true) { | ||
1640 | - //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè | ||
1641 | - } | ||
1642 | - | ||
1643 | - unlink($tmpfname); | ||
1644 | - $this->db->autoExecute("catalogs_modifications",array('is_update'=>0),DB_AUTOQUERY_UPDATE); | ||
1645 | - } | ||
1646 | - | ||
1647 | - function exportOrdersCSV(){ | ||
1648 | - $tmpfname = "tmp/orders.csv"; | ||
1649 | - $handle = fopen($tmpfname, "w"); | ||
1650 | - $res = $this->db->getAll('select name,email,adress,phone From catalogs_orders order by id desc'); | ||
1651 | - foreach($res as $key=>$row){ | ||
1652 | - File_FGetCSV::fputcsv($handle,$row,';'); | ||
1653 | - } | ||
1654 | - fclose($handle); | ||
1655 | - $params = array( | ||
1656 | - 'file' => $tmpfname, | ||
1657 | - 'contenttype' => 'application/xls', | ||
1658 | - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'orders.csv'), | ||
1659 | - 'cache' => false | ||
1660 | - ); | ||
1661 | - $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë | ||
1662 | - if ($error === true) { | ||
1663 | - //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè | ||
1664 | - } | ||
1665 | - | ||
1666 | - unlink($tmpfname); | ||
1667 | - } | ||
1668 | - | ||
1669 | - function deleteProductParams($product_id){ | ||
1670 | - $sql = "delete from catalogs_products_params where product_id=?"; | ||
1671 | - $this->db->query($sql,array($product_id)); | ||
1672 | - } | ||
1673 | - | ||
1674 | - function saveProductParams($product_id,$pruduct_params){ | ||
1675 | - $this->deleteProductParams($product_id); | ||
1676 | - $array_params = explode("=",$pruduct_params); | ||
1677 | - foreach($array_params as $row){ | ||
1678 | - $arr = explode('*',$row); | ||
1679 | - $this->db->autoExecute("catalogs_products_params",array('product_id'=>$product_id,'name'=>$arr[0],'size'=>$arr[1],'metka'=>$arr[2]),DB_AUTOQUERY_INSERT); | ||
1680 | - } | ||
1681 | - } | ||
1682 | - | ||
1683 | - function getProductParams($product_id){ | ||
1684 | - $sql = "select * from catalogs_products_params where product_id=? order by id"; | ||
1685 | - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
1686 | - return $row; | ||
1687 | - } | ||
1688 | - | ||
1689 | - function viewProductParams($product_id){ | ||
1690 | - $this->tpl->assign('params',$this->getProductParams($product_id)); | ||
1691 | - } | ||
1692 | - | ||
1693 | - function saveTmpProduct($row,$product_id){ | ||
1694 | - if($product_id>0){ | ||
1695 | - $this->db->autoExecute("catalogs_tmp_products",array('name'=>$row[3],'product_id'=>$product_id),DB_AUTOQUERY_INSERT); | ||
1696 | - } | ||
1697 | - } | ||
1698 | - | ||
1699 | - function clearTmpProduct(){ | ||
1700 | - $sql = "TRUNCATE TABLE catalogs_tmp_products"; | ||
1701 | - $this->db->query($sql,array()); | ||
1702 | - } | ||
1703 | - | ||
1704 | - function viewTmpProducts(){ | ||
1705 | - $sql = "SELECT count( name ) AS cn, name | ||
1706 | -FROM catalogs_tmp_products | ||
1707 | -GROUP BY name | ||
1708 | -ORDER BY name"; | ||
1709 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1710 | - $this->tpl->assign('list',$row); | ||
1711 | - $this->tpl->assign('list_total',$this->db->getOne("select count(*) from catalogs_tmp_products")); | ||
1712 | - } | ||
1713 | - | ||
1714 | - function importCSV($upload){ error_reporting(0); | ||
1715 | - if($upload['file']['name']=="file_1.csv"){print"Îøèáêà! Ôàéë öåí!";exit;} | ||
1716 | - //$arr_line = file($upload['file']['tmp_name']); | ||
1717 | - $f = fopen($upload['file']['tmp_name'], "r") or die("Îøèáêà!"); | ||
1718 | - // print"<pre>"; | ||
1719 | - $this->clearTmpProduct(); | ||
1720 | - for ($i=0; $row_line=File_FGetCSV::fgetcsv($f,15000000,";"); $i++) { | ||
1721 | - // foreach($arr_line as $line){ | ||
1722 | - //$row_line = fgetcsv(";",$line); | ||
1723 | - $rubric_id = $this->import_saveRubric($row_line[0],0); | ||
1724 | - $rubric_parent_id = $this->import_saveRubric($row_line[1],$rubric_id); | ||
1725 | - $brend_id = $this->import_saveBrend($row_line[2],$rubric_parent_id); | ||
1726 | - $pruduct_name = trim($row_line[3]); | ||
1727 | - $pruduct_about = trim($row_line[4]); | ||
1728 | - $pruduct_text = trim($row_line[5]); | ||
1729 | - switch($row_line[7]){ | ||
1730 | - case 'ìóæñêîé' : $pruduct_sex = 1; break; | ||
1731 | - case 'æåíñêèé' : $pruduct_sex = 2; break; | ||
1732 | - case 'äåòñêèé' : $pruduct_sex = 3; break; | ||
1733 | - case 'óíèñåêñ' : $pruduct_sex = 4; break; | ||
1734 | - default : $pruduct_sex = 0; break; | ||
1735 | - } | ||
1736 | - $pruduct_date = trim($row_line[8]); | ||
1737 | - $pruduct_cine = trim($row_line[9]); | ||
1738 | - $pruduct_cine_last = trim($row_line[10]); | ||
1739 | - if($pruduct_cine<1){$pruduct_cine=$pruduct_cine_last;$pruduct_cine_last=0;} | ||
1740 | - $pruduct_akcii_id = trim($row_line[11]); | ||
1741 | - $pruduct_strnumber = trim($row_line[12]); | ||
1742 | - $pruduct_active = trim($row_line[13]); | ||
1743 | - $pruduct_params = trim($row_line[14]); | ||
1744 | - $pruduct_pic_tmp = trim($row_line[16]); | ||
1745 | - $pruduct_video = trim($row_line[15]); | ||
1746 | - $pruduct_update_id = $this->getProductID_R($pruduct_name,$rubric_parent_id); | ||
1747 | - $upload_pruduct = (strlen($pruduct_pic_tmp)>0 && is_file("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp"))?array('pic'=>array('tmp_name'=>"./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",'name'=>$pruduct_pic_tmp,'big'=>true)):null; | ||
1748 | - $product_id = $this->saveProduct( | ||
1749 | - array('rubric_id'=>$rubric_parent_id, | ||
1750 | - 'rubric_parent_id'=>$rubric_parent_id, | ||
1751 | - 'brend_id'=>$brend_id, | ||
1752 | - 'name'=>$pruduct_name, | ||
1753 | - 'about'=>$pruduct_about, | ||
1754 | - 'text'=>$pruduct_text, | ||
1755 | - 'video_code'=>$pruduct_video, | ||
1756 | - 'sex'=>$pruduct_sex, | ||
1757 | - 'date'=>$pruduct_date, | ||
1758 | - 'cine'=>$pruduct_cine, | ||
1759 | - 'cine_last'=>$pruduct_cine_last, | ||
1760 | - 'akcii_id'=>$pruduct_akcii_id, | ||
1761 | - 'strnumber'=>$pruduct_strnumber, | ||
1762 | - 'active'=>$pruduct_active, | ||
1763 | - 'meta_title'=>$pruduct_name, | ||
1764 | - 'meta_description'=>$pruduct_name, | ||
1765 | - 'meta_keywords'=>$pruduct_name, | ||
1766 | - 'meta_about'=>$pruduct_name, | ||
1767 | - 'filter'=>$this->import_saveFilters($rubric_parent_id,$row_line[6]), | ||
1768 | - 'years'=>$this->import_saveYear($rubric_parent_id,$pruduct_date), | ||
1769 | - 'akcii'=>array(), | ||
1770 | - 'update_id'=>$pruduct_update_id), | ||
1771 | - $upload_pruduct | ||
1772 | - ); | ||
1773 | - //print $pruduct_update_id;exit; | ||
1774 | - $this->saveProductParams($product_id,$pruduct_params); | ||
1775 | - $this->deleteProductModifications($product_id,true); | ||
1776 | - $m_i = 0; | ||
1777 | - for($i=17;$i<count($row_line);$i++){ | ||
1778 | - $arr_mod = trim($row_line[$i]); | ||
1779 | - if(strlen($arr_mod)>0){ | ||
1780 | - $row_mod = explode("=",$arr_mod); | ||
1781 | - $upload_mod = (strlen($row_mod[3])>0 && is_file("./uploaded/pic/catalogs/modifications/big/".$row_mod[3]))?array('pic'=>array('tmp_name'=>"./uploaded/pic/catalogs/modifications/big/".$row_mod[3],'name'=>$row_mod[3],'big'=>true)):null; | ||
1782 | - | ||
1783 | - $this->SaveModification( | ||
1784 | - array('product_id'=>$product_id, | ||
1785 | - 'code'=>$row_mod[0], | ||
1786 | - 'size'=>$row_mod[1], | ||
1787 | - 'color'=>$row_mod[2], | ||
1788 | - 'active'=>$row_mod[4] | ||
1789 | - ),$upload_mod | ||
1790 | - ); | ||
1791 | - if($row_mod[4]>0)$m_i++; | ||
1792 | - } | ||
1793 | - } | ||
1794 | - $this->updateProduct_countModification($product_id,$m_i); | ||
1795 | - //$this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]); | ||
1796 | - //$strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data); | ||
1797 | - //print_r($row_line); | ||
1798 | - $this->saveTmpProduct($row_line,$product_id); | ||
1799 | - if(($i%30)==0)sleep(1); | ||
1800 | - } | ||
1801 | - // print"</pre>"; | ||
1802 | - | ||
1803 | - } | ||
1804 | - | ||
1805 | - function importCSV_cine($upload){ | ||
1806 | - if($upload['file']['name']!="file_1.csv"){print"Îøèáêà! Òîëüêî file_1.csv";exit;} | ||
1807 | - $arr_line = file($upload['file']['tmp_name']); | ||
1808 | - //print"<pre>"; | ||
1809 | - $i = 0; | ||
1810 | - $mktime = mktime(); | ||
1811 | - foreach($arr_line as $line){ | ||
1812 | - $row_line = explode(";",$line); | ||
1813 | - $this->import_updateProductCine($this->getModificationProduct_id($row_line[0]),$row_line,$line,$mktime); | ||
1814 | - if(($i%30)==0)sleep(1); | ||
1815 | - $i++; | ||
1816 | - // print_r($row_line); | ||
1817 | - }//print"</pre>"; | ||
1818 | - | ||
1819 | - // $this->updateCountModificationProducts(); | ||
1820 | - } | ||
1821 | - | ||
1822 | - function loadCSV_cine($upload){ | ||
1823 | - if($upload['file']['name']!="file_1.csv"){print"Îøèáêà! Òîëüêî file_1.csv";exit;} | ||
1824 | - $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv"; | ||
1825 | - //echo $file; | ||
1826 | - //exit; | ||
1827 | - move_uploaded_file($upload['file']['tmp_name'], $file); | ||
1828 | - } | ||
1829 | - | ||
1830 | - function is_loadCSV_cine(){ | ||
1831 | - $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv"; | ||
1832 | - $is = is_file($file); | ||
1833 | - $this->tpl->assign('is',$is); | ||
1834 | - } | ||
1835 | - | ||
1836 | - function CronImportCSV_cine($upload){ | ||
1837 | - if($upload['file']['name']!="file_1.csv"){print"Îøèáêà! Òîëüêî file_1.csv";exit;} | ||
1838 | - $arr_line = file($upload['file']['tmp_name']); | ||
1839 | - //print"<pre>"; | ||
1840 | - $i = 0; | ||
1841 | - $mktime = mktime(); | ||
1842 | - foreach($arr_line as $line){ | ||
1843 | - $row_line = explode(";",$line); | ||
1844 | - $this->import_updateProductCine($this->getModificationProduct_id($row_line[0]),$row_line,$line,$mktime); | ||
1845 | - if(($i%30)==0)sleep(1); | ||
1846 | - $i++; | ||
1847 | - // print_r($row_line); | ||
1848 | - }//print"</pre>"; | ||
1849 | - //$this->updateCountModificationProducts(); | ||
1850 | - } | ||
1851 | - | ||
1852 | - function updateCountModificationProducts(){ // print"test"; | ||
1853 | -// $this->db->autoExecute("catalogs_products",array('count_modifications'=>0),DB_AUTOQUERY_UPDATE); | ||
1854 | - $res = $this->db->getAll("select * from catalogs_products",array(),DB_FETCHMODE_ASSOC); | ||
1855 | - $i = 0; | ||
1856 | - foreach($res as $row){ | ||
1857 | - $count = $this->db->getOne("select count(*) from catalogs_modifications where product_id=? and active>0",array($row['id'])); | ||
1858 | - $this->db->autoExecute("catalogs_products",array('count_modifications'=>$count),DB_AUTOQUERY_UPDATE,"id='".$row['id']."'"); | ||
1859 | - // if(($i%10)==0)sleep(10); | ||
1860 | - $i++; | ||
1861 | - } | ||
1862 | - } | ||
1863 | - | ||
1864 | - function config_update($id,$value){ | ||
1865 | - $this->db->autoExecute("catalogs_config",array('value'=>$value),DB_AUTOQUERY_UPDATE,"id='".$id."'"); | ||
1866 | - } | ||
1867 | - | ||
1868 | - function view_config_value($id){ | ||
1869 | - $r = $this->db->getOne("select value from catalogs_config where id=?",$id); | ||
1870 | - $this->tpl->assign("config",$r); | ||
1871 | - return $r; | ||
1872 | - } | ||
1873 | - | ||
1874 | - function displayCatalogsCurs(){ | ||
1875 | - $this->tpl->assign("tpl",'catalogs_curs.tpl'); | ||
1876 | - } | ||
1877 | - | ||
1878 | - function displayCatalogs(){ | ||
1879 | - $this->tpl->assign("tpl",'catalogs.tpl'); | ||
1880 | - } | ||
1881 | - | ||
1882 | - function displayProducts(){ | ||
1883 | - $this->tpl->assign("tpl",'catalogs_products.tpl'); | ||
1884 | - } | ||
1885 | - | ||
1886 | - function displayProductsTops(){ | ||
1887 | - $this->tpl->assign("tpl",'catalogs_products_tops.tpl'); | ||
1888 | - } | ||
1889 | - | ||
1890 | - function displayProductsHits(){ | ||
1891 | - $this->tpl->assign("tpl",'catalogs_products_hits.tpl'); | ||
1892 | - } | ||
1893 | - | ||
1894 | - function displayProductsHitsAll(){ | ||
1895 | - $this->tpl->assign("tpl",'catalogs_products_hits_all.tpl'); | ||
1896 | - } | ||
1897 | - | ||
1898 | - function displayBasket($count_products,$cine_products,$cine_products_discount,$discount){ | ||
1899 | - $this->tpl->assign("count_products",$count_products); | ||
1900 | - $this->tpl->assign("cine_products",$cine_products); | ||
1901 | - $this->tpl->assign("cine_products_discount",$cine_products_discount); | ||
1902 | - $this->tpl->assign("discount",$discount); | ||
1903 | - $this->tpl->display('basket.tpl'); | ||
1904 | - } | ||
1905 | - | ||
1906 | - function displayProduct(){ | ||
1907 | - $this->tpl->assign("tpl",'catalogs_product.tpl'); | ||
1908 | - } | ||
1909 | - | ||
1910 | - function displayProductBasket(){ | ||
1911 | - $this->tpl->assign("tpl",'catalogs_basket.tpl'); | ||
1912 | - } | ||
1913 | - | ||
1914 | - function displayBrends(){ | ||
1915 | - $this->tpl->assign("tpl",'catalogs_brends.tpl'); | ||
1916 | - } | ||
1917 | - | ||
1918 | - function displayBrend(){ | ||
1919 | - $this->tpl->assign("tpl",'catalogs_brend.tpl'); | ||
1920 | - } | ||
1921 | - | ||
1922 | - function displayCities(){ | ||
1923 | - $this->tpl->assign("tpl",'catalogs_cities.tpl'); | ||
1924 | - } | ||
1925 | - | ||
1926 | - function displayProductBasketSend(){ | ||
1927 | - $this->tpl->assign("tpl",'catalogs_basket_send.tpl'); | ||
1928 | - } | ||
1929 | - | ||
1930 | - function displayReg(){ | ||
1931 | - $this->tpl->assign("tpl",'catalogs_reg.tpl'); | ||
1932 | - } | ||
1933 | - | ||
1934 | - function displayEditUser(){ | ||
1935 | - $this->tpl->assign("tpl",'catalogs_user_edit.tpl'); | ||
1936 | - } | ||
1937 | - | ||
1938 | - function displayNoPsw(){ | ||
1939 | - $this->tpl->assign("tpl",'catalogs_nopsw.tpl'); | ||
1940 | - } | ||
1941 | - | ||
1942 | - function displayOrders(){ | ||
1943 | - $this->tpl->assign("tpl",'catalogs_orders.tpl'); | ||
1944 | - } | ||
1945 | - | ||
1946 | - function displayOrder(){ | ||
1947 | - $this->tpl->assign("tpl",'catalogs_order.tpl'); | ||
1948 | - } | ||
1949 | - | ||
1950 | - function displayUsers(){ | ||
1951 | - $this->tpl->assign("tpl",'catalogs_users.tpl'); | ||
1952 | - } | ||
1953 | - | ||
1954 | - function displayUser(){ | ||
1955 | - $this->tpl->assign("tpl",'catalogs_user.tpl'); | ||
1956 | - } | ||
1957 | - | ||
1958 | - function displayFilters(){ | ||
1959 | - $this->tpl->assign("tpl",'catalogs_filters.tpl'); | ||
1960 | - } | ||
1961 | - | ||
1962 | - function displayYears(){ | ||
1963 | - $this->tpl->assign("tpl",'catalogs_years.tpl'); | ||
1964 | - } | ||
1965 | - | ||
1966 | - function displayWinProducts(){ | ||
1967 | - $this->tpl->display('catalogs_win_products.tpl'); | ||
1968 | - } | ||
1969 | - | ||
1970 | - function displayModifications(){ | ||
1971 | - $this->tpl->assign("tpl",'catalogs_modifications.tpl'); | ||
1972 | - } | ||
1973 | - | ||
1974 | - function displayImport(){ | ||
1975 | - $this->tpl->assign("tpl",'catalogs_import.tpl'); | ||
1976 | - } | ||
1977 | - | ||
1978 | - function displayImportCine(){ | ||
1979 | - $this->tpl->assign("tpl",'catalogs_import_cine.tpl'); | ||
1980 | - } | ||
1981 | - | ||
1982 | - function displayAkcii(){ | ||
1983 | - $this->tpl->assign("tpl",'catalogs_akcii.tpl'); | ||
1984 | - } | ||
1985 | - | ||
1986 | - function displayCompare(){ | ||
1987 | - $this->tpl->assign("tpl",'catalogs_compare.tpl'); | ||
1988 | - } | ||
1989 | - | ||
1990 | - function displayTmpProducts(){ | ||
1991 | - $this->tpl->assign("tpl",'catalogs_tmp_products.tpl'); | ||
1992 | - } | ||
1993 | - | ||
1994 | -} | ||
1995 | -?> |
libs/catalogs2.class.php deleted
1 | -<?php | ||
2 | -class Catalogs{ | ||
3 | - var $db = null; | ||
4 | - var $tpl = null; | ||
5 | - var $error = null; | ||
6 | - var $photo_id = null; | ||
7 | - | ||
8 | - | ||
9 | - function Catalogs(&$db,&$tpl,&$error){ | ||
10 | - $this->db = &$db; | ||
11 | - $this->tpl = &$tpl; | ||
12 | - $this->error = &$error; | ||
13 | - } | ||
14 | - | ||
15 | - | ||
16 | - function trim(&$data){ | ||
17 | - foreach($data as $key=>$value){ | ||
18 | - if(is_array($value))$this->trim($value); | ||
19 | - else $data[$key] = stripslashes(trim($value)); | ||
20 | - } | ||
21 | - } | ||
22 | - | ||
23 | - | ||
24 | - function valid($data,$upload = null){ | ||
25 | - | ||
26 | - if(isset($data['name'])){ | ||
27 | - if( !preg_match("/.{1,100}/i",$data['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ."; | ||
28 | - } | ||
29 | - | ||
30 | - if(isset($data['about_min'])){ | ||
31 | - if( !preg_match("/.+/is",$data['about_min']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Êðàòêîå îïèñàíèå."; | ||
32 | - } | ||
33 | - /* | ||
34 | - if(isset($data['text'])){ | ||
35 | - if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ïîëíîå îïèñàíèå."; | ||
36 | - } */ | ||
37 | -/* | ||
38 | - if(isset($data['cine'])){ | ||
39 | - if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Öåíà, òîëüêî öèôðû."; | ||
40 | - } */ | ||
41 | - | ||
42 | - if(isset($upload['pic']['name']) && $upload['pic']['tmp_name']){ | ||
43 | - $type = substr(strrchr($upload['pic']['name'],"."),1); | ||
44 | - if( !preg_match("/^(jpeg|jpg|gif|png|bmp)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif."; | ||
45 | - } | ||
46 | - | ||
47 | - if(isset($upload['file']['name'])){ | ||
48 | - if( !preg_match("/\.csv$/i",$upload['file']['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ CSV ôàéë, òîëüêî csv."; | ||
49 | - } | ||
50 | - | ||
51 | - | ||
52 | - if(isset($data['order_name'])){ | ||
53 | - if( !preg_match("/.{1,100}/i",$data['order_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
54 | - } | ||
55 | - | ||
56 | - if(isset($data['order_adress'])){ | ||
57 | - if( !preg_match("/.{1,200}/i",$data['order_adress']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Àäðåñ (Ìàêñèìóì 200 ñèìâîëîâ)."; | ||
58 | - } | ||
59 | - | ||
60 | - if(isset($data['order_phone'])){ | ||
61 | - if( !preg_match("/.{1,70}/i",$data['order_phone']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Òåëåôîí (Ìàêñèìóì 70 ñèìâîëîâ)."; | ||
62 | - } | ||
63 | - | ||
64 | - if(isset($data['user_name'])){ | ||
65 | - if( !preg_match("/.{1,100}/i",$data['user_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
66 | - } | ||
67 | - | ||
68 | - if(isset($data['user_email'])){ | ||
69 | - if( !preg_match("/.{1,80}/i",$data['user_email']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø e-mail (Ìàêñèìóì 80 ñèìâîëîâ)."; | ||
70 | - } | ||
71 | - | ||
72 | - if(isset($data['user_login'])){ | ||
73 | - if( !preg_match("/.{1,100}/i",$data['user_login']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ëîãèí (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
74 | - elseif( $this->isLoginUser($data['user_login']) ) $this->error[] = "Îøèáêà òàêîé Ëîãèí óæå åñòü!"; | ||
75 | - } | ||
76 | - | ||
77 | - if(isset($data['you_login'])){ | ||
78 | - if( !$this->isLoginUser($data['you_login']) ) $this->error[] = "Òàêîãî ËÎÃÈÍÀ íåò â áàçå äàííûõ ñàéòà!"; | ||
79 | - } | ||
80 | - | ||
81 | - if(isset($data['user_psw'])){ | ||
82 | - if( !preg_match("/.{1,100}/i",$data['user_psw']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ïàðîëü (Ìàêñèìóì 100 ñèìâîëîâ)."; | ||
83 | - } | ||
84 | - | ||
85 | - return ( count($this->error) ) ? true : false; | ||
86 | - } | ||
87 | - | ||
88 | - function deleteRubric($id,$field="id"){ | ||
89 | - $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?"; | ||
90 | - $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); | ||
91 | - foreach($res as $row){ | ||
92 | - @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}"); | ||
93 | - $sql = "delete from catalogs_rubrics where id=?"; | ||
94 | - $this->db->query($sql,array($row['id'])); | ||
95 | - $this->deleteFiltersRubric_id($row['id']); | ||
96 | - $this->deleteYearsRubric_id($row['id']); | ||
97 | - $this->deleteProductsRubric($row['id']); | ||
98 | - $this->deleteRubric($row['id'],"parent_id"); | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - function deleteProductPics($id,$pics = array('pic_big','pic')){ | ||
103 | - $sql = "select pic_big,pic from catalogs_products where id=?"; | ||
104 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
105 | - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}"); | ||
106 | - if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}"); | ||
107 | - } | ||
108 | - | ||
109 | - function deleteProduct($id){ | ||
110 | - $this->deleteProductPics($id); | ||
111 | - $sql = "delete from catalogs_products where id=?"; | ||
112 | - $this->db->query($sql,array($id)); | ||
113 | - $this->delete_keysProductsFilters($id); | ||
114 | - $this->delete_keysProductsAkcii($id); | ||
115 | - $this->delete_keysProductsYears($id); | ||
116 | - $this->delete_keysProductsCities($id); | ||
117 | - $this->deleteProductModifications($id); | ||
118 | - } | ||
119 | - | ||
120 | - function deleteProductsRubric($id){ | ||
121 | - $res = $this->db->getAll("select id from catalogs_products where rubric_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
122 | - foreach($res as $row){ | ||
123 | - $this->deleteProduct($row['id']); | ||
124 | - } | ||
125 | - } | ||
126 | - | ||
127 | - | ||
128 | - function PhotosCheck($id_s,$check_s = array()){ | ||
129 | - $sql = "UPDATE gallery SET active = ? WHERE id =?"; | ||
130 | - | ||
131 | - foreach($id_s as $id){ | ||
132 | - $this->db->query($sql,array(0,$id)); | ||
133 | - } | ||
134 | - if(count($check_s)){ | ||
135 | - foreach($check_s as $id){ | ||
136 | - $this->db->query($sql,array(1,$id)); | ||
137 | - } | ||
138 | - } | ||
139 | - } | ||
140 | - | ||
141 | - function viewRubrics($id = 0,$parent_id = 0){ // print $parent_id."<br />"; | ||
142 | - global $rubrics; | ||
143 | - $sql = "select a.*,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? group by a.id order by a.sort asc"; | ||
144 | - $res = $this->db->query($sql,array($id)); | ||
145 | - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){ | ||
146 | - $rubrics[] = $row; //print $row['id']."<br />"; | ||
147 | - | ||
148 | - if(in_array($row['id'],$this->getParentIdRubric($parent_id))){$this->viewRubrics($row['id']);} | ||
149 | - // if($row['level']==0){$this->viewRubrics($row['id']);} | ||
150 | - } | ||
151 | - $this->tpl->assign("rubrics",$rubrics); | ||
152 | - } | ||
153 | - | ||
154 | - function getParentIdRubric($id){ | ||
155 | - //$ids = array(); | ||
156 | - global $ids; | ||
157 | - if(!count($ids))$ids = array(); | ||
158 | - while($id>0){ | ||
159 | - $row = $this->db->getRow('select id,parent_id from catalogs_rubrics where id=?',array($id),DB_FETCHMODE_ASSOC); | ||
160 | - //if(isset($row['id'])) | ||
161 | - $ids[] = $row['id']; | ||
162 | - $id = $row['parent_id']; | ||
163 | - } //print_r($ids); | ||
164 | - // sort($ids); | ||
165 | - return $ids; | ||
166 | - } | ||
167 | - | ||
168 | - function viewRubricsAll($id = 0){ | ||
169 | - global $rubrics; | ||
170 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
171 | - $res = $this->db->query($sql,array($id)); | ||
172 | - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){ | ||
173 | - $rubrics[] = $row; | ||
174 | - $this->viewRubricsAll($row['id']); | ||
175 | - } | ||
176 | - $this->tpl->assign("rubrics",$rubrics); | ||
177 | - } | ||
178 | - | ||
179 | - | ||
180 | - function viewRubrics_begin($item = 'parents'){ | ||
181 | - $sql = "select a.*,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? order by a.sort asc"; | ||
182 | - $row = $this->db->getAll($sql,array(0),DB_FETCHMODE_ASSOC); | ||
183 | - foreach($row as $key=>$value){ | ||
184 | - if($item=='parents'){ | ||
185 | - $row[$key]['parents'] = $this->db->getAll("select * from catalogs_rubrics where parent_id=? order by sort asc",array($value['id']),DB_FETCHMODE_ASSOC); | ||
186 | - }elseif($item=='brends'){ | ||
187 | - $row[$key]['brends'] = $this->db->getAll("select * from catalogs_brends where rubric_id in (select id from catalogs_rubrics where parent_id=? or id=?) group by name",array($value['id'],$value['id']),DB_FETCHMODE_ASSOC); | ||
188 | - } | ||
189 | - } | ||
190 | - $this->tpl->assign("catalogs_rubrics_begin",$row); | ||
191 | - } | ||
192 | - | ||
193 | - function viewRubrics_parent($parent_id = 0){ | ||
194 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
195 | - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); | ||
196 | - $this->tpl->assign("catalogs_rubrics_parent",$row); | ||
197 | - } | ||
198 | - | ||
199 | - function viewRubrics_parent2($rub_id){ | ||
200 | - $parent_id = $this->getRubricParent($rub_id); | ||
201 | - if($parent_id==0)$parent_id = $rub_id; | ||
202 | - $sql = "select * from catalogs_rubrics where parent_id=? order by sort asc"; | ||
203 | - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); | ||
204 | - $this->tpl->assign("catalogs_rubrics_parent2",$row); | ||
205 | - } | ||
206 | - | ||
207 | - function viewRubricOne($id,&$row){ | ||
208 | - $sql = "select * from catalogs_rubrics where id=?"; | ||
209 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
210 | - $this->tpl->assign('rubric',$row); | ||
211 | - } | ||
212 | - | ||
213 | - function getRubricName($id){ | ||
214 | - $sql = "select name from catalogs_rubrics where id=?"; | ||
215 | - return $this->db->getOne($sql,array($id)); | ||
216 | - } | ||
217 | - | ||
218 | - function getRubricParent($id){ | ||
219 | - $sql = "select parent_id from catalogs_rubrics where id=?"; | ||
220 | - return $this->db->getOne($sql,array($id)); | ||
221 | - } | ||
222 | - | ||
223 | - function SaveRubric($data,$upload){ | ||
224 | - $table_name = "catalogs_rubrics"; | ||
225 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
226 | - $parent_id = (isset($data['parent_id']) ? $data['parent_id'] : 0); | ||
227 | - $fields_values = array('parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1),'sort' => $data['sort'],'name' => $data['name'],'list_name' => $data['list_name'],'sort_cost' => $data['sort_cost'],'meta_title' => $data['meta_title'],'meta_description' => $data['meta_description'],'meta_keywords' => $data['meta_keywords'],'meta_about' => $data['meta_about']); | ||
228 | - /* | ||
229 | - if($upload['pic']['tmp_name']){ | ||
230 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/")); | ||
231 | - } */ | ||
232 | - | ||
233 | - if($upload['pic']['tmp_name']){ | ||
234 | - if($data['update_id']>0)$this->deletePicRubric($data['update_id']); | ||
235 | - $uploadfile = "./uploaded/pic/catalogs/rubrics/"; | ||
236 | - $type = substr(strrchr($upload['pic']['name'],"."),1); | ||
237 | - $uploadname = mktime() . "." . $type; | ||
238 | - if (!move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))print"Îøèáêà ïðè çàêà÷êå ôàéëà!"; | ||
239 | - $fields_values['pic'] = $uploadname; | ||
240 | - } | ||
241 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
242 | - } | ||
243 | - | ||
244 | - function deletePicRubric($id){ | ||
245 | - $sql = "select pic from catalogs_rubrics where id=?"; | ||
246 | - $rub = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
247 | - @unlink("./uploaded/pic/catalogs/rubrics/{$rub['pic']}"); | ||
248 | - } | ||
249 | - | ||
250 | - function getLevelRubric($id){ | ||
251 | - $level = $this->db->getOne("select level from catalogs_rubrics where id=?",array($id)); | ||
252 | - return ($level==null)? -1 : $level; | ||
253 | - } | ||
254 | - | ||
255 | - function saveUser($data){ | ||
256 | - $table_name = "catalogs_users"; | ||
257 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
258 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'login' => $data['user_login'],'psw' => $data['user_psw'],'about' => $data['user_about'],'mktime'=>mktime()); | ||
259 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
260 | - } | ||
261 | - | ||
262 | - function updateUser($data){ | ||
263 | - $table_name = "catalogs_users"; | ||
264 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
265 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'login' => $data['user_login'],'psw' => $data['user_psw'],'about' => $data['user_about'],'discount'=>$data['user_discount']); | ||
266 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
267 | - } | ||
268 | - | ||
269 | - function updateUserID($data,$id){ | ||
270 | - $table_name = "catalogs_users"; | ||
271 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
272 | - $fields_values = array('name' => $data['user_name'],'email' => $data['user_email'],'psw' => $data['user_psw'],'about' => $data['user_about'],'phone' => $data['user_phone'],'phonemob' => $data['user_phonemob'],'adress' => $data['user_adress']); | ||
273 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$id}"); | ||
274 | - } | ||
275 | - | ||
276 | - function deleteUser($id){ | ||
277 | - $this->db->query("delete from catalogs_users where id=?",array($id)); | ||
278 | - $res_order_id = $this->db->getRow("select id from catalogs_orders where user_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
279 | - if(count($res_order_id)){ | ||
280 | - foreach($res_order_id as $_id){ | ||
281 | - $this->db->query("delete from catalogs_orders where id=?",array($_id)); | ||
282 | - $this->db->query("delete from catalogs_orders_products where order_id=?",array($_id)); | ||
283 | - }} | ||
284 | - } | ||
285 | - | ||
286 | - function isLoginUser($login){ | ||
287 | - return $this->db->getOne("select id from catalogs_users where login=?",array($login)); | ||
288 | - } | ||
289 | - | ||
290 | - function sendLoginInfo($login){ | ||
291 | - $user = $this->db->getRow("select * from catalogs_users where login=?",array($login),DB_FETCHMODE_ASSOC); | ||
292 | - $mail = new PHPMailer(); | ||
293 | - $mail->CharSet = "windows-1251"; | ||
294 | - $mail->From = "shop@eltrade.com.ua"; | ||
295 | - $mail->FromName = "shop@eltrade.com.ua"; | ||
296 | - $mail->AddAddress($user['email'], $user['name']); | ||
297 | - $mail->Subject = "Àêêàóíò ýêñòðèì"; | ||
298 | - $msg = ""; | ||
299 | - $msg .= "Çäðàâñòâóéòå: ".$user['name']; | ||
300 | - $msg .= "<br />"; | ||
301 | - $msg .= "Âàø ëîãèí: ".$user['login']; | ||
302 | - $msg .= "<br>"; | ||
303 | - $msg .= "Âàø ïàðîëü: ".$user['psw']; | ||
304 | - $msg .= "<br>"; | ||
305 | - $msg .= "Ñ óâàæåíèåì, shop@eltrade.com.ua"; | ||
306 | - | ||
307 | - $mail->MsgHTML($msg); | ||
308 | - | ||
309 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
310 | - $mail->ClearAddresses(); | ||
311 | - $mail->ClearAttachments(); | ||
312 | - } | ||
313 | - | ||
314 | - function isUser($login,$psw){ | ||
315 | - $row = $this->db->getRow("select * from catalogs_users where login=? AND psw=?",array($login,$psw),DB_FETCHMODE_ASSOC); | ||
316 | - $this->tpl->assign('user_service',$row); | ||
317 | - return $row['id']; | ||
318 | - } | ||
319 | - | ||
320 | - function viewUser($id){ | ||
321 | - $sql = "select * from catalogs_users where id=?"; | ||
322 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
323 | - $this->tpl->assign('user',$row); | ||
324 | - } | ||
325 | - | ||
326 | - function getUserDiscount($id){ | ||
327 | - return $this->db->getOne("select discount from catalogs_users where id=?",array($id)); | ||
328 | - } | ||
329 | - | ||
330 | - function viewUsers(){ | ||
331 | - $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders | ||
332 | -FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id | ||
333 | -GROUP BY catalogs_users.id | ||
334 | -ORDER BY catalogs_users.mktime DESC"; | ||
335 | - | ||
336 | - $pagerOptions = Array( | ||
337 | - 'mode' => 'Sliding', | ||
338 | - 'delta' => 6, | ||
339 | - 'perPage' => 10, | ||
340 | - 'linkClass'=>"link_class", | ||
341 | - 'curPageLinkClassName'=>"link_class_active", | ||
342 | - 'spacesBeforeSeparator' => 1, | ||
343 | - 'spacesAfterSeparator' => 1 | ||
344 | - ); | ||
345 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
346 | - | ||
347 | - $this->tpl->assign('usersData', $res); | ||
348 | - } | ||
349 | - | ||
350 | - function viewModifications($product_id){ | ||
351 | - $sql = "select * from catalogs_modifications where product_id=? order by id desc"; | ||
352 | - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
353 | - $this->tpl->assign('modifications', $row); | ||
354 | - } | ||
355 | - | ||
356 | - function viewModificationsProduct($product_id){ | ||
357 | - $sql = "select * from catalogs_modifications where product_id=? and active>0 order by id desc"; | ||
358 | - // $sql = "select m.* from catalogs_keys_products_cities k left join catalogs_modifications m on m.code=k.mod_code where k.product_id=? and k.count>0 order by k.mod_code desc"; | ||
359 | - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
360 | - $this->tpl->assign('modifications', $row); | ||
361 | - } | ||
362 | - | ||
363 | - function viewModificationOne($id){ | ||
364 | - $sql = "select * from catalogs_modifications where id=?"; | ||
365 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
366 | - $this->tpl->assign('modification', $row); | ||
367 | - } | ||
368 | - | ||
369 | - function getModificationProduct_id($code){ | ||
370 | - return $this->db->getOne("select product_id from catalogs_modifications where code=?",array($code)); | ||
371 | - } | ||
372 | - | ||
373 | - function SaveModification($data,$upload){ | ||
374 | - $table_name = "catalogs_modifications"; | ||
375 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
376 | - $fields_values = array('product_id'=>$data['product_id'],'code'=>$data['code'],'size' => $data['size'],'color' => $data['color'],'active' => $data['active']); | ||
377 | - if(isset($data['delete_pic'])){if($data['update_id']>0){$this->deleteModificationPics($data['update_id']);}$fields_values['pic']=null;$fields_values['pic_big']=null;} | ||
378 | - if($upload['pic']['tmp_name']){ | ||
379 | - if($data['update_id']>0){ | ||
380 | - $delete_pics = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?array('pic'):array('pic','pic_big'); | ||
381 | - $this->deleteModificationPics($data['update_id'],$delete_pics); | ||
382 | - } | ||
383 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"144",'height'=>"144",'upload_path'=>"./uploaded/pic/catalogs/modifications/")); | ||
384 | - $fields_values['pic_big'] = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?$upload['pic']['name']:upload_ImageResize($upload['pic'],array('width'=>"500",'height'=>"500",'upload_path'=>"./uploaded/pic/catalogs/modifications/big/")); | ||
385 | - } | ||
386 | - | ||
387 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='{$data['update_id']}'"); | ||
388 | - return $id; | ||
389 | - } | ||
390 | - | ||
391 | - function deleteModification($id){ | ||
392 | - $this->deleteModificationPics($id); | ||
393 | - $this->db->query("delete from catalogs_modifications where id=?",array($id)); | ||
394 | - } | ||
395 | - | ||
396 | - function deleteProductModifications($product_id,$nopic = false){ | ||
397 | - IF($nopic==false){ | ||
398 | - $sql = "select * from catalogs_modifications where product_id=?"; | ||
399 | - $res = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); | ||
400 | - foreach($res as $row){ | ||
401 | - $this->deleteModificationPics($row['id']); | ||
402 | - } | ||
403 | - } | ||
404 | - $this->db->query("delete from catalogs_modifications where product_id=?",array($product_id)); | ||
405 | - } | ||
406 | - | ||
407 | - function deleteModificationPics($id,$pics = array('pic_big','pic')){ | ||
408 | - $sql = "select pic,pic_big from catalogs_modifications where id=?"; | ||
409 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
410 | - if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}"); | ||
411 | - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); | ||
412 | - } | ||
413 | - | ||
414 | - function ProductClick($id){ | ||
415 | - $this->db->query("update catalogs_products set click=click+1 where id='$id'"); | ||
416 | - } | ||
417 | - | ||
418 | - function SaveProduct($data,$upload){ | ||
419 | - $table_name = "catalogs_products"; | ||
420 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
421 | - $id = ($data['update_id']>0) ? $data['update_id'] : $this->db->nextId('mySequence_'.$table_name); | ||
422 | - $fields_values = array('id'=>$id,'rubric_id'=>$data['rubric_id'],'rubric_parent_id'=>$this->getRubricParent($data['rubric_id']),'brend_id'=>$data['brend_id'],'name' => $data['name'],'about' => $data['about'],'text' => $data['text'],'strnumber' => $data['strnumber'],'cine'=>$data['cine'],'cine_last'=>$data['cine_last'],'sex'=>$data['sex'], 'mktime' => mktime(),'meta_title' => $data['meta_title'],'meta_description' => $data['meta_description'],'meta_keywords' => $data['meta_keywords'],'meta_about' => $data['meta_about'],'active' => $data['active']); | ||
423 | - if($upload['pic']['tmp_name']){ | ||
424 | - $delete_pics = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?array('pic'):array('pic','pic_big'); | ||
425 | - $this->deleteProductPics($id,$delete_pics); | ||
426 | - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"144",'height'=>"144",'upload_path'=>"./uploaded/pic/catalogs/products/")); | ||
427 | - $fields_values['pic_big'] = (isset($upload['pic']['big']) && $upload['pic']['big']==true)?$upload['pic']['name']:upload_ImageResize($upload['pic'],array('width'=>"500",'height'=>"500",'upload_path'=>"./uploaded/pic/catalogs/products/big/")); | ||
428 | - } | ||
429 | - | ||
430 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id='$id'"); | ||
431 | - $this->save_keysProductsFilters($id,$data); | ||
432 | - $this->save_keysProductsYears($id,$data); | ||
433 | - $this->save_keysProductsCities($id,$data); | ||
434 | - $this->save_keysProductsAkcii($id,$data); | ||
435 | - return $id; | ||
436 | - } | ||
437 | - | ||
438 | - function save_keysProductsFilters($id,$data){ | ||
439 | - $this->delete_keysProductsFilters($id); | ||
440 | - if(!isset($data['filter']))return false; | ||
441 | - $table_name = "catalogs_keys_products_filters"; | ||
442 | - foreach($data['filter'] as $filter_id){ | ||
443 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); | ||
444 | - } | ||
445 | - } | ||
446 | - | ||
447 | - function delete_keysProductsFilters($id){ | ||
448 | - $this->db->query("delete from catalogs_keys_products_filters where product_id=?",array($id)); | ||
449 | - } | ||
450 | - | ||
451 | - function save_keysProductsYears($id,$data){ | ||
452 | - $this->delete_keysProductsYears($id); | ||
453 | - if(!isset($data['years']))return false; | ||
454 | - $table_name = "catalogs_keys_products_years"; | ||
455 | - foreach($data['years'] as $filter_id){ | ||
456 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'year_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); | ||
457 | - } | ||
458 | - } | ||
459 | - | ||
460 | - function delete_keysProductsYears($id){ | ||
461 | - $this->db->query("delete from catalogs_keys_products_years where product_id=?",array($id)); | ||
462 | - } | ||
463 | - | ||
464 | - function save_keysProductsCities($id,$data){ | ||
465 | - $this->delete_keysProductsCities($id); | ||
466 | - if(!isset($data['city']))return false; | ||
467 | - $table_name = "catalogs_keys_products_cities"; | ||
468 | - foreach($data['city'] as $city_id){ | ||
469 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'city_id'=>$city_id),DB_AUTOQUERY_INSERT); | ||
470 | - } | ||
471 | - } | ||
472 | - | ||
473 | - function delete_keysProductsAkcii($id){ | ||
474 | - $this->db->query("delete from catalogs_keys_products_akcii where product_id=?",array($id)); | ||
475 | - } | ||
476 | - | ||
477 | - function save_keysProductsAkcii($id,$data){ | ||
478 | - $this->delete_keysProductsAkcii($id); | ||
479 | - if(!isset($data['akcii']))return false; | ||
480 | - $table_name = "catalogs_keys_products_akcii"; | ||
481 | - foreach($data['akcii'] as $rubric_id){ | ||
482 | - $this->db->autoExecute($table_name,array('product_id'=>$id,'rubric_id'=>$rubric_id),DB_AUTOQUERY_INSERT); | ||
483 | - } | ||
484 | - } | ||
485 | - | ||
486 | - function delete_keysProductsCities($id){ | ||
487 | - $this->db->query("delete from catalogs_keys_products_cities where product_id=?",array($id)); | ||
488 | - } | ||
489 | - | ||
490 | - | ||
491 | - function saveProductSizeCine($id,$data){ | ||
492 | - $this->db->query("delete from catalogs_products_cine where product_id=?",array($id)); | ||
493 | - foreach($data['size'] as $key=>$size){ | ||
494 | - $this->db->autoExecute("catalogs_products_cine",array('product_id'=>$id,'size'=>$size,'cine'=>$data['cine'][$key],'metka'=>$data['size_metka'][$key],'n'=>$key),DB_AUTOQUERY_INSERT); | ||
495 | - } | ||
496 | - } | ||
497 | - | ||
498 | - | ||
499 | - function productsIsHits($products,$hits,$tops,$headers){ | ||
500 | - $sql = "update catalogs_products set hit=?,top=?,header=? where id=?"; | ||
501 | - foreach($products as $id){ | ||
502 | - if(@in_array($id,$hits))$hit = true; | ||
503 | - else $hit = false; | ||
504 | - if(@in_array($id,$tops))$top = true; | ||
505 | - else $top = false; | ||
506 | - if(@in_array($id,$headers))$header = true; | ||
507 | - else $header = false; | ||
508 | - $this->db->query($sql,array($hit,$top,$header, $id)); | ||
509 | - } | ||
510 | - } | ||
511 | - | ||
512 | - function productsIsHits2($data,$hits){ | ||
513 | - $sql = "update catalogs_products set hit=?,hit_sort=? where id=?"; | ||
514 | - foreach($data['product_id'] as $key=>$id){ | ||
515 | - if(@in_array($id,$hits))$hit = true; | ||
516 | - else $hit = false; | ||
517 | - $this->db->query($sql,array($hit,$data['hit_sort'][$key],$id)); | ||
518 | - } | ||
519 | - } | ||
520 | - | ||
521 | - function viewProducts($params,$rubricsP = false,$count_modf = true){ | ||
522 | - $search = array(); | ||
523 | - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; | ||
524 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){ | ||
525 | - $array_string = explode(" ",trim($params['search_str'])); | ||
526 | - $search_string = array(); | ||
527 | - $search_string[] = "catalogs_products.name like '%{$params['search_str']}%'"; | ||
528 | - foreach($array_string as $str){ | ||
529 | - $search_string[] = "catalogs_products.name like '$str'"; | ||
530 | - $search_string[] = "catalogs_products.name like'% $str %'"; | ||
531 | - $search_string[] = "catalogs_products.name like'%$str %'"; | ||
532 | - $search_string[] = "catalogs_products.name like'% $str%'"; | ||
533 | - } | ||
534 | - $search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", $params['search_str']).")"; | ||
535 | - } | ||
536 | - // print_r($params); | ||
537 | - if(isset($params['brendID']) && $params['brendID']>0)$search[] = sprintf("catalogs_products.brend_id='%d'",$params['brendID']); | ||
538 | - if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")"; | ||
539 | - if(isset($params['sex']) && $params['sex']>0)$search[] = sprintf("catalogs_products.sex='%d'",$params['sex']); | ||
540 | - //if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']); | ||
541 | - if($count_modf==true)$search[] = "catalogs_products.count_modifications>0"; | ||
542 | - if(isset($params['rubID']) && $params['rubID']>0){ | ||
543 | - $search[] = ($rubricsP==true)?sprintf("(catalogs_products.rubric_id='%d')",$params['rubID']):sprintf("(catalogs_products.rubric_parent_id='%d' || catalogs_products.rubric_id='%d')",$params['rubID'],$params['rubID']); | ||
544 | - } | ||
545 | - if(isset($params['filterID'])){ | ||
546 | - //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']); | ||
547 | - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")"; | ||
548 | - } | ||
549 | - if(isset($params['yearID']) && $params['yearID']>0){ | ||
550 | - //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']); | ||
551 | - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")"; | ||
552 | - } | ||
553 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id "; | ||
554 | - if(isset($params['akcii']) && $params['akcii']>0)$sql .= "RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id "; | ||
555 | - if(isset($params['filterID']) && $params['filterID']>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; | ||
556 | - if(isset($params['yearID']) && $params['yearID']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; | ||
557 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id ";} | ||
558 | - $sql .= "WHERE 1=1 "; | ||
559 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
560 | - if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";} | ||
561 | - if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= " GROUP BY catalogs_products.id ";} | ||
562 | - $sql .= "order by "; | ||
563 | - if(isset($_GET['sort'])){ | ||
564 | - switch($_GET['sort']){ | ||
565 | - case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break; | ||
566 | - case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break; | ||
567 | - case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break; | ||
568 | - default : $sql .= " catalogs_products.mktime desc"; | ||
569 | - } | ||
570 | - }else $sql .= " catalogs_products.cine desc"; | ||
571 | - // print $sql; | ||
572 | - $pagerOptions = Array( | ||
573 | - 'mode' => 'Sliding', | ||
574 | - 'delta' => 6, | ||
575 | - 'perPage' => $perPage, | ||
576 | - 'linkClass'=>"link_class", | ||
577 | - 'curPageLinkClassName'=>"link_class_active", | ||
578 | - 'spacesBeforeSeparator' => 1, | ||
579 | - 'spacesAfterSeparator' => 1 | ||
580 | - ); | ||
581 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
582 | - | ||
583 | - $this->tpl->assign('productsData', $res); | ||
584 | - } | ||
585 | - | ||
586 | - function getCineCurs($type_curs,$cine){ | ||
587 | - $curs = array(); | ||
588 | - | ||
589 | - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); | ||
590 | - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); | ||
591 | - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); | ||
592 | - | ||
593 | - switch($type_curs){ | ||
594 | - case 'uah' : | ||
595 | - $curs['uah'] = round($cine,2); | ||
596 | - $curs['uah_bank'] = round(($cine/$usd)*$uah_bank,2); | ||
597 | - $curs['usd'] = round($cine/$usd,2); | ||
598 | - break; | ||
599 | - case 'uah_bank' : | ||
600 | - $curs['uah'] = round(($cine/$uah_bank)*$uah,2); | ||
601 | - $curs['uah_bank'] = round($cine,2); | ||
602 | - $curs['usd'] = round($cine/$uah_bank,2); | ||
603 | - break; | ||
604 | - case 'usd' : | ||
605 | - $curs['uah'] = round($cine*$uah,2); | ||
606 | - $curs['uah_bank'] = round($cine*$uah_bank,2); | ||
607 | - $curs['usd'] = round($cine,2); | ||
608 | - break; | ||
609 | - } | ||
610 | - return $curs; | ||
611 | - } | ||
612 | - | ||
613 | - function viewProductsAkcii($rubric_id){ | ||
614 | - $sql = "select catalogs_products.* from catalogs_keys_products_akcii left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id where catalogs_keys_products_akcii.rubric_id=?"; | ||
615 | - $res = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); | ||
616 | - //print_r($res); | ||
617 | - $this->tpl->assign('products_akcii',$res); | ||
618 | - } | ||
619 | - | ||
620 | - function viewProductsHitsAll2(){ | ||
621 | - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; | ||
622 | - $sql = "select * from catalogs_products where hit=?"; | ||
623 | - $pagerOptions = Array( | ||
624 | - 'mode' => 'Sliding', | ||
625 | - 'delta' => 6, | ||
626 | - 'perPage' => $perPage, | ||
627 | - 'linkClass'=>"link_class", | ||
628 | - 'curPageLinkClassName'=>"link_class_active", | ||
629 | - 'spacesBeforeSeparator' => 1, | ||
630 | - 'spacesAfterSeparator' => 1 | ||
631 | - ); | ||
632 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array(true)); | ||
633 | - | ||
634 | - $this->tpl->assign('productsData', $res); | ||
635 | - } | ||
636 | - | ||
637 | - function viewProductsHits($params,$limit = 4,$curs = null){ | ||
638 | - $search = array(); | ||
639 | - if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("rubric_parent_id=%d",$params['rubID']); | ||
640 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 "; | ||
641 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
642 | - $sql .= "order by catalogs_products.mktime desc"; | ||
643 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
644 | - $this->tpl->assign('products_hits',$res); | ||
645 | - } | ||
646 | - | ||
647 | - function viewProductsTops($params,$limit = 4,$curs = null){ | ||
648 | - $search = array(); | ||
649 | - if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("rubric_parent_id=%d",$params['rubID']); | ||
650 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 "; | ||
651 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
652 | - $sql .= "order by catalogs_products.mktime desc"; | ||
653 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
654 | - $this->tpl->assign('products_top',$res); | ||
655 | - } | ||
656 | - | ||
657 | - function viewProductsTopOne(){ | ||
658 | - $count = $this->db->getOne("select count(*) from catalogs_products WHERE catalogs_products.header=?",array(true)); | ||
659 | - $limit = 1; $round = rand(0,($count-$limit)); | ||
660 | - $res = $this->db->getRow("select * from catalogs_products WHERE catalogs_products.header=? order by id " . ((rand(1,1000)%2) ? "asc" : "desc") . " LIMIT $round,$limit",array(true),DB_FETCHMODE_ASSOC); | ||
661 | - $this->tpl->assign('products_top_one',$res); | ||
662 | - } | ||
663 | - | ||
664 | - function viewProductsLast($limit = 1){ | ||
665 | - $search = array(); | ||
666 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.active=? "; | ||
667 | - $sql .= "order by catalogs_products.mktime desc LIMIT $limit"; | ||
668 | - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
669 | - $this->tpl->assign('products_last',$res); | ||
670 | - } | ||
671 | - | ||
672 | - function viewProductsHitsAll($limit = 4){ | ||
673 | - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE hit=? "; | ||
674 | - $sql .= "order by mktime desc LIMIT $limit"; | ||
675 | - $products_hits = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); | ||
676 | - $this->tpl->assign('products_hits_all',$products_hits); | ||
677 | - } | ||
678 | - | ||
679 | - function viewProductOne($id,&$row){ | ||
680 | - $sql = "select p.*,b.text as brend_text from catalogs_products p left join catalogs_brends b ON b.id=p.brend_id where p.id=?"; | ||
681 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
682 | - $this->tpl->assign('product',$row); | ||
683 | - } | ||
684 | - | ||
685 | - function viewProductNembers($str_n){ | ||
686 | - $arr_id = explode(",",$str_n); | ||
687 | - $products = array(); | ||
688 | - foreach($arr_id as $id){ | ||
689 | - $count = $this->db->getOne("select count(*) from catalogs_keys_products_filters where filter_id=?",array(trim($id))); | ||
690 | - $limit = 1; $round = rand(0,($count-$limit)); | ||
691 | - $products[] = $this->db->getRow("select catalogs_products.* from catalogs_keys_products_filters Left Join catalogs_products ON catalogs_products.id=catalogs_keys_products_filters.product_id where catalogs_keys_products_filters.filter_id=? order by catalogs_keys_products_filters.product_id " . ((rand(1,1000)%2) ? "asc" : "desc") . " LIMIT $round,$limit",array(trim($id)),DB_FETCHMODE_ASSOC); | ||
692 | - } | ||
693 | - $this->tpl->assign('products_parent',$products); | ||
694 | - } | ||
695 | - | ||
696 | - function getProductSizeCine($id,&$products){ | ||
697 | - $res = $this->db->getAll("select * from catalogs_products_cine where product_id=?",array($id),DB_FETCHMODE_ASSOC); | ||
698 | - $i = 0; | ||
699 | - foreach($res as $row){ | ||
700 | - $products['size_' . $row['n']] = $row['size']; | ||
701 | - $products['cine_' . $row['n']] = $row['cine']; | ||
702 | - $products['metka_' . $row['n']] = $row['metka']; | ||
703 | - $products['id_cine_' . $row['n']] = $row['id']; | ||
704 | - $i++; | ||
705 | - } //print_r($products); | ||
706 | - } | ||
707 | - /* | ||
708 | - function getProductCine($id,$curs = null){ | ||
709 | - $sql = "select cine from catalogs_products where id=?"; | ||
710 | - $row = $this->db->getOne($sql,array($id)); | ||
711 | - return $row; | ||
712 | - }*/ | ||
713 | - | ||
714 | - function getProductCine($id){ | ||
715 | - $sql = "select catalogs_products.cine from catalogs_modifications left join catalogs_products on catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?"; | ||
716 | - return $this->db->getOne($sql,array($id)); | ||
717 | - } | ||
718 | - | ||
719 | - function viewProductCine($id){ | ||
720 | - $row = $this->db->getAll("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC",array($id),DB_FETCHMODE_ASSOC); | ||
721 | - $this->tpl->assign('product_cines',$row); | ||
722 | - } | ||
723 | - | ||
724 | - function viewCatalogsCurs(){ | ||
725 | - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); | ||
726 | - $this->tpl->assign('curs_uah',$uah); | ||
727 | - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); | ||
728 | - $this->tpl->assign('curs_uah_bank',$uah_bank); | ||
729 | - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); | ||
730 | - $this->tpl->assign('curs_usd',$usd); | ||
731 | - } | ||
732 | - | ||
733 | - function saveCurs($data){ | ||
734 | - $table_name = "catalogs_curs"; | ||
735 | - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; | ||
736 | - foreach($data as $key=>$value){ | ||
737 | - $this->db->autoExecute($table_name,array('curs'=>$value),$DB_AUTOQUERY,"type='$key'"); | ||
738 | - } | ||
739 | - } | ||
740 | - | ||
741 | - function viewVarCurs($curs){ | ||
742 | - $this->tpl->assign('curs',$curs); | ||
743 | - } | ||
744 | - | ||
745 | - function viewBasketProducts($session_basket,$curs = null,$discount = 0){ | ||
746 | - $products = array(); $i = 0; $cineAll = 0; | ||
747 | -// $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?"; | ||
748 | - $sql = "select catalogs_modifications.id,catalogs_products.cine,catalogs_products.name,catalogs_modifications.code,catalogs_modifications.size,catalogs_modifications.color,catalogs_modifications.pic,catalogs_modifications.pic_big from catalogs_modifications Left Join catalogs_products On catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?"; | ||
749 | - foreach($session_basket as $id){ | ||
750 | - $products_count = 1; | ||
751 | - if(count($products)){ | ||
752 | - foreach($products as $key=>$value){ | ||
753 | - if($value['id']==$id){$products_count=$products[$key]['products_count']+$products_count;$products[$key]['products_count']=$products_count;$products[$key]['products_cine_all']=$products[$key]['cine']*$products_count;$cineAll = $cineAll+$products[$key]['cine'];} | ||
754 | - }} | ||
755 | - if($products_count==1){ | ||
756 | - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); | ||
757 | - $products[$i] = $row; | ||
758 | - $products[$i]['products_count']=$products_count; | ||
759 | - $products[$i]['products_cine_all']=$products[$i]['cine']*$products_count; | ||
760 | - $cineAll = $cineAll+$products[$i]['products_cine_all']; | ||
761 | - $i++; | ||
762 | - } | ||
763 | - | ||
764 | - } | ||
765 | - /*print"<pre>"; | ||
766 | - print_r($products); | ||
767 | - print"</pre>";*/ | ||
768 | - $this->tpl->assign('cineAll',$cineAll); | ||
769 | - $this->tpl->assign('cineAll_discount',$cineAll - (($cineAll*$discount)/100)); | ||
770 | - $this->tpl->assign('basket_products',$products); //print_r($products); | ||
771 | - } | ||
772 | - | ||
773 | - | ||
774 | - function BasketUpload(&$session_basket,$proructs_count){ | ||
775 | - $session_basket = array(); | ||
776 | - foreach($proructs_count as $key=>$value){ | ||
777 | - for($i=0;$i<$value;$i++){ | ||
778 | - $session_basket[] = $key; | ||
779 | - } | ||
780 | - } | ||
781 | - } | ||
782 | - | ||
783 | - function sendOrder($data){ | ||
784 | - $mail = new PHPMailer(); | ||
785 | - $mail->CharSet = "windows-1251"; | ||
786 | - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
787 | - $mail->FromName = $data['order_name']; | ||
788 | - $mail->AddAddress("extremstyleshop@ukr.net","extremstyleshop"); | ||
789 | - $mail->AddAddress("shopextremstyle@gmail.com","shopextremstyle"); | ||
790 | - $mail->Subject = "Îôîðìèòü çàêàç ñ ÝêñòðèìÑòèëü"; | ||
791 | - $title = Mail::str_rus("Îôîðìèòü çàêàç"); | ||
792 | - $msg = ""; | ||
793 | - foreach($data['product_id'] as $key=>$value){ | ||
794 | - $msg .= "ID: ".$value." "; | ||
795 | - $msg .= "Íàçâàíèå: <b>".$data['product_name'][$key]."</b> "; | ||
796 | - $msg .= "Öåíà çà îäèí: ".$data['product_cine'][$key]." "; | ||
797 | - $msg .= "Êîëè÷åñòâî: ".$data['product_count'][$key]." "; | ||
798 | - $msg .= "Çà âåñü òîâàð: ".$data['product_cine_all'][$key]." "; | ||
799 | - $msg .= "<br>"; | ||
800 | - } | ||
801 | - $msg .= "Îáùàÿ ñóìà: ".$data['cineAll']; | ||
802 | - $msg .= "<br>"; | ||
803 | - /* $msg .= "Ñêèäêà: ".$data['discount']." %"; | ||
804 | - $msg .= "<br>"; */ | ||
805 | - $msg .= "Èòîãî ê îïëàòå: ".$data['cineAll_discount']; | ||
806 | - $msg .= "<br><br><br>"; | ||
807 | - $msg .= "Êîíòàêòíûå äàííûå:"; | ||
808 | - $msg .= "<br>"; | ||
809 | - $msg .= "Èìÿ: ".$data['order_name']; | ||
810 | - $msg .= "<br>"; | ||
811 | - $msg .= "Àäðåñ: ".$data['order_adress']; | ||
812 | - $msg .= "<br>"; | ||
813 | - $msg .= "E-mail: ".$data['order_email']; | ||
814 | - $msg .= "<br>"; | ||
815 | - $msg .= "Êîíòàêòíûé òåëåôîí: ".$data['order_phone']; | ||
816 | - $msg .= "<br>"; | ||
817 | - $msg .= "Ìîáèëüíûé òåëåôîí: ".$data['order_phonemob']; | ||
818 | - $msg .= "<br>"; | ||
819 | - $msg .= "Êîììåíòàðèé: ".$data['order_comment']; | ||
820 | -// $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua"; | ||
821 | -// Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg)); | ||
822 | - $mail->MsgHTML($msg); | ||
823 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
824 | - $mail->ClearAddresses(); | ||
825 | - $mail->ClearAttachments(); | ||
826 | - | ||
827 | - $this->sendOrderXML($data); | ||
828 | - } | ||
829 | - | ||
830 | - | ||
831 | - function sendOrderXML($data){ | ||
832 | - $mail = new PHPMailer(); | ||
833 | - $mail->CharSet = "windows-1251"; | ||
834 | - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
835 | - $mail->FromName = $data['order_name']; | ||
836 | - $mail->AddAddress("extremshop@portal.myoffice.biz.ua","extremshop"); | ||
837 | - $mail->Subject = "xml çàêàç ñ ÝêñòðèìÑòèëü"; | ||
838 | - $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; | ||
839 | - $xml = '<?xml version="1.0" encoding="windows-1251" ?>'; | ||
840 | - $xml .= '<Order orderNum="'.mktime().'">'; | ||
841 | - foreach($data['product_id'] as $key=>$value){ | ||
842 | - $xml .= "<OrderItem ID='".$data['product_code'][$key]."'>"; | ||
843 | - $xml .= "<ProductName>".$data['product_name2'][$key]."</ProductName>"; | ||
844 | - $xml .= "<Size>".$data['product_size'][$key]."</Size>"; | ||
845 | - $xml .= "<Color>".$data['product_color'][$key]."</Color>"; | ||
846 | - $xml .= "<Price>".$data['product_price'][$key]."</Price>"; | ||
847 | - $xml .= "<Count>".$data['product_count'][$key]."</Count>"; | ||
848 | - $xml .= "</OrderItem>"; | ||
849 | - } | ||
850 | - $xml .= '<CustomerInfo>'; | ||
851 | - $xml .= '<Name>'.$data['order_name'].'</Name>'; | ||
852 | - $xml .= '<Mobile>'.$data['order_phone'].'</Mobile>'; | ||
853 | - $xml .= '<Email>'.$data['order_email'].'</Email>'; | ||
854 | - $xml .= '</CustomerInfo>'; | ||
855 | - $xml .= '<DeliveryInfo>'; | ||
856 | - $xml .= '<City>Óêðàèíà</City>'; | ||
857 | - $xml .= '<Address>'.$data['order_adress'].'</Address>'; | ||
858 | - $xml .= '<DeliveryType>Äîñòàâêà</DeliveryType>'; | ||
859 | - $xml .= '</DeliveryInfo>'; | ||
860 | - $xml .= '<Comment>'.$data['order_comment'].'</Comment>'; | ||
861 | - $xml .= '</Order>'; | ||
862 | - $tmpfname = tempnam("tmp", "FOO"); | ||
863 | - $handle = fopen($tmpfname, "w"); | ||
864 | - fwrite($handle, $xml); | ||
865 | - $mail->AddAttachment($tmpfname, 'order.xml'); | ||
866 | - if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;} | ||
867 | - fclose($handle); | ||
868 | - unlink($tmpfname); | ||
869 | - $mail->ClearAddresses(); | ||
870 | - $mail->ClearAttachments(); | ||
871 | - // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml)); | ||
872 | - // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml)); | ||
873 | - } | ||
874 | - | ||
875 | - function saveOrder($data,$userID){ | ||
876 | - $table_name = "catalogs_orders"; | ||
877 | - if(isset($data['update_id']) && $data['update_id']>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$id = $data['update_id']; $where = sprintf("id='%d'",$id);} | ||
878 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$id = $this->db->nextId('mySequence_'.$table_name);$where = null;} | ||
879 | - $fields_values = array('id'=>$id,'user_id'=>$userID,'name' => $data['order_name'],'email' => $data['order_email'],'adress' => $data['order_adress'],'phone' => $data['order_phone'],'phonemob' => $data['order_phonemob'],'comment' => $data['order_comment'],'mktime'=>mktime()); | ||
880 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where); | ||
881 | - if(isset($data['product_id'])){ | ||
882 | - foreach($data['product_id'] as $key=>$value){ | ||
883 | - $this->db->autoExecute("catalogs_orders_products",array('order_id'=>$id,'product_id'=>$value,'count'=>$data['product_count'][$key]),DB_AUTOQUERY_INSERT); | ||
884 | - } | ||
885 | - } | ||
886 | - } | ||
887 | - | ||
888 | - function deleteOrder($id){ | ||
889 | - $this->db->query("delete from catalogs_orders where id=?",array($id)); | ||
890 | - $this->db->query("delete from catalogs_orders_products where order_id=?",array($id)); | ||
891 | - } | ||
892 | - | ||
893 | - function updateOrder($data){ | ||
894 | - $table_name = "catalogs_orders"; | ||
895 | - $fields_values = array('name' => $data['order_name'],'email' => $data['order_email'],'adress' => $data['order_adress'],'phone' => $data['order_phone'],'comment' => $data['order_comment'],'mktime'=>mktime()); | ||
896 | - if(isset($data['order_active']))$fields_values['active'] = 1; | ||
897 | - else $fields_values['active'] = 0; | ||
898 | - $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,sprintf("id='%d'",$data['update_id'])); | ||
899 | - } | ||
900 | - | ||
901 | - function updateOrderProducts($data){ | ||
902 | - foreach($data['product_id'] as $key=>$value){ | ||
903 | - if($data['product_count'][$value]<1){$this->db->query("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");} | ||
904 | - else{$this->db->autoExecute("catalogs_orders_products",array('count'=>$data['product_count'][$value]),DB_AUTOQUERY_UPDATE,"order_id='{$data['order_id']}' AND product_id='$value'");} | ||
905 | - } | ||
906 | - } | ||
907 | - | ||
908 | - function viewOrder($id){ | ||
909 | - $row = $this->db->getRow("select * from catalogs_orders where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
910 | - $this->tpl->assign('order', $row); | ||
911 | - } | ||
912 | - | ||
913 | - function viewOrderProducts($order_id){ | ||
914 | - $res = $this->db->getAll("select p.*,op.*,pr.name,pr.pic,pr.pic_big from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id Left join catalogs_products pr On pr.id=p.product_id where order_id=?",array($order_id),DB_FETCHMODE_ASSOC); | ||
915 | - $sum = 0; | ||
916 | - foreach($res as $key=>$row){ | ||
917 | - $sum = $sum + ($row['cine']*$row['count']); | ||
918 | - $res[$key]['cine_all'] = ($row['cine']*$row['count']); | ||
919 | - } | ||
920 | - $discount = $this->db->getOne('select catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id where catalogs_orders.id=?',array($order_id)); | ||
921 | - $this->tpl->assign('cine', array('sum'=>$sum,'discount'=>$discount,'sum_discount'=>($sum - (($sum*$discount)/100)) )); | ||
922 | - $this->tpl->assign('basket_products', $res); | ||
923 | - } | ||
924 | - | ||
925 | - function viewOrders($params = array()){ | ||
926 | - $search = array(); | ||
927 | - if(isset($params['userID']) && $params['userID']>0)$search[] = sprintf("catalogs_orders.user_id='%d'",$params['userID']); | ||
928 | - $sql = "select catalogs_orders.*,catalogs_users.login as user_login,catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id WHERE 1=1 "; | ||
929 | - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; | ||
930 | - $sql .= " order by mktime desc"; | ||
931 | - $pagerOptions = Array( | ||
932 | - 'mode' => 'Sliding', | ||
933 | - 'delta' => 16, | ||
934 | - 'perPage' => 50, | ||
935 | - 'linkClass'=>"link_class", | ||
936 | - 'curPageLinkClassName'=>"link_class_active", | ||
937 | - 'spacesBeforeSeparator' => 1, | ||
938 | - 'spacesAfterSeparator' => 1 | ||
939 | - ); | ||
940 | - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); | ||
941 | - foreach($res['data'] as $key=>$value){ | ||
942 | - $res['data'][$key]['sum'] = $this->getOrderProductsSum($value['id']); | ||
943 | - $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum']*$value['discount'])/100); | ||
944 | - } | ||
945 | - $this->tpl->assign('ordersData', $res); | ||
946 | - } | ||
947 | - | ||
948 | - function getOrderProductsSum($order_id){ | ||
949 | - $res = $this->db->getAll("select op.*,p.cine from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id where op.order_id=?",array($order_id),DB_FETCHMODE_ASSOC); | ||
950 | - // print_r($res); | ||
951 | - $sum = 0; | ||
952 | - foreach($res as $row){ | ||
953 | - $sum = $sum + ($row['cine']*$row['count']); | ||
954 | - } | ||
955 | - return $sum; | ||
956 | - } | ||
957 | - | ||
958 | - function SaveBrend($data){ | ||
959 | - $table_name = "catalogs_brends"; | ||
960 | - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
961 | - $fields_values = array('rubric_id'=>$data['rubric_id'],'name'=>$data['brend'],'text'=>$data['text'],'seo'=>$data['seo'],'sort'=>$data['sort'],'meta_title'=>$data['meta_title'],'meta_description'=>$data['meta_description'],'meta_keywords'=>$data['meta_keywords']); | ||
962 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
963 | - } | ||
964 | - | ||
965 | - function viewBrends($type = false){ | ||
966 | - $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id "; | ||
967 | - if($type!=false)$sql .= "where b.type='$type'"; | ||
968 | - $sql .= " Order by b.sort Asc"; | ||
969 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
970 | - $this->tpl->assign('brends',$row); | ||
971 | - } | ||
972 | - | ||
973 | - function viewBrendsGroup($params = array()){ | ||
974 | - $sql = "select * from catalogs_brends where 1=1 "; | ||
975 | - if(isset($params['rubID'])){ | ||
976 | - $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']); | ||
977 | - $rubric_id = ($rubric_id==0)?$params['rubID']:$rubric_id; | ||
978 | - $sql .= "and rubric_id='".$rubric_id."'"; | ||
979 | - } | ||
980 | - $sql .= " Group by name Order by sort Asc"; | ||
981 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
982 | - $this->tpl->assign('brends',$row); | ||
983 | - } | ||
984 | - | ||
985 | - function SaveCity($data){ | ||
986 | - $table_name = "catalogs_cities"; | ||
987 | - $DB_AUTOQUERY = (isset($data['update_id']) && $data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; | ||
988 | - $fields_values = array('name'=>$data['name']); | ||
989 | - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); | ||
990 | - return mysql_insert_id(); | ||
991 | - } | ||
992 | - | ||
993 | - function is_city($name){ | ||
994 | - return $this->db->getOne('select id from catalogs_cities where name=?',array($name)); | ||
995 | - } | ||
996 | - | ||
997 | - function viewCityMod($code){ | ||
998 | - $sql = "select c.name from catalogs_keys_products_cities k left join catalogs_cities c on c.id=k.city_id where k.mod_code=? and k.count>0"; | ||
999 | - $row = $this->db->getCol($sql,"name",array($code)); | ||
1000 | - return implode(', ',$row); | ||
1001 | - } | ||
1002 | - | ||
1003 | - function viewCitiesProductID($id){ | ||
1004 | - $sql = "select city_id from catalogs_keys_products_cities where product_id=?"; | ||
1005 | - $row = $this->db->getCol($sql,"city_id",array($id)); | ||
1006 | - $this->tpl->assign('product_cities',$row); | ||
1007 | - } | ||
1008 | - | ||
1009 | - function viewCities($type = false){ | ||
1010 | - $sql = "select * from catalogs_cities "; | ||
1011 | - $sql .= " Order by name Asc"; | ||
1012 | - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); | ||
1013 | - $this->tpl->assign('cities',$row); | ||
1014 | - } | ||
1015 | - | ||
1016 | - function viewCitiesProduct($id){ | ||
1017 | - $sql = "select catalogs_cities.* from catalogs_keys_products_cities left join catalogs_cities on catalogs_cities.id=catalogs_keys_products_cities.city_id Where catalogs_keys_products_cities.product_id=? "; | ||
1018 | - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); | ||
1019 | - $this->tpl->assign('cities',$row); | ||
1020 | - } | ||
1021 | - | ||
1022 | - function viewCity($id){ | ||
1023 | - $row = $this->db->getRow("select * from catalogs_cities where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
1024 | - $this->tpl->assign('city', $row); | ||
1025 | - } | ||
1026 | - | ||
1027 | - function deleteCity($id){ | ||
1028 | - $this->db->query("delete from catalogs_cities where id=?",array($id)); | ||
1029 | - $this->delete_keysCitiesProduct($id); | ||
1030 | - } | ||
1031 | - | ||
1032 | - function delete_keysCitiesProduct($id){ | ||
1033 | - $sql = "delete from catalogs_keys_products_cities where city_id=?"; | ||
1034 | - $this->db->query($sql,array($id)); | ||
1035 | - } | ||
1036 | - | ||
1037 | - function SaveYears($data){ | ||
1038 | - $table_name = "catalogs_years"; | ||
1039 | - foreach($data['filter'] as $key=>$name){ | ||
1040 | - if(strlen($name)>0){ | ||
1041 | - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} | ||
1042 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} | ||
1043 | - $this->db->autoExecute($table_name,array('name'=>$name,'rubric_id'=>$data['rubric_id']),$DB_AUTOQUERY,$where); | ||
1044 | - } | ||
1045 | - } | ||
1046 | - } | ||
1047 | - | ||
1048 | - function viewYearsProductID($id){ | ||
1049 | - $sql = "select year_id from catalogs_keys_products_years where product_id=?"; | ||
1050 | - $row = $this->db->getCol($sql,"year_id",array($id)); | ||
1051 | - $this->tpl->assign('product_years',$row); | ||
1052 | - } | ||
1053 | - | ||
1054 | - function viewYears($rubric_id){ | ||
1055 | - $row = $this->db->getAll("select * from catalogs_years where rubric_id=? order by id",array($rubric_id),DB_FETCHMODE_ASSOC); | ||
1056 | - $this->tpl->assign('years', $row); | ||
1057 | - } | ||
1058 | - | ||
1059 | - function deleteYearsRubric_id($id){ | ||
1060 | - $this->db->query("delete from catalogs_years where rubric_id=?",array($id)); | ||
1061 | - $this->delete_keysYearsRubric($id); | ||
1062 | - } | ||
1063 | - | ||
1064 | - function delete_keysYearsRubric($id){ | ||
1065 | - $sql = "delete from catalogs_keys_products_years where rubric_id=?"; | ||
1066 | - $this->db->query($sql,array($id)); | ||
1067 | - } | ||
1068 | - | ||
1069 | - function deleteYear($id){ | ||
1070 | - $this->db->query("delete from catalogs_years where id=?",array($id)); | ||
1071 | - $this->delete_keysYearsProduct($id); | ||
1072 | - } | ||
1073 | - | ||
1074 | - function delete_keysYearsProduct($id){ | ||
1075 | - $sql = "delete from catalogs_keys_products_years where year_id=?"; | ||
1076 | - $this->db->query($sql,array($id)); | ||
1077 | - } | ||
1078 | - | ||
1079 | - function SaveFilters($data){ | ||
1080 | - $table_name = "catalogs_filters"; | ||
1081 | - foreach($data['filter'] as $key=>$name){ | ||
1082 | - if(strlen($name)>0){ | ||
1083 | - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} | ||
1084 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} | ||
1085 | - $this->db->autoExecute($table_name,array('name'=>$name,'rubric_id'=>$data['rubric_id'],"sort"=>$data['sort'][$key]),$DB_AUTOQUERY,$where); | ||
1086 | - } | ||
1087 | - } | ||
1088 | - } | ||
1089 | - | ||
1090 | - function viewFilterProductID($id){ | ||
1091 | - $sql = "select filter_id from catalogs_keys_products_filters where product_id=?"; | ||
1092 | - $row = $this->db->getCol($sql,"filter_id",array($id)); | ||
1093 | - $this->tpl->assign('product_filters',$row); | ||
1094 | - } | ||
1095 | - | ||
1096 | - function deleteFilter($id){ | ||
1097 | - $this->db->query("delete from catalogs_filters where id=?",array($id)); | ||
1098 | - $this->delete_keysFilterProduct($id); | ||
1099 | - } | ||
1100 | - | ||
1101 | - function deleteFiltersRubric_id($rubric_id){ | ||
1102 | - $this->db->query("delete from catalogs_filters where rubric_id=?",array($rubric_id)); | ||
1103 | - $this->delete_keysFilterRubric($rubric_id); | ||
1104 | - } | ||
1105 | - | ||
1106 | - function delete_keysFilterProduct($id){ | ||
1107 | - $sql = "delete from catalogs_keys_products_filters where filter_id=?"; | ||
1108 | - $this->db->query($sql,array($id)); | ||
1109 | - } | ||
1110 | - | ||
1111 | - function delete_keysFilterRubric($id){ | ||
1112 | - $sql = "delete from catalogs_keys_products_filters where rubric_id=?"; | ||
1113 | - $this->db->query($sql,array($id)); | ||
1114 | - } | ||
1115 | - | ||
1116 | - function viewFilters($rubric_id){ | ||
1117 | - $row = $this->db->getAll("select * from catalogs_filters where rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC); | ||
1118 | - $this->tpl->assign('filters', $row); | ||
1119 | - } | ||
1120 | - | ||
1121 | - function viewBrend($id){ | ||
1122 | - $row = $this->db->getRow("select * from catalogs_brends where id=?",array($id),DB_FETCHMODE_ASSOC); | ||
1123 | - $this->tpl->assign('brend', $row); | ||
1124 | - } | ||
1125 | - | ||
1126 | - function viewBrendName($name){ | ||
1127 | - $name = iconv("utf-8", "windows-1251", $name); | ||
1128 | - $sql = "select * from catalogs_brends where name=? and seo>'' limit 1"; | ||
1129 | - $row = $this->db->getRow($sql,array($name),DB_FETCHMODE_ASSOC); | ||
1130 | - $this->tpl->assign('brend_seo', $row); | ||
1131 | - } | ||
1132 | - | ||
1133 | - function getBrendIDs_name($name){ $name = iconv("utf-8", "windows-1251", $name); | ||
1134 | - $sql = "select id from catalogs_brends where name=?"; | ||
1135 | - return $this->db->getCol($sql,"id",array($name)); | ||
1136 | - } | ||
1137 | - | ||
1138 | - function deleteBrend($id){ | ||
1139 | - $this->db->query("delete from catalogs_brends where id=?",array($id)); | ||
1140 | - } | ||
1141 | - | ||
1142 | - function viewAkciiProductID($id){ | ||
1143 | - $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?"; | ||
1144 | - $row = $this->db->getCol($sql,"rubric_id",array($id)); | ||
1145 | - $this->tpl->assign('product_akcii',$row); | ||
1146 | - } | ||
1147 | - | ||
1148 | - function import_saveRubric($name,$parent_id){ | ||
1149 | - $id = $this->db->getOne("select id from catalogs_rubrics where name=? and parent_id=?",array($name,$parent_id)); | ||
1150 | - if( !$id ){ | ||
1151 | - $this->db->autoExecute("catalogs_rubrics",array('name'=>$name,'parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1)),DB_AUTOQUERY_INSERT); | ||
1152 | - return mysql_insert_id(); | ||
1153 | - } | ||
1154 | - return $id; | ||
1155 | - } | ||
1156 | - | ||
1157 | - function import_saveBrend($name,$rubric_id){ | ||
1158 | - //getRubricParent(); | ||
1159 | - $id = $this->db->getOne("select id from catalogs_brends where name=? and rubric_id=?",array($name,$rubric_id)); | ||
1160 | - if( !$id ){ | ||
1161 | - $this->db->autoExecute("catalogs_brends",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); | ||
1162 | - return mysql_insert_id(); | ||
1163 | - } | ||
1164 | - return $id; | ||
1165 | - } | ||
1166 | - | ||
1167 | - function import_saveFilters($rubric_id,$str){ | ||
1168 | - if(!$str)return array(); | ||
1169 | - $row_str = explode(",",trim($str)); | ||
1170 | - $arr_id = array(); | ||
1171 | - foreach($row_str as $str){ | ||
1172 | - $name = trim($str); | ||
1173 | - $id = $this->db->getOne("select id from catalogs_filters where rubric_id=? and name=?",array($rubric_id,$name)); | ||
1174 | - if( !$id ){ | ||
1175 | - $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); | ||
1176 | - $id = mysql_insert_id(); | ||
1177 | - } | ||
1178 | - $arr_id[] = $id; | ||
1179 | - } | ||
1180 | - return $arr_id; | ||
1181 | - } | ||
1182 | - | ||
1183 | - function import_saveYear($rubric_id,$name){ | ||
1184 | - $id = $this->db->getOne("select id from catalogs_years where rubric_id=? and name=?",array($rubric_id,$name)); | ||
1185 | - if( !$id ){ | ||
1186 | - $this->db->autoExecute("catalogs_years",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); | ||
1187 | - $id = mysql_insert_id(); | ||
1188 | - } | ||
1189 | - return ($id)?array($id):array(); | ||
1190 | - } | ||
1191 | - | ||
1192 | - function import_updateProductCine($product_id,$row,$line=''){ //print"<pre>";print_r($row);print"</pre>"; | ||
1193 | - IF($row[3]>0){ | ||
1194 | - if($row[2]<1){$cine=$row[1];$cine_last=0;} | ||
1195 | - else {$cine=$row[2];$cine_last=(($row[1]>0)?$row[1]:$row[2]);} | ||
1196 | - $this->db->autoExecute("catalogs_products",array('cine'=>$cine,'cine_last'=>$cine_last),DB_AUTOQUERY_UPDATE,"id='$product_id'"); | ||
1197 | - } | ||
1198 | - /* if($this->getModificationActive($row[0])!=$row[3]){ | ||
1199 | - $prefix = ($row[3]==0)?'-':'+'; | ||
1200 | - $this->updateProductModificationCountPrefix($product_id,$prefix); | ||
1201 | - } */ | ||
1202 | - $city = trim($row[4]); | ||
1203 | - if(strlen($city)>0){ //print $city; | ||
1204 | - $city_id = $this->is_city($city); | ||
1205 | - if(!$city_id){$city_id = $this->SaveCity(array('name'=>$city));} | ||
1206 | - if($this->getKeysModificationCity($row[0], $city_id)){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "mod_code='".$row[0]."' and city_id='".$city_id."'";} | ||
1207 | - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;} | ||
1208 | - //print $city_id .'--'.$where."<br>"; | ||
1209 | - $s = $this->db->autoExecute("catalogs_keys_products_cities",array('count'=>$row[3],'product_id'=>$product_id,'mod_code'=>$row[0],'city_id'=>$city_id),$DB_AUTOQUERY,$where); | ||
1210 | - // if (PEAR::isError($s)) die($s->getMessage()); | ||
1211 | - } | ||
1212 | - $active = $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0",array($row[0])); | ||
1213 | - if($this->db->getOne("select count(*) from catalogs_modifications where code=?",array($row[0]))>0){ | ||
1214 | - $this->db->autoExecute("catalogs_modifications",array('active'=>$active,'is_update'=>1,'prefix'=>$row[5]),DB_AUTOQUERY_UPDATE,"code='".$row[0]."'"); | ||
1215 | - }else{ | ||
1216 | - $this->saveCsvMod($line); | ||
1217 | - } | ||
1218 | - } | ||
1219 | - | ||
1220 | - function saveCsvMod($line){ | ||
1221 | - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv"; | ||
1222 | - $handle = fopen($tmpfname, "a"); | ||
1223 | - fwrite($handle,$line); | ||
1224 | - fclose($handle); | ||
1225 | - } | ||
1226 | - | ||
1227 | - function getKeysModificationCity($code, $city_id){ | ||
1228 | - return $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id)); | ||
1229 | - } | ||
1230 | - | ||
1231 | - function getProductID($name){ | ||
1232 | - $id = $this->db->getOne("select id from catalogs_products where name=?",array($name)); | ||
1233 | - return $id; | ||
1234 | - } | ||
1235 | - | ||
1236 | - function getModificationActive($code){ | ||
1237 | - return $this->db->getOne("select active from catalogs_modifications where code=?",array($code)); | ||
1238 | - } | ||
1239 | - | ||
1240 | - function updateProduct_countModification($product_id,$count){ | ||
1241 | - $this->db->autoExecute("catalogs_products",array('count_modifications'=>$count),DB_AUTOQUERY_UPDATE,"id='$product_id'"); | ||
1242 | - } | ||
1243 | - | ||
1244 | - function updateProductModificationCountPrefix($product_id,$prefix = "+"){ | ||
1245 | -// print $product_id; | ||
1246 | - $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?"; | ||
1247 | - $this->db->query($sql,array($product_id)); | ||
1248 | - } | ||
1249 | - | ||
1250 | - function exportCSV(){ | ||
1251 | - $tmpfname = "tmp/price.csv"; | ||
1252 | - $handle = fopen($tmpfname, "w"); | ||
1253 | - // fwrite($handle, $xml); | ||
1254 | - $res = $this->db->getAll('select p.id,p.rubric_id,r.name,r2.name,b.name as brend,p.name,p.about,p.text,null,p.sex,null,p.cine,p.cine_last,p.strnumber,p.active,p.pic_big from catalogs_products p left join catalogs_rubrics r on r.id=p.rubric_id left join catalogs_rubrics r2 on r2.id=p.rubric_parent_id left join catalogs_brends b on b.id=p.brend_id',array()); | ||
1255 | - foreach($res as $key=>$row){ | ||
1256 | - $list = $row; | ||
1257 | - $mod_res = $this->db->getAll('select code,size,color,pic_big,active from catalogs_modifications where product_id=?',array($row[0])); | ||
1258 | - foreach($mod_res as $mod_row){$list[] = implode('=',$mod_row);} | ||
1259 | - | ||
1260 | - $f_row = $this->db->getCol("select name from catalogs_filters where rubric_id=?",'name',array($list[1])); | ||
1261 | - $list[8]=implode(',',$f_row); | ||
1262 | - | ||
1263 | - switch($list[9]){ | ||
1264 | - case 1 : $list[9] = 'ìóæñêîé'; break; | ||
1265 | - case 2 : $list[9] = 'æåíñêèé'; break; | ||
1266 | - case 3 : $list[9] = 'äåòñêèé'; break; | ||
1267 | - case 4 : $list[9] = 'óíèñåêñ'; break; | ||
1268 | - default : $list[9] = 'ìóæñêîé'; break; | ||
1269 | - } | ||
1270 | - | ||
1271 | - $y_row = $this->db->getCol("select name from catalogs_years where rubric_id=? order by id desc limit 1",'name',array($list[1])); | ||
1272 | - $list[10]=implode(',',$y_row); | ||
1273 | - | ||
1274 | - | ||
1275 | - unset($list[0]);unset($list[1]); | ||
1276 | - //print_r($list);exit; | ||
1277 | - File_FGetCSV::fputcsv($handle,$list,';'); | ||
1278 | - } | ||
1279 | - | ||
1280 | - fclose($handle); | ||
1281 | - | ||
1282 | - $params = array( | ||
1283 | - 'file' => $tmpfname, | ||
1284 | - 'contenttype' => 'application/xls', | ||
1285 | - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'), | ||
1286 | - 'cache' => false | ||
1287 | - ); | ||
1288 | - $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë | ||
1289 | - if ($error === true) { | ||
1290 | - //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè | ||
1291 | - } | ||
1292 | - | ||
1293 | - unlink($tmpfname); | ||
1294 | - } | ||
1295 | - | ||
1296 | - function exportModCSV(){ | ||
1297 | - $tmpfname = "tmp/price_mod.csv"; | ||
1298 | - $handle = fopen($tmpfname, "w"); | ||
1299 | - $res = $this->db->getAll('select m.code,p.cine,p.cine_last,m.active,null,m.prefix,m.is_update From catalogs_modifications m Left join catalogs_products p on p.id=m.product_id'); | ||
1300 | - foreach($res as $key=>$row){ | ||
1301 | - File_FGetCSV::fputcsv($handle,$row,';'); | ||
1302 | - } | ||
1303 | - fclose($handle); | ||
1304 | - $params = array( | ||
1305 | - 'file' => $tmpfname, | ||
1306 | - 'contenttype' => 'application/xls', | ||
1307 | - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'file_1.csv'), | ||
1308 | - 'cache' => false | ||
1309 | - ); | ||
1310 | - $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë | ||
1311 | - if ($error === true) { | ||
1312 | - //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè | ||
1313 | - } | ||
1314 | - | ||
1315 | - unlink($tmpfname); | ||
1316 | - $this->db->autoExecute("catalogs_modifications",array('is_update'=>0),DB_AUTOQUERY_UPDATE); | ||
1317 | - } | ||
1318 | - | ||
1319 | - function importCSV($upload){ error_reporting(0); | ||
1320 | - if($upload['file']['name']=="file_1.csv"){print"Îøèáêà! Ôàéë öåí!";exit;} | ||
1321 | - //$arr_line = file($upload['file']['tmp_name']); | ||
1322 | - $f = fopen($upload['file']['tmp_name'], "r") or die("Îøèáêà!"); | ||
1323 | - // print"<pre>"; | ||
1324 | - for ($i=0; $row_line=File_FGetCSV::fgetcsv($f,15000000,";"); $i++) { | ||
1325 | - // foreach($arr_line as $line){ | ||
1326 | - //$row_line = fgetcsv(";",$line); | ||
1327 | - $rubric_id = $this->import_saveRubric($row_line[0],0); | ||
1328 | - $rubric_parent_id = $this->import_saveRubric($row_line[1],$rubric_id); | ||
1329 | - $brend_id = $this->import_saveBrend($row_line[2],$rubric_parent_id); | ||
1330 | - $pruduct_name = trim($row_line[3]); | ||
1331 | - $pruduct_about = trim($row_line[4]); | ||
1332 | - $pruduct_text = trim($row_line[5]); | ||
1333 | - switch($row_line[7]){ | ||
1334 | - case 'ìóæñêîé' : $pruduct_sex = 1; break; | ||
1335 | - case 'æåíñêèé' : $pruduct_sex = 2; break; | ||
1336 | - case 'äåòñêèé' : $pruduct_sex = 3; break; | ||
1337 | - case 'óíèñåêñ' : $pruduct_sex = 4; break; | ||
1338 | - default : $pruduct_sex = 0; break; | ||
1339 | - } | ||
1340 | - $pruduct_date = trim($row_line[8]); | ||
1341 | - $pruduct_cine = trim($row_line[9]); | ||
1342 | - $pruduct_cine_last = trim($row_line[10]); | ||
1343 | - if($pruduct_cine<1){$pruduct_cine=$pruduct_cine_last;$pruduct_cine_last=0;} | ||
1344 | - | ||
1345 | - $pruduct_strnumber = trim($row_line[11]); | ||
1346 | - $pruduct_active = trim($row_line[12]); | ||
1347 | - $pruduct_pic_tmp = trim($row_line[13]); | ||
1348 | - $pruduct_update_id = $this->getProductID($pruduct_name); | ||
1349 | - $upload_pruduct = (strlen($pruduct_pic_tmp)>0 && is_file("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp"))?array('pic'=>array('tmp_name'=>"./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",'name'=>$pruduct_pic_tmp,'big'=>true)):null; | ||
1350 | - $product_id = $this->saveProduct( | ||
1351 | - array('rubric_id'=>$rubric_parent_id, | ||
1352 | - 'rubric_parent_id'=>$rubric_parent_id, | ||
1353 | - 'brend_id'=>$brend_id, | ||
1354 | - 'name'=>$pruduct_name, | ||
1355 | - 'about'=>$pruduct_about, | ||
1356 | - 'text'=>$pruduct_text, | ||
1357 | - 'sex'=>$pruduct_sex, | ||
1358 | - 'date'=>$pruduct_date, | ||
1359 | - 'cine'=>$pruduct_cine, | ||
1360 | - 'cine_last'=>$pruduct_cine_last, | ||
1361 | - 'strnumber'=>$pruduct_strnumber, | ||
1362 | - 'active'=>$pruduct_active, | ||
1363 | - 'meta_title'=>$pruduct_name, | ||
1364 | - 'meta_description'=>$pruduct_name, | ||
1365 | - 'meta_keywords'=>$pruduct_name, | ||
1366 | - 'meta_about'=>$pruduct_name, | ||
1367 | - 'filter'=>$this->import_saveFilters($rubric_parent_id,$row_line[6]), | ||
1368 | - 'years'=>$this->import_saveYear($rubric_parent_id,$pruduct_date), | ||
1369 | - 'akcii'=>array(), | ||
1370 | - 'update_id'=>$pruduct_update_id), | ||
1371 | - $upload_pruduct | ||
1372 | - ); | ||
1373 | - $this->deleteProductModifications($product_id,true); | ||
1374 | - $m_i = 0; | ||
1375 | - for($i=14;$i<count($row_line);$i++){ | ||
1376 | - $arr_mod = trim($row_line[$i]); | ||
1377 | - if(strlen($arr_mod)>0){ | ||
1378 | - $row_mod = explode("=",$arr_mod); | ||
1379 | - $upload_mod = (strlen($row_mod[3])>0 && is_file("./uploaded/pic/catalogs/modifications/big/".$row_mod[3]))?array('pic'=>array('tmp_name'=>"./uploaded/pic/catalogs/modifications/big/".$row_mod[3],'name'=>$row_mod[3],'big'=>true)):null; | ||
1380 | - | ||
1381 | - $this->SaveModification( | ||
1382 | - array('product_id'=>$product_id, | ||
1383 | - 'code'=>$row_mod[0], | ||
1384 | - 'size'=>$row_mod[1], | ||
1385 | - 'color'=>$row_mod[2], | ||
1386 | - 'active'=>$row_mod[4] | ||
1387 | - ),$upload_mod | ||
1388 | - ); | ||
1389 | - if($row_mod[4]>0)$m_i++; | ||
1390 | - } | ||
1391 | - } | ||
1392 | - $this->updateProduct_countModification($product_id,$m_i); | ||
1393 | - //$this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]); | ||
1394 | - //$strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data); | ||
1395 | - //print_r($row_line); | ||
1396 | - if(($i%30)==0)sleep(1); | ||
1397 | - } | ||
1398 | - // print"</pre>"; | ||
1399 | - | ||
1400 | - } | ||
1401 | - | ||
1402 | - function importCSV_cine($upload){ | ||
1403 | - if($upload['file']['name']!="file_1.csv"){print"Îøèáêà! Òîëüêî file_1.csv";exit;} | ||
1404 | - $arr_line = file($upload['file']['tmp_name']); | ||
1405 | - //print"<pre>"; | ||
1406 | - $i = 0; | ||
1407 | - foreach($arr_line as $line){ | ||
1408 | - $row_line = explode(";",$line); | ||
1409 | - $this->import_updateProductCine($this->getModificationProduct_id($row_line[0]),$row_line,$line); | ||
1410 | - if(($i%30)==0)sleep(1); | ||
1411 | - $i++; | ||
1412 | - // print_r($row_line); | ||
1413 | - }//print"</pre>"; | ||
1414 | - $this->updateCountModificationProducts(); | ||
1415 | - } | ||
1416 | - | ||
1417 | - function CronImportCSV_cine($upload){ | ||
1418 | - if($upload['file']['name']!="file_1.csv"){print"Îøèáêà! Òîëüêî file_1.csv";exit;} | ||
1419 | - $arr_line = file($upload['file']['tmp_name']); | ||
1420 | - //print"<pre>"; | ||
1421 | - $i = 0; | ||
1422 | - foreach($arr_line as $line){ | ||
1423 | - $row_line = explode(";",$line); | ||
1424 | - $this->import_updateProductCine($this->getModificationProduct_id($row_line[0]),$row_line,$line); | ||
1425 | - if(($i%30)==0)sleep(1); | ||
1426 | - $i++; | ||
1427 | - // print_r($row_line); | ||
1428 | - }//print"</pre>"; | ||
1429 | - //$this->updateCountModificationProducts(); | ||
1430 | - } | ||
1431 | - | ||
1432 | - function updateCountModificationProducts(){ | ||
1433 | - $this->db->autoExecute("catalogs_products",array('count_modifications'=>0),DB_AUTOQUERY_UPDATE); | ||
1434 | - $res = $this->db->getAll("select * from catalogs_products",array(),DB_FETCHMODE_ASSOC); | ||
1435 | - $i = 0; | ||
1436 | - foreach($res as $row){ | ||
1437 | - $count = $this->db->getOne("select count(*) from catalogs_modifications where product_id=? and active>0",array($row['id'])); | ||
1438 | - $this->db->autoExecute("catalogs_products",array('count_modifications'=>$count),DB_AUTOQUERY_UPDATE,"id='".$row['id']."'"); | ||
1439 | - // if(($i%10)==0)sleep(10); | ||
1440 | - $i++; | ||
1441 | - } | ||
1442 | - } | ||
1443 | - | ||
1444 | - function config_update($id,$value){ | ||
1445 | - $this->db->autoExecute("catalogs_config",array('value'=>$value),DB_AUTOQUERY_UPDATE,"id='".$id."'"); | ||
1446 | - } | ||
1447 | - | ||
1448 | - function view_config_value($id){ | ||
1449 | - $r = $this->db->getOne("select value from catalogs_config where id=?",$id); | ||
1450 | - $this->tpl->assign("config",$r); | ||
1451 | - return $r; | ||
1452 | - } | ||
1453 | - | ||
1454 | - function displayCatalogsCurs(){ | ||
1455 | - $this->tpl->assign("tpl",'catalogs_curs.tpl'); | ||
1456 | - } | ||
1457 | - | ||
1458 | - function displayCatalogs(){ | ||
1459 | - $this->tpl->assign("tpl",'catalogs.tpl'); | ||
1460 | - } | ||
1461 | - | ||
1462 | - function displayProducts(){ | ||
1463 | - $this->tpl->assign("tpl",'catalogs_products.tpl'); | ||
1464 | - } | ||
1465 | - | ||
1466 | - function displayProductsTops(){ | ||
1467 | - $this->tpl->assign("tpl",'catalogs_products_tops.tpl'); | ||
1468 | - } | ||
1469 | - | ||
1470 | - function displayProductsHits(){ | ||
1471 | - $this->tpl->assign("tpl",'catalogs_products_hits.tpl'); | ||
1472 | - } | ||
1473 | - | ||
1474 | - function displayProductsHitsAll(){ | ||
1475 | - $this->tpl->assign("tpl",'catalogs_products_hits_all.tpl'); | ||
1476 | - } | ||
1477 | - | ||
1478 | - function displayBasket($count_products,$cine_products,$cine_products_discount,$discount){ | ||
1479 | - $this->tpl->assign("count_products",$count_products); | ||
1480 | - $this->tpl->assign("cine_products",$cine_products); | ||
1481 | - $this->tpl->assign("cine_products_discount",$cine_products_discount); | ||
1482 | - $this->tpl->assign("discount",$discount); | ||
1483 | - $this->tpl->display('basket.tpl'); | ||
1484 | - } | ||
1485 | - | ||
1486 | - function displayProduct(){ | ||
1487 | - $this->tpl->assign("tpl",'catalogs_product.tpl'); | ||
1488 | - } | ||
1489 | - | ||
1490 | - function displayProductBasket(){ | ||
1491 | - $this->tpl->assign("tpl",'catalogs_basket.tpl'); | ||
1492 | - } | ||
1493 | - | ||
1494 | - function displayBrends(){ | ||
1495 | - $this->tpl->assign("tpl",'catalogs_brends.tpl'); | ||
1496 | - } | ||
1497 | - | ||
1498 | - function displayCities(){ | ||
1499 | - $this->tpl->assign("tpl",'catalogs_cities.tpl'); | ||
1500 | - } | ||
1501 | - | ||
1502 | - function displayProductBasketSend(){ | ||
1503 | - $this->tpl->assign("tpl",'catalogs_basket_send.tpl'); | ||
1504 | - } | ||
1505 | - | ||
1506 | - function displayReg(){ | ||
1507 | - $this->tpl->assign("tpl",'catalogs_reg.tpl'); | ||
1508 | - } | ||
1509 | - | ||
1510 | - function displayEditUser(){ | ||
1511 | - $this->tpl->assign("tpl",'catalogs_user_edit.tpl'); | ||
1512 | - } | ||
1513 | - | ||
1514 | - function displayNoPsw(){ | ||
1515 | - $this->tpl->assign("tpl",'catalogs_nopsw.tpl'); | ||
1516 | - } | ||
1517 | - | ||
1518 | - function displayOrders(){ | ||
1519 | - $this->tpl->assign("tpl",'catalogs_orders.tpl'); | ||
1520 | - } | ||
1521 | - | ||
1522 | - function displayOrder(){ | ||
1523 | - $this->tpl->assign("tpl",'catalogs_order.tpl'); | ||
1524 | - } | ||
1525 | - | ||
1526 | - function displayUsers(){ | ||
1527 | - $this->tpl->assign("tpl",'catalogs_users.tpl'); | ||
1528 | - } | ||
1529 | - | ||
1530 | - function displayUser(){ | ||
1531 | - $this->tpl->assign("tpl",'catalogs_user.tpl'); | ||
1532 | - } | ||
1533 | - | ||
1534 | - function displayFilters(){ | ||
1535 | - $this->tpl->assign("tpl",'catalogs_filters.tpl'); | ||
1536 | - } | ||
1537 | - | ||
1538 | - function displayYears(){ | ||
1539 | - $this->tpl->assign("tpl",'catalogs_years.tpl'); | ||
1540 | - } | ||
1541 | - | ||
1542 | - function displayWinProducts(){ | ||
1543 | - $this->tpl->display('catalogs_win_products.tpl'); | ||
1544 | - } | ||
1545 | - | ||
1546 | - function displayModifications(){ | ||
1547 | - $this->tpl->assign("tpl",'catalogs_modifications.tpl'); | ||
1548 | - } | ||
1549 | - | ||
1550 | - function displayImport(){ | ||
1551 | - $this->tpl->assign("tpl",'catalogs_import.tpl'); | ||
1552 | - } | ||
1553 | - | ||
1554 | - function displayImportCine(){ | ||
1555 | - $this->tpl->assign("tpl",'catalogs_import_cine.tpl'); | ||
1556 | - } | ||
1557 | - | ||
1558 | - function displayAkcii(){ | ||
1559 | - $this->tpl->assign("tpl",'catalogs_akcii.tpl'); | ||
1560 | - } | ||
1561 | - | ||
1562 | -} | ||
1563 | -?> |