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

<?php
	$defaultid="U".strval(time()-strtotime("2005-01-01 01:01:01"));
	$defaultword="";
	for ($i=1;$i<=10;$i++) {				//生成10位随机密码字符串，密码全部是数字
		$defaultword=$defaultword.chr(rand(48,57));
	}
	$buylength="0";
	$otherlength="0";
	$money1="0";
	$money2="0";
?>
<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">
<script language="javascript">
var typeid=new Array();
var usertype=new Array();
var price=new Array();
var typemode=new Array();
var unit=new Array();
<?php
	$n=0;
	$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 * from types",$db);
	if ($row = mysql_fetch_array($rs)) {
       while ( !($row==FALSE) ) {
	       echo("typeid[".strval($n)."]='".$row["typeid"]."';\r\n");
	       echo("usertype[".strval($n)."]='".$row["name"]."';\r\n");
		   $str=strval(round($row["price"],2));
	       echo("price[".strval($n)."]='".$str."';\r\n");
	       echo("typemode[".strval($n)."]='".$row["typemode"]."';\r\n");
	       echo("unit[".strval($n)."]='".strval($row["unit"])."';\r\n");
		   $n=$n+1;
	       $row = mysql_fetch_array($rs);
       }
	}
    echo("var typecount=".strval($n).";\r\n");
	mysql_free_result($rs);
?>

function InputGP()
{
    cancelBubble=true;
    var n=document.form1.gp_name.selectedIndex;
    if (n>=0) {
	    document.form1.gpname.value=document.form1.gp_name.options(n).text;
    }
}

function setmoney1()
{
    cancelBubble=true;
	var str=document.form1.usertype.options(document.form1.usertype.selectedIndex).text.toString();
    var n1=str.search(/单价/);
    var n2=str.search(/元/);
    var price=parseFloat(str.substring(n1+2,n2));
    var buylength=document.form1.buylength.value;
    var money1=Math.round(price*parseInt(buylength,"10")*10)/10;
	document.all.money12.innerText=" "+money1.toString()+"元";
	document.form1.money1.value=money1.toString();
	setmoney2();
}

function setmoney2()
{
    cancelBubble=true;
	var money2=Math.round(parseInt(document.form1.discount.value,"10")*parseFloat(document.form1.money1.value)/10)/10;
	document.all.money22.innerText=" "+money2.toString()+"元";
	document.form1.money2.value=money2.toString();
}
function checktype(obj)
{
    cancelBubble=true;
	var i=0;
	for (i=0;i<typecount;i++) {
		if (typeid[i]==obj.value) break;
	}
	if (i>=typecount) return;
    if (typemode[i]!="1")
    {
        document.all.buy.style.display="none";
        document.form1.buylength.value="0";
        document.all.present.style.display="none";
        document.form1.otherlength.value="0";
        document.all.money11.style.display="none";
        document.all.money12.innerText=" 0元";
        document.form1.money1.value="0";
        document.all.discount1.style.display="none";
        document.form1.discount.value="100";
        document.all.money21.style.display="none";
        document.all.money22.innerText=" 0元";
        document.form1.money2.value="0";
		document.form1.money3.value="0";
		if (typemode[i]=="2") {
			document.all.deposit.style.display="";
		}
		else {
	        document.all.deposit.style.display="none";
		}
    }
    else
    {
        document.all.buy.style.display="";
        document.all.present.style.display="";
        document.all.money11.style.display="";
        document.all.discount1.style.display="";
        document.all.money21.style.display="";
        document.all.deposit.style.display="none";
		document.form1.money3.value="0";
        setmoney1();
    }
}

function IsInt(obj)
{   
    var str=obj.value;
    var tmpstr=parseInt(str,"10");
    if (tmpstr!=str)
        return(false);
    else
    {
        obj.value=tmpstr;
        return(true);
    }
}

function checkData()
{
     var loginname=document.form1.loginname.value;
     if (loginname==""||loginname.length>20)
     {
         alert("用户ID不能为空，长度也不能大于20个字符(1个汉字占2个字符)！");
         document.form1.loginname.focus();
         document.form1.loginname.select();
     } 
     else
     {
         obj=document.form1.onlines;
         cansub=IsInt(obj);
         if (cansub&&obj.value>=1)
         {
             obj=document.form1.buylength;
             cansub=IsInt(obj);
             if (cansub&&obj.value>=0)
             {
                 obj=document.form1.otherlength;
                 cansub=IsInt(obj);
                 if (cansub&&obj.value>=0)
                 {
                     obj=document.form1.discount;
                     cansub=IsInt(obj);
                     if (cansub&&obj.value>0)
					 {
						 obj=document.form1.money3;
						 cansub=IsInt(obj);
						 if (cansub&&obj.value>=0)
							 document.form1.submit();
						 else
						 { 
							 alert("预付押金只能是整数且大于等于0");
							 document.form1.money3.focus();
							 document.form1.money3.select();
						 }
					 }
                     else
                     { 
                         alert("折扣只能是整数且大于0");
                         document.form1.discount.focus();
                         document.form1.discount.select();
                     }
                 }
                 else
                 { 
                     alert("赠送数量只能是整数且大于等于0");
                     document.form1.otherlength.focus();
                     document.form1.otherlength.select();
                 } 
             }
             else
             {
                 alert("购买数量只能是整数且大于等于0");
                 document.form1.buylength.focus();
                 document.form1.buylength.select();
             } 
         }
         else
         {
             alert("允许同时在线人数只能是整数且大于等于1");
             document.form1.onlines.focus();
             document.form1.onlines.select();
         } 
     }
}
</script>

