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