6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
17 * Path for SquirrelMail required files.
20 define('SM_PATH','../');
22 /* SquirrelMail required files. */
23 include_once(SM_PATH
. 'include/validate.php');
24 include_once(SM_PATH
. 'functions/global.php');
25 include_once(SM_PATH
. 'functions/display_messages.php');
26 include_once(SM_PATH
. 'functions/imap.php');
27 include_once(SM_PATH
. 'functions/options.php');
28 include_once(SM_PATH
. 'functions/strings.php');
29 include_once(SM_PATH
. 'functions/html.php');
30 include_once(SM_PATH
. 'functions/forms.php');
32 /*********************************/
33 /*** Build the resultant page. ***/
34 /*********************************/
36 define('SMOPT_MODE_DISPLAY', 'display');
37 define('SMOPT_MODE_SUBMIT', 'submit');
38 define('SMOPT_MODE_LINK', 'link');
40 define('SMOPT_PAGE_MAIN', 'main');
41 define('SMOPT_PAGE_PERSONAL', 'personal');
42 define('SMOPT_PAGE_DISPLAY', 'display');
43 define('SMOPT_PAGE_COMPOSE', 'compose');
44 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
45 define('SMOPT_PAGE_FOLDER', 'folder');
46 define('SMOPT_PAGE_ORDER', 'order');
48 function process_optionmode_submit($optpage, $optpage_data) {
49 /* Initialize the maximum option refresh level. */
50 $max_refresh = SMOPT_REFRESH_NONE
;
52 /* Save each option in each option group. */
53 foreach ($optpage_data['options'] as $option_grp) {
54 foreach ($option_grp['options'] as $option) {
55 /* Remove Debug Mode Until Needed
56 echo "name = '$option->name', "
57 . "value = '$option->value', "
58 . "new_value = '$option->new_value'\n";
61 if ($option->changed()) {
63 $max_refresh = max($max_refresh, $option->refresh_level
);
68 /* Return the max refresh level. */
69 return ($max_refresh);
72 function process_optionmode_link($optpage) {
73 /* There will be something here, later. */
78 * This function prints out an option page row.
80 function print_optionpages_row($leftopt, $rightopt = false) {
84 $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
85 $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
87 $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
88 $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' );
92 html_tag( 'table', "\n" .
93 html_tag( 'tr', "\n" .
94 html_tag( 'td', "\n" .
95 html_tag( 'table', "\n" .
96 html_tag( 'tr', "\n" .
98 '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
99 'left', $color[9], 'valign="top" width="49%"' ) .
102 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
105 html_tag( 'tr', "\n" .
108 'left', $color[0], 'valign="top" width="49%"' ) .
111 'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
114 '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
115 'left', '', 'valign="top"' )
117 '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
120 /* ---------------------------- main ---------------------------- */
122 /* get the globals that we may need */
123 sqgetGlobalVar('key', $key, SQ_COOKIE
);
124 sqgetGlobalVar('username', $username, SQ_SESSION
);
125 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
126 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
128 sqgetGlobalVar('optpage', $optpage);
129 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
130 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
131 /* end of getting globals */
133 /* Make sure we have an Option Page set. Default to main. */
134 if ( !isset($optpage) ||
$optpage == '' ) {
135 $optpage = SMOPT_PAGE_MAIN
;
137 $optpage = strip_tags( $optpage );
140 /* Make sure we have an Option Mode set. Default to display. */
141 if (!isset($optmode)) {
142 $optmode = SMOPT_MODE_DISPLAY
;
146 * First, set the load information for each option page.
149 /* Initialize load information variables. */
152 $optpage_loader = '';
154 /* Set the load information for each page. */
156 case SMOPT_PAGE_MAIN
:
158 case SMOPT_PAGE_PERSONAL
:
159 $optpage_name = _("Personal Information");
160 $optpage_file = SM_PATH
. 'include/options/personal.php';
161 $optpage_loader = 'load_optpage_data_personal';
162 $optpage_loadhook = 'optpage_loadhook_personal';
164 case SMOPT_PAGE_DISPLAY
:
165 $optpage_name = _("Display Preferences");
166 $optpage_file = SM_PATH
. 'include/options/display.php';
167 $optpage_loader = 'load_optpage_data_display';
168 $optpage_loadhook = 'optpage_loadhook_display';
170 case SMOPT_PAGE_COMPOSE
:
171 $optpage_name = _("Compose Preferences");
172 $optpage_file = SM_PATH
. 'include/options/compose.php';
173 $optpage_loader = 'load_optpage_data_compose';
174 $optpage_loadhook = 'optpage_loadhook_compose';
176 case SMOPT_PAGE_HIGHLIGHT
:
177 $optpage_name = _("Message Highlighting");
178 $optpage_file = SM_PATH
. 'include/options/highlight.php';
179 $optpage_loader = 'load_optpage_data_highlight';
180 $optpage_loadhook = 'optpage_loadhook_highlight';
182 case SMOPT_PAGE_FOLDER
:
183 $optpage_name = _("Folder Preferences");
184 $optpage_file = SM_PATH
. 'include/options/folder.php';
185 $optpage_loader = 'load_optpage_data_folder';
186 $optpage_loadhook = 'optpage_loadhook_folder';
188 case SMOPT_PAGE_ORDER
:
189 $optpage_name = _("Index Order");
190 $optpage_file = SM_PATH
. 'include/options/order.php';
191 $optpage_loader = 'load_optpage_data_order';
192 $optpage_loadhook = 'optpage_loadhook_order';
194 default: do_hook('optpage_set_loadinfo');
197 /**********************************************************/
198 /*** Second, load the option information for this page. ***/
199 /**********************************************************/
201 if ( !@is_file
( $optpage_file ) ) {
202 $optpage = SMOPT_PAGE_MAIN
;
203 } else if ($optpage != SMOPT_PAGE_MAIN
) {
204 /* Include the file for this optionpage. */
206 require_once($optpage_file);
208 /* Assemble the data for this option page. */
209 $optpage_data = array();
210 $optpage_data = $optpage_loader();
211 do_hook($optpage_loadhook);
212 $optpage_data['options'] =
213 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
216 /***********************************************************/
217 /*** Next, process anything that needs to be processed. ***/
218 /***********************************************************/
220 $optpage_save_error=array();
222 if ( isset( $optpage_data ) ) {
224 case SMOPT_MODE_SUBMIT
:
225 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
227 case SMOPT_MODE_LINK
:
228 $max_refresh = process_optionmode_link($optpage, $optpage_data);
233 $optpage_title = _("Options");
234 if (isset($optpage_name) && ($optpage_name != '')) {
235 $optpage_title .= " - $optpage_name";
238 /*******************************************************************/
239 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
240 /*******************************************************************/
242 /* If in submit mode, select a save hook name and run it. */
243 if ($optmode == SMOPT_MODE_SUBMIT
) {
244 /* Select a save hook name. */
246 case SMOPT_PAGE_PERSONAL
:
247 $save_hook_name = 'options_personal_save';
249 case SMOPT_PAGE_DISPLAY
:
250 $save_hook_name = 'options_display_save';
252 case SMOPT_PAGE_COMPOSE
:
253 $save_hook_name = 'options_compose_save';
255 case SMOPT_PAGE_FOLDER
:
256 $save_hook_name = 'options_folder_save';
259 $save_hook_name = 'options_save';
263 /* Run the options save hook. */
264 do_hook($save_hook_name);
267 /***************************************************************/
268 /* Apply logic to decide what optpage we want to display next. */
269 /***************************************************************/
271 /* If this is the result of an option page being submitted, then */
272 /* show the main page. Otherwise, show whatever page was called. */
274 if ($optmode == SMOPT_MODE_SUBMIT
) {
275 $optpage = SMOPT_PAGE_MAIN
;
278 /***************************************************************/
279 /* Finally, display whatever page we are supposed to show now. */
280 /***************************************************************/
282 displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
284 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
285 html_tag( 'tr' ) . "\n" .
286 html_tag( 'td', '', 'center' ) .
287 "<b>$optpage_title</b><br />\n".
288 html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
289 html_tag( 'tr' ) . "\n" .
290 html_tag( 'td', '', 'center', $color[4] ) . "\n";
293 * The main option page has a different layout then the rest of the option
294 * pages. Therefore, we create it here first, then the others below.
296 if ($optpage == SMOPT_PAGE_MAIN
) {
297 /**********************************************************/
298 /* First, display the results of a submission, if needed. */
299 /**********************************************************/
300 if ($optmode == SMOPT_MODE_SUBMIT
) {
301 if (!isset($frame_top)) {
305 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
306 echo "<font color=\"$color[2]\"><b>" . _("Error(s) occurred while saving your options") . "</b></font><br />\n";
308 foreach ($optpage_save_error as $error_message) {
309 echo '<li><small>' . $error_message . "</small></li>\n";
312 echo '<b>' . _("Some of your preference changes were not applied.") . "</b><br />\n";
314 /* Display a message indicating a successful save. */
315 echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
318 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
319 if ( !isset( $max_refresh ) ) {
320 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
321 echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
322 } else if ($max_refresh) {
323 echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
326 /******************************************/
327 /* Build our array of Option Page Blocks. */
328 /******************************************/
329 $optpage_blocks = array();
331 /* Build a section for Personal Options. */
332 $optpage_blocks[] = array(
333 'name' => _("Personal Information"),
334 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
335 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
339 /* Build a section for Display Options. */
340 $optpage_blocks[] = array(
341 'name' => _("Display Preferences"),
342 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
343 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
347 /* Build a section for Message Highlighting Options. */
348 $optpage_blocks[] = array(
349 'name' =>_("Message Highlighting"),
350 'url' => 'options_highlight.php',
351 '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."),
355 /* Build a section for Folder Options. */
356 $optpage_blocks[] = array(
357 'name' => _("Folder Preferences"),
358 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
359 'desc' => _("These settings change the way your folders are displayed and manipulated."),
363 /* Build a section for Index Order Options. */
364 $optpage_blocks[] = array(
365 'name' => _("Index Order"),
366 'url' => 'options_order.php',
367 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
371 /* Build a section for Compose Options. */
372 $optpage_blocks[] = array(
373 'name' => _("Compose Preferences"),
374 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE
,
375 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
379 /* Build a section for plugins wanting to register an optionpage. */
380 do_hook('optpage_register_block');
382 /*****************************************************/
383 /* Let's sort Javascript Option Pages to the bottom. */
384 /*****************************************************/
385 $js_optpage_blocks = array();
386 $reg_optpage_blocks = array();
387 foreach ($optpage_blocks as $cur_optpage) {
388 if (!isset($cur_optpage['js']) ||
!$cur_optpage['js']) {
389 $reg_optpage_blocks[] = $cur_optpage;
390 } else if ($javascript_on == SMPREF_JS_ON
) {
391 $js_optpage_blocks[] = $cur_optpage;
394 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
396 /********************************************/
397 /* Now, print out each option page section. */
398 /********************************************/
399 $first_optpage = false;
400 echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
401 html_tag( 'tr' ) . "\n" .
402 html_tag( 'td', '', 'left', '', 'valign="top"' ) .
403 html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
404 html_tag( 'tr' ) . "\n" .
405 html_tag( 'td', '', 'left' );
406 foreach ($optpage_blocks as $next_optpage) {
407 if ($first_optpage == false) {
408 $first_optpage = $next_optpage;
410 print_optionpages_row($first_optpage, $next_optpage);
411 $first_optpage = false;
415 if ($first_optpage != false) {
416 print_optionpages_row($first_optpage);
419 echo "</td></tr></table></td></tr></table>\n";
421 do_hook('options_link_and_description');
424 /*************************************************************************/
425 /* If we are not looking at the main option page, display the page here. */
426 /*************************************************************************/
428 echo addForm('options.php', 'post', 'f')
429 . create_optpage_element($optpage)
430 . create_optmode_element(SMOPT_MODE_SUBMIT
)
431 . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n";
433 /* Output the option groups for this page. */
434 print_option_groups($optpage_data['options']);
436 /* Set the inside_hook_name and submit_name. */
438 case SMOPT_PAGE_PERSONAL
:
439 $inside_hook_name = 'options_personal_inside';
440 $bottom_hook_name = 'options_personal_bottom';
441 $submit_name = 'submit_personal';
443 case SMOPT_PAGE_DISPLAY
:
444 $inside_hook_name = 'options_display_inside';
445 $bottom_hook_name = 'options_display_bottom';
446 $submit_name = 'submit_display';
448 case SMOPT_PAGE_COMPOSE
:
449 $inside_hook_name = 'options_compose_inside';
450 $bottom_hook_name = 'options_compose_bottom';
451 $submit_name = 'submit_compose';
453 case SMOPT_PAGE_HIGHLIGHT
:
454 $inside_hook_name = 'options_highlight_inside';
455 $bottom_hook_name = 'options_highlight_bottom';
456 $submit_name = 'submit_highlight';
458 case SMOPT_PAGE_FOLDER
:
459 $inside_hook_name = 'options_folder_inside';
460 $bottom_hook_name = 'options_folder_bottom';
461 $submit_name = 'submit_folder';
463 case SMOPT_PAGE_ORDER
:
464 $inside_hook_name = 'options_order_inside';
465 $bottom_hook_name = 'options_order_bottom';
466 $submit_name = 'submit_order';
469 $inside_hook_name = '';
470 $bottom_hook_name = '';
471 $submit_name = 'submit';
474 /* If it is not empty, trigger the inside hook. */
475 if ($inside_hook_name != '') {
476 do_hook($inside_hook_name);
479 /* Spit out a submit button. */
480 OptionSubmit($submit_name);
481 echo '</table></form>';
483 /* If it is not empty, trigger the bottom hook. */
484 if ($bottom_hook_name != '') {
485 do_hook($bottom_hook_name);
495 $oTemplate->display('footer.tpl');