<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2010 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/
class Personal
{
	function Personal()
	{
		//缓存
		if($GLOBALS["WebConfig"]["webtmp"]==1)
		{
			$GLOBALS['Templ'] -> caching = true;
			if($GLOBALS["WebConfig"]["webtmptime"] > 0 )
			{
				$GLOBALS['Templ'] -> cache_lifetime = $GLOBALS["WebConfig"]["webtmptime"] ;
			}else{
				$GLOBALS['Templ'] -> cache_lifetime = 3600 ;  //60 *  60 * 24
			}
 
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'];
		}
		
		
		$getconfig = $GLOBALS['Helpe'] -> get_config();
		$GLOBALS['Templ'] -> assign('getconfig',$getconfig);

		$getmenu = $GLOBALS['Helpe'] -> get_menu();
		$GLOBALS['Templ'] -> assign('getmenu',$getmenu);
		
		$getprosort = $GLOBALS['Helpe'] -> get_prosort();
		$GLOBALS['Templ'] -> assign('getprosort',$getprosort);
		
		$getlink = $GLOBALS['Helpe'] -> get_link();
		$GLOBALS['Templ'] -> assign('getlink',$getlink);
			
		$getads = $GLOBALS['Helpe'] -> get_ads( $instr = '1,2,3,4,5,6,7,8,9,10,11' );
		$GLOBALS['Templ'] -> assign('getads',$getads);
		
		$getuserlink = $GLOBALS['WebSe']->getuserlink();
		$GLOBALS['Templ']->assign('getuserlink',$getuserlink);
		
	}
	
	
	function index()
	{
		$typeval = $_REQUEST["type"];

		if($typeval =='')
		{
			$typeval = 'index';
		}

		$sqlQuery 	= " SELECT per_id,per_column,per_main  FROM  ".SQL_PREFIX."personal  WHERE per_type = '".$typeval."' ORDER BY `per_id`  ";
			
		$infoper 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
		
		$this -> getcolumn($infoper["per_column"]);
		
		$this -> getmain($infoper["per_main"]);
		
		if($typeval !='' )
		{
			$cache_id = $typeval;
		}
		$GLOBALS['Templ'] -> display('personal_tpl.html',$cache_id);
	
	}
	
	function getcolumn( $typestr = '' )
	{

		$typestrArray = explode('|',$typestr);

		
		foreach((array)$typestrArray as $tkey => $tval )
		{
			if($tval!='')
			{
				$array = array('con'=>$tval);
				$perArray[$tval] = $this -> getData( $array );
			}
		}
		
		$GLOBALS['Templ']->assign('perArray',$perArray);
		
	}
	
	function getmain( $typestr = '' )
	{

		@eval(base64_decode($typestr));

		foreach((array)$mainArray as $key => $val)
		{

			$perRightInfo[] = $this -> getData( $val );
		}
		
		$GLOBALS['Templ']->assign('perRightInfo',$perRightInfo);
		
	}
	
	function getData( $array = array() )
	{		
		if( $array["con"] != '' )
		{
			switch ($array["con"]){
			case 'artsort':
				return $GLOBALS['Helpe']  -> get_artsort();
				break;
			case 'prosort':
				return $GLOBALS['Helpe']  -> get_prosort();				
				break;
			case 'artlice':
				return $this  -> get_art($array["sid"],$array["n"]);

				break;
			case 'product':
				return $this  -> get_pro($array["sid"],$array["n"]);

				break;
			case 'contact':
				return $GLOBALS['contactArray'];
				break;
				
			default:
				return false;
			}
		}else{
			return false;
		}
	}
	
	function get_art( $sid = '', $num = '10')
	{
		$info["title"] = '最新新闻';
		
		if( $sid != '' )
		{
			$seletsort = " SELECT ars_id,ars_name  FROM ".SQL_PREFIX."artsort WHERE ars_id = ".$sid." or  ars_parentid = ".$sid ;
			$sortInfo  = $GLOBALS['MySql']  ->  selectInfo($seletsort);
			
			$sinid 	   = $sid;

				foreach((array)$sortInfo as $skey => $sval )
				{
					if( $sval["ars_id"]== $sid )
					{
						$info["title"]  = $sortval = $sval["ars_name"];
					}
 						$sinid .= ','.$sval["ars_id"];
				}
			
			$sqlQuery 		= " SELECT art_id, art_title , art_uptime   FROM  ".SQL_PREFIX."artlice   WHERE art_sysfile ='' and  art_enabled = 1 and  ars_id in ( ".$sinid." ) ".$whereadd."  GROUP BY  art_id ORDER BY art_uptime DESC, `art_id` LIMIT  0 , $num ";

		}else{
			$sqlQuery 		= " SELECT art_id, art_title , art_uptime   FROM  ".SQL_PREFIX."artlice   WHERE art_sysfile ='' and  art_enabled = 1  GROUP BY  art_id ORDER BY art_uptime DESC,  `art_id` LIMIT  0 , $num ";
			
		}
		
		$info["artinfo"] = $GLOBALS['MySql']  -> selectInfo($sqlQuery);
		
		foreach ((array)$info["artinfo"] as $akey => $row)
		{
			$info["artinfo"][$akey]["get_url"]	= $GLOBALS['Helpe']  -> buildUrl( $valid = $row["art_id"],'art');
		}
		
		return $info;
	}
	
	function get_pro( $sid = '', $num = '8')
	{
		
		$addsql = '';
		
 		$info["title"] 	= '最新商品';
		
		if( $sid != '' )
		{
			$seletsort = " SELECT prs_id,prs_name  FROM ".SQL_PREFIX."prosort WHERE prs_id = ".$sid." or  prs_parentid = ".$sid ;
			$sortInfo  = $GLOBALS['MySql']  ->  selectInfo($seletsort);
			$sinid 	   = '';


			foreach((array)$sortInfo as $skey => $sval )
			{
				if( $sval["prs_id"]== $sid )
				{
					$info["title"] 	= $sortval = $sval["prs_name"];
					 
				}
				if($skey==0)
				{
					$sinid = $sval["prs_id"];
				}else{
					$sinid .= ','.$sval["prs_id"];
				}
			}
			if($sinid=='')
			{
				$addsql = " and prs_id in ( ".$sid." ) ";
			}else{
				$addsql = " and prs_id in ( ".$sinid." ) ";
			}
		}

		 $sqlQuery 	= " SELECT pro_id, pro_name ,pro_img, pro_uptime   FROM  ".SQL_PREFIX."product   WHERE pro_enabled = 1 $addsql  GROUP BY  pro_id ORDER BY  `pro_id` LIMIT  0 , $num ";
 
		$info["proinfo"] 	= $GLOBALS['MySql']  ->  selectInfo( $sqlQuery );
		
		

		foreach((array)$info["proinfo"] as $pkey => $pval )
		{
			 $info["proinfo"][$pkey]["pro_img"] = $GLOBALS['Helpe'] -> buildImg( $pval["pro_img"] ) ;  
			 $info["proinfo"][$pkey]["get_url"]	= $GLOBALS['Helpe'] -> buildUrl( $valid = $pval["pro_id"],'pro');
		}

		return $info;
		
	}

}

	


$Personal = new Personal();

?>