Overview

Packages

  • Auth
  • Core
  • Horde
    • Imsp
  • None
  • Notification

Classes

  • Horde
  • Horde_Config
  • Horde_Config_Form
  • Horde_Core_ActiveSync_Connector
  • Horde_Core_ActiveSync_Driver
  • Horde_Core_Ajax_Application
  • Horde_Core_Ajax_Imple
  • Horde_Core_Ajax_Imple_AutoCompleter
  • Horde_Core_Ajax_Imple_Geocoder_Geonames
  • Horde_Core_Ajax_Imple_SpellChecker
  • Horde_Core_Alarm_Handler_Notify
  • Horde_Core_Auth_Application
  • Horde_Core_Auth_Composite
  • Horde_Core_Auth_Ldap
  • Horde_Core_Auth_Msad
  • Horde_Core_Auth_Shibboleth
  • Horde_Core_Auth_Signup_Base
  • Horde_Core_Auth_Signup_Form
  • Horde_Core_Auth_Signup_Null
  • Horde_Core_Auth_Signup_Sql
  • Horde_Core_Auth_Signup_SqlObject
  • Horde_Core_Autoloader_Callback_Mime
  • Horde_Core_Autoloader_Callback_Nls
  • Horde_Core_Block
  • Horde_Core_Block_Collection
  • Horde_Core_Block_Layout
  • Horde_Core_Block_Layout_Manager
  • Horde_Core_Block_Layout_View
  • Horde_Core_Block_Upgrade
  • Horde_Core_Browser
  • Horde_Core_Bundle
  • Horde_Core_Cli
  • Horde_Core_Controller_NotFound
  • Horde_Core_Controller_RequestConfiguration
  • Horde_Core_Controller_RequestMapper
  • Horde_Core_Controller_SettingsFinder
  • Horde_Core_Db_Migration
  • Horde_Core_Factory_ActiveSyncBackend
  • Horde_Core_Factory_ActiveSyncServer
  • Horde_Core_Factory_ActiveSyncState
  • Horde_Core_Factory_Ajax
  • Horde_Core_Factory_Alarm
  • Horde_Core_Factory_Auth
  • Horde_Core_Factory_AuthSignup
  • Horde_Core_Factory_Base
  • Horde_Core_Factory_BlockCollection
  • Horde_Core_Factory_Browser
  • Horde_Core_Factory_Cache
  • Horde_Core_Factory_Crypt
  • Horde_Core_Factory_Data
  • Horde_Core_Factory_Db
  • Horde_Core_Factory_DbBase
  • Horde_Core_Factory_DbPear
  • Horde_Core_Factory_Dns
  • Horde_Core_Factory_Editor
  • Horde_Core_Factory_Facebook
  • Horde_Core_Factory_Group
  • Horde_Core_Factory_History
  • Horde_Core_Factory_HttpClient
  • Horde_Core_Factory_Identity
  • Horde_Core_Factory_Image
  • Horde_Core_Factory_Imple
  • Horde_Core_Factory_Imsp
  • Horde_Core_Factory_ImspAuth
  • Horde_Core_Factory_Injector
  • Horde_Core_Factory_KolabServer
  • Horde_Core_Factory_KolabSession
  • Horde_Core_Factory_KolabStorage
  • Horde_Core_Factory_Ldap
  • Horde_Core_Factory_Lock
  • Horde_Core_Factory_Logger
  • Horde_Core_Factory_LoginTasks
  • Horde_Core_Factory_Mail
  • Horde_Core_Factory_Mapper
  • Horde_Core_Factory_Matcher
  • Horde_Core_Factory_Memcache
  • Horde_Core_Factory_MimeViewer
  • Horde_Core_Factory_Notification
  • Horde_Core_Factory_Perms
  • Horde_Core_Factory_PermsCore
  • Horde_Core_Factory_Prefs
  • Horde_Core_Factory_Request
  • Horde_Core_Factory_Secret
  • Horde_Core_Factory_SessionHandler
  • Horde_Core_Factory_Share
  • Horde_Core_Factory_ShareBase
  • Horde_Core_Factory_Template
  • Horde_Core_Factory_TextFilter
  • Horde_Core_Factory_ThemesCache
  • Horde_Core_Factory_Token
  • Horde_Core_Factory_Tree
  • Horde_Core_Factory_Twitter
  • Horde_Core_Factory_UrlShortener
  • Horde_Core_Factory_Vfs
  • Horde_Core_Factory_View
  • Horde_Core_Factory_Weather
  • Horde_Core_Group_Ldap
  • Horde_Core_Log_Logger
  • Horde_Core_LoginTasks
  • Horde_Core_LoginTasks_Backend_Horde
  • Horde_Core_LoginTasks_SystemTask_Upgrade
  • Horde_Core_Mime_Viewer_Syntaxhighlighter
  • Horde_Core_Mime_Viewer_Vcard
  • Horde_Core_Notification_Event_Status
  • Horde_Core_Notification_Handler_Decorator_Hordelog
  • Horde_Core_Notification_Storage_Session
  • Horde_Core_Perms
  • Horde_Core_Perms_Ui
  • Horde_Core_Prefs_Cache_Session
  • Horde_Core_Prefs_Identity
  • Horde_Core_Prefs_Storage_Configuration
  • Horde_Core_Prefs_Storage_Hooks
  • Horde_Core_Prefs_Storage_Upgrade
  • Horde_Core_Prefs_Ui
  • Horde_Core_Prefs_Ui_Widgets
  • Horde_Core_Share_Driver
  • Horde_Core_Share_FactoryCallback
  • Horde_Core_Sidebar
  • Horde_Core_Text_Filter_Bbcode
  • Horde_Core_Text_Filter_Emails
  • Horde_Core_Text_Filter_Emoticons
  • Horde_Core_Text_Filter_Highlightquotes
  • Horde_Core_Translation
  • Horde_Core_Tree_Html
  • Horde_Core_Tree_Javascript
  • Horde_Core_Tree_Simplehtml
  • Horde_Core_Ui_FlagImage
  • Horde_Core_Ui_JsCalendar
  • Horde_Core_Ui_Language
  • Horde_Core_Ui_Layout
  • Horde_Core_Ui_ModalFormRenderer
  • Horde_Core_Ui_Pager
  • Horde_Core_Ui_Tabs
  • Horde_Core_Ui_TagCloud
  • Horde_Core_Ui_VarRenderer
  • Horde_Core_Ui_VarRenderer_Html
  • Horde_Core_Ui_VarRenderer_TablesetHtml
  • Horde_Core_Ui_Widget
  • Horde_ErrorHandler
  • Horde_Help
  • Horde_Menu
  • Horde_Registry
  • Horde_Registry_Api
  • Horde_Registry_Application
  • Horde_Registry_Caller
  • Horde_Registry_Nlsconfig
  • Horde_Script_Files
  • Horde_Session
  • Horde_Session_Null
  • Horde_Themes
  • Horde_Themes_Cache
  • Horde_Themes_Css
  • Horde_Themes_Element
  • Horde_Themes_Image
  • Horde_Themes_Sound

