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