From 7a508b626927c3f92125c618487b4ec40eea7038 Mon Sep 17 00:00:00 2001 From: andryeyev Date: Wed, 23 Dec 2015 12:39:17 +0200 Subject: [PATCH] + попытка исправить фильтры (отложили на будущее) --- libs/catalogs.class.php | 8580 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 5048 insertions(+), 3532 deletions(-) diff --git a/libs/catalogs.class.php b/libs/catalogs.class.php index f2b827d..1dd5e84 100644 --- a/libs/catalogs.class.php +++ b/libs/catalogs.class.php @@ -1,168 +1,235 @@ db = &$db; - $this->tpl = &$tpl; - $this->error = &$error; - $this->cache = &$cache; - } - - - function trim(&$data){ - foreach($data as $key=>$value){ - if(is_array($value))$this->trim($value); - else $data[$key] = stripslashes(trim($value)); - } - } - - - function valid($data,$upload = null){ - - if(isset($data['name'])){ - if( !preg_match("/.{1,100}/i",$data['name']) ) $this->error[] = " ."; - } - - if(isset($data['about_min'])){ - if( !preg_match("/.+/is",$data['about_min']) ) $this->error[] = " ."; - } - /* - if(isset($data['text'])){ - if( !preg_match("/.+/is",$data['text']) ) $this->error[] = " ."; - } */ -/* - if(isset($data['cine'])){ - if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = " , ."; - } */ - - if(isset($upload['pic']['name']) && $upload['pic']['tmp_name']){ - $type = substr(strrchr($upload['pic']['name'],"."),1); - if( !preg_match("/^(jpeg|jpg|gif|png|bmp)$/i",$type) ) $this->error[] = " , jpg,png,gif."; - } - - if(isset($upload['file']['name'])){ - if( !preg_match("/\.csv$/i",$upload['file']['name']) ) $this->error[] = " CSV , csv."; - } - +class Catalogs +{ + var $db = null; + var $tpl = null; + var $error = null; + var $cache = null; + var $photo_id = null; + + function Catalogs (&$db, &$tpl, &$error, &$cache) + { + $this->db = &$db; + $this->tpl = &$tpl; + $this->error = &$error; + $this->cache = &$cache; + } + + function trim (&$data) + { + foreach ($data as $key => $value) + { + if (is_array ($value)) + $this->trim ($value); + else + $data[$key] = stripslashes (trim ($value)); + } + } + + function valid ($data, $upload = null) + { + if (isset ($data['name'])) + { + if (! preg_match ("/.{1,100}/i", $data['name'])) + $this->error[] = " ."; + } + + if (isset ($data['about_min'])) + { + if (! preg_match ("/.+/is", $data['about_min'])) + $this->error[] = " ."; + } + /* + * if(isset($data['text'])){ + * if( !preg_match("/.+/is",$data['text']) ) $this->error[] = " ."; + * } + */ + /* + * if(isset($data['cine'])){ + * if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = " , ."; + * } + */ + + if (isset ($upload['pic']['name']) && $upload['pic']['tmp_name']) + { + $type = substr (strrchr ($upload['pic']['name'], "."), 1); + if (! preg_match ("/^(jpeg|jpg|gif|png|bmp)$/i", $type)) + $this->error[] = " , jpg,png,gif."; + } + + if (isset ($upload['file']['name'])) + { + if (! preg_match ("/\.csv$/i", $upload['file']['name'])) + $this->error[] = " CSV , csv."; + } + + if (isset ($data['order_name'])) + { + if (! preg_match ("/.{1,100}/i", $data['order_name'])) + $this->error[] = " ( 100 )."; + } + + if (isset ($data['order_adress'])) + { + if (! preg_match ("/.{1,200}/i", $data['order_adress'])) + $this->error[] = " ( 200 )."; + } + + if (isset ($data['order_phone2']) && strlen ($data['order_phone2']) > 0) + { + if (! preg_match ("/.{1,20}/i", $data['order_phone2'])) + $this->error[] = " ( 70 )."; + } + + if (isset ($data['order_phone'])) + { + if (trim ($data['order_phone']) == "") + $this->error[] = " (: (0XX) XXX-XXXX)."; + if (strlen (trim ($data['order_phone'])) < 5) + $this->error[] = " (: (0XX) XXX-XXXX)."; + } + + if (isset ($data['delivery']) && $data['delivery'] == 0) + { + $this->error[] = " ."; + } + + if (isset ($data['user_name'])) + { + if (! preg_match ("/.{1,100}/i", $data['user_name'])) + $this->error[] = " ( 100 )."; + } + + if (isset ($data['order_city'])) + { + if (! preg_match ("/.{1,100}/i", $data['order_city'])) + $this->error[] = " ( 100 )."; + } + + if (isset ($data['user_email'])) + { + if (! preg_match ("/.{1,80}/i", $data['user_email'])) + $this->error[] = " e-mail ( 80 )."; + } + + if (isset ($data['user_login'])) + { + if (! preg_match ("/.{1,100}/i", $data['user_login'])) + $this->error[] = " ( 100 )."; + elseif ($this->isLoginUser ($data['user_login'])) + $this->error[] = " !"; + } + + if (isset ($data['you_login'])) + { + if (! $this->isLoginUser ($data['you_login'])) + $this->error[] = " !"; + } + + if (isset ($data['user_psw'])) + { + if (! preg_match ("/.{1,100}/i", $data['user_psw'])) + $this->error[] = " ( 100 )."; + } + + return (count ($this->error)) ? true : false; + } - if(isset($data['order_name'])){ - if( !preg_match("/.{1,100}/i",$data['order_name']) ) $this->error[] = " ( 100 )."; - } - - if(isset($data['order_adress'])){ - if( !preg_match("/.{1,200}/i",$data['order_adress']) ) $this->error[] = " ( 200 )."; - } - - if(isset($data['order_phone2'])&& strlen($data['order_phone2'])>0){ - if( !preg_match("/.{1,20}/i",$data['order_phone2']) ) $this->error[] = " ( 70 )."; - } + function deleteRubric ($id, $field = "id") + { + $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?"; + $res = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + foreach ($res as $row) + { + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}"); + $sql = "delete from catalogs_rubrics where id=?"; + $this->db->query ($sql, array ( + $row['id'] + )); + $this->deleteFiltersRubric_id ($row['id']); + $this->deleteFiltersRubric_id2 ($row['id']); + $this->deleteYearsRubric_id ($row['id']); + $this->deleteProductsRubric ($row['id']); + $this->deleteRubric ($row['id'], "parent_id"); + } + } - if(isset($data['order_phone'])){ -if( trim($data['order_phone']) == "" ) $this->error[] = " (: (0XX) XXX-XXXX)."; -if( strlen(trim($data['order_phone']))<5 ) $this->error[] = " (: (0XX) XXX-XXXX)."; - } - - if(isset($data['delivery']) && $data['delivery']==0){ - $this->error[] = " ."; - } - - if(isset($data['user_name'])){ - if( !preg_match("/.{1,100}/i",$data['user_name']) ) $this->error[] = " ( 100 )."; - } - - if(isset($data['order_city'])){ - if( !preg_match("/.{1,100}/i",$data['order_city']) ) $this->error[] = " ( 100 )."; - } - - if(isset($data['user_email'])){ - if( !preg_match("/.{1,80}/i",$data['user_email']) ) $this->error[] = " e-mail ( 80 )."; - } - - if(isset($data['user_login'])){ - if( !preg_match("/.{1,100}/i",$data['user_login']) ) $this->error[] = " ( 100 )."; - elseif( $this->isLoginUser($data['user_login']) ) $this->error[] = " !"; - } - - if(isset($data['you_login'])){ - if( !$this->isLoginUser($data['you_login']) ) $this->error[] = " !"; - } - - if(isset($data['user_psw'])){ - if( !preg_match("/.{1,100}/i",$data['user_psw']) ) $this->error[] = " ( 100 )."; - } + function deleteProductPics ($id, $pics = array('pic_big','pic','pic2')) + { + $sql = "select pic_big,pic,pic2 from catalogs_products where id=?"; + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}"); + if (in_array ('pic', $pics)) + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}"); + if (in_array ('pic2', $pics)) + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/2/{$row['pic2']}"); + } - return ( count($this->error) ) ? true : false; - } - - function deleteRubric($id,$field="id"){ - $sql = "select pic,id,parent_id from catalogs_rubrics where $field=?"; - $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - foreach($res as $row){ - @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}"); - $sql = "delete from catalogs_rubrics where id=?"; - $this->db->query($sql,array($row['id'])); - $this->deleteFiltersRubric_id($row['id']); - $this->deleteFiltersRubric_id2($row['id']); - $this->deleteYearsRubric_id($row['id']); - $this->deleteProductsRubric($row['id']); - $this->deleteRubric($row['id'],"parent_id"); - } - } - - function deleteProductPics($id,$pics = array('pic_big','pic','pic2')){ - $sql = "select pic_big,pic,pic2 from catalogs_products where id=?"; - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}"); - if(in_array('pic',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}"); - if(in_array('pic2',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/2/{$row['pic2']}"); - } - - function deleteProduct($id){ - $this->deleteProductPics($id); - $sql = "delete from catalogs_products where id=?"; - $this->db->query($sql,array($id)); - $this->delete_keysProductsFilters($id); - $this->delete_keysProductsFilters2($id); - $this->delete_keysProductsAkcii($id); - $this->delete_keysProductsYears($id); - $this->delete_keysProductsCities($id); - $this->deleteProductModifications($id); - } - - function deleteProductsRubric($id){ - $res = $this->db->getAll("select id from catalogs_products where rubric_id=?",array($id),DB_FETCHMODE_ASSOC); - foreach($res as $row){ - $this->deleteProduct($row['id']); - $this->deleteGalleryProduct($row['id']); - } - } + function deleteProduct ($id) + { + $this->deleteProductPics ($id); + $sql = "delete from catalogs_products where id=?"; + $this->db->query ($sql, array ( + $id + )); + $this->delete_keysProductsFilters ($id); + $this->delete_keysProductsFilters2 ($id); + $this->delete_keysProductsAkcii ($id); + $this->delete_keysProductsYears ($id); + $this->delete_keysProductsCities ($id); + $this->deleteProductModifications ($id); + } + function deleteProductsRubric ($id) + { + $res = $this->db->getAll ("select id from catalogs_products where rubric_id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + foreach ($res as $row) + { + $this->deleteProduct ($row['id']); + $this->deleteGalleryProduct ($row['id']); + } + } - function PhotosCheck($id_s,$check_s = array()){ - $sql = "UPDATE gallery SET active = ? WHERE id =?"; + function PhotosCheck ($id_s, $check_s = array()) + { + $sql = "UPDATE gallery SET active = ? WHERE id =?"; + + foreach ($id_s as $id) + { + $this->db->query ($sql, array ( + 0, + $id + )); + } + + if (count ($check_s)) + { + foreach ($check_s as $id) + { + $this->db->query ($sql, array ( + 1, + $id + )); + } + } + } - foreach($id_s as $id){ - $this->db->query($sql,array(0,$id)); - } - if(count($check_s)){ - foreach($check_s as $id){ - $this->db->query($sql,array(1,$id)); - } - } - } - - function viewRubrics($id = 0,$parent_id = 0){ // print $parent_id."
"; - global $rubrics; - //if(!$this->cache->cacheLife("cache_sql_rubrics")){ - - //$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"; - $sql = " + function viewRubrics ($id = 0, $parent_id = 0) + { // print $parent_id."
"; + global $rubrics; + // if(!$this->cache->cacheLife("cache_sql_rubrics")){ + + // $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"; + $sql = " select a.name, a.name_ukr, @@ -186,33 +253,45 @@ if( strlen(trim($data['order_phone']))<5 ) $this->error[] = " group by a.id order by a.sort asc "; - -$res = $this->db->query($sql,array($id)); - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)){ - $rubrics[] = $row; //print $row['id']."
"; + + $res = $this->db->query ($sql, array ( + $id + )); - if(in_array($row['id'],$this->getParentIdRubric($parent_id))){$this->viewRubrics($row['id']);} - // if($row['level']==0){$this->viewRubrics($row['id']);} - } + while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC)) + { + $rubrics[] = $row; // print $row['id']."
"; + + if (in_array ($row['id'], $this->getParentIdRubric ($parent_id))) + { + $this->viewRubrics ($row['id']); + } + // if($row['level']==0){$this->viewRubrics($row['id']);} + } // $this->cache->cacheSave($rubrics,130); - //}else $count = $this->cache->sql_result; - $this->tpl->assign("rubrics",$rubrics); - } - - function getParentIdRubric($id){ - //$ids = array(); - global $ids; - if(!count($ids))$ids = array(); - while($id>0){ - $row = $this->db->getRow('select id,parent_id from catalogs_rubrics where id=?',array($id),DB_FETCHMODE_ASSOC); - //if(isset($row['id'])) - $ids[] = $row['id']; - $id = $row['parent_id']; - } //print_r($ids); - // sort($ids); - return $ids; - } - + // }else $count = $this->cache->sql_result; + $this->tpl->assign ("rubrics", $rubrics); + } + + function getParentIdRubric ($id) + { + // $ids = array(); + global $ids; + if (! count ($ids)) + $ids = array (); + while ($id > 0) + { + $row = $this->db->getRow ('select id,parent_id from catalogs_rubrics where id=?', array ( + $id + ), DB_FETCHMODE_ASSOC); + // if(isset($row['id'])) + $ids[] = $row['id']; + $id = $row['parent_id']; + } // print_r($ids); + // sort($ids); + return $ids; + } + function viewRubricsAll ($id = 0) { global $rubrics; @@ -234,24 +313,24 @@ $res = $this->db->query($sql,array($id)); WHERE parent_id=? ORDER BY sort asc "; - $res = $this->db->query($sql,array($id)); - while ($res->fetchInto($row,DB_FETCHMODE_ASSOC)) + $res = $this->db->query ($sql, array ( + $id + )); + while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC)) { $rubrics[] = $row; - $this->viewRubricsAll($row['id']); + $this->viewRubricsAll ($row['id']); } - - $this->tpl->assign("rubrics",$rubrics); + + $this->tpl->assign ("rubrics", $rubrics); } - - function viewRubrics_begin ($item = 'parents',$lang = 'ru') + function viewRubrics_begin ($item = 'parents', $lang = 'ru') { - //if(!$this->cache->cacheLife("cache_sql_rubrics_$item"."_".$lang)){ - + // if(!$this->cache->cacheLife("cache_sql_rubrics_$item"."_".$lang)){ $sql = " SELECT - a.name".(($lang=='ukr')?'_ukr':'')." as name, + a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name, a.id, a.parent_id, a.level, @@ -274,15 +353,17 @@ $res = $this->db->query($sql,array($id)); ORDER BY a.sort asc "; - $row = $this->db->getAll($sql, array (0), DB_FETCHMODE_ASSOC); - + $row = $this->db->getAll ($sql, array ( + 0 + ), DB_FETCHMODE_ASSOC); + foreach ($row as $key => $value) { if ($item == 'parents') { - $row[$key]['parents'] = $this->db->getAll(" + $row[$key]['parents'] = $this->db->getAll (" SELECT - a.name".(($lang=='ukr')?'_ukr':'')." as name, + a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name, a.id, a.parent_id, a.level, @@ -296,11 +377,13 @@ $res = $this->db->query($sql,array($id)); FROM catalogs_rubrics a WHERE parent_id=? ORDER BY sort asc - ", array($value['id']), DB_FETCHMODE_ASSOC); + ", array ( + $value['id'] + ), DB_FETCHMODE_ASSOC); } else if ($item == 'brends') { - $row[$key]['brends'] = $this->db->getAll(" + $row[$key]['brends'] = $this->db->getAll (" SELECT * FROM catalogs_brends WHERE rubric_id in ( @@ -309,58 +392,58 @@ $res = $this->db->query($sql,array($id)); WHERE parent_id=? or id=? ) GROUP BY name - ",array ($value['id'], $value['id']), DB_FETCHMODE_ASSOC); + ", array ( + $value['id'], + $value['id'] + ), DB_FETCHMODE_ASSOC); } } - - $this->tpl->assign("catalogs_rubrics_begin", $row); + + $this->tpl->assign ("catalogs_rubrics_begin", $row); } // ==== CACHE viewRubrics begin ==== - function getFilenameCacheVRB ($item = 'parents', $lang = 'ru') { - return $_SERVER['DOCUMENT_ROOT'].'/cache/menu/menu-'.$item.'-'.$lang.'.php'; + return $_SERVER['DOCUMENT_ROOT'] . '/cache/menu/menu-' . $item . '-' . $lang . '.php'; } - + function isFreshCacheVRB ($item = 'parents', $lang = 'ru') { $filename = $this->getFilenameCacheVRB ($item, $lang); $time = 60 * 60 * 24; - - if (is_file ($filename) && (filemtime ($filename) + $time) > time()) + + if (is_file ($filename) && (filemtime ($filename) + $time) > time ()) { return true; } return false; } - + function saveCacheVRB ($item = 'parents', $lang = 'ru') - { - $filename = $this->getFilenameCacheVRB ($item, $lang); - + { + $filename = $this->getFilenameCacheVRB ($item, $lang); + ob_start (); - var_export ($this->tpl->get_template_vars('catalogs_rubrics_begin')); - // $row - "catalogs_rubrics_begin", $row - file_put_contents ($filename, 'tpl->get_template_vars ('catalogs_rubrics_begin')); + // $row - "catalogs_rubrics_begin", $row + file_put_contents ($filename, 'getFilenameCacheVRB ($item, $lang); if (! isset ($this->zlofound)) - { - $this->tpl->assign("catalogs_rubrics_begin", $row); + { + $this->tpl->assign ("catalogs_rubrics_begin", $row); $this->zlofound = true; unset ($row); } - } - - // ==== ==== - - function viewRubrics_parent($parent_id = 0) + } + + function viewRubrics_parent ($parent_id = 0) { $sql = " SELECT @@ -381,14 +464,16 @@ $res = $this->db->query($sql,array($id)); ORDER BY sort asc "; - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); - $this->tpl->assign("catalogs_rubrics_parent",$row); + $row = $this->db->getAll ($sql, array ( + $parent_id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ("catalogs_rubrics_parent", $row); } - + function viewRubrics_parent2 ($rub_id, $lang = 'ru') { - $parent_id = $this->getRubricParent($rub_id); - + $parent_id = $this->getRubricParent ($rub_id); + if ($parent_id == 0) { $parent_id = $rub_id; @@ -396,7 +481,7 @@ $res = $this->db->query($sql,array($id)); $sql = " SELECT - a.name".(($lang=='ukr')?'_ukr':'')." as name, + a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name, a.id, a.parent_id, a.level, @@ -412,437 +497,563 @@ $res = $this->db->query($sql,array($id)); ORDER BY sort asc "; - $row = $this->db->getAll($sql,array($parent_id),DB_FETCHMODE_ASSOC); - $this->tpl->assign("catalogs_rubrics_parent2",$row); + $row = $this->db->getAll ($sql, array ( + $parent_id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ("catalogs_rubrics_parent2", $row); } - - function viewRubricOne($id,&$row,$lang = 'ru'){ - if($lang=='ukr') - $sql = "select *,name_ukr as name,name_h1_ukr as name_h1,top_text_ukr as top_text,seo_text_ukr as seo_text, + + function viewRubricOne ($id, &$row, $lang = 'ru') + { + if ($lang == 'ukr') + $sql = "select *,name_ukr as name,name_h1_ukr as name_h1,top_text_ukr as top_text,seo_text_ukr as seo_text, meta_title_ukr as meta_title,meta_description_ukr as meta_description,meta_keywords_ukr as meta_keywords,meta_about_ukr as meta_about, filter2_ukr as filter2, filter_ukr as filter, list_name_ukr as list_name from catalogs_rubrics where id=?"; - else - $sql = "select * from catalogs_rubrics where id=?"; - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('rubric',$row); - } + else + $sql = "select * from catalogs_rubrics where id=?"; + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('rubric', $row); + } - function getRubricName($id,$lang = 'ru'){ - $sql = "select name".($lang=='ukr'?'_ukr':'')." from catalogs_rubrics where id=?"; - return $this->db->getOne($sql,array($id)); - } + function getRubricName ($id, $lang = 'ru') + { + $sql = "select name" . ($lang == 'ukr' ? '_ukr' : '') . " from catalogs_rubrics where id=?"; + return $this->db->getOne ($sql, array ( + $id + )); + } - function getRubricParent($id){ - $sql = "select parent_id from catalogs_rubrics where id=?"; - return $this->db->getOne($sql,array($id)); - } + function getRubricParent ($id) + { + $sql = "select parent_id from catalogs_rubrics where id=?"; + return $this->db->getOne ($sql, array ( + $id + )); + } - function activeRubricTop($id,$top){ - $table_name = "catalogs_rubrics"; - $fields_values = array('top'=>$top); - $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,"id=$id"); - } - - function SaveRubric($data,$upload){ - $table_name = "catalogs_rubrics"; - -if(trim($data['translit']) == '') $data['translit'] = translit($data['name']); - - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $parent_id = (isset($data['parent_id']) ? $data['parent_id'] : 0); - $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']); - -if(isset($data['literal']))$fields_values['literal'] = 1; -else $fields_values['literal'] = 0; - -if(isset($data['if_filter_mod']))$fields_values['if_filter_mod'] = 1; -else $fields_values['if_filter_mod'] = 0; - -if(isset($data['is_usd']))$fields_values['is_usd'] = 1; -else $fields_values['is_usd'] = 0; - -if(isset($data['is_xml']))$fields_values['is_xml'] = 1; -else $fields_values['is_xml'] = 0; - -if(isset($data['is_xml2']))$fields_values['is_xml2'] = 1; -else $fields_values['is_xml2'] = 0; + function activeRubricTop ($id, $top) + { + $table_name = "catalogs_rubrics"; + $fields_values = array ( + 'top' => $top + ); + $this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, "id=$id"); + } -if(isset($data['is_width']))$fields_values['is_width'] = 1; -else $fields_values['is_width'] = 0; - /* - if($upload['pic']['tmp_name']){ - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/")); - } */ - - if($upload['pic']['tmp_name']){ - if($data['update_id']>0)$this->deletePicRubric($data['update_id']); - $uploadfile = "./uploaded/pic/catalogs/rubrics/"; - $type = substr(strrchr($upload['pic']['name'],"."),1); - $uploadname = mktime() . "." . $type; - if (!move_uploaded_file($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))print" !"; - $fields_values['pic'] = $uploadname; - } - //print_r($fields_values);exit; - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); - } - - function deletePicRubric($id){ - $sql = "select pic from catalogs_rubrics where id=?"; - $rub = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - @unlink("./uploaded/pic/catalogs/rubrics/{$rub['pic']}"); - } - - function getLevelRubric($id){ - $level = $this->db->getOne("select level from catalogs_rubrics where id=?",array($id)); - return ($level==null)? -1 : $level; - } - - function saveUser($data){ - $table_name = "catalogs_users"; - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $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()); - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); - } - - function updateUser($data){ - $table_name = "catalogs_users"; - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; - $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']); - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); - } - - function updateUserID($data,$id){ - $table_name = "catalogs_users"; - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; - $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']); - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$id}"); - } - - function deleteUser($id){ - $this->db->query("delete from catalogs_users where id=?",array($id)); - $res_order_id = $this->db->getRow("select id from catalogs_orders where user_id=?",array($id),DB_FETCHMODE_ASSOC); - if(count($res_order_id)){ - foreach($res_order_id as $_id){ - $this->db->query("delete from catalogs_orders where id=?",array($_id)); - $this->db->query("delete from catalogs_orders_products where order_id=?",array($_id)); - }} - } - - function isLoginUser($login){ - return $this->db->getOne("select id from catalogs_users where login=?",array($login)); - } - - function sendLoginInfo($login){ - $user = $this->db->getRow("select * from catalogs_users where login=?",array($login),DB_FETCHMODE_ASSOC); - $mail = new PHPMailer(); - $mail->CharSet = "windows-1251"; - $mail->From = "shop@eltrade.com.ua"; - $mail->FromName = "shop@eltrade.com.ua"; - $mail->AddAddress($user['email'], $user['name']); - $mail->Subject = " "; - $msg = ""; - $msg .= ": ".$user['name']; - $msg .= "
"; - $msg .= " : ".$user['login']; - $msg .= "
"; - $msg .= " : ".$user['psw']; - $msg .= "
"; - $msg .= " , shop@eltrade.com.ua"; + function SaveRubric ($data, $upload) + { + $table_name = "catalogs_rubrics"; + + if (trim ($data['translit']) == '') + $data['translit'] = translit ($data['name']); + + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $parent_id = (isset ($data['parent_id']) ? $data['parent_id'] : 0); + $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'] + ); + + if (isset ($data['literal'])) + $fields_values['literal'] = 1; + else + $fields_values['literal'] = 0; + + if (isset ($data['if_filter_mod'])) + $fields_values['if_filter_mod'] = 1; + else + $fields_values['if_filter_mod'] = 0; + + if (isset ($data['is_usd'])) + $fields_values['is_usd'] = 1; + else + $fields_values['is_usd'] = 0; + + if (isset ($data['is_xml'])) + $fields_values['is_xml'] = 1; + else + $fields_values['is_xml'] = 0; + + if (isset ($data['is_xml2'])) + $fields_values['is_xml2'] = 1; + else + $fields_values['is_xml2'] = 0; + + if (isset ($data['is_width'])) + $fields_values['is_width'] = 1; + else + $fields_values['is_width'] = 0; + /* + * if($upload['pic']['tmp_name']){ + * $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/")); + * } + */ + + if ($upload['pic']['tmp_name']) + { + if ($data['update_id'] > 0) + $this->deletePicRubric ($data['update_id']); + $uploadfile = "./uploaded/pic/catalogs/rubrics/"; + $type = substr (strrchr ($upload['pic']['name'], "."), 1); + $uploadname = mktime () . "." . $type; + if (! move_uploaded_file ($_FILES['pic']['tmp_name'], $uploadfile . $uploadname)) + print " !"; + $fields_values['pic'] = $uploadname; + } + // print_r($fields_values);exit; + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}"); + } - $mail->MsgHTML($msg); + function deletePicRubric ($id) + { + $sql = "select pic from catalogs_rubrics where id=?"; + $rub = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + @unlink ("./uploaded/pic/catalogs/rubrics/{$rub['pic']}"); + } - if(!$mail->Send()){echo "There has been a mail error sending to
";return false;} - $mail->ClearAddresses(); - $mail->ClearAttachments(); - } - - function isUser($login,$psw){ - $row = $this->db->getRow("select * from catalogs_users where login=? AND psw=?",array($login,$psw),DB_FETCHMODE_ASSOC); - //print $login .' - '.$psw; - $this->tpl->assign('user_service',$row); - return $row['id']; - } - - function viewUser($id){ - $sql = "select * from catalogs_users where id=?"; - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('user',$row); - } - - function getUserDiscount($id){ - return $this->db->getOne("select discount from catalogs_users where id=?",array($id)); - } - - function viewUsers(){ - $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders -FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id -GROUP BY catalogs_users.id -ORDER BY catalogs_users.mktime DESC"; + function getLevelRubric ($id) + { + $level = $this->db->getOne ("select level from catalogs_rubrics where id=?", array ( + $id + )); + return ($level == null) ? - 1 : $level; + } - $pagerOptions = Array( - 'mode' => 'Sliding', - 'delta' => 6, - 'perPage' => 10, - 'linkClass'=>"link_class", - 'curPageLinkClassName'=>"link_class_active", - 'spacesBeforeSeparator' => 1, - 'spacesAfterSeparator' => 1 - ); - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); + function saveUser ($data) + { + $table_name = "catalogs_users"; + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $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 () + ); + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}"); + } - $this->tpl->assign('usersData', $res); - } - -// ====================== -// ==== MODIFICATION ==== -// ====================== - -function viewModifications ($product_id) -{ - $sql = "select * from catalogs_modifications where product_id=? order by id desc"; - $row = $this->db->getAll ($sql, array ( - $product_id - ), DB_FETCHMODE_ASSOC); - if (trim ($_REQUEST['test2']) == '1') - print_r ($row); - $this->tpl->assign ('modifications', $row); -} - -function viewModificationsProduct ($product_id) -{ - $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc"; - // $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"; - $row = $this->db->getAll ($sql, array ( - $product_id - ), DB_FETCHMODE_ASSOC); - - for ($i = 0; $i < count ($row); $i ++) + function updateUser ($data) { - $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); - // if($row2['city_id']==25){ unset($row[$i]); } + $table_name = "catalogs_users"; + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $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'] + ); + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}"); } - $new_row = array (); - // if($_GET['test']=='18') print_r($row); - foreach ($row as $key => $value) + + function updateUserID ($data, $id) { - // $new_row[] = $value; + $table_name = "catalogs_users"; + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $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'] + ); + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$id}"); } - // if($_GET['test']=='18') print_r($new_row); - $this->tpl->assign ('modifications', $row); - return $row; -} -function viewModificationOne ($id) -{ - $sql = "select * from catalogs_modifications where id=?"; - $row = $this->db->getRow ($sql, array ( - $id - ), DB_FETCHMODE_ASSOC); - $this->tpl->assign ('modification', $row); - return $row; -} + function deleteUser ($id) + { + $this->db->query ("delete from catalogs_users where id=?", array ( + $id + )); + $res_order_id = $this->db->getRow ("select id from catalogs_orders where user_id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + if (count ($res_order_id)) + { + foreach ($res_order_id as $_id) + { + $this->db->query ("delete from catalogs_orders where id=?", array ( + $_id + )); + $this->db->query ("delete from catalogs_orders_products where order_id=?", array ( + $_id + )); + } + } + } -function getModificationProduct_id ($code) -{ - return $this->db->getOne ("select product_id from catalogs_modifications where code=?", array ( - $code - )); -} + function isLoginUser ($login) + { + return $this->db->getOne ("select id from catalogs_users where login=?", array ( + $login + )); + } -function getModification ($product_id, $code) -{ - return $this->db->getOne (" - SELECT id - FROM catalogs_modifications - WHERE product_id=? - AND code=?", array ( - $product_id, - $code - )); -} - -function SaveModification ($data, $upload) -{ - $table_name = "catalogs_modifications"; - $DB_AUTOQUERY = ($data ['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $fields_values = array ( - 'product_id' => $data ['product_id'], - 'code' => $data ['code'], - 'size' => $data ['size'], - 'color' => $data ['color'], - 'active' => $data ['active'] - ); - - if (isset ($data ['color2'])) + function sendLoginInfo ($login) { - $fields_values ['color2'] = $data ['color2']; + $user = $this->db->getRow ("select * from catalogs_users where login=?", array ( + $login + ), DB_FETCHMODE_ASSOC); + $mail = new PHPMailer (); + $mail->CharSet = "windows-1251"; + $mail->From = "shop@eltrade.com.ua"; + $mail->FromName = "shop@eltrade.com.ua"; + $mail->AddAddress ($user['email'], $user['name']); + $mail->Subject = " "; + $msg = ""; + $msg .= ": " . $user['name']; + $msg .= "
"; + $msg .= " : " . $user['login']; + $msg .= "
"; + $msg .= " : " . $user['psw']; + $msg .= "
"; + $msg .= " , shop@eltrade.com.ua"; + + $mail->MsgHTML ($msg); + + if (! $mail->Send ()) + { + echo "There has been a mail error sending to
"; + return false; + } + $mail->ClearAddresses (); + $mail->ClearAttachments (); } - if (isset ($data ['rost'])) + function isUser ($login, $psw) { - $fields_values ['rost'] = $data ['rost']; + $row = $this->db->getRow ("select * from catalogs_users where login=? AND psw=?", array ( + $login, + $psw + ), DB_FETCHMODE_ASSOC); + // print $login .' - '.$psw; + $this->tpl->assign ('user_service', $row); + return $row['id']; } - if (isset ($data ['delete_pic'])) + function viewUser ($id) { - if ($data ['update_id'] > 0) - { - $this->deleteModificationPics ($data ['update_id']); - } - - $fields_values ['pic'] = null; - $fields_values ['pic_big'] = null; + $sql = "select * from catalogs_users where id=?"; + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('user', $row); } - if ($upload ['pic'] ['tmp_name']) + function getUserDiscount ($id) { - if ($data ['update_id'] > 0) + return $this->db->getOne ("select discount from catalogs_users where id=?", array ( + $id + )); + } + + function viewUsers () + { + $sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders +FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id +GROUP BY catalogs_users.id +ORDER BY catalogs_users.mktime DESC"; + + $pagerOptions = Array ( + 'mode' => 'Sliding', + 'delta' => 6, + 'perPage' => 10, + 'linkClass' => "link_class", + 'curPageLinkClassName' => "link_class_active", + 'spacesBeforeSeparator' => 1, + 'spacesAfterSeparator' => 1 + ); + $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ()); + + $this->tpl->assign ('usersData', $res); + } + + // ====================== + // ==== MODIFICATION ==== + // ====================== + + function viewModifications ($product_id) + { + $sql = "select * from catalogs_modifications where product_id=? order by id desc"; + $row = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + if (trim ($_REQUEST['test2']) == '1') + print_r ($row); + $this->tpl->assign ('modifications', $row); + } + + function viewModificationsProduct ($product_id) + { + $sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc"; + // $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"; + $row = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + + for ($i = 0; $i < count ($row); $i ++) { - $delete_pics = (isset ($upload ['pic'] ['big']) && $upload ['pic'] ['big'] == true) ? array ( - 'pic' - ) : array ( - 'pic', - 'pic_big' - ); - - $this->deleteModificationPics ($data ['update_id'], $delete_pics); + $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); + // if($row2['city_id']==25){ unset($row[$i]); } } - - $fields_values ['pic'] = upload_ImageResize ($upload ['pic'], array ( - 'width' => "144", - 'height' => "144", - 'upload_path' => "./uploaded/pic/catalogs/modifications/" + $new_row = array (); + // if($_GET['test']=='18') print_r($row); + foreach ($row as $key => $value) + { + // $new_row[] = $value; + } + // if($_GET['test']=='18') print_r($new_row); + $this->tpl->assign ('modifications', $row); + return $row; + } + + function viewModificationOne ($id) + { + $sql = "select * from catalogs_modifications where id=?"; + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('modification', $row); + return $row; + } + + function getModificationProduct_id ($code) + { + return $this->db->getOne ("select product_id from catalogs_modifications where code=?", array ( + $code )); - - $fields_values ['pic_big'] = (isset ($upload ['pic'] ['big']) && $upload ['pic'] ['big'] == true) ? $upload ['pic'] ['name'] : upload_ImageResize ($upload ['pic'], array ( - 'width' => "1000", - 'height' => "1000", - 'upload_path' => "./uploaded/pic/catalogs/modifications/big/" + } + + function getModification ($product_id, $code) + { + return $this->db->getOne (" + SELECT id + FROM catalogs_modifications + WHERE product_id=? + AND code=?", array ( + $product_id, + $code )); } + + function SaveModification ($data, $upload) + { + $table_name = "catalogs_modifications"; + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $fields_values = array ( + 'product_id' => $data['product_id'], + 'code' => $data['code'], + 'size' => $data['size'], + 'color' => $data['color'], + 'active' => $data['active'] + ); - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='{$data['update_id']}'"); - return $id; -} - -function deleteModification ($id) -{ - $this->deleteModificationPics ($id); - $this->db->query ("delete from catalogs_modifications where id=?", array ( - $id - )); -} - -function deleteProductModifications ($product_id, $nopic = false) -{ - IF ($nopic == false) + if (isset ($data['color2'])) + { + $fields_values['color2'] = $data['color2']; + } + + if (isset ($data['rost'])) + { + $fields_values['rost'] = $data['rost']; + } + + if (isset ($data['delete_pic'])) + { + if ($data['update_id'] > 0) + { + $this->deleteModificationPics ($data['update_id']); + } + + $fields_values['pic'] = null; + $fields_values['pic_big'] = null; + } + + if ($upload['pic']['tmp_name']) + { + if ($data['update_id'] > 0) + { + $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array ( + 'pic' + ) : array ( + 'pic', + 'pic_big' + ); + + $this->deleteModificationPics ($data['update_id'], $delete_pics); + } + + $fields_values['pic'] = upload_ImageResize ($upload['pic'], array ( + 'width' => "144", + 'height' => "144", + 'upload_path' => "./uploaded/pic/catalogs/modifications/" + )); + + $fields_values['pic_big'] = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? $upload['pic']['name'] : upload_ImageResize ($upload['pic'], array ( + 'width' => "1000", + 'height' => "1000", + 'upload_path' => "./uploaded/pic/catalogs/modifications/big/" + )); + } + + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='{$data['update_id']}'"); + return $id; + } + + function deleteModification ($id) { - $sql = " + $this->deleteModificationPics ($id); + $this->db->query ("delete from catalogs_modifications where id=?", array ( + $id + )); + } + + function deleteProductModifications ($product_id, $nopic = false) + { + IF ($nopic == false) + { + $sql = " select * from catalogs_modifications where product_id=?"; - $res = $this->db->getAll ($sql, array ( + $res = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + + foreach ($res as $row) + { + $this->deleteModificationPics ($row['id']); + } + } + + $this->db->query (" + delete from catalogs_modifications + where product_id=?", array ( $product_id + )); + } + + function deleteModificationPics ($id, $pics = array('pic_big','pic')) + { + $sql = "select pic,pic_big from catalogs_modifications where id=?"; + + $row = $this->db->getRow ($sql, array ( + $id ), DB_FETCHMODE_ASSOC); - foreach ($res as $row) + if (in_array ('pic', $pics)) { - $this->deleteModificationPics ($row ['id']); + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}"); } + + // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); } - - $this->db->query (" - delete from catalogs_modifications - where product_id=?", array ( - $product_id - )); -} - -function deleteModificationPics ($id, $pics = array('pic_big','pic')) -{ - $sql = "select pic,pic_big from catalogs_modifications where id=?"; - $row = $this->db->getRow ($sql, array ( - $id - ), DB_FETCHMODE_ASSOC); - - if (in_array ('pic', $pics)) + // ================= + // ==== PRODUCT ==== + // ================= + + function ProductClick ($id) { - @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}"); + $this->db->query ("update catalogs_products set click=click+1 where id='$id'"); } - - // if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}"); -} - -// ================= -// ==== PRODUCT ==== -// ================= - - function ProductClick($id){ - $this->db->query("update catalogs_products set click=click+1 where id='$id'"); - } - -function SaveProduct ($data, $upload) -{ - $table_name = "catalogs_products"; - - if (trim (@$data['translit']) == "") - $data['translit'] = translit ($data['name']); - - $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $id = ($data['update_id'] > 0) ? $data['update_id'] : $this->db->nextId ('mySequence_' . $table_name); - $fields_values = array ( - 'id' => $id, - 'rubric_id' => $data['rubric_id'], - 'rubric_parent_id' => $this->getRubricParent ($data['rubric_id']), - 'brend_id' => $data['brend_id'], - 'name' => $data['name'], - 'about' => $data['about'], - 'text' => $data['text'], - 'update_text' => (int)$data['update_text'], - 'strnumber' => $data['strnumber'], - 'cine' => $data['cine'], - 'cine_last' => $data['cine_last'], - 'mktime' => mktime (), - 'meta_title' => $data['meta_title'], - 'meta_description' => $data['meta_description'], - 'meta_keywords' => $data['meta_keywords'], - 'meta_about' => $data['meta_about'], - 'active' => $data['active'], - 'translit' => $data['translit'] - ); - if (isset ($data['is_cost2'])) - $fields_values['is_cost2'] = 1; - else - $fields_values['is_cost2'] = 0; - if (isset ($data['cine2'])) - $fields_values['cine2'] = $data['cine2']; - if (isset ($data['params'])) - $this->saveProductParams ($id, $data['params']); - if (isset ($data['doc'])) - $fields_values['doc'] = $data['doc']; - if (isset ($data['update_text'])) - $fields_values['update_text'] = $data['update_text']; - if (isset ($data['video_code'])) - $fields_values['video_code'] = $data['video_code']; - if (isset ($data['akcii_id'])) - $fields_values['akcii_id'] = $data['akcii_id']; - - if (isset ($data['translit'])) - $fields_values['translit'] = $data['translit']; - - if ($upload['pic']['tmp_name']) - { - $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array ( - 'pic', - 'pic2' - ) : array ( - 'pic', - 'pic2', - 'pic_big' + + function SaveProduct ($data, $upload) + { + $table_name = "catalogs_products"; + + if (trim (@$data['translit']) == "") + $data['translit'] = translit ($data['name']); + + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $id = ($data['update_id'] > 0) ? $data['update_id'] : $this->db->nextId ('mySequence_' . $table_name); + $fields_values = array ( + 'id' => $id, + 'rubric_id' => $data['rubric_id'], + 'rubric_parent_id' => $this->getRubricParent ($data['rubric_id']), + 'brend_id' => $data['brend_id'], + 'name' => $data['name'], + 'about' => $data['about'], + 'text' => $data['text'], + 'update_text' => (int) $data['update_text'], + 'strnumber' => $data['strnumber'], + 'cine' => $data['cine'], + 'cine_last' => $data['cine_last'], + 'mktime' => mktime (), + 'meta_title' => $data['meta_title'], + 'meta_description' => $data['meta_description'], + 'meta_keywords' => $data['meta_keywords'], + 'meta_about' => $data['meta_about'], + 'active' => $data['active'], + 'translit' => $data['translit'] ); - $this->deleteProductPics ($id, $delete_pics); - $fields_values['pic'] = upload_ImageResize ($upload['pic'], array ( + if (isset ($data['is_cost2'])) + $fields_values['is_cost2'] = 1; + else + $fields_values['is_cost2'] = 0; + if (isset ($data['cine2'])) + $fields_values['cine2'] = $data['cine2']; + if (isset ($data['params'])) + $this->saveProductParams ($id, $data['params']); + if (isset ($data['doc'])) + $fields_values['doc'] = $data['doc']; + if (isset ($data['update_text'])) + $fields_values['update_text'] = $data['update_text']; + if (isset ($data['video_code'])) + $fields_values['video_code'] = $data['video_code']; + if (isset ($data['akcii_id'])) + $fields_values['akcii_id'] = $data['akcii_id']; + + if (isset ($data['translit'])) + $fields_values['translit'] = $data['translit']; + + if ($upload['pic']['tmp_name']) + { + $delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array ( + 'pic', + 'pic2' + ) : array ( + 'pic', + 'pic2', + 'pic_big' + ); + $this->deleteProductPics ($id, $delete_pics); + $fields_values['pic'] = upload_ImageResize ($upload['pic'], array ( 'width' => "144", 'height' => "144", 'upload_path' => "./uploaded/pic/catalogs/products/" @@ -857,288 +1068,676 @@ function SaveProduct ($data, $upload) 'height' => "1000", 'upload_path' => "./uploaded/pic/catalogs/products/big/" )); - } + } + + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='$id'"); + $this->save_keysProductsFilters ($id, $data); + $this->save_keysProductsFilters2 ($id, $data); + $this->save_keysProductsYears ($id, $data); + // $this->save_keysProductsCities($id,$data); + $this->save_keysProductsAkcii ($id, $data); + $this->save_keysProductsSex ($id, $data); - $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='$id'"); - $this->save_keysProductsFilters ($id, $data); - $this->save_keysProductsFilters2 ($id, $data); - $this->save_keysProductsYears ($id, $data); - // $this->save_keysProductsCities($id,$data); - $this->save_keysProductsAkcii ($id, $data); - $this->save_keysProductsSex ($id, $data); + return $id; + } - return $id; -} - - function save_keysProductsSex($id,$data){ - $this->delete_keysProductsSex($id); - if(!isset($data['sex']))return false; - $table_name = "catalogs_keys_products_sex"; - foreach($data['sex'] as $sex){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'sex'=>$sex,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsSex($id){ - $this->db->query("delete from catalogs_keys_products_sex where product_id=?",array($id)); - } - - function save_keysProductsFilters2($id,$data){ - $this->delete_keysProductsFilters2($id); - if(!isset($data['filter2']))return false; - $table_name = "catalogs_keys_products_filters2"; - foreach($data['filter2'] as $filter_id){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsFilters2($id){ - $this->db->query("delete from catalogs_keys_products_filters2 where product_id=?",array($id)); - } - - function save_keysProductsFilters($id,$data){ - $this->delete_keysProductsFilters($id); - if(!isset($data['filter']))return false; - $table_name = "catalogs_keys_products_filters"; - foreach($data['filter'] as $filter_id){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'filter_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsFilters($id){ - $this->db->query("delete from catalogs_keys_products_filters where product_id=?",array($id)); - } - - function save_keysProductsYears($id,$data){ - $this->delete_keysProductsYears($id); - if(!isset($data['years']))return false; - $table_name = "catalogs_keys_products_years"; - foreach($data['years'] as $filter_id){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'year_id'=>$filter_id,'rubric_id'=>$data['rubric_id']),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsYears($id){ - $this->db->query("delete from catalogs_keys_products_years where product_id=?",array($id)); - } - - function save_keysProductsCities($id,$data){ - $this->delete_keysProductsCities($id); - if(!isset($data['city']))return false; - $table_name = "catalogs_keys_products_cities"; - foreach($data['city'] as $city_id){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'city_id'=>$city_id),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsAkcii($id){ - $this->db->query("delete from catalogs_keys_products_akcii where product_id=?",array($id)); - } - - function save_keysProductsAkcii($id,$data){ - $this->delete_keysProductsAkcii($id); - if(!isset($data['akcii']))return false; - $table_name = "catalogs_keys_products_akcii"; - foreach($data['akcii'] as $rubric_id){ - $this->db->autoExecute($table_name,array('product_id'=>$id,'rubric_id'=>$rubric_id),DB_AUTOQUERY_INSERT); - } - } - - function delete_keysProductsCities($id){ - $this->db->query("delete from catalogs_keys_products_cities where product_id=?",array($id)); - } + function save_keysProductsSex ($id, $data) + { + $this->delete_keysProductsSex ($id); + if (! isset ($data['sex'])) + return false; + $table_name = "catalogs_keys_products_sex"; + foreach ($data['sex'] as $sex) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'sex' => $sex, + 'rubric_id' => $data['rubric_id'] + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsSex ($id) + { + $this->db->query ("delete from catalogs_keys_products_sex where product_id=?", array ( + $id + )); + } + + function save_keysProductsFilters2 ($id, $data) + { + $this->delete_keysProductsFilters2 ($id); + if (! isset ($data['filter2'])) + return false; + $table_name = "catalogs_keys_products_filters2"; + foreach ($data['filter2'] as $filter_id) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'filter_id' => $filter_id, + 'rubric_id' => $data['rubric_id'] + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsFilters2 ($id) + { + $this->db->query ("delete from catalogs_keys_products_filters2 where product_id=?", array ( + $id + )); + } + + function save_keysProductsFilters ($id, $data) + { + $this->delete_keysProductsFilters ($id); + if (! isset ($data['filter'])) + return false; + $table_name = "catalogs_keys_products_filters"; + foreach ($data['filter'] as $filter_id) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'filter_id' => $filter_id, + 'rubric_id' => $data['rubric_id'] + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsFilters ($id) + { + $this->db->query ("delete from catalogs_keys_products_filters where product_id=?", array ( + $id + )); + } + + function save_keysProductsYears ($id, $data) + { + $this->delete_keysProductsYears ($id); + if (! isset ($data['years'])) + return false; + $table_name = "catalogs_keys_products_years"; + foreach ($data['years'] as $filter_id) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'year_id' => $filter_id, + 'rubric_id' => $data['rubric_id'] + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsYears ($id) + { + $this->db->query ("delete from catalogs_keys_products_years where product_id=?", array ( + $id + )); + } + + function save_keysProductsCities ($id, $data) + { + $this->delete_keysProductsCities ($id); + if (! isset ($data['city'])) + return false; + $table_name = "catalogs_keys_products_cities"; + foreach ($data['city'] as $city_id) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'city_id' => $city_id + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsAkcii ($id) + { + $this->db->query ("delete from catalogs_keys_products_akcii where product_id=?", array ( + $id + )); + } + + function save_keysProductsAkcii ($id, $data) + { + $this->delete_keysProductsAkcii ($id); + if (! isset ($data['akcii'])) + return false; + $table_name = "catalogs_keys_products_akcii"; + foreach ($data['akcii'] as $rubric_id) + { + $this->db->autoExecute ($table_name, array ( + 'product_id' => $id, + 'rubric_id' => $rubric_id + ), DB_AUTOQUERY_INSERT); + } + } + + function delete_keysProductsCities ($id) + { + $this->db->query ("delete from catalogs_keys_products_cities where product_id=?", array ( + $id + )); + } + + function saveProductSizeCine ($id, $data) + { + $this->db->query ("delete from catalogs_products_cine where product_id=?", array ( + $id + )); + foreach ($data['size'] as $key => $size) + { + $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); + } + } + + function productsIsHits ($products, $hits, $tops, $akcii) + { + $sql = "update catalogs_products set active=?,top=?,akcii_id=? where id=?"; + foreach ($products as $id) + { + if (@in_array ($id, $hits)) + $hit = true; + else + $hit = false; + if (@in_array ($id, $tops)) + $top = true; + else + $top = false; + if (@in_array ($id, $akcii)) + $akcii = true; + else + $akcii = false; + $this->db->query ($sql, array ( + $hit, + $top, + $akcii, + $id + )); + } + } + + function productsIsHits2 ($data, $hits) + { + $sql = "update catalogs_products set hit=?,hit_sort=? where id=?"; + foreach ($data['product_id'] as $key => $id) + { + if (@in_array ($id, $hits)) + $hit = true; + else + $hit = false; + $this->db->query ($sql, array ( + $hit, + $data['hit_sort'][$key], + $id + )); + } + } + + function viewProductsRubrics ($rubrics, $limit = 20) + { + $data = array (); + foreach ($rubrics as $key => $rubric_id) + { + $data[$key]['rubric']['name'] = $this->getRubricName ($rubric_id); + $data[$key]['rubric']['id'] = $rubric_id; + + $count = $this->db->getOne ("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?", array ( + $rubric_id + )); + $limit = 5; + $round = ($count > $limit) ? rand (0, ($count - $limit)) : $limit; + $sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand (1, 1000) % 2) ? "asc" : "desc") . " limit $round,$limit"; + $data[$key]['products'] = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + } + /* + * print"
";
+         * print_r($data);
+         * print"
"; + */ + $this->tpl->assign ('products', $data); + } + + function seralizeFilter ($str) + { + $array = explode (';', iconv ('UTF-8', 'CP1251', $str)); + $filter = array (); + foreach ($array as $key => $value) + { + $filter[substr ($value, 0, 1)][] = "'" . substr (str_replace (".", ",", $value), 1, strpos ($value, "_") - 1) . "'"; + } + // print_r($filter); + return $filter; + } + + function seralizeSex ($str) + { + $sex = array (); + $sex_num = array ( + 'male' => 1, + 'female' => 2, + 'child' => 3, + 'unisex' => 4 + ); + $sex_row = explode (';', $str); + foreach ($sex_row as $row) + { + $sex[] = $sex_num[$row]; + } + return $sex; + } + + // ================= + // ==== FILTER ===== + // ================= + + /** + *
+ * + * @param array $setting + * @return array / + */ + function queryBuild (array $setting = array ()) + { + Tools::ifNotExist ($setting, array ( + 'akcii' => true, + 'sex' => true, + )); - - function saveProductSizeCine($id,$data){ - $this->db->query("delete from catalogs_products_cine where product_id=?",array($id)); - foreach($data['size'] as $key=>$size){ - $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); - } - } - + $SQL = new SqlQuery(); + $SQL->select(' + catalogs_products.*, catalogs_products.name.as name, + catalogs_brends.name as brend_name, + catalogs_rubrics.list_name' . ($lang == 'ukr' ? '_ukr' : '') . ' as list_name, + catalogs_rubrics.translit as rubric_translit, + catalogs_keys_products_filters.*, + catalogs_keys_products_filters2.*, + catalogs_modifications.* + '); + + $SQL->from('catalogs_products'); - function productsIsHits($products,$hits,$tops,$akcii){ - $sql = "update catalogs_products set active=?,top=?,akcii_id=? where id=?"; - foreach($products as $id){ - if(@in_array($id,$hits))$hit = true; - else $hit = false; - if(@in_array($id,$tops))$top = true; - else $top = false; - if(@in_array($id,$akcii))$akcii = true; - else $akcii = false; - $this->db->query($sql,array($hit,$top,$akcii, $id)); - } - } - - function productsIsHits2($data,$hits){ - $sql = "update catalogs_products set hit=?,hit_sort=? where id=?"; - foreach($data['product_id'] as $key=>$id){ - if(@in_array($id,$hits))$hit = true; - else $hit = false; - $this->db->query($sql,array($hit,$data['hit_sort'][$key],$id)); - } - } - - function viewProductsRubrics($rubrics,$limit=20){ - $data = array(); - foreach($rubrics as $key=>$rubric_id){ - $data[$key]['rubric']['name'] = $this->getRubricName($rubric_id); - $data[$key]['rubric']['id'] = $rubric_id; - - $count = $this->db->getOne("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?",array($rubric_id)); - $limit = 5; $round = ($count>$limit) ? rand(0,($count-$limit)) : $limit; - $sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand(1,1000)%2) ? "asc" : "desc") . " limit $round,$limit"; - $data[$key]['products'] = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); - } - /* print"
";
-  print_r($data);
-  print"
"; */ - $this->tpl->assign('products',$data); - } - - function seralizeFilter($str){ - $array = explode(';',iconv('UTF-8','CP1251',$str)); - $filter = array(); - foreach($array as $key=>$value){ - $filter[substr($value,0,1)][] = "'".substr(str_replace(".", ",", $value),1, strpos($value,"_")-1 )."'"; - } - //print_r($filter); - return $filter; - } - - function seralizeSex($str){ - $sex = array(); - $sex_num = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $sex_row = explode(';',$str); - foreach($sex_row as $row){ - $sex[] = $sex_num[$row]; - } - return $sex; - } - + $SQL->innerJoin( + 'catalogs_brends', NULL, + 'catalogs_brends.id = catalogs_products.brend_id' + ); - function viewProducts($params,$rubricsP = false,$count_modf = true,$lang='ru'){ - - - //exit; - //print $params['filter_products']; - - if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']); - $search = array(); - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; - if(isset($params['search_str']) && strlen($params['search_str'])>0){ - $array_string = explode(" ",trim($params['search_str'])); - foreach($array_string as $row){ - $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."')"; - } - $search_string = array(); - // $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'"; - // $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'"; - /* foreach($array_string as $str){ - $search_string[] = "catalogs_products.name like '$str'"; - $search_string[] = "catalogs_products.name like'% $str %'"; - $search_string[] = "catalogs_products.name like'%$str %'"; - $search_string[] = "catalogs_products.name like'% $str%'"; + $SQL->innerJoin( + 'catalogs_rubrics', NULL, + 'catalogs_rubrics.id=catalogs_products.rubric_id' + ); - $search_string[] = "catalogs_products.text like '$str'"; - $search_string[] = "catalogs_products.text like'% $str %'"; - $search_string[] = "catalogs_products.text like'%$str %'"; - $search_string[] = "catalogs_products.text like'% $str%'"; - } */ - //$search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")"; - } - // print_r($params); - if(isset($params['brendID']) && $params['brendID']>0)$search[] = sprintf("catalogs_products.brend_id='%d'",$params['brendID']); - if(isset($params['akciiID']) && $params['akciiID']>0)$search[] = sprintf("catalogs_products.akcii_id>'%d'",0); - if(isset($params['new']) && $params['new']>0)$search[] = sprintf("catalogs_products.active='%d'",$params['new']); - if(isset($params['top']) && $params['top']>0)$search[] = sprintf("catalogs_products.top='%d'",$params['top']); - if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")"; - if(isset($params['sex']) && strlen($params['sex'])>0){ - $sex = $this->seralizeSex($params['sex']); - //print_r($sex); + $SQL->innerJoin( + 'catalogs_keys_products_filters', NULL, + 'catalogs_keys_products_filters.product_id = catalogs_products.id' + ); - // $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); + $SQL->innerJoin( + 'catalogs_keys_products_filters2', NULL, + 'catalogs_keys_products_filters2.product_id = catalogs_products.id' + ); - $search[] = "s.sex IN (" . implode(",",$sex) . ")"; - } - //if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']); - if($count_modf==true)$search[] = "catalogs_products.count_modifications>0"; - if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']) && !isset($params['what'])){ - $search[] = ($rubricsP==true)?sprintf("(catalogs_products.rubric_id='%d')",$params['rubID']):sprintf(" - (catalogs_products.rubric_parent_id='%d' || - catalogs_products.rubric_id='%d' || - catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') || - catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))",$params['rubID'],$params['rubID'],$params['rubID'],$params['rubID']); - } - - /* if(isset($params['filterID'])){ - //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']); - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")"; - }*/ + $SQL->innerJoin( + 'catalogs_modifications', NULL, + 'catalogs_modifications.product_id = catalogs_products.id + AND catalogs_modifications.active = 1' + ); + + // + if ($setting['akcii']) + { + $SQL->select('catalogs_keys_products_akcii.*'); + $SQL->innerJoin( + 'catalogs_keys_products_akcii', NULL, + 'catalogs_keys_products_akcii.product_id = catalogs_products.id' + ); + } + + // + if ($setting['sex']) + { + $SQL->select('sex.*'); + $SQL->innerJoin( + 'catalogs_keys_products_sex', 'sex', + 'catalogs_keys_products_sex.product_id = catalogs_products.id + AND sex.sex_id > 0' + ); + } + + $SQL->where('catalogs_products.count_modifications > 0'); + + // =========================== + // ==== ==== + // =========================== + + if (isset ($params['filter']) && count ($params['filter']) > 0) + { + // LIMIT + if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100) + { + $perPage = $_GET['perPage']; + } + else + { + $perPage = 20; + } + + $SQL->limit($perPage); + + // + if (isset ($params['search_str']) && strlen ($params['search_str']) > 0) + { + $array_string = explode (' ', trim ($params['search_str'])); + + foreach ($array_string as $word) + { + $SQL->where('( + catalogs_products.name LIKE "%'.$word.'%" + OR catalogs_products.text LIKE "%'.$word.'%" + OR catalogs_rubrics.name LIKE "%'.$word.'%" + OR catalogs_brends.name LIKE "%'.$word.'%" + OR catalogs_modifications.code = "'.$word.'" + )'); + } + } + + // PARAM + + if (isset ($params['brendID']) && $params['brendID'] > 0) + { + $SQL->where( sprintf ("catalogs_products.brend_id='%d'", $params['brendID'])); + } + + if (isset ($params['akciiID']) && $params['akciiID'] > 0) + { + $SQL->where( sprintf ("catalogs_products.akcii_id>'%d'", 0)); + } + + if (isset ($params['new']) && $params['new'] > 0) + { + $SQL->where( sprintf ("catalogs_products.active='%d'", $params['new'])); + } - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - elseif(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($params['what'])){ - $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")"; - } - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - if(isset($filter['r']) && count($filter['r'])>0){ - $search[] = "m2.rost in (".implode(",",$filter['r']).")"; - } -/* if(isset($params['yearID']) && $params['yearID']>0){ - //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']); - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")"; - }*/ - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - $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 "; - if(isset($params['akcii']) && $params['akcii']>0)$sql .= "RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id "; - 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 "; - 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 "; + if (isset ($params['top']) && $params['top'] > 0) + { + $SQL->where( sprintf ("catalogs_products.top='%d'", $params['top'])); + } + + if (isset ($params['brend']) && strlen ($params['brend']) > 0) + { + $SQL->where( "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")"); + } + + if (isset ($params['sex']) && strlen ($params['sex']) > 0) + { + $sex = $this->seralizeSex ($params['sex']); + + $SQL->where( "s.sex IN (" . implode (",", $sex) . ")"); + } + + // + if ($count_modf == true) + { + $SQL->where( "catalogs_products.count_modifications>0"); + } - 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 "; + if (isset ($params['rubID']) && $params['rubID'] > 0 + && ! isset ($params['filter_products']) + && ! isset ($params['what'])) + { + $SQL->where( ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf (" + ( + catalogs_products.rubric_parent_id='%d' || + catalogs_products.rubric_id='%d' || + catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') || + catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') + )", + $params['rubID'], + $params['rubID'], + $params['rubID'], + $params['rubID'] + )); + } + + $filter = $this->seralizeFilter ($params['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $SQL->where( "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"); + } + elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what'])) + { + $SQL->where( "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")"); + } + + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $SQL->where( "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"); + } + + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $SQL->where( "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"); + } + + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $SQL->where( "m2.rost in (" . implode (",", $filter['r']) . ")"); + } - //if(isset($params['filterID']) && $params['filterID']>0)$sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; -// if(isset($params['yearID']) && $params['yearID']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - if(isset($params['search_str']) && strlen($params['search_str'])>0){$sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id ";} - 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 ";} - 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 ";} - if(isset($params['sex']) && strlen($params['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";} + if (isset ($filter['y']) && $filter['y'] > 0) + { + $SQL->where( "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"); + } - - $sql .= "WHERE 1=1 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - // if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";} - //if(isset($params['search_str']) && strlen($params['search_str'])>0){} - $sql .= " GROUP BY catalogs_products.id "; - $sql .= "order by "; - if(isset($params['sort'])){ - switch($params['sort']){ - case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break; - default : $sql .= " catalogs_products.mktime desc"; - } - }else $sql .= (!empty($params['top']))?" catalogs_rubrics.top desc":" catalogs_products.rating desc"; + // ==== SORT ==== - $pagerOptions = Array( - 'mode' => 'Sliding', - 'delta' => 5, - 'perPage' => $perPage, - 'linkClass'=>"link_class", - 'curPageLinkClassName'=>"link_class_active", - 'spacesBeforeSeparator' => 1, - 'spacesAfterSeparator' => 1 - ); + if (isset ($params['sort'])) + { + switch ($params['sort']) + { + case 'cine' : + + $SQL->orderBy('catalogs_products.cine '. ($_GET['order'] == 'asc' ? 'ASC' : 'DESC')); + break; + + case 'click' : + + $SQL->orderBy('catalogs_products.click' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC')); + break; + + case 'rating' : + + $SQL->orderBy('catalogs_products.rating' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC')); + break; + + case 'hit' : + + $SQL->orderBy('catalogs_products.hit_sort ASC'); + break; + + default : + + $SQL->orderBy('catalogs_products.mktime DESC'); + } + } + else + { + $SQL->orderBy(! empty ($params['top']) ? 'catalogs_rubrics.top DESC' : 'catalogs_products.rating DESC'); + } + + // ==== GROUP ==== + + $SQL->groupBy('catalogs_products.id'); + } + + return $this->db->getAll ($SQL->__toSting(), array (), DB_FETCHMODE_ASSOC); + } + + function viewProducts ($params, $rubricsP = false, $count_modf = true, $lang = 'ru') + { + + // exit; + // print $params['filter_products']; + if (isset ($params['filter']) && count ($params['filter']) > 0) + $filter = $this->seralizeFilter ($params['filter']); + $search = array (); + if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100) + $perPage = $_GET['perPage']; + else + $perPage = 20; + if (isset ($params['search_str']) && strlen ($params['search_str']) > 0) + { + $array_string = explode (" ", trim ($params['search_str'])); + foreach ($array_string as $row) + { + $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 . "')"; + } + $search_string = array (); + // $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'"; + // $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'"; + /* + * foreach($array_string as $str){ + * $search_string[] = "catalogs_products.name like '$str'"; + * $search_string[] = "catalogs_products.name like'% $str %'"; + * $search_string[] = "catalogs_products.name like'%$str %'"; + * $search_string[] = "catalogs_products.name like'% $str%'"; + * + * $search_string[] = "catalogs_products.text like '$str'"; + * $search_string[] = "catalogs_products.text like'% $str %'"; + * $search_string[] = "catalogs_products.text like'%$str %'"; + * $search_string[] = "catalogs_products.text like'% $str%'"; + * } + */ + // $search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")"; + } + // print_r($params); + if (isset ($params['brendID']) && $params['brendID'] > 0) + $search[] = sprintf ("catalogs_products.brend_id='%d'", $params['brendID']); + if (isset ($params['akciiID']) && $params['akciiID'] > 0) + $search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0); + if (isset ($params['new']) && $params['new'] > 0) + $search[] = sprintf ("catalogs_products.active='%d'", $params['new']); + if (isset ($params['top']) && $params['top'] > 0) + $search[] = sprintf ("catalogs_products.top='%d'", $params['top']); + if (isset ($params['brend']) && strlen ($params['brend']) > 0) + $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")"; + if (isset ($params['sex']) && strlen ($params['sex']) > 0) + { + $sex = $this->seralizeSex ($params['sex']); + // print_r($sex); + + // $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); + + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } + // if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']); + if ($count_modf == true) + $search[] = "catalogs_products.count_modifications>0"; + if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']) && ! isset ($params['what'])) + { + $search[] = ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf (" + (catalogs_products.rubric_parent_id='%d' || + catalogs_products.rubric_id='%d' || + catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') || + catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))", $params['rubID'], $params['rubID'], $params['rubID'], $params['rubID']); + } + + /* + * if(isset($params['filterID'])){ + * //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']); + * $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")"; + * } + */ + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")"; + } + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + /* + * if(isset($params['yearID']) && $params['yearID']>0){ + * //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']); + * $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")"; + * } + */ + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + $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 + RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id + AND catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id + WHERE 1=1 + "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + // if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";} + // if(isset($params['search_str']) && strlen($params['search_str'])>0){} + $sql .= " GROUP BY catalogs_products.id "; + $sql .= "order by "; + if (isset ($params['sort'])) + { + switch ($params['sort']) + { + case 'cine' : + $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'click' : + $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'rating' : + $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'hit' : + $sql .= " catalogs_products.hit_sort asc"; + break; + default : + $sql .= " catalogs_products.mktime desc"; + } + } + else + $sql .= (! empty ($params['top'])) ? " catalogs_rubrics.top desc" : " catalogs_products.rating desc"; + + $pagerOptions = Array ( + 'mode' => 'Sliding', + 'delta' => 5, + 'perPage' => $perPage, + 'linkClass' => "link_class", + 'curPageLinkClassName' => "link_class_active", + 'spacesBeforeSeparator' => 1, + 'spacesAfterSeparator' => 1 + ); // echo $sql; // $sql=""; $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ()); @@ -1160,2848 +1759,3765 @@ function SaveProduct ($data, $upload) $res['data'][$i]['rating'] = @$res['data'][$i]['rating'] * 17; } } - + $this->tpl->assign ('productsData', $res); return $res; - } - - function getFilterPh1($product_id,$lang = 'ru'){ - $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':'')."<>''"; - return $this->db->getOne($sql,array($product_id)); - } - - function getCineCurs($type_curs,$cine){ - $curs = array(); - - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); - - switch($type_curs){ - case 'uah' : - $curs['uah'] = round($cine,2); - $curs['uah_bank'] = round(($cine/$usd)*$uah_bank,2); - $curs['usd'] = round($cine/$usd,2); - break; - case 'uah_bank' : - $curs['uah'] = round(($cine/$uah_bank)*$uah,2); - $curs['uah_bank'] = round($cine,2); - $curs['usd'] = round($cine/$uah_bank,2); - break; - case 'usd' : - $curs['uah'] = round($cine*$uah,2); - $curs['uah_bank'] = round($cine*$uah_bank,2); - $curs['usd'] = round($cine,2); - break; - } - return $curs; - } - - function viewProductsAkcii($rubric_id,$limit = 8){ - // $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products - // LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - // LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id - // WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 "; - // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - // $sql .= "order by RAND() LIMIT $limit"; - - $search = array(); - if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']); - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - - - if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")"; -/* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]); - } */ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "catalogs_products.sex IN (" . implode(",",$sex) . ")"; - } - - /*$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_keys_products_akcii - left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";*/ - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; - 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 "; - 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 "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - 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 ";} - //$sql .= "where catalogs_keys_products_akcii.rubric_id=? "; - $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 "; - if($rubric_id>0)$sql .="and catalogs_products.rubric_id='$rubric_id' "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "order by RAND()"; - if($rubric_id==0){$sql .= " limit 8";} - $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - //print_r($res); -for($i=0;$itpl->assign('products_akcii',$res); - } + } + + function getFilterPh1 ($product_id, $lang = 'ru') + { + $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' : '') . "<>''"; + return $this->db->getOne ($sql, array ( + $product_id + )); + } + + function getCineCurs ($type_curs, $cine) + { + $curs = array (); + + $uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'uah' + )); + $uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'uah_bank' + )); + $usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'usd' + )); + + switch ($type_curs) + { + case 'uah' : + $curs['uah'] = round ($cine, 2); + $curs['uah_bank'] = round (($cine / $usd) * $uah_bank, 2); + $curs['usd'] = round ($cine / $usd, 2); + break; + case 'uah_bank' : + $curs['uah'] = round (($cine / $uah_bank) * $uah, 2); + $curs['uah_bank'] = round ($cine, 2); + $curs['usd'] = round ($cine / $uah_bank, 2); + break; + case 'usd' : + $curs['uah'] = round ($cine * $uah, 2); + $curs['uah_bank'] = round ($cine * $uah_bank, 2); + $curs['usd'] = round ($cine, 2); + break; + } + return $curs; + } + + function viewProductsAkcii ($rubric_id, $limit = 8) + { + // $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products + // LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + // LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id + // WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 "; + // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; + // $sql .= "order by RAND() LIMIT $limit"; + $search = array (); + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")"; + } + + /* + * $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_keys_products_akcii + * left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id + * LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + * LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; + */ + $sql = " + SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit + FROM catalogs_products + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 + WHERE catalogs_products.count_modifications>0 + AND catalogs_products.akcii_id>0 + "; + if ($rubric_id > 0) + $sql .= "and catalogs_products.rubric_id='$rubric_id' "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "order by RAND()"; + if ($rubric_id == 0) + { + $sql .= " limit 8"; + } + $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + // print_r($res); + for ($i = 0; $i < count ($res); $i ++) + { + $res[$i]['rating2'] = $res[$i]['rating']; + if (@$res[$i]['rating']) + $res[$i]['rating'] = round ((@$res[$i]['rating'] / @$res[$i]['vote_num']), 0); + else + $res[$i]['rating'] = 0; + $res[$i]['rating'] = @$res[$i]['rating'] * 17; + } + $this->tpl->assign ('products_akcii', $res); + } - function getProductsAkcii($limit = 6){ - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products + function getProductsAkcii ($limit = 6) + { + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; - //$sql .= "where catalogs_keys_products_akcii.rubric_id=? "; - $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 "; - //if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "order by RAND() limit $limit"; - return $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - } - - function viewProductsHitsAll2(){ - if(isset($_GET['perPage']) && $_GET['perPage']>0 && $_GET['perPage']<=100)$perPage = $_GET['perPage'];else $perPage = 20; - $sql = "select * from catalogs_products where hit=?"; - $pagerOptions = Array( - 'mode' => 'Sliding', - 'delta' => 6, - 'perPage' => $perPage, - 'linkClass'=>"link_class", - 'curPageLinkClassName'=>"link_class_active", - 'spacesBeforeSeparator' => 1, - 'spacesAfterSeparator' => 1 - ); - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array(true)); + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; + // $sql .= "where catalogs_keys_products_akcii.rubric_id=? "; + $sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 "; + // if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; + $sql .= "order by RAND() limit $limit"; + return $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + } - $this->tpl->assign('productsData', $res); - } + function viewProductsHitsAll2 () + { + if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100) + $perPage = $_GET['perPage']; + else + $perPage = 20; + $sql = "select * from catalogs_products where hit=?"; + $pagerOptions = Array ( + 'mode' => 'Sliding', + 'delta' => 6, + 'perPage' => $perPage, + 'linkClass' => "link_class", + 'curPageLinkClassName' => "link_class_active", + 'spacesBeforeSeparator' => 1, + 'spacesAfterSeparator' => 1 + ); + $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ( + true + )); + + $this->tpl->assign ('productsData', $res); + } - function viewProductsActiveAll($params,$limit = 4,$curs = null){ - $search = array(); - - $sql = " + function viewProductsActiveAll ($params, $limit = 4, $curs = null) + { + $search = array (); + + $sql = " SELECT * FROM ( select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "ORDER BY RAND()) as T "; - $sql .= "Group By rubric_id ORDER BY RAND() LIMIT $limit"; - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - //print_r($res); - $this->tpl->assign('products_active',$res); - } - - function viewProductsActive($params,$limit = 4,$curs = null){ - $search = array(); - if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']))$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']); - if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']); - - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){ - $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")"; - } - - if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")"; - -/* if(isset($params['sex']) && strlen($params['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); - } */ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "s.sex IN (" . implode(",",$sex) . ")"; - } - - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; - 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 "; - 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 "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - 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 ";} - 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 "; - if(isset($params['sex']) && strlen($params['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";} - - $sql .= "WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "order by RAND() LIMIT $limit"; - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - //print_r($res); - $this->tpl->assign('products_active',$res); - } - - function viewProductsHits($params,$limit = 4,$curs = null){ - $search = array(); - if(isset($params['rubID']) && $params['rubID']>0)$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']); - - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id - WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "order by "; - if(isset($params['sort'])){ - switch($params['sort']){ - case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break; - default : $sql .= " RAND()"; - } - }else $sql .= " RAND()"; - $sql .=" LIMIT $limit"; - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - //print_r($res); - $this->tpl->assign('products_hits',$res); - } - - function viewProductsTops($params,$limit = 4,$curs = null){ - $search = array(); - if(isset($params['rubID']) && $params['rubID']>0 && !isset($params['filter_products']))$search[] = sprintf("catalogs_products.rubric_id=%d",$params['rubID']); - if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']); - - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){ - $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")"; - } - - if(isset($params['brend']) && strlen($params['brend'])>0)$search[] = "catalogs_products.brend_id in(".implode(",",$this->getBrendIDs_name($params['brend'])).")"; - - /*if(isset($params['sex']) && strlen($params['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); - }*/ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "catalogs_products.sex IN (" . implode(",",$sex) . ")"; - } - - $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products - LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id - LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id "; - 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 "; - 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 "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - 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 ";} - 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 "; - - $sql .= "WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - // $sql .= "order by RAND()"; - $sql .= "order by "; - if(isset($params['sort'])){ - switch($params['sort']){ - case 'cine' : $sql .= " catalogs_products.cine " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'click' : $sql .= " catalogs_products.click " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'rating' : $sql .= " catalogs_products.rating " . (($_GET['order']=='asc')?"asc":"desc"); break; - case 'hit' : $sql .= " catalogs_products.hit_sort asc"; break; - default : $sql .= " r.top desc"; - } - }else $sql .= " r.top desc"; - $sql .=" LIMIT $limit"; - //print $sql; - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - //print_r($res); - $this->tpl->assign('products_top',$res); - } - - function viewProductsTopOne(){ - $count = $this->db->getOne("select count(*) from catalogs_products WHERE catalogs_products.header=?",array(true)); - $limit = 1; $round = rand(0,($count-$limit)); - $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); - $this->tpl->assign('products_top_one',$res); - } - - function viewProductsLast($limit = 1){ - $search = array(); - $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=? "; - $sql .= "order by catalogs_products.mktime desc LIMIT $limit"; - $res = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - $this->tpl->assign('products_last',$res); - } - - function viewProductsHitsAll($limit = 4){ - $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=? "; - $sql .= "order by mktime desc LIMIT $limit"; - $products_hits = $this->db->getAll($sql,array(true),DB_FETCHMODE_ASSOC); - $this->tpl->assign('products_hits_all',$products_hits); - } - - function activeNull($rubric_id){ - $sql = "update catalogs_products set active=? where rubric_id=?"; - $this->db->query($sql,array(0,$rubric_id)); - } - - function viewProductOne($id,&$row){ -// $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=?"; - $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=?"; - - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - $row['ph1'] = $this->getFilterPh1($row['id']); - - $row['rating2'] = $row['rating']; - if( @$row['rating'] ) $row['rating'] = round( (@$row['rating'] / @$row['vote_num']), 0 ); - else $row['rating'] = 0; - $row['rating'] = @$row['rating'] * 17; - //print_r($row); - $this->tpl->assign('product',$row); - } - - function deleteCompareProduct(&$compare,$id){ - foreach($compare as $key=>$_id){ - if($_id == $id)unset($compare[$key]); - } - } - - function viewCompareProducts($compare){ - $products = array(); - $i = 0; - foreach($compare as $id){ - $sql = "select p.* from catalogs_products p where p.id=?"; - $products[$i] = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - $products[$i]['params'] = $this->getProductParams($id); - $i++; - } //print_r($products); - $this->tpl->assign('products',$products); - } - - function viewProductNembers($str_n){ - $arr_id = explode(",",$str_n); - $products = array(); - foreach($arr_id as $id){ - $count = $this->db->getOne("select count(*) from catalogs_keys_products_filters where filter_id=?",array(trim($id))); - $limit = 1; $round = rand(0,($count-$limit)); //" LIMIT 0,$limit" - $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"; - $row = $this->db->getRow($sql ,array(trim($id)),DB_FETCHMODE_ASSOC); - if(count($row)>0)$products[] = $row; - } - -// $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); - $this->tpl->assign('products_parent',$products); - } - - function getProductSizeCine($id,&$products){ - $res = $this->db->getAll("select * from catalogs_products_cine where product_id=?",array($id),DB_FETCHMODE_ASSOC); - $i = 0; - foreach($res as $row){ - $products['size_' . $row['n']] = $row['size']; - $products['cine_' . $row['n']] = $row['cine']; - $products['metka_' . $row['n']] = $row['metka']; - $products['id_cine_' . $row['n']] = $row['id']; - $i++; - } //print_r($products); - } - /* - function getProductCine($id,$curs = null){ - $sql = "select cine from catalogs_products where id=?"; - $row = $this->db->getOne($sql,array($id)); - return $row; - }*/ - - function getProductCine($id){ - $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=?"; - return $this->db->getOne($sql,array($id)); - } - - function viewProductCine($id){ - $row = $this->db->getAll("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC",array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('product_cines',$row); - } - - function viewCatalogsCurs(){ - $uah = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah')); - $this->tpl->assign('curs_uah',$uah); - $uah_bank = $this->db->getOne("select curs from catalogs_curs where type=?",array('uah_bank')); - $this->tpl->assign('curs_uah_bank',$uah_bank); - $usd = $this->db->getOne("select curs from catalogs_curs where type=?",array('usd')); - $this->tpl->assign('curs_usd',$usd); - } - - function saveCurs($data){ - $table_name = "catalogs_curs"; - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; - foreach($data as $key=>$value){ - $this->db->autoExecute($table_name,array('curs'=>$value),$DB_AUTOQUERY,"type='$key'"); - } - } - - function viewVarCurs($curs){ - $this->tpl->assign('curs',$curs); - } - - function viewBasketProducts($session_basket,$curs = null,$discount = 0){ - $products = array(); $i = 0; $cineAll = 0; -// $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?"; -// $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=?"; - $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=?"; - - foreach($session_basket as $id){ - $products_count = 1; - if(count($products)){ - foreach($products as $key=>$value){ - 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'];} - }} - if($products_count==1){ - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - $products[$i] = $row; - $products[$i]['cine'] = round($products[$i]['cine'] - ($products[$i]['cine']*$products[$i]['sale']/100)); - - $products[$i]['products_count']=$products_count; - $products[$i]['products_cine_all']=$products[$i]['cine']*$products_count; - $cineAll = $cineAll+$products[$i]['products_cine_all']; - $i++; - } + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "ORDER BY RAND()) as T "; + $sql .= "Group By rubric_id ORDER BY RAND() LIMIT $limit"; + $res = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + // print_r($res); + $this->tpl->assign ('products_active', $res); + } - } - /*print"
";
-  print_r($products);
-  print"
";*/ - $this->tpl->assign('cineAll',$cineAll); - $this->tpl->assign('cineAll_discount',$cineAll - (($cineAll*$discount)/100)); - $this->tpl->assign('basket_products',$products); //print_r($products); - } - - - function BasketUpload(&$session_basket,$proructs_count){ - - // ========== ZLODEYEV ============ - - foreach($proructs_count as $key=>$value){ - - // ==== ==== - - // - $sql4 = "SELECT * FROM catalogs_modifications as m - LEFT JOIN catalogs_products as p - ON p.id=m.product_id - WHERE m.id='".$key."' "; - $result4 = mysql_query($sql4) or die(mysql_error()); - if (mysql_affected_rows()!=0) { - $item=mysql_fetch_assoc($result4); - } + function viewProductsActive ($params, $limit = 4, $curs = null) + { + $search = array (); + if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products'])) + $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']); + if (isset ($params['filter']) && count ($params['filter']) > 0) + $filter = $this->seralizeFilter ($params['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")"; + } - $f=0; + if (isset ($params['brend']) && strlen ($params['brend']) > 0) + $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")"; + + /* + * if(isset($params['sex']) && strlen($params['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } - if (isset($_SESSION['shopcart'])) { + $sql = " + SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit + FROM catalogs_products + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id + WHERE catalogs_products.active=? + AND catalogs_products.count_modifications>0 + "; - foreach ($_SESSION['shopcart'] as $i => $cart) { + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "order by RAND() LIMIT $limit"; + $res = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + // print_r($res); + $this->tpl->assign ('products_active', $res); + } - - if ($cart['code']!='' && $cart['code']==$key) { - $f=1; - $_SESSION['shopcart'][$i]['count']=$value; - $_SESSION['shopcart'][$i]['total']=$value*$_SESSION['shopcart'][$i]['price']; - if ($_SESSION['shopcart'][$i]['total']==0) { - unset($_SESSION['shopcart'][$i]); - } + function viewProductsHits ($params, $limit = 4, $curs = null) + { + $search = array (); + if (isset ($params['rubID']) && $params['rubID'] > 0) + $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']); + + $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id + WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "order by "; + if (isset ($params['sort'])) + { + switch ($params['sort']) + { + case 'cine' : + $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc"); break; - } + case 'click' : + $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'rating' : + $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'hit' : + $sql .= " catalogs_products.hit_sort asc"; + break; + default : + $sql .= " RAND()"; } - } + } + else + $sql .= " RAND()"; + $sql .= " LIMIT $limit"; + $res = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + // print_r($res); + $this->tpl->assign ('products_hits', $res); } - - // ========== ZLODEYEV ============ - - - $session_basket = array(); - foreach($proructs_count as $key=>$value){ - for($i=0;$i<$value;$i++){ - $session_basket[] = $key; - } - } - } - - function sendOrder($data){ - $mail = new PHPMailer(); - $mail->CharSet = "windows-1251"; - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; - $mail->FromName = $data['order_name']; - $mail->AddAddress("shop@eltrade.com.ua","shop"); - $mail->Subject = " "; - $title = Mail::str_rus(" "); - $msg = ""; - foreach($data['product_id'] as $key=>$value){ - $msg .= "ID: ".$value." "; - $msg .= ": ".$data['product_name'][$key]." "; - $msg .= " : ".$data['product_cine'][$key]." "; - $msg .= ": ".$data['product_count'][$key]." "; - $msg .= " : ".$data['product_cine_all'][$key]." "; - $msg .= "
"; - } - $msg .= " : ".$data['cineAll']; - $msg .= "
"; - /* $msg .= ": ".$data['discount']." %"; - $msg .= "
"; */ - $msg .= " : ".$data['cineAll_discount']; - $msg .= "


