b88a2dbf0df23cb5a7b2323dd68f87ed5e9b78bc
[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 /**
20 * Icon themes and user CSS themes should probably both be moved to conf.pl
21 *
22 * TODO: move to conf.pl
23 **/
24 // load icon themes if in use
25 global $use_icons;
26 if ($use_icons) {
27 global $icon_themes;
28 $dirName = SM_PATH . 'images/themes';
29 if (is_readable($dirName) && is_dir($dirName)) {
30 $d = dir($dirName);
31 while($dir = $d->read()) {
32 if ($dir != "." && $dir != "..") {
33 if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php"))
34 include("$dirName/$dir/theme.php");
35 }
36 }
37 }
38 }
39
40 global $use_iframe;
41 if (! isset($use_iframe)) $use_iframe=false;
42
43 /**
44 * This function builds an array with all the information about
45 * the options available to the user, and returns it. The options
46 * are grouped by the groups in which they are displayed.
47 * For each option, the following information is stored:
48 * - name: the internal (variable) name
49 * - caption: the description of the option in the UI
50 * - type: one of SMOPT_TYPE_*
51 * - refresh: one of SMOPT_REFRESH_*
52 * - size: one of SMOPT_SIZE_*
53 * - save: the name of a function to call when saving this option
54 * @return array all option information
55 */
56 function load_optpage_data_display() {
57 global $theme, $fontsets, $language, $languages,$aTemplateSet,
58 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
59 $show_alternative_names, $use_icons, $use_iframe, $sTemplateID,
60 $oTemplate, $user_themes, $chosen_theme;
61
62 /* Build a simple array into which we will build options. */
63 $optgrps = array();
64 $optvals = array();
65
66 /******************************************************/
67 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
68 /******************************************************/
69
70 /*** Load the General Options into the array ***/
71 $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
72 $optvals[SMOPT_GRP_GENERAL] = array();
73
74 /* load the template set option */
75 $templateset_values = array();
76
77 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
78 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['ID'];
79 }
80 ksort($templateset_values);
81 $templateset_values = array_flip($templateset_values);
82 // display template options only when there is more than one template
83 if (count($templateset_values)>1) {
84 $optvals[SMOPT_GRP_GENERAL][] = array(
85 'name' => 'sTemplateID',
86 'caption' => _("Skin"),
87 'type' => SMOPT_TYPE_STRLIST,
88 'refresh' => SMOPT_REFRESH_ALL,
89 'posvals' => $templateset_values,
90 'save' => 'save_option_template'
91 );
92 }
93
94 /* Load the theme option. */
95
96 /**
97 * User themes start with a 'u_', template themes start with a 't_' to
98 * differentiate which is which. This seems kind of hackish, but we can
99 * come up with a better solution later.
100 PL: No need for the prefixes. Just use full paths, no?
101
102 SB: Don't think so. If the user chooses a template theme than changes the
103 path to the template, it would error out, right? Or should we worry about
104 that?
105 *
106 * TODO: Clean me.
107 **/
108 $theme_values = array();
109
110 // Always provide the template default first.
111 $theme_values['none'] = 'Template Default Theme';
112
113 // List alternate themes provided by templates first
114 $template_themes = array();
115 /*
116 * Since this requires mods to the template class, I'm holding off on alternate
117 * template styles until Paul finishes template inheritence.
118 * -- SB, 2006-09-30
119 *
120 $template_themes = $oTemplate->get_alternative_stylesheets();
121 asort($template_provided);
122 foreach ($template_provided as $sheet=>$name) {
123 $theme_values['t_'.$sheet] = 'Template Theme - '.htmlspecialchars($name);
124 }
125 */
126 // Next, list styles provided in SM_PATH/css/
127 asort($user_themes);
128 foreach ($user_themes as $style) {
129 if ($style['PATH'] == 'none')
130 continue;
131 $theme_values['u_'.$style['PATH']] = 'User Theme - '.htmlspecialchars($style['NAME']);
132 }
133
134 if (count($user_themes) + count($template_themes) > 1) {
135 $optvals[SMOPT_GRP_GENERAL][] = array(
136 'name' => 'chosen_theme',
137 'caption' => _("Theme"),
138 'type' => SMOPT_TYPE_STRLIST,
139 'refresh' => SMOPT_REFRESH_ALL,
140 'posvals' => $theme_values,
141 'save' => 'css_theme_save'
142 );
143 }
144
145 /* Icon theme selection */
146 if ($use_icons) {
147 global $icon_themes, $icon_theme;
148
149 $temp = array();
150 $value = 0;
151 for ($count = 0; $count < sizeof($icon_themes); $count++) {
152 $temp[$icon_themes[$count]['PATH']] = $icon_themes[$count]['NAME'];
153 }
154 if (sizeof($icon_themes) > 0) {
155 $optvals[SMOPT_GRP_GENERAL][] = array(
156 'name' => 'icon_theme',
157 'caption' => _("Icon Theme"),
158 'type' => SMOPT_TYPE_STRLIST,
159 'refresh' => SMOPT_REFRESH_NONE,
160 'posvals' => $temp,
161 'save' => 'icon_theme_save'
162 );
163 }
164 }
165
166 $fontset_values = array();
167 $fontset_list = array();
168
169 if (!empty($fontsets) && is_array($fontsets)) {
170
171 foreach (array_keys($fontsets) as $fontset_key) {
172 $fontset_list[$fontset_key]=$fontset_key;
173 }
174 ksort($fontset_list);
175 }
176
177 if (count($fontset_list) > 1) {
178 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
179 $optvals[SMOPT_GRP_GENERAL][] = array(
180 'name' => 'chosen_fontset',
181 'caption' => _("Font style"),
182 'type' => SMOPT_TYPE_STRLIST,
183 'refresh' => SMOPT_REFRESH_ALL,
184 'posvals' => $fontset_list
185 );
186 }
187
188 $optvals[SMOPT_GRP_GENERAL][] = array(
189 'name' => 'chosen_fontsize',
190 'caption' => _("Font size"),
191 'type' => SMOPT_TYPE_STRLIST,
192 'refresh' => SMOPT_REFRESH_ALL,
193 'posvals' => array('' => _("Default font size"),
194 '8' => '8 px',
195 '10' => '10 px',
196 '12' => '12 px',
197 '14' => '14 px')
198 );
199
200 $language_values = array();
201 foreach ($languages as $lang_key => $lang_attributes) {
202 if (isset($lang_attributes['NAME'])) {
203 $language_values[$lang_key] = $lang_attributes['NAME'];
204 if ( isset($show_alternative_names) &&
205 $show_alternative_names &&
206 isset($lang_attributes['ALTNAME']) ) {
207 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
208 }
209 }
210 }
211
212 asort($language_values);
213 $language_values =
214 array_merge(array('' => _("Default")), $language_values);
215 $language = $squirrelmail_language;
216
217 // add language selection only when more than 2 languages are available
218 // (default, English and some other)
219 if (count($language_values)>2) {
220 $optvals[SMOPT_GRP_GENERAL][] = array(
221 'name' => 'language',
222 'caption' => _("Language"),
223 'type' => SMOPT_TYPE_STRLIST,
224 'refresh' => SMOPT_REFRESH_ALL,
225 'posvals' => $language_values,
226 'htmlencoded' => true
227 );
228 }
229
230 /* Set values for the "use javascript" option. */
231 $optvals[SMOPT_GRP_GENERAL][] = array(
232 'name' => 'javascript_setting',
233 'caption' => _("Use Javascript"),
234 'type' => SMOPT_TYPE_STRLIST,
235 'refresh' => SMOPT_REFRESH_ALL,
236 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
237 SMPREF_JS_ON => _("Always"),
238 SMPREF_JS_OFF => _("Never")),
239 'save' => 'save_option_javascript_autodetect',
240 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
241 );
242
243 $optvals[SMOPT_GRP_GENERAL][] = array(
244 'name' => 'js_autodetect_results',
245 'caption' => '',
246 'type' => SMOPT_TYPE_HIDDEN,
247 'refresh' => SMOPT_REFRESH_NONE
248 //'post_script' => $js_autodetect_script,
249 );
250
251 $optvals[SMOPT_GRP_GENERAL][] = array(
252 'name' => 'hour_format',
253 'caption' => _("Hour Format"),
254 'type' => SMOPT_TYPE_STRLIST,
255 'refresh' => SMOPT_REFRESH_FOLDERLIST,
256 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
257 SMPREF_TIME_24HR => _("24-hour clock"))
258 );
259
260 /*** Load the General Options into the array ***/
261 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
262 $optvals[SMOPT_GRP_MAILBOX] = array();
263
264 $optvals[SMOPT_GRP_MAILBOX][] = array(
265 'name' => 'show_num',
266 'caption' => _("Number of Messages per Page"),
267 'type' => SMOPT_TYPE_INTEGER,
268 'refresh' => SMOPT_REFRESH_NONE,
269 'size' => SMOPT_SIZE_TINY
270 );
271
272 $optvals[SMOPT_GRP_MAILBOX][] = array(
273 'name' => 'alt_index_colors',
274 'caption' => _("Enable Alternating Row Colors"),
275 'type' => SMOPT_TYPE_BOOLEAN,
276 'refresh' => SMOPT_REFRESH_NONE
277 );
278
279 $optvals[SMOPT_GRP_MAILBOX][] = array(
280 'name' => 'fancy_index_highlite',
281 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
282 'type' => SMOPT_TYPE_BOOLEAN,
283 'refresh' => SMOPT_REFRESH_NONE
284 );
285
286 $optvals[SMOPT_GRP_MAILBOX][] = array(
287 'name' => 'show_flag_buttons',
288 'caption' => _("Show Flag / Unflag Buttons"),
289 'type' => SMOPT_TYPE_BOOLEAN,
290 'refresh' => SMOPT_REFRESH_NONE
291 );
292
293 $optvals[SMOPT_GRP_MAILBOX][] = array(
294 'name' => 'show_copy_buttons',
295 'caption' => _("Enable Message Copy Buttons"),
296 'type' => SMOPT_TYPE_BOOLEAN,
297 'refresh' => SMOPT_REFRESH_NONE
298 );
299
300 $optvals[SMOPT_GRP_MAILBOX][] = array(
301 'name' => 'page_selector',
302 'caption' => _("Enable Page Selector"),
303 'type' => SMOPT_TYPE_BOOLEAN,
304 'refresh' => SMOPT_REFRESH_NONE
305 );
306
307 $optvals[SMOPT_GRP_MAILBOX][] = array(
308 'name' => 'compact_paginator',
309 'caption' => _("Use Compact Page Selector"),
310 'type' => SMOPT_TYPE_BOOLEAN,
311 'refresh' => SMOPT_REFRESH_NONE
312 );
313
314 $optvals[SMOPT_GRP_MAILBOX][] = array(
315 'name' => 'page_selector_max',
316 'caption' => _("Maximum Number of Pages to Show"),
317 'type' => SMOPT_TYPE_INTEGER,
318 'refresh' => SMOPT_REFRESH_NONE,
319 'size' => SMOPT_SIZE_TINY
320 );
321
322 $optvals[SMOPT_GRP_MAILBOX][] = array(
323 'name' => 'show_full_date',
324 'caption' => _("Always Show Full Date"),
325 'type' => SMOPT_TYPE_BOOLEAN,
326 'refresh' => SMOPT_REFRESH_NONE
327 );
328
329 $optvals[SMOPT_GRP_MAILBOX][] = array(
330 'name' => 'truncate_sender',
331 'caption' => _("Length of From/To Field (0 for full)"),
332 'type' => SMOPT_TYPE_INTEGER,
333 'refresh' => SMOPT_REFRESH_NONE,
334 'size' => SMOPT_SIZE_TINY
335 );
336
337 $optvals[SMOPT_GRP_MAILBOX][] = array(
338 'name' => 'truncate_subject',
339 'caption' => _("Length of Subject Field (0 for full)"),
340 'type' => SMOPT_TYPE_INTEGER,
341 'refresh' => SMOPT_REFRESH_NONE,
342 'size' => SMOPT_SIZE_TINY
343 );
344 /*
345 FIXME!
346 disabled because the template doesn't support it (yet?)
347 $optvals[SMOPT_GRP_MAILBOX][] = array(
348 'name' => 'show_recipient_instead',
349 'caption' => _("Show recipient name if the message is from your default identity"),
350 'type' => SMOPT_TYPE_BOOLEAN,
351 'refresh' => SMOPT_REFRESH_NONE,
352 'size' => SMOPT_SIZE_TINY
353 );
354 */
355
356 if ($allow_thread_sort == TRUE) {
357 $optvals[SMOPT_GRP_MAILBOX][] = array(
358 'name' => 'sort_by_ref',
359 'caption' => _("Enable Thread Sort by References Header"),
360 'type' => SMOPT_TYPE_BOOLEAN,
361 'refresh' => SMOPT_REFRESH_ALL
362 );
363 }
364
365
366
367 /*** Load the General Options into the array ***/
368 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
369 $optvals[SMOPT_GRP_MESSAGE] = array();
370
371 $optvals[SMOPT_GRP_MESSAGE][] = array(
372 'name' => 'wrap_at',
373 'caption' => _("Wrap Incoming Text At"),
374 'type' => SMOPT_TYPE_INTEGER,
375 'refresh' => SMOPT_REFRESH_NONE,
376 'size' => SMOPT_SIZE_TINY
377 );
378
379 $optvals[SMOPT_GRP_MESSAGE][] = array(
380 'name' => 'show_html_default',
381 'caption' => _("Show HTML Version by Default"),
382 'type' => SMOPT_TYPE_BOOLEAN,
383 'refresh' => SMOPT_REFRESH_NONE
384 );
385
386 if ($use_iframe) {
387 // Type is set to string in order to be able to use 100%.
388 $optvals[SMOPT_GRP_MESSAGE][] = array(
389 'name' => 'iframe_height',
390 'caption' => _("Height of inline frame"),
391 'type' => SMOPT_TYPE_STRING,
392 'size' => SMOPT_SIZE_TINY,
393 'refresh' => SMOPT_REFRESH_NONE
394 );
395 }
396 $optvals[SMOPT_GRP_MESSAGE][] = array(
397 'name' => 'enable_forward_as_attachment',
398 'caption' => _("Enable Forward as Attachment"),
399 'type' => SMOPT_TYPE_BOOLEAN,
400 'refresh' => SMOPT_REFRESH_NONE
401 );
402
403 $optvals[SMOPT_GRP_MESSAGE][] = array(
404 'name' => 'show_xmailer_default',
405 'caption' => _("Enable Mailer Display"),
406 'type' => SMOPT_TYPE_BOOLEAN,
407 'refresh' => SMOPT_REFRESH_NONE
408 );
409
410 $optvals[SMOPT_GRP_MESSAGE][] = array(
411 'name' => 'attachment_common_show_images',
412 'caption' => _("Display Attached Images with Message"),
413 'type' => SMOPT_TYPE_BOOLEAN,
414 'refresh' => SMOPT_REFRESH_NONE
415 );
416
417 if ($default_use_mdn) {
418 $optvals[SMOPT_GRP_MESSAGE][] = array(
419 'name' => 'mdn_user_support',
420 'caption' => _("Enable Mail Delivery Notification"),
421 'type' => SMOPT_TYPE_BOOLEAN,
422 'refresh' => SMOPT_REFRESH_NONE
423 );
424 }
425
426 $optvals[SMOPT_GRP_MESSAGE][] = array(
427 'name' => 'delete_prev_next_display',
428 'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
429 'type' => SMOPT_TYPE_BOOLEAN,
430 'refresh' => SMOPT_REFRESH_ALL
431 );
432
433 /* Assemble all this together and return it as our result. */
434 $result = array(
435 'grps' => $optgrps,
436 'vals' => $optvals
437 );
438 return ($result);
439 }
440
441 /******************************************************************/
442 /** Define any specialized save functions for this option page. ***/
443 /******************************************************************/
444
445 /**
446 * This function saves a new template setting.
447 * It updates the template array.
448 */
449 function save_option_template($option) {
450 global $aTemplateSet;
451
452 /* Do checking to make sure new template is in the available templates array. */
453 $templateset_in_array = false;
454 for ($i = 0; $i < count($aTemplateSet); ++$i) {
455 if ($aTemplateSet[$i]['ID'] == $option->new_value) {
456 $templateset_in_array = true;
457 break;
458 }
459 }
460
461 if (!$templateset_in_array) {
462 $option->new_value = '';
463 } else {
464
465 // clear template cache when changing template sets
466 // (in order to do so, we have to change the global
467 // template set ID now... should not be a problem --
468 // in fact, if we don't do it now, very anomalous
469 // problems occur)
470 //
471 global $sTemplateID;
472 $sTemplateID = $option->new_value;
473 Template::cache_template_file_hierarchy(TRUE);
474
475 }
476
477 /* Save the option like normal. */
478 save_option($option);
479 }
480
481 /**
482 * This function saves the javascript detection option.
483 */
484 function save_option_javascript_autodetect($option) {
485 save_option($option);
486 checkForJavascript(TRUE);
487 }
488
489 /**
490 * This function saves the user's icon theme setting
491 */
492 function icon_theme_save($option) {
493 global $icon_themes, $data_dir, $username;
494
495
496 // Don't assume the new value is there, double check
497 // and only save if found
498 //
499 $found = false;
500 while (!$found && (list($index, $data) = each($icon_themes))) {
501 if ($data['PATH'] == $option->new_value)
502 $found = true;
503 }
504
505 if (!$found)
506 $option->new_value = 'none';
507
508 save_option($option);
509 }
510
511 function css_theme_save ($option) {
512 global $user_themes, $data_dir, $username;
513
514 // Don't assume the new value is there, double check
515 // and only save if found
516 //
517 $found = false;
518 reset($user_themes);
519 while (!$found && (list($index, $data) = each($user_themes))) {
520 if ('u_'.$data['PATH'] == $option->new_value)
521 $found = true;
522 }
523 if ($found)
524 setPref($data_dir, $username, 'chosen_theme', $option->new_value);
525 else
526 setPref($data_dir, $username, 'chosen_theme', 'none');
527 }
528
529