<?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, 'sysmsgs');
?>
<!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");

$pagesize = '10'; 
$pageindex = isset($_GET['pageindex']) ? $_GET['pageindex'] : '1'; 

$maxpageindex = $pageindex;

$firstpageurl = 'sysmsgs.php';
$prevpageurl = 'sysmsgs.php';
$nextpageurl = 'sysmsgs.php';
$lastpageurl = 'sysmsgs.php';

$methodname = 'Admin.GetSysMsgs';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'<pagesize>' . $pagesize . '</pagesize>' . 
	'<pageindex>' . $pageindex . '</pageindex>' . 
	'</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: 
		$maxpageindex = $responsexml->maxpageindex;	
		if ($pageindex > $maxpageindex) $pageindex = $maxpageindex;	
		
		//firstpageurl
		$newpageindex = 1;
		$firstpageurl = 'sysmsgs.php?pageindex=' . $newpageindex;

		//prevpageurl
		$newpageindex = $pageindex - 1;
		if ($newpageindex < 1) $newpageindex = 1;
		$prevpageurl = 'sysmsgs.php?pageindex=' . $newpageindex;

		//nextpageurl
		$newpageindex = $pageindex + 1;
		if ($newpageindex > $maxpageindex) $newpageindex = $maxpageindex;
		$nextpageurl = 'sysmsgs.php?pageindex=' . $newpageindex;

		//lastpageurl
		$newpageindex = $maxpageindex;
		$lastpageurl = 'sysmsgs.php?pageindex=' . $newpageindex;

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='sysmsgs_add.php'" /></li>
		</ul>
		</div>
	</div>

	<table class="grid1">
		<thead>
			<tr>
				<th width="48"></th>
				<th width="100">标题</th>
				<th width="100">分类</th>
				<th width="150">内容</th>
				<th width="50">链接</th>
				<th width="100">接收范围</th>
				<th width="100">附加选项</th>
				<th width="100">发布时间</th>
				<th width="100">操作</th>
			</tr>
		</thead>	
        <tbody>
EOT;
		$itemindex = 0;
		foreach ($responsexml->sysmsgs->item as $item) {
			$itemindex += 1;
			$itembgcolor = '#f2f2f2';
			if (($itemindex % 2) == 0) $itembgcolor = '#e9e9e9';

			//subpageurlparams
			$subpageurlparams = 'sysmsgid=' . $item->sysmsgid . '&title=' . urlencode($item->title);

			$cutline = $item->content;
			if (strlen($item->content) >= 33)  
				$cutline = substr($item->content, 0, 33) . '...';
				
			$link = '<span style="color:#808080">无</span>';
			if ($item->link != '') $link = '有';
				
			$sendto = '全部帐号';
			if ($item->forusertype == 0) $sendto = '外部帐号';
			if ($item->forusertype == 1) $sendto = '内部帐号';
			if ($item->fordepartname != '') { if ($sendto != '') $sendto .= ','; $sendto .= $item->fordepartname; }
			if ($item->sendtodetail != '') { if ($sendto != '') $sendto .= ','; $sendto .= $item->sendtodetail; }
				
			$options = '';
			if ($item->foronlineusers == 1) { if ($options != '') $options .= ','; $options .= '在线用户'; }
			if ($item->needreaded == 1) { if ($options != '') $options .= ','; $options .= '已读计数'; }
			if ($item->needfeedback == 1) { if ($options != '') $options .= ','; $options .= '消息反馈'; }
echo<<<EOT
		<tr>
			<td><img width="40px" height="40px" style="" src="../images/sysmsg.gif"/></td>
			<td style="padding:12px 0 0 0;">$item->title</td>
			<td style="padding:12px 0 0 0;">$item->category</td>
			<td style="padding:12px 0 0 0;">$cutline</td>
			<td style="padding:12px 0 0 0;">$link</td>
			<td style="padding:12px 0 0 0;">$sendto</td>
			<td style="padding:12px 0 0 0;">$options</td>
			<td style="padding:12px 0 0 0;">$item->sendtime</td>
			<td style="padding:12px 0 0 0;text-align:center">
				<a href="sysmsgs_remove.php?{$subpageurlparams}"><img width="16px" height="16px" align="absmiddle" src="../images/remove.gif" title="删除" /></a>
			</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>
			<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>
EOT;
	
		//当前是第X/X页,本页有X条记录
echo<<<EOT
		<div class="statusbar">			
			<div style="float:left;width:200px;">
EOT;
		//第一页，上一页(((
		if ($pageindex == 1) {
echo<<<EOT
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><span style="color:#808080">第一页</span></div>
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><span style="color:#808080">上一页</span></div>
EOT;
		} else {
echo<<<EOT
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><a href="{$firstpageurl}">第一页</a></div>
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><a href="{$prevpageurl}">上一页</a></div>
EOT;
		}//)))第一页，上一页
		//下一页，最后页(((
		if ($pageindex == $maxpageindex) {
echo<<<EOT
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><span style="color:#808080">下一页</span></div>
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><span style="color:#808080">最后页</span></div>
EOT;
		} else {
echo<<<EOT
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><a href="{$nextpageurl}">下一页</a></div>
				<div style="float:left;margin:0;padding:8px 0 0 0;width:44px;text-align:center;"><a href="{$lastpageurl}">最后页</a></div>
EOT;
		}//)))下一页，最后页
echo<<<EOT
			</div>
			<div style="float:left;margin:0;padding:8px 0 0 0;text-align:left;">当前是第{$pageindex}/{$maxpageindex}页,本页有{$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>
