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

<?php
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	$userid="";
	$password="";
	$username="";
	$onlines="";
	$usertel="";
	$comment="";
	$ipaddr="";
	$mac="";
	$band=0;
	$errno=1;
	$loginname=trim($_REQUEST["loginname"]);
	if ($loginname!="") {
		$rs = mysql_query("select userid,password,onlines,username,usertel,comment,gpid,ipaddr,mac from users where checked='n' and loginname='".$loginname."'",$db);
		if ($row = mysql_fetch_array($rs)) {
			$userid=$row["userid"];
			$password=$row["password"];
			$username=$row["username"];
			$usertel=$row["usertel"];
			$comment=$row["comment"];
			$onlines=strval($row["onlines"]);
			$gpid=$row["gpid"];
			$ipaddr=$row["ipaddr"];
			$mac=$row["mac"];
			$rs1 = mysql_query( "select bandwidth from userband where loginname='".$loginname."'",$db );
			if ($row1 = mysql_fetch_array($rs1)) {
				$band=$row1["bandwidth"];
			}
			mysql_free_result($rs1);
		}
	    else {
	      $errno=3;
		}
		mysql_free_result($rs);
	}
    else {
        $errno=2;
	}
?>

<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 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT LANGUAGE="javascript">
function setup()
{
<?php if ($errno==1) { ?>
    var gpid=document.FrontPage_Form1.oldgpid.value;
    var i=0;
    if (document.FrontPage_Form1.gp_name.options.length>0) {
	    for (i=0;i<document.FrontPage_Form1.gp_name.options.length;i++)
	    {
      		if (document.FrontPage_Form1.gp_name.options(i).value==gpid)
	         {
        		  document.FrontPage_Form1.gp_name.options(i).selected=true;
			  document.FrontPage_Form1.gpname.value=document.FrontPage_Form1.gp_name.options(i).text;
		          break;
	         }
          
	    }
    }
<?php } ?>
}

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

function checkdata()
{
    cancelBubble=true;
    if (document.FrontPage_Form1.loginname.value!="")
       {
        if (document.FrontPage_Form1.password.value!="")
           {
            if (document.FrontPage_Form1.onlines.value!="")
               {
                document.FrontPage_Form1.onlines.value=document.FrontPage_Form1.onlines.value.replace(/\s{1,}/g,"");
                if (document.FrontPage_Form1.onlines.value.match(/\D{1,}/)!=null)
                    alert("同时允许在线人数只能为大于等于1的整数");
                else
                    document.FrontPage_Form1.submit();
               }
            else
                alert("同时允许在线人数不能为空");
           }
        else
            alert("密码不能为空");
       }
    else
        alert("用户ID不能为空");
}
</SCRIPT>


<title>用户属性修改</title>
</head>

<body background="bkg.bmp" onload="setup();">

<p align="center"><font size="5"><b>用户属性修改</b></font></p>
<hr color="#999966">
<div align="center">
<center>
<?php if ($errno==1) { ?>
<form name="FrontPage_Form1" method="POST" action="updateuser_result.php" language="JavaScript">
<input type="hidden" name="userid" value="<?php echo $userid; ?>">
<table border="1" width="584" bordercolor="#008080" cellspacing="0" cellpadding="0">
    <tr>
      <td width="173" align="center" height="50">用户ID</td>
      <td width="397" align="left" height="50">
         <input type="text" name="loginname" size="20" value="<?php echo $loginname; ?>">
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">用户密码</td>
      <td width="397" align="left" height="50">
         <input type="text" name="password" size="20" value="<?php echo $password; ?>">
      </td>	
    </tr> 
    <tr>
      <td width="173" align="center" height="50">用户组别</td>
      <td width="397" align="left" height="50"><input type="text" name="gpname" size="8" value="" maxlength="50">&nbsp;&nbsp;
          <select size="1" name="gp_name" onclick="InputGP();">  
<?php
        $rs1 = mysql_query("select gpid,gpname from groups order by gpid",$db);
        while ($row1 = mysql_fetch_array($rs1)) {
	        echo("<option value=".chr(34).strval($row1["gpid"]).chr(34).">".$row1["gpname"]."</option>");
        }
		mysql_free_result($rs1);
?>
          </select>
          <input type="hidden" name="oldgpid" size="8" value="<?php echo strval($gpid); ?>">
         <br><font size="2">新用户组请直接输入,为空为表示该用户不属于任何组别。<br>已有的用户组请从右边的下拉菜单中选择。<font>
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">用户名称</td>
      <td width="397" align="left" height="50">
		  <input type="text" name="username" size="20" maxlength="50" value="<?php echo $username; ?>">
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">联系方式</td>
      <td width="397" align="left" height="50">
	      <input type="text" name="usertel" size="20" maxlength="50" value="<?php echo $usertel; ?>">
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">备注说明</td>
      <td width="397" align="left" height="50">
          <input type="text" name="comment" size="40" maxlength="100" value="<?php echo $comment; ?>">
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">使用IP地址</td>
      <td width="397" align="left" height="50">
          <input type="text" name="ipaddr" size="15" value="<?php echo $ipaddr; ?>"><br>不填则用户可以任意IP地址登录
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">使用MAC地址</td>
      <td width="397" align="left" height="50">
          <input type="text" name="mac" size="20" value="<?php echo $mac; ?>">(格式：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>
      <td width="173" align="center" height="50">允许同时在线人数</td>
      <td width="397" align="left" height="50">
          <input type="text" name="onlines" size="3" value="<?php echo $onlines; ?>">
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">最大带宽</td>
      <td width="397" align="left" height="50">
          <select size="1" name="band">
		  <?php
			$bandname[1]="无限制";
			$bandname[2]="64K";
			$bandname[3]="128K";
			$bandname[4]="256K";
			$bandname[5]="512K";
			$bandname[6]="1M";
			$bandname[7]="2M";
			$bandname[8]="4M";
			$bandname[9]="8M";
			$bandname[10]="16M";
			$bandname[11]="32M";
			$bandname[12]="64M";
            for ($n=0;$n<=11;$n++) {
				if ($band==$n) {
					echo("<option selected value=".chr(34).strval($n).chr(34).">".$bandname[$n+1]."</option>");
				}
				else {
					echo("<option value=".chr(34).strval($n).chr(34).">".$bandname[$n+1]."</option>");
				}
            }
		  ?>
          </select>
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">用户上网范围控制</td>
      <td width="397" align="center" height="50">
          <a href=useracl1.php?userid=<?php echo $userid; ?> target=_blank>上网范围</a>
      </td>
    </tr>
    <tr>
      <td width="173" align="center" height="50">用户每天允许上网时间</td>
      <td width="397" align="center" height="50">
          <a href=userallowtime1.php?userid=<?php echo $userid; ?> target=_blank>允许时间</a>
      </td>
    </tr>
    <tr>
      <td colspan="2" width="524" align="center" height="51"><input type="button" value="提交" name="B1" onclick="checkdata();"></td>
    </tr>
</table>
</form>
<?php } elseif ($errno==2) {?>
<p>必须输入用户ID</p>
<?php } elseif ($errno==3) {?>
<p>无效ID</p>
<?php } ?>
</center>
</div>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>
</body>
</html>
<?php
mysql_close($db);
?>
