<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<link  href="skin/css/style.css" rel="stylesheet" type="text/css" />
<title>充值卡管理</title>
<script src="skin/js/common.js" type="text/javascript"></script>
<script src="skin/js/main.js" type="text/javascript"></script>
<style type="text/css">
.btn {
	border:1px solid;
	border-color:#fff #999 #999 #fff;
	background:#DDDDDD
}
select {
	font-size:12px;
}
form{float:left;}
</style>
</head>
<body>
<?php
	$sqlt="SELECT SUM( climit ) AS card FROM duomi_card";
	$rowt = $dsql->GetOne($sqlt);
    if($rowt['card']>0){
        $card = $rowt['card'];
    }else{
        $card = 0;
    }
	$sqlyes="SELECT SUM( climit ) AS ok FROM duomi_card where status=1";
	$rowyes = $dsql->GetOne($sqlyes);
    if($rowyes['ok']>0){
        $ok = $rowyes['ok'];
    }else{
        $ok = 0;
    }
	
	$sqlno="SELECT SUM( climit ) AS no FROM duomi_card  where status=0";
	$rowno = $dsql->GetOne($sqlno);
    if($rowno['no']>0){
        $no = $rowno['no'];
    }else{
        $no = 0;
    }
	
	$w=" where ckey <> '' ";
    $numPerPage=10;
    $page = isset($page) ? intval($page) : 1;
    if($page==0) $page=1;
    
    if ($cstatus=="1") 
	{$w.=" and status=1";}
	elseif($cstatus=="0")
	{$w.=" and status=0";}
	else
	{$w.='';}
	
	if (!empty($climit) AND $climit != "all") 
	{$w.=" and climit=$climit";}
	else
	{$w.='';}
	
	if($action=="search")
	{
		$ckey=$_POST['ckey'];
		if (!empty($ckey)) $w =" where ckey='$ckey'";
	}
	
	//计算有多少条数据
    $csqlStr="select count(*) as dd from duomi_card ".$w;
	$rowTotal = $dsql->GetOne($csqlStr);
    if(is_array($rowTotal)){
        $TotalResult = $rowTotal['dd'];
    }else{
        $TotalResult = 0;
    }
    $TotalPage = ceil($TotalResult/$numPerPage);
    if ($page>$TotalPage) $page=$TotalPage;
    $limitstart = ($page-1) * $numPerPage;
    if($limitstart<0) $limitstart=0;
    
   $sqlStr="select * from duomi_card ".$w." ORDER BY  `id` DESC limit $limitstart,$numPerPage";

?>
<div class="r_main">
  <div class="r_content">
    <div class="r_content_1">
      <table class="tb_style" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td colspan="15" class="td_title">&nbsp;充值卡管理<span style="float:right">当前总额:<font color=red><?php echo $card ?></font>元 | 已使用:<font color=red><?php echo $ok ?></font>元 | 未使用:<font color=red><?php echo $no ?></font>元</span>
            </td>
        </tr>
        
        <?php
if($TotalResult==0){
    echo "<tr><td colspan='10'><br>&nbsp;<font color=red>无充值卡信息</font><br><br></td></tr>";}
?>
        <tr bgcolor="#f5fafe" align="center">
          <td width="10%" height="30" align="center" bgcolor="#FFFFFF" class="td_btop3" >ID</td>
          <td width="15%" bgcolor="#FFFFFF" class="td_btop3">卡号</td>
          <td width="15%" bgcolor="#FFFFFF" class="td_btop3">卡密码</td>
          <td width="8%" bgcolor="#FFFFFF" class="td_btop3">卡面值(元)</td>
          <td width="15%" bgcolor="#FFFFFF" class="td_btop3">生成时间</td>
          <td width="7%" bgcolor="#FFFFFF" class="td_btop3">状态</td>
          <td width="10%" bgcolor="#FFFFFF" class="td_btop3">充值用户</td>
          <td width="15%" bgcolor="#FFFFFF" class="td_btop3">充值时间</td>
          <td width="5%" align="center" bgcolor="#FFFFFF" class="td_btop3">操作</td>
        </tr>
        <form method="post" name="videolistform">
          <?php
