<?php

/* ========================================================================
 * $Id: edit.php 2512 2020-05-16 05:22:51Z 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');
    $user=onez()->gp('user');
    $siteId=(int)onez()->gp('siteId');
    $where=$G['this']->where();
    strpos($user,'user')!==0 && onez()->error('来源不合法');
    $uId=(int)substr($user,4);
    $u=$G['this']->data()->open('users')->one("id='$uId'$where");
    !$u && onez()->error('没有此用户体系的权限');
    $r=$G['this']->user_before();
    $T=array();
    if($id){
      $T=onez('data',$user)->noappid()->open('member')->one("index11='$G[userid]' and id='$id'");
      unset($T['key3']);
    }else{
      $T['key5']='管理员添加';
    }
    $form->init($T);
    !$u['grades'] && $u['grades']=array(''=>'-请修改用户体系中的用户组资料-',);
    $form->add(array('label'=>'用户组','type'=>'select','key'=>'key1','options'=>$u['grades'],'notempty'=>'','default'=>'','group'=>''));
    $form->add(array('label'=>'登录账号','type'=>'text','key'=>'key2','hint'=>'','notempty'=>'登录账号不能为空','default'=>'','group'=>''));
    if($id){
      $form->add(array('label'=>'登录密码','type'=>'text','key'=>'key3','hint'=>'不改请留空','notempty'=>'','default'=>'','group'=>''));
    }else{
      $form->add(array('label'=>'登录密码','type'=>'text','key'=>'key3','hint'=>'','notempty'=>'登录密码不能为空','default'=>'','group'=>''));
    }
    $form->add(array('label'=>'昵称','type'=>'text','key'=>'key4','hint'=>'','notempty'=>'昵称不能为空','default'=>'','group'=>''));
    $form->add(array('label'=>'注册来源','type'=>'text','key'=>'key5','hint'=>'','notempty'=>'','default'=>'','group'=>''));
    
    if($onez=$form->submit()){
      
      if($id){
        if($onez['key3']){
          $onez['key3']=md5($onez['key3']);
        }else{
          unset($onez['key3']);
        }
        onez('data',$user)->noappid()->open('member')->update($onez,"userid='$G[userid]' and id='$id'");
      }else{
        $onez['key3']=md5($onez['key3']);
        $onez['index11']=$G['userid'];
        $onez['index12']=$siteId;
        onez('data',$user)->noappid()->open('member')->insert($onez);
      }
      $G['this']->user_after();
      return $this->ok('提交成功','reload2');
    }
    $G['this']->user_after();
    $form->output($A);
  }
  return;
}
$this->add(array(
  'type'=>'pageform',
  'name'=>'表单',
  'data'=>'form',
));