Exceptions

  • Horde_Exception_HookNotSet
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Core_Perms_Ui class provides UI methods for the Horde permissions
  4:  * system.
  5:  *
  6:  * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author   Chuck Hagenbuch <chuck@horde.org>
 12:  * @category Horde
 13:  * @package  Core
 14:  */
 15: class Horde_Core_Perms_Ui
 16: {
 17:     /**
 18:      * The Horde_Perms object we're displaying UI stuff for.
 19:      *
 20:      * @var Horde_Perms_Base
 21:      */
 22:     protected $_perms;
 23: 
 24:     /**
 25:      * The Horde_Core_Perms object we're displaying UI stuff for.
 26:      *
 27:      * @var Horde_Core_Perms
 28:      */
 29:     protected $_corePerms;
 30: 
 31:     /**
 32:      * The Horde_Form object that will be used for displaying the edit form.
 33:      *
 34:      * @var Horde_Form
 35:      */
 36:     protected $_form = null;
 37: 
 38:     /**
 39:      * The Horde_Variables object used in Horde_Form.
 40:      *
 41:      * @var Horde_Variables
 42:      */
 43:     protected $_vars = null;
 44: 
 45:     /**
 46:      * The permission type.
 47:      *
 48:      * @var string
 49:      */
 50:     protected $_type = 'matrix';
 51: 
 52:     /**
 53:      * Constructor.
 54:      *
 55:      * @param Horde_Perms_Base $perms  The object to display UI stuff for.
 56:      * @param Horde_Core_Perms_Base $corePerms
 57:      */
 58:     public function __construct(Horde_Perms_Base $perms,
 59:                                 Horde_Core_Perms $corePerms)
 60:     {
 61:         $this->_perms = $perms;
 62:         $this->_corePerms = $corePerms;
 63:     }
 64: 
 65:     /**
 66:      * Return a Horde_Tree representation of the permissions tree.
 67:      *
 68:      * @return string  The html showing the permissions as a Horde_Tree.
 69:      * @throws Horde_Perms_Exception
 70:      */
 71:     public function renderTree($current = Horde_Perms::ROOT)
 72:     {
 73:         global $registry;
 74: 
 75:         /* Get the perms tree. */
 76:         $nodes = $this->_perms->getTree();
 77: 
 78:         $perms_node = array('icon' => Horde_Themes::img('perms.png'));
 79:         $add = Horde::url('admin/perms/addchild.php');
 80:         $add_img = Horde::img('add_perm.png', Horde_Core_Translation::t("Add Permission"));
 81:         $edit = Horde::url('admin/perms/edit.php');
 82:         $delete = Horde::url('admin/perms/delete.php');
 83:         $edit_img = Horde::img('edit.png', Horde_Core_Translation::t("Edit Permission"));
 84:         $delete_img = Horde::img('delete.png', Horde_Core_Translation::t("Delete Permission"));
 85:         $blank_img = Horde::img('blank.gif', '', array('width' => 16, 'height' => 16));
 86: 
 87:         /* Set up the tree. */
 88:         $tree = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Tree')->create('perms_ui', 'Javascript', array(
 89:             'alternate' => true,
 90:             'hideHeaders' => true
 91:         ));
 92:         $tree->setHeader(array(
 93:             array(
 94:                 'class' => 'treeHdrSpacer'
 95:             )
 96:         ));
 97: 
 98:         foreach ($nodes as $perm_id => $node) {
 99:             $node_class = ($current == $perm_id)
100:                 ? array('class' => 'selected')
101:                 : array();
102:             if ($perm_id == Horde_Perms::ROOT) {
103:                 $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add New Permission"))) . $add_img . '</a>';
104:                 $base_node_params = array('icon' => Horde_Themes::img('administration.png'));
105: 
106:                 $tree->addNode($perm_id, null, Horde_Core_Translation::t("All Permissions"), 0, true,
107:                                $base_node_params + $node_class,
108:                                array($add_link));
109:             } else {
110:                 $parent_id = $this->_perms->getParent($node);
111: 
112:                 $perms_extra = array();
113:                 $parents = explode(':', $node);
114: 
115:                 if (!in_array($parents[0], $GLOBALS['registry']->listApps(array('notoolbar', 'active', 'hidden')))) {
116:                     // This backend has permissions for an application that is
117:                     // not installed.  Perhaps the application has been removed
118:                     // or the backend is shared with other Horde installations.
119:                     // Skip this app and do not include it in the tree.
120:                     continue;
121:                 }
122: 
123:                 try {
124:                     $app_perms = $this->_corePerms->getApplicationPermissions($parents[0]);
125:                 } catch (Horde_Perms_Exception $e) {
126:                     $GLOBALS['notification']->push($e);
127:                     continue;
128:                 }
129: 
130:                 if (isset($app_perms['tree']) &&
131:                     is_array(Horde_Array::getElement($app_perms['tree'], $parents))) {
132:                     $add_link = $add->add('perm_id', $perm_id)->link(array('class' => 'permsAdd', 'title' => Horde_Core_Translation::t("Add Child Permission"))) . $add_img . '</a>';
133:                     $perms_extra[] = $add_link;
134:                 } else {
135:                     $perms_extra[] = $blank_img;
136:                 }
137: 
138:                 $edit_link = $edit->add('perm_id', $perm_id)->link(array('class' => 'permsEdit', 'title' => Horde_Core_Translation::t("Edit Permission"))) . $edit_img . '</a>';
139:                 $perms_extra[] = $edit_link;
140:                 $delete_link = $delete->add('perm_id', $perm_id)->link(array('class' => 'permsDelete', 'title' => Horde_Core_Translation::t("Delete Permission"))) . $delete_img . '</a>';
141:                 $perms_extra[] = $delete_link;
142:                 $name = $this->_corePerms->getTitle($node);
143: 
144:                 $expanded = isset($nodes[$current]) &&
145:                     strpos($nodes[$current], $node) === 0 &&
146:                     $nodes[$current] != $node;
147:                 $tree->addNode($perm_id, $parent_id, $name,
148:                                substr_count($node, ':') + 1, $expanded,
149:                                $perms_node + $node_class, $perms_extra);
150:             }
151:         }
152: 
153:         $tree->sort('label');
154: 
155:         return $tree->renderTree();
156:     }
157: 
158:     /**
159:      * Set an existing form object to use for the edit form.
160:      *
161:      * @param Horde_Form $form  An existing Horde_Form object to use.
162:      */
163:     public function setForm(&$form)
164:     {
165:         $this->_form = $form;
166:     }
167: 
168:     /**
169:      * Set an existing vars object to use for the edit form.
170:      *
171:      * @param Horde_Variables $vars  An existing Horde_Variables object to
172:      *                               use.
173:      */
174:     public function setVars($vars)
175:     {
176:         $this->_vars = $vars;
177:     }
178: 
179:     /**
180:      * Create a form to add a permission.
181:      *
182:      * @param Horde_Perms_Permission $permission  Permission
183:      * @param string $force_choice                If the permission to be
184:      *                                            added can be one of many,
185:      *                                            setting this will force the
186:      *                                            choice to one particular.
187:      */
188:     public function setupAddForm($permission, $force_choice = null)
189:     {
190:         /* Initialise form if required. */
191:         $this->_formInit();
192: 
193:         $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Add a child permission to \"%s\""), $this->_corePerms->getTitle($permission->getName())));
194:         $this->_form->setButtons(Horde_Core_Translation::t("Add"));
195:         $this->_vars->set('perm_id', $this->_perms->getPermissionId($permission));
196:         $this->_form->addHidden('', 'perm_id', 'text', false);
197: 
198:         /* Set up the actual child adding field. */
199:         $child_perms = $this->_corePerms->getAvailable($permission->getName());
200:         if ($child_perms === false) {
201:             /* False, so no childs are to be added below this level. */
202:             $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.")));
203:         } elseif (is_array($child_perms)) {
204:             if (!empty($force_choice)) {
205:                 /* Choice array available, but choice being forced. */
206:                 $this->_vars->set('child', $force_choice);
207:                 $this->_form->addVariable(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, true, null, array($child_perms));
208:             } else {
209:                 /* Choice array available, so set up enum field. */
210:                 $prefix = $permission->getName() . ':';
211:                 $length = strlen($prefix);
212:                 foreach ($this->_perms->getTree() as $name) {
213:                     if (strpos($name, $prefix) === 0) {
214:                         unset($child_perms[substr($name, $length)]);
215:                     }
216:                 }
217:                 $this->_form->addVariable(Horde_Core_Translation::t("Permissions"), 'child', 'enum', true, false, null, array($child_perms));
218:             }
219:         }
220:     }
221: 
222:     /**
223:      * Function to validate any add form input.
224:      *
225:      * @param array &$info  Ref to hold info from the form
226:      *
227:      * @return mixed  Either false if the form does not validate correctly or
228:      *                an array with all the form values.
229:      */
230:     public function validateAddForm(&$info)
231:     {
232:         if (!$this->_form->validate($this->_vars)) {
233:             return false;
234:         }
235: 
236:         $this->_form->getInfo($this->_vars, $info);
237:         return true;
238:     }
239: 
240:     /**
241:      * Create a permission editing form.
242:      *
243:      * @param Horde_Perms_Permission $permission  TODO
244:      */
245:     public function setupEditForm($permission)
246:     {
247:         global $registry;
248: 
249:         /* Initialise form if required. */
250:         $this->_formInit();
251: 
252:         $this->_form->setButtons(Horde_Core_Translation::t("Update"), true);
253:         $perm_id = $this->_perms->getPermissionId($permission);
254:         $this->_form->addHidden('', 'perm_id', 'text', false);
255: 
256:         /* Get permission configuration. */
257:         $this->_type = $permission->get('type');
258:         $params = $permission->get('params');
259: 
260:         /* Default permissions. */
261:         $perm_val = $permission->getDefaultPermissions();
262:         $this->_form->setSection('default', Horde_Core_Translation::t("All Authenticated Users"), Horde::img('perms.png'), false);
263: 
264:         /* We MUST use 'deflt' for the variable name because 'default' is a
265:          * reserved word in JavaScript. */
266:         if ($this->_type == 'matrix') {
267:             /* Set up the columns for the permissions matrix. */
268:             $cols = Horde_Perms::getPermsArray();
269: 
270:             /* Define a single matrix row for default perms. */
271:             $matrix = array(Horde_Perms::integerToArray($perm_val));
272:             $this->_form->addVariable('', 'deflt', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix));
273:         } else {
274:             $var = $this->_form->addVariable('', 'deflt', $this->_type, false, false, null, $params);
275:             $var->setDefault($perm_val);
276:         }
277: 
278:         /* Guest permissions. */
279:         $perm_val = $permission->getGuestPermissions();
280:         $this->_form->setSection('guest', Horde_Core_Translation::t("Guest Permissions"), '', false);
281: 
282:         if ($this->_type == 'matrix') {
283:             /* Define a single matrix row for guest perms. */
284:             $matrix = array(Horde_Perms::integerToArray($perm_val));
285:             $this->_form->addVariable('', 'guest', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix));
286:         } else {
287:             $var = $this->_form->addVariable('', 'guest', $this->_type, false, false, null, $params);
288:             $var->setDefault($perm_val);
289:         }
290: 
291:         /* Object creator permissions. */
292:         $perm_val = $permission->getCreatorPermissions();
293:         $this->_form->setSection('creator', Horde_Core_Translation::t("Creator Permissions"), Horde::img('user.png'), false);
294: 
295:         if ($this->_type == 'matrix') {
296:             /* Define a single matrix row for creator perms. */
297:             $matrix = array(Horde_Perms::integerToArray($perm_val));
298:             $this->_form->addVariable('', 'creator', 'matrix', false, false, null, array($cols, array(0 => ''), $matrix));
299:         } else {
300:             $var = $this->_form->addVariable('', 'creator', $this->_type, false, false, null, $params);
301:             $var->setDefault($perm_val);
302:         }
303: 
304:         /* Users permissions. */
305:         $perm_val = $permission->getUserPermissions();
306:         $this->_form->setSection('users', Horde_Core_Translation::t("Individual Users"), Horde::img('user.png'), false);
307:         $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create();
308:         if ($auth->hasCapability('list')) {
309:             /* The auth driver has list capabilities so set up an array which
310:              * the matrix field type will recognise to set up an enum box for
311:              * adding new users to the permissions matrix. */
312:             $new_users = array();
313: 
314:             try {
315:                 $user_list = $auth->listUsers();
316:                 sort($user_list);
317:                 foreach ($user_list as $user) {
318:                     if (!isset($perm_val[$user])) {
319:                         $new_users[$user] = $user;
320:                     }
321:                 }
322:             } catch (Horde_Auth_Exception $e) {
323:                 $new_users = true;
324:             }
325:         } else {
326:             /* No list capabilities, setting to true so that the matrix field
327:              * type will offer a text input box for adding new users. */
328:             $new_users = true;
329:         }
330: 
331:         if ($this->_type == 'matrix') {
332:             /* Set up the matrix array, breaking up each permission integer
333:              * into an array.  The keys of this array will be the row
334:              * headers. */
335:             $rows = array();
336:             $matrix = array();
337:             foreach ($perm_val as $u_id => $u_perms) {
338:                 $rows[$u_id] = $u_id;
339:                 $matrix[$u_id] = Horde_Perms::integerToArray($u_perms);
340:             }
341:             $this->_form->addVariable('', 'u', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_users));
342:         } else {
343:             if ($new_users) {
344:                 if (is_array($new_users)) {
345:                     $u_n = Horde_Util::getFormData('u_n');
346:                     $u_n = empty($u_n['u']) ? null : $u_n['u'];
347:                     $user_html = '<select name="u_n[u]"><option value="">' . Horde_Core_Translation::t("-- select --") . '</option>';
348:                     foreach ($new_users as $new_user) {
349:                         $user_html .= '<option value="' . $new_user . '"';
350:                         $user_html .= $u_n == $new_user ? ' selected="selected"' : '';
351:                         $user_html .= '>' . htmlspecialchars($new_user) . '</option>';
352:                     }
353:                     $user_html .= '</select>';
354:                 } else {
355:                     $user_html = '<input type="text" name="u_n[u]" />';
356:                 }
357:                 $this->_form->addVariable($user_html, 'u_n[v]', $this->_type, false, false, null, $params);
358:             }
359:             foreach ($perm_val as $u_id => $u_perms) {
360:                 $var = $this->_form->addVariable($u_id, 'u_v[' . $u_id . ']', $this->_type, false, false, null, $params);
361:                 $var->setDefault($u_perms);
362:             }
363:         }
364: 
365:         /* Groups permissions. */
366:         $perm_val = $permission->getGroupPermissions();
367:         $this->_form->setSection('groups', Horde_Core_Translation::t("Groups"), Horde::img('group.png'), false);
368:         try {
369:             $group_list = $GLOBALS['injector']
370:                 ->getInstance('Horde_Group')
371:                 ->listAll();
372:         } catch (Horde_Group_Exception $e) {
373:             $GLOBALS['notification']->push($e);
374:             $group_list = array();
375:         }
376: 
377:         if (!empty($group_list)) {
378:             /* There is an available list of groups so set up an array which
379:              * the matrix field type will recognise to set up an enum box for
380:              * adding new groups to the permissions matrix. */
381:             $new_groups = array();
382:             foreach ($group_list as $groupId => $group) {
383:                 if (!isset($perm_val[$groupId])) {
384:                     $new_groups[$groupId] = $group;
385:                 }
386:             }
387:         } else {
388:             /* Do not offer a text box to add new groups. */
389:             $new_groups = false;
390:         }
391: 
392:         if ($this->_type == 'matrix') {
393:             /* Set up the matrix array, break up each permission integer into
394:              * an array. The keys of this array will be the row headers. */
395:             $rows = array();
396:             $matrix = array();
397:             foreach ($perm_val as $g_id => $g_perms) {
398:                 $rows[$g_id] = isset($group_list[$g_id]) ? $group_list[$g_id] : $g_id;
399:                 $matrix[$g_id] = Horde_Perms::integerToArray($g_perms);
400:             }
401:             $this->_form->addVariable('', 'g', 'matrix', false, false, null, array($cols, $rows, $matrix, $new_groups));
402:         } else {
403:             if ($new_groups) {
404:                 if (is_array($new_groups)) {
405:                     $g_n = Horde_Util::getFormData('g_n');
406:                     $g_n = empty($g_n['g']) ? null : $g_n['g'];
407:                     $group_html = '<select name="g_n[g]"><option value="">' . Horde_Core_Translation::t("-- select --") . '</option>';
408:                     foreach ($new_groups as $groupId => $group) {
409:                         $group_html .= '<option value="' . $groupId . '"';
410:                         $group_html .= $g_n == $groupId ? ' selected="selected"' : '';
411:                         $group_html .= '>' . htmlspecialchars($group) . '</option>';
412:                     }
413:                     $group_html .= '</select>';
414:                 } else {
415:                     $group_html = '<input type="text" name="g_n[g]" />';
416:                 }
417:                 $this->_form->addVariable($group_html, 'g_n[v]', $this->_type, false, false, null, $params);
418:             }
419:             foreach ($perm_val as $g_id => $g_perms) {
420:                 $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);
421:                 $var->setDefault($g_perms);
422:             }
423:         }
424: 
425:         /* Set form title. */
426:         $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Edit permissions for \"%s\""), $this->_corePerms->getTitle($permission->getName())));
427:     }
428: 
429:     /**
430:      * Function to validate any edit form input.
431:      *
432:      * @return mixed  Either false if the form does not validate correctly or
433:      *                an array with all the form values.
434:      */
435:     public function validateEditForm(&$info)
436:     {
437:         if (!$this->_form->validate($this->_vars)) {
438:             return false;
439:         }
440: 
441:         $this->_form->getInfo($this->_vars, $info);
442: 
443:         if ($this->_type == 'matrix') {
444:             /* Collapse the array for default/guest/creator. */
445:             $info['deflt'] = isset($info['deflt'][0])
446:                 ? $info['deflt'][0]
447:                 : null;
448:             $info['guest'] = isset($info['guest'][0])
449:                 ? $info['guest'][0]
450:                 : null;
451:             $info['creator'] = isset($info['creator'][0])
452:                 ? $info['creator'][0]
453:                 : null;
454:         } else {
455:             $u_n = $this->_vars->get('u_n');
456:             $info['u'] = array();
457:             if (!empty($u_n['u'])) {
458:                 $info['u'][$u_n['u']] = $info['u_n']['v'];
459:             }
460:             unset($info['u_n']);
461:             if (isset($info['u_v'])) {
462:                 $info['u'] += $info['u_v'];
463:                 unset($info['u_v']);
464:             }
465:             $g_n = $this->_vars->get('g_n');
466:             $info['g'] = array();
467:             if (!empty($g_n['g'])) {
468:                 $info['g'][$g_n['g']] = $info['g_n']['v'];
469:             }
470:             unset($info['g_n']);
471:             if (isset($info['g_v'])) {
472:                 $info['g'] += $info['g_v'];
473:                 unset($info['g_v']);
474:             }
475:         }
476:         $info['default'] = $info['deflt'];
477:         unset($info['deflt']);
478: 
479:         return true;
480:     }
481: 
482:     /**
483:      * Create a permission deleting form.
484:      *
485:      * @param Horde_Perms_Permission $permission  A permissions object.
486:      */
487:     public function setupDeleteForm($permission)
488:     {
489:         /* Initialise form if required. */
490:         $this->_formInit();
491: 
492:         $this->_form->setTitle(sprintf(Horde_Core_Translation::t("Delete permissions for \"%s\""), $this->_corePerms->getTitle($permission->getName())));
493:         $this->_form->setButtons(array(Horde_Core_Translation::t("Delete"), Horde_Core_Translation::t("Do not delete")));
494:         $this->_form->addHidden('', 'perm_id', 'text', false);
495:         $this->_form->addVariable(sprintf(Horde_Core_Translation::t("Delete permissions for \"%s\" and any sub-permissions?"), $this->_corePerms->getTitle($permission->getName())), 'prompt', 'description', false);
496:     }
497: 
498:     /**
499:      * Function to validate any delete form input.
500:      *
501:      * @param TODO $info  TODO
502:      *
503:      * @return mixed  If the delete button confirmation has been pressed return
504:      *                true, if any other submit button has been pressed return
505:      *                false. If form did not validate return null.
506:      */
507:     public function validateDeleteForm(&$info)
508:     {
509:         $form_submit = $this->_vars->get('submitbutton');
510: 
511:         if ($form_submit == Horde_Core_Translation::t("Delete")) {
512:             if ($this->_form->validate($this->_vars)) {
513:                 $this->_form->getInfo($this->_vars, $info);
514:                 return true;
515:             }
516:         } elseif (!empty($form_submit)) {
517:             return false;
518:         }
519: 
520:         return null;
521:     }
522: 
523:     /**
524:      * Renders the edit form.
525:      */
526:     public function renderForm($form_script = 'edit.php')
527:     {
528:         $renderer = new Horde_Form_Renderer();
529:         $this->_form->renderActive($renderer, $this->_vars, $form_script, 'post');
530:     }
531: 
532:     /**
533:      * Creates any form objects if they have not been initialised yet.
534:      */
535:     protected function _formInit()
536:     {
537:         if (is_null($this->_vars)) {
538:             /* No existing vars set, get them now. */
539:             $this->_vars = Horde_Variables::getDefaultVariables();
540:         }
541: 
542:         if (!($this->_form instanceof Horde_Form)) {
543:             /* No existing valid form object set so set up a new one. */
544:             $this->_form = new Horde_Form($this->_vars);
545:         }
546:     }
547: 
548: }
549: 
API documentation generated by ApiGen