<?php
//首页商品搜索结果

function GoodsSearchResult(){

		global $fsql,$tbl_shop_con,$pages,$page,$tbl_member_rights,$CartType,$ShowpagesTempString;
		

		$key=$_GET["key"];
		$searchmenuid=$_GET["searchmenuid"];
		$searchcatid=$_GET["searchcatid"];
		$fromprice=$_GET["fromprice"];
		$toprice=$_GET["toprice"];
		$supersearch=$_GET["supersearch"];
		$prop1=$_GET["prop1"];
		$prop2=$_GET["prop2"];
		$prop3=$_GET["prop3"];
		$prop4=$_GET["prop4"];
		$prop5=$_GET["prop5"];

		$fromprice=$fromprice+0;
		$toprice=$toprice+0;
		$key=chop(trim($key));

		if($supersearch=="yes"){
		return "";
		}
		$Temp=LoadTemp("temp/goodssearch.htm");


		$scl="  fabu='1' ";

		if($searchmenuid!="" && $searchmenuid!="0"){
			$scl.="  and menuid='$searchmenuid' ";
		}

		if($key!=""){
			$scl.=" and (title regexp '$key' or bn  regexp '$key' or memo  regexp '$key' or body  regexp '$key')  ";
		}

		if($searchcatid!="0" && $searchcatid!=""){
			$fmdpath=fmpath($searchcatid);
			$scl.=" and catpath regexp '$fmdpath' ";

		}

	
		if(isset($_COOKIE["MEMBERID"])){
			$memberid=$_COOKIE["MEMBERID"];
			$fsql->query("select secureset from $tbl_member_rights where memberid='$memberid' and securetype='price'");
			if($fsql->next_record()){
				$secureset=$fsql->f('secureset');
				$pricestr="price".$secureset;
			}else{
				$pricestr="price1";
			}
		}else{
			$pricestr="price1";
		
		}

		if($fromprice!=""){
			$scl.=" and ".$pricestr.">=".$fromprice." ";
		}
		if($toprice!=""){
			$scl.=" and ".$pricestr."<=".$toprice." ";
		}

		if($prop1!=""){
			$scl.=" and prop1 regexp '$prop1'  ";
		}
		if($prop2!=""){
			$scl.=" and prop2 regexp '$prop2'  ";
		}
		if($prop3!=""){
			$scl.=" and prop3 regexp '$prop3'  ";
		}
		if($prop4!=""){
			$scl.=" and prop4 regexp '$prop4'  ";
		}
		if($prop5!=""){
			$scl.=" and prop5 regexp '$prop5'  ";
		}

		

		$totalnums=TblCount($tbl_shop_con,"id",$scl);

		$pages = new pages;		
		$pages->setvar(array("key" => $key, "nowmenuid" => $nowmenuid,"searchmenuid" => $searchmenuid, "searchcatid" => $searchcatid, "cpath" => $cpath,"catid" => $catid,"fromprice" => $fromprice,"toprice" => $toprice,"prop1" => $prop1,"prop2" => $prop2,"prop3" => $prop3,"prop4" => $prop4,"prop5" => $prop5));
		$pages->set(10,$totalnums);		                          
		$pagelimit=$pages->limit();	  

		$FormString="<table  border=0 cellspacing=0 cellpadding=4 width=100% align=center>";
		$kk=1;
		$vv=0;

		

		$fsql->query("select * from $tbl_shop_con where $scl order by id desc  limit $pagelimit");
		
		while($fsql->next_record()){
				$id=$fsql->f('id');
				$goodsmenuid=$fsql->f('menuid');
				$title=$fsql->f('title');
				$body=$fsql->f('body');
				$catpath=$fsql->f('catpath');
				$dtime=$fsql->f('dtime');
				$nowcatid=$fsql->f('catid');
				$cl=$fsql->f('cl');
				$memo=$fsql->f('memo');
				$bn=$fsql->f('bn');
				$kucun=$fsql->f('kucun');
				$src=$fsql->f('src');
				$type=$fsql->f('type');
				$xtsrc=$fsql->f('xtsrc');
				$fabu=$fsql->f('fabu');
				$tejia=$fsql->f('tejia');
				$tj=$fsql->f('tj');
				$remai=$fsql->f('remai');
				$danwei=$fsql->f('danwei');
				$xiaoliang=$fsql->f('xiaoliang');
				$price0=$fsql->f('price0');
				$price1=$fsql->f('price1');
				$price2=$fsql->f('price2');
				$price3=$fsql->f('price3');
				$price4=$fsql->f('price4');
				$price5=$fsql->f('price5');
				$price6=$fsql->f('price6');
				$price7=$fsql->f('price7');
				$price8=$fsql->f('price8');
				$price9=$fsql->f('price9');
				$price10=$fsql->f('price10');
				$price11=$fsql->f('price11');
				$price12=$fsql->f('price12');
				$price=NowPrice($id,$price1,$price2,$price3,$price4,$price5,$price6,$price7,$price8,$price9,$price10,$price11,$price12);

				

				if($CartType=="pop"){
					$cartlink="popcart.php?nowmenuid=$goodsmenuid&gid=$id";
				}else{
					$cartlink="cart.php?nowmenuid=$goodsmenuid&gid=$id";
				}
				if($src=="")    {
					
					$src="images/noimg.gif";
					$type="gif";
					

				}
				
				$goodslink="shop_detail.php?id=$id&nowmenuid=$goodsmenuid&cpath=$catpath&catid=$nowcatid";
				$lookpic="popimage.php?xtsrc=".$xtsrc."&src=".$src;
				
				$savemoney=$price0-$price;
				
				$title=str_replace("$key","<font color=red>".$key."</font>",$title);
				$memo=csubstr(Chop(strip_tags($memo)),0,160,"1");
				$memo=str_replace("$key","<font color=red>".$key."</font>",$memo);
				
				if($kk==1)      {$FormString.="<tr>";	}
				$tempstr=str_replace("{#src#}",$src,$Temp);
				$tempstr=str_replace("{#bn#}",$bn,$tempstr);
				$tempstr=str_replace("{#goods#}",$title,$tempstr);
				$tempstr=str_replace("{#lookpic#}",$lookpic,$tempstr);
				$tempstr=str_replace("{#price0#}",$price0,$tempstr);
				$tempstr=str_replace("{#price#}",$price,$tempstr);
				$tempstr=str_replace("{#savemoney#}",$savemoney,$tempstr);
				$tempstr=str_replace("{#store#}",$kucun,$tempstr);
				$tempstr=str_replace("{#unit#}",$danwei,$tempstr);
				$tempstr=str_replace("{#click#}",$cl,$tempstr);
				$tempstr=str_replace("{#intro#}",$memo,$tempstr);
				$tempstr=str_replace("{#cartlink#}",$cartlink,$tempstr);
				$tempstr=str_replace("{#goodslink#}",$goodslink,$tempstr);
				$FormString.="<td width=100% valign=top>".$tempstr."</td>";
				if($kk==1){
					$FormString.="</tr>";
					$kk=0;
				}
				
				
		$kk++;
		$vv++;
								
				
		}

		if($vv<1){
			$FormString.="<tr><td><br>对不起,没有找到您搜索的商品!<br><br><br><br><br><br></td></tr>";
		}

		$FormString.="</table>";

		$ShowpagesString.="<table width=100% border=0 cellspacing=0 cellpadding=2 align=center><tr><td class=pages width=50%>&nbsp;";
		$ShowpagesString.=$pages->ShowNow();
		$ShowpagesString.="</td><td class=pages width=50% align=right>";
		$ShowpagesString.=$pages->output($ShowPageList);
		$ShowpagesString.="</td></tr></table>";
		$FormString.=EditTemp($TitleEnd,"Showpages",$ShowpagesString,"hidden",$ShowpagesTempString);
		return $FormString;


}
?>