예제 #1
0
 /**
  * New / Edit user form (use Ajax)
  *
  * @param   integer  $id User ID (if 0 then is a new item)
  * @param   integer  $id_group Group ID (if 0 then is a new item)
  * @return  void
  */
 public function edit($id, $id_group = 0)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'login', 'users'));
     $lang = X4Route_core::$lang;
     // get object
     $user = new User_model();
     $u = $id ? $user->get_by_id($id) : new User_obj($id_group, $lang);
     // get group
     $group = new Group_model();
     $g = $group->get_by_id($u->id_group, 'groups', 'id_area, name');
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $u->id_group, 'name' => 'id_group');
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $g->id_area, 'name' => 'id_area');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _GROUP . ': ' . $g->name . '</h4>');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     // languages
     $lmod = new Language_model();
     $fields[] = array('label' => ucfirst(_LANGUAGE), 'type' => 'select', 'value' => $u->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _USERNAME, 'type' => 'text', 'value' => $u->username, 'name' => 'username', 'suggestion' => _USERNAME_RULE, 'rule' => 'required|minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // password
     if ($id) {
         $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4 class="acenter zerom">' . _PASSWORD_CHANGE_MSG . '</h4>');
         $rule = '';
     } else {
         // for a new user you must insert a password
         $rule = 'required|';
     }
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password', 'suggestion' => _PASSWORD_RULE, 'rule' => $rule . 'minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _REPEAT_PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password2', 'rule' => $rule . 'equal-password', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $u->description, 'name' => 'description', 'sanitize' => 'string', 'rule' => 'required');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _EMAIL, 'type' => 'text', 'value' => $u->mail, 'name' => 'mail', 'rule' => 'required|mail', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PHONE, 'type' => 'text', 'value' => $u->phone, 'name' => 'phone', 'rule' => 'phone', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _LEVEL, 'type' => 'select', 'value' => $u->level, 'options' => array($user->get_levels(), 'id', 'name'), 'name' => 'level', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     // permissions on areas
     $perm = new Permission_model();
     $area = new Area_model();
     $fields[] = array('label' => _DOMAIN, 'type' => 'select', 'value' => X4Utils_helper::obj2array($perm->get_aprivs($id), null, 'id_area'), 'options' => array($area->get_areas($g->id_area, false), 'id', 'name'), 'multiple' => 4, 'name' => 'domain', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // if submitted
     if (X4Route_core::$post) {
         $e = X4Validation_helper::form($fields, 'editor');
         if ($e) {
             $this->editing($id, $_POST);
         } else {
             $this->notice($fields);
         }
         die;
     }
     // contents
     $view = new X4View_core('editor');
     $view->title = $id ? _EDIT_USER : _ADD_USER;
     // form builder
     $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"');
     $view->render(TRUE);
 }
예제 #2
0
 /**
  * Register Edit / New Area form data
  *
  * @access	private
  * @param   integer $id item ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($id, $_post)
 {
     $msg = null;
     // check permissions
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'areas', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_area_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('lang' => $_post['lang'], 'name' => X4Utils_helper::unspace($_post['name']), 'title' => $_post['title'], 'description' => $_post['description'], 'id_theme' => $_post['id_theme'], 'private' => intval(isset($_post['private'])) && $_post['private'], 'folder' => $_post['folder']);
         $mod = new Area_model();
         // check if area name already exists
         $check = (bool) $mod->exists($post['name'], $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_AREA_ALREADY_EXISTS', 'msg'));
         } else {
             // Redirect checker
             $redirect = false;
             // enable logs
             if (LOGS && DEVEL) {
                 $mod->set_log(true);
             }
             // update or insert
             if ($id) {
                 $result = $mod->update($id, $post);
                 if ($id == 1 && X4Route_core::$lang != $post['lang']) {
                     $redirect = true;
                 }
             } else {
                 $result = $mod->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $id = $result[0];
                     $perm = new Permission_model();
                     // aprivs permissions
                     $domain = X4Utils_helper::obj2array($perm->get_aprivs($_SESSION['xuid']), null, 'id_area');
                     $domain[] = $result[0];
                     $res = $perm->set_aprivs($_SESSION['xuid'], $domain);
                     // privs permissions
                     $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('areas', $array, $id);
                 }
             }
             if ($result[1]) {
                 // refresh languages related to area
                 $lang = new Language_model();
                 $lang->set_alang($id, $_post['languages'], $_post['lang']);
                 // update theme settings
                 if ($_post['id'] && $_post['id_theme'] != $_post['old_id_theme']) {
                     $menu = new Menu_model();
                     // reset tpl, css, id_menu, ordinal
                     $result = $menu->reset($_post['id']);
                     $langs = $lang->get_languages();
                     // restore ordinal
                     foreach ($langs as $i) {
                         $menu->ordinal($_post['id'], $i->code, 'home', 'A');
                     }
                 }
                 if (APC) {
                     apc_clear_cache();
                     apc_clear_cache('user');
                     apc_clear_cache('opcode');
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 if ($redirect) {
                     X4Route_core::redirect($this->site->site->domain . '/admin');
                 } else {
                     $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'areas', 'title' => null);
                 }
             }
         }
     }
     $this->response($msg);
 }