/** * 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(Horde_Core_Translation::t("Add a child permission to \"%s\""), $this->_corePerms->getTitle($permission->getName()))); $this->_form->setButtons(Horde_Core_Translation::t("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->_corePerms->getAvailable($permission->getName()); if ($child_perms === false) { /* False, so no childs are to be added below this level. */ $this->_form->addVariable(Horde_Core_Translation::t("Permission"), 'child', 'invalid', true, false, null, array(Horde_Core_Translation::t("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(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, true, null, array($child_perms)); } else { /* Choice array available, so set up enum field. */ $prefix = $permission->getName() . ':'; $length = strlen($prefix); foreach ($this->_perms->getTree() as $name) { if (strpos($name, $prefix) === 0) { unset($child_perms[substr($name, $length)]); } } $this->_form->addVariable(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, false, null, array($child_perms)); } } }