6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Displays the options page. Pulls from proper user preference files
10 * and config.php. Displays preferences as selected and other options.
15 require_once('../src/validate.php');
16 require_once('../functions/display_messages.php');
17 require_once('../functions/imap.php');
18 require_once('../functions/array.php');
19 require_once('../functions/options.php');
20 require_once('../functions/strings.php');
22 /*********************************/
23 /*** Build the resultant page. ***/
24 /*********************************/
26 displayPageHeader($color, 'None');
28 define('SMOPT_MODE_DISPLAY', 'display');
29 define('SMOPT_MODE_SUBMIT', 'submit');
30 define('SMOPT_MODE_LINK', 'link');
32 define('SMOPT_PAGE_MAIN', 'main');
33 define('SMOPT_PAGE_PERSONAL', 'personal');
34 define('SMOPT_PAGE_DISPLAY', 'display');
35 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
36 define('SMOPT_PAGE_FOLDER', 'folder');
37 define('SMOPT_PAGE_ORDER', 'order');
39 function process_optionmode_submit($optpage, $optpage_data) {
40 /* Initialize the maximum option refresh level. */
41 $max_refresh = SMOPT_REFRESH_NONE
;
43 /* Save each option in each option group. */
44 foreach ($optpage_data['options'] as $option_grp) {
45 foreach ($option_grp['options'] as $option) {
46 /* Remove Debug Mode Until Needed
47 echo "name = '$option->name', "
48 . "value = '$option->value', "
49 . "new_value = '$option->new_value'<BR>\n";
51 if ($option->changed()) {
53 $max_refresh = max($max_refresh, $option->refresh_level
);
58 /* Return the max refresh level. */
59 return ($max_refresh);
62 function process_optionmode_link($optpage) {
63 /* There will be something here, later. */
68 * This function prints out an option page row.
70 function print_optionpages_row($leftopt, $rightopt = false) {
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">' .
77 "<TD VALIGN=TOP BGCOLOR=\"$color[9]\" WIDTH=\"49%\">" .
78 '<A HREF="' . $leftopt['url'] . '">' . $leftopt['name'] . '</A>'.
80 "<TD VALIGN=TOP BGCOLOR=\"$color[4]\" WIDTH=\"2%\"> </TD>";
82 echo "<TD VALIGN=top BGCOLOR=\"$color[9]\" WIDTH=\"49%\">" .
83 '<A HREF="' . $rightopt['url'] . '">' . $rightopt['name'] . '</A>' .
86 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"49%\"> </TD>";
91 "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"49%\">" .
94 "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"2%\"> </TD>";
96 echo "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"49%\">" .
100 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"49%\"> </TD>";
109 /* ---------------------------- main ---------------------------- */
111 /* Make sure we have an Option Page set. Default to main. */
112 if (!isset($optpage)) {
116 /* Make sure we have an Option Mode set. Default to display. */
117 if (!isset($optmode)) {
118 $optmode = SMOPT_MODE_DISPLAY
;
122 * First, set the load information for each option page.
125 /* Initialize load information variables. */
128 $optpage_loader = '';
130 /* Set the load information for each page. */
132 case SMOPT_PAGE_MAIN
: break;
133 case SMOPT_PAGE_PERSONAL
:
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';
139 case SMOPT_PAGE_DISPLAY
:
140 $optpage_name = _("Display Preferences");
141 $optpage_file = '../src/options_display.php';
142 $optpage_loader = 'load_optpage_data_display';
143 $optpage_loadhook = 'optpage_loadhook_display';
145 case SMOPT_PAGE_HIGHLIGHT
:
146 $optpage_name = _("Message Highlighting");
147 $optpage_file = '../src/options_highlight.php';
148 $optpage_loader = 'load_optpage_data_highlight';
149 $optpage_loadhook = 'optpage_loadhook_highlight';
151 case SMOPT_PAGE_FOLDER
:
152 $optpage_name = _("Folder Preferences");
153 $optpage_file = '../src/options_folder.php';
154 $optpage_loader = 'load_optpage_data_folder';
155 $optpage_loadhook = 'optpage_loadhook_folder';
157 case SMOPT_PAGE_ORDER
:
158 $optpage_name = _("Index Order");
159 $optpage_file = '../src/options_order.php';
160 $optpage_loader = 'load_optpage_data_order';
161 $optpage_loadhook = 'optpage_loadhook_order';
163 default: do_hook('optpage_set_loadinfo');
166 /**********************************************************/
167 /*** Second, load the option information for this page. ***/
168 /**********************************************************/
170 if ($optpage != SMOPT_PAGE_MAIN
) {
171 /* Include the file for this optionpage. */
172 require_once($optpage_file);
174 /* Assemble the data for this option page. */
175 $optpage_data = array();
176 $optpage_data = $optpage_loader();
177 do_hook($optpage_loadhook);
178 $optpage_data['options'] =
179 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
182 /***********************************************************/
183 /*** Next, process anything that needs to be processed. ***/
184 /***********************************************************/
186 if ( isset( $optpage_data ) ) {
188 case SMOPT_MODE_SUBMIT
:
189 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
191 case SMOPT_MODE_LINK
:
192 $max_refresh = process_optionmode_link($optpage, $optpage_data);
196 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
198 $optpage_title = _("Options");
199 if (isset($optpage_name) && ($optpage_name != '')) {
200 $optpage_title .= " - $optpage_name";
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";
210 /*******************************************************************/
211 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
212 /*******************************************************************/
214 /* If in submit mode, select a save hook name and run it. */
215 if ($optmode == SMOPT_MODE_SUBMIT
) {
216 /* Select a save hook name. */
218 case SMOPT_PAGE_PERSONAL
:
219 $save_hook_name = 'options_personal_save';
221 case SMOPT_PAGE_DISPLAY
:
222 $save_hook_name = 'options_display_save';
224 case SMOPT_PAGE_FOLDER
:
225 $save_hook_name = 'options_folder_save';
228 $save_hook_name = 'options_save';
232 /* Run the options save hook. */
233 do_hook($save_hook_name);
236 /***************************************************************/
237 /* Apply logic to decide what optpage we want to display next. */
238 /***************************************************************/
240 /* If this is the result of an option page being submitted, then */
241 /* show the main page. Otherwise, show whatever page was called. */
243 if ($optmode == SMOPT_MODE_SUBMIT
) {
244 $optpage = SMOPT_PAGE_MAIN
;
247 /***************************************************************/
248 /* Finally, display whatever page we are supposed to show now. */
249 /***************************************************************/
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.
255 if ($optpage == SMOPT_PAGE_MAIN
) {
256 /**********************************************************/
257 /* First, display the results of a submission, if needed. */
258 /**********************************************************/
259 if ($optmode == SMOPT_MODE_SUBMIT
) {
260 if (!isset($frame_top)) {
263 /* Display a message indicating a successful save. */
264 echo '<B>' . _("Successfully Saved Options") . ": $optpage_name</B><BR>\n";
266 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
267 if ( !isset( $max_refresh ) ) {
268 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
269 echo '<A HREF="../src/left_main.php" TARGET="left">' . _("Refresh Folder List") . '</A><BR>';
270 } else if ($max_refresh) {
271 echo '<A HREF="../src/webmail.php?right_frame=options.php" TARGET="' . $frame_top . '">' . _("Refresh Page") . '</A><BR>';
274 /******************************************/
275 /* Build our array of Option Page Blocks. */
276 /******************************************/
277 $optpage_blocks = array();
279 /* Build a section for Personal Options. */
280 $optpage_blocks[] = array(
281 'name' => _("Personal Information"),
282 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
283 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
287 /* Build a section for Display Options. */
288 $optpage_blocks[] = array(
289 'name' => _("Display Preferences"),
290 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
291 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
295 /* Build a section for Message Highlighting Options. */
296 $optpage_blocks[] = array(
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."),
303 /* Build a section for Folder Options. */
304 $optpage_blocks[] = array(
305 'name' => _("Folder Preferences"),
306 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
307 'desc' => _("These settings change the way your folders are displayed and manipulated."),
311 /* Build a section for Index Order Options. */
312 $optpage_blocks[] = array(
313 'name' => _("Index Order"),
314 'url' => 'options_order.php',
315 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
319 /* Build a section for plugins wanting to register an optionpage. */
320 do_hook('optpage_register_block');
322 /*****************************************************/
323 /* Let's sort Javascript Option Pages to the bottom. */
324 /*****************************************************/
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;
330 } else if ($javascript_on == SMPREF_JS_ON
) {
331 $js_optpage_blocks[] = $cur_optpage;
334 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
336 /********************************************/
337 /* Now, print out each option page section. */
338 /********************************************/
339 $first_optpage = false;
340 echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=\"5\" BORDER=\"0\">" .
341 '<TR><TD VALIGN="TOP">' .
342 "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" BORDER=\"0\"><TR><TD>";
343 foreach ($optpage_blocks as $next_optpage) {
344 if ($first_optpage == false) {
345 $first_optpage = $next_optpage;
347 print_optionpages_row($first_optpage, $next_optpage);
348 $first_optpage = false;
352 if ($first_optpage != false) {
353 print_optionpages_row($first_optpage);
356 echo "</TD></TR></TABLE></TD></TR></TABLE>\n";
358 do_hook('options_link_and_description');
361 /*************************************************************************/
362 /* If we are not looking at the main option page, display the page here. */
363 /*************************************************************************/
365 echo '<FORM NAME="f" ACTION="options.php" METHOD="POST"><BR>' . "\n"
366 . create_optpage_element($optpage)
367 . create_optmode_element(SMOPT_MODE_SUBMIT
)
368 . '<TABLE WIDTH="100%" CELLPADDING=2 CELLSPACING=0 BORDER=0>' . "\n";
370 /* Output the option groups for this page. */
371 print_option_groups($optpage_data['options']);
373 /* Set the inside_hook_name and submit_name. */
375 case SMOPT_PAGE_PERSONAL
:
376 $inside_hook_name = 'options_personal_inside';
377 $bottom_hook_name = 'options_personal_bottom';
378 $submit_name = 'submit_personal';
380 case SMOPT_PAGE_DISPLAY
:
381 $inside_hook_name = 'options_display_inside';
382 $bottom_hook_name = 'options_display_bottom';
383 $submit_name = 'submit_display';
385 case SMOPT_PAGE_HIGHLIGHT
:
386 $inside_hook_name = 'options_highlight_inside';
387 $bottom_hook_name = 'options_highlight_bottom';
388 $submit_name = 'submit_highlight';
390 case SMOPT_PAGE_FOLDER
:
391 $inside_hook_name = 'options_folder_inside';
392 $bottom_hook_name = 'options_folder_bottom';
393 $submit_name = 'submit_folder';
395 case SMOPT_PAGE_ORDER
:
396 $inside_hook_name = 'options_order_inside';
397 $bottom_hook_name = 'options_order_bottom';
398 $submit_name = 'submit_order';
401 $inside_hook_name = '';
402 $bottom_hook_name = '';
403 $submit_name = 'submit';
406 /* If it is not empty, trigger the inside hook. */
407 if ($inside_hook_name != '') {
408 do_hook($inside_hook_name);
411 /* Spit out a submit button. */
412 OptionSubmit($submit_name);
413 echo '</TABLE></FORM>';
415 /* If it is not empty, trigger the bottom hook. */
416 if ($bottom_hook_name != '') {
417 do_hook($bottom_hook_name);