<?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, 'webapps');
?>
<!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" />
<style type="text/css">
.td1 { padding:5px 0 0 0;width:70px;height:20px;vertical-align:top; }
.td2 { width:880px;vertical-align:top; }
</style>
<script type="text/javascript">
String.prototype.trim=function() {
     return this.replace(/(^\s*)(\s*$)/g, '');
}
function chkform() {
	var form = document.getElementById('form');
    if(form.appname.value.trim() == "") { 
      alert('应用名称不能为空！'); 
      return false; 
    } 
    if(form.category.value.trim() == "") { 
      alert('应用分类不能为空！'); 
      return false; 
    } 
	if(form.appurl.value.trim() == "") { 
      alert('应用地址不能为空！'); 
      return false; 
    } 
	if ((form.appurl.value.trim().substring(0, 7) != "http://") && 
		(form.appurl.value.trim().substring(0, 8) != "https://")) { 
      alert('应用地址必须以"http://"或"https://"开头'); 
      return false; 
    } 
    return   true; 
}//chkform
</script>
</head>
<body>

<?php
$step = isset($_GET['step']) ? $_GET['step'] : '1'; 

function step1() {
	require_once("../common.php");

	$appid = isset($_GET['appid']) ? $_GET['appid'] : '0';
	$appname = isset($_GET['appname']) ? urldecode($_GET['appname']) : '';

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

	$methodname = 'Admin.GetWebApp';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<ip>' . getip() . '</ip>' . 
		'<appid>' . $appid . '</appid>' . 
		'</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="whiteline"></div>

	<div class="rightbar">
		<b class="b1"></b><b class="b2 d1"></b><b class="b3 d1"></b><b class="b4 d1"></b>
		<div class="b d1">
			<ul>
				<li>在应用地址中使用的系统变量：</li>
				<li style="list-style:none;"><span style="color:#28a9ff;">[%HTTP_HOST%]</span>：当前服务器的主机名与端口。(如:&quot;http:&#x2F;&#x2F;localhost:5880/admin&quot;可写成&quot;http:&#x2F;&#x2F;[%HTTP_HOST%]/admin&quot;)</li>
				<li style="list-style:none;"><span style="color:#28a9ff;">[%USERID%]</span>：当前登录帐号的&quot;用户ID&quot;。(如:&quot;http:&#x2F;&#x2F;www.xxx.com/webapp1.php?userid=[%USERID%]&quot;)</li>
				<li style="list-style:none;"><span style="color:#28a9ff;">[%USERNAME%]</span>：当前登录帐号的&quot;用户名&quot;。(如:&quot;http:&#x2F;&#x2F;www.xxx.com/webapp1.php?username=[%USERNAME%]&quot;)</li>
				<li style="list-style:none;"><span style="color:#28a9ff;">[%PASSWORD%]</span>：当前登录帐号的MD5密码。(如:&quot;http:&#x2F;&#x2F;www.xxx.com/webapp1.php?userid=[%USERID%]&amp;pwd=[%PASSWORD%]&quot;)</li>
				<li style="list-style:none;"><span style="color:#28a9ff;">[%TOKEN%]</span>：当前登录帐号的令牌，可以在应用的登录页面代码中调用<a href="../../openapi/openapi.php?wsdl" target="_blank">&quot;openapi.php?wsdl&quot;</a>WebService接口验证用户是否已经登录。</li>
			</ul>
		</div>
		<b class="b4b d1"></b><b class="b3b d1"></b><b class="b2b d1"></b><b class="b1b"></b>
	</div>

	<div class="whiteline"></div>

	<div class="rightbar">
		<div class="form_title">编辑应用&nbsp;&quot;$appname&quot;</div>
		<div class="form_panel">
			<form action="webapps_modify.php?step=2" method="post" enctype="multipart/form-data" id="form" onSubmit="return chkform();">
			<input type="hidden" name="appid" value="{$appid}"/>
			<table border="0">
			<tr>
				<td class="td1">应用名称:</td>
				<td class="td2"><input style="width:260px;" type="text" name="appname" value="{$responsexml->appname}"><span style="color:#ff0000;">&nbsp;*</span>&nbsp;<span style="color:#2fb900;">最大长度为50个字符</span></td>
			</tr>
			<tr>
				<td class="td1">应用分类:</td>
				<td class="td2"><input style="width:260px;" type="text" name="category" value="{$responsexml->category}"><span style="color:#ff0000;">&nbsp;*</span>&nbsp;<span style="color:#2fb900;">最大长度为50个字符</span></td>
			</tr>
			<tr>
				<td class="td1">应用介绍:</td>
				<td class="td2"><textarea style="width:264px;height:80px;" id="introduction" name="introduction">$responsexml->introduction</textarea>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">最大长度为255个字符</span></td>
			</tr>
			<tr>
				<td class="td1">应用URL:</td>
				<td class="td2"><textarea style="width:264px;height:80px;" id="appurl" name="appurl">$responsexml->appurl</textarea><span style="color:#ff0000;">&nbsp;*</span>&nbsp;<span style="color:#2fb900;">应用URL中可插入系统变量(见上面黄色区域中的说明)</span></td>
			</tr>
			<tr>
				<td class="td1">请求方式:</td>
				<td class="td2">
					<select style="width:266px;" name="method">
					<option value="0"
EOT;
if ($responsexml->method == 0) echo ' selected ';
echo<<<EOT
					>GET</option>
					<option value="1"
EOT;
if ($responsexml->method == 1) echo ' selected ';
echo<<<EOT
					>POST</option>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td1">POST参数:</td>
				<td class="td2"><textarea style="width:264px;height:80px;" id="postdata" name="postdata">$responsexml->postdata</textarea><span style="color:#ff0000;">&nbsp;*</span>&nbsp;<span style="color:#2fb900;">POST参数中可插入系统变量(见上面黄色区域中的说明)</span></td>
			</tr>
			<tr>
				<td class="td1">自动弹出:</td>
				<td class="td2">
					<select style="width:266px;" name="popup">
					<option value="0"
EOT;
if ($responsexml->popup == 0) echo ' selected ';
echo<<<EOT
					>关闭</option>
					<option value="1"
EOT;
if ($responsexml->popup != 0) echo ' selected ';
echo<<<EOT
					>开启</option>
					</select>
				</td>
			</tr>
			<tr>
				<td class="td1">浏览器:</td>
				<td class="td2">
					<select style="width:266px;" name="clientwebbrowser">
					<option value="0"
EOT;
if ($responsexml->clientwebbrowser == 0) echo ' selected ';
echo<<<EOT
					>系统默认</option>
					<option value="1"
EOT;
if ($responsexml->clientwebbrowser == 1) echo ' selected ';
echo<<<EOT
					>客户端嵌入</option>
					<option value="2"
EOT;
if ($responsexml->clientwebbrowser == 2) echo ' selected ';
echo<<<EOT
					>客户端嵌入(弹出:系统默认)</option>
					</select>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">打开应用时所使用的浏览器</span>
				</td>
			</tr>
			<tr>
				<td class="td1">页面宽度:</td>
				<td class="td2"><input style="width:260px;" type="text" name="webbrowserwidth" value="{$responsexml->webbrowserwidth}">&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">使用客户端嵌入浏览器有效(单位:像素)</span></td>
			</tr>
			<tr>
				<td class="td1">页面高度:</td>
				<td class="td2"><input style="width:260px;" type="text" name="webbrowserheight" value="{$responsexml->webbrowserheight}">&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">使用客户端嵌入浏览器有效(单位:像素)</span></td>
			</tr>
			<tr>
				<td class="td1">快捷方式:</td>
				<td class="td2" style="height:40px;">
					<select style="width:266px;" name="shortcut">
					<option value="0"
EOT;
if ($responsexml->shortcut == 0) echo ' selected ';
echo<<<EOT
					>应用列表</option>
					<option value="1"
EOT;
if ($responsexml->shortcut == 1) echo ' selected ';
echo<<<EOT
					>用户信息栏</option>
					<option value="2"
EOT;
if ($responsexml->shortcut == 2) echo ' selected ';
echo<<<EOT
					>快速启动栏</option>
					</select>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">应用快捷方式在主面板上的显示位置</span>
				</td>
			</tr>
			<tr>
				<td class="td1"></td>
				<td class="td2"><input class="cssbtn" type="submit" value="修改">&nbsp;<input class="cssbtn" type="button" value="取消" onclick="window.location='webapps.php'"></td>
			</tr>
			</table>
			</form>
		</div>
	</div>

	<div class="whiteline"></div>
	<div class="whiteline"></div>
	<div class="whiteline"></div>
	<div class="whiteline"></div>
	<div class="whiteline"></div>
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;
	}//switch
}//step1

function step2() {
	require_once("../common.php");

	$appid = isset($_POST['appid']) ? $_POST['appid'] : ''; 
	$appname = isset($_POST['appname']) ? $_POST['appname'] : ''; 
	$category = isset($_POST['category']) ? $_POST['category'] : ''; 
	$introduction = isset($_POST['introduction']) ? $_POST['introduction'] : ''; 
	$appurl = isset($_POST['appurl']) ? $_POST['appurl'] : ''; 
	$method = isset($_POST['method']) ? $_POST['method'] : '0'; 
	$postdata = isset($_POST['postdata']) ? $_POST['postdata'] : ''; 
	$popup = isset($_POST['popup']) ? $_POST['popup'] : '0'; 
	$clientwebbrowser = isset($_POST['clientwebbrowser']) ? $_POST['clientwebbrowser'] : '0'; 
	$webbrowserwidth = isset($_POST['webbrowserwidth']) ? $_POST['webbrowserwidth'] : '600'; 
	$webbrowserheight = isset($_POST['webbrowserheight']) ? $_POST['webbrowserheight'] : '400'; 
	$shortcut = isset($_POST['shortcut']) ? $_POST['shortcut'] : '0'; 

	$methodname = 'Admin.ModifyWebApp';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<ip>' . getip() . '</ip>' . 
		'<appid>' . $appid . '</appid>' . 
		'<appname>' . $appname . '</appname>' . 
		'<category>' . $category . '</category>' . 
		'<introduction>' . $introduction . '</introduction>' . 
		'<appurl>' . strtoxml($appurl) . '</appurl>' . 
		'<method>' . $method . '</method>' . 
		'<postdata>' . strtoxml($postdata) . '</postdata>' . 
		'<popup>' . $popup . '</popup>' . 
		'<clientwebbrowser>' . $clientwebbrowser . '</clientwebbrowser>' . 
		'<webbrowserwidth>' . $webbrowserwidth . '</webbrowserwidth>' . 
		'<webbrowserheight>' . $webbrowserheight . '</webbrowserheight>' . 
		'<shortcut>' . $shortcut . '</shortcut>' . 
		'</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="msgbox">
		<div class="msgbox_text">
			<img width="40px" height="40px" align="absmiddle" src="../images/ok.gif" />&nbsp;应用修改成功！
		</div>
		<div class="msgbox_btns">
			<input class="cssbtn" type="button" value="返回" onclick="window.location='webapps.php'" />
		</div>
	</div>
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 class="msgbox_btns">
			<input class="cssbtn" type="button" value="返回" onclick="window.location='webapps.php'" />
		</div>
	</div>
EOT;
	}//switch
}//step2

if ($step == 1) {
	step1();
}
else if ($step == 2) {
	step2();
}
?>

</body>
</html>
