/** * Edit user permission form (use Ajax) * * @param integer $id_user User ID * @param integer $id_area Area ID * @param integer $table if equal to 0 manage abstract permission (creation, installation) else manage real permission over table records * @return void */ public function perm($id_user, $id_area, $table = 0) { // load dictionaries $this->dict->get_wordarray(array('form', 'groups', 'users')); $mod = new Permission_model(); // user data $u = $mod->get_by_id($id_user, 'users', 'id_group, username'); // user permission $what = $mod->get_uprivs($id_user, $id_area); // permission level $l = $mod->get_levels(); // build the form $fields = array(); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id_user, 'name' => 'id'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $u->id_group, 'name' => 'id_group'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id_area, 'name' => 'id_area'); $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $table, 'name' => 'table'); // tables without items $nodetail = array('areas', 'sites'); // tables for administrators $onlyadmin = array('themes', 'templates', 'menus', 'groups', 'users', 'languages', 'sites', 'privs'); // tables if advanced editing $exclude = ADVANCED_EDITING ? array('contents', 'logs') : array('blocks', 'sections', 'logs'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix">'); foreach ($what as $t) { if ($table == 0) { // only abstract permissions if (substr($t->privtype, 0, 1) == '_') { $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="one-half xs-one-whole">'); $fields[] = array('label' => constant(strtoupper($t->privtype)), 'type' => 'select', 'value' => $t->level, 'name' => $t->privtype, 'options' => array($l, 'id', 'name', 0), 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div>'); } } else { // only real permissions on tables if (substr($t->privtype, 0, 1) != '_' && !in_array($t->privtype, $exclude)) { // relative to admin area or not only for administrators if ($id_area == 1 || !in_array($t->privtype, $onlyadmin)) { $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="one-half xs-one-whole">'); // if in tables with items if (!in_array($t->privtype, $nodetail)) { $fields[] = array('label' => constant(strtoupper($t->privtype)), 'type' => 'select', 'value' => $t->level, 'name' => $t->privtype, 'options' => array($l, 'id', 'name', 0), 'suggestion' => '', 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div> <div class="one-half xs-one-whole double-pad-top"> <a class="btop" href="' . BASE_URL . 'users/permissions/' . $id_user . '/' . $id_area . '/' . $t->privtype . '" title="' . _EDIT_DETAIL_PRIV . '">' . _EDIT_DETAIL_PRIV . '</a> </div> <div class="clear"></div>'); } else { $fields[] = array('label' => constant(strtoupper($t->privtype)), 'type' => 'select', 'value' => $t->level, 'name' => $t->privtype, 'options' => array($l, 'id', 'name', 0), 'extra' => 'class="large"'); $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="clear"></div>'); } } } } // old value memo $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $t->level, 'name' => 'old_' . $t->privtype); } $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div>'); // if submitted if (X4Route_core::$post) { $e = X4Validation_helper::form($fields, 'editpriv'); if ($e) { $this->permitting($_POST); } else { $this->notice($fields); } die; } // contents $view = new X4View_core('editor'); $view->title = $id_area ? _EDIT_PRIV . ': ' . $u->username : _EDIT_PRIV . ': ' . _GLOBAL_PRIVS; // form builder $view->form = '<div id="scrolled">' . X4Form_helper::doform('editpriv', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editpriv\');"') . '</div>'; $view->js = ' <script> window.addEvent("domready", function() { buttonize("simple-modal", "btop", "modal"); var myScroll = new Scrollable($("scrolled")); }); </script>'; $view->render(TRUE); }