<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<0007>")) {	//没有权限
		ob_clean();
		header("Location: accesserror.html");
		exit;
	}
?>


<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>开通用户响应</title>

<script language="javascript">
function printuser()
{
	myid1.background="";
	document.all.myid2.style.display="none";
	document.all.myid3.style.display="none";
	document.all.myid4.style.display="none";
	document.all.myid5.style.display="none";
	document.all.myid6.style.display="none";
	document.all.myid7.style.display="none";
	document.all.myid8.style.display="none";
	print();
}
</script>

</head>

<body id="myid1" background="bkg.bmp">

<p id="myid2" align="center"><font size="5"><b>开通用户响应</b></font></p>
<hr id="myid3" color="#999966">


<?php
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$loginname=trim($_REQUEST["loginname"]);
	$usertype=trim($_REQUEST["usertype"]);
	$onlines=trim($_REQUEST["onlines"]);
	$prepay=trim($_REQUEST["prepay"]);
	if (loginname!="" && usertype!="") {						//必须输入用户ID和类型
		$n=intval($onlines);
		$m=intval($prepay);
		$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
		mysql_select_db(get_cfg_var("SIPDB"),$db);
		$rs = mysql_query("select loginname from users where loginname='".$loginname."' and checked='n'",$db);		//检查是否已有该用户ID
		if (($row = mysql_fetch_array($rs))==FALSE) {										//没有找到，还没有开通该用户
			$password="";
			for ($i=1;$i<=10;$i++) {				//生成10位随机密码字符串，密码全部是数字
				$password=$password.chr(rand(48,57));
			}
			$userid=$loginname."-".strval(time()-strtotime("2005-01-01 01:01:01"));		//生成一个内部用户唯一编号
			if (strlen($userid)>20) {		//长度大于20，只使用登录名称，以便和电脑名称兼容
				$userid=$loginname;
			}
			$cookiemask="";
			for ($i=1;$i<=20;$i++) {						//生成20位随机密码字符串，密码全部是大写字符
				$cookiemask=$cookiemask.chr(rand(65,90));
			}
			mysql_query( "insert into users(userid,loginname,password,type,onlines,addtime,checked,cookiemask,suspendtime,prepay) values('".$userid."','".$loginname."','".$password."','".$usertype."',".$onlines.",'".$timestr."','n','".$cookiemask."','',".$prepay.")",$db );
			mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','开通上网用户，用户ID：".$userid."')",$db );
			if ($m>0) {
				mysql_query( "insert into cash values('".$userid."','".$timestr."',".$prepay.",'1','".$_SESSION["operator"]."')",$db );
			}
			echo("<p id=myid4 align=center>用户开通成功!<br><br>以下内容请用户记住！<br></p>");
			
			echo("<div align='center'>");
			echo("  <center>");
			echo("  <table border='1' width='358' bordercolor='#008080' cellspacing='0' cellpadding='0'>");
			echo("    <tr>");
			echo("      <td width='151' height='33'>上网用户ID</td>");
			echo("      <td width='191' height='33' align='center'><font size='5'>".$loginname."</font></td>");
			echo("    </tr>");
			echo("    <tr>");
			echo("      <td width='151' height='34'>上网用户密码</td>");
			echo("      <td width='191' height='34' align='center'><font size='5'>".$password."</font></td>");
			echo("    </tr>");
			echo("  </table>");
			echo("  </center>");
			echo("</div>");
			echo("<p></p>");
			echo("<form id=myid5>");
			echo("  <p align=center><input type=button value=打印 onclick='javascript:printuser();'></p>");
			echo("</form>");

			
		} else {
			echo("<p align=center>错误，该用户已经开通！</p>");
		}
		mysql_free_result($rs);
		mysql_close($db);
	} else {
		echo("<p align=center>必须输入用户ID和类型！</p>");
	}
?>


<hr id="myid6">
<p id="myid7" align="center">SIP酒店上网计费管理系统</p>
<p id="myid8" align="center">作者：<b>深圳市飞沃软件有限公司</b></p>


</body>

</html>
