moving administrator check to option block registration. reduces amount of
[squirrelmail.git] / include / options / display.php
CommitLineData
c36ed9cf 1<?php
e7db48af 2
35586184 3/**
4 * options_display.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays all optinos about display preferences
10 *
763b63fe 11 * @version $Id$
2b646597 12 * @package squirrelmail
35586184 13 */
cbe5423b 14
2b646597 15/** Define the group constants for the display options page. */
cbe5423b 16define('SMOPT_GRP_GENERAL', 0);
17define('SMOPT_GRP_MAILBOX', 1);
18define('SMOPT_GRP_MESSAGE', 2);
19
6395c46d 20// load icon themes if in use
21global $use_icons;
22if ($use_icons) {
23 global $icon_themes;
24 $dirName = SM_PATH . 'images/themes';
4f7a5870 25 if (is_readable($dirName) && is_dir($dirName)) {
26 $d = dir($dirName);
27 while($dir = $d->read()) {
28 if ($dir != "." && $dir != "..") {
29 if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php"))
30 include("$dirName/$dir/theme.php");
31 }
6395c46d 32 }
33 }
34}
35
a144f6b8 36global $use_iframe;
37if (! isset($use_iframe)) $use_iframe=false;
38
48af4b64 39/**
40 * This function builds an array with all the information about
41 * the options available to the user, and returns it. The options
42 * are grouped by the groups in which they are displayed.
43 * For each option, the following information is stored:
44 * - name: the internal (variable) name
45 * - caption: the description of the option in the UI
46 * - type: one of SMOPT_TYPE_*
47 * - refresh: one of SMOPT_REFRESH_*
48 * - size: one of SMOPT_SIZE_*
49 * - save: the name of a function to call when saving this option
50 * @return array all option information
51 */
cbe5423b 52function load_optpage_data_display() {
91e0dccc 53 global $theme, $language, $languages,
ce68b76b 54 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
a144f6b8 55 $show_alternative_names, $available_languages, $use_icons, $use_iframe;
a3ec3c91 56
ce393174 57 /* Build a simple array into which we will build options. */
bbcafebd 58 $optgrps = array();
59 $optvals = array();
a3ec3c91 60
bbcafebd 61 /******************************************************/
62 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
63 /******************************************************/
bbcafebd 64
65 /*** Load the General Options into the array ***/
66 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
67 $optvals[SMOPT_GRP_GENERAL] = array();
68
69 /* Load the theme option. */
ce393174 70 $theme_values = array();
71 foreach ($theme as $theme_key => $theme_attributes) {
be278741 72 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
ce393174 73 }
be278741 74 ksort($theme_values);
75 $theme_values = array_flip($theme_values);
bbcafebd 76 $optvals[SMOPT_GRP_GENERAL][] = array(
ce393174 77 'name' => 'chosen_theme',
78 'caption' => _("Theme"),
79 'type' => SMOPT_TYPE_STRLIST,
80 'refresh' => SMOPT_REFRESH_ALL,
cbe5423b 81 'posvals' => $theme_values,
82 'save' => 'save_option_theme'
ce393174 83 );
5d110fa6 84
8f1ba72b 85 $css_values = array( 'none' => _("Default" ) );
bb7173fa 86 $css_dir = SM_PATH . 'themes/css';
87 if (is_readable($css_dir) && is_dir($css_dir)) {
88 $handle=opendir($css_dir);
4f7a5870 89 while ($file = readdir($handle) ) {
90 if ( substr( $file, -4 ) == '.css' ) {
91 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
92 }
8f1ba72b 93 }
4f7a5870 94 closedir($handle);
dcd6f144 95 }
5d110fa6 96
54078578 97 if ( count( $css_values ) > 1 ) {
5d110fa6 98
e2cdae1f 99 $optvals[SMOPT_GRP_GENERAL][] = array(
100 'name' => 'custom_css',
101 'caption' => _("Custom Stylesheet"),
102 'type' => SMOPT_TYPE_STRLIST,
103 'refresh' => SMOPT_REFRESH_ALL,
104 'posvals' => $css_values
105 );
5d110fa6 106
e2cdae1f 107 }
39d3ec89 108
109 // config.php can be unupdated.
110 if (! isset($available_languages) || $available_languages=="" ) {
111 $available_languages="ALL"; }
5d110fa6 112
e557fdb0 113 $language_values = array();
39d3ec89 114 if ( strtoupper($available_languages)=='ALL') {
0bb37159 115 foreach ($languages as $lang_key => $lang_attributes) {
116 if (isset($lang_attributes['NAME'])) {
117 $language_values[$lang_key] = $lang_attributes['NAME'];
118 if ( isset($show_alternative_names) &&
119 $show_alternative_names &&
120 isset($lang_attributes['ALTNAME']) ) {
121 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
122 }
123 }
124 }
39d3ec89 125 } else if (strtoupper($available_languages)!='NONE') {
0bb37159 126 // admin can set list of available languages in config
127 $available_languages_array=explode (" ",$available_languages);
39d3ec89 128 foreach ($available_languages_array as $lang_key ) {
0bb37159 129 if (isset($languages[$lang_key]['NAME'])) {
130 $language_values[$lang_key] = $languages[$lang_key]['NAME'];
131 if ( isset($show_alternative_names) &&
132 $show_alternative_names &&
133 isset($languages[$lang_key]['ALTNAME']) ) {
134 $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME'];
135 }
136 }
137 }
ce393174 138 }
e557fdb0 139 asort($language_values);
8405d0a4 140 $language_values =
141 array_merge(array('' => _("Default")), $language_values);
ec2c91a1 142 $language = $squirrelmail_language;
39d3ec89 143 if (strtoupper($available_languages)!='NONE') {
0bb37159 144 // if set to 'none', interface will use only default language
145 $optvals[SMOPT_GRP_GENERAL][] = array(
146 'name' => 'language',
147 'caption' => _("Language"),
148 'type' => SMOPT_TYPE_STRLIST,
149 'refresh' => SMOPT_REFRESH_ALL,
150 'posvals' => $language_values,
151 'htmlencoded' => true
152 );
39d3ec89 153 }
ce393174 154
a3ec3c91 155 /* Set values for the "use javascript" option. */
bbcafebd 156 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 157 'name' => 'javascript_setting',
ce393174 158 'caption' => _("Use Javascript"),
a3ec3c91 159 'type' => SMOPT_TYPE_STRLIST,
160 'refresh' => SMOPT_REFRESH_ALL,
161 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
162 SMPREF_JS_ON => _("Always"),
ae958cd3 163 SMPREF_JS_OFF => _("Never")),
164 'save' => 'save_option_javascript_autodetect',
165 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
a3ec3c91 166 );
167
bbcafebd 168 $optvals[SMOPT_GRP_GENERAL][] = array(
a3ec3c91 169 'name' => 'js_autodetect_results',
170 'caption' => '',
171 'type' => SMOPT_TYPE_HIDDEN,
ae958cd3 172 'refresh' => SMOPT_REFRESH_NONE
5826affb 173 //'post_script' => $js_autodetect_script,
a3ec3c91 174 );
f2df3fa1 175
5bcd1b00 176 $optvals[SMOPT_GRP_GENERAL][] = array(
177 'name' => 'hour_format',
178 'caption' => _("Hour Format"),
179 'type' => SMOPT_TYPE_STRLIST,
180 'refresh' => SMOPT_REFRESH_FOLDERLIST,
181 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
182 SMPREF_TIME_24HR => _("24-hour clock"))
183 );
a3ec3c91 184
bbcafebd 185 /*** Load the General Options into the array ***/
186 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
187 $optvals[SMOPT_GRP_MAILBOX] = array();
188
189 $optvals[SMOPT_GRP_MAILBOX][] = array(
a3ec3c91 190 'name' => 'show_num',
f2df3fa1 191 'caption' => _("Number of Messages per Page"),
a3ec3c91 192 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 193 'refresh' => SMOPT_REFRESH_NONE,
194 'size' => SMOPT_SIZE_TINY
a3ec3c91 195 );
196
bbcafebd 197 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 198 'name' => 'alt_index_colors',
199 'caption' => _("Enable Alternating Row Colors"),
200 'type' => SMOPT_TYPE_BOOLEAN,
201 'refresh' => SMOPT_REFRESH_NONE
202 );
203
18adc53f 204 $optvals[SMOPT_GRP_MAILBOX][] = array(
205 'name' => 'fancy_index_highlite',
206 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
207 'type' => SMOPT_TYPE_BOOLEAN,
208 'refresh' => SMOPT_REFRESH_NONE
209 );
210
6395c46d 211 if ($use_icons) {
212 global $icon_themes, $icon_theme;
213 $temp = array();
214 for ($count = 0; $count < sizeof($icon_themes); $count++) {
215 $temp[$count] = $icon_themes[$count]['NAME'];
216 if ($icon_theme == $icon_themes[$count]['PATH'])
217 $value = $count;
218 }
4f7a5870 219 if (sizeof($icon_themes) > 0) {
220 $optvals[SMOPT_GRP_MAILBOX][] = array(
221 'name' => 'icon_theme',
222 'caption' => _("Message Flags Icon Theme"),
223 'type' => SMOPT_TYPE_STRLIST,
224 'refresh' => SMOPT_REFRESH_NONE,
225 'posvals' => $temp,
226 'initial_value' => $value,
227 'save' => 'icon_theme_save'
228 );
229 }
6395c46d 230 }
231
bbcafebd 232 $optvals[SMOPT_GRP_MAILBOX][] = array(
fd181f53 233 'name' => 'show_flag_buttons',
234 'caption' => _("Show Flag / Unflag Buttons"),
235 'type' => SMOPT_TYPE_BOOLEAN,
236 'refresh' => SMOPT_REFRESH_NONE
237 );
238
239 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 240 'name' => 'page_selector',
241 'caption' => _("Enable Page Selector"),
242 'type' => SMOPT_TYPE_BOOLEAN,
243 'refresh' => SMOPT_REFRESH_NONE
244 );
245
bbcafebd 246 $optvals[SMOPT_GRP_MAILBOX][] = array(
0bb37159 247 'name' => 'compact_paginator',
248 'caption' => _("Use Compact Page Selector"),
249 'type' => SMOPT_TYPE_BOOLEAN,
250 'refresh' => SMOPT_REFRESH_NONE
251 );
252
253 $optvals[SMOPT_GRP_MAILBOX][] = array(
a440e68f 254 'name' => 'page_selector_max',
255 'caption' => _("Maximum Number of Pages to Show"),
256 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 257 'refresh' => SMOPT_REFRESH_NONE,
258 'size' => SMOPT_SIZE_TINY
a440e68f 259 );
260
3e3b60e3 261 $optvals[SMOPT_GRP_MAILBOX][] = array(
262 'name' => 'show_full_date',
263 'caption' => _("Always Show Full Date"),
264 'type' => SMOPT_TYPE_BOOLEAN,
265 'refresh' => SMOPT_REFRESH_NONE
266 );
267
459e3347 268 $optvals[SMOPT_GRP_MAILBOX][] = array(
269 'name' => 'truncate_sender',
270 'caption' => _("Length of From/To Field (0 for full)"),
271 'type' => SMOPT_TYPE_INTEGER,
272 'refresh' => SMOPT_REFRESH_NONE,
273 'size' => SMOPT_SIZE_TINY
274 );
275
3fc1a95f 276 $optvals[SMOPT_GRP_MAILBOX][] = array(
277 'name' => 'truncate_subject',
278 'caption' => _("Length of Subject Field (0 for full)"),
279 'type' => SMOPT_TYPE_INTEGER,
280 'refresh' => SMOPT_REFRESH_NONE,
281 'size' => SMOPT_SIZE_TINY
282 );
91c27aee 283/*
284 disabled because the template doesn't support it (yet?)
1ae2832e 285 $optvals[SMOPT_GRP_MAILBOX][] = array(
286 'name' => 'show_recipient_instead',
287 'caption' => _("Show recipient name if the message is from your default identity"),
288 'type' => SMOPT_TYPE_BOOLEAN,
289 'refresh' => SMOPT_REFRESH_NONE,
290 'size' => SMOPT_SIZE_TINY
291 );
91c27aee 292*/
f2df3fa1 293
5ed9d4fd 294 if ($allow_thread_sort == TRUE) {
295 $optvals[SMOPT_GRP_MAILBOX][] = array(
296 'name' => 'sort_by_ref',
297 'caption' => _("Enable Thread Sort by References Header"),
298 'type' => SMOPT_TYPE_BOOLEAN,
299 'refresh' => SMOPT_REFRESH_ALL
300 );
301 }
302
1ae2832e 303
459e3347 304
bbcafebd 305 /*** Load the General Options into the array ***/
5ed9d4fd 306 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
bbcafebd 307 $optvals[SMOPT_GRP_MESSAGE] = array();
308
309 $optvals[SMOPT_GRP_MESSAGE][] = array(
a3ec3c91 310 'name' => 'wrap_at',
311 'caption' => _("Wrap Incoming Text At"),
312 'type' => SMOPT_TYPE_INTEGER,
bbcafebd 313 'refresh' => SMOPT_REFRESH_NONE,
314 'size' => SMOPT_SIZE_TINY
a3ec3c91 315 );
316
bbcafebd 317 $optvals[SMOPT_GRP_MESSAGE][] = array(
fd87494d 318 'name' => 'show_html_default',
319 'caption' => _("Show HTML Version by Default"),
320 'type' => SMOPT_TYPE_BOOLEAN,
321 'refresh' => SMOPT_REFRESH_NONE
322 );
323
a144f6b8 324 if ($use_iframe) {
325 // Type is set to string in order to be able to use 100%.
326 $optvals[SMOPT_GRP_MESSAGE][] = array(
327 'name' => 'iframe_height',
328 'caption' => _("Height of inline frame"),
329 'type' => SMOPT_TYPE_STRING,
330 'size' => SMOPT_SIZE_TINY,
331 'refresh' => SMOPT_REFRESH_NONE
332 );
333 }
bbcafebd 334 $optvals[SMOPT_GRP_MESSAGE][] = array(
6206f6c4 335 'name' => 'enable_forward_as_attachment',
336 'caption' => _("Enable Forward as Attachment"),
fd87494d 337 'type' => SMOPT_TYPE_BOOLEAN,
338 'refresh' => SMOPT_REFRESH_NONE
339 );
340
bbcafebd 341 $optvals[SMOPT_GRP_MESSAGE][] = array(
9ab0d96f 342 'name' => 'show_xmailer_default',
a440e68f 343 'caption' => _("Enable Mailer Display"),
9ab0d96f 344 'type' => SMOPT_TYPE_BOOLEAN,
345 'refresh' => SMOPT_REFRESH_NONE
346 );
347
7baf86a9 348 $optvals[SMOPT_GRP_MESSAGE][] = array(
349 'name' => 'attachment_common_show_images',
10f0ce72 350 'caption' => _("Display Attached Images with Message"),
7baf86a9 351 'type' => SMOPT_TYPE_BOOLEAN,
352 'refresh' => SMOPT_REFRESH_NONE
353 );
354
57257333 355 if ($default_use_mdn) {
356 $optvals[SMOPT_GRP_MESSAGE][] = array(
357 'name' => 'mdn_user_support',
6206f6c4 358 'caption' => _("Enable Mail Delivery Notification"),
57257333 359 'type' => SMOPT_TYPE_BOOLEAN,
360 'refresh' => SMOPT_REFRESH_NONE
361 );
362 }
07687736 363
9c3e6cd4 364 $optvals[SMOPT_GRP_MESSAGE][] = array(
4267d5de 365 'name' => 'delete_prev_next_display',
366 'caption' => _("Show 'Delete & Prev/Next' Links"),
367 'type' => SMOPT_TYPE_BOOLEAN,
368 'refresh' => SMOPT_REFRESH_ALL
369 );
5d110fa6 370
cbe5423b 371 /* Assemble all this together and return it as our result. */
372 $result = array(
373 'grps' => $optgrps,
ae958cd3 374 'vals' => $optvals
cbe5423b 375 );
376 return ($result);
377}
a3ec3c91 378
cbe5423b 379/******************************************************************/
380/** Define any specialized save functions for this option page. ***/
381/******************************************************************/
f1e6f580 382
48af4b64 383/**
384 * This function saves a new theme setting.
385 * It updates the theme array.
386 */
cbe5423b 387function save_option_theme($option) {
388 global $theme;
bb7173fa 389
cbe5423b 390 /* Do checking to make sure $new_theme is in the array. */
391 $theme_in_array = false;
392 for ($i = 0; $i < count($theme); ++$i) {
393 if ($theme[$i]['PATH'] == $option->new_value) {
394 $theme_in_array = true;
395 break;
396 }
397 }
398
399 if (!$theme_in_array) {
400 $option->new_value = '';
401 }
e7db48af 402
cbe5423b 403 /* Save the option like normal. */
404 save_option($option);
405}
e7db48af 406
48af4b64 407/**
408 * This function saves the javascript detection option.
409 */
cbe5423b 410function save_option_javascript_autodetect($option) {
ae958cd3 411 save_option($option);
412 checkForJavascript(TRUE);
cbe5423b 413}
414
5d110fa6 415/**
6395c46d 416 * This function saves the user's icon theme setting
417 */
418function icon_theme_save($option) {
419
420 global $icon_themes, $data_dir, $username;
421
422
5d110fa6 423 // Don't assume the new value is there, double check
424 // and only save if found
6395c46d 425 //
426 if (isset($icon_themes[$option->new_value]['PATH']))
427 setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
428 else
429 setPref($data_dir, $username, 'icon_theme', 'none');
430
431}
432
f8a1ed5a 433?>