<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Download
{
	function Download()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',WEBBASE_file.ROOT_URL."login/actlogin");
	}
	
	function infolist(  )
	{
		$pageSize = 20 ;		
		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
			
		$sqlQuery = " SELECT dow_id, dow_name, dow_file, dow_size, dow_list ,dow_count, dow_enabled  FROM  ".SQL_PREFIX."download  WHERE 1 GROUP BY dow_id ORDER BY `dow_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."download  WHERE 1  ORDER BY `dow_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump();
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=download&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('download_tpl.html');
		
	}
	
	function add(  )
	{
		$GLOBALS['Templ'] -> caching = true;
		$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'dow_desc' );	//加载文本编辑器

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=download&act=addinfo");
		$GLOBALS['Templ']->display('downloadadd_tpl.html');
	}
	
	function addinfo()
	{
		$dow_nameval 	= $GLOBALS['Reque'] -> funpost("dow_name");
		
		$dow_fileval 	= $_REQUEST["pro_img"]["1"];
	    $dow_imgeval 	=$_REQUEST["pro_img"]["2"];
		
		$dow_sizeval 	= $GLOBALS['Reque'] -> funpost("dow_size");
		$dow_descval 	= $_REQUEST["dow_desc"];
		//$dow_descval 	= $GLOBALS['Reque'] -> funpost("dow_desc");
		$dow_listval 	= $GLOBALS['Reque'] -> funpost("dow_list");
		$dow_enabledval = $GLOBALS['Reque'] -> funpost("dow_enabled");
		
		 
		if($dow_nameval and $dow_fileval)
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."download  WHERE dow_name = '".$dow_nameval."' ORDER BY `dow_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
				$dow_addtimeval = time();
				$insertip =" INSERT INTO `".SQL_PREFIX."download` (`dow_name` , `dow_file` ,  `dow_img` ,`dow_size` , `dow_desc` ,`dow_list` , `dow_enabled`,`dow_addtime` ) VALUES (  '$dow_nameval', '$dow_fileval', '$dow_imgeval','$dow_sizeval','$dow_descval',  '$dow_listval', '$dow_enabledval','$dow_addtimeval')";
				
				$GLOBALS['MySql'] -> querySql($insertip);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=infolist");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}else{
				
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_isrealyerror']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=add");
				$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
			}
			
		}else{
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
		    //var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$insertip = " DELETE FROM `".SQL_PREFIX."download` WHERE `".SQL_PREFIX."download`.`dow_id` in ( $infoid ) ";
		

		$GLOBALS['MySql'] -> querySql($insertip);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_delsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$upshow = " UPDATE `".SQL_PREFIX."download` SET dow_enabled = 1  WHERE `".SQL_PREFIX."download`.`dow_id` in ( $infoid ) ";

		$GLOBALS['MySql'] -> querySql($upshow);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_showsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$indel = implode(',', $delArray);

		
		$uphide = " UPDATE `".SQL_PREFIX."download` SET dow_enabled = 0  WHERE `".SQL_PREFIX."download`.`dow_id` in ( $indel ) ";

		$GLOBALS['MySql'] -> querySql($uphide);
		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_hidesusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function info(  )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."download  WHERE dow_id = '".$infoid."' ORDER BY `dow_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$GLOBALS['Helpe'] -> load_ckeditor( $textName = 'dow_desc' ,$textValue = $info["dow_desc"] );	//加载文本编辑器

		$GLOBALS['Templ'] -> display('downloadedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$dow_idval 		= $GLOBALS['Reque'] -> funpost("dow_id");
		$dow_nameval 	= $GLOBALS['Reque'] -> funpost("dow_name");

		$dow_fileval 	= $_REQUEST["pro_img"]["1"];
	    $dow_imgeval 	=$_REQUEST["pro_img"]["2"];
		$dow_sizeval 	= $GLOBALS['Reque'] -> funpost("dow_size");
		$dow_descval 	= $_REQUEST["dow_desc"];
		//$dow_descval 	= $GLOBALS['Reque'] -> funpost("dow_desc");
		$dow_listval 	= $GLOBALS['Reque'] -> funpost("dow_list");
		$dow_enabledval = $GLOBALS['Reque'] -> funpost("dow_enabled");
		
		
		if($dow_nameval !='' and $dow_fileval !='' and $dow_idval !='')
		{
			$updatedownload = "UPDATE `".SQL_PREFIX."download` SET  dow_name = '".$dow_nameval."' , dow_file = '".$dow_fileval."' , dow_img = '".$dow_imgval."' , dow_size = '".$dow_sizeval."', dow_desc = '".$dow_descval."', dow_list = '".$dow_listval."',dow_enabled = '".$dow_enabledval."'  WHERE  dow_id = '".$dow_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatedownload );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=infolist");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_losssusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=download&act=info&id=".$dow_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Download = new Download();

?>