9a311f5cffcfd956bb02fa4becffd2a9601c55c1
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays all optinos about display preferences
10 *
11 * $Id$
12 * @package squirrelmail
13 */
14
15 /** Define the group constants for the display options page. */
16 define('SMOPT_GRP_GENERAL', 0);
17 define('SMOPT_GRP_MAILBOX', 1);
18 define('SMOPT_GRP_MESSAGE', 2);
19
20 // load icon themes if in use
21 global $use_icons;
22 if ($use_icons) {
23 global $icon_themes;
24 $dirName = SM_PATH . 'images/themes';
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 * This function builds an array with all the information about
36 * the options available to the user, and returns it. The options
37 * are grouped by the groups in which they are displayed.
38 * For each option, the following information is stored:
39 * - name: the internal (variable) name
40 * - caption: the description of the option in the UI
41 * - type: one of SMOPT_TYPE_*
42 * - refresh: one of SMOPT_REFRESH_*
43 * - size: one of SMOPT_SIZE_*
44 * - save: the name of a function to call when saving this option
45 * @return array all option information
46 */
47 function load_optpage_data_display() {
48 global $theme, $language, $languages, $js_autodetect_results,
49 $compose_new_win, $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
50 $optmode, $show_alternative_names, $available_languages, $use_icons;
51
52 /* Build a simple array into which we will build options. */
53 $optgrps = array();
54 $optvals = array();
55
56 /******************************************************/
57 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
58 /******************************************************/
59
60 /*** Load the General Options into the array ***/
61 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
62 $optvals[SMOPT_GRP_GENERAL] = array();
63
64 /* Load the theme option. */
65 $theme_values = array();
66 foreach ($theme as $theme_key => $theme_attributes) {
67 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
68 }
69 ksort($theme_values);
70 $theme_values = array_flip($theme_values);
71 $optvals[SMOPT_GRP_GENERAL][] = array(
72 'name' => 'chosen_theme',
73 'caption' => _("Theme"),
74 'type' => SMOPT_TYPE_STRLIST,
75 'refresh' => SMOPT_REFRESH_ALL,
76 'posvals' => $theme_values,
77 'save' => 'save_option_theme'
78 );
79
80 $css_values = array( 'none' => _("Default" ) );
81 $handle=opendir('../themes/css/');
82 while ($file = readdir($handle) ) {
83 if ( substr( $file, -4 ) == '.css' ) {
84 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
85 }
86 }
87 closedir($handle);
88
89 if ( count( $css_values ) > 1 ) {
90
91 $optvals[SMOPT_GRP_GENERAL][] = array(
92 'name' => 'custom_css',
93 'caption' => _("Custom Stylesheet"),
94 'type' => SMOPT_TYPE_STRLIST,
95 'refresh' => SMOPT_REFRESH_ALL,
96 'posvals' => $css_values
97 );
98
99 }
100
101 // config.php can be unupdated.
102 if (! isset($available_languages) || $available_languages=="" ) {
103 $available_languages="ALL"; }
104
105 $language_values = array();
106 if ( strtoupper($available_languages)=='ALL') {
107 foreach ($languages as $lang_key => $lang_attributes) {
108 if (isset($lang_attributes['NAME'])) {
109 $language_values[$lang_key] = $lang_attributes['NAME'];
110 if ( isset($show_alternative_names) &&
111 $show_alternative_names &&
112 isset($lang_attributes['ALTNAME']) ) {
113 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
114 }
115 }
116 }
117 } else if (strtoupper($available_languages)!='NONE') {
118 // admin can set list of available languages in config
119 $available_languages_array=explode (" ",$available_languages);
120 foreach ($available_languages_array as $lang_key ) {
121 if (isset($languages[$lang_key]['NAME'])) {
122 $language_values[$lang_key] = $languages[$lang_key]['NAME'];
123 if ( isset($show_alternative_names) &&
124 $show_alternative_names &&
125 isset($languages[$lang_key]['ALTNAME']) ) {
126 $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME'];
127 }
128 }
129 }
130 }
131 asort($language_values);
132 $language_values =
133 array_merge(array('' => _("Default")), $language_values);
134 $language = $squirrelmail_language;
135 if (strtoupper($available_languages)!='NONE') {
136 // if set to 'none', interface will use only default language
137 $optvals[SMOPT_GRP_GENERAL][] = array(
138 'name' => 'language',
139 'caption' => _("Language"),
140 'type' => SMOPT_TYPE_STRLIST,
141 'refresh' => SMOPT_REFRESH_ALL,
142 'posvals' => $language_values
143 );
144 }
145
146 /* Set values for the "use javascript" option. */
147 $optvals[SMOPT_GRP_GENERAL][] = array(
148 'name' => 'javascript_setting',
149 'caption' => _("Use Javascript"),
150 'type' => SMOPT_TYPE_STRLIST,
151 'refresh' => SMOPT_REFRESH_ALL,
152 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
153 SMPREF_JS_ON => _("Always"),
154 SMPREF_JS_OFF => _("Never"))
155 );
156
157
158 if ($optmode != 'submit')
159 $onLoadScript = 'document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\'';
160 else
161 $onLoadScript = '';
162
163 $optvals[SMOPT_GRP_GENERAL][] = array(
164 'name' => 'js_autodetect_results',
165 'caption' => '',
166 'type' => SMOPT_TYPE_HIDDEN,
167 'refresh' => SMOPT_REFRESH_NONE,
168 //'post_script' => $js_autodetect_script,
169 'save' => 'save_option_javascript_autodetect'
170 );
171
172 /*** Load the General Options into the array ***/
173 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
174 $optvals[SMOPT_GRP_MAILBOX] = array();
175
176 $optvals[SMOPT_GRP_MAILBOX][] = array(
177 'name' => 'show_num',
178 'caption' => _("Number of Messages to Index"),
179 'type' => SMOPT_TYPE_INTEGER,
180 'refresh' => SMOPT_REFRESH_NONE,
181 'size' => SMOPT_SIZE_TINY
182 );
183
184 $optvals[SMOPT_GRP_MAILBOX][] = array(
185 'name' => 'alt_index_colors',
186 'caption' => _("Enable Alternating Row Colors"),
187 'type' => SMOPT_TYPE_BOOLEAN,
188 'refresh' => SMOPT_REFRESH_NONE
189 );
190
191 if ($use_icons) {
192 global $icon_themes, $icon_theme;
193 $temp = array();
194 for ($count = 0; $count < sizeof($icon_themes); $count++) {
195 $temp[$count] = $icon_themes[$count]['NAME'];
196 if ($icon_theme == $icon_themes[$count]['PATH'])
197 $value = $count;
198 }
199 $optvals[SMOPT_GRP_MAILBOX][] = array(
200 'name' => 'icon_theme',
201 'caption' => _("Message Flags Icon Theme"),
202 'type' => SMOPT_TYPE_STRLIST,
203 'refresh' => SMOPT_REFRESH_NONE,
204 'posvals' => $temp,
205 'initial_value' => $value,
206 'save' => 'icon_theme_save'
207 );
208 }
209
210 $optvals[SMOPT_GRP_MAILBOX][] = array(
211 'name' => 'page_selector',
212 'caption' => _("Enable Page Selector"),
213 'type' => SMOPT_TYPE_BOOLEAN,
214 'refresh' => SMOPT_REFRESH_NONE
215 );
216
217 $optvals[SMOPT_GRP_MAILBOX][] = array(
218 'name' => 'page_selector_max',
219 'caption' => _("Maximum Number of Pages to Show"),
220 'type' => SMOPT_TYPE_INTEGER,
221 'refresh' => SMOPT_REFRESH_NONE,
222 'size' => SMOPT_SIZE_TINY
223 );
224
225 $optvals[SMOPT_GRP_MAILBOX][] = array(
226 'name' => 'show_full_date',
227 'caption' => _("Always Show Full Date"),
228 'type' => SMOPT_TYPE_BOOLEAN,
229 'refresh' => SMOPT_REFRESH_NONE
230 );
231
232 $optvals[SMOPT_GRP_MAILBOX][] = array(
233 'name' => 'truncate_sender',
234 'caption' => _("Length of From/To Field (0 for full)"),
235 'type' => SMOPT_TYPE_INTEGER,
236 'refresh' => SMOPT_REFRESH_NONE,
237 'size' => SMOPT_SIZE_TINY
238 );
239
240 $optvals[SMOPT_GRP_MAILBOX][] = array(
241 'name' => 'truncate_subject',
242 'caption' => _("Length of Subject Field (0 for full)"),
243 'type' => SMOPT_TYPE_INTEGER,
244 'refresh' => SMOPT_REFRESH_NONE,
245 'size' => SMOPT_SIZE_TINY
246 );
247
248 $optvals[SMOPT_GRP_MAILBOX][] = array(
249 'name' => 'show_recipient_instead',
250 'caption' => _("Show recipient name if the message is from your default identity"),
251 'type' => SMOPT_TYPE_BOOLEAN,
252 'refresh' => SMOPT_REFRESH_NONE,
253 'size' => SMOPT_SIZE_TINY
254 );
255
256
257 /*** Load the General Options into the array ***/
258 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display and Composition");
259 $optvals[SMOPT_GRP_MESSAGE] = array();
260
261 $optvals[SMOPT_GRP_MESSAGE][] = array(
262 'name' => 'wrap_at',
263 'caption' => _("Wrap Incoming Text At"),
264 'type' => SMOPT_TYPE_INTEGER,
265 'refresh' => SMOPT_REFRESH_NONE,
266 'size' => SMOPT_SIZE_TINY
267 );
268
269 $optvals[SMOPT_GRP_MESSAGE][] = array(
270 'name' => 'editor_size',
271 'caption' => _("Width of Editor Window"),
272 'type' => SMOPT_TYPE_INTEGER,
273 'refresh' => SMOPT_REFRESH_NONE,
274 'size' => SMOPT_SIZE_TINY
275 );
276
277 $optvals[SMOPT_GRP_MESSAGE][] = array(
278 'name' => 'editor_height',
279 'caption' => _("Height of Editor Window"),
280 'type' => SMOPT_TYPE_INTEGER,
281 'refresh' => SMOPT_REFRESH_NONE,
282 'size' => SMOPT_SIZE_TINY
283 );
284
285 $optvals[SMOPT_GRP_MESSAGE][] = array(
286 'name' => 'location_of_buttons',
287 'caption' => _("Location of Buttons when Composing"),
288 'type' => SMOPT_TYPE_STRLIST,
289 'refresh' => SMOPT_REFRESH_NONE,
290 'posvals' => array(SMPREF_LOC_TOP => _("Before headers"),
291 SMPREF_LOC_BETWEEN => _("Between headers and message body"),
292 SMPREF_LOC_BOTTOM => _("After message body"))
293 );
294
295
296 $optvals[SMOPT_GRP_MESSAGE][] = array(
297 'name' => 'use_javascript_addr_book',
298 'caption' => _("Addressbook Display Format"),
299 'type' => SMOPT_TYPE_STRLIST,
300 'refresh' => SMOPT_REFRESH_NONE,
301 'posvals' => array('1' => _("Javascript"),
302 '0' => _("HTML"))
303 );
304
305 $optvals[SMOPT_GRP_MESSAGE][] = array(
306 'name' => 'show_html_default',
307 'caption' => _("Show HTML Version by Default"),
308 'type' => SMOPT_TYPE_BOOLEAN,
309 'refresh' => SMOPT_REFRESH_NONE
310 );
311
312 $optvals[SMOPT_GRP_MESSAGE][] = array(
313 'name' => 'enable_forward_as_attachment',
314 'caption' => _("Enable Forward as Attachment"),
315 'type' => SMOPT_TYPE_BOOLEAN,
316 'refresh' => SMOPT_REFRESH_NONE
317 );
318
319 $optvals[SMOPT_GRP_MESSAGE][] = array(
320 'name' => 'forward_cc',
321 'caption' => _("Include CCs when Forwarding Messages"),
322 'type' => SMOPT_TYPE_BOOLEAN,
323 'refresh' => SMOPT_REFRESH_NONE
324 );
325
326 $optvals[SMOPT_GRP_MESSAGE][] = array(
327 'name' => 'include_self_reply_all',
328 'caption' => _("Include Me in CC when I Reply All"),
329 'type' => SMOPT_TYPE_BOOLEAN,
330 'refresh' => SMOPT_REFRESH_NONE
331 );
332
333 $optvals[SMOPT_GRP_MESSAGE][] = array(
334 'name' => 'show_xmailer_default',
335 'caption' => _("Enable Mailer Display"),
336 'type' => SMOPT_TYPE_BOOLEAN,
337 'refresh' => SMOPT_REFRESH_NONE
338 );
339
340 $optvals[SMOPT_GRP_MESSAGE][] = array(
341 'name' => 'attachment_common_show_images',
342 'caption' => _("Display Attached Images with Message"),
343 'type' => SMOPT_TYPE_BOOLEAN,
344 'refresh' => SMOPT_REFRESH_NONE
345 );
346
347 $optvals[SMOPT_GRP_MESSAGE][] = array(
348 'name' => 'pf_cleandisplay',
349 'caption' => _("Enable Printer Friendly Clean Display"),
350 'type' => SMOPT_TYPE_BOOLEAN,
351 'refresh' => SMOPT_REFRESH_NONE
352 );
353
354 if ($default_use_mdn) {
355 $optvals[SMOPT_GRP_MESSAGE][] = array(
356 'name' => 'mdn_user_support',
357 'caption' => _("Enable Mail Delivery Notification"),
358 'type' => SMOPT_TYPE_BOOLEAN,
359 'refresh' => SMOPT_REFRESH_NONE
360 );
361 }
362
363 $optvals[SMOPT_GRP_MESSAGE][] = array(
364 'name' => 'compose_new_win',
365 'caption' => _("Compose Messages in New Window"),
366 'type' => SMOPT_TYPE_BOOLEAN,
367 'refresh' => SMOPT_REFRESH_ALL
368 );
369
370 $optvals[SMOPT_GRP_MESSAGE][] = array(
371 'name' => 'compose_width',
372 'caption' => _("Width of Compose Window"),
373 'type' => SMOPT_TYPE_INTEGER,
374 'refresh' => SMOPT_REFRESH_ALL,
375 'size' => SMOPT_SIZE_TINY
376 );
377
378 $optvals[SMOPT_GRP_MESSAGE][] = array(
379 'name' => 'compose_height',
380 'caption' => _("Height of Compose Window"),
381 'type' => SMOPT_TYPE_INTEGER,
382 'refresh' => SMOPT_REFRESH_ALL,
383 'size' => SMOPT_SIZE_TINY
384 );
385
386 $optvals[SMOPT_GRP_MESSAGE][] = array(
387 'name' => 'sig_first',
388 'caption' => _("Append Signature before Reply/Forward Text"),
389 'type' => SMOPT_TYPE_BOOLEAN,
390 'refresh' => SMOPT_REFRESH_NONE
391 );
392
393 $optvals[SMOPT_GRP_MESSAGE][] = array(
394 'name' => 'reply_focus',
395 'caption' => _("Cursor Position when Replying"),
396 'type' => SMOPT_TYPE_STRLIST,
397 'refresh' => SMOPT_REFRESH_NONE,
398 'posvals' => array('' => _("To: field"),
399 'focus' => _("Focus in body"),
400 'select' => _("Select body"))
401 );
402
403 $optvals[SMOPT_GRP_MESSAGE][] = array(
404 'name' => 'strip_sigs',
405 'caption' => _("Strip signature when replying"),
406 'type' => SMOPT_TYPE_BOOLEAN,
407 'refresh' => SMOPT_REFRESH_NONE
408 );
409
410 $optvals[SMOPT_GRP_MESSAGE][] = array(
411 'name' => 'internal_date_sort',
412 'caption' => _("Enable Sort by of Receive Date"),
413 'type' => SMOPT_TYPE_BOOLEAN,
414 'refresh' => SMOPT_REFRESH_ALL
415 );
416 if ($allow_thread_sort == TRUE) {
417 $optvals[SMOPT_GRP_MESSAGE][] = array(
418 'name' => 'sort_by_ref',
419 'caption' => _("Enable Thread Sort by References Header"),
420 'type' => SMOPT_TYPE_BOOLEAN,
421 'refresh' => SMOPT_REFRESH_ALL
422 );
423 $optvals[SMOPT_GRP_MESSAGE][] = array(
424 'name' => 'delete_prev_next_display',
425 'caption' => _("Show 'Delete & Prev/Next' Links"),
426 'type' => SMOPT_TYPE_BOOLEAN,
427 'refresh' => SMOPT_REFRESH_ALL
428 );
429
430 }
431 /* Assemble all this together and return it as our result. */
432 $result = array(
433 'grps' => $optgrps,
434 'vals' => $optvals,
435 'xtra' => $onLoadScript
436 );
437 return ($result);
438 }
439
440 /******************************************************************/
441 /** Define any specialized save functions for this option page. ***/
442 /******************************************************************/
443
444 /**
445 * This function saves a new theme setting.
446 * It updates the theme array.
447 */
448 function save_option_theme($option) {
449 global $theme;
450
451 /* Do checking to make sure $new_theme is in the array. */
452 $theme_in_array = false;
453 for ($i = 0; $i < count($theme); ++$i) {
454 if ($theme[$i]['PATH'] == $option->new_value) {
455 $theme_in_array = true;
456 break;
457 }
458 }
459
460 if (!$theme_in_array) {
461 $option->new_value = '';
462 }
463
464 /* Save the option like normal. */
465 save_option($option);
466 }
467
468 /**
469 * This function saves the javascript detection option.
470 */
471 function save_option_javascript_autodetect($option) {
472 global $data_dir, $username, $new_javascript_setting;
473
474 /* Set javascript either on or off. */
475 if ($new_javascript_setting == SMPREF_JS_AUTODETECT) {
476 if ($option->new_value == SMPREF_JS_ON) {
477 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
478 } else {
479 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
480 }
481 } else {
482 setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
483 }
484 }
485
486 /**
487 * This function saves the user's icon theme setting
488 */
489 function icon_theme_save($option) {
490
491 global $icon_themes, $data_dir, $username;
492
493
494 // Don't assume the new value is there, double check
495 // and only save if found
496 //
497 if (isset($icon_themes[$option->new_value]['PATH']))
498 setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
499 else
500 setPref($data_dir, $username, 'icon_theme', 'none');
501
502 }
503
504 ?>