<?php
 /*******************************************************************
 * 版权协议：2009-2019
 * 版权所有: PHP-北京金南曦网络技术有限公司旗下PHPWMS，PHP商城系统技术支持中心http://www.php188.net，并保留所有权利。 
* PHP商城系统网址: http://www.php188.com
 * PHPWMS系统网址：http://www.phpwms.com
 * 销售电话：010-87875088
 * 销售电话：010-87875188 
*------------------------------------------------------------------
 * 这不是一个完全免费软件！您只能在不用于商业目的的前提下对程序代码进
 * 行修改和使用；不允许对程序代码以任何形式任何目的的再发布。
 *------------------------------------------------------------------
 * 文件名称：phpwms.search.php
 * 摘　　要：文章评论
 * 适用范围：PHPWMS 1.0
 * 版　　本：1.0
 *------------------------------------------------------------------
 * Script Written By phpwms项目组
 * 最后更新： 2009-09-24 phpwms 由PHP金南曦网络技术有限公司整理发布
 *******************************************************************/
if(!defined('IN_SYS')) {exit('phpwms');}
class search_WMS extends base {
	protected function init(){
		parent::init();
	}
	public function wmsAction(){
		$this->serachAction();
	}
	public function serachAction(){
		if($this->isPost()){
			$key = $_POST['key'];
			$bs64_key = base64_encode($key);
			$channel_name = $_POST['channel_type'];
			$models = get_models();
			$type_name = '';
			foreach($models  as $m){
				if($m['en_name'] == $channel_name){
					$type_name = $m['cn_name'] . '：';
					$channel_type = $m['id'];
					break;
				}
			}
		}else{
			$channel_name =  $this->_parseItem[1];
			$bs64_key =  $this->_parseItem[2];
			$key = base64_decode($bs64_key) ;
			$channel_type =to_int($this->_parseItem[0]);
		}
		$channel_type = empty($channel_type) ? '1' : $channel_type;
		$channel_name = empty($channel_name) ? 'article' : $channel_name;
		$search_name = empty($key) ? '全部' : $key;
		$this->setSeo(array('keywords'=> $search_name, 'title'=> $search_name ));
		
		$sql = "SELECT CT.`c_id`  FROM ##__contents AS CT ,##__category AS CAT
			WHERE CT.`category_id` = CAT.`category_id` AND 
			CAT.`channel_model` = '$channel_type' AND 
			 (`long_title` like '%$key%' or `short_title` like '%$key%' OR `content` like '%$key%')
			 GROUP BY CT.`c_id` ";
		$data = $this->db->fetch($sql);
		$total = count($data);
		$se_sql = "SELECT * FROM ##__contents AS CT ,##__category AS CAT
			WHERE CT.`category_id` = CAT.`category_id` AND 
			CAT.`channel_model` = '$channel_type' AND 
			 (`long_title` like '%$key%' or `short_title` like '%$key%' OR `content` like '%$key%')
			 GROUP BY CT.`c_id` ";
		$url = building_url('models@search', 'serach', array($channel_type,$channel_name,$bs64_key));
		$e_data = page_for_db_extend($total,$se_sql,$url,20);
		$e_data['data'] = format_content($e_data['data']);
		$this->assign(array(
			'channel_id'=>$channel_type,
			'category_id'=>to_int($this->_parseItem['1']),
			'data'=>$e_data,
			'channel_name'=>$channel_name,
		));
		$this->_setNav(array(array('name'=>$type_name.$search_name)));
		$this->display('search.php');
	}
}
?>