ba6cbdb7aa667805eb6b6807f3cfcd8358a630bb
[squirrelmail.git] / include / options / display.php
1 <?php
2
3 /**
4 * options_display.php
5 *
6 * Copyright (c) 1999-2005 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 * @version $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 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 }
32 }
33 }
34 }
35
36 global $use_iframe;
37 if (! isset($use_iframe)) $use_iframe=false;
38
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 */
52 function load_optpage_data_display() {
53 global $theme, $language, $languages,
54 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
55 $show_alternative_names, $available_languages, $use_icons, $use_iframe;
56
57 /* Build a simple array into which we will build options. */
58 $optgrps = array();
59 $optvals = array();
60
61 /******************************************************/
62 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
63 /******************************************************/
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. */
70 $theme_values = array();
71 foreach ($theme as $theme_key => $theme_attributes) {
72 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
73 }
74 ksort($theme_values);
75 $theme_values = array_flip($theme_values);
76 $optvals[SMOPT_GRP_GENERAL][] = array(
77 'name' => 'chosen_theme',
78 'caption' => _("Theme"),
79 'type' => SMOPT_TYPE_STRLIST,
80 'refresh' => SMOPT_REFRESH_ALL,
81 'posvals' => $theme_values,
82 'save' => 'save_option_theme'
83 );
84
85 $css_values = array( 'none' => _("Default" ) );
86 $css_dir = SM_PATH . 'themes/css';
87 if (is_readable($css_dir) && is_dir($css_dir)) {
88 $handle=opendir($css_dir);
89 while ($file = readdir($handle) ) {
90 if ( substr( $file, -4 ) == '.css' ) {
91 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
92 }
93 }
94 closedir($handle);
95 }
96
97 if ( count( $css_values ) > 1 ) {
98
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 );
106
107 }
108
109 // config.php can be unupdated.
110 if (! isset($available_languages) || $available_languages=="" ) {
111 $available_languages="ALL"; }
112
113 $language_values = array();
114 if ( strtoupper($available_languages)=='ALL') {
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 }
125 } else if (strtoupper($available_languages)!='NONE') {
126 // admin can set list of available languages in config
127 $available_languages_array=explode (" ",$available_languages);
128 foreach ($available_languages_array as $lang_key ) {
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 }
138 }
139 asort($language_values);
140 $language_values =
141 array_merge(array('' => _("Default")), $language_values);
142 $language = $squirrelmail_language;
143 if (strtoupper($available_languages)!='NONE') {
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 );
153 }
154
155 /* Set values for the "use javascript" option. */
156 $optvals[SMOPT_GRP_GENERAL][] = array(
157 'name' => 'javascript_setting',
158 'caption' => _("Use Javascript"),
159 'type' => SMOPT_TYPE_STRLIST,
160 'refresh' => SMOPT_REFRESH_ALL,
161 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
162 SMPREF_JS_ON => _("Always"),
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 . '\';"'
166 );
167
168 $optvals[SMOPT_GRP_GENERAL][] = array(
169 'name' => 'js_autodetect_results',
170 'caption' => '',
171 'type' => SMOPT_TYPE_HIDDEN,
172 'refresh' => SMOPT_REFRESH_NONE
173 //'post_script' => $js_autodetect_script,
174 );
175
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 );
184
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(
190 'name' => 'show_num',
191 'caption' => _("Number of Messages per Page"),
192 'type' => SMOPT_TYPE_INTEGER,
193 'refresh' => SMOPT_REFRESH_NONE,
194 'size' => SMOPT_SIZE_TINY
195 );
196
197 $optvals[SMOPT_GRP_MAILBOX][] = array(
198 'name' => 'alt_index_colors',
199 'caption' => _("Enable Alternating Row Colors"),
200 'type' => SMOPT_TYPE_BOOLEAN,
201 'refresh' => SMOPT_REFRESH_NONE
202 );
203
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
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 }
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 }
230 }
231
232 $optvals[SMOPT_GRP_MAILBOX][] = array(
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(
240 'name' => 'page_selector',
241 'caption' => _("Enable Page Selector"),
242 'type' => SMOPT_TYPE_BOOLEAN,
243 'refresh' => SMOPT_REFRESH_NONE
244 );
245
246 $optvals[SMOPT_GRP_MAILBOX][] = array(
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(
254 'name' => 'page_selector_max',
255 'caption' => _("Maximum Number of Pages to Show"),
256 'type' => SMOPT_TYPE_INTEGER,
257 'refresh' => SMOPT_REFRESH_NONE,
258 'size' => SMOPT_SIZE_TINY
259 );
260
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
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
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 );
283 /*
284 disabled because the template doesn't support it (yet?)
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 );
292 */
293
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
303
304
305 /*** Load the General Options into the array ***/
306 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
307 $optvals[SMOPT_GRP_MESSAGE] = array();
308
309 $optvals[SMOPT_GRP_MESSAGE][] = array(
310 'name' => 'wrap_at',
311 'caption' => _("Wrap Incoming Text At"),
312 'type' => SMOPT_TYPE_INTEGER,
313 'refresh' => SMOPT_REFRESH_NONE,
314 'size' => SMOPT_SIZE_TINY
315 );
316
317 $optvals[SMOPT_GRP_MESSAGE][] = array(
318 'name' => 'show_html_default',
319 'caption' => _("Show HTML Version by Default"),
320 'type' => SMOPT_TYPE_BOOLEAN,
321 'refresh' => SMOPT_REFRESH_NONE
322 );
323
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 }
334 $optvals[SMOPT_GRP_MESSAGE][] = array(
335 'name' => 'enable_forward_as_attachment',
336 'caption' => _("Enable Forward as Attachment"),
337 'type' => SMOPT_TYPE_BOOLEAN,
338 'refresh' => SMOPT_REFRESH_NONE
339 );
340
341 $optvals[SMOPT_GRP_MESSAGE][] = array(
342 'name' => 'show_xmailer_default',
343 'caption' => _("Enable Mailer Display"),
344 'type' => SMOPT_TYPE_BOOLEAN,
345 'refresh' => SMOPT_REFRESH_NONE
346 );
347
348 $optvals[SMOPT_GRP_MESSAGE][] = array(
349 'name' => 'attachment_common_show_images',
350 'caption' => _("Display Attached Images with Message"),
351 'type' => SMOPT_TYPE_BOOLEAN,
352 'refresh' => SMOPT_REFRESH_NONE
353 );
354
355 if ($default_use_mdn) {
356 $optvals[SMOPT_GRP_MESSAGE][] = array(
357 'name' => 'mdn_user_support',
358 'caption' => _("Enable Mail Delivery Notification"),
359 'type' => SMOPT_TYPE_BOOLEAN,
360 'refresh' => SMOPT_REFRESH_NONE
361 );
362 }
363
364 $optvals[SMOPT_GRP_MESSAGE][] = array(
365 'name' => 'delete_prev_next_display',
366 'caption' => _("Show 'Delete & Prev/Next' Links"),
367 'type' => SMOPT_TYPE_BOOLEAN,
368 'refresh' => SMOPT_REFRESH_ALL
369 );
370
371 /* Assemble all this together and return it as our result. */
372 $result = array(
373 'grps' => $optgrps,
374 'vals' => $optvals
375 );
376 return ($result);
377 }
378
379 /******************************************************************/
380 /** Define any specialized save functions for this option page. ***/
381 /******************************************************************/
382
383 /**
384 * This function saves a new theme setting.
385 * It updates the theme array.
386 */
387 function save_option_theme($option) {
388 global $theme;
389
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 }
402
403 /* Save the option like normal. */
404 save_option($option);
405 }
406
407 /**
408 * This function saves the javascript detection option.
409 */
410 function save_option_javascript_autodetect($option) {
411 save_option($option);
412 checkForJavascript(TRUE);
413 }
414
415 /**
416 * This function saves the user's icon theme setting
417 */
418 function icon_theme_save($option) {
419
420 global $icon_themes, $data_dir, $username;
421
422
423 // Don't assume the new value is there, double check
424 // and only save if found
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
433 ?>