<?php
header("Content-type:text/html;charset=utf-8");  
session_start();
$session_admin = isset($_SESSION['admin']) ? $_SESSION['admin'] : ''; 
if ($session_admin == '') {
	die("Can not access");
}
require_once("../common.php");
checkadminrights($session_admin, 'admins');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" rel="stylesheet" href="../css/base.css" />
<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.pack.css" />
<script type="text/javascript" src="../js/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.pack.js"></script>
<style type="text/css">
#searchbar ul { margin:0;padding:0;list-style:none;display:inline; }
#searchbar li { float:left;margin:0;padding:10px 0 0 0; }
</style>
</head>
<body>

<?php
require_once("../common.php");

$methodname = 'Admin.GetAdmins';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'</request>';
$responseinfo = '';
$responsexml = null;
$errorcode = ERRORCODE_UNKNOWN;


$cmd = new COM("OpenCom.Command");
$methodname = iconv('UTF-8', 'GBK//IGNORE', $methodname);
$requestinfo = iconv('UTF-8', 'GBK//IGNORE', $requestinfo);
if ($cmd->Execute($methodname, $requestinfo, $responseinfo, 5000)) {
	$responseinfo = iconv('GBK', 'UTF-8//IGNORE', $responseinfo);
	$responsexml = simplexml_load_string($responseinfo);
	$errorcode = $responsexml->errorcode;
}
$cmd = null;
 
switch($errorcode) {
	case ERRORCODE_OK: 
echo<<<EOT
	<div class="rightbar">
		<div id="searchbar" style="float:left;margin:0;padding:0;height:45px;text-align:left;font-size:13px;color:#000000;">
		<ul>
			<li><input class="cssbtn" type="button" value="添加管理员" onclick="window.location='admins_add.php'" /></li>
		</ul>
		</div>
	</div>

	<table class="grid1">
		<thead>
			<tr>
				<th width="48"></th>
				<th width="100">管理员</th>
				<th width="300">权限</th>
				<th width="200">描述</th>
				<th width="60">操作</th>
			</tr>
		</thead>	
        <tbody>
EOT;
		$itemindex = 0;
		foreach ($responsexml->admins->item as $item) {
			$itemindex += 1;
			$itembgcolor = '#f2f2f2';
			if (($itemindex % 2) == 0) $itembgcolor = '#e9e9e9';

			$lastlogintimestr = '<span style="color:#808080;">无</span>';
			if ($item->lastlogintime != '') $lastlogintimestr = $item->lastlogintime;

			$adminrights_text = '';
			if (strpos($item->adminrights, 'departments') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[组织机构管理]';
			}
			if (strpos($item->adminrights, 'users') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[内部帐号管理]';
			}
			if (strpos($item->adminrights, 'publicusers') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[外部帐号管理]';
			}
			if (strpos($item->adminrights, 'accounts') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[发布与注册]';
			}
			if (strpos($item->adminrights, 'groups') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[群组管理]';
			}
			if (strpos($item->adminrights, 'rooms') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[讨论组管理]';
			}
			if (strpos($item->adminrights, 'webapps') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[内部应用管理]';
			}
			if (strpos($item->adminrights, 'publicwebapps') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[外部应用管理]';
			}
			if (strpos($item->adminrights, 'sysmsgs') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[系统消息]';
			}
			if (strpos($item->adminrights, 'admins') !== false) {
				if ($adminrights_text != '') $adminrights_text .= ' + ';
				$adminrights_text .= '[管理员帐号管理]';
			}

			if ($adminrights_text == '') {
				$adminrights_text = '没有任何权限';
			}
echo<<<EOT
		<tr>
			<td>
EOT;
		if (strval($item->islock) == 1) {
echo<<<EOT
				<img width="40px" height="40px" style="" src="../images/admin_gray.gif"/>	
EOT;
		} else { 
echo<<<EOT
				<img width="40px" height="40px" style="" src="../images/admin.gif"/>	
EOT;
		}
echo<<<EOT
			</td>
			<td style="padding:12px 0 0 0;">$item->adminname</td>
			<td style="padding:12px 0 0 0;">$adminrights_text</td>
			<td style="padding:12px 0 0 0;">$item->description</td>
			<td style="padding:12px 0 0 0;text-align:center">
EOT;

			if ((strtolower($item->adminname) == 'admin') or (strtolower($item->adminname) == 'guest')) {
echo<<<EOT
					<a href="admins_modify.php?adminname={$item->adminname}"><img width="16px" height="16px" align="absmiddle" src="../images/modify.gif" title="修改资料" /></a>
					<a href="admins_resetpwd.php?adminname={$item->adminname}"><img width="16px" height="16px" align="absmiddle" src="../images/pwd.gif" title="修改密码" /></a>
EOT;
			} else {
echo<<<EOT
					<a href="admins_modify.php?adminname={$item->adminname}"><img width="16px" height="16px" align="absmiddle" src="../images/modify.gif" title="修改资料" /></a>
					<a href="admins_resetpwd.php?adminname={$item->adminname}"><img width="16px" height="16px" align="absmiddle" src="../images/pwd.gif" title="修改密码" /></a>
					<a href="admins_remove.php?adminname={$item->adminname}"><img width="16px" height="16px" align="absmiddle" src="../images/remove.gif" title="删除" /></a>
EOT;
			}//if

echo<<<EOT
			</td>
		</tr>
EOT;
		}//foreach
		if ($itemindex == 0) {
echo<<<EOT
		<tr>
			<td style="padding:12px 0 0 0;">null</td>
			<td style="padding:12px 0 0 0;">null</td>
			<td style="padding:12px 0 0 0;">null</td>
			<td style="padding:12px 0 0 0;">null</td>
			<td style="padding:12px 0 0 0;">null</td>
		</tr>
EOT;
		}//if
echo<<<EOT
		</tbody>
	</table>

	<div class="statusbar">
		<div style="float:left;margin:0;padding:8px 0 0 0;text-align:left;">共有{$itemindex}个管理员.</div>
	</div>

	<script type="text/javascript">
	$(document).ready(function(){  
		var w = document.documentElement.clientWidth;
		var h = document.documentElement.clientHeight - 110;
		$('.grid1').flexigrid({height:h,singleSelect:true,resizable:false,showToggleBtn:false});
	}); 
	</script>
EOT;
		break;
	default:
echo<<<EOT
	<div class="msgbox">
		<div class="msgbox_text">
			<img width="40px" height="40px" align="absmiddle" src="../images/warning.gif" />&nbsp;管理员列表获取失败！
		</div>
	</div>
EOT;
}
?>

</body>
</html>
