<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Addressbook
{
	function Addressbook()
	{

	}
	
	function infolist(  )
	{
		$pageSize = 20 ;		$pageNumval 	= $GLOBALS['Reque'] -> reqval["pageNum"];
		
		if( $pageNumval > 1 )
		{
			$pageNum  = $pageNumval;
			$LIMITnum = ceil( ( $pageNumval -1 ) * $pageSize );
		}else{
			$pageNum  = 1;
			$LIMITnum = 0 ;
		}
		
		$use_idval   		= $_SESSION["emplyeeUser"]["use_id"];
			
		$sqlQuery = " SELECT adb_id, adb_domain, adb_desc,  adb_list   FROM  ".SQL_PREFIX."addressbook  WHERE 1 and use_id = $use_idval GROUP BY adb_id ORDER BY `adb_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."addressbook  WHERE 1 and use_id = $use_idval ORDER BY `adb_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump();
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=addressbook&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		
		$GLOBALS['Templ']->assign('info',$info);
		
		$GLOBALS['Templ']->display('adb_tpl.html');
		
	}
	
	
	
	function add(  )
	{
		
		//$GLOBALS['Templ'] -> caching = true;
		//$GLOBALS['Templ'] -> cache_lifetime = 86400 ;  //60 *  60 * 24
		
		$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php?load=addressbook&act=addinfo");
		$GLOBALS['Templ']->display('addressbookadd_tpl.html');
	}
	
	function addinfo()
	{
		$adb_domainval 	= $GLOBALS['Reque'] -> funpost("adb_domain");
		$adb_descval 	= $GLOBALS['Reque'] -> funpost("adb_desc");
		$adb_listval 	= $GLOBALS['Reque'] -> funpost("adb_list");
 		$use_idval   	= $_SESSION["emplyeeUser"]["use_id"];
		
		if($adb_domainval !='' and $adb_descval !='')
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."addressbook  WHERE adb_domain = '".$adb_domainval."' ORDER BY `adb_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
			
				$insertip =" INSERT INTO `".SQL_PREFIX."addressbook` (`adb_domain` , `adb_desc` , `use_id` , `adb_list`  ) VALUES (  '$adb_domainval', '$adb_descval', '$use_idval', '$adb_listval' )";

				$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=addressbook&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=addressbook&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=addressbook&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del()
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$insertip = " DELETE FROM `".SQL_PREFIX."addressbook` WHERE `".SQL_PREFIX."addressbook`.`adb_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=addressbook&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$upshow = " UPDATE `".SQL_PREFIX."addressbook` SET adb_enabled = 1  WHERE `".SQL_PREFIX."addressbook`.`adb_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=addressbook&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$uphide = " UPDATE `".SQL_PREFIX."addressbook` SET adb_enabled = 0  WHERE  `adb_id` in ( $infoid ) ";

		$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=addressbook&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function info( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."addressbook  WHERE adb_id = '".$infoid."' ORDER BY `adb_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('addressbookedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$adb_idval 		= $GLOBALS['Reque'] -> funpost("adb_id");
		$adb_domainval 	= $GLOBALS['Reque'] -> funpost("adb_domain");
		$adb_descval 	= $GLOBALS['Reque'] -> funpost("adb_desc");
		$adb_listval 	= $GLOBALS['Reque'] -> funpost("adb_list");

		
		if($adb_domainval !='' and $adb_descval !='' and $adb_idval !='')
		{
			$updateaddressbook = "UPDATE `".SQL_PREFIX."addressbook` SET  adb_domain = '".$adb_domainval."' , adb_desc = '".$adb_descval."' ,   adb_list = '".$adb_listval."' WHERE  adb_id = '".$adb_idval."' ";	
			$GLOBALS['MySql'] -> querySql( $updateaddressbook );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=addressbook&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=addressbook&act=info&id=".$adb_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Addressbook = new Addressbook();

?>