<?php
if (!defined('HUCART_COM')) exit('HuCart.COM No direct script access allowed');
class Security  extends HC_Controller
{
	//注意无须构造函数,使用了构造函数得重构父类 parent::__construct();
	function __construct()
	{
		parent::__construct();
		$this -> load_lang('adminsys/security');
		$this -> load_db();
		$this -> load('admin'); 
		$this -> admin -> online_admin();
		$this -> load('helper');
		//var_dump($this->input);
	}

	
	function info_list()
	{
		$this -> load('page',$this->lang['page']);

		$keywordval 	= $this -> input ->  post["keyword"];
		$prs_idval 		= $this -> input ->  post["prs_id"];
		$page_num_val 	= $this -> input ->  get["page_num"];

		$listval  = $this -> input ->  get["listval"];
		$listtype = $this -> input ->  get["listtype"];

		$orderbyval = "";
		if($listval!='' and $listtype =='DESC' )
		{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = $listval;
			$orderbyval = $listval ."  DESC ";
			$listhtml = '';	//反向排序参数
			
		}elseif($listval!='' )
		{
			$orderbyval = $listval;
			$listhtml = 'DESC';
			
			//$endArray["listtype"] = '';
			//$endArray["listval"]  = $listval;

		}else{
			//$endArray["listtype"] = 'DESC';
			//$endArray["listval"]  = 'art_uptime';
			$orderbyval = " add_time DESC ";	
		}
		//列表字段显示
		$show_arr = array('sec_id' => 1,'sec_numcode'=>1,'pro_id'=>0,'add_time'=>1,'sec_enabled'=>1);
		$field_show = $this -> helper -> get_th_list( $show_arr , $list_val , $list_type , $lang_arr = $this->lang['field_list'] );


		$sql_query = " SELECT sec_id, sec_numcode, pro_id, add_time,sec_enabled FROM  ".$this -> db -> prefix."security  WHERE 1 GROUP BY sec_id ORDER BY $orderbyval  LIMIT  ". $this -> page ->get_limit_val();
		
		$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( $infocount["CNUM"] );
		
		$this -> view -> assign('field_show',$field_show);
		
		$this -> view -> assign('listval',$listval);
		$this -> view -> assign('listtype',$listtype);

		
		$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 -> assign( 'edit_submit', $this-> lang['add_submit']);
		$this -> view -> assign( 'txt_title', $this-> lang['add_title']);
		$this -> view -> display('security_edit.tpl');
		
	}
	
	function add_info()
	{

		$sec_numcodeval 		= $this -> input ->  post["sec_numcode"];
		$pro_idval  			= $this -> input ->  post["pro_id"];
		$sec_urlval  			= $this -> input ->  post["sec_url"];	
 
		$sec_descval 			= $this -> input ->  post["sec_desc"];
		$sec_enabledval			= $this -> input ->  post["sec_enabled"];


		if($sec_numcodeval !=''  )
		{
			$sql_query = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."security  WHERE sec_numcode = '".$sec_numcodeval."' and  sec_list = '".$sec_listval."' ";
			$info 	  = $this -> db -> select_one($sql_query);
			
			if( $info["CNUM"] < 1 )
			{				

				$add_timeval = date("Y-m-d H:i:s");  	//time();
				$insertsql ="INSERT INTO `".$this -> db -> prefix."security` (`sec_numcode` , `pro_id` , `sec_desc`,`add_time` ,`sec_enabled`) 
		VALUES (  '$sec_numcodeval', '$pro_idval', '$sec_urlval', '$sec_descval', '$add_timeval','$sec_enabledval')";
				
				$this -> db -> query_sql($insertsql);
				
				$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 delete( )
	{
		$infoid = $this -> input ->  get["id"];
			
		$pro_sql = " SELECT count(1) as CNUM  FROM  ".$this -> db -> prefix."product  WHERE  sec_id in  ( $infoid ) ORDER BY `sec_id` "; 
		$pro_info = $this -> db -> select_one($pro_sql);
		if($pro_info["CNUM"] > 0){
			$this -> view ->  assign('info_title',$this->lang['err_pro_info_exist']);
			$this -> view ->  assign('URL_TIME',URL_TIME);
			$this -> view ->  assign('get_url',ADMIN_WEBURL."/index.php?load=pro_sort&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()
	{
		$idval = $this -> input ->  get["id"];

		$sql_query = " SELECT *  FROM  ".$this -> db -> prefix."security  WHERE sec_id = '".$idval."' ORDER BY `sec_id` ";
		$info = $this -> db -> select_one($sql_query);
		
		$this -> view -> assign( 'edit_submit', $this-> lang['edit_submit']);
		$this -> view -> assign( 'txt_title', $this-> lang['edit_title']);
		
		$this -> view -> assign('act_url',ADMIN_WEBURL."/index.php?load=security&act=edit_info");
		$this -> view ->  assign('info',$info);
		$this -> view ->  display('security_edit.tpl');
	
	}
	
	
	function edit_info( )
	{	
		$sec_idval 				= $this -> input ->  post["sec_id"];
		$sec_numcodeval 			= $this -> input ->  post["sec_numcode"];
		$pro_idval  			= $this -> input ->  post["pro_id"];
		$sec_urlval  			= $this -> input ->  post["sec_url"];	
 
		$sec_descval  			= $this -> input ->  post["sec_desc"];
		$sec_enabledval  		= $this -> input ->  post["sec_enabled"];

		if($sec_idval !='' and $sec_numcodeval !='' )
		{

			$updatesql = "UPDATE `".$this -> db -> prefix."security` SET  sec_numcode = '".$sec_numcodeval."' , pro_id = '".$pro_idval."'  , sec_url = '".$sec_urlval."' ,  sec_desc = '".$sec_descval."' , sec_enabled = '".$sec_enabledval."' 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=".$sec_idval);
			$this -> view ->  display('suggestion.tpl');
			
		}
		
	}
	
	function show()
	{
		//var_dump($this -> input);
		//exit();
		$infoid = $this -> input ->  get["id"];
		$up_show = " UPDATE `".$this -> db -> prefix."security` SET sec_enabled = 1  WHERE  `sec_id` in ( $infoid ) ";
		$this -> db -> query_sql($up_show);
		
		$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=security&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
	
	function hide()
	{		
		$infoid = $this -> input ->  get["id"];
		$up_hide = " UPDATE `".$this -> db -> prefix."security` SET sec_enabled = 0  WHERE `sec_id` in ( $infoid ) ";
		$this -> db -> query_sql($up_hide);
		
		$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=security&act=info_list");
		$this -> view ->  display('suggestion.tpl');
	}
		
}

