<?php 
class Admin_mod  extends HC_Controller
{
	public function __construct()
	{
		parent::__construct();
		if(empty($this -> db)){
			$this -> load_db();
		}
		$this -> load('admin');
		$this -> admin -> online_admin();
	}
	
	public function get_power( $admp_item = '' )
	{
		if($admp_item !=''){
			$sql_query = " SELECT admp_action  FROM  ".$this -> db -> prefix."adm_power  WHERE admp_item = '".$admp_item."' AND  adm_id =".$_SESSION["admin"]["adm_id"];
			 return $this -> db -> select_one( $sql_query );
		}
			return false;
	}
	public function get_power_detail( $admp_action = '', $show_arr = array(),$type='info_list', $is_arr = true )
	{
		if( $_SESSION["admin"]["adm_user"]!= EMPLOYEE_BASEUSER )
		{
				if($admp_action!='' && !empty($show_arr) ){
					
					$all_power = json_decode($admp_action,true);

					//如果存在细节项，侧按细节项处理。
					if(!empty($all_power[$type]) && is_array($all_power[$type]) && $is_arr==true ){ //&& $is_arr==true 
						foreach($show_arr as $key => $val)
						{
							if(!in_array($key,$all_power[$type]))
							{
								unset($show_arr[$key]);
							}	
						}
						//var_dump($show_arr);
						return $show_arr;
					}
					//无细节项
					if(in_array($type,(array)$all_power)){
						if($is_arr==false){
							return true;
						}else{
							return $show_arr;
						}
					}
					
					//var_dump($all_power);
					//echo '=====';

					
				}elseif($type!='' && empty($show_arr) && $admp_action!='' ){
					$all_power = json_decode($admp_action,true);
					//var_dump($all_power);
					//echo $type;
					if(in_array($type,(array)$all_power)){
						
						return true;
					}else{
						$this -> view -> assign('lang', $this->lang);
						$this -> view -> display('no_power.tpl');
						exit();
					}
					//echo 'A+A+A+';
					
				}
				///var_dump($show_arr);
				//echo 'A+A+A+';
				
				if($type!='edit_info'){
					$this -> view -> assign('lang', $this->lang);
					$this -> view -> display('no_power.tpl');
					exit();
				}
		
		//超级管理员权限
		}else{
			if(!empty($show_arr)){
				return $show_arr;
			}else{
				return true;
			}
			
		}
	}
	
	
	public function get_power_menu()
	{
		$sql_query = " SELECT admp_item,admp_action  FROM  ".$this -> db -> prefix."adm_power  WHERE adm_id =".$_SESSION["admin"]["adm_id"];
		$info = $this -> db -> select_info($sql_query); //,'MYSQL_NUM'
		//var_dump($info);
		$re_arr = array();
		foreach($info as $val)
		{
			$sval_arr[$val['admp_item']] = json_decode($val['admp_action']);
			//var_dump($sval_arr);
			//$re_arr = array_merge((array)$re_arr,(array)$val['admp_item']);
			//$a = json_decode($val['admp_action']);
			//var_dump($a);
			//echo (array)$val['admp_action'];
			//echo '<br><br>';
		}
		//var_dump($sval_arr);
		//exit();
		//var_dump( $re_arr );
		//echo '--------------------------------------------------------';
		return $sval_arr;
	}
	
	
	
	
	
	
	
	

} 