cf7ef5f7b72f74933c1b2a9ebca8a92daeef5127
[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-2005 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, $language, $languages,
53 $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
54 $show_alternative_names, $use_icons, $use_iframe;
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 theme option. */
69 $theme_values = array();
70 foreach ($theme as $theme_key => $theme_attributes) {
71 $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
72 }
73 ksort($theme_values);
74 $theme_values = array_flip($theme_values);
75 $optvals[SMOPT_GRP_GENERAL][] = array(
76 'name' => 'chosen_theme',
77 'caption' => _("Theme"),
78 'type' => SMOPT_TYPE_STRLIST,
79 'refresh' => SMOPT_REFRESH_ALL,
80 'posvals' => $theme_values,
81 'save' => 'save_option_theme'
82 );
83
84 $css_values = array( 'none' => _("Default" ) );
85 $css_dir = SM_PATH . 'themes/css';
86 if (is_readable($css_dir) && is_dir($css_dir)) {
87 $handle=opendir($css_dir);
88 while ($file = readdir($handle) ) {
89 if ( substr( $file, -4 ) == '.css' ) {
90 $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
91 }
92 }
93 closedir($handle);
94 }
95
96 if ( count( $css_values ) > 1 ) {
97
98 $optvals[SMOPT_GRP_GENERAL][] = array(
99 'name' => 'custom_css',
100 'caption' => _("Custom Stylesheet"),
101 'type' => SMOPT_TYPE_STRLIST,
102 'refresh' => SMOPT_REFRESH_ALL,
103 'posvals' => $css_values
104 );
105
106 }
107
108 $language_values = array();
109 foreach ($languages as $lang_key => $lang_attributes) {
110 if (isset($lang_attributes['NAME'])) {
111 $language_values[$lang_key] = $lang_attributes['NAME'];
112 if ( isset($show_alternative_names) &&
113 $show_alternative_names &&
114 isset($lang_attributes['ALTNAME']) ) {
115 $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
116 }
117 }
118 }
119
120 asort($language_values);
121 $language_values =
122 array_merge(array('' => _("Default")), $language_values);
123 $language = $squirrelmail_language;
124
125 // TODO: maybe we can add count($language_values) check here
126 $optvals[SMOPT_GRP_GENERAL][] = array(
127 'name' => 'language',
128 'caption' => _("Language"),
129 'type' => SMOPT_TYPE_STRLIST,
130 'refresh' => SMOPT_REFRESH_ALL,
131 'posvals' => $language_values,
132 'htmlencoded' => true
133 );
134
135 /* Set values for the "use javascript" option. */
136 $optvals[SMOPT_GRP_GENERAL][] = array(
137 'name' => 'javascript_setting',
138 'caption' => _("Use Javascript"),
139 'type' => SMOPT_TYPE_STRLIST,
140 'refresh' => SMOPT_REFRESH_ALL,
141 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
142 SMPREF_JS_ON => _("Always"),
143 SMPREF_JS_OFF => _("Never")),
144 'save' => 'save_option_javascript_autodetect',
145 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
146 );
147
148 $optvals[SMOPT_GRP_GENERAL][] = array(
149 'name' => 'js_autodetect_results',
150 'caption' => '',
151 'type' => SMOPT_TYPE_HIDDEN,
152 'refresh' => SMOPT_REFRESH_NONE
153 //'post_script' => $js_autodetect_script,
154 );
155
156 $optvals[SMOPT_GRP_GENERAL][] = array(
157 'name' => 'hour_format',
158 'caption' => _("Hour Format"),
159 'type' => SMOPT_TYPE_STRLIST,
160 'refresh' => SMOPT_REFRESH_FOLDERLIST,
161 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
162 SMPREF_TIME_24HR => _("24-hour clock"))
163 );
164
165 /*** Load the General Options into the array ***/
166 $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
167 $optvals[SMOPT_GRP_MAILBOX] = array();
168
169 $optvals[SMOPT_GRP_MAILBOX][] = array(
170 'name' => 'show_num',
171 'caption' => _("Number of Messages per Page"),
172 'type' => SMOPT_TYPE_INTEGER,
173 'refresh' => SMOPT_REFRESH_NONE,
174 'size' => SMOPT_SIZE_TINY
175 );
176
177 $optvals[SMOPT_GRP_MAILBOX][] = array(
178 'name' => 'alt_index_colors',
179 'caption' => _("Enable Alternating Row Colors"),
180 'type' => SMOPT_TYPE_BOOLEAN,
181 'refresh' => SMOPT_REFRESH_NONE
182 );
183
184 $optvals[SMOPT_GRP_MAILBOX][] = array(
185 'name' => 'fancy_index_highlite',
186 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
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 if (sizeof($icon_themes) > 0) {
200 $optvals[SMOPT_GRP_MAILBOX][] = array(
201 'name' => 'icon_theme',
202 'caption' => _("Message Flags Icon Theme"),
203 'type' => SMOPT_TYPE_STRLIST,
204 'refresh' => SMOPT_REFRESH_NONE,
205 'posvals' => $temp,
206 'initial_value' => $value,
207 'save' => 'icon_theme_save'
208 );
209 }
210 }
211
212 $optvals[SMOPT_GRP_MAILBOX][] = array(
213 'name' => 'show_flag_buttons',
214 'caption' => _("Show Flag / Unflag Buttons"),
215 'type' => SMOPT_TYPE_BOOLEAN,
216 'refresh' => SMOPT_REFRESH_NONE
217 );
218
219 $optvals[SMOPT_GRP_MAILBOX][] = array(
220 'name' => 'page_selector',
221 'caption' => _("Enable Page Selector"),
222 'type' => SMOPT_TYPE_BOOLEAN,
223 'refresh' => SMOPT_REFRESH_NONE
224 );
225
226 $optvals[SMOPT_GRP_MAILBOX][] = array(
227 'name' => 'compact_paginator',
228 'caption' => _("Use Compact Page Selector"),
229 'type' => SMOPT_TYPE_BOOLEAN,
230 'refresh' => SMOPT_REFRESH_NONE
231 );
232
233 $optvals[SMOPT_GRP_MAILBOX][] = array(
234 'name' => 'page_selector_max',
235 'caption' => _("Maximum Number of Pages to Show"),
236 'type' => SMOPT_TYPE_INTEGER,
237 'refresh' => SMOPT_REFRESH_NONE,
238 'size' => SMOPT_SIZE_TINY
239 );
240
241 $optvals[SMOPT_GRP_MAILBOX][] = array(
242 'name' => 'show_full_date',
243 'caption' => _("Always Show Full Date"),
244 'type' => SMOPT_TYPE_BOOLEAN,
245 'refresh' => SMOPT_REFRESH_NONE
246 );
247
248 $optvals[SMOPT_GRP_MAILBOX][] = array(
249 'name' => 'truncate_sender',
250 'caption' => _("Length of From/To Field (0 for full)"),
251 'type' => SMOPT_TYPE_INTEGER,
252 'refresh' => SMOPT_REFRESH_NONE,
253 'size' => SMOPT_SIZE_TINY
254 );
255
256 $optvals[SMOPT_GRP_MAILBOX][] = array(
257 'name' => 'truncate_subject',
258 'caption' => _("Length of Subject Field (0 for full)"),
259 'type' => SMOPT_TYPE_INTEGER,
260 'refresh' => SMOPT_REFRESH_NONE,
261 'size' => SMOPT_SIZE_TINY
262 );
263 /*
264 disabled because the template doesn't support it (yet?)
265 $optvals[SMOPT_GRP_MAILBOX][] = array(
266 'name' => 'show_recipient_instead',
267 'caption' => _("Show recipient name if the message is from your default identity"),
268 'type' => SMOPT_TYPE_BOOLEAN,
269 'refresh' => SMOPT_REFRESH_NONE,
270 'size' => SMOPT_SIZE_TINY
271 );
272 */
273
274 if ($allow_thread_sort == TRUE) {
275 $optvals[SMOPT_GRP_MAILBOX][] = array(
276 'name' => 'sort_by_ref',
277 'caption' => _("Enable Thread Sort by References Header"),
278 'type' => SMOPT_TYPE_BOOLEAN,
279 'refresh' => SMOPT_REFRESH_ALL
280 );
281 }
282
283
284
285 /*** Load the General Options into the array ***/
286 $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
287 $optvals[SMOPT_GRP_MESSAGE] = array();
288
289 $optvals[SMOPT_GRP_MESSAGE][] = array(
290 'name' => 'wrap_at',
291 'caption' => _("Wrap Incoming Text At"),
292 'type' => SMOPT_TYPE_INTEGER,
293 'refresh' => SMOPT_REFRESH_NONE,
294 'size' => SMOPT_SIZE_TINY
295 );
296
297 $optvals[SMOPT_GRP_MESSAGE][] = array(
298 'name' => 'show_html_default',
299 'caption' => _("Show HTML Version by Default"),
300 'type' => SMOPT_TYPE_BOOLEAN,
301 'refresh' => SMOPT_REFRESH_NONE
302 );
303
304 if ($use_iframe) {
305 // Type is set to string in order to be able to use 100%.
306 $optvals[SMOPT_GRP_MESSAGE][] = array(
307 'name' => 'iframe_height',
308 'caption' => _("Height of inline frame"),
309 'type' => SMOPT_TYPE_STRING,
310 'size' => SMOPT_SIZE_TINY,
311 'refresh' => SMOPT_REFRESH_NONE
312 );
313 }
314 $optvals[SMOPT_GRP_MESSAGE][] = array(
315 'name' => 'enable_forward_as_attachment',
316 'caption' => _("Enable Forward as Attachment"),
317 'type' => SMOPT_TYPE_BOOLEAN,
318 'refresh' => SMOPT_REFRESH_NONE
319 );
320
321 $optvals[SMOPT_GRP_MESSAGE][] = array(
322 'name' => 'show_xmailer_default',
323 'caption' => _("Enable Mailer Display"),
324 'type' => SMOPT_TYPE_BOOLEAN,
325 'refresh' => SMOPT_REFRESH_NONE
326 );
327
328 $optvals[SMOPT_GRP_MESSAGE][] = array(
329 'name' => 'attachment_common_show_images',
330 'caption' => _("Display Attached Images with Message"),
331 'type' => SMOPT_TYPE_BOOLEAN,
332 'refresh' => SMOPT_REFRESH_NONE
333 );
334
335 if ($default_use_mdn) {
336 $optvals[SMOPT_GRP_MESSAGE][] = array(
337 'name' => 'mdn_user_support',
338 'caption' => _("Enable Mail Delivery Notification"),
339 'type' => SMOPT_TYPE_BOOLEAN,
340 'refresh' => SMOPT_REFRESH_NONE
341 );
342 }
343
344 $optvals[SMOPT_GRP_MESSAGE][] = array(
345 'name' => 'delete_prev_next_display',
346 'caption' => _("Show 'Delete & Prev/Next' Links"),
347 'type' => SMOPT_TYPE_BOOLEAN,
348 'refresh' => SMOPT_REFRESH_ALL
349 );
350
351 /* Assemble all this together and return it as our result. */
352 $result = array(
353 'grps' => $optgrps,
354 'vals' => $optvals
355 );
356 return ($result);
357 }
358
359 /******************************************************************/
360 /** Define any specialized save functions for this option page. ***/
361 /******************************************************************/
362
363 /**
364 * This function saves a new theme setting.
365 * It updates the theme array.
366 */
367 function save_option_theme($option) {
368 global $theme;
369
370 /* Do checking to make sure $new_theme is in the array. */
371 $theme_in_array = false;
372 for ($i = 0; $i < count($theme); ++$i) {
373 if ($theme[$i]['PATH'] == $option->new_value) {
374 $theme_in_array = true;
375 break;
376 }
377 }
378
379 if (!$theme_in_array) {
380 $option->new_value = '';
381 }
382
383 /* Save the option like normal. */
384 save_option($option);
385 }
386
387 /**
388 * This function saves the javascript detection option.
389 */
390 function save_option_javascript_autodetect($option) {
391 save_option($option);
392 checkForJavascript(TRUE);
393 }
394
395 /**
396 * This function saves the user's icon theme setting
397 */
398 function icon_theme_save($option) {
399
400 global $icon_themes, $data_dir, $username;
401
402
403 // Don't assume the new value is there, double check
404 // and only save if found
405 //
406 if (isset($icon_themes[$option->new_value]['PATH']))
407 setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
408 else
409 setPref($data_dir, $username, 'icon_theme', 'none');
410
411 }
412
413 ?>