/** * 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) { /* Get the perms tree. */ $nodes = $this->_perms->getTree(); $perms_node = array('icon' => Horde_Themes::img('perms.png')); $add = Horde::url('admin/perms/addchild.php'); $add_img = Horde_Themes_Image::tag('plus.png', array('alt' => Horde_Core_Translation::t("Add Permission"))); $edit = Horde::url('admin/perms/edit.php'); $delete = Horde::url('admin/perms/delete.php'); $edit_img = Horde_Themes_Image::tag('edit.png', array('alt' => Horde_Core_Translation::t("Edit Permission"))); $delete_img = Horde_Themes_Image::tag('delete.png', array('alt' => Horde_Core_Translation::t("Delete Permission"))); $blank_img = Horde_Themes_Image::tag('blank.gif', array('attr' => array('width' => 16, 'height' => 16))); /* Set up the tree. */ $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', array('alternate' => true, 'hideHeaders' => true)); $tree->setHeader(array(array('class' => 'horde-tree-spacer'))); foreach ($nodes as $perm_id => $node) { $node_class = $current == $perm_id ? array('class' => 'selected') : array(); if ($perm_id == Horde_Perms::ROOT) { $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add New Permission"))) . $add_img . '</a>'; $base_node_params = array('icon' => Horde_Themes::img('administration.png')); $tree->addNode(array('id' => $perm_id, 'label' => Horde_Core_Translation::t("All Permissions"), 'expanded' => true, 'params' => $base_node_params + $node_class, 'right' => array($add_link))); } else { $parent_id = $this->_perms->getParent($node); $perms_extra = array(); $parents = explode(':', $node); if (!in_array($parents[0], $GLOBALS['registry']->listApps(array('notoolbar', 'active', 'hidden')))) { // 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->_corePerms->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 = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add Child Permission"))) . $add_img . '</a>'; $perms_extra[] = $add_link; } else { $perms_extra[] = $blank_img; } $edit_link = $edit->add('perm_id', $perm_id)->link(array('class' => 'permsEdit', 'title' => Horde_Core_Translation::t("Edit Permission"))) . $edit_img . '</a>'; $perms_extra[] = $edit_link; $delete_link = $delete->add('perm_id', $perm_id)->link(array('class' => 'permsDelete', 'title' => Horde_Core_Translation::t("Delete Permission"))) . $delete_img . '</a>'; $perms_extra[] = $delete_link; $name = $this->_corePerms->getTitle($node); $expanded = isset($nodes[$current]) && strpos($nodes[$current], $node) === 0 && $nodes[$current] != $node; $tree->addNode(array('id' => $perm_id, 'parent' => $parent_id, 'label' => $name, 'expanded' => $expanded, 'params' => $perms_node + $node_class, 'right' => $perms_extra)); } } $tree->sort('label'); return $tree->renderTree(); }