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:  * Collection of prefs UI widgets for use with application-specific (a/k/a
  4:  * 'special') configuration.
  5:  *
  6:  * Copyright 2010-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   Michael Slusarz <slusarz@horde.org>
 12:  * @category Horde
 13:  * @package  Core
 14:  */
 15: class Horde_Core_Prefs_Ui_Widgets
 16: {
 17:     /* Source selection widget. */
 18: 
 19:     /**
 20:      * Code to run on init.
 21:      */
 22:     static public function sourceInit()
 23:     {
 24:         Horde::addScriptFile('sourceselect.js', 'horde');
 25:     }
 26: 
 27:     /**
 28:      * Create code needed for source selection.
 29:      *
 30:      * @param array $data  Data items:
 31:      * <pre>
 32:      * 'mainlabel' - (string) Main label.
 33:      * 'no_up' - (boolean) [OPTIONAL] Disable movement of selected items
 34:      *           up/down.
 35:      * 'selectlabel' - (array) Selected label.
 36:      * 'sourcelabel' - (string) [OPTIONAL] Source selection label.
 37:      * 'sources' - (array) List of sources - keys are source names. Each
 38:      *             source is an array with two entries - selected and
 39:      *             unselected.
 40:      * 'unselectlabel' - (array) Unselected label.
 41:      * </pre>
 42:      *
 43:      * @return string  HTML UI code.
 44:      */
 45:     static public function source($data)
 46:     {
 47:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
 48: 
 49:         $t->set('mainlabel', $data['mainlabel']);
 50:         $t->set('selectlabel', $data['selectlabel']);
 51:         $t->set('unselectlabel', $data['unselectlabel']);
 52: 
 53:         $sources = array();
 54:         foreach ($data['sources'] as $key => $val) {
 55:             $selected = $unselected = array();
 56: 
 57:             foreach ($val['selected'] as $key2 => $val2) {
 58:                 $selected[] = array(
 59:                     'l' => $val2,
 60:                     'v' => $key2
 61:                 );
 62:             }
 63: 
 64:             foreach ($val['unselected'] as $key2 => $val2) {
 65:                 $unselected[] = array(
 66:                     'l' => $val2,
 67:                     'v' => $key2
 68:                 );
 69:             }
 70: 
 71:             $sources[$key] = array($selected, $unselected);
 72:         }
 73: 
 74:         if (count($sources) == 1) {
 75:             $val = reset($sources);
 76:             $t->set('selected', $val[0]);
 77:             $t->set('unselected', $val[1]);
 78:         } else {
 79:             $js = array();
 80:             foreach ($sources as $key => $val) {
 81:                 $js[] = array(
 82:                     'selected' => $val[0],
 83:                     'source' => $key,
 84:                     'unselected' => $val[1]
 85:                 );
 86:             }
 87:             Horde::addInlineJsVars(array(
 88:                 'HordeSourceSelectPrefs.source_list' => $js
 89:             ));
 90:         }
 91: 
 92:         $t->set('addimg', Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'lhand.png' : 'rhand.png', Horde_Core_Translation::t("Add source")));
 93:         $t->set('removeimg', Horde::img($GLOBALS['registry']->nlsconfig->curr_rtl ? 'rhand.png' : 'lhand.png', Horde_Core_Translation::t("Remove source")));
 94: 
 95:         if (empty($data['no_up'])) {
 96:             $t->set('upimg', Horde::img('nav/up.png', Horde_Core_Translation::t("Move up")));
 97:             $t->set('downimg', Horde::img('nav/down.png', Horde_Core_Translation::t("Move down")));
 98:         }
 99: 
100:         return $t->fetch($GLOBALS['registry']->get('templates', 'horde') . '/prefs/source.html');
101:     }
102: 
103:     /**
104:      * Process form data for source selection.
105:      *
106:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
107:      *
108:      * @return array  If only one source was originally given, contains the
109:      *                list of selected values (JSON encoded). If multiple
110:      *                sources were given, this variable will contain a list of
111:      *                arrays; each subarray contains the source name and the
112:      *                list of selected values (JSON encoded).
113:      */
114:     static public function sourceUpdate($ui)
115:     {
116:         $out = array();
117: 
118:         if (isset($ui->vars->sources)) {
119:             $out['sources'] = $ui->vars->sources;
120:         }
121: 
122:         return $out;
123:     }
124: 
125:     /* Addressbook selection widget. Extends the source widget to handle
126:      * the special case of addressbook selection. */
127: 
128:     /**
129:      * Code to run on init for addressbook selection.
130:      */
131:     static public function addressbooksInit()
132:     {
133:         self::sourceInit();
134:         Horde::addScriptFile('addressbooksprefs.js', 'horde');
135:     }
136: 
137:     /**
138:      * Create code needed for addressbook selection.
139:      *
140:      * @param array $data  Data items:
141:      * <pre>
142:      * 'fields' - (array) Hash containing addressbook sources as keys and an
143:      *            array of search fields as values.
144:      * 'sources' - (array) List of selected addressbooks.
145:      * </pre>
146:      *
147:      * @return string  HTML UI code.
148:      */
149:     static public function addressbooks($data)
150:     {
151:         global $prefs, $registry;
152: 
153:         $selected = $unselected = array();
154:         $out = '';
155: 
156:         if (!$registry->hasMethod('contacts/sources') ||
157:             $prefs->isLocked('search_sources')) {
158:             return;
159:         }
160: 
161:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
162:         $t->setOption('gettext', true);
163: 
164:         try {
165:             $readable = $registry->call('contacts/sources');
166:         } catch (Horde_Exception $e) {
167:             $readable = array();
168:         }
169: 
170:         try {
171:             $writeable = $registry->call('contacts/sources', array(true));
172:         } catch (Horde_Exception $e) {
173:             $writeable = array();
174:         }
175: 
176:         if (count($readable) == 1) {
177:             // Only one source, no need to display the selection widget
178:             $data['sources'] = array_keys($readable);
179:         }
180: 
181:         foreach ($data['sources'] as $source) {
182:             if (!empty($readable[$source])) {
183:                 $selected[$source] = $readable[$source];
184:             }
185:         }
186: 
187:         foreach (array_diff(array_keys($readable), $data['sources']) as $val) {
188:             $unselected[$val] = $readable[$val];
189:         }
190: 
191:         if (!empty($selected) || !empty($unselected)) {
192:             $out = Horde_Core_Prefs_Ui_Widgets::source(array(
193:                   'mainlabel' => Horde_Core_Translation::t("Choose the order of address books to search when expanding addresses."),
194:                   'selectlabel' => Horde_Core_Translation::t("Selected address books:"),
195:                   'sources' => array(array(
196:                       'selected' => $selected,
197:                       'unselected' => $unselected
198:                   )),
199:                   'unselectlabel' => Horde_Core_Translation::t("Available address books:")
200:              ));
201: 
202:             $t->set('selected', count($unselected) > 1);
203: 
204:             $js = array();
205:             foreach (array_keys($readable) as $source) {
206:                 $tmp = $tmpsel = array();
207: 
208:                 try {
209:                     foreach ($registry->call('contacts/fields', array($source)) as $field) {
210:                         if ($field['search']) {
211:                             $tmp[] = array(
212:                                 'name' => $field['name'],
213:                                 'label' => $field['label']
214:                             );
215:                             if (isset($data['fields'][$source]) &&
216:                                 in_array($field['name'], $data['fields'][$source])) {
217:                                 $tmpsel[] = $field['name'];
218:                             }
219:                         }
220:                     }
221:                 } catch (Horde_Exception $e) {}
222: 
223:                 $js[$source] = array(
224:                     'entries' => $tmp,
225:                     'selected' => $tmpsel
226:                 );
227:             }
228: 
229:             Horde::addInlineJsVars(array(
230:                 'HordeAddressbooksPrefs.fields' => $js,
231:                 'HordeAddressbooksPrefs.nonetext' => Horde_Core_Translation::t("No address book selected.")
232:             ));
233:         }
234: 
235:         return $out . $t->fetch($GLOBALS['registry']->get('templates', 'horde') . '/prefs/addressbooks.html');
236:     }
237: 
238:     /**
239:      * Process form data for address book selection.
240:      *
241:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
242:      *
243:      * @return array  Array with two possible keys: sources and fields.
244:      *                Sources contains the list of selected addressbooks (JSON
245:      *                encoded). Fields contains a hash containing sources as
246:      *                keys and an array of search fields as the value.
247:      */
248:     static public function addressbooksUpdate($ui)
249:     {
250:         $out = self::sourceUpdate($ui);
251: 
252:         if (isset($ui->vars->sources)) {
253:             $out['sources'] = $ui->vars->sources;
254:         }
255: 
256:         if (isset($ui->vars->search_fields)) {
257:             $out['fields'] = $ui->vars->search_fields;
258:         }
259: 
260:         return $out;
261:     }
262: 
263:     /* Alarms selection widget. */
264: 
265:     /**
266:      * Code to run on init for alarms selection.
267:      */
268:     static public function alarmInit()
269:     {
270:         Horde::addScriptFile('alarmprefs.js', 'horde');
271:     }
272: 
273:     /**
274:      * Create code needed for alarm selection.
275:      *
276:      * @param array $data  Data items:
277:      * - 'helplink': (string) [OPTIONAL] Help link.
278:      * - 'label': (string) Label.
279:      * - 'pref': (string) Preference name.
280:      * - 'value': (array) [OPTIONAL] Preference value.
281:      *
282:      * @return string  HTML UI code.
283:      */
284:     static public function alarm($data)
285:     {
286:         $pref = $data['pref'];
287: 
288:         Horde::addInlineJsVars(array(
289:             'HordeAlarmPrefs.pref' => $pref
290:         ));
291: 
292:         $alarm_pref = isset($data['value'])
293:             ? $data['value']
294:             : unserialize($GLOBALS['prefs']->getValue($pref));
295:         $selected = array_keys($alarm_pref);
296: 
297:         $t = $GLOBALS['injector']->createInstance('Horde_Template');
298:         $t->setOption('gettext', true);
299: 
300:         $param_list = $select_list = array();
301: 
302:         foreach ($GLOBALS['injector']->getInstance('Horde_Alarm')->handlers() as $method => $handler) {
303:             $select_list[] = array(
304:                 'l' => $handler->getDescription(),
305:                 's' => in_array($method, $selected),
306:                 'v' => $method
307:             );
308: 
309:             $tmp = array(
310:                 'method' => $method,
311:                 'param' => array()
312:             );
313: 
314:             foreach ($handler->getParameters() as $name => $param) {
315:                 switch ($param['type']) {
316:                 case 'text':
317:                     $tmp['param'][] = array(
318:                         'label' => Horde::label($pref . '_' . $name, $param['desc']),
319:                         'name' => $pref . '_' . $name,
320:                         'text' => true,
321:                         'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name])
322:                         );
323:                     break;
324: 
325:                 case 'bool':
326:                     $tmp['param'][] = array(
327:                         'bool' => true,
328:                         'checked' => !empty($alarm_pref[$method][$name]),
329:                         'label' => Horde::label($pref . '_' . $name, $param['desc']),
330:                         'name' => $pref . '_' . $name
331:                     );
332:                     break;
333: 
334:                 case 'sound':
335:                     $current_sound = empty($alarm_pref[$method][$name])
336:                         ? ''
337:                         : $alarm_pref[$method][$name];
338:                     $sounds = array();
339:                     foreach (Horde_Themes::soundList() as $key => $val) {
340:                         $sounds[] = array(
341:                             'c' => ($current_sound == $key),
342:                             'uri' => htmlspecialchars($val->uri),
343:                             'val' => htmlspecialchars($key)
344:                         );
345:                     }
346:                     $t->set('sounds', $sounds);
347: 
348:                     $tmp['param'][] = array(
349:                         'sound' => true,
350:                         'checked' => !$current_sound,
351:                         'name' => $pref . '_' . $name
352:                     );
353:                     break;
354:                 }
355:             }
356: 
357:             $param_list[] = $tmp;
358:         }
359: 
360:         $t->set('desc', Horde::label($pref, $data['label']));
361:         if (!empty($data['helplink'])) {
362:             $t->set('helplink', $data['helplink']);
363:         }
364:         $t->set('pref', htmlspecialchars($pref));
365:         $t->set('param_list', $param_list);
366:         $t->set('select_list', $select_list);
367: 
368:         return $t->fetch($GLOBALS['registry']->get('templates', 'horde') . '/prefs/alarm.html');
369:     }
370: 
371:     /**
372:      * Process form data for alarm selection.
373:      *
374:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
375:      * @param array $data              Data items:
376:      * <pre>
377:      * 'pref' - (string) Preference name.
378:      * </pre>
379:      *
380:      * @return array  TODO
381:      */
382:     static public function alarmUpdate($ui, $data)
383:     {
384:         $pref = $data['pref'];
385:         $methods = $GLOBALS['injector']->getInstance('Horde_Alarm')->handlers();
386:         $val = (isset($ui->vars->$pref) && is_array($ui->vars->$pref))
387:             ? $ui->vars->$pref
388:             : array();
389:         $value = array();
390: 
391:         foreach ($val as $method) {
392:             $value[$method] = array();
393:             if (!empty($methods[$method])) {
394:                 foreach ($methods[$method]->getParameters() as $param => $info) {
395:                     $value[$method][$param] = $ui->vars->get($pref . '_' . $param, '');
396:                     if ($info['required'] && ($value[$method][$param] === '')) {
397:                         $GLOBALS['notification']->push(sprintf(Horde_Core_Translation::t("You must provide a setting for \"%s\"."), $methods[$method]->getDescription()), 'horde.error');
398:                         return null;
399:                     }
400:                 }
401:             }
402:         }
403: 
404:         return $value;
405:     }
406: 
407: }
408: 
API documentation generated by ApiGen