<?php
class Session
{
    function __construct()
    {
		if(!isset($_SESSION))
		{  
			session_start();  
		} 
		$_SESSION["session_id"] = session_id();
    }

	public function set_session_arr( $arr )
	{
		foreach($arr as $key => $val)
		{
			if(is_array($val))
			{
				foreach($val as $skey => $sval)
				{
					$_SESSION[$key][$skey] = $sval;
				}
			}else{
				$this -> set_session( $key ,$val );
			}
		}
	}

	public function set_session( $key , $val )
	{
		$_SESSION[$key] = $val;
	}
	
	function del_session( $arr )
	{
		foreach($arr as $key)
		{
			unset( $_SESSION[$key] );
		}
	}
	
	function drop_session()
	{
		//session_unset(); 
		//session_destroy();
		session_destroy();
	}
	
	function employeePower()
	{		
 
		if($_SESSION["emplyeeUser"]["use_id"] =='' or  $_SESSION["emplyeeUser"]["use_name"] =='' or  $_SESSION["emplyeeUser"]["use_email"] =='' )
		{
			//δ��¼

			header("location:".ADMIN_WEBURL."/login.php?load=login&act=act");
			exit();
			//exit();  ///admin/index.php?/login/act/
			
		}else{
			if($_SESSION["emplyeeUser"]["use_name"] != EMPLOYEE_BASEUSER )
			{

				$sqlpower = " SELECT usp_action  FROM  ".$this -> db -> prefix."user_power  WHERE use_id = ".$_SESSION["emplyeeUser"]["use_id"]."  GROUP BY use_id ORDER BY `use_id` LIMIT 1 ";
		
				$loginUser = $this -> db -> selectOne($sqlpower);
				
				$usp_actionval = base64_decode($loginUser["usp_action"]);
				//var_dump($usp_actionval);
				@eval($usp_actionval);

				if(isset($companywebArray))
				{ 
					$GLOBALS["emplyeePower"] = $companywebArray;
					//$checkinArray = array_keys( $companywebArray );
				}

				$actfile = $GLOBALS['Reque'] -> getval["load"];
					
				$needact = $GLOBALS['Reque'] -> getval["act"];

				
				/* if( array_key_exists($actfile,$GLOBALS["emplyeePower"])  and  in_array($needact,(array)$GLOBALS["emplyeePower"][$actfile]) )
				{
					
					//echo '��Ȩ�޲�������!';
					
				}else */
				if($actfile!='' and $actfile!='top' and $actfile!='menu' and $actfile!='delimit' and $actfile!='main' and $actfile!='bottom' and  !( $actfile=='user' and  $needact =='actlogout' ) )
				{
					
					require ROOT_PATH.'includes/languages/'.$GLOBALS['WebConfig']['language'].'/'.$GLOBALS['language_path'].'/config.php';
					
					if($actfile!='' and in_array('infolist',(array)$GLOBALS["emplyeePower"][$actfile]))
					{
						$this -> view -> assign('infomessage',$this->lang['cf_nopower']);
						$this -> view -> assign('URL_TIME',URL_TIME);
						$this -> view -> assign('geturl',ADMIN_WEBURL."/index.php?load=".$actfile."&act=infolist");
						$this -> view -> display('nopower_tpl.html');
						exit();
					}else{
						$this -> view -> assign('infomessage',$this->lang['cf_nopower']);
						$this -> view -> assign('URL_TIME',URL_TIME);
						$this -> view -> assign('geturl',ADMIN_WEBURL."/index.php?load=main");
						$this -> view -> display('nopower_tpl.html');
						exit();
					}
					
					
				}
			
			}
			
			//$this -> view -> cache_dir = ROOT_PATH.'/admin/cache/'.$_SESSION["webAdmin"]["admin_name"]; ///�����Ա����Ŀ¼
		}
		
	}
	
	function userOnLine()
	{

		if($_SESSION["user"]["use_id"] =='' or  $_SESSION["user"]["use_name"] =='' or  $_SESSION["user"]["use_email"] =='' )
		{
			header("location:".ADMIN_WEBURL."/index.php?/user/login/");
			exit();
			//header("location:".WEBBASE_URL.ROOT_URL."login/act/");
		}
	}
	
