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