Commit 1b81d16ba193b6db665e8689ea032148eb3d3f8c

Authored by andryeyev
1 parent 33349e3d

+ откат до пред. версии фильтров/каталога

Showing 1 changed file with 3646 additions and 5231 deletions   Show diff stats
libs/catalogs.class.php
Changes suppressed. Click to show
1 1 <?php
  2 +class Catalogs{
  3 + var $db = null;
  4 + var $tpl = null;
  5 + var $error = null;
  6 + var $cache = null;
  7 + var $photo_id = null;
  8 +
  9 +
  10 + function Catalogs(&$db,&$tpl,&$error,&$cache){
  11 + $this->db = &$db;
  12 + $this->tpl = &$tpl;
  13 + $this->error = &$error;
  14 + $this->cache = &$cache;
  15 + }
  16 +
  17 +
  18 + function trim(&$data){
  19 + foreach($data as $key=>$value){
  20 + if(is_array($value))$this->trim($value);
  21 + else $data[$key] = stripslashes(trim($value));
  22 + }
  23 + }
  24 +
2 25  
3   -include_once $_SERVER['DOCUMENT_ROOT'].'/libs/SqlQuery.class.php';
4   -
5   -class Catalogs
6   -{
7   - var $db = null;
8   - var $tpl = null;
9   - var $error = null;
10   - var $cache = null;
11   - var $photo_id = null;
12   -
13   - function Catalogs (&$db, &$tpl, &$error, &$cache)
14   - {
15   - $this->db = &$db;
16   - $this->tpl = &$tpl;
17   - $this->error = &$error;
18   - $this->cache = &$cache;
19   - }
20   -
21   - function trim (&$data)
22   - {
23   - foreach ($data as $key => $value)
24   - {
25   - if (is_array ($value))
26   - $this->trim ($value);
27   - else
28   - $data[$key] = stripslashes (trim ($value));
29   - }
30   - }
31   -
32   - function valid ($data, $upload = null)
33   - {
34   - if (isset ($data['name']))
35   - {
36   - if (! preg_match ("/.{1,100}/i", $data['name']))
37   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ.";
38   - }
39   -
40   - if (isset ($data['about_min']))
41   - {
42   - if (! preg_match ("/.+/is", $data['about_min']))
43   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Êðàòêîå îïèñàíèå.";
44   - }
45   - /*
46   - * if(isset($data['text'])){
47   - * if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ïîëíîå îïèñàíèå.";
48   - * }
49   - */
50   - /*
51   - * if(isset($data['cine'])){
52   - * if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Öåíà, òîëüêî öèôðû.";
53   - * }
54   - */
55   -
56   - if (isset ($upload['pic']['name']) && $upload['pic']['tmp_name'])
57   - {
58   - $type = substr (strrchr ($upload['pic']['name'], "."), 1);
59   - if (! preg_match ("/^(jpeg|jpg|gif|png|bmp)$/i", $type))
60   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
61   - }
62   -
63   - if (isset ($upload['file']['name']))
64   - {
65   - if (! preg_match ("/\.csv$/i", $upload['file']['name']))
66   - $this->error[] = "Îøèáêà ââîäà ïîëÿ CSV ôàéë, òîëüêî csv.";
67   - }
68   -
69   - if (isset ($data['order_name']))
70   - {
71   - if (! preg_match ("/.{1,100}/i", $data['order_name']))
72   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
73   - }
74   -
75   - if (isset ($data['order_adress']))
76   - {
77   - if (! preg_match ("/.{1,200}/i", $data['order_adress']))
78   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Àäðåñ (Ìàêñèìóì 200 ñèìâîëîâ).";
79   - }
80   -
81   - if (isset ($data['order_phone2']) && strlen ($data['order_phone2']) > 0)
82   - {
83   - if (! preg_match ("/.{1,20}/i", $data['order_phone2']))
84   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Òåëåôîí (Ìàêñèìóì 70 ñèìâîëîâ).";
85   - }
86   -
87   - if (isset ($data['order_phone']))
88   - {
89   - if (trim ($data['order_phone']) == "")
90   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
91   - if (strlen (trim ($data['order_phone'])) < 5)
92   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
93   - }
94   -
95   - if (isset ($data['delivery']) && $data['delivery'] == 0)
96   - {
97   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Äîñòàâêà.";
98   - }
99   -
100   - if (isset ($data['user_name']))
101   - {
102   - if (! preg_match ("/.{1,100}/i", $data['user_name']))
103   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
104   - }
105   -
106   - if (isset ($data['order_city']))
107   - {
108   - if (! preg_match ("/.{1,100}/i", $data['order_city']))
109   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Ãîðîä (Ìàêñèìóì 100 ñèìâîëîâ).";
110   - }
111   -
112   - if (isset ($data['user_email']))
113   - {
114   - if (! preg_match ("/.{1,80}/i", $data['user_email']))
115   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø e-mail (Ìàêñèìóì 80 ñèìâîëîâ).";
116   - }
117   -
118   - if (isset ($data['user_login']))
119   - {
120   - if (! preg_match ("/.{1,100}/i", $data['user_login']))
121   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ëîãèí (Ìàêñèìóì 100 ñèìâîëîâ).";
122   - elseif ($this->isLoginUser ($data['user_login']))
123   - $this->error[] = "Îøèáêà òàêîé Ëîãèí óæå åñòü!";
124   - }
125   -
126   - if (isset ($data['you_login']))
127   - {
128   - if (! $this->isLoginUser ($data['you_login']))
129   - $this->error[] = "Òàêîãî ËÎÃÈÍÀ íåò â áàçå äàííûõ ñàéòà!";
130   - }
131   -
132   - if (isset ($data['user_psw']))
133   - {
134   - if (! preg_match ("/.{1,100}/i", $data['user_psw']))
135   - $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ïàðîëü (Ìàêñèìóì 100 ñèìâîëîâ).";
136   - }
137   -
138   - return (count ($this->error)) ? true : false;
139   - }
140   -
141   - function deleteRubric ($id, $field = "id")
142   - {
143   - $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?";
144   - $res = $this->db->getAll ($sql, array (
145   - $id
146   - ), DB_FETCHMODE_ASSOC);
147   - foreach ($res as $row)
148   - {
149   - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}");
150   - $sql = "delete from catalogs_rubrics where id=?";
151   - $this->db->query ($sql, array (
152   - $row['id']
153   - ));
154   - $this->deleteFiltersRubric_id ($row['id']);
155   - $this->deleteFiltersRubric_id2 ($row['id']);
156   - $this->deleteYearsRubric_id ($row['id']);
157   - $this->deleteProductsRubric ($row['id']);
158   - $this->deleteRubric ($row['id'], "parent_id");
159   - }
160   - }
161   -
162   - function deleteProductPics ($id, $pics = array('pic_big','pic','pic2'))
163   - {
164   - $sql = "select pic_big,pic,pic2 from catalogs_products where id=?";
165   - $row = $this->db->getRow ($sql, array (
166   - $id
167   - ), DB_FETCHMODE_ASSOC);
168   - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}");
169   - if (in_array ('pic', $pics))
170   - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}");
171   - if (in_array ('pic2', $pics))
172   - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/2/{$row['pic2']}");
173   - }
174   -
175   - function deleteProduct ($id)
176   - {
177   - $this->deleteProductPics ($id);
178   - $sql = "delete from catalogs_products where id=?";
179   - $this->db->query ($sql, array (
180   - $id
181   - ));
182   - $this->delete_keysProductsFilters ($id);
183   - $this->delete_keysProductsFilters2 ($id);
184   - $this->delete_keysProductsAkcii ($id);
185   - $this->delete_keysProductsYears ($id);
186   - $this->delete_keysProductsCities ($id);
187   - $this->deleteProductModifications ($id);
188   - }
189   -
190   - function deleteProductsRubric ($id)
191   - {
192   - $res = $this->db->getAll ("select id from catalogs_products where rubric_id=?", array (
193   - $id
194   - ), DB_FETCHMODE_ASSOC);
195   - foreach ($res as $row)
196   - {
197   - $this->deleteProduct ($row['id']);
198   - $this->deleteGalleryProduct ($row['id']);
199   - }
200   - }
201   -
202   - function PhotosCheck ($id_s, $check_s = array())
203   - {
204   - $sql = "UPDATE gallery SET active = ? WHERE id =?";
205   -
206   - foreach ($id_s as $id)
207   - {
208   - $this->db->query ($sql, array (
209   - 0,
210   - $id
211   - ));
212   - }
213   -
214   - if (count ($check_s))
215   - {
216   - foreach ($check_s as $id)
217   - {
218   - $this->db->query ($sql, array (
219   - 1,
220   - $id
221   - ));
222   - }
223   - }
224   - }
225   -
226   - function viewRubrics ($id = 0, $parent_id = 0)
227   - { // print $parent_id."<br />";
228   - global $rubrics;
229   - // if(!$this->cache->cacheLife("cache_sql_rubrics")){
230   -
231   - // $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";
232   - $sql = "
  26 + function valid($data,$upload = null){
  27 +
  28 + if(isset($data['name'])){
  29 + if( !preg_match("/.{1,100}/i",$data['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ.";
  30 + }
  31 +
  32 + if(isset($data['about_min'])){
  33 + if( !preg_match("/.+/is",$data['about_min']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Êðàòêîå îïèñàíèå.";
  34 + }
  35 + /*
  36 + if(isset($data['text'])){
  37 + if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ïîëíîå îïèñàíèå.";
  38 + } */
  39 +/*
  40 + if(isset($data['cine'])){
  41 + if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Öåíà, òîëüêî öèôðû.";
  42 + } */
  43 +
  44 + if(isset($upload['pic']['name']) && $upload['pic']['tmp_name']){
  45 + $type = substr(strrchr($upload['pic']['name'],"."),1);
  46 + if( !preg_match("/^(jpeg|jpg|gif|png|bmp)$/i",$type) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
  47 + }
  48 +
  49 + if(isset($upload['file']['name'])){
  50 + if( !preg_match("/\.csv$/i",$upload['file']['name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ CSV ôàéë, òîëüêî csv.";
  51 + }
  52 +
  53 +
  54 + if(isset($data['order_name'])){
  55 + if( !preg_match("/.{1,100}/i",$data['order_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
  56 + }
  57 +
  58 + if(isset($data['order_adress'])){
  59 + if( !preg_match("/.{1,200}/i",$data['order_adress']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Àäðåñ (Ìàêñèìóì 200 ñèìâîëîâ).";
  60 + }
  61 +
  62 + if(isset($data['order_phone2'])&& strlen($data['order_phone2'])>0){
  63 + if( !preg_match("/.{1,20}/i",$data['order_phone2']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Òåëåôîí (Ìàêñèìóì 70 ñèìâîëîâ).";
  64 + }
  65 +
  66 + if(isset($data['order_phone'])){
  67 +if( trim($data['order_phone']) == "" ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
  68 +if( strlen(trim($data['order_phone']))<5 ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
  69 + }
  70 +
  71 + if(isset($data['delivery']) && $data['delivery']==0){
  72 + $this->error[] = "Îøèáêà ââîäà ïîëÿ Äîñòàâêà.";
  73 + }
  74 +
  75 + if(isset($data['user_name'])){
  76 + if( !preg_match("/.{1,100}/i",$data['user_name']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
  77 + }
  78 +
  79 + if(isset($data['order_city'])){
  80 + if( !preg_match("/.{1,100}/i",$data['order_city']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ãîðîä (Ìàêñèìóì 100 ñèìâîëîâ).";
  81 + }
  82 +
  83 + if(isset($data['user_email'])){
  84 + if( !preg_match("/.{1,80}/i",$data['user_email']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø e-mail (Ìàêñèìóì 80 ñèìâîëîâ).";
  85 + }
  86 +
  87 + if(isset($data['user_login'])){
  88 + if( !preg_match("/.{1,100}/i",$data['user_login']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ëîãèí (Ìàêñèìóì 100 ñèìâîëîâ).";
  89 + elseif( $this->isLoginUser($data['user_login']) ) $this->error[] = "Îøèáêà òàêîé Ëîãèí óæå åñòü!";
  90 + }
  91 +
  92 + if(isset($data['you_login'])){
  93 + if( !$this->isLoginUser($data['you_login']) ) $this->error[] = "Òàêîãî ËÎÃÈÍÀ íåò â áàçå äàííûõ ñàéòà!";
  94 + }
  95 +
  96 + if(isset($data['user_psw'])){
  97 + if( !preg_match("/.{1,100}/i",$data['user_psw']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ïàðîëü (Ìàêñèìóì 100 ñèìâîëîâ).";
  98 + }
  99 +
  100 + return ( count($this->error) ) ? true : false;
  101 + }
  102 +
  103 + function deleteRubric($id,$field="id"){
  104 + $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?";
  105 + $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  106 + foreach($res as $row){
  107 + @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}");
  108 + $sql = "delete from catalogs_rubrics where id=?";
  109 + $this->db->query($sql,array($row['id']));
  110 + $this->deleteFiltersRubric_id($row['id']);
  111 + $this->deleteFiltersRubric_id2($row['id']);
  112 + $this->deleteYearsRubric_id($row['id']);
  113 + $this->deleteProductsRubric($row['id']);
  114 + $this->deleteRubric($row['id'],"parent_id");
  115 + }
  116 + }
  117 +
  118 + function deleteProductPics($id,$pics = array('pic_big','pic','pic2')){
  119 + $sql = "select pic_big,pic,pic2 from catalogs_products where id=?";
  120 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  121 + // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}");
  122 + if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}");
  123 + if(in_array('pic2',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/2/{$row['pic2']}");
  124 + }
  125 +
  126 + function deleteProduct($id){
  127 + $this->deleteProductPics($id);
  128 + $sql = "delete from catalogs_products where id=?";
  129 + $this->db->query($sql,array($id));
  130 + $this->delete_keysProductsFilters($id);
  131 + $this->delete_keysProductsFilters2($id);
  132 + $this->delete_keysProductsAkcii($id);
  133 + $this->delete_keysProductsYears($id);
  134 + $this->delete_keysProductsCities($id);
  135 + $this->deleteProductModifications($id);
  136 + }
  137 +
  138 + function deleteProductsRubric($id){
  139 + $res = $this->db->getAll("select id from catalogs_products where rubric_id=?",array($id),DB_FETCHMODE_ASSOC);
  140 + foreach($res as $row){
  141 + $this->deleteProduct($row['id']);
  142 + $this->deleteGalleryProduct($row['id']);
  143 + }
  144 + }
  145 +
  146 +
  147 + function PhotosCheck($id_s,$check_s = array()){
  148 + $sql = "UPDATE gallery SET active = ? WHERE id =?";
  149 +
  150 + foreach($id_s as $id){
  151 + $this->db->query($sql,array(0,$id));
  152 + }
  153 + if(count($check_s)){
  154 + foreach($check_s as $id){
  155 + $this->db->query($sql,array(1,$id));
  156 + }
  157 + }
  158 + }
  159 +
  160 + function viewRubrics($id = 0,$parent_id = 0){ // print $parent_id."<br />";
  161 + global $rubrics;
  162 + //if(!$this->cache->cacheLife("cache_sql_rubrics")){
  163 +
  164 + //$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";
  165 + $sql = "
233 166 select
234 167 a.name,
235 168 a.name_ukr,
... ... @@ -253,45 +186,33 @@ class Catalogs
253 186 group by a.id
254 187 order by a.sort asc
255 188 ";
256   -
257   - $res = $this->db->query ($sql, array (
258   - $id
259   - ));
  189 +
  190 +$res = $this->db->query($sql,array($id));
  191 + while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){
  192 + $rubrics[] = $row; //print $row['id']."<br />";
260 193  
261   - while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC))
262   - {
263   - $rubrics[] = $row; // print $row['id']."<br />";
264   -
265   - if (in_array ($row['id'], $this->getParentIdRubric ($parent_id)))
266   - {
267   - $this->viewRubrics ($row['id']);
268   - }
269   - // if($row['level']==0){$this->viewRubrics($row['id']);}
270   - }
  194 + if(in_array($row['id'],$this->getParentIdRubric($parent_id))){$this->viewRubrics($row['id']);}
  195 + // if($row['level']==0){$this->viewRubrics($row['id']);}
  196 + }
271 197 // $this->cache->cacheSave($rubrics,130);
272   - // }else $count = $this->cache->sql_result;
273   - $this->tpl->assign ("rubrics", $rubrics);
274   - }
275   -
276   - function getParentIdRubric ($id)
277   - {
278   - // $ids = array();
279   - global $ids;
280   - if (! count ($ids))
281   - $ids = array ();
282   - while ($id > 0)
283   - {
284   - $row = $this->db->getRow ('select id,parent_id from catalogs_rubrics where id=?', array (
285   - $id
286   - ), DB_FETCHMODE_ASSOC);
287   - // if(isset($row['id']))
288   - $ids[] = $row['id'];
289   - $id = $row['parent_id'];
290   - } // print_r($ids);
291   - // sort($ids);
292   - return $ids;
293   - }
294   -
  198 + //}else $count = $this->cache->sql_result;
  199 + $this->tpl->assign("rubrics",$rubrics);
  200 + }
  201 +
  202 + function getParentIdRubric($id){
  203 + //$ids = array();
  204 + global $ids;
  205 + if(!count($ids))$ids = array();
  206 + while($id>0){
  207 + $row = $this->db->getRow('select id,parent_id from catalogs_rubrics where id=?',array($id),DB_FETCHMODE_ASSOC);
  208 + //if(isset($row['id']))
  209 + $ids[] = $row['id'];
  210 + $id = $row['parent_id'];
  211 + } //print_r($ids);
  212 + // sort($ids);
  213 + return $ids;
  214 + }
  215 +
295 216 function viewRubricsAll ($id = 0)
296 217 {
297 218 global $rubrics;
... ... @@ -313,24 +234,24 @@ class Catalogs
313 234 WHERE parent_id=?
314 235 ORDER BY sort asc
315 236 ";
316   - $res = $this->db->query ($sql, array (
317   - $id
318   - ));
319   - while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC))
  237 + $res = $this->db->query($sql,array($id));
  238 + while ($res->fetchInto($row,DB_FETCHMODE_ASSOC))
320 239 {
321 240 $rubrics[] = $row;
322   - $this->viewRubricsAll ($row['id']);
  241 + $this->viewRubricsAll($row['id']);
323 242 }
324   -
325   - $this->tpl->assign ("rubrics", $rubrics);
  243 +
  244 + $this->tpl->assign("rubrics",$rubrics);
326 245 }
327 246  
328   - function viewRubrics_begin ($item = 'parents', $lang = 'ru')
  247 +
  248 + function viewRubrics_begin ($item = 'parents',$lang = 'ru')
329 249 {
330   - // if(!$this->cache->cacheLife("cache_sql_rubrics_$item"."_".$lang)){
  250 + //if(!$this->cache->cacheLife("cache_sql_rubrics_$item"."_".$lang)){
  251 +
331 252 $sql = "
332 253 SELECT
333   - a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
  254 + a.name".(($lang=='ukr')?'_ukr':'')." as name,
334 255 a.id,
335 256 a.parent_id,
336 257 a.level,
... ... @@ -353,17 +274,15 @@ class Catalogs
353 274 ORDER BY a.sort asc
354 275 ";
355 276  
356   - $row = $this->db->getAll ($sql, array (
357   - 0
358   - ), DB_FETCHMODE_ASSOC);
359   -
  277 + $row = $this->db->getAll($sql, array (0), DB_FETCHMODE_ASSOC);
  278 +
360 279 foreach ($row as $key => $value)
361 280 {
362 281 if ($item == 'parents')
363 282 {
364   - $row[$key]['parents'] = $this->db->getAll ("
  283 + $row[$key]['parents'] = $this->db->getAll("
365 284 SELECT
366   - a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
  285 + a.name".(($lang=='ukr')?'_ukr':'')." as name,
367 286 a.id,
368 287 a.parent_id,
369 288 a.level,
... ... @@ -377,13 +296,11 @@ class Catalogs
377 296 FROM catalogs_rubrics a
378 297 WHERE parent_id=?
379 298 ORDER BY sort asc
380   - ", array (
381   - $value['id']
382   - ), DB_FETCHMODE_ASSOC);
  299 + ", array($value['id']), DB_FETCHMODE_ASSOC);
383 300 }
384 301 else if ($item == 'brends')
385 302 {
386   - $row[$key]['brends'] = $this->db->getAll ("
  303 + $row[$key]['brends'] = $this->db->getAll("
387 304 SELECT *
388 305 FROM catalogs_brends
389 306 WHERE rubric_id in (
... ... @@ -392,58 +309,58 @@ class Catalogs
392 309 WHERE parent_id=? or id=?
393 310 )
394 311 GROUP BY name
395   - ", array (
396   - $value['id'],
397   - $value['id']
398   - ), DB_FETCHMODE_ASSOC);
  312 + ",array ($value['id'], $value['id']), DB_FETCHMODE_ASSOC);
399 313 }
400 314 }
401   -
402   - $this->tpl->assign ("catalogs_rubrics_begin", $row);
  315 +
  316 + $this->tpl->assign("catalogs_rubrics_begin", $row);
403 317 }
404 318  
405 319 // ==== CACHE viewRubrics begin ====
  320 +
406 321 function getFilenameCacheVRB ($item = 'parents', $lang = 'ru')
407 322 {
408   - return $_SERVER['DOCUMENT_ROOT'] . '/cache/menu/menu-' . $item . '-' . $lang . '.php';
  323 + return $_SERVER['DOCUMENT_ROOT'].'/cache/menu/menu-'.$item.'-'.$lang.'.php';
409 324 }
410   -
  325 +
411 326 function isFreshCacheVRB ($item = 'parents', $lang = 'ru')
412 327 {
413 328 $filename = $this->getFilenameCacheVRB ($item, $lang);
414 329 $time = 60 * 60 * 24;
415   -
416   - if (is_file ($filename) && (filemtime ($filename) + $time) > time ())
  330 +
  331 + if (is_file ($filename) && (filemtime ($filename) + $time) > time())
417 332 {
418 333 return true;
419 334 }
420 335  
421 336 return false;
422 337 }
423   -
  338 +
424 339 function saveCacheVRB ($item = 'parents', $lang = 'ru')
425   - {
426   - $filename = $this->getFilenameCacheVRB ($item, $lang);
427   -
  340 + {
  341 + $filename = $this->getFilenameCacheVRB ($item, $lang);
  342 +
428 343 ob_start ();
429   - var_export ($this->tpl->get_template_vars ('catalogs_rubrics_begin'));
430   - // $row - êàñòûëü çàòî÷êà ïîä "catalogs_rubrics_begin", $row
431   - file_put_contents ($filename, '<?php $row = ' . ob_get_clean () . ';');
  344 + var_export ($this->tpl->get_template_vars('catalogs_rubrics_begin'));
  345 + // $row - êàñòûëü çàòî÷êà ïîä "catalogs_rubrics_begin", $row
  346 + file_put_contents ($filename, '<?php $row = '.ob_get_clean (). ';');
432 347 }
433   -
  348 +
434 349 function loadCacheVRB ($item = 'parents', $lang = 'ru')
435   - {
  350 + {
436 351 include_once $this->getFilenameCacheVRB ($item, $lang);
437 352  
438 353 if (! isset ($this->zlofound))
439   - {
440   - $this->tpl->assign ("catalogs_rubrics_begin", $row);
  354 + {
  355 + $this->tpl->assign("catalogs_rubrics_begin", $row);
441 356 $this->zlofound = true;
442 357 unset ($row);
443 358 }
444   - }
445   -
446   - function viewRubrics_parent ($parent_id = 0)
  359 + }
  360 +
  361 + // ==== ====
  362 +
  363 + function viewRubrics_parent($parent_id = 0)
447 364 {
448 365 $sql = "
449 366 SELECT
... ... @@ -464,16 +381,14 @@ class Catalogs
464 381 ORDER BY sort asc
465 382 ";
466 383  
467   - $row = $this->db->getAll ($sql, array (
468   - $parent_id
469   - ), DB_FETCHMODE_ASSOC);
470   - $this->tpl->assign ("catalogs_rubrics_parent", $row);
  384 + $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC);
  385 + $this->tpl->assign("catalogs_rubrics_parent",$row);
471 386 }
472   -
  387 +
473 388 function viewRubrics_parent2 ($rub_id, $lang = 'ru')
474 389 {
475   - $parent_id = $this->getRubricParent ($rub_id);
476   -
  390 + $parent_id = $this->getRubricParent($rub_id);
  391 +
477 392 if ($parent_id == 0)
478 393 {
479 394 $parent_id = $rub_id;
... ... @@ -481,7 +396,7 @@ class Catalogs
481 396  
482 397 $sql = "
483 398 SELECT
484   - a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
  399 + a.name".(($lang=='ukr')?'_ukr':'')." as name,
485 400 a.id,
486 401 a.parent_id,
487 402 a.level,
... ... @@ -497,563 +412,437 @@ class Catalogs
497 412 ORDER BY sort asc
498 413 ";
499 414  
500   - $row = $this->db->getAll ($sql, array (
501   - $parent_id
502   - ), DB_FETCHMODE_ASSOC);
503   - $this->tpl->assign ("catalogs_rubrics_parent2", $row);
  415 + $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC);
  416 + $this->tpl->assign("catalogs_rubrics_parent2",$row);
504 417 }
505   -
506   - function viewRubricOne ($id, &$row, $lang = 'ru')
507   - {
508   - if ($lang == 'ukr')
509   - $sql = "select *,name_ukr as name,name_h1_ukr as name_h1,top_text_ukr as top_text,seo_text_ukr as seo_text,
  418 +
  419 + function viewRubricOne($id,&$row,$lang = 'ru'){
  420 + if($lang=='ukr')
  421 + $sql = "select *,name_ukr as name,name_h1_ukr as name_h1,top_text_ukr as top_text,seo_text_ukr as seo_text,
510 422 meta_title_ukr as meta_title,meta_description_ukr as meta_description,meta_keywords_ukr as meta_keywords,meta_about_ukr as meta_about,
511 423 filter2_ukr as filter2, filter_ukr as filter, list_name_ukr as list_name from catalogs_rubrics where id=?";
512   - else
513   - $sql = "select * from catalogs_rubrics where id=?";
514   - $row = $this->db->getRow ($sql, array (
515   - $id
516   - ), DB_FETCHMODE_ASSOC);
517   - $this->tpl->assign ('rubric', $row);
518   - }
  424 + else
  425 + $sql = "select * from catalogs_rubrics where id=?";
  426 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  427 + $this->tpl->assign('rubric',$row);
  428 + }
519 429  
520   - function getRubricName ($id, $lang = 'ru')
521   - {
522   - $sql = "select name" . ($lang == 'ukr' ? '_ukr' : '') . " from catalogs_rubrics where id=?";
523   - return $this->db->getOne ($sql, array (
524   - $id
525   - ));
526   - }
  430 + function getRubricName($id,$lang = 'ru'){
  431 + $sql = "select name".($lang=='ukr'?'_ukr':'')." from catalogs_rubrics where id=?";
  432 + return $this->db->getOne($sql,array($id));
  433 + }
527 434  
528   - function getRubricParent ($id)
529   - {
530   - $sql = "select parent_id from catalogs_rubrics where id=?";
531   - return $this->db->getOne ($sql, array (
532   - $id
533   - ));
534   - }
  435 + function getRubricParent($id){
  436 + $sql = "select parent_id from catalogs_rubrics where id=?";
  437 + return $this->db->getOne($sql,array($id));
  438 + }
535 439  
536   - function activeRubricTop ($id, $top)
537   - {
538   - $table_name = "catalogs_rubrics";
539   - $fields_values = array (
540   - 'top' => $top
541   - );
542   - $this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, "id=$id");
543   - }
  440 + function activeRubricTop($id,$top){
  441 + $table_name = "catalogs_rubrics";
  442 + $fields_values = array('top'=>$top);
  443 + $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,"id=$id");
  444 + }
  445 +
  446 + function SaveRubric($data,$upload){
  447 + $table_name = "catalogs_rubrics";
  448 +
  449 +if(trim($data['translit']) == '') $data['translit'] = translit($data['name']);
  450 +
  451 + $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  452 + $parent_id = (isset($data['parent_id']) ? $data['parent_id'] : 0);
  453 + $fields_values = array('parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1),'sort' => $data['sort'],'name' => $data['name'],'name_ukr' => $data['name_ukr'],'list_name' => $data['list_name'],'list_name_ukr' => $data['list_name_ukr'],'name_h1' => $data['name_h1'],'name_h1_ukr' => $data['name_h1_ukr'],'seo_text' => $data['seo_text'],'seo_text_ukr' => $data['seo_text_ukr'],'top_text' => $data['top_text'],'top_text_ukr' => $data['top_text_ukr'],'filter' => $data['filter'],'filter_ukr' => $data['filter_ukr'],'filter2' => $data['filter2'],'filter2_ukr' => $data['filter2_ukr'],'filter_products' => $data['filter_products'],'sort_cost' => $data['sort_cost'],'meta_title' => $data['meta_title'],'meta_title_ukr' => $data['meta_title_ukr'],'meta_description' => $data['meta_description'],'meta_description_ukr' => $data['meta_description_ukr'],'meta_keywords' => $data['meta_keywords'],'meta_keywords_ukr' => $data['meta_keywords_ukr'],'meta_about' => $data['meta_about'],'meta_about_ukr' => $data['meta_about_ukr'],'translit' => $data['translit']);
  454 +
  455 +if(isset($data['literal']))$fields_values['literal'] = 1;
  456 +else $fields_values['literal'] = 0;
  457 +
  458 +if(isset($data['if_filter_mod']))$fields_values['if_filter_mod'] = 1;
  459 +else $fields_values['if_filter_mod'] = 0;
  460 +
  461 +if(isset($data['is_usd']))$fields_values['is_usd'] = 1;
  462 +else $fields_values['is_usd'] = 0;
  463 +
  464 +if(isset($data['is_xml']))$fields_values['is_xml'] = 1;
  465 +else $fields_values['is_xml'] = 0;
  466 +
  467 +if(isset($data['is_xml2']))$fields_values['is_xml2'] = 1;
  468 +else $fields_values['is_xml2'] = 0;
  469 +
  470 +if(isset($data['is_width']))$fields_values['is_width'] = 1;
  471 +else $fields_values['is_width'] = 0;
  472 + /*
  473 + if($upload['pic']['tmp_name']){
  474 + $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/"));
  475 + } */
  476 +
  477 + if($upload['pic']['tmp_name']){
  478 + if($data['update_id']>0)$this->deletePicRubric($data['update_id']);
  479 + $uploadfile = "./uploaded/pic/catalogs/rubrics/";
  480 + $type = substr(strrchr($upload['pic']['name'],"."),1);
  481 + $uploadname = mktime() . "." . $type;
  482 + if (!move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))print"Îøèáêà ïðè çàêà÷êå ôàéëà!";
  483 + $fields_values['pic'] = $uploadname;
  484 + }
  485 + //print_r($fields_values);exit;
  486 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
  487 + }
  488 +
  489 + function deletePicRubric($id){
  490 + $sql = "select pic from catalogs_rubrics where id=?";
  491 + $rub = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  492 + @unlink("./uploaded/pic/catalogs/rubrics/{$rub['pic']}");
  493 + }
  494 +
  495 + function getLevelRubric($id){
  496 + $level = $this->db->getOne("select level from catalogs_rubrics where id=?",array($id));
  497 + return ($level==null)? -1 : $level;
  498 + }
  499 +
  500 + function saveUser($data){
  501 + $table_name = "catalogs_users";
  502 + $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  503 + $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());
  504 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
  505 + }
  506 +
  507 + function updateUser($data){
  508 + $table_name = "catalogs_users";
  509 + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
  510 + $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']);
  511 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
  512 + }
  513 +
  514 + function updateUserID($data,$id){
  515 + $table_name = "catalogs_users";
  516 + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
  517 + $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']);
  518 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$id}");
  519 + }
  520 +
  521 + function deleteUser($id){
  522 + $this->db->query("delete from catalogs_users where id=?",array($id));
  523 + $res_order_id = $this->db->getRow("select id from catalogs_orders where user_id=?",array($id),DB_FETCHMODE_ASSOC);
  524 + if(count($res_order_id)){
  525 + foreach($res_order_id as $_id){
  526 + $this->db->query("delete from catalogs_orders where id=?",array($_id));
  527 + $this->db->query("delete from catalogs_orders_products where order_id=?",array($_id));
  528 + }}
  529 + }
  530 +
  531 + function isLoginUser($login){
  532 + return $this->db->getOne("select id from catalogs_users where login=?",array($login));
  533 + }
  534 +
  535 + function sendLoginInfo($login){
  536 + $user = $this->db->getRow("select * from catalogs_users where login=?",array($login),DB_FETCHMODE_ASSOC);
  537 + $mail = new PHPMailer();
  538 + $mail->CharSet = "windows-1251";
  539 + $mail->From = "shop@eltrade.com.ua";
  540 + $mail->FromName = "shop@eltrade.com.ua";
  541 + $mail->AddAddress($user['email'], $user['name']);
  542 + $mail->Subject = "Àêêàóíò ýêñòðèì";
  543 + $msg = "";
  544 + $msg .= "Çäðàâñòâóéòå: ".$user['name'];
  545 + $msg .= "<br />";
  546 + $msg .= "Âàø ëîãèí: ".$user['login'];
  547 + $msg .= "<br>";
  548 + $msg .= "Âàø ïàðîëü: ".$user['psw'];
  549 + $msg .= "<br>";
  550 + $msg .= "Ñ óâàæåíèåì, shop@eltrade.com.ua";
  551 +
  552 + $mail->MsgHTML($msg);
  553 +
  554 + if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;}
  555 + $mail->ClearAddresses();
  556 + $mail->ClearAttachments();
  557 + }
  558 +
  559 + function isUser($login,$psw){
  560 + $row = $this->db->getRow("select * from catalogs_users where login=? AND psw=?",array($login,$psw),DB_FETCHMODE_ASSOC);
  561 + //print $login .' - '.$psw;
  562 + $this->tpl->assign('user_service',$row);
  563 + return $row['id'];
  564 + }
  565 +
  566 + function viewUser($id){
  567 + $sql = "select * from catalogs_users where id=?";
  568 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  569 + $this->tpl->assign('user',$row);
  570 + }
  571 +
  572 + function getUserDiscount($id){
  573 + return $this->db->getOne("select discount from catalogs_users where id=?",array($id));
  574 + }
  575 +
  576 + function viewUsers(){
  577 + $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders
  578 +FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id
  579 +GROUP BY catalogs_users.id
  580 +ORDER BY catalogs_users.mktime DESC";
544 581  
545   - function SaveRubric ($data, $upload)
  582 + $pagerOptions = Array(
  583 + 'mode' => 'Sliding',
  584 + 'delta' => 6,
  585 + 'perPage' => 10,
  586 + 'linkClass'=>"link_class",
  587 + 'curPageLinkClassName'=>"link_class_active",
  588 + 'spacesBeforeSeparator' => 1,
  589 + 'spacesAfterSeparator' => 1
  590 + );
  591 + $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array());
  592 +
  593 + $this->tpl->assign('usersData', $res);
  594 + }
  595 +
  596 +// ======================
  597 +// ==== MODIFICATION ====
  598 +// ======================
  599 +
  600 +function viewModifications ($product_id)
  601 +{
  602 + $sql = "select * from catalogs_modifications where product_id=? order by id desc";
  603 + $row = $this->db->getAll ($sql, array (
  604 + $product_id
  605 + ), DB_FETCHMODE_ASSOC);
  606 + if (trim ($_REQUEST['test2']) == '1')
  607 + print_r ($row);
  608 + $this->tpl->assign ('modifications', $row);
  609 +}
  610 +
  611 +function viewModificationsProduct ($product_id)
  612 +{
  613 + $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc";
  614 + // $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";
  615 + $row = $this->db->getAll ($sql, array (
  616 + $product_id
  617 + ), DB_FETCHMODE_ASSOC);
  618 +
  619 + for ($i = 0; $i < count ($row); $i ++)
546 620 {
547   - $table_name = "catalogs_rubrics";
548   -
549   - if (trim ($data['translit']) == '')
550   - $data['translit'] = translit ($data['name']);
551   -
552   - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
553   - $parent_id = (isset ($data['parent_id']) ? $data['parent_id'] : 0);
554   - $fields_values = array (
555   - 'parent_id' => $parent_id,
556   - "level" => ($this->getLevelRubric ($parent_id) + 1),
557   - 'sort' => $data['sort'],
558   - 'name' => $data['name'],
559   - 'name_ukr' => $data['name_ukr'],
560   - 'list_name' => $data['list_name'],
561   - 'list_name_ukr' => $data['list_name_ukr'],
562   - 'name_h1' => $data['name_h1'],
563   - 'name_h1_ukr' => $data['name_h1_ukr'],
564   - 'seo_text' => $data['seo_text'],
565   - 'seo_text_ukr' => $data['seo_text_ukr'],
566   - 'top_text' => $data['top_text'],
567   - 'top_text_ukr' => $data['top_text_ukr'],
568   - 'filter' => $data['filter'],
569   - 'filter_ukr' => $data['filter_ukr'],
570   - 'filter2' => $data['filter2'],
571   - 'filter2_ukr' => $data['filter2_ukr'],
572   - 'filter_products' => $data['filter_products'],
573   - 'sort_cost' => $data['sort_cost'],
574   - 'meta_title' => $data['meta_title'],
575   - 'meta_title_ukr' => $data['meta_title_ukr'],
576   - 'meta_description' => $data['meta_description'],
577   - 'meta_description_ukr' => $data['meta_description_ukr'],
578   - 'meta_keywords' => $data['meta_keywords'],
579   - 'meta_keywords_ukr' => $data['meta_keywords_ukr'],
580   - 'meta_about' => $data['meta_about'],
581   - 'meta_about_ukr' => $data['meta_about_ukr'],
582   - 'translit' => $data['translit']
583   - );
584   -
585   - if (isset ($data['literal']))
586   - $fields_values['literal'] = 1;
587   - else
588   - $fields_values['literal'] = 0;
589   -
590   - if (isset ($data['if_filter_mod']))
591   - $fields_values['if_filter_mod'] = 1;
592   - else
593   - $fields_values['if_filter_mod'] = 0;
594   -
595   - if (isset ($data['is_usd']))
596   - $fields_values['is_usd'] = 1;
597   - else
598   - $fields_values['is_usd'] = 0;
599   -
600   - if (isset ($data['is_xml']))
601   - $fields_values['is_xml'] = 1;
602   - else
603   - $fields_values['is_xml'] = 0;
604   -
605   - if (isset ($data['is_xml2']))
606   - $fields_values['is_xml2'] = 1;
607   - else
608   - $fields_values['is_xml2'] = 0;
609   -
610   - if (isset ($data['is_width']))
611   - $fields_values['is_width'] = 1;
612   - else
613   - $fields_values['is_width'] = 0;
614   - /*
615   - * if($upload['pic']['tmp_name']){
616   - * $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/"));
617   - * }
618   - */
619   -
620   - if ($upload['pic']['tmp_name'])
621   - {
622   - if ($data['update_id'] > 0)
623   - $this->deletePicRubric ($data['update_id']);
624   - $uploadfile = "./uploaded/pic/catalogs/rubrics/";
625   - $type = substr (strrchr ($upload['pic']['name'], "."), 1);
626   - $uploadname = mktime () . "." . $type;
627   - if (! move_uploaded_file ($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))
628   - print "Îøèáêà ïðè çàêà÷êå ôàéëà!";
629   - $fields_values['pic'] = $uploadname;
630   - }
631   - // print_r($fields_values);exit;
632   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
  621 + $row2 = $this->db->getRow ("SELECT * FROM catalogs_keys_products_cities WHERE product_id='" . $product_id . "' AND mod_code='" . @$row[$i]['code'] . "' LIMIT 1;", array (), DB_FETCHMODE_ASSOC);
  622 + // if($row2['city_id']==25){ unset($row[$i]); }
633 623 }
634   -
635   - function deletePicRubric ($id)
  624 + $new_row = array ();
  625 + // if($_GET['test']=='18') print_r($row);
  626 + foreach ($row as $key => $value)
636 627 {
637   - $sql = "select pic from catalogs_rubrics where id=?";
638   - $rub = $this->db->getRow ($sql, array (
639   - $id
640   - ), DB_FETCHMODE_ASSOC);
641   - @unlink ("./uploaded/pic/catalogs/rubrics/{$rub['pic']}");
  628 + // $new_row[] = $value;
642 629 }
  630 + // if($_GET['test']=='18') print_r($new_row);
  631 + $this->tpl->assign ('modifications', $row);
  632 + return $row;
  633 +}
643 634  
644   - function getLevelRubric ($id)
645   - {
646   - $level = $this->db->getOne ("select level from catalogs_rubrics where id=?", array (
647   - $id
648   - ));
649   - return ($level == null) ? - 1 : $level;
650   - }
  635 +function viewModificationOne ($id)
  636 +{
  637 + $sql = "select * from catalogs_modifications where id=?";
  638 + $row = $this->db->getRow ($sql, array (
  639 + $id
  640 + ), DB_FETCHMODE_ASSOC);
  641 + $this->tpl->assign ('modification', $row);
  642 + return $row;
  643 +}
  644 +
  645 +function getModificationProduct_id ($code)
  646 +{
  647 + return $this->db->getOne ("select product_id from catalogs_modifications where code=?", array (
  648 + $code
  649 + ));
  650 +}
651 651  
652   - function saveUser ($data)
  652 +function getModification ($product_id, $code)
  653 +{
  654 + return $this->db->getOne ("
  655 + SELECT id
  656 + FROM catalogs_modifications
  657 + WHERE product_id=?
  658 + AND code=?", array (
  659 + $product_id,
  660 + $code
  661 + ));
  662 +}
  663 +
  664 +function SaveModification ($data, $upload)
  665 +{
  666 + $table_name = "catalogs_modifications";
  667 + $DB_AUTOQUERY = ($data ['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  668 + $fields_values = array (
  669 + 'product_id' => $data ['product_id'],
  670 + 'code' => $data ['code'],
  671 + 'size' => $data ['size'],
  672 + 'color' => $data ['color'],
  673 + 'active' => $data ['active']
  674 + );
  675 +
  676 + if (isset ($data ['color2']))
653 677 {
654   - $table_name = "catalogs_users";
655   - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
656   - $fields_values = array (
657   - 'name' => $data['user_name'],
658   - 'email' => $data['user_email'],
659   - 'login' => $data['user_login'],
660   - 'psw' => $data['user_psw'],
661   - 'about' => $data['user_about'],
662   - 'mktime' => mktime ()
663   - );
664   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
  678 + $fields_values ['color2'] = $data ['color2'];
665 679 }
666   -
667   - function updateUser ($data)
  680 +
  681 + if (isset ($data ['rost']))
668 682 {
669   - $table_name = "catalogs_users";
670   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
671   - $fields_values = array (
672   - 'name' => $data['user_name'],
673   - 'email' => $data['user_email'],
674   - 'login' => $data['user_login'],
675   - 'psw' => $data['user_psw'],
676   - 'about' => $data['user_about'],
677   - 'discount' => $data['user_discount']
678   - );
679   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
  683 + $fields_values ['rost'] = $data ['rost'];
680 684 }
681   -
682   - function updateUserID ($data, $id)
  685 +
  686 + if (isset ($data ['delete_pic']))
683 687 {
684   - $table_name = "catalogs_users";
685   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
686   - $fields_values = array (
687   - 'name' => $data['user_name'],
688   - 'email' => $data['user_email'],
689   - 'psw' => $data['user_psw'],
690   - 'about' => $data['user_about'],
691   - 'phone' => $data['user_phone'],
692   - 'phonemob' => $data['user_phonemob'],
693   - 'adress' => $data['user_adress']
694   - );
695   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$id}");
696   - }
  688 + if ($data ['update_id'] > 0)
  689 + {
  690 + $this->deleteModificationPics ($data ['update_id']);
  691 + }
697 692  
698   - function deleteUser ($id)
  693 + $fields_values ['pic'] = null;
  694 + $fields_values ['pic_big'] = null;
  695 + }
  696 +
  697 + if ($upload ['pic'] ['tmp_name'])
699 698 {
700   - $this->db->query ("delete from catalogs_users where id=?", array (
701   - $id
702   - ));
703   - $res_order_id = $this->db->getRow ("select id from catalogs_orders where user_id=?", array (
704   - $id
705   - ), DB_FETCHMODE_ASSOC);
706   - if (count ($res_order_id))
  699 + if ($data ['update_id'] > 0)
707 700 {
708   - foreach ($res_order_id as $_id)
709   - {
710   - $this->db->query ("delete from catalogs_orders where id=?", array (
711   - $_id
712   - ));
713   - $this->db->query ("delete from catalogs_orders_products where order_id=?", array (
714   - $_id
715   - ));
716   - }
  701 + $delete_pics = (isset ($upload ['pic'] ['big']) && $upload ['pic'] ['big'] == true) ? array (
  702 + 'pic'
  703 + ) : array (
  704 + 'pic',
  705 + 'pic_big'
  706 + );
  707 +
  708 + $this->deleteModificationPics ($data ['update_id'], $delete_pics);
717 709 }
718   - }
  710 +
  711 + $fields_values ['pic'] = upload_ImageResize ($upload ['pic'], array (
  712 + 'width' => "144",
  713 + 'height' => "144",
  714 + 'upload_path' => "./uploaded/pic/catalogs/modifications/"
  715 + ));
719 716  
720   - function isLoginUser ($login)
721   - {
722   - return $this->db->getOne ("select id from catalogs_users where login=?", array (
723   - $login
  717 + $fields_values ['pic_big'] = (isset ($upload ['pic'] ['big']) && $upload ['pic'] ['big'] == true) ? $upload ['pic'] ['name'] : upload_ImageResize ($upload ['pic'], array (
  718 + 'width' => "1000",
  719 + 'height' => "1000",
  720 + 'upload_path' => "./uploaded/pic/catalogs/modifications/big/"
724 721 ));
725 722 }
  723 +
  724 + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='{$data['update_id']}'");
  725 + return $id;
  726 +}
726 727  
727   - function sendLoginInfo ($login)
  728 +function deleteModification ($id)
  729 +{
  730 + $this->deleteModificationPics ($id);
  731 + $this->db->query ("delete from catalogs_modifications where id=?", array (
  732 + $id
  733 + ));
  734 +}
  735 +
  736 +function deleteProductModifications ($product_id, $nopic = false)
  737 +{
  738 + IF ($nopic == false)
728 739 {
729   - $user = $this->db->getRow ("select * from catalogs_users where login=?", array (
730   - $login
  740 + $sql = "
  741 + select *
  742 + from catalogs_modifications
  743 + where product_id=?";
  744 + $res = $this->db->getAll ($sql, array (
  745 + $product_id
731 746 ), DB_FETCHMODE_ASSOC);
732   - $mail = new PHPMailer ();
733   - $mail->CharSet = "windows-1251";
734   - $mail->From = "shop@eltrade.com.ua";
735   - $mail->FromName = "shop@eltrade.com.ua";
736   - $mail->AddAddress ($user['email'], $user['name']);
737   - $mail->Subject = "Àêêàóíò ýêñòðèì";
738   - $msg = "";
739   - $msg .= "Çäðàâñòâóéòå: " . $user['name'];
740   - $msg .= "<br />";
741   - $msg .= "Âàø ëîãèí: " . $user['login'];
742   - $msg .= "<br>";
743   - $msg .= "Âàø ïàðîëü: " . $user['psw'];
744   - $msg .= "<br>";
745   - $msg .= "Ñ óâàæåíèåì, shop@eltrade.com.ua";
746   -
747   - $mail->MsgHTML ($msg);
748 747  
749   - if (! $mail->Send ())
750   - {
751   - echo "There has been a mail error sending to <br>";
752   - return false;
753   - }
754   - $mail->ClearAddresses ();
755   - $mail->ClearAttachments ();
756   - }
757   -
758   - function isUser ($login, $psw)
759   - {
760   - $row = $this->db->getRow ("select * from catalogs_users where login=? AND psw=?", array (
761   - $login,
762   - $psw
763   - ), DB_FETCHMODE_ASSOC);
764   - // print $login .' - '.$psw;
765   - $this->tpl->assign ('user_service', $row);
766   - return $row['id'];
767   - }
768   -
769   - function viewUser ($id)
770   - {
771   - $sql = "select * from catalogs_users where id=?";
772   - $row = $this->db->getRow ($sql, array (
773   - $id
774   - ), DB_FETCHMODE_ASSOC);
775   - $this->tpl->assign ('user', $row);
776   - }
777   -
778   - function getUserDiscount ($id)
779   - {
780   - return $this->db->getOne ("select discount from catalogs_users where id=?", array (
781   - $id
782   - ));
783   - }
784   -
785   - function viewUsers ()
786   - {
787   - $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders
788   -FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id
789   -GROUP BY catalogs_users.id
790   -ORDER BY catalogs_users.mktime DESC";
791   -
792   - $pagerOptions = Array (
793   - 'mode' => 'Sliding',
794   - 'delta' => 6,
795   - 'perPage' => 10,
796   - 'linkClass' => "link_class",
797   - 'curPageLinkClassName' => "link_class_active",
798   - 'spacesBeforeSeparator' => 1,
799   - 'spacesAfterSeparator' => 1
800   - );
801   - $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
802   -
803   - $this->tpl->assign ('usersData', $res);
804   - }
805   -
806   - // ======================
807   - // ==== MODIFICATION ====
808   - // ======================
809   -
810   - function viewModifications ($product_id)
811   - {
812   - $sql = "select * from catalogs_modifications where product_id=? order by id desc";
813   - $row = $this->db->getAll ($sql, array (
814   - $product_id
815   - ), DB_FETCHMODE_ASSOC);
816   - if (trim ($_REQUEST['test2']) == '1')
817   - print_r ($row);
818   - $this->tpl->assign ('modifications', $row);
819   - }
820   -
821   - function viewModificationsProduct ($product_id)
822   - {
823   - $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc";
824   - // $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";
825   - $row = $this->db->getAll ($sql, array (
826   - $product_id
827   - ), DB_FETCHMODE_ASSOC);
828   -
829   - for ($i = 0; $i < count ($row); $i ++)
830   - {
831   - $row2 = $this->db->getRow ("SELECT * FROM catalogs_keys_products_cities WHERE product_id='" . $product_id . "' AND mod_code='" . @$row[$i]['code'] . "' LIMIT 1;", array (), DB_FETCHMODE_ASSOC);
832   - // if($row2['city_id']==25){ unset($row[$i]); }
833   - }
834   - $new_row = array ();
835   - // if($_GET['test']=='18') print_r($row);
836   - foreach ($row as $key => $value)
837   - {
838   - // $new_row[] = $value;
839   - }
840   - // if($_GET['test']=='18') print_r($new_row);
841   - $this->tpl->assign ('modifications', $row);
842   - return $row;
843   - }
844   -
845   - function viewModificationOne ($id)
846   - {
847   - $sql = "select * from catalogs_modifications where id=?";
848   - $row = $this->db->getRow ($sql, array (
849   - $id
850   - ), DB_FETCHMODE_ASSOC);
851   - $this->tpl->assign ('modification', $row);
852   - return $row;
853   - }
854   -
855   - function getModificationProduct_id ($code)
856   - {
857   - return $this->db->getOne ("select product_id from catalogs_modifications where code=?", array (
858   - $code
859   - ));
860   - }
861   -
862   - function getModification ($product_id, $code)
863   - {
864   - return $this->db->getOne ("
865   - SELECT id
866   - FROM catalogs_modifications
867   - WHERE product_id=?
868   - AND code=?", array (
869   - $product_id,
870   - $code
871   - ));
872   - }
873   -
874   - function SaveModification ($data, $upload)
875   - {
876   - $table_name = "catalogs_modifications";
877   - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
878   - $fields_values = array (
879   - 'product_id' => $data['product_id'],
880   - 'code' => $data['code'],
881   - 'size' => $data['size'],
882   - 'color' => $data['color'],
883   - 'active' => $data['active']
884   - );
885   -
886   - if (isset ($data['color2']))
887   - {
888   - $fields_values['color2'] = $data['color2'];
889   - }
890   -
891   - if (isset ($data['rost']))
892   - {
893   - $fields_values['rost'] = $data['rost'];
894   - }
895   -
896   - if (isset ($data['delete_pic']))
897   - {
898   - if ($data['update_id'] > 0)
899   - {
900   - $this->deleteModificationPics ($data['update_id']);
901   - }
902   -
903   - $fields_values['pic'] = null;
904   - $fields_values['pic_big'] = null;
905   - }
906   -
907   - if ($upload['pic']['tmp_name'])
  748 + foreach ($res as $row)
908 749 {
909   - if ($data['update_id'] > 0)
910   - {
911   - $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array (
912   - 'pic'
913   - ) : array (
914   - 'pic',
915   - 'pic_big'
916   - );
917   -
918   - $this->deleteModificationPics ($data['update_id'], $delete_pics);
919   - }
920   -
921   - $fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
922   - 'width' => "144",
923   - 'height' => "144",
924   - 'upload_path' => "./uploaded/pic/catalogs/modifications/"
925   - ));
926   -
927   - $fields_values['pic_big'] = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? $upload['pic']['name'] : upload_ImageResize ($upload['pic'], array (
928   - 'width' => "1000",
929   - 'height' => "1000",
930   - 'upload_path' => "./uploaded/pic/catalogs/modifications/big/"
931   - ));
  750 + $this->deleteModificationPics ($row ['id']);
932 751 }
933   -
934   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='{$data['update_id']}'");
935   - return $id;
936 752 }
937   -
938   - function deleteModification ($id)
939   - {
940   - $this->deleteModificationPics ($id);
941   - $this->db->query ("delete from catalogs_modifications where id=?", array (
942   - $id
943   - ));
944   - }
945   -
946   - function deleteProductModifications ($product_id, $nopic = false)
947   - {
948   - IF ($nopic == false)
949   - {
950   - $sql = "
951   - select *
952   - from catalogs_modifications
953   - where product_id=?";
954   - $res = $this->db->getAll ($sql, array (
955   - $product_id
956   - ), DB_FETCHMODE_ASSOC);
957   -
958   - foreach ($res as $row)
959   - {
960   - $this->deleteModificationPics ($row['id']);
961   - }
962   - }
963   -
964   - $this->db->query ("
  753 +
  754 + $this->db->query ("
965 755 delete from catalogs_modifications
966 756 where product_id=?", array (
967 757 $product_id
968   - ));
969   - }
970   -
971   - function deleteModificationPics ($id, $pics = array('pic_big','pic'))
972   - {
973   - $sql = "select pic,pic_big from catalogs_modifications where id=?";
974   -
975   - $row = $this->db->getRow ($sql, array (
976   - $id
977   - ), DB_FETCHMODE_ASSOC);
978   -
979   - if (in_array ('pic', $pics))
980   - {
981   - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}");
982   - }
983   -
984   - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}");
985   - }
986   -
987   - // =================
988   - // ==== PRODUCT ====
989   - // =================
  758 + ));
  759 +}
  760 +
  761 +function deleteModificationPics ($id, $pics = array('pic_big','pic'))
  762 +{
  763 + $sql = "select pic,pic_big from catalogs_modifications where id=?";
990 764  
991   - function ProductClick ($id)
  765 + $row = $this->db->getRow ($sql, array (
  766 + $id
  767 + ), DB_FETCHMODE_ASSOC);
  768 +
  769 + if (in_array ('pic', $pics))
992 770 {
993   - $this->db->query ("update catalogs_products set click=click+1 where id='$id'");
  771 + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}");
994 772 }
995   -
996   - function SaveProduct ($data, $upload)
997   - {
998   - $table_name = "catalogs_products";
999   -
1000   - if (trim (@$data['translit']) == "")
1001   - $data['translit'] = translit ($data['name']);
1002   -
1003   - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
1004   - $id = ($data['update_id'] > 0) ? $data['update_id'] : $this->db->nextId ('mySequence_' . $table_name);
1005   - $fields_values = array (
1006   - 'id' => $id,
1007   - 'rubric_id' => $data['rubric_id'],
1008   - 'rubric_parent_id' => $this->getRubricParent ($data['rubric_id']),
1009   - 'brend_id' => $data['brend_id'],
1010   - 'name' => $data['name'],
1011   - 'about' => $data['about'],
1012   - 'text' => $data['text'],
1013   - 'update_text' => (int) $data['update_text'],
1014   - 'strnumber' => $data['strnumber'],
1015   - 'cine' => $data['cine'],
1016   - 'cine_last' => $data['cine_last'],
1017   - 'mktime' => mktime (),
1018   - 'meta_title' => $data['meta_title'],
1019   - 'meta_description' => $data['meta_description'],
1020   - 'meta_keywords' => $data['meta_keywords'],
1021   - 'meta_about' => $data['meta_about'],
1022   - 'active' => $data['active'],
1023   - 'translit' => $data['translit']
  773 +
  774 + // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}");
  775 +}
  776 +
  777 +// =================
  778 +// ==== PRODUCT ====
  779 +// =================
  780 +
  781 + function ProductClick($id){
  782 + $this->db->query("update catalogs_products set click=click+1 where id='$id'");
  783 + }
  784 +
  785 +function SaveProduct ($data, $upload)
  786 +{
  787 + $table_name = "catalogs_products";
  788 +
  789 + if (trim (@$data['translit']) == "")
  790 + $data['translit'] = translit ($data['name']);
  791 +
  792 + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  793 + $id = ($data['update_id'] > 0) ? $data['update_id'] : $this->db->nextId ('mySequence_' . $table_name);
  794 + $fields_values = array (
  795 + 'id' => $id,
  796 + 'rubric_id' => $data['rubric_id'],
  797 + 'rubric_parent_id' => $this->getRubricParent ($data['rubric_id']),
  798 + 'brend_id' => $data['brend_id'],
  799 + 'name' => $data['name'],
  800 + 'about' => $data['about'],
  801 + 'text' => $data['text'],
  802 + 'update_text' => (int)$data['update_text'],
  803 + 'strnumber' => $data['strnumber'],
  804 + 'cine' => $data['cine'],
  805 + 'cine_last' => $data['cine_last'],
  806 + 'mktime' => mktime (),
  807 + 'meta_title' => $data['meta_title'],
  808 + 'meta_description' => $data['meta_description'],
  809 + 'meta_keywords' => $data['meta_keywords'],
  810 + 'meta_about' => $data['meta_about'],
  811 + 'active' => $data['active'],
  812 + 'translit' => $data['translit']
  813 + );
  814 + if (isset ($data['is_cost2']))
  815 + $fields_values['is_cost2'] = 1;
  816 + else
  817 + $fields_values['is_cost2'] = 0;
  818 + if (isset ($data['cine2']))
  819 + $fields_values['cine2'] = $data['cine2'];
  820 + if (isset ($data['params']))
  821 + $this->saveProductParams ($id, $data['params']);
  822 + if (isset ($data['doc']))
  823 + $fields_values['doc'] = $data['doc'];
  824 + if (isset ($data['update_text']))
  825 + $fields_values['update_text'] = $data['update_text'];
  826 + if (isset ($data['video_code']))
  827 + $fields_values['video_code'] = $data['video_code'];
  828 + if (isset ($data['akcii_id']))
  829 + $fields_values['akcii_id'] = $data['akcii_id'];
  830 +
  831 + if (isset ($data['translit']))
  832 + $fields_values['translit'] = $data['translit'];
  833 +
  834 + if ($upload['pic']['tmp_name'])
  835 + {
  836 + $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array (
  837 + 'pic',
  838 + 'pic2'
  839 + ) : array (
  840 + 'pic',
  841 + 'pic2',
  842 + 'pic_big'
1024 843 );
1025   - if (isset ($data['is_cost2']))
1026   - $fields_values['is_cost2'] = 1;
1027   - else
1028   - $fields_values['is_cost2'] = 0;
1029   - if (isset ($data['cine2']))
1030   - $fields_values['cine2'] = $data['cine2'];
1031   - if (isset ($data['params']))
1032   - $this->saveProductParams ($id, $data['params']);
1033   - if (isset ($data['doc']))
1034   - $fields_values['doc'] = $data['doc'];
1035   - if (isset ($data['update_text']))
1036   - $fields_values['update_text'] = $data['update_text'];
1037   - if (isset ($data['video_code']))
1038   - $fields_values['video_code'] = $data['video_code'];
1039   - if (isset ($data['akcii_id']))
1040   - $fields_values['akcii_id'] = $data['akcii_id'];
1041   -
1042   - if (isset ($data['translit']))
1043   - $fields_values['translit'] = $data['translit'];
1044   -
1045   - if ($upload['pic']['tmp_name'])
1046   - {
1047   - $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array (
1048   - 'pic',
1049   - 'pic2'
1050   - ) : array (
1051   - 'pic',
1052   - 'pic2',
1053   - 'pic_big'
1054   - );
1055   - $this->deleteProductPics ($id, $delete_pics);
1056   - $fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
  844 + $this->deleteProductPics ($id, $delete_pics);
  845 + $fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
1057 846 'width' => "144",
1058 847 'height' => "144",
1059 848 'upload_path' => "./uploaded/pic/catalogs/products/"
... ... @@ -1068,4524 +857,3150 @@ ORDER BY catalogs_users.mktime DESC&quot;;
1068 857 'height' => "1000",
1069 858 'upload_path' => "./uploaded/pic/catalogs/products/big/"
1070 859 ));
1071   - }
1072   -
1073   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='$id'");
1074   - $this->save_keysProductsFilters ($id, $data);
1075   - $this->save_keysProductsFilters2 ($id, $data);
1076   - $this->save_keysProductsYears ($id, $data);
1077   - // $this->save_keysProductsCities($id,$data);
1078   - $this->save_keysProductsAkcii ($id, $data);
1079   - $this->save_keysProductsSex ($id, $data);
1080   -
1081   - return $id;
1082   - }
1083   -
1084   - function save_keysProductsSex ($id, $data)
1085   - {
1086   - $this->delete_keysProductsSex ($id);
1087   - if (! isset ($data['sex']))
1088   - return false;
1089   - $table_name = "catalogs_keys_products_sex";
1090   - foreach ($data['sex'] as $sex)
1091   - {
1092   - $this->db->autoExecute ($table_name, array (
1093   - 'product_id' => $id,
1094   - 'sex' => $sex,
1095   - 'rubric_id' => $data['rubric_id']
1096   - ), DB_AUTOQUERY_INSERT);
1097   - }
1098   - }
1099   -
1100   - function delete_keysProductsSex ($id)
1101   - {
1102   - $this->db->query ("delete from catalogs_keys_products_sex where product_id=?", array (
1103   - $id
1104   - ));
1105 860 }
  861 +
  862 + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='$id'");
  863 + $this->save_keysProductsFilters ($id, $data);
  864 + $this->save_keysProductsFilters2 ($id, $data);
  865 + $this->save_keysProductsYears ($id, $data);
  866 + // $this->save_keysProductsCities($id,$data);
  867 + $this->save_keysProductsAkcii ($id, $data);
  868 + $this->save_keysProductsSex ($id, $data);
1106 869  
1107   - function save_keysProductsFilters2 ($id, $data)
1108   - {
1109   - $this->delete_keysProductsFilters2 ($id);
1110   - if (! isset ($data['filter2']))
1111   - return false;
1112   - $table_name = "catalogs_keys_products_filters2";
1113   - foreach ($data['filter2'] as $filter_id)
  870 + return $id;
  871 +}
  872 +
  873 + function save_keysProductsSex($id,$data){
  874 + $this->delete_keysProductsSex($id);
  875 + if(!isset($data['sex']))return false;
  876 + $table_name = "catalogs_keys_products_sex";
  877 + foreach($data['sex'] as $sex){
  878 + $this->db->autoExecute($table_name,array('product_id'=>$id,'sex'=>$sex,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT);
  879 + }
  880 + }
  881 +
  882 + function delete_keysProductsSex($id){
  883 + $this->db->query("delete from catalogs_keys_products_sex where product_id=?",array($id));
  884 + }
  885 +
  886 + function save_keysProductsFilters2($id,$data){
  887 + $this->delete_keysProductsFilters2($id);
  888 + if(!isset($data['filter2']))return false;
  889 + $table_name = "catalogs_keys_products_filters2";
  890 + foreach($data['filter2'] as $filter_id){
  891 + $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT);
  892 + }
  893 + }
  894 +
  895 + function delete_keysProductsFilters2($id){
  896 + $this->db->query("delete from catalogs_keys_products_filters2 where product_id=?",array($id));
  897 + }
  898 +
  899 + function save_keysProductsFilters($id,$data){
  900 + $this->delete_keysProductsFilters($id);
  901 + if(!isset($data['filter']))return false;
  902 + $table_name = "catalogs_keys_products_filters";
  903 + foreach($data['filter'] as $filter_id){
  904 + $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT);
  905 + }
  906 + }
  907 +
  908 + function delete_keysProductsFilters($id){
  909 + $this->db->query("delete from catalogs_keys_products_filters where product_id=?",array($id));
  910 + }
  911 +
  912 + function save_keysProductsYears($id,$data){
  913 + $this->delete_keysProductsYears($id);
  914 + if(!isset($data['years']))return false;
  915 + $table_name = "catalogs_keys_products_years";
  916 + foreach($data['years'] as $filter_id){
  917 + $this->db->autoExecute($table_name,array('product_id'=>$id,'year_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT);
  918 + }
  919 + }
  920 +
  921 + function delete_keysProductsYears($id){
  922 + $this->db->query("delete from catalogs_keys_products_years where product_id=?",array($id));
  923 + }
  924 +
  925 + function save_keysProductsCities($id,$data){
  926 + $this->delete_keysProductsCities($id);
  927 + if(!isset($data['city']))return false;
  928 + $table_name = "catalogs_keys_products_cities";
  929 + foreach($data['city'] as $city_id){
  930 + $this->db->autoExecute($table_name,array('product_id'=>$id,'city_id'=>$city_id),DB_AUTOQUERY_INSERT);
  931 + }
  932 + }
  933 +
  934 + function delete_keysProductsAkcii($id){
  935 + $this->db->query("delete from catalogs_keys_products_akcii where product_id=?",array($id));
  936 + }
  937 +
  938 + function save_keysProductsAkcii($id,$data){
  939 + $this->delete_keysProductsAkcii($id);
  940 + if(!isset($data['akcii']))return false;
  941 + $table_name = "catalogs_keys_products_akcii";
  942 + foreach($data['akcii'] as $rubric_id){
  943 + $this->db->autoExecute($table_name,array('product_id'=>$id,'rubric_id'=>$rubric_id),DB_AUTOQUERY_INSERT);
  944 + }
  945 + }
  946 +
  947 + function delete_keysProductsCities($id){
  948 + $this->db->query("delete from catalogs_keys_products_cities where product_id=?",array($id));
  949 + }
  950 +
  951 +
  952 + function saveProductSizeCine($id,$data){
  953 + $this->db->query("delete from catalogs_products_cine where product_id=?",array($id));
  954 + foreach($data['size'] as $key=>$size){
  955 + $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);
  956 + }
  957 + }
  958 +
  959 +
  960 + function productsIsHits($products,$hits,$tops,$akcii){
  961 + $sql = "update catalogs_products set active=?,top=?,akcii_id=? where id=?";
  962 + foreach($products as $id){
  963 + if(@in_array($id,$hits))$hit = true;
  964 + else $hit = false;
  965 + if(@in_array($id,$tops))$top = true;
  966 + else $top = false;
  967 + if(@in_array($id,$akcii))$akcii = true;
  968 + else $akcii = false;
  969 + $this->db->query($sql,array($hit,$top,$akcii, $id));
  970 + }
  971 + }
  972 +
  973 + function productsIsHits2($data,$hits){
  974 + $sql = "update catalogs_products set hit=?,hit_sort=? where id=?";
  975 + foreach($data['product_id'] as $key=>$id){
  976 + if(@in_array($id,$hits))$hit = true;
  977 + else $hit = false;
  978 + $this->db->query($sql,array($hit,$data['hit_sort'][$key],$id));
  979 + }
  980 + }
  981 +
  982 + function viewProductsRubrics($rubrics,$limit=20){
  983 + $data = array();
  984 + foreach($rubrics as $key=>$rubric_id){
  985 + $data[$key]['rubric']['name'] = $this->getRubricName($rubric_id);
  986 + $data[$key]['rubric']['id'] = $rubric_id;
  987 +
  988 + $count = $this->db->getOne("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?",array($rubric_id));
  989 + $limit = 5; $round = ($count>$limit) ? rand(0,($count-$limit)) : $limit;
  990 + $sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand(1,1000)%2) ? "asc" : "desc") . " limit $round,$limit";
  991 + $data[$key]['products'] = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC);
  992 + }
  993 + /* print"<pre>";
  994 + print_r($data);
  995 + print"</pre>"; */
  996 + $this->tpl->assign('products',$data);
  997 + }
  998 +
  999 + function seralizeFilter($str){
  1000 + $array = explode(';',iconv('UTF-8','CP1251',$str));
  1001 + $filter = array();
  1002 + foreach($array as $key=>$value){
  1003 + $filter[substr($value,0,1)][] = "'".substr(str_replace(".", ",", $value),1, strpos($value,"_")-1 )."'";
  1004 + }
  1005 + //print_r($filter);
  1006 + return $filter;
  1007 + }
  1008 +
  1009 + function seralizeSex($str){
  1010 + $sex = array();
  1011 + $sex_num = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  1012 + $sex_row = explode(';',$str);
  1013 + foreach($sex_row as $row){
  1014 + $sex[] = $sex_num[$row];
  1015 + }
  1016 + return $sex;
  1017 + }
  1018 +
  1019 +
  1020 + function viewProducts($params,$rubricsP = false,$count_modf = true,$lang='ru'){
  1021 +
  1022 +
  1023 + //exit;
  1024 + //print $params['filter_products'];
  1025 +
  1026 + if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']);
  1027 + $search = array();
  1028 + if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20;
  1029 + if(isset($params['search_str']) && strlen($params['search_str'])>0){
  1030 + $array_string = explode(" ",trim($params['search_str']));
  1031 + foreach($array_string as $row){
  1032 + $search[] = "(catalogs_products.name LIKE '%".$row."%' OR catalogs_products.text LIKE '%".$row." %' OR catalogs_rubrics.name LIKE '%".$row."%' OR catalogs_brends.name LIKE '%".$row."%' OR catalogs_modifications.code='".$row."')";
  1033 + }
  1034 + $search_string = array();
  1035 + // $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'";
  1036 + // $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'";
  1037 + /* foreach($array_string as $str){
  1038 + $search_string[] = "catalogs_products.name like '$str'";
  1039 + $search_string[] = "catalogs_products.name like'% $str %'";
  1040 + $search_string[] = "catalogs_products.name like'%$str %'";
  1041 + $search_string[] = "catalogs_products.name like'% $str%'";
  1042 +
  1043 + $search_string[] = "catalogs_products.text like '$str'";
  1044 + $search_string[] = "catalogs_products.text like'% $str %'";
  1045 + $search_string[] = "catalogs_products.text like'%$str %'";
  1046 + $search_string[] = "catalogs_products.text like'% $str%'";
  1047 + } */
  1048 + //$search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")";
  1049 + }
  1050 + // print_r($params);
  1051 + if(isset($params['brendID']) && $params['brendID']>0)$search[] = sprintf("catalogs_products.brend_id='%d'",$params['brendID']);
  1052 + if(isset($params['akciiID']) && $params['akciiID']>0)$search[] = sprintf("catalogs_products.akcii_id>'%d'",0);
  1053 + if(isset($params['new']) && $params['new']>0)$search[] = sprintf("catalogs_products.active='%d'",$params['new']);
  1054 + if(isset($params['top']) && $params['top']>0)$search[] = sprintf("catalogs_products.top='%d'",$params['top']);
  1055 + if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")";
  1056 + if(isset($params['sex']) && strlen($params['sex'])>0){
  1057 + $sex = $this->seralizeSex($params['sex']);
  1058 + //print_r($sex);
  1059 +
  1060 + // $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
  1061 +
  1062 + $search[] = "s.sex IN (" . implode(",",$sex) . ")";
  1063 + }
  1064 + //if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']);
  1065 + if($count_modf==true)$search[] = "catalogs_products.count_modifications>0";
  1066 + if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']) && !isset($params['what'])){
  1067 + $search[] = ($rubricsP==true)?sprintf("(catalogs_products.rubric_id='%d')",$params['rubID']):sprintf("
  1068 + (catalogs_products.rubric_parent_id='%d' ||
  1069 + catalogs_products.rubric_id='%d' ||
  1070 + catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') ||
  1071 + catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))",$params['rubID'],$params['rubID'],$params['rubID'],$params['rubID']);
  1072 + }
  1073 +
  1074 + /* if(isset($params['filterID'])){
  1075 + //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']);
  1076 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")";
  1077 + }*/
  1078 +
  1079 + if(isset($filter['f']) && count($filter['f'])>0){
  1080 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  1081 + }
  1082 + elseif(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($params['what'])){
  1083 + $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")";
  1084 + }
  1085 + if(isset($filter['g']) && count($filter['g'])>0){
  1086 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  1087 + }
  1088 + if(isset($filter['s']) && count($filter['s'])>0){
  1089 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  1090 + }
  1091 + if(isset($filter['r']) && count($filter['r'])>0){
  1092 + $search[] = "m2.rost in (".implode(",",$filter['r']).")";
  1093 + }
  1094 +/* if(isset($params['yearID']) && $params['yearID']>0){
  1095 + //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']);
  1096 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")";
  1097 + }*/
  1098 + if(isset($filter['y']) && $filter['y']>0){
  1099 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  1100 + }
  1101 + $sql = "select catalogs_rubrics.translit as rubric_translit,catalogs_products.*,catalogs_products.name".($lang=='ukr'?'':'')." as name,catalogs_brends.name as brend_name,catalogs_rubrics.list_name".($lang=='ukr'?'_ukr':'')." as 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 ";
  1102 + if(isset($params['akcii']) && $params['akcii']>0)$sql .= "RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id ";
  1103 + 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 ";
  1104 + elseif(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($params['what']))$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
  1105 +
  1106 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
  1107 +
  1108 + //if(isset($params['filterID']) && $params['filterID']>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
  1109 +// if(isset($params['yearID']) && $params['yearID']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1110 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1111 + if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id ";}
  1112 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";}
  1113 + if(isset($filter['r']) && count($filter['r'])>0){$sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 ";}
  1114 + if(isset($params['sex']) && strlen($params['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";}
  1115 +
  1116 +
  1117 + $sql .= "WHERE 1=1 ";
  1118 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1119 + // if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";}
  1120 + //if(isset($params['search_str']) && strlen($params['search_str'])>0){}
  1121 + $sql .= " GROUP BY catalogs_products.id ";
  1122 + $sql .= "order by ";
  1123 + if(isset($params['sort'])){
  1124 + switch($params['sort']){
  1125 + case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1126 + case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1127 + case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1128 + case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break;
  1129 + default : $sql .= " catalogs_products.mktime desc";
  1130 + }
  1131 + }else $sql .= (!empty($params['top']))?" catalogs_rubrics.top desc":" catalogs_products.rating desc";
  1132 +
  1133 + $pagerOptions = Array(
  1134 + 'mode' => 'Sliding',
  1135 + 'delta' => 5,
  1136 + 'perPage' => $perPage,
  1137 + 'linkClass'=>"link_class",
  1138 + 'curPageLinkClassName'=>"link_class_active",
  1139 + 'spacesBeforeSeparator' => 1,
  1140 + 'spacesAfterSeparator' => 1
  1141 + );
  1142 + // echo $sql;
  1143 + // $sql="";
  1144 + $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
  1145 + if (! empty ($res))
1114 1146 {
1115   - $this->db->autoExecute ($table_name, array (
1116   - 'product_id' => $id,
1117   - 'filter_id' => $filter_id,
1118   - 'rubric_id' => $data['rubric_id']
1119   - ), DB_AUTOQUERY_INSERT);
  1147 + // if($_GET['test']=='1')
  1148 + for ($i = 0; $i < count ($res['data']); $i ++)
  1149 + {
  1150 + $res['data'][$i]['mod'] = $this->db->getRow ('select * from catalogs_modifications where product_id=? and active=1 Order By id Asc', array (
  1151 + $res['data'][$i]['id']
  1152 + ), DB_FETCHMODE_ASSOC);
  1153 + $res['data'][$i]['ph1'] = $this->getFilterPh1 ($res['data'][$i]['id'], $lang);
  1154 +
  1155 + $res['data'][$i]['rating2'] = $res['data'][$i]['rating'];
  1156 + if (@$res['data'][$i]['rating'])
  1157 + $res['data'][$i]['rating'] = round ((@$res['data'][$i]['rating'] / @$res['data'][$i]['vote_num']), 0);
  1158 + else
  1159 + $res['data'][$i]['rating'] = 0;
  1160 + $res['data'][$i]['rating'] = @$res['data'][$i]['rating'] * 17;
  1161 + }
1120 1162 }
1121   - }
1122   -
1123   - function delete_keysProductsFilters2 ($id)
1124   - {
1125   - $this->db->query ("delete from catalogs_keys_products_filters2 where product_id=?", array (
1126   - $id
1127   - ));
1128   - }
  1163 +
  1164 + $this->tpl->assign ('productsData', $res);
  1165 + return $res;
  1166 + }
  1167 +
  1168 + function getFilterPh1($product_id,$lang = 'ru'){
  1169 + $sql = "select ph1".($lang=='ukr'?'_ukr':'')." as ph1 from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where k.product_id=? AND f.ph1".($lang=='ukr'?'_ukr':'')."<>''";
  1170 + return $this->db->getOne($sql,array($product_id));
  1171 + }
  1172 +
  1173 + function getCineCurs($type_curs,$cine){
  1174 + $curs = array();
  1175 +
  1176 + $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah'));
  1177 + $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank'));
  1178 + $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd'));
  1179 +
  1180 + switch($type_curs){
  1181 + case 'uah' :
  1182 + $curs['uah'] = round($cine,2);
  1183 + $curs['uah_bank'] = round(($cine/$usd)*$uah_bank,2);
  1184 + $curs['usd'] = round($cine/$usd,2);
  1185 + break;
  1186 + case 'uah_bank' :
  1187 + $curs['uah'] = round(($cine/$uah_bank)*$uah,2);
  1188 + $curs['uah_bank'] = round($cine,2);
  1189 + $curs['usd'] = round($cine/$uah_bank,2);
  1190 + break;
  1191 + case 'usd' :
  1192 + $curs['uah'] = round($cine*$uah,2);
  1193 + $curs['uah_bank'] = round($cine*$uah_bank,2);
  1194 + $curs['usd'] = round($cine,2);
  1195 + break;
  1196 + }
  1197 + return $curs;
  1198 + }
  1199 +
  1200 + function viewProductsAkcii($rubric_id,$limit = 8){
  1201 + // $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1202 + // LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1203 + // LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  1204 + // WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 ";
  1205 + // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1206 + // $sql .= "order by RAND() LIMIT $limit";
  1207 +
  1208 + $search = array();
  1209 + if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']);
  1210 + if(isset($filter['f']) && count($filter['f'])>0){
  1211 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  1212 + }
  1213 + if(isset($filter['g']) && count($filter['g'])>0){
  1214 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  1215 + }
  1216 + if(isset($filter['s']) && count($filter['s'])>0){
  1217 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  1218 + }
  1219 + if(isset($filter['y']) && $filter['y']>0){
  1220 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  1221 + }
  1222 +
  1223 +
  1224 + if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")";
  1225 +/* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1226 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  1227 + $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
  1228 + } */
  1229 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1230 + $sex = $this->seralizeSex($_GET['sex']);
  1231 + $search[] = "catalogs_products.sex IN (" . implode(",",$sex) . ")";
  1232 + }
  1233 +
  1234 + /*$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_keys_products_akcii
  1235 + left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id
  1236 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1237 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";*/
  1238 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1239 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1240 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
  1241 + 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 ";
  1242 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
  1243 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1244 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";}
  1245 + //$sql .= "where catalogs_keys_products_akcii.rubric_id=? ";
  1246 + $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 ";
  1247 + if($rubric_id>0)$sql .="and catalogs_products.rubric_id='$rubric_id' ";
  1248 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1249 + $sql .= "order by RAND()";
  1250 + if($rubric_id==0){$sql .= " limit 8";}
  1251 + $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  1252 + //print_r($res);
  1253 +for($i=0;$i<count($res);$i++){
  1254 + $res[$i]['rating2'] = $res[$i]['rating'];
  1255 + if( @$res[$i]['rating'] ) $res[$i]['rating'] = round( (@$res[$i]['rating'] / @$res[$i]['vote_num']), 0 );
  1256 + else $res[$i]['rating'] = 0;
  1257 + $res[$i]['rating'] = @$res[$i]['rating'] * 17;
  1258 +}
  1259 + $this->tpl->assign('products_akcii',$res);
  1260 + }
  1261 +
  1262 + function getProductsAkcii($limit = 6){
  1263 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1264 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1265 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
  1266 + //$sql .= "where catalogs_keys_products_akcii.rubric_id=? ";
  1267 + $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 ";
  1268 + //if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1269 + $sql .= "order by RAND() limit $limit";
  1270 + return $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  1271 + }
  1272 +
  1273 + function viewProductsHitsAll2(){
  1274 + if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20;
  1275 + $sql = "select * from catalogs_products where hit=?";
  1276 + $pagerOptions = Array(
  1277 + 'mode' => 'Sliding',
  1278 + 'delta' => 6,
  1279 + 'perPage' => $perPage,
  1280 + 'linkClass'=>"link_class",
  1281 + 'curPageLinkClassName'=>"link_class_active",
  1282 + 'spacesBeforeSeparator' => 1,
  1283 + 'spacesAfterSeparator' => 1
  1284 + );
  1285 + $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array(true));
  1286 +
  1287 + $this->tpl->assign('productsData', $res);
  1288 + }
  1289 +
  1290 + function viewProductsActiveAll($params,$limit = 4,$curs = null){
  1291 + $search = array();
  1292 +
  1293 + $sql = "
  1294 + SELECT * FROM (
  1295 + select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1296 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1297 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  1298 + WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 ";
  1299 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1300 + $sql .= "ORDER BY RAND()) as T ";
  1301 + $sql .= "Group By rubric_id ORDER BY RAND() LIMIT $limit";
  1302 + $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1303 + //print_r($res);
  1304 + $this->tpl->assign('products_active',$res);
  1305 + }
  1306 +
  1307 + function viewProductsActive($params,$limit = 4,$curs = null){
  1308 + $search = array();
  1309 + if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']))$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']);
  1310 + if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']);
  1311 +
  1312 + if(isset($filter['f']) && count($filter['f'])>0){
  1313 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  1314 + }
  1315 + if(isset($filter['g']) && count($filter['g'])>0){
  1316 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  1317 + }
  1318 + if(isset($filter['s']) && count($filter['s'])>0){
  1319 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  1320 + }
  1321 + if(isset($filter['y']) && $filter['y']>0){
  1322 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  1323 + }
  1324 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){
  1325 + $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")";
  1326 + }
  1327 +
  1328 + if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")";
  1329 +
  1330 +/* if(isset($params['sex']) && strlen($params['sex'])>0){
  1331 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  1332 + $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
  1333 + } */
  1334 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1335 + $sex = $this->seralizeSex($_GET['sex']);
  1336 + $search[] = "s.sex IN (" . implode(",",$sex) . ")";
  1337 + }
  1338 +
  1339 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1340 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1341 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
  1342 + 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 ";
  1343 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
  1344 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1345 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";}
  1346 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f']))$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
  1347 + if(isset($params['sex']) && strlen($params['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";}
  1348 +
  1349 + $sql .= "WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 ";
  1350 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1351 + $sql .= "order by RAND() LIMIT $limit";
  1352 + $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1353 + //print_r($res);
  1354 + $this->tpl->assign('products_active',$res);
  1355 + }
  1356 +
  1357 + function viewProductsHits($params,$limit = 4,$curs = null){
  1358 + $search = array();
  1359 + if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']);
  1360 +
  1361 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1362 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1363 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  1364 + WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 ";
  1365 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1366 + $sql .= "order by ";
  1367 + if(isset($params['sort'])){
  1368 + switch($params['sort']){
  1369 + case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1370 + case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1371 + case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1372 + case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break;
  1373 + default : $sql .= " RAND()";
  1374 + }
  1375 + }else $sql .= " RAND()";
  1376 + $sql .=" LIMIT $limit";
  1377 + $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1378 + //print_r($res);
  1379 + $this->tpl->assign('products_hits',$res);
  1380 + }
  1381 +
  1382 + function viewProductsTops($params,$limit = 4,$curs = null){
  1383 + $search = array();
  1384 + if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']))$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']);
  1385 + if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']);
  1386 +
  1387 + if(isset($filter['f']) && count($filter['f'])>0){
  1388 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  1389 + }
  1390 + if(isset($filter['g']) && count($filter['g'])>0){
  1391 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  1392 + }
  1393 + if(isset($filter['s']) && count($filter['s'])>0){
  1394 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  1395 + }
  1396 + if(isset($filter['y']) && $filter['y']>0){
  1397 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  1398 + }
  1399 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){
  1400 + $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")";
  1401 + }
  1402 +
  1403 + if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")";
  1404 +
  1405 + /*if(isset($params['sex']) && strlen($params['sex'])>0){
  1406 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  1407 + $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
  1408 + }*/
  1409 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1410 + $sex = $this->seralizeSex($_GET['sex']);
  1411 + $search[] = "catalogs_products.sex IN (" . implode(",",$sex) . ")";
  1412 + }
  1413 +
  1414 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  1415 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  1416 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
  1417 + 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 ";
  1418 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
  1419 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1420 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";}
  1421 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f']))$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
  1422 +
  1423 + $sql .= "WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 ";
  1424 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1425 + // $sql .= "order by RAND()";
  1426 + $sql .= "order by ";
  1427 + if(isset($params['sort'])){
  1428 + switch($params['sort']){
  1429 + case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1430 + case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1431 + case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break;
  1432 + case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break;
  1433 + default : $sql .= " r.top desc";
  1434 + }
  1435 + }else $sql .= " r.top desc";
  1436 + $sql .=" LIMIT $limit";
  1437 + //print $sql;
  1438 + $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1439 + //print_r($res);
  1440 + $this->tpl->assign('products_top',$res);
  1441 + }
  1442 +
  1443 + function viewProductsTopOne(){
  1444 + $count = $this->db->getOne("select count(*) from catalogs_products WHERE catalogs_products.header=?",array(true));
  1445 + $limit = 1; $round = rand(0,($count-$limit));
  1446 + $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);
  1447 + $this->tpl->assign('products_top_one',$res);
  1448 + }
  1449 +
  1450 + function viewProductsLast($limit = 1){
  1451 + $search = array();
  1452 + $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=? ";
  1453 + $sql .= "order by catalogs_products.mktime desc LIMIT $limit";
  1454 + $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1455 + $this->tpl->assign('products_last',$res);
  1456 + }
  1457 +
  1458 + function viewProductsHitsAll($limit = 4){
  1459 + $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=? ";
  1460 + $sql .= "order by mktime desc LIMIT $limit";
  1461 + $products_hits = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC);
  1462 + $this->tpl->assign('products_hits_all',$products_hits);
  1463 + }
  1464 +
  1465 + function activeNull($rubric_id){
  1466 + $sql = "update catalogs_products set active=? where rubric_id=?";
  1467 + $this->db->query($sql,array(0,$rubric_id));
  1468 + }
  1469 +
  1470 + function viewProductOne($id,&$row){
  1471 +// $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 b2 ON b2.id=p.brend_id left join catalogs_brends b ON b.name=b2.name and b.active=1 where p.id=?";
  1472 + $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=?";
  1473 +
  1474 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  1475 + $row['ph1'] = $this->getFilterPh1($row['id']);
  1476 +
  1477 + $row['rating2'] = $row['rating'];
  1478 + if( @$row['rating'] ) $row['rating'] = round( (@$row['rating'] / @$row['vote_num']), 0 );
  1479 + else $row['rating'] = 0;
  1480 + $row['rating'] = @$row['rating'] * 17;
  1481 + //print_r($row);
  1482 + $this->tpl->assign('product',$row);
  1483 + }
  1484 +
  1485 + function deleteCompareProduct(&$compare,$id){
  1486 + foreach($compare as $key=>$_id){
  1487 + if($_id == $id)unset($compare[$key]);
  1488 + }
  1489 + }
  1490 +
  1491 + function viewCompareProducts($compare){
  1492 + $products = array();
  1493 + $i = 0;
  1494 + foreach($compare as $id){
  1495 + $sql = "select p.* from catalogs_products p where p.id=?";
  1496 + $products[$i] = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  1497 + $products[$i]['params'] = $this->getProductParams($id);
  1498 + $i++;
  1499 + } //print_r($products);
  1500 + $this->tpl->assign('products',$products);
  1501 + }
  1502 +
  1503 + function viewProductNembers($str_n){
  1504 + $arr_id = explode(",",$str_n);
  1505 + $products = array();
  1506 + foreach($arr_id as $id){
  1507 + $count = $this->db->getOne("select count(*) from catalogs_keys_products_filters where filter_id=?",array(trim($id)));
  1508 + $limit = 1; $round = rand(0,($count-$limit)); //" LIMIT 0,$limit"
  1509 + $sql = "select catalogs_rubrics.translit as rubric_translit,catalogs_rubrics.name as rubric, 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";
  1510 + $row = $this->db->getRow($sql ,array(trim($id)),DB_FETCHMODE_ASSOC);
  1511 + if(count($row)>0)$products[] = $row;
  1512 + }
  1513 +
  1514 +// $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);
  1515 + $this->tpl->assign('products_parent',$products);
  1516 + }
  1517 +
  1518 + function getProductSizeCine($id,&$products){
  1519 + $res = $this->db->getAll("select * from catalogs_products_cine where product_id=?",array($id),DB_FETCHMODE_ASSOC);
  1520 + $i = 0;
  1521 + foreach($res as $row){
  1522 + $products['size_' . $row['n']] = $row['size'];
  1523 + $products['cine_' . $row['n']] = $row['cine'];
  1524 + $products['metka_' . $row['n']] = $row['metka'];
  1525 + $products['id_cine_' . $row['n']] = $row['id'];
  1526 + $i++;
  1527 + } //print_r($products);
  1528 + }
  1529 + /*
  1530 + function getProductCine($id,$curs = null){
  1531 + $sql = "select cine from catalogs_products where id=?";
  1532 + $row = $this->db->getOne($sql,array($id));
  1533 + return $row;
  1534 + }*/
  1535 +
  1536 + function getProductCine($id){
  1537 + $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=?";
  1538 + return $this->db->getOne($sql,array($id));
  1539 + }
  1540 +
  1541 + function viewProductCine($id){
  1542 + $row = $this->db->getAll("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC",array($id),DB_FETCHMODE_ASSOC);
  1543 + $this->tpl->assign('product_cines',$row);
  1544 + }
  1545 +
  1546 + function viewCatalogsCurs(){
  1547 + $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah'));
  1548 + $this->tpl->assign('curs_uah',$uah);
  1549 + $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank'));
  1550 + $this->tpl->assign('curs_uah_bank',$uah_bank);
  1551 + $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd'));
  1552 + $this->tpl->assign('curs_usd',$usd);
  1553 + }
  1554 +
  1555 + function saveCurs($data){
  1556 + $table_name = "catalogs_curs";
  1557 + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
  1558 + foreach($data as $key=>$value){
  1559 + $this->db->autoExecute($table_name,array('curs'=>$value),$DB_AUTOQUERY,"type='$key'");
  1560 + }
  1561 + }
  1562 +
  1563 + function viewVarCurs($curs){
  1564 + $this->tpl->assign('curs',$curs);
  1565 + }
  1566 +
  1567 + function viewBasketProducts($session_basket,$curs = null,$discount = 0){
  1568 + $products = array(); $i = 0; $cineAll = 0;
  1569 +// $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?";
  1570 +// $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=?";
  1571 + $sql = "select catalogs_modifications.id,catalogs_modifications.sale,IF(catalogs_modifications.cine>0,catalogs_modifications.cine,catalogs_products.cine) 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=?";
  1572 +
  1573 + foreach($session_basket as $id){
  1574 + $products_count = 1;
  1575 + if(count($products)){
  1576 + foreach($products as $key=>$value){
  1577 + 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'];}
  1578 + }}
  1579 + if($products_count==1){
  1580 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  1581 + $products[$i] = $row;
  1582 + $products[$i]['cine'] = round($products[$i]['cine'] - ($products[$i]['cine']*$products[$i]['sale']/100));
  1583 +
  1584 + $products[$i]['products_count']=$products_count;
  1585 + $products[$i]['products_cine_all']=$products[$i]['cine']*$products_count;
  1586 + $cineAll = $cineAll+$products[$i]['products_cine_all'];
  1587 + $i++;
  1588 + }
  1589 +
  1590 + }
  1591 + /*print"<pre>";
  1592 + print_r($products);
  1593 + print"</pre>";*/
  1594 + $this->tpl->assign('cineAll',$cineAll);
  1595 + $this->tpl->assign('cineAll_discount',$cineAll - (($cineAll*$discount)/100));
  1596 + $this->tpl->assign('basket_products',$products); //print_r($products);
  1597 + }
  1598 +
  1599 +
  1600 + function BasketUpload(&$session_basket,$proructs_count){
  1601 +
  1602 + // ========== ZLODEYEV ============
  1603 +
  1604 + foreach($proructs_count as $key=>$value){
  1605 +
  1606 + // ==== îáíîâëÿåì ====
1129 1607  
1130   - function save_keysProductsFilters ($id, $data)
1131   - {
1132   - $this->delete_keysProductsFilters ($id);
1133   - if (! isset ($data['filter']))
1134   - return false;
1135   - $table_name = "catalogs_keys_products_filters";
1136   - foreach ($data['filter'] as $filter_id)
1137   - {
1138   - $this->db->autoExecute ($table_name, array (
1139   - 'product_id' => $id,
1140   - 'filter_id' => $filter_id,
1141   - 'rubric_id' => $data['rubric_id']
1142   - ), DB_AUTOQUERY_INSERT);
1143   - }
  1608 + // Âûáèðàåì èíôî î òîâàðå
  1609 + $sql4 = "SELECT * FROM catalogs_modifications as m
  1610 + LEFT JOIN catalogs_products as p
  1611 + ON p.id=m.product_id
  1612 + WHERE m.id='".$key."' ";
  1613 + $result4 = mysql_query($sql4) or die(mysql_error());
  1614 + if (mysql_affected_rows()!=0) {
  1615 + $item=mysql_fetch_assoc($result4);
  1616 + }
  1617 +
  1618 + $f=0;
  1619 +
  1620 + if (isset($_SESSION['shopcart'])) {
  1621 +
  1622 + foreach ($_SESSION['shopcart'] as $i => $cart) {
  1623 +
  1624 +
  1625 + if ($cart['code']!='' && $cart['code']==$key) {
  1626 + $f=1;
  1627 + $_SESSION['shopcart'][$i]['count']=$value;
  1628 + $_SESSION['shopcart'][$i]['total']=$value*$_SESSION['shopcart'][$i]['price'];
  1629 + if ($_SESSION['shopcart'][$i]['total']==0) {
  1630 + unset($_SESSION['shopcart'][$i]);
  1631 + }
  1632 + break;
  1633 + }
  1634 + }
  1635 + }
1144 1636 }
1145   -
1146   - function delete_keysProductsFilters ($id)
1147   - {
1148   - $this->db->query ("delete from catalogs_keys_products_filters where product_id=?", array (
1149   - $id
1150   - ));
1151   - }
1152   -
1153   - function save_keysProductsYears ($id, $data)
1154   - {
1155   - $this->delete_keysProductsYears ($id);
1156   - if (! isset ($data['years']))
1157   - return false;
1158   - $table_name = "catalogs_keys_products_years";
1159   - foreach ($data['years'] as $filter_id)
1160   - {
1161   - $this->db->autoExecute ($table_name, array (
1162   - 'product_id' => $id,
1163   - 'year_id' => $filter_id,
1164   - 'rubric_id' => $data['rubric_id']
1165   - ), DB_AUTOQUERY_INSERT);
1166   - }
1167   - }
1168   -
1169   - function delete_keysProductsYears ($id)
1170   - {
1171   - $this->db->query ("delete from catalogs_keys_products_years where product_id=?", array (
1172   - $id
1173   - ));
1174   - }
1175   -
1176   - function save_keysProductsCities ($id, $data)
1177   - {
1178   - $this->delete_keysProductsCities ($id);
1179   - if (! isset ($data['city']))
1180   - return false;
1181   - $table_name = "catalogs_keys_products_cities";
1182   - foreach ($data['city'] as $city_id)
1183   - {
1184   - $this->db->autoExecute ($table_name, array (
1185   - 'product_id' => $id,
1186   - 'city_id' => $city_id
1187   - ), DB_AUTOQUERY_INSERT);
1188   - }
1189   - }
1190   -
1191   - function delete_keysProductsAkcii ($id)
1192   - {
1193   - $this->db->query ("delete from catalogs_keys_products_akcii where product_id=?", array (
1194   - $id
1195   - ));
1196   - }
1197   -
1198   - function save_keysProductsAkcii ($id, $data)
1199   - {
1200   - $this->delete_keysProductsAkcii ($id);
1201   - if (! isset ($data['akcii']))
1202   - return false;
1203   - $table_name = "catalogs_keys_products_akcii";
1204   - foreach ($data['akcii'] as $rubric_id)
1205   - {
1206   - $this->db->autoExecute ($table_name, array (
1207   - 'product_id' => $id,
1208   - 'rubric_id' => $rubric_id
1209   - ), DB_AUTOQUERY_INSERT);
1210   - }
1211   - }
1212   -
1213   - function delete_keysProductsCities ($id)
1214   - {
1215   - $this->db->query ("delete from catalogs_keys_products_cities where product_id=?", array (
1216   - $id
1217   - ));
1218   - }
1219   -
1220   - function saveProductSizeCine ($id, $data)
1221   - {
1222   - $this->db->query ("delete from catalogs_products_cine where product_id=?", array (
1223   - $id
1224   - ));
1225   - foreach ($data['size'] as $key => $size)
1226   - {
1227   - $this->db->autoExecute ("catalogs_products_cine", array (
1228   - 'product_id' => $id,
1229   - 'size' => $size,
1230   - 'cine' => $data['cine'][$key],
1231   - 'metka' => $data['size_metka'][$key],
1232   - 'n' => $key
1233   - ), DB_AUTOQUERY_INSERT);
1234   - }
1235   - }
1236   -
1237   - function productsIsHits ($products, $hits, $tops, $akcii)
1238   - {
1239   - $sql = "update catalogs_products set active=?,top=?,akcii_id=? where id=?";
1240   - foreach ($products as $id)
1241   - {
1242   - if (@in_array ($id, $hits))
1243   - $hit = true;
1244   - else
1245   - $hit = false;
1246   - if (@in_array ($id, $tops))
1247   - $top = true;
1248   - else
1249   - $top = false;
1250   - if (@in_array ($id, $akcii))
1251   - $akcii = true;
1252   - else
1253   - $akcii = false;
1254   - $this->db->query ($sql, array (
1255   - $hit,
1256   - $top,
1257   - $akcii,
1258   - $id
1259   - ));
1260   - }
1261   - }
1262   -
1263   - function productsIsHits2 ($data, $hits)
1264   - {
1265   - $sql = "update catalogs_products set hit=?,hit_sort=? where id=?";
1266   - foreach ($data['product_id'] as $key => $id)
1267   - {
1268   - if (@in_array ($id, $hits))
1269   - $hit = true;
1270   - else
1271   - $hit = false;
1272   - $this->db->query ($sql, array (
1273   - $hit,
1274   - $data['hit_sort'][$key],
1275   - $id
1276   - ));
1277   - }
1278   - }
1279   -
1280   - function viewProductsRubrics ($rubrics, $limit = 20)
1281   - {
1282   - $data = array ();
1283   - foreach ($rubrics as $key => $rubric_id)
1284   - {
1285   - $data[$key]['rubric']['name'] = $this->getRubricName ($rubric_id);
1286   - $data[$key]['rubric']['id'] = $rubric_id;
1287   -
1288   - $count = $this->db->getOne ("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?", array (
1289   - $rubric_id
1290   - ));
1291   - $limit = 5;
1292   - $round = ($count > $limit) ? rand (0, ($count - $limit)) : $limit;
1293   - $sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand (1, 1000) % 2) ? "asc" : "desc") . " limit $round,$limit";
1294   - $data[$key]['products'] = $this->db->getAll ($sql, array (
1295   - $rubric_id
1296   - ), DB_FETCHMODE_ASSOC);
1297   - }
1298   - /*
1299   - * print"<pre>";
1300   - * print_r($data);
1301   - * print"</pre>";
1302   - */
1303   - $this->tpl->assign ('products', $data);
1304   - }
1305   -
1306   - function seralizeFilter ($str)
1307   - {
1308   - $array = explode (';', iconv ('UTF-8', 'CP1251', $str));
1309   - $filter = array ();
1310   - foreach ($array as $key => $value)
1311   - {
1312   - $filter[substr ($value, 0, 1)][] = "'" . substr (str_replace (".", ",", $value), 1, strpos ($value, "_") - 1) . "'";
1313   - }
1314   - // print_r($filter);
1315   - return $filter;
1316   - }
1317   -
1318   - function seralizeSex ($str)
1319   - {
1320   - $sex = array ();
1321   - $sex_num = array (
1322   - 'male' => 1,
1323   - 'female' => 2,
1324   - 'child' => 3,
1325   - 'unisex' => 4
1326   - );
1327   - $sex_row = explode (';', $str);
1328   - foreach ($sex_row as $row)
1329   - {
1330   - $sex[] = $sex_num[$row];
1331   - }
1332   - return $sex;
1333   - }
1334   -
1335   - // =================
1336   - // ==== FILTER =====
1337   - // =================
1338   -
1339   - /**
1340   - * Ôèëüòðàöèÿ òîâàðîâ ïî êðèòåðèÿåì<br/>
1341   - * Ìîæíî èñïîëüçîâàòü â êà÷åñòâå âûâîäà ñïèñêà ñâîéñòâ ôèëüòðîâ
1342   - * @param array $setting
1343   - * @return array òîâàðû/ñïèñêà ñâîéñòâ ôèëüòðîâ
1344   - */
1345   - function queryBuild (array $setting = array ())
1346   - {
1347   - Tools::ifNotExist ($setting, array (
1348   - 'akcii' => true,
1349   - 'sex' => true,
1350   - ));
1351   -
1352   - $SQL = new SqlQuery();
1353   - $SQL->select('
1354   - catalogs_products.*, catalogs_products.name.as name,
1355   - catalogs_brends.name as brend_name,
1356   - catalogs_rubrics.list_name' . ($lang == 'ukr' ? '_ukr' : '') . ' as list_name,
1357   - catalogs_rubrics.translit as rubric_translit,
1358   - catalogs_keys_products_filters.*,
1359   - catalogs_keys_products_filters2.*,
1360   - catalogs_modifications.*
1361   - ');
1362   -
1363   - $SQL->from('catalogs_products');
1364   -
1365   - $SQL->innerJoin(
1366   - 'catalogs_brends', NULL,
1367   - 'catalogs_brends.id = catalogs_products.brend_id'
1368   - );
1369   -
1370   - $SQL->innerJoin(
1371   - 'catalogs_rubrics', NULL,
1372   - 'catalogs_rubrics.id=catalogs_products.rubric_id'
1373   - );
1374   -
1375   - $SQL->innerJoin(
1376   - 'catalogs_keys_products_filters', NULL,
1377   - 'catalogs_keys_products_filters.product_id = catalogs_products.id'
1378   - );
1379   -
1380   - $SQL->innerJoin(
1381   - 'catalogs_keys_products_filters2', NULL,
1382   - 'catalogs_keys_products_filters2.product_id = catalogs_products.id'
1383   - );
1384   -
1385   - $SQL->innerJoin(
1386   - 'catalogs_modifications', NULL,
1387   - 'catalogs_modifications.product_id = catalogs_products.id
1388   - AND catalogs_modifications.active = 1'
1389   - );
1390   -
1391   - // àêöèè
1392   - if ($setting['akcii'])
1393   - {
1394   - $SQL->select('catalogs_keys_products_akcii.*');
1395   - $SQL->innerJoin(
1396   - 'catalogs_keys_products_akcii', NULL,
1397   - 'catalogs_keys_products_akcii.product_id = catalogs_products.id'
1398   - );
1399   - }
1400   -
1401   - // ïîë
1402   - if ($setting['sex'])
1403   - {
1404   - $SQL->select('sex.*');
1405   - $SQL->innerJoin(
1406   - 'catalogs_keys_products_sex', 'sex',
1407   - 'catalogs_keys_products_sex.product_id = catalogs_products.id
1408   - AND sex.sex_id > 0'
1409   - );
1410   - }
1411   -
1412   - $SQL->where('catalogs_products.count_modifications > 0');
1413   -
1414   - // ===========================
1415   - // ==== ðàçáîð ïàðàìåòðîâ ====
1416   - // ===========================
1417   -
1418   - if (isset ($params['filter']) && count ($params['filter']) > 0)
1419   - {
1420   - // LIMIT
1421   - if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
1422   - {
1423   - $perPage = $_GET['perPage'];
1424   - }
1425   - else
1426   - {
1427   - $perPage = 20;
1428   - }
1429   -
1430   - $SQL->limit($perPage);
1431   -
1432   - // ÏÎÈÑÊ
1433   - if (isset ($params['search_str']) && strlen ($params['search_str']) > 0)
1434   - {
1435   - $array_string = explode (' ', trim ($params['search_str']));
1436   -
1437   - foreach ($array_string as $word)
1438   - {
1439   - $SQL->where('(
1440   - catalogs_products.name LIKE "%'.$word.'%"
1441   - OR catalogs_products.text LIKE "%'.$word.'%"
1442   - OR catalogs_rubrics.name LIKE "%'.$word.'%"
1443   - OR catalogs_brends.name LIKE "%'.$word.'%"
1444   - OR catalogs_modifications.code = "'.$word.'"
1445   - )');
1446   - }
1447   - }
1448   -
1449   - // PARAM
1450   -
1451   - if (isset ($params['brendID']) && $params['brendID'] > 0)
1452   - {
1453   - $SQL->where( sprintf ("catalogs_products.brend_id='%d'", $params['brendID']));
1454   - }
1455   -
1456   - if (isset ($params['akciiID']) && $params['akciiID'] > 0)
1457   - {
1458   - $SQL->where( sprintf ("catalogs_products.akcii_id>'%d'", 0));
1459   - }
1460   -
1461   - if (isset ($params['new']) && $params['new'] > 0)
1462   - {
1463   - $SQL->where( sprintf ("catalogs_products.active='%d'", $params['new']));
1464   - }
1465   -
1466   - if (isset ($params['top']) && $params['top'] > 0)
1467   - {
1468   - $SQL->where( sprintf ("catalogs_products.top='%d'", $params['top']));
1469   - }
1470   -
1471   - if (isset ($params['brend']) && strlen ($params['brend']) > 0)
1472   - {
1473   - $SQL->where( "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")");
1474   - }
1475   -
1476   - if (isset ($params['sex']) && strlen ($params['sex']) > 0)
1477   - {
1478   - $sex = $this->seralizeSex ($params['sex']);
1479   -
1480   - $SQL->where( "s.sex IN (" . implode (",", $sex) . ")");
1481   - }
1482   -
1483   - // ÕÇ
1484   - if ($count_modf == true)
1485   - {
1486   - $SQL->where( "catalogs_products.count_modifications>0");
1487   - }
1488   -
1489   - if (isset ($params['rubID']) && $params['rubID'] > 0
1490   - && ! isset ($params['filter_products'])
1491   - && ! isset ($params['what']))
1492   - {
1493   - $SQL->where( ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf ("
1494   - (
1495   - catalogs_products.rubric_parent_id='%d' ||
1496   - catalogs_products.rubric_id='%d' ||
1497   - catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') ||
1498   - catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d')
1499   - )",
1500   - $params['rubID'],
1501   - $params['rubID'],
1502   - $params['rubID'],
1503   - $params['rubID']
1504   - ));
1505   - }
1506   -
1507   - $filter = $this->seralizeFilter ($params['filter']);
1508   -
1509   - if (isset ($filter['f']) && count ($filter['f']) > 0)
1510   - {
1511   - $SQL->where( "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")");
1512   - }
1513   - elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what']))
1514   - {
1515   - $SQL->where( "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")");
1516   - }
1517   -
1518   - if (isset ($filter['g']) && count ($filter['g']) > 0)
1519   - {
1520   - $SQL->where( "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")");
1521   - }
1522   -
1523   - if (isset ($filter['s']) && count ($filter['s']) > 0)
1524   - {
1525   - $SQL->where( "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")");
1526   - }
1527   -
1528   - if (isset ($filter['r']) && count ($filter['r']) > 0)
1529   - {
1530   - $SQL->where( "m2.rost in (" . implode (",", $filter['r']) . ")");
1531   - }
1532   -
1533   - if (isset ($filter['y']) && $filter['y'] > 0)
1534   - {
1535   - $SQL->where( "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")");
1536   - }
1537   -
1538   - // ==== SORT ====
1539   -
1540   - if (isset ($params['sort']))
1541   - {
1542   - switch ($params['sort'])
1543   - {
1544   - case 'cine' :
1545   -
1546   - $SQL->orderBy('catalogs_products.cine '. ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
1547   - break;
1548   -
1549   - case 'click' :
1550   -
1551   - $SQL->orderBy('catalogs_products.click' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
1552   - break;
1553   -
1554   - case 'rating' :
1555   -
1556   - $SQL->orderBy('catalogs_products.rating' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
1557   - break;
1558   -
1559   - case 'hit' :
1560   -
1561   - $SQL->orderBy('catalogs_products.hit_sort ASC');
1562   - break;
1563   -
1564   - default :
1565   -
1566   - $SQL->orderBy('catalogs_products.mktime DESC');
1567   - }
1568   - }
1569   - else
1570   - {
1571   - $SQL->orderBy(! empty ($params['top']) ? 'catalogs_rubrics.top DESC' : 'catalogs_products.rating DESC');
1572   - }
1573   -
1574   - // ==== GROUP ====
1575   -
1576   - $SQL->groupBy('catalogs_products.id');
1577   - }
1578   -
1579   - return $this->db->getAll ($SQL->__toSting(), array (), DB_FETCHMODE_ASSOC);
1580   - }
1581   -
1582   - function viewProducts ($params, $rubricsP = false, $count_modf = true, $lang = 'ru')
1583   - {
1584   -
1585   - // exit;
1586   - // print $params['filter_products'];
1587   - if (isset ($params['filter']) && count ($params['filter']) > 0)
1588   - $filter = $this->seralizeFilter ($params['filter']);
1589   - $search = array ();
1590   - if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
1591   - $perPage = $_GET['perPage'];
1592   - else
1593   - $perPage = 20;
1594   - if (isset ($params['search_str']) && strlen ($params['search_str']) > 0)
1595   - {
1596   - $array_string = explode (" ", trim ($params['search_str']));
1597   - foreach ($array_string as $row)
1598   - {
1599   - $search[] = "(catalogs_products.name LIKE '%" . $row . "%' OR catalogs_products.text LIKE '%" . $row . "%' OR catalogs_rubrics.name LIKE '%" . $row . "%' OR catalogs_brends.name LIKE '%" . $row . "%' OR catalogs_modifications.code='" . $row . "%')";
1600   - }
1601   - $search_string = array ();
1602   - // $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'";
1603   - // $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'";
1604   - /*
1605   - * foreach($array_string as $str){
1606   - * $search_string[] = "catalogs_products.name like '$str'";
1607   - * $search_string[] = "catalogs_products.name like'% $str %'";
1608   - * $search_string[] = "catalogs_products.name like'%$str %'";
1609   - * $search_string[] = "catalogs_products.name like'% $str%'";
1610   - *
1611   - * $search_string[] = "catalogs_products.text like '$str'";
1612   - * $search_string[] = "catalogs_products.text like'% $str %'";
1613   - * $search_string[] = "catalogs_products.text like'%$str %'";
1614   - * $search_string[] = "catalogs_products.text like'% $str%'";
1615   - * }
1616   - */
1617   - // $search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")";
1618   - }
1619   - // print_r($params);
1620   - if (isset ($params['brendID']) && $params['brendID'] > 0)
1621   - $search[] = sprintf ("catalogs_products.brend_id='%d'", $params['brendID']);
1622   - if (isset ($params['akciiID']) && $params['akciiID'] > 0)
1623   - $search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0);
1624   - if (isset ($params['new']) && $params['new'] > 0)
1625   - $search[] = sprintf ("catalogs_products.active='%d'", $params['new']);
1626   - if (isset ($params['top']) && $params['top'] > 0)
1627   - $search[] = sprintf ("catalogs_products.top='%d'", $params['top']);
1628   - if (isset ($params['brend']) && strlen ($params['brend']) > 0)
1629   - $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
1630   - if (isset ($params['sex']) && strlen ($params['sex']) > 0)
1631   - {
1632   - $sex = $this->seralizeSex ($params['sex']);
1633   - // print_r($sex);
1634   -
1635   - // $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
1636   -
1637   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
1638   - }
1639   - // if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']);
1640   - if ($count_modf == true)
1641   - $search[] = "catalogs_products.count_modifications>0";
1642   - if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']) && ! isset ($params['what']))
1643   - {
1644   - $search[] = ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf ("
1645   - (catalogs_products.rubric_parent_id='%d' ||
1646   - catalogs_products.rubric_id='%d' ||
1647   - catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') ||
1648   - catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))", $params['rubID'], $params['rubID'], $params['rubID'], $params['rubID']);
1649   - }
1650   -
1651   - /*
1652   - * if(isset($params['filterID'])){
1653   - * //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']);
1654   - * $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")";
1655   - * }
1656   - */
1657   -
1658   - if (isset ($filter['f']) && count ($filter['f']) > 0)
1659   - {
1660   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
1661   - }
1662   - elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what']))
1663   - {
1664   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
1665   - }
1666   - if (isset ($filter['g']) && count ($filter['g']) > 0)
1667   - {
1668   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
1669   - }
1670   - if (isset ($filter['s']) && count ($filter['s']) > 0)
1671   - {
1672   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
1673   - }
1674   - if (isset ($filter['r']) && count ($filter['r']) > 0)
1675   - {
1676   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
1677   - }
1678   - /*
1679   - * if(isset($params['yearID']) && $params['yearID']>0){
1680   - * //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']);
1681   - * $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")";
1682   - * }
1683   - */
1684   - if (isset ($filter['y']) && $filter['y'] > 0)
1685   - {
1686   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
1687   - }
1688   - $sql = "
1689   - SELECT catalogs_rubrics.translit as rubric_translit,catalogs_products.*,catalogs_products.name" . ($lang == 'ukr' ? '' : '') . " as name,catalogs_brends.name as brend_name,catalogs_rubrics.list_name" . ($lang == 'ukr' ? '_ukr' : '') . " as list_name
1690   - FROM catalogs_products
1691   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1692   - LEFT JOIN catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id
1693   - RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id
1694   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
1695   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
1696   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
1697   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id
1698   - AND catalogs_modifications.active=1
1699   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1
1700   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
1701   - WHERE 1=1
1702   - ";
1703   - if (count ($search))
1704   - $sql .= "AND " . implode (" AND ", $search) . " ";
1705   - // if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";}
1706   - // if(isset($params['search_str']) && strlen($params['search_str'])>0){}
1707   - $sql .= " GROUP BY catalogs_products.id ";
1708   - $sql .= "order by ";
1709   - if (isset ($params['sort']))
1710   - {
1711   - switch ($params['sort'])
1712   - {
1713   - case 'cine' :
1714   - $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
1715   - break;
1716   - case 'click' :
1717   - $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
1718   - break;
1719   - case 'rating' :
1720   - $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
1721   - break;
1722   - case 'hit' :
1723   - $sql .= " catalogs_products.hit_sort asc";
1724   - break;
1725   - default :
1726   - $sql .= " catalogs_products.mktime desc";
1727   - }
1728   - }
1729   - else
1730   - $sql .= (! empty ($params['top'])) ? " catalogs_rubrics.top desc" : " catalogs_products.rating desc";
1731   -
1732   - $pagerOptions = Array (
1733   - 'mode' => 'Sliding',
1734   - 'delta' => 5,
1735   - 'perPage' => $perPage,
1736   - 'linkClass' => "link_class",
1737   - 'curPageLinkClassName' => "link_class_active",
1738   - 'spacesBeforeSeparator' => 1,
1739   - 'spacesAfterSeparator' => 1
1740   - );
1741   - // echo $sql;
1742   - // $sql="";
1743   - $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
1744   - if (! empty ($res))
1745   - {
1746   - // if($_GET['test']=='1')
1747   - for ($i = 0; $i < count ($res['data']); $i ++)
1748   - {
1749   - $res['data'][$i]['mod'] = $this->db->getRow ('select * from catalogs_modifications where product_id=? and active=1 Order By id Asc', array (
1750   - $res['data'][$i]['id']
1751   - ), DB_FETCHMODE_ASSOC);
1752   - $res['data'][$i]['ph1'] = $this->getFilterPh1 ($res['data'][$i]['id'], $lang);
1753   -
1754   - $res['data'][$i]['rating2'] = $res['data'][$i]['rating'];
1755   - if (@$res['data'][$i]['rating'])
1756   - $res['data'][$i]['rating'] = round ((@$res['data'][$i]['rating'] / @$res['data'][$i]['vote_num']), 0);
1757   - else
1758   - $res['data'][$i]['rating'] = 0;
1759   - $res['data'][$i]['rating'] = @$res['data'][$i]['rating'] * 17;
1760   - }
1761   - }
1762   -
1763   - $this->tpl->assign ('productsData', $res);
1764   - return $res;
1765   - }
1766   -
1767   - function getFilterPh1 ($product_id, $lang = 'ru')
1768   - {
1769   - $sql = "select ph1" . ($lang == 'ukr' ? '_ukr' : '') . " as ph1 from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where k.product_id=? AND f.ph1" . ($lang == 'ukr' ? '_ukr' : '') . "<>''";
1770   - return $this->db->getOne ($sql, array (
1771   - $product_id
1772   - ));
1773   - }
1774   -
1775   - function getCineCurs ($type_curs, $cine)
1776   - {
1777   - $curs = array ();
1778   -
1779   - $uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
1780   - 'uah'
1781   - ));
1782   - $uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
1783   - 'uah_bank'
1784   - ));
1785   - $usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
1786   - 'usd'
1787   - ));
1788   -
1789   - switch ($type_curs)
1790   - {
1791   - case 'uah' :
1792   - $curs['uah'] = round ($cine, 2);
1793   - $curs['uah_bank'] = round (($cine / $usd) * $uah_bank, 2);
1794   - $curs['usd'] = round ($cine / $usd, 2);
1795   - break;
1796   - case 'uah_bank' :
1797   - $curs['uah'] = round (($cine / $uah_bank) * $uah, 2);
1798   - $curs['uah_bank'] = round ($cine, 2);
1799   - $curs['usd'] = round ($cine / $uah_bank, 2);
1800   - break;
1801   - case 'usd' :
1802   - $curs['uah'] = round ($cine * $uah, 2);
1803   - $curs['uah_bank'] = round ($cine * $uah_bank, 2);
1804   - $curs['usd'] = round ($cine, 2);
1805   - break;
1806   - }
1807   - return $curs;
1808   - }
1809   -
1810   - function viewProductsAkcii ($rubric_id, $limit = 8)
1811   - {
1812   - // $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
1813   - // LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1814   - // LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
1815   - // WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 ";
1816   - // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
1817   - // $sql .= "order by RAND() LIMIT $limit";
1818   - $search = array ();
1819   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
1820   - $filter = $this->seralizeFilter ($_GET['filter']);
1821   - if (isset ($filter['f']) && count ($filter['f']) > 0)
1822   - {
1823   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
1824   - }
1825   - if (isset ($filter['g']) && count ($filter['g']) > 0)
1826   - {
1827   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
1828   - }
1829   - if (isset ($filter['s']) && count ($filter['s']) > 0)
1830   - {
1831   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
1832   - }
1833   - if (isset ($filter['y']) && $filter['y'] > 0)
1834   - {
1835   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
1836   - }
1837   -
1838   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
1839   - $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
1840   - /*
1841   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
1842   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
1843   - * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
1844   - * }
1845   - */
1846   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
1847   - {
1848   - $sex = $this->seralizeSex ($_GET['sex']);
1849   - $search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")";
1850   - }
1851   -
1852   - /*
1853   - * $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_keys_products_akcii
1854   - * left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id
1855   - * LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1856   - * LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
1857   - */
1858   - $sql = "
1859   - SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
1860   - FROM catalogs_products
1861   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1862   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
1863   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
1864   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
1865   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
1866   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
1867   - WHERE catalogs_products.count_modifications>0
1868   - AND catalogs_products.akcii_id>0
1869   - ";
1870   - if ($rubric_id > 0)
1871   - $sql .= "and catalogs_products.rubric_id='$rubric_id' ";
1872   - if (count ($search))
1873   - $sql .= "AND " . implode (" AND ", $search) . " ";
1874   - $sql .= "order by RAND()";
1875   - if ($rubric_id == 0)
1876   - {
1877   - $sql .= " limit 8";
1878   - }
1879   - $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
1880   - // print_r($res);
1881   - for ($i = 0; $i < count ($res); $i ++)
1882   - {
1883   - $res[$i]['rating2'] = $res[$i]['rating'];
1884   - if (@$res[$i]['rating'])
1885   - $res[$i]['rating'] = round ((@$res[$i]['rating'] / @$res[$i]['vote_num']), 0);
1886   - else
1887   - $res[$i]['rating'] = 0;
1888   - $res[$i]['rating'] = @$res[$i]['rating'] * 17;
1889   - }
1890   - $this->tpl->assign ('products_akcii', $res);
1891   - }
1892   -
1893   - function getProductsAkcii ($limit = 6)
1894   - {
1895   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
1896   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1897   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
1898   - // $sql .= "where catalogs_keys_products_akcii.rubric_id=? ";
1899   - $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 ";
1900   - // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
1901   - $sql .= "order by RAND() limit $limit";
1902   - return $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
1903   - }
1904   -
1905   - function viewProductsHitsAll2 ()
1906   - {
1907   - if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
1908   - $perPage = $_GET['perPage'];
1909   - else
1910   - $perPage = 20;
1911   - $sql = "select * from catalogs_products where hit=?";
1912   - $pagerOptions = Array (
1913   - 'mode' => 'Sliding',
1914   - 'delta' => 6,
1915   - 'perPage' => $perPage,
1916   - 'linkClass' => "link_class",
1917   - 'curPageLinkClassName' => "link_class_active",
1918   - 'spacesBeforeSeparator' => 1,
1919   - 'spacesAfterSeparator' => 1
1920   - );
1921   - $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array (
1922   - true
1923   - ));
1924   -
1925   - $this->tpl->assign ('productsData', $res);
1926   - }
1927   -
1928   - function viewProductsActiveAll ($params, $limit = 4, $curs = null)
1929   - {
1930   - $search = array ();
1931   -
1932   - $sql = "
1933   - SELECT * FROM (
1934   - select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
1935   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1936   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
1937   - WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 ";
1938   - if (count ($search))
1939   - $sql .= "AND " . implode (" AND ", $search) . " ";
1940   - $sql .= "ORDER BY RAND()) as T ";
1941   - $sql .= "Group By rubric_id ORDER BY RAND() LIMIT $limit";
1942   - $res = $this->db->getAll ($sql, array (
1943   - true
1944   - ), DB_FETCHMODE_ASSOC);
1945   - // print_r($res);
1946   - $this->tpl->assign ('products_active', $res);
1947   - }
1948   -
1949   - function viewProductsActive ($params, $limit = 4, $curs = null)
1950   - {
1951   - $search = array ();
1952   - if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']))
1953   - $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
1954   - if (isset ($params['filter']) && count ($params['filter']) > 0)
1955   - $filter = $this->seralizeFilter ($params['filter']);
1956   -
1957   - if (isset ($filter['f']) && count ($filter['f']) > 0)
1958   - {
1959   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
1960   - }
1961   - if (isset ($filter['g']) && count ($filter['g']) > 0)
1962   - {
1963   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
1964   - }
1965   - if (isset ($filter['s']) && count ($filter['s']) > 0)
1966   - {
1967   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
1968   - }
1969   - if (isset ($filter['y']) && $filter['y'] > 0)
1970   - {
1971   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
1972   - }
1973   - if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
1974   - {
1975   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
1976   - }
1977   -
1978   - if (isset ($params['brend']) && strlen ($params['brend']) > 0)
1979   - $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
1980   -
1981   - /*
1982   - * if(isset($params['sex']) && strlen($params['sex'])>0){
1983   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
1984   - * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
1985   - * }
1986   - */
1987   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
1988   - {
1989   - $sex = $this->seralizeSex ($_GET['sex']);
1990   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
1991   - }
1992   -
1993   - $sql = "
1994   - SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
1995   - FROM catalogs_products
1996   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
1997   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
1998   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
1999   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
2000   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
2001   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
2002   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
2003   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
2004   - WHERE catalogs_products.active=?
2005   - AND catalogs_products.count_modifications>0
2006   - ";
2007   -
2008   - if (count ($search))
2009   - $sql .= "AND " . implode (" AND ", $search) . " ";
2010   - $sql .= "order by RAND() LIMIT $limit";
2011   - $res = $this->db->getAll ($sql, array (
2012   - true
2013   - ), DB_FETCHMODE_ASSOC);
2014   - // print_r($res);
2015   - $this->tpl->assign ('products_active', $res);
2016   - }
2017   -
2018   - function viewProductsHits ($params, $limit = 4, $curs = null)
2019   - {
2020   - $search = array ();
2021   - if (isset ($params['rubID']) && $params['rubID'] > 0)
2022   - $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
2023   -
2024   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
2025   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
2026   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
2027   - WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 ";
2028   - if (count ($search))
2029   - $sql .= "AND " . implode (" AND ", $search) . " ";
2030   - $sql .= "order by ";
2031   - if (isset ($params['sort']))
2032   - {
2033   - switch ($params['sort'])
2034   - {
2035   - case 'cine' :
2036   - $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2037   - break;
2038   - case 'click' :
2039   - $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2040   - break;
2041   - case 'rating' :
2042   - $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2043   - break;
2044   - case 'hit' :
2045   - $sql .= " catalogs_products.hit_sort asc";
2046   - break;
2047   - default :
2048   - $sql .= " RAND()";
2049   - }
2050   - }
2051   - else
2052   - $sql .= " RAND()";
2053   - $sql .= " LIMIT $limit";
2054   - $res = $this->db->getAll ($sql, array (
2055   - true
2056   - ), DB_FETCHMODE_ASSOC);
2057   - // print_r($res);
2058   - $this->tpl->assign ('products_hits', $res);
2059   - }
2060   -
2061   - function viewProductsTops ($params, $limit = 4, $curs = null)
2062   - {
2063   - $search = array ();
2064   - if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']))
2065   - $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
2066   - if (isset ($params['filter']) && count ($params['filter']) > 0)
2067   - $filter = $this->seralizeFilter ($params['filter']);
2068   -
2069   - if (isset ($filter['f']) && count ($filter['f']) > 0)
2070   - {
2071   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
2072   - }
2073   - if (isset ($filter['g']) && count ($filter['g']) > 0)
2074   - {
2075   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
2076   - }
2077   - if (isset ($filter['s']) && count ($filter['s']) > 0)
2078   - {
2079   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
2080   - }
2081   - if (isset ($filter['y']) && $filter['y'] > 0)
2082   - {
2083   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
2084   - }
2085   - if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
2086   - {
2087   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
2088   - }
2089   -
2090   - if (isset ($params['brend']) && strlen ($params['brend']) > 0)
2091   - $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
2092   -
2093   - /*
2094   - * if(isset($params['sex']) && strlen($params['sex'])>0){
2095   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
2096   - * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
2097   - * }
2098   - */
2099   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
2100   - {
2101   - $sex = $this->seralizeSex ($_GET['sex']);
2102   - $search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")";
2103   - }
2104   -
2105   - $sql = "
2106   - SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
2107   - FROM catalogs_products
2108   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
2109   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
2110   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
2111   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
2112   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
2113   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
2114   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
2115   - WHERE catalogs_products.top=?
2116   - AND catalogs_products.count_modifications>0
2117   - ";
2118   -
2119   - if (count ($search))
2120   - $sql .= "AND " . implode (" AND ", $search) . " ";
2121   - // $sql .= "order by RAND()";
2122   - $sql .= "order by ";
2123   - if (isset ($params['sort']))
2124   - {
2125   - switch ($params['sort'])
2126   - {
2127   - case 'cine' :
2128   - $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2129   - break;
2130   - case 'click' :
2131   - $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2132   - break;
2133   - case 'rating' :
2134   - $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
2135   - break;
2136   - case 'hit' :
2137   - $sql .= " catalogs_products.hit_sort asc";
2138   - break;
2139   - default :
2140   - $sql .= " r.top desc";
2141   - }
2142   - }
2143   - else
2144   - $sql .= " r.top desc";
2145   - $sql .= " LIMIT $limit";
2146   - // print $sql;
2147   - $res = $this->db->getAll ($sql, array (
2148   - true
2149   - ), DB_FETCHMODE_ASSOC);
2150   - // print_r($res);
2151   - $this->tpl->assign ('products_top', $res);
2152   - }
2153   -
2154   - function viewProductsTopOne ()
2155   - {
2156   - $count = $this->db->getOne ("select count(*) from catalogs_products WHERE catalogs_products.header=?", array (
2157   - true
2158   - ));
2159   - $limit = 1;
2160   - $round = rand (0, ($count - $limit));
2161   - $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 (
2162   - true
2163   - ), DB_FETCHMODE_ASSOC);
2164   - $this->tpl->assign ('products_top_one', $res);
2165   - }
2166   -
2167   - function viewProductsLast ($limit = 1)
2168   - {
2169   - $search = array ();
2170   - $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=? ";
2171   - $sql .= "order by catalogs_products.mktime desc LIMIT $limit";
2172   - $res = $this->db->getAll ($sql, array (
2173   - true
2174   - ), DB_FETCHMODE_ASSOC);
2175   - $this->tpl->assign ('products_last', $res);
2176   - }
2177   -
2178   - function viewProductsHitsAll ($limit = 4)
2179   - {
2180   - $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=? ";
2181   - $sql .= "order by mktime desc LIMIT $limit";
2182   - $products_hits = $this->db->getAll ($sql, array (
2183   - true
2184   - ), DB_FETCHMODE_ASSOC);
2185   - $this->tpl->assign ('products_hits_all', $products_hits);
2186   - }
2187   -
2188   - function activeNull ($rubric_id)
2189   - {
2190   - $sql = "update catalogs_products set active=? where rubric_id=?";
2191   - $this->db->query ($sql, array (
2192   - 0,
2193   - $rubric_id
2194   - ));
2195   - }
2196   -
2197   - function viewProductOne ($id, &$row)
2198   - {
2199   - // $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 b2 ON b2.id=p.brend_id left join catalogs_brends b ON b.name=b2.name and b.active=1 where p.id=?";
2200   - $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=?";
2201   -
2202   - $row = $this->db->getRow ($sql, array (
2203   - $id
2204   - ), DB_FETCHMODE_ASSOC);
2205   - $row['ph1'] = $this->getFilterPh1 ($row['id']);
2206   -
2207   - $row['rating2'] = $row['rating'];
2208   - if (@$row['rating'])
2209   - $row['rating'] = round ((@$row['rating'] / @$row['vote_num']), 0);
2210   - else
2211   - $row['rating'] = 0;
2212   - $row['rating'] = @$row['rating'] * 17;
2213   - // print_r($row);
2214   - $this->tpl->assign ('product', $row);
2215   - }
2216   -
2217   - function deleteCompareProduct (&$compare, $id)
2218   - {
2219   - foreach ($compare as $key => $_id)
2220   - {
2221   - if ($_id == $id)
2222   - unset ($compare[$key]);
2223   - }
2224   - }
2225   -
2226   - function viewCompareProducts ($compare)
2227   - {
2228   - $products = array ();
2229   - $i = 0;
2230   - foreach ($compare as $id)
2231   - {
2232   - $sql = "select p.* from catalogs_products p where p.id=?";
2233   - $products[$i] = $this->db->getRow ($sql, array (
2234   - $id
2235   - ), DB_FETCHMODE_ASSOC);
2236   - $products[$i]['params'] = $this->getProductParams ($id);
2237   - $i ++;
2238   - } // print_r($products);
2239   - $this->tpl->assign ('products', $products);
2240   - }
2241   -
2242   - function viewProductNembers ($str_n)
2243   - {
2244   - $arr_id = explode (",", $str_n);
2245   - $products = array ();
2246   - foreach ($arr_id as $id)
2247   - {
2248   - $count = $this->db->getOne ("select count(*) from catalogs_keys_products_filters where filter_id=?", array (
2249   - trim ($id)
2250   - ));
2251   - $limit = 1;
2252   - $round = rand (0, ($count - $limit)); // " LIMIT 0,$limit"
2253   - $sql = "select catalogs_rubrics.translit as rubric_translit,catalogs_rubrics.name as rubric, 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";
2254   - $row = $this->db->getRow ($sql, array (
2255   - trim ($id)
2256   - ), DB_FETCHMODE_ASSOC);
2257   - if (count ($row) > 0)
2258   - $products[] = $row;
2259   - }
2260   -
2261   - // $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);
2262   - $this->tpl->assign ('products_parent', $products);
2263   - }
2264   -
2265   - function getProductSizeCine ($id, &$products)
2266   - {
2267   - $res = $this->db->getAll ("select * from catalogs_products_cine where product_id=?", array (
2268   - $id
2269   - ), DB_FETCHMODE_ASSOC);
2270   - $i = 0;
2271   - foreach ($res as $row)
2272   - {
2273   - $products['size_' . $row['n']] = $row['size'];
2274   - $products['cine_' . $row['n']] = $row['cine'];
2275   - $products['metka_' . $row['n']] = $row['metka'];
2276   - $products['id_cine_' . $row['n']] = $row['id'];
2277   - $i ++;
2278   - } // print_r($products);
2279   - }
2280   -
2281   - /*
2282   - * function getProductCine($id,$curs = null){
2283   - * $sql = "select cine from catalogs_products where id=?";
2284   - * $row = $this->db->getOne($sql,array($id));
2285   - * return $row;
2286   - * }
2287   - */
2288   - function getProductCine ($id)
2289   - {
2290   - $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=?";
2291   - return $this->db->getOne ($sql, array (
2292   - $id
2293   - ));
2294   - }
2295   -
2296   - function viewProductCine ($id)
2297   - {
2298   - $row = $this->db->getAll ("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC", array (
2299   - $id
2300   - ), DB_FETCHMODE_ASSOC);
2301   - $this->tpl->assign ('product_cines', $row);
2302   - }
2303   -
2304   - function viewCatalogsCurs ()
2305   - {
2306   - $uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
2307   - 'uah'
2308   - ));
2309   - $this->tpl->assign ('curs_uah', $uah);
2310   - $uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
2311   - 'uah_bank'
2312   - ));
2313   - $this->tpl->assign ('curs_uah_bank', $uah_bank);
2314   - $usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
2315   - 'usd'
2316   - ));
2317   - $this->tpl->assign ('curs_usd', $usd);
2318   - }
2319   -
2320   - function saveCurs ($data)
2321   - {
2322   - $table_name = "catalogs_curs";
2323   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
2324   - foreach ($data as $key => $value)
2325   - {
2326   - $this->db->autoExecute ($table_name, array (
2327   - 'curs' => $value
2328   - ), $DB_AUTOQUERY, "type='$key'");
2329   - }
2330   - }
2331   -
2332   - function viewVarCurs ($curs)
2333   - {
2334   - $this->tpl->assign ('curs', $curs);
2335   - }
2336   -
2337   - function viewBasketProducts ($session_basket, $curs = null, $discount = 0)
2338   - {
2339   - $products = array ();
2340   - $i = 0;
2341   - $cineAll = 0;
2342   - // $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?";
2343   - // $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=?";
2344   - $sql = "select catalogs_modifications.id,catalogs_modifications.sale,IF(catalogs_modifications.cine>0,catalogs_modifications.cine,catalogs_products.cine) 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=?";
2345   -
2346   - foreach ($session_basket as $id)
2347   - {
2348   - $products_count = 1;
2349   - if (count ($products))
2350   - {
2351   - foreach ($products as $key => $value)
2352   - {
2353   - if ($value['id'] == $id)
2354   - {
2355   - $products_count = $products[$key]['products_count'] + $products_count;
2356   - $products[$key]['products_count'] = $products_count;
2357   - $products[$key]['products_cine_all'] = $products[$key]['cine'] * $products_count;
2358   - $cineAll = $cineAll + $products[$key]['cine'];
2359   - }
2360   - }
2361   - }
2362   - if ($products_count == 1)
2363   - {
2364   - $row = $this->db->getRow ($sql, array (
2365   - $id
2366   - ), DB_FETCHMODE_ASSOC);
2367   - $products[$i] = $row;
2368   - $products[$i]['cine'] = round ($products[$i]['cine'] - ($products[$i]['cine'] * $products[$i]['sale'] / 100));
2369   -
2370   - $products[$i]['products_count'] = $products_count;
2371   - $products[$i]['products_cine_all'] = $products[$i]['cine'] * $products_count;
2372   - $cineAll = $cineAll + $products[$i]['products_cine_all'];
2373   - $i ++;
2374   - }
2375   - }
2376   - /*
2377   - * print"<pre>";
2378   - * print_r($products);
2379   - * print"</pre>";
2380   - */
2381   - $this->tpl->assign ('cineAll', $cineAll);
2382   - $this->tpl->assign ('cineAll_discount', $cineAll - (($cineAll * $discount) / 100));
2383   - $this->tpl->assign ('basket_products', $products); // print_r($products);
2384   - }
2385   -
2386   - function BasketUpload (&$session_basket, $proructs_count)
2387   - {
2388   -
2389   - // ========== ZLODEYEV ============
2390   - foreach ($proructs_count as $key => $value)
2391   - {
2392   -
2393   - // ==== îáíîâëÿåì ====
2394   -
2395   - // Âûáèðàåì èíôî î òîâàðå
2396   - $sql4 = "SELECT * FROM catalogs_modifications as m
2397   - LEFT JOIN catalogs_products as p
2398   - ON p.id=m.product_id
2399   - WHERE m.id='" . $key . "' ";
2400   - $result4 = mysql_query ($sql4) or die (mysql_error ());
2401   - if (mysql_affected_rows () != 0)
2402   - {
2403   - $item = mysql_fetch_assoc ($result4);
2404   - }
2405   -
2406   - $f = 0;
2407   -
2408   - if (isset ($_SESSION['shopcart']))
2409   - {
2410   -
2411   - foreach ($_SESSION['shopcart'] as $i => $cart)
2412   - {
2413   -
2414   - if ($cart['code'] != '' && $cart['code'] == $key)
2415   - {
2416   - $f = 1;
2417   - $_SESSION['shopcart'][$i]['count'] = $value;
2418   - $_SESSION['shopcart'][$i]['total'] = $value * $_SESSION['shopcart'][$i]['price'];
2419   - if ($_SESSION['shopcart'][$i]['total'] == 0)
2420   - {
2421   - unset ($_SESSION['shopcart'][$i]);
2422   - }
2423   - break;
2424   - }
2425   - }
2426   - }
2427   - }
2428   -
2429   - // ========== ZLODEYEV ============
2430   -
2431   - $session_basket = array ();
2432   - foreach ($proructs_count as $key => $value)
2433   - {
2434   - for ($i = 0; $i < $value; $i ++)
2435   - {
2436   - $session_basket[] = $key;
2437   - }
2438   - }
2439   - }
2440   -
2441   - function sendOrder ($data)
2442   - {
2443   - $mail = new PHPMailer ();
2444   - $mail->CharSet = "windows-1251";
2445   - $mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
2446   - $mail->FromName = $data['order_name'];
2447   - $mail->AddAddress ("shop@eltrade.com.ua", "shop");
2448   - $mail->Subject = "Îôîðìèòü çàêàç ñ ÝêñòðèìÑòèëü";
2449   - $title = Mail::str_rus ("Îôîðìèòü çàêàç");
2450   - $msg = "";
2451   - foreach ($data['product_id'] as $key => $value)
2452   - {
2453   - $msg .= "ID: " . $value . " ";
2454   - $msg .= "Íàçâàíèå: <b>" . $data['product_name'][$key] . "</b> ";
2455   - $msg .= "Öåíà çà îäèí: " . $data['product_cine'][$key] . " ";
2456   - $msg .= "Êîëè÷åñòâî: " . $data['product_count'][$key] . " ";
2457   - $msg .= "Çà âåñü òîâàð: " . $data['product_cine_all'][$key] . " ";
2458   - $msg .= "<br>";
2459   - }
2460   - $msg .= "Îáùàÿ ñóìà: " . $data['cineAll'];
2461   - $msg .= "<br>";
2462   - /*
2463   - * $msg .= "Ñêèäêà: ".$data['discount']." %";
2464   - * $msg .= "<br>";
2465   - */
2466   - $msg .= "Èòîãî ê îïëàòå: " . $data['cineAll_discount'];
2467   - $msg .= "<br><br><br>";
2468   - $msg .= "Êîíòàêòíûå äàííûå:";
2469   - $msg .= "<br>";
2470   - $msg .= "Èìÿ: " . $data['order_name'];
2471   - $msg .= "<br>";
2472   - $msg .= "Àäðåñ: " . $data['order_adress'];
2473   - $msg .= "<br>";
2474   - $msg .= "E-mail: " . $data['order_email'];
2475   - $msg .= "<br>";
2476   - $msg .= "Êîíòàêòíûé òåëåôîí: " . $data['order_phone'];
2477   - // $msg .= "<br>";
2478   - // $msg .= "Ìîáèëüíûé òåëåôîí: ".$data['order_phonemob'];
2479   - $msg .= "<br>";
2480   - $msg .= "Êîììåíòàðèé: " . $data['order_comment'];
2481   - // $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua";
2482   - // Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg));
2483   - $mail->MsgHTML ($msg);
2484   - if (! $mail->Send ())
2485   - {
2486   - echo "There has been a mail error sending to <br>";
2487   - return false;
2488   - }
2489   - $mail->ClearAddresses ();
2490   - $mail->ClearAttachments ();
2491   -
2492   - $this->sendOrderXML ($data);
2493   - }
2494   -
2495   - function sendOrderXML ($data)
2496   - {
2497   - $data['order_phone'] = str_replace ("-", "", $data['order_phone']);
2498   - $data['order_phone'] = str_replace (")", "", $data['order_phone']);
2499   - $data['order_phone'] = str_replace ("(", "", $data['order_phone']);
2500   - $data['order_phone'] = str_replace (" ", "", $data['order_phone']);
2501   - $ffffffff = substr ($data['order_phone'], 0, 3);
2502   - if ($ffffffff != "380")
2503   - $data['order_phone'] = "+38" . $data['order_phone'];
2504   -
2505   - $mail = new PHPMailer ();
2506   - $mail->CharSet = "windows-1251";
2507   - $mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
2508   - $mail->FromName = $data['order_name'];
2509   - $mail->AddAddress ("extremshop@portal.myoffice.biz.ua", "extremshop");
2510   - $mail->Subject = "xml çàêàç ñ ÝêñòðèìÑòèëü";
2511   - $order_email = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
2512   - $xml = '<?xml version="1.0" encoding="windows-1251" ?>';
2513   - $xml .= '<Order orderNum="' . mktime () . '">';
2514   - foreach ($data['product_id'] as $key => $value)
2515   - {
2516   - $xml .= "<OrderItem ID='" . $data['product_code'][$key] . "'>";
2517   - $xml .= "<ProductName>" . $data['product_name2'][$key] . "</ProductName>";
2518   - $xml .= "<Size>" . $data['product_size'][$key] . "</Size>";
2519   - $xml .= "<Color>" . $data['product_color'][$key] . "</Color>";
2520   - $xml .= "<Price>" . $data['product_price'][$key] . "</Price>";
2521   - $xml .= "<Count>" . $data['product_count'][$key] . "</Count>";
2522   - $xml .= "</OrderItem>";
2523   - }
2524   - $xml .= '<CustomerInfo>';
2525   - $xml .= '<Name>' . $data['order_name'] . '</Name>';
2526   - $xml .= '<Mobile>' . $data['order_phone'] . '</Mobile>';
2527   - $xml .= '<Email>' . $data['order_email'] . '</Email>';
2528   - $xml .= '</CustomerInfo>';
2529   - $xml .= '<DeliveryInfo>';
2530   - $xml .= '<City>Óêðàèíà</City>';
2531   - $xml .= '<Address>' . $data['order_adress'] . '</Address>';
2532   - $xml .= '<DeliveryType>Äîñòàâêà</DeliveryType>';
2533   - $xml .= '</DeliveryInfo>';
2534   - $xml .= '<Comment>' . $data['order_comment'] . '</Comment>';
2535   - $xml .= '</Order>';
2536   - $tmpfname = tempnam ("tmp", "FOO");
2537   - $handle = fopen ($tmpfname, "w");
2538   - fwrite ($handle, $xml);
2539   - $mail->AddAttachment ($tmpfname, 'order.xml');
2540   - if (! $mail->Send ())
2541   - {
2542   - echo "There has been a mail error sending to <br>";
2543   - return false;
2544   - }
2545   - fclose ($handle);
2546   - unlink ($tmpfname);
2547   - $mail->ClearAddresses ();
2548   - $mail->ClearAttachments ();
2549   - // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml));
2550   - // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml));
2551   - }
2552   -
2553   - function saveOrder ($data, $userID = 0)
2554   - {
2555   - $table_name = "catalogs_orders";
2556   -
2557   - if (isset ($data['update_id']) && $data['update_id'] > 0)
2558   - {
2559   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
2560   - $id = $data['update_id'];
2561   - $where = sprintf ("id='%d'", $id);
2562   - }
2563   - else
2564   - {
2565   - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
2566   - $id = $this->db->nextId ('mySequence_' . $table_name);
2567   - $where = null;
2568   - }
2569   -
2570   - $fields_values = array (
2571   - 'id' => $id,
2572   - 'user_id' => $userID,
2573   - 'name' => $data['order_name'],
2574   - 'email' => $data['order_email'],
2575   - 'adress' => $data['order_adress'],
2576   - // 'phone' => phone_mobil($data['order_phone']),
2577   - 'phone' => $data['order_phone'],
2578   - 'comment' => $data['order_comment'],
2579   - 'delivery' => $data['delivery'],
2580   - 'total' => $_SESSION['cart']['total'],
2581   - 'status' => '1',
2582   - 'mktime' => mktime ()
2583   - );
2584   - $DB_AUTOQUERY;
2585   -
2586   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, $where);
2587   -
2588   - if (isset ($data['product_id']))
2589   - {
2590   - $i = - 1;
2591   - foreach ($data['product_id'] as $key => $value)
2592   - {
2593   - $i ++;
2594   - $this->db->autoExecute ("catalogs_orders_products", array (
2595   - 'order_id' => $id,
2596   - 'product_id' => $value,
2597   - 'product_cine_id' => $_SESSION['cart'][$i]['price'],
2598   - 'count' => $data['product_count'][$key]
2599   - ), DB_AUTOQUERY_INSERT);
2600   - }
2601   - }
2602   - }
2603   -
2604   - function deleteOrder ($id)
2605   - {
2606   - $this->db->query ("delete from catalogs_orders where id=?", array (
2607   - $id
2608   - ));
2609   - $this->db->query ("delete from catalogs_orders_products where order_id=?", array (
2610   - $id
2611   - ));
2612   - }
2613   -
2614   - function updateOrder ($data)
2615   - {
2616   - $table_name = "catalogs_orders";
2617   - $fields_values = array (
2618   - 'name' => $data['order_name'],
2619   - 'email' => $data['order_email'],
2620   - 'adress' => $data['order_adress'],
2621   - 'phone' => $data['order_phone'],
2622   - 'comment' => $data['order_comment'],
2623   - 'mktime' => mktime ()
2624   - );
2625   - if (isset ($data['order_active']))
2626   - $fields_values['active'] = 1;
2627   - else
2628   - $fields_values['active'] = 0;
2629   - $this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, sprintf ("id='%d'", $data['update_id']));
2630   - }
2631   -
2632   - function updateOrderProducts ($data)
2633   - {
2634   - foreach ($data['product_id'] as $key => $value)
2635   - {
2636   - if ($data['product_count'][$value] < 1)
2637   - {
2638   - $this->db->query ("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");
2639   - }
2640   - else
2641   - {
2642   - $this->db->autoExecute ("catalogs_orders_products", array (
2643   - 'count' => $data['product_count'][$value]
2644   - ), DB_AUTOQUERY_UPDATE, "order_id='{$data['order_id']}' AND product_id='$value'");
2645   - }
2646   - }
2647   - }
2648   -
2649   - function viewOrder ($id)
2650   - {
2651   - $row = $this->db->getRow ("select * from catalogs_orders where id=?", array (
2652   - $id
2653   - ), DB_FETCHMODE_ASSOC);
2654   - $this->tpl->assign ('order', $row);
2655   - }
2656   -
2657   - function viewOrderProducts ($order_id)
2658   - {
2659   - $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 (
2660   - $order_id
2661   - ), DB_FETCHMODE_ASSOC);
2662   - $sum = 0;
2663   - foreach ($res as $key => $row)
2664   - {
2665   - $sum = $sum + ($row['cine'] * $row['count']);
2666   - $res[$key]['cine_all'] = ($row['cine'] * $row['count']);
2667   - }
2668   - $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 (
2669   - $order_id
2670   - ));
2671   - $this->tpl->assign ('cine', array (
2672   - 'sum' => $sum,
2673   - 'discount' => $discount,
2674   - 'sum_discount' => ($sum - (($sum * $discount) / 100))
2675   - ));
2676   - $this->tpl->assign ('basket_products', $res);
2677   - }
2678   -
2679   - function viewOrders ($params = array())
2680   - {
2681   - $search = array ();
2682   - if (isset ($params['userID']) && $params['userID'] > 0)
2683   - $search[] = sprintf ("catalogs_orders.user_id='%d'", $params['userID']);
2684   - $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 ";
2685   - if (count ($search))
2686   - $sql .= "AND " . implode (" AND ", $search) . " ";
2687   - $sql .= " order by mktime desc";
2688   - $pagerOptions = Array (
2689   - 'mode' => 'Sliding',
2690   - 'delta' => 16,
2691   - 'perPage' => 50,
2692   - 'linkClass' => "link_class",
2693   - 'curPageLinkClassName' => "link_class_active",
2694   - 'spacesBeforeSeparator' => 1,
2695   - 'spacesAfterSeparator' => 1
2696   - );
2697   - $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
2698   - foreach ($res['data'] as $key => $value)
2699   - {
2700   - $res['data'][$key]['sum'] = $this->getOrderProductsSum ($value['id']);
2701   - $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum'] * $value['discount']) / 100);
2702   - }
2703   - $this->tpl->assign ('ordersData', $res);
2704   - }
2705   -
2706   - function getOrderProductsSum ($order_id)
2707   - {
2708   - $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 (
2709   - $order_id
2710   - ), DB_FETCHMODE_ASSOC);
2711   - // print_r($res);
2712   - $sum = 0;
2713   - foreach ($res as $row)
2714   - {
2715   - $sum = $sum + ($row['cine'] * $row['count']);
2716   - }
2717   - return $sum;
2718   - }
2719   -
2720   - function SaveBrend ($data, $upload)
2721   - {
2722   - $table_name = "catalogs_brends";
2723   - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
2724   - $fields_values = array (
2725   - 'rubric_id' => $data['rubric_id'],
2726   - 'name' => $data['brend'],
2727   - 'email' => $data['email'],
2728   - 'text' => $data['text_setka'],
2729   - 'youtube' => $data['youtube'],
2730   - 'seo' => $data['seo_text'],
2731   - 'sort' => $data['sort'],
2732   - 'meta_title' => $data['meta_title'],
2733   - 'meta_description' => $data['meta_description'],
2734   - 'meta_keywords' => $data['meta_keywords'],
2735   - 'active' => $data['active'],
2736   - 'about' => $data['about'],
2737   - 'link' => $data['link'],
2738   - 'teh' => $data['teh']
2739   - );
2740   -
2741   - if (isset ($data['delete_video']) && $data['delete_video'] == 1)
2742   - {
2743   - $this->deleteBrendPic ($data['update_id']);
2744   - $fields_values['pic'] = null;
2745   - }
2746   - if ($upload['pic']['tmp_name'])
2747   - {
2748   - if ($data['update_id'] > 0)
2749   - $this->deleteBrendPic ($data['update_id'], array (
2750   - 'pic'
2751   - ));
2752   - $name_pic = mktime () . "." . substr (strrchr ($_FILES['pic']['name'], "."), 1);
2753   - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic";
2754   - move_uploaded_file ($_FILES["pic"]["tmp_name"], $file_name);
2755   - chmod ($file_name, "0777");
2756   - $fields_values['pic'] = $name_pic;
2757   - }
2758   -
2759   - if (isset ($data['delete_pic_s']) && $data['delete_pic_s'] == 1)
2760   - {
2761   - $this->deleteBrendPic ($data['update_id'], array (
2762   - 'pic_s'
2763   - ));
2764   - $fields_values['pic_s'] = null;
2765   - }
2766   - if ($upload['pic_s']['tmp_name'])
2767   - {
2768   - if ($data['update_id'] > 0)
2769   - $this->deleteBrendPic ($data['update_id'], array (
2770   - 'pic_s'
2771   - ));
2772   - $name_pic = mktime () . "." . substr (strrchr ($_FILES['pic_s']['name'], "."), 1);
2773   - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic";
2774   - move_uploaded_file ($_FILES["pic_s"]["tmp_name"], $file_name);
2775   - chmod ($file_name, "0777");
2776   - $fields_values['pic_s'] = $name_pic;
2777   - }
2778   -
2779   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
2780   - }
2781   -
2782   - function deleteBrendPic ($id, $pics = array('pic','pic_s'))
2783   - {
2784   - $sql = "select " . implode (',', $pics) . " from catalogs_brends where id=?";
2785   - $row = $this->db->getRow ($sql, array (
2786   - $id
2787   - ), DB_FETCHMODE_ASSOC);
2788   - if (isset ($row['pic']))
2789   - {
2790   - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}";
2791   - @unlink ($file_name);
2792   - }
2793   - if (isset ($row['pic_s']))
2794   - {
2795   - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}";
2796   - @unlink ($file_name);
2797   - }
2798   - }
2799   -
2800   - function viewBrends ($type = false)
2801   - {
2802   - $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id ";
2803   - if ($type != false)
2804   - $sql .= "where b.type='$type'";
2805   - $sql .= " Order by b.name Asc";
2806   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
2807   - $this->tpl->assign ('brends', $row);
2808   - }
2809   -
2810   - function viewBrendsGroup ($params = array())
2811   - {
2812   - $search = array ();
2813   - if (isset ($params['filter']) && count ($params['filter']) > 0)
2814   - $filter = $this->seralizeFilter ($params['filter']);
2815   -
2816   - if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
2817   - {
2818   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
2819   - }
2820   -
2821   - if (isset ($filter['y']) && $filter['y'] > 0)
2822   - {
2823   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
2824   - }
2825   -
2826   - if (isset ($filter['f']) && count ($filter['f']) > 0)
2827   - {
2828   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
2829   - }
2830   -
2831   - if (isset ($filter['g']) && count ($filter['g']) > 0)
2832   - {
2833   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
2834   - }
2835   -
2836   - if (isset ($filter['s']) && count ($filter['s']) > 0)
2837   - {
2838   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
2839   - }
2840   - if (isset ($filter['r']) && count ($filter['r']) > 0)
2841   - {
2842   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
2843   - }
2844   - if (isset ($_GET['new']) && $_GET['new'] > 0)
2845   - $search[] = sprintf ("catalogs_products.active='%d'", $_GET['new']);
2846   - if (isset ($_GET['top']) && $_GET['top'] > 0)
2847   - $search[] = sprintf ("catalogs_products.top='%d'", $_GET['top']);
2848   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
2849   - $search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0);
2850   - /*
2851   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
2852   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
2853   - * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
2854   - * }
2855   - */
2856   -
2857   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
2858   - {
2859   - $sex = $this->seralizeSex ($_GET['sex']);
2860   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
2861   - }
2862   -
2863   - // ==== catalogs_products ====
2864   -
2865   - $sql[] = "
2866   - SELECT *
2867   - FROM catalogs_products
2868   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
2869   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
2870   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
2871   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
2872   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
2873   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
2874   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1
2875   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
2876   - WHERE catalogs_products.count_modifications > 0
2877   - AND catalogs_brends.id > 0
2878   - ";
2879   -
2880   - if (count ($search))
2881   - {
2882   - $sql[] = "AND " . implode (" AND ", $search) . " ";
2883   - }
2884   -
2885   - if (isset ($params['rubID']) && ! isset ($params['filter_products']))
2886   - {
2887   - $rubric_id = $params['rubID']; // $this->getRubricParent($params['rubID']);
2888   - $rubric_id = ($rubric_id == 0) ? $params['rubID'] : $rubric_id;
2889   - $sql[] = "and catalogs_products.rubric_id='" . $rubric_id . "'";
2890   - }
2891   -
2892   - $sql[] = " Group by catalogs_brends.name Order by catalogs_brends.name Asc";
2893   -
2894   - if (count ($sql) > 4)
2895   - {
2896   - $row = $this->db->getAll (implode (' ', $sql), array (), DB_FETCHMODE_ASSOC);
2897   - }
2898   - else
2899   - {
2900   - // çíà÷èò ñòðàíèöà
2901   - $row = array ();
2902   - }
2903   - $this->tpl->assign ('brends', $row);
2904   - }
2905   -
2906   - // =====
2907   -
2908   - function viewBrendsActive ()
2909   - {
2910   - $sql = "select * from catalogs_brends where active=1 ";
2911   - $sql .= " Order by name Asc";
2912   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
2913   - $this->tpl->assign ('brends_a', $row);
2914   - }
2915   -
2916   - function SaveCity ($data)
2917   - {
2918   - $table_name = "catalogs_cities";
2919   - $DB_AUTOQUERY = (isset ($data['update_id']) && $data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
2920   - $fields_values = array (
2921   - 'name' => $data['name']
2922   - );
2923   - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
2924   - return mysql_insert_id ();
2925   - }
2926   -
2927   - function is_city ($name)
2928   - {
2929   - return $this->db->getOne ('select id from catalogs_cities where name=?', array (
2930   - $name
2931   - ));
2932   - }
2933   -
2934   - function viewCityMod ($code)
2935   - {
2936   - $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";
2937   - $row = $this->db->getCol ($sql, "name", array (
2938   - $code
2939   - ));
2940   - if (! count ($row))
2941   - return "";
2942   - if (count ($row) == 1 && trim ($row[0]) == '')
2943   - {
2944   - return "";
2945   - }
2946   -
2947   - foreach ($row as $key => $value)
2948   - {
2949   - if ($value == "Èíòåðíåò ìàãàçèí" or $value == "Êèåâ(Îëèìïèéñêèé)" or $value == "Ëüâîâ" or trim ($value) == "")
2950   - unset ($row[$key]);
2951   - }
2952   - $row2 = array ();
2953   - foreach ($row as $key => $value)
2954   - if (trim ($value) != '')
2955   - $row2[] = $value;
2956   - $row = $row2;
2957   -
2958   - $l = array ();
2959   - for ($i = 0; $i < count ($row); $i ++)
2960   - {
2961   - $key = 0;
2962   - for ($i2 = 0; $i2 < count ($l); $i2 ++)
2963   - if ($l[$i2] == $row[$i])
2964   - $key = 1;
2965   - if ($key == 0)
2966   - $l[] = $row[$i];
2967   - }
2968   - if (trim ($_REQUEST['test2']) != '1')
2969   - {
2970   - return implode (', ', $l);
2971   - }
2972   - return implode (', ', $row);
2973   - }
2974   -
2975   - function viewCitiesProductID ($id)
2976   - {
2977   - $sql = "select city_id from catalogs_keys_products_cities where product_id=?";
2978   - $row = $this->db->getCol ($sql, "city_id", array (
2979   - $id
2980   - ));
2981   - $this->tpl->assign ('product_cities', $row);
2982   - }
2983   -
2984   - function viewCities ($type = false)
2985   - {
2986   - $sql = "select * from catalogs_cities ";
2987   - $sql .= " Order by name Asc";
2988   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
2989   - $this->tpl->assign ('cities', $row);
2990   - }
2991   -
2992   - function viewCitiesProduct ($id)
2993   - {
2994   - $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=?";
2995   - $row = $this->db->getAll ($sql, array (
2996   - $id
2997   - ), DB_FETCHMODE_ASSOC);
2998   - $this->tpl->assign ('cities', $row);
2999   - }
3000   -
3001   - function viewCity ($id)
3002   - {
3003   - $row = $this->db->getRow ("select * from catalogs_cities where id=?", array (
3004   - $id
3005   - ), DB_FETCHMODE_ASSOC);
3006   - $this->tpl->assign ('city', $row);
3007   - }
3008   -
3009   - function deleteCity ($id)
3010   - {
3011   - $this->db->query ("delete from catalogs_cities where id=?", array (
3012   - $id
3013   - ));
3014   - $this->delete_keysCitiesProduct ($id);
3015   - }
3016   -
3017   - function delete_keysCitiesProduct ($id)
3018   - {
3019   - $sql = "delete from catalogs_keys_products_cities where city_id=?";
3020   - $this->db->query ($sql, array (
3021   - $id
3022   - ));
3023   - }
3024   -
3025   - function SaveYears ($data)
3026   - {
3027   - $table_name = "catalogs_years";
3028   - foreach ($data['filter'] as $key => $name)
3029   - {
3030   - if (strlen ($name) > 0)
3031   - {
3032   - if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
3033   - {
3034   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
3035   - $where = "id='{$data['update_id'][$key]}'";
3036   - }
3037   - else
3038   - {
3039   - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
3040   - $where = "";
3041   - }
3042   - $this->db->autoExecute ($table_name, array (
3043   - 'name' => $name,
3044   - 'rubric_id' => $data['rubric_id']
3045   - ), $DB_AUTOQUERY, $where);
3046   - }
3047   - }
3048   - }
3049   -
3050   - function viewYearsProduct ($id)
3051   - {
3052   - $sql = "select y.* from catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id where k.product_id=?";
3053   - $row = $this->db->getAll ($sql, array (
3054   - $id
3055   - ), DB_FETCHMODE_ASSOC);
3056   - $this->tpl->assign ('product_years', $row);
3057   - }
3058   -
3059   - function viewYearsProductID ($id)
3060   - {
3061   - $sql = "select year_id from catalogs_keys_products_years where product_id=?";
3062   - $row = $this->db->getCol ($sql, "year_id", array (
3063   - $id
3064   - ));
3065   - $this->tpl->assign ('product_years', $row);
3066   - }
3067   -
3068   - function viewYears ($rubric_id, $filters = null)
3069   - {
3070   - $search = array ();
3071   -
3072   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3073   - $filter = $this->seralizeFilter ($_GET['filter']);
3074   -
3075   - if (isset ($filter['f']) && count ($filter['f']) > 0)
3076   - {
3077   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
3078   - }
3079   -
3080   - if (isset ($filter['s']) && count ($filter['s']) > 0)
3081   - {
3082   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
3083   - }
3084   -
3085   - if (isset ($filter['r']) && count ($filter['r']) > 0)
3086   - {
3087   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
3088   - }
3089   -
3090   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3091   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3092   -
3093   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3094   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3095   -
3096   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3097   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3098   -
3099   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3100   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3101   -
3102   - /**
3103   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
3104   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
3105   - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
3106   - * }
3107   - */
3108   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
3109   - {
3110   - $sex = $this->seralizeSex ($_GET['sex']);
3111   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
3112   - }
3113   -
3114   - if (strlen ($filters) > 0 && ! isset ($filter['f']))
3115   - {
3116   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
3117   - }
3118   -
3119   - $sql = "
3120   - SELECT y.*
3121   - FROM catalogs_products p, catalogs_keys_products_years k
3122   - LEFT JOIN catalogs_years y ON y.id=k.year_id
3123   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
3124   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
3125   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
3126   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
3127   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
3128   - WHERE p.id=k.product_id
3129   - AND p.count_modifications>0
3130   - ";
3131   -
3132   - if ($filters == null)
3133   - $sql .= " and p.rubric_id='" . $rubric_id . "' ";
3134   -
3135   - if (count ($search))
3136   - $sql .= "AND " . implode (" AND ", $search) . " ";
3137   -
3138   - $sql .= " GROUP BY k.year_id order by y.name desc";
3139   -
3140   - // print $sql;
3141   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
3142   - $this->tpl->assign ('years', $row);
3143   - }
3144   -
3145   - function viewYearsAll ($rubric_id)
3146   - {
3147   - $sql = "SELECT * FROM catalogs_years WHERE rubric_id=? ORDER BY id asc ";
3148   - $row = $this->db->getAll ($sql, array (
3149   - $rubric_id
3150   - ), DB_FETCHMODE_ASSOC);
3151   - $this->tpl->assign ('years', $row);
3152   - }
3153   -
3154   - function viewSexProduct ($id)
3155   - {
3156   - $sql = "select * from catalogs_keys_products_sex where product_id=?";
3157   - $row = $this->db->getAll ($sql, array (
3158   - $id
3159   - ), DB_FETCHMODE_ASSOC);
3160   - $this->tpl->assign ('product_sex', $row);
3161   - }
3162   -
3163   - function viewSexProductID ($id)
3164   - {
3165   - $sql = "select sex from catalogs_keys_products_sex where product_id=?";
3166   - $row = $this->db->getCol ($sql, "sex", array (
3167   - $id
3168   - ));
3169   - $this->tpl->assign ('product_sex', $row);
3170   - }
3171   -
3172   - function viewSex ($rubric_id, $filters = null, $lang = 'rus')
3173   - {
3174   - $search = array ();
3175   -
3176   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3177   - $filter = $this->seralizeFilter ($_GET['filter']);
3178   -
3179   - if (isset ($filter['f']) && count ($filter['f']) > 0)
3180   - {
3181   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
3182   - }
3183   - if (isset ($filter['y']) && $filter['y'] > 0)
3184   - {
3185   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
3186   - }
3187   - if (isset ($filter['s']) && count ($filter['s']) > 0)
3188   - {
3189   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
3190   - }
3191   - if (isset ($filter['r']) && count ($filter['r']) > 0)
3192   - {
3193   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
3194   - }
3195   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3196   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3197   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3198   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3199   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3200   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3201   -
3202   - if (strlen ($filters) > 0 && ! isset ($filter['f']))
3203   - {
3204   - $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
3205   - }
3206   -
3207   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3208   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3209   -
3210   - $sql = "
3211   - SELECT s.sex
3212   - FROM catalogs_products p
3213   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=p.id
3214   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
3215   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
3216   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=p.id and catalogs_modifications.active=1
3217   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1
3218   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
3219   - WHERE p.count_modifications>0
3220   - AND s.sex < 4
3221   - AND p.sex > 0
3222   - ";
3223   -
3224   - if ($filters == null)
3225   - $sql .= " and p.rubric_id='" . $rubric_id . "' ";
3226   - if (count ($search))
3227   - $sql .= "AND " . implode (" AND ", $search) . " ";
3228   -
3229   - $sql .= " GROUP BY s.sex";
3230   - // print $sql;
3231   - $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
3232   - // print_r($res);
3233   - $sex = array ();
3234   - if ($lang == 'ukr')
3235   - $arr = array (
3236   - 1 => array (
3237   - 'name' => "×îëîâ³÷èé",
3238   - 'link' => 'male'
3239   - ),
3240   - 2 => array (
3241   - 'name' => "Ƴíî÷èé",
3242   - 'link' => 'female'
3243   - ),
3244   - 3 => array (
3245   - 'name' => "Äèòÿ÷èé",
3246   - 'link' => 'child'
3247   - )
3248   - );
3249   - // 4=>array('name'=>"Óí³ñåêñ",'link'=>'unisex')
3250   -
3251   - else
3252   - $arr = array (
3253   - 1 => array (
3254   - 'name' => "Ìóæñêîé",
3255   - 'link' => 'male'
3256   - ),
3257   - 2 => array (
3258   - 'name' => "Æåíñêèé",
3259   - 'link' => 'female'
3260   - ),
3261   - 3 => array (
3262   - 'name' => "Äåòñêèé",
3263   - 'link' => 'child'
3264   - )
3265   - );
3266   - // 4=>array('name'=>"Óíèñåêñ",'link'=>'unisex')
3267   -
3268   -
3269   - foreach ($res as $row)
3270   - {
3271   - $sex[] = $arr[$row['sex']];
3272   - }
3273   -
3274   - if (isset ($_GET['s']))
3275   - print_r ($sex);
3276   -
3277   - $this->tpl->assign ('sex', $sex);
3278   - }
3279   -
3280   - function getYearsName_IDs ($ids)
3281   - {
3282   - // $sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name";
3283   - // $row = $this->db->getCol($sql,"name",array());
3284   - // return implode(", ",$row);
3285   - $name = array ();
3286   - foreach ($ids as $id)
3287   - {
3288   - $name[] = $this->db->getOne ("select name from catalogs_years where id=$id", array ());
3289   - }
3290   - return implode (", ", $name);
3291   - }
3292   -
3293   - function deleteYearsRubric_id ($id)
3294   - {
3295   - $this->db->query ("delete from catalogs_years where rubric_id=?", array (
3296   - $id
3297   - ));
3298   - $this->delete_keysYearsRubric ($id);
3299   - }
3300   -
3301   - function delete_keysYearsRubric ($id)
3302   - {
3303   - $sql = "delete from catalogs_keys_products_years where rubric_id=?";
3304   - $this->db->query ($sql, array (
3305   - $id
3306   - ));
3307   - }
3308   -
3309   - function deleteYear ($id)
3310   - {
3311   - $this->db->query ("delete from catalogs_years where id=?", array (
3312   - $id
3313   - ));
3314   - $this->delete_keysYearsProduct ($id);
3315   - }
3316   -
3317   - function delete_keysYearsProduct ($id)
3318   - {
3319   - $sql = "delete from catalogs_keys_products_years where year_id=?";
3320   - $this->db->query ($sql, array (
3321   - $id
3322   - ));
3323   - }
3324   -
3325   - function SaveFilters ($data)
3326   - {
3327   - $table_name = "catalogs_filters";
3328   - foreach ($data['filter'] as $key => $name)
3329   - {
3330   - if (strlen ($name) > 0)
3331   - {
3332   - if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
3333   - {
3334   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
3335   - $where = "id='{$data['update_id'][$key]}'";
3336   - }
3337   - else
3338   - {
3339   - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
3340   - $where = "";
3341   - }
3342   - $active = (isset ($data['active'][$key])) ? 1 : 0;
3343   - $fields = array (
3344   - 'name' => $name,
3345   - "name_ukr" => $data['filter_ukr'][$key],
3346   - 'prefix' => encodestring ($name),
3347   - 'rubric_id' => $data['rubric_id'],
3348   - "ph1" => $data['ph1'][$key],
3349   - "ph1_ukr" => $data['ph1_ukr'][$key],
3350   - "sort" => $data['sort'][$key],
3351   - "active" => $active
3352   - );
3353   - if (isset ($data['cat'][$key]))
3354   - {
3355   - $fields['cat'] = $data['cat'][$key];
3356   - }
3357   - $this->db->autoExecute ($table_name, $fields, $DB_AUTOQUERY, $where);
3358   - }
3359   - }
3360   - }
3361   -
3362   - function viewFilterProduct ($id)
3363   - {
3364   - $sql = "select f.* from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where f.active='0' and k.product_id=?";
3365   - $row = $this->db->getAll ($sql, array (
3366   - $id
3367   - ), DB_FETCHMODE_ASSOC);
3368   - $this->tpl->assign ('product_filters', $row);
3369   - return $row;
3370   - }
3371   -
3372   - function viewFilterProductID ($id)
3373   - {
3374   - $sql = "select filter_id from catalogs_keys_products_filters where product_id=?";
3375   - $row = $this->db->getCol ($sql, "filter_id", array (
3376   - $id
3377   - ));
3378   - $this->tpl->assign ('product_filters', $row);
3379   - }
3380   -
3381   - function deleteFilter ($id)
3382   - {
3383   - $this->db->query ("delete from catalogs_filters where id=?", array (
3384   - $id
3385   - ));
3386   - $this->delete_keysFilterProduct ($id);
3387   - }
3388   -
3389   - function deleteFiltersRubric_id ($rubric_id)
3390   - {
3391   - $this->db->query ("delete from catalogs_filters where rubric_id=?", array (
3392   - $rubric_id
3393   - ));
3394   - $this->delete_keysFilterRubric ($rubric_id);
3395   - }
3396   -
3397   - function delete_keysFilterProduct ($id)
3398   - {
3399   - $sql = "delete from catalogs_keys_products_filters where filter_id=?";
3400   - $this->db->query ($sql, array (
3401   - $id
3402   - ));
3403   - }
3404   -
3405   - function delete_keysFilterRubric ($id)
3406   - {
3407   - $sql = "delete from catalogs_keys_products_filters where rubric_id=?";
3408   - $this->db->query ($sql, array (
3409   - $id
3410   - ));
3411   - }
3412   -
3413   - function viewFilters ($rubric_id, $all = false, $lang = 'ru')
3414   - {
3415   - $search = array ();
3416   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3417   - $filter = $this->seralizeFilter ($_GET['filter']);
3418   - if (isset ($filter['g']) && count ($filter['g']) > 0)
3419   - {
3420   - $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
3421   - }
3422   - if (isset ($filter['y']) && $filter['y'] > 0)
3423   - {
3424   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
3425   - }
3426   -
3427   - if (isset ($filter['s']) && count ($filter['s']) > 0)
3428   - {
3429   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
3430   - }
3431   -
3432   - if (isset ($filter['r']) && count ($filter['r']) > 0)
3433   - {
3434   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
3435   - }
3436   -
3437   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3438   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3439   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3440   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3441   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3442   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3443   -
3444   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3445   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3446   - /*
3447   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
3448   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
3449   - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
3450   - * }
3451   - */
3452   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
3453   - {
3454   - $sex = $this->seralizeSex ($_GET['sex']);
3455   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
3456   - }
3457   - $sql = "
3458   - SELECT f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name,f.h1" . ($lang == 'ukr' ? '_ukr' : '') . " as h1
3459   - FROM catalogs_products p, catalogs_keys_products_filters k
3460   - LEFT JOIN catalogs_filters f ON f.id=k.filter_id
3461   - LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=k.product_id
3462   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id
3463   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
3464   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
3465   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
3466   - WHERE p.id=k.product_id
3467   - AND p.count_modifications>0
3468   - ";
3469   - // $sql = "select * from catalogs_filters where 1=1 ";
3470   - if ($all == false)
3471   - $sql .= "and f.active='0' ";
3472   - if (count ($search))
3473   - $sql .= "AND " . implode (" AND ", $search) . " ";
3474   - $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
3475   - // print $sql;
3476   - $row = $this->db->getAll ($sql, array (
3477   - $rubric_id
3478   - ), DB_FETCHMODE_ASSOC);
3479   - $this->tpl->assign ('filters', $row);
3480   - }
3481   -
3482   - function viewFiltersAll ($rubric_id)
3483   - {
3484   - $row = $this->db->getAll ("select * from catalogs_filters where rubric_id=? order by sort", array (
3485   - $rubric_id
3486   - ), DB_FETCHMODE_ASSOC);
3487   - $this->tpl->assign ('filters', $row);
3488   - }
3489   -
3490   - function getFiltersName_IDs ($ids, $lang)
3491   - {
3492   - // $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
3493   - // $row = $this->db->getCol($sql,"name",array());
3494   - $name = array ();
3495   - foreach ($ids as $id)
3496   - {
3497   - $row = $this->db->getRow ("select h1" . ($lang == 'ukr' ? '_ukr' : '') . " as h1 from catalogs_filters where id=$id", array (), DB_FETCHMODE_ASSOC);
3498   - $name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']);
3499   - }
3500   -
3501   - return implode (", ", $name);
3502   - }
3503   -
3504   - function getFilters2Name_IDs ($ids)
3505   - {
3506   - // $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
3507   - // $row = $this->db->getCol($sql,"name",array());
3508   - $name = array ();
3509   - foreach ($ids as $id)
3510   - {
3511   - $row = $this->db->getRow ("select h1,name from catalogs_filters2 where id=$id", array (), DB_FETCHMODE_ASSOC);
3512   - $name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']);
3513   - }
3514   - // print_r($name);
3515   - return implode (", ", $name);
3516   - }
3517   -
3518   - function SaveFilters2 ($data)
3519   - {
3520   - $table_name = "catalogs_filters2";
3521   - foreach ($data['filter2'] as $key => $name)
3522   - {
3523   - if (strlen ($name) > 0)
3524   - {
3525   - if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
3526   - {
3527   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
3528   - $where = "id='{$data['update_id'][$key]}'";
3529   - }
3530   - else
3531   - {
3532   - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
3533   - $where = "";
3534   - }
3535   - $active = (isset ($data['active'][$key])) ? 1 : 0;
3536   - $this->db->autoExecute ($table_name, array (
3537   - 'name' => $name,
3538   - "name_ukr" => $data['filter_ukr'][$key],
3539   - 'prefix' => encodestring ($name),
3540   - 'rubric_id' => $data['rubric_id'],
3541   - "sort" => $data['sort'][$key],
3542   - "active" => $active
3543   - ), $DB_AUTOQUERY, $where);
3544   - }
3545   - }
3546   - }
3547   -
3548   - function viewFilterProductID2 ($id)
3549   - {
3550   - $sql = "select filter_id from catalogs_keys_products_filters2 where product_id=?";
3551   - $row = $this->db->getCol ($sql, "filter_id", array (
3552   - $id
3553   - ));
3554   - $this->tpl->assign ('product_filters2', $row);
3555   - }
3556   -
3557   - function deleteFilter2 ($id)
3558   - {
3559   - $this->db->query ("delete from catalogs_filters2 where id=?", array (
3560   - $id
3561   - ));
3562   - $this->delete_keysFilterProduct2 ($id);
3563   - }
3564   -
3565   - function delete_keysFilterProduct2 ($id)
3566   - {
3567   - $sql = "delete from catalogs_keys_products_filters2 where filter_id=?";
3568   - $this->db->query ($sql, array (
3569   - $id
3570   - ));
3571   - }
3572   -
3573   - function deleteFiltersRubric_id2 ($rubric_id)
3574   - {
3575   - $this->db->query ("delete from catalogs_filters2 where rubric_id=?", array (
3576   - $rubric_id
3577   - ));
3578   - $this->delete_keysFilterRubric2 ($rubric_id);
3579   - }
3580   -
3581   - function delete_keysFilterRubric2 ($id)
3582   - {
3583   - $sql = "delete from catalogs_keys_products_filters2 where rubric_id=?";
3584   - $this->db->query ($sql, array (
3585   - $id
3586   - ));
3587   - }
3588   -
3589   - function viewFilters2 ($rubric_id, $lang = 'ru')
3590   - {
3591   - $search = array ();
3592   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3593   - $filter = $this->seralizeFilter ($_GET['filter']);
3594   - if (isset ($filter['f']) && count ($filter['f']) > 0)
3595   - {
3596   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
3597   - }
3598   - if (isset ($filter['y']) && $filter['y'] > 0)
3599   - {
3600   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
3601   - }
3602   -
3603   - if (isset ($filter['s']) && count ($filter['s']) > 0)
3604   - {
3605   - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
3606   - }
3607   -
3608   - if (isset ($filter['r']) && count ($filter['r']) > 0)
3609   - {
3610   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
3611   - }
3612   -
3613   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3614   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3615   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3616   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3617   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3618   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3619   -
3620   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3621   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3622   - /*
3623   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
3624   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
3625   - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
3626   - * }
3627   - */
3628   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
3629   - {
3630   - $sex = $this->seralizeSex ($_GET['sex']);
3631   - $search[] = "s.sex IN (" . implode (",", $sex) . ")";
3632   - }
3633   - $sql = "
3634   - SELECT f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name
3635   - FROM catalogs_products p, catalogs_keys_products_filters2 k
3636   - LEFT JOIN catalogs_filters2 f ON f.id=k.filter_id
3637   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
3638   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id
3639   - LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
3640   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
3641   - LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
3642   - WHERE p.id=k.product_id
3643   - AND p.count_modifications>0
3644   - ";
3645   - // $sql = "select * from catalogs_filters where 1=1 ";
3646   - if ($all == false)
3647   - $sql .= "and f.active='0' ";
3648   - if (count ($search))
3649   - $sql .= "AND " . implode (" AND ", $search) . " ";
3650   - $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
3651   - // print $sql;
3652   - $row = $this->db->getAll ($sql, array (
3653   - $rubric_id
3654   - ), DB_FETCHMODE_ASSOC);
3655   -
3656   - // $row = $this->db->getAll("select *,f.name".($lang=='ukr'?'_ukr':'')." as name from catalogs_filters2 f where f.active='0' and f.rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC);
3657   - $this->tpl->assign ('filters2', $row);
3658   - }
3659   -
3660   - function getFiltersMod_IDs ($ids)
3661   - {
3662   - $name = array ();
3663   - foreach ($ids as $id)
3664   - {
3665   - $name[] = $this->db->getOne ("select size from catalogs_modifications where size=$id", array ());
3666   - }
3667   - return implode (", ", $name);
3668   - }
3669   -
3670   - function viewFiltersMod ($rubric_id)
3671   - {
3672   - $search = array ();
3673   -
3674   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3675   - $filter = $this->seralizeFilter ($_GET['filter']);
3676   -
3677   - if (isset ($filter['f']) && count ($filter['f']) > 0)
3678   - {
3679   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
3680   - }
3681   -
3682   - if (isset ($filter['y']) && $filter['y'] > 0)
3683   - {
3684   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
3685   - }
3686   -
3687   - if (isset ($filter['r']) && count ($filter['r']) > 0)
3688   - {
3689   - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
3690   - }
3691   -
3692   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3693   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3694   - /*
3695   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
3696   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
3697   - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
3698   - * }
3699   - */
3700   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
3701   - {
3702   - $sex = $this->seralizeSex ($_GET['sex']);
3703   - $search[] = "p.sex IN (" . implode (",", $sex) . ")";
3704   - }
3705   -
3706   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3707   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3708   -
3709   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3710   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3711   -
3712   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3713   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3714   -
3715   - $sql = "
3716   - SELECT m.*
3717   - FROM catalogs_modifications m,catalogs_products p
3718   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
3719   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
3720   - LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1
3721   - WHERE m.size<>''
3722   - ";
3723   -
3724   - if (count ($search))
3725   - $sql .= "AND " . implode (" AND ", $search) . " ";
3726   -
3727   - $sql .= "
3728   - and m.product_id=p.id
3729   - and m.active=1
3730   - and p.rubric_id=?
3731   - and p.count_modifications>0
3732   - and m.size > 0
3733   - GROUP BY m.size";
3734   - $row = $this->db->getAll ($sql, array (
3735   - $rubric_id
3736   - ), DB_FETCHMODE_ASSOC);
3737   -
3738   - if ($_GET['t'] == 1)
3739   - {
3740   - print "<pre>";
3741   - print_r ($row);
3742   - print "</pre>";
3743   - }
3744   -
3745   - $this->tpl->assign ('size', $row);
3746   - }
3747   -
3748   - function viewFiltersRost ($rubric_id)
3749   - {
3750   - $search = array ();
3751   -
3752   - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
3753   - $filter = $this->seralizeFilter ($_GET['filter']);
3754   -
3755   - if (isset ($filter['f']) && count ($filter['f']) > 0)
3756   - {
3757   - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
3758   - }
3759   -
3760   - if (isset ($filter['y']) && $filter['y'] > 0)
3761   - {
3762   - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
3763   - }
3764   -
3765   - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
3766   - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
3767   - /*
3768   - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
3769   - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
3770   - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
3771   - * }
3772   - */
3773   - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
3774   - {
3775   - $sex = $this->seralizeSex ($_GET['sex']);
3776   - $search[] = "p.sex IN (" . implode (",", $sex) . ")";
3777   - }
3778   -
3779   - $sql = "
3780   - SELECT m.*
3781   - FROM catalogs_modifications m, catalogs_products p
3782   - LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
3783   - LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
3784   - WHERE m.rost > 0";
3785   -
3786   - if (count ($search))
3787   - {
3788   - $sql .= "AND " . implode (" AND ", $search) . " ";
3789   - }
3790   -
3791   - $sql .= "
3792   - AND m.product_id=p.id
3793   - AND m.active=1
3794   - AND p.rubric_id=?
3795   - AND p.count_modifications>0
3796   - GROUP BY m.rost
3797   - ";
3798   -
3799   - $row = $this->db->getAll ($sql, array (
3800   - $rubric_id
3801   - ), DB_FETCHMODE_ASSOC);
3802   -
3803   - if ($_GET['t'] == 1)
3804   - {
3805   - print "<pre>";
3806   - print_r ($row);
3807   - print "</pre>";
3808   - }
3809   -
3810   - $this->tpl->assign ('rost', $row);
3811   - }
3812   -
3813   - function viewRostProduct ($id)
3814   - {
3815   - $sql = "select m.* from catalogs_modifications m where m.product_id=? GROUP BY m.rost";
3816   - $row = $this->db->getAll ($sql, array (
3817   - $id
3818   - ), DB_FETCHMODE_ASSOC);
3819   - $this->tpl->assign ('product_rost', $row);
3820   - }
3821   -
3822   - function viewFiltersInProducts ($filter_products, $lang = 'ru')
3823   - {
3824   - $search = array ();
3825   - if (isset ($_GET['new']) && $_GET['new'] > 0)
3826   - $search[] = sprintf ("p.active='%d'", $_GET['new']);
3827   - if (isset ($_GET['top']) && $_GET['top'] > 0)
3828   - $search[] = sprintf ("p.top='%d'", $_GET['top']);
3829   - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
3830   - $search[] = sprintf ("p.akcii_id>'%d'", 0);
3831   -
3832   - $sql = "select f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name from catalogs_products p, catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where p.id=k.product_id AND f.id IN (" . $filter_products . ") and f.active='0' ";
3833   - if (count ($search))
3834   - $sql .= "AND " . implode (" AND ", $search) . " ";
3835   - $sql .= 'GROUP BY k.filter_id order by f.sort';
3836   - // print $sql;
3837   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
3838   - $this->tpl->assign ('filters', $row);
3839   - }
3840   -
3841   - function viewBrend ($id)
3842   - {
3843   - $row = $this->db->getRow ("select * from catalogs_brends where id=?", array (
3844   - $id
3845   - ), DB_FETCHMODE_ASSOC);
3846   - $this->tpl->assign ('brend', $row);
3847   - }
3848   -
3849   - function viewBrendName ($name)
3850   - {
3851   - $name = iconv ("utf-8", "windows-1251", $name);
3852   - $sql = "select * from catalogs_brends where name=? limit 1";
3853   - $row = $this->db->getRow ($sql, array (
3854   - $name
3855   - ), DB_FETCHMODE_ASSOC);
3856   - $this->tpl->assign ('brend_seo', $row);
3857   - return $row;
3858   - }
3859   -
3860   - function getBrendIDs_name ($name)
3861   - {
3862   - $n = array ();
3863   - $name_arr = explode (";", $name);
3864   - foreach ($name_arr as $row)
3865   - {
3866   - $n[] = "'" . $row . "'";
3867   - }
3868   - // $name = iconv("utf-8", "windows-1251", $name);
3869   - $sql = "select id from catalogs_brends where name in (" . implode (",", $n) . ")";
3870   - // print $sql;
3871   - return $this->db->getCol ($sql, "id", array ());
3872   - }
3873   -
3874   - function viewBrendRubrics ($name, $lang = 'ru')
3875   - {
3876   - $name = iconv ("utf-8", "windows-1251", $name);
3877   - $sql = "
3878   - SELECT r.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,r.parent_id,r.translit,count(p.id) as c
3879   - FROM catalogs_brends b
3880   - LEFT JOIN catalogs_rubrics r On r.id=b.rubric_id
3881   - LEFT JOIN catalogs_products p On p.brend_id=b.id AND p.count_modifications>0
3882   - WHERE b.name=?
3883   - AND r.name<>''
3884   - GROUP BY p.brend_id
3885   - ";
3886   - $res = $this->db->getAll ($sql, array (
3887   - $name
3888   - ), DB_FETCHMODE_ASSOC);
3889   - $rubrics = array ();
3890   - foreach ($res as $row)
3891   - {
3892   - if ($row['c'] > 0)
3893   - {
3894   - $rubrics[$this->getRubricName ($row['parent_id'], $lang)][] = $row;
3895   - }
3896   - }
3897   - // print"<pre>";
3898   - // print_r($rubrics);
3899   - // print"</pre>";
3900   - $this->tpl->assign ('brend_rubrics', $rubrics);
3901   - }
3902   -
3903   - function deleteBrend ($id)
3904   - {
3905   - $this->db->query ("delete from catalogs_brends where id=?", array (
3906   - $id
3907   - ));
3908   - }
3909   -
3910   - function viewAkciiProductID ($id)
3911   - {
3912   - $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?";
3913   - $row = $this->db->getCol ($sql, "rubric_id", array (
3914   - $id
3915   - ));
3916   - $this->tpl->assign ('product_akcii', $row);
3917   - }
3918   -
3919   - function import_saveRubric ($name, $parent_id)
3920   - {
3921   - $id = $this->db->getOne ("select id from catalogs_rubrics where name=? and parent_id=?", array (
3922   - $name,
3923   - $parent_id
3924   - ));
3925   - if (! $id)
3926   - {
3927   - $this->db->autoExecute ("catalogs_rubrics", array (
3928   - 'name' => $name,
3929   - 'translit' => translit ($name),
3930   - 'parent_id' => $parent_id,
3931   - "level" => ($this->getLevelRubric ($parent_id) + 1)
3932   - ), DB_AUTOQUERY_INSERT);
3933   - return mysql_insert_id ();
3934   - }
3935   - return $id;
3936   - }
3937   -
3938   - function import_saveBrend ($name, $rubric_id)
3939   - {
3940   - // getRubricParent();
3941   - $id = $this->db->getOne ("select id from catalogs_brends where name=? and rubric_id=?", array (
3942   - $name,
3943   - $rubric_id
3944   - ));
3945   - if (! $id)
3946   - {
3947   - $this->db->autoExecute ("catalogs_brends", array (
3948   - 'rubric_id' => $rubric_id,
3949   - 'name' => $name
3950   - ), DB_AUTOQUERY_INSERT);
3951   - return mysql_insert_id ();
3952   - }
3953   - return $id;
3954   - }
3955   -
3956   - function import_saveFilters2 ($rubric_id, $str)
3957   - {
3958   - if (! $str)
3959   - return array ();
3960   - $row_str = explode (",", trim ($str));
3961   - $arr_id = array ();
3962   - foreach ($row_str as $str)
3963   - {
3964   - $name = trim ($str);
3965   - $name_r = explode ('=', $name);
3966   - $name = $name_r[0];
3967   - $active = (isset ($name_r[1])) ? 1 : 0;
3968   - $id = $this->db->getOne ("select id from catalogs_filters2 where rubric_id=? and name=?", array (
3969   - $rubric_id,
3970   - $name
3971   - ));
3972   - if (! $id)
3973   - {
3974   - $this->db->autoExecute ("catalogs_filters2", array (
3975   - 'rubric_id' => $rubric_id,
3976   - 'name' => $name,
3977   - 'prefix' => encodestring ($name),
3978   - 'active' => $active
3979   - ), DB_AUTOQUERY_INSERT);
3980   - $id = mysql_insert_id ();
3981   - }
3982   - else
3983   - {
3984   - $this->db->autoExecute ("catalogs_filters2", array (
3985   - 'rubric_id' => $rubric_id,
3986   - 'name' => $name,
3987   - 'prefix' => encodestring ($name),
3988   - 'active' => $active
3989   - ), DB_AUTOQUERY_UPDATE, "id=$id");
3990   - }
3991   - $arr_id[] = $id;
3992   - }
3993   - return $arr_id;
3994   - }
3995   -
3996   - function import_saveFilters ($rubric_id, $str)
3997   - {
3998   - if (! $str)
3999   - return array ();
4000   - $row_str = explode (",", trim ($str));
4001   - $arr_id = array ();
4002   - foreach ($row_str as $str)
4003   - {
4004   - $name = trim ($str);
4005   - $name_r = explode ('=', $name);
4006   - $name = $name_r[0];
4007   - $active = (isset ($name_r[1])) ? 1 : 0;
4008   - $id = $this->db->getOne ("select id from catalogs_filters where rubric_id=? and name=?", array (
4009   - $rubric_id,
4010   - $name
4011   - ));
4012   - if (! $id)
4013   - {
4014   - $this->db->autoExecute ("catalogs_filters", array (
4015   - 'rubric_id' => $rubric_id,
4016   - 'name' => $name,
4017   - 'prefix' => encodestring ($name),
4018   - 'active' => $active
4019   - ), DB_AUTOQUERY_INSERT);
4020   - $id = mysql_insert_id ();
4021   - }
4022   - else
4023   - {
4024   - $this->db->autoExecute ("catalogs_filters", array (
4025   - 'rubric_id' => $rubric_id,
4026   - 'name' => $name,
4027   - 'prefix' => encodestring ($name),
4028   - 'active' => $active
4029   - ), DB_AUTOQUERY_UPDATE, "id=$id");
4030   - }
4031   - $arr_id[] = $id;
4032   - }
4033   - return $arr_id;
4034   - }
4035   -
4036   - function import_saveYear ($rubric_id, $name)
4037   - {
4038   - if (! $name)
4039   - return false;
4040   - $id = $this->db->getOne ("select id from catalogs_years where rubric_id=? and name=?", array (
4041   - $rubric_id,
4042   - $name
4043   - ));
4044   - if (! $id)
4045   - {
4046   - $this->db->autoExecute ("catalogs_years", array (
4047   - 'rubric_id' => $rubric_id,
4048   - 'name' => $name
4049   - ), DB_AUTOQUERY_INSERT);
4050   - $id = mysql_insert_id ();
4051   - }
4052   - return ($id) ? array (
4053   - $id
4054   - ) : array ();
4055   - }
4056   -
4057   - function import_updateProductCine ($product_id, $row, $line = '', $mktime = 0)
4058   - { // print"<pre>";print_r($row);print"</pre>";
4059   - IF ($product_id > 0)
4060   - {
4061   - IF ($row[3] > 0)
4062   - {
4063   - if ($row[2] < 1)
4064   - {
4065   - $cine = $row[1];
4066   - $cine_last = 0;
4067   - }
4068   - else
4069   - {
4070   - $cine = $row[2];
4071   - $cine_last = (($row[1] > 0) ? $row[1] : $row[2]);
4072   - }
4073   - $this->db->autoExecute ("catalogs_products", array (
4074   - 'cine' => $cine,
4075   - 'cine_last' => $cine_last
4076   - ), DB_AUTOQUERY_UPDATE, "id='$product_id'");
4077   - }
4078   -
4079   - $city = trim ($row[4]);
4080   - if (! $city)
4081   - $city = "Èíòåðíåò ìàãàçèí";
4082   - // echo "OK(1) - <br/>";
4083   - if (strlen ($city) > 0)
4084   - { // print $city;
4085   - $city_id = $this->is_city ($city);
4086   - // echo "OK(2) - <br/>";
4087   - if (! $city_id)
4088   - {
4089   - $city_id = $this->SaveCity (array (
4090   - 'name' => $city
4091   - ));
4092   - }
4093   - $this->db->query ("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array (
4094   - $product_id,
4095   - $row[0],
4096   - $mktime
4097   - ));
4098   -
4099   - if ($row[3] == 0)
4100   - {
4101   - }
4102   - else
4103   - {
4104   - // $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array($product_id,$row[0],$mktime));
4105   - // echo "OK(3) - <br/>";
4106   - if ($this->getKeysModificationCity ($row[0], $city_id))
4107   - {
4108   - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
4109   - $where = "mod_code='" . $row[0] . "' and city_id='" . $city_id . "'";
4110   - }
4111   - else
4112   - {
4113   - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
4114   - $where = null;
4115   - }
4116   -
4117   - // if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;}
4118   - // print $city_id .'--'.$where."<br>";
4119   - $fields = array (
4120   - 'count' => $row[3],
4121   - 'product_id' => $product_id,
4122   - 'mod_code' => $row[0],
4123   - 'city_id' => $city_id,
4124   - 'mktime' => $mktime
4125   - );
4126   - $s = $this->db->autoExecute ("catalogs_keys_products_cities", $fields, $DB_AUTOQUERY, $where);
4127   - if (PEAR::isError ($s))
4128   - die ($s->getMessage ());
4129   - }
4130   - }
4131   - // echo "OK(4) - <br/>";
4132   - $active = $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0", array (
4133   - $row[0]
4134   - ));
4135   - // $active = true;
4136   - if ($this->db->getOne ("select count(*) from catalogs_modifications where code=?", array (
4137   - $row[0]
4138   - )) > 0)
4139   - {
4140   - $this->db->autoExecute ("catalogs_modifications", array (
4141   - 'active' => $active,
4142   - 'is_update' => 1,
4143   - 'prefix' => $row[4]
4144   - ), DB_AUTOQUERY_UPDATE, "code='" . $row[0] . "'");
4145   - // echo "OK(5) - <br/>";
4146   - }
4147   - else
4148   - {
4149   - // echo "OK(6) - <br/>";
4150   - $this->saveCsvMod ($line);
4151   - }
4152   - }
4153   - }
4154   -
4155   - function saveCsvMod ($line)
4156   - {
4157   - echo "OK1 - <br/>";
4158   - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv";
4159   - $handle = @fopen ($tmpfname, "a");
4160   - // $row = explode(";",$line);
4161   - // File_FGetCSV::fputcsv($handle,$row,';');
4162   - echo "OK2 - <br/>";
4163   - echo $line;
4164   - echo "OK3 - <br/>";
4165   - fwrite ($handle, $line);
4166   - fclose ($handle);
4167   - }
4168   -
4169   - function getKeysModificationCity ($code, $city_id)
4170   - {
4171   - return $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array (
4172   - $code,
4173   - $city_id
4174   - ));
4175   - }
4176   -
4177   - function getKeysModificationCity_count ($code, $city_id)
4178   - {
4179   - return $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array (
4180   - $code,
4181   - $city_id
4182   - ));
4183   - }
4184   -
4185   - function getKeysModificationCityMktime_count ($code, $city_id, $mktime)
4186   - {
4187   - $r = $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array (
4188   - $code,
4189   - $city_id,
4190   - $mktime
4191   - ));
4192   - return $r;
4193   - }
4194   -
4195   - function getProductID ($name)
4196   - {
4197   - $id = $this->db->getOne ("select id from catalogs_products where name=?", array (
4198   - $name
4199   - ));
4200   - return $id;
4201   - }
4202   -
4203   - function getProductID_R ($name, $rubric_parent_id)
4204   - {
4205   - $id = $this->db->getOne ("select id from catalogs_products where name=? and rubric_id=?", array (
4206   - $name,
4207   - $rubric_parent_id
4208   - ));
4209   -
4210   - return $id;
4211   - }
4212   -
4213   - function getModificationActive ($code)
4214   - {
4215   - return $this->db->getOne ("select active from catalogs_modifications where code=?", array (
4216   - $code
4217   - ));
4218   - }
4219   -
4220   - function updateProduct_countModification ($product_id, $count)
4221   - {
4222   - $this->db->autoExecute ("catalogs_products", array (
4223   - 'count_modifications' => $count
4224   - ), DB_AUTOQUERY_UPDATE, "id='$product_id'");
4225   - }
4226   -
4227   - function updateProductModificationCountPrefix ($product_id, $prefix = "+")
4228   - {
4229   - // print $product_id;
4230   - $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?";
4231   - $this->db->query ($sql, array (
4232   - $product_id
4233   - ));
4234   - }
4235   -
4236   - function exportCSV ()
4237   - {
4238   - $tmpfname = "tmp/price.csv";
4239   - $handle = fopen ($tmpfname, "w");
4240   - // fwrite($handle, $xml);
4241   - $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,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null 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 ());
4242   - foreach ($res as $key => $row)
4243   - {
4244   - $list = $row;
4245   - $mod_res = $this->db->getAll ('select code,size,color,pic_big,active from catalogs_modifications where product_id=? Order by id', array (
4246   - $row[0]
4247   - ));
4248   - foreach ($mod_res as $mod_row)
4249   - {
4250   - $list[] = implode ('=', $mod_row);
4251   - }
4252   -
4253   - $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 (
4254   - $list[0]
4255   - ));
4256   - $list[8] = implode (',', $f_row);
4257   -
4258   - $f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?", 'name', array (
4259   - $list[0]
4260   - ));
4261   - $list[9] = implode (',', $f_row);
4262   -
4263   - switch ($list[10])
4264   - {
4265   - case 1 :
4266   - $list[10] = 'ìóæñêîé';
4267   - break;
4268   - case 2 :
4269   - $list[10] = 'æåíñêèé';
4270   - break;
4271   - case 3 :
4272   - $list[10] = 'äåòñêèé';
4273   - break;
4274   - case 4 :
4275   - $list[10] = 'óíèñåêñ';
4276   - break;
4277   - default :
4278   - $list[10] = 'ìóæñêîé';
4279   - break;
4280   - }
4281   -
4282   - $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 (
4283   - $list[0]
4284   - ));
4285   - $list[11] = implode (',', $y_row);
4286   -
4287   - $p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array (
4288   - $list[0]
4289   - ));
4290   - $list[20] = implode (',', $p_row);
4291   -
4292   - // print_r($list);exit;
4293   - $p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array (
4294   - $list[0]
4295   - ));
4296   - $param = array ();
4297   - foreach ($p_res as $row_p)
4298   - {
4299   - $param[] = implode ('*', $row_p);
4300   - }
4301   - $list[17] = implode ('=', $param);
4302   -
4303   - unset ($list[0]);
4304   - unset ($list[1]);
4305   -
4306   - File_FGetCSV::fputcsv ($handle, $list, ';');
4307   - }
4308   -
4309   - fclose ($handle);
4310   -
4311   - $params = array (
4312   - 'file' => $tmpfname,
4313   - 'contenttype' => 'application/xls',
4314   - 'contentdisposition' => array (
4315   - HTTP_DOWNLOAD_ATTACHMENT,
4316   - 'price.csv'
4317   - ),
4318   - 'cache' => false
4319   - );
4320   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4321   - if ($error === true)
4322   - {
4323   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4324   - }
4325   -
4326   - unlink ($tmpfname);
4327   - }
4328   -
4329   - function exportCSVaktual ()
4330   - {
4331   - $tmpfname = "tmp/price.csv";
4332   - $handle = fopen ($tmpfname, "w");
4333   - // fwrite($handle, $xml);
4334   - $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,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null 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 WHERE p.count_modifications>0', array ());
4335   - foreach ($res as $key => $row)
4336   - {
4337   - $list = $row;
4338   - $mod_res = $this->db->getAll ('select code,size,rost,color,pic_big,active from catalogs_modifications where product_id=? Order by id', array (
4339   - $row[0]
4340   - ));
4341   - foreach ($mod_res as $mod_row)
4342   - {
4343   - if (strlen ($mod_row[2]) > 0)
4344   - $mod_row[1] = $mod_row[1] . '*' . $mod_row[2];
4345   - unset ($mod_row[2]);
4346   - $list[] = implode ('=', $mod_row);
4347   - }
4348   -
4349   - $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 (
4350   - $list[0]
4351   - ));
4352   - $list[8] = implode (',', $f_row);
4353   -
4354   - $f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?", 'name', array (
4355   - $list[0]
4356   - ));
4357   - $list[9] = implode (',', $f_row);
4358   -
4359   - switch ($list[10])
4360   - {
4361   - case 1 :
4362   - $list[10] = 'ìóæñêîé';
4363   - break;
4364   - case 2 :
4365   - $list[10] = 'æåíñêèé';
4366   - break;
4367   - case 3 :
4368   - $list[10] = 'äåòñêèé';
4369   - break;
4370   - case 4 :
4371   - $list[10] = 'óíèñåêñ';
4372   - break;
4373   - default :
4374   - $list[10] = 'ìóæñêîé';
4375   - break;
4376   - }
4377   -
4378   - $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 (
4379   - $list[0]
4380   - ));
4381   - $list[11] = implode (',', $y_row);
4382   -
4383   - $p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array (
4384   - $list[0]
4385   - ));
4386   - $list[20] = implode (',', $p_row);
4387   -
4388   - // print_r($list);exit;
4389   - $p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array (
4390   - $list[0]
4391   - ));
4392   - $param = array ();
4393   - foreach ($p_res as $row_p)
4394   - {
4395   - $param[] = implode ('*', $row_p);
4396   - }
4397   - $list[17] = implode ('=', $param);
4398   -
4399   - unset ($list[0]);
4400   - unset ($list[1]);
4401   -
4402   - File_FGetCSV::fputcsv ($handle, $list, ';');
4403   - }
4404   -
4405   - fclose ($handle);
4406   -
4407   - $params = array (
4408   - 'file' => $tmpfname,
4409   - 'contenttype' => 'application/xls',
4410   - 'contentdisposition' => array (
4411   - HTTP_DOWNLOAD_ATTACHMENT,
4412   - 'price.csv'
4413   - ),
4414   - 'cache' => false
4415   - );
4416   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4417   - if ($error === true)
4418   - {
4419   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4420   - }
4421   -
4422   - unlink ($tmpfname);
4423   - }
4424   -
4425   - function exportModCSV ()
4426   - {
4427   - $tmpfname = "tmp/price_mod.csv";
4428   - $handle = fopen ($tmpfname, "w");
4429   - $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 Order by m.id');
4430   - foreach ($res as $key => $row)
4431   - {
4432   - File_FGetCSV::fputcsv ($handle, $row, ';');
4433   - }
4434   - fclose ($handle);
4435   - $params = array (
4436   - 'file' => $tmpfname,
4437   - 'contenttype' => 'application/xls',
4438   - 'contentdisposition' => array (
4439   - HTTP_DOWNLOAD_ATTACHMENT,
4440   - 'file_1.csv'
4441   - ),
4442   - 'cache' => false
4443   - );
4444   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4445   - if ($error === true)
4446   - {
4447   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4448   - }
4449   -
4450   - unlink ($tmpfname);
4451   - $this->db->autoExecute ("catalogs_modifications", array (
4452   - 'is_update' => 0
4453   - ), DB_AUTOQUERY_UPDATE);
4454   - }
4455   -
4456   - /**
4457   - * Ýêñïîðò ñ ðàçáèâêîé íà ÷àñòè
4458   - */
4459   - function exportUsersCSV ()
4460   - {
4461   - set_time_limit(3000);
4462   - ini_set('memory_limit', '256M');
4463   -
4464   - $param = array (
4465   - 'parts' => 1,
4466   - 'count' => 0,
4467   - 'start' => 0,
4468   - 'end' => 0,
4469   - 'limit' => 0,
4470   - 'folder' => $_SERVER['DOCUMENT_ROOT'].'/tmp',
4471   - 'files' => array(),
4472   - 'zip_name' => 'users.zip',
4473   - );
4474 1637  
4475   -
4476   - $total = $this->db->getOne ('
4477   - SELECT count(id) as total
4478   - FROM zlo_users
4479   - ');
4480   -
4481   - $param['limit'] = round ($total / $param['parts']);
4482   -
4483   - for ($i = 0; $i < $param['parts']; $i++)
4484   - {
4485   - $param['files'][] = $param['folder'].'/user-'.$i.'.csv';
4486   - $param['count'] = $i;
4487   - $param['start'] = $i * $param['limit'];
4488   -
4489   - $this->exportUsersFiles ($param);
4490   - }
4491   -
4492   - // ==== ZIP ====
  1638 + // ========== ZLODEYEV ============
4493 1639  
4494   - $zip = new ZipArchive();
4495   -
4496   - if ($zip->open($param['zip_name'], ZIPARCHIVE::CREATE) === TRUE)
4497   - {
4498   - foreach ($param['files'] as $i => $file)
4499   - {
4500   - $content = file_get_contents($file);
4501   - $zip->addFromString(pathinfo ($file, PATHINFO_FILENAME).'.csv', $content);
4502   -
4503   - unlink ($file);
4504   - }
4505   -
4506   - $zip->close();
4507   -
4508   - if (file_exists ($param['zip_name']))
4509   - {
4510   - // îòäà¸ì ôàéë íà ñêà÷èâàíèå
4511   - header('Content-type: application/zip');
4512   - header('Content-Disposition: attachment; filename="'.$param['zip_name'].'"');
4513   - readfile($param['zip_name']);
4514   -
4515   - // óäàëÿåì zip ôàéë åñëè îí ñóùåñòâóåò
4516   - unlink ($param['zip_name']);
4517   - }
4518   - }
4519   - }
4520   -
4521   - function exportUsersFiles ($param)
4522   - {
4523   - $tmpfname = $param['files'][$param['count']];
4524   -
4525   - $handle = fopen ($tmpfname, "w");
4526   -
4527   - $sql = '
4528   - SELECT
4529   - u.id,
4530   - u.username,
4531   - u.tel,
4532   - u.city,
4533   - u.email,
4534   - g.name,
4535   - u.registered,
4536   - summary,
4537   - u.birthday,
4538   - c.card
4539   - FROM zlo_users AS u
4540   - LEFT JOIN card c ON c.user_id = u.id
4541   - LEFT JOIN zlo_users_group AS g ON u.group = g.id
4542   - LEFT JOIN (
4543   - SELECT user_id AS order_user_id, sum( `total` ) AS `summary`
4544   - FROM catalogs_orders
4545   - GROUP BY user_id
4546   - ) o ON u.id = o.order_user_id
4547   - LIMIT '.$param['start'].', '.$param['limit'].'
4548   - ';
4549   -
4550   - $res = $this->db->getAll ($sql);
4551   -
4552   - foreach ($res as $key => $row)
4553   - {
4554   - File_FGetCSV::fputcsv ($handle, $row, ';');
4555   - }
4556   -
4557   - fclose ($handle);
4558   - }
4559 1640  
4560   - function exportUsersBirdthCSV ()
4561   - {
4562   - $tmpfname = "tmp/usersBirdth.csv";
4563   - $handle = fopen ($tmpfname, "w");
4564   -
4565   - $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,u.birthday,c.card
4566   - FROM zlo_users AS u
4567   - LEFT JOIN card c ON c.user_id = u.id
4568   - LEFT JOIN zlo_users_group AS g ON u.group = g.id
4569   - WHERE DAYOFMONTH(u.birthday) >= '19' AND DAYOFMONTH(u.birthday) <= '28' and MONTH(u.birthday) = '10'
4570   - ";
4571   - $res = $this->db->getAll ($sql);
4572   - foreach ($res as $key => $row)
4573   - {
4574   - File_FGetCSV::fputcsv ($handle, $row, ';');
4575   - }
4576   - fclose ($handle);
4577   - $params = array (
4578   - 'file' => $tmpfname,
4579   - 'contenttype' => 'application/xls',
4580   - 'contentdisposition' => array (
4581   - HTTP_DOWNLOAD_ATTACHMENT,
4582   - 'users.csv'
4583   - ),
4584   - 'cache' => false
4585   - );
4586   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4587   - if ($error === true)
4588   - {
4589   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4590   - }
4591   -
4592   - unlink ($tmpfname);
4593   - }
4594   -
4595   - function exportSeoF1CSV ()
4596   - {
4597   - $tmpfname = "tmp/seo_f1.csv";
4598   - $handle = fopen ($tmpfname, "w");
4599   - $res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics");
4600   - foreach ($res as $key => $row)
4601   - {
4602   - // $res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
4603   - // foreach($res_b as $row_b){
4604   - $list = array ();
4605   - $f_res = $this->db->getAll ("select id,prefix,name from catalogs_filters where rubric_id=?", array (
4606   - $row[0]
4607   - ));
4608   - foreach ($f_res as $f_row)
4609   - {
4610   - $list[0] = $row[0];
4611   - $list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1];
4612   - $list[2] = $f_row[2];
4613   - $list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;filter=f" . $f_row[0] . "_" . $f_row[1] . "/";
4614   - // $list[4] = $row_b[0];
4615   - File_FGetCSV::fputcsv ($handle, $list, ';');
4616   - }
4617   - // }
4618   - }
4619   -
4620   - $res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics");
4621   - foreach ($res as $key => $row)
4622   - {
4623   - // $res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
4624   - // foreach($res_b as $row_b){
4625   - $list = array ();
4626   - $f_res = $this->db->getAll ("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id", array (
4627   - $row[0]
4628   - ));
4629   - foreach ($f_res as $f_row)
4630   - {
4631   - if (! strlen ($f_row[0]))
4632   - continue;
4633   - $list[0] = $row[0];
4634   - $list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1];
4635   - $list[2] = $f_row[0];
4636   - $list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;brend=" . $f_row[0] . "/";
4637   - // $list[4] = $row_b[0];
4638   - File_FGetCSV::fputcsv ($handle, $list, ';');
4639   - }
4640   - // }
4641   - }
4642   -
4643   - fclose ($handle);
4644   - $params = array (
4645   - 'file' => $tmpfname,
4646   - 'contenttype' => 'application/xls',
4647   - 'contentdisposition' => array (
4648   - HTTP_DOWNLOAD_ATTACHMENT,
4649   - 'seo_f1.csv'
4650   - ),
4651   - 'cache' => false
4652   - );
4653   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4654   - if ($error === true)
4655   - {
4656   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4657   - }
4658   -
4659   - unlink ($tmpfname);
4660   - }
4661   -
4662   - function exportSeoCSV ()
  1641 + $session_basket = array();
  1642 + foreach($proructs_count as $key=>$value){
  1643 + for($i=0;$i<$value;$i++){
  1644 + $session_basket[] = $key;
  1645 + }
  1646 + }
  1647 + }
  1648 +
  1649 + function sendOrder($data){
  1650 + $mail = new PHPMailer();
  1651 + $mail->CharSet = "windows-1251";
  1652 + $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
  1653 + $mail->FromName = $data['order_name'];
  1654 + $mail->AddAddress("shop@eltrade.com.ua","shop");
  1655 + $mail->Subject = "Îôîðìèòü çàêàç ñ ÝêñòðèìÑòèëü";
  1656 + $title = Mail::str_rus("Îôîðìèòü çàêàç");
  1657 + $msg = "";
  1658 + foreach($data['product_id'] as $key=>$value){
  1659 + $msg .= "ID: ".$value." ";
  1660 + $msg .= "Íàçâàíèå: <b>".$data['product_name'][$key]."</b> ";
  1661 + $msg .= "Öåíà çà îäèí: ".$data['product_cine'][$key]." ";
  1662 + $msg .= "Êîëè÷åñòâî: ".$data['product_count'][$key]." ";
  1663 + $msg .= "Çà âåñü òîâàð: ".$data['product_cine_all'][$key]." ";
  1664 + $msg .= "<br>";
  1665 + }
  1666 + $msg .= "Îáùàÿ ñóìà: ".$data['cineAll'];
  1667 + $msg .= "<br>";
  1668 + /* $msg .= "Ñêèäêà: ".$data['discount']." %";
  1669 + $msg .= "<br>"; */
  1670 + $msg .= "Èòîãî ê îïëàòå: ".$data['cineAll_discount'];
  1671 + $msg .= "<br><br><br>";
  1672 + $msg .= "Êîíòàêòíûå äàííûå:";
  1673 + $msg .= "<br>";
  1674 + $msg .= "Èìÿ: ".$data['order_name'];
  1675 + $msg .= "<br>";
  1676 + $msg .= "Àäðåñ: ".$data['order_adress'];
  1677 + $msg .= "<br>";
  1678 + $msg .= "E-mail: ".$data['order_email'];
  1679 + $msg .= "<br>";
  1680 + $msg .= "Êîíòàêòíûé òåëåôîí: ".$data['order_phone'];
  1681 +// $msg .= "<br>";
  1682 +// $msg .= "Ìîáèëüíûé òåëåôîí: ".$data['order_phonemob'];
  1683 + $msg .= "<br>";
  1684 + $msg .= "Êîììåíòàðèé: ".$data['order_comment'];
  1685 +// $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua";
  1686 +// Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg));
  1687 + $mail->MsgHTML($msg);
  1688 + if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;}
  1689 + $mail->ClearAddresses();
  1690 + $mail->ClearAttachments();
  1691 +
  1692 + $this->sendOrderXML($data);
  1693 + }
  1694 +
  1695 +
  1696 + function sendOrderXML($data){
  1697 +
  1698 +
  1699 +
  1700 +$data['order_phone'] = str_replace("-","",$data['order_phone']);
  1701 +$data['order_phone'] = str_replace(")","",$data['order_phone']);
  1702 +$data['order_phone'] = str_replace("(","",$data['order_phone']);
  1703 +$data['order_phone'] = str_replace(" ","",$data['order_phone']);
  1704 +$ffffffff = substr($data['order_phone'],0,3);
  1705 +if($ffffffff!="380")
  1706 +$data['order_phone'] = "+38".$data['order_phone'];
  1707 +
  1708 +
  1709 +
  1710 + $mail = new PHPMailer();
  1711 + $mail->CharSet = "windows-1251";
  1712 + $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
  1713 + $mail->FromName = $data['order_name'];
  1714 + $mail->AddAddress("extremshop@portal.myoffice.biz.ua","extremshop");
  1715 + $mail->Subject = "xml çàêàç ñ ÝêñòðèìÑòèëü";
  1716 + $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
  1717 + $xml = '<?xml version="1.0" encoding="windows-1251" ?>';
  1718 + $xml .= '<Order orderNum="'.mktime().'">';
  1719 + foreach($data['product_id'] as $key=>$value){
  1720 + $xml .= "<OrderItem ID='".$data['product_code'][$key]."'>";
  1721 + $xml .= "<ProductName>".$data['product_name2'][$key]."</ProductName>";
  1722 + $xml .= "<Size>".$data['product_size'][$key]."</Size>";
  1723 + $xml .= "<Color>".$data['product_color'][$key]."</Color>";
  1724 + $xml .= "<Price>".$data['product_price'][$key]."</Price>";
  1725 + $xml .= "<Count>".$data['product_count'][$key]."</Count>";
  1726 + $xml .= "</OrderItem>";
  1727 + }
  1728 + $xml .= '<CustomerInfo>';
  1729 + $xml .= '<Name>'.$data['order_name'].'</Name>';
  1730 + $xml .= '<Mobile>'.$data['order_phone'].'</Mobile>';
  1731 + $xml .= '<Email>'.$data['order_email'].'</Email>';
  1732 + $xml .= '</CustomerInfo>';
  1733 + $xml .= '<DeliveryInfo>';
  1734 + $xml .= '<City>Óêðàèíà</City>';
  1735 + $xml .= '<Address>'.$data['order_adress'].'</Address>';
  1736 + $xml .= '<DeliveryType>Äîñòàâêà</DeliveryType>';
  1737 + $xml .= '</DeliveryInfo>';
  1738 + $xml .= '<Comment>'.$data['order_comment'].'</Comment>';
  1739 + $xml .= '</Order>';
  1740 + $tmpfname = tempnam("tmp", "FOO");
  1741 + $handle = fopen($tmpfname, "w");
  1742 + fwrite($handle, $xml);
  1743 + $mail->AddAttachment($tmpfname, 'order.xml');
  1744 + if(!$mail->Send()){echo "There has been a mail error sending to <br>";return false;}
  1745 + fclose($handle);
  1746 + unlink($tmpfname);
  1747 + $mail->ClearAddresses();
  1748 + $mail->ClearAttachments();
  1749 + // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml));
  1750 + // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml));
  1751 + }
  1752 +
  1753 + function saveOrder($data,$userID = 0){
  1754 +
  1755 + $table_name = "catalogs_orders";
  1756 +
  1757 + if(isset($data['update_id']) && $data['update_id']>0){
  1758 + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
  1759 + $id = $data['update_id'];
  1760 + $where = sprintf("id='%d'",$id);
  1761 + } else {
  1762 + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
  1763 + $id = $this->db->nextId('mySequence_'.$table_name);
  1764 + $where = null;
  1765 + }
  1766 +
  1767 +
  1768 +
  1769 +
  1770 + $fields_values = array(
  1771 + 'id'=>$id,
  1772 + 'user_id'=>$userID,
  1773 + 'name' => $data['order_name'],
  1774 + 'email' => $data['order_email'],
  1775 + 'adress' => $data['order_adress'],
  1776 + //'phone' => phone_mobil($data['order_phone']),
  1777 + 'phone' => $data['order_phone'],
  1778 + 'comment' => $data['order_comment'],
  1779 + 'delivery' => $data['delivery'],
  1780 + 'total'=>$_SESSION['cart']['total'],
  1781 + 'status' => '1',
  1782 + 'mktime'=>mktime()
  1783 + );
  1784 + $DB_AUTOQUERY;
  1785 +
  1786 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where);
  1787 +
  1788 + if(isset($data['product_id'])){ $i=-1;
  1789 + foreach($data['product_id'] as $key=>$value){ $i++;
  1790 + $this->db->autoExecute("catalogs_orders_products",array(
  1791 + 'order_id'=>$id,
  1792 + 'product_id'=>$value,
  1793 + 'product_cine_id'=>$_SESSION['cart'][$i]['price'],
  1794 + 'count'=>$data['product_count'][$key])
  1795 + ,DB_AUTOQUERY_INSERT);
  1796 + }
  1797 + }
  1798 +
  1799 +
  1800 + }
  1801 +
  1802 + function deleteOrder($id){
  1803 + $this->db->query("delete from catalogs_orders where id=?",array($id));
  1804 + $this->db->query("delete from catalogs_orders_products where order_id=?",array($id));
  1805 + }
  1806 +
  1807 + function updateOrder($data){
  1808 + $table_name = "catalogs_orders";
  1809 + $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());
  1810 + if(isset($data['order_active']))$fields_values['active'] = 1;
  1811 + else $fields_values['active'] = 0;
  1812 + $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,sprintf("id='%d'",$data['update_id']));
  1813 + }
  1814 +
  1815 + function updateOrderProducts($data){
  1816 + foreach($data['product_id'] as $key=>$value){
  1817 + if($data['product_count'][$value]<1){$this->db->query("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");}
  1818 + 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'");}
  1819 + }
  1820 + }
  1821 +
  1822 + function viewOrder($id){
  1823 + $row = $this->db->getRow("select * from catalogs_orders where id=?",array($id),DB_FETCHMODE_ASSOC);
  1824 + $this->tpl->assign('order', $row);
  1825 + }
  1826 +
  1827 + function viewOrderProducts($order_id){
  1828 + $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);
  1829 + $sum = 0;
  1830 + foreach($res as $key=>$row){
  1831 + $sum = $sum + ($row['cine']*$row['count']);
  1832 + $res[$key]['cine_all'] = ($row['cine']*$row['count']);
  1833 + }
  1834 + $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));
  1835 + $this->tpl->assign('cine', array('sum'=>$sum,'discount'=>$discount,'sum_discount'=>($sum - (($sum*$discount)/100)) ));
  1836 + $this->tpl->assign('basket_products', $res);
  1837 + }
  1838 +
  1839 + function viewOrders($params = array()){
  1840 + $search = array();
  1841 + if(isset($params['userID']) && $params['userID']>0)$search[] = sprintf("catalogs_orders.user_id='%d'",$params['userID']);
  1842 + $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 ";
  1843 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1844 + $sql .= " order by mktime desc";
  1845 + $pagerOptions = Array(
  1846 + 'mode' => 'Sliding',
  1847 + 'delta' => 16,
  1848 + 'perPage' => 50,
  1849 + 'linkClass'=>"link_class",
  1850 + 'curPageLinkClassName'=>"link_class_active",
  1851 + 'spacesBeforeSeparator' => 1,
  1852 + 'spacesAfterSeparator' => 1
  1853 + );
  1854 + $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array());
  1855 + foreach($res['data'] as $key=>$value){
  1856 + $res['data'][$key]['sum'] = $this->getOrderProductsSum($value['id']);
  1857 + $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum']*$value['discount'])/100);
  1858 + }
  1859 + $this->tpl->assign('ordersData', $res);
  1860 + }
  1861 +
  1862 + function getOrderProductsSum($order_id){
  1863 + $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);
  1864 + // print_r($res);
  1865 + $sum = 0;
  1866 + foreach($res as $row){
  1867 + $sum = $sum + ($row['cine']*$row['count']);
  1868 + }
  1869 + return $sum;
  1870 + }
  1871 +
  1872 + function SaveBrend($data,$upload){
  1873 + $table_name = "catalogs_brends";
  1874 + $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  1875 + $fields_values = array('rubric_id'=>$data['rubric_id'],'name'=>$data['brend'],'email'=>$data['email'],'text'=>$data['text_setka'],'youtube'=>$data['youtube'],'seo'=>$data['seo_text'],'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']);
  1876 +
  1877 + if(isset($data['delete_video']) && $data['delete_video']==1){
  1878 + $this->deleteBrendPic($data['update_id']);
  1879 + $fields_values['pic'] = null;
  1880 + }
  1881 + if($upload['pic']['tmp_name']){
  1882 + if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic'));
  1883 + $name_pic = mktime() . "." . substr(strrchr($_FILES['pic']['name'],"."),1);
  1884 + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic";
  1885 + move_uploaded_file($_FILES["pic"]["tmp_name"], $file_name);
  1886 + chmod($file_name,"0777");
  1887 + $fields_values['pic'] = $name_pic;
  1888 + }
  1889 +
  1890 + if(isset($data['delete_pic_s']) && $data['delete_pic_s']==1){
  1891 + $this->deleteBrendPic($data['update_id'],array('pic_s'));
  1892 + $fields_values['pic_s'] = null;
  1893 + }
  1894 + if($upload['pic_s']['tmp_name']){
  1895 + if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic_s'));
  1896 + $name_pic = mktime() . "." . substr(strrchr($_FILES['pic_s']['name'],"."),1);
  1897 + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic";
  1898 + move_uploaded_file($_FILES["pic_s"]["tmp_name"], $file_name);
  1899 + chmod($file_name,"0777");
  1900 + $fields_values['pic_s'] = $name_pic;
  1901 + }
  1902 +
  1903 +
  1904 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
  1905 + }
  1906 +
  1907 + function deleteBrendPic($id,$pics = array('pic','pic_s')){
  1908 + $sql = "select " . implode(',',$pics) . " from catalogs_brends where id=?";
  1909 + $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC);
  1910 + if(isset($row['pic'])){
  1911 + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}";
  1912 + @unlink($file_name);
  1913 + }
  1914 + if(isset($row['pic_s'])){
  1915 + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}";
  1916 + @unlink($file_name);
  1917 + }
  1918 + }
  1919 +
  1920 + function viewBrends($type = false){
  1921 + $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id ";
  1922 + if($type!=false)$sql .= "where b.type='$type'";
  1923 + $sql .= " Order by b.name Asc";
  1924 + $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  1925 + $this->tpl->assign('brends',$row);
  1926 + }
  1927 +
  1928 + function viewBrendsGroup($params = array()){
  1929 + $search = array();
  1930 + if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']);
  1931 +
  1932 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){
  1933 + $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")";
  1934 + }
  1935 +
  1936 + if(isset($filter['y']) && $filter['y']>0){
  1937 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  1938 + }
  1939 +
  1940 + if(isset($filter['f']) && count($filter['f'])>0){
  1941 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  1942 + }
  1943 +
  1944 + if(isset($filter['g']) && count($filter['g'])>0){
  1945 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  1946 + }
  1947 +
  1948 + if(isset($filter['s']) && count($filter['s'])>0){
  1949 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  1950 + }
  1951 + if(isset($filter['r']) && count($filter['r'])>0){
  1952 + $search[] = "m2.rost in (".implode(",",$filter['r']).")";
  1953 + }
  1954 + if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("catalogs_products.active='%d'",$_GET['new']);
  1955 + if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("catalogs_products.top='%d'",$_GET['top']);
  1956 +if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("catalogs_products.akcii_id>'%d'",0);
  1957 + /*if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1958 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  1959 + $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
  1960 + }*/
  1961 +
  1962 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  1963 + $sex = $this->seralizeSex($_GET['sex']);
  1964 + $search[] = "s.sex IN (" . implode(",",$sex) . ")";
  1965 + }
  1966 +/*
  1967 + $sql = "select * from catalogs_products ";
  1968 + $sql .= "LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id ";
  1969 + if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){
  1970 + //$sql .= "LEFT JOIN catalogs_products ON catalogs_products.brend_id=catalogs_brends.id ";
  1971 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
  1972 + }
  1973 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
  1974 + 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 ";
  1975 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
  1976 +
  1977 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";}
  1978 + if(isset($filter['r']) && count($filter['r'])>0){$sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 ";}
  1979 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";}
  1980 + $sql .= "where catalogs_products.count_modifications>0 and catalogs_brends.id>0 ";
  1981 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  1982 + if(isset($params['rubID']) && !isset($params['filter_products'])){
  1983 + $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']);
  1984 + $rubric_id = ($rubric_id==0)?$params['rubID']:$rubric_id;
  1985 + $sql .= "and catalogs_products.rubric_id='".$rubric_id."'";
  1986 + }
  1987 + $sql .= " Group by catalogs_brends.name Order by catalogs_brends.name Asc";
  1988 + // print $sql;
  1989 + $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  1990 + $this->tpl->assign('brends',$row);
  1991 + }
  1992 +*/
  1993 +
  1994 + // ==== catalogs_products ====
  1995 +
  1996 + $sql = array ();
  1997 + $sql[] = "select * from catalogs_products ";
  1998 + $sql[] = "LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id ";
  1999 +
  2000 + if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
4663 2001 {
4664   - $tmpfname = "tmp/seo.csv";
4665   - $handle = fopen ($tmpfname, "w");
4666   - $res = $this->db->getAll ('select p.id,p.rubric_id,r.name_h1,null,r.list_name,b.name,p.name,null,p.cine, r.translit,p.translit,r.name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id');
4667   - foreach ($res as $key => $row)
4668   - {
4669   - $row[3] = $this->getFilterPh1 ($row[0]);
4670   - if (! strlen ($row[2]))
4671   - $row[2] = $row[11];
4672   - $row[7] = "http://extremstyle.ua/" . $row[9] . "-catalogs/" . $row[10] . "-" . $row[0] . "/";
4673   - unset ($row[9]);
4674   - unset ($row[10]);
4675   - unset ($row[11]);
4676   - File_FGetCSV::fputcsv ($handle, $row, ';');
4677   - }
4678   - fclose ($handle);
4679   - $params = array (
4680   - 'file' => $tmpfname,
4681   - 'contenttype' => 'application/xls',
4682   - 'contentdisposition' => array (
4683   - HTTP_DOWNLOAD_ATTACHMENT,
4684   - 'seo.csv'
4685   - ),
4686   - 'cache' => false
4687   - );
4688   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4689   - if ($error === true)
4690   - {
4691   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4692   - }
4693   -
4694   - unlink ($tmpfname);
  2002 + //$sql .= "LEFT JOIN catalogs_products ON catalogs_products.brend_id=catalogs_brends.id ";
  2003 + $sql[] = "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
4695 2004 }
4696   -
4697   - function exportProductsSeoCSV ()
  2005 +
  2006 + if (isset ($filter['y']) && $filter['y'] > 0)
4698 2007 {
4699   - $tmpfname = "tmp/products_seo.csv";
4700   - $handle = fopen ($tmpfname, "w");
4701   - $res = $this->db->getAll ('select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where b.name=?', array (
4702   - 'Dakine'
4703   - ));
4704   - foreach ($res as $key => $row)
4705   - {
4706   - $vowels = array (
4707   - "'05",
4708   - "'06",
4709   - "'07",
4710   - "'08",
4711   - "'09",
4712   - "'10",
4713   - "'11",
4714   - "'12",
4715   - "'13",
4716   - "'14",
4717   - "'15",
4718   - "'16",
4719   - "2005",
4720   - "2006",
4721   - "2007",
4722   - "2008",
4723   - "2009",
4724   - "2010",
4725   - "2011",
4726   - "2012",
4727   - "2013",
4728   - "2014",
4729   - "2015",
4730   - "2016"
4731   - );
4732   - $row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]);
4733   - $row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
4734   - unset ($row[6]);
4735   - unset ($row[7]);
4736   - File_FGetCSV::fputcsv ($handle, $row, ';');
4737   - }
4738   - fclose ($handle);
4739   - $params = array (
4740   - 'file' => $tmpfname,
4741   - 'contenttype' => 'application/xls',
4742   - 'contentdisposition' => array (
4743   - HTTP_DOWNLOAD_ATTACHMENT,
4744   - 'products_seo.csv'
4745   - ),
4746   - 'cache' => false
4747   - );
4748   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4749   - if ($error === true)
4750   - {
4751   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4752   - }
4753   -
4754   - unlink ($tmpfname);
  2008 + $sql[] = "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id ";
4755 2009 }
4756   -
4757   - function exportProducts2SeoCSV ()
  2010 +
  2011 + if (isset ($filter['f']) && count ($filter['f']) > 0)
4758 2012 {
4759   - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/cron/products_seo.csv";
4760   - $handle = fopen ($tmpfname, "w");
4761   - $sql = 'select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id LEFT JOIN catalogs_keys_products_years ky ON ky.product_id=p.id LEFT JOIN catalogs_years y ON y.id=ky.year_id where p.count_modifications>0 and b.name=? and y.name in ("2013","2014","2015","2014-2015")';
4762   - $res = $this->db->getAll ($sql, array (
4763   - 'Dakine'
4764   - ));
4765   - foreach ($res as $key => $row)
4766   - {
4767   - $vowels = array (
4768   - "'05",
4769   - "'06",
4770   - "'07",
4771   - "'08",
4772   - "'09",
4773   - "'10",
4774   - "'11",
4775   - "'12",
4776   - "'13",
4777   - "'14",
4778   - "'15",
4779   - "'16",
4780   - "2005",
4781   - "2006",
4782   - "2007",
4783   - "2008",
4784   - "2009",
4785   - "2010",
4786   - "2011",
4787   - "2012",
4788   - "2013",
4789   - "2014",
4790   - "2015",
4791   - "2016"
4792   - );
4793   - $row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]);
4794   - $row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
4795   - unset ($row[5]);
4796   - unset ($row[6]);
4797   - unset ($row[7]);
4798   - File_FGetCSV::fputcsv ($handle, $row, ';');
4799   - }
4800   - fclose ($handle);
  2013 + $sql[] = "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id ";
4801 2014 }
4802   -
4803   - function exportProductsFeed ()
  2015 +
  2016 + if (isset ($filter['g']) && count ($filter['g']) > 0)
4804 2017 {
4805   - $tmpfname = "tmp/products_feed.csv";
4806   - $handle = fopen ($tmpfname, "w");
4807   - $sql = 'select r.id,r.name,p.id,p.name,p.cine_last,r.translit,p.translit,r.list_name,p.pic,b.name,p.about,p.cine From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where p.count_modifications>0 and p.cine>0';
4808   - $res = $this->db->getAll ($sql, array ());
4809   - $list = array (
4810   - 'ID',
4811   - 'ID2',
4812   - 'Item title',
4813   - 'Destination URL',
4814   - 'Image URL',
4815   - 'Item subtitle',
4816   - 'Item description',
4817   - 'Item category',
4818   - 'Price',
4819   - 'Sale price',
4820   - 'Contextual keywords',
4821   - 'Item address'
4822   - );
4823   - File_FGetCSV::fputcsv ($handle, $list, ',');
4824   - foreach ($res as $key => $row)
4825   - {
4826   - $url = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
4827   - $image = "http://extremstyle.ua/uploaded/pic/catalogs/products/" . $row[8];
4828   - $subtitle = $row[1] . ' ' . $row[9];
4829   - $list = array (
4830   - $row[2],
4831   - $row[2] . 'S',
4832   - substr ($row[3], 0, 12),
4833   - $url,
4834   - $image,
4835   - substr ($subtitle, 0, 12),
4836   - "Ãàðàíòèÿ êà÷åñòâà",
4837   - $row[1],
4838   - round ($row[11]) . ' UAH',
4839   - round ($row[4]) . ' UAH',
4840   - $row[1] . ' ' . $row[9]
4841   - );
4842   - // print_r($list);
4843   - unset ($row[5]);
4844   - unset ($row[6]);
4845   - unset ($row[7]);
4846   - File_FGetCSV::fputcsv ($handle, $list, ',');
4847   - }
4848   - fclose ($handle);
4849   - $params = array (
4850   - 'file' => $tmpfname,
4851   - 'contenttype' => 'application/xls',
4852   - 'contentdisposition' => array (
4853   - HTTP_DOWNLOAD_ATTACHMENT,
4854   - 'products_feed.csv'
4855   - ),
4856   - 'cache' => false
4857   - );
4858   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4859   - if ($error === true)
4860   - {
4861   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4862   - }
4863   -
4864   - unlink ($tmpfname);
  2018 + $sql[] = "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id ";
4865 2019 }
4866   -
4867   - function exportOrdersCSV ()
  2020 +
  2021 + if (isset ($filter['s']) && count ($filter['s']) > 0)
4868 2022 {
4869   - $tmpfname = "tmp/orders.csv";
4870   - $handle = fopen ($tmpfname, "w");
4871   - $res = $this->db->getAll ('select o.id,o.name,o.email,o.adress,o.phone,o.total From catalogs_orders o LEFT JOIN zlo_users u ON u.id=o.user_id WHERE u.`group`=2 order by o.id desc');
4872   - foreach ($res as $key => $row)
4873   - {
4874   - $products = $this->db->getAll ("select p.* from catalogs_orders_products op
4875   - LEFT JOIN catalogs_modifications m ON m.code=op.code
4876   - LEFT JOIN catalogs_products p ON p.id=m.product_id
4877   - where op.order_id=? GROUP BY p.id", array (
4878   - $row[0]
4879   - ), DB_FETCHMODE_ASSOC);
4880   - $arr_products = array ();
4881   - foreach ($products as $p)
4882   - {
4883   - $arr_products[] = $p['name'];
4884   - }
4885   - $row[6] = implode (', ', $arr_products);
4886   - File_FGetCSV::fputcsv ($handle, $row, ';');
4887   - }
4888   - fclose ($handle);
4889   - $params = array (
4890   - 'file' => $tmpfname,
4891   - 'contenttype' => 'application/xls',
4892   - 'contentdisposition' => array (
4893   - HTTP_DOWNLOAD_ATTACHMENT,
4894   - 'orders.csv'
4895   - ),
4896   - 'cache' => false
4897   - );
4898   - $error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
4899   - if ($error === true)
4900   - {
4901   - // åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
4902   - }
4903   -
4904   - unlink ($tmpfname);
  2023 + $sql[] = "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 ";
4905 2024 }
4906   -
4907   - function deleteProductParams ($product_id)
  2025 +
  2026 + if (isset ($filter['r']) && count ($filter['r']) > 0)
4908 2027 {
4909   - $sql = "delete from catalogs_products_params where product_id=?";
4910   - $this->db->query ($sql, array (
4911   - $product_id
4912   - ));
  2028 + $sql[] = "LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 ";
4913 2029 }
4914   -
4915   - function saveProductParams ($product_id, $pruduct_params)
  2030 +
  2031 + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
4916 2032 {
4917   - $this->deleteProductParams ($product_id);
4918   - $array_params = explode ("=", $pruduct_params);
4919   - foreach ($array_params as $row)
4920   - {
4921   - $arr = explode ('*', $row);
4922   - $this->db->autoExecute ("catalogs_products_params", array (
4923   - 'product_id' => $product_id,
4924   - 'name' => $arr[0],
4925   - 'size' => $arr[1],
4926   - 'metka' => $arr[2]
4927   - ), DB_AUTOQUERY_INSERT);
4928   - }
  2033 + $sql[] = "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";
4929 2034 }
4930   -
4931   - function getProductParams ($product_id)
  2035 +
  2036 + $sql[] = "where catalogs_products.count_modifications > 0 and catalogs_brends.id > 0 ";
  2037 +
  2038 + if (count ($search))
4932 2039 {
4933   - $sql = "select * from catalogs_products_params where product_id=? order by id";
4934   - $row = $this->db->getAll ($sql, array (
4935   - $product_id
4936   - ), DB_FETCHMODE_ASSOC);
4937   - return $row;
  2040 + $sql[] = "AND " . implode(" AND ", $search) . " ";
4938 2041 }
4939   -
4940   - function viewProductParams ($product_id)
  2042 +
  2043 + if (isset ($params['rubID']) && ! isset ($params['filter_products']))
4941 2044 {
4942   - $this->tpl->assign ('params', $this->getProductParams ($product_id));
  2045 + $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']);
  2046 + $rubric_id = ($rubric_id == 0) ? $params['rubID'] : $rubric_id;
  2047 + $sql[] = "and catalogs_products.rubric_id='".$rubric_id."'";
4943 2048 }
4944   -
4945   - /**
4946   - * íóæíî äëÿ ïðîñìîòðà ïîâòîðåíèå ñòðîê â ôàéëå èìïîðòà
4947   - */
4948   -
4949   - function saveTmpProduct ($row, $product_id)
  2049 +
  2050 + $sql[] = " Group by catalogs_brends.name Order by catalogs_brends.name Asc";
  2051 +
  2052 + if (count ($sql) > 4)
4950 2053 {
4951   - if ($product_id > 0)
4952   - {
4953   - $this->db->autoExecute ("catalogs_tmp_products", array (
4954   - 'name' => $row[3],
4955   - 'product_id' => $product_id
4956   - ), DB_AUTOQUERY_INSERT);
4957   - }
  2054 + $row = $this->db->getAll(implode (' ', $sql), array(), DB_FETCHMODE_ASSOC);
4958 2055 }
4959   -
4960   - function clearTmpProduct ()
  2056 + else
4961 2057 {
4962   - $sql = "TRUNCATE TABLE catalogs_tmp_products";
4963   - $this->db->query ($sql, array ());
  2058 + // çíà÷èò ñòðàíèöà
  2059 + $row = array ();
4964 2060 }
4965   -
4966   - function viewTmpProducts ()
  2061 + $this->tpl->assign('brends', $row);
  2062 +
  2063 +}
  2064 +
  2065 +// =====
  2066 +
  2067 + function viewBrendsActive(){
  2068 + $sql = "select * from catalogs_brends where active=1 ";
  2069 + $sql .= " Order by name Asc";
  2070 + $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  2071 + $this->tpl->assign('brends_a',$row);
  2072 + }
  2073 +
  2074 + function SaveCity($data){
  2075 + $table_name = "catalogs_cities";
  2076 + $DB_AUTOQUERY = (isset($data['update_id']) && $data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
  2077 + $fields_values = array('name'=>$data['name']);
  2078 + $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}");
  2079 + return mysql_insert_id();
  2080 + }
  2081 +
  2082 + function is_city($name){
  2083 + return $this->db->getOne('select id from catalogs_cities where name=?',array($name));
  2084 + }
  2085 +
  2086 + function viewCityMod($code){
  2087 + $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";
  2088 + $row = $this->db->getCol($sql,"name",array($code));
  2089 + if(!count($row))return "";
  2090 + if(count($row) == 1 && trim($row[0])==''){ return ""; }
  2091 +
  2092 + foreach($row as $key=>$value){if($value=="Èíòåðíåò ìàãàçèí" or $value=="Êèåâ(Îëèìïèéñêèé)" or $value=="Ëüâîâ" or trim($value)=="")unset($row[$key]);}
  2093 +$row2 = array();
  2094 +foreach($row as $key=>$value) if(trim($value)!='') $row2[] = $value;
  2095 +$row = $row2;
  2096 +
  2097 + $l = array();
  2098 + for($i=0;$i<count($row);$i++){
  2099 + $key = 0;
  2100 + for($i2=0;$i2<count($l);$i2++)
  2101 + if($l[$i2]==$row[$i]) $key=1;
  2102 + if($key==0) $l[]=$row[$i];
  2103 + }
  2104 + if(trim($_REQUEST['test2'])!='1')
  2105 + { return implode(', ',$l);}
  2106 + return implode(', ',$row);
  2107 + }
  2108 +
  2109 + function viewCitiesProductID($id){
  2110 + $sql = "select city_id from catalogs_keys_products_cities where product_id=?";
  2111 + $row = $this->db->getCol($sql,"city_id",array($id));
  2112 + $this->tpl->assign('product_cities',$row);
  2113 + }
  2114 +
  2115 + function viewCities($type = false){
  2116 + $sql = "select * from catalogs_cities ";
  2117 + $sql .= " Order by name Asc";
  2118 + $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  2119 + $this->tpl->assign('cities',$row);
  2120 + }
  2121 +
  2122 + function viewCitiesProduct($id){
  2123 + $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=?";
  2124 + $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  2125 + $this->tpl->assign('cities',$row);
  2126 + }
  2127 +
  2128 + function viewCity($id){
  2129 + $row = $this->db->getRow("select * from catalogs_cities where id=?",array($id),DB_FETCHMODE_ASSOC);
  2130 + $this->tpl->assign('city', $row);
  2131 + }
  2132 +
  2133 + function deleteCity($id){
  2134 + $this->db->query("delete from catalogs_cities where id=?",array($id));
  2135 + $this->delete_keysCitiesProduct($id);
  2136 + }
  2137 +
  2138 + function delete_keysCitiesProduct($id){
  2139 + $sql = "delete from catalogs_keys_products_cities where city_id=?";
  2140 + $this->db->query($sql,array($id));
  2141 + }
  2142 +
  2143 + function SaveYears($data){
  2144 + $table_name = "catalogs_years";
  2145 + foreach($data['filter'] as $key=>$name){
  2146 + if(strlen($name)>0){
  2147 + if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";}
  2148 + else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";}
  2149 + $this->db->autoExecute($table_name,array('name'=>$name,'rubric_id'=>$data['rubric_id']),$DB_AUTOQUERY,$where);
  2150 + }
  2151 + }
  2152 + }
  2153 +
  2154 + function viewYearsProduct($id){
  2155 + $sql = "select y.* from catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id where k.product_id=?";
  2156 + $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  2157 + $this->tpl->assign('product_years',$row);
  2158 + }
  2159 +
  2160 + function viewYearsProductID($id){
  2161 + $sql = "select year_id from catalogs_keys_products_years where product_id=?";
  2162 + $row = $this->db->getCol($sql,"year_id",array($id));
  2163 + $this->tpl->assign('product_years',$row);
  2164 + }
  2165 +
  2166 +function viewYears ($rubric_id, $filters = null)
  2167 +{
  2168 + $search = array ();
  2169 +
  2170 + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
  2171 + $filter = $this->seralizeFilter ($_GET['filter']);
  2172 +
  2173 + if (isset ($filter['f']) && count ($filter['f']) > 0)
4967 2174 {
4968   - $sql = "
4969   - SELECT count( name ) AS cn, name
4970   - FROM catalogs_tmp_products
4971   - GROUP BY name
4972   - ORDER BY name";
4973   - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
4974   - $this->tpl->assign ('list', $row);
4975   - $this->tpl->assign ('list_total', $this->db->getOne ("
4976   - select count(*)
4977   - from catalogs_tmp_products
4978   - "));
  2175 + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
4979 2176 }
4980   -
4981   - function deleteGalleryProduct ($id)
  2177 +
  2178 + if (isset ($filter['s']) && count ($filter['s']) > 0)
4982 2179 {
4983   - $sql = "select * from catalogs_gallery where product_id=?";
4984   - $res = $this->db->getAll ($sql, array (
4985   - $id
4986   - ), DB_FETCHMODE_ASSOC);
4987   - foreach ($res as $row)
4988   - {
4989   - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}");
4990   - $this->db->query ("delete from catalogs_gallery where id=?", array (
4991   - $row['id']
4992   - ));
4993   - }
  2180 + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
4994 2181 }
4995   -
4996   - function saveGalleryPics ($product_id, $pruduct_gallery_pics)
  2182 +
  2183 + if (isset ($filter['r']) && count ($filter['r']) > 0)
4997 2184 {
4998   - $this->deleteGalleryProduct ($product_id);
4999   - if (strlen ($pruduct_gallery_pics) > 0)
5000   - {
5001   - $arr = explode (",", $pruduct_gallery_pics);
5002   - foreach ($arr as $pic)
5003   - {
5004   - $pic = trim ($pic);
5005   - $id = $this->db->nextId ('mySequence_catalogs_gallery');
5006   - $fields_values = array (
5007   - 'id' => $id,
5008   - 'name' => $pic,
5009   - 'product_id' => $product_id
5010   - );
5011   - $upload['pic'] = array (
5012   - 'tmp_name' => "./uploaded/pic/catalogs/products/big/$pic",
5013   - 'name' => $pic
5014   - );
5015   - $fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
5016   - 'width' => "100",
5017   - 'height' => "100",
5018   - 'upload_path' => "./uploaded/pic/catalogs/products/gallery/"
5019   - ));
5020   - $fields_values['pic_big'] = $pic;
5021   -
5022   - $this->db->autoExecute ("catalogs_gallery", $fields_values, DB_AUTOQUERY_INSERT);
5023   - }
5024   - }
  2185 + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
5025 2186 }
5026 2187  
5027   - function importCSV ($upload)
5028   - {
5029   - error_reporting (0);
5030   -
5031   - if ($upload['file']['name'] == "file_1.csv")
5032   - {
5033   - print "Îøèáêà! Ôàéë öåí!";
5034   - exit ();
5035   - }
5036   -
5037   - // $arr_line = file($upload['file']['tmp_name']);
5038   - $f = fopen ($upload['file']['tmp_name'], "r") or die ("Îøèáêà!");
5039   -
5040   - // print"<pre>";
5041   -
5042   - $this->clearTmpProduct ();
5043   -
5044   - for ($i = 0; $row_line = File_FGetCSV::fgetcsv ($f, 15000, ";"); $i ++)
5045   - {
5046   - // foreach($arr_line as $line){
5047   - // $row_line = fgetcsv(";",$line);
5048   - $rubric_id = $this->import_saveRubric ($row_line[0], 0);
5049   - $rubric_parent_id = $this->import_saveRubric ($row_line[1], $rubric_id);
5050   - $brend_id = $this->import_saveBrend ($row_line[2], $rubric_parent_id);
5051   - $pruduct_name = trim ($row_line[3]);
5052   - $pruduct_about = trim ($row_line[4]);
5053   - $pruduct_text = trim ($row_line[5]);
5054   - $sex = explode (',', $row_line[8]);
5055   - $pruduct_sex = array ();
5056   -
5057   - foreach ($sex as $s)
5058   - {
5059   - switch (trim ($s))
5060   - {
5061   - case 'ìóæñêîé' :
5062   - $pruduct_sex[] = 1;
5063   - break;
5064   - case 'æåíñêèé' :
5065   - $pruduct_sex[] = 2;
5066   - break;
5067   - case 'äåòñêèé' :
5068   - $pruduct_sex[] = 3;
5069   - break;
5070   - case 'óíèñåêñ' :
5071   - $pruduct_sex[] = 4;
5072   - break;
5073   - default :
5074   - $pruduct_sex[] = array ();
5075   - break;
5076   - }
5077   - }
5078   -
5079   - $pruduct_date = trim ($row_line[9]);
5080   - $pruduct_cine = trim ($row_line[10]);
5081   - $pruduct_cine_last = trim ($row_line[11]);
5082   -
5083   - if ($pruduct_cine < 1)
5084   - {
5085   - $pruduct_cine = $pruduct_cine_last;
5086   - $pruduct_cine_last = 0;
5087   - }
5088   -
5089   - $pruduct_akcii_id = trim ($row_line[12]);
5090   - $pruduct_strnumber = trim ($row_line[13]);
5091   - $pruduct_active = trim ($row_line[14]);
5092   - $pruduct_params = trim ($row_line[15]);
5093   - $pruduct_pic_tmp = trim ($row_line[17]);
5094   - $pruduct_gallery_pics = trim ($row_line[18]);
5095   - $pruduct_video = trim ($row_line[16]);
5096   - $pruduct_update_id = $this->getProductID_R ($pruduct_name, $rubric_parent_id);
5097   -
5098   - if ($pruduct_update_id > 0)
5099   - {
5100   - $row_product = $this->db->getRow ('
5101   - select update_text, about, text
5102   - from catalogs_products
5103   - where id=?', array (
5104   - $pruduct_update_id
5105   - ), DB_FETCHMODE_ASSOC);
5106   -
5107   - // íå îáíîâëÿòü ïðè èìïîðòå?
5108   - // 0 - îáíîâëÿòü
5109   - // 1 - íå îáíîâëÿòü
5110   - if ($row_product['update_text'] == 1)
5111   - {
5112   - // about - ukr
5113   - $pruduct_about = $row_product['about'];
5114   -
5115   - // text - ru
5116   - $pruduct_text = $row_product['text'];
5117   - }
5118   - }
5119   -
5120   - $upload_pruduct = (strlen ($pruduct_pic_tmp) > 0 && is_file ("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp")) ? array (
5121   - 'pic' => array (
5122   - 'tmp_name' => "./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",
5123   - 'name' => $pruduct_pic_tmp,
5124   - 'big' => true
5125   - )
5126   - ) : null;
5127   -
5128   - $product_id = $this->saveProduct (array (
5129   - 'rubric_id' => $rubric_parent_id,
5130   - 'rubric_parent_id' => $rubric_parent_id,
5131   - 'brend_id' => $brend_id,
5132   - 'name' => $pruduct_name,
5133   - 'about' => $pruduct_about,
5134   - 'update_text' => isset ($row_product['update_text']) ? $row_product['update_text'] : 0,
5135   - 'text' => $pruduct_text,
5136   - 'video_code' => $pruduct_video,
5137   - 'sex' => $pruduct_sex,
5138   - 'date' => $pruduct_date,
5139   - 'cine' => $pruduct_cine,
5140   - 'cine_last' => $pruduct_cine_last,
5141   - 'akcii_id' => $pruduct_akcii_id,
5142   - 'strnumber' => $pruduct_strnumber,
5143   - 'active' => $pruduct_active,
5144   - 'meta_title' => $pruduct_name,
5145   - 'meta_description' => $pruduct_name,
5146   - 'meta_keywords' => $pruduct_name,
5147   - 'meta_about' => $pruduct_name,
5148   - 'filter' => $this->import_saveFilters ($rubric_parent_id, $row_line[6]),
5149   - 'filter2' => $this->import_saveFilters2 ($rubric_parent_id, $row_line[7]),
5150   - 'years' => $this->import_saveYear ($rubric_parent_id, $pruduct_date),
5151   - 'akcii' => array (),
5152   - 'update_id' => $pruduct_update_id
5153   - ), $upload_pruduct);
5154   -
5155   - // print $pruduct_update_id;exit;
5156   - $this->saveProductParams ($product_id, $pruduct_params);
5157   - $this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
5158   - // íå óäàëÿåì !
5159   - // $this->deleteProductModifications ($product_id, true);
5160   - $m_i = 0;
5161   -
5162   - for ($i = 19; $i < count ($row_line); $i ++)
5163   - {
5164   - $arr_mod = trim ($row_line[$i]);
5165   -
5166   - if (strlen ($arr_mod) > 0)
5167   - {
5168   - $row_mod = explode ("=", $arr_mod);
5169   -
5170   - $upload_mod = (strlen ($row_mod[3]) > 0 && is_file ("./uploaded/pic/catalogs/modifications/big/" . $row_mod[3])) ? array (
5171   - 'pic' => array (
5172   - 'tmp_name' => "./uploaded/pic/catalogs/modifications/big/" . $row_mod[3],
5173   - 'name' => $row_mod[3],
5174   - 'big' => true
5175   - )
5176   - ) : null;
5177   -
5178   - $size_mod = explode ("*", $row_mod[1]);
5179   - $rost = (isset ($size_mod[1])) ? $size_mod[1] : '';
5180   -
5181   - // íàõîäèì modifications_id
5182   - $modifications_id = $this->getModification ($product_id, $row_mod[0]);
5183   -
5184   - // ñîõðàíÿåì
5185   - $this->SaveModification (array (
5186   - 'product_id' => $product_id,
5187   - 'code' => $row_mod[0],
5188   - 'size' => $size_mod[0],
5189   - 'rost' => $rost,
5190   - 'color' => $row_mod[2],
5191   - 'active' => $row_mod[4],
5192   - 'update_id' => (int) $modifications_id
5193   - ), $upload_mod);
5194   -
5195   - if ($row_mod[4] > 0)
5196   - {
5197   - $m_i ++;
5198   - }
5199   - }
5200   - }
5201   -
5202   - $this->updateProduct_countModification ($product_id, $m_i);
5203   -
5204   - // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);
5205   - // $strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data);
5206   - // print_r($row_line);
5207   -
5208   - $this->saveTmpProduct ($row_line, $product_id);
5209   - if (($i % 30) == 0)
5210   - {
5211   - sleep (1);
5212   - }
5213   - }
5214   - // print"</pre>";
5215   - }
  2188 + if (isset ($_GET['new']) && $_GET['new'] > 0)
  2189 + $search[] = sprintf ("p.active='%d'", $_GET['new']);
  2190 +
  2191 + if (isset ($_GET['top']) && $_GET['top'] > 0)
  2192 + $search[] = sprintf ("p.top='%d'", $_GET['top']);
  2193 +
  2194 + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
  2195 + $search[] = sprintf ("p.akcii_id>'%d'", 0);
5216 2196  
5217   - function importCSV_cine ($upload)
5218   - {
5219   - if ($upload['file']['name'] != "file_1.csv")
5220   - {
5221   - print "Îøèáêà! Òîëüêî file_1.csv";
5222   - exit ();
5223   - }
5224   -
5225   - $arr_line = file ($upload['file']['tmp_name']);
5226   -
5227   - // print"<pre>";
5228   - $i = 0;
5229   - $mktime = mktime ();
5230   - foreach ($arr_line as $line)
5231   - {
5232   - $row_line = explode (";", $line);
5233   - $this->import_updateProductCine ($this->getModificationProduct_id ($row_line[0]), $row_line, $line, $mktime);
5234   -
5235   - if (($i % 30) == 0)
5236   - {
5237   - sleep (1);
5238   - }
5239   -
5240   - $i ++;
5241   - }
5242   - }
  2197 + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
  2198 + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
5243 2199  
5244   - function loadCSV_cine ($upload)
  2200 + /**
  2201 + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2202 + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  2203 + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
  2204 + * }
  2205 + */
  2206 + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
5245 2207 {
5246   - if ($upload['file']['name'] != "file_1.csv")
5247   - {
5248   - print "Îøèáêà! Òîëüêî file_1.csv";
5249   - exit ();
5250   - }
5251   -
5252   - $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv";
5253   -
5254   - // echo $file;
5255   - // exit;
5256   -
5257   - move_uploaded_file ($upload['file']['tmp_name'], $file);
  2208 + $sex = $this->seralizeSex ($_GET['sex']);
  2209 + $search[] = "s.sex IN (" . implode (",", $sex) . ")";
5258 2210 }
5259 2211  
5260   - function is_loadCSV_cine ()
  2212 + if (strlen ($filters) > 0 && ! isset ($filter['f']))
5261 2213 {
5262   - $is = is_file ($_SERVER['DOCUMENT_ROOT'] . '/cron/file_1.csv');
5263   - $this->tpl->assign ('is', $is);
  2214 + $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
5264 2215 }
5265 2216  
5266   - function CronImportCSV_cine ($upload)
5267   - {
5268   - $this->importCSV_cine ($upload);
5269   - }
  2217 + $sql = "select y.* from catalogs_products p, catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id ";
5270 2218  
5271   - function updateCountModificationProducts ()
  2219 + if (isset ($filter['f']) && count ($filter['f']) > 0)
  2220 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id ";
  2221 +
  2222 + if (isset ($filter['s']) && count ($filter['s']) > 0)
5272 2223 {
5273   - $res = $this->db->getAll ("
5274   - select id
5275   - from catalogs_products
5276   - ", array (), DB_FETCHMODE_ASSOC);
5277   -
5278   - $i = 0;
5279   -
5280   - foreach ($res as $row)
5281   - {
5282   - $count = $this->db->getOne ("
5283   - select count(*)
5284   - from catalogs_modifications
5285   - where product_id=? and active>0", array (
5286   - $row['id']
5287   - ));
5288   -
5289   - $this->db->autoExecute ("catalogs_products", array (
5290   - 'count_modifications' => $count
5291   - ), DB_AUTOQUERY_UPDATE, "id='" . $row['id'] . "'");
5292   -
5293   - $i ++;
5294   - }
  2224 + $sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 ";
5295 2225 }
5296 2226  
5297   - function config_update ($id, $value)
  2227 + if (isset ($filter['r']) && count ($filter['r']) > 0)
5298 2228 {
5299   - $this->db->autoExecute ("catalogs_config", array (
5300   - 'value' => $value
5301   - ), DB_AUTOQUERY_UPDATE, "id='" . $id . "'");
  2229 + $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 ";
5302 2230 }
5303 2231  
5304   - function view_config_value ($id)
  2232 + if (strlen ($filters) > 0 && ! isset ($filter['f']))
5305 2233 {
5306   - $r = $this->db->getOne ("select value from catalogs_config where id=?", $id);
5307   - $this->tpl->assign ("config", $r);
5308   - return $r;
  2234 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id ";
5309 2235 }
5310 2236  
5311   - function addViewProduct ($product_id)
  2237 + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
5312 2238 {
5313   - $i = 0;
5314   - foreach ($_SESSION['view_product'] as $id)
5315   - {
5316   - if ($product_id == $id)
5317   - $i ++;
5318   - }
5319   - if ($i == 0)
5320   - $_SESSION['view_product'][] = $product_id;
  2239 + $sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id ";
5321 2240 }
5322 2241  
5323   - function viewUserProducts ($limit = "all")
5324   - { // unset($_SESSION['view_product']);
5325   - if (isset ($_SESSION['view_product']) && count ($_SESSION['view_product']) > 0)
5326   - {
5327   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5328   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5329   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5330   - WHERE catalogs_products.id IN (" . implode (",", $_SESSION['view_product']) . ") ";
5331   - if ($limit != "all")
5332   - $sql .= "LIMIT " . $limit;
5333   - $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
5334   - $this->tpl->assign ("products_view", $res);
5335   - }
5336   - }
  2242 + $sql .= "where p.id=k.product_id and p.count_modifications>0 ";
  2243 +
  2244 + if ($filters == null)
  2245 + $sql .= " and p.rubric_id='" . $rubric_id . "' ";
5337 2246  
5338   - function viewSimilarProducts ($product_id, $brend, $rubric_id, $mods)
5339   - {
5340   - IF ($brend == 'Dakine')
5341   - {
5342   - $rub_arr = array (
5343   - 14071,
5344   - 14069,
5345   - 14070,
5346   - 14072
5347   - );
5348   - unset ($rub_arr[array_search ('rubric_id', $rub_arr)]);
5349   -
5350   - if (count ($mods) > 1)
5351   - {
5352   - $r = array ();
5353   - foreach ($mods as $key => $mod)
5354   - {
5355   - $r[$key]['color'] = $mod['color'];
5356   - $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
5357   - $product_id
5358   - ), DB_FETCHMODE_ASSOC);
5359   - $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5360   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5361   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5362   - LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
5363   - WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine<? and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
5364   - $r[$key]["products_similar_prev"] = $this->db->getAll ($sql, array (
5365   - $row['cine'],
5366   - $brend,
5367   - $mod['color']
5368   - ), DB_FETCHMODE_ASSOC);
5369   -
5370   - $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5371   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5372   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5373   - LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
5374   - WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
5375   - $r[$key]["products_similar_next"] = $this->db->getAll ($sql, array (
5376   - $row['cine'],
5377   - $brend,
5378   - $mod['color']
5379   - ), DB_FETCHMODE_ASSOC);
5380   - }
5381   - // print_r($r);
5382   - $this->tpl->assign ("products_similar", $r);
5383   - }
5384   - else
5385   - {
5386   -
5387   - $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
5388   - $product_id
5389   - ), DB_FETCHMODE_ASSOC);
5390   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5391   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5392   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5393   - WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine<? and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
5394   - $res = $this->db->getAll ($sql, array (
5395   - $row['cine'],
5396   - $brend
5397   - ), DB_FETCHMODE_ASSOC);
5398   - $this->tpl->assign ("products_similar_prev", $res);
5399   -
5400   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5401   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5402   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5403   - WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
5404   - $res = $this->db->getAll ($sql, array (
5405   - $row['cine'],
5406   - $brend
5407   - ), DB_FETCHMODE_ASSOC);
5408   - $this->tpl->assign ("products_similar_next", $res);
5409   - }
5410   - }
5411   - else
5412   - {
5413   - $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
5414   - $product_id
5415   - ), DB_FETCHMODE_ASSOC);
5416   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5417   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5418   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5419   - WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine<? Order by catalogs_products.cine DESC LIMIT 5";
5420   - $res = $this->db->getAll ($sql, array (
5421   - $row['rubric_id'],
5422   - $row['cine']
5423   - ), DB_FETCHMODE_ASSOC);
5424   - $this->tpl->assign ("products_similar_prev", $res);
5425   -
5426   - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
5427   - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
5428   - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
5429   - WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine>? Order by catalogs_products.cine DESC LIMIT 5";
5430   - $res = $this->db->getAll ($sql, array (
5431   - $row['rubric_id'],
5432   - $row['cine']
5433   - ), DB_FETCHMODE_ASSOC);
5434   - $this->tpl->assign ("products_similar_next", $res);
5435   - }
5436   - }
  2247 + if (count ($search))
  2248 + $sql .= "AND " . implode (" AND ", $search) . " ";
  2249 +
  2250 + $sql .= " GROUP BY k.year_id order by y.name desc";
  2251 +
  2252 + // print $sql;
  2253 + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
  2254 + $this->tpl->assign ('years', $row);
  2255 +}
  2256 +
  2257 + function viewYearsAll($rubric_id){
  2258 + $sql = "SELECT * FROM catalogs_years WHERE rubric_id=? ORDER BY id asc ";
  2259 + $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC);
  2260 + $this->tpl->assign('years', $row);
  2261 + }
  2262 +
  2263 + function viewSexProduct($id){
  2264 + $sql = "select * from catalogs_keys_products_sex where product_id=?";
  2265 + $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  2266 + $this->tpl->assign('product_sex',$row);
  2267 + }
  2268 +
  2269 + function viewSexProductID($id){
  2270 + $sql = "select sex from catalogs_keys_products_sex where product_id=?";
  2271 + $row = $this->db->getCol($sql,"sex",array($id));
  2272 + $this->tpl->assign('product_sex',$row);
  2273 + }
  2274 +
  2275 +function viewSex ($rubric_id, $filters = null, $lang = 'rus')
  2276 +{
  2277 + $search = array ();
  2278 +
  2279 + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
  2280 + $filter = $this->seralizeFilter ($_GET['filter']);
5437 2281  
5438   - function displayCatalogsCurs ()
  2282 + if (isset ($filter['f']) && count ($filter['f']) > 0)
5439 2283 {
5440   - $this->tpl->assign ("tpl", 'catalogs_curs.tpl');
  2284 + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
5441 2285 }
5442   -
5443   - function displayCatalogs ()
  2286 + if (isset ($filter['y']) && $filter['y'] > 0)
5444 2287 {
5445   - $this->tpl->assign ("tpl", 'catalogs.tpl');
  2288 + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
5446 2289 }
5447   -
5448   - function displayProducts ()
  2290 + if (isset ($filter['s']) && count ($filter['s']) > 0)
5449 2291 {
5450   - $this->tpl->assign ("tpl", 'catalogs_product-list.tpl');
  2292 + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
5451 2293 }
5452   -
5453   - function displayProductsTops ()
  2294 + if (isset ($filter['r']) && count ($filter['r']) > 0)
5454 2295 {
5455   - $this->tpl->assign ("tpl", 'catalogs_products_tops.tpl');
  2296 + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
5456 2297 }
  2298 + if (isset ($_GET['new']) && $_GET['new'] > 0)
  2299 + $search[] = sprintf ("p.active='%d'", $_GET['new']);
  2300 + if (isset ($_GET['top']) && $_GET['top'] > 0)
  2301 + $search[] = sprintf ("p.top='%d'", $_GET['top']);
  2302 + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
  2303 + $search[] = sprintf ("p.akcii_id>'%d'", 0);
5457 2304  
5458   - function displayProductsHits ()
  2305 + if (strlen ($filters) > 0 && ! isset ($filter['f']))
5459 2306 {
5460   - $this->tpl->assign ("tpl", 'catalogs_products_hits.tpl');
  2307 + $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
5461 2308 }
5462 2309  
5463   - function displayProductsHitsAll ()
5464   - {
5465   - $this->tpl->assign ("tpl", 'catalogs_products_hits_all.tpl');
5466   - }
  2310 + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
  2311 + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
5467 2312  
5468   - function displayBasket ($count_products, $cine_products, $cine_products_discount, $discount)
5469   - {
5470   - $this->tpl->assign ("count_products", $count_products);
5471   - $this->tpl->assign ("cine_products", $cine_products);
5472   - $this->tpl->assign ("cine_products_discount", $cine_products_discount);
5473   - $this->tpl->assign ("discount", $discount);
5474   - $this->tpl->display ('basket.tpl');
5475   - }
  2313 + $sql = "select s.sex from catalogs_products p LEFT JOIN catalogs_keys_products_sex s ON s.product_id=p.id ";
5476 2314  
5477   - function displayProduct ()
  2315 + if (isset ($filter['f']) && count ($filter['f']) > 0)
  2316 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id ";
  2317 + if (isset ($filter['y']) && $filter['y'] > 0)
  2318 + $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id ";
  2319 + if (isset ($filter['s']) && count ($filter['s']) > 0)
5478 2320 {
5479   - $this->tpl->assign ("tpl", 'catalogs_product.tpl');
  2321 + $sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=p.id and catalogs_modifications.active=1 ";
5480 2322 }
5481   -
5482   - function displayProductBasket ()
  2323 + if (isset ($filter['r']) && count ($filter['r']) > 0)
5483 2324 {
5484   - $this->tpl->assign ("tpl", 'catalogs_basket.tpl');
  2325 + $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 ";
5485 2326 }
5486   -
5487   - function displayBrends ()
  2327 + if (strlen ($filters) > 0 && ! isset ($filter['f']))
5488 2328 {
5489   - $this->tpl->assign ("tpl", 'catalogs_brends.tpl');
  2329 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id ";
5490 2330 }
5491 2331  
5492   - function displayBrend ()
5493   - {
5494   - $this->tpl->assign ("tpl", 'catalogs_brend.tpl');
5495   - }
  2332 + $sql .= "where p.count_modifications>0
  2333 + and s.sex < 4
  2334 + and p.sex > 0
  2335 + ";
5496 2336  
5497   - function displayCities ()
  2337 + if ($filters == null)
  2338 + $sql .= " and p.rubric_id='" . $rubric_id . "' ";
  2339 + if (count ($search))
  2340 + $sql .= "AND " . implode (" AND ", $search) . " ";
  2341 +
  2342 + $sql .= " GROUP BY s.sex";
  2343 + // print $sql;
  2344 + $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
  2345 + // print_r($res);
  2346 + $sex = array ();
  2347 + if ($lang == 'ukr')
  2348 + $arr = array (
  2349 + 1 => array (
  2350 + 'name' => "×îëîâ³÷èé",
  2351 + 'link' => 'male'
  2352 + ),
  2353 + 2 => array (
  2354 + 'name' => "Ƴíî÷èé",
  2355 + 'link' => 'female'
  2356 + ),
  2357 + 3 => array (
  2358 + 'name' => "Äèòÿ÷èé",
  2359 + 'link' => 'child'
  2360 + )
  2361 + )
  2362 + // 4=>array('name'=>"Óí³ñåêñ",'link'=>'unisex')
  2363 + ;
  2364 + else
  2365 + $arr = array (
  2366 + 1 => array (
  2367 + 'name' => "Ìóæñêîé",
  2368 + 'link' => 'male'
  2369 + ),
  2370 + 2 => array (
  2371 + 'name' => "Æåíñêèé",
  2372 + 'link' => 'female'
  2373 + ),
  2374 + 3 => array (
  2375 + 'name' => "Äåòñêèé",
  2376 + 'link' => 'child'
  2377 + )
  2378 + )
  2379 + // 4=>array('name'=>"Óíèñåêñ",'link'=>'unisex')
  2380 + ;
  2381 +
  2382 + foreach ($res as $row)
5498 2383 {
5499   - $this->tpl->assign ("tpl", 'catalogs_cities.tpl');
  2384 + $sex[] = $arr[$row['sex']];
5500 2385 }
5501 2386  
5502   - function displayProductBasketSend ()
5503   - {
5504   - $this->tpl->assign ("tpl", 'catalogs_basket_send.tpl');
5505   - }
  2387 + if (isset ($_GET['s']))
  2388 + print_r ($sex);
5506 2389  
5507   - function displayReg ()
5508   - {
5509   - $this->tpl->assign ("tpl", 'catalogs_reg.tpl');
5510   - }
  2390 + $this->tpl->assign ('sex', $sex);
  2391 +}
  2392 +
  2393 + function getYearsName_IDs($ids){
  2394 + //$sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name";
  2395 + //$row = $this->db->getCol($sql,"name",array());
  2396 + //return implode(", ",$row);
  2397 +
  2398 + $name = array();
  2399 + foreach($ids as $id){
  2400 + $name[] = $this->db->getOne("select name from catalogs_years where id=$id",array());
  2401 + }
  2402 + return implode(", ",$name);
  2403 + }
  2404 +
  2405 + function deleteYearsRubric_id($id){
  2406 + $this->db->query("delete from catalogs_years where rubric_id=?",array($id));
  2407 + $this->delete_keysYearsRubric($id);
  2408 + }
  2409 +
  2410 + function delete_keysYearsRubric($id){
  2411 + $sql = "delete from catalogs_keys_products_years where rubric_id=?";
  2412 + $this->db->query($sql,array($id));
  2413 + }
  2414 +
  2415 + function deleteYear($id){
  2416 + $this->db->query("delete from catalogs_years where id=?",array($id));
  2417 + $this->delete_keysYearsProduct($id);
  2418 + }
  2419 +
  2420 + function delete_keysYearsProduct($id){
  2421 + $sql = "delete from catalogs_keys_products_years where year_id=?";
  2422 + $this->db->query($sql,array($id));
  2423 + }
  2424 +
  2425 + function SaveFilters($data){
  2426 + $table_name = "catalogs_filters";
  2427 + foreach($data['filter'] as $key=>$name){
  2428 + if(strlen($name)>0){
  2429 + if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";}
  2430 + else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";}
  2431 + $active = (isset($data['active'][$key])) ? 1 : 0;
  2432 + $fields = array('name'=>$name,"name_ukr"=>$data['filter_ukr'][$key],'prefix'=>encodestring($name),'rubric_id'=>$data['rubric_id'],"ph1"=>$data['ph1'][$key],"ph1_ukr"=>$data['ph1_ukr'][$key],"sort"=>$data['sort'][$key],"active"=>$active);
  2433 + if(isset($data['cat'][$key])){$fields['cat'] = $data['cat'][$key];}
  2434 + $this->db->autoExecute($table_name,$fields,$DB_AUTOQUERY,$where);
  2435 + }
  2436 + }
  2437 + }
  2438 +
  2439 + function viewFilterProduct($id){
  2440 + $sql = "select f.* from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where f.active='0' and k.product_id=?";
  2441 + $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  2442 + $this->tpl->assign('product_filters',$row);
  2443 + return $row;
  2444 + }
  2445 +
  2446 + function viewFilterProductID($id){
  2447 + $sql = "select filter_id from catalogs_keys_products_filters where product_id=?";
  2448 + $row = $this->db->getCol($sql,"filter_id",array($id));
  2449 + $this->tpl->assign('product_filters',$row);
  2450 + }
  2451 +
  2452 + function deleteFilter($id){
  2453 + $this->db->query("delete from catalogs_filters where id=?",array($id));
  2454 + $this->delete_keysFilterProduct($id);
  2455 + }
  2456 +
  2457 + function deleteFiltersRubric_id($rubric_id){
  2458 + $this->db->query("delete from catalogs_filters where rubric_id=?",array($rubric_id));
  2459 + $this->delete_keysFilterRubric($rubric_id);
  2460 + }
  2461 +
  2462 + function delete_keysFilterProduct($id){
  2463 + $sql = "delete from catalogs_keys_products_filters where filter_id=?";
  2464 + $this->db->query($sql,array($id));
  2465 + }
  2466 +
  2467 + function delete_keysFilterRubric($id){
  2468 + $sql = "delete from catalogs_keys_products_filters where rubric_id=?";
  2469 + $this->db->query($sql,array($id));
  2470 + }
  2471 +
  2472 + function viewFilters($rubric_id,$all = false,$lang = 'ru'){
  2473 + $search = array();
  2474 + if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']);
  2475 + if(isset($filter['g']) && count($filter['g'])>0){
  2476 + $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")";
  2477 + }
  2478 + if(isset($filter['y']) && $filter['y']>0){
  2479 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  2480 + }
  2481 +
  2482 + if(isset($filter['s']) && count($filter['s'])>0){
  2483 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  2484 + }
  2485 +
  2486 + if(isset($filter['r']) && count($filter['r'])>0){
  2487 + $search[] = "m2.rost in (".implode(",",$filter['r']).")";
  2488 + }
  2489 +
  2490 + if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']);
  2491 + if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']);
  2492 +if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0);
  2493 +
  2494 + if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "p.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")";
  2495 + /* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2496 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  2497 + $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
  2498 + } */
  2499 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2500 + $sex = $this->seralizeSex($_GET['sex']);
  2501 + $search[] = "s.sex IN (" . implode(",",$sex) . ")";
  2502 + }
  2503 + $sql = "select f.*,f.name".($lang=='ukr'?'_ukr':'')." as name,f.h1".($lang=='ukr'?'_ukr':'')." as h1 from catalogs_products p, catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id ";
  2504 + if(isset($filter['g']) && count($filter['g'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=k.product_id ";
  2505 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id ";
  2506 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 ";}
  2507 + if(isset($filter['r']) && count($filter['r'])>0){$sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 ";}
  2508 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id ";}
  2509 + $sql .= "where p.id=k.product_id and p.count_modifications>0 ";
  2510 + //$sql = "select * from catalogs_filters where 1=1 ";
  2511 + if($all == false)$sql .= "and f.active='0' ";
  2512 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  2513 + $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
  2514 + // print $sql;
  2515 + $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC);
  2516 + $this->tpl->assign('filters', $row);
  2517 + }
  2518 +
  2519 + function viewFiltersAll($rubric_id){
  2520 + $row = $this->db->getAll("select * from catalogs_filters where rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC);
  2521 + $this->tpl->assign('filters', $row);
  2522 + }
  2523 +
  2524 + function getFiltersName_IDs($ids,$lang){
  2525 + //$sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
  2526 + //$row = $this->db->getCol($sql,"name",array());
  2527 + $name = array();
  2528 + foreach($ids as $id){
  2529 + $row = $this->db->getRow("select h1".($lang=='ukr'?'_ukr':'')." as h1 from catalogs_filters where id=$id",array(),DB_FETCHMODE_ASSOC);
  2530 + $name[] = ((strlen($row['h1'])>0) ? $row['h1'] : $row['name']);
  2531 + }
  2532 +
  2533 + return implode(", ",$name);
  2534 + }
  2535 +
  2536 + function getFilters2Name_IDs($ids){
  2537 + //$sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
  2538 + //$row = $this->db->getCol($sql,"name",array());
  2539 + $name = array();
  2540 + foreach($ids as $id){
  2541 + $row = $this->db->getRow("select h1,name from catalogs_filters2 where id=$id",array(),DB_FETCHMODE_ASSOC);
  2542 + $name[] = ((strlen($row['h1'])>0) ? $row['h1'] : $row['name']);
  2543 + }
  2544 +//print_r($name);
  2545 + return implode(", ",$name);
  2546 + }
  2547 +
  2548 + function SaveFilters2($data){
  2549 + $table_name = "catalogs_filters2";
  2550 + foreach($data['filter2'] as $key=>$name){
  2551 + if(strlen($name)>0){
  2552 + if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";}
  2553 + else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";}
  2554 + $active = (isset($data['active'][$key])) ? 1 : 0;
  2555 + $this->db->autoExecute($table_name,array('name'=>$name,"name_ukr"=>$data['filter_ukr'][$key],'prefix'=>encodestring($name),'rubric_id'=>$data['rubric_id'],"sort"=>$data['sort'][$key],"active"=>$active),$DB_AUTOQUERY,$where);
  2556 + }
  2557 + }
  2558 + }
  2559 +
  2560 + function viewFilterProductID2($id){
  2561 + $sql = "select filter_id from catalogs_keys_products_filters2 where product_id=?";
  2562 + $row = $this->db->getCol($sql,"filter_id",array($id));
  2563 + $this->tpl->assign('product_filters2',$row);
  2564 + }
  2565 +
  2566 + function deleteFilter2($id){
  2567 + $this->db->query("delete from catalogs_filters2 where id=?",array($id));
  2568 + $this->delete_keysFilterProduct2($id);
  2569 + }
  2570 +
  2571 + function delete_keysFilterProduct2($id){
  2572 + $sql = "delete from catalogs_keys_products_filters2 where filter_id=?";
  2573 + $this->db->query($sql,array($id));
  2574 + }
  2575 +
  2576 + function deleteFiltersRubric_id2($rubric_id){
  2577 + $this->db->query("delete from catalogs_filters2 where rubric_id=?",array($rubric_id));
  2578 + $this->delete_keysFilterRubric2($rubric_id);
  2579 + }
  2580 +
  2581 + function delete_keysFilterRubric2($id){
  2582 + $sql = "delete from catalogs_keys_products_filters2 where rubric_id=?";
  2583 + $this->db->query($sql,array($id));
  2584 + }
  2585 +
  2586 + function viewFilters2($rubric_id,$lang='ru'){
  2587 + $search = array();
  2588 + if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']);
  2589 + if(isset($filter['f']) && count($filter['f'])>0){
  2590 + $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")";
  2591 + }
  2592 + if(isset($filter['y']) && $filter['y']>0){
  2593 + $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")";
  2594 + }
  2595 +
  2596 + if(isset($filter['s']) && count($filter['s'])>0){
  2597 + $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")";
  2598 + }
  2599 +
  2600 + if(isset($filter['r']) && count($filter['r'])>0){
  2601 + $search[] = "m2.rost in (".implode(",",$filter['r']).")";
  2602 + }
  2603 +
  2604 + if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']);
  2605 + if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']);
  2606 +if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0);
  2607 +
  2608 + if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "p.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")";
  2609 + /* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2610 + $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  2611 + $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
  2612 + } */
  2613 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2614 + $sex = $this->seralizeSex($_GET['sex']);
  2615 + $search[] = "s.sex IN (" . implode(",",$sex) . ")";
  2616 + }
  2617 + $sql = "select f.*,f.name".($lang=='ukr'?'_ukr':'')." as name from catalogs_products p, catalogs_keys_products_filters2 k LEFT JOIN catalogs_filters2 f ON f.id=k.filter_id ";
  2618 + if(isset($filter['f']) && count($filter['f'])>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id ";
  2619 + if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id ";
  2620 + if(isset($filter['s']) && count($filter['s'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 ";}
  2621 + if(isset($filter['r']) && count($filter['r'])>0){$sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 ";}
  2622 + if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id ";}
  2623 + $sql .= "where p.id=k.product_id and p.count_modifications>0 ";
  2624 + //$sql = "select * from catalogs_filters where 1=1 ";
  2625 + if($all == false)$sql .= "and f.active='0' ";
  2626 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  2627 + $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
  2628 + //print $sql;
  2629 + $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC);
  2630 +
  2631 + // $row = $this->db->getAll("select *,f.name".($lang=='ukr'?'_ukr':'')." as name from catalogs_filters2 f where f.active='0' and f.rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC);
  2632 + $this->tpl->assign('filters2', $row);
  2633 + }
  2634 +
  2635 + function getFiltersMod_IDs($ids){
  2636 + $name = array();
  2637 + foreach($ids as $id){
  2638 + $name[] = $this->db->getOne("select size from catalogs_modifications where size=$id",array());
  2639 + }
  2640 + return implode(", ",$name);
  2641 + }
  2642 +
  2643 + function viewFiltersMod ($rubric_id)
  2644 +{
  2645 + $search = array ();
5511 2646  
5512   - function displayEditUser ()
5513   - {
5514   - $this->tpl->assign ("tpl", 'catalogs_user_edit.tpl');
5515   - }
  2647 + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
  2648 + $filter = $this->seralizeFilter ($_GET['filter']);
5516 2649  
5517   - function displayNoPsw ()
  2650 + if (isset ($filter['f']) && count ($filter['f']) > 0)
5518 2651 {
5519   - $this->tpl->assign ("tpl", 'catalogs_nopsw.tpl');
  2652 + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
5520 2653 }
5521   -
5522   - function displayOrders ()
  2654 +
  2655 + if (isset ($filter['y']) && $filter['y'] > 0)
5523 2656 {
5524   - $this->tpl->assign ("tpl", 'catalogs_orders.tpl');
  2657 + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
5525 2658 }
5526   -
5527   - function displayOrder ()
  2659 +
  2660 + if (isset ($filter['r']) && count ($filter['r']) > 0)
5528 2661 {
5529   - $this->tpl->assign ("tpl", 'catalogs_order.tpl');
  2662 + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
5530 2663 }
5531 2664  
5532   - function displayUsers ()
  2665 + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
  2666 + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
  2667 + /*
  2668 + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2669 + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  2670 + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
  2671 + * }
  2672 + */
  2673 + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
5533 2674 {
5534   - $this->tpl->assign ("tpl", 'catalogs_users.tpl');
  2675 + $sex = $this->seralizeSex ($_GET['sex']);
  2676 + $search[] = "p.sex IN (" . implode (",", $sex) . ")";
5535 2677 }
5536 2678  
5537   - function displayUser ()
5538   - {
5539   - $this->tpl->assign ("tpl", 'catalogs_user.tpl');
5540   - }
  2679 + if (isset ($_GET['new']) && $_GET['new'] > 0)
  2680 + $search[] = sprintf ("p.active='%d'", $_GET['new']);
5541 2681  
5542   - function displayFilters ()
5543   - {
5544   - $this->tpl->assign ("tpl", 'catalogs_filters.tpl');
5545   - }
  2682 + if (isset ($_GET['top']) && $_GET['top'] > 0)
  2683 + $search[] = sprintf ("p.top='%d'", $_GET['top']);
  2684 +
  2685 + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
  2686 + $search[] = sprintf ("p.akcii_id>'%d'", 0);
5546 2687  
5547   - function displayFilters2 ()
  2688 + $sql = "select m.* from catalogs_modifications m,catalogs_products p ";
  2689 + if (isset ($filter['f']) && count ($filter['f']) > 0)
  2690 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id ";
  2691 +
  2692 + if (isset ($filter['y']) && $filter['y'] > 0)
  2693 + $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id ";
  2694 +
  2695 + if (isset ($filter['r']) && count ($filter['r']) > 0)
5548 2696 {
5549   - $this->tpl->assign ("tpl", 'catalogs_filters2.tpl');
  2697 + $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 ";
5550 2698 }
5551 2699  
5552   - function displayYears ()
  2700 + $sql .= "where m.size<>'' ";
  2701 +
  2702 + if (count ($search))
  2703 + $sql .= "AND " . implode (" AND ", $search) . " ";
  2704 +
  2705 + $sql .= "
  2706 + and m.product_id=p.id
  2707 + and m.active=1
  2708 + and p.rubric_id=?
  2709 + and p.count_modifications>0
  2710 + and m.size > 0
  2711 + GROUP BY m.size";
  2712 + $row = $this->db->getAll ($sql, array (
  2713 + $rubric_id
  2714 + ), DB_FETCHMODE_ASSOC);
  2715 +
  2716 + if ($_GET['t'] == 1)
5553 2717 {
5554   - $this->tpl->assign ("tpl", 'catalogs_years.tpl');
  2718 + print "<pre>";
  2719 + print_r ($row);
  2720 + print "</pre>";
5555 2721 }
  2722 +
  2723 + $this->tpl->assign ('size', $row);
  2724 +}
  2725 +
  2726 +function viewFiltersRost ($rubric_id)
  2727 +{
  2728 + $search = array ();
5556 2729  
5557   - function displayWinProducts ()
  2730 + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
  2731 + $filter = $this->seralizeFilter ($_GET['filter']);
  2732 +
  2733 + if (isset ($filter['f']) && count ($filter['f']) > 0)
5558 2734 {
5559   - $this->tpl->display ('catalogs_win_products.tpl');
  2735 + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
5560 2736 }
5561 2737  
5562   - function displayModifications ()
  2738 + if (isset ($filter['y']) && $filter['y'] > 0)
5563 2739 {
5564   - $this->tpl->assign ("tpl", 'catalogs_modifications.tpl');
  2740 + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
5565 2741 }
5566 2742  
5567   - function displayImport ()
  2743 + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
  2744 + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
  2745 + /*
  2746 + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
  2747 + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
  2748 + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
  2749 + * }
  2750 + */
  2751 + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
5568 2752 {
5569   - $this->tpl->assign ("tpl", 'catalogs_import.tpl');
  2753 + $sex = $this->seralizeSex ($_GET['sex']);
  2754 + $search[] = "p.sex IN (" . implode (",", $sex) . ")";
5570 2755 }
5571 2756  
5572   - function displayImportCine ()
  2757 + $sql = "select m.* from catalogs_modifications m, catalogs_products p ";
  2758 +
  2759 + if (isset ($filter['f']) && count ($filter['f']) > 0)
  2760 + $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id ";
  2761 +
  2762 + if (isset ($filter['y']) && $filter['y'] > 0)
  2763 + $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id ";
  2764 +
  2765 + $sql .= "where m.rost<>'' ";
  2766 +
  2767 + if (count ($search))
5573 2768 {
5574   - $this->tpl->assign ("tpl", 'catalogs_import_cine.tpl');
  2769 + $sql .= "AND " . implode (" AND ", $search) . " ";
5575 2770 }
5576 2771  
5577   - function displayAkcii ()
  2772 + $sql .= "
  2773 + and m.product_id=p.id
  2774 + and m.active=1
  2775 + and p.rubric_id=?
  2776 + and p.count_modifications>0
  2777 + GROUP BY m.rost";
  2778 + $row = $this->db->getAll ($sql, array (
  2779 + $rubric_id
  2780 + ), DB_FETCHMODE_ASSOC);
  2781 +
  2782 + if ($_GET['t'] == 1)
  2783 + {
  2784 + print "<pre>";
  2785 + print_r ($row);
  2786 + print "</pre>";
  2787 + }
  2788 +
  2789 + $this->tpl->assign ('rost', $row);
  2790 +}
  2791 +
  2792 + function viewRostProduct($id){
  2793 + $sql = "select m.* from catalogs_modifications m where m.product_id=? GROUP BY m.rost";
  2794 + $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  2795 + $this->tpl->assign('product_rost',$row);
  2796 + }
  2797 +
  2798 + function viewFiltersInProducts($filter_products,$lang='ru'){
  2799 + $search = array();
  2800 + if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']);
  2801 + if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']);
  2802 + if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0);
  2803 +
  2804 + $sql ="select f.*,f.name".($lang=='ukr'?'_ukr':'')." as name from catalogs_products p, catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where p.id=k.product_id AND f.id IN (".$filter_products.") and f.active='0' ";
  2805 + if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
  2806 + $sql .= 'GROUP BY k.filter_id order by f.sort';
  2807 + //print $sql;
  2808 + $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  2809 + $this->tpl->assign('filters', $row);
  2810 + }
  2811 +
  2812 + function viewBrend($id){
  2813 + $row = $this->db->getRow("select * from catalogs_brends where id=?",array($id),DB_FETCHMODE_ASSOC);
  2814 + $this->tpl->assign('brend', $row);
  2815 + }
  2816 +
  2817 + function viewBrendName($name){
  2818 + $name = iconv("utf-8", "windows-1251", $name);
  2819 + $sql = "select * from catalogs_brends where name=? limit 1";
  2820 + $row = $this->db->getRow($sql,array($name),DB_FETCHMODE_ASSOC);
  2821 + $this->tpl->assign('brend_seo', $row);
  2822 + return $row;
  2823 + }
  2824 +
  2825 + function getBrendIDs_name($name){
  2826 + $n = array();
  2827 + $name_arr = explode(";",$name);
  2828 + foreach($name_arr as $row){
  2829 + $n[] = "'".$row."'";
  2830 + }
  2831 + //$name = iconv("utf-8", "windows-1251", $name);
  2832 + $sql = "select id from catalogs_brends where name in (" . implode(",",$n) . ")";
  2833 + //print $sql;
  2834 + return $this->db->getCol($sql,"id",array());
  2835 + }
  2836 +
  2837 + function viewBrendRubrics($name,$lang = 'ru'){
  2838 + $name = iconv("utf-8", "windows-1251", $name);
  2839 + $sql = "select r.name".(($lang=='ukr')?'_ukr':'')." as name,r.parent_id,r.translit,count(p.id) as c from catalogs_brends b
  2840 + Left Join catalogs_rubrics r On r.id=b.rubric_id
  2841 + Left Join catalogs_products p On p.brend_id=b.id AND p.count_modifications>0
  2842 + where b.name=? and r.name<>'' Group by p.brend_id";
  2843 + $res = $this->db->getAll($sql,array($name),DB_FETCHMODE_ASSOC);
  2844 + $rubrics = array();
  2845 + foreach($res as $row){
  2846 + if($row['c']>0){
  2847 + $rubrics[$this->getRubricName($row['parent_id'],$lang)][] = $row;
  2848 + }
  2849 + }
  2850 + // print"<pre>";
  2851 + // print_r($rubrics);
  2852 + // print"</pre>";
  2853 + $this->tpl->assign('brend_rubrics',$rubrics);
  2854 + }
  2855 +
  2856 + function deleteBrend($id){
  2857 + $this->db->query("delete from catalogs_brends where id=?",array($id));
  2858 + }
  2859 +
  2860 + function viewAkciiProductID($id){
  2861 + $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?";
  2862 + $row = $this->db->getCol($sql,"rubric_id",array($id));
  2863 + $this->tpl->assign('product_akcii',$row);
  2864 + }
  2865 +
  2866 + function import_saveRubric($name,$parent_id){
  2867 + $id = $this->db->getOne("select id from catalogs_rubrics where name=? and parent_id=?",array($name,$parent_id));
  2868 + if( !$id ){
  2869 + $this->db->autoExecute("catalogs_rubrics",array('name'=>$name,'translit'=>translit($name),'parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1)),DB_AUTOQUERY_INSERT);
  2870 + return mysql_insert_id();
  2871 + }
  2872 + return $id;
  2873 + }
  2874 +
  2875 + function import_saveBrend($name,$rubric_id){
  2876 + //getRubricParent();
  2877 + $id = $this->db->getOne("select id from catalogs_brends where name=? and rubric_id=?",array($name,$rubric_id));
  2878 + if( !$id ){
  2879 + $this->db->autoExecute("catalogs_brends",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT);
  2880 + return mysql_insert_id();
  2881 + }
  2882 + return $id;
  2883 + }
  2884 +
  2885 + function import_saveFilters2($rubric_id,$str){
  2886 + if(!$str)return array();
  2887 + $row_str = explode(",",trim($str));
  2888 + $arr_id = array();
  2889 + foreach($row_str as $str){
  2890 + $name = trim($str);
  2891 + $name_r = explode('=',$name);$name = $name_r[0]; $active = (isset($name_r[1])) ? 1 : 0;
  2892 + $id = $this->db->getOne("select id from catalogs_filters2 where rubric_id=? and name=?",array($rubric_id,$name));
  2893 + if( !$id ){
  2894 + $this->db->autoExecute("catalogs_filters2",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_INSERT);
  2895 + $id = mysql_insert_id();
  2896 + }else{ $this->db->autoExecute("catalogs_filters2",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_UPDATE,"id=$id");}
  2897 + $arr_id[] = $id;
  2898 + }
  2899 + return $arr_id;
  2900 + }
  2901 +
  2902 + function import_saveFilters($rubric_id,$str){
  2903 + if(!$str)return array();
  2904 + $row_str = explode(",",trim($str));
  2905 + $arr_id = array();
  2906 + foreach($row_str as $str){
  2907 + $name = trim($str);
  2908 + $name_r = explode('=',$name);$name = $name_r[0]; $active = (isset($name_r[1])) ? 1 : 0;
  2909 + $id = $this->db->getOne("select id from catalogs_filters where rubric_id=? and name=?",array($rubric_id,$name));
  2910 + if( !$id ){
  2911 + $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_INSERT);
  2912 + $id = mysql_insert_id();
  2913 + }else{ $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_UPDATE,"id=$id");}
  2914 + $arr_id[] = $id;
  2915 + }
  2916 + return $arr_id;
  2917 + }
  2918 +
  2919 + function import_saveYear($rubric_id,$name){
  2920 + if(!$name)return false;
  2921 + $id = $this->db->getOne("select id from catalogs_years where rubric_id=? and name=?",array($rubric_id,$name));
  2922 + if( !$id ){
  2923 + $this->db->autoExecute("catalogs_years",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT);
  2924 + $id = mysql_insert_id();
  2925 + }
  2926 + return ($id)?array($id):array();
  2927 + }
  2928 +
  2929 + function import_updateProductCine($product_id,$row,$line='',$mktime = 0){ // print"<pre>";print_r($row);print"</pre>";
  2930 +
  2931 + IF($product_id>0){
  2932 + IF($row[3]>0){
  2933 + if($row[2]<1){$cine=$row[1];$cine_last=0;}
  2934 + else {$cine=$row[2];$cine_last=(($row[1]>0)?$row[1]:$row[2]);}
  2935 + $this->db->autoExecute("catalogs_products",array('cine'=>$cine,'cine_last'=>$cine_last),DB_AUTOQUERY_UPDATE,"id='$product_id'");
  2936 + }
  2937 +
  2938 +
  2939 + $city = trim($row[4]);
  2940 + if(!$city)$city = "Èíòåðíåò ìàãàçèí";
  2941 + //echo "OK(1) - <br/>";
  2942 + if(strlen($city)>0){ //print $city;
  2943 + $city_id = $this->is_city($city);
  2944 + //echo "OK(2) - <br/>";
  2945 + if(!$city_id){$city_id = $this->SaveCity(array('name'=>$city));}
  2946 + $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array($product_id,$row[0],$mktime));
  2947 +
  2948 + if($row[3]==0){
  2949 +
  2950 + }
  2951 + else{
  2952 + // $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime<?", array($product_id,$row[0],$mktime));
  2953 + //echo "OK(3) - <br/>";
  2954 + if($this->getKeysModificationCity($row[0], $city_id)){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "mod_code='".$row[0]."' and city_id='".$city_id."'";}
  2955 + else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;}
  2956 +
  2957 + // if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;}
  2958 + //print $city_id .'--'.$where."<br>";
  2959 + $fields = array('count'=>$row[3],'product_id'=>$product_id,'mod_code'=>$row[0],'city_id'=>$city_id,'mktime'=>$mktime);
  2960 + $s = $this->db->autoExecute("catalogs_keys_products_cities",$fields,$DB_AUTOQUERY,$where);
  2961 + if (PEAR::isError($s)) die($s->getMessage());
  2962 + }}
  2963 + //echo "OK(4) - <br/>";
  2964 + $active = $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0",array($row[0]));
  2965 + //$active = true;
  2966 + if($this->db->getOne("select count(*) from catalogs_modifications where code=?",array($row[0]))>0){
  2967 + $this->db->autoExecute("catalogs_modifications",array('active'=>$active,'is_update'=>1,'prefix'=>$row[4]),DB_AUTOQUERY_UPDATE,"code='".$row[0]."'");
  2968 + //echo "OK(5) - <br/>";
  2969 + }else{
  2970 + //echo "OK(6) - <br/>";
  2971 + $this->saveCsvMod($line);
  2972 + }
  2973 + }
  2974 + }
  2975 +
  2976 + function saveCsvMod($line){
  2977 + echo "OK1 - <br/>";
  2978 + $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv";
  2979 + $handle = @fopen($tmpfname, "a");
  2980 +// $row = explode(";",$line);
  2981 +// File_FGetCSV::fputcsv($handle,$row,';');
  2982 + echo "OK2 - <br/>";
  2983 + echo $line;
  2984 + echo "OK3 - <br/>";
  2985 + fwrite($handle,$line);
  2986 + fclose($handle);
  2987 + }
  2988 +
  2989 + function getKeysModificationCity($code, $city_id){
  2990 + return $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id));
  2991 + }
  2992 +
  2993 + function getKeysModificationCity_count($code, $city_id){
  2994 + return $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id));
  2995 + }
  2996 +
  2997 + function getKeysModificationCityMktime_count($code, $city_id, $mktime){
  2998 + $r = $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array($code, $city_id, $mktime));
  2999 + return $r;
  3000 + }
  3001 +
  3002 + function getProductID($name){
  3003 + $id = $this->db->getOne("select id from catalogs_products where name=?",array($name));
  3004 + return $id;
  3005 + }
  3006 +
  3007 +function getProductID_R ($name, $rubric_parent_id)
  3008 +{
  3009 + $id = $this->db->getOne ("select id from catalogs_products where name=? and rubric_id=?", array (
  3010 + $name,
  3011 + $rubric_parent_id
  3012 + ));
  3013 +
  3014 + return $id;
  3015 +}
  3016 +
  3017 + function getModificationActive($code){
  3018 + return $this->db->getOne("select active from catalogs_modifications where code=?",array($code));
  3019 + }
  3020 +
  3021 +function updateProduct_countModification ($product_id, $count)
  3022 +{
  3023 + $this->db->autoExecute ("catalogs_products", array (
  3024 + 'count_modifications' => $count
  3025 + ), DB_AUTOQUERY_UPDATE, "id='$product_id'");
  3026 +}
  3027 +
  3028 + function updateProductModificationCountPrefix($product_id,$prefix = "+"){
  3029 +// print $product_id;
  3030 + $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?";
  3031 + $this->db->query($sql,array($product_id));
  3032 + }
  3033 +
  3034 + function exportCSV(){
  3035 + $tmpfname = "tmp/price.csv";
  3036 + $handle = fopen($tmpfname, "w");
  3037 + // fwrite($handle, $xml);
  3038 + $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,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null 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());
  3039 + foreach($res as $key=>$row){
  3040 + $list = $row;
  3041 + $mod_res = $this->db->getAll('select code,size,color,pic_big,active from catalogs_modifications where product_id=? Order by id',array($row[0]));
  3042 + foreach($mod_res as $mod_row){$list[] = implode('=',$mod_row);}
  3043 +
  3044 + $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]));
  3045 + $list[8]=implode(',',$f_row);
  3046 +
  3047 + $f_row = $this->db->getCol("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?",'name',array($list[0]));
  3048 + $list[9]=implode(',',$f_row);
  3049 +
  3050 + switch($list[10]){
  3051 + case 1 : $list[10] = 'ìóæñêîé'; break;
  3052 + case 2 : $list[10] = 'æåíñêèé'; break;
  3053 + case 3 : $list[10] = 'äåòñêèé'; break;
  3054 + case 4 : $list[10] = 'óíèñåêñ'; break;
  3055 + default : $list[10] = 'ìóæñêîé'; break;
  3056 + }
  3057 +
  3058 + $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]));
  3059 + $list[11]=implode(',',$y_row);
  3060 +
  3061 + $p_row = $this->db->getCol("select pic_big from catalogs_gallery where product_id=?",'pic_big',array($list[0]));
  3062 + $list[20]=implode(',',$p_row);
  3063 +
  3064 + //print_r($list);exit;
  3065 + $p_res = $this->db->getAll("select name,size,metka from catalogs_products_params where product_id=? order by id asc",array($list[0]));
  3066 + $param = array();
  3067 + foreach($p_res as $row_p){
  3068 + $param[] = implode('*',$row_p);
  3069 + }
  3070 + $list[17] = implode('=',$param);
  3071 +
  3072 + unset($list[0]);unset($list[1]);
  3073 +
  3074 + File_FGetCSV::fputcsv($handle,$list,';');
  3075 +
  3076 +
  3077 +
  3078 + }
  3079 +
  3080 + fclose($handle);
  3081 +
  3082 + $params = array(
  3083 + 'file' => $tmpfname,
  3084 + 'contenttype' => 'application/xls',
  3085 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'),
  3086 + 'cache' => false
  3087 + );
  3088 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3089 + if ($error === true) {
  3090 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3091 + }
  3092 +
  3093 + unlink($tmpfname);
  3094 + }
  3095 +
  3096 + function exportCSVaktual(){
  3097 + $tmpfname = "tmp/price.csv";
  3098 + $handle = fopen($tmpfname, "w");
  3099 + // fwrite($handle, $xml);
  3100 + $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,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null 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 WHERE p.count_modifications>0',array());
  3101 + foreach($res as $key=>$row){
  3102 + $list = $row;
  3103 + $mod_res = $this->db->getAll('select code,size,rost,color,pic_big,active from catalogs_modifications where product_id=? Order by id',array($row[0]));
  3104 + foreach($mod_res as $mod_row){if(strlen($mod_row[2])>0)$mod_row[1] = $mod_row[1].'*'.$mod_row[2]; unset($mod_row[2]);$list[] = implode('=',$mod_row);}
  3105 +
  3106 + $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]));
  3107 + $list[8]=implode(',',$f_row);
  3108 +
  3109 + $f_row = $this->db->getCol("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?",'name',array($list[0]));
  3110 + $list[9]=implode(',',$f_row);
  3111 +
  3112 + switch($list[10]){
  3113 + case 1 : $list[10] = 'ìóæñêîé'; break;
  3114 + case 2 : $list[10] = 'æåíñêèé'; break;
  3115 + case 3 : $list[10] = 'äåòñêèé'; break;
  3116 + case 4 : $list[10] = 'óíèñåêñ'; break;
  3117 + default : $list[10] = 'ìóæñêîé'; break;
  3118 + }
  3119 +
  3120 + $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]));
  3121 + $list[11]=implode(',',$y_row);
  3122 +
  3123 + $p_row = $this->db->getCol("select pic_big from catalogs_gallery where product_id=?",'pic_big',array($list[0]));
  3124 + $list[20]=implode(',',$p_row);
  3125 +
  3126 + //print_r($list);exit;
  3127 + $p_res = $this->db->getAll("select name,size,metka from catalogs_products_params where product_id=? order by id asc",array($list[0]));
  3128 + $param = array();
  3129 + foreach($p_res as $row_p){
  3130 + $param[] = implode('*',$row_p);
  3131 + }
  3132 + $list[17] = implode('=',$param);
  3133 +
  3134 + unset($list[0]);unset($list[1]);
  3135 +
  3136 + File_FGetCSV::fputcsv($handle,$list,';');
  3137 +
  3138 +
  3139 +
  3140 + }
  3141 +
  3142 + fclose($handle);
  3143 +
  3144 + $params = array(
  3145 + 'file' => $tmpfname,
  3146 + 'contenttype' => 'application/xls',
  3147 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'),
  3148 + 'cache' => false
  3149 + );
  3150 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3151 + if ($error === true) {
  3152 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3153 + }
  3154 +
  3155 + unlink($tmpfname);
  3156 + }
  3157 +
  3158 + function exportModCSV(){
  3159 + $tmpfname = "tmp/price_mod.csv";
  3160 + $handle = fopen($tmpfname, "w");
  3161 + $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 Order by m.id');
  3162 + foreach($res as $key=>$row){
  3163 + File_FGetCSV::fputcsv($handle,$row,';');
  3164 + }
  3165 + fclose($handle);
  3166 + $params = array(
  3167 + 'file' => $tmpfname,
  3168 + 'contenttype' => 'application/xls',
  3169 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'file_1.csv'),
  3170 + 'cache' => false
  3171 + );
  3172 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3173 + if ($error === true) {
  3174 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3175 + }
  3176 +
  3177 + unlink($tmpfname);
  3178 + $this->db->autoExecute("catalogs_modifications",array('is_update'=>0),DB_AUTOQUERY_UPDATE);
  3179 + }
  3180 +
  3181 + function exportUsersCSV(){
  3182 + $tmpfname = "tmp/users.csv";
  3183 + $handle = fopen($tmpfname, "w");
  3184 +
  3185 + $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,summary,u.birthday,c.card
  3186 + FROM zlo_users AS u
  3187 + LEFT JOIN card c ON c.user_id = u.id
  3188 + LEFT JOIN zlo_users_group AS g ON u.group = g.id
  3189 + LEFT JOIN (SELECT user_id AS order_user_id, sum( `total` ) AS `summary` FROM catalogs_orders group by user_id ) o
  3190 + ON u.id = o.order_user_id
  3191 + ";
  3192 + $res = $this->db->getAll($sql);
  3193 + foreach($res as $key=>$row){
  3194 + File_FGetCSV::fputcsv($handle,$row,';');
  3195 + }
  3196 + fclose($handle);
  3197 + $params = array(
  3198 + 'file' => $tmpfname,
  3199 + 'contenttype' => 'application/xls',
  3200 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'users.csv'),
  3201 + 'cache' => false
  3202 + );
  3203 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3204 + if ($error === true) {
  3205 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3206 + }
  3207 +
  3208 + unlink($tmpfname);
  3209 + }
  3210 +
  3211 + function exportUsersBirdthCSV(){
  3212 + $tmpfname = "tmp/usersBirdth.csv";
  3213 + $handle = fopen($tmpfname, "w");
  3214 +
  3215 + $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,u.birthday,c.card
  3216 + FROM zlo_users AS u
  3217 + LEFT JOIN card c ON c.user_id = u.id
  3218 + LEFT JOIN zlo_users_group AS g ON u.group = g.id
  3219 + WHERE DAYOFMONTH(u.birthday) >= '19' AND DAYOFMONTH(u.birthday) <= '28' and MONTH(u.birthday) = '10'
  3220 + ";
  3221 + $res = $this->db->getAll($sql);
  3222 + foreach($res as $key=>$row){
  3223 + File_FGetCSV::fputcsv($handle,$row,';');
  3224 + }
  3225 + fclose($handle);
  3226 + $params = array(
  3227 + 'file' => $tmpfname,
  3228 + 'contenttype' => 'application/xls',
  3229 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'users.csv'),
  3230 + 'cache' => false
  3231 + );
  3232 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3233 + if ($error === true) {
  3234 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3235 + }
  3236 +
  3237 + unlink($tmpfname);
  3238 + }
  3239 +
  3240 + function exportSeoF1CSV(){
  3241 + $tmpfname = "tmp/seo_f1.csv";
  3242 + $handle = fopen($tmpfname, "w");
  3243 + $res = $this->db->getAll("select id,name,translit,name_h1 from catalogs_rubrics");
  3244 + foreach($res as $key=>$row){
  3245 + //$res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
  3246 + //foreach($res_b as $row_b){
  3247 + $list = array();
  3248 + $f_res = $this->db->getAll("select id,prefix,name from catalogs_filters where rubric_id=?",array($row[0]));
  3249 + foreach($f_res as $f_row){
  3250 + $list[0] = $row[0];
  3251 + $list[1] = (strlen($row[3])>0) ? $row[3] : $row[1];
  3252 + $list[2] = $f_row[2];
  3253 + $list[3] = "http://extremstyle.ua/".$row[2]."-catalogs/filter;filter=f".$f_row[0]."_".$f_row[1]."/";
  3254 + //$list[4] = $row_b[0];
  3255 + File_FGetCSV::fputcsv($handle,$list,';');
  3256 + }
  3257 + //}
  3258 + }
  3259 +
  3260 +
  3261 + $res = $this->db->getAll("select id,name,translit,name_h1 from catalogs_rubrics");
  3262 + foreach($res as $key=>$row){
  3263 + //$res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
  3264 + //foreach($res_b as $row_b){
  3265 + $list = array();
  3266 + $f_res = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
  3267 + foreach($f_res as $f_row){
  3268 + if(!strlen($f_row[0]))continue;
  3269 + $list[0] = $row[0];
  3270 + $list[1] = (strlen($row[3])>0) ? $row[3] : $row[1];
  3271 + $list[2] = $f_row[0];
  3272 + $list[3] = "http://extremstyle.ua/".$row[2]."-catalogs/filter;brend=".$f_row[0]."/";
  3273 + //$list[4] = $row_b[0];
  3274 + File_FGetCSV::fputcsv($handle,$list,';');
  3275 + }
  3276 + //}
  3277 + }
  3278 +
  3279 +
  3280 +
  3281 + fclose($handle);
  3282 + $params = array(
  3283 + 'file' => $tmpfname,
  3284 + 'contenttype' => 'application/xls',
  3285 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'seo_f1.csv'),
  3286 + 'cache' => false
  3287 + );
  3288 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3289 + if ($error === true) {
  3290 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3291 + }
  3292 +
  3293 + unlink($tmpfname);
  3294 + }
  3295 +
  3296 + function exportSeoCSV(){
  3297 + $tmpfname = "tmp/seo.csv";
  3298 + $handle = fopen($tmpfname, "w");
  3299 + $res = $this->db->getAll('select p.id,p.rubric_id,r.name_h1,null,r.list_name,b.name,p.name,null,p.cine, r.translit,p.translit,r.name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id');
  3300 + foreach($res as $key=>$row){
  3301 + $row[3] = $this->getFilterPh1($row[0]);
  3302 + if(!strlen($row[2]))$row[2] = $row[11];
  3303 + $row[7] = "http://extremstyle.ua/".$row[9]."-catalogs/".$row[10]."-".$row[0]."/";
  3304 + unset($row[9]);unset($row[10]);unset($row[11]);
  3305 + File_FGetCSV::fputcsv($handle,$row,';');
  3306 + }
  3307 + fclose($handle);
  3308 + $params = array(
  3309 + 'file' => $tmpfname,
  3310 + 'contenttype' => 'application/xls',
  3311 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'seo.csv'),
  3312 + 'cache' => false
  3313 + );
  3314 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3315 + if ($error === true) {
  3316 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3317 + }
  3318 +
  3319 + unlink($tmpfname);
  3320 + }
  3321 +
  3322 +
  3323 + function exportProductsSeoCSV(){
  3324 + $tmpfname = "tmp/products_seo.csv";
  3325 + $handle = fopen($tmpfname, "w");
  3326 + $res = $this->db->getAll('select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where b.name=?',array('Dakine'));
  3327 + foreach($res as $key=>$row){
  3328 + $vowels = array("'05","'06","'07","'08","'09","'10", "'11", "'12", "'13", "'14", "'15", "'16","2005","2006","2007","2008","2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016",);
  3329 + $row[3] = $this->getFilterPh1($row[2]) .' '. str_replace($vowels, "", $row[3]);
  3330 + $row[8] = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/";
  3331 + unset($row[6]);unset($row[7]);
  3332 + File_FGetCSV::fputcsv($handle,$row,';');
  3333 + }
  3334 + fclose($handle);
  3335 + $params = array(
  3336 + 'file' => $tmpfname,
  3337 + 'contenttype' => 'application/xls',
  3338 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'products_seo.csv'),
  3339 + 'cache' => false
  3340 + );
  3341 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3342 + if ($error === true) {
  3343 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3344 + }
  3345 +
  3346 + unlink($tmpfname);
  3347 + }
  3348 +
  3349 + function exportProducts2SeoCSV(){
  3350 + $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/cron/products_seo.csv";
  3351 + $handle = fopen($tmpfname, "w");
  3352 + $sql = 'select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id LEFT JOIN catalogs_keys_products_years ky ON ky.product_id=p.id LEFT JOIN catalogs_years y ON y.id=ky.year_id where p.count_modifications>0 and b.name=? and y.name in ("2013","2014","2015","2014-2015")';
  3353 + $res = $this->db->getAll($sql,array('Dakine'));
  3354 + foreach($res as $key=>$row){
  3355 + $vowels = array("'05","'06","'07","'08","'09","'10", "'11", "'12", "'13", "'14", "'15", "'16","2005","2006","2007","2008","2009", "2010", "2011", "2012", "2013", "2014", "2015", "2016",);
  3356 + $row[3] = $this->getFilterPh1($row[2]) .' '. str_replace($vowels, "", $row[3]);
  3357 + $row[8] = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/";
  3358 + unset($row[5]);unset($row[6]);unset($row[7]);
  3359 + File_FGetCSV::fputcsv($handle,$row,';');
  3360 + }
  3361 + fclose($handle);
  3362 +
  3363 + }
  3364 +
  3365 + function exportProductsFeed(){
  3366 + $tmpfname = "tmp/products_feed.csv";
  3367 + $handle = fopen($tmpfname, "w");
  3368 + $sql = 'select r.id,r.name,p.id,p.name,p.cine_last,r.translit,p.translit,r.list_name,p.pic,b.name,p.about,p.cine From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where p.count_modifications>0 and p.cine>0';
  3369 + $res = $this->db->getAll($sql,array());
  3370 + $list = array('ID','ID2','Item title','Destination URL','Image URL','Item subtitle','Item description','Item category','Price','Sale price','Contextual keywords','Item address');
  3371 + File_FGetCSV::fputcsv($handle,$list,',');
  3372 + foreach($res as $key=>$row){
  3373 + $url = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/";
  3374 + $image = "http://extremstyle.ua/uploaded/pic/catalogs/products/".$row[8];
  3375 + $subtitle = $row[1].' '.$row[9];
  3376 + $list = array(
  3377 + $row[2],$row[2].'S',substr($row[3],0,12),$url,$image,substr($subtitle,0,12),"Ãàðàíòèÿ êà÷åñòâà",$row[1],round($row[11]).' UAH',round($row[4]).' UAH',$row[1].' '.$row[9],
  3378 + );
  3379 + //print_r($list);
  3380 + unset($row[5]);unset($row[6]);unset($row[7]);
  3381 + File_FGetCSV::fputcsv($handle,$list,',');
  3382 + }
  3383 + fclose($handle);
  3384 + $params = array(
  3385 + 'file' => $tmpfname,
  3386 + 'contenttype' => 'application/xls',
  3387 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'products_feed.csv'),
  3388 + 'cache' => false
  3389 + );
  3390 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3391 + if ($error === true) {
  3392 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3393 + }
  3394 +
  3395 + unlink($tmpfname);
  3396 + }
  3397 +
  3398 + function exportOrdersCSV(){
  3399 + $tmpfname = "tmp/orders.csv";
  3400 + $handle = fopen($tmpfname, "w");
  3401 + $res = $this->db->getAll('select o.id,o.name,o.email,o.adress,o.phone,o.total From catalogs_orders o LEFT JOIN zlo_users u ON u.id=o.user_id WHERE u.`group`=2 order by o.id desc');
  3402 + foreach($res as $key=>$row){
  3403 + $products = $this->db->getAll("select p.* from catalogs_orders_products op
  3404 + LEFT JOIN catalogs_modifications m ON m.code=op.code
  3405 + LEFT JOIN catalogs_products p ON p.id=m.product_id
  3406 + where op.order_id=? GROUP BY p.id",array($row[0]),DB_FETCHMODE_ASSOC);
  3407 + $arr_products = array();
  3408 + foreach($products as $p){
  3409 + $arr_products[] = $p['name'];
  3410 + }
  3411 + $row[6] = implode(', ',$arr_products);
  3412 + File_FGetCSV::fputcsv($handle,$row,';');
  3413 + }
  3414 + fclose($handle);
  3415 + $params = array(
  3416 + 'file' => $tmpfname,
  3417 + 'contenttype' => 'application/xls',
  3418 + 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'orders.csv'),
  3419 + 'cache' => false
  3420 + );
  3421 + $error = HTTP_Download::staticSend($params, false); //îòäà¸ì ôàéë
  3422 + if ($error === true) {
  3423 + //åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
  3424 + }
  3425 +
  3426 + unlink($tmpfname);
  3427 + }
  3428 +
  3429 + function deleteProductParams($product_id){
  3430 + $sql = "delete from catalogs_products_params where product_id=?";
  3431 + $this->db->query($sql,array($product_id));
  3432 + }
  3433 +
  3434 + function saveProductParams($product_id,$pruduct_params){
  3435 + $this->deleteProductParams($product_id);
  3436 + $array_params = explode("=",$pruduct_params);
  3437 + foreach($array_params as $row){
  3438 + $arr = explode('*',$row);
  3439 + $this->db->autoExecute("catalogs_products_params",array('product_id'=>$product_id,'name'=>$arr[0],'size'=>$arr[1],'metka'=>$arr[2]),DB_AUTOQUERY_INSERT);
  3440 + }
  3441 + }
  3442 +
  3443 + function getProductParams($product_id){
  3444 + $sql = "select * from catalogs_products_params where product_id=? order by id";
  3445 + $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC);
  3446 + return $row;
  3447 + }
  3448 +
  3449 + function viewProductParams($product_id){
  3450 + $this->tpl->assign('params',$this->getProductParams($product_id));
  3451 + }
  3452 +
  3453 +/**
  3454 + * íóæíî äëÿ ïðîñìîòðà ïîâòîðåíèå ñòðîê â ôàéëå èìïîðòà
  3455 + */
  3456 +function saveTmpProduct ($row, $product_id)
  3457 +{
  3458 + if ($product_id > 0)
5578 3459 {
5579   - $this->tpl->assign ("tpl", 'catalogs_akcii.tpl');
  3460 + $this->db->autoExecute ("catalogs_tmp_products", array (
  3461 + 'name' => $row [3],
  3462 + 'product_id' => $product_id
  3463 + ), DB_AUTOQUERY_INSERT);
5580 3464 }
5581   -
5582   - function displayCompare ()
  3465 +}
  3466 +
  3467 +function clearTmpProduct ()
  3468 +{
  3469 + $sql = "TRUNCATE TABLE catalogs_tmp_products";
  3470 + $this->db->query ($sql, array ());
  3471 +}
  3472 +
  3473 +function viewTmpProducts ()
  3474 +{
  3475 + $sql = "
  3476 + SELECT count( name ) AS cn, name
  3477 + FROM catalogs_tmp_products
  3478 + GROUP BY name
  3479 + ORDER BY name";
  3480 + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
  3481 + $this->tpl->assign ('list', $row);
  3482 + $this->tpl->assign ('list_total', $this->db->getOne ("
  3483 + select count(*)
  3484 + from catalogs_tmp_products
  3485 + "));
  3486 +}
  3487 +
  3488 + function deleteGalleryProduct($id){
  3489 + $sql = "select * from catalogs_gallery where product_id=?";
  3490 + $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC);
  3491 + foreach($res as $row){
  3492 + @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}");
  3493 + $this->db->query("delete from catalogs_gallery where id=?",array($row['id']));
  3494 + }
  3495 + }
  3496 +
  3497 + function saveGalleryPics($product_id,$pruduct_gallery_pics){
  3498 + $this->deleteGalleryProduct($product_id);
  3499 + if(strlen($pruduct_gallery_pics)>0){
  3500 + $arr = explode(",",$pruduct_gallery_pics);
  3501 + foreach($arr as $pic){
  3502 + $pic = trim($pic);
  3503 + $id = $this->db->nextId('mySequence_catalogs_gallery');
  3504 + $fields_values = array('id'=>$id,'name' => $pic,'product_id' => $product_id);
  3505 + $upload['pic'] = array('tmp_name'=>"./uploaded/pic/catalogs/products/big/$pic",'name'=>$pic);
  3506 + $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"100",'height'=>"100",'upload_path'=>"./uploaded/pic/catalogs/products/gallery/"));
  3507 + $fields_values['pic_big'] = $pic;
  3508 +
  3509 + $this->db->autoExecute("catalogs_gallery",$fields_values,DB_AUTOQUERY_INSERT);
  3510 + }
  3511 + }
  3512 + }
  3513 +
  3514 + function importCSV ($upload)
  3515 + {
  3516 + error_reporting (0);
  3517 +
  3518 + if ($upload['file']['name'] == "file_1.csv")
  3519 + {
  3520 + print "Îøèáêà! Ôàéë öåí!";
  3521 + exit ();
  3522 + }
  3523 +
  3524 + // $arr_line = file($upload['file']['tmp_name']);
  3525 + $f = fopen ($upload['file']['tmp_name'], "r") or die ("Îøèáêà!");
  3526 +
  3527 + // print"<pre>";
  3528 +
  3529 + $this->clearTmpProduct();
  3530 +
  3531 + for ($i = 0; $row_line = File_FGetCSV::fgetcsv ($f, 15000, ";"); $i ++)
  3532 + {
  3533 + // foreach($arr_line as $line){
  3534 + // $row_line = fgetcsv(";",$line);
  3535 + $rubric_id = $this->import_saveRubric ($row_line [0], 0);
  3536 + $rubric_parent_id = $this->import_saveRubric ($row_line [1], $rubric_id);
  3537 + $brend_id = $this->import_saveBrend ($row_line [2], $rubric_parent_id);
  3538 + $pruduct_name = trim ($row_line [3]);
  3539 + $pruduct_about = trim ($row_line [4]);
  3540 + $pruduct_text = trim ($row_line [5]);
  3541 + $sex = explode (',', $row_line [8]);
  3542 + $pruduct_sex = array ();
  3543 +
  3544 + foreach ($sex as $s)
  3545 + {
  3546 + switch (trim ($s))
  3547 + {
  3548 + case 'ìóæñêîé' :
  3549 + $pruduct_sex [] = 1;
  3550 + break;
  3551 + case 'æåíñêèé' :
  3552 + $pruduct_sex [] = 2;
  3553 + break;
  3554 + case 'äåòñêèé' :
  3555 + $pruduct_sex [] = 3;
  3556 + break;
  3557 + case 'óíèñåêñ' :
  3558 + $pruduct_sex [] = 4;
  3559 + break;
  3560 + default :
  3561 + $pruduct_sex [] = array ();
  3562 + break;
  3563 + }
  3564 + }
  3565 +
  3566 + $pruduct_date = trim ($row_line [9]);
  3567 + $pruduct_cine = trim ($row_line [10]);
  3568 + $pruduct_cine_last = trim ($row_line [11]);
  3569 +
  3570 + if ($pruduct_cine < 1)
  3571 + {
  3572 + $pruduct_cine = $pruduct_cine_last;
  3573 + $pruduct_cine_last = 0;
  3574 + }
  3575 +
  3576 + $pruduct_akcii_id = trim ($row_line [12]);
  3577 + $pruduct_strnumber = trim ($row_line [13]);
  3578 + $pruduct_active = trim ($row_line [14]);
  3579 + $pruduct_params = trim ($row_line [15]);
  3580 + $pruduct_pic_tmp = trim ($row_line [17]);
  3581 + $pruduct_gallery_pics = trim ($row_line [18]);
  3582 + $pruduct_video = trim ($row_line [16]);
  3583 + $pruduct_update_id = $this->getProductID_R ($pruduct_name, $rubric_parent_id);
  3584 +
  3585 + if ($pruduct_update_id > 0)
  3586 + {
  3587 + $row_product = $this->db->getRow ('
  3588 + select update_text, about, text
  3589 + from catalogs_products
  3590 + where id=?', array (
  3591 + $pruduct_update_id
  3592 + ),
  3593 + DB_FETCHMODE_ASSOC
  3594 + );
  3595 +
  3596 + // íå îáíîâëÿòü ïðè èìïîðòå?
  3597 + // 0 - îáíîâëÿòü
  3598 + // 1 - íå îáíîâëÿòü
  3599 + if ($row_product['update_text'] == 1)
  3600 + {
  3601 + // about - ukr
  3602 + $pruduct_about = $row_product['about'];
  3603 +
  3604 + // text - ru
  3605 + $pruduct_text = $row_product['text'];
  3606 + }
  3607 + }
  3608 +
  3609 + $upload_pruduct = (strlen ($pruduct_pic_tmp) > 0 && is_file ("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp")) ? array (
  3610 + 'pic' => array (
  3611 + 'tmp_name' => "./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",
  3612 + 'name' => $pruduct_pic_tmp,
  3613 + 'big' => true
  3614 + )
  3615 + ) : null;
  3616 +
  3617 + $product_id = $this->saveProduct (array (
  3618 + 'rubric_id' => $rubric_parent_id,
  3619 + 'rubric_parent_id' => $rubric_parent_id,
  3620 + 'brend_id' => $brend_id,
  3621 + 'name' => $pruduct_name,
  3622 + 'about' => $pruduct_about,
  3623 + 'update_text' => isset ($row_product['update_text']) ? $row_product['update_text'] : 0,
  3624 + 'text' => $pruduct_text,
  3625 + 'video_code' => $pruduct_video,
  3626 + 'sex' => $pruduct_sex,
  3627 + 'date' => $pruduct_date,
  3628 + 'cine' => $pruduct_cine,
  3629 + 'cine_last' => $pruduct_cine_last,
  3630 + 'akcii_id' => $pruduct_akcii_id,
  3631 + 'strnumber' => $pruduct_strnumber,
  3632 + 'active' => $pruduct_active,
  3633 + 'meta_title' => $pruduct_name,
  3634 + 'meta_description' => $pruduct_name,
  3635 + 'meta_keywords' => $pruduct_name,
  3636 + 'meta_about' => $pruduct_name,
  3637 + 'filter' => $this->import_saveFilters ($rubric_parent_id, $row_line [6]),
  3638 + 'filter2' => $this->import_saveFilters2 ($rubric_parent_id, $row_line [7]),
  3639 + 'years' => $this->import_saveYear ($rubric_parent_id, $pruduct_date),
  3640 + 'akcii' => array (),
  3641 + 'update_id' => $pruduct_update_id
  3642 + ), $upload_pruduct);
  3643 +
  3644 + // print $pruduct_update_id;exit;
  3645 + $this->saveProductParams ($product_id, $pruduct_params);
  3646 + $this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
  3647 + // íå óäàëÿåì !
  3648 + //$this->deleteProductModifications ($product_id, true);
  3649 + $m_i = 0;
  3650 +
  3651 + for ($i = 19; $i < count ($row_line); $i ++)
  3652 + {
  3653 + $arr_mod = trim ($row_line [$i]);
  3654 +
  3655 + if (strlen ($arr_mod) > 0)
  3656 + {
  3657 + $row_mod = explode ("=", $arr_mod);
  3658 +
  3659 + $upload_mod = (strlen ($row_mod [3]) > 0 && is_file ("./uploaded/pic/catalogs/modifications/big/" . $row_mod [3])) ? array (
  3660 + 'pic' => array (
  3661 + 'tmp_name' => "./uploaded/pic/catalogs/modifications/big/" . $row_mod [3],
  3662 + 'name' => $row_mod [3],
  3663 + 'big' => true
  3664 + )
  3665 + ) : null;
  3666 +
  3667 + $size_mod = explode ("*", $row_mod [1]);
  3668 + $rost = (isset ($size_mod [1])) ? $size_mod [1] : '';
  3669 +
  3670 + // íàõîäèì modifications_id
  3671 + $modifications_id = $this->getModification($product_id, $row_mod[0]);
  3672 +
  3673 + // ñîõðàíÿåì
  3674 + $this->SaveModification (array (
  3675 + 'product_id' => $product_id,
  3676 + 'code' => $row_mod [0],
  3677 + 'size' => $size_mod [0],
  3678 + 'rost' => $rost,
  3679 + 'color' => $row_mod [2],
  3680 + 'active' => $row_mod [4],
  3681 + 'update_id' => (int)$modifications_id
  3682 + ), $upload_mod);
  3683 +
  3684 + if ($row_mod[4] > 0)
  3685 + {
  3686 + $m_i ++;
  3687 + }
  3688 + }
  3689 + }
  3690 +
  3691 + $this->updateProduct_countModification ($product_id, $m_i);
  3692 +
  3693 + // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);
  3694 + // $strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data);
  3695 + // print_r($row_line);
  3696 +
  3697 + $this->saveTmpProduct ($row_line, $product_id);
  3698 + if (($i % 30) == 0)
  3699 + {
  3700 + sleep (1);
  3701 + }
  3702 + }
  3703 + // print"</pre>";
  3704 + }
  3705 +
  3706 + function importCSV_cine ($upload)
  3707 + {
  3708 + if ($upload['file']['name'] != "file_1.csv")
  3709 + {
  3710 + print "Îøèáêà! Òîëüêî file_1.csv";
  3711 + exit;
  3712 + }
  3713 +
  3714 + $arr_line = file ($upload['file']['tmp_name']);
  3715 +
  3716 + //print"<pre>";
  3717 + $i = 0;
  3718 + $mktime = mktime();
  3719 + foreach ($arr_line as $line)
  3720 + {
  3721 + $row_line = explode (";", $line);
  3722 + $this->import_updateProductCine($this->getModificationProduct_id ($row_line[0]), $row_line, $line, $mktime);
  3723 +
  3724 + if (($i % 30) == 0)
  3725 + {
  3726 + sleep (1);
  3727 + }
  3728 +
  3729 + $i++;
  3730 + }
  3731 +}
  3732 +
  3733 +function loadCSV_cine($upload)
  3734 +{
  3735 + if ($upload['file']['name'] != "file_1.csv")
5583 3736 {
5584   - $this->tpl->assign ("tpl", 'catalogs_compare.tpl');
  3737 + print "Îøèáêà! Òîëüêî file_1.csv";
  3738 + exit;
5585 3739 }
5586 3740  
5587   - function displayTmpProducts ()
  3741 + $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv";
  3742 +
  3743 + //echo $file;
  3744 + //exit;
  3745 +
  3746 + move_uploaded_file ($upload['file']['tmp_name'], $file);
  3747 +}
  3748 +
  3749 +function is_loadCSV_cine()
  3750 +{
  3751 + $is = is_file($_SERVER['DOCUMENT_ROOT'] . '/cron/file_1.csv');
  3752 + $this->tpl->assign('is', $is);
  3753 +}
  3754 +
  3755 +function CronImportCSV_cine($upload)
  3756 +{
  3757 + $this->importCSV_cine ($upload);
  3758 +}
  3759 +
  3760 +function updateCountModificationProducts ()
  3761 +{
  3762 + $res = $this->db->getAll("
  3763 + select id
  3764 + from catalogs_products
  3765 + ", array (), DB_FETCHMODE_ASSOC);
  3766 +
  3767 + $i = 0;
  3768 +
  3769 + foreach ($res as $row)
5588 3770 {
5589   - $this->tpl->assign ("tpl", 'catalogs_tmp_products.tpl');
  3771 + $count = $this->db->getOne ("
  3772 + select count(*)
  3773 + from catalogs_modifications
  3774 + where product_id=? and active>0", array (
  3775 + $row['id']
  3776 + )
  3777 + );
  3778 +
  3779 + $this->db->autoExecute ("catalogs_products", array (
  3780 + 'count_modifications' => $count
  3781 + ), DB_AUTOQUERY_UPDATE, "id='" . $row['id'] . "'");
  3782 +
  3783 + $i ++;
5590 3784 }
  3785 +}
  3786 +
  3787 + function config_update($id,$value){
  3788 + $this->db->autoExecute("catalogs_config",array('value'=>$value),DB_AUTOQUERY_UPDATE,"id='".$id."'");
  3789 + }
  3790 +
  3791 + function view_config_value($id){
  3792 + $r = $this->db->getOne("select value from catalogs_config where id=?",$id);
  3793 + $this->tpl->assign("config",$r);
  3794 + return $r;
  3795 + }
  3796 +
  3797 + function addViewProduct($product_id){
  3798 + $i = 0;
  3799 + foreach($_SESSION['view_product'] as $id){
  3800 + if($product_id==$id)$i++;
  3801 + }
  3802 + if($i==0)$_SESSION['view_product'][] = $product_id;
  3803 + }
  3804 +
  3805 + function viewUserProducts($limit = "all"){ //unset($_SESSION['view_product']);
  3806 + if(isset($_SESSION['view_product']) && count($_SESSION['view_product'])>0){
  3807 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3808 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3809 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3810 + WHERE catalogs_products.id IN (".implode(",",$_SESSION['view_product']).") ";
  3811 + if($limit != "all")$sql .= "LIMIT ".$limit;
  3812 + $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
  3813 + $this->tpl->assign("products_view",$res);
  3814 + }
  3815 + }
  3816 +
  3817 + function viewSimilarProducts($product_id,$brend,$rubric_id,$mods){
  3818 + IF($brend == 'Dakine'){
  3819 + $rub_arr = array(14071,14069,14070,14072);
  3820 + unset($rub_arr[array_search('rubric_id', $rub_arr)]);
  3821 +
  3822 + if(count($mods)>1){
  3823 + $r = array();
  3824 + foreach($mods as $key=>$mod){
  3825 + $r[$key]['color'] = $mod['color'];
  3826 + $row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
  3827 + $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3828 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3829 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3830 + LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
  3831 + WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cine<? and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
  3832 + $r[$key]["products_similar_prev"] = $this->db->getAll($sql,array($row['cine'],$brend,$mod['color']),DB_FETCHMODE_ASSOC);
  3833 +
  3834 +
  3835 + $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3836 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3837 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3838 + LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
  3839 + WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
  3840 + $r[$key]["products_similar_next"] = $this->db->getAll($sql,array($row['cine'],$brend,$mod['color']),DB_FETCHMODE_ASSOC);
  3841 +
  3842 +
  3843 + }
  3844 +//print_r($r);
  3845 +$this->tpl->assign("products_similar",$r);
  3846 + }
  3847 + else{
  3848 +
  3849 + $row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
  3850 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3851 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3852 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3853 + WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cine<? and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
  3854 + $res = $this->db->getAll($sql,array($row['cine'],$brend),DB_FETCHMODE_ASSOC);
  3855 + $this->tpl->assign("products_similar_prev",$res);
  3856 +
  3857 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3858 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3859 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3860 + WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
  3861 + $res = $this->db->getAll($sql,array($row['cine'],$brend),DB_FETCHMODE_ASSOC);
  3862 + $this->tpl->assign("products_similar_next",$res);
  3863 + }
  3864 + } else{
  3865 + $row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
  3866 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3867 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3868 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3869 + WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine<? Order by catalogs_products.cine DESC LIMIT 5";
  3870 + $res = $this->db->getAll($sql,array($row['rubric_id'],$row['cine']),DB_FETCHMODE_ASSOC);
  3871 + $this->tpl->assign("products_similar_prev",$res);
  3872 +
  3873 + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
  3874 + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
  3875 + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
  3876 + WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine>? Order by catalogs_products.cine DESC LIMIT 5";
  3877 + $res = $this->db->getAll($sql,array($row['rubric_id'],$row['cine']),DB_FETCHMODE_ASSOC);
  3878 + $this->tpl->assign("products_similar_next",$res);
  3879 + }
  3880 + }
  3881 +
  3882 + function displayCatalogsCurs(){
  3883 + $this->tpl->assign("tpl",'catalogs_curs.tpl');
  3884 + }
  3885 +
  3886 + function displayCatalogs(){
  3887 + $this->tpl->assign("tpl",'catalogs.tpl');
  3888 + }
  3889 +
  3890 + function displayProducts(){
  3891 + $this->tpl->assign("tpl",'catalogs_product-list.tpl');
  3892 + }
  3893 +
  3894 + function displayProductsTops(){
  3895 + $this->tpl->assign("tpl",'catalogs_products_tops.tpl');
  3896 + }
  3897 +
  3898 + function displayProductsHits(){
  3899 + $this->tpl->assign("tpl",'catalogs_products_hits.tpl');
  3900 + }
  3901 +
  3902 + function displayProductsHitsAll(){
  3903 + $this->tpl->assign("tpl",'catalogs_products_hits_all.tpl');
  3904 + }
  3905 +
  3906 + function displayBasket($count_products,$cine_products,$cine_products_discount,$discount){
  3907 + $this->tpl->assign("count_products",$count_products);
  3908 + $this->tpl->assign("cine_products",$cine_products);
  3909 + $this->tpl->assign("cine_products_discount",$cine_products_discount);
  3910 + $this->tpl->assign("discount",$discount);
  3911 + $this->tpl->display('basket.tpl');
  3912 + }
  3913 +
  3914 + function displayProduct(){
  3915 + $this->tpl->assign("tpl",'catalogs_product.tpl');
  3916 + }
  3917 +
  3918 + function displayProductBasket(){
  3919 + $this->tpl->assign("tpl",'catalogs_basket.tpl');
  3920 + }
  3921 +
  3922 + function displayBrends(){
  3923 + $this->tpl->assign("tpl",'catalogs_brends.tpl');
  3924 + }
  3925 +
  3926 + function displayBrend(){
  3927 + $this->tpl->assign("tpl",'catalogs_brend.tpl');
  3928 + }
  3929 +
  3930 + function displayCities(){
  3931 + $this->tpl->assign("tpl",'catalogs_cities.tpl');
  3932 + }
  3933 +
  3934 + function displayProductBasketSend(){
  3935 + $this->tpl->assign("tpl",'catalogs_basket_send.tpl');
  3936 + }
  3937 +
  3938 + function displayReg(){
  3939 + $this->tpl->assign("tpl",'catalogs_reg.tpl');
  3940 + }
  3941 +
  3942 + function displayEditUser(){
  3943 + $this->tpl->assign("tpl",'catalogs_user_edit.tpl');
  3944 + }
  3945 +
  3946 + function displayNoPsw(){
  3947 + $this->tpl->assign("tpl",'catalogs_nopsw.tpl');
  3948 + }
  3949 +
  3950 + function displayOrders(){
  3951 + $this->tpl->assign("tpl",'catalogs_orders.tpl');
  3952 + }
  3953 +
  3954 + function displayOrder(){
  3955 + $this->tpl->assign("tpl",'catalogs_order.tpl');
  3956 + }
  3957 +
  3958 + function displayUsers(){
  3959 + $this->tpl->assign("tpl",'catalogs_users.tpl');
  3960 + }
  3961 +
  3962 + function displayUser(){
  3963 + $this->tpl->assign("tpl",'catalogs_user.tpl');
  3964 + }
  3965 +
  3966 + function displayFilters(){
  3967 + $this->tpl->assign("tpl",'catalogs_filters.tpl');
  3968 + }
  3969 +
  3970 + function displayFilters2(){
  3971 + $this->tpl->assign("tpl",'catalogs_filters2.tpl');
  3972 + }
  3973 +
  3974 + function displayYears(){
  3975 + $this->tpl->assign("tpl",'catalogs_years.tpl');
  3976 + }
  3977 +
  3978 + function displayWinProducts(){
  3979 + $this->tpl->display('catalogs_win_products.tpl');
  3980 + }
  3981 +
  3982 + function displayModifications(){
  3983 + $this->tpl->assign("tpl",'catalogs_modifications.tpl');
  3984 + }
  3985 +
  3986 + function displayImport(){
  3987 + $this->tpl->assign("tpl",'catalogs_import.tpl');
  3988 + }
  3989 +
  3990 + function displayImportCine(){
  3991 + $this->tpl->assign("tpl",'catalogs_import_cine.tpl');
  3992 + }
  3993 +
  3994 + function displayAkcii(){
  3995 + $this->tpl->assign("tpl",'catalogs_akcii.tpl');
  3996 + }
  3997 +
  3998 + function displayCompare(){
  3999 + $this->tpl->assign("tpl",'catalogs_compare.tpl');
  4000 + }
  4001 +
  4002 + function displayTmpProducts(){
  4003 + $this->tpl->assign("tpl",'catalogs_tmp_products.tpl');
  4004 + }
  4005 +
5591 4006 }
5592 4007 \ No newline at end of file
... ...