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