<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Security
{
	function Security()
	{
	
	}
	
	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 *  FROM  ".$this -> db -> prefix."security  WHERE 1 GROUP BY sec_id ORDER BY `sec_id` LIMIT  $limit_num , $page_size ";
		
		$info = $this -> db -> select_info($sql_query);
		
		$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."security  WHERE 1  ORDER BY `sec_id`  ";
		
		$infocount = $this -> db -> select_one($sql_query);
		
		$page_str = $this -> page ->get_admin_page( $url = '?load=security&act=info_list', $page_num  , $page_size  , $result_count = $infocount["CNUM"] );
		

		$this -> view -> assign('page_str',$page_str);
		$this -> view -> assign('info',$info);
		$this -> view -> display('security.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=security&act=add_info");
		$this -> view -> display('securityadd.tpl');
	}
	
	function add_info()
	{
		$sec_numcodeval 		= $this -> input ->  funpost("sec_numcode");
		$pro_idval 		= $this -> input ->  funpost("pro_id");
		$sec_remarkval		= $this -> input ->  funpost("sec_remark");
		$sec_enabledval 		= $this -> input ->  funpost("sec_enabled");
		$sec_lockedval	 	= $this -> input ->  funpost("sec_locked");

		if($sec_numcodeval !='' and $pro_idval !='' and $sec_remarkval !='' )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."security  WHERE sec_numcode = '".$sec_numcodeval."' ";
			
			$info = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{				
				$insertip ="INSERT INTO `".$this -> db -> prefix."security` (`sec_numcode` , `pro_id` , `sec_remark` , `sec_enabled` , `sec_locked` ) VALUES (  '$sec_numcodeval', '$pro_idval', '$sec_remarkval', '$sec_enabledval', '$sec_lockedval')";
				
				$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=security&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=security&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=security&act=add");
			$this -> view ->  display('suggestion.tpl');		}
			//var_dump($_REQUEST);
	}
	
	function del( )
	{
		$infoid = $this -> input ->  get["id"];
		
		$selectsql ="SELECT count(*) as NUM FROM `".$this -> db -> prefix."security` WHERE sec_locked = 1 AND `sec_id` in ( $infoid ) ";
		
		$info = $this -> db -> select_one( $selectsql );
		
		if($info["NUM"] > 0 )
		{
			$this -> view ->  assign('info_title',$_LANG['bd_islocked']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=security&act=info_list");
			$this -> view ->  display('suggestion.tpl');

		}else{
			$deletesql ="DELETE FROM `".$this -> db -> prefix."security` WHERE `sec_id` in ( $infoid ) ";
			
			$this -> db -> query_sql($deletesql);
			
			
			$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=security&act=info_list");
			$this -> view ->  display('suggestion.tpl');
		}
	}
	
	function info( )
	{
		$infoid = $this -> input ->  get["id"];
		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."security  WHERE sec_id = '".$infoid."' ORDER BY `sec_id` ";
		$info = $this -> db -> select_one($sql_query);
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=security&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('securityedit.tpl');
	
	}
	
	
	function edit_info( )
	{	
		$sec_idval 			= $this -> input ->  funpost("sec_id");
		$sec_numcodeval 	= $this -> input ->  funpost("sec_numcode");
		$pro_idval 			= $this -> input ->  funpost("pro_id");
		$sec_remarkval		= $this -> input ->  funpost("sec_remark");
		$sec_enabledval 	= $this -> input ->  funpost("sec_enabled");
		$sec_lockedval		= $this -> input ->  funpost("sec_locked");
		
		if($sec_idval !='' and $sec_numcodeval !='' )
		{

			$updatesql = "UPDATE `".$this -> db -> prefix."security` SET  sec_numcode = '".$sec_numcodeval."' , pro_id = '".$pro_idval."'  , sec_remark = '".$sec_remarkval."' , sec_enabled = '".$sec_enabledval."' , sec_locked = '".$sec_lockedval."'   WHERE  sec_id = '".$sec_idval."' ";
			
			$this -> db -> query_sql( $updatesql );
			
			$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=security&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=security&act=info&id=".$admin_idval);
			$this -> view ->  display('suggestion.tpl');	
		}
		
	}
		
}


$Security = new Security();

?>