<?
session_start();
require_once "../init.php";
require_once "../authority.inc.php";
if($_GET['UserID'])
{
$UserID = $_GET['UserID'];
}
else
{
$UserID = $_POST['UserID'];
}
if($_GET['key'])
{
$key = $_GET['key'];
}
else
{
$key = $_POST['key'];
}
if($_POST['Edit'])
{
	$Edit = $_POST['Edit'];
}
else
{
	$Edit = $_GET['Edit'];
}
if($_POST['perm'])
{
	$perm = $_POST['perm'];
}
else
{
	$perm = $_GET['perm'];
}
if($_POST['perm_sys'])
{
	$perm_sys = $_POST['perm_sys'];
}
else
{
	$perm_sys = $_GET['perm_sys'];
}
if(!CheckHashKey('admins'.$UserID,$key)){
   $DB->close();
   die("非法入侵");
}
$sql = "select * from admins where UserID='$UserID'";
$AdminInfo = $DB->getdata($sql);
if($Edit==1){
  if($perm_sys==1)$permstring = "|SYSTEM|";
  elseif(count($perm)>0) $permstring = "|".implode("|",$perm)."|";
  $sql="update admins set Perm='$permstring' where UserID='$UserID'";
  $DB->query($sql);
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" 
/>
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="/admin/lib/PIE_IE678.js"></script>
<![endif]-->


<!--[if IE 6]>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>分配管理员权限</title>
<LINK href="../share/style.css" rel=stylesheet>
<script src='../share/global.js'></script>
</head>
<body>

<div id="topLink">
<div id="topInfo">
	<span class="tTitle">员工管理</span>
	<span class="sarr"> >> </span>
	管理员 <?=$AdminInfo['UserID']?> 的权限分配
	<span class="sarr"> >> </span>
	<a href="<?=$GLOBALS["parentpath"]?>/admins/admins_list.php">返回到员工管理</a>
</div>
</div>
<!--子导航--><div styl="padding:20px;">


<!--结束-->
<br>
<form action="admins_perm.php" method="post" onSubmit="return check(this)" width="100%" cellspacing="0" cellpadding="0">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td>
			<?
			 $sql="select * from secu_class";
			 $res=$DB->query($sql);
			  while($sesu_class=$DB->fetch_array($res)){ 
			$i++;
				  ?>
				<fieldset style="height:50px;margin:20px;" align="center"> <legend> <font color="#009900"><?=$sesu_class[Name]?></font></legend>
					<?
					  $sql="select * from security where ClassID=$sesu_class[ID]";
					  $res2=$DB->query($sql);
					  $icount=0;
					  while($security=$DB->fetch_array($res2)){ 
						  $icount++;
						  $i++;
						  $hasPerm=preg_match("/\|$security[SID]\|/",$AdminInfo['Perm'])||preg_match("/\|ALL\|/",$AdminInfo['Perm']);
						  if($hasPerm)$chk="checked";
						  else $chk="";
						  echo "<input type='checkbox' name='perm[]' id='p$i' value='$security[SID]' $chk><label for='p$i'>$security[SName]</label>";
						 // if($icount%8==0)echo "</tr><tr>";
					  }
					?>
				</fieldset><br>
			  <? }?>
			  <?if($_SESSION['Perm_S']=="|SYSTEM|"){?>
			  <center><br>
			  <input type='checkbox' name='perm_sys' value='1' <? if($AdminInfo['Perm']=="|SYSTEM|") echo "checked"?>><font color='red'>授权为超级管理员</font>
			  </center>
			  <?}?>
			</td>
          </tr>
          <tr>
            <td align='center'><br>
			    <input name="Edit" type="hidden" value="1">
				<input name="UserID" type="hidden" value="<?=$AdminInfo['UserID']?>">
				<input name="key" type="hidden" value="<?=$key?>">
				<input name="submit" type="submit" class="bt2" value="提交">&nbsp;&nbsp;
                <input name="reset" type="reset" class="bt2" value="重置">&nbsp;&nbsp;
			    <input type="button" class="bt2" value="返回" onClick="location='admins_list.php'">
			</td>
          </tr>
        </table>
    </form>
	</div><br>
<? 
$DB->close();
include "../share/bottom.php";
?>
</body>
</html>
