<?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, 'departments');

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

	$departid = isset($_GET['departid']) ? $_GET['departid'] : '';
	$departname = isset($_GET['departname']) ? urldecode($_GET['departname']) : '';
	$userid = isset($_GET['userid']) ? $_GET['userid'] : '0'; 
	$nickname = isset($_GET['nickname']) ? urldecode($_GET['nickname']) : '';

	//subpageurlparams
	$subpageurlparams = 'departid=' . $departid . '&departname=' . urlencode($departname) . 
		'&userid=' . $userid . '&nickname=' . urlencode($nickname);

	$smstotal = isset($_POST['smstotal']) ? $_POST['smstotal'] : '';
	$smsdaylimit = isset($_POST['smsdaylimit']) ? $_POST['smsdaylimit'] : '';

	$methodname = 'Admin.UpdateSMSSetting';
	$requestinfo = '<?xml version="1.0" encoding="utf-8"?><request>' . 
		'<ip>' . getip() . '</ip>' . 
		'<userid>' . $userid . '</userid>' .
		'<smstotal>' . $smstotal . '</smstotal>' . 
		'<smsdaylimit>' . $smsdaylimit . '</smsdaylimit>' .
		'</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: 
			header("location:   departments_users.php?{$subpageurlparams}");
			break;
		default:
			header("location:   departments_users.php?{$subpageurlparams}");
	}//switch
}//step2

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

if ($step == '2') {
	step2();
	exit;
}
?>
<!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:150px;height:20px;vertical-align:top; }
.td2 { width:780px;vertical-align:top; }
</style>
</head>
<body>

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

	$departid = isset($_GET['departid']) ? $_GET['departid'] : '';
	$departname = isset($_GET['departname']) ? urldecode($_GET['departname']) : '';
	$userid = isset($_GET['userid']) ? $_GET['userid'] : '0'; 
	$nickname = isset($_GET['nickname']) ? urldecode($_GET['nickname']) : '';

	//subpageurlparams
	$subpageurlparams = 'departid=' . $departid . '&departname=' . urlencode($departname) . 
		'&userid=' . $userid . '&nickname=' . urlencode($nickname);

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

	$smstotal = $responsexml->smstotal;
	$smsdaylimit = $responsexml->smsdaylimit;
	$smsdaystart = $responsexml->smsdaystart;
	$smsdaysended = $responsexml->smsdaysended;
	$smstotalsended = $responsexml->smstotalsended;

echo<<<EOT
	<div class="rightbar">
		<div class="form_title">
			为&nbsp;&quot;{$nickname}&quot;&nbsp;设置短信参数
		</div>
		<div class="form_panel">
			<form action="departments_smssetting.php?step=2&{$subpageurlparams}" method="post" id="form">
			<table style="border:0;">
			<tr>
				<td class="td1">最大短信发送数量:</td>
				<td class="td2"><input style="width:260px;" type="text" name="smstotal" value="{$smstotal}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;">设置为0表示关闭短信发送功能</span></td>
			</tr>
			<tr>
				<td class="td1">当日最大短信发送数量:</td>
				<td class="td2"><input style="width:260px;" type="text" name="smsdaylimit" value="{$smsdaylimit}"/>&nbsp;&nbsp;&nbsp;<span style="color:#33cc00;">设置为0表示关闭限制功能</span></td>
			</tr>
			<tr>
				<td class="td1">所有已发送短信数量:</td>
				<td class="td2"><input style="width:260px;background-color:#e1e1e1;" type="text" name="smsdaysended" value="{$smsdaysended}" readonly /></td>
			</tr>
			<tr>
				<td class="td1">当日已发送短信数量:</td>
				<td class="td2" style="height:40px;"><input style="width:260px;background-color:#e1e1e1;" type="text" name="smstotalsended" value="{$smstotalsended}" readonly /></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='departments_users.php?{$subpageurlparams}'" /></td>
			</tr>
			</table>
			</form>
		</div>
	</div>
EOT;
?>

</body>
</html>
