<?php
!defined('IN_ONEZ') && exit('Access Denied');

define('CUR_URL','/master/sent.php');
$userid=(int)onez()->gp('userid');

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

$T=$G['user']=$G['this']->data()->open('member')->one("id='$userid'");
$options=array();
$options[$userid.'']=($G['user']['nickname']?$G['user']['nickname']:$G['user']['key2']);
#$options['']='';

$form->add(array('label'=>'被赠送人','type'=>'select','key'=>'to','options'=>$options));

$form->add(array('label'=>'次数','type'=>'text','key'=>'num','hint'=>'','notempty'=>'','group'=>''));
$form->add(array('label'=>'赠送信息','type'=>'textarea','key'=>'payname','default'=>'系统赠送','notempty'=>'','group'=>''));


#处理提交
if($onez=$form->submit()){
  ob_clean();
  $userid=$onez['to'];
  !$userid && onez()->error('请选择被赠送人');
  $num=(int)$onez['num'];
  $num<=0 && $num!=-1 && onez()->error('次数有误');
  $G['this']->addnum($userid,$num,$onez['payname']);
  onez()->ok('赠送成功','reload2');
}
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>
      <a href="<?php echo onez()->href('/wxapp/wxapp/nav.php')?>">
        导航菜单管理
      </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()->href('/wxapp/wxapp/nav.php')?>" class="btn btn-default">
          返回
        </a>
      </div>
    </div>
    <input type="hidden" name="action" value="save" />
  </form>
</section>
<script type="text/javascript">
$(function(){
  window.addEventListener('message', function(event){
    var data=event.data;
    if(typeof data.action!='undefined'){
      $('#input-href').val(data.action);
      $('#input-hrefname').val(data.name);
      closeWin();
      return;
    }
    if(typeof data.id!='undefined' && typeof data.name!='undefined'){
      closeWin();
      $('#input-href').val('/page/'+data.id+'/'+data.name);
      if($('#input-navname').val().length<1){
        $('#input-navname').val(data.name);
      }
      return;
    }
    for(var k in event.data){
      if($('#input-'+k).length>0){
        OnezUploadResult(k,'ok',event.data[k]);
      }
    }
    closeWin();
  }, false);
});
</script>
<?php
echo $form->js();
onez('admin')->footer();
?>