<title>注册用户</title>
</head>

<body background="bkg.bmp" onload="checktype(document.form1.usertype);">

<p align="center"><font size="5"><b>注册用户</b></font></p>
<hr color="#999966">
<div align="center">
<center>
<form method="POST" name="form1" action="adduser_result.php">
<table border="1" width="626" bordercolor="#008080" cellspacing="0" cellpadding="0">
<tr>
   <td width="173" align="center" height="46">用户ID</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <input type="text" name="loginname" size="20" maxlength="20" value="<?php echo $defaultid; ?>">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户密码</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp; <input type="text" name="password" size="20" value="<?php echo $defaultword; ?>">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户类型</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <select size="1" name="usertype" onclick="checktype(this);">
<?php
		$rs = mysql_query("select typeid,name,price from types order by typeid",$db);		//读取结帐类型列表
		if ($row = mysql_fetch_array($rs)) {
           echo("<option selected value=".chr(34).$row["typeid"].chr(34).">".$row["name"]."，单价".strval($row["price"])."元</option>");	//缺省选择第一项
           while ( $row = mysql_fetch_array($rs) ) {
	           echo("<option value=".chr(34).$row["typeid"].chr(34).">".$row["name"]."，单价".strval($row["price"])."元</option>");
           }
		}
		mysql_free_result($rs);
?>
       </select> 
   </td>
</tr>
<tr>
   <td width="173" align="center" height="56">用户组别</td>
   <td width="439" align="left" height="56">&nbsp;&nbsp;
	   <input type="text" name="gpname" size="8" value="" maxlength="50">&nbsp;&nbsp;
	   <select size="1" name="gp_name" onclick="InputGP();">
<?php
        $rs = mysql_query("select gpname from groups order by gpname");
       while ($row = mysql_fetch_array($rs)) {
	       echo("<option value=".chr(34).$row["gpname"].chr(34).">".$row["gpname"]."</option>");
       }
		mysql_free_result($rs);
		mysql_close($db);
?>
       </select>
       <br><font size="2">&nbsp; &nbsp;新用户组请直接输入,为空为无组别<br>&nbsp;&nbsp; 已有的用户组请从右边的下拉菜单中选择</font>
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">允许同时在线人数</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <input type="text" name="onlines" size="3" value="1">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">用户名称</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <input type="text" name="username" size="20" maxlength="50">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">联系方式</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="usertel" size="20" maxlength="50"> </td>
</tr>
<tr>
   <td width="173" align="center" height="46">备注说明</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="comment" size="20" maxlength="100">
   </td>
</tr>
<tr>
   <td width="173" align="center" height="46">使用IP地址</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="ipaddr" size="15"><br>&nbsp;&nbsp; 设置该IP后，用户只能使用具有该IP的客户机登录上网。不填则用户可以使用任意IP地址的客户机登录。
   </td>
</tr>
<tr>
   <td width="173" align="center" height="58">使用MAC地址</td>
   <td width="488" align="left" height="58">&nbsp;&nbsp; 
       <input type="text" name="mac" size="20">(格式：xx-xx-xx-xx-xx-xx)<br>&nbsp;&nbsp; 
    设置该MAC后，用户只能使用具有该MAC地址的客户机登录上网。不填则用户可以使用任意MAC地址的客户机登录。MAC地址格式必须为：xx-xx-xx-xx-xx-xx，否则客户机不能上网。例如，12-4f-6a-08-2d-e0为有效MAC地址，12-4f-6a-8-2d-e0则为无效MAC地址。
   </td>
</tr>
<tr id="buy">
   <td width="173" align="center" height="46">购买数量</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	<input type="text" name="buylength" size="8" value="<?php echo $buylength; ?>" onkeyup="setmoney1();">
   </td>
</tr>
<tr id="present">
   <td width="173" align="center" height="46">赠送数量</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="otherlength" size="8" value="<?php echo $otherlength; ?>"><br>
				·“包年”类型赠送数量是以月为单位；<br>
				·“计流量(G)”类型赠送数量是以M为单位；<br>
				·其它类型赠送数量的单位和该类型购买数量的单位相同。 
   </td>
</tr>
<tr id="money11">
   <td width="173" align="center" height="46">合计费用</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <span id="money12"><?php echo $money1; ?>元</span>
       <input type="hidden" name="money1" value="0">
   </td>
</tr>
<tr id="discount1">
   <td width="173" align="center" height="46">优惠折扣率</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
       <input type="text" name="discount" size="3" value="100" onkeyup="setmoney2();">%
   </td>
</tr>
<tr id="money21">
   <td width="173" align="center" height="46">实收费用</td>
   <td width="439" align="left" height="46">&nbsp;&nbsp;
	   <span id="money22"><?php echo $money2; ?>元</span>
	   <input type="hidden" name="money2" value="0">
   </td>
</tr>
<tr id="deposit">
   <td width="173" align="center" height="44">预付押金(元)</td>
   <td width="488" align="left" height="44">&nbsp;&nbsp; 
	   <input type="text" name="money3" value="0"> 
   </td>
</tr>
<tr>
   <td colspan="2" width="566" align="center" height="57">
       <input type="button" value="提交" name="B1" onclick="checkData();">
   </td>
</tr>
</table>
</form>
</center>
</div>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
