Пример #1
0
 /**
 * Register Edit / New User form data
 *
 (if 0 then is a new item)
 * @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 permission
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'users', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_user_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('lang' => $_post['lang'], 'id_group' => $_post['id_group'], 'username' => $_post['username'], 'description' => $_post['description'], 'mail' => $_post['mail'], 'phone' => $_post['phone'], 'level' => $_post['level']);
         // update password
         if (!empty($_post['password'])) {
             $post['password'] = X4Utils_helper::hashing($_post['password']);
         }
         // check if an user with the same username or password already exists
         $user = new User_model();
         $check = (bool) $user->exists($post['username'], $post['mail'], $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_USER_ALREADY_EXISTS', 'msg'));
         } else {
             $perm = new Permission_model();
             if ($id) {
                 // update
                 $result = $user->update($id, $post);
                 // update user privileges on areas
                 $perm->set_aprivs($id, $_post['domain']);
                 // redirect
                 $where = '/detail/' . $id;
             } else {
                 // insert
                 $result = $user->insert($post);
                 // redirect
                 $where = '';
                 if ($result[1]) {
                     $id = $result[0];
                     // set privileges on areas
                     $perm->set_aprivs($id, $_post['domain']);
                     // add privs on new user
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('users', $array, $_post['id_area']);
                     // refactory permissions for the user
                     $perm->refactory($id);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'users' . $where, 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
Пример #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);
 }