<?php

/* ========================================================================
 * $Id: badip.edit.php 2965 2017-11-30 09:47:39Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onezphp.com
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
define('CUR_URL',onez('chat.group.common')->href('/admin/users/badip.php'));
$groupid=onez()->gp('groupid');

$id=(int)onez()->gp('id');
if($id){#编辑
  $item=$G['this']->data()->open('group_badip')->one("id='$id'");
  $G['title']='编辑IP黑名单';
  $btnname='保存修改';
}else{#添加
  $item=array();
  $copyid=(int)onez()->gp('copyid');
  $item['index2']=strtotime('+1 days');
  if($copyid){
    $item=$G['this']->data()->open('group_badip')->one("id='$copyid'");
  }
  $G['title']='添加IP黑名单';
  $btnname='立即添加';
}

#初始化表单
$form=onez('admin')->widget('form')
  ->set('title',$G['title'])
  ->set('values',$item)
;
#创建表单项
$form->add(array('type'=>'hidden','key'=>'action','value'=>'save'));


$options=array('0'=>'所有群组');
$C=$G['this']->data()->open('group')->record("1 order by step,id");
foreach($C as $r){
  $options[$r['id']]=$r['name'];
}
$form->add(array('label'=>'限制群组','type'=>'select','key'=>'upid','options'=>$options,'group'=>''));
$form->add(array('label'=>'IP地址','type'=>'text','key'=>'token','hint'=>'','notempty'=>'IP地址不能为空','group'=>''));
$form->add(array('label'=>'备注说明','type'=>'text','key'=>'summary','hint'=>'','notempty'=>'','group'=>''));
$form->add(array('label'=>'过期时间','type'=>'form.time','key'=>'index2','hint'=>'','notempty'=>'','group'=>''));

#处理提交
if($onez=$form->submit()){
  ob_clean();
  if($id){
    $G['this']->data()->open('group_badip')->update($onez,"id='$id'");
  }else{
    $onez['userid']=$G['userid'];
    $id=$G['this']->data()->open('group_badip')->insert($onez);
  }
  #onez()->ok('操作成功',onez('chat.group.common')->href('/admin/users/badip.php&groupid='.$groupid));
  onez()->ok('操作成功','reload2');
}
onez('admin')->header();
?>
<section class="content-header">
  <h1>
    <?php echo $G['title']?>
  </h1>
  <ol class="breadcrumb">
    <li>
      <a href="<?php echo onez()->href('/')?>">
        <i class="fa fa-dashboard">
        </i>
        管理首页
      </a>
    </li>
    <li class="active">
      <?php echo $G['title']?>
    </li>
  </ol>
</section>
<section class="content">
  <form id="form-common" method="post">
    <div class="box box-info">
      <div class="box-header with-border">
        <h3 class="box-title">
          <?php echo $G['title']?>
        </h3>
        <div class="box-tools pull-right">
        </div>
      </div>
      <div class="box-body">
        <?php echo $form->code()?>
      </div>
      <div class="box-footer clearfix">
        <button type="submit" class="btn btn-primary">
          <?php echo $btnname?>
        </button>
        <!--<a href="<?php echo onez('chat.group.common')->href('/admin/users/badip.php&groupid='.$groupid)?>" class="btn btn-default">
          返回
        </a>-->
      </div>
    </div>
    <input type="hidden" name="action" value="save" />
  </form>
</section>
<?php
echo $form->js();
onez('admin')->footer();
?>