<?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, 'accounts');
?>
<!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" />
<script type="text/javascript" src="../../ckeditor/ckeditor.js"></script>
<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.title.value.trim() == "") { 
      alert('标题不能为空！'); 
      return false; 
    } 
	if(form.content.value.trim() == "") { 
      alert('内容不能为空！'); 
      return false; 
    } 
	if (form.htmlurl.value.trim() != '') {
		if ((form.htmlurl.value.trim().substring(0, 7) != "http://") && 
			(form.htmlurl.value.trim().substring(0, 8) != "https://")) { 
		  alert('链接地址必须以"http://"或"https://"开头'); 
		  return false; 
		} 
	}
    return   true; 
}//chkform

function changelinktype(obj) {
	if (obj.value == 1) {
		document.getElementById('link1').style.display = "";
		document.getElementById('link2').style.display = "none";
	} else if (obj.value == 2) {
		document.getElementById('link1').style.display = "none";
		document.getElementById('link2').style.display = "";
	} else {
		document.getElementById('link1').style.display = "none";
		document.getElementById('link2').style.display = "none";
	}
}
</script>
</head>
<body>

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

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

echo<<<EOT
<div class="rightbar">
	<div class="form_title">发布外部帐号</div>
	<div class="form_panel">
		<form action="accounts_add.php?step=2" method="post" id="form" onSubmit="return chkform();">
		<table  style="border:0;">
		<tr>
			<td class="td1">帐号段:</td>
			<td class="td2" style="height:40px;"><input style="width:120px;" type="text" name="beginuserid" value=""/>&nbsp;到&nbsp;<input style="width:120px;" type="text" name="enduserid" value=""/>&nbsp;&nbsp;&nbsp;<span style="color:#2fb900;">非"0"开头的9位以内数字，单个号段相差不能超过10000</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='accounts.php'"></td>
		</tr>
		</table>
		</form>
	</div>
</div>
EOT;
}//step1

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

    $accounttype = 0; //外部帐号
	$beginuserid = isset($_POST['beginuserid']) ? $_POST['beginuserid'] : '0'; 
	$enduserid = isset($_POST['enduserid']) ? $_POST['enduserid'] : '0'; 

	$methodname = 'Admin.AddAccounts';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<ip>' . getip() . '</ip>' . 
		'<accounttype>' . $accounttype . '</accounttype>' . 
		'<beginuserid>' . $beginuserid . '</beginuserid>' . 
		'<enduserid>' . $enduserid . '</enduserid>' . 
		'</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='accounts_add.php'" />
			<input class="cssbtn" type="button" value="返回" onclick="window.location='accounts.php'" />
		</div>
	</div>
EOT;
			break;
		case ERRORCODE_INVALIDPARAMS: 
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='accounts_add.php'" />
			<input class="cssbtn" type="button" value="返回" onclick="window.location='accounts.php'" />
		</div>
	</div>
EOT;
			break;
		case ERRORCODE_EXISTS: 
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='accounts_add.php'" />
			<input class="cssbtn" type="button" value="返回" onclick="window.location='accounts.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='accounts_add.php'" />
			<input class="cssbtn" type="button" value="返回" onclick="window.location='accounts.php'" />
		</div>
	</div>
EOT;
	}//switch
}//step2

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

</body>
</html>
