<?php
define('IN_OUN', true); 
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php");
include_once( ROOT_PATH."ads.php"); 

$Aconf['header_title'] = $Aweb_url['products'][0]."|".$Aconf["web_title"];

$pcid = $id + 0; 
/* 得到当前分类的所有下级分类 start */ 
$tmpid    = next_node_all($id,$pre."productcat","pcid",true);
$strID    = ($tmpid)?$id.$tmpid:$id; 


 /* 分类翻页 */ 
$strTmp = ($id > 0)?" AND a.pcid in($strID) ":" ";
$where = " a.states<>1 AND  a.domain_id = '".$_SESSION[$un_domain_id]."'".$strTmp; 
$sql = "SELECT COUNT(*) as count FROM ".$pre."producttxt AS a WHERE 1 AND ". $where;
$row = $oPub->getRow($sql);
$page = new ShowPage;
$page->PageSize = 15;
$page->PHP_SELF =$PHP_SELF;
$page->Total = $row["count"];
$pagenew = $page->PageNum();
$page->LinkAry = array('id'=>$pcid); 
$strOffSet = $page->OffSet(); 
$Ahome["showpage"] = ($row["count"]  > 30)?$page->ShowLink_num():'';  
$Ahome["products"] = products_list( "top","$strOffSet",$strID);
//当前分类的关联文章

/* 得到所有产品分类的关联文章分类 */
if(!empty($strID)){
	$sql = "SELECT acids FROM ".$pre."productcat  where pcid in (".$strID.") and domain_id=".$_SESSION[$un_domain_id];
	$row = $oPub->select($sql); 
	$stracids = '';
	while( @list( $k, $v) = @each( $row ) ) {
		$stracids .= $v["acids"].','; 
	}
	if(!empty($stracids)){
		$Astracids = explode(",",$stracids);
		$Aacids = array();
		while( @list( $k, $v) = @each( $Astracids ) ) {
			if($v > 0 && !in_array($v,$Aacids)){
				array_push($Aacids,$v); 
			} 
		}
		//找到当前文章分类的子分类
		
		$idtype ="acid";
		$stracids = '';
		while( @list( $k, $v) = @each( $Aacids ) ) {
			$tmpid  = next_node_all($v,$pre."articat",$idtype,true);
			$strID  = ($tmpid)?$v.$tmpid:$v;
			$stracids .= $strID.',';
		}
		$Astracids = explode(",",$stracids);
		$Aacids = array();
		while( @list( $k, $v) = @each( $Astracids ) ) {
			if($v > 0 && !in_array($v,$Aacids)){
				array_push($Aacids,$v); 
			} 
		}
		$stracids = implode(",", $Aacids); //所有关联文章分类
		$Ahome["pro_articles"] = articles_list( 'top', 20,$stracids,26);
	}
}else{
	$Ahome["pro_articles"] = articles_list( 'top', 20,'',26);
}
 /* 得到所有关联文章分类 end */

/* 当前分类的所有前置分类 用于当前位置导航 */ 
$sql = "SELECT name,fid,descs,keywords FROM ".$pre."productcat 
	where pcid = '".$pcid."'and domain_id=".$_SESSION[$un_domain_id]." limit 1";
$row = $oPub->getRow($sql);
$nowcatname = $row[name]; 
$Aconf['description']  = $row["descs"];
$Aconf['keywords']     = $row["keywords"]; 
$fid = $row[fid];  
$strPrenave = pre_node($fid,$pre."productcat","pcid",$Aconf["nowFile"],true);
$Ahome["nowNave"]  = '<A HREF="./">首页</A> > <A HREF="'.$Aconf["nowFile"].'">所有商品</a> '.$strPrenave.' > '.$nowcatname; 
$Aconf["header_title"] = $nowcatname.'|'.$Aconf['header_title'];  

if ((DEBUG_MODE & 2) != 2) {
    $smarty->caching = true;
}

$strCache_id = $_SESSION[$un_domain_id].$pcid.$pagenew; 
$cache_id = sprintf('%X', crc32($str_cache_id));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
    assign_template($Aconf); 
    $smarty->assign('home', $Ahome ); 
    $smarty->assign('user_info', $_SESSION );
    unset($Ahome);
    /* 页面中的动态内容 */
    assign_dynamic(str_replace('.html','',$str_templates));
}
$smarty->display($Aconf["displayFile"], $cache_id);  

?>
