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