"; - $msg .= " :"; - $msg .= "
"; - $msg .= ": ".$data['order_name']; - $msg .= "
"; - $msg .= ": ".$data['order_adress']; - $msg .= "
"; - $msg .= "E-mail: ".$data['order_email']; - $msg .= "
"; - $msg .= " : ".$data['order_phone']; -// $msg .= "
"; -// $msg .= " : ".$data['order_phonemob']; - $msg .= "
"; - $msg .= ": ".$data['order_comment']; -// $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua"; -// Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg)); - $mail->MsgHTML($msg); - if(!$mail->Send()){echo "There has been a mail error sending to
";return false;} - $mail->ClearAddresses(); - $mail->ClearAttachments(); - - $this->sendOrderXML($data); - } - - - function sendOrderXML($data){ - - - -$data['order_phone'] = str_replace("-","",$data['order_phone']); -$data['order_phone'] = str_replace(")","",$data['order_phone']); -$data['order_phone'] = str_replace("(","",$data['order_phone']); -$data['order_phone'] = str_replace(" ","",$data['order_phone']); -$ffffffff = substr($data['order_phone'],0,3); -if($ffffffff!="380") -$data['order_phone'] = "+38".$data['order_phone']; - - - - $mail = new PHPMailer(); - $mail->CharSet = "windows-1251"; - $mail->From = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; - $mail->FromName = $data['order_name']; - $mail->AddAddress("extremshop@portal.myoffice.biz.ua","extremshop"); - $mail->Subject = "xml "; - $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; - $xml = ''; - $xml .= ''; - foreach($data['product_id'] as $key=>$value){ - $xml .= ""; - $xml .= "".$data['product_name2'][$key].""; - $xml .= "".$data['product_size'][$key].""; - $xml .= "".$data['product_color'][$key].""; - $xml .= "".$data['product_price'][$key].""; - $xml .= "".$data['product_count'][$key].""; - $xml .= ""; - } - $xml .= ''; - $xml .= ''.$data['order_name'].''; - $xml .= ''.$data['order_phone'].''; - $xml .= ''.$data['order_email'].''; - $xml .= ''; - $xml .= ''; - $xml .= ''; - $xml .= '
'.$data['order_adress'].'
'; - $xml .= ''; - $xml .= '
'; - $xml .= ''.$data['order_comment'].''; - $xml .= '
'; - $tmpfname = tempnam("tmp", "FOO"); - $handle = fopen($tmpfname, "w"); - fwrite($handle, $xml); - $mail->AddAttachment($tmpfname, 'order.xml'); - if(!$mail->Send()){echo "There has been a mail error sending to
";return false;} - fclose($handle); - unlink($tmpfname); - $mail->ClearAddresses(); - $mail->ClearAttachments(); - // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml)); - // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml)); - } - - function saveOrder($data,$userID = 0){ - - $table_name = "catalogs_orders"; - - if(isset($data['update_id']) && $data['update_id']>0){ - $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; - $id = $data['update_id']; - $where = sprintf("id='%d'",$id); - } else { - $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; - $id = $this->db->nextId('mySequence_'.$table_name); - $where = null; - } - - - - - $fields_values = array( - 'id'=>$id, - 'user_id'=>$userID, - 'name' => $data['order_name'], - 'email' => $data['order_email'], - 'adress' => $data['order_adress'], - //'phone' => phone_mobil($data['order_phone']), - 'phone' => $data['order_phone'], - 'comment' => $data['order_comment'], - 'delivery' => $data['delivery'], - 'total'=>$_SESSION['cart']['total'], - 'status' => '1', - 'mktime'=>mktime() - ); - $DB_AUTOQUERY; - - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,$where); - - if(isset($data['product_id'])){ $i=-1; - foreach($data['product_id'] as $key=>$value){ $i++; - $this->db->autoExecute("catalogs_orders_products",array( - 'order_id'=>$id, - 'product_id'=>$value, - 'product_cine_id'=>$_SESSION['cart'][$i]['price'], - 'count'=>$data['product_count'][$key]) - ,DB_AUTOQUERY_INSERT); - } - } - - - } - - function deleteOrder($id){ - $this->db->query("delete from catalogs_orders where id=?",array($id)); - $this->db->query("delete from catalogs_orders_products where order_id=?",array($id)); - } - - function updateOrder($data){ - $table_name = "catalogs_orders"; - $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()); - if(isset($data['order_active']))$fields_values['active'] = 1; - else $fields_values['active'] = 0; - $this->db->autoExecute($table_name,$fields_values,DB_AUTOQUERY_UPDATE,sprintf("id='%d'",$data['update_id'])); - } - - function updateOrderProducts($data){ - foreach($data['product_id'] as $key=>$value){ - if($data['product_count'][$value]<1){$this->db->query("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");} - 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'");} - } - } - - function viewOrder($id){ - $row = $this->db->getRow("select * from catalogs_orders where id=?",array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('order', $row); - } - - function viewOrderProducts($order_id){ - $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); - $sum = 0; - foreach($res as $key=>$row){ - $sum = $sum + ($row['cine']*$row['count']); - $res[$key]['cine_all'] = ($row['cine']*$row['count']); - } - $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)); - $this->tpl->assign('cine', array('sum'=>$sum,'discount'=>$discount,'sum_discount'=>($sum - (($sum*$discount)/100)) )); - $this->tpl->assign('basket_products', $res); - } - - function viewOrders($params = array()){ - $search = array(); - if(isset($params['userID']) && $params['userID']>0)$search[] = sprintf("catalogs_orders.user_id='%d'",$params['userID']); - $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 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= " order by mktime desc"; - $pagerOptions = Array( - 'mode' => 'Sliding', - 'delta' => 16, - 'perPage' => 50, - 'linkClass'=>"link_class", - 'curPageLinkClassName'=>"link_class_active", - 'spacesBeforeSeparator' => 1, - 'spacesAfterSeparator' => 1 - ); - $res = Pager_Wrapper_DB($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array()); - foreach($res['data'] as $key=>$value){ - $res['data'][$key]['sum'] = $this->getOrderProductsSum($value['id']); - $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum']*$value['discount'])/100); - } - $this->tpl->assign('ordersData', $res); - } - - function getOrderProductsSum($order_id){ - $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); - // print_r($res); - $sum = 0; - foreach($res as $row){ - $sum = $sum + ($row['cine']*$row['count']); - } - return $sum; - } - - function SaveBrend($data,$upload){ - $table_name = "catalogs_brends"; - $DB_AUTOQUERY = ($data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $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']); - - if(isset($data['delete_video']) && $data['delete_video']==1){ - $this->deleteBrendPic($data['update_id']); - $fields_values['pic'] = null; - } - if($upload['pic']['tmp_name']){ - if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic')); - $name_pic = mktime() . "." . substr(strrchr($_FILES['pic']['name'],"."),1); - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic"; - move_uploaded_file($_FILES["pic"]["tmp_name"], $file_name); - chmod($file_name,"0777"); - $fields_values['pic'] = $name_pic; - } - - if(isset($data['delete_pic_s']) && $data['delete_pic_s']==1){ - $this->deleteBrendPic($data['update_id'],array('pic_s')); - $fields_values['pic_s'] = null; - } - if($upload['pic_s']['tmp_name']){ - if($data['update_id']>0)$this->deleteBrendPic($data['update_id'],array('pic_s')); - $name_pic = mktime() . "." . substr(strrchr($_FILES['pic_s']['name'],"."),1); - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic"; - move_uploaded_file($_FILES["pic_s"]["tmp_name"], $file_name); - chmod($file_name,"0777"); - $fields_values['pic_s'] = $name_pic; - } - - - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); - } - - function deleteBrendPic($id,$pics = array('pic','pic_s')){ - $sql = "select " . implode(',',$pics) . " from catalogs_brends where id=?"; - $row = $this->db->getRow($sql,array($id),DB_FETCHMODE_ASSOC); - if(isset($row['pic'])){ - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}"; - @unlink($file_name); - } - if(isset($row['pic_s'])){ - $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}"; - @unlink($file_name); - } - } - - function viewBrends($type = false){ - $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id "; - if($type!=false)$sql .= "where b.type='$type'"; - $sql .= " Order by b.name Asc"; - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - $this->tpl->assign('brends',$row); - } - - function viewBrendsGroup($params = array()){ - $search = array(); - if(isset($params['filter']) && count($params['filter'])>0)$filter = $this->seralizeFilter($params['filter']); - - if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){ - $search[] = "catalogs_keys_products_filters.filter_id in (".$params['filter_products'].")"; - } - - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - if(isset($filter['r']) && count($filter['r'])>0){ - $search[] = "m2.rost in (".implode(",",$filter['r']).")"; - } - if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("catalogs_products.active='%d'",$_GET['new']); - if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("catalogs_products.top='%d'",$_GET['top']); -if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("catalogs_products.akcii_id>'%d'",0); - /*if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]); - }*/ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "s.sex IN (" . implode(",",$sex) . ")"; - } -/* - $sql = "select * from catalogs_products "; - $sql .= "LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id "; - if(isset($params['filter_products']) && strlen($params['filter_products'])>0 && !isset($filter['f'])){ - //$sql .= "LEFT JOIN catalogs_products ON catalogs_products.brend_id=catalogs_brends.id "; - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; - } - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; - 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 "; - 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 "; - - 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 ";} - 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 ";} - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id ";} - $sql .= "where catalogs_products.count_modifications>0 and catalogs_brends.id>0 "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - if(isset($params['rubID']) && !isset($params['filter_products'])){ - $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']); - $rubric_id = ($rubric_id==0)?$params['rubID']:$rubric_id; - $sql .= "and catalogs_products.rubric_id='".$rubric_id."'"; - } - $sql .= " Group by catalogs_brends.name Order by catalogs_brends.name Asc"; - // print $sql; - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - $this->tpl->assign('brends',$row); - } -*/ - - // ==== catalogs_products ==== - - $sql = array (); - $sql[] = "select * from catalogs_products "; - $sql[] = "LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id "; - - if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f'])) - { - //$sql .= "LEFT JOIN catalogs_products ON catalogs_products.brend_id=catalogs_brends.id "; - $sql[] = "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; - } - - if (isset ($filter['y']) && $filter['y'] > 0) + function viewProductsTops ($params, $limit = 4, $curs = null) { - $sql[] = "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id "; + $search = array (); + if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products'])) + $search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']); + if (isset ($params['filter']) && count ($params['filter']) > 0) + $filter = $this->seralizeFilter ($params['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")"; + } + + if (isset ($params['brend']) && strlen ($params['brend']) > 0) + $search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")"; + + /* + * if(isset($params['sex']) && strlen($params['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")"; + } + + $sql = " + SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit + FROM catalogs_products + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + WHERE catalogs_products.top=? + AND catalogs_products.count_modifications>0 + "; + + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + // $sql .= "order by RAND()"; + $sql .= "order by "; + if (isset ($params['sort'])) + { + switch ($params['sort']) + { + case 'cine' : + $sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'click' : + $sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'rating' : + $sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc"); + break; + case 'hit' : + $sql .= " catalogs_products.hit_sort asc"; + break; + default : + $sql .= " r.top desc"; + } + } + else + $sql .= " r.top desc"; + $sql .= " LIMIT $limit"; + // print $sql; + $res = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + // print_r($res); + $this->tpl->assign ('products_top', $res); } - if (isset ($filter['f']) && count ($filter['f']) > 0) + function viewProductsTopOne () { - $sql[] = "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id "; + $count = $this->db->getOne ("select count(*) from catalogs_products WHERE catalogs_products.header=?", array ( + true + )); + $limit = 1; + $round = rand (0, ($count - $limit)); + $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); + $this->tpl->assign ('products_top_one', $res); } - if (isset ($filter['g']) && count ($filter['g']) > 0) + function viewProductsLast ($limit = 1) { - $sql[] = "LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id "; + $search = array (); + $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=? "; + $sql .= "order by catalogs_products.mktime desc LIMIT $limit"; + $res = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('products_last', $res); } - if (isset ($filter['s']) && count ($filter['s']) > 0) + function viewProductsHitsAll ($limit = 4) { - $sql[] = "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 "; + $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=? "; + $sql .= "order by mktime desc LIMIT $limit"; + $products_hits = $this->db->getAll ($sql, array ( + true + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('products_hits_all', $products_hits); } - if (isset ($filter['r']) && count ($filter['r']) > 0) + function activeNull ($rubric_id) { - $sql[] = "LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 "; + $sql = "update catalogs_products set active=? where rubric_id=?"; + $this->db->query ($sql, array ( + 0, + $rubric_id + )); } - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + function viewProductOne ($id, &$row) { - $sql[] = "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id "; + // $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=?"; + $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=?"; + + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $row['ph1'] = $this->getFilterPh1 ($row['id']); + + $row['rating2'] = $row['rating']; + if (@$row['rating']) + $row['rating'] = round ((@$row['rating'] / @$row['vote_num']), 0); + else + $row['rating'] = 0; + $row['rating'] = @$row['rating'] * 17; + // print_r($row); + $this->tpl->assign ('product', $row); } - $sql[] = "where catalogs_products.count_modifications > 0 and catalogs_brends.id > 0 "; - - if (count ($search)) + function deleteCompareProduct (&$compare, $id) { - $sql[] = "AND " . implode(" AND ", $search) . " "; + foreach ($compare as $key => $_id) + { + if ($_id == $id) + unset ($compare[$key]); + } } - if (isset ($params['rubID']) && ! isset ($params['filter_products'])) + function viewCompareProducts ($compare) { - $rubric_id = $params['rubID'];//$this->getRubricParent($params['rubID']); - $rubric_id = ($rubric_id == 0) ? $params['rubID'] : $rubric_id; - $sql[] = "and catalogs_products.rubric_id='".$rubric_id."'"; + $products = array (); + $i = 0; + foreach ($compare as $id) + { + $sql = "select p.* from catalogs_products p where p.id=?"; + $products[$i] = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $products[$i]['params'] = $this->getProductParams ($id); + $i ++; + } // print_r($products); + $this->tpl->assign ('products', $products); } - $sql[] = " Group by catalogs_brends.name Order by catalogs_brends.name Asc"; - - if (count ($sql) > 4) - { - $row = $this->db->getAll(implode (' ', $sql), array(), DB_FETCHMODE_ASSOC); - } - else + function viewProductNembers ($str_n) { - // - $row = array (); + $arr_id = explode (",", $str_n); + $products = array (); + foreach ($arr_id as $id) + { + $count = $this->db->getOne ("select count(*) from catalogs_keys_products_filters where filter_id=?", array ( + trim ($id) + )); + $limit = 1; + $round = rand (0, ($count - $limit)); // " LIMIT 0,$limit" + $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"; + $row = $this->db->getRow ($sql, array ( + trim ($id) + ), DB_FETCHMODE_ASSOC); + if (count ($row) > 0) + $products[] = $row; + } + + // $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); + $this->tpl->assign ('products_parent', $products); } - $this->tpl->assign('brends', $row); - -} - -// ===== - - function viewBrendsActive(){ - $sql = "select * from catalogs_brends where active=1 "; - $sql .= " Order by name Asc"; - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - $this->tpl->assign('brends_a',$row); - } - - function SaveCity($data){ - $table_name = "catalogs_cities"; - $DB_AUTOQUERY = (isset($data['update_id']) && $data['update_id']>0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; - $fields_values = array('name'=>$data['name']); - $this->db->autoExecute($table_name,$fields_values,$DB_AUTOQUERY,"id={$data['update_id']}"); - return mysql_insert_id(); - } - - function is_city($name){ - return $this->db->getOne('select id from catalogs_cities where name=?',array($name)); - } - - function viewCityMod($code){ - $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"; - $row = $this->db->getCol($sql,"name",array($code)); - if(!count($row))return ""; - if(count($row) == 1 && trim($row[0])==''){ return ""; } - - foreach($row as $key=>$value){if($value==" " or $value=="()" or $value=="" or trim($value)=="")unset($row[$key]);} -$row2 = array(); -foreach($row as $key=>$value) if(trim($value)!='') $row2[] = $value; -$row = $row2; - - $l = array(); - for($i=0;$idb->getCol($sql,"city_id",array($id)); - $this->tpl->assign('product_cities',$row); - } - function viewCities($type = false){ - $sql = "select * from catalogs_cities "; - $sql .= " Order by name Asc"; - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - $this->tpl->assign('cities',$row); - } - - function viewCitiesProduct($id){ - $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=?"; - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('cities',$row); - } - - function viewCity($id){ - $row = $this->db->getRow("select * from catalogs_cities where id=?",array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('city', $row); - } - - function deleteCity($id){ - $this->db->query("delete from catalogs_cities where id=?",array($id)); - $this->delete_keysCitiesProduct($id); - } - - function delete_keysCitiesProduct($id){ - $sql = "delete from catalogs_keys_products_cities where city_id=?"; - $this->db->query($sql,array($id)); - } - - function SaveYears($data){ - $table_name = "catalogs_years"; - foreach($data['filter'] as $key=>$name){ - if(strlen($name)>0){ - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} - $this->db->autoExecute($table_name,array('name'=>$name,'rubric_id'=>$data['rubric_id']),$DB_AUTOQUERY,$where); - } - } - } - - function viewYearsProduct($id){ - $sql = "select y.* from catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id where k.product_id=?"; - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('product_years',$row); - } - - function viewYearsProductID($id){ - $sql = "select year_id from catalogs_keys_products_years where product_id=?"; - $row = $this->db->getCol($sql,"year_id",array($id)); - $this->tpl->assign('product_years',$row); - } - -function viewYears ($rubric_id, $filters = null) -{ - $search = array (); - - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) - $filter = $this->seralizeFilter ($_GET['filter']); - - if (isset ($filter['f']) && count ($filter['f']) > 0) + function getProductSizeCine ($id, &$products) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + $res = $this->db->getAll ("select * from catalogs_products_cine where product_id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + $i = 0; + foreach ($res as $row) + { + $products['size_' . $row['n']] = $row['size']; + $products['cine_' . $row['n']] = $row['cine']; + $products['metka_' . $row['n']] = $row['metka']; + $products['id_cine_' . $row['n']] = $row['id']; + $i ++; + } // print_r($products); } - if (isset ($filter['s']) && count ($filter['s']) > 0) + /* + * function getProductCine($id,$curs = null){ + * $sql = "select cine from catalogs_products where id=?"; + * $row = $this->db->getOne($sql,array($id)); + * return $row; + * } + */ + function getProductCine ($id) { - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + $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=?"; + return $this->db->getOne ($sql, array ( + $id + )); } - - if (isset ($filter['r']) && count ($filter['r']) > 0) + + function viewProductCine ($id) { - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + $row = $this->db->getAll ("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC", array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('product_cines', $row); } - if (isset ($_GET['new']) && $_GET['new'] > 0) - $search[] = sprintf ("p.active='%d'", $_GET['new']); - - if (isset ($_GET['top']) && $_GET['top'] > 0) - $search[] = sprintf ("p.top='%d'", $_GET['top']); - - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) - $search[] = sprintf ("p.akcii_id>'%d'", 0); - - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; - - /** - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); - * } - */ - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + function viewCatalogsCurs () { - $sex = $this->seralizeSex ($_GET['sex']); - $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + $uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'uah' + )); + $this->tpl->assign ('curs_uah', $uah); + $uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'uah_bank' + )); + $this->tpl->assign ('curs_uah_bank', $uah_bank); + $usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array ( + 'usd' + )); + $this->tpl->assign ('curs_usd', $usd); } - if (strlen ($filters) > 0 && ! isset ($filter['f'])) + function saveCurs ($data) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")"; + $table_name = "catalogs_curs"; + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + foreach ($data as $key => $value) + { + $this->db->autoExecute ($table_name, array ( + 'curs' => $value + ), $DB_AUTOQUERY, "type='$key'"); + } } - $sql = "select y.* from catalogs_products p, catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id "; - - 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 "; - - if (isset ($filter['s']) && count ($filter['s']) > 0) + function viewVarCurs ($curs) { - $sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 "; + $this->tpl->assign ('curs', $curs); } - if (isset ($filter['r']) && count ($filter['r']) > 0) + function viewBasketProducts ($session_basket, $curs = null, $discount = 0) { - $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 "; + $products = array (); + $i = 0; + $cineAll = 0; + // $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?"; + // $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=?"; + $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=?"; + + foreach ($session_basket as $id) + { + $products_count = 1; + if (count ($products)) + { + foreach ($products as $key => $value) + { + 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']; + } + } + } + if ($products_count == 1) + { + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $products[$i] = $row; + $products[$i]['cine'] = round ($products[$i]['cine'] - ($products[$i]['cine'] * $products[$i]['sale'] / 100)); + + $products[$i]['products_count'] = $products_count; + $products[$i]['products_cine_all'] = $products[$i]['cine'] * $products_count; + $cineAll = $cineAll + $products[$i]['products_cine_all']; + $i ++; + } + } + /* + * print"
";
+         * print_r($products);
+         * print"
"; + */ + $this->tpl->assign ('cineAll', $cineAll); + $this->tpl->assign ('cineAll_discount', $cineAll - (($cineAll * $discount) / 100)); + $this->tpl->assign ('basket_products', $products); // print_r($products); } - if (strlen ($filters) > 0 && ! isset ($filter['f'])) + function BasketUpload (&$session_basket, $proructs_count) { - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id "; + + // ========== ZLODEYEV ============ + foreach ($proructs_count as $key => $value) + { + + // ==== ==== + + // + $sql4 = "SELECT * FROM catalogs_modifications as m + LEFT JOIN catalogs_products as p + ON p.id=m.product_id + WHERE m.id='" . $key . "' "; + $result4 = mysql_query ($sql4) or die (mysql_error ()); + if (mysql_affected_rows () != 0) + { + $item = mysql_fetch_assoc ($result4); + } + + $f = 0; + + if (isset ($_SESSION['shopcart'])) + { + + foreach ($_SESSION['shopcart'] as $i => $cart) + { + + if ($cart['code'] != '' && $cart['code'] == $key) + { + $f = 1; + $_SESSION['shopcart'][$i]['count'] = $value; + $_SESSION['shopcart'][$i]['total'] = $value * $_SESSION['shopcart'][$i]['price']; + if ($_SESSION['shopcart'][$i]['total'] == 0) + { + unset ($_SESSION['shopcart'][$i]); + } + break; + } + } + } + } + + // ========== ZLODEYEV ============ + + $session_basket = array (); + foreach ($proructs_count as $key => $value) + { + for ($i = 0; $i < $value; $i ++) + { + $session_basket[] = $key; + } + } } - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + function sendOrder ($data) { - $sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id "; + $mail = new PHPMailer (); + $mail->CharSet = "windows-1251"; + $mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; + $mail->FromName = $data['order_name']; + $mail->AddAddress ("shop@eltrade.com.ua", "shop"); + $mail->Subject = " "; + $title = Mail::str_rus (" "); + $msg = ""; + foreach ($data['product_id'] as $key => $value) + { + $msg .= "ID: " . $value . " "; + $msg .= ": " . $data['product_name'][$key] . " "; + $msg .= " : " . $data['product_cine'][$key] . " "; + $msg .= ": " . $data['product_count'][$key] . " "; + $msg .= " : " . $data['product_cine_all'][$key] . " "; + $msg .= "
"; + } + $msg .= " : " . $data['cineAll']; + $msg .= "
"; + /* + * $msg .= ": ".$data['discount']." %"; + * $msg .= "
"; + */ + $msg .= " : " . $data['cineAll_discount']; + $msg .= "


