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