6 * Copyright (c) 1999-2005 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.
13 * @package squirrelmail
18 * Path for SquirrelMail required files.
21 define('SM_PATH','../');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'include/validate.php');
25 include_once(SM_PATH
. 'functions/global.php');
26 include_once(SM_PATH
. 'functions/display_messages.php');
27 include_once(SM_PATH
. 'functions/imap.php');
28 include_once(SM_PATH
. 'functions/options.php');
29 include_once(SM_PATH
. 'functions/strings.php');
30 include_once(SM_PATH
. 'functions/html.php');
31 include_once(SM_PATH
. 'functions/forms.php');
33 /*********************************/
34 /*** Build the resultant page. ***/
35 /*********************************/
37 define('SMOPT_MODE_DISPLAY', 'display');
38 define('SMOPT_MODE_SUBMIT', 'submit');
39 define('SMOPT_MODE_LINK', 'link');
41 define('SMOPT_PAGE_MAIN', 'main');
42 define('SMOPT_PAGE_PERSONAL', 'personal');
43 define('SMOPT_PAGE_DISPLAY', 'display');
44 define('SMOPT_PAGE_COMPOSE', 'compose');
45 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
46 define('SMOPT_PAGE_FOLDER', 'folder');
47 define('SMOPT_PAGE_ORDER', 'order');
49 function process_optionmode_submit($optpage, $optpage_data) {
50 /* Initialize the maximum option refresh level. */
51 $max_refresh = SMOPT_REFRESH_NONE
;
53 /* Save each option in each option group. */
54 foreach ($optpage_data['options'] as $option_grp) {
55 foreach ($option_grp['options'] as $option) {
56 /* Remove Debug Mode Until Needed
57 echo "name = '$option->name', "
58 . "value = '$option->value', "
59 . "new_value = '$option->new_value'\n";
62 if ($option->changed()) {
64 $max_refresh = max($max_refresh, $option->refresh_level
);
69 /* Return the max refresh level. */
70 return ($max_refresh);
73 function process_optionmode_link($optpage) {
74 /* There will be something here, later. */
79 * This function prints out an option page row.
81 function print_optionpages_row($leftopt, $rightopt = false) {
85 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
86 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
88 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
89 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
93 html_tag( 'table', "\n" .
94 html_tag( 'tr', "\n" .
95 html_tag( 'td', "\n" .
96 html_tag( 'table', "\n" .
97 html_tag( 'tr', "\n" .
99 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
100 'left', $color[9], 'valign="top" width="49%"' ) .
103 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
106 html_tag( 'tr', "\n" .
109 'left', $color[0], 'valign="top" width="49%"' ) .
112 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
115 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
116 'left', '', 'valign="top"' )
118 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
121 /* ---------------------------- main ---------------------------- */
123 /* get the globals that we may need */
124 sqgetGlobalVar('key', $key, SQ_COOKIE
);
125 sqgetGlobalVar('username', $username, SQ_SESSION
);
126 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
127 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
129 sqgetGlobalVar('optpage', $optpage);
130 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
131 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
132 /* end of getting globals */
134 /* Make sure we have an Option Page set. Default to main. */
135 if ( !isset($optpage) ||
$optpage == '' ) {
136 $optpage = SMOPT_PAGE_MAIN
;
138 $optpage = strip_tags( $optpage );
141 /* Make sure we have an Option Mode set. Default to display. */
142 if (!isset($optmode)) {
143 $optmode = SMOPT_MODE_DISPLAY
;
147 * First, set the load information for each option page.
150 /* Initialize load information variables. */
153 $optpage_loader = '';
155 /* Set the load information for each page. */
157 case SMOPT_PAGE_MAIN
:
159 case SMOPT_PAGE_PERSONAL
:
160 $optpage_name = _("Personal Information");
161 $optpage_file = SM_PATH
. 'include/options/personal.php';
162 $optpage_loader = 'load_optpage_data_personal';
163 $optpage_loadhook = 'optpage_loadhook_personal';
165 case SMOPT_PAGE_DISPLAY
:
166 $optpage_name = _("Display Preferences");
167 $optpage_file = SM_PATH
. 'include/options/display.php';
168 $optpage_loader = 'load_optpage_data_display';
169 $optpage_loadhook = 'optpage_loadhook_display';
171 case SMOPT_PAGE_COMPOSE
:
172 $optpage_name = _("Compose Preferences");
173 $optpage_file = SM_PATH
. 'include/options/compose.php';
174 $optpage_loader = 'load_optpage_data_compose';
175 $optpage_loadhook = 'optpage_loadhook_compose';
177 case SMOPT_PAGE_HIGHLIGHT
:
178 $optpage_name = _("Message Highlighting");
179 $optpage_file = SM_PATH
. 'include/options/highlight.php';
180 $optpage_loader = 'load_optpage_data_highlight';
181 $optpage_loadhook = 'optpage_loadhook_highlight';
183 case SMOPT_PAGE_FOLDER
:
184 $optpage_name = _("Folder Preferences");
185 $optpage_file = SM_PATH
. 'include/options/folder.php';
186 $optpage_loader = 'load_optpage_data_folder';
187 $optpage_loadhook = 'optpage_loadhook_folder';
189 case SMOPT_PAGE_ORDER
:
190 $optpage_name = _("Index Order");
191 $optpage_file = SM_PATH
. 'include/options/order.php';
192 $optpage_loader = 'load_optpage_data_order';
193 $optpage_loadhook = 'optpage_loadhook_order';
195 default: do_hook('optpage_set_loadinfo');
198 /**********************************************************/
199 /*** Second, load the option information for this page. ***/
200 /**********************************************************/
202 if ( !@is_file
( $optpage_file ) ) {
203 $optpage = SMOPT_PAGE_MAIN
;
204 } else if ($optpage != SMOPT_PAGE_MAIN
) {
205 /* Include the file for this optionpage. */
207 require_once($optpage_file);
209 /* Assemble the data for this option page. */
210 $optpage_data = array();
211 $optpage_data = $optpage_loader();
212 do_hook($optpage_loadhook);
213 $optpage_data['options'] =
214 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
217 /***********************************************************/
218 /*** Next, process anything that needs to be processed. ***/
219 /***********************************************************/
221 $optpage_save_error=array();
223 if ( isset( $optpage_data ) ) {
225 case SMOPT_MODE_SUBMIT
:
226 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
228 case SMOPT_MODE_LINK
:
229 $max_refresh = process_optionmode_link($optpage, $optpage_data);
234 $optpage_title = _("Options");
235 if (isset($optpage_name) && ($optpage_name != '')) {
236 $optpage_title .= " - $optpage_name";
239 /*******************************************************************/
240 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
241 /*******************************************************************/
243 /* If in submit mode, select a save hook name and run it. */
244 if ($optmode == SMOPT_MODE_SUBMIT
) {
245 /* Select a save hook name. */
247 case SMOPT_PAGE_PERSONAL
:
248 $save_hook_name = 'options_personal_save';
250 case SMOPT_PAGE_DISPLAY
:
251 $save_hook_name = 'options_display_save';
253 case SMOPT_PAGE_COMPOSE
:
254 $save_hook_name = 'options_compose_save';
256 case SMOPT_PAGE_FOLDER
:
257 $save_hook_name = 'options_folder_save';
260 $save_hook_name = 'options_save';
264 /* Run the options save hook. */
265 do_hook($save_hook_name);
268 /***************************************************************/
269 /* Apply logic to decide what optpage we want to display next. */
270 /***************************************************************/
272 /* If this is the result of an option page being submitted, then */
273 /* show the main page. Otherwise, show whatever page was called. */
275 if ($optmode == SMOPT_MODE_SUBMIT
) {
276 $optpage = SMOPT_PAGE_MAIN
;
279 /***************************************************************/
280 /* Finally, display whatever page we are supposed to show now. */
281 /***************************************************************/
283 displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
285 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
286 html_tag( 'tr' ) . "\n" .
287 html_tag( 'td', '', 'center' ) .
288 "<b>$optpage_title</b><br />\n".
289 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
290 html_tag( 'tr' ) . "\n" .
291 html_tag( 'td', '', 'center', $color[4] ) . "\n";
294 * The main option page has a different layout then the rest of the option
295 * pages. Therefore, we create it here first, then the others below.
297 if ($optpage == SMOPT_PAGE_MAIN
) {
298 /**********************************************************/
299 /* First, display the results of a submission, if needed. */
300 /**********************************************************/
301 if ($optmode == SMOPT_MODE_SUBMIT
) {
302 if (!isset($frame_top)) {
306 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
307 echo "<font color=\"$color[2]\"><b>" . _("Error(s) occurred while saving your options") . "</b></font><br />\n";
309 foreach ($optpage_save_error as $error_message) {
310 echo '<li><small>' . $error_message . "</small></li>\n";
313 echo '<b>' . _("Some of your preference changes were not applied.") . "</b><br />\n";
315 /* Display a message indicating a successful save. */
316 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
319 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
320 if ( !isset( $max_refresh ) ) {
321 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
322 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
323 } else if ($max_refresh) {
324 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
327 /******************************************/
328 /* Build our array of Option Page Blocks. */
329 /******************************************/
330 $optpage_blocks = array();
332 /* Build a section for Personal Options. */
333 $optpage_blocks[] = array(
334 'name' => _("Personal Information"),
335 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
336 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
340 /* Build a section for Display Options. */
341 $optpage_blocks[] = array(
342 'name' => _("Display Preferences"),
343 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
344 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
348 /* Build a section for Message Highlighting Options. */
349 $optpage_blocks[] = array(
350 'name' =>_("Message Highlighting"),
351 'url' => 'options_highlight.php',
352 '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."),
356 /* Build a section for Folder Options. */
357 $optpage_blocks[] = array(
358 'name' => _("Folder Preferences"),
359 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
360 'desc' => _("These settings change the way your folders are displayed and manipulated."),
364 /* Build a section for Index Order Options. */
365 $optpage_blocks[] = array(
366 'name' => _("Index Order"),
367 'url' => 'options_order.php',
368 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
372 /* Build a section for Compose Options. */
373 $optpage_blocks[] = array(
374 'name' => _("Compose Preferences"),
375 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE
,
376 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
380 /* Build a section for plugins wanting to register an optionpage. */
381 do_hook('optpage_register_block');
383 /*****************************************************/
384 /* Let's sort Javascript Option Pages to the bottom. */
385 /*****************************************************/
386 $js_optpage_blocks = array();
387 $reg_optpage_blocks = array();
388 foreach ($optpage_blocks as $cur_optpage) {
389 if (!isset($cur_optpage['js']) ||
!$cur_optpage['js']) {
390 $reg_optpage_blocks[] = $cur_optpage;
391 } else if ($javascript_on == SMPREF_JS_ON
) {
392 $js_optpage_blocks[] = $cur_optpage;
395 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
397 /********************************************/
398 /* Now, print out each option page section. */
399 /********************************************/
400 $first_optpage = false;
401 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
402 html_tag( 'tr' ) . "\n" .
403 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
404 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
405 html_tag( 'tr' ) . "\n" .
406 html_tag( 'td', '', 'left' );
407 foreach ($optpage_blocks as $next_optpage) {
408 if ($first_optpage == false) {
409 $first_optpage = $next_optpage;
411 print_optionpages_row($first_optpage, $next_optpage);
412 $first_optpage = false;
416 if ($first_optpage != false) {
417 print_optionpages_row($first_optpage);
420 echo "</td></tr></table></td></tr></table>\n";
422 do_hook('options_link_and_description');
425 /*************************************************************************/
426 /* If we are not looking at the main option page, display the page here. */
427 /*************************************************************************/
429 echo addForm('options.php', 'post', 'f')
430 . create_optpage_element($optpage)
431 . create_optmode_element(SMOPT_MODE_SUBMIT
)
432 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n";
434 /* Output the option groups for this page. */
435 print_option_groups($optpage_data['options']);
437 /* Set the inside_hook_name and submit_name. */
439 case SMOPT_PAGE_PERSONAL
:
440 $inside_hook_name = 'options_personal_inside';
441 $bottom_hook_name = 'options_personal_bottom';
442 $submit_name = 'submit_personal';
444 case SMOPT_PAGE_DISPLAY
:
445 $inside_hook_name = 'options_display_inside';
446 $bottom_hook_name = 'options_display_bottom';
447 $submit_name = 'submit_display';
449 case SMOPT_PAGE_COMPOSE
:
450 $inside_hook_name = 'options_compose_inside';
451 $bottom_hook_name = 'options_compose_bottom';
452 $submit_name = 'submit_compose';
454 case SMOPT_PAGE_HIGHLIGHT
:
455 $inside_hook_name = 'options_highlight_inside';
456 $bottom_hook_name = 'options_highlight_bottom';
457 $submit_name = 'submit_highlight';
459 case SMOPT_PAGE_FOLDER
:
460 $inside_hook_name = 'options_folder_inside';
461 $bottom_hook_name = 'options_folder_bottom';
462 $submit_name = 'submit_folder';
464 case SMOPT_PAGE_ORDER
:
465 $inside_hook_name = 'options_order_inside';
466 $bottom_hook_name = 'options_order_bottom';
467 $submit_name = 'submit_order';
470 $inside_hook_name = '';
471 $bottom_hook_name = '';
472 $submit_name = 'submit';
475 /* If it is not empty, trigger the inside hook. */
476 if ($inside_hook_name != '') {
477 do_hook($inside_hook_name);
480 /* Spit out a submit button. */
481 OptionSubmit($submit_name);
482 echo '</table></form>';
484 /* If it is not empty, trigger the bottom hook. */
485 if ($bottom_hook_name != '') {
486 do_hook($bottom_hook_name);