<?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=6;              //ID
		  }
          else {
             $loginname=$row["loginname"];
             mysql_free_result($rs);
             if ($viptype!="" && $givelength!="" && $discount!="") {
                $rs = mysql_query("select userid from vipuser where userid='".$userid."'",$db);
		        if ($row = mysql_fetch_array($rs)) {
                   mysql_free_result($rs);
                   $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);
                   }
                   mysql_query( "update vipuser set viptype='".$viptype."',givelength=".$givelength.",discount=".$discount." where userid='".$userid."'",$db );
		           mysql_query( "insert into operation values('".$_SESSION["operator"]."','".$timestr."','修改用户优惠等级信息，用户ID：".$userid."')",$db );
                   $info=2;                         //修改成功
				}
                else {
                   mysql_free_result($rs);
                   $info=3;                          //用户优惠等级不存在
                }
			 }
             else {
                $info=4;                             //修改所需信息不全
             }
          }
          mysql_close($db);
	   }
       else {
          $info=5;                                   //用户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>
<script language="jscript">
function setresult()
{
        parent.vip1.location.href="vipquery1.php";
}
</script>
</head>

<body background="bkg.bmp" style="background-attachment: fixed; background-position-y:100;" onload="setresult();">

<p align="center"><font size="3"><b>用户优惠等级修改响应</b></font></p>
<div align="center">  
<center>
<?php  
    if ($info!=1) {
       switch ($info) {
       case 2:
             echo("用户：".$loginname."，优惠等级信息修改成功");
			 break;
       case 3:
             echo("用户：".$loginname."优惠等级不存在，修改失败");
			 break;
       case 5:
             echo("请输入用户ID,添加失败");
			 break;
       case 6:
             echo("无效的用户ID,添加失败");
			 break;
       case 4:
             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>

</body>

</html>

