<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2010 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/
class Pro
{
	function Pro()
	{
		
		//缓存
		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
			}
			$smdirid 	= trim($_REQUEST["id"]).trim($_REQUEST["pageNum"]);
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$GLOBALS['Helpe'] -> buildsmartydir( $type = 'p', $smdirid );
		}
		
		$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);
		
		
		$act = trim($_REQUEST["act"]);
		if($act=='')
		{
			$this -> infolist();
		}
		
	}
	
	function infolist()
	{
	
		$sid 		= trim($_REQUEST["sid"]);
		$pageNum 	= trim($_REQUEST["pageNum"]);
		
		$pageSize = 16 ;

		if( $pageNum > 1 )
		{
			$pageNum  = $pageNum;
			$LIMITnum = ceil( ( $pageNum -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}

		
		$addsql = '';

		$webtitle = '商品中心';
		//处理你现在的位置
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/pro.html">商品中心</a>';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=pro&act=infolist">商品中心</a>';
		}

		if( $sid > 0 )
		{
			$addsql = " and prs_id = ".$sid;
			$endArray["sid"] = $sid;
		}
		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 	   = '';
			$addpage   = '&sid='.$sid;
			if($sortInfo!='')
			{
				foreach( $sortInfo as $skey => $sval )
				{
					if( $sval["prs_id"]== $sid )
					{
						$webtitle 	= $sortval = $sval["prs_name"];
						if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
						{
							$nowaddress = $nowaddress. ' > <a href="'.BASE_WEBURL.'/pro-list-1-'.$sid.'.html">'.$sval["prs_name"].'</a>';
						}else{
							$nowaddress = $nowaddress. ' > <a href="'.BASE_WEBURL.'/?load=pro&act=infolist'.$addpage.'">'.$sval["prs_name"].'</a>';
						}
					}
					if($skey==0)
					{
						$sinid = $sval["prs_id"];
					}else{
						$sinid .= ','.$sval["prs_id"];
					}
				}
			}
			$addsql = " and prs_id in ( ".$sinid." ) ";
		}
		
		
		if($GLOBALS['Reque'] -> reqval["keyword"] !='')
		{   
			$keywordval 	= $GLOBALS['Reque'] -> reqval["keyword"];
			$keywordval  	= urldecode($keywordval); 
		}
		if($keywordval!='')
		{ 	
			$endArray["keyword"] =$keywordval;
			$endurl 	   .= '&keyword='.urlencode($keywordval);
			$addsql .= " AND ( pro_name LIKE  '%".$keywordval."%' )";  
		}
		

		$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  $LIMITnum , $pageSize ";
		$info 		= $GLOBALS['MySql']  ->  selectInfo( $sqlQuery );
		
		
		foreach((array)$info as $pkey => $pval )
		{
			 $info[$pkey]["pro_img"] = $GLOBALS['Helpe'] -> buildImg( $pval["pro_img"] ) ;
			 $info[$pkey]["pro_url"]= $GLOBALS['Helpe']  -> buildUrl( $valid = $pval["pro_id"],'pro');
		}

		
		$sqlQuery 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."product  WHERE pro_enabled = 1 $addsql ORDER BY `pro_id`  ";
		
		$infocount 	= $GLOBALS['MySql']  ->  selectOne( $sqlQuery );
		
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$url = BASE_WEBURL.'/pro-list';
			$endArray["sid"] = $sid;
		}else{
			$url = './?load=pro&act=infolist'.$addpage.$addurl;
		}
		$PageStr 	= $GLOBALS['Page'] -> buildPageStr( $url , $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] ,$endArray );
		
		
		
		$GLOBALS['Templ'] -> assign('keyword',$keywordval);
		
		$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
		$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
		$GLOBALS['Templ'] -> assign('PageStr',$PageStr);
		$GLOBALS['Templ'] -> assign('info',$info);
		if($sid !='' or $pageNum!='' or  $newkeyword !='')
		{
			$cache_id = $sid.'p'.$pageNum.'k'.$keyid;
		}
		$GLOBALS['Templ'] -> display('prolist_tpl.html',$cache_id);
	}
	
	function detail()
	{
		$id 		= trim($_REQUEST["id"]);
		// $pageNum 	= trim($_REQUEST["pageNum"]);
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/pro.html">产品中心</a>';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=pro&act=infolist">产品中心</a>';
		}
		if($id > 0 )
		{
			$sqlQuery 	= " SELECT p.* ,s.prs_name  FROM  ".SQL_PREFIX."product as p  left join  ".SQL_PREFIX."prosort  as s on p.prs_id = s.prs_id   WHERE p.pro_enabled = 1  and p.pro_id = ".$id." ORDER BY p.`pro_id`  ";
			
			$infodetail 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
			
			$nowaddress = $nowaddress. " > 详细内容";
			$webtitle = $infodetail["pro_name"];
			
			
			$sqlup = " UPDATE ".SQL_PREFIX."product set pro_count = pro_count +1 WHERE pro_id = ".$id ; 
			
			$GLOBALS['MySql'] -> querySql($sqlup);
			
			
			//查询上一篇
			$prosql = " SELECT pro_id, pro_name  FROM ".SQL_PREFIX."product WHERE  pro_id < ".$id." GROUP BY pro_id   ORDER BY pro_id  DESC ";
			$Prodetail 	= $GLOBALS['MySql']  ->  selectOne($prosql);
			$Prodetail["pro_url"]= $GLOBALS['Helpe']  -> buildUrl( $valid = $Prodetail["pro_id"],'pro');
			//查询下一篇
			$nextsql = " SELECT pro_id, pro_name  FROM ".SQL_PREFIX."product WHERE  pro_id > ".$id." GROUP BY pro_id  ORDER BY pro_id  ";
			$Nextdetail 	= $GLOBALS['MySql']  ->  selectOne($nextsql);
			$Nextdetail["pro_url"]= $GLOBALS['Helpe']  -> buildUrl( $valid = $Nextdetail["pro_id"],'pro');
			
			$GLOBALS['Templ'] -> assign('Prodetail',$Prodetail);
			$GLOBALS['Templ'] -> assign('Nextdetail',$Nextdetail);
			
			
			$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
			$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
			$GLOBALS['Templ'] -> assign('infodetail',$infodetail);
			$cache_id = $id.'d'.$pageNum;
			$GLOBALS['Templ'] -> display('pro_tpl.html', $cache_id);
			
		}else{
			$GLOBALS['Helpe'] -> error404();
		}
		
		
	
	}

}

$Pro = new Pro();

?>