<?php
!defined('IN_ONEZ') && exit('Access Denied');
$G['title']='证书管理';
$action=onez()->gp('action');
if($action=='delete'){
  $id=(int)onez()->gp('id');
  $G['this']->data()->open('android_keystore')->delete("userid='$G[userid]' and id='$id' and index1=0");
  onez()->ok('删除证书成功','reload');

}
$xxx="";
onez('admin')->header();

$record=$G['this']->data()->open('android_keystore')->page("userid='$G[userid]'$xxx order by step,id");
if(!$record[0]){
  $onez=array();
  $onez['name']='系统随机生成';
  $onez['alias']='ks'.$G['userid'];
  $onez['password']=md5(uniqid());
  $onez['userid']=$G['userid'];
  $onez['index1']=1;
  $id=$G['this']->data()->open('android_keystore')->insert($onez);
  $record=$G['this']->data()->open('android_keystore')->page("userid='$G[userid]'$xxx order by step,id");
}
?>
<section class="content-header">
  <h1>
    <?=$G['title']?><small></small>
  </h1>
  <ol class="breadcrumb">
    <li>
      <a href="<?php echo onez()->href('/')?>">
        <i class="fa fa-dashboard">
        </i>
        管理首页
      </a>
    </li>
    <li class="active">
      <?=$G['title']?>
    </li>
  </ol>
</section>
<section class="content">
  <div class="btns" style="padding-bottom: 10px">
    <div class="pull-left">

      <a href="<?=onez()->href('/pages/android/keystore.edit.php')?>" class="btn btn-success">
        创建新证书
      </a>
    </div>
    <div class="pull-right">
      <a href="<?=onez()->href('/pages/android/keystore.edit.php?type=auto')?>" class="btn btn-danger">
        自动生成
      </a>
    </div>
    <div class="clearfix"></div>
  </div>
  <div class="box box-info">
    <div class="box-header with-border">
      <h3 class="box-title">
        <?=$G['title']?>
      </h3>
      <div class="box-tools pull-right">
      </div>
    </div>
    <div class="box-body  table-responsive no-padding">
      <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['name']?>            </td>
            <td>
              <?=$rs['alias']?>
            </td>
            <td>
              <?=$rs['password']?>
            </td>
            <td>
              <a href="javascript:void(0)" onclick="_sel('<?=$rs['id']?>','<?=$rs['name']?>')" class="btn btn-xs btn-info">
                选择
              </a>
              <a href="<?=onez()->href('/pages/android/keystore.edit.php?id='.$rs['id'])?>" class="btn btn-xs btn-success">
                编辑
              </a>
              <?if($rs['index1']==0){?>
              <a href="javascript:void(0)" onclick="onez.del('<?=$rs['id']?>')" class="btn btn-xs btn-danger">
                删除
              </a>
              <?}?>
            </td>
          </tr>
          <?php }?>
        </tbody>
      </table>
    </div>
<?if($record[1]){ ?>
    <div class="box-footer clearfix">
      <?=$record[1]?>
    </div>
<? } ?>
  </div>
</section>
<script type="text/javascript">
function _sel(id,name){
  $('#input-keystore_id',parent.document).val(id);
  $('#input-keystore_name',parent.document).val(name);
  parent.closeWin();
}
$(function(){
  $(".todo-list").sortable({
    placeholder: "tr",
    handle: ".handle",
    forcePlaceholderSize: true,
    stop: function(){
      var ids=[];
      $('[data-id]').each(function(){
        ids.push($(this).attr('data-id'));
      });
      $.post(window.location.href,{action:'steps',ids:ids.join(',')},function(){
      });
    },
    zIndex: 999999
  });
});
</script>
<?php
onez('admin')->footer();
?>