Cleaned up options main for IE and Netscape compatibility. Did major work on the...
[squirrelmail.git] / src / options.php
1 <?php
2
3 /**
4 * options.php
5 *
6 * Copyright (c) 1999-2001 The SquirrelMail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Displays the options page. Pulls from proper user preference files
10 * and config.php. Displays preferences as selected and other options.
11 *
12 * $Id$
13 */
14
15 require_once('../src/validate.php');
16 require_once('../functions/display_messages.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/options.php');
20
21 /* Set the base uri. */
22 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
23 $base_uri = $regs[1];
24
25 /* First and foremost, deal with language stuff. */
26 if (isset($language)) {
27 setcookie('squirrelmail_language', $language, time()+2592000, $base_uri);
28 $squirrelmail_language = $language;
29 } else {
30 $language = getPref($data_dir, $username, 'language');
31 }
32
33 /*********************************/
34 /*** Build the resultant page. ***/
35 /*********************************/
36
37 displayPageHeader($color, _("None"));
38
39 define('SMOPT_MODE_DISPLAY', 'display');
40 define('SMOPT_MODE_SUBMIT', 'submit');
41 define('SMOPT_MODE_LINK', 'link');
42
43 define('SMOPT_PAGE_MAIN', 'main');
44 define('SMOPT_PAGE_PERSONAL', 'personal');
45 define('SMOPT_PAGE_DISPLAY', 'display');
46 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
47 define('SMOPT_PAGE_FOLDER', 'folder');
48 define('SMOPT_PAGE_ORDER', 'order');
49
50 function process_optionmode_submit($optpage, $optpage_data) {
51 /* Initialize the maximum option refresh level. */
52 $max_refresh = SMOPT_REFRESH_NONE;
53
54 /* Save each option in each option group. */
55 foreach ($optpage_data['options'] as $option_grp) {
56 foreach ($option_grp['options'] as $option) {
57 echo "name = '$option->name', "
58 . "value = '$option->value', "
59 . "new_value = '$option->new_value'<BR>\n";
60 if ($option->changed()) {
61 $option->save();
62 $max_refresh = max($max_refresh, $option->refresh_level);
63 }
64 }
65 }
66
67 /* Return the max refresh level. */
68 return ($max_refresh);
69 }
70
71 function process_optionmode_link($optpage) {
72 /* There will be something here, later. */
73 }
74
75 /* Make sure we have an Option Page set. Default to main. */
76 if (!isset($optpage)) {
77 $optpage = 'main';
78 }
79
80 /* Make sure we have an Option Mode set. Default to display. */
81 if (!isset($optmode)) {
82 $optmode = SMOPT_MODE_DISPLAY;
83 }
84
85 /*************************************************************/
86 /*** First, set the load information for each option page. ***/
87 /*************************************************************/
88
89 /* Initialize load information variables. */
90 $optpage_name = '';
91 $optpage_file = '';
92 $optpage_loader = '';
93
94 /* Set the load information for each page. */
95 switch ($optpage) {
96 case SMOPT_PAGE_MAIN: break;
97 case SMOPT_PAGE_PERSONAL:
98 $optpage_name = _("Personal Information");
99 $optpage_file = 'options_personal.php';
100 $optpage_loader = 'load_optpage_data_personal';
101 break;
102 case SMOPT_PAGE_DISPLAY:
103 $optpage_name = _("Display Preferences");
104 $optpage_file = 'options_display.php';
105 $optpage_loader = 'load_optpage_data_display';
106 break;
107 case SMOPT_PAGE_HIGHLIGHT:
108 $optpage_name = _("Message Highlighting");
109 $optpage_file = 'options_highlight.php';
110 $optpage_loader = 'load_optpage_data_highlight';
111 break;
112 case SMOPT_PAGE_FOLDER:
113 $optpage_name = _("Folder Preferences");
114 $optpage_file = 'options_folder.php';
115 $optpage_loader = 'load_optpage_data_folder';
116 break;
117 case SMOPT_PAGE_ORDER:
118 $optpage_name = _("Index Order");
119 $optpage_file = 'options_order.php';
120 $optpage_loader = 'load_optpage_data_order';
121 break;
122 default: do_hook('set_optpage_loadinfo');
123 }
124
125 /**********************************************************/
126 /*** Second, load the option information for this page. ***/
127 /**********************************************************/
128
129 if ($optpage != SMOPT_PAGE_MAIN) {
130 /* Include the file for this optionpage. */
131 require_once($optpage_file);
132
133 /* Assemble the data for this option page. */
134 $optpage_data = array();
135 $optpage_data = $optpage_loader();
136 $optpage_data['options'] =
137 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
138 }
139
140 /***********************************************************/
141 /*** Next, process anything that needs to be processed. ***/
142 /***********************************************************/
143
144 switch ($optmode) {
145 case SMOPT_MODE_SUBMIT:
146 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
147 break;
148 case SMOPT_MODE_LINK:
149 $max_refresh = process_optionmode_link($optpage, $optpage_data);
150 break;
151 }
152
153 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
154
155 $optpage_title = _("Options");
156 if (isset($optpage_name) && ($optpage_name != '')) {
157 $optpage_title .= " - $optpage_name";
158 }
159
160 ?>
161
162 <BR>
163 <TABLE BGCOLOR="<?php echo $color[0] ?>" WIDTH="95%" ALIGN="CENTER" CELLPADDING="2" CELLSPACING="0" BORDER="0">
164 <TR><TD ALIGN="CENTER">
165 <B><?php echo $optpage_title; ?></B><BR>
166 <TABLE WIDTH="100%" BORDER="0" CELLPADDING="5" CELLSPACING="0">
167 <TR><TD BGCOLOR="<?php echo $color[4] ?>" ALIGN="CENTER">
168
169 <?php
170
171 /*******************************************************************/
172 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
173 /*******************************************************************/
174
175 /* If in submit mode, select a save hook name and run it. */
176 if ($optmode == SMOPT_MODE_SUBMIT) {
177 /* Select a save hook name. */
178 switch ($optpage) {
179 case SMOPT_PAGE_PERSONAL:
180 $save_hook_name = 'options_personal_save';
181 break;
182 case SMOPT_PAGE_DISPLAY:
183 $save_hook_name = 'options_display_save';
184 break;
185 case SMOPT_PAGE_FOLDER:
186 $save_hook_name = 'options_folder_save';
187 break;
188 default: $save_hook_name = 'options_save';
189 break;
190 }
191
192 /* Run the options save hook. */
193 do_hook($save_hook_name);
194 }
195
196 /***************************************************************/
197 /* Apply logic to decide what optpage we want to display next. */
198 /***************************************************************/
199
200 /* If this is the result of an option page being submitted, then */
201 /* show the main page. Otherwise, show whatever page was called. */
202
203 if ($optmode == SMOPT_MODE_SUBMIT) {
204 $optpage = SMOPT_PAGE_MAIN;
205 }
206
207 /***************************************************************/
208 /* Finally, display whatever page we are supposed to show now. */
209 /***************************************************************/
210
211 /*
212 * The main option page has a different layout then the rest of the option
213 * pages. Therefore, we create it here first, then the others below.
214 */
215 if ($optpage == SMOPT_PAGE_MAIN) {
216 /**********************************************************/
217 /* First, display the results of a submission, if needed. */
218 /**********************************************************/
219 if ($optmode == SMOPT_MODE_SUBMIT) {
220 /* Display a message indicating a successful save. */
221 echo '<B>' . _("Successfully Saved Options") . ": $optpage_name</B><BR>\n";
222
223 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
224 if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
225 echo '<A HREF="../src/left_main.php" TARGET="left">' . _("Refresh Folder List") . '</A><BR>';
226 } else if ($max_refresh) {
227 echo '<A HREF="../src/webmail.php?right_frame=options.php" TARGET="_top">' . _("Refresh Page") . '</A><BR>';
228 }
229 }
230 /******************************************/
231 /* Build our array of Option Page Blocks. */
232 /******************************************/
233 $optpage_blocks = array();
234
235 /* Build a section for Personal Options. */
236 $optpage_blocks[] = array(
237 'name' => _("Personal Information"),
238 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
239 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
240 'js' => false
241 );
242
243 /* Build a section for Display Options. */
244 $optpage_blocks[] = array(
245 'name' => _("Display Preferences"),
246 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
247 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
248 'js' => false
249 );
250
251 /* Build a section for Message Highlighting Options. */
252 $optpage_blocks[] = array(
253 'name' =>_("Message Highlighting"),
254 'url' => 'options_highlight.php',
255 'desc' =>_("Based upon given criteria, incoming messages can have different background colors in the message list. This helps to easily distinguish who the messages are from, especially for mailing lists."),
256 'js' => false
257 );
258
259 /* Build a section for Folder Options. */
260 $optpage_blocks[] = array(
261 'name' => _("Folder Preferences"),
262 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
263 'desc' => _("These settings change the way your folders are displayed and manipulated."),
264 'js' => false
265 );
266
267 /* Build a section for Index Order Options. */
268 $optpage_blocks[] = array(
269 'name' => _("Index Order"),
270 'url' => 'options_order.php',
271 'desc' => _("The order of the message index can be rearanged and changed to contain the headers in any order you want."),
272 'js' => false
273 );
274
275 /* Build a section for plugins wanting to register an optionpage. */
276 do_hook('optpage_register_block');
277
278 /*****************************************************/
279 /* Let's sort Javascript Option Pages to the bottom. */
280 /*****************************************************/
281 $js_optpage_blocks = array();
282 $reg_optpage_blocks = array();
283 foreach ($optpage_blocks as $cur_optpage) {
284 if (!$cur_optpage['js']) {
285 $reg_optpage_blocks[] = $cur_optpage;
286 } else if ($javascript_on == SMPREF_JS_ON) {
287 $js_optpage_blocks[] = $cur_optpage;
288 }
289 }
290 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
291
292 /********************************************/
293 /* Now, print out each option page section. */
294 /********************************************/
295 $first_optpage = false;
296 echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=\"5\" BORDER=\"0\">" .
297 '<TR><TD VALIGN="TOP">' .
298 "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" BORDER=\"0\">";
299 foreach ($optpage_blocks as $next_optpage) {
300 if ($first_optpage == false) {
301 $first_optpage = $next_optpage;
302 } else {
303 print_optionpages_row($first_optpage, $next_optpage);
304 $first_optpage = false;
305 }
306 }
307
308 if ($first_optpage != false) {
309 print_optionpages_row($first_optpage);
310 }
311
312 echo "</TABLE></TD></TR></TABLE>\n";
313
314 do_hook('options_link_and_description');
315
316
317 /*************************************************************************/
318 /* If we are not looking at the main option page, display the page here. */
319 /*************************************************************************/
320 } else {
321 echo '<FORM NAME="f" ACTION="options.php" METHOD="POST"><BR>' . "\n"
322 . '<TABLE WIDTH="100%" CELLPADDING="2" CELLSPACING="0" BORDER="0">' . "\n"
323 . create_optpage_element($optpage)
324 . create_optmode_element(SMOPT_MODE_SUBMIT);
325
326 /* Output the option groups for this page. */
327 print_option_groups($optpage_data['options']);
328
329 /*** FIXME: CURRENTLY, THIS NEXT SWITCH STATEMENT DOES NOT TAKE
330 *** INTO ACCOUNT FOR PLUGINS. NEED TO FIX IT. ***/
331
332 /* Set the inside_hook_name and submit_name. */
333 switch ($optpage) {
334 case SMOPT_PAGE_PERSONAL:
335 $inside_hook_name = 'options_personal_inside';
336 $bottom_hook_name = 'options_personal_bottom';
337 $submit_name = 'submit_personal';
338 break;
339 case SMOPT_PAGE_DISPLAY:
340 $inside_hook_name = 'options_display_inside';
341 $bottom_hook_name = 'options_display_bottom';
342 $submit_name = 'submit_display';
343 break;
344 case SMOPT_PAGE_HIGHLIGHT:
345 $inside_hook_name = 'options_highlight_inside';
346 $bottom_hook_name = 'options_display_bottom';
347 $submit_name = 'submit_highlight';
348 break;
349 case SMOPT_PAGE_FOLDER:
350 $inside_hook_name = 'options_folder_inside';
351 $bottom_hook_name = 'options_display_bottom';
352 $submit_name = 'submit_folder';
353 break;
354 case SMOPT_PAGE_ORDER:
355 $inside_hook_name = 'options_order_inside';
356 $bottom_hook_name = 'options_order_bottom';
357 $submit_name = 'submit_order';
358 break;
359 default:
360 $inside_hook_name = '';
361 $bottom_hook_name = '';
362 $submit_name = 'submit';
363 }
364
365 /* If it is not empty, trigger the inside hook. */
366 if ($inside_hook_name != '') {
367 do_hook($inside_hook_name);
368 }
369
370 /* Spit out a submit button. */
371 OptionSubmit($submit_name);
372 echo '</TABLE></FORM>';
373
374 /* If it is not empty, trigger the bottom hook. */
375 if ($bottom_hook_name != '') {
376 do_hook($bottom_hook_name);
377 }
378 }
379
380 ?>
381 </TD></TR>
382 </TABLE>
383
384 </TD></TR>
385 </TABLE>
386
387 </BODY></HTML>
388
389 <?php
390
391 /*******************************************************************/
392 /* Please be warned. The code below this point sucks. This is just */
393 /* my first implementation to make the option rows work for both */
394 /* Javascript and non-Javascript option chunks. */
395 /* */
396 /* Please, someone make these better for me. All three functions */
397 /* below REALLY do close to the same thing. */
398 /* */
399 /* This code would be GREATLY improved by a templating system. */
400 /* Don't try to implement that now, however. That will come later. */
401 /*******************************************************************/
402
403 /*******************************************************************/
404 /* Actually, now that I think about it, don't do anything with */
405 /* this code yet. There is ACTUALLY supposed to be a difference */
406 /* between the three functions that write the option rows. I just */
407 /* have not yet gotten to integrating that yet. */
408 /*******************************************************************/
409
410 /**
411 * This function prints out an option page row.
412 */
413 function print_optionpages_row($leftopt, $rightopt = false) {
414 global $color;
415
416 echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=5 BORDER=0>" .
417 '<TR><TD VALIGN="TOP">' .
418 '<TABLE WIDTH="100%" CELLPADDING="3" CELLSPACING="0" BORDER="0">' .
419 '<TR>' .
420 "<TD VALIGN=TOP BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
421 '<A HREF="' . $leftopt['url'] . '">' . $leftopt['name'] . '</A>'.
422 '</TD>'.
423 "<TD VALIGN=TOP BGCOLOR=\"$color[4]\">&nbsp;</TD>";
424 if ($rightopt) {
425 echo "<TD VALIGN=top BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
426 '<A HREF="' . $rightopt['url'] . '">' . $rightopt['name'] . '</A>' .
427 '</TD>';
428 } else {
429 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\">&nbsp;</TD>";
430 }
431
432 echo '</TR>' .
433 '<TR>' .
434 "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
435 $leftopt['desc'] .
436 '</TD>' .
437 "<TD VALIGN=top BGCOLOR=\"$color[4]\">&nbsp;</TD>";
438 if ($rightopt) {
439 echo "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
440 $rightopt['desc'] .
441 '</TD>';
442 } else {
443 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\">&nbsp;</TD>";
444 }
445
446 echo '</TR>' .
447 '</TABLE>' .
448 '</TD></TR>' .
449 "</TABLE>\n";
450 }
451
452 ?>