예제 #1
0
                } else {
                    $str = chr(0xf0 | ($num & 0x1c0000) >> 18) . chr(0x80 | ($num & 0x3f000) >> 12) . chr(0x80 | ($num & 0xfc0) >> 6) . chr(0x80 | $num & 0x3f);
                }
            }
        }
        $str = iconv("UTF-8", "{$encoding}//IGNORE", $str);
        $url = str_replace('%u' . $unicode, $str, $url);
    }
    return urldecode($url);
}
if (isset($_GET['q'])) {
    $q = unicodeUrlDecode($_GET['q'], "cp1251");
    $q = trim(strtolower(SQL::slashes($q)));
    $condition = '';
    if ($q) {
        if ($words = Rumor::getAllForms($q)) {
            $or = array();
            foreach ($words as $w) {
                $or[] = "i.name LIKE '%" . $w . "%'";
            }
            $condition .= " AND (" . implode(' OR ', $or) . ")";
        } else {
            $condition .= " AND (i.name LIKE '%" . SQL::slashes($q) . "%')";
        }
    }
    $query = "SELECT i.name,price \r\n\t\tFROM sc_shop_item i\r\n\t\t\t\r\n\t\tWHERE price>0 AND in_stock>0";
    if (isset($_GET['m']) && $_GET['m'] == 'all') {
    } else {
        //			$query.=" AND ";
    }
    //		$query.=" AND (lower(i.name) LIKE '%$q%'
예제 #2
0
 function displayGoods($id)
 {
     global $ST, $get;
     $par = 0;
     $data['parentid'] = 0;
     $data['parentname'] = $this->mod_name;
     $data['description'] = '';
     $data['action'] = array();
     $data['id'] = 0;
     $page = new Page($this->getPageSize(), $this->cfg('PAGE_SIZE_SELECT'));
     //		$page=new Page(1);
     //		$page=new Page($this->cfg('PAGE_SIZE'));
     $catIds = array();
     if ($prop = $this->getURIIntVal('prop')) {
         $rs = $ST->select("SELECT * FROM sc_shop_prop WHERE id={$prop}");
         if ($rs->next()) {
             $this->explorer[] = array('name' => $rs->get('name'), 'url' => $this->mod_uri . $this->getURIIntVal('catalog') . '/prop/' . $rs->get('id') . '/');
             $this->setTitle($rs->get('name'));
             $this->setHeader($rs->get('name'));
         }
     }
     $condition = "WHERE i.price>0";
     if ($id && is_int($id)) {
         $par = $id;
         if ($man = $this->getURIVal('man')) {
             $this->explorer[] = array('name' => $man, 'url' => $this->mod_uri . $this->getURIIntVal('catalog') . '/man/' . $man . '/');
         }
         $rs = $ST->select("SELECT * FROM sc_shop_catalog WHERE id=" . $id);
         if ($rs->next()) {
             $data['description'] = $rs->get('description');
             $data['id'] = $rs->get('id');
             if (trim($rs->get('cache_child_catalog_ids'))) {
                 $catIds = explode(',', $rs->get('cache_child_catalog_ids'));
             }
             //				$this->actCatalog[]=$id;
             //				if(!empty($catIds[0])){
             //
             //					$id=$catIds[0];
             //					$rs=$ST->select("SELECT * FROM sc_shop_catalog WHERE id=".$id);
             //					if($rs->next()){
             //						$catIds=array();
             //					}
             //					$this->actCatalog[]=$id;
             //				}
             $this->explorer[] = array('name' => $rs->get('name'), 'url' => $this->mod_uri . $rs->get('id') . '/');
             $this->setTitle($rs->get('name'));
             $this->setHeader($rs->get('name'));
             //Хлебные крошки
             $parent = $data['parentid'] = $rs->get('parentid');
             //				$this->actCatalog[]=$parent;
             while ($parent) {
                 $rs1 = $ST->select("SELECT id,name,parentid FROM sc_shop_catalog WHERE id=" . $parent);
                 if ($rs1->next()) {
                     $parent = $rs1->getInt('parentid');
                     $this->actCatalog[] = $parent;
                     $this->explorer[] = array('name' => $rs1->get('name'), 'url' => $this->mod_uri . $rs1->get('id') . '/');
                 } else {
                     break;
                 }
             }
             if (!empty($this->explorer[1])) {
                 $data['parentname'] = $this->explorer[1]['name'];
             }
         }
         $catIds[] = $id;
     }
     //		$condition="WHERE of.itemid=i.id AND i.price>=0 AND of.in_stock>0 AND of.region='{$this->getRegion()}'";/*Раздельное наличие*/
     $condition .= " AND i.in_stock>-1";
     //Не показывать удалённые
     //		$condition.=" AND i.category IN (SELECT id FROM sc_shop_catalog WHERE state>0)";
     if ($this->cfg('SHOP_GOODS_IN_STOCK_ONLY') == 'true') {
         //Настройка показывать только в наличии
         $condition .= " AND i.in_stock>0";
     }
     if ($this->cfg('SHOP_GOODS_W_IMG_ONLY') == 'true') {
         //Настройка показывать только с картинками
         $condition .= " AND i.img<>''";
     }
     if ($this->cfg('SHOP_GOODS_CHECKED_ONLY')) {
         //Настройка показывать только в подтверждённые
         $condition .= " AND i.confirm=1";
     }
     if (preg_match('/(\\d*)\\D*-(\\d*)\\D*/', $this->getURIVal('price'), $res)) {
         if ($res[1] > 0) {
             $condition .= " AND i.price>={$res[1]}";
         }
         if ($res[2] > 0) {
             $condition .= " AND i.price<={$res[2]}";
         }
     }
     //		if($univ=$this->getURIIntVal('universal')){
     //			$condition.=" AND (i.id=$univ OR i.universal=$univ)";
     //		}
     if ($this->getURIVal('catalog') == 'fav') {
         if ($arr = $this->getFavoriteData()) {
             $condition .= " AND i.id IN('" . implode("','", $arr) . "')";
         }
     }
     if ($this->getURIVal('catalog') == 'new') {
         $condition .= " AND i.sort3>0";
         $this->setPageTitle('Новинки');
     }
     if ($this->getURIVal('catalog') == 'special') {
         $condition .= " AND i.sort>0";
         $this->setPageTitle('СПЕЦИАЛЬНОЕ ПРЕДЛОЖЕНИЕ');
     }
     //		if($this->getURIVal('catalog')=='action'){
     //			$condition.=" AND i.sort1>0";
     //			$this->setPageTitle('СПЕЦИАЛЬНОЕ ПРЕДЛОЖЕНИЕ');
     //		}
     if ($action = $this->getURIIntVal('action')) {
         $rs = $ST->select("SELECT * FROM sc_news WHERE type='action' AND state='public' AND id={$action}");
         if ($rs->next()) {
             $data['action'] = $rs->getRow();
             $this->setPageTitle($rs->get('title'), "/catalog/action/{$action}/");
             $condition .= " AND i.sort1={$action}";
         }
         //			$this->setPageTitle('СПЕЦИАЛЬНОЕ ПРЕДЛОЖЕНИЕ');
     }
     if ($catIds) {
         $condition .= " \r\n\t\t\t\r\n\t\t\t\tAND (\r\n\t\t\t\tEXISTS(SELECT id FROM sc_shop_catalog AS sc WHERE sort>-1 AND sc.id IN(" . trim(implode(",", $catIds), ',') . ") AND i.category=sc.id  )\r\n\t\t\t\t \r\n\t\t\t\tOR EXISTS(SELECT itemid FROM sc_shop_item2cat,sc_shop_catalog sc WHERE sort>-1 AND sc.id=catid AND itemid=i.id AND sc.id IN(" . trim(implode(",", $catIds), ',') . ")  )\r\n\t\t\t)\r\n\t\t\t";
     }
     if ($prop = trim($this->getURIVal('prop'))) {
         $p_c = array();
         if ($prop = explode(',', $prop)) {
             foreach ($prop as $p) {
                 $p_c[] = " EXISTS (SELECT item_id FROM sc_shop_prop_val WHERE prop_id=" . intval($p) . " AND i.id=item_id)";
             }
         }
         if ($p_c) {
             $condition .= " AND (" . implode(' AND ', $p_c) . ")";
         }
         //			$condition.=" AND EXISTS (SELECT item_id FROM sc_shop_prop_val WHERE prop_id={$prop} AND i.id=item_id)";
     }
     if (preg_match('/(\\d+),(\\d+)/', $this->getURIVal('rel'), $res)) {
         $condition .= " AND EXISTS (SELECT ch FROM sc_shop_relation WHERE par={$res[1]} AND type={$res[2]} AND i.id=ch )";
     }
     $prop_condition = '';
     $prop2_condition = '';
     if ($prop = $get->getArray('p')) {
         $c3 = array();
         $c4 = array();
         foreach ($prop as $pid => $val) {
             $pr = array_diff(array_keys($prop), array($pid));
             if (is_array($val)) {
                 foreach ($val as &$v) {
                     $v = SQL::slashes($v);
                 }
                 $c3[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id={$pid} AND value IN('" . implode("','", $val) . "'))";
                 $c4[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND ((prop_id={$pid} AND value IN('" . implode("','", $val) . "')) OR prop_id NOT IN('" . implode("','", $pr) . "') ))";
             } else {
                 $val = trim($val);
                 if (preg_match('/^([\\d\\.]+)-([\\d\\.]+)$/', $val, $res)) {
                     $c3[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id={$pid} AND value>={$res[1]} AND value<={$res[2]})";
                     $c4[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND ((prop_id={$pid} AND value>={$res[1]} AND value<={$res[2]}) OR prop_id NOT IN('" . implode("','", $pr) . "') ))";
                 } elseif ($val) {
                     $c3[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id={$pid} AND value='" . SQL::slashes($val) . "')";
                     $c4[] = " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND ((prop_id={$pid} AND value='" . SQL::slashes($val) . "') OR prop_id NOT IN('" . implode("','", $pr) . "') ))";
                 }
             }
         }
         $prop_condition .= implode('', $c3);
         $prop2_condition .= implode('', $c4);
     }
     //		if($prop=$get->getArray('p')){
     //			$c3=array();
     //			foreach ($prop as $pid=>$val) {
     //				$c3[(int)$pid]=$pid."=".SQL::slashes($val);
     //				$c3[(int)$pid]=" prop_id::varchar||'='||value = '$pid=".SQL::slashes($val)."'";
     //			}
     ////			$prop_condition.= " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id IN(".implode(',',array_keys($c3)).") AND prop_id::varchar||'='||value IN('".implode("','",$c3)."'))";;
     //			$prop_condition.= " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id
     //				AND prop_id IN(".implode(',',array_keys($c3)).")
     //				AND ".implode(" AND ",$c3)."
     //			)";
     //		}
     //		if($prop=$get->getArray('type')){//Тип устройства
     //			$c3=array();
     //			foreach ($prop as $pid) {
     //				$c3[]=(int)$pid;
     //			}
     //			$prop_condition.= " AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id IN (".implode(',',$c3)."))";
     //		}
     //		if($prop=$get->getArray('max')){
     //			$c3=array();
     //			foreach ($prop as $pid=>$val) {
     //				$c3[]=" AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id=$pid AND value::numeric<=".floatval($val).")";
     //			}
     //			$prop_condition.= implode('',$c3);
     //		}
     //		if($prop=$get->getArray('min')){
     //			$c3=array();
     //			foreach ($prop as $pid=>$val) {
     //				$c3[]=" AND EXISTS(SELECT item_id FROM sc_shop_prop_val WHERE i.id=item_id AND prop_id=$pid AND value::numeric>=".floatval($val).")";
     //			}
     //			$prop_condition.= implode('',$c3);
     //		}
     $man_condition = '';
     if (($man = $this->getURIVal('man')) && ($man = explode(',', $man))) {
         $man_condition .= " AND i.manufacturer IN('" . trim(implode("','", $man), ',') . "')";
     }
     if (($man = $this->getURIVal('manid')) && ($man = explode(',', $man))) {
         $man_condition .= " AND i.manufacturer_id IN('" . trim(implode("','", $man), ',') . "')";
     }
     if ($man = $get->getArray('man')) {
         foreach ($man as &$m) {
             $m = SQL::slashes($m);
         }
         $man_condition .= " AND i.manufacturer IN('" . trim(implode("','", $man), ',') . "')";
     }
     if ($man = $get->getArray('manid')) {
         foreach ($man as &$m) {
             $m = SQL::slashes($m);
         }
         $man_condition .= " AND i.manufacturer_id IN('" . trim(implode("','", $man), ',') . "')";
     }
     $p_condition = '';
     if ($get->getInt('minp')) {
         $p_condition .= " AND i.price >={$get->getInt('minp')}";
     }
     if ($get->getInt('maxp')) {
         $p_condition .= " AND i.price <={$get->getInt('maxp')}";
     }
     $sh_arr = array('hit' => 'sort', 'new' => 'sort1', 'act' => 'sort2');
     $s_condition = '';
     if ($show = $this->getURIVal('show')) {
         $s_condition = " AND {$sh_arr[$show]} >0";
     }
     $q = trim(strtolower(SQL::slashes(urldecode($get->get('search')))));
     if ($q) {
         if ($words = Rumor::getAllForms($q)) {
             $or = array();
             foreach ($words as $w) {
                 $or[] = "i.name LIKE '%" . $w . "%'";
             }
             $condition .= " AND (" . implode(' OR ', $or) . ")";
         } else {
             $condition .= " AND (i.name LIKE '%" . SQL::slashes($q) . "%')";
         }
         //$condition.=" AND lower(i.name) LIKE '%" . $q . "%'";
     }
     //		$query="SELECT count(*) AS c FROM sc_shop_item i,sc_shop_offer of $condition $man_condition $p_condition $prop_condition $s_condition" ;
     $query = "SELECT count(*) AS c FROM sc_shop_item i {$condition} {$man_condition} {$p_condition} {$prop_condition} {$s_condition}";
     $rs = $ST->select($query);
     if ($rs->next()) {
         $page->all = $rs->getInt('c');
     }
     $order = '';
     $sort = 'DESC';
     if ($this->getURIVal('sort') == 'desc') {
         $sort = 'DESC';
     } elseif ($this->getURIVal('sort') == 'asc') {
         $sort = 'ASC';
     }
     //		$order.='sort DESC,name';
     //		$order.='category,views DESC,name';
     $order .= 'sort DESC,name';
     if ($this->getURIVal('price')) {
         $order = 'price DESC';
     }
     if ($this->getURIVal('catalog') == 'new') {
         $order = 'sort3 DESC';
     }
     $ord = $this->getURIVal('ord');
     if (in_array($ord, array('price', 'manufacturer', 'name', 'views', 'sort1', 'sort2', 'sort3'))) {
         $order = $ord . ' ' . $sort;
     }
     if ($ord == 'hit') {
         $order = 'sort2 DESC';
     }
     if ($ord == 'updated') {
         $order = 'sort_print DESC';
     }
     if ($ord == 'default') {
         $order = 'sort DESC, name ' . $sort;
         $order = 'name ' . $sort;
         if ($show) {
             $order = "{$sh_arr[$show]} DESC, name " . $sort;
         }
     }
     //		$queryStr="SELECT i.*,coalesce(cn.c,0) AS cnt FROM sc_shop_item i
     //		LEFT JOIN(SELECT COUNT(itemid) AS c,itemid FROM sc_shop_order_item oi,sc_shop_order o WHERE o.id=oi.orderid AND o.order_status=8 GROUP BY itemid) AS cn ON cn.itemid=i.id,
     //		sc_shop_offer of
     //		$condition $man_condition $p_condition $prop_condition ORDER BY $order LIMIT ".$page->getBegin().",".$page->per ;
     //		$queryStr="SELECT i.* FROM sc_shop_item i,
     //		sc_shop_offer of
     //		$condition $man_condition $p_condition $prop_condition $s_condition ORDER BY $order LIMIT ".$page->getBegin().",".$page->per ;
     $queryStr = "SELECT i.*,r,c FROM sc_shop_item i\r\n\t\t\r\n\t\tLEFT JOIN(SELECT COUNT(DISTINCT commentid) AS c,AVG(rating) AS r,itemid  FROM sc_comment,sc_comment_rait r \r\n\t\t\t\t\tWHERE commentid=id  AND TRIM(comment)<>'' AND status=1 AND type IN('','goods') GROUP BY itemid) AS rait ON rait.itemid=i.id\r\n\t\t\t\r\n\t\t\r\n\t\t{$condition} {$man_condition} {$p_condition} {$prop_condition} {$s_condition} ORDER BY {$order} LIMIT " . $page->getBegin() . "," . $page->per;
     $data['manufacturer_list'] = array();
     $data['type_list'] = array();
     $data['prop_list'] = array();
     $data['show_list'] = array(0, 0, 0);
     $data['min_max_price'] = array(0, 0, 0, 0);
     //			$q_vendor="SELECT DISTINCT manufacturer FROM sc_shop_item i,sc_shop_offer of $condition AND manufacturer<>''";
     //			$rs=$ST->select($q_vendor);
     //			while ($rs->next()) {
     //				$data['manufacturer_list'][]=$rs->get('manufacturer');
     //			}
     //			if(count($data['manufacturer_list'])<2){
     //				$data['manufacturer_list']=array();
     //			}
     $q_vendor = "SELECT m.name,m.id,COUNT(m.id) AS c FROM sc_shop_item i,sc_manufacturer m {$condition} AND i.manufacturer_id=m.id GROUP BY m.name,m.id";
     $rs = $ST->select($q_vendor);
     while ($rs->next()) {
         $data['manufacturer_list'][] = $rs->getRow();
     }
     //			$this->data=&$data;
     $rs = $ST->select($queryStr);
     $data['catalog'] = array();
     $data['page'] = $page;
     $units = $this->enum('sh_unit');
     while ($rs->next()) {
         $row = $rs->getRow();
         //			if($row['pack_size']>1){
         //				$row['price_pack']=$row['price']*$row['pack_size']*$discount;
         //			}
         $row['unit'] = @$units[$row['unit']];
         //			if($row['sort']>0){
         //				$row['hit']=true;
         //			}
         //			if($row['sort']>0){
         //				$row['new']=true;
         //			}
         $data['catalog'][$row['id']] = $row;
     }
     if ($data['catalog']) {
         $ids = array_keys($data['catalog']);
         $q = "SELECT * FROM sc_shop_item_nmn WHERE itemid IN (" . implode(',', $ids) . ") AND hidden=0 ORDER BY price";
         $rs = $ST->select($q);
         while ($rs->next()) {
             $data['catalog'][$rs->getInt('itemid')]['nmn'][$rs->getInt('id')] = $rs->getRow();
         }
     }
     $data['children'] = $this->getChildCategory($par);
     $data['children_man'] = array();
     if (count(explode(',', $this->getUriVal('manid'))) == 1) {
         $rs = $ST->select("SELECT c.id FROM sc_manufacturer m,sc_shop_catalog c WHERE m.name=c.name AND m.id={$this->getUriIntVal('manid')}");
         if ($rs->next()) {
             $data['children_man'] = $this->getChildCategory($rs->getInt('id'));
         }
     }
     $data['in_basket'] = array();
     $basket = $this->getBasket();
     foreach ($basket as $item) {
         $data['in_basket'][$item['id']] = $item['count'];
     }
     /* Свойства */
     $q_prop = "SELECT DISTINCT p.id AS pid,p.sort,p.name,p.type,pv.value FROM sc_shop_item i,sc_shop_prop as p,sc_shop_prop_val pv \r\n\t\t\t{$condition} \r\n\t\t\tAND i.category={$id}\r\n\t\t\tAND i.id=pv.item_id\r\n\t\t\tAND pv.prop_id=p.id\r\n\t\t\tAND p.grp<>0  \r\n\t\t\tAND p.sort<>0 ORDER BY p.sort DESC, value";
     //		$prop2_condition
     //			$q_prop="SELECT DISTINCT p.id AS pid,p.sort,p.name,p.type,pv.value FROM sc_shop_item i,sc_shop_prop as p,sc_shop_prop_val pv
     //			$condition
     //			$prop_condition
     //			AND i.category=$id
     //			AND i.id=pv.item_id
     //			AND pv.prop_id=p.id
     //			AND p.grp<>0
     //			AND p.sort<>0 ORDER BY p.sort, value";
     //
     //			$rs=$ST->select($q_prop);
     //			while ($rs->next()) {
     //				$data['prop_list'][$rs->get('pid')]['name']=$rs->get('name');
     //				$data['prop_list'][$rs->get('pid')]['sort']=$rs->get('sort');
     //				$data['prop_list'][$rs->get('pid')]['type']=$rs->get('type');
     //				$data['prop_list'][$rs->get('pid')]['v'][]=$rs->get('value');
     //			}
     $q_prop = "SELECT p.id AS pid,p.sort,p.name,p.type,pv.value,pv.item_id FROM sc_shop_item i,sc_shop_prop as p,sc_shop_prop_val pv \r\n\t\t\t{$condition} \r\n\t\t\t{$prop_condition}\r\n\t\t\tAND i.category={$id}\r\n\t\t\tAND i.id=pv.item_id\r\n\t\t\tAND pv.prop_id=p.id\r\n\t\t\tAND p.grp<>0  \r\n\t\t\tAND p.sort<>0 ORDER BY p.sort,p.name,value";
     $rs = $ST->select($q_prop);
     $pl = array();
     //			$pl_item=array();
     while ($rs->next()) {
         $pl[$rs->get('pid')]['name'] = $rs->get('name');
         $pl[$rs->get('pid')]['sort'] = $rs->get('sort');
         $pl[$rs->get('pid')]['type'] = $rs->get('type');
         if (empty($pl[$rs->get('pid')]['v'][$rs->get('value')])) {
             //					$pl[$rs->get('pid')]['v'][$rs->get('value')]=array();
             $pl[$rs->get('pid')]['v'][$rs->get('value')] = 0;
         }
         //				$pl[$rs->get('pid')]['v'][$rs->get('value')][]=$rs->getInt('item_id');
         $pl[$rs->get('pid')]['v'][$rs->get('value')]++;
         //				$pl_item[$rs->getInt('item_id')][$rs->get('pid')]=$rs->get('value');
     }
     foreach ($pl as $pid => &$p) {
         if ($p['type'] == 4) {
             $list = $this->enum('sh_prop_list_' . $pid);
             $v = array();
             foreach ($list as $val) {
                 if (isset($p['v'][$val])) {
                     $v[$val] = $p['v'][$val];
                 }
             }
             $p['v'] = $v;
         }
     }
     $data['prop_list2'] = $pl;
     //			$q_pr="SELECT MAX(i.price) AS maxp, MIN(i.price) AS minp FROM sc_shop_item i,sc_shop_offer of $condition ";
     //			$q_pr="SELECT MAX(i.price) AS maxp, MIN(i.price) AS minp FROM sc_shop_item i $condition ";
     //			$rs=$ST->select($q_pr);
     //			if($rs->next()){
     //				$data['min_max_price']=array($rs->get('minp'),$rs->get('maxp'),$rs->get('minp'),$rs->get('maxp'));
     //
     //				if($data['min_max_price'][1]==$data['min_max_price'][0]){
     //					$data['min_max_price'][0]=0;
     //					$data['min_max_price'][2]=0;
     //				}
     //
     //			}
     //			if($get->getInt('minp')){
     //				$data['min_max_price'][0]=$get->getInt('minp');
     //			}
     //			if($get->getInt('maxp')){
     //				$data['min_max_price'][1]=$get->getInt('maxp');
     //			}
     $this->tplLeftComponent = dirname(__FILE__) . "/catalog_left.tpl.php";
     $this->display($data, dirname(__FILE__) . '/catalog.tpl.php');
 }