<?php
!defined('IN_ONEZ') && exit('Access Denied');
$action=onez()->gp('action');
if($action=='delete'){
}
$kw=onez()->gp('kw');
if($kw){
  $xxx.=" and key1 like '%$kw%'";
}
$tabs=array();
$tabs['all']='全部';
$tabs['new']='未使用';
$tabs['used']='已使用';
$tabs['exptime']='已过期';
$tab=onez()->gp('tab');
empty($tabs[$tab]) && $tab='all';
if($tab=='new'){
  $xxx.=" and index1=0";
}elseif($tab=='used'){
  $xxx.=" and index1>0";
}elseif($tab=='exptime'){
  $xxx.=" and index2>".time();
}
$record=$G['this']->data()->open('sn')->page("1$xxx order by id desc");
?>

<div class="" style="padding-bottom: 10px">
  <div class="pull-left">
<?foreach($tabs as $k=>$v){?>
<a href="<?=onez()->href('/index.php?menu=sn&tab='.$k)?>" class="btn btn-<?=$k==$tab?'success':'default'?>"><?=$v?></a>
<?}?>
  </div>
  <div class="pull-right">
    <form method="post">
      <div class="input-group input-group-sm" style="width: 200px;">
        <input class="form-control" id="input-kw" name="kw" type="text" value="<?=$kw?>">
        <span class="input-group-btn">
          <button class="btn btn-info" type="submit">搜索</button>
        </span>
      </div>
    </form>
  </div>
  <div class="clearfix"></div>
</div>


<div class="panel panel-primary" style="margin-bottom: 0">
	<div class="panel-heading">生成码管理</div>
  <table class="table table-striped">
    <thead>
      <tr>
        <th>序列号</th>
        <th>生成时间</th>
        <th>来源</th>
        <th>状态</th>
      </tr>
    </thead>
    <tbody class="todo-list">
      <?php foreach($record[0] as $rs){
        ?>
      <tr>
        <td><?=$rs['key1']?></td>
        <td><?=date('Y-m-d H:i:s',$rs['addtime'])?></td>
        <td><?=$rs['summary']?></td>
        <td>
          <?
          if($rs['index2']){
            echo '已于'.date('Y-m-d H:i:s',$rs['index2']).'使用';
          }else{
            echo '未使用。过期时间: '.date('Y-m-d H:i:s',$rs['index1']).'';
          }
          ?>
        </td>
      </tr>
      <?php }?>
      <?php if(!$record[0]){?>
      <tr>
        <td colspan="10" class="text-center">
          <p style="margin-top: 10px">没有符合条件的生成码</p>
        </td>
      </tr>
      <?php }?>
    </tbody>
  </table>
</div>
<?=$record[1]?>