Changes on 18 August to functions.php were intended to correct issue with the $icon_t...
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Displays all optinos about display preferences
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Define the group constants for the display options page. */
15 define('SMOPT_GRP_GENERAL', 0);
16 define('SMOPT_GRP_MAILBOX', 1);
17 define('SMOPT_GRP_MESSAGE', 2);
18
19 // load icon themes if in use
20 global $use_icons;
21 if ($use_icons) {
22 global $icon_themes;
23 $dirName = SM_PATH . 'images/themes';
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 }
31 }
32 }
33 }
34
35 global $use_iframe;
36 if (! isset($use_iframe)) $use_iframe=false;
37
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 */
51 function load_optpage_data_display() {
52 global $theme, $fontsets, $language, $languages,$aTemplateSet,
53 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
54 $show_alternative_names, $use_icons, $use_iframe, $sTplDir;
55
56 /* Build a simple array into which we will build options. */
57 $optgrps = array();
58 $optvals = array();
59
60 /******************************************************/
61 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
62 /******************************************************/
63
64 /*** Load the General Options into the array ***/
65 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
66 $optvals[SMOPT_GRP_GENERAL] = array();
67
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);
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 }
87
88 /* Load the theme option. */
89 $theme_values = array();
90 foreach ($theme as $theme_key => $theme_attributes) {
91 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
92 }
93 ksort($theme_values);
94 $theme_values = array_flip($theme_values);
95 $optvals[SMOPT_GRP_GENERAL][] = array(
96 'name' => 'chosen_theme',
97 'caption' => _("Theme"),
98 'type' => SMOPT_TYPE_STRLIST,
99 'refresh' => SMOPT_REFRESH_ALL,
100 'posvals' => $theme_values,
101 'save' => 'save_option_theme'
102 );
103
104 $css_values = array( 'none' => _("Default" ) );
105 $css_dir = SM_PATH . 'themes/css';
106 if (is_readable($css_dir) && is_dir($css_dir)) {
107 $handle=opendir($css_dir);
108 while ($file = readdir($handle) ) {
109 if ( substr( $file, -4 ) == '.css' ) {
110 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
111 }
112 }
113 closedir($handle);
114 }
115
116 /*
117 if ( count( $css_values ) > 1 ) {
118
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 );
126
127 }
128 */
129
130 $fontset_values = array();
131 $fontset_list = array();
132
133 if (!empty($fontsets) && is_array($fontsets)) {
134
135 foreach (array_keys($fontsets) as $fontset_key) {
136 $fontset_list[$fontset_key]=$fontset_key;
137 }
138 ksort($fontset_list);
139 }
140
141 if (count($fontset_list) > 1) {
142 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
143 $optvals[SMOPT_GRP_GENERAL][] = array(
144 'name' => 'chosen_fontset',
145 'caption' => _("Font style"),
146 'type' => SMOPT_TYPE_STRLIST,
147 'refresh' => SMOPT_REFRESH_ALL,
148 'posvals' => $fontset_list
149 );
150 }
151
152 $optvals[SMOPT_GRP_GENERAL][] = array(
153 'name' => 'chosen_fontsize',
154 'caption' => _("Font size"),
155 'type' => SMOPT_TYPE_STRLIST,
156 'refresh' => SMOPT_REFRESH_ALL,
157 'posvals' => array('' => _("Default font size"),
158 '8' => '8 px',
159 '10' => '10 px',
160 '12' => '12 px',
161 '14' => '14 px')
162 );
163
164 $language_values = array();
165 foreach ($languages as $lang_key => $lang_attributes) {
166 if (isset($lang_attributes['NAME'])) {
167 $language_values[$lang_key] = $lang_attributes['NAME'];
168 if ( isset($show_alternative_names) &&
169 $show_alternative_names &&
170 isset($lang_attributes['ALTNAME']) ) {
171 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
172 }
173 }
174 }
175
176 asort($language_values);
177 $language_values =
178 array_merge(array('' => _("Default")), $language_values);
179 $language = $squirrelmail_language;
180
181 // add language selection only when more than 2 languages are available
182 // (default, English and some other)
183 if (count($language_values)>2) {
184 $optvals[SMOPT_GRP_GENERAL][] = array(
185 'name' => 'language',
186 'caption' => _("Language"),
187 'type' => SMOPT_TYPE_STRLIST,
188 'refresh' => SMOPT_REFRESH_ALL,
189 'posvals' => $language_values,
190 'htmlencoded' => true
191 );
192 }
193
194 /* Set values for the "use javascript" option. */
195 $optvals[SMOPT_GRP_GENERAL][] = array(
196 'name' => 'javascript_setting',
197 'caption' => _("Use Javascript"),
198 'type' => SMOPT_TYPE_STRLIST,
199 'refresh' => SMOPT_REFRESH_ALL,
200 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
201 SMPREF_JS_ON => _("Always"),
202 SMPREF_JS_OFF => _("Never")),
203 'save' => 'save_option_javascript_autodetect',
204 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
205 );
206
207 $optvals[SMOPT_GRP_GENERAL][] = array(
208 'name' => 'js_autodetect_results',
209 'caption' => '',
210 'type' => SMOPT_TYPE_HIDDEN,
211 'refresh' => SMOPT_REFRESH_NONE
212 //'post_script' => $js_autodetect_script,
213 );
214
215 $optvals[SMOPT_GRP_GENERAL][] = array(
216 'name' => 'hour_format',
217 'caption' => _("Hour Format"),
218 'type' => SMOPT_TYPE_STRLIST,
219 'refresh' => SMOPT_REFRESH_FOLDERLIST,
220 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
221 SMPREF_TIME_24HR => _("24-hour clock"))
222 );
223
224 /* Icon theme selection */
225 if ($use_icons) {
226 global $icon_themes, $icon_theme;
227
228 $temp = array();
229 $value = 0;
230 for ($count = 0; $count < sizeof($icon_themes); $count++) {
231 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
232 }
233 if (sizeof($icon_themes) > 0) {
234 $optvals[SMOPT_GRP_GENERAL][] = array(
235 'name' => 'icon_theme',
236 'caption' => _("Icon Theme"),
237 'type' => SMOPT_TYPE_STRLIST,
238 'refresh' => SMOPT_REFRESH_NONE,
239 'posvals' => $temp,
240 'save' => 'icon_theme_save'
241 );
242 }
243 }
244
245
246 /*** Load the General Options into the array ***/
247 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
248 $optvals[SMOPT_GRP_MAILBOX] = array();
249
250 $optvals[SMOPT_GRP_MAILBOX][] = array(
251 'name' => 'show_num',
252 'caption' => _("Number of Messages per Page"),
253 'type' => SMOPT_TYPE_INTEGER,
254 'refresh' => SMOPT_REFRESH_NONE,
255 'size' => SMOPT_SIZE_TINY
256 );
257
258 $optvals[SMOPT_GRP_MAILBOX][] = array(
259 'name' => 'alt_index_colors',
260 'caption' => _("Enable Alternating Row Colors"),
261 'type' => SMOPT_TYPE_BOOLEAN,
262 'refresh' => SMOPT_REFRESH_NONE
263 );
264
265 $optvals[SMOPT_GRP_MAILBOX][] = array(
266 'name' => 'fancy_index_highlite',
267 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
268 'type' => SMOPT_TYPE_BOOLEAN,
269 'refresh' => SMOPT_REFRESH_NONE
270 );
271
272 $optvals[SMOPT_GRP_MAILBOX][] = array(
273 'name' => 'show_flag_buttons',
274 'caption' => _("Show Flag / Unflag Buttons"),
275 'type' => SMOPT_TYPE_BOOLEAN,
276 'refresh' => SMOPT_REFRESH_NONE
277 );
278
279 $optvals[SMOPT_GRP_MAILBOX][] = array(
280 'name' => 'show_copy_buttons',
281 'caption' => _("Enable Message Copy Buttons"),
282 'type' => SMOPT_TYPE_BOOLEAN,
283 'refresh' => SMOPT_REFRESH_NONE
284 );
285
286 $optvals[SMOPT_GRP_MAILBOX][] = array(
287 'name' => 'page_selector',
288 'caption' => _("Enable Page Selector"),
289 'type' => SMOPT_TYPE_BOOLEAN,
290 'refresh' => SMOPT_REFRESH_NONE
291 );
292
293 $optvals[SMOPT_GRP_MAILBOX][] = array(
294 'name' => 'compact_paginator',
295 'caption' => _("Use Compact Page Selector"),
296 'type' => SMOPT_TYPE_BOOLEAN,
297 'refresh' => SMOPT_REFRESH_NONE
298 );
299
300 $optvals[SMOPT_GRP_MAILBOX][] = array(
301 'name' => 'page_selector_max',
302 'caption' => _("Maximum Number of Pages to Show"),
303 'type' => SMOPT_TYPE_INTEGER,
304 'refresh' => SMOPT_REFRESH_NONE,
305 'size' => SMOPT_SIZE_TINY
306 );
307
308 $optvals[SMOPT_GRP_MAILBOX][] = array(
309 'name' => 'show_full_date',
310 'caption' => _("Always Show Full Date"),
311 'type' => SMOPT_TYPE_BOOLEAN,
312 'refresh' => SMOPT_REFRESH_NONE
313 );
314
315 $optvals[SMOPT_GRP_MAILBOX][] = array(
316 'name' => 'truncate_sender',
317 'caption' => _("Length of From/To Field (0 for full)"),
318 'type' => SMOPT_TYPE_INTEGER,
319 'refresh' => SMOPT_REFRESH_NONE,
320 'size' => SMOPT_SIZE_TINY
321 );
322
323 $optvals[SMOPT_GRP_MAILBOX][] = array(
324 'name' => 'truncate_subject',
325 'caption' => _("Length of Subject Field (0 for full)"),
326 'type' => SMOPT_TYPE_INTEGER,
327 'refresh' => SMOPT_REFRESH_NONE,
328 'size' => SMOPT_SIZE_TINY
329 );
330 /*
331 disabled because the template doesn't support it (yet?)
332 $optvals[SMOPT_GRP_MAILBOX][] = array(
333 'name' => 'show_recipient_instead',
334 'caption' => _("Show recipient name if the message is from your default identity"),
335 'type' => SMOPT_TYPE_BOOLEAN,
336 'refresh' => SMOPT_REFRESH_NONE,
337 'size' => SMOPT_SIZE_TINY
338 );
339 */
340
341 if ($allow_thread_sort == TRUE) {
342 $optvals[SMOPT_GRP_MAILBOX][] = array(
343 'name' => 'sort_by_ref',
344 'caption' => _("Enable Thread Sort by References Header"),
345 'type' => SMOPT_TYPE_BOOLEAN,
346 'refresh' => SMOPT_REFRESH_ALL
347 );
348 }
349
350
351
352 /*** Load the General Options into the array ***/
353 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
354 $optvals[SMOPT_GRP_MESSAGE] = array();
355
356 $optvals[SMOPT_GRP_MESSAGE][] = array(
357 'name' => 'wrap_at',
358 'caption' => _("Wrap Incoming Text At"),
359 'type' => SMOPT_TYPE_INTEGER,
360 'refresh' => SMOPT_REFRESH_NONE,
361 'size' => SMOPT_SIZE_TINY
362 );
363
364 $optvals[SMOPT_GRP_MESSAGE][] = array(
365 'name' => 'show_html_default',
366 'caption' => _("Show HTML Version by Default"),
367 'type' => SMOPT_TYPE_BOOLEAN,
368 'refresh' => SMOPT_REFRESH_NONE
369 );
370
371 if ($use_iframe) {
372 // Type is set to string in order to be able to use 100%.
373 $optvals[SMOPT_GRP_MESSAGE][] = array(
374 'name' => 'iframe_height',
375 'caption' => _("Height of inline frame"),
376 'type' => SMOPT_TYPE_STRING,
377 'size' => SMOPT_SIZE_TINY,
378 'refresh' => SMOPT_REFRESH_NONE
379 );
380 }
381 $optvals[SMOPT_GRP_MESSAGE][] = array(
382 'name' => 'enable_forward_as_attachment',
383 'caption' => _("Enable Forward as Attachment"),
384 'type' => SMOPT_TYPE_BOOLEAN,
385 'refresh' => SMOPT_REFRESH_NONE
386 );
387
388 $optvals[SMOPT_GRP_MESSAGE][] = array(
389 'name' => 'show_xmailer_default',
390 'caption' => _("Enable Mailer Display"),
391 'type' => SMOPT_TYPE_BOOLEAN,
392 'refresh' => SMOPT_REFRESH_NONE
393 );
394
395 $optvals[SMOPT_GRP_MESSAGE][] = array(
396 'name' => 'attachment_common_show_images',
397 'caption' => _("Display Attached Images with Message"),
398 'type' => SMOPT_TYPE_BOOLEAN,
399 'refresh' => SMOPT_REFRESH_NONE
400 );
401
402 if ($default_use_mdn) {
403 $optvals[SMOPT_GRP_MESSAGE][] = array(
404 'name' => 'mdn_user_support',
405 'caption' => _("Enable Mail Delivery Notification"),
406 'type' => SMOPT_TYPE_BOOLEAN,
407 'refresh' => SMOPT_REFRESH_NONE
408 );
409 }
410
411 $optvals[SMOPT_GRP_MESSAGE][] = array(
412 'name' => 'delete_prev_next_display',
413 'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
414 'type' => SMOPT_TYPE_BOOLEAN,
415 'refresh' => SMOPT_REFRESH_ALL
416 );
417
418 /* Assemble all this together and return it as our result. */
419 $result = array(
420 'grps' => $optgrps,
421 'vals' => $optvals
422 );
423 return ($result);
424 }
425
426 /******************************************************************/
427 /** Define any specialized save functions for this option page. ***/
428 /******************************************************************/
429
430 /**
431 * This function saves a new template setting.
432 * It updates the template array.
433 */
434 function save_option_template($option) {
435 global $aTemplateSet;
436
437 /* Do checking to make sure $new_theme is in the array. */
438 $templateset_in_array = false;
439 for ($i = 0; $i < count($aTemplateSet); ++$i) {
440 if ($aTemplateSet[$i]['PATH'] == $option->new_value) {
441 $templateset_in_array = true;
442 break;
443 }
444 }
445
446 if (!$templateset_in_array) {
447 $option->new_value = '';
448 }
449 /* Save the option like normal. */
450 save_option($option);
451 }
452
453 /**
454 * This function saves a new theme setting.
455 * It updates the theme array.
456 */
457 function save_option_theme($option) {
458 global $theme;
459
460 /* Do checking to make sure $new_theme is in the array. */
461 $theme_in_array = false;
462 for ($i = 0; $i < count($theme); ++$i) {
463 if ($theme[$i]['PATH'] == $option->new_value) {
464 $theme_in_array = true;
465 break;
466 }
467 }
468
469 if (!$theme_in_array) {
470 $option->new_value = '';
471 }
472
473 /* Save the option like normal. */
474 save_option($option);
475 }
476
477 /**
478 * This function saves the javascript detection option.
479 */
480 function save_option_javascript_autodetect($option) {
481 save_option($option);
482 checkForJavascript(TRUE);
483 }
484
485 /**
486 * This function saves the user's icon theme setting
487 */
488 function icon_theme_save($option) {
489 global $icon_themes, $data_dir, $username;
490
491
492 // Don't assume the new value is there, double check
493 // and only save if found
494 //
495 $found = false;
496 while (!$found && (list($index, $data) = each($icon_themes))) {
497 if ($data['PATH'] == $option->new_value)
498 $found = true;
499 }
500 if ($found)
501 setPref($data_dir, $username, 'icon_theme', $option->new_value);
502 else
503 setPref($data_dir, $username, 'icon_theme', 'none');
504
505 }