/b2b/core/shop/controller/ctl.gallery.php
PHP | 593 lines | 476 code | 48 blank | 69 comment | 91 complexity | 68c95f59d6fc7fbc308f94171d7dc4b6 MD5 | raw file
- <?php
- class ctl_gallery extends shopPage{
- var $_call = 'index';
- var $type='goodsCat';
- var $seoTag=array('shopname','goods_amount','goods_cat','goods_cat_p','goods_type','brand','sort_path');
- function ctl_gallery(){
- parent::shopPage();
- $this->title = str_replace("{ENV_path}","{ENV_sort_path}",$this->system->getConf('site.list_title'));
- $this->keyWords = str_replace("{ENV_path}","{ENV_sort_path}",$this->system->getConf('site.list_meta_key_words'));
- $this->metaDesc = str_replace("{ENV_path}","{ENV_sort_path}",$this->system->getConf('site.list_meta_desc'));
- }
-
- function index($view,$cat_id=0,$urlFilter=null,$orderBy=0,$tab=null,$page=1,$cat_type=null) {
-
- // //??URL?????????,???????????????
- // if(!preg_match('/.*[text|grid|wholesale|index]\.html$/i',$_SERVER['QUERY_STRING'])) {
- // $view = $this->system->getConf('gallery.default_view');
- //
- // }
- $o=$this->system->loadModel('goods/productCat');
- if($view == 'default'){
- $view = $o->get_gallery_default_view();
- }
-
- if($orderBy==5 || $orderBy==6){
- $this->noCache = true;
- }
-
- if($cat_type){
- $this->type='virtualcat';
- $this->cat_type=$cat_type;
- $virtualCat=$this->system->loadModel('goods/virtualcat');
- $vcat=$virtualCat->instance($cat_type);
- parse_str($vcat['filter'],$type_filter);
- }
- $urlFilter=htmlspecialchars(urldecode($urlFilter));
-
- //????? yanglish 2010/7/11
- $this->showValideCode('login');
- $cat_id = $cat_id?$cat_id:'';
- if(!empty($type_filter['cat_id'])){
- $cat_id .= empty($cat_id) ? implode(',',$type_filter['cat_id']) : ','.implode(',',$type_filter['cat_id']);
- }
- if($cat_id){
- $cat_id = explode(",",$cat_id);
- foreach($cat_id as $k=>$v){
- $cat_id[$k]=intval($v);
- }
- $cat_id = array_unique($cat_id);
- $this->id = implode(",",$cat_id);
- }
- //{{{?????
-
- $pageLimit = 20;
- $this->pagedata['pdtPic']=array('width'=>100,'heigth'=>100);
- $this->pagedata['args'] = array(implode(",",$cat_id),urlencode($urlFilter),$orderBy,$tab,$page,$cat_type);
- $this->pagedata['curView'] = $view;
-
- $productCat = $this->system->loadModel('goods/productCat');
- if($cat_type){
- $this->pagedata['childnode'] = $virtualCat->getCatParentById($cat_type);
- }else{
- $this->pagedata['childnode'] = $productCat->getCatParentById($cat_id,$view);
- }
- $brandGroup=$this->system->loadModel('goods/brand');
- $objGoods = $this->system->loadModel('goods/products');
-
- $brandResult=$brandGroup->getBrandGroup($cat_id);
- $this->productCat = &$productCat;
- $cat = $productCat->get($cat_id,$view,$type_filter['type_id']);
-
- if(!in_array($view,$cat['setting']['list_tpl'])){
- header('Location: '.$this->system->mkUrl('gallery',current($cat['setting']['list_tpl']),$this->pagedata['args']),true,301);
- }
-
- if($cat_type){
-
- $vcat['addon'] = unserialize($vcat['addon']);
- if(trim($vcat['addon']['meta']['keywords'])){
- $this->keyWords = trim($vcat['addon']['meta']['keywords']);
- }
- if(trim($vcat['addon']['meta']['description'])){
- $this->metaDesc = trim($vcat['addon']['meta']['description']);
- }
- }else{
- if(trim($cat['addon'])){
- $cat['addon'] = unserialize($cat['addon']);
- if(trim($cat['addon']['meta']['keywords'])){
- $this->keyWords = trim($cat['addon']['meta']['keywords']);
- }
- if(trim($cat['addon']['meta']['description'])){
- $this->metaDesc = trim($cat['addon']['meta']['description']);
- }
- }
- }
-
- if($this->system->getConf('system.seo.noindex_catalog'))
- $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />';
-
- $searchtools = &$this->system->loadModel('goods/search');
- $path =array();
- $filter = $searchtools->decode($urlFilter,$path,$cat);
- if($filter['name'][0]){
- $filter['name'][0] = str_replace('%xia%','_',$filter['name'][0]);
- $filter['name'][0] = str_replace('%zhong%','-',$filter['name'][0]);
- }
- if($filter['bn'][0]){
- $filter['bn'][0] = str_replace('%xia%','_',$filter['bn'][0]);
- $filter['bn'][0] = str_replace('%zhong%','-',$filter['bn'][0]);
- }
-
- $GLOBALS['search_result'] = $filter['name'][0];
- $this->filter = &$filter;
- if($GLOBALS['search_result']==''){ //???????title
- $this->title = '{ENV_shopname}';
- }
- else{
- $this->title = $GLOBALS['search_result'].'__{ENV_shopname}';
- }
-
- if($cat['cat_name']){ //??????title
- $this->title = $cat['cat_name'].'__{ENV_shopname}';
- }
-
- if($vcat['virtual_cat_name']){ //????????title
- $this->title = $vcat['virtual_cat_name'].'__{ENV_shopname}';
-
- }
-
- $filter=array_merge(array('cat_id'=>$cat_id,'marketable'=>'true'),$filter);
-
- //--------?????????
- if ($vcat['type_id'])
- $type_id = $vcat['type_id'];
- else{
- if($cat_id){
- foreach ($cat_id as $c){
- $subcat = $productCat->getSubCatId($c);
- $cat_id += array_merge($cat_id,$subcat);
- }
- }
- $type = $productCat->getFieldById($cat_id,array('type_id'));
- if ($type){
- $tmp_type = array();
- foreach($type as $v){
- $tmp_type[] = $v['type_id'];
- }
- $tmp_type = array_unique($tmp_type);
- if (count($tmp_type) == 1){
- $type_id = $tmp_type[0];
- }else{
- $type_id = 0;
- }
- }else{
- $type_id = 0;
- }
- }
- $vcat=null;
- $gType = $this->system->loadModel('goods/gtype');
- $SpecList = $gType->getSpec($type_id,1);
- //--------
- foreach($path as $p){
- $arg = unserialize(serialize($this->pagedata['args']));
- $arg[1] = $p['str'];
- $title = array();
- if(is_numeric($p['type'])){
- foreach($p['data'] as $i){
- $name = $cat['props'][$p['type']]['options'][$i];
- $title[] = $name?$name:$i;
- $tip = $cat['props'][$p['type']]['name'];
- }
- }elseif($p['type']=='brand_id'){
- $brand = array();
-
- foreach($cat['brand'] as $b){
- $brand[$b['brand_id']] = $b['brand_name'];
- }
- foreach($p['data'] as $i){
- $title[] = $brand[$i];
- $tip = "??";
- }
- unset($brand);
- }elseif(substr($p['type'],0,2)=='s_'){
- $spec = array();
- foreach($p['data'] as $spk => $spv){
- $tmp=explode(",",$spv);
- $tip = $SpecList[$tmp[0]]['name'];
- $title[]=$SpecList[$tmp[0]]['spec_value'][$tmp[1]]['spec_value'];
- }
- $curSpec[$tmp[0]]=$tmp[1];
- }
-
- $title = implode(',',$title);
- if($title){
- //$this->title=' '.$title;
- $this->path[] = array('title'=>" ".$title,'link'=>$this->system->mkUrl('gallery',$view,$arg),'tips'=>$tip);
- }
- }
- $cat_id = array_unique($cat_id); //???? by yangyichao 2012-1-30
-
- //-----------
- if($this->system->getConf('system.seo.noindex_catalog'))
- $this->header .= '<meta name="robots" content="noindex,noarchive,follow" />';
-
- $filter['cat_id'] = $cat_id;
- $filter['goods_type'] = 'normal';
- $filter['marketable'] = 'true';
- //-----??????????????ID
- if ($urlFilter){
- if($type_id){
- $filter['type_id']=$type_id;
- }
- }
- //--------
-
-
- $this->pagedata['desc'] = $cat['desc'];
- $this->pagedata['tabs'] = $cat['tabs'];
- $this->pagedata['cat_id'] = implode(",",$cat_id);
- $this->pagedata['views'] = $cat['setting']['list_tpl'];
- $this->pagedata['orderBy'] = $objGoods->orderBy();
- if($cat['tabs'][$tab]){
- parse_str($cat['tabs'][$tab]['filter'],$_filter);
- $filter = array_merge($filter,$_filter);
- }
- if($GLOBALS['runtime']['member_lv']){
- $filter['mlevel'] = $GLOBALS['runtime']['member_lv'];
- }
- if(!isset($this->pagedata['orderBy'][$orderBy])){
- $this->system->error(404);
- }else{
- $orderby = $this->pagedata['orderBy'][$orderBy]['sql'];
- }
-
- foreach($brandResult as $v=>$k){
- $brand_count[$k['brand_id']]['plus']=$k['brand_cat'];
- }
- $selector = array();
- $search = array();
- //echo "<pre>";print_r($filter);exit;
- if((!is_array($cat_id) && $cat_id) || $cat_id[0] || $cat_type){
- $goods_relate=$objGoods->getList("*",$filter,$pageLimit*($page-1),$pageLimit,$c);//2011.2.21 by-panguodong ????????????????$pageLimit ???????
- }
- if ($goods_relate){
- unset($tmpSpecValue);
- foreach($goods_relate as $grk => $grv){
- if ($grv['spec_desc']){
- $tmpSdesc=unserialize($grv['spec_desc']);
- if(is_array($tmpSdesc)){
- foreach($tmpSdesc as $tsk => $tsv){
- foreach($tsv as $tk => $tv){
- if (!in_array($tv['spec_value_id'],$tmpSpecValue))
- $tmpSpecValue[]=$tv['spec_value_id'];
- }
- }
- }
- }
- }
- }
- /***********************/
- if ($SpecList){
- if ($curSpec)
- $curSpecKey=array_keys($curSpec);
- foreach($SpecList as $spk => $spv){
- $selected=0;
- /*
- $existsSV=0;
- foreach($spv['spec_value'] as $spvk => $spvv){
- if (!in_array($spvk,$tmpSpecValue))
- unset($spv['spec_value'][$spvk]);
- else
- $existsSV=1;
- }
- if ($existsSV){*/
- if ($curSpecKey&&in_array($spk,$curSpecKey)){
- $spv['spec_value'][$curSpec[$spk]]['selected']=true;
- $selected=1;
- }
- if ($spv['spec_style']=="select"){ //??
- $SpecSelList[$spk] = $spv;
- if ($selected)
- $SpecSelList[$spk]['selected'] = true;
- }elseif ($spv['spec_style']=="flat"){
- $SpecFlatList[$spk] = $spv;
- if ($selected)
- $SpecFlatList[$spk]['selected'] = true;
- }
- //}
- }
- }
- $this->pagedata['SpecFlatList'] = $SpecFlatList;
- $this->pagedata['SpecSelList'] = $SpecSelList;
- $this->pagedata['specimagewidth'] = $this->system->getConf('spec.image.width');
- $this->pagedata['specimageheight'] = $this->system->getConf('spec.image.height');
- /************************/
- if(is_array($cat['brand'])){
- $filter_b=$filter;
- foreach($cat['brand'] as $bk => $bv){
- $bCount=0;
- $brand = array('name'=>'??','value'=>array_flip($filter['brand_id']));
- // foreach($goods_relate as $gk => $gv){
- // if ($gv['brand_id'])
- // if ($gv['brand_id']==$bv['brand_id']){
- // $bCount++;
- // }
- // }
- //by zhoulei 2011-7-11 ????????
- $filter_b['brand_id'] = $bv['brand_id'];
- $bCount = $objGoods->count($filter_b);
- if ($bCount>0){
- $tmpOp[$bv['brand_id']]=$bv['brand_name']."<span class='num'>(".$bCount.")</span>";
- }
- }
- $brand['options'] = $tmpOp;
- $selector['brand_id'] = $brand;
- }
-
- $navselector=0;
- foreach($cat['props'] as $prop_id=>$prop){
- if($prop['show']){// ???????? by yangbing 2010-04-30
- $navselector = 1;
- }else{
- continue;
- }
- if($prop['search']=='select'){
- $prop['options'] = array_merge($prop['options']);
- $prop['value'] = $filter['p_'.$prop_id][0];
- $searchSelect[$prop_id] = $prop;
- }elseif($prop['search']=='input'){
- $prop['value'] = ($filter['p_'.$prop_id][0]);
- $searchInput[$prop_id] = $prop;
- }elseif($prop['search']=='nav'){
- $prop['value'] = array_flip($filter['p_'.$prop_id]);
- $plugadd=array();
- $pfilter = $filter;
- foreach($goods_relate as $k=>$v){
- if($v["p_".$prop_id]!=null){
- $pfilter["p_".$prop_id] = $v["p_".$prop_id];
- // if($plugadd[$v["p_".$prop_id]]){
- // $plugadd[$v["p_".$prop_id]]=$plugadd[$v["p_".$prop_id]]+1;
- // }else{
- // $plugadd[$v["p_".$prop_id]]=1;
- // }
- }
- // $aFilter['goods_id'][] = $v['goods_id']; //????????
- }
- $plugadd[$pfilter['p_'.$prop_id]] = $objGoods->count($pfilter);
- foreach($prop['options'] as $q=>$e){
- if($plugadd[$q]){
- $prop['options'][$q]=$prop['options'][$q]."<span class='num'>(".$plugadd[$q].")</span>";
- }else{
- unset($prop['options'][$q]);
- }
- }
- $selector[$prop_id] = $prop;
- }
- }
-
- // if(count($prop['options']) <= 1){
- // $navselector=0;
- // }
- /*
- if ($navselector){
- $p_num = 0;
- $nsvcount=0;
- $noshow=0;
- foreach($selector as $sk => $sv){
- if ($sv['value']){
- $nsvcount++;
- }
- if (is_numeric($sk)){
- $p_num++;
- if(!$sv['show']){
- $noshow++;
- }
- }
- }
- if ($nsvcount==intval($p_num-$noshow))
- $navselector=0;
- }*/
-
- foreach($cat['spec'] as $spec_id=>$spec_name){
- $sId['spec_id'][] = $spec_id;
- }
- if ($cat['ordernum']){
- if ($selector){
- foreach($selector as $key => $val){
- if(!in_array($key,$cat['ordernum'])&&$val){
- $selectorExd[$key]=$val;
- }
- }
- }
- }
-
- $selector['ordernum'] = $cat['ordernum'];
- $aProduct = $objGoods->getList(null,$filter,$pageLimit*($page-1),$pageLimit,$count,$orderby);
- //??????????????????
- $mdl_wss = $this->system->loadModel('trading/wholesaleSingle');
- foreach($aProduct as $pk=>$pv){
- $mdl_wss->process_good_use_rule(&$aProduct[$pk]);
- }
- //-----------------------------
-
- //?????????
- $aProduct = $this->_checkDealerPurview($aProduct);
- //echo "<pre>";print_r($selector);exit();
- $this->pagedata['mask_webslice'] = $this->system->getConf('system.ui.webslice')?' hslice':null;
- $this->pagedata['searchInput'] = &$searchInput;
- $this->pagedata['searchSelect'] = &$searchSelect;
- $this->pagedata['selector'] = &$selector;
- $this->pagedata['selectorExd'] = $selectorExd;
- $this->pagedata['navselector'] = &$navselector;
- $this->cat_id = $cat_id;
- $smarty = &$this->system->loadModel('system/frontend');
- $smarty->register_function("selector", array(&$this,'_selector'));
-
- $this->pagedata['pager'] = array(
- 'current'=>$page,
- 'total'=>ceil($count/$pageLimit),
- 'link'=>$this->system->mkUrl('gallery',$view,array(implode(',',$cat_id),urlencode($p['str']),$orderBy,$tab,($tmp = time()),$cat_type)),
- 'token'=>$tmp);
- if($page != 1 && $page > $this->pagedata['pager']['total']){
- $this->system->error(404);
- }
- if(!count($aProduct)){
- $this->pagedata['emtpy_info']=stripslashes($this->system->getConf('errorpage.searchempty'));
- }
-
- if($this->system->getConf('site.show_goods_storage')){//??????
- $this->pagedata['goodsstorage'] = $this->system->getConf('site.show_goods_storage');
- $this->pagedata['goodsstorage_real'] = $this->system->getConf('site.show_goods_storage_real');
- $this->pagedata['goodsstorage_alert'] = $this->system->getConf('site.goods_storage_alert');
- }
-
- $objImage = $this->system->loadModel('goods/gimage');
- $this->pagedata['searchtotal']=$count;
- if(is_array($aProduct) && count($aProduct) > 0){
- $objGoods->getSparePrice($aProduct, $GLOBALS['runtime']['member_lv']);
- $objGoods->extend_product_info($aProduct,$GLOBALS['runtime']['member_lv']);
- if($this->system->getConf('site.show_mark_price')){
- $setting['mktprice'] = $this->system->getConf('site.market_price');
- }else{
- $setting['mktprice'] =0;
- }
- $setting['saveprice'] = $this->system->getConf('site.save_price');
- $setting['buytarget'] = $this->system->getConf('site.buy.target');
- $this->pagedata['setting'] = $setting;
- $this->pagedata['products'] = $aProduct;
- }
-
- if($GLOBALS['runtime']['member_lv']<0){
- $this->pagedata['LOGIN'] = 'nologin';
- }
- $this->pagedata['cat_type'] = $cat_type;
- $this->pagedata['search_array'] = implode("+",$GLOBALS['search_array']);
- $this->pagedata['_PDT_LST_TPL'] = 'file:'.$cat['tpl'];
- $this->pagedata['_MAIN_'] = 'gallery/index.html';
- $this->path[]=array('title'=>'');
- $this->getGlobal($this->seoTag,$this->pagedata);
-
- // if($view != $_COOKIE['GALLERY_VIEW']){
- // $this->system->setCookie('GALLERY_VIEW',$view,null);
- // }
- $this->output();
-
-
- }
-
- function _selector($params, &$smarty){
- $filter = unserialize(serialize($this->filter));
- if(is_numeric($params['key'])){
- $data = &$filter['p_'.$params['key']];
- }elseif ($params['key']=="spec"){
- $tmp=explode(",",$params['value']);
- $data = &$filter['s_'.$tmp[0]];
- }else{
- $data = &$filter[$params['key']];
- }
-
- if($params['mod']=='append'){
- $data[] = $params['value'];
- }elseif($params['mod']=='remove'){
- $data = array_flip($data);
- unset($data[$params['value']]);
- $data = array_flip($data);
- }else{
- if ($params['key']=="spec"){
- $tmpData = explode(",",$params['value']);
- $data = array($tmpData[1]);
- }
- else
- $data = array($params['value']);
- }
-
- $searchtools = &$this->system->loadModel('goods/search');
- $args = unserialize(serialize($this->pagedata['args']));
-
- $args[1] = $searchtools->encode($filter);
- $args[4]=1;
- return $this->system->mkUrl('gallery',$smarty->_tpl_vars['curView'],$args);
- }
-
- function _get_schema_template($tpl_name, &$tpl_source, &$smarty) {
- $tpl_source = file_get_contents(SCHEMA_DIR.$tpl_name.'/view/gallery.html');
- if (!is_bool($tpl_source)) {
- return true;
- } else {
- return false;
- }
-
- }
-
- function _get_schema_timestamp($tpl_name, &$tpl_timestamp, &$smarty) {
- $tpl_timestamp = filemtime(SCHEMA_DIR.$tpl_name.'/view/gallery.html');
- if (!is_bool($tpl_timestamp)) {
- return true;
- } else {
- return false;
- }
- }
-
- function get_goods_amount(&$result){
- return $result['searchtotal'];
- }
-
- function get_goods_cat(&$result){
- $pcat=$this->system->loadModel('goods/productCat');
- $row=$pcat->instance($result['cat_id'],'cat_name');
- return $row['cat_name'];
- }
- function get_goods_cat_p(&$result){
- $pcat=$this->system->loadModel('goods/productCat');
- $row=$pcat->getpath($result['cat_id']);
- if ($row){
- foreach($row as $k => $v){
- $tmpRow[]=$v['title'];
- }
- return implode(",",$tmpRow);
- }
- }
- function get_goods_type(&$result){
- $pcat=$this->system->loadModel('goods/productCat');
- $row=$pcat->instance($result['cat_id'],'type_id');
- if ($row['type_id']){
- $gtype=$this->system->loadModel('goods/gtype');
- $grow=$gtype->instance($row['type_id'],'name');
- return $grow['name'];
- }
- }
- function get_brand(&$result){
- if($sExd=$result['selectorExd']){
- if ($sExdB=$sExd['brand_id']){
- if ($sExdB['options']){
- foreach($sExdB['options'] as $key => $val){
- $brandExd[]=substr($val,0,strpos($val,"<"));
- }
- return implode(",",$brandExd);
- }
- }
- }
- }
-
- function get_sort_path(&$result){
- $sitemap = &$this->system->loadModel('content/sitemap');
- $path = array_merge($sitemap->getPath('goodsCat',$result['cat_id'],'index'),$this->path);
- if ($path){
- for($i=count($path)-1;$i>0;$i--){
- if ($path[$i]['title'])
- $tmpPath[]=$path[$i]['title'];
- }
- if ($tmpPath)
- return implode(",",$tmpPath);
- }
- }
- //????? yanglish 2010/7/11
- function showValideCode($tp=''){
- switch ($tp){
- case "login":
- if($this->system->getConf('site.login_valide') == true || $this->system->getConf('site.login_valide') == 'true'){
- $this->pagedata['valideCode'] = true;
- }
- break;
- case "signup":
- if($this->system->getConf('site.register_valide') == true || $this->system->getConf('site.register_valide') == 'true'){
- $this->pagedata['valideCode'] = true;
- }
- break;
- }
- }
- function _get_secure($tpl_name, &$smarty) { return true; }
- function _get_trusted($tpl_name, &$smarty) {;}
- }
- ?>