<?php
require_once WEBROOT.'include/function.php';

$catid = intval(var_request("catid","0"));

//$catid = getnochengrencid($catid);
$page = intval(var_request("page","1"));

$sort = htmlspecialchars(var_request("sort",""),ENT_QUOTES);
if(empty($sort)) {
	$sortnum = intval(var_request("sortnum",Show_list_sort));
	$sort = proSortNumToSort($sortnum);
}


$sp = intval(var_request("sp","1"));
$ep = intval(var_request("ep","1000000"));
$cat_name = "";
$qserach = urldecode(var_request("qserach",""));

if(charset=="utf-8"){
	$qserach = Newiconv("UTF-8","GBK",$qserach);
}

if(var_request("searchbuyer","")!=""){
	if(empty($qserach)) $qserach = "柠檬绿茶";
	redirect_to(getshopurl($qserach));	
	exit;
}
if(var_request("searchshop","")!=""){
	if(empty($qserach)) $qserach = "热门";
	redirect_to(getsearchshopurl($qserach));
	exit;
}
if($qserach!=""){
	redirect_to(getsearchurl($qserach,$catid));	
	exit;
}

$q = htmlspecialchars(getcnstr(var_request("q_jt","")),ENT_QUOTES);

if(empty($q)) $q = urldecode(urldecode(var_request('q',"")));
if($qserach!=""){
	$q =$qserach;
}

$q = setsplitkeyword($searchkeypb,$q,"");

if($q=="" && $catid=="0") $q = "女装";

$qstr = ($q);

if(checkpingbi($catidpb,$catid)){
	exit("<script language=\"javascript\">alert('对不起，该类别已被屏蔽。');location.href='".$sitetitleurl."';</script>");	
}

if($catid != 0 )
{
	$Taoapi->method = 'taobao.itemcats.get';
	$Taoapi->fields = 'cid,name,parent_cid,status';
	$Taoapi->cids = $catid;
	$TaoapiCat = $Taoapi->Send('get','xml')->getArrayData();
	$TaoapiCat = $TaoapiCat["item_cats"]["item_cat"];
	$cat_name = $TaoapiCat["name"];

	if(Show_list_small){
		$Taoapi->method = 'taobao.itemcats.get';
		$Taoapi->fields = 'cid,name,parent_cid';
		$Taoapi->parent_cid = $catid;
		$TaoapiSubCats = $Taoapi->Send('get','xml')->getArrayData();
	}
}

$result_subcats = "";
$result_subcats_count = 0;

if(isset($TaoapiSubCats["item_cats"]["item_cat"])){
	$result_subcats = $TaoapiSubCats["item_cats"]["item_cat"];
	$result_subcats_count = count($result_subcats);
}
$Taoapi->method = 'taobao.taobaoke.items.get';
$Taoapi->fields = 'iid,num_iid,title,nick,pic_url,volume,price,click_url,shop_click_url,seller_credit_score,commission,commission_rate,commission_num,commission_volume';
$Taoapi->pid = $userpiddp;

if($catid!="0") $Taoapi->cid = $catid;
$Taoapi->page_no = $page;
$Taoapi->page_size = $pagenumKeys;
$Taoapi->sort = $sort;

if($sp!="1" && $ep!="1000000") {
	$Taoapi->start_price = $sp;
	$Taoapi->end_price = $ep;
}
if(!empty($defaultarea)){
	$Taoapi->area = $defaultarea;
}

if($ismall=="1")$Taoapi->mall_item = "true";

if($q!=""){
	$Taoapi->keyword = Newiconv("GBK","UTF-8",$q);
}
$Taoapi->start_credit = $shoplevelstart;
$Taoapi->end_credit  = $shoplevelend;
$Taoapi->start_commissionRate  = $stratmoneyKeys;
$Taoapi->end_commissionRate  = $endmoneyKeys;
$TaoapiItems = $Taoapi->Send('get','xml')->getArrayData();
$taobaokeItem = $TaoapiItems["taobaoke_items"]["taobaoke_item"];


$totalResults = $TaoapiItems["total_results"];
if(!isset($TaoapiItems["total_results"])){
	$totalResults = 0;
}
if($totalResults==1){
	
	$taobaokeItem = array();
	$taobaokeItem[] = $TaoapiItems["taobaoke_items"]["taobaoke_item"];
}


$cat_name = Newiconv("UTF-8","GBK",$cat_name);

if($totalResults>0){
	//过滤标题
	for($i = 0; $i < count($taobaokeItem); $i++) {
		
		if(!isset($taobaokeItem[$i]["title"])) break;
		$taousernick = Newiconv("utf-8","gbk",$taobaokeItem[$i]["nick"]);
		
		$taobaokeItem[$i]["title"] = Newiconv("UTF-8","GBK",(strip_tags($taobaokeItem[$i]["title"])));
		
		$taobaokeItem[$i]["title"] = setsplitkeyword($searchkeypb,$taobaokeItem[$i]["title"],"***");
		
		$taobaokeItem[$i]["title"] =  Newiconv("GBK","UTF-8",strtr($taobaokeItem[$i]["title"],"'","’"));


		$taobaokeItem[$i]["taodiurl"] = getproducturl($taobaokeItem[$i]["num_iid"]);
		$taobaokeItem[$i]["taodishopurl"] = getshopurl($taousernick);
		
	}
}else{
	$taobaokeItem = null;
}
if($list_title=="")$list_title = "{类别名}{关键词}_{网站名}";
if($list_keyword=="")$list_keyword = "{类别名}{关键词},淘宝{类别名}{关键词}";
if($list_discription=="")$list_discription = "您所查看的是{类别名}{关键词},{网站名}提醒您，使用支付宝交易，先收货后付款！";

$tihuanarr = array();
$tihuanarr["{类别名}"] = $cat_name;
$tihuanarr["{关键词}"] = $q;
$tihuanarr["{网站名}"] = $sitetitle;


$page_title = strtr($list_title,$tihuanarr); 
$page_keyword = strtr($list_keyword,$tihuanarr); 
$page_discription = strtr($list_discription,$tihuanarr); 

if($is_indexs=="ok"){
	$page_title = $sitetitle;
	$page_keyword = $sitekey; 
	$page_discription = $sitedesc; 
}

require_once WEBROOT.'include/functiondaohang.php';

require_once(WEBROOT."include/pages.php");

//加载模板
require_once WEBROOT.'template/'.$templatefolder.'/list.php';
showend();

?>
