53ad67016b749ce401c30bfb113ebf5db95925cb
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Displays all optinos about display preferences
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Define the group constants for the display options page. */
15 define('SMOPT_GRP_GENERAL', 0);
16 define('SMOPT_GRP_MAILBOX', 1);
17 define('SMOPT_GRP_MESSAGE', 2);
18 define('SMOPT_GRP_ABOOK', 3);
19
20 global $use_iframe;
21 if (! isset($use_iframe)) $use_iframe=false;
22
23 /**
24 * This function builds an array with all the information about
25 * the options available to the user, and returns it. The options
26 * are grouped by the groups in which they are displayed.
27 * For each option, the following information is stored:
28 * - name: the internal (variable) name
29 * - caption: the description of the option in the UI
30 * - type: one of SMOPT_TYPE_*
31 * - refresh: one of SMOPT_REFRESH_*
32 * - size: one of SMOPT_SIZE_*
33 * - save: the name of a function to call when saving this option
34 * @return array all option information
35 */
36 function load_optpage_data_display() {
37 global $theme, $fontsets, $language, $languages,$aTemplateSet,
38 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
39 $show_alternative_names, $use_iframe, $use_icons,
40 $sTemplateID, $oTemplate,
41 $user_themes, $chosen_theme;
42
43 /* Build a simple array into which we will build options. */
44 $optgrps = array();
45 $optvals = array();
46
47 /******************************************************/
48 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
49 /******************************************************/
50
51 /*** Load the General Options into the array ***/
52 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
53 $optvals[SMOPT_GRP_GENERAL] = array();
54
55 /* load the template set option */
56 $templateset_values = array();
57
58 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
59 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
60 }
61 ksort($templateset_values);
62 $templateset_values = array_flip($templateset_values);
63 // display template options only when there is more than one template
64 if (count($templateset_values)>1) {
65 $optvals[SMOPT_GRP_GENERAL][] = array(
66 'name' => 'sTemplateID',
67 'caption' => _("Skin"),
68 'type' => SMOPT_TYPE_STRLIST,
69 'refresh' => SMOPT_REFRESH_ALL,
70 'posvals' => $templateset_values,
71 'save' => 'save_option_template'
72 );
73 }
74
75 /* Load the theme option. */
76 $theme_values = array();
77
78 // Always provide the template default first.
79 $theme_values['none'] = 'Template Default Theme';
80
81 // List alternate themes provided by templates first
82 $template_themes = $oTemplate->get_alternative_stylesheets(true);
83 asort($template_themes);
84 foreach ($template_themes as $sheet=>$name) {
85 $theme_values[$sheet] = 'Template Theme - '.htmlspecialchars($name);
86 }
87 // Next, list user-provided styles
88 asort($user_themes);
89 foreach ($user_themes as $style) {
90 if ($style['PATH'] == 'none')
91 continue;
92 $theme_values[$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
93 }
94
95 if (count($user_themes) + count($template_themes) > 1) {
96 $optvals[SMOPT_GRP_GENERAL][] = array(
97 'name' => 'chosen_theme',
98 'caption' => _("Theme"),
99 'type' => SMOPT_TYPE_STRLIST,
100 'refresh' => SMOPT_REFRESH_ALL,
101 'posvals' => $theme_values,
102 'save' => 'css_theme_save'
103 );
104 }
105
106 /* Icon theme selection */
107 if ($use_icons) {
108 global $icon_themes, $icon_theme;
109
110 $temp = array();
111 $value = 0;
112 for ($count = 0; $count < sizeof($icon_themes); $count++) {
113 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
114 }
115 if (sizeof($icon_themes) > 0) {
116 $optvals[SMOPT_GRP_GENERAL][] = array(
117 'name' => 'icon_theme',
118 'caption' => _("Icon Theme"),
119 'type' => SMOPT_TYPE_STRLIST,
120 'refresh' => SMOPT_REFRESH_NONE,
121 'posvals' => $temp,
122 'save' => 'icon_theme_save'
123 );
124 }
125 }
126
127 $fontset_values = array();
128 $fontset_list = array();
129
130 if (!empty($fontsets) && is_array($fontsets)) {
131
132 foreach (array_keys($fontsets) as $fontset_key) {
133 $fontset_list[$fontset_key]=$fontset_key;
134 }
135 ksort($fontset_list);
136 }
137
138 if (count($fontset_list) > 1) {
139 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
140 $optvals[SMOPT_GRP_GENERAL][] = array(
141 'name' => 'chosen_fontset',
142 'caption' => _("Font style"),
143 'type' => SMOPT_TYPE_STRLIST,
144 'refresh' => SMOPT_REFRESH_ALL,
145 'posvals' => $fontset_list
146 );
147 }
148
149 $optvals[SMOPT_GRP_GENERAL][] = array(
150 'name' => 'chosen_fontsize',
151 'caption' => _("Font size"),
152 'type' => SMOPT_TYPE_STRLIST,
153 'refresh' => SMOPT_REFRESH_ALL,
154 'posvals' => array('' => _("Default font size"),
155 '8' => '8 px',
156 '10' => '10 px',
157 '12' => '12 px',
158 '14' => '14 px')
159 );
160
161 $language_values = array();
162 foreach ($languages as $lang_key => $lang_attributes) {
163 if (isset($lang_attributes['NAME'])) {
164 $language_values[$lang_key] = $lang_attributes['NAME'];
165 if ( isset($show_alternative_names) &&
166 $show_alternative_names &&
167 isset($lang_attributes['ALTNAME']) ) {
168 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
169 }
170 }
171 }
172
173 asort($language_values);
174 $language_values =
175 array_merge(array('' => _("Default")), $language_values);
176 $language = $squirrelmail_language;
177
178 // add language selection only when more than 2 languages are available
179 // (default, English and some other)
180 if (count($language_values)>2) {
181 $optvals[SMOPT_GRP_GENERAL][] = array(
182 'name' => 'language',
183 'caption' => _("Language"),
184 'type' => SMOPT_TYPE_STRLIST,
185 'refresh' => SMOPT_REFRESH_ALL,
186 'posvals' => $language_values,
187 'htmlencoded' => true
188 );
189 }
190
191 /* Set values for the "use javascript" option. */
192 $optvals[SMOPT_GRP_GENERAL][] = array(
193 'name' => 'javascript_setting',
194 'caption' => _("Use Javascript"),
195 'type' => SMOPT_TYPE_STRLIST,
196 'refresh' => SMOPT_REFRESH_ALL,
197 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
198 SMPREF_JS_ON => _("Always"),
199 SMPREF_JS_OFF => _("Never")),
200 'save' => 'save_option_javascript_autodetect',
201 'extra_attributes' => array('onclick' => 'document.option_form.new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';'),
202 );
203
204 $optvals[SMOPT_GRP_GENERAL][] = array(
205 'name' => 'js_autodetect_results',
206 'caption' => '',
207 'type' => SMOPT_TYPE_HIDDEN,
208 'refresh' => SMOPT_REFRESH_NONE
209 //'post_script' => $js_autodetect_script,
210 );
211
212 $optvals[SMOPT_GRP_GENERAL][] = array(
213 'name' => 'hour_format',
214 'caption' => _("Hour Format"),
215 'type' => SMOPT_TYPE_STRLIST,
216 'refresh' => SMOPT_REFRESH_FOLDERLIST,
217 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
218 SMPREF_TIME_24HR => _("24-hour clock"))
219 );
220
221 /*** Load the General Options into the array ***/
222 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
223 $optvals[SMOPT_GRP_MAILBOX] = array();
224
225 $optvals[SMOPT_GRP_MAILBOX][] = array(
226 'name' => 'show_num',
227 'caption' => _("Number of Messages per Page"),
228 'type' => SMOPT_TYPE_INTEGER,
229 'refresh' => SMOPT_REFRESH_NONE,
230 'size' => SMOPT_SIZE_TINY
231 );
232
233 $optvals[SMOPT_GRP_MAILBOX][] = array(
234 'name' => 'alt_index_colors',
235 'caption' => _("Enable Alternating Row Colors"),
236 'type' => SMOPT_TYPE_BOOLEAN,
237 'refresh' => SMOPT_REFRESH_NONE
238 );
239
240 $optvals[SMOPT_GRP_MAILBOX][] = array(
241 'name' => 'fancy_index_highlite',
242 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
243 'type' => SMOPT_TYPE_BOOLEAN,
244 'refresh' => SMOPT_REFRESH_NONE
245 );
246
247 $optvals[SMOPT_GRP_MAILBOX][] = array(
248 'name' => 'show_flag_buttons',
249 'caption' => _("Show Flag / Unflag Buttons"),
250 'type' => SMOPT_TYPE_BOOLEAN,
251 'refresh' => SMOPT_REFRESH_NONE
252 );
253
254 $optvals[SMOPT_GRP_MAILBOX][] = array(
255 'name' => 'show_copy_buttons',
256 'caption' => _("Enable Message Copy Buttons"),
257 'type' => SMOPT_TYPE_BOOLEAN,
258 'refresh' => SMOPT_REFRESH_NONE
259 );
260
261 $optvals[SMOPT_GRP_MAILBOX][] = array(
262 'name' => 'page_selector',
263 'caption' => _("Enable Page Selector"),
264 'type' => SMOPT_TYPE_BOOLEAN,
265 'refresh' => SMOPT_REFRESH_NONE
266 );
267
268 $optvals[SMOPT_GRP_MAILBOX][] = array(
269 'name' => 'compact_paginator',
270 'caption' => _("Use Compact Page Selector"),
271 'type' => SMOPT_TYPE_BOOLEAN,
272 'refresh' => SMOPT_REFRESH_NONE
273 );
274
275 $optvals[SMOPT_GRP_MAILBOX][] = array(
276 'name' => 'page_selector_max',
277 'caption' => _("Maximum Number of Pages to Show"),
278 'type' => SMOPT_TYPE_INTEGER,
279 'refresh' => SMOPT_REFRESH_NONE,
280 'size' => SMOPT_SIZE_TINY
281 );
282
283 $optvals[SMOPT_GRP_MAILBOX][] = array(
284 'name' => 'show_full_date',
285 'caption' => _("Always Show Full Date"),
286 'type' => SMOPT_TYPE_BOOLEAN,
287 'refresh' => SMOPT_REFRESH_NONE
288 );
289
290 $optvals[SMOPT_GRP_MAILBOX][] = array(
291 'name' => 'custom_date_format',
292 'caption' => _("Custom Date Format"),
293 //FIXME: need better wording here. users should be made aware that this is for advanced use. It might be nice to provide a list of the more common date format characters. It may be helpful to know that it overrides settings such as the one above show_full_date, and only if kept empty will the other date formats apply. For non-English users, it also may be helpful to know that the format is still passed through our own date_intl() function which translates things like the day of the week, month names and abbreviations, etc.
294 'trailing_text' => ' ' . _("(Uses format of PHP date() function)"),
295 'type' => SMOPT_TYPE_STRING,
296 'refresh' => SMOPT_REFRESH_NONE,
297 'size' => SMOPT_SIZE_TINY,
298 );
299
300 $optvals[SMOPT_GRP_MAILBOX][] = array(
301 'name' => 'truncate_sender',
302 'caption' => _("Length of From/To Field (0 for full)"),
303 'type' => SMOPT_TYPE_INTEGER,
304 'refresh' => SMOPT_REFRESH_NONE,
305 'size' => SMOPT_SIZE_TINY
306 );
307
308 $optvals[SMOPT_GRP_MAILBOX][] = array(
309 'name' => 'truncate_subject',
310 'caption' => _("Length of Subject Field (0 for full)"),
311 'type' => SMOPT_TYPE_INTEGER,
312 'refresh' => SMOPT_REFRESH_NONE,
313 'size' => SMOPT_SIZE_TINY
314 );
315 /*
316 FIXME!
317 disabled because the template doesn't support it (yet?)
318 $optvals[SMOPT_GRP_MAILBOX][] = array(
319 'name' => 'show_recipient_instead',
320 'caption' => _("Show recipient name if the message is from your default identity"),
321 'type' => SMOPT_TYPE_BOOLEAN,
322 'refresh' => SMOPT_REFRESH_NONE,
323 'size' => SMOPT_SIZE_TINY
324 );
325 */
326
327 if ($allow_thread_sort == TRUE) {
328 $optvals[SMOPT_GRP_MAILBOX][] = array(
329 'name' => 'sort_by_ref',
330 'caption' => _("Enable Thread Sort by References Header"),
331 'type' => SMOPT_TYPE_BOOLEAN,
332 'refresh' => SMOPT_REFRESH_ALL
333 );
334 }
335
336
337
338 /*** Load the General Options into the array ***/
339 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
340 $optvals[SMOPT_GRP_MESSAGE] = array();
341
342 $optvals[SMOPT_GRP_MESSAGE][] = array(
343 'name' => 'wrap_at',
344 'caption' => _("Wrap Incoming Text At"),
345 'type' => SMOPT_TYPE_INTEGER,
346 'refresh' => SMOPT_REFRESH_NONE,
347 'size' => SMOPT_SIZE_TINY
348 );
349
350 $optvals[SMOPT_GRP_MESSAGE][] = array(
351 'name' => 'show_html_default',
352 'caption' => _("Show HTML Version by Default"),
353 'type' => SMOPT_TYPE_BOOLEAN,
354 'refresh' => SMOPT_REFRESH_NONE
355 );
356
357 if ($use_iframe) {
358 // Type is set to string in order to be able to use 100%.
359 $optvals[SMOPT_GRP_MESSAGE][] = array(
360 'name' => 'iframe_height',
361 'caption' => _("Height of inline frame"),
362 'type' => SMOPT_TYPE_STRING,
363 'size' => SMOPT_SIZE_TINY,
364 'refresh' => SMOPT_REFRESH_NONE
365 );
366 }
367 $optvals[SMOPT_GRP_MESSAGE][] = array(
368 'name' => 'enable_forward_as_attachment',
369 'caption' => _("Enable Forward as Attachment"),
370 'type' => SMOPT_TYPE_BOOLEAN,
371 'refresh' => SMOPT_REFRESH_NONE
372 );
373
374 $optvals[SMOPT_GRP_MESSAGE][] = array(
375 'name' => 'show_xmailer_default',
376 'caption' => _("Enable Mailer Display"),
377 'type' => SMOPT_TYPE_BOOLEAN,
378 'refresh' => SMOPT_REFRESH_NONE
379 );
380
381 $optvals[SMOPT_GRP_MESSAGE][] = array(
382 'name' => 'attachment_common_show_images',
383 'caption' => _("Display Attached Images with Message"),
384 'type' => SMOPT_TYPE_BOOLEAN,
385 'refresh' => SMOPT_REFRESH_NONE
386 );
387
388 if ($default_use_mdn) {
389 $optvals[SMOPT_GRP_MESSAGE][] = array(
390 'name' => 'mdn_user_support',
391 'caption' => _("Enable Mail Delivery Notification"),
392 'type' => SMOPT_TYPE_BOOLEAN,
393 'refresh' => SMOPT_REFRESH_NONE
394 );
395 }
396
397 $optvals[SMOPT_GRP_MESSAGE][] = array(
398 'name' => 'delete_prev_next_display',
399 'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
400 'type' => SMOPT_TYPE_BOOLEAN,
401 'refresh' => SMOPT_REFRESH_ALL
402 );
403
404
405
406 /*** Load the Address Book Options into the array ***/
407 $optgrps[SMOPT_GRP_ABOOK] = _("Address Book Display Options");
408 $optvals[SMOPT_GRP_ABOOK] = array();
409
410 $optvals[SMOPT_GRP_ABOOK][] = array(
411 'name' => 'abook_show_num',
412 'caption' => _("Number of Addresses per Page"),
413 'type' => SMOPT_TYPE_INTEGER,
414 'refresh' => SMOPT_REFRESH_NONE,
415 'size' => SMOPT_SIZE_TINY
416 );
417
418 $optvals[SMOPT_GRP_ABOOK][] = array(
419 'name' => 'abook_page_selector',
420 'caption' => _("Enable Page Selector"),
421 'type' => SMOPT_TYPE_BOOLEAN,
422 'refresh' => SMOPT_REFRESH_NONE
423 );
424
425 $optvals[SMOPT_GRP_ABOOK][] = array(
426 'name' => 'abook_compact_paginator',
427 'caption' => _("Use Compact Page Selector"),
428 'type' => SMOPT_TYPE_BOOLEAN,
429 'refresh' => SMOPT_REFRESH_NONE
430 );
431
432 $optvals[SMOPT_GRP_ABOOK][] = array(
433 'name' => 'abook_page_selector_max',
434 'caption' => _("Maximum Number of Pages to Show"),
435 'type' => SMOPT_TYPE_INTEGER,
436 'refresh' => SMOPT_REFRESH_NONE,
437 'size' => SMOPT_SIZE_TINY
438 );
439
440
441
442 /* Assemble all this together and return it as our result. */
443 $result = array(
444 'grps' => $optgrps,
445 'vals' => $optvals
446 );
447 return ($result);
448 }
449
450 /******************************************************************/
451 /** Define any specialized save functions for this option page. ***/
452 /******************************************************************/
453
454 /**
455 * This function saves a new template setting.
456 * It updates the template array.
457 */
458 function save_option_template($option) {
459 global $aTemplateSet;
460
461 /* Do checking to make sure new template is in the available templates array. */
462 $templateset_in_array = false;
463 for ($i = 0; $i < count($aTemplateSet); ++$i) {
464 if ($aTemplateSet[$i]['ID'] == $option->new_value) {
465 $templateset_in_array = true;
466 break;
467 }
468 }
469
470 if (!$templateset_in_array) {
471 $option->new_value = '';
472 } else {
473
474 // clear template cache when changing template sets
475 // (in order to do so, we have to change the global
476 // template set ID now... should not be a problem --
477 // in fact, if we don't do it now, very anomalous
478 // problems occur)
479 //
480 global $sTemplateID;
481 $sTemplateID = $option->new_value;
482 Template::cache_template_file_hierarchy($sTemplateID, TRUE);
483
484 }
485
486 /**
487 * TODO: If the template changes and we are using a template provided theme
488 * ($user_theme), do we want to reset $user_theme?
489 */
490 /* Save the option like normal. */
491 save_option($option);
492 }
493
494 /**
495 * This function saves the javascript detection option.
496 */
497 function save_option_javascript_autodetect($option) {
498 save_option($option);
499 checkForJavascript(TRUE);
500 }
501
502 /**
503 * This function saves the user's icon theme setting
504 */
505 function icon_theme_save($option) {
506 global $icon_themes;
507
508
509 // Don't assume the new value is there, double check
510 // and only save if found
511 $found = false;
512 while (!$found && (list($index, $data) = each($icon_themes))) {
513 if ($data['PATH'] == $option->new_value)
514 $found = true;
515 }
516
517 if (!$found)
518 $option->new_value = 'none';
519
520 save_option($option);
521 }
522
523 function css_theme_save ($option) {
524 global $user_themes, $oTemplate;
525
526 // Don't assume the new value is there, double check
527 // and only save if found
528 $found = false;
529 reset($user_themes);
530 while (!$found && (list($index, $data) = each($user_themes))) {
531 if ($data['PATH'] == $option->new_value)
532 $found = true;
533 }
534
535 if (!$found) {
536 $template_themes = $oTemplate->get_alternative_stylesheets(true);
537 while (!$found && (list($path, $name) = each($template_themes))) {
538 if ($path == $option->new_value)
539 $found = true;
540 }
541 }
542
543 if (!$found)
544 $option->new_value = 'none';
545
546 save_option($option);
547 }
548
549