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