<?php
class WebSession
{
	//var $WebSession = array();
	function WebSession()
	{
		session_start();
		$_SESSION["session_id"] = session_id();
		//var_dump($_SESSION);
	}
	
	function SetSession( $arr )
	{
		foreach($arr as $key => $val)
		{
			if(is_array($val))
			{
				foreach($val as $skey => $sval)
				{
					$_SESSION[$key][$skey] = $sval;
				}
			}else{
				$_SESSION[$key] = $val;
			}
		}
	}
	
	function delSession( $arr )
	{
		foreach($arr as $key)
		{
			unset( $_SESSION[$key] );
		}
	}
	
	function dropSession()
	{
		//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:".EMPLOYEE_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  ".SQL_PREFIX."userpower  WHERE use_id = ".$_SESSION["emplyeeUser"]["use_id"]."  GROUP BY use_id ORDER BY `use_id` LIMIT 1 ";
		
				$loginUser = $GLOBALS['MySql'] -> selectOne($sqlpower);
				
				$usp_actionval = base64_decode($loginUser["usp_action"]);
				
				@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 '有权限操作数据!';
					
				}elseif($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]))
					{
						$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['cf_nopower']);
						$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
						$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=".$actfile."&act=infolist");
						$GLOBALS['Templ'] -> display('nopower_tpl.html');
						exit();
					}else{
						$GLOBALS['Templ'] -> assign('infomessage',$GLOBALS['_LANG']['cf_nopower']);
						$GLOBALS['Templ'] -> assign('URL_TIME',URL_TIME);
						$GLOBALS['Templ'] -> assign('geturl',EMPLOYEE_WEBURL."/index.php?load=main");
						$GLOBALS['Templ'] -> display('nopower_tpl.html');
						exit();
					}
					
					
				}
			
			}
			
			//$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.'/admin/cache/'.$_SESSION["webAdmin"]["admin_name"]; ///后管理员缓存目录
		}
		
	}
	
	function userOnLine()
	{

		if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' or  $_SESSION["webUser"]["use_email"] =='' )
		{
			header("location:".ADMIN_WEBURL."/index.php/user/login/");
			exit();
			//header("location:".WEBBASE_URL.ROOT_URL."login/act/");
		}else{
			
			
		}
	}
	
	function isEmployee()
	{
	
		if($_SESSION["emplyeeUser"]["use_id"] =='' or  $_SESSION["emplyeeUser"]["use_name"] =='' or  $_SESSION["emplyeeUser"]["use_email"] =='' )
		{
			header("location:".EMPLOYEE_WEBURL."/login.php?load=login&act=act");
			exit();
		}else{
			//登录后须要处理的事情
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["emplyeeUser"]["use_id"]; ///生成缓存目录
			
			//应该处理权限。一些数组，分类缓存数据等等。

			
			$this -> employeePower();

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

	function OnPower()
	{
	
		
	}

	function isUser()
	{
	
		if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' or  $_SESSION["webUser"]["use_email"] =='' )
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act");
			exit();
		}else{
			//登录后须要处理的事情
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["webUser"]["use_id"]; ///生成缓存目录
			
			//应该处理权限。一些数组，分类缓存数据等等。
			
			$GLOBALS['Url'] -> loadact();
			
		}
	}
	
	function isLoginUser( $getUrl = '')
	{
		if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' or  $_SESSION["webUser"]["use_email"] =='' )
		{
			header("location:".BASE_WEBURL."/user/login.php?load=login&act=act");
			exit();
			
		}elseif($getUrl == '')
		{
			//登录后须要处理的事情
			$GLOBALS['Templ'] -> cache_dir = ROOT_PATH.$GLOBALS['cache_path'].'/'.$_SESSION["webUser"]["use_id"]; ///生成缓存目录
			
			//应该处理权限。一些数组，分类缓存数据等等。
			
			$GLOBALS['Url'] -> loadact();
			
		}elseif($getUrl != '')
		{
			
		
		}
	}
	

	
	function getuserlink()
	{
		if(isset($_SESSION["webUser"]))
		{

			if($_SESSION["webUser"]["use_id"] =='' or  $_SESSION["webUser"]["use_name"] =='' or  $_SESSION["webUser"]["use_email"] =='' )
			{
				$userlink = '<a href="'.BASE_WEBURL.'/user/login.php?load=login&act=reg" target="_self" >'.$GLOBALS['_LANG']['us_reg'].'</a>| <a href="javascript:loginshow()"  target="_self" onclick="loginshow()" >'.$GLOBALS['_LANG']['us_login'].'</a>&nbsp;';
				
			}else{
				$GLOBALS['Templ']->assign('webuse_id',		$_SESSION["webUser"]["use_id"]);
				$GLOBALS['Templ']->assign('webuse_name',	$_SESSION["webUser"]["use_name"]);
				$GLOBALS['Templ']->assign('webuse_email',	$_SESSION["webUser"]["use_email"]);
				
				$userlink = $GLOBALS['_LANG']['us_welcome'].'<a href="'.BASE_WEBURL.'/user/" target="_self" >'.$_SESSION["webUser"]["use_name"].'</a>&nbsp; | <a href="'.BASE_WEBURL.'/user/" target="_self" >'.$GLOBALS['_LANG']['us_member'].'</a>&nbsp;|  <a href="'.BASE_WEBURL.'/user/login.php?load=login&act=logout" target="_self" >'.$GLOBALS['_LANG']['us_logout'].'</a> ';
			}
			
			
		}else{
			$userlink = '<a href="'.BASE_WEBURL.'/user/login.php?load=login&act=reg"  target="_self" >'.$GLOBALS['_LANG']['us_reg'].'</a>| <a href="javascript:loginshow()"  target="_self" onclick="loginshow()" >'.$GLOBALS['_LANG']['us_login'].'</a>&nbsp;';
		
		}
		
		///您好，admin, 欢迎您回来！ 用户中心 |  退出
		
		return $userlink;
	}
	
	
}
$WebSe = new WebSession();
?>