<?php
/**
 *----------------------------------------------------------------------------*
 * 版权所有 2005-2013 GV32.COM，并保留所有权利。
 * 网站地址: http://www.gv32.com；
 * 作者: GV32.COM
 *----------------------------------------------------------------------------*
**/
class Download
{
	function Download()
	{
		//缓存
		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 = 'd', $smdirid );
		}
		
		$getconfig = $GLOBALS['Helpe'] -> get_config();
		$GLOBALS['Templ'] -> assign('getconfig',$getconfig);

		$getmenu = $GLOBALS['Helpe'] -> get_menu();
		$GLOBALS['Templ'] -> assign('getmenu',$getmenu);
		
		$getlink = $GLOBALS['Helpe'] -> get_link();
		$GLOBALS['Templ'] -> assign('getlink',$getlink);

		$getartsort = $GLOBALS['Helpe'] -> get_artsort();
		$GLOBALS['Templ'] -> assign('getartsort',$getartsort);
		
		$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()
	{
		$webtitle = '下载中心';
		//处理你现在的位置
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/download.html">下载中心</a>';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=download&act=infolist">下载中心</a>';
		}
		$id 	 = trim($_REQUEST["id"]);
		$pageNum = trim($_REQUEST["pageNum"]);
		
		$pageSize = 20 ;
		
		if( $pageNum > 1 )
		{
			$pageNum  = $pageNum;
			$LIMITnum = ceil( ( $pageNum -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		
		$sqlQuery = " SELECT dow_id, dow_name , dow_uptime ,dow_count  FROM  ".SQL_PREFIX."download   WHERE  dow_enabled = 1  GROUP BY  dow_id ORDER BY  `dow_id` LIMIT  $LIMITnum , $pageSize ";
		$info 		= $GLOBALS['MySql']  ->  selectInfo($sqlQuery);
		foreach((array)$info as $dkey => $dval )
		{
			 
			$info[$dkey]["get_url"] = $GLOBALS['Helpe']  -> buildUrl( $valid = $dval["dow_id"],'dow');	
		}
		
 
		$sqlQuery 	= " SELECT count(1) as CNUM  FROM  ".SQL_PREFIX."download  WHERE  dow_enabled = 1  ORDER BY `dow_id`  ";
		$infocount 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);

		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$url = BASE_WEBURL.'/download-list';
			$endArray["sid"] = $sid;
		}else{
			$url = './?load=download&act=infolist'.$addpage.$addurl;
		}
		$PageStr = $GLOBALS['Page'] -> buildPageStr( $url , $pageNum  , $pageSize  , $resultCount = $infocount["CNUM"] );
		
		$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('downloadlist_tpl.html',$cache_id);
		
	}
	
	
	function detail()
	{
		$webtitle = '下载中心';
		//处理你现在的位置
		
		if( $GLOBALS["WebConfig"]["webhtml"] == 1 )
		{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/download.html">下载中心</a> > 详细内容 ';
		}else{
			$nowaddress = '您的位置：<a href="'.BASE_WEBURL.'/">首页</a> > <a href="'.BASE_WEBURL.'/?load=download&act=infolist">下载中心</a> > 详细内容 ';
		}

		$id 		= trim($_REQUEST["id"]);
		$pageNum 	= trim($_REQUEST["pageNum"]);
		

		if($id > 0 )
		{
			$sqlQuery 	= " SELECT *  FROM  ".SQL_PREFIX."download as a  WHERE dow_enabled = 1  and dow_id = ".$id." ORDER BY `dow_id`  ";
			
			$infodetail 	= $GLOBALS['MySql']  ->  selectOne($sqlQuery);
			
			//var_dump($infodetail);
			$GLOBALS['Templ'] -> assign('infodetail',$infodetail);
			
			//$PageStr 	= $GLOBALS['Page'] -> buildPageStr( $url = './?load=download&act=detail&id='.$id, $pageNum , $pageSize = 1 , $resultCount=$reinfodetail["pageCount"]);
			//$GLOBALS['Templ'] -> assign('PageStr',$PageStr);
			
			$sqlup = " UPDATE ".SQL_PREFIX."download set dow_count = dow_count +1 WHERE dow_id = ".$id ; 
			$GLOBALS['MySql'] -> querySql($sqlup);
			
			$GLOBALS['Templ'] -> assign('webtitle',$webtitle);
			$GLOBALS['Templ'] -> assign('nowaddress',$nowaddress);
			$cache_id = $id.'d'.$pageNum;
			$GLOBALS['Templ'] -> display('download_tpl.html',$cache_id);
			
		}else{
			$GLOBALS['Helpe'] -> error404();
		}
	
	}

 
}

$Download = new Download();
?>