"; + $msg .= " :"; + $msg .= "
"; + $msg .= ": " . $data['order_name']; + $msg .= "
"; + $msg .= ": " . $data['order_adress']; + $msg .= "
"; + $msg .= "E-mail: " . $data['order_email']; + $msg .= "
"; + $msg .= " : " . $data['order_phone']; + // $msg .= "
"; + // $msg .= " : ".$data['order_phonemob']; + $msg .= "
"; + $msg .= ": " . $data['order_comment']; + // $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua"; + // Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg)); + $mail->MsgHTML ($msg); + if (! $mail->Send ()) + { + echo "There has been a mail error sending to
"; + return false; + } + $mail->ClearAddresses (); + $mail->ClearAttachments (); + + $this->sendOrderXML ($data); } - $sql .= "where p.id=k.product_id and p.count_modifications>0 "; - - if ($filters == null) - $sql .= " and p.rubric_id='" . $rubric_id . "' "; - - if (count ($search)) - $sql .= "AND " . implode (" AND ", $search) . " "; - - $sql .= " GROUP BY k.year_id order by y.name desc"; - - // print $sql; - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); - $this->tpl->assign ('years', $row); -} - - function viewYearsAll($rubric_id){ - $sql = "SELECT * FROM catalogs_years WHERE rubric_id=? ORDER BY id asc "; - $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('years', $row); - } - - function viewSexProduct($id){ - $sql = "select * from catalogs_keys_products_sex where product_id=?"; - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('product_sex',$row); - } - - function viewSexProductID($id){ - $sql = "select sex from catalogs_keys_products_sex where product_id=?"; - $row = $this->db->getCol($sql,"sex",array($id)); - $this->tpl->assign('product_sex',$row); - } - -function viewSex ($rubric_id, $filters = null, $lang = 'rus') -{ - $search = array (); - - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) - $filter = $this->seralizeFilter ($_GET['filter']); - - if (isset ($filter['f']) && count ($filter['f']) > 0) + function sendOrderXML ($data) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + $data['order_phone'] = str_replace ("-", "", $data['order_phone']); + $data['order_phone'] = str_replace (")", "", $data['order_phone']); + $data['order_phone'] = str_replace ("(", "", $data['order_phone']); + $data['order_phone'] = str_replace (" ", "", $data['order_phone']); + $ffffffff = substr ($data['order_phone'], 0, 3); + if ($ffffffff != "380") + $data['order_phone'] = "+38" . $data['order_phone']; + + $mail = new PHPMailer (); + $mail->CharSet = "windows-1251"; + $mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; + $mail->FromName = $data['order_name']; + $mail->AddAddress ("extremshop@portal.myoffice.biz.ua", "extremshop"); + $mail->Subject = "xml "; + $order_email = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com"; + $xml = ''; + $xml .= ''; + foreach ($data['product_id'] as $key => $value) + { + $xml .= ""; + $xml .= "" . $data['product_name2'][$key] . ""; + $xml .= "" . $data['product_size'][$key] . ""; + $xml .= "" . $data['product_color'][$key] . ""; + $xml .= "" . $data['product_price'][$key] . ""; + $xml .= "" . $data['product_count'][$key] . ""; + $xml .= ""; + } + $xml .= ''; + $xml .= '' . $data['order_name'] . ''; + $xml .= '' . $data['order_phone'] . ''; + $xml .= '' . $data['order_email'] . ''; + $xml .= ''; + $xml .= ''; + $xml .= ''; + $xml .= '
' . $data['order_adress'] . '
'; + $xml .= ''; + $xml .= '
'; + $xml .= '' . $data['order_comment'] . ''; + $xml .= '
'; + $tmpfname = tempnam ("tmp", "FOO"); + $handle = fopen ($tmpfname, "w"); + fwrite ($handle, $xml); + $mail->AddAttachment ($tmpfname, 'order.xml'); + if (! $mail->Send ()) + { + echo "There has been a mail error sending to
"; + return false; + } + fclose ($handle); + unlink ($tmpfname); + $mail->ClearAddresses (); + $mail->ClearAttachments (); + // Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml)); + // Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml)); } - if (isset ($filter['y']) && $filter['y'] > 0) + + function saveOrder ($data, $userID = 0) { - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + $table_name = "catalogs_orders"; + + if (isset ($data['update_id']) && $data['update_id'] > 0) + { + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $id = $data['update_id']; + $where = sprintf ("id='%d'", $id); + } + else + { + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; + $id = $this->db->nextId ('mySequence_' . $table_name); + $where = null; + } + + $fields_values = array ( + 'id' => $id, + 'user_id' => $userID, + 'name' => $data['order_name'], + 'email' => $data['order_email'], + 'adress' => $data['order_adress'], + // 'phone' => phone_mobil($data['order_phone']), + 'phone' => $data['order_phone'], + 'comment' => $data['order_comment'], + 'delivery' => $data['delivery'], + 'total' => $_SESSION['cart']['total'], + 'status' => '1', + 'mktime' => mktime () + ); + $DB_AUTOQUERY; + + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, $where); + + if (isset ($data['product_id'])) + { + $i = - 1; + foreach ($data['product_id'] as $key => $value) + { + $i ++; + $this->db->autoExecute ("catalogs_orders_products", array ( + 'order_id' => $id, + 'product_id' => $value, + 'product_cine_id' => $_SESSION['cart'][$i]['price'], + 'count' => $data['product_count'][$key] + ), DB_AUTOQUERY_INSERT); + } + } } - if (isset ($filter['s']) && count ($filter['s']) > 0) + + function deleteOrder ($id) { - $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + $this->db->query ("delete from catalogs_orders where id=?", array ( + $id + )); + $this->db->query ("delete from catalogs_orders_products where order_id=?", array ( + $id + )); } - if (isset ($filter['r']) && count ($filter['r']) > 0) + + function updateOrder ($data) { - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + $table_name = "catalogs_orders"; + $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 () + ); + if (isset ($data['order_active'])) + $fields_values['active'] = 1; + else + $fields_values['active'] = 0; + $this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, sprintf ("id='%d'", $data['update_id'])); } - if (isset ($_GET['new']) && $_GET['new'] > 0) - $search[] = sprintf ("p.active='%d'", $_GET['new']); - if (isset ($_GET['top']) && $_GET['top'] > 0) - $search[] = sprintf ("p.top='%d'", $_GET['top']); - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) - $search[] = sprintf ("p.akcii_id>'%d'", 0); - if (strlen ($filters) > 0 && ! isset ($filter['f'])) + function updateOrderProducts ($data) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")"; + foreach ($data['product_id'] as $key => $value) + { + if ($data['product_count'][$value] < 1) + { + $this->db->query ("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'"); + } + 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'"); + } + } } - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; - - $sql = "select s.sex from catalogs_products p LEFT JOIN catalogs_keys_products_sex s ON s.product_id=p.id "; - - if (isset ($filter['f']) && count ($filter['f']) > 0) - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id "; - if (isset ($filter['y']) && $filter['y'] > 0) - $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id "; - if (isset ($filter['s']) && count ($filter['s']) > 0) + function viewOrder ($id) { - $sql .= "LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=p.id and catalogs_modifications.active=1 "; + $row = $this->db->getRow ("select * from catalogs_orders where id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('order', $row); } - if (isset ($filter['r']) && count ($filter['r']) > 0) + + function viewOrderProducts ($order_id) { - $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 "; + $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); + $sum = 0; + foreach ($res as $key => $row) + { + $sum = $sum + ($row['cine'] * $row['count']); + $res[$key]['cine_all'] = ($row['cine'] * $row['count']); + } + $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 + )); + $this->tpl->assign ('cine', array ( + 'sum' => $sum, + 'discount' => $discount, + 'sum_discount' => ($sum - (($sum * $discount) / 100)) + )); + $this->tpl->assign ('basket_products', $res); } - if (strlen ($filters) > 0 && ! isset ($filter['f'])) + + function viewOrders ($params = array()) { - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id "; + $search = array (); + if (isset ($params['userID']) && $params['userID'] > 0) + $search[] = sprintf ("catalogs_orders.user_id='%d'", $params['userID']); + $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 "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= " order by mktime desc"; + $pagerOptions = Array ( + 'mode' => 'Sliding', + 'delta' => 16, + 'perPage' => 50, + 'linkClass' => "link_class", + 'curPageLinkClassName' => "link_class_active", + 'spacesBeforeSeparator' => 1, + 'spacesAfterSeparator' => 1 + ); + $res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ()); + foreach ($res['data'] as $key => $value) + { + $res['data'][$key]['sum'] = $this->getOrderProductsSum ($value['id']); + $res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum'] * $value['discount']) / 100); + } + $this->tpl->assign ('ordersData', $res); } - $sql .= "where p.count_modifications>0 - and s.sex < 4 - and p.sex > 0 - "; - - if ($filters == null) - $sql .= " and p.rubric_id='" . $rubric_id . "' "; - if (count ($search)) - $sql .= "AND " . implode (" AND ", $search) . " "; - - $sql .= " GROUP BY s.sex"; - // print $sql; - $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); - // print_r($res); - $sex = array (); - if ($lang == 'ukr') - $arr = array ( - 1 => array ( - 'name' => "", - 'link' => 'male' - ), - 2 => array ( - 'name' => "Ƴ", - 'link' => 'female' - ), - 3 => array ( - 'name' => "", - 'link' => 'child' - ) - ) - // 4=>array('name'=>"",'link'=>'unisex') - ; - else - $arr = array ( - 1 => array ( - 'name' => "", - 'link' => 'male' - ), - 2 => array ( - 'name' => "", - 'link' => 'female' - ), - 3 => array ( - 'name' => "", - 'link' => 'child' - ) - ) - // 4=>array('name'=>"",'link'=>'unisex') - ; - - foreach ($res as $row) + function getOrderProductsSum ($order_id) { - $sex[] = $arr[$row['sex']]; + $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); + // print_r($res); + $sum = 0; + foreach ($res as $row) + { + $sum = $sum + ($row['cine'] * $row['count']); + } + return $sum; } - if (isset ($_GET['s'])) - print_r ($sex); + function SaveBrend ($data, $upload) + { + $table_name = "catalogs_brends"; + $DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $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'] + ); + + if (isset ($data['delete_video']) && $data['delete_video'] == 1) + { + $this->deleteBrendPic ($data['update_id']); + $fields_values['pic'] = null; + } + if ($upload['pic']['tmp_name']) + { + if ($data['update_id'] > 0) + $this->deleteBrendPic ($data['update_id'], array ( + 'pic' + )); + $name_pic = mktime () . "." . substr (strrchr ($_FILES['pic']['name'], "."), 1); + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic"; + move_uploaded_file ($_FILES["pic"]["tmp_name"], $file_name); + chmod ($file_name, "0777"); + $fields_values['pic'] = $name_pic; + } + + if (isset ($data['delete_pic_s']) && $data['delete_pic_s'] == 1) + { + $this->deleteBrendPic ($data['update_id'], array ( + 'pic_s' + )); + $fields_values['pic_s'] = null; + } + if ($upload['pic_s']['tmp_name']) + { + if ($data['update_id'] > 0) + $this->deleteBrendPic ($data['update_id'], array ( + 'pic_s' + )); + $name_pic = mktime () . "." . substr (strrchr ($_FILES['pic_s']['name'], "."), 1); + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic"; + move_uploaded_file ($_FILES["pic_s"]["tmp_name"], $file_name); + chmod ($file_name, "0777"); + $fields_values['pic_s'] = $name_pic; + } + + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}"); + } - $this->tpl->assign ('sex', $sex); -} - - function getYearsName_IDs($ids){ - //$sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name"; - //$row = $this->db->getCol($sql,"name",array()); - //return implode(", ",$row); - - $name = array(); - foreach($ids as $id){ - $name[] = $this->db->getOne("select name from catalogs_years where id=$id",array()); - } - return implode(", ",$name); - } - - function deleteYearsRubric_id($id){ - $this->db->query("delete from catalogs_years where rubric_id=?",array($id)); - $this->delete_keysYearsRubric($id); - } - - function delete_keysYearsRubric($id){ - $sql = "delete from catalogs_keys_products_years where rubric_id=?"; - $this->db->query($sql,array($id)); - } - - function deleteYear($id){ - $this->db->query("delete from catalogs_years where id=?",array($id)); - $this->delete_keysYearsProduct($id); - } - - function delete_keysYearsProduct($id){ - $sql = "delete from catalogs_keys_products_years where year_id=?"; - $this->db->query($sql,array($id)); - } - - function SaveFilters($data){ - $table_name = "catalogs_filters"; - foreach($data['filter'] as $key=>$name){ - if(strlen($name)>0){ - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} - $active = (isset($data['active'][$key])) ? 1 : 0; - $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); - if(isset($data['cat'][$key])){$fields['cat'] = $data['cat'][$key];} - $this->db->autoExecute($table_name,$fields,$DB_AUTOQUERY,$where); - } - } - } - - function viewFilterProduct($id){ - $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=?"; - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('product_filters',$row); - return $row; - } - - function viewFilterProductID($id){ - $sql = "select filter_id from catalogs_keys_products_filters where product_id=?"; - $row = $this->db->getCol($sql,"filter_id",array($id)); - $this->tpl->assign('product_filters',$row); - } - - function deleteFilter($id){ - $this->db->query("delete from catalogs_filters where id=?",array($id)); - $this->delete_keysFilterProduct($id); - } - - function deleteFiltersRubric_id($rubric_id){ - $this->db->query("delete from catalogs_filters where rubric_id=?",array($rubric_id)); - $this->delete_keysFilterRubric($rubric_id); - } - - function delete_keysFilterProduct($id){ - $sql = "delete from catalogs_keys_products_filters where filter_id=?"; - $this->db->query($sql,array($id)); - } - - function delete_keysFilterRubric($id){ - $sql = "delete from catalogs_keys_products_filters where rubric_id=?"; - $this->db->query($sql,array($id)); - } - - function viewFilters($rubric_id,$all = false,$lang = 'ru'){ - $search = array(); - if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']); - if(isset($filter['g']) && count($filter['g'])>0){ - $search[] = "catalogs_keys_products_filters2.filter_id in (".implode(",",$filter['g']).")"; - } - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - - if(isset($filter['r']) && count($filter['r'])>0){ - $search[] = "m2.rost in (".implode(",",$filter['r']).")"; - } - - if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']); - if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']); -if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0); - - if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "p.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")"; - /* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); - } */ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "s.sex IN (" . implode(",",$sex) . ")"; - } - $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 "; - 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 "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id "; - 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 ";} - 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 ";} - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id ";} - $sql .= "where p.id=k.product_id and p.count_modifications>0 "; - //$sql = "select * from catalogs_filters where 1=1 "; - if($all == false)$sql .= "and f.active='0' "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc"; - // print $sql; - $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('filters', $row); - } - - function viewFiltersAll($rubric_id){ - $row = $this->db->getAll("select * from catalogs_filters where rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('filters', $row); - } - - function getFiltersName_IDs($ids,$lang){ - //$sql = "select name from catalogs_filters where id in (".implode(",",$ids).")"; - //$row = $this->db->getCol($sql,"name",array()); - $name = array(); - foreach($ids as $id){ - $row = $this->db->getRow("select h1".($lang=='ukr'?'_ukr':'')." as h1 from catalogs_filters where id=$id",array(),DB_FETCHMODE_ASSOC); - $name[] = ((strlen($row['h1'])>0) ? $row['h1'] : $row['name']); - } - - return implode(", ",$name); - } - - function getFilters2Name_IDs($ids){ - //$sql = "select name from catalogs_filters where id in (".implode(",",$ids).")"; - //$row = $this->db->getCol($sql,"name",array()); - $name = array(); - foreach($ids as $id){ - $row = $this->db->getRow("select h1,name from catalogs_filters2 where id=$id",array(),DB_FETCHMODE_ASSOC); - $name[] = ((strlen($row['h1'])>0) ? $row['h1'] : $row['name']); - } -//print_r($name); - return implode(", ",$name); - } - - function SaveFilters2($data){ - $table_name = "catalogs_filters2"; - foreach($data['filter2'] as $key=>$name){ - if(strlen($name)>0){ - if(isset($data['update_id'][$key]) && $data['update_id'][$key]>0){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "id='{$data['update_id'][$key]}'";} - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = "";} - $active = (isset($data['active'][$key])) ? 1 : 0; - $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); - } - } - } - - function viewFilterProductID2($id){ - $sql = "select filter_id from catalogs_keys_products_filters2 where product_id=?"; - $row = $this->db->getCol($sql,"filter_id",array($id)); - $this->tpl->assign('product_filters2',$row); - } - - function deleteFilter2($id){ - $this->db->query("delete from catalogs_filters2 where id=?",array($id)); - $this->delete_keysFilterProduct2($id); - } - - function delete_keysFilterProduct2($id){ - $sql = "delete from catalogs_keys_products_filters2 where filter_id=?"; - $this->db->query($sql,array($id)); - } - - function deleteFiltersRubric_id2($rubric_id){ - $this->db->query("delete from catalogs_filters2 where rubric_id=?",array($rubric_id)); - $this->delete_keysFilterRubric2($rubric_id); - } - - function delete_keysFilterRubric2($id){ - $sql = "delete from catalogs_keys_products_filters2 where rubric_id=?"; - $this->db->query($sql,array($id)); - } - - function viewFilters2($rubric_id,$lang='ru'){ - $search = array(); - if(isset($_GET['filter']) && count($_GET['filter'])>0)$filter = $this->seralizeFilter($_GET['filter']); - if(isset($filter['f']) && count($filter['f'])>0){ - $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$filter['f']).")"; - } - if(isset($filter['y']) && $filter['y']>0){ - $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$filter['y']).")"; - } - - if(isset($filter['s']) && count($filter['s'])>0){ - $search[] = "catalogs_modifications.size in (".implode(",",$filter['s']).")"; - } - - if(isset($filter['r']) && count($filter['r'])>0){ - $search[] = "m2.rost in (".implode(",",$filter['r']).")"; - } - - if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']); - if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']); -if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0); - - if(isset($_GET['brend']) && strlen($_GET['brend'])>0)$search[] = "p.brend_id in(".implode(",",$this->getBrendIDs_name($_GET['brend'])).")"; - /* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); - } */ - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - $sex = $this->seralizeSex($_GET['sex']); - $search[] = "s.sex IN (" . implode(",",$sex) . ")"; - } - $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 "; - 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 "; - if(isset($filter['y']) && $filter['y']>0)$sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id "; - 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 ";} - 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 ";} - if(isset($_GET['sex']) && strlen($_GET['sex'])>0){$sql .= "LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id ";} - $sql .= "where p.id=k.product_id and p.count_modifications>0 "; - //$sql = "select * from catalogs_filters where 1=1 "; - if($all == false)$sql .= "and f.active='0' "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc"; - //print $sql; - $row = $this->db->getAll($sql,array($rubric_id),DB_FETCHMODE_ASSOC); - - // $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); - $this->tpl->assign('filters2', $row); - } - - function getFiltersMod_IDs($ids){ - $name = array(); - foreach($ids as $id){ - $name[] = $this->db->getOne("select size from catalogs_modifications where size=$id",array()); - } - return implode(", ",$name); - } - - function viewFiltersMod ($rubric_id) -{ - $search = array (); + function deleteBrendPic ($id, $pics = array('pic','pic_s')) + { + $sql = "select " . implode (',', $pics) . " from catalogs_brends where id=?"; + $row = $this->db->getRow ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + if (isset ($row['pic'])) + { + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}"; + @unlink ($file_name); + } + if (isset ($row['pic_s'])) + { + $file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}"; + @unlink ($file_name); + } + } - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) - $filter = $this->seralizeFilter ($_GET['filter']); + function viewBrends ($type = false) + { + $sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id "; + if ($type != false) + $sql .= "where b.type='$type'"; + $sql .= " Order by b.name Asc"; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('brends', $row); + } - if (isset ($filter['f']) && count ($filter['f']) > 0) + function viewBrendsGroup ($params = array()) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + $search = array (); + if (isset ($params['filter']) && count ($params['filter']) > 0) + $filter = $this->seralizeFilter ($params['filter']); + + if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")"; + } + + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("catalogs_products.active='%d'", $_GET['new']); + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("catalogs_products.top='%d'", $_GET['top']); + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0); + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]); + * } + */ + + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } + + // ==== catalogs_products ==== + + $sql[] = " + SELECT * + FROM catalogs_products + LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1 + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id + WHERE catalogs_products.count_modifications > 0 + AND catalogs_brends.id > 0 + "; + + if (count ($search)) + { + $sql[] = "AND " . implode (" AND ", $search) . " "; + } + + if (isset ($params['rubID']) && ! isset ($params['filter_products'])) + { + $rubric_id = $params['rubID']; // $this->getRubricParent($params['rubID']); + $rubric_id = ($rubric_id == 0) ? $params['rubID'] : $rubric_id; + $sql[] = "and catalogs_products.rubric_id='" . $rubric_id . "'"; + } + + $sql[] = " Group by catalogs_brends.name Order by catalogs_brends.name Asc"; + + if (count ($sql) > 4) + { + $row = $this->db->getAll (implode (' ', $sql), array (), DB_FETCHMODE_ASSOC); + } + else + { + // + $row = array (); + } + $this->tpl->assign ('brends', $row); } - - if (isset ($filter['y']) && $filter['y'] > 0) + + // ===== + + function viewBrendsActive () { - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + $sql = "select * from catalogs_brends where active=1 "; + $sql .= " Order by name Asc"; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('brends_a', $row); } - - if (isset ($filter['r']) && count ($filter['r']) > 0) + + function SaveCity ($data) { - $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + $table_name = "catalogs_cities"; + $DB_AUTOQUERY = (isset ($data['update_id']) && $data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT; + $fields_values = array ( + 'name' => $data['name'] + ); + $this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}"); + return mysql_insert_id (); } - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; - /* - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); - * } - */ - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + function is_city ($name) { - $sex = $this->seralizeSex ($_GET['sex']); - $search[] = "p.sex IN (" . implode (",", $sex) . ")"; + return $this->db->getOne ('select id from catalogs_cities where name=?', array ( + $name + )); } - if (isset ($_GET['new']) && $_GET['new'] > 0) - $search[] = sprintf ("p.active='%d'", $_GET['new']); + function viewCityMod ($code) + { + $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"; + $row = $this->db->getCol ($sql, "name", array ( + $code + )); + if (! count ($row)) + return ""; + if (count ($row) == 1 && trim ($row[0]) == '') + { + return ""; + } + + foreach ($row as $key => $value) + { + if ($value == " " or $value == "()" or $value == "" or trim ($value) == "") + unset ($row[$key]); + } + $row2 = array (); + foreach ($row as $key => $value) + if (trim ($value) != '') + $row2[] = $value; + $row = $row2; + + $l = array (); + for ($i = 0; $i < count ($row); $i ++) + { + $key = 0; + for ($i2 = 0; $i2 < count ($l); $i2 ++) + if ($l[$i2] == $row[$i]) + $key = 1; + if ($key == 0) + $l[] = $row[$i]; + } + if (trim ($_REQUEST['test2']) != '1') + { + return implode (', ', $l); + } + return implode (', ', $row); + } - if (isset ($_GET['top']) && $_GET['top'] > 0) - $search[] = sprintf ("p.top='%d'", $_GET['top']); + function viewCitiesProductID ($id) + { + $sql = "select city_id from catalogs_keys_products_cities where product_id=?"; + $row = $this->db->getCol ($sql, "city_id", array ( + $id + )); + $this->tpl->assign ('product_cities', $row); + } - if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) - $search[] = sprintf ("p.akcii_id>'%d'", 0); + function viewCities ($type = false) + { + $sql = "select * from catalogs_cities "; + $sql .= " Order by name Asc"; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('cities', $row); + } - $sql = "select m.* from catalogs_modifications m,catalogs_products p "; - if (isset ($filter['f']) && count ($filter['f']) > 0) - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id "; + function viewCitiesProduct ($id) + { + $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=?"; + $row = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('cities', $row); + } - if (isset ($filter['y']) && $filter['y'] > 0) - $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id "; + function viewCity ($id) + { + $row = $this->db->getRow ("select * from catalogs_cities where id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('city', $row); + } - if (isset ($filter['r']) && count ($filter['r']) > 0) + function deleteCity ($id) { - $sql .= "LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 "; + $this->db->query ("delete from catalogs_cities where id=?", array ( + $id + )); + $this->delete_keysCitiesProduct ($id); } - $sql .= "where m.size<>'' "; + function delete_keysCitiesProduct ($id) + { + $sql = "delete from catalogs_keys_products_cities where city_id=?"; + $this->db->query ($sql, array ( + $id + )); + } - if (count ($search)) - $sql .= "AND " . implode (" AND ", $search) . " "; + function SaveYears ($data) + { + $table_name = "catalogs_years"; + foreach ($data['filter'] as $key => $name) + { + if (strlen ($name) > 0) + { + if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0) + { + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $where = "id='{$data['update_id'][$key]}'"; + } + else + { + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; + $where = ""; + } + $this->db->autoExecute ($table_name, array ( + 'name' => $name, + 'rubric_id' => $data['rubric_id'] + ), $DB_AUTOQUERY, $where); + } + } + } - $sql .= " - and m.product_id=p.id - and m.active=1 - and p.rubric_id=? - and p.count_modifications>0 - and m.size > 0 - GROUP BY m.size"; - $row = $this->db->getAll ($sql, array ( - $rubric_id - ), DB_FETCHMODE_ASSOC); + function viewYearsProduct ($id) + { + $sql = "select y.* from catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id where k.product_id=?"; + $row = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('product_years', $row); + } - if ($_GET['t'] == 1) + function viewYearsProductID ($id) { - print "
";
-        print_r ($row);
-        print "
"; + $sql = "select year_id from catalogs_keys_products_years where product_id=?"; + $row = $this->db->getCol ($sql, "year_id", array ( + $id + )); + $this->tpl->assign ('product_years', $row); } - - $this->tpl->assign ('size', $row); -} - -function viewFiltersRost ($rubric_id) -{ - $search = array (); - if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) - $filter = $this->seralizeFilter ($_GET['filter']); + function viewYears ($rubric_id, $filters = null) + { + $search = array (); + + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + + /** + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } + + if (strlen ($filters) > 0 && ! isset ($filter['f'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")"; + } + + $sql = " + SELECT y.* + FROM catalogs_products p, catalogs_keys_products_years k + LEFT JOIN catalogs_years y ON y.id=k.year_id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id + WHERE p.id=k.product_id + AND p.count_modifications>0 + "; + + if ($filters == null) + $sql .= " and p.rubric_id='" . $rubric_id . "' "; + + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + + $sql .= " GROUP BY k.year_id order by y.name desc"; + + // print $sql; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('years', $row); + } - if (isset ($filter['f']) && count ($filter['f']) > 0) + function viewYearsAll ($rubric_id) { - $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + $sql = "SELECT * FROM catalogs_years WHERE rubric_id=? ORDER BY id asc "; + $row = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('years', $row); } - if (isset ($filter['y']) && $filter['y'] > 0) + function viewSexProduct ($id) { - $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + $sql = "select * from catalogs_keys_products_sex where product_id=?"; + $row = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('product_sex', $row); } - if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) - $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; - /* - * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ - * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); - * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); - * } - */ - if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + function viewSexProductID ($id) { - $sex = $this->seralizeSex ($_GET['sex']); - $search[] = "p.sex IN (" . implode (",", $sex) . ")"; + $sql = "select sex from catalogs_keys_products_sex where product_id=?"; + $row = $this->db->getCol ($sql, "sex", array ( + $id + )); + $this->tpl->assign ('product_sex', $row); } - $sql = "select m.* from catalogs_modifications m, catalogs_products p "; + function viewSex ($rubric_id, $filters = null, $lang = 'rus') + { + $search = array (); + + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + if (strlen ($filters) > 0 && ! isset ($filter['f'])) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")"; + } + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + + $sql = " + SELECT s.sex + FROM catalogs_products p + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=p.id + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=p.id and catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id + WHERE p.count_modifications>0 + AND s.sex < 4 + AND p.sex > 0 + "; + + if ($filters == null) + $sql .= " and p.rubric_id='" . $rubric_id . "' "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + + $sql .= " GROUP BY s.sex"; + // print $sql; + $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + // print_r($res); + $sex = array (); + if ($lang == 'ukr') + $arr = array ( + 1 => array ( + 'name' => "", + 'link' => 'male' + ), + 2 => array ( + 'name' => "Ƴ", + 'link' => 'female' + ), + 3 => array ( + 'name' => "", + 'link' => 'child' + ) + ); + // 4=>array('name'=>"",'link'=>'unisex') + + else + $arr = array ( + 1 => array ( + 'name' => "", + 'link' => 'male' + ), + 2 => array ( + 'name' => "", + 'link' => 'female' + ), + 3 => array ( + 'name' => "", + 'link' => 'child' + ) + ); + // 4=>array('name'=>"",'link'=>'unisex') + + + foreach ($res as $row) + { + $sex[] = $arr[$row['sex']]; + } + + if (isset ($_GET['s'])) + print_r ($sex); + + $this->tpl->assign ('sex', $sex); + } - if (isset ($filter['f']) && count ($filter['f']) > 0) - $sql .= "LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id "; + function getYearsName_IDs ($ids) + { + // $sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name"; + // $row = $this->db->getCol($sql,"name",array()); + // return implode(", ",$row); + $name = array (); + foreach ($ids as $id) + { + $name[] = $this->db->getOne ("select name from catalogs_years where id=$id", array ()); + } + return implode (", ", $name); + } - if (isset ($filter['y']) && $filter['y'] > 0) - $sql .= "LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id "; + function deleteYearsRubric_id ($id) + { + $this->db->query ("delete from catalogs_years where rubric_id=?", array ( + $id + )); + $this->delete_keysYearsRubric ($id); + } - $sql .= "where m.rost<>'' "; + function delete_keysYearsRubric ($id) + { + $sql = "delete from catalogs_keys_products_years where rubric_id=?"; + $this->db->query ($sql, array ( + $id + )); + } - if (count ($search)) + function deleteYear ($id) { - $sql .= "AND " . implode (" AND ", $search) . " "; + $this->db->query ("delete from catalogs_years where id=?", array ( + $id + )); + $this->delete_keysYearsProduct ($id); } - $sql .= " - and m.product_id=p.id - and m.active=1 - and p.rubric_id=? - and p.count_modifications>0 - GROUP BY m.rost"; - $row = $this->db->getAll ($sql, array ( - $rubric_id - ), DB_FETCHMODE_ASSOC); + function delete_keysYearsProduct ($id) + { + $sql = "delete from catalogs_keys_products_years where year_id=?"; + $this->db->query ($sql, array ( + $id + )); + } - if ($_GET['t'] == 1) + function SaveFilters ($data) { - print "
";
-        print_r ($row);
-        print "
"; + $table_name = "catalogs_filters"; + foreach ($data['filter'] as $key => $name) + { + if (strlen ($name) > 0) + { + if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0) + { + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $where = "id='{$data['update_id'][$key]}'"; + } + else + { + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; + $where = ""; + } + $active = (isset ($data['active'][$key])) ? 1 : 0; + $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 + ); + if (isset ($data['cat'][$key])) + { + $fields['cat'] = $data['cat'][$key]; + } + $this->db->autoExecute ($table_name, $fields, $DB_AUTOQUERY, $where); + } + } } - $this->tpl->assign ('rost', $row); -} - - function viewRostProduct($id){ - $sql = "select m.* from catalogs_modifications m where m.product_id=? GROUP BY m.rost"; - $row = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('product_rost',$row); - } - - function viewFiltersInProducts($filter_products,$lang='ru'){ - $search = array(); - if(isset($_GET['new']) && $_GET['new']>0)$search[] = sprintf("p.active='%d'",$_GET['new']); - if(isset($_GET['top']) && $_GET['top']>0)$search[] = sprintf("p.top='%d'",$_GET['top']); - if(isset($_GET['akciiID']) && $_GET['akciiID']>0)$search[] = sprintf("p.akcii_id>'%d'",0); - - $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' "; - if(count($search))$sql .= "AND " . implode(" AND ",$search) . " "; - $sql .= 'GROUP BY k.filter_id order by f.sort'; - //print $sql; - $row = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC); - $this->tpl->assign('filters', $row); - } - - function viewBrend($id){ - $row = $this->db->getRow("select * from catalogs_brends where id=?",array($id),DB_FETCHMODE_ASSOC); - $this->tpl->assign('brend', $row); - } - - function viewBrendName($name){ - $name = iconv("utf-8", "windows-1251", $name); - $sql = "select * from catalogs_brends where name=? limit 1"; - $row = $this->db->getRow($sql,array($name),DB_FETCHMODE_ASSOC); - $this->tpl->assign('brend_seo', $row); - return $row; - } - - function getBrendIDs_name($name){ - $n = array(); - $name_arr = explode(";",$name); - foreach($name_arr as $row){ - $n[] = "'".$row."'"; - } - //$name = iconv("utf-8", "windows-1251", $name); - $sql = "select id from catalogs_brends where name in (" . implode(",",$n) . ")"; - //print $sql; - return $this->db->getCol($sql,"id",array()); - } - - function viewBrendRubrics($name,$lang = 'ru'){ - $name = iconv("utf-8", "windows-1251", $name); - $sql = "select r.name".(($lang=='ukr')?'_ukr':'')." as name,r.parent_id,r.translit,count(p.id) as c from catalogs_brends b - Left Join catalogs_rubrics r On r.id=b.rubric_id - Left Join catalogs_products p On p.brend_id=b.id AND p.count_modifications>0 - where b.name=? and r.name<>'' Group by p.brend_id"; - $res = $this->db->getAll($sql,array($name),DB_FETCHMODE_ASSOC); - $rubrics = array(); - foreach($res as $row){ - if($row['c']>0){ - $rubrics[$this->getRubricName($row['parent_id'],$lang)][] = $row; - } - } - // print"
";
-  // print_r($rubrics);
-  // print"
"; - $this->tpl->assign('brend_rubrics',$rubrics); - } - - function deleteBrend($id){ - $this->db->query("delete from catalogs_brends where id=?",array($id)); - } - - function viewAkciiProductID($id){ - $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?"; - $row = $this->db->getCol($sql,"rubric_id",array($id)); - $this->tpl->assign('product_akcii',$row); - } - - function import_saveRubric($name,$parent_id){ - $id = $this->db->getOne("select id from catalogs_rubrics where name=? and parent_id=?",array($name,$parent_id)); - if( !$id ){ - $this->db->autoExecute("catalogs_rubrics",array('name'=>$name,'translit'=>translit($name),'parent_id' => $parent_id,"level"=>($this->getLevelRubric($parent_id)+1)),DB_AUTOQUERY_INSERT); - return mysql_insert_id(); - } - return $id; - } - - function import_saveBrend($name,$rubric_id){ - //getRubricParent(); - $id = $this->db->getOne("select id from catalogs_brends where name=? and rubric_id=?",array($name,$rubric_id)); - if( !$id ){ - $this->db->autoExecute("catalogs_brends",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); - return mysql_insert_id(); - } - return $id; - } - - function import_saveFilters2($rubric_id,$str){ - if(!$str)return array(); - $row_str = explode(",",trim($str)); - $arr_id = array(); - foreach($row_str as $str){ - $name = trim($str); - $name_r = explode('=',$name);$name = $name_r[0]; $active = (isset($name_r[1])) ? 1 : 0; - $id = $this->db->getOne("select id from catalogs_filters2 where rubric_id=? and name=?",array($rubric_id,$name)); - if( !$id ){ - $this->db->autoExecute("catalogs_filters2",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_INSERT); - $id = mysql_insert_id(); - }else{ $this->db->autoExecute("catalogs_filters2",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_UPDATE,"id=$id");} - $arr_id[] = $id; - } - return $arr_id; - } - - function import_saveFilters($rubric_id,$str){ - if(!$str)return array(); - $row_str = explode(",",trim($str)); - $arr_id = array(); - foreach($row_str as $str){ - $name = trim($str); - $name_r = explode('=',$name);$name = $name_r[0]; $active = (isset($name_r[1])) ? 1 : 0; - $id = $this->db->getOne("select id from catalogs_filters where rubric_id=? and name=?",array($rubric_id,$name)); - if( !$id ){ - $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_INSERT); - $id = mysql_insert_id(); - }else{ $this->db->autoExecute("catalogs_filters",array('rubric_id'=>$rubric_id,'name'=>$name,'prefix'=>encodestring($name),'active'=>$active),DB_AUTOQUERY_UPDATE,"id=$id");} - $arr_id[] = $id; - } - return $arr_id; - } - - function import_saveYear($rubric_id,$name){ - if(!$name)return false; - $id = $this->db->getOne("select id from catalogs_years where rubric_id=? and name=?",array($rubric_id,$name)); - if( !$id ){ - $this->db->autoExecute("catalogs_years",array('rubric_id'=>$rubric_id,'name'=>$name),DB_AUTOQUERY_INSERT); - $id = mysql_insert_id(); - } - return ($id)?array($id):array(); - } - - function import_updateProductCine($product_id,$row,$line='',$mktime = 0){ // print"
";print_r($row);print"
"; - - IF($product_id>0){ - IF($row[3]>0){ - if($row[2]<1){$cine=$row[1];$cine_last=0;} - else {$cine=$row[2];$cine_last=(($row[1]>0)?$row[1]:$row[2]);} - $this->db->autoExecute("catalogs_products",array('cine'=>$cine,'cine_last'=>$cine_last),DB_AUTOQUERY_UPDATE,"id='$product_id'"); - } - - - $city = trim($row[4]); - if(!$city)$city = " "; - //echo "OK(1) -
"; - if(strlen($city)>0){ //print $city; - $city_id = $this->is_city($city); - //echo "OK(2) -
"; - if(!$city_id){$city_id = $this->SaveCity(array('name'=>$city));} - $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktimedb->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime"; - if($this->getKeysModificationCity($row[0], $city_id)){$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;$where = "mod_code='".$row[0]."' and city_id='".$city_id."'";} - else{$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;$where = null;} - - // if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;} - //print $city_id .'--'.$where."
"; - $fields = array('count'=>$row[3],'product_id'=>$product_id,'mod_code'=>$row[0],'city_id'=>$city_id,'mktime'=>$mktime); - $s = $this->db->autoExecute("catalogs_keys_products_cities",$fields,$DB_AUTOQUERY,$where); - if (PEAR::isError($s)) die($s->getMessage()); - }} - //echo "OK(4) -
"; - $active = $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0",array($row[0])); - //$active = true; - if($this->db->getOne("select count(*) from catalogs_modifications where code=?",array($row[0]))>0){ - $this->db->autoExecute("catalogs_modifications",array('active'=>$active,'is_update'=>1,'prefix'=>$row[4]),DB_AUTOQUERY_UPDATE,"code='".$row[0]."'"); - //echo "OK(5) -
"; - }else{ - //echo "OK(6) -
"; - $this->saveCsvMod($line); - } - } - } - - function saveCsvMod($line){ - echo "OK1 -
"; - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv"; - $handle = @fopen($tmpfname, "a"); -// $row = explode(";",$line); -// File_FGetCSV::fputcsv($handle,$row,';'); - echo "OK2 -
"; - echo $line; - echo "OK3 -
"; - fwrite($handle,$line); - fclose($handle); - } - - function getKeysModificationCity($code, $city_id){ - return $this->db->getOne("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id)); - } - - function getKeysModificationCity_count($code, $city_id){ - return $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array($code, $city_id)); - } - - function getKeysModificationCityMktime_count($code, $city_id, $mktime){ - $r = $this->db->getOne("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array($code, $city_id, $mktime)); - return $r; - } - - function getProductID($name){ - $id = $this->db->getOne("select id from catalogs_products where name=?",array($name)); - return $id; - } - -function getProductID_R ($name, $rubric_parent_id) -{ - $id = $this->db->getOne ("select id from catalogs_products where name=? and rubric_id=?", array ( - $name, - $rubric_parent_id - )); - - return $id; -} - - function getModificationActive($code){ - return $this->db->getOne("select active from catalogs_modifications where code=?",array($code)); - } - -function updateProduct_countModification ($product_id, $count) -{ - $this->db->autoExecute ("catalogs_products", array ( + function viewFilterProduct ($id) + { + $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=?"; + $row = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('product_filters', $row); + return $row; + } + + function viewFilterProductID ($id) + { + $sql = "select filter_id from catalogs_keys_products_filters where product_id=?"; + $row = $this->db->getCol ($sql, "filter_id", array ( + $id + )); + $this->tpl->assign ('product_filters', $row); + } + + function deleteFilter ($id) + { + $this->db->query ("delete from catalogs_filters where id=?", array ( + $id + )); + $this->delete_keysFilterProduct ($id); + } + + function deleteFiltersRubric_id ($rubric_id) + { + $this->db->query ("delete from catalogs_filters where rubric_id=?", array ( + $rubric_id + )); + $this->delete_keysFilterRubric ($rubric_id); + } + + function delete_keysFilterProduct ($id) + { + $sql = "delete from catalogs_keys_products_filters where filter_id=?"; + $this->db->query ($sql, array ( + $id + )); + } + + function delete_keysFilterRubric ($id) + { + $sql = "delete from catalogs_keys_products_filters where rubric_id=?"; + $this->db->query ($sql, array ( + $id + )); + } + + function viewFilters ($rubric_id, $all = false, $lang = 'ru') + { + $search = array (); + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + if (isset ($filter['g']) && count ($filter['g']) > 0) + { + $search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } + $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 + LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=k.product_id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id + WHERE p.id=k.product_id + AND p.count_modifications>0 + "; + // $sql = "select * from catalogs_filters where 1=1 "; + if ($all == false) + $sql .= "and f.active='0' "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc"; + // print $sql; + $row = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('filters', $row); + } + + function viewFiltersAll ($rubric_id) + { + $row = $this->db->getAll ("select * from catalogs_filters where rubric_id=? order by sort", array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('filters', $row); + } + + function getFiltersName_IDs ($ids, $lang) + { + // $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")"; + // $row = $this->db->getCol($sql,"name",array()); + $name = array (); + foreach ($ids as $id) + { + $row = $this->db->getRow ("select h1" . ($lang == 'ukr' ? '_ukr' : '') . " as h1 from catalogs_filters where id=$id", array (), DB_FETCHMODE_ASSOC); + $name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']); + } + + return implode (", ", $name); + } + + function getFilters2Name_IDs ($ids) + { + // $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")"; + // $row = $this->db->getCol($sql,"name",array()); + $name = array (); + foreach ($ids as $id) + { + $row = $this->db->getRow ("select h1,name from catalogs_filters2 where id=$id", array (), DB_FETCHMODE_ASSOC); + $name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']); + } + // print_r($name); + return implode (", ", $name); + } + + function SaveFilters2 ($data) + { + $table_name = "catalogs_filters2"; + foreach ($data['filter2'] as $key => $name) + { + if (strlen ($name) > 0) + { + if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0) + { + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $where = "id='{$data['update_id'][$key]}'"; + } + else + { + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; + $where = ""; + } + $active = (isset ($data['active'][$key])) ? 1 : 0; + $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); + } + } + } + + function viewFilterProductID2 ($id) + { + $sql = "select filter_id from catalogs_keys_products_filters2 where product_id=?"; + $row = $this->db->getCol ($sql, "filter_id", array ( + $id + )); + $this->tpl->assign ('product_filters2', $row); + } + + function deleteFilter2 ($id) + { + $this->db->query ("delete from catalogs_filters2 where id=?", array ( + $id + )); + $this->delete_keysFilterProduct2 ($id); + } + + function delete_keysFilterProduct2 ($id) + { + $sql = "delete from catalogs_keys_products_filters2 where filter_id=?"; + $this->db->query ($sql, array ( + $id + )); + } + + function deleteFiltersRubric_id2 ($rubric_id) + { + $this->db->query ("delete from catalogs_filters2 where rubric_id=?", array ( + $rubric_id + )); + $this->delete_keysFilterRubric2 ($rubric_id); + } + + function delete_keysFilterRubric2 ($id) + { + $sql = "delete from catalogs_keys_products_filters2 where rubric_id=?"; + $this->db->query ($sql, array ( + $id + )); + } + + function viewFilters2 ($rubric_id, $lang = 'ru') + { + $search = array (); + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($filter['s']) && count ($filter['s']) > 0) + { + $search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")"; + } + + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "s.sex IN (" . implode (",", $sex) . ")"; + } + $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 + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id + LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1 + LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1 + LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id + WHERE p.id=k.product_id + AND p.count_modifications>0 + "; + // $sql = "select * from catalogs_filters where 1=1 "; + if ($all == false) + $sql .= "and f.active='0' "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc"; + // print $sql; + $row = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + + // $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); + $this->tpl->assign ('filters2', $row); + } + + function getFiltersMod_IDs ($ids) + { + $name = array (); + foreach ($ids as $id) + { + $name[] = $this->db->getOne ("select size from catalogs_modifications where size=$id", array ()); + } + return implode (", ", $name); + } + + function viewFiltersMod ($rubric_id) + { + $search = array (); + + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($filter['r']) && count ($filter['r']) > 0) + { + $search[] = "m2.rost in (" . implode (",", $filter['r']) . ")"; + } + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "p.sex IN (" . implode (",", $sex) . ")"; + } + + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + $sql = " + SELECT m.* + FROM catalogs_modifications m,catalogs_products p + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id + LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1 + WHERE m.size<>'' + "; + + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + + $sql .= " + and m.product_id=p.id + and m.active=1 + and p.rubric_id=? + and p.count_modifications>0 + and m.size > 0 + GROUP BY m.size"; + $row = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + + if ($_GET['t'] == 1) + { + print "
";
+            print_r ($row);
+            print "
"; + } + + $this->tpl->assign ('size', $row); + } + + function viewFiltersRost ($rubric_id) + { + $search = array (); + + if (isset ($_GET['filter']) && count ($_GET['filter']) > 0) + $filter = $this->seralizeFilter ($_GET['filter']); + + if (isset ($filter['f']) && count ($filter['f']) > 0) + { + $search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")"; + } + + if (isset ($filter['y']) && $filter['y'] > 0) + { + $search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")"; + } + + if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0) + $search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")"; + /* + * if(isset($_GET['sex']) && strlen($_GET['sex'])>0){ + * $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4); + * $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]); + * } + */ + if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0) + { + $sex = $this->seralizeSex ($_GET['sex']); + $search[] = "p.sex IN (" . implode (",", $sex) . ")"; + } + + $sql = " + SELECT m.* + FROM catalogs_modifications m, catalogs_products p + LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id + LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id + WHERE m.rost > 0"; + + if (count ($search)) + { + $sql .= "AND " . implode (" AND ", $search) . " "; + } + + $sql .= " + AND m.product_id=p.id + AND m.active=1 + AND p.rubric_id=? + AND p.count_modifications>0 + GROUP BY m.rost + "; + + $row = $this->db->getAll ($sql, array ( + $rubric_id + ), DB_FETCHMODE_ASSOC); + + if ($_GET['t'] == 1) + { + print "
";
+            print_r ($row);
+            print "
"; + } + + $this->tpl->assign ('rost', $row); + } + + function viewRostProduct ($id) + { + $sql = "select m.* from catalogs_modifications m where m.product_id=? GROUP BY m.rost"; + $row = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('product_rost', $row); + } + + function viewFiltersInProducts ($filter_products, $lang = 'ru') + { + $search = array (); + if (isset ($_GET['new']) && $_GET['new'] > 0) + $search[] = sprintf ("p.active='%d'", $_GET['new']); + if (isset ($_GET['top']) && $_GET['top'] > 0) + $search[] = sprintf ("p.top='%d'", $_GET['top']); + if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0) + $search[] = sprintf ("p.akcii_id>'%d'", 0); + + $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' "; + if (count ($search)) + $sql .= "AND " . implode (" AND ", $search) . " "; + $sql .= 'GROUP BY k.filter_id order by f.sort'; + // print $sql; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('filters', $row); + } + + function viewBrend ($id) + { + $row = $this->db->getRow ("select * from catalogs_brends where id=?", array ( + $id + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('brend', $row); + } + + function viewBrendName ($name) + { + $name = iconv ("utf-8", "windows-1251", $name); + $sql = "select * from catalogs_brends where name=? limit 1"; + $row = $this->db->getRow ($sql, array ( + $name + ), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('brend_seo', $row); + return $row; + } + + function getBrendIDs_name ($name) + { + $n = array (); + $name_arr = explode (";", $name); + foreach ($name_arr as $row) + { + $n[] = "'" . $row . "'"; + } + // $name = iconv("utf-8", "windows-1251", $name); + $sql = "select id from catalogs_brends where name in (" . implode (",", $n) . ")"; + // print $sql; + return $this->db->getCol ($sql, "id", array ()); + } + + function viewBrendRubrics ($name, $lang = 'ru') + { + $name = iconv ("utf-8", "windows-1251", $name); + $sql = " + SELECT r.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,r.parent_id,r.translit,count(p.id) as c + FROM catalogs_brends b + LEFT JOIN catalogs_rubrics r On r.id=b.rubric_id + LEFT JOIN catalogs_products p On p.brend_id=b.id AND p.count_modifications>0 + WHERE b.name=? + AND r.name<>'' + GROUP BY p.brend_id + "; + $res = $this->db->getAll ($sql, array ( + $name + ), DB_FETCHMODE_ASSOC); + $rubrics = array (); + foreach ($res as $row) + { + if ($row['c'] > 0) + { + $rubrics[$this->getRubricName ($row['parent_id'], $lang)][] = $row; + } + } + // print"
";
+        // print_r($rubrics);
+        // print"
"; + $this->tpl->assign ('brend_rubrics', $rubrics); + } + + function deleteBrend ($id) + { + $this->db->query ("delete from catalogs_brends where id=?", array ( + $id + )); + } + + function viewAkciiProductID ($id) + { + $sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?"; + $row = $this->db->getCol ($sql, "rubric_id", array ( + $id + )); + $this->tpl->assign ('product_akcii', $row); + } + + function import_saveRubric ($name, $parent_id) + { + $id = $this->db->getOne ("select id from catalogs_rubrics where name=? and parent_id=?", array ( + $name, + $parent_id + )); + if (! $id) + { + $this->db->autoExecute ("catalogs_rubrics", array ( + 'name' => $name, + 'translit' => translit ($name), + 'parent_id' => $parent_id, + "level" => ($this->getLevelRubric ($parent_id) + 1) + ), DB_AUTOQUERY_INSERT); + return mysql_insert_id (); + } + return $id; + } + + function import_saveBrend ($name, $rubric_id) + { + // getRubricParent(); + $id = $this->db->getOne ("select id from catalogs_brends where name=? and rubric_id=?", array ( + $name, + $rubric_id + )); + if (! $id) + { + $this->db->autoExecute ("catalogs_brends", array ( + 'rubric_id' => $rubric_id, + 'name' => $name + ), DB_AUTOQUERY_INSERT); + return mysql_insert_id (); + } + return $id; + } + + function import_saveFilters2 ($rubric_id, $str) + { + if (! $str) + return array (); + $row_str = explode (",", trim ($str)); + $arr_id = array (); + foreach ($row_str as $str) + { + $name = trim ($str); + $name_r = explode ('=', $name); + $name = $name_r[0]; + $active = (isset ($name_r[1])) ? 1 : 0; + $id = $this->db->getOne ("select id from catalogs_filters2 where rubric_id=? and name=?", array ( + $rubric_id, + $name + )); + if (! $id) + { + $this->db->autoExecute ("catalogs_filters2", array ( + 'rubric_id' => $rubric_id, + 'name' => $name, + 'prefix' => encodestring ($name), + 'active' => $active + ), DB_AUTOQUERY_INSERT); + $id = mysql_insert_id (); + } + else + { + $this->db->autoExecute ("catalogs_filters2", array ( + 'rubric_id' => $rubric_id, + 'name' => $name, + 'prefix' => encodestring ($name), + 'active' => $active + ), DB_AUTOQUERY_UPDATE, "id=$id"); + } + $arr_id[] = $id; + } + return $arr_id; + } + + function import_saveFilters ($rubric_id, $str) + { + if (! $str) + return array (); + $row_str = explode (",", trim ($str)); + $arr_id = array (); + foreach ($row_str as $str) + { + $name = trim ($str); + $name_r = explode ('=', $name); + $name = $name_r[0]; + $active = (isset ($name_r[1])) ? 1 : 0; + $id = $this->db->getOne ("select id from catalogs_filters where rubric_id=? and name=?", array ( + $rubric_id, + $name + )); + if (! $id) + { + $this->db->autoExecute ("catalogs_filters", array ( + 'rubric_id' => $rubric_id, + 'name' => $name, + 'prefix' => encodestring ($name), + 'active' => $active + ), DB_AUTOQUERY_INSERT); + $id = mysql_insert_id (); + } + else + { + $this->db->autoExecute ("catalogs_filters", array ( + 'rubric_id' => $rubric_id, + 'name' => $name, + 'prefix' => encodestring ($name), + 'active' => $active + ), DB_AUTOQUERY_UPDATE, "id=$id"); + } + $arr_id[] = $id; + } + return $arr_id; + } + + function import_saveYear ($rubric_id, $name) + { + if (! $name) + return false; + $id = $this->db->getOne ("select id from catalogs_years where rubric_id=? and name=?", array ( + $rubric_id, + $name + )); + if (! $id) + { + $this->db->autoExecute ("catalogs_years", array ( + 'rubric_id' => $rubric_id, + 'name' => $name + ), DB_AUTOQUERY_INSERT); + $id = mysql_insert_id (); + } + return ($id) ? array ( + $id + ) : array (); + } + + function import_updateProductCine ($product_id, $row, $line = '', $mktime = 0) + { // print"
";print_r($row);print"
"; + IF ($product_id > 0) + { + IF ($row[3] > 0) + { + if ($row[2] < 1) + { + $cine = $row[1]; + $cine_last = 0; + } + else + { + $cine = $row[2]; + $cine_last = (($row[1] > 0) ? $row[1] : $row[2]); + } + $this->db->autoExecute ("catalogs_products", array ( + 'cine' => $cine, + 'cine_last' => $cine_last + ), DB_AUTOQUERY_UPDATE, "id='$product_id'"); + } + + $city = trim ($row[4]); + if (! $city) + $city = " "; + // echo "OK(1) -
"; + if (strlen ($city) > 0) + { // print $city; + $city_id = $this->is_city ($city); + // echo "OK(2) -
"; + if (! $city_id) + { + $city_id = $this->SaveCity (array ( + 'name' => $city + )); + } + $this->db->query ("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktimedb->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime"; + if ($this->getKeysModificationCity ($row[0], $city_id)) + { + $DB_AUTOQUERY = DB_AUTOQUERY_UPDATE; + $where = "mod_code='" . $row[0] . "' and city_id='" . $city_id . "'"; + } + else + { + $DB_AUTOQUERY = DB_AUTOQUERY_INSERT; + $where = null; + } + + // if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;} + // print $city_id .'--'.$where."
"; + $fields = array ( + 'count' => $row[3], + 'product_id' => $product_id, + 'mod_code' => $row[0], + 'city_id' => $city_id, + 'mktime' => $mktime + ); + $s = $this->db->autoExecute ("catalogs_keys_products_cities", $fields, $DB_AUTOQUERY, $where); + if (PEAR::isError ($s)) + die ($s->getMessage ()); + } + } + // echo "OK(4) -
"; + $active = $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0", array ( + $row[0] + )); + // $active = true; + if ($this->db->getOne ("select count(*) from catalogs_modifications where code=?", array ( + $row[0] + )) > 0) + { + $this->db->autoExecute ("catalogs_modifications", array ( + 'active' => $active, + 'is_update' => 1, + 'prefix' => $row[4] + ), DB_AUTOQUERY_UPDATE, "code='" . $row[0] . "'"); + // echo "OK(5) -
"; + } + else + { + // echo "OK(6) -
"; + $this->saveCsvMod ($line); + } + } + } + + function saveCsvMod ($line) + { + echo "OK1 -
"; + $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv"; + $handle = @fopen ($tmpfname, "a"); + // $row = explode(";",$line); + // File_FGetCSV::fputcsv($handle,$row,';'); + echo "OK2 -
"; + echo $line; + echo "OK3 -
"; + fwrite ($handle, $line); + fclose ($handle); + } + + function getKeysModificationCity ($code, $city_id) + { + return $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array ( + $code, + $city_id + )); + } + + function getKeysModificationCity_count ($code, $city_id) + { + return $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array ( + $code, + $city_id + )); + } + + function getKeysModificationCityMktime_count ($code, $city_id, $mktime) + { + $r = $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array ( + $code, + $city_id, + $mktime + )); + return $r; + } + + function getProductID ($name) + { + $id = $this->db->getOne ("select id from catalogs_products where name=?", array ( + $name + )); + return $id; + } + + function getProductID_R ($name, $rubric_parent_id) + { + $id = $this->db->getOne ("select id from catalogs_products where name=? and rubric_id=?", array ( + $name, + $rubric_parent_id + )); + + return $id; + } + + function getModificationActive ($code) + { + return $this->db->getOne ("select active from catalogs_modifications where code=?", array ( + $code + )); + } + + function updateProduct_countModification ($product_id, $count) + { + $this->db->autoExecute ("catalogs_products", array ( 'count_modifications' => $count - ), DB_AUTOQUERY_UPDATE, "id='$product_id'"); -} - - function updateProductModificationCountPrefix($product_id,$prefix = "+"){ -// print $product_id; - $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?"; - $this->db->query($sql,array($product_id)); - } - - function exportCSV(){ - $tmpfname = "tmp/price.csv"; - $handle = fopen($tmpfname, "w"); - // fwrite($handle, $xml); - $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()); - foreach($res as $key=>$row){ - $list = $row; - $mod_res = $this->db->getAll('select code,size,color,pic_big,active from catalogs_modifications where product_id=? Order by id',array($row[0])); - foreach($mod_res as $mod_row){$list[] = implode('=',$mod_row);} - - $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])); - $list[8]=implode(',',$f_row); - - $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])); - $list[9]=implode(',',$f_row); - - switch($list[10]){ - case 1 : $list[10] = ''; break; - case 2 : $list[10] = ''; break; - case 3 : $list[10] = ''; break; - case 4 : $list[10] = ''; break; - default : $list[10] = ''; break; - } - - $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])); - $list[11]=implode(',',$y_row); - - $p_row = $this->db->getCol("select pic_big from catalogs_gallery where product_id=?",'pic_big',array($list[0])); - $list[20]=implode(',',$p_row); - - //print_r($list);exit; - $p_res = $this->db->getAll("select name,size,metka from catalogs_products_params where product_id=? order by id asc",array($list[0])); - $param = array(); - foreach($p_res as $row_p){ - $param[] = implode('*',$row_p); - } - $list[17] = implode('=',$param); - - unset($list[0]);unset($list[1]); - - File_FGetCSV::fputcsv($handle,$list,';'); - - - - } - - fclose($handle); - - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportCSVaktual(){ - $tmpfname = "tmp/price.csv"; - $handle = fopen($tmpfname, "w"); - // fwrite($handle, $xml); - $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()); - foreach($res as $key=>$row){ - $list = $row; - $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])); - 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);} - - $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])); - $list[8]=implode(',',$f_row); - - $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])); - $list[9]=implode(',',$f_row); - - switch($list[10]){ - case 1 : $list[10] = ''; break; - case 2 : $list[10] = ''; break; - case 3 : $list[10] = ''; break; - case 4 : $list[10] = ''; break; - default : $list[10] = ''; break; - } - - $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])); - $list[11]=implode(',',$y_row); - - $p_row = $this->db->getCol("select pic_big from catalogs_gallery where product_id=?",'pic_big',array($list[0])); - $list[20]=implode(',',$p_row); - - //print_r($list);exit; - $p_res = $this->db->getAll("select name,size,metka from catalogs_products_params where product_id=? order by id asc",array($list[0])); - $param = array(); - foreach($p_res as $row_p){ - $param[] = implode('*',$row_p); - } - $list[17] = implode('=',$param); - - unset($list[0]);unset($list[1]); - - File_FGetCSV::fputcsv($handle,$list,';'); - - - - } - - fclose($handle); - - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'price.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportModCSV(){ - $tmpfname = "tmp/price_mod.csv"; - $handle = fopen($tmpfname, "w"); - $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'); - foreach($res as $key=>$row){ - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'file_1.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - $this->db->autoExecute("catalogs_modifications",array('is_update'=>0),DB_AUTOQUERY_UPDATE); - } - - function exportUsersCSV(){ - $tmpfname = "tmp/users.csv"; - $handle = fopen($tmpfname, "w"); - - $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,summary,u.birthday,c.card + ), DB_AUTOQUERY_UPDATE, "id='$product_id'"); + } + + function updateProductModificationCountPrefix ($product_id, $prefix = "+") + { + // print $product_id; + $sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?"; + $this->db->query ($sql, array ( + $product_id + )); + } + + function exportCSV () + { + $tmpfname = "tmp/price.csv"; + $handle = fopen ($tmpfname, "w"); + // fwrite($handle, $xml); + $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 ()); + foreach ($res as $key => $row) + { + $list = $row; + $mod_res = $this->db->getAll ('select code,size,color,pic_big,active from catalogs_modifications where product_id=? Order by id', array ( + $row[0] + )); + foreach ($mod_res as $mod_row) + { + $list[] = implode ('=', $mod_row); + } + + $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] + )); + $list[8] = implode (',', $f_row); + + $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] + )); + $list[9] = implode (',', $f_row); + + switch ($list[10]) + { + case 1 : + $list[10] = ''; + break; + case 2 : + $list[10] = ''; + break; + case 3 : + $list[10] = ''; + break; + case 4 : + $list[10] = ''; + break; + default : + $list[10] = ''; + break; + } + + $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] + )); + $list[11] = implode (',', $y_row); + + $p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array ( + $list[0] + )); + $list[20] = implode (',', $p_row); + + // print_r($list);exit; + $p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array ( + $list[0] + )); + $param = array (); + foreach ($p_res as $row_p) + { + $param[] = implode ('*', $row_p); + } + $list[17] = implode ('=', $param); + + unset ($list[0]); + unset ($list[1]); + + File_FGetCSV::fputcsv ($handle, $list, ';'); + } + + fclose ($handle); + + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'price.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportCSVaktual () + { + $tmpfname = "tmp/price.csv"; + $handle = fopen ($tmpfname, "w"); + // fwrite($handle, $xml); + $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 ()); + foreach ($res as $key => $row) + { + $list = $row; + $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] + )); + 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); + } + + $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] + )); + $list[8] = implode (',', $f_row); + + $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] + )); + $list[9] = implode (',', $f_row); + + switch ($list[10]) + { + case 1 : + $list[10] = ''; + break; + case 2 : + $list[10] = ''; + break; + case 3 : + $list[10] = ''; + break; + case 4 : + $list[10] = ''; + break; + default : + $list[10] = ''; + break; + } + + $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] + )); + $list[11] = implode (',', $y_row); + + $p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array ( + $list[0] + )); + $list[20] = implode (',', $p_row); + + // print_r($list);exit; + $p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array ( + $list[0] + )); + $param = array (); + foreach ($p_res as $row_p) + { + $param[] = implode ('*', $row_p); + } + $list[17] = implode ('=', $param); + + unset ($list[0]); + unset ($list[1]); + + File_FGetCSV::fputcsv ($handle, $list, ';'); + } + + fclose ($handle); + + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'price.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportModCSV () + { + $tmpfname = "tmp/price_mod.csv"; + $handle = fopen ($tmpfname, "w"); + $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'); + foreach ($res as $key => $row) + { + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'file_1.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + $this->db->autoExecute ("catalogs_modifications", array ( + 'is_update' => 0 + ), DB_AUTOQUERY_UPDATE); + } + + function exportUsersCSV () + { + $tmpfname = "tmp/users.csv"; + $handle = fopen ($tmpfname, "w"); + + $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,summary,u.birthday,c.card FROM zlo_users AS u LEFT JOIN card c ON c.user_id = u.id LEFT JOIN zlo_users_group AS g ON u.group = g.id LEFT JOIN (SELECT user_id AS order_user_id, sum( `total` ) AS `summary` FROM catalogs_orders group by user_id ) o ON u.id = o.order_user_id "; - $res = $this->db->getAll($sql); - foreach($res as $key=>$row){ - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'users.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportUsersBirdthCSV(){ - $tmpfname = "tmp/usersBirdth.csv"; - $handle = fopen($tmpfname, "w"); - - $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,u.birthday,c.card + $res = $this->db->getAll ($sql); + foreach ($res as $key => $row) + { + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'users.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportUsersBirdthCSV () + { + $tmpfname = "tmp/usersBirdth.csv"; + $handle = fopen ($tmpfname, "w"); + + $sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,u.birthday,c.card FROM zlo_users AS u LEFT JOIN card c ON c.user_id = u.id LEFT JOIN zlo_users_group AS g ON u.group = g.id WHERE DAYOFMONTH(u.birthday) >= '19' AND DAYOFMONTH(u.birthday) <= '28' and MONTH(u.birthday) = '10' "; - $res = $this->db->getAll($sql); - foreach($res as $key=>$row){ - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'users.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportSeoF1CSV(){ - $tmpfname = "tmp/seo_f1.csv"; - $handle = fopen($tmpfname, "w"); - $res = $this->db->getAll("select id,name,translit,name_h1 from catalogs_rubrics"); - foreach($res as $key=>$row){ - //$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])); - //foreach($res_b as $row_b){ - $list = array(); - $f_res = $this->db->getAll("select id,prefix,name from catalogs_filters where rubric_id=?",array($row[0])); - foreach($f_res as $f_row){ - $list[0] = $row[0]; - $list[1] = (strlen($row[3])>0) ? $row[3] : $row[1]; - $list[2] = $f_row[2]; - $list[3] = "http://extremstyle.ua/".$row[2]."-catalogs/filter;filter=f".$f_row[0]."_".$f_row[1]."/"; - //$list[4] = $row_b[0]; - File_FGetCSV::fputcsv($handle,$list,';'); - } - //} - } - - - $res = $this->db->getAll("select id,name,translit,name_h1 from catalogs_rubrics"); - foreach($res as $key=>$row){ - //$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])); - //foreach($res_b as $row_b){ - $list = array(); - $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])); - foreach($f_res as $f_row){ - if(!strlen($f_row[0]))continue; - $list[0] = $row[0]; - $list[1] = (strlen($row[3])>0) ? $row[3] : $row[1]; - $list[2] = $f_row[0]; - $list[3] = "http://extremstyle.ua/".$row[2]."-catalogs/filter;brend=".$f_row[0]."/"; - //$list[4] = $row_b[0]; - File_FGetCSV::fputcsv($handle,$list,';'); - } - //} - } - - - - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'seo_f1.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportSeoCSV(){ - $tmpfname = "tmp/seo.csv"; - $handle = fopen($tmpfname, "w"); - $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'); - foreach($res as $key=>$row){ - $row[3] = $this->getFilterPh1($row[0]); - if(!strlen($row[2]))$row[2] = $row[11]; - $row[7] = "http://extremstyle.ua/".$row[9]."-catalogs/".$row[10]."-".$row[0]."/"; - unset($row[9]);unset($row[10]);unset($row[11]); - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'seo.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - - function exportProductsSeoCSV(){ - $tmpfname = "tmp/products_seo.csv"; - $handle = fopen($tmpfname, "w"); - $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')); - foreach($res as $key=>$row){ - $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",); - $row[3] = $this->getFilterPh1($row[2]) .' '. str_replace($vowels, "", $row[3]); - $row[8] = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/"; - unset($row[6]);unset($row[7]); - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'products_seo.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportProducts2SeoCSV(){ - $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/cron/products_seo.csv"; - $handle = fopen($tmpfname, "w"); - $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")'; - $res = $this->db->getAll($sql,array('Dakine')); - foreach($res as $key=>$row){ - $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",); - $row[3] = $this->getFilterPh1($row[2]) .' '. str_replace($vowels, "", $row[3]); - $row[8] = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/"; - unset($row[5]);unset($row[6]);unset($row[7]); - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - - } - - function exportProductsFeed(){ - $tmpfname = "tmp/products_feed.csv"; - $handle = fopen($tmpfname, "w"); - $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'; - $res = $this->db->getAll($sql,array()); - $list = array('ID','ID2','Item title','Destination URL','Image URL','Item subtitle','Item description','Item category','Price','Sale price','Contextual keywords','Item address'); - File_FGetCSV::fputcsv($handle,$list,','); - foreach($res as $key=>$row){ - $url = "http://extremstyle.ua/".$row[5]."-catalogs/".$row[6]."-".$row[2]."/"; - $image = "http://extremstyle.ua/uploaded/pic/catalogs/products/".$row[8]; - $subtitle = $row[1].' '.$row[9]; - $list = array( - $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], - ); - //print_r($list); - unset($row[5]);unset($row[6]);unset($row[7]); - File_FGetCSV::fputcsv($handle,$list,','); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'products_feed.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function exportOrdersCSV(){ - $tmpfname = "tmp/orders.csv"; - $handle = fopen($tmpfname, "w"); - $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'); - foreach($res as $key=>$row){ - $products = $this->db->getAll("select p.* from catalogs_orders_products op + $res = $this->db->getAll ($sql); + foreach ($res as $key => $row) + { + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'users.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportSeoF1CSV () + { + $tmpfname = "tmp/seo_f1.csv"; + $handle = fopen ($tmpfname, "w"); + $res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics"); + foreach ($res as $key => $row) + { + // $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])); + // foreach($res_b as $row_b){ + $list = array (); + $f_res = $this->db->getAll ("select id,prefix,name from catalogs_filters where rubric_id=?", array ( + $row[0] + )); + foreach ($f_res as $f_row) + { + $list[0] = $row[0]; + $list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1]; + $list[2] = $f_row[2]; + $list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;filter=f" . $f_row[0] . "_" . $f_row[1] . "/"; + // $list[4] = $row_b[0]; + File_FGetCSV::fputcsv ($handle, $list, ';'); + } + // } + } + + $res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics"); + foreach ($res as $key => $row) + { + // $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])); + // foreach($res_b as $row_b){ + $list = array (); + $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] + )); + foreach ($f_res as $f_row) + { + if (! strlen ($f_row[0])) + continue; + $list[0] = $row[0]; + $list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1]; + $list[2] = $f_row[0]; + $list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;brend=" . $f_row[0] . "/"; + // $list[4] = $row_b[0]; + File_FGetCSV::fputcsv ($handle, $list, ';'); + } + // } + } + + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'seo_f1.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportSeoCSV () + { + $tmpfname = "tmp/seo.csv"; + $handle = fopen ($tmpfname, "w"); + $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'); + foreach ($res as $key => $row) + { + $row[3] = $this->getFilterPh1 ($row[0]); + if (! strlen ($row[2])) + $row[2] = $row[11]; + $row[7] = "http://extremstyle.ua/" . $row[9] . "-catalogs/" . $row[10] . "-" . $row[0] . "/"; + unset ($row[9]); + unset ($row[10]); + unset ($row[11]); + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'seo.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportProductsSeoCSV () + { + $tmpfname = "tmp/products_seo.csv"; + $handle = fopen ($tmpfname, "w"); + $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' + )); + foreach ($res as $key => $row) + { + $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" + ); + $row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]); + $row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/"; + unset ($row[6]); + unset ($row[7]); + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'products_seo.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportProducts2SeoCSV () + { + $tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/cron/products_seo.csv"; + $handle = fopen ($tmpfname, "w"); + $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")'; + $res = $this->db->getAll ($sql, array ( + 'Dakine' + )); + foreach ($res as $key => $row) + { + $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" + ); + $row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]); + $row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/"; + unset ($row[5]); + unset ($row[6]); + unset ($row[7]); + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + } + + function exportProductsFeed () + { + $tmpfname = "tmp/products_feed.csv"; + $handle = fopen ($tmpfname, "w"); + $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'; + $res = $this->db->getAll ($sql, array ()); + $list = array ( + 'ID', + 'ID2', + 'Item title', + 'Destination URL', + 'Image URL', + 'Item subtitle', + 'Item description', + 'Item category', + 'Price', + 'Sale price', + 'Contextual keywords', + 'Item address' + ); + File_FGetCSV::fputcsv ($handle, $list, ','); + foreach ($res as $key => $row) + { + $url = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/"; + $image = "http://extremstyle.ua/uploaded/pic/catalogs/products/" . $row[8]; + $subtitle = $row[1] . ' ' . $row[9]; + $list = array ( + $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] + ); + // print_r($list); + unset ($row[5]); + unset ($row[6]); + unset ($row[7]); + File_FGetCSV::fputcsv ($handle, $list, ','); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'products_feed.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function exportOrdersCSV () + { + $tmpfname = "tmp/orders.csv"; + $handle = fopen ($tmpfname, "w"); + $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'); + foreach ($res as $key => $row) + { + $products = $this->db->getAll ("select p.* from catalogs_orders_products op LEFT JOIN catalogs_modifications m ON m.code=op.code LEFT JOIN catalogs_products p ON p.id=m.product_id - where op.order_id=? GROUP BY p.id",array($row[0]),DB_FETCHMODE_ASSOC); - $arr_products = array(); - foreach($products as $p){ - $arr_products[] = $p['name']; - } - $row[6] = implode(', ',$arr_products); - File_FGetCSV::fputcsv($handle,$row,';'); - } - fclose($handle); - $params = array( - 'file' => $tmpfname, - 'contenttype' => 'application/xls', - 'contentdisposition' => array(HTTP_DOWNLOAD_ATTACHMENT, 'orders.csv'), - 'cache' => false - ); - $error = HTTP_Download::staticSend($params, false); // - if ($error === true) { - // , - } - - unlink($tmpfname); - } - - function deleteProductParams($product_id){ - $sql = "delete from catalogs_products_params where product_id=?"; - $this->db->query($sql,array($product_id)); - } - - function saveProductParams($product_id,$pruduct_params){ - $this->deleteProductParams($product_id); - $array_params = explode("=",$pruduct_params); - foreach($array_params as $row){ - $arr = explode('*',$row); - $this->db->autoExecute("catalogs_products_params",array('product_id'=>$product_id,'name'=>$arr[0],'size'=>$arr[1],'metka'=>$arr[2]),DB_AUTOQUERY_INSERT); - } - } - - function getProductParams($product_id){ - $sql = "select * from catalogs_products_params where product_id=? order by id"; - $row = $this->db->getAll($sql,array($product_id),DB_FETCHMODE_ASSOC); - return $row; - } - - function viewProductParams($product_id){ - $this->tpl->assign('params',$this->getProductParams($product_id)); - } - -/** - * - */ -function saveTmpProduct ($row, $product_id) -{ - if ($product_id > 0) + where op.order_id=? GROUP BY p.id", array ( + $row[0] + ), DB_FETCHMODE_ASSOC); + $arr_products = array (); + foreach ($products as $p) + { + $arr_products[] = $p['name']; + } + $row[6] = implode (', ', $arr_products); + File_FGetCSV::fputcsv ($handle, $row, ';'); + } + fclose ($handle); + $params = array ( + 'file' => $tmpfname, + 'contenttype' => 'application/xls', + 'contentdisposition' => array ( + HTTP_DOWNLOAD_ATTACHMENT, + 'orders.csv' + ), + 'cache' => false + ); + $error = HTTP_Download::staticSend ($params, false); // + if ($error === true) + { + // , + } + + unlink ($tmpfname); + } + + function deleteProductParams ($product_id) + { + $sql = "delete from catalogs_products_params where product_id=?"; + $this->db->query ($sql, array ( + $product_id + )); + } + + function saveProductParams ($product_id, $pruduct_params) + { + $this->deleteProductParams ($product_id); + $array_params = explode ("=", $pruduct_params); + foreach ($array_params as $row) + { + $arr = explode ('*', $row); + $this->db->autoExecute ("catalogs_products_params", array ( + 'product_id' => $product_id, + 'name' => $arr[0], + 'size' => $arr[1], + 'metka' => $arr[2] + ), DB_AUTOQUERY_INSERT); + } + } + + function getProductParams ($product_id) + { + $sql = "select * from catalogs_products_params where product_id=? order by id"; + $row = $this->db->getAll ($sql, array ( + $product_id + ), DB_FETCHMODE_ASSOC); + return $row; + } + + function viewProductParams ($product_id) + { + $this->tpl->assign ('params', $this->getProductParams ($product_id)); + } + + /** + * + */ + + function saveTmpProduct ($row, $product_id) + { + if ($product_id > 0) + { + $this->db->autoExecute ("catalogs_tmp_products", array ( + 'name' => $row[3], + 'product_id' => $product_id + ), DB_AUTOQUERY_INSERT); + } + } + + function clearTmpProduct () + { + $sql = "TRUNCATE TABLE catalogs_tmp_products"; + $this->db->query ($sql, array ()); + } + + function viewTmpProducts () + { + $sql = " + SELECT count( name ) AS cn, name + FROM catalogs_tmp_products + GROUP BY name + ORDER BY name"; + $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); + $this->tpl->assign ('list', $row); + $this->tpl->assign ('list_total', $this->db->getOne (" + select count(*) + from catalogs_tmp_products + ")); + } + + function deleteGalleryProduct ($id) + { + $sql = "select * from catalogs_gallery where product_id=?"; + $res = $this->db->getAll ($sql, array ( + $id + ), DB_FETCHMODE_ASSOC); + foreach ($res as $row) + { + @unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}"); + $this->db->query ("delete from catalogs_gallery where id=?", array ( + $row['id'] + )); + } + } + + function saveGalleryPics ($product_id, $pruduct_gallery_pics) + { + $this->deleteGalleryProduct ($product_id); + if (strlen ($pruduct_gallery_pics) > 0) + { + $arr = explode (",", $pruduct_gallery_pics); + foreach ($arr as $pic) + { + $pic = trim ($pic); + $id = $this->db->nextId ('mySequence_catalogs_gallery'); + $fields_values = array ( + 'id' => $id, + 'name' => $pic, + 'product_id' => $product_id + ); + $upload['pic'] = array ( + 'tmp_name' => "./uploaded/pic/catalogs/products/big/$pic", + 'name' => $pic + ); + $fields_values['pic'] = upload_ImageResize ($upload['pic'], array ( + 'width' => "100", + 'height' => "100", + 'upload_path' => "./uploaded/pic/catalogs/products/gallery/" + )); + $fields_values['pic_big'] = $pic; + + $this->db->autoExecute ("catalogs_gallery", $fields_values, DB_AUTOQUERY_INSERT); + } + } + } + + function importCSV ($upload) { - $this->db->autoExecute ("catalogs_tmp_products", array ( - 'name' => $row [3], - 'product_id' => $product_id - ), DB_AUTOQUERY_INSERT); + error_reporting (0); + + if ($upload['file']['name'] == "file_1.csv") + { + print "! !"; + exit (); + } + + // $arr_line = file($upload['file']['tmp_name']); + $f = fopen ($upload['file']['tmp_name'], "r") or die ("!"); + + // print"
";
+        
+        $this->clearTmpProduct ();
+        
+        for ($i = 0; $row_line = File_FGetCSV::fgetcsv ($f, 15000, ";"); $i ++)
+        {
+            // foreach($arr_line as $line){
+            // $row_line = fgetcsv(";",$line);
+            $rubric_id = $this->import_saveRubric ($row_line[0], 0);
+            $rubric_parent_id = $this->import_saveRubric ($row_line[1], $rubric_id);
+            $brend_id = $this->import_saveBrend ($row_line[2], $rubric_parent_id);
+            $pruduct_name = trim ($row_line[3]);
+            $pruduct_about = trim ($row_line[4]);
+            $pruduct_text = trim ($row_line[5]);
+            $sex = explode (',', $row_line[8]);
+            $pruduct_sex = array ();
+            
+            foreach ($sex as $s)
+            {
+                switch (trim ($s))
+                {
+                    case '' :
+                        $pruduct_sex[] = 1;
+                        break;
+                    case '' :
+                        $pruduct_sex[] = 2;
+                        break;
+                    case '' :
+                        $pruduct_sex[] = 3;
+                        break;
+                    case '' :
+                        $pruduct_sex[] = 4;
+                        break;
+                    default :
+                        $pruduct_sex[] = array ();
+                        break;
+                }
+            }
+            
+            $pruduct_date = trim ($row_line[9]);
+            $pruduct_cine = trim ($row_line[10]);
+            $pruduct_cine_last = trim ($row_line[11]);
+            
+            if ($pruduct_cine < 1)
+            {
+                $pruduct_cine = $pruduct_cine_last;
+                $pruduct_cine_last = 0;
+            }
+            
+            $pruduct_akcii_id = trim ($row_line[12]);
+            $pruduct_strnumber = trim ($row_line[13]);
+            $pruduct_active = trim ($row_line[14]);
+            $pruduct_params = trim ($row_line[15]);
+            $pruduct_pic_tmp = trim ($row_line[17]);
+            $pruduct_gallery_pics = trim ($row_line[18]);
+            $pruduct_video = trim ($row_line[16]);
+            $pruduct_update_id = $this->getProductID_R ($pruduct_name, $rubric_parent_id);
+            
+            if ($pruduct_update_id > 0)
+            {
+                $row_product = $this->db->getRow ('
+                select update_text, about, text
+                from catalogs_products
+                where id=?', array (
+                    $pruduct_update_id 
+                ), DB_FETCHMODE_ASSOC);
+                
+                //    ?
+                // 0 - 
+                // 1 -  
+                if ($row_product['update_text'] == 1)
+                {
+                    // about - ukr
+                    $pruduct_about = $row_product['about'];
+                    
+                    // text - ru
+                    $pruduct_text = $row_product['text'];
+                }
+            }
+            
+            $upload_pruduct = (strlen ($pruduct_pic_tmp) > 0 && is_file ("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp")) ? array (
+                'pic' => array (
+                    'tmp_name' => "./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",
+                    'name' => $pruduct_pic_tmp,
+                    'big' => true 
+                ) 
+            ) : null;
+            
+            $product_id = $this->saveProduct (array (
+                'rubric_id' => $rubric_parent_id,
+                'rubric_parent_id' => $rubric_parent_id,
+                'brend_id' => $brend_id,
+                'name' => $pruduct_name,
+                'about' => $pruduct_about,
+                'update_text' => isset ($row_product['update_text']) ? $row_product['update_text'] : 0,
+                'text' => $pruduct_text,
+                'video_code' => $pruduct_video,
+                'sex' => $pruduct_sex,
+                'date' => $pruduct_date,
+                'cine' => $pruduct_cine,
+                'cine_last' => $pruduct_cine_last,
+                'akcii_id' => $pruduct_akcii_id,
+                'strnumber' => $pruduct_strnumber,
+                'active' => $pruduct_active,
+                'meta_title' => $pruduct_name,
+                'meta_description' => $pruduct_name,
+                'meta_keywords' => $pruduct_name,
+                'meta_about' => $pruduct_name,
+                'filter' => $this->import_saveFilters ($rubric_parent_id, $row_line[6]),
+                'filter2' => $this->import_saveFilters2 ($rubric_parent_id, $row_line[7]),
+                'years' => $this->import_saveYear ($rubric_parent_id, $pruduct_date),
+                'akcii' => array (),
+                'update_id' => $pruduct_update_id 
+            ), $upload_pruduct);
+            
+            // print $pruduct_update_id;exit;
+            $this->saveProductParams ($product_id, $pruduct_params);
+            $this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
+            //   !
+            // $this->deleteProductModifications ($product_id, true);
+            $m_i = 0;
+            
+            for ($i = 19; $i < count ($row_line); $i ++)
+            {
+                $arr_mod = trim ($row_line[$i]);
+                
+                if (strlen ($arr_mod) > 0)
+                {
+                    $row_mod = explode ("=", $arr_mod);
+                    
+                    $upload_mod = (strlen ($row_mod[3]) > 0 && is_file ("./uploaded/pic/catalogs/modifications/big/" . $row_mod[3])) ? array (
+                        'pic' => array (
+                            'tmp_name' => "./uploaded/pic/catalogs/modifications/big/" . $row_mod[3],
+                            'name' => $row_mod[3],
+                            'big' => true 
+                        ) 
+                    ) : null;
+                    
+                    $size_mod = explode ("*", $row_mod[1]);
+                    $rost = (isset ($size_mod[1])) ? $size_mod[1] : '';
+                    
+                    //  modifications_id
+                    $modifications_id = $this->getModification ($product_id, $row_mod[0]);
+                    
+                    // 
+                    $this->SaveModification (array (
+                        'product_id' => $product_id,
+                        'code' => $row_mod[0],
+                        'size' => $size_mod[0],
+                        'rost' => $rost,
+                        'color' => $row_mod[2],
+                        'active' => $row_mod[4],
+                        'update_id' => (int) $modifications_id 
+                    ), $upload_mod);
+                    
+                    if ($row_mod[4] > 0)
+                    {
+                        $m_i ++;
+                    }
+                }
+            }
+            
+            $this->updateProduct_countModification ($product_id, $m_i);
+            
+            // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);
+            // $strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data);
+            // print_r($row_line);
+            
+            $this->saveTmpProduct ($row_line, $product_id);
+            if (($i % 30) == 0)
+            {
+                sleep (1);
+            }
+        }
+        // print"
"; } -} - -function clearTmpProduct () -{ - $sql = "TRUNCATE TABLE catalogs_tmp_products"; - $this->db->query ($sql, array ()); -} - -function viewTmpProducts () -{ - $sql = " - SELECT count( name ) AS cn, name - FROM catalogs_tmp_products - GROUP BY name - ORDER BY name"; - $row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC); - $this->tpl->assign ('list', $row); - $this->tpl->assign ('list_total', $this->db->getOne (" - select count(*) - from catalogs_tmp_products - ")); -} - - function deleteGalleryProduct($id){ - $sql = "select * from catalogs_gallery where product_id=?"; - $res = $this->db->getAll($sql,array($id),DB_FETCHMODE_ASSOC); - foreach($res as $row){ - @unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}"); - $this->db->query("delete from catalogs_gallery where id=?",array($row['id'])); + + function importCSV_cine ($upload) + { + if ($upload['file']['name'] != "file_1.csv") + { + print "! file_1.csv"; + exit (); } - } - - function saveGalleryPics($product_id,$pruduct_gallery_pics){ - $this->deleteGalleryProduct($product_id); - if(strlen($pruduct_gallery_pics)>0){ - $arr = explode(",",$pruduct_gallery_pics); - foreach($arr as $pic){ - $pic = trim($pic); - $id = $this->db->nextId('mySequence_catalogs_gallery'); - $fields_values = array('id'=>$id,'name' => $pic,'product_id' => $product_id); - $upload['pic'] = array('tmp_name'=>"./uploaded/pic/catalogs/products/big/$pic",'name'=>$pic); - $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"100",'height'=>"100",'upload_path'=>"./uploaded/pic/catalogs/products/gallery/")); - $fields_values['pic_big'] = $pic; - - $this->db->autoExecute("catalogs_gallery",$fields_values,DB_AUTOQUERY_INSERT); + + $arr_line = file ($upload['file']['tmp_name']); + + // print"
";
+        $i = 0;
+        $mktime = mktime ();
+        foreach ($arr_line as $line)
+        {
+            $row_line = explode (";", $line);
+            $this->import_updateProductCine ($this->getModificationProduct_id ($row_line[0]), $row_line, $line, $mktime);
+            
+            if (($i % 30) == 0)
+            {
+                sleep (1);
+            }
+            
+            $i ++;
         }
+    }
+    
+    function loadCSV_cine ($upload)
+    {
+        if ($upload['file']['name'] != "file_1.csv")
+        {
+            print "!  file_1.csv";
+            exit ();
         }
- }
-
- function importCSV ($upload)
- {
-     error_reporting (0);
- 
-     if ($upload['file']['name'] == "file_1.csv")
-     {
-         print "!  !";
-         exit ();
-     }
- 
-     // $arr_line = file($upload['file']['tmp_name']);
-     $f = fopen ($upload['file']['tmp_name'], "r") or die ("!");
- 
-     // print"
";
- 
-     $this->clearTmpProduct();
- 
-     for ($i = 0; $row_line = File_FGetCSV::fgetcsv ($f, 15000, ";"); $i ++)
-     {
-         // foreach($arr_line as $line){
-         // $row_line = fgetcsv(";",$line);
-         $rubric_id = $this->import_saveRubric ($row_line [0], 0);
-         $rubric_parent_id = $this->import_saveRubric ($row_line [1], $rubric_id);
-         $brend_id = $this->import_saveBrend ($row_line [2], $rubric_parent_id);
-         $pruduct_name = trim ($row_line [3]);
-         $pruduct_about = trim ($row_line [4]);
-         $pruduct_text = trim ($row_line [5]);
-         $sex = explode (',', $row_line [8]);
-         $pruduct_sex = array ();
- 
-         foreach ($sex as $s)
-         {
-             switch (trim ($s))
-             {
-                 case '' :
-                     $pruduct_sex [] = 1;
-                     break;
-                 case '' :
-                     $pruduct_sex [] = 2;
-                     break;
-                 case '' :
-                     $pruduct_sex [] = 3;
-                     break;
-                 case '' :
-                     $pruduct_sex [] = 4;
-                     break;
-                 default :
-                     $pruduct_sex [] = array ();
-                     break;
-             }
-         }
-  
-         $pruduct_date = trim ($row_line [9]);
-         $pruduct_cine = trim ($row_line [10]);
-         $pruduct_cine_last = trim ($row_line [11]);
- 
-         if ($pruduct_cine < 1)
-         {
-             $pruduct_cine = $pruduct_cine_last;
-             $pruduct_cine_last = 0;
-         }
- 
-         $pruduct_akcii_id = trim ($row_line [12]);
-         $pruduct_strnumber = trim ($row_line [13]);
-         $pruduct_active = trim ($row_line [14]);
-         $pruduct_params = trim ($row_line [15]);
-         $pruduct_pic_tmp = trim ($row_line [17]);
-         $pruduct_gallery_pics = trim ($row_line [18]);
-         $pruduct_video = trim ($row_line [16]);
-         $pruduct_update_id = $this->getProductID_R ($pruduct_name, $rubric_parent_id);
- 
-         if ($pruduct_update_id > 0)
-         {
-             $row_product = $this->db->getRow ('
-                select update_text, about, text
-                from catalogs_products
-                where id=?', array (
-                     $pruduct_update_id
-                 ),
-                 DB_FETCHMODE_ASSOC
-             );
-
-             //    ?
-             // 0 - 
-             // 1 -  
-             if ($row_product['update_text'] == 1)
-             {  
-                 // about - ukr
-                 $pruduct_about = $row_product['about'];
-                 
-                 // text - ru
-                 $pruduct_text = $row_product['text'];
-             } 
-         }
- 
-         $upload_pruduct = (strlen ($pruduct_pic_tmp) > 0 && is_file ("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp")) ? array (
-             'pic' => array (
-                 'tmp_name' => "./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",
-                 'name' => $pruduct_pic_tmp,
-                 'big' => true
-             )
-         ) : null;
- 
-         $product_id = $this->saveProduct (array (
-             'rubric_id' => $rubric_parent_id,
-             'rubric_parent_id' => $rubric_parent_id,
-             'brend_id' => $brend_id,
-             'name' => $pruduct_name,
-             'about' => $pruduct_about,
-             'update_text' => isset ($row_product['update_text']) ? $row_product['update_text'] : 0,
-             'text' => $pruduct_text,
-             'video_code' => $pruduct_video,
-             'sex' => $pruduct_sex,
-             'date' => $pruduct_date,
-             'cine' => $pruduct_cine,
-             'cine_last' => $pruduct_cine_last,
-             'akcii_id' => $pruduct_akcii_id,
-             'strnumber' => $pruduct_strnumber,
-             'active' => $pruduct_active,
-             'meta_title' => $pruduct_name,
-             'meta_description' => $pruduct_name,
-             'meta_keywords' => $pruduct_name,
-             'meta_about' => $pruduct_name,
-             'filter' => $this->import_saveFilters ($rubric_parent_id, $row_line [6]),
-             'filter2' => $this->import_saveFilters2 ($rubric_parent_id, $row_line [7]),
-             'years' => $this->import_saveYear ($rubric_parent_id, $pruduct_date),
-             'akcii' => array (),
-             'update_id' => $pruduct_update_id
-         ), $upload_pruduct);
- 
-         // print $pruduct_update_id;exit;
-         $this->saveProductParams ($product_id, $pruduct_params);
-         $this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
-         //   !
-         //$this->deleteProductModifications ($product_id, true);
-         $m_i = 0;
- 
-         for ($i = 19; $i < count ($row_line); $i ++)
-         {
-             $arr_mod = trim ($row_line [$i]);
- 
-             if (strlen ($arr_mod) > 0)
-             {
-                 $row_mod = explode ("=", $arr_mod);
- 
-                 $upload_mod = (strlen ($row_mod [3]) > 0 && is_file ("./uploaded/pic/catalogs/modifications/big/" . $row_mod [3])) ? array (
-                     'pic' => array (
-                         'tmp_name' => "./uploaded/pic/catalogs/modifications/big/" . $row_mod [3],
-                         'name' => $row_mod [3],
-                         'big' => true
-                     )
-                 ) : null;
- 
-                 $size_mod = explode ("*", $row_mod [1]);
-                 $rost = (isset ($size_mod [1])) ? $size_mod [1] : '';
-                 
-                 //  modifications_id
-                 $modifications_id = $this->getModification($product_id, $row_mod[0]);  
-
-                 // 
-                 $this->SaveModification (array (
-                     'product_id' => $product_id,
-                     'code' => $row_mod [0],
-                     'size' => $size_mod [0],
-                     'rost' => $rost,
-                     'color' => $row_mod [2],
-                     'active' => $row_mod [4],
-                     'update_id' => (int)$modifications_id
-                 ), $upload_mod); 
- 
-                 if ($row_mod[4] > 0)
-                 {
-                     $m_i ++;
-                 }
-             }
-         }
-
-         $this->updateProduct_countModification ($product_id, $m_i);
- 
-         // $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);
-         // $strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data);
-         // print_r($row_line);
- 
-         $this->saveTmpProduct ($row_line, $product_id);
-         if (($i % 30) == 0)
-         {
-             sleep (1);
-         }
-     }
-     // print"
"; - } - - function importCSV_cine ($upload) - { - if ($upload['file']['name'] != "file_1.csv") - { - print "! file_1.csv"; - exit; - } - - $arr_line = file ($upload['file']['tmp_name']); - - //print"
";
-     $i = 0;
-     $mktime = mktime();
-     foreach ($arr_line as $line)
-     {
-         $row_line = explode (";", $line);
-         $this->import_updateProductCine($this->getModificationProduct_id ($row_line[0]), $row_line, $line, $mktime);
- 
-         if (($i % 30) == 0)
-         {
-             sleep (1);
-         }
- 
-         $i++;
-     }
-}
-
-function loadCSV_cine($upload)
-{
-    if ($upload['file']['name'] != "file_1.csv")
+        
+        $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv";
+        
+        // echo $file;
+        // exit;
+        
+        move_uploaded_file ($upload['file']['tmp_name'], $file);
+    }
+    
+    function is_loadCSV_cine ()
     {
-        print "!  file_1.csv";
-        exit;
+        $is = is_file ($_SERVER['DOCUMENT_ROOT'] . '/cron/file_1.csv');
+        $this->tpl->assign ('is', $is);
     }
     
