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