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