$dsql->SetQuery($sqlStr);
$dsql->Execute('key_list');
while($row=$dsql->GetObject('key_list'))
{
$id=$row->id;
$copy.="卡号：".$row->ckey." 卡密码：".$row->cpwd." 卡面值：".$row->climit."元"."<br>"
?>
          <tr bgcolor="#f5fafe" align="center">
            <td width="10%" height="30" class="td_border" style="text-align:center"><input type="checkbox" value="<?php echo $id;?>" name="e_id[]" class="checkbox" />
            <?php echo $id;?></td>
            <td width="15%" class="td_border"><?php echo $row->ckey;?></td>
            <td width="15%" class="td_border"><?php echo $row->cpwd;?></td>
			<td width="8%" class="td_border"><?php echo $row->climit;?></td>
			<td width="15%" class="td_border"><?php echo $row->maketime;?></td>
            <td width="7%" class="td_border"><?php if($row->status=="0") echo "未使用"; else echo "已使用";?></td>
            <td width="10%" class="td_border"><?php echo $row->uname;?></td>
            <td width="15%" class="td_border"><?php echo $row->usetime;?></td>
            <td width="5%" class="td_border" align="center"><a href="?action=del&id=<?php echo $id;?>" onClick="return confirm('确定要删除吗')">删除</a></td>
          </tr>
          <?php }?>
          <tr>
            <td height="30" colspan="11" class="td_border">&nbsp;全选
              <input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="checkAll(this.checked,'input','e_id[]')" />
              <!--input type="checkbox" name="chkothers" id="chkothers" class="checkbox" onclick="checkOthers('input','e_id[]')" /-->
              <input type="submit" value="批量删除" onclick="if(confirm('确定要批量删除吗')){videolistform.action='?action=delall';}else{return false}" class="rb1"  />
			  <input type="button" value="显示当前卡号" class="rb1" onclick="document.getElementById('copy').style.display = 'block'";>
			  <input type="button" value="关闭当前卡号" class="rb1" onclick="document.getElementById('copy').style.display = 'none'";>
              <form action="" method="post" >
              &nbsp;&nbsp;&nbsp;条件选择：
			  <select id='climit' name='climit' style="width:80px" onChange="self.location.href='?cstatus=<?php echo $cstatus ?>&climit='+this.options[this.selectedIndex].value">
			    <option value=''>选择金额</option>
				<option value='all'>全部金额</option>
                <option value="1">1元</option>
				<option value="5">5元</option>
				<option value="10">10元</option>
                <option value="20">20元</option>
                <option value="30">30元</option>
                <option value="40">40元</option>
				<option value="50">50元</option>
				<option value="100">100元</option>
				<option value="500">500元</option>
				<option value="1000">1000元</option>
				</select>
				&nbsp;
				<select id='cstatus' name='cstatus' style="width:80px" onChange="self.location.href='?climit=<?php echo $climit ?>&cstatus='+this.options[this.selectedIndex].value">
			    <option value=''>选择状态</option>
				<option value='all'>全部状态</option>
                <option value="1">已使用</option>
				<option value="0">未使用</option>
				</select>
          </form> 
		   <form action="?action=search" method="post" style="float:right">
              &nbsp;&nbsp;&nbsp;卡号搜索：<input  name="ckey" type="text" id="ckey" size="25">
			  <input type="submit" name="selectBtn" value="搜索" class="btn"  />
		   </form>
			</td>
          </tr>
        </form>
        <tr>
          <td height="30" colspan="11" class="td_border">
            <div class="cuspages">
              <div class="pages"> &nbsp;页次：<?php echo $page;?>/<?php echo $TotalPage;?> 每页<?php echo $numPerPage;?> 总收录数据<?php echo $TotalResult;?>条 <a href="?page=1&cstatus=<?php echo $cstatus ?>&climit=<?php echo $climit;?>">首页</a> <a href="?page=<?php echo ($page-1);?>&cstatus=<?php echo $cstatus ?>&climit=<?php echo $climit;?>">上一页</a> <a href="?page=<?php echo ($page+1);?>&cstatus=<?php echo $cstatus ?>&climit=<?php echo $climit;?>">下一页</a> <a href="?page=<?php echo $TotalPage;?>&cstatus=<?php echo $cstatus ?>&climit=<?php echo $climit;?>">尾页</a>&nbsp;&nbsp;跳转
                <input type="text" id="skip" value="" onkeyup="this.value=this.value.replace(/[^\d]+/,'')" style="width:40px"/>
                &nbsp;&nbsp;
                <input type="button" value="确定" class="btn" onclick="location.href='?page='+ document.getElementById('skip').value +'&cstatus=<?php echo $cstatus ?>&climit=<?php echo $climit;?>';"/>
              </div>
            </div>
 </td>
        </tr>
      </table>
    </div>
    <div id="copy" name="copy" style="display:none;background:#f5f5f5;padding-left:15px;line-height:35px"><?php echo $copy; ?></div>
  </div>
</div>
<?php
viewFoot();
?>