<?php
!defined('IN_ONEZ') && exit('Access Denied');
include_once(dirname(__FILE__).'/init.php');

$groupid=onez()->gp('groupid');
$gid=(int)onez()->gp('gid');


$G['title']='手动充值';

#初始化表单
$form=onez('admin')->widget('form')
  ->set('title',$G['title'])
  ->set('values',$item)
;
#创建表单项
$form->add(array('type'=>'hidden','key'=>'action','value'=>'save'));
$form->add(array('label'=>'充值金额','type'=>'text','key'=>'key1','hint'=>'','notempty'=>'充值金额不能为空','group'=>''));
$form->add(array('label'=>'充值截图','type'=>'form.file','key'=>'pic','hint'=>'','notempty'=>'请上传充值截图','group'=>''));
$form->add(array('label'=>'备注信息','type'=>'textarea','key'=>'summary','hint'=>'','notempty'=>'','group'=>''));

$charge_intro=onez('chat.group.plugin.credit')->option('charge_intro');
$charge_intro && $form->add(array('label'=>'充值说明','type'=>'html','html'=>$charge_intro));

#处理提交
if($onez=$form->submit()){
  ob_clean();
  $money=(float)$onez['key1'];
  $money<=0 && onez()->error('充值金额有误');
  $onez['userid']=$G['userid'];
  $onez['key2']='wait';
  $onez['money1']=$money;
  $onez['upid']=(int)$groupid;
  $G['this']->data()->open('charge.user')->insert($onez);
  onez()->ok('操作成功',onez('chat.group.plugin.credit')->href('/group/charge.log.php'));
}
onez('admin')->header();
?>
<section class="content-header">
  <h1>
    <?=$G['title']?>
  </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">
  <form id="form-common" method="post">
    <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">
        <?=$form->code()?>
      </div>
      <div class="box-footer clearfix">
        <button type="submit" class="btn btn-primary">
          提交申请
        </button>
        <a href="<?=onez('chat.group.plugin.credit')->href('/group/charge.log.php')?>" class="btn btn-info">查看申请记录</a>
      </div>
    </div>
    <input type="hidden" name="action" value="save" />
  </form>
</section>
<script type="text/javascript">
$(function(){
  $('#form-common').bind('submit',function(){
    $.post(window.location.href,$(this).serialize()+'&ajax=1',function(data){
      onez.doit(data);
    },'json');
    return false;
  });
});
</script>
<?php
onez('admin')->footer();
?>