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

<?php
	$loginname="";
	$password="";
	$username="";
	$onlines="";
	$usertel="";
	$comment="";
	$ipaddr="";
	$mac="";
	$createtime="";
	$usertype="";
	$lasttime="";
	$lastlength="";
	$vipstr="&nbsp;";
	$allcount=0;
	$alltime=0;
	$alllength=0;
	$allmoney=0;
	$band="无限制";
	$suspendtime="";
	$userid=trim($_REQUEST["userid"]);
	if ($userid!="") {
		$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,password,type,onlines,username,usertel,comment,createtime,gpid,ipaddr,suspendtime,mac from users where userid='".$userid."'",$db );
		if ($row = mysql_fetch_array($rs)) {
			$loginname=$row[0];
			$password=$row[1];
			$username=$row[4];
			$usertel=$row[5];
			$comment=$row[6];
			$onlines=strval($row[3]);
			$createtime=$row[7];
			$usertype=$row[2];
			$gpid=$row[8];
			$gpname="";
			$ipaddr=$row[9];
			$suspendtime=$row[10];
			if (is_null($suspendtime)) {
				$suspendtime="";
			}
			$mac=$row[11];
			$rs1=mysql_query("select gpname from groups where gpid=".strval($gpid),$db);
			if ($row1 = mysql_fetch_array($rs1)) {
		       $gpname=$row1["gpname"];
		    }
			mysql_free_result($rs1);
		}
		mysql_free_result($rs);
		if ($usertype!="") {
			$rs = mysql_query( "select name,typemode,unit from types where typeid='".$usertype."'",$db );
			$row = mysql_fetch_array($rs);
			$type_name=$row["name"];
			$typemode=$row["typemode"];
			$typeunit=$row["unit"];
			mysql_free_result($rs);
		}
        $rs = mysql_query( "select viptype,givelength,discount from vipuser where userid='".$userid."'",$db );
		if ($row = mysql_fetch_array($rs)) {
	        $viptype=strval($row["viptype"]);
    	    $givelength=strval($row["givelength"]);
       		 $discount=strval($row["discount"]);
       		 $vipstr="用户优惠等级：".$viptype.",赠送数量：".$givelength.",折扣：".$discount."%.";
        }
        mysql_free_result($rs);
        $rs = mysql_query("select sum(money2) as allmoney from addtimelist where userid='".$userid."'",$db);
		if ($row = mysql_fetch_array($rs)) {
			$allmoney=$row["allmoney"];
		    if (is_null($allmoney)) $allmoney=0;
			$allmoney=round($allmoney,2);
        }
        mysql_free_result($rs);
		$rs = mysql_query( "select addtime,length,datalength,otherlength from addtimelist where userid='".$userid."' order by addtime",$db );
		if ($row = mysql_fetch_array($rs)) {
			$otherlength=0;
			while ($row) {
		       $lasttime=strval($row["addtime"]);
			   $lastlength=strval($row["length"]+$row["datalength"]);
			   if ($typeunit!=6 && $typeunit!=7) {				//不是流量类型
				  $lastlength=strval($row["length"]);	
			   }
			   else {
				  $lastlength=strval($row["datalength"]);		
			   }
			   $otherlength=$row["otherlength"];
			   $row = mysql_fetch_array($rs);
			}
			if ($otherlength>0) {
				$lastlength=$lastlength."(赠送".strval($otherlength).")";
			}
		}
		mysql_free_result($rs);
		$rs = mysql_query( "select count(ipaddr),sum(usetime),sum(datalength) from history where userid='".$userid."' and starttime>'".$lasttime."'",$db );	//读取该用户从上一次结帐后以来的上网记录
		//计算总共时间，总共流量。
		if ($row = mysql_fetch_array($rs)) {			//有记录
			$allcount=$row[0];
			$alltime=$row[1];
			$alllength=$row[2];
		    if (is_null($allcount)) $allcount=0;
		    if (is_null($alltime)) $alltime=0;
		    if (is_null($alllength)) $alllength=0;
		}
		mysql_free_result($rs);
		$tmpband=0;
		$rs = mysql_query( "select bandwidth from userband where loginname='".$loginname."'",$db );
		if ($row = mysql_fetch_array($rs)) {
			$tmpband=$row["bandwidth"];
		}
		mysql_free_result($rs);
		if ($tmpband>0) {
			$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";
			$band=$bandname[$tmpband];
		}
		$money3=0;
		if ($typemode=="2") {
		   $rs=mysql_query( "select sum(spare) from cash where userid='".$userid."'" ,$db);	//剩余押金
		   if ($row = mysql_fetch_array($rs)) {
			  $money3=$row[0];
			  if (is_null($money3)) {
				 $money3=0;
			  } else {
				 $money3=round($money3,2);
			  }
		   }
		   mysql_free_result($rs);
		}
		mysql_close($db);
	}
