/* Run through the action handlers */
foreach ($preflist as $pref) {
switch ($this->prefs[$pref]['type']) {
- case 'alarm':
- $methods = Horde_Alarm::notificationMethods();
- $val = (isset($this->vars->$pref) && is_array($this->vars->$pref))
- ? $this->vars->$pref
- : array();
- $value = array();
-
- foreach ($val as $method) {
- $value[$method] = array();
- if (!empty($methods[$method])) {
- foreach (array_keys($methods[$method]) as $param) {
- $value[$method][$param] = $this->vars->get($pref . '_' . $param, '');
- if (is_array($methods[$method][$param]) &&
- $methods[$method][$param]['required'] &&
- ($value[$method][$param] === '')) {
- $notification->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method][$param]['desc']), 'horde.error');
- break 3;
- }
- }
- }
- }
-
- $updated |= $prefs->setValue($pref, serialize($value));
- break;
-
case 'checkbox':
$updated |= $prefs->setValue($pref, intval(isset($this->vars->$pref)));
break;
$type = $this->prefs[$pref]['type'];
switch ($type) {
- case 'alarm':
- Horde::addScriptFile('alarmprefs.js', 'horde');
- Horde::addInlineScript(array(
- 'HordeAlarmPrefs.pref = ' . Horde_Serialize::serialize($pref, Horde_Serialize::JSON)
- ));
-
- $alarm_pref = unserialize($prefs->getValue($pref));
- $selected = array_keys($alarm_pref);
-
- $param_list = $select_list = array();
- foreach (Horde_Alarm::notificationMethods() as $method => $params) {
- $select_list[] = array(
- 'l' => $params['__desc'],
- 's' => in_array($method, $selected),
- 'v' => $method
- );
-
- if (count($params > 1)) {
- $tmp = array(
- 'method' => $method,
- 'param' => array()
- );
-
- foreach ($params as $name => $param) {
- if (substr($name, 0, 2) == '__') {
- continue;
- }
-
- switch ($param['type']) {
- case 'text':
- $tmp['param'][] = array(
- 'label' => Horde::label($pref . '_' . $name, $param['desc']),
- 'name' => $pref . '_' . $name,
- 'text' => true,
- 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name])
- );
- break;
-
- case 'bool':
- $tmp['param'][] = array(
- 'bool' => true,
- 'checked' => !empty($alarm_pref[$method][$name]),
- 'label' => Horde::label($pref . '_' . $name, $param['desc']),
- 'name' => $pref . '_' . $name
- );
- break;
-
- case 'sound':
- $current_sound = empty($alarm_pref[$method][$name])
- ? ''
- : $alarm_pref[$method][$name];
- $sounds = array();
- foreach (Horde_Themes::soundList() as $key => $val) {
- $sounds[] = array(
- 'c' => ($current_sound == $key),
- 'uri' => htmlspecialchars($val->uri),
- 'val' => htmlspecialchars($key)
- );
- }
-
- $tmp['param'][] = array(
- 'sound' => true,
- 'checked' => !$current_sound,
- 'name' => $pref . '_' . $name
- );
- break;
- }
- }
-
- $param_list[] = $tmp;
- }
- }
- $t->set('param_list', $param_list);
- $t->set('select_list', $select_list);
- break;
-
case 'checkbox':
$t->set('checked', $prefs->getValue($pref));
break;
return $out . $t->fetch(HORDE_TEMPLATES . '/prefs/addressbooks.html');
}
+ /* Alarms selection widget. */
+
+ /**
+ * Code to run on init for alarms selection.
+ */
+ static public function alarmInit()
+ {
+ Horde::addScriptFile('alarmprefs.js', 'horde');
+ }
+
+ /**
+ * Create code needed for alarm selection.
+ *
+ * @param array $data Data items:
+ * <pre>
+ * 'helplink' - (string) [OPTIONAL] Help link.
+ * 'label' - (string) Label.
+ * 'pref' - (string) Preference name.
+ * </pre>
+ *
+ * @return string HTML UI code.
+ */
+ static public function alarm($data)
+ {
+ $pref = $data['pref'];
+
+ Horde::addInlineScript(array(
+ 'HordeAlarmPrefs.pref = ' . Horde_Serialize::serialize($pref, Horde_Serialize::JSON)
+ ));
+
+ $alarm_pref = unserialize($prefs->getValue($pref));
+ $selected = array_keys($alarm_pref);
+
+ $param_list = $select_list = array();
+ foreach (Horde_Alarm::notificationMethods() as $method => $params) {
+ $select_list[] = array(
+ 'l' => $params['__desc'],
+ 's' => in_array($method, $selected),
+ 'v' => $method
+ );
+
+ if (count($params > 1)) {
+ $tmp = array(
+ 'method' => $method,
+ 'param' => array()
+ );
+
+ foreach ($params as $name => $param) {
+ if (substr($name, 0, 2) == '__') {
+ continue;
+ }
+
+ switch ($param['type']) {
+ case 'text':
+ $tmp['param'][] = array(
+ 'label' => Horde::label($pref . '_' . $name, $param['desc']),
+ 'name' => $pref . '_' . $name,
+ 'text' => true,
+ 'value' => empty($alarm_pref[$method][$name]) ? '' : htmlspecialchars($alarm_pref[$method][$name])
+ );
+ break;
+
+ case 'bool':
+ $tmp['param'][] = array(
+ 'bool' => true,
+ 'checked' => !empty($alarm_pref[$method][$name]),
+ 'label' => Horde::label($pref . '_' . $name, $param['desc']),
+ 'name' => $pref . '_' . $name
+ );
+ break;
+
+ case 'sound':
+ $current_sound = empty($alarm_pref[$method][$name])
+ ? ''
+ : $alarm_pref[$method][$name];
+ $sounds = array();
+ foreach (Horde_Themes::soundList() as $key => $val) {
+ $sounds[] = array(
+ 'c' => ($current_sound == $key),
+ 'uri' => htmlspecialchars($val->uri),
+ 'val' => htmlspecialchars($key)
+ );
+ }
+
+ $tmp['param'][] = array(
+ 'sound' => true,
+ 'checked' => !$current_sound,
+ 'name' => $pref . '_' . $name
+ );
+ break;
+ }
+ }
+
+ $param_list[] = $tmp;
+ }
+ }
+
+ $base = $GLOBALS['injector']->createInstance('Horde_Template');
+ $base->setOption('gettext', true);
+
+ $t->set('desc', Horde::label($pref, $data['label']));
+ if (!empty($data['helplink'])) {
+ $t->set('helplink', $data['helplink']);
+ }
+ $t->set('pref', htmlspecialchars($pref));
+ $t->set('param_list', $param_list);
+ $t->set('select_list', $select_list);
+
+ return $t->fetch(HORDE_TEMPLATES . '/prefs/alarm.html');
+ }
+
+ /**
+ * Process form data.
+ *
+ * @param array $data Data items:
+ * <pre>
+ * 'pref' - (string) Preference name.
+ * </pre>
+ *
+ * @return array TODO
+ */
+ static public function alarmUpdate($ui, $data)
+ {
+ $pref = $data['pref'];
+ $methods = Horde_Alarm::notificationMethods();
+ $val = (isset($ui->vars->$pref) && is_array($ui->vars->$pref))
+ ? $ui->vars->$pref
+ : array();
+ $value = array();
+
+ foreach ($val as $method) {
+ $value[$method] = array();
+ if (!empty($methods[$method])) {
+ foreach (array_keys($methods[$method]) as $param) {
+ $value[$method][$param] = $ui->vars->get($pref . '_' . $param, '');
+ if (is_array($methods[$method][$param]) &&
+ $methods[$method][$param]['required'] &&
+ ($value[$method][$param] === '')) {
+ $GLOBALS['notification']->push(sprintf(_("You must provide a setting for \"%s\"."), $methods[$method][$param]['desc']), 'horde.error');
+ return null;
+ }
+ }
+ }
+ }
+
+ return $value;
+ }
+
}
* following is the list of types, with a description of further keys used
* for each type.
*
- * 'alarm'
- * -------
- * TODO
- *
* 'checkbox'
* ----------
* Provides a checkbox (yes/no) entry.
'desc' => _("Choose how you want to be notified about event changes, event alarms and upcoming events."),
'members' => array(
'event_notification', 'event_notification_exclude_self',
- 'daily_agenda', 'event_reminder', 'event_alarms'
+ 'daily_agenda', 'event_reminder', 'event_alarms_select'
)
);
);
// alarm methods
+$_prefs['event_alarms_select'] = array(
+ 'type' => 'special'
+);
+
$_prefs['event_alarms'] = array(
- 'value' => 'a:1:{s:6:"notify";a:0:{}}',
- 'type' => 'alarm',
- 'desc' => _("Choose how you want to receive reminders for events with alarms:")
+ 'value' => 'a:1:{s:6:"notify";a:0:{}}'
);
// number of days to generate Free/Busy information for:
break;
case 'notification':
- if (empty($conf['alarms']['driver'])) {
+ if (empty($conf['alarms']['driver']) ||
+ $prefs->isLocked('event_alarms') ||
+ $prefs->isLocked('event_alarms_select')) {
$ui->suppress[]= 'event_alarms';
+ } else {
+ Horde_Core_Prefs_Ui_Widgets::alarminit();
}
break;
case 'default_alarm_management':
return $this->_defaultAlarmManagement($ui);
+ case 'event_alarms_select':
+ return Horde_Core_Prefs_Ui_Widgets::alarm(array(
+ 'label' => _("Choose how you want to receive reminders for events with alarms:"),
+ 'pref' => 'event_alarms'
+ ));
+
case 'sourceselect':
$search = Kronolith::getAddressbookSearchParams();
return Horde_Core_Prefs_Ui_Widgets::addressbooks(array(
$GLOBALS['prefs']->setValue('default_alarm', (int)$ui->vars->alarm_value * (int)$ui->vars->alarm_unit);
return true;
+ case 'event_alarms_select':
+ $data = Horde_Core_Prefs_Ui_Widgets::alarmUpdate($ui, array('pref' => 'event_alarms'));
+ if (!is_null($data)) {
+ $GLOBALS['prefs']->setValue('event_alarms', serialize($data));
+ return true;
+ }
+ break;
+
case 'remote_cal_management':
return $this->_prefsRemoteCalManagement($ui);
'column' => _("Task List and Share Options"),
'label' => _("Notifications"),
'desc' => _("Choose if you want to be notified of task changes and task alarms."),
- 'members' => array('task_notification', 'task_alarms'),
+ 'members' => array('task_notification', 'task_alarms_select'),
);
$prefGroups['external'] = array(
);
// alarm methods
+$_prefs['task_alarms_select'] = array(
+ 'type' => 'special'
+);
+
$_prefs['task_alarms'] = array(
- 'value' => 'a:1:{s:6:"notify";a:0:{}}',
- 'type' => 'alarm',
- 'desc' => _("Choose how you want to receive reminders for tasks with alarms:"),
+ 'value' => 'a:1:{s:6:"notify";a:0:{}}'
);
// show data from other applications that can be listed as tasks?
switch ($ui->group) {
case 'notification':
- if (empty($conf['alarms']['driver'])) {
+ if (empty($conf['alarms']['driver']) ||
+ $prefs->isLocked('task_alarms') ||
+ $prefs->isLocked('task_alarms_select')) {
$ui->suppress[] = 'task_alarms';
}
break;
}
/**
+ * Generate code used to display a special preference.
+ *
+ * @param Horde_Core_Prefs_Ui $ui The UI object.
+ * @param string $item The preference name.
+ *
+ * @return string The HTML code to display on the options page.
+ */
+ public function prefsSpecial($ui, $item)
+ {
+ switch ($item) {
+ case 'task_alarms_select':
+ return Horde_Core_Prefs_Ui_Widgets::alarm(array(
+ 'label' => _("Choose how you want to receive reminders for tasks with alarms:"),
+ 'pref' => 'task_alarms'
+ ));
+ }
+
+ return '';
+ }
+
+ /**
+ * Special preferences handling on update.
+ *
+ * @param Horde_Core_Prefs_Ui $ui The UI object.
+ * @param string $item The preference name.
+ *
+ * @return boolean True if preference was updated.
+ */
+ public function prefsSpecialUpdate($ui, $item)
+ {
+ switch ($item) {
+ case 'task_alarms_select':
+ $data = Horde_Core_Prefs_Ui_Widgets::alarmUpdate($ui, array('pref' => 'task_alarms'));
+ if (!is_null($data)) {
+ $GLOBALS['prefs']->setValue('task_alarms', serialize($data));
+ return true;
+ }
+ break;
+ }
+
+ return false;
+ }
+
+ /**
* Generate the menu to use on the prefs page.
*
* @return Horde_Menu A Horde_Menu object.