-    $file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv";
-
-    //echo $file;
-    //exit;
-
-    move_uploaded_file ($upload['file']['tmp_name'], $file);
-}
-  
-function is_loadCSV_cine()
-{
-    $is = is_file($_SERVER['DOCUMENT_ROOT'] . '/cron/file_1.csv');
-    $this->tpl->assign('is', $is);
-}
- 
-function CronImportCSV_cine($upload)
-{
-    $this->importCSV_cine ($upload);
-}
- 
-function updateCountModificationProducts ()
-{
-    $res = $this->db->getAll("
+    function CronImportCSV_cine ($upload)
+    {
+        $this->importCSV_cine ($upload);
+    }
+    
+    function updateCountModificationProducts ()
+    {
+        $res = $this->db->getAll ("
        select id
        from catalogs_products
     ", array (), DB_FETCHMODE_ASSOC);
- 
-    $i = 0;
- 
-    foreach ($res as $row)
-    {
-        $count = $this->db->getOne ("
+        
+        $i = 0;
+        
+        foreach ($res as $row)
+        {
+            $count = $this->db->getOne ("
            select count(*)
            from catalogs_modifications
            where product_id=? and active>0", array (
-               $row['id']
-           )
-        );
- 
-        $this->db->autoExecute ("catalogs_products", array (
-           'count_modifications' => $count
-        ), DB_AUTOQUERY_UPDATE, "id='" . $row['id'] . "'");
- 
-        $i ++;
+                $row['id'] 
+            ));
+            
+            $this->db->autoExecute ("catalogs_products", array (
+                'count_modifications' => $count 
+            ), DB_AUTOQUERY_UPDATE, "id='" . $row['id'] . "'");
+            
+            $i ++;
+        }
     }
-}
- 
- function config_update($id,$value){
-  $this->db->autoExecute("catalogs_config",array('value'=>$value),DB_AUTOQUERY_UPDATE,"id='".$id."'");
- }
- 
- function view_config_value($id){
-  $r = $this->db->getOne("select value from catalogs_config where id=?",$id);
-  $this->tpl->assign("config",$r);
-  return $r;
- }
- 
- function addViewProduct($product_id){
+    
+    function config_update ($id, $value)
+    {
+        $this->db->autoExecute ("catalogs_config", array (
+            'value' => $value 
+        ), DB_AUTOQUERY_UPDATE, "id='" . $id . "'");
+    }
+    
+    function view_config_value ($id)
+    {
+        $r = $this->db->getOne ("select value from catalogs_config where id=?", $id);
+        $this->tpl->assign ("config", $r);
+        return $r;
+    }
+    
+    function addViewProduct ($product_id)
+    {
         $i = 0;
-        foreach($_SESSION['view_product'] as $id){
-                if($product_id==$id)$i++;
+        foreach ($_SESSION['view_product'] as $id)
+        {
+            if ($product_id == $id)
+                $i ++;
         }
-        if($i==0)$_SESSION['view_product'][] = $product_id;
- }
- 
- function viewUserProducts($limit = "all"){ //unset($_SESSION['view_product']);
-  if(isset($_SESSION['view_product']) && count($_SESSION['view_product'])>0){        
-  $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+        if ($i == 0)
+            $_SESSION['view_product'][] = $product_id;
+    }
+    
+    function viewUserProducts ($limit = "all")
+    { // unset($_SESSION['view_product']);
+        if (isset ($_SESSION['view_product']) && count ($_SESSION['view_product']) > 0)
+        {
+            $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
-  WHERE catalogs_products.id IN (".implode(",",$_SESSION['view_product']).") ";
-  if($limit != "all")$sql .= "LIMIT ".$limit;
-  $res = $this->db->getAll($sql,array(),DB_FETCHMODE_ASSOC);
-  $this->tpl->assign("products_view",$res);
-  }
- }
- 
- function viewSimilarProducts($product_id,$brend,$rubric_id,$mods){
-	IF($brend == 'Dakine'){
-		$rub_arr = array(14071,14069,14070,14072);
-		unset($rub_arr[array_search('rubric_id', $rub_arr)]);
-		
-		if(count($mods)>1){
-			$r = array();
-			foreach($mods as $key=>$mod){
-	$r[$key]['color'] = 	$mod['color'];		
-	$row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
-	$sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+  WHERE catalogs_products.id IN (" . implode (",", $_SESSION['view_product']) . ") ";
+            if ($limit != "all")
+                $sql .= "LIMIT " . $limit;
+            $res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
+            $this->tpl->assign ("products_view", $res);
+        }
+    }
+    
+    function viewSimilarProducts ($product_id, $brend, $rubric_id, $mods)
+    {
+        IF ($brend == 'Dakine')
+        {
+            $rub_arr = array (
+                14071,
+                14069,
+                14070,
+                14072 
+            );
+            unset ($rub_arr[array_search ('rubric_id', $rub_arr)]);
+            
+            if (count ($mods) > 1)
+            {
+                $r = array ();
+                foreach ($mods as $key => $mod)
+                {
+                    $r[$key]['color'] = $mod['color'];
+                    $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
+                        $product_id 
+                    ), DB_FETCHMODE_ASSOC);
+                    $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
   LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
-  WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cinedb->getAll($sql,array($row['cine'],$brend,$mod['color']),DB_FETCHMODE_ASSOC);
-  
-	
-	$sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+  WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cinedb->getAll ($sql, array (
+                        $row['cine'],
+                        $brend,
+                        $mod['color'] 
+                    ), DB_FETCHMODE_ASSOC);
+                    
+                    $sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
   LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
-  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";
-  $r[$key]["products_similar_next"] = $this->db->getAll($sql,array($row['cine'],$brend,$mod['color']),DB_FETCHMODE_ASSOC);
-  				
-				
-			}
-//print_r($r);
-$this->tpl->assign("products_similar",$r);			
-		}
-		else{
-		
-	$row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
-	$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+  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";
+                    $r[$key]["products_similar_next"] = $this->db->getAll ($sql, array (
+                        $row['cine'],
+                        $brend,
+                        $mod['color'] 
+                    ), DB_FETCHMODE_ASSOC);
+                }
+                // print_r($r);
+                $this->tpl->assign ("products_similar", $r);
+            }
+            else
+            {
+                
+                $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
+                    $product_id 
+                ), DB_FETCHMODE_ASSOC);
+                $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
-  WHERE catalogs_products.rubric_id IN (".implode(',',$rub_arr).") and catalogs_products.count_modifications>0 and catalogs_products.cinedb->getAll($sql,array($row['cine'],$brend),DB_FETCHMODE_ASSOC);
-  $this->tpl->assign("products_similar_prev",$res);
-	
-	$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+  WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cinedb->getAll ($sql, array (
+                    $row['cine'],
+                    $brend 
+                ), DB_FETCHMODE_ASSOC);
+                $this->tpl->assign ("products_similar_prev", $res);
+                
+                $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
-  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";
-  $res = $this->db->getAll($sql,array($row['cine'],$brend),DB_FETCHMODE_ASSOC);
-  $this->tpl->assign("products_similar_next",$res);		
-		}
-	} else{
-	$row = $this->db->getRow("select * from catalogs_products where id=?",array($product_id),DB_FETCHMODE_ASSOC);
-	$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+  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";
+                $res = $this->db->getAll ($sql, array (
+                    $row['cine'],
+                    $brend 
+                ), DB_FETCHMODE_ASSOC);
+                $this->tpl->assign ("products_similar_next", $res);
+            }
+        }
+        else
+        {
+            $row = $this->db->getRow ("select * from catalogs_products where id=?", array (
+                $product_id 
+            ), DB_FETCHMODE_ASSOC);
+            $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
   WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cinedb->getAll($sql,array($row['rubric_id'],$row['cine']),DB_FETCHMODE_ASSOC);
-  $this->tpl->assign("products_similar_prev",$res);
-	
-	$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
+            $res = $this->db->getAll ($sql, array (
+                $row['rubric_id'],
+                $row['cine'] 
+            ), DB_FETCHMODE_ASSOC);
+            $this->tpl->assign ("products_similar_prev", $res);
+            
+            $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products 
   LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
   LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
   WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine>? Order by catalogs_products.cine DESC LIMIT 5";
-  $res = $this->db->getAll($sql,array($row['rubric_id'],$row['cine']),DB_FETCHMODE_ASSOC);
-  $this->tpl->assign("products_similar_next",$res);
-	}  
- }
-
- function displayCatalogsCurs(){
-  $this->tpl->assign("tpl",'catalogs_curs.tpl');
- }
- 
- function displayCatalogs(){
-  $this->tpl->assign("tpl",'catalogs.tpl');
- }
- 
- function displayProducts(){
-  $this->tpl->assign("tpl",'catalogs_product-list.tpl');
- }
- 
- function displayProductsTops(){
-  $this->tpl->assign("tpl",'catalogs_products_tops.tpl');
- }
- 
- function displayProductsHits(){
-  $this->tpl->assign("tpl",'catalogs_products_hits.tpl');
- }
- 
- function displayProductsHitsAll(){
-  $this->tpl->assign("tpl",'catalogs_products_hits_all.tpl');
- }
-
- function displayBasket($count_products,$cine_products,$cine_products_discount,$discount){
-  $this->tpl->assign("count_products",$count_products);
-  $this->tpl->assign("cine_products",$cine_products);
-  $this->tpl->assign("cine_products_discount",$cine_products_discount);
-  $this->tpl->assign("discount",$discount);
-  $this->tpl->display('basket.tpl');
- }
- 
- function displayProduct(){
-  $this->tpl->assign("tpl",'catalogs_product.tpl');
- }
- 
- function displayProductBasket(){
-  $this->tpl->assign("tpl",'catalogs_basket.tpl');
- }
- 
- function displayBrends(){
-  $this->tpl->assign("tpl",'catalogs_brends.tpl');
- }
- 
- function displayBrend(){
-  $this->tpl->assign("tpl",'catalogs_brend.tpl');
- }
- 
- function displayCities(){
-  $this->tpl->assign("tpl",'catalogs_cities.tpl');
- }
-
- function displayProductBasketSend(){
-  $this->tpl->assign("tpl",'catalogs_basket_send.tpl');
- }
- 
- function displayReg(){
-  $this->tpl->assign("tpl",'catalogs_reg.tpl');
- }
- 
- function displayEditUser(){
-  $this->tpl->assign("tpl",'catalogs_user_edit.tpl');
- }
- 
- function displayNoPsw(){
-  $this->tpl->assign("tpl",'catalogs_nopsw.tpl');
- }
- 
- function displayOrders(){
-  $this->tpl->assign("tpl",'catalogs_orders.tpl');
- }
- 
- function displayOrder(){
-  $this->tpl->assign("tpl",'catalogs_order.tpl');
- }
- 
- function displayUsers(){
-  $this->tpl->assign("tpl",'catalogs_users.tpl');
- }
- 
- function displayUser(){
-  $this->tpl->assign("tpl",'catalogs_user.tpl');
- }
- 
- function displayFilters(){
-  $this->tpl->assign("tpl",'catalogs_filters.tpl');
- }
- 
- function displayFilters2(){
-  $this->tpl->assign("tpl",'catalogs_filters2.tpl');
- } 
- 
- function displayYears(){
-  $this->tpl->assign("tpl",'catalogs_years.tpl');
- }
- 
- function displayWinProducts(){
-  $this->tpl->display('catalogs_win_products.tpl');
- }
- 
- function displayModifications(){
-  $this->tpl->assign("tpl",'catalogs_modifications.tpl');
- }
- 
- function displayImport(){
-  $this->tpl->assign("tpl",'catalogs_import.tpl');
- }
- 
- function displayImportCine(){
-  $this->tpl->assign("tpl",'catalogs_import_cine.tpl');
- }
- 
- function displayAkcii(){
-  $this->tpl->assign("tpl",'catalogs_akcii.tpl');
- }
- 
- function displayCompare(){
-  $this->tpl->assign("tpl",'catalogs_compare.tpl');
- }
- 
- function displayTmpProducts(){
-  $this->tpl->assign("tpl",'catalogs_tmp_products.tpl');
- }
- 
-}
-?>
\ No newline at end of file
+            $res = $this->db->getAll ($sql, array (
+                $row['rubric_id'],
+                $row['cine'] 
+            ), DB_FETCHMODE_ASSOC);
+            $this->tpl->assign ("products_similar_next", $res);
+        }
+    }
+    
+    function displayCatalogsCurs ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_curs.tpl');
+    }
+    
+    function displayCatalogs ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs.tpl');
+    }
+    
+    function displayProducts ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_product-list.tpl');
+    }
+    
+    function displayProductsTops ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_products_tops.tpl');
+    }
+    
+    function displayProductsHits ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_products_hits.tpl');
+    }
+    
+    function displayProductsHitsAll ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_products_hits_all.tpl');
+    }
+    
+    function displayBasket ($count_products, $cine_products, $cine_products_discount, $discount)
+    {
+        $this->tpl->assign ("count_products", $count_products);
+        $this->tpl->assign ("cine_products", $cine_products);
+        $this->tpl->assign ("cine_products_discount", $cine_products_discount);
+        $this->tpl->assign ("discount", $discount);
+        $this->tpl->display ('basket.tpl');
+    }
+    
+    function displayProduct ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_product.tpl');
+    }
+    
+    function displayProductBasket ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_basket.tpl');
+    }
+    
+    function displayBrends ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_brends.tpl');
+    }
+    
+    function displayBrend ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_brend.tpl');
+    }
+    
+    function displayCities ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_cities.tpl');
+    }
+    
+    function displayProductBasketSend ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_basket_send.tpl');
+    }
+    
+    function displayReg ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_reg.tpl');
+    }
+    
+    function displayEditUser ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_user_edit.tpl');
+    }
+    
+    function displayNoPsw ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_nopsw.tpl');
+    }
+    
+    function displayOrders ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_orders.tpl');
+    }
+    
+    function displayOrder ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_order.tpl');
+    }
+    
+    function displayUsers ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_users.tpl');
+    }
+    
+    function displayUser ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_user.tpl');
+    }
+    
+    function displayFilters ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_filters.tpl');
+    }
+    
+    function displayFilters2 ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_filters2.tpl');
+    }
+    
+    function displayYears ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_years.tpl');
+    }
+    
+    function displayWinProducts ()
+    {
+        $this->tpl->display ('catalogs_win_products.tpl');
+    }
+    
+    function displayModifications ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_modifications.tpl');
+    }
+    
+    function displayImport ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_import.tpl');
+    }
+    
+    function displayImportCine ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_import_cine.tpl');
+    }
+    
+    function displayAkcii ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_akcii.tpl');
+    }
+    
+    function displayCompare ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_compare.tpl');
+    }
+    
+    function displayTmpProducts ()
+    {
+        $this->tpl->assign ("tpl", 'catalogs_tmp_products.tpl');
+    }
+}
\ No newline at end of file
--
libgit2 0.21.4