From: Michael M Slusarz Date: Sat, 15 May 2010 02:56:01 +0000 (-0600) Subject: Move Perms UI code to Core X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=b59a9a7f414dc3edc7d6fc0caf8396e38b1c4649;p=horde.git Move Perms UI code to Core --- diff --git a/framework/Core/lib/Horde/Core/Perms/Ui.php b/framework/Core/lib/Horde/Core/Perms/Ui.php new file mode 100644 index 000000000..b6659ee87 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Perms/Ui.php @@ -0,0 +1,538 @@ + + * @category Horde + * @package Core + */ +class Horde_Core_Perms_Ui +{ + /** + * The Horde_Perms object we're displaying UI stuff for. + * + * @var Horde_Perms + */ + protected $_perms; + + /** + * The Horde_Form object that will be used for displaying the edit form. + * + * @var Horde_Form + */ + protected $_form = null; + + /** + * The Horde_Variables object used in Horde_Form. + * + * @var Horde_Variables + */ + protected $_vars = null; + + /** + * The permission type. + * + * @var string + */ + protected $_type = 'matrix'; + + /** + * Constructor. + * + * @param Horde_Perms $perms The object to display UI stuff for. + */ + public function __construct($perms) + { + $this->_perms = $perms; + } + + /** + * Return a Horde_Tree representation of the permissions tree. + * + * @return string The html showing the permissions as a Horde_Tree. + * @throws Horde_Perms_Exception + */ + public function renderTree($current = Horde_Perms::ROOT) + { + global $registry; + + /* Get the perms tree. */ + $nodes = $this->_perms->getTree(); + + $icondir = array('icondir' => Horde_Themes::img()); + $perms_node = $icondir + array('icon' => 'perms.png'); + $add = Horde::applicationUrl('admin/perms/addchild.php'); + $add_img = Horde::img('add_perm.png', _("Add Permission")); + $edit = Horde::applicationUrl('admin/perms/edit.php'); + $delete = Horde::applicationUrl('admin/perms/delete.php'); + $edit_img = Horde::img('edit.png', _("Edit Permission")); + $delete_img = Horde::img('delete.png', _("Delete Permission")); + $blank_img = Horde::img('blank.gif', '', array('width' => 16, 'height' => 16)); + + /* Set up the tree. */ + $tree = Horde_Tree::singleton('perms_ui', 'Javascript'); + $tree->setOption(array('alternate' => true, 'hideHeaders' => true)); + $tree->setHeader(array(array('width' => '50%'))); + + foreach ($nodes as $perm_id => $node) { + $node_class = ($current == $perm_id) + ? array('class' => 'selected') + : array(); + if ($perm_id == Horde_Perms::ROOT) { + $add_link = Horde::link( + Horde_Util::addParameter($add, 'perm_id', $perm_id), + _("Add New Permission")) + . $add_img . ''; + $base_node_params = $icondir + + array('icon' => 'administration.png'); + + $tree->addNode($perm_id, null, _("All Permissions"), 0, true, + $base_node_params + $node_class, + array($add_link)); + } else { + $parent_id = $this->_perms->getParent($node); + + $perms_extra = array(); + $parents = explode(':', $node); + + if (!in_array($parents[0], $GLOBALS['registry']->listApps())) { + // This backend has permissions for an application that is + // not installed. Perhaps the application has been removed + // or the backend is shared with other Horde installations. + // Skip this app and do not include it in the tree. + continue; + } + + try { + $app_perms = $this->_perms->getApplicationPermissions($parents[0]); + } catch (Horde_Perms_Exception $e) { + $GLOBALS['notification']->push($e); + continue; + } + + if (isset($app_perms['tree']) && + is_array(Horde_Array::getElement($app_perms['tree'], $parents))) { + $add_link = Horde::link( + Horde_Util::addParameter($add, 'perm_id', $perm_id), + _("Add Child Permission")) + . $add_img . ''; + $perms_extra[] = $add_link; + } else { + $perms_extra[] = $blank_img; + } + + $edit_link = Horde::link( + Horde_Util::addParameter($edit, 'perm_id', $perm_id), + _("Edit Permission")) + . $edit_img . ''; + $perms_extra[] = $edit_link; + $delete_link = Horde::link( + Horde_Util::addParameter($delete, 'perm_id', $perm_id), + _("Delete Permission")) + . $delete_img . ''; + $perms_extra[] = $delete_link; + $name = $this->_perms->getTitle($node); + + $expanded = isset($nodes[$current]) && + strpos($nodes[$current], $node) === 0 && + $nodes[$current] != $node; + $tree->addNode($perm_id, $parent_id, $name, + substr_count($node, ':') + 1, $expanded, + $perms_node + $node_class, $perms_extra); + } + } + + $tree->sort('label'); + + return $tree->renderTree(); + } + + /** + * Set an existing form object to use for the edit form. + * + * @param Horde_Form $form An existing Horde_Form object to use. + */ + public function setForm(&$form) + { + $this->_form = $form; + } + + /** + * Set an existing vars object to use for the edit form. + * + * @param Horde_Variables $vars An existing Horde_Variables object to + * use. + */ + public function setVars($vars) + { + $this->_vars = $vars; + } + + /** + * Create a form to add a permission. + * + * @param Horde_Perms_Permission $permission Permission + * @param string $force_choice If the permission to be + * added can be one of many, + * setting this will force the + * choice to one particular. + */ + public function setupAddForm($permission, $force_choice = null) + { + /* Initialise form if required. */ + $this->_formInit(); + + $this->_form->setTitle(sprintf(_("Add a child permission to \"%s\""), $this->_perms->getTitle($permission->getName()))); + $this->_form->setButtons(_("Add")); + $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission)); + $this->_form->addHidden('', 'perm_id', 'text', false); + + /* Set up the actual child adding field. */ + $child_perms = $this->_perms->getAvailable($permission->getName()); + if ($child_perms === false) { + /* False, so no childs are to be added below this level. */ + $this->_form->addVariable(_("Permission"), 'child', 'invalid', true, false, null, array(_("No children can be added to this permission."))); + } elseif (is_array($child_perms)) { + if (!empty($force_choice)) { + /* Choice array available, but choice being forced. */ + $this->_vars->set('child', $force_choice); + $this->_form->addVariable(_("Permissions"), 'child', 'enum', true, true, null, array($child_perms)); + } else { + /* Choice array available, so set up enum field. */ + $this->_form->addVariable(_("Permissions"), 'child', 'enum', true, false, null, array($child_perms)); + } + } + } + + /** + * Function to validate any add form input. + * + * @param array &$info Ref to hold info from the form + * + * @return mixed Either false if the form does not validate correctly or + * an array with all the form values. + */ + public function validateAddForm(&$info) + { + if (!$this->_form->validate($this->_vars)) { + return false; + } + + $this->_form->getInfo($this->_vars, $info); + return true; + } + + /** + * Create a permission editing form. + * + * @param Horde_Perms_Permission $permission TODO + */ + public function setupEditForm($permission) + { + global $registry; + + /* Initialise form if required. */ + $this->_formInit(); + + $this->_form->setButtons(_("Update"), true); + $perm_id = $this->_perms->getPermissionId($permission); + $this->_form->addHidden('', 'perm_id', 'text', false); + + /* Get permission configuration. */ + $this->_type = $permission->get('type'); + $params = $permission->get('params'); + + /* Default permissions. */ + $perm_val = $permission->getDefaultPermissions(); + $this->_form->setSection('default', _("All Authenticated Users"), Horde::img('perms.png'), false); + + /* We MUST use 'deflt' for the variable name because 'default' is a + * reserved word in JavaScript. */ + if ($this->_type == 'matrix') { + /* Set up the columns for the permissions matrix. */ + $cols = Horde_Perms::getPermsArray(); + + /* Define a single matrix row for default perms. */ + $matrix = array(Horde_Perms::integerToArray($perm_val)); + $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + } else { + $var = $this->_form->addVariable('', 'deflt', $this->_type, false, false, null, $params); + $var->setDefault($perm_val); + } + + /* Guest permissions. */ + $perm_val = $permission->getGuestPermissions(); + $this->_form->setSection('guest', _("Guest Permissions"), '', false); + + if ($this->_type == 'matrix') { + /* Define a single matrix row for guest perms. */ + $matrix = array(Horde_Perms::integerToArray($perm_val)); + $this->_form->addVariable('', 'guest', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + } else { + $var = $this->_form->addVariable('', 'guest', $this->_type, false, false, null, $params); + $var->setDefault($perm_val); + } + + /* Object creator permissions. */ + $perm_val = $permission->getCreatorPermissions(); + $this->_form->setSection('creator', _("Creator Permissions"), Horde::img('user.png'), false); + + if ($this->_type == 'matrix') { + /* Define a single matrix row for creator perms. */ + $matrix = array(Horde_Perms::integerToArray($perm_val)); + $this->_form->addVariable('', 'creator', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); + } else { + $var = $this->_form->addVariable('', 'creator', $this->_type, false, false, null, $params); + $var->setDefault($perm_val); + } + + /* Users permissions. */ + $perm_val = $permission->getUserPermissions(); + $this->_form->setSection('users', _("Individual Users"), Horde::img('user.png'), false); + $auth = Horde_Auth::singleton($GLOBALS['conf']['auth']['driver']); + if ($auth->hasCapability('list')) { + /* The auth driver has list capabilities so set up an array which + * the matrix field type will recognise to set up an enum box for + * adding new users to the permissions matrix. */ + $new_users = array(); + + try { + $user_list = $auth->listUsers(); + sort($user_list); + foreach ($user_list as $user) { + if (!isset($perm_val[$user])) { + $new_users[$user] = $user; + } + } + } catch (Horde_Auth_Exception $e) { + $new_users = true; + } + } else { + /* No list capabilities, setting to true so that the matrix field + * type will offer a text input box for adding new users. */ + $new_users = true; + } + + if ($this->_type == 'matrix') { + /* Set up the matrix array, breaking up each permission integer + * into an array. The keys of this array will be the row + * headers. */ + $rows = array(); + $matrix = array(); + foreach ($perm_val as $u_id => $u_perms) { + $rows[$u_id] = $u_id; + $matrix[$u_id] = Horde_Perms::integerToArray($u_perms); + } + $this->_form->addVariable('', 'u', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_users)); + } else { + if ($new_users) { + if (is_array($new_users)) { + $u_n = Horde_Util::getFormData('u_n'); + $u_n = empty($u_n['u']) ? null : $u_n['u']; + $user_html = ''; + } else { + $user_html = ''; + } + $this->_form->addVariable($user_html, 'u_n[v]', $this->_type, false, false, null, $params); + } + foreach ($perm_val as $u_id => $u_perms) { + $var = $this->_form->addVariable($u_id, 'u_v[' . $u_id . ']', $this->_type, false, false, null, $params); + $var->setDefault($u_perms); + } + } + + /* Groups permissions. */ + $perm_val = $permission->getGroupPermissions(); + $this->_form->setSection('groups', _("Groups"), Horde::img('group.png'), false); + require_once 'Horde/Group.php'; + $groups = Group::singleton(); + $group_list = $groups->listGroups(); + if ($group_list instanceof PEAR_Error) { + $GLOBALS['notification']->push($group_list); + $group_list = array(); + } + + if (!empty($group_list)) { + /* There is an available list of groups so set up an array which + * the matrix field type will recognise to set up an enum box for + * adding new groups to the permissions matrix. */ + $new_groups = array(); + foreach ($group_list as $groupId => $group) { + if (!isset($perm_val[$groupId])) { + $new_groups[$groupId] = $group; + } + } + } else { + /* Do not offer a text box to add new groups. */ + $new_groups = false; + } + + if ($this->_type == 'matrix') { + /* Set up the matrix array, break up each permission integer into + * an array. The keys of this array will be the row headers. */ + $rows = array(); + $matrix = array(); + foreach ($perm_val as $g_id => $g_perms) { + $rows[$g_id] = isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id; + $matrix[$g_id] = Horde_Perms::integerToArray($g_perms); + } + $this->_form->addVariable('', 'g', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_groups)); + } else { + if ($new_groups) { + if (is_array($new_groups)) { + $g_n = Horde_Util::getFormData('g_n'); + $g_n = empty($g_n['g']) ? null : $g_n['g']; + $group_html = ''; + } else { + $group_html = ''; + } + $this->_form->addVariable($group_html, 'g_n[v]', $this->_type, false, false, null, $params); + } + foreach ($perm_val as $g_id => $g_perms) { + $var = &$this->_form->addVariable(isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id, 'g_v[' . $g_id . ']', $this->_type, false, false, null, $params); + $var->setDefault($g_perms); + } + } + + /* Set form title. */ + $this->_form->setTitle(sprintf(_("Edit permissions for \"%s\""), $this->_perms->getTitle($permission->getName()))); + } + + /** + * Function to validate any edit form input. + * + * @return mixed Either false if the form does not validate correctly or + * an array with all the form values. + */ + public function validateEditForm(&$info) + { + if (!$this->_form->validate($this->_vars)) { + return false; + } + + $this->_form->getInfo($this->_vars, $info); + + if ($this->_type == 'matrix') { + /* Collapse the array for default/guest/creator. */ + $info['deflt'] = isset($info['deflt'][0]) + ? $info['deflt'][0] + : null; + $info['guest'] = isset($info['guest'][0]) + ? $info['guest'][0] + : null; + $info['creator'] = isset($info['creator'][0]) + ? $info['creator'][0] + : null; + } else { + $u_n = $this->_vars->get('u_n'); + $info['u'] = array(); + if (!empty($u_n['u'])) { + $info['u'][$u_n['u']] = $info['u_n']['v']; + } + unset($info['u_n']); + if (isset($info['u_v'])) { + $info['u'] += $info['u_v']; + unset($info['u_v']); + } + $g_n = $this->_vars->get('g_n'); + $info['g'] = array(); + if (!empty($g_n['g'])) { + $info['g'][$g_n['g']] = $info['g_n']['v']; + } + unset($info['g_n']); + if (isset($info['g_v'])) { + $info['g'] += $info['g_v']; + unset($info['g_v']); + } + } + $info['default'] = $info['deflt']; + unset($info['deflt']); + + return true; + } + + /** + * Create a permission deleting form. + * + * @param Horde_Perms_Permission $permission A permissions object. + */ + public function setupDeleteForm($permission) + { + /* Initialise form if required. */ + $this->_formInit(); + + $this->_form->setTitle(sprintf(_("Delete permissions for \"%s\""), $this->_perms->getTitle($permission->getName()))); + $this->_form->setButtons(array(_("Delete"), _("Do not delete"))); + $this->_form->addHidden('', 'perm_id', 'text', false); + $this->_form->addVariable(sprintf(_("Delete permissions for \"%s\" and any sub-permissions?"), $this->_perms->getTitle($permission->getName())), 'prompt', 'description', false); + } + + /** + * Function to validate any delete form input. + * + * @param TODO $info TODO + * + * @return mixed If the delete button confirmation has been pressed return + * true, if any other submit button has been pressed return + * false. If form did not validate return null. + */ + public function validateDeleteForm($info) + { + $form_submit = $this->_vars->get('submitbutton'); + + if ($form_submit == _("Delete")) { + if ($this->_form->validate($this->_vars)) { + $this->_form->getInfo($this->_vars, $info); + return true; + } + } elseif (!empty($form_submit)) { + return false; + } + + return null; + } + + /** + * Renders the edit form. + */ + public function renderForm($form_script = 'edit.php') + { + $renderer = new Horde_Form_Renderer(); + $this->_form->renderActive($renderer, $this->_vars, $form_script, 'post'); + } + + /** + * Creates any form objects if they have not been initialised yet. + */ + protected function _formInit() + { + if (is_null($this->_vars)) { + /* No existing vars set, get them now. */ + $this->_vars = Horde_Variables::getDefaultVariables(); + } + + if (!($this->_form instanceof Horde_Form)) { + /* No existing valid form object set so set up a new one. */ + $this->_form = new Horde_Form($this->_vars); + } + } + +} diff --git a/framework/Core/package.xml b/framework/Core/package.xml index 6290539cb..0239c9aad 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -37,7 +37,8 @@ Application Framework. beta LGPL - * Import prefs UI handling class from Horde_Prefs. + * Import perms UI handling class from horde/Perms. + * Import prefs UI handling class from horde/Prefs. * Convert from PEAR Log to Horde_Log for logging. * Add Horde_Themes:: class. * Add Horde::nocacheUrl(). @@ -103,6 +104,9 @@ Application Framework. + + + @@ -255,6 +259,7 @@ Application Framework. + diff --git a/framework/Perms/lib/Horde/Perms/Ui.php b/framework/Perms/lib/Horde/Perms/Ui.php deleted file mode 100644 index e4188d782..000000000 --- a/framework/Perms/lib/Horde/Perms/Ui.php +++ /dev/null @@ -1,538 +0,0 @@ - - * @category Horde - * @package Horde_Perms - */ -class Horde_Perms_Ui -{ - /** - * The Horde_Perms object we're displaying UI stuff for. - * - * @var Horde_Perms - */ - protected $_perms; - - /** - * The Horde_Form object that will be used for displaying the edit form. - * - * @var Horde_Form - */ - protected $_form = null; - - /** - * The Horde_Variables object used in Horde_Form. - * - * @var Horde_Variables - */ - protected $_vars = null; - - /** - * The permission type. - * - * @var string - */ - protected $_type = 'matrix'; - - /** - * Constructor. - * - * @param Horde_Perms $perms The object to display UI stuff for. - */ - public function __construct($perms) - { - $this->_perms = $perms; - } - - /** - * Return a Horde_Tree representation of the permissions tree. - * - * @return string The html showing the permissions as a Horde_Tree. - * @throws Horde_Perms_Exception - */ - public function renderTree($current = Horde_Perms::ROOT) - { - global $registry; - - /* Get the perms tree. */ - $nodes = $this->_perms->getTree(); - - $icondir = array('icondir' => Horde_Themes::img()); - $perms_node = $icondir + array('icon' => 'perms.png'); - $add = Horde::applicationUrl('admin/perms/addchild.php'); - $add_img = Horde::img('add_perm.png', _("Add Permission")); - $edit = Horde::applicationUrl('admin/perms/edit.php'); - $delete = Horde::applicationUrl('admin/perms/delete.php'); - $edit_img = Horde::img('edit.png', _("Edit Permission")); - $delete_img = Horde::img('delete.png', _("Delete Permission")); - $blank_img = Horde::img('blank.gif', '', array('width' => 16, 'height' => 16)); - - /* Set up the tree. */ - $tree = Horde_Tree::singleton('perms_ui', 'Javascript'); - $tree->setOption(array('alternate' => true, 'hideHeaders' => true)); - $tree->setHeader(array(array('width' => '50%'))); - - foreach ($nodes as $perm_id => $node) { - $node_class = ($current == $perm_id) - ? array('class' => 'selected') - : array(); - if ($perm_id == Horde_Perms::ROOT) { - $add_link = Horde::link( - Horde_Util::addParameter($add, 'perm_id', $perm_id), - _("Add New Permission")) - . $add_img . ''; - $base_node_params = $icondir + - array('icon' => 'administration.png'); - - $tree->addNode($perm_id, null, _("All Permissions"), 0, true, - $base_node_params + $node_class, - array($add_link)); - } else { - $parent_id = $this->_perms->getParent($node); - - $perms_extra = array(); - $parents = explode(':', $node); - - if (!in_array($parents[0], $GLOBALS['registry']->listApps())) { - // This backend has permissions for an application that is - // not installed. Perhaps the application has been removed - // or the backend is shared with other Horde installations. - // Skip this app and do not include it in the tree. - continue; - } - - try { - $app_perms = $this->_perms->getApplicationPermissions($parents[0]); - } catch (Horde_Perms_Exception $e) { - $GLOBALS['notification']->push($e); - continue; - } - - if (isset($app_perms['tree']) && - is_array(Horde_Array::getElement($app_perms['tree'], $parents))) { - $add_link = Horde::link( - Horde_Util::addParameter($add, 'perm_id', $perm_id), - _("Add Child Permission")) - . $add_img . ''; - $perms_extra[] = $add_link; - } else { - $perms_extra[] = $blank_img; - } - - $edit_link = Horde::link( - Horde_Util::addParameter($edit, 'perm_id', $perm_id), - _("Edit Permission")) - . $edit_img . ''; - $perms_extra[] = $edit_link; - $delete_link = Horde::link( - Horde_Util::addParameter($delete, 'perm_id', $perm_id), - _("Delete Permission")) - . $delete_img . ''; - $perms_extra[] = $delete_link; - $name = $this->_perms->getTitle($node); - - $expanded = isset($nodes[$current]) && - strpos($nodes[$current], $node) === 0 && - $nodes[$current] != $node; - $tree->addNode($perm_id, $parent_id, $name, - substr_count($node, ':') + 1, $expanded, - $perms_node + $node_class, $perms_extra); - } - } - - $tree->sort('label'); - - return $tree->renderTree(); - } - - /** - * Set an existing form object to use for the edit form. - * - * @param Horde_Form $form An existing Horde_Form object to use. - */ - public function setForm(&$form) - { - $this->_form = $form; - } - - /** - * Set an existing vars object to use for the edit form. - * - * @param Horde_Variables $vars An existing Horde_Variables object to - * use. - */ - public function setVars($vars) - { - $this->_vars = $vars; - } - - /** - * Create a form to add a permission. - * - * @param Horde_Perms_Permission $permission Permission - * @param string $force_choice If the permission to be - * added can be one of many, - * setting this will force the - * choice to one particular. - */ - public function setupAddForm($permission, $force_choice = null) - { - /* Initialise form if required. */ - $this->_formInit(); - - $this->_form->setTitle(sprintf(_("Add a child permission to \"%s\""), $this->_perms->getTitle($permission->getName()))); - $this->_form->setButtons(_("Add")); - $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission)); - $this->_form->addHidden('', 'perm_id', 'text', false); - - /* Set up the actual child adding field. */ - $child_perms = $this->_perms->getAvailable($permission->getName()); - if ($child_perms === false) { - /* False, so no childs are to be added below this level. */ - $this->_form->addVariable(_("Permission"), 'child', 'invalid', true, false, null, array(_("No children can be added to this permission."))); - } elseif (is_array($child_perms)) { - if (!empty($force_choice)) { - /* Choice array available, but choice being forced. */ - $this->_vars->set('child', $force_choice); - $this->_form->addVariable(_("Permissions"), 'child', 'enum', true, true, null, array($child_perms)); - } else { - /* Choice array available, so set up enum field. */ - $this->_form->addVariable(_("Permissions"), 'child', 'enum', true, false, null, array($child_perms)); - } - } - } - - /** - * Function to validate any add form input. - * - * @param array &$info Ref to hold info from the form - * - * @return mixed Either false if the form does not validate correctly or - * an array with all the form values. - */ - public function validateAddForm(&$info) - { - if (!$this->_form->validate($this->_vars)) { - return false; - } - - $this->_form->getInfo($this->_vars, $info); - return true; - } - - /** - * Create a permission editing form. - * - * @param Horde_Perms_Permission $permission TODO - */ - public function setupEditForm($permission) - { - global $registry; - - /* Initialise form if required. */ - $this->_formInit(); - - $this->_form->setButtons(_("Update"), true); - $perm_id = $this->_perms->getPermissionId($permission); - $this->_form->addHidden('', 'perm_id', 'text', false); - - /* Get permission configuration. */ - $this->_type = $permission->get('type'); - $params = $permission->get('params'); - - /* Default permissions. */ - $perm_val = $permission->getDefaultPermissions(); - $this->_form->setSection('default', _("All Authenticated Users"), Horde::img('perms.png'), false); - - /* We MUST use 'deflt' for the variable name because 'default' is a - * reserved word in JavaScript. */ - if ($this->_type == 'matrix') { - /* Set up the columns for the permissions matrix. */ - $cols = Horde_Perms::getPermsArray(); - - /* Define a single matrix row for default perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); - } else { - $var = $this->_form->addVariable('', 'deflt', $this->_type, false, false, null, $params); - $var->setDefault($perm_val); - } - - /* Guest permissions. */ - $perm_val = $permission->getGuestPermissions(); - $this->_form->setSection('guest', _("Guest Permissions"), '', false); - - if ($this->_type == 'matrix') { - /* Define a single matrix row for guest perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'guest', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); - } else { - $var = $this->_form->addVariable('', 'guest', $this->_type, false, false, null, $params); - $var->setDefault($perm_val); - } - - /* Object creator permissions. */ - $perm_val = $permission->getCreatorPermissions(); - $this->_form->setSection('creator', _("Creator Permissions"), Horde::img('user.png'), false); - - if ($this->_type == 'matrix') { - /* Define a single matrix row for creator perms. */ - $matrix = array(Horde_Perms::integerToArray($perm_val)); - $this->_form->addVariable('', 'creator', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix)); - } else { - $var = $this->_form->addVariable('', 'creator', $this->_type, false, false, null, $params); - $var->setDefault($perm_val); - } - - /* Users permissions. */ - $perm_val = $permission->getUserPermissions(); - $this->_form->setSection('users', _("Individual Users"), Horde::img('user.png'), false); - $auth = Horde_Auth::singleton($GLOBALS['conf']['auth']['driver']); - if ($auth->hasCapability('list')) { - /* The auth driver has list capabilities so set up an array which - * the matrix field type will recognise to set up an enum box for - * adding new users to the permissions matrix. */ - $new_users = array(); - - try { - $user_list = $auth->listUsers(); - sort($user_list); - foreach ($user_list as $user) { - if (!isset($perm_val[$user])) { - $new_users[$user] = $user; - } - } - } catch (Horde_Auth_Exception $e) { - $new_users = true; - } - } else { - /* No list capabilities, setting to true so that the matrix field - * type will offer a text input box for adding new users. */ - $new_users = true; - } - - if ($this->_type == 'matrix') { - /* Set up the matrix array, breaking up each permission integer - * into an array. The keys of this array will be the row - * headers. */ - $rows = array(); - $matrix = array(); - foreach ($perm_val as $u_id => $u_perms) { - $rows[$u_id] = $u_id; - $matrix[$u_id] = Horde_Perms::integerToArray($u_perms); - } - $this->_form->addVariable('', 'u', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_users)); - } else { - if ($new_users) { - if (is_array($new_users)) { - $u_n = Horde_Util::getFormData('u_n'); - $u_n = empty($u_n['u']) ? null : $u_n['u']; - $user_html = ''; - } else { - $user_html = ''; - } - $this->_form->addVariable($user_html, 'u_n[v]', $this->_type, false, false, null, $params); - } - foreach ($perm_val as $u_id => $u_perms) { - $var = $this->_form->addVariable($u_id, 'u_v[' . $u_id . ']', $this->_type, false, false, null, $params); - $var->setDefault($u_perms); - } - } - - /* Groups permissions. */ - $perm_val = $permission->getGroupPermissions(); - $this->_form->setSection('groups', _("Groups"), Horde::img('group.png'), false); - require_once 'Horde/Group.php'; - $groups = Group::singleton(); - $group_list = $groups->listGroups(); - if ($group_list instanceof PEAR_Error) { - $GLOBALS['notification']->push($group_list); - $group_list = array(); - } - - if (!empty($group_list)) { - /* There is an available list of groups so set up an array which - * the matrix field type will recognise to set up an enum box for - * adding new groups to the permissions matrix. */ - $new_groups = array(); - foreach ($group_list as $groupId => $group) { - if (!isset($perm_val[$groupId])) { - $new_groups[$groupId] = $group; - } - } - } else { - /* Do not offer a text box to add new groups. */ - $new_groups = false; - } - - if ($this->_type == 'matrix') { - /* Set up the matrix array, break up each permission integer into - * an array. The keys of this array will be the row headers. */ - $rows = array(); - $matrix = array(); - foreach ($perm_val as $g_id => $g_perms) { - $rows[$g_id] = isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id; - $matrix[$g_id] = Horde_Perms::integerToArray($g_perms); - } - $this->_form->addVariable('', 'g', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_groups)); - } else { - if ($new_groups) { - if (is_array($new_groups)) { - $g_n = Horde_Util::getFormData('g_n'); - $g_n = empty($g_n['g']) ? null : $g_n['g']; - $group_html = ''; - } else { - $group_html = ''; - } - $this->_form->addVariable($group_html, 'g_n[v]', $this->_type, false, false, null, $params); - } - foreach ($perm_val as $g_id => $g_perms) { - $var = &$this->_form->addVariable(isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id, 'g_v[' . $g_id . ']', $this->_type, false, false, null, $params); - $var->setDefault($g_perms); - } - } - - /* Set form title. */ - $this->_form->setTitle(sprintf(_("Edit permissions for \"%s\""), $this->_perms->getTitle($permission->getName()))); - } - - /** - * Function to validate any edit form input. - * - * @return mixed Either false if the form does not validate correctly or - * an array with all the form values. - */ - public function validateEditForm(&$info) - { - if (!$this->_form->validate($this->_vars)) { - return false; - } - - $this->_form->getInfo($this->_vars, $info); - - if ($this->_type == 'matrix') { - /* Collapse the array for default/guest/creator. */ - $info['deflt'] = isset($info['deflt'][0]) - ? $info['deflt'][0] - : null; - $info['guest'] = isset($info['guest'][0]) - ? $info['guest'][0] - : null; - $info['creator'] = isset($info['creator'][0]) - ? $info['creator'][0] - : null; - } else { - $u_n = $this->_vars->get('u_n'); - $info['u'] = array(); - if (!empty($u_n['u'])) { - $info['u'][$u_n['u']] = $info['u_n']['v']; - } - unset($info['u_n']); - if (isset($info['u_v'])) { - $info['u'] += $info['u_v']; - unset($info['u_v']); - } - $g_n = $this->_vars->get('g_n'); - $info['g'] = array(); - if (!empty($g_n['g'])) { - $info['g'][$g_n['g']] = $info['g_n']['v']; - } - unset($info['g_n']); - if (isset($info['g_v'])) { - $info['g'] += $info['g_v']; - unset($info['g_v']); - } - } - $info['default'] = $info['deflt']; - unset($info['deflt']); - - return true; - } - - /** - * Create a permission deleting form. - * - * @param Horde_Perms_Permission $permission A permissions object. - */ - public function setupDeleteForm($permission) - { - /* Initialise form if required. */ - $this->_formInit(); - - $this->_form->setTitle(sprintf(_("Delete permissions for \"%s\""), $this->_perms->getTitle($permission->getName()))); - $this->_form->setButtons(array(_("Delete"), _("Do not delete"))); - $this->_form->addHidden('', 'perm_id', 'text', false); - $this->_form->addVariable(sprintf(_("Delete permissions for \"%s\" and any sub-permissions?"), $this->_perms->getTitle($permission->getName())), 'prompt', 'description', false); - } - - /** - * Function to validate any delete form input. - * - * @param TODO $info TODO - * - * @return mixed If the delete button confirmation has been pressed return - * true, if any other submit button has been pressed return - * false. If form did not validate return null. - */ - public function validateDeleteForm($info) - { - $form_submit = $this->_vars->get('submitbutton'); - - if ($form_submit == _("Delete")) { - if ($this->_form->validate($this->_vars)) { - $this->_form->getInfo($this->_vars, $info); - return true; - } - } elseif (!empty($form_submit)) { - return false; - } - - return null; - } - - /** - * Renders the edit form. - */ - public function renderForm($form_script = 'edit.php') - { - $renderer = new Horde_Form_Renderer(); - $this->_form->renderActive($renderer, $this->_vars, $form_script, 'post'); - } - - /** - * Creates any form objects if they have not been initialised yet. - */ - protected function _formInit() - { - if (is_null($this->_vars)) { - /* No existing vars set, get them now. */ - $this->_vars = Horde_Variables::getDefaultVariables(); - } - - if (!($this->_form instanceof Horde_Form)) { - /* No existing valid form object set so set up a new one. */ - $this->_form = new Horde_Form($this->_vars); - } - } - -} diff --git a/framework/Perms/package.xml b/framework/Perms/package.xml index 96bdf93f6..dc9c39dc5 100644 --- a/framework/Perms/package.xml +++ b/framework/Perms/package.xml @@ -30,7 +30,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial Horde 4 package. + * Eliminated horde/Core dependency. + * Initial Horde 4 package. @@ -45,7 +46,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - @@ -78,7 +78,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org - Horde_Tree + Tree pear.horde.org @@ -91,7 +91,6 @@ http://pear.php.net/dtd/package-2.0.xsd"> - diff --git a/horde/admin/perms/addchild.php b/horde/admin/perms/addchild.php index 9534404f1..a6f52086d 100644 --- a/horde/admin/perms/addchild.php +++ b/horde/admin/perms/addchild.php @@ -27,7 +27,7 @@ try { } /* Set up form. */ -$ui = new Horde_Perms_Ui($perms); +$ui = new Horde_Core_Perms_Ui($perms); $ui->setVars($vars); $ui->setupAddForm($permission); diff --git a/horde/admin/perms/delete.php b/horde/admin/perms/delete.php index 35560b305..5ec3c365f 100644 --- a/horde/admin/perms/delete.php +++ b/horde/admin/perms/delete.php @@ -28,7 +28,7 @@ try { } /* Set up form. */ -$ui = new Horde_Perms_Ui($perms); +$ui = new Horde_Core_Perms_Ui($perms); $ui->setVars($vars); $ui->setupDeleteForm($permission); diff --git a/horde/admin/perms/edit.php b/horde/admin/perms/edit.php index 7fb277551..d755fb0ea 100644 --- a/horde/admin/perms/edit.php +++ b/horde/admin/perms/edit.php @@ -94,7 +94,7 @@ if ($category !== null) { } } -$ui = new Horde_Perms_Ui($perms); +$ui = new Horde_Core_Perms_Ui($perms); $ui->setVars($vars); $ui->setupEditForm($permission); diff --git a/horde/admin/perms/index.php b/horde/admin/perms/index.php index 93c14c6c6..3fbcf7aa5 100644 --- a/horde/admin/perms/index.php +++ b/horde/admin/perms/index.php @@ -18,7 +18,7 @@ $title = _("Permissions Administration"); require HORDE_TEMPLATES . '/common-header.inc'; require HORDE_TEMPLATES . '/admin/menu.inc'; -$ui = new Horde_Perms_Ui($injector->getInstance('Horde_Perms')); +$ui = new Horde_Core_Perms_Ui($injector->getInstance('Horde_Perms')); echo '

' . Horde::img('perms.png') . ' ' . _("Permissions") . '

'; $ui->renderTree($perm_id);