6 * Displays all optinos about display preferences
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
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);
19 // load icon themes if in use
23 $dirName = SM_PATH
. 'images/themes';
24 if (is_readable($dirName) && is_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");
36 if (! isset($use_iframe)) $use_iframe=false;
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
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;
56 /* Build a simple array into which we will build options. */
60 /******************************************************/
61 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
62 /******************************************************/
64 /*** Load the General Options into the array ***/
65 $optgrps[SMOPT_GRP_GENERAL
] = _("General Display Options");
66 $optvals[SMOPT_GRP_GENERAL
] = array();
68 /* load the template set option */
69 $templateset_values = array();
71 foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) {
72 $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['PATH'];
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(
80 'caption' => _("Template"),
81 'type' => SMOPT_TYPE_STRLIST
,
82 'refresh' => SMOPT_REFRESH_ALL
,
83 'posvals' => $templateset_values,
84 'save' => 'save_option_template'
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'];
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'
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 );
117 if ( count( $css_values ) > 1 ) {
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
130 $fontset_values = array();
131 foreach (array_keys($fontsets) as $fontset_key) {
132 $fontset_list[$fontset_key]=$fontset_key;
134 ksort($fontset_list);
136 if (count($fontset_list) > 1) {
137 $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list);
138 $optvals[SMOPT_GRP_GENERAL
][] = array(
139 'name' => 'chosen_fontset',
140 'caption' => _("Font style"),
141 'type' => SMOPT_TYPE_STRLIST
,
142 'refresh' => SMOPT_REFRESH_ALL
,
143 'posvals' => $fontset_list
147 $optvals[SMOPT_GRP_GENERAL
][] = array(
148 'name' => 'chosen_fontsize',
149 'caption' => _("Font size"),
150 'type' => SMOPT_TYPE_STRLIST
,
151 'refresh' => SMOPT_REFRESH_ALL
,
152 'posvals' => array('' => _("Default font size"),
159 $language_values = array();
160 foreach ($languages as $lang_key => $lang_attributes) {
161 if (isset($lang_attributes['NAME'])) {
162 $language_values[$lang_key] = $lang_attributes['NAME'];
163 if ( isset($show_alternative_names) &&
164 $show_alternative_names &&
165 isset($lang_attributes['ALTNAME']) ) {
166 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
171 asort($language_values);
173 array_merge(array('' => _("Default")), $language_values);
174 $language = $squirrelmail_language;
176 // add language selection only when more than 2 languages are available
177 // (default, English and some other)
178 if (count($language_values)>2) {
179 $optvals[SMOPT_GRP_GENERAL
][] = array(
180 'name' => 'language',
181 'caption' => _("Language"),
182 'type' => SMOPT_TYPE_STRLIST
,
183 'refresh' => SMOPT_REFRESH_ALL
,
184 'posvals' => $language_values,
185 'htmlencoded' => true
189 /* Set values for the "use javascript" option. */
190 $optvals[SMOPT_GRP_GENERAL
][] = array(
191 'name' => 'javascript_setting',
192 'caption' => _("Use Javascript"),
193 'type' => SMOPT_TYPE_STRLIST
,
194 'refresh' => SMOPT_REFRESH_ALL
,
195 'posvals' => array(SMPREF_JS_AUTODETECT
=> _("Autodetect"),
196 SMPREF_JS_ON
=> _("Always"),
197 SMPREF_JS_OFF
=> _("Never")),
198 'save' => 'save_option_javascript_autodetect',
199 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON
. '\';"'
202 $optvals[SMOPT_GRP_GENERAL
][] = array(
203 'name' => 'js_autodetect_results',
205 'type' => SMOPT_TYPE_HIDDEN
,
206 'refresh' => SMOPT_REFRESH_NONE
207 //'post_script' => $js_autodetect_script,
210 $optvals[SMOPT_GRP_GENERAL
][] = array(
211 'name' => 'hour_format',
212 'caption' => _("Hour Format"),
213 'type' => SMOPT_TYPE_STRLIST
,
214 'refresh' => SMOPT_REFRESH_FOLDERLIST
,
215 'posvals' => array(SMPREF_TIME_12HR
=> _("12-hour clock"),
216 SMPREF_TIME_24HR
=> _("24-hour clock"))
219 /* Icon theme selection */
221 global $icon_themes, $icon_theme;
223 for ($count = 0; $count < sizeof($icon_themes); $count++
) {
224 $temp[$count] = $icon_themes[$count]['NAME'];
225 if ($icon_theme == $icon_themes[$count]['PATH'])
228 if (sizeof($icon_themes) > 0) {
229 $optvals[SMOPT_GRP_GENERAL
][] = array(
230 'name' => 'icon_theme',
231 'caption' => _("Icon Theme"),
232 'type' => SMOPT_TYPE_STRLIST
,
233 'refresh' => SMOPT_REFRESH_NONE
,
235 'initial_value' => $value,
236 'save' => 'icon_theme_save'
241 /*** Load the General Options into the array ***/
242 $optgrps[SMOPT_GRP_MAILBOX
] = _("Mailbox Display Options");
243 $optvals[SMOPT_GRP_MAILBOX
] = array();
245 $optvals[SMOPT_GRP_MAILBOX
][] = array(
246 'name' => 'show_num',
247 'caption' => _("Number of Messages per Page"),
248 'type' => SMOPT_TYPE_INTEGER
,
249 'refresh' => SMOPT_REFRESH_NONE
,
250 'size' => SMOPT_SIZE_TINY
253 $optvals[SMOPT_GRP_MAILBOX
][] = array(
254 'name' => 'alt_index_colors',
255 'caption' => _("Enable Alternating Row Colors"),
256 'type' => SMOPT_TYPE_BOOLEAN
,
257 'refresh' => SMOPT_REFRESH_NONE
260 $optvals[SMOPT_GRP_MAILBOX
][] = array(
261 'name' => 'fancy_index_highlite',
262 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
263 'type' => SMOPT_TYPE_BOOLEAN
,
264 'refresh' => SMOPT_REFRESH_NONE
267 $optvals[SMOPT_GRP_MAILBOX
][] = array(
268 'name' => 'show_flag_buttons',
269 'caption' => _("Show Flag / Unflag Buttons"),
270 'type' => SMOPT_TYPE_BOOLEAN
,
271 'refresh' => SMOPT_REFRESH_NONE
274 $optvals[SMOPT_GRP_MAILBOX
][] = array(
275 'name' => 'page_selector',
276 'caption' => _("Enable Page Selector"),
277 'type' => SMOPT_TYPE_BOOLEAN
,
278 'refresh' => SMOPT_REFRESH_NONE
281 $optvals[SMOPT_GRP_MAILBOX
][] = array(
282 'name' => 'compact_paginator',
283 'caption' => _("Use Compact Page Selector"),
284 'type' => SMOPT_TYPE_BOOLEAN
,
285 'refresh' => SMOPT_REFRESH_NONE
288 $optvals[SMOPT_GRP_MAILBOX
][] = array(
289 'name' => 'page_selector_max',
290 'caption' => _("Maximum Number of Pages to Show"),
291 'type' => SMOPT_TYPE_INTEGER
,
292 'refresh' => SMOPT_REFRESH_NONE
,
293 'size' => SMOPT_SIZE_TINY
296 $optvals[SMOPT_GRP_MAILBOX
][] = array(
297 'name' => 'show_full_date',
298 'caption' => _("Always Show Full Date"),
299 'type' => SMOPT_TYPE_BOOLEAN
,
300 'refresh' => SMOPT_REFRESH_NONE
303 $optvals[SMOPT_GRP_MAILBOX
][] = array(
304 'name' => 'truncate_sender',
305 'caption' => _("Length of From/To Field (0 for full)"),
306 'type' => SMOPT_TYPE_INTEGER
,
307 'refresh' => SMOPT_REFRESH_NONE
,
308 'size' => SMOPT_SIZE_TINY
311 $optvals[SMOPT_GRP_MAILBOX
][] = array(
312 'name' => 'truncate_subject',
313 'caption' => _("Length of Subject Field (0 for full)"),
314 'type' => SMOPT_TYPE_INTEGER
,
315 'refresh' => SMOPT_REFRESH_NONE
,
316 'size' => SMOPT_SIZE_TINY
319 disabled because the template doesn't support it (yet?)
320 $optvals[SMOPT_GRP_MAILBOX][] = array(
321 'name' => 'show_recipient_instead',
322 'caption' => _("Show recipient name if the message is from your default identity"),
323 'type' => SMOPT_TYPE_BOOLEAN,
324 'refresh' => SMOPT_REFRESH_NONE,
325 'size' => SMOPT_SIZE_TINY
329 if ($allow_thread_sort == TRUE) {
330 $optvals[SMOPT_GRP_MAILBOX
][] = array(
331 'name' => 'sort_by_ref',
332 'caption' => _("Enable Thread Sort by References Header"),
333 'type' => SMOPT_TYPE_BOOLEAN
,
334 'refresh' => SMOPT_REFRESH_ALL
340 /*** Load the General Options into the array ***/
341 $optgrps[SMOPT_GRP_MESSAGE
] = _("Message Display Options");
342 $optvals[SMOPT_GRP_MESSAGE
] = array();
344 $optvals[SMOPT_GRP_MESSAGE
][] = array(
346 'caption' => _("Wrap Incoming Text At"),
347 'type' => SMOPT_TYPE_INTEGER
,
348 'refresh' => SMOPT_REFRESH_NONE
,
349 'size' => SMOPT_SIZE_TINY
352 $optvals[SMOPT_GRP_MESSAGE
][] = array(
353 'name' => 'show_html_default',
354 'caption' => _("Show HTML Version by Default"),
355 'type' => SMOPT_TYPE_BOOLEAN
,
356 'refresh' => SMOPT_REFRESH_NONE
360 // Type is set to string in order to be able to use 100%.
361 $optvals[SMOPT_GRP_MESSAGE
][] = array(
362 'name' => 'iframe_height',
363 'caption' => _("Height of inline frame"),
364 'type' => SMOPT_TYPE_STRING
,
365 'size' => SMOPT_SIZE_TINY
,
366 'refresh' => SMOPT_REFRESH_NONE
369 $optvals[SMOPT_GRP_MESSAGE
][] = array(
370 'name' => 'enable_forward_as_attachment',
371 'caption' => _("Enable Forward as Attachment"),
372 'type' => SMOPT_TYPE_BOOLEAN
,
373 'refresh' => SMOPT_REFRESH_NONE
376 $optvals[SMOPT_GRP_MESSAGE
][] = array(
377 'name' => 'show_xmailer_default',
378 'caption' => _("Enable Mailer Display"),
379 'type' => SMOPT_TYPE_BOOLEAN
,
380 'refresh' => SMOPT_REFRESH_NONE
383 $optvals[SMOPT_GRP_MESSAGE
][] = array(
384 'name' => 'attachment_common_show_images',
385 'caption' => _("Display Attached Images with Message"),
386 'type' => SMOPT_TYPE_BOOLEAN
,
387 'refresh' => SMOPT_REFRESH_NONE
390 if ($default_use_mdn) {
391 $optvals[SMOPT_GRP_MESSAGE
][] = array(
392 'name' => 'mdn_user_support',
393 'caption' => _("Enable Mail Delivery Notification"),
394 'type' => SMOPT_TYPE_BOOLEAN
,
395 'refresh' => SMOPT_REFRESH_NONE
399 $optvals[SMOPT_GRP_MESSAGE
][] = array(
400 'name' => 'delete_prev_next_display',
401 'caption' => _("Show 'Delete & Prev/Next' Links"),
402 'type' => SMOPT_TYPE_BOOLEAN
,
403 'refresh' => SMOPT_REFRESH_ALL
406 /* Assemble all this together and return it as our result. */
414 /******************************************************************/
415 /** Define any specialized save functions for this option page. ***/
416 /******************************************************************/
419 * This function saves a new template setting.
420 * It updates the template array.
422 function save_option_template($option) {
423 global $aTemplateSet;
425 /* Do checking to make sure $new_theme is in the array. */
426 $templateset_in_array = false;
427 for ($i = 0; $i < count($aTemplateSet); ++
$i) {
428 if ($aTemplateSet[$i]['PATH'] == $option->new_value
) {
429 $templateset_in_array = true;
434 if (!$templateset_in_array) {
435 $option->new_value
= '';
437 /* Save the option like normal. */
438 save_option($option);
442 * This function saves a new theme setting.
443 * It updates the theme array.
445 function save_option_theme($option) {
448 /* Do checking to make sure $new_theme is in the array. */
449 $theme_in_array = false;
450 for ($i = 0; $i < count($theme); ++
$i) {
451 if ($theme[$i]['PATH'] == $option->new_value
) {
452 $theme_in_array = true;
457 if (!$theme_in_array) {
458 $option->new_value
= '';
461 /* Save the option like normal. */
462 save_option($option);
466 * This function saves the javascript detection option.
468 function save_option_javascript_autodetect($option) {
469 save_option($option);
470 checkForJavascript(TRUE);
474 * This function saves the user's icon theme setting
476 function icon_theme_save($option) {
478 global $icon_themes, $data_dir, $username;
481 // Don't assume the new value is there, double check
482 // and only save if found
484 if (isset($icon_themes[$option->new_value
]['PATH']))
485 setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value
]['PATH']);
487 setPref($data_dir, $username, 'icon_theme', 'none');