<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<1010>")) {	//没有权限
		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 myload()
{
<?php
 	 $timestr=strftime("%Y-%m-%d %H:%M:%S");
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	$loginname=trim($_REQUEST["loginname"]);
	$bandwidth=trim($_REQUEST["bandwidth"]);
	if ($loginname!="" && $bandwidth!="") {
		$rs = mysql_query( "select bandwidth from userband where loginname='".$loginname."'",$db );
		if ( ($row = mysql_fetch_array($rs))==FALSE ) {
			mysql_free_result($rs);
			mysql_query( "insert into userband values('".$loginname."',".$bandwidth.",0)",$db );
			mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','添加用户上网带宽。用户ID：".$loginname."，带宽：".$bandwidth."')",$db );
			echo("alert('添加成功！');");
		}
		else {
			mysql_free_result($rs);
			echo("alert('此用户已经设置其带宽！如需要修改，先删除，再添加！');");
		}
	}
	else {
		$allcount=trim($_REQUEST["allcount"]);
		if ($allcount!="") {
			if (intval($allcount)>0) {
				$bDelete=FALSE;
				$count=intval($allcount);
				$myname="";
				for($n=1;$n<=$count;$n++) {
					$loginname=trim($_REQUEST["var".strval($n)]);
					if ($loginname!="") {
						mysql_query("delete from userband where loginname='".$loginname."'",$db);
						$bDelete=TRUE;
						if ($myname!="") {
							$myname=$myname.",".$loginname;
						}
						else {
							$myname=$loginname;
						}
					}
				}
				if ($bDelete) {
					mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','删除用户上网带宽。用户ID：".$myname."')",$db );
					echo("alert('删除成功！');");
				}
			}
		}
	}
?>
}
</SCRIPT>

</head>

<body background="bkg.bmp" onload="javascript:myload();">

<p align="center"><font size="5"><b>用户上网带宽管理</b></font></p>
<hr color="#999966">


<form name="form1" method="POST" action="userband.php">
    <p align="center">用户带宽列表<br>
    <div align="center">
      <center>
    <table border="1" cellpadding="0" cellspacing="0" bordercolor="#008080" width="486">
	<tr><td width="346">
        <p align="center">用户ID</p>
      </td><td width="178">
        <p align="center">上网带宽</p>
      </td><td width="169">
        <p align="center">删除选择</p>
      </td>
<?php
		$bandname[1]="64K";
		$bandname[2]="128K";
		$bandname[3]="256K";
		$bandname[4]="512K";
		$bandname[5]="1M";
		$bandname[6]="2M";
		$bandname[7]="4M";
		$bandname[8]="8M";
		$bandname[9]="16M";
		$bandname[10]="32M";
		$bandname[11]="64M";
		$n=1;
		$rs = mysql_query("select loginname,bandwidth from userband where loginname not like 'gp_%' order by loginname",$db);
		while ($row = mysql_fetch_array($rs)) {
			echo("<tr>");
			echo("<td align=center>".$row["loginname"]."</td>");
			echo("<td align=center>".$bandname[$row["bandwidth"]]."</td>");
			echo("<td align=center><input type=checkbox name=var".strval($n)." value=".$row["loginname"]."></td>");
			echo("</tr>");
			$n=$n+1;
		}
		mysql_free_result($rs);
		if ($n>1) {
			echo("<tr><td colspan=3 align=right><input type=submit value=删除 name=B1></td><tr>");
		}
		mysql_close($db);
?>
    </table>
      </center>
    </div>
  <p align="center">　</p>
  <input type=hidden name=allcount value=<?php echo strval($n-1); ?>>
</form>
<p></p>
<form name="form2" method="POST" action="userband.php">
  <div align="center">
    <center>
    <table border="1" cellpadding="0" cellspacing="0" bordercolor="#008080" width="486" height="102">
      <tr>
        <td width="418" height="58">
          <p align="center">用户ID<input type="text" name="loginname" size="20"></p>
        </td>
        <td width="284" height="58"> 
  <p align="center">上网带宽<select size="1" name="bandwidth">
    <option selected value="1">64K</option>
    <option value="2">128K</option>
    <option value="3">256K</option>
    <option value="4">512K</option>
    <option value="5">1M</option>
    <option value="6">2M</option>
    <option value="7">4M</option>
    <option value="8">8M</option>
    <option value="9">16M</option>
    <option value="10">32M</option>
    <option value="11">64M</option>
  </select></p>
      </td>
      </tr>
        <td colspan=2 align="center" width="813" height="40"><input type="submit" value="添加" name="B1"></td>
    </table>
    </center>
  </div>
</form>

<ol>
  <li>
    <p align="left" style="line-height: 150%">上网带宽，不区分上行、下行，是上下行的总带宽，单位是bit/s(bps)，和常规意义上的网络带宽单位相同。</li>
  <li>
    <p align="left" style="line-height: 150%">实际上网时，每个用户的带宽，可管理的最小范围是64K(bps)。</li>
  <li>
    <p align="left" style="line-height: 150%">如果为一个用户单独设置了带宽，而且这个用户属于一个组别，而且这个组别也设置了带宽管理数值。这种情况下，<b>实际上网时，都使用该用户自己的设定带宽值，不再受其所属组别的带宽限制。</b></li>
</ol>



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


</body>

</html>
