<?php
$GLOBALS["parentpath"] = file_exists("authority.inc.php")?".":"..";

function Go2Login($mess){
	  global $db;
	  $backUrl = GetUrl();
      echo "<LINK href='$GLOBALS[parentpath]/share/std.css' rel='stylesheet'>";
	  echo "<table width='500' align='center' border='0'>";
	  echo "<tr><td> ".$mess." ，请选择以下操作";
	  echo "<br><br><br>";
	  echo "<a href='#' onclick='history.go(-1)'><b>后退一步</b></a>&nbsp;&nbsp;";
	  echo "<a href='$GLOBALS[parentpath]/index.php'><b>返回管理后台首页</b></a>&nbsp;&nbsp;";
	  echo "<a href='$GLOBALS[parentpath]/login.php?backUrl=".$backUrl."'><b>以另一身份登录</b></a>&nbsp;&nbsp;";
	  echo "<br><br><br>";
	  echo "</td></tr></table>";
	  $db->close();
	  exit;
}

function GetSecurity(){
	 global $db;
     if($_SESSION['Security_S']) return $_SESSION['Security_S'];
     $sql = "select * from security";
	 $res = $db->query($sql);
	 $secuity = array();
     while($secu = $db->fetch_array($res)){
	      $key = strtolower($secu["SPage"]);
		  $secuity[$key]['SID'] = $secu['SID'];
		  $secuity[$key]['ClassID'] = $secu['ClassID'];
		  $secuity[$key]['SName'] = $secu['SName'];
		  $secuity[$key]['SPage'] = $secu['SPage'];
	 }
     $_SESSION['Security_S'] = $secuity;
	 return $_SESSION['Security_S'];
}



if($_SERVER['HTTP_REFERER'] == null )
{
	if(!$_SESSION['AdmUserID_S'] ){
		
		header("location:$GLOBALS[parentpath]/login.php");
		exit();
	}
}
else
{
	if(!$_SESSION['AdmUserID_S'] ){
		
		header("location:$GLOBALS[parentpath]/login.php?mess=请先登录");
		exit();
	}
}

if($_SESSION['Perm_S']!="|SYSTEM|"){ //如果最高管理员
	$spage = strtolower($_SERVER['PHP_SELF']);
	$addpath = "/admin/";
	$ipos = strrpos($addpath,$spage);
	$spage = substr($spage,$ipos + strlen($addpath));
	//echo $spage;
	$perms = GetSecurity();
	if($perms[$spage]){ //如果当前页有权限设定
	   $hasPerm = eregi("\|".$perms[$spage]['SID']."\|",$_SESSION['Perm_S']);
	   if(!$hasPerm) Go2Login("您没有 <".$perms[$spage]['SName']."> 的权限");
	}
}
?>