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

$forusertype = 0; //PublicUsers

$methodname = 'Admin.GetWebApps';
$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
    '<ip>' . getip() . '</ip>' . 
	'<forusertype>' . $forusertype . '</forusertype>' . 
	'</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='publicwebapps_add.php'" /></li>
		</ul>
		</div>
	</div>

	<table class="grid1">
		<thead>
			<tr>
				<th width="48"></th>
				<th width="100">应用名称</th>
				<th width="150">应用URL</th>
				<th width="80">应用分类</th>
				<th width="100">浏览器</th>
				<th width="80">快捷方式</th>
				<th width="100">操作</th>
			</tr>
		</thead>	
        <tbody>
EOT;
		$itemindex = 0;
		foreach ($responsexml->webapps->item as $item) {
			$itemindex += 1;
			$itembgcolor = '#f2f2f2';
			if (($itemindex % 2) == 0) $itembgcolor = '#e9e9e9';

			//subpageurlparams
			$subpageurlparams = 'appid=' . $item->appid . '&appname=' . urlencode($item->appname);

			$appurl = $item->appurl;
			if (strlen($item->appurl) >= 33)  
				$appurl = substr($item->appurl, 0, 33) . '...';

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

			$webbrowserstr = '系统默认';
			if ($item->clientwebbrowser == 1) $webbrowserstr = '客户端嵌入';
			if ($item->clientwebbrowser == 2) $webbrowserstr = '客户端嵌入<br>(弹出:系统默认)';
				
			$shortcutstr = '应用列表';
			if ($item->shortcut == 1) 
				$shortcutstr = '用户信息档';	
			else if ($item->shortcut == 2) 
				$shortcutstr = '快速启动栏'; 
echo<<<EOT
		<tr>
			<td><a href="webapps_changeimage.php?{$subpageurlparams}" title="点击修改图标"><img width="40px" height="40px" style="" src="../../webapps/{$item->appimage}"/></a></td>
			<td style="padding:12px 0 0 0;">$item->appname</td>
			<td style="padding:12px 0 0 0;">$appurl</td>
			<td style="padding:12px 0 0 0;">$categorystr</td>
			<td style="padding:12px 0 0 0;">$webbrowserstr</td>
			<td style="padding:12px 0 0 0;">$shortcutstr</td>
			<td style="padding:12px 0 0 0;text-align:center">
				<a href="publicwebapps_moveup.php?{$subpageurlparams}"><img width="16px" height="16px" align="absmiddle" src="../images/up.gif" title="向上" /></a>
				<a href="publicwebapps_movedown.php?{$subpageurlparams}"><img width="16px" height="16px" align="absmiddle" src="../images/down.gif" title="向下" /></a>
				<a href="publicwebapps_changeimage.php?{$subpageurlparams}"><img width="16px" height="16px" align="absmiddle" src="../images/image.gif" title="修改图标" /></a>
				<a href="publicwebapps_modify.php?{$subpageurlparams}"><img width="16px" height="16px" align="absmiddle" src="../images/modify.gif" title="编辑" /></a>
				<a href="publicwebapps_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>
		</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>
