<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>
</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
    $bOk=FALSE;
	$timestr=strftime("%Y-%m-%d %H:%M:%S");
	$loginname=trim($_REQUEST["loginname"]);
	$password=trim($_REQUEST["password"]);
	$usertype=trim($_REQUEST["usertype"]);
	$buylength=trim($_REQUEST["buylength"]);
	$money=trim($_REQUEST["money1"]);
	$onlines="1";
	$username=trim($_REQUEST["username"]);
	$usertel=trim($_REQUEST["usertel"]);
	$comment=trim($_REQUEST["comment"]);
	$ipaddr=$_SERVER["REMOTE_ADDR"];
	if ($loginname!="" && $usertype!="") {						//必须输入用户ID和类型
		$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."'",$db);		//检查是否已有该用户ID
		if ( ($row = mysql_fetch_array($rs))==FALSE ) {    //没有找到，还没有开通该用户
			mysql_free_result($rs);
			$rs = mysql_query("select loginname from tmpusers where loginname='".$loginname."'",$db);		//检查是否已有该用户ID
			if ( ($row = mysql_fetch_array($rs))==FALSE ) {    //没有找到，还没有开通该用户
				mysql_free_result($rs);
				$gpid="0";                                        //初始化组别号
				$rs=mysql_query( "select name,price from types where typeid='".$usertype."'",$db );
				$row = mysql_fetch_array($rs);
				$usertypename=$row["name"];
				$price=strval($row["price"]);
				mysql_free_result($rs);
				$userid=$loginname."-".strval(time()-strtotime("2005-01-01 01:01:01"));		//生成一个内部用户唯一编号
				if (strlen($userid)>20) {		//长度大于20，只使用登录名称，以便和电脑名称兼容
					$userid=$loginname;
				}
				$createtime=$timestr;
				$cookiemask="";
				for ($i=1;$i<=20;$i++) {						//生成20位随机密码字符串，密码全部是大写字符
					$cookiemask=$cookiemask.chr(rand(65,90));
				}
				mysql_query( "insert into tmpusers values('".$userid."','".$loginname."','".$password."','".$usertype."',".$onlines.",'".$createtime."','".$username."','".$usertel."','".$comment."',".$gpid.",'".$cookiemask."','".$ipaddr."',".$buylength.",".$price.",".$money.")",$db );
				echo("<p id=myid4 align=center>用户注册成功!</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("    <tr>");
				echo("      <td width='151' height='34'>用户类型</td>");
				echo("      <td width='191' height='34' align='center'><font size='5'>".$usertypename."</font></td>");
				echo("    </tr>");
				echo("    <tr>");
				echo("      <td width='151' height='34'>单价</td>");
				echo("      <td width='191' height='34' align='center'><font size='5'>".$price."元</font></td>");
				echo("    </tr>");
				echo("    <tr>");
				echo("      <td width='151' height='34'>购买数量</td>");
				echo("      <td width='191' height='34' align='center'><font size='5'>".$buylength."</font></td>");
				echo("    </tr>");
				echo("    <tr>");
				echo("      <td width='151' height='34'>合计费用</td>");
				echo("      <td width='191' height='34' align='center'><font size='5'>".$money."元</font></td>");
				echo("    </tr>");
				echo("  </table>");
				echo("  </center>");
				echo("</div>");
				echo("<p></p>");
				$bOk=TRUE;
			}
			else {
				mysql_free_result($rs);
				echo("<p align=center>错误，该用户ID已经存在！</p>");
			}
		}
		else {
			mysql_free_result($rs);
			echo("<p align=center>错误，该用户ID已经存在！</p>");
		}
		mysql_close($db);
	}
	else {
		echo("<p align=center>必须输入用户ID和类型</p>");
	}
?>

<?php
if ($bOk) {
?>
<p align="center">请在7天内交付费用，过期不付费，将自动删除注册帐号！</p>
<?php
}
?>

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

</body>

</html>
