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

<?php
	   $timestr=strftime("%Y-%m-%d %H:%M:%S");
       $userid=$_REQUEST["userid"];
       $usertype=$_REQUEST["usertype"];
       $viptype=trim($_REQUEST["viptype"]);
       $givelength=trim($_REQUEST["givelength"]);
       $discount=trim($_REQUEST["discount"]);
       if ($givelength=="") {
          $givelength="0";
       }
       if ($discount=="") {
          $discount="100";
       }
       $info=1;
       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 from users where userid='".$userid."'",$db);
          if ( ($row = mysql_fetch_array($rs))==FALSE ) {
             mysql_free_result($rs);
             $info=5;     //无效ID
		  }
          else {
             $loginname=$row["loginname"];
             mysql_free_result($rs);
             if ($viptype!="" && $givelength!="" && $discount!="") {
                $rs = mysql_query("select viptype from vips where viptype='".$viptype."'",$db);
		        if ( ($row = mysql_fetch_array($rs))==FALSE ) {
                   mysql_free_result($rs);
                   mysql_query( "insert into vips values('".$viptype."',".$givelength.",".$discount.")",$db );
                   mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','添加优惠等级，等级名称：".$viptype."')",$db );
				}
                else {
                   mysql_free_result($rs);
                }
                $rs = mysql_query("select userid from vipuser where userid='".$userid."'",$db);
	            if ( ($row = mysql_fetch_array($rs))==FALSE ) {
                   mysql_free_result($rs);
                   mysql_query( "insert into vipuser values('".$userid."','".$viptype."',".$givelength.",".$discount.")",$db );
                   mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','添加用户优惠等级信息，用户ID：".$userid."')",$db );
                   $info=2;       //添加成功
				}
                else {
                   mysql_free_result($rs);
                   $info=3;       //该用户已经拥有优惠等级
                }
			 }
             else {
                $info=6;          //添加优惠等级所需的信息不全
             }
          }
          mysql_close($db);
	   }
       else {
          $n=4;                //用户ID为空
       }
?>
<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">
<title>用户优惠等级添加响应</title>
</head>

<body background="bkg.bmp">

<p align="center"><font size="5"><b>用户优惠等级添加响应</b></font></p>
<hr color="#999966">
<div align="center">  
<center>
<?php  
    if ($info!=1) {
       switch ($info) {
       case 2:
             echo("用户：".$loginname."，等级信息添加成功");
			 break;
       case 3:
             echo("用户：".$loginname."已经存在等级信息，添加失败");
			 break;
       case 4:
             echo("请输入用户ID,添加失败");
			 break;
       case 5:
             echo("无效的用户ID,添加失败");
			 break;
       case 6:
             echo("请输入完整的优惠等级信息,添加失败");
			 break;
       }
    }
?>
<?php if ($info==2) { ?>
<table border="1" width="400" bordercolor="#008080" cellspacing="0" cellpadding="0">
<tr>
   <td width="30%" align="center">用户ID</td>
   <td width="70%" align="center"><?php echo $loginname; ?></td>
</tr>
<tr>
   <td width="30%" align="center">用户类型</td>
   <td width="70%" align="center"><?php echo $usertype; ?></td>
</tr>
<tr>
   <td width="30%" align="center">优惠等级</td>
   <td width="70%" align="center"><?php echo $viptype; ?></td>
</tr>
<tr>
      <td width="30%" align="center">赠送</td>
      <td width="70%" align="center"><?php echo $givelength; ?></td>
</tr>
<tr>
   <td width="30%" align="center">折扣</td>
   <td width="70%" align="center"><?php echo $discount; ?>%</td>
</tr>
</table>
<table border=0 align=center><tr><td align=left>
<p><font size='2'><b>1.</b>“包年”类型赠送数量是以月为单位；<br><b>2.</b>“计流量(G)”类型赠送数量是以M为单位；<br><b>3.</b>其它类型赠送数量的单位和该类型续费数量单位相同；<br><b>4.</b>先使用后付款用户无赠送信息</font></p>
</td></tr></table>
<?php } ?>
</center>
</div>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>

