1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Core_Prefs_Ui_Widgets
16: {
17:
18:
19: 20: 21:
22: static public function sourceInit()
23: {
24: Horde::addScriptFile('sourceselect.js', 'horde');
25: }
26:
27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 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: 105: 106: 107: 108: 109: 110: 111: 112: 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: 126:
127:
128: 129: 130:
131: static public function addressbooksInit()
132: {
133: self::sourceInit();
134: Horde::addScriptFile('addressbooksprefs.js', 'horde');
135: }
136:
137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 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:
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: 240: 241: 242: 243: 244: 245: 246: 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:
264:
265: 266: 267:
268: static public function alarmInit()
269: {
270: Horde::addScriptFile('alarmprefs.js', 'horde');
271: }
272:
273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 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: 373: 374: 375: 376: 377: 378: 379: 380: 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: