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

	}
	
	function info_list(  )
	{
		$page_size = 20 ;		$page_num_val 	= $this -> input ->  req["page_num"];
		
		if( $page_num_val > 1 )
		{
			$page_num  = $page_num_val;
			$limit_num = ceil( ( $page_num_val -1 ) * $page_size );
		}else{
			$page_num  = 1;
			$limit_num = 0 ;
		}
		
		$use_idval   		= $_SESSION["emplyeeUser"]["use_id"];
			
		$sql_query = " SELECT web_id, web_domain, web_desc,  web_list   FROM  ".$this -> db -> prefix."web  WHERE 1 and use_id = $use_idval GROUP BY web_id ORDER BY `web_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."web  WHERE 1 and use_id = $use_idval ORDER BY `web_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		//var_dump();
		$page_str = $this -> page ->get_admin_page( $url = '?load=web&act=info_list', $page_num  , $page_size  , $result_count = $infocount["LNUM"]);
		
		$this -> view -> assign('page_str',$page_str);
		
		$this -> view -> assign('info',$info);
		
		$this -> view -> display('web.tpl');
		
	}
	
	
	
	function add(  )
	{
		
		//$this -> view ->  caching = true;
		//$this -> view ->  cache_lifetime = 86400 ;  //60 *  60 * 24
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=web&act=add_info");
		$this -> view -> display('webadd.tpl');
	}
	
	function add_info()
	{
		$web_domainval 	= $this -> input ->  funpost("web_domain");
		$web_descval 	= $this -> input ->  funpost("web_desc");
		$web_listval 	= $this -> input ->  funpost("web_list");
 		$use_idval   	= $_SESSION["emplyeeUser"]["use_id"];
		
		if($web_domainval !='' and $web_descval !='')
		{
			$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."web  WHERE web_domain = '".$web_domainval."' ORDER BY `web_id` ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["LNUM"] < 1 )
			{
			
				$insertip =" INSERT INTO `".$this -> db -> prefix."web` (`web_domain` , `web_desc` , `use_id` , `web_list`  ) VALUES (  '$web_domainval', '$web_descval', '$use_idval', '$web_listval' )";

				$this -> db -> query_sql($insertip);
				$this -> view ->  assign('info_title',$this->lang['add_success']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info_list");
				$this -> view ->  display('suggestion.tpl');
				
			}else{
				
				$this -> view ->  assign('info_title',$this->lang['err_info_exist']);
				$this -> view ->  assign('URL_TIME',URL_TIME);
				$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=add");
				$this -> view ->  display('suggestion.tpl');	
			}
			
		}else{
			
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=add");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del()
	{
		$infoid = $this -> input ->  get["id"];
		$insertip = " DELETE FROM `".$this -> db -> prefix."web` WHERE `".$this -> db -> prefix."web`.`web_id` in ( $infoid ) ";
		$this -> db -> query_sql($insertip);
		$this -> view ->  assign('info_title',$this->lang['del_success']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function show( )
	{
		$infoid = $this -> input ->  get["id"];
		$upshow = " UPDATE `".$this -> db -> prefix."web` SET web_enabled = 1  WHERE `".$this -> db -> prefix."web`.`web_id` in ( $infoid ) ";

		$this -> db -> query_sql($upshow);
		$this -> view ->  assign('info_title',$_LANG['bd_showsusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function hide( )
	{
		$infoid = $this -> input ->  get["id"];
		$uphide = " UPDATE `".$this -> db -> prefix."web` SET web_enabled = 0  WHERE  `web_id` in ( $infoid ) ";

		$this -> db -> query_sql($uphide);
		$this -> view ->  assign('info_title',$_LANG['bd_hidesusse']);
		$this -> view ->  assign('URL_TIME',URL_TIME);
		$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function info( )
	{
		$infoid = $this -> input ->  get["id"];
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."web  WHERE web_id = '".$infoid."' ORDER BY `web_id` ";
		$info = $this -> db -> select_one($sql_query);
		//var_dump($info);
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('webedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$web_idval 		= $this -> input ->  funpost("web_id");
		$web_domainval 	= $this -> input ->  funpost("web_domain");
		$web_descval 	= $this -> input ->  funpost("web_desc");
		$web_listval 	= $this -> input ->  funpost("web_list");

		
		if($web_domainval !='' and $web_descval !='' and $web_idval !='')
		{
			$updateweb = "UPDATE `".$this -> db -> prefix."web` SET  web_domain = '".$web_domainval."' , web_desc = '".$web_descval."' ,   web_list = '".$web_listval."' WHERE  web_id = '".$web_idval."' ";	
			$this -> db -> query_sql( $updateweb );
			
			$this -> view ->  assign('info_title',$this->lang['edit_success']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info_list");
			$this -> view ->  display('suggestion.tpl');
				
		}else{
		
			$this -> view ->  assign('info_title',$this->lang['err_info_missing']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=web&act=info&id=".$web_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//


$Web = new Web();

?>