?php
require_once './include/common.php';
$act=trim($_REQUEST['act']);
if(!$act){
$act='list';
}
$templateid=$dtemp;
$cid=intval($_REQUEST['cid']);
if($act=='list'){
$qstr=' where type=1 ';
$keywords=trim($_REQUEST['keywords']);
$keyword2=str_replace('_', '\_', $keywords);
$keyword2=dhtmlspecialchars(daddslashes($keyword2));
if($cid||$keywords){
$qstr.=' and';
$qarr=array();
$urlarr=array();
if($cid){
$thecatetree=getcatetree($productcate, $cid);
$qarrstr='cid='.$cid;
foreach($thecatetree as $key=>$val){
if($cid!=$val['cid']){
$qarrstr.=" or cid=$val[cid]";
}
}
$qarrstr='('.$qarrstr.')';
$qarr[]=$qarrstr;
$urlstr.="&cid=$cid";
}
if($keywords){
$qarr[]="title like '%$keyword2%'";
$urlstr.="&keywords=$keywords";
}
$qstr.=implode(' and ', $qarr).' ';
}
$page=$_GET['page']?$_GET['page']:1;
$perpage=9;
$start=($page-1)*$perpage;
$query=$db->query("select count(*) from product{$qstr}");
$temp=$db->fetch_array($query);
$lcount=$temp['count(*)'];
$pcount=ceil($lcount/$perpage);
if($page>1){
$fpage=$page-1;
$firstpage="首页";
$lastpage="上一页";
}else{
$firstpage="首页";
$lastpage="上一页";
}
if($page<$pcount){
$npage=$page+1;
$endpage="末页";
$nextpage="下一页";
}else{
$endpage="末页";
$nextpage="下一页";
}
$curr=$page*$perpage;
if($curr>=$lcount){
$curr=$lcount;
}
$query=$db->query("select * from product{$qstr}order by aid desc limit $start, $perpage");
$lists=array();
$i=0;
$j=-1;
while($abinfo=$db->fetch_array($query)){
if($i%3==0){
$j++;
}
$i++;
$abinfo['ttitle']=cut_str($abinfo['title'], 42);
$abinfo['catename']=$productcate[$abinfo['cid']]['catename'];
$lists[$j][]=$abinfo;
}
if(count($lists[$j])<3){
$less=3-count($lists[$j]);
for($k=0;$k<$less;$k++){
$lists[$j][]=array();
}
}
if($cid){
$templateid=$productcate[$cid]['temp'];
}
$tpldir='./temp/'.$templateid.'/';
$catetree=array();
$productcatetree2=showtree($productcatetree, $cid);
foreach($productcatetree2 as $val){
$ischild=$val['ischild'];
if($ischild){
$val[pre]="
";
}else{
$val[pre]="
";
}
if($val['deep']>1){
$val[pre]=str_repeat(' ', $val['deep']-1).$val[pre];
}
$catetree[]=$val;
}
if($cid){
$title=$productcate[$cid]['catename'];
}else{
$title="产品中心";
}
$seotitle=$title;
include template('product_list');
}elseif($act='read'){
$aid=intval($_GET['aid']);
if(!$aid){
show("Error: 参数错误");
}
$query=$db->query("select * from product where aid=$aid");
if(!$abinfo=$db->fetch_array($query)){
show("Error: 参数错误");
}
$cid=$abinfo['cid'];
if($cid){
$templateid=$productcate[$cid]['temp'];
}
$tpldir='./temp/'.$templateid.'/';
$catetree=array();
$productcatetree2=showtree2($productcatetree, $cid);
foreach($productcatetree2 as $val){
$ischild=$val['ischild'];
if($ischild){
$val[pre]="
";
}else{
$val[pre]="
";
}
if($val['deep']>1){
$val[pre]=str_repeat(' ', $val['deep']-1).$val[pre];
}
$catetree[]=$val;
}
$catename=$productcate[$cid]['catename'];
include template('product');
}
?>