<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Link
{
	function Link()
	{
		//$GLOBALS['WebSe'] -> isOnLine();
		
		//$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?/login/actlogin");
	}
	
	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 ;
		}
			
		$sql_query = " SELECT lin_id, lin_name, lin_url, lin_logo, lin_list , lin_enabled  FROM  ".$this -> db -> prefix."link  WHERE 1 GROUP BY lin_id ORDER BY `lin_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."link  WHERE 1  ORDER BY `lin_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		//var_dump();
		$page_str = $this -> page ->get_admin_page( $url = '?load=link&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('link.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=link&act=add_info");
		$this -> view -> display('linkadd.tpl');
	}
	
	function add_info()
	{
		$lin_nameval 	= $this -> input ->  funpost("lin_name");
		$lin_urlval 	= $this -> input ->  funpost("lin_url");
		$lin_logoval 	= $this -> input ->  funpost("lin_logo");
		$lin_listval 	= $this -> input ->  funpost("lin_list");
		$lin_enabledval = $this -> input ->  funpost("lin_enabled");
		
		if($lin_nameval and $lin_urlval)
		{
			$sql_query = " SELECT count(1) as LNUM  FROM  ".$this -> db -> prefix."link  WHERE lin_name = '".$lin_nameval."' ORDER BY `lin_id` ";
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["LNUM"] < 1 )
			{
				$insertip =" INSERT INTO `".$this -> db -> prefix."link` (`lin_name` , `lin_url` , `lin_logo` , `lin_list` , `lin_enabled` ) VALUES (  '$lin_nameval', '$lin_urlval', '$lin_logoval', '$lin_listval', '$lin_enabledval')";
				
				$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=link&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=link&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=link&act=add");
			$this -> view ->  display('suggestion.tpl');		}
		//var_dump($_REQUEST);
	}
	
	function del()
	{
		$infoid = $this -> input ->  get["id"];
		$insertip = " DELETE FROM `".$this -> db -> prefix."link` WHERE `".$this -> db -> prefix."link`.`lin_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=link&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function show( )
	{
		$infoid = $this -> input ->  get["id"];
		$upshow = " UPDATE `".$this -> db -> prefix."link` SET lin_enabled = 1  WHERE `".$this -> db -> prefix."link`.`lin_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=link&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function hide( )
	{
		$infoid = $this -> input ->  get["id"];
		$uphide = " UPDATE `".$this -> db -> prefix."link` SET lin_enabled = 0  WHERE  `lin_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=link&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	
	function info( )
	{
		$infoid = $this -> input ->  get["id"];
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."link  WHERE lin_id = '".$infoid."' ORDER BY `lin_id` ";
		$info = $this -> db -> select_one($sql_query);
		//var_dump($info);
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('linkedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
	
		$lin_idval 	= $this -> input ->  funpost("lin_id");
		$lin_nameval 	= $this -> input ->  funpost("lin_name");
		$lin_urlval 	= $this -> input ->  funpost("lin_url");
		$lin_logoval 	= $this -> input ->  funpost("lin_logo");
		$lin_listval 	= $this -> input ->  funpost("lin_list");
		$lin_enabledval = $this -> input ->  funpost("lin_enabled");
		
		if($lin_nameval !='' and $lin_urlval !='' and $lin_idval !='')
		{
			$updatelink = "UPDATE `".$this -> db -> 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."' ";
			
			$this -> db -> query_sql( $updatelink );
			
			$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=link&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=link&act=info&id=".$lin_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}

//


$Link = new Link();

?>