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

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language=jscript>
//计算money1
function setcount()
{
    cancelBubble=true;
    var n=0;
    var tmpmoney1=0;
    var totalmoney1=0;
    var obj="";
    var count=parseInt(document.form1.count.value,"10");
    for (i=1;i<=count;i++)
        {
         tmpmoney1=0;
         obj=eval("document.form1.price"+i.toString());
         if (document.all.table1.rows(i).cells(1).childNodes(0).checked)
            {
             n=n+1;
             tmpmoney1=Math.round(parseFloat(obj.value,"10")*parseInt(document.form1.buylength.value,"10")*10)/10;
             obj=eval("document.form1.money1"+i.toString());
             obj.value=tmpmoney1.toString();
            }
         totalmoney1=parseFloat(totalmoney1)+parseFloat(tmpmoney1);
        }
    totalmoney1=Math.round(totalmoney1*10)/10;
    document.all.usercount.innerText=" "+count.toString()+"人";
    document.all.addcount.innerText=" "+n.toString()+"人";
    document.all.totalmoney11.innerText=" "+totalmoney1.toString()+"元";
    document.form1.totalmoney1.value=totalmoney1.toString();
    setvalue();
}

//计算money2
function setvalue()
{
    cancelBubble=true;
    var tmpmoney2=0;
    var totalmoney2=0;
    var obj="";
    var count=parseInt(document.form1.count.value,"10");
    for (i=1;i<=count;i++)
        {
         tmpmoney2=0;
         if (document.all.table1.rows(i).cells(1).childNodes(0).checked)
            {
             obj=eval("document.form1.money1"+i.toString());
             tmpmoney2=Math.round(parseFloat(obj.value)*parseInt(document.form1.discount.value,"10")/10)/10;
             obj=eval("document.form1.money2"+i.toString());
             obj.value=tmpmoney2.toString();
            }
         totalmoney2=parseFloat(totalmoney2)+parseFloat(tmpmoney2);
        }
    totalmoney2=Math.round(totalmoney2*10)/10;
    document.all.totalmoney21.innerText=" "+totalmoney2.toString()+"元";
    document.form1.totalmoney2.value=totalmoney2.toString();
}

//检查数据是否为整数
function IsInt(obj)
{   
    var str=obj.value;
    var tmpstr=parseInt(str,"10");
    if (tmpstr!=str)
        return(false);
    else
       {
        obj.value=tmpstr;
        return(true);
       }
}

//检查输入的数据的有效性
function checkData()
{
   var obj=document.form1.buylength;
   var cansub=IsInt(obj);
   var str="";
   if (cansub&&obj.value>0)
       var cansub1=true;
   else
      str=str+"每用户续费数量只能是整数且大于0\n";
   obj=document.form1.discount;
   cansub=IsInt(obj);
   if (cansub&&obj.value>0)
       var cansub2=true;    
   else
       str=str+"折扣只能是整数且大于等于0\n";
   obj=document.form1.otherlength;
   cansub=IsInt(obj);
   if (cansub&&obj.value>=0)
       var cansub3=true;
   else
       str=str+"每用户赠送数量只能是整数且大于等于0\n";
   if (cansub1&&cansub2&&cansub3)
       document.form1.submit();
   else
       alert(str);
}

</script>
<title>组续费</title>

