/** * Edit group permission (use Ajax) * * @param integer $id_group Group ID * @return void */ public function gperm($id_group) { // load dictionaries $this->dict->get_wordarray(array('form', 'groups')); // get objects (group permissions) $mod = new Permission_model(); $gp = X4Utils_helper::obj2array($mod->get_gprivs($id_group), 'what', 'level'); // get area data $g = $mod->get_by_id($id_group, 'groups', 'id_area'); $a = $mod->get_by_id($g->id_area, 'areas', 'private'); // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id_group, 'name' => 'id'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $a->private, 'name' => 'xrif'); // available permission levels $l = $mod->get_levels(); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix">'); // registered group permissions $types = $mod->get_privtypes($a->private); foreach ($types as $i) { $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="one-half xs-one-whole">'); // actual permission level $value = isset($gp[$i->name]) ? $gp[$i->name] : 0; $fields[] = array('label' => constant($i->description), 'type' => 'select', 'value' => $value, 'name' => $i->name, 'options' => array($l, 'id', 'name', 0), 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $value, 'name' => 'old_' . $i->name); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div>'); } $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div>'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'gprivs'); if ($e) { $this->permitting($_POST); } else { $this->notice($fields); } die; } // contents $view = new X4View_core('editor'); $view->title = _GROUP_PERMISSION; // form builder $view->form = '<div id="scrolled">' . X4Form_helper::doform('gprivs', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'gprivs\');"') . '</div>'; $view->js = ' <script> window.addEvent("domready", function() { var myScroll = new Scrollable($("scrolled")); }); </script>'; $view->render(TRUE); }
/** * 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); }
/** * Syncronize user privileges with user permissions * if force is null add priv but not change permission levels * else add, edit and delete privs * * @param integer $id_user User ID * @param array $areas array of area objects * @param mixed $force if null leaves privs personalizations (only add missing privs) else (integer) set to default * @return array Array(0, boolean) */ private function sync_priv($id_user, $areas, $force = null) { $sql = array(); foreach ($areas as $i) { // get user privilege types on area $up = X4Utils_helper::obj2array($this->get_uprivs($id_user, $i->id_area), 'privtype', 'level'); foreach ($up as $k => $v) { // handle all if area is admin and only commons if area isn't admin if ($i->id_area == 1 || !in_array($k, $this->admin_privtypes)) { // abstract privilege if (substr($k, 0, 1) == '_') { // get the Priv ID $id = $this->get_id($i->id_area, $id_user, $k, 0); // if exists create empty array if ($id) { $items = array(); } else { // add empty item to insert $item = new Obj_item(0); $items = array($item); } } else { // set case $case = is_null($force) ? null : $v; // get items // if case is null get all items without permissions // if not null get all items with permission not equal to case value $items = $this->get_all_records($k, $id_user, $i->id_area, $case); } } else { $items = array(); } // if there are something to handle if ($items) { if (is_null($force)) { // no forcing, only insert missing permissions foreach ($items as $ii) { $sql[] = 'INSERT INTO privs (updated, id_area, id_who, what, id_what, level, xon) VALUES (NOW(), ' . $i->id_area . ', ' . $id_user . ', ' . $this->db->escape($k) . ', ' . $ii->id . ', ' . $v . ', 1)'; } } else { // forcing foreach ($items as $ii) { // set all permission to right value (eliminate customizzations) if permission is greater than zero if ($v) { $sql[] = 'UPDATE privs SET level = ' . $v . ' WHERE id_who = ' . $id_user . ' AND what = ' . $this->db->escape($k) . ' AND id_what = ' . $ii->id; } else { $sql[] = 'DELETE FROM privs WHERE id_who = ' . $id_user . ' AND what = ' . $this->db->escape($k) . ' AND id_what = ' . $ii->id; } } } } } // set privs on admin pages if ($i->id_area == 1) { // get administration pages without permission $pages = $this->get_pages_by_xid('base', $id_user); if ($pages) { foreach ($pages as $ii) { $sql[] = 'INSERT INTO privs (updated, id_area, id_who, what, id_what, level, xon) VALUES (NOW(), 1, ' . $id_user . ', \'pages\', ' . $ii->id . ', 1, 1)'; } } } } return empty($sql) ? array(0, 1) : $this->db->multi_exec($sql); }
/** * 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); }