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

	}
	
	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 web_id, web_domain, web_desc,  web_list   FROM  ".SQL_PREFIX."web  WHERE 1 and use_id = $use_idval GROUP BY web_id ORDER BY `web_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."web  WHERE 1 and use_id = $use_idval ORDER BY `web_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump();
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=web&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		
		$GLOBALS['Templ']->assign('info',$info);
		
		$GLOBALS['Templ']->display('web_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=web&act=addinfo");
		$GLOBALS['Templ']->display('webadd_tpl.html');
	}
	
	function addinfo()
	{
		$web_domainval 	= $GLOBALS['Reque'] -> funpost("web_domain");
		$web_descval 	= $GLOBALS['Reque'] -> funpost("web_desc");
		$web_listval 	= $GLOBALS['Reque'] -> funpost("web_list");
 		$use_idval   	= $_SESSION["emplyeeUser"]["use_id"];
		
		if($web_domainval !='' and $web_descval !='')
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."web  WHERE web_domain = '".$web_domainval."' ORDER BY `web_id` ";
			
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
			
				$insertip =" INSERT INTO `".SQL_PREFIX."web` (`web_domain` , `web_desc` , `use_id` , `web_list`  ) VALUES (  '$web_domainval', '$web_descval', '$use_idval', '$web_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=web&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=web&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=web&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
			//var_dump($_REQUEST);
	}
	
	function del()
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$insertip = " DELETE FROM `".SQL_PREFIX."web` WHERE `".SQL_PREFIX."web`.`web_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=web&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$upshow = " UPDATE `".SQL_PREFIX."web` SET web_enabled = 1  WHERE `".SQL_PREFIX."web`.`web_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=web&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$uphide = " UPDATE `".SQL_PREFIX."web` SET web_enabled = 0  WHERE  `web_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=web&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function info( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."web  WHERE web_id = '".$infoid."' ORDER BY `web_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('webedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$web_idval 		= $GLOBALS['Reque'] -> funpost("web_id");
		$web_domainval 	= $GLOBALS['Reque'] -> funpost("web_domain");
		$web_descval 	= $GLOBALS['Reque'] -> funpost("web_desc");
		$web_listval 	= $GLOBALS['Reque'] -> funpost("web_list");

		
		if($web_domainval !='' and $web_descval !='' and $web_idval !='')
		{
			$updateweb = "UPDATE `".SQL_PREFIX."web` SET  web_domain = '".$web_domainval."' , web_desc = '".$web_descval."' ,   web_list = '".$web_listval."' WHERE  web_id = '".$web_idval."' ";	
			$GLOBALS['MySql'] -> querySql( $updateweb );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=web&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=web&act=info&id=".$web_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Web = new Web();

?>