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