?>

<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>


<title>用户详细资料</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>用户详细资料</b></font></p>
<hr color="#999966">
<div align="center">
  <table border="1" width="584" bordercolor="#008080" cellspacing="0" cellpadding="0">
    <tr>
      <td width="249" align="center" height="50">用户ID</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $loginname; ?></p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户密码</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $password; ?></p>
        </td>
    </tr>
        <tr>
      <td width="249" align="center" height="50">用户组别</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $gpname; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户名称</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $username; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">联系方式</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $usertel; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">备注说明</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $comment; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">使用IP地址</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $ipaddr; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">使用MAC地址</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $mac; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户类型</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $type_name; ?></p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">注册时间</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $createtime; ?></p>
        </td>
    </tr>

    <tr>
      <td width="249" align="center" height="50">允许同时在线人数</td>
      <td width="642" align="left" height="50">
          <p align="center"><?php echo $onlines; ?></p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">上次购买（结帐）时间</td>
      <td width="407" align="left" height="50">
       <p align="center">&nbsp;<?php echo $lasttime; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">上次购买（结帐）数量</td>
      <td width="642" align="left" height="50">
      <p align="center"><?php echo $lastlength; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">上次购买（结帐）以来实际总上网次数</td>
      <td width="642" align="left" height="50">
        <p align="center"><?php echo $allcount; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">上次购买（结帐）以来实际总上网时间（秒）</td>
      <td width="642" align="left" height="50">
        <p align="center"><?php echo $alltime; ?>&nbsp;</p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">上次购买（结帐）以来实际总上网流量（K）</td>
      <td width="642" align="left" height="50">
        <p align="center"><?php echo $alllength; ?>&nbsp;</p>
        </td>
    </tr>
	<?php if ($typemode=="2") { ?>
    <tr>
      <td width="249" align="center" height="50">可用押金</td>
      <td width="642" align="center" height="50"><?php echo strval($money3); ?>元</td>
    </tr>
	<?php } ?>
    <tr>
      <td width="249" align="center" height="50">总计缴费</td>
      <td width="642" align="center" height="50">
      <p align="center"><?php echo $allmoney; ?>元&nbsp&nbsp
      <?php
      		if ($allmoney>=0.1) {
		      echo("<a href=queryadd2_result.php?userid=".$userid." target=_blank>(详细消费清单)</a>");
      		}
      ?>
      </p>
      </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">最大带宽</td>
      <td width="642" align="left" height="50">
      <p align="center"><?php echo $band; ?></p>
        </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">实际上网情况</td>
      <td width="642" align="center" height="50">
      <p align="center"><a href=queryhistory_result.php?userid=<?php echo $userid; ?> target=_blank>上网清单</a></p>
      </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户优惠信息</td>
      <td width="642" align="center" height="50">
      <p align="center"><?php echo $vipstr; ?></p>
      </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户上网范围控制</td>
      <td width="642" align="center" height="50">
      <p align="center"><a href=useracl1.php?userid=<?php echo $userid; ?> target=_blank>上网范围</a></p>
      </td>
    </tr>
    <tr>
      <td width="249" align="center" height="50">用户每天允许上网时间</td>
      <td width="642" align="center" height="50">
      <p align="center"><a href=userallowtime1.php?userid=<?php echo $userid; ?> target=_blank>允许时间</a></p>
      </td>
    </tr>
	<?php if ($suspendtime!="") { ?>
    <tr>
      <td width="249" align="center" height="50">用户处于欠费状态</td>
      <td width="642" align="center" height="50">设置欠费状态时间：<?php echo $suspendtime; ?></td>
    </tr>
	<?php } ?>
  </table>
</div>

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

</body>

</html>











