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