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