<body background="bkg.bmp" onload='setcount();'>
<p align="center"><font size="5"><b>组续费</b></font></p>
<hr color="#999966">
<center>
<?php
   $gpid=trim($_REQUEST["gpid"]);
   if ($gpid!="") {
?>
<form name='form1'  method='POST' action='gpaddtime3.php'>
<table><tr>
 <td align="center">
 <DIV ID=oDiv STYLE="height: 400px; overflow-y: scroll;">
<?php
   $db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
   mysql_select_db(get_cfg_var("SIPDB"),$db); 
   $count=0;
   $sqlstr= "select u.userid,u.loginname,u.username,t.name,t.price,u.type from users u,types t where u.type=t.typeid and gpid=".$gpid." and u.checked='n' order by u.type,u.userid";  
   $rs=mysql_query( $sqlstr,$db );
   if ( ($row = mysql_fetch_array($rs))==FALSE ) { 
      echo("<p align='center'>该用户组没有用户</p>");
   }
   else {
         echo("<font size='3'><b>选取需要续费的成员</b></font>");
         echo("<table id='table1' border='1' bordercolor='#008080' cellspacing='0' cellpadding='0'>");
         echo("<tr>");
         echo("<td align='center'>序号</td>");
         echo("<td align='center'>续费</td>");
         echo("<td align='center'>用户ID</td>"); 
         echo("<td align='center'>用户姓名</td>");
         echo("<td align='center'>用户类型</td>");
         echo("</tr>");
         $n=0;
         while ($row) {
               //输出组成员信息
               $n=$n+1;
               echo("<tr>");
		       echo("<td align='center'>".strval($n)."</td>");    //序号
		       echo("<td align='center'><input type=checkbox name=isadd".strval($n)." value=y checked onclick='setcount();'></td>"); //续费选择框
		       echo("<td align='center'>".$row[1]."</td>");          //用户ID
		       echo("<td align='center'>".$row[2]."&nbsp;</td>");    //用户姓名
		       echo("<td align='center'>".$row[3]."</td>");          //用户类型 
		       echo("<input type=hidden name=userid".strval($n)." value=".$row[0].">");
		       echo("<input type=hidden name=money1".strval($n)." value='0'>");           
		       echo("<input type=hidden name=money2".strval($n)." value='0'>");          
		       echo("<input type=hidden name=price".strval($n)." value=".strval($row[4]).">");           //类型单价
		       echo("<input type=hidden name=type".strval($n)." value=".strval($row[5]).">");            //类型号
		       echo("</tr>");  
		       $row = mysql_fetch_array($rs);
	     }
	     echo("</table>");
         echo("<input type=hidden name=gpid value=".$gpid.">");
		 $count=$n;
   }
   echo("<input type=hidden name=count value=".strval($count).">");
   mysql_free_result($rs);
   mysql_close($db); 
 ?></div>
 </td>
 <td width="50"></td>
 <td valign="top" align="center">
    <font size='3'><b>购买信息</b></font>
    <table  border='1' bordercolor='#008080' cellspacing='0' cellpadding='0'>
    <tr>
       <td width="124" align="center">总组员数</td>
       <td align="left" width="124">
          <span id="usercount">&nbsp;0人</span>
       </td>
    </tr>
    <tr>
       <td width="124" align="center">续费人数</td>
       <td align="left">
          <span id="addcount">&nbsp;0人</span>
       </td>
    </tr>
    <tr>
       <td width="124" align="center">续费数量</td>
       <td align="left">
          &nbsp;<input type="text" name="buylength" size="8" value="0" onkeyup="setcount();">
       </td>
    </tr>
    <tr>
      <td width="124" align="center">赠送数量</td>
      <td align="left">
		 &nbsp;<input type="text" name="otherlength" value="0" size="8">
      </td>
    </tr>
    <tr>
       <td width="124" align="center">合计费用</td>
       <td align="left">
          <span id="totalmoney11">&nbsp元</span>    
          <input type="hidden" name="totalmoney1" value="0">      
       </td>
    </tr>
    <tr>
      <td width="124" align="center">优惠折扣率</td>
      <td align="left" >
		 &nbsp;<input type="text" name="discount" size="3" value="100" onkeyup="setvalue();">% 
      </td>
    </tr>
    <tr>
      <td width="124" align="center">实收费用</td>
      <td align="left">
          <span id="totalmoney21">&nbsp元</span>
          <input type="hidden" name="totalmoney2" value="0">
      </td>
    </tr>    
    </table>
    <input type="button" value="提交" name="B1" onclick="checkData();">
    <table style="font-size:3.5mm;">
    <tr><td align="center"><br>备注</td></tr>
    <tr><td align="left">
    <ul>
    　 <li>购买数量的单位与每位续费组员的类型有关。</li>
       <li>关于赠送：</li>
            <ul>
            <li>“包年”类型赠送数量是以月为单位</li>
            <li>“计流量(G)”类型赠送数量是以M为单位；</li>
            <li>其它类型赠送数量的单位和该类型续费数量单位相同。</li>
        </ul>
    </ul> 
    </td></tr></table>
</td>
</tr></table>
</form>
<?php   
}
else {
   echo("请选择要续费的组");
}
?>
</center>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>
</body>

</html>
