<?php
if (!defined('GV32_COM')) exit('GV32.COM No direct script access allowed');
class Link
{
	function Link()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		
		//$GLOBALS['Templ']->assign('actUrl',EMPLOYEE_WEBURL."/index.php/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 lin_id, lin_name, lin_url, lin_logo, lin_list , lin_enabled  FROM  ".SQL_PREFIX."link  WHERE 1 GROUP BY lin_id ORDER BY `lin_id` LIMIT  $LIMITnum , $pageSize ";
		
		$info = $GLOBALS['MySql'] -> selectInfo($sqlQuery);
		
		$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."link  WHERE 1  ORDER BY `lin_id`  ";
		
		$infocount = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump();
		$PageStr = $GLOBALS['Page']->buildPageStr( $url = '?load=link&act=infolist', $pageNum  , $pageSize  , $resultCount = $infocount["LNUM"]);
		
		$GLOBALS['Templ']->assign('PageStr',$PageStr);
		$GLOBALS['Templ']->assign('info',$info);
		$GLOBALS['Templ']->display('link_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=link&act=addinfo");
		$GLOBALS['Templ']->display('linkadd_tpl.html');
	}
	
	function addinfo()
	{
		$lin_nameval 	= $GLOBALS['Reque'] -> funpost("lin_name");
		$lin_urlval 	= $GLOBALS['Reque'] -> funpost("lin_url");
		$lin_logoval 	= $GLOBALS['Reque'] -> funpost("lin_logo");
		$lin_listval 	= $GLOBALS['Reque'] -> funpost("lin_list");
		$lin_enabledval = $GLOBALS['Reque'] -> funpost("lin_enabled");
		
		if($lin_nameval and $lin_urlval)
		{
			$sqlQuery = " SELECT count(1) as LNUM  FROM  ".SQL_PREFIX."link  WHERE lin_name = '".$lin_nameval."' ORDER BY `lin_id` ";
			$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
			
			if( $info["LNUM"] < 1 )
			{
				$insertip =" INSERT INTO `".SQL_PREFIX."link` (`lin_name` , `lin_url` , `lin_logo` , `lin_list` , `lin_enabled` ) VALUES (  '$lin_nameval', '$lin_urlval', '$lin_logoval', '$lin_listval', '$lin_enabledval')";
				
				$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=link&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=link&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=link&act=add");
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');		}
		//var_dump($_REQUEST);
	}
	
	function del()
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$insertip = " DELETE FROM `".SQL_PREFIX."link` WHERE `".SQL_PREFIX."link`.`lin_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=link&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function show( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$upshow = " UPDATE `".SQL_PREFIX."link` SET lin_enabled = 1  WHERE `".SQL_PREFIX."link`.`lin_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=link&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	function hide( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$uphide = " UPDATE `".SQL_PREFIX."link` SET lin_enabled = 0  WHERE  `lin_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=link&act=infolist");
		$GLOBALS['Templ'] -> display('suggestion_tpl.html');
	}
	
	
	function info( )
	{
		$infoid = $GLOBALS['Reque'] -> getval["id"];
		$sqlQuery = " SELECT *  FROM  ".SQL_PREFIX."link  WHERE lin_id = '".$infoid."' ORDER BY `lin_id` ";
		$info = $GLOBALS['MySql'] -> selectOne($sqlQuery);
		//var_dump($info);
		$GLOBALS['Templ'] -> assign('info',$info);
		$GLOBALS['Templ'] -> display('linkedit_tpl.html');
	
	}
	
	
	function editinfo( )
	{	
	
		$lin_idval 	= $GLOBALS['Reque'] -> funpost("lin_id");
		$lin_nameval 	= $GLOBALS['Reque'] -> funpost("lin_name");
		$lin_urlval 	= $GLOBALS['Reque'] -> funpost("lin_url");
		$lin_logoval 	= $GLOBALS['Reque'] -> funpost("lin_logo");
		$lin_listval 	= $GLOBALS['Reque'] -> funpost("lin_list");
		$lin_enabledval = $GLOBALS['Reque'] -> funpost("lin_enabled");
		
		if($lin_nameval !='' and $lin_urlval !='' and $lin_idval !='')
		{
			$updatelink = "UPDATE `".SQL_PREFIX."link` SET  lin_name = '".$lin_nameval."' , lin_url = '".$lin_urlval."' , lin_logo = '".$lin_logoval."', lin_list = '".$lin_listval."',lin_enabled = '".$lin_enabledval."'  WHERE  lin_id = '".$lin_idval."' ";
			
			$GLOBALS['MySql'] -> querySql( $updatelink );
			
			$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['bd_editsusse']);
			$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
			$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=link&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=link&act=info&id=".$lin_idval);
			$GLOBALS['Templ'] -> display('suggestion_tpl.html');	
		}
		
	}
		
}

//nmon_x86_rhel4


$Link = new Link();

?>