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 /* Set the base uri. */
23 ereg ("(^.*/)[^/]+/[^/]+$", $PHP_SELF, $regs);
26 /* First and foremost, deal with language stuff. */
27 if (isset($language)) {
28 setcookie('squirrelmail_language', $language, time()+
2592000, $base_uri);
29 $squirrelmail_language = $language;
31 $language = getPref($data_dir, $username, 'language');
34 /*********************************/
35 /*** Build the resultant page. ***/
36 /*********************************/
38 displayPageHeader($color, 'None');
40 define('SMOPT_MODE_DISPLAY', 'display');
41 define('SMOPT_MODE_SUBMIT', 'submit');
42 define('SMOPT_MODE_LINK', 'link');
44 define('SMOPT_PAGE_MAIN', 'main');
45 define('SMOPT_PAGE_PERSONAL', 'personal');
46 define('SMOPT_PAGE_DISPLAY', 'display');
47 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
48 define('SMOPT_PAGE_FOLDER', 'folder');
49 define('SMOPT_PAGE_ORDER', 'order');
51 function process_optionmode_submit($optpage, $optpage_data) {
52 /* Initialize the maximum option refresh level. */
53 $max_refresh = SMOPT_REFRESH_NONE
;
55 /* Save each option in each option group. */
56 foreach ($optpage_data['options'] as $option_grp) {
57 foreach ($option_grp['options'] as $option) {
58 /* Remove Debug Mode Until Needed
59 echo "name = '$option->name', "
60 . "value = '$option->value', "
61 . "new_value = '$option->new_value'<BR>\n";
63 if ($option->changed()) {
65 $max_refresh = max($max_refresh, $option->refresh_level
);
70 /* Return the max refresh level. */
71 return ($max_refresh);
74 function process_optionmode_link($optpage) {
75 /* There will be something here, later. */
78 /* Make sure we have an Option Page set. Default to main. */
79 if (!isset($optpage)) {
83 /* Make sure we have an Option Mode set. Default to display. */
84 if (!isset($optmode)) {
85 $optmode = SMOPT_MODE_DISPLAY
;
88 /*************************************************************/
89 /*** First, set the load information for each option page. ***/
90 /*************************************************************/
92 /* Initialize load information variables. */
97 /* Set the load information for each page. */
99 case SMOPT_PAGE_MAIN
: break;
100 case SMOPT_PAGE_PERSONAL
:
101 $optpage_name = _("Personal Information");
102 $optpage_file = '../src/options_personal.php';
103 $optpage_loader = 'load_optpage_data_personal';
104 $optpage_loadhook = 'optpage_loadhook_personal';
106 case SMOPT_PAGE_DISPLAY
:
107 $optpage_name = _("Display Preferences");
108 $optpage_file = '../src/options_display.php';
109 $optpage_loader = 'load_optpage_data_display';
110 $optpage_loadhook = 'optpage_loadhook_display';
112 case SMOPT_PAGE_HIGHLIGHT
:
113 $optpage_name = _("Message Highlighting");
114 $optpage_file = '../src/options_highlight.php';
115 $optpage_loader = 'load_optpage_data_highlight';
116 $optpage_loadhook = 'optpage_loadhook_highlight';
118 case SMOPT_PAGE_FOLDER
:
119 $optpage_name = _("Folder Preferences");
120 $optpage_file = '../src/options_folder.php';
121 $optpage_loader = 'load_optpage_data_folder';
122 $optpage_loadhook = 'optpage_loadhook_folder';
124 case SMOPT_PAGE_ORDER
:
125 $optpage_name = _("Index Order");
126 $optpage_file = '../src/options_order.php';
127 $optpage_loader = 'load_optpage_data_order';
128 $optpage_loadhook = 'optpage_loadhook_order';
130 default: do_hook('optpage_set_loadinfo');
133 /**********************************************************/
134 /*** Second, load the option information for this page. ***/
135 /**********************************************************/
137 if ($optpage != SMOPT_PAGE_MAIN
) {
138 /* Include the file for this optionpage. */
139 require_once($optpage_file);
141 /* Assemble the data for this option page. */
142 $optpage_data = array();
143 $optpage_data = $optpage_loader();
144 do_hook($optpage_loadhook);
145 $optpage_data['options'] =
146 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
149 /***********************************************************/
150 /*** Next, process anything that needs to be processed. ***/
151 /***********************************************************/
153 if ( isset( $optpage_data ) ) {
155 case SMOPT_MODE_SUBMIT
:
156 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
158 case SMOPT_MODE_LINK
:
159 $max_refresh = process_optionmode_link($optpage, $optpage_data);
163 /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/
165 $optpage_title = _("Options");
166 if (isset($optpage_name) && ($optpage_name != '')) {
167 $optpage_title .= " - $optpage_name";
173 <TABLE BGCOLOR
="<?php echo $color[0] ?>" WIDTH
="95%" ALIGN
="CENTER" CELLPADDING
="2" CELLSPACING
="0" BORDER
="0">
174 <TR
><TD ALIGN
="CENTER">
175 <B
><?php
echo $optpage_title; ?
></B
><BR
>
176 <TABLE WIDTH
="100%" BORDER
="0" CELLPADDING
="5" CELLSPACING
="0">
177 <TR
><TD BGCOLOR
="<?php echo $color[4] ?>" ALIGN
="CENTER">
181 /*******************************************************************/
182 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
183 /*******************************************************************/
185 /* If in submit mode, select a save hook name and run it. */
186 if ($optmode == SMOPT_MODE_SUBMIT
) {
187 /* Select a save hook name. */
189 case SMOPT_PAGE_PERSONAL
:
190 $save_hook_name = 'options_personal_save';
192 case SMOPT_PAGE_DISPLAY
:
193 $save_hook_name = 'options_display_save';
195 case SMOPT_PAGE_FOLDER
:
196 $save_hook_name = 'options_folder_save';
199 $save_hook_name = 'options_save';
203 /* Run the options save hook. */
204 do_hook($save_hook_name);
207 /***************************************************************/
208 /* Apply logic to decide what optpage we want to display next. */
209 /***************************************************************/
211 /* If this is the result of an option page being submitted, then */
212 /* show the main page. Otherwise, show whatever page was called. */
214 if ($optmode == SMOPT_MODE_SUBMIT
) {
215 $optpage = SMOPT_PAGE_MAIN
;
218 /***************************************************************/
219 /* Finally, display whatever page we are supposed to show now. */
220 /***************************************************************/
223 * The main option page has a different layout then the rest of the option
224 * pages. Therefore, we create it here first, then the others below.
226 if ($optpage == SMOPT_PAGE_MAIN
) {
227 /**********************************************************/
228 /* First, display the results of a submission, if needed. */
229 /**********************************************************/
230 if ($optmode == SMOPT_MODE_SUBMIT
) {
231 if (!isset($frame_top)) {
234 /* Display a message indicating a successful save. */
235 echo '<B>' . _("Successfully Saved Options") . ": $optpage_name</B><BR>\n";
237 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
238 if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
239 echo '<A HREF="../src/left_main.php" TARGET="left">' . _("Refresh Folder List") . '</A><BR>';
240 } else if ($max_refresh) {
241 echo '<A HREF="../src/webmail.php?right_frame=options.php" TARGET="' . $frame_top . '">' . _("Refresh Page") . '</A><BR>';
244 /******************************************/
245 /* Build our array of Option Page Blocks. */
246 /******************************************/
247 $optpage_blocks = array();
249 /* Build a section for Personal Options. */
250 $optpage_blocks[] = array(
251 'name' => _("Personal Information"),
252 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
253 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
257 /* Build a section for Display Options. */
258 $optpage_blocks[] = array(
259 'name' => _("Display Preferences"),
260 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
261 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
265 /* Build a section for Message Highlighting Options. */
266 $optpage_blocks[] = array(
267 'name' =>_("Message Highlighting"),
268 'url' => 'options_highlight.php',
269 '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."),
273 /* Build a section for Folder Options. */
274 $optpage_blocks[] = array(
275 'name' => _("Folder Preferences"),
276 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
277 'desc' => _("These settings change the way your folders are displayed and manipulated."),
281 /* Build a section for Index Order Options. */
282 $optpage_blocks[] = array(
283 'name' => _("Index Order"),
284 'url' => 'options_order.php',
285 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
289 /* Build a section for plugins wanting to register an optionpage. */
290 do_hook('optpage_register_block');
292 /*****************************************************/
293 /* Let's sort Javascript Option Pages to the bottom. */
294 /*****************************************************/
295 $js_optpage_blocks = array();
296 $reg_optpage_blocks = array();
297 foreach ($optpage_blocks as $cur_optpage) {
298 if (!$cur_optpage['js']) {
299 $reg_optpage_blocks[] = $cur_optpage;
300 } else if ($javascript_on == SMPREF_JS_ON
) {
301 $js_optpage_blocks[] = $cur_optpage;
304 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
306 /********************************************/
307 /* Now, print out each option page section. */
308 /********************************************/
309 $first_optpage = false;
310 echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=\"5\" BORDER=\"0\">" .
311 '<TR><TD VALIGN="TOP">' .
312 "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=\"3\" CELLSPACING=\"0\" BORDER=\"0\"><TR><TD>";
313 foreach ($optpage_blocks as $next_optpage) {
314 if ($first_optpage == false) {
315 $first_optpage = $next_optpage;
317 print_optionpages_row($first_optpage, $next_optpage);
318 $first_optpage = false;
322 if ($first_optpage != false) {
323 print_optionpages_row($first_optpage);
326 echo "</TD></TR></TABLE></TD></TR></TABLE>\n";
328 do_hook('options_link_and_description');
331 /*************************************************************************/
332 /* If we are not looking at the main option page, display the page here. */
333 /*************************************************************************/
335 echo '<FORM NAME="f" ACTION="options.php" METHOD="POST"><BR>' . "\n"
336 . create_optpage_element($optpage)
337 . create_optmode_element(SMOPT_MODE_SUBMIT
)
338 . '<TABLE WIDTH="100%" CELLPADDING=2 CELLSPACING=0 BORDER=0>' . "\n";
340 /* Output the option groups for this page. */
341 print_option_groups($optpage_data['options']);
343 /* Set the inside_hook_name and submit_name. */
345 case SMOPT_PAGE_PERSONAL
:
346 $inside_hook_name = 'options_personal_inside';
347 $bottom_hook_name = 'options_personal_bottom';
348 $submit_name = 'submit_personal';
350 case SMOPT_PAGE_DISPLAY
:
351 $inside_hook_name = 'options_display_inside';
352 $bottom_hook_name = 'options_display_bottom';
353 $submit_name = 'submit_display';
355 case SMOPT_PAGE_HIGHLIGHT
:
356 $inside_hook_name = 'options_highlight_inside';
357 $bottom_hook_name = 'options_highlight_bottom';
358 $submit_name = 'submit_highlight';
360 case SMOPT_PAGE_FOLDER
:
361 $inside_hook_name = 'options_folder_inside';
362 $bottom_hook_name = 'options_folder_bottom';
363 $submit_name = 'submit_folder';
365 case SMOPT_PAGE_ORDER
:
366 $inside_hook_name = 'options_order_inside';
367 $bottom_hook_name = 'options_order_bottom';
368 $submit_name = 'submit_order';
371 $inside_hook_name = '';
372 $bottom_hook_name = '';
373 $submit_name = 'submit';
376 /* If it is not empty, trigger the inside hook. */
377 if ($inside_hook_name != '') {
378 do_hook($inside_hook_name);
381 /* Spit out a submit button. */
382 OptionSubmit($submit_name);
383 echo '</TABLE></FORM>';
385 /* If it is not empty, trigger the bottom hook. */
386 if ($bottom_hook_name != '') {
387 do_hook($bottom_hook_name);
402 /*******************************************************************/
403 /* Please be warned. The code below this point sucks. This is just */
404 /* my first implementation to make the option rows work for both */
405 /* Javascript and non-Javascript option chunks. */
407 /* Please, someone make these better for me. All three functions */
408 /* below REALLY do close to the same thing. */
410 /* This code would be GREATLY improved by a templating system. */
411 /* Don't try to implement that now, however. That will come later. */
412 /*******************************************************************/
414 /*******************************************************************/
415 /* Actually, now that I think about it, don't do anything with */
416 /* this code yet. There is ACTUALLY supposed to be a difference */
417 /* between the three functions that write the option rows. I just */
418 /* have not yet gotten to integrating that yet. */
419 /*******************************************************************/
422 * This function prints out an option page row.
424 function print_optionpages_row($leftopt, $rightopt = false) {
427 echo "<TABLE BGCOLOR=\"$color[4]\" WIDTH=\"100%\" CELLPADDING=0 CELLSPACING=5 BORDER=0>" .
428 '<TR><TD VALIGN="TOP">' .
429 '<TABLE WIDTH="100%" CELLPADDING="3" CELLSPACING="0" BORDER="0">' .
431 "<TD VALIGN=TOP BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
432 '<A HREF="' . $leftopt['url'] . '">' . $leftopt['name'] . '</A>'.
434 "<TD VALIGN=TOP BGCOLOR=\"$color[4]\"> </TD>";
436 echo "<TD VALIGN=top BGCOLOR=\"$color[9]\" WIDTH=\"50%\">" .
437 '<A HREF="' . $rightopt['url'] . '">' . $rightopt['name'] . '</A>' .
440 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\"> </TD>";
443 echo '</TR>' . "\n" .
445 "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
448 "<TD VALIGN=top BGCOLOR=\"$color[4]\"> </TD>";
450 echo "<TD VALIGN=top BGCOLOR=\"$color[0]\" WIDTH=\"50%\">" .
454 echo "<TD VALIGN=top BGCOLOR=\"$color[4]\" WIDTH=\"50%\"> </TD>";
457 echo '</TR>' . "\n" .