<?php
class searchControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
		$this->loadModel(array("shop","product"));
	}
	
	public function onDefault(){
		$tagname=get('tagname','h');
		$this->loadControl("productapi");
		$where=" status =1 ";
		if($tagname){
			$where.=" AND title like '%{$tagname}%' ";
			$url.="&tagname=".urlencode($tagname);
		}
		$pagesize=ISWAP?24:48;
		$start=get('per_page','i');
		$option=array(
			"where"=>$where,
			"start"=>$start,
			"limit"=>$pagesize,			
		);
		$rscount=true;
		$list=$this->productapiControl->select($option,$rscount);
		if($list){
			foreach($list as $k=>$v){
				$v['title']=str_replace($tagname,'<span style="color:red;">'.$tagname.'</span>',$v['title']);
				$list[$k]=$v;
			}
		}
		$this->smarty->assign(
			array(
			"baseurl"=>$url,
			"seo"=>$seo,
			"list"=>$list,
			"pagelist"=>$pagelist,
			"rscount"=>$rscount,
			"pagesize"=>$pagesize,
			)
		);
		$pagelist=$this->pagelist($rscount,$pagesize,$url);
		$this->smarty->display("search/index.html");
	}
	
	public function onAuto(){
		$word=get_post('word','h');
		$shopid=get_post('shopid','i');
		$op=array(
			"where"=>" shopname like '%".$word."%' ",
			"limit"=>6,
		);
		 
		$shoplist=$this->shop->select($op);
		$option=array(
			"where"=>" title like '%".$word."%' ",
			"limit"=>6,
		);
		
		$productlist=$this->product->select($option);
		$this->smarty->assign(array(
			"shoplist"=>$shoplist,
			"productlist"=>$productlist
		));
		$this->smarty->display("search/auto.html");
	}
	
}
?>