<?php
!defined('IN_ONEZ') && exit('Access Denied');
$action=onez()->gp('action');
if($action=='delete'){
  $id=(int)onez()->gp('id');
  #$G['this']->data()->open('userinfo')->delete("id='$id' and key1='new'");
  onez()->ok('删除用户成功','reload');


}
$tabs=array();
$tabs['id']='按注册时间';
$tabs['userid']='按用户编号';
$tabs['index5']='按推广人数';
$tab=onez()->gp('tab');
empty($tabs[$tab]) && $tab='id';
$kw=onez()->gp('kw');
if($kw){
  define('IS_ONEZ_DEBUG',1);
  $userid=(int)$kw;
  $xxx.=" and (userid='$userid' or userid in (select userid from onez_member where username like '%$kw%' or nickname like '%$kw%'))";
}

$record=$G['this']->data()->open('userinfo')->page("1$xxx order by $tab desc");
?>

<div class="" style="padding-bottom: 10px">
  <div class="pull-left">
<?foreach($tabs as $k=>$v){?>
<a href="<?=onez()->href('/index.php?menu=users&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>
        <th>推广人数</th>
        <th>推广总额</th>
        <th>剩余数量</th>
        <th>生成总数</th>
        <th>支付总额</th>
        <th></th>
      </tr>
    </thead>
    <tbody class="todo-list">
      <?php foreach($record[0] as $rs){
        $u=$G['this']->data()->open('member')->one("id='$rs[userid]'");
        $up=$G['this']->data()->open('member')->one("id='$rs[upid]'");
        ?>
      <tr>
        <td><?=$rs['userid']?></td>
        <td><img src="<?=$G['this']->avatar($rs['userid'])?>" style="width:16px;height:16px;position: relative;top: -2px;" /> <?=$u['nickname']?> (<?=$u['key2']?>)</td>
        <td><?=date('Y-m-d H:i:s',$rs['addtime'])?></td>
        <td>
<?if($rs['upid']){?>
<img src="<?=$G['this']->avatar($rs['upid'])?>" style="width:16px;height:16px;position: relative;top: -2px;" /> <?=$up['nickname']?> (<?=$up['key2']?>)
<?}?>
        </td>
        <td><?=$rs['index7']?></td>
        <td><?=$rs['money1']?></td>
        <td><code class="totalprice"><?=$rs['nolimit']?'无限':$rs['index1']?></code>次</td>
        <td><?=$rs['index6']?></td>
        <td><?=$rs['pay_total']?></td>
        <td>
          <a href="<?=onez()->href('/master/sent.php?userid='.$rs['userid'])?>" data-title="赠送次数" class="onez-miniwin btn btn-xs btn-success">
            赠送次数
          </a>
        </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]?>