<?php
if (!defined('IN_HANFOX')) exit('Access Denied');

$pagename = '搜索结果';
$pageurl = '?mod=shopsearch';
$tempfile = 'shopsearch.html';
$mode = 'shop';
$table = $DB->table('shop');


//搜索页不缓存
$smarty->caching = false;

$pagesize = 15;
$curpage = intval($_GET['page']);
if ($curpage > 1) {
	$start = ($curpage - 1) * $pagesize;
} else {
	$start = 0;
	$curpage = 1;
}
		
$strtype = htmlspecialchars(strtolower(trim($_GET['type'])));
$keyword = htmlspecialchars(addslashes(trim($_GET['query'])),ENT_NOQUOTES,'UTF-8');
//$keyword = mb_convert_encoding(trim($_GET['query']), "UTF-8", "gb2312");
//$keyword = htmlspecialchars($str,ENT_COMPAT,'GB2312');
//echo $keyword = stripslashes($_GET['query']);

if (!$smarty->isCached($tempfile)) {
	$where = "w.shop_status=3";
	if ($keyword) {
		$pageurl .= '&type='.$strtype.'&query='.urlencode($keyword);
				
		$smarty->assign('site_title', $keyword.' - '.$pagename.' - （第'.$curpage.'页） - '.$options['site_name']);
		$smarty->assign('site_keywords', $keyword.'，搜索结果，查询结果'.',网购导航,'.$options['site_name']);
		$smarty->assign('site_description', '以下是与关键字(词)“'.$keyword.'”相关的结果（第'.$curpage.'页）。');
		$smarty->assign('site_path', get_sitepath().' &raquo; '.$pagename.' &raquo; <font color="#ff0000">'.$keyword.'</font>');
		$smarty->assign('rss_feed', get_rssfeed());
				
		switch ($strtype) {
			case 'name' :
				$where = "w.shop_name like '%$keyword%'";
				break;
			case 'weixin' :
				$where = "w.shop_weixin like '%$keyword%'";
				break;
			case 'tags' :
				$where = "w.shop_tags like '%$keyword%'";
				break;
			case 'intro' :
				$where = "w.shop_intro like '%$keyword%'";
			default :
				$where = "w.shop_name like '%$keyword%'";
				break;
			}
		}
			
		$shop = get_shop_list($where, 'shop_ctime', 'DESC', $start, $pagesize);
		$total = $DB->get_count($table.' w', $where);
		$showpage = showpage($pageurl, $total, $curpage, $pagesize);
			
		$smarty->assign('pagename', $pagename);
		$smarty->assign('category_list', get_categories());
		$smarty->assign('archives', get_archives());
		$smarty->assign('keyword', $keyword);
		$smarty->assign('total', $total);
		$smarty->assign('shop', $shop);
		$smarty->assign('showpage', $showpage);
		$smarty->assign('mode', $mode);
		unset($shop);
}

smarty_output($tempfile, $cache_id);
?>