	function isEmployee()
	{
	
		if($_SESSION["emplyeeUser"]["use_id"] =='' or  $_SESSION["emplyeeUser"]["use_name"] =='' or  $_SESSION["emplyeeUser"]["use_email"] =='' )
		{
			header("location:".ADMIN_WEBURL."/login.php?load=login&act=act");
			exit();
		}else{
			//��¼����Ҫ���������
			$this -> view -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["emplyeeUser"]["use_id"]; ///���ɻ���Ŀ¼
			
			//Ӧ�ô���Ȩ�ޡ�һЩ���飬���໺�����ݵȵȡ�
			//echo "ddddddddddddd";
			
			$this -> employeePower();

			$GLOBALS['Url'] -> loadact();
			
			
		}
		
	}

	function OnPower()
	{
	
		
	}

	function isUser()
	{
	
		if($_SESSION["user"]["use_id"] =='' or  $_SESSION["user"]["use_name"] =='' or  $_SESSION["user"]["use_email"] =='' )
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act");
			exit();
		}else{
			//��¼����Ҫ���������
			$this -> view -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["user"]["use_id"]; ///���ɻ���Ŀ¼
			
			//Ӧ�ô���Ȩ�ޡ�һЩ���飬���໺�����ݵȵȡ�
			
			$GLOBALS['Url'] -> loadact();
			
		}
	}
	
	function isLoginUser( $getUrl = '')
	{
		if( ( $_SESSION["user"]["use_id"] =='' or  $_SESSION["user"]["use_name"] =='' or  $_SESSION["user"]["use_email"] =='') and  $getUrl =='')
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act");
			exit();
			
		}elseif($getUrl == '')
		{
			//��¼����Ҫ���������
			$this -> view -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["user"]["use_id"]; ///���ɻ���Ŀ¼
			
			//Ӧ�ô���Ȩ�ޡ�һЩ���飬���໺�����ݵȵȡ�
			
			$GLOBALS['Url'] -> loadact();
			
		}elseif($getUrl != '' and  ($_SESSION["user"]["use_id"] =='' or  $_SESSION["user"]["use_name"] =='' or  $_SESSION["user"]["use_email"] =='' ))
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act&".$getUrl);
			exit('');
		}
	}
	

	function get_user_link( $lang = array() )
	{
		if(!isset($lang['reg'])){ 	$lang['reg'] 		= 'Register'; }
		if(!isset($lang['login'])){ 	$lang['login'] 	= 'Login'; }
		if(!isset($lang['exit'])){ 	$lang['exit'] 		= 'Exit'; }

		if(isset($_SESSION["user"]))
		{
			
			if($_SESSION["user"]["use_id"] =='' or  $_SESSION["user"]["use_name"] =='' or  $_SESSION["user"]["use_email"] =='' )
			{
				$user_link = '<a href="'.USER_WEBURL.'/index.php?load=login&act=reg" target="_self" >'.$lang['reg'].'</a> | <a href="javascript:loginshow()"  target="_self" onclick="loginshow()" >'.$lang['login'].'</a>&nbsp;';
				
			}else{
				$user_link = $lang['welcome'].'<a href="'.USER_WEBURL.'/" target="_self" >'.$_SESSION["user"]["use_name"].'</a>&nbsp; | <a href="'.USER_WEBURL.'/" target="_self" >'.$lang['member'].'</a>&nbsp;|  <a href="'.USER_WEBURL.'/index.php?load=login&act=logout" target="_self" >'.$lang['exit'].'</a> ';
			}
			
			
		}else{
			$user_link = '<a href="'.USER_WEBURL.'/index.php?load=login&act=reg"  target="_self" >'.$lang['reg'].'</a>| <a href="javascript:loginshow()"  target="_self" onclick="loginshow()" >'.$lang['login'].'</a>&nbsp;';
		
		}

		return $user_link;
	}
	
	
	
	
	
}

