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