<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<2030>")) {	//没有权限
		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 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<SCRIPT language="JavaScript">

//检查输入的信息
function checkinfo()        
{
    var givelength=document.FrontPage_Form1.givelength.value;
    var discount=document.FrontPage_Form1.discount.value;
    var viptype=document.FrontPage_Form1.viptype.value;
    var cansubmit1=false;
    var cansubmit2=false;
    var cansubmit3=false;
    
        
    if (viptype!="")
        cansubmit3=true;
    else   
        alert("等级名称不能为空");
        
    if (givelength!="")
       {
        var tmpstr=parseInt(givelength,"10");
        if (tmpstr==NaN||tmpstr!=givelength)
            alert("赠送数量必须为整数");
        else
           {
            if (tmpstr>=0)
               {
                document.FrontPage_Form1.givelength.value=tmpstr;
                cansubmit1=true;
               }
            else
                alert("赠送数量应为大于等于0的整数");
            }
        }  
    else
        alert("赠送数量不能为空");
    
    if (discount!="")
       {     
        tmpstr=parseInt(discount,"10")
        if (tmpstr==NaN||tmpstr!=discount)
            alert("折扣必须为整数");
        else
           {
            if (tmpstr>0&&tmpstr<=100)
               {
                document.FrontPage_Form1.discount.value=tmpstr;
                cansubmit2=true;
               }
            else
                alert("折扣应为大于0小于等于100的整数");
           }
       }
    else
        alert("折扣不能为空");

    if (cansubmit1&&cansubmit2&&cansubmit3)
       document.FrontPage_Form1.submit();
}

function setresult()
{
    if (document.FrontPage_Form1.isadd.value=="y")
        parent.vip1.location.href="vipquery1.php";
}
</SCRIPT>
<title>添加优惠等级</title>
</head>

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

<p align="center"><font size="3"><b>添加优惠等级</b></font></p>
<center>
<?php
     $timestr=strftime("%Y-%m-%d %H:%M:%S");
	 $viptype=trim($_REQUEST["viptype"]);
     $givelength=trim($_REQUEST["givelength"]);
     $discount=trim($_REQUEST["discount"]);
     $ispostback=$_REQUEST["ispostback"];
     $isadd="n";
     if ($ispostback=="y") {                             //是否为回送
        if ($viptype!="" && $discount!="" && $givelength!="") {
           $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 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 );
              echo("<font size=2>成功添加</font>");
              $isadd="y";
		   }
           else {
              mysql_free_result($rs);
              echo("<font size=2>要添加的优惠等级已经存在</font>");
           }
           mysql_close($db);
		}
        else {
           echo("<font size=2>请填写完整的信息</font>");
        }
     }
?>
<form name=FrontPage_Form1 method="POST" action="addvip.php">
<table border="1"  bordercolor="#008080" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center" width="50">名称</td>
    <td align="left" width="180">&nbsp
    <input type="text" name="viptype" size="20" maxlength="40">　
    </td>
  </tr>
  <tr>
    <td align="center" width="50">赠送</td>
    <td align="left" width="180">&nbsp
    <input type="text" name="givelength" value="0" size="10" >
    </td>
  </tr>
  <tr>
    <td align="center" width="50">折扣</td>
    <td align="left" width="180">&nbsp
    <input type="text" name="discount" value="100" size="3" maxlength="3">%　
    <input type="hidden" name="ispostback" value="y">　
    <input type="hidden" name="isadd" value="<?php echo $isadd; ?>">　
    </td>
  </tr>
   <tr>
    <td colspan="2" align="center" width="230">
    <input type="button" name="b1" value="确认" onclick="checkinfo();">　
    </td>
  </tr>
</table>
</form>
</center>
</body>

</html>






































