<?php 
/* 显示的模块 */
if (!defined('IN_OUN')) {
    die('Hacking attempt');
} 
/* 基本配置信息 */
$n = 0;
$Asets = explode("]",$Aconf['home']);   
foreach ($Asets as $v) {
   $At = array();
   $At = explode("|",$v); 
   if($At[0] == 'one') {
	   $Atv = explode(";",$At[1]);
	   foreach($Atv as $val) {
		   $Atmp = explode(":",$val);
		   if($Atmp[0]) {
			   $Aitem["one"][$Atmp[0]] = explode(",",$Atmp[1]);
			}
		}
	}
   if($At[0] == 'two')
	{
	   $Atv = explode(";",$At[1]);
	   foreach($Atv as $val) {
		   $Atmp = explode(":",$val);
		   if($Atmp[0]) {
			   $Aitem["two"][$Atmp[0]] = explode(",",$Atmp[1]);  
			}
		}
	}

   if($At[0] == 'three') {  
       $Atv = explode(";",$At[1]);
       foreach($Atv as $val) {
           $Atmp = explode(":",$val);
           if($Atmp[0]) {
               $Aitem["three"][$Atmp[0]] = explode(",",$Atmp[1]);     
               $Aitem["three"][$Atmp[0]][2] = str_replace("~", ',',$Aitem["three"][$Atmp[0]][2]);
            }
        }
    }
}//forreach($Asets as $v)
/* one  start */
 //公告 
if($Aitem["one"]["notices"][0]){
	$Aconf["notices_title"] = $Aitem["one"]["notices"][3]; 
}else{
	$Aconf["notices"] = false;
}
 //公司简介
if($Aitem["one"]["descs"][0]){
	$Aconf["descs_title"] = $Aitem["one"]["descs"][3]; 
}else{
	$Aconf["descs"] = false;
}
 //新闻分类,只得到二级分类
if($Aitem["one"]["articat"][0]){
	$Ahome["articat_title"] = $Aitem["one"]["articat"][3];  
	$sql = "SELECT acid,name,next_node FROM ".$pre."articat 
			where fid = 0 
			AND domain_id=$_SESSION[$un_domain_id]  
			ORDER BY acid ASC";
	$row = $oPub->select($sql); 
	while( @list( $key, $val ) = @each( $row ) ) {
		$row[$key]['name'] = $val["name"];
		if($Aconf['rewrite']){
			$row[$key]['name_url'] = 'articles-'.$val["acid"].'-0.html';
		}else{
			$row[$key]['name_url'] = 'articles.php?id='.$val["acid"]; 
		}
		//得到下级分类
		$row[$key]["next_node"] = '';
		$tmpid  = next_node_all($val["acid"], $pre."articat","acid",false);
		if($tmpid){
			$Atmp = explode(",",$tmpid);
			$tmpid = '';
			while( @list( $keyx, $valx ) = @each( $Atmp ) ) {
				if($valx > 0 ){
					$tmpid  .=$valx.',';
				}
			}
			if($tmpid){
				$tmpid = substr($tmpid,0,-1);
			} 
		} 
		if($tmpid){ 
			$sql = "SELECT acid,name FROM ".$pre."articat 
			where acid in($tmpid)   
			AND domain_id=$_SESSION[$un_domain_id]  
			ORDER BY acid ASC";
			$rownext = $oPub->select($sql); 
			$str = '';
			while( @list( $keyy, $valy ) = @each( $rownext ) ) {
				if($Aconf['rewrite']){
					$str = '<a href="articles-'.$valy["acid"].'-0.html">'.$valy["name"].'</a>';
				}else{
					$str= '<a href="articles.php?id='.$valy["acid"].'">'.$valy["name"].'</a>';
				}
				$rownext[$keyy]["sub_next"] = $str;
			}
			$row[$key]["next_node"] = $rownext; 
		}

	}
	$Ahome["articat"] = $row;

}else{
	$Ahome["articat"] = false;
} 
 //商品分类
