<?php

/* ========================================================================
 * $Id: edit.php 2389 2020-07-08 13:18:57Z onez $
 * 
 * Email: www@onez.cn
 * QQ: 6200103
 * HomePage: http://www.onez.cn
 * ========================================================================
 * Copyright 2016-2017 佳蓝科技.
 * 
 * ======================================================================== */

!defined('IN_ONEZ') && exit('Access Denied');
# edit
#请求数据
if($MODE=='$post'){
  $id=onez()->gp('id');
  $action=onez()->gp('action');
  if($action=='data'){

    $form=$this->load('form');
    if($id){
      $T=$G['this']->data()->open('products')->one("id='$id'");
      $T['message']=onez('bs.app.shipments')->strcode($T['message'],'DECODE');
      $form->init($T);
    }
    $options=array();
    $T=$G['this']->data()->open('categorys')->record("key2='article' order by step desc,id desc");
    foreach($T as $rs){
      $options[$rs['id']]=$rs['name'];
    }
    $form->add(array('label'=>'所属分类','key'=>'upid','type'=>'select','options'=>$options,'hint'=>'','group'=>'',));
    $form->add(array('label'=>'文章标题','key'=>'name','type'=>'text','notempty'=>'名称不能为空','hint'=>'','group'=>'',));
    $form->add(array('label'=>'唯一编码','key'=>'token','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'缩略图','key'=>'thumb','type'=>'image','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'优先级','key'=>'step','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'价格','key'=>'price','type'=>'text','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'阅读码','key'=>'readcode','type'=>'text','notempty'=>'','hint'=>'','default'=>rand(10000000,99999999),'tip'=>'购买后发送给用户',));
    
    $form->add(array('label'=>'免费内容','key'=>'content','ptoken'=>'bs.editor','notempty'=>'','hint'=>'','group'=>'',));
    $form->add(array('label'=>'付费内容','key'=>'message','ptoken'=>'bs.editor','notempty'=>'','hint'=>'','group'=>'',));
    
    if($onez=$form->submit()){
      $onez['key1']=$onez['name'];
      $onez['money1']=$onez['price'];
      $onez['message']=onez('bs.app.shipments')->strcode($_REQUEST['message'],'ENCODE');
      $onez['content']=$_REQUEST['content'];
      if($id){
        $G['this']->data()->open('products')->update($onez,"id='$id'");
      }else{
        $onez['userid']=$G['userid'];
        $onez['key2']='article';
  
        $G['this']->data()->open('products')->insert($onez);
      }
      return $this->ok('提交成功','reload2');
    }
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'$form',
));
?>