* * See the enclosed file COPYING for license information (LGPL). If you did * not receive this file, see http://www.fsf.org/copyleft/lgpl.html. * * @author Joel Vandal * @package Horde **/ @define('HORDE_BASE', dirname(__FILE__) . '/../..') ; require_once HORDE_BASE . '/lib/base.php'; if (!Auth::isAdmin()) { Horde::authenticationFailureRedirect(); } /* Set up the form variables. */ require_once 'Horde/Variables.php'; $vars = &Variables::getDefaultVariables(); $user_name = $vars->get('user_name'); $f_user_name = Auth::removeHook($user_name); require_once 'Horde/Form.php'; require_once 'Horde/UI/VarRenderer.php'; require_once 'Horde/Tree.php'; require_once 'Horde/DataTree.php'; require HORDE_TEMPLATES . '/common-header.inc'; $title = _("Edit Permissions"); /* Set up the form object. */ $form = Horde_Form::singleton('', $vars, null); $tree = &Horde_Tree::factory('perms_user', 'html'); $tree->setOption('alternate', true); $tree->setOption('querystring', true); /* Get list of active applications */ $apps = $registry->listApps(array('notoolbar', 'active', 'hidden'), true); $nodes = array(); foreach (array_keys($apps) as $app) { /* Get permissions tree for each application */ $_perms = $perms->getApplicationPermissions($app); if (!isset($_perms['title'])) { continue; } $app_name = $registry->get('name', $app); addNode($app, $app_name); $nodes[$app] = $app_name; foreach($_perms['title'] as $node => $tag) { addNode($node, $tag); $nodes[$node] = $tag; } } if ($vars->get('formname') == 'edit') { $form->validate($vars); if ($form->isValid()) { $form->getInfo($vars, $info); foreach ($nodes as $node => $t) { if (isset($info[$node])) { $val = $info[$node]; $npermission = &$perms->getPermission($node); if (is_array($val)) { if (isset($val[0][PERMS_SHOW])) { $npermission->addUserPermission($f_user_name, PERMS_SHOW, false); } else { $npermission->removeUserPermission($f_user_name, PERMS_SHOW, false); } if (isset($val[0][PERMS_READ])) { $npermission->addUserPermission($f_user_name, PERMS_READ, false); } else { $npermission->removeUserPermission($f_user_name, PERMS_READ, false); } if (isset($val[0][PERMS_EDIT])) { $npermission->addUserPermission($f_user_name, PERMS_EDIT, false); } else { $npermission->removeUserPermission($f_user_name, PERMS_EDIT, false); } if (isset($val[0][PERMS_DELETE])) { $npermission->addUserPermission($f_user_name, PERMS_DELETE, false); } else { $npermission->removeUserPermission($f_user_name, PERMS_DELETE, false); } } else { $npermission->addUserPermission($f_user_name, $val, false); } $npermission->save(); } } $notification->push(_("Permissions saved."), 'horde.success'); $url = Horde::selfUrl(true); header('Location: ' . $url); exit; } } require HORDE_TEMPLATES . '/admin/user/perms.inc'; require $registry->get('templates', 'horde') . '/common-footer.inc'; function addNode($node, $title) { global $perms, $user_name, $vars, $tree, $form, $_perms; $level = substr_count($node, ':') + 1; $parent_id = implode(':', array_slice(explode(':', $node), 0, -1)); $parent_id = (!empty($parent_id)) ? $parent_id : null; $permission = &$perms->getPermission($node, $user_name); if (is_a($permission, 'PEAR_Error')) { /* Check to see if the permission we are copying from exists before we * autocreate. */ $permission = &$perms->newPermission($node); $result = $perms->addPermission($permission, $parent_id); if (!is_a($result, 'PEAR_Error')) { $perm_id = $perms->getPermissionId($permission); } $permission->save(); } else { $userperms = $permission->getUserPermissions(); $perm_val = null; if (isset($userperms[$user_name])) { $perm_val = $userperms[$user_name]; } } $type = isset($_perms['type'][$node]) ? $_perms['type'][$node] : 'matrix'; /* Get type and create variable */ switch($type) { case 'matrix': /* Define a single matrix row for perms. */ $matrix = array(); $matrix[0] = Perms::integerToArray($perm_val); $cols = Perms::getPermsArray(); $params = array($cols, array(0 => ''), $matrix); break; default: $params = array(); break; } $vtype = Horde_Form::getType($type, $params); $var = &new Horde_Form_Variable($node, $node, $vtype, false, false, null); $var->setDefault($perm_val); /* Render the variable */ $varRenderer = &Horde_UI_VarRenderer::singleton('html'); $ntype = "_renderVarInput_$type"; $extra = $varRenderer->$ntype($form, $var, $vars, true); $extra = sprintf('
%s
', 250, $extra); $form->addVariable($node, $node, $type, false, false, null, $params); /* Add node to the tree */ $tree->addNode($node, $parent_id, $title, $level, false, $params, $extra); }