if($Aitem["one"]["productcat"][0]){
	$Ahome["productcat_title"] = $Aitem["one"]["productcat"][3];
	$sql = "SELECT pcid,name,next_node FROM ".$pre."productcat 
			where fid = 0 
			AND domain_id=$_SESSION[$un_domain_id]  
			ORDER BY pcid ASC";
	$row = $oPub->select($sql); 
	while( @list( $key, $val ) = @each( $row ) ) {
		$row[$key]['name'] = $val["name"];
		if($Aconf['rewrite']){
				$row[$key]['name_url'] = 'products-'.$val["pcid"].'-0.html';
		}else{
				$row[$key]['name_url'] = 'products.php?id='.$val["pcid"]; 
		}
		//得到下级分类
		$row[$key]["next_node"] = '';
		$tmpid  = next_node_all($val["pcid"], $pre."productcat","pcid",false);
		if($tmpid){
			$Atmp = explode(",",$tmpid);
			$tmpid = '';
			while( @list( $keyx, $valx ) = @each( $Atmp ) ) {
				if($valx > 0 ){
					$tmpid  .=$valx.',';
				}
			}
			if($tmpid){
				$tmpid = substr($tmpid,0,-1);
			} 
		} 
		if($tmpid){ 
			$sql = "SELECT pcid,name FROM ".$pre."productcat 
			where pcid in($tmpid)   
			AND domain_id=$_SESSION[$un_domain_id]  
			ORDER BY pcid ASC";
			$rownext = $oPub->select($sql); 
			$str = '';
			while( @list( $keyy, $valy ) = @each( $rownext ) ) {
				if($Aconf['rewrite']){
					$str = '<a href="products-'.$valy["pcid"].'-0.html">'.$valy["name"].'</a>';
				}else{
					$str= '<a href="products.php?id='.$valy["pcid"].'">'.$valy["name"].'</a>';
				}
				$rownext[$keyy]["sub_next"] = $str;
			}
			$row[$key]["next_node"] = $rownext; 
		}

	}
	$Ahome["productcat"] = $row;
}else{
	$Ahome["productcat"] = false;
}
 //推荐调查
