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