<?php 
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
 //要添加错误处理
class Personal
{
	function Personal()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/login/actlogin");
	}
	
	function infolist()
	{
		$pageSize = 160 ;
		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		
		$sqlQuery = " SELECT per_id, per_name, per_enabled, per_type  FROM  ".SQL_PREFIX."personal  WHERE  1  GROUP BY per_id ORDER BY  `per_id` LIMIT  $LIMITnum , $pageSize ";

		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);

		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."personal  WHERE 1   ORDER BY `per_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
 
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=personal&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('personal_tpl.html');
		
	}
	
	function add(  )
	{

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=personal&act=addinfo");
		$GLOBALS['Templ']->display('personaladd_tpl.html');
	}
	
	function addinfo()
	{
		$per_nameval 	= $GLOBALS['Reque'] -> funpost("per_name");
		$per_typeval 	= $GLOBALS['Reque'] -> funpost("per_type");
		$per_enabledval = $GLOBALS['Reque'] -> funpost("per_enabled");
		

		if($per_nameval and $per_typeval)
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."personal  WHERE   per_type = '".$per_typeval."' ORDER BY `per_id` ";	
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
				$insertsql =" INSERT INTO `".SQL_PREFIX."personal` (`per_name` , `per_type` , `per_enabled` ) VALUES (  '$per_nameval', '$per_typeval', '$per_enabledval')";
				
				$GLOBALS['MySql'] -> querySql($insertsql);
				$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_addsusse']);
				$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
				$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&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=personal&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=personal&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
		//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$insertip = " DELETE FROM `".SQL_PREFIX."personal` WHERE `per_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=personal&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function info( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."personal  WHERE per_id = '".$infoid."' ORDER BY `per_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('personaledit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
		$per_idval 		  = $GLOBALS['Reque'] -> funpost("per_id");
		$per_nameval 	  = $GLOBALS['Reque'] -> funpost("per_name");
		$per_typeval 	  = $GLOBALS['Reque'] -> funpost("per_type");
		$per_enabledval   = $GLOBALS['Reque'] -> funpost("per_enabled");
		
		
		if($per_nameval !='' and $per_typeval !='' and $per_idval !='')
		{
			
			$updatepersonal = "UPDATE `".SQL_PREFIX."personal` SET  per_name = '".$per_nameval."' , per_type = '".$per_typeval."' , per_enabled = '".$per_enabledval."' WHERE  per_id = '".$per_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatepersonal );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&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=personal&act=info&id=".$per_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
	
	
	function item( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."personal  WHERE per_id = '".$infoid."' ORDER BY `per_id` ";
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		$columnArray = explode('|',$info["per_column"]);
		
		foreach((array)$columnArray as $ckey => $cval)
		{
			$per_column[$cval] = $cval;
		}
		
		$column_actionval = base64_decode($info["per_main"]);
		@eval($column_actionval);
		
		///var_dump($mainArray);
		

		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=personal&act=editinfo");
		
		$GLOBALS['Templ'] -> assign('info',$info);
		
		$GLOBALS['Templ'] -> assign('mainArray',$mainArray);
		
		$GLOBALS['Templ'] -> assign('per_column',$per_column);
		
		$GLOBALS['Templ'] -> display('personalitemedit_tpl.html');
	
	}
	
	function delitem()
	{

		$keyval =  $_REQUEST["key"];
		
		$delcon =  $_REQUEST["editcon"][$keyval];
		
		$per_idval = $GLOBALS['Reque'] -> reqval["per_id"];
		
		$sqlQuery = " SELECT per_main  FROM  ".SQL_PREFIX."personal  WHERE per_id = '".$per_idval."' ORDER BY `per_id` ";
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		
		$column_actionval = base64_decode($info["per_main"]);
		
		@eval($column_actionval);
		

		
		if($mainArray[$keyval]["con"]==$delcon)
		{
			unset($mainArray[$keyval]);
		}
		

		
		$per_mainadd ='';
		foreach($mainArray as $mkey => $mval )
		{
			$per_mainadd .= "\$mainArray[] =  array( 'con'=>'".$mval["con"]."','n'=>'".$mval["n"]."','sid'=>'".$mval["sid"]."'); ";
			
		}
		
		$updatesql = "UPDATE `".SQL_PREFIX."personal` SET  per_main = '".base64_encode($per_mainadd)."'  WHERE  per_id = '".$per_idval."' ";
			
		$GLOBALS['MySql'] -> querySql( $updatesql );

		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_edititemsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
		

	}
	
	
	
	function edititem()
	{
	 
		$keyval =  $_REQUEST["key"];
		
		$valcon =  $_REQUEST["editcon"][$keyval];
		$valsid =  $_REQUEST["editsid"][$keyval];
		$valn 	=  $_REQUEST["editn"][$keyval];
		
		$per_idval = $GLOBALS['Reque'] -> reqval["per_id"];
		
		$sqlQuery = " SELECT per_main  FROM  ".SQL_PREFIX."personal  WHERE per_id = '".$per_idval."' ORDER BY `per_id` ";
		
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);

		
		$column_actionval = base64_decode($info["per_main"]);
		
		@eval($column_actionval);
		

		
 
		//unset($mainArray[$keyval]);
		$mainArray[$keyval]["con"] = $valcon ;
		$mainArray[$keyval]["n"]	= $valn ;
		$mainArray[$keyval]["sid"] = $valsid ;
 
 
		$per_mainadd ='';
		foreach($mainArray as $mkey => $mval )
		{
			$per_mainadd .= "\$mainArray[] =  array( 'con'=>'".$mval["con"]."','n'=>'".$mval["n"]."','sid'=>'".$mval["sid"]."'); ";
			
		}
		
		$updatesql = "UPDATE `".SQL_PREFIX."personal` SET  per_main = '".base64_encode($per_mainadd)."'  WHERE  per_id = '".$per_idval."' ";
			
		$GLOBALS['MySql'] -> querySql( $updatesql );

		$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_edititemsusse']);
		$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
		$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	
	function editleftitem()
	{
		//var_dump($_REQUEST["per_column"]);
		$per_idval = $_REQUEST["per_id"];
		
		if($_REQUEST["per_column"]!=''){
			$per_columnval = implode('|',$_REQUEST["per_column"]);
		}else{
			$per_columnval = '';
		}
		
		if($per_idval !='' )
		{
			
			
			$updatesql = "UPDATE `".SQL_PREFIX."personal` SET  per_column = '".$per_columnval."'  WHERE  per_id = '".$per_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );

			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_edititemsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_lossitemsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}

	function editadditem()
	{
		/// var_dump($_REQUEST);
		
		//要添加错误处理

		$per_mainadd = "\$mainArray[] =  array( 'con'=>'".$_REQUEST["con"]."','n'=>'".$_REQUEST["n"]."','sid'=>'".$_REQUEST["sid"]."'); ";

		///exit();
		
		$per_idval = $_REQUEST["per_id"];

		if($per_idval !='' )
		{
			$sqlQuery = " SELECT per_main  FROM  ".SQL_PREFIX."personal  WHERE per_id = '".$per_idval."' ORDER BY `per_id` ";
		
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			$per_mainaddval = base64_encode( base64_decode($info["per_main"]).$per_mainadd );
 
			$updatesql = "UPDATE `".SQL_PREFIX."personal` SET  per_main = '".$per_mainaddval."'  WHERE  per_id = '".$per_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatesql );

			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_edititemsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');
				
		}else{
		
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_lossitemsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=personal&act=item&id=".$per_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}	
}

//nmon_x86_rhel4
$Personal = new Personal();

?>