if($Aitem["one"]["vote"][0]){
	$Ahome["vote_title"] = $Aitem["one"]["vote"][3]; 
	$Ahome["vote"] = false;
	$sql = "SELECT a.vtid,a.vt_name,a.vt_desc FROM ".$pre."vote_title AS a 
		WHERE a.states=0 AND a.is_show = 1  AND	 a.domain_id = ".$_SESSION[$un_domain_id]." order by top desc,vtid desc limit 1";
	$row = $oPub->getRow($sql);
	$Ahome["vote"]["vote_title"] = $row;
	if($row) {  
		$Ahome["vote"]["for_vote_group"]= vote($row["vtid"]); 
	}  
}else{
	$Ahome["vote"] = false;
} 
/* two start  */
//新闻列表
if($Aitem["two"]["articles"][0]){
	$Ahome["Tarticles_title"] = $Aitem["two"]["articles"][3]; 
	$orderby = 'arti_date';$limits=$Aitem["two"]["articles"][1];$substr=30;
	$Ahome['Tarticles'] = articles_list($orderby, $limits,$acid='',$substr);
}else{
	$Ahome["Tarticles"] = false;
}
//置顶新闻
if($Aitem["two"]["articles_top"][0]){
	$Ahome["Tarticles_top_title"] = $Aitem["two"]["articles_top"][3]; 
	$orderby = 'top';$limits=$Aitem["two"]["articles_top"][1];$substr=30;
	$Ahome['Tarticles_top'] = articles_list($orderby, $limits,$acid='',$substr); 
}else{
	$Ahome["Tarticles_top"] = false;
}
//焦点新闻
if($Aitem["two"]["articles_focus"][0]){
	$Ahome["Tarticles_focus_title"] = $Aitem["two"]["articles_focus"][3];
	$orderby = 'focus';$limits=$Aitem["two"]["articles_focus"][1];$substr=30;
	$Ahome["Tarticles_focus"] = articles_list($orderby, $limits,$acid='',$substr); 	 
}else{
	$Ahome["Tarticles_focus"] = false;
}
//滚动新闻
if($Aitem["two"]["articles_trundle"][0]){
	$Ahome["Tarticles_trundle_title"] = $Aitem["two"]["articles_trundle"][3]; 
	$orderby = 'trundle';$limits=$Aitem["two"]["articles_trundle"][1];$substr=30;
	$Ahome["Tarticles_trundle"] = articles_list($orderby, $limits,$acid='',$substr);	
}else{
	$Ahome["Tarticles_trundle"] = false;
}
//新闻图库
if($Aitem["two"]["articles_ifpic"][0]){
	$Ahome["Tarticles_ifpic_title"] = $Aitem["two"]["articles_ifpic"][3]; 
	$orderby = 'ifpic';$limits=$Aitem["two"]["articles_ifpic"][1];$substr=30;
	$Ahome["Tarticles_ifpic"] = articles_list($orderby, $limits,$acid='',$substr,' a.ifpic=1');
}else{
	$Ahome["Tarticles_ifpic"] = false;
}
//评论最多的文章
if($Aitem["two"]["articles_comms"][0]){
	$Ahome["Tarticles_comms_title"] = $Aitem["two"]["articles_comms"][3]; 
	$orderby = 'comms';$limits=$Aitem["two"]["articles_comms"][1];$substr=30;
	$Ahome["Tarticles_comms"] = articles_list($orderby, $limits,$acid='',$substr);
}else{
	$Ahome["Tarticles_comms"] = false;
}
//商品列表
if($Aitem["two"]["products"][0]){
	$Ahome["Tproducts_title"] = $Aitem["two"]["products"][3]; 
	$limit = $Aitem["two"]["products"][1]; 
	$orderby = 'up_date';$limits=$Aitem["two"]["products"][1];
	$Ahome['Tproducts'] = products_list($orderby, $limit);

}else{
	$Ahome["Tproducts"] = false;
}
//推荐商品
if($Aitem["two"]["products_top"][0]){
	$Ahome["Tproducts_top_title"] = $Aitem["two"]["products_top"][3]; 
	$limit = $Aitem["two"]["products_top"][1]; 
	$orderby = 'top';$limits=$Aitem["two"]["products_top"][1];
	$Ahome['Tproducts_top'] = products_list($orderby, $limit);
}else{
	$Ahome["Tproducts_top"] = false;
}
//推荐品牌
if($Aitem["two"]["probrand"][0]){
	$Ahome["Tprobrand_title"] = $Aitem["two"]["probrand"][3]; 
	$limit = $Aitem["two"]["probrand"][1]; 
	$sql   = "SELECT prbid,brand_name,brand_logo  FROM ".$pre."probrand 
		   WHERE `domain_id` ='".$_SESSION[$un_domain_id]."' AND is_show=1 
		   order by sort_order asc 
		   LIMIT ".$limit; 
    $row = $oPub->select($sql);
    if($row)
    foreach ($row AS $key=>$value) {
		$row[$key]["brand_logo"] = ($value["brand_logo"] == '')?'images/command/no_brandimgs.png':'data/brandlogo/'.$value["brand_logo"];	
		if($Aconf['rewrite']){
			$row[$key]['brand_url'] = 'brand-'.$value["prbid"].'-0.html'; 
		}else{
			$row[$key]['brand_url'] = 'brand.php?id='.$value["prbid"]; 
		} 	   
    }
	$Ahome["Tprobrand"] = $row; 
}else{
	$Ahome["Tprobrand"] = false;
}
//推荐经销商
if($Aitem["two"]["pravail"][0]){ 
	$Ahome["Tpravail_title"] = $Aitem["two"]["pravail"][3];  
	$limit = $Aitem["two"]["pravail"][1]; 
    //$sql = "SELECT praid,pra_name,shop_logo  FROM ".$pre."pravail WHERE domain_id=".$_SESSION[$un_domain_id]." AND ifshow=1 and cotype = 0 ORDER BY sort_order,praid ASC";
	$sql = "SELECT praid,pra_name,shop_logo  FROM ".$pre."pravail WHERE domain_id=".$_SESSION[$un_domain_id]." and cotype = 0 ORDER BY sort_order,praid ASC";
    $row = $oPub->select($sql); 
	if($row)
    foreach ($row AS $key=>$val) {	
		$row[$key]["shop_logo"] = ($val["shop_logo"] == '')?'images/command/no_shoplogo.png':$val["shop_logo"];
		if($Aconf['rewrite']){
			$row[$key]['pravail_url'] = 'shop-'.$val["praid"].'.html'; 
		}else{
 			$row[$key]['pravail_url'] =  'shop.php?id='.$val["praid"];
		} 
	}
	$Ahome["Tpravail"] = $row;
}else{
	$Ahome["Tpravail"] = false;
}
 
//调查列表
if($Aitem["two"]["votes"][0]){
	$Ahome["Tvotes_title"] = $Aitem["two"]["votes"][3]; 
	$limit = $Aitem["two"]["votes"][1];
	$where = "a.states=0 AND a.is_show = 1 AND a.domain_id = ".$_SESSION[$un_domain_id];
	$sql = "SELECT a.vtid,a.vt_name,a.vt_desc,a.vt_nums,a.add_time 
		   FROM ".$pre."vote_title as a  WHERE  $where 
			ORDER BY a.add_time DESC   
			LIMIT ". $limit;
	$row = $oPub->select($sql);
	if($row ) { 
		foreach ($row AS $key=>$val) {
			$row[$key]['vt_desc'] = sub_str(clean_html($val["vt_desc"]),100,true);
			$row[$key]['add_time']  = ($val['add_time'])?date("m月d日h:i", $val['add_time']):'';
			if($Aconf['rewrite']){
				$row[$key]['vt_url'] = 'vote-'.$val["vtid"].'-0.html'; 
			}else{
				$row[$key]['vt_url'] =  'vote.php?id='.$val["vtid"];
			} 
		} 
		$Ahome["Tvotes"] = $row ;
	}
}else{
	$Ahome["Tvotes"] = false;
}
//友情链接
if($Aitem["two"]["links"][0]){
	$Ahome["links_title"] = $Aitem["two"]["links"][3];  

	$strWhere = ($Aconf['links'])?" is_show=1 AND ":"  ";
	$strWhere = " WHERE ".$strWhere."  domain_id=".$_SESSION[$un_domain_id];

    $sql = "SELECT lk_name,lk_logo,site_url  FROM ".$pre."links ".$strWhere."  
		    ORDER BY sort_order,lkid ASC limit ".$Aitem["two"]["links"][1];
    $Alinks = $oPub->select($sql);
    if($Alinks)
    foreach ($Alinks AS $key=>$value)
    {
       $Alinks[$key]["lk_logo"] = ($value["lk_logo"] == '')?false:'data/links/'.$value["lk_logo"];
    }
	$Ahome["links"] = $Alinks; 
}else{
	$Ahome["links"] = false;
}    
/* three  start */
/* 新闻多个分类的综合调用
    所有分类调用$home.acids
    单个分类调用$home.acids.$key (其中key值通过后台，模版管理->页面显示设置，新闻子分类确认)   
    单个分类标题调用 $home.acids_title.$key                                                                                           
*/
if(!isset($Aitem["three"])) $Aitem["three"]=false; 
if($Aitem["three"]){
    $Aacids = array();
    foreach ($Aitem["three"] AS $key=>$Av) {
        if($Av[0]){ 
            $Aacids[$key]["title"] = $Av[3]; 
            $orderby = 'top';$limits=$Av[1];$substr=30;
			if(count(explode(",",$Av[2])) > 1){
				$Aacids[$key]["url"]   = 'articles.php?more='.$Av[2];
			}else{
				$Aacids[$key]["url"]   = 'articles.php?id='.$Av[2];
			}
            $Aacids[$key]["list"] = articles_list($orderby, $limits,$Av[2],$substr);  
        }else{
            $Aacids[$key] = false;
        }    
    }
    $Ahome["acids"] =  $Aacids;  
}

//推荐管理 start 
$sql = "SELECT id,name,imgwidth,imgheight,limits 
		FROM ".$pre."tjcat WHERE domain_id='".$_SESSION[$un_domain_id]."' ORDER BY id ASC";
$rowtj = $oPub->select($sql);
$Atj = array();
while( @list($k, $v) = @each($rowtj)){ 
	$keys = 'tj_'.$v["id"]; 
	$sql = "SELECT * FROM  ".$pre."tj 
			where tjcatid='".$v["id"]."' order by orders limit ".$v["limits"];
	$rowtjvalue = $oPub->select($sql);
	$picxs = $links = $texts = '';
	while( @list($key, $val) = @each($rowtjvalue)){ 
		if($val["img"]){
			$rowtjvalue[$key]["img"] = 'data/tj/'.$val["img"];
		}else{
			$rowtjvalue[$key]["img"] = 'images/command/no_imgsbig.png';
		} 
       $picxs .= $rowtjvalue[$key]["img"].'|';
	   $links .= $val["url"].'|';
       $texts .= $val["name"].'|';
	}
	if(!empty($picxs)) { 
		$Aflashrow['pics']     = substr($picxs,0,-1);
		$Aflashrow['links']     = substr($links,0,-1);
		$Aflashrow['texts']    = substr($texts,0,-1);
		$Atjflash[$v["id"]] = $Aflashrow; 
	}	

	$Atj[$keys] = $rowtjvalue;
	$Atj[$v["id"]] = $v;
	
}
$Ahome["tj"] = $Atj;
$Ahome["tjflash"] = $Atjflash;//flash形式展播
//导航条
$Ahome["nav"] = get_nav(); 
?>