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