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