4350c59e8271aedda5253e26ae1a00300375e142
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-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
17 * Include the SquirrelMail initialization file.
19 require('../include/init.php');
21 /* SquirrelMail required files. */
23 //include(SM_PATH . 'functions/imap_general.php');
24 require_once(SM_PATH
. 'functions/options.php');
25 require_once(SM_PATH
. 'functions/forms.php');
27 /*********************************/
28 /*** Build the resultant page. ***/
29 /*********************************/
31 define('SMOPT_MODE_DISPLAY', 'display');
32 define('SMOPT_MODE_SUBMIT', 'submit');
33 define('SMOPT_MODE_LINK', 'link');
35 define('SMOPT_PAGE_MAIN', 'main');
36 define('SMOPT_PAGE_PERSONAL', 'personal');
37 define('SMOPT_PAGE_DISPLAY', 'display');
38 define('SMOPT_PAGE_COMPOSE', 'compose');
39 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
40 define('SMOPT_PAGE_FOLDER', 'folder');
41 define('SMOPT_PAGE_ORDER', 'order');
43 function process_optionmode_submit($optpage, $optpage_data) {
44 /* Initialize the maximum option refresh level. */
45 $max_refresh = SMOPT_REFRESH_NONE
;
49 /* Save each option in each option group. */
50 foreach ($optpage_data['options'] as $option_grp) {
51 foreach ($option_grp['options'] as $option) {
53 /* Special case: need to make sure emailaddress
54 * is saved if we use it as a test for ask_user_info */
55 global $ask_user_info;
56 if ( $optpage = SMOPT_PAGE_PERSONAL
&& $ask_user_info &&
57 $option->name
== 'email_address' ) {
58 $option->setValue('');
61 /* Remove Debug Mode Until Needed
62 echo "name = '$option->name', "
63 . "value = '$option->value', "
64 . "new_value = '$option->new_value'\n";
67 if ($option->changed()) {
69 $max_refresh = max($max_refresh, $option->refresh_level
);
74 /* Return the max refresh level. */
75 return ($max_refresh);
78 function process_optionmode_link($optpage) {
79 /* There will be something here, later. */
84 /* ---------------------------- main ---------------------------- */
86 /* get the globals that we may need */
87 sqgetGlobalVar('optpage', $optpage);
88 sqgetGlobalVar('optmode', $optmode, SQ_FORM
);
89 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST
);
90 /* end of getting globals */
92 /* Make sure we have an Option Page set. Default to main. */
93 if ( !isset($optpage) ||
$optpage == '' ) {
94 $optpage = SMOPT_PAGE_MAIN
;
96 $optpage = strip_tags( $optpage );
99 /* Make sure we have an Option Mode set. Default to display. */
100 if (!isset($optmode)) {
101 $optmode = SMOPT_MODE_DISPLAY
;
105 * First, set the load information for each option page.
108 /* Initialize load information variables. */
111 $optpage_loader = '';
113 /* Set the load information for each page. */
115 case SMOPT_PAGE_MAIN
:
117 case SMOPT_PAGE_PERSONAL
:
118 $optpage_name = _("Personal Information");
119 $optpage_file = SM_PATH
. 'include/options/personal.php';
120 $optpage_loader = 'load_optpage_data_personal';
121 $optpage_loadhook = 'optpage_loadhook_personal';
123 case SMOPT_PAGE_DISPLAY
:
124 $optpage_name = _("Display Preferences");
125 $optpage_file = SM_PATH
. 'include/options/display.php';
126 $optpage_loader = 'load_optpage_data_display';
127 $optpage_loadhook = 'optpage_loadhook_display';
129 case SMOPT_PAGE_COMPOSE
:
130 $optpage_name = _("Compose Preferences");
131 $optpage_file = SM_PATH
. 'include/options/compose.php';
132 $optpage_loader = 'load_optpage_data_compose';
133 $optpage_loadhook = 'optpage_loadhook_compose';
135 case SMOPT_PAGE_HIGHLIGHT
:
136 $optpage_name = _("Message Highlighting");
137 $optpage_file = SM_PATH
. 'include/options/highlight.php';
138 $optpage_loader = 'load_optpage_data_highlight';
139 $optpage_loadhook = 'optpage_loadhook_highlight';
141 case SMOPT_PAGE_FOLDER
:
142 $optpage_name = _("Folder Preferences");
143 $optpage_file = SM_PATH
. 'include/options/folder.php';
144 $optpage_loader = 'load_optpage_data_folder';
145 $optpage_loadhook = 'optpage_loadhook_folder';
147 case SMOPT_PAGE_ORDER
:
148 $optpage_name = _("Index Order");
149 $optpage_file = SM_PATH
. 'include/options/order.php';
150 $optpage_loader = 'load_optpage_data_order';
151 $optpage_loadhook = 'optpage_loadhook_order';
153 default: do_hook('optpage_set_loadinfo', $null);
156 /**********************************************************/
157 /*** Second, load the option information for this page. ***/
158 /**********************************************************/
160 if ( !@is_file
( $optpage_file ) ) {
161 $optpage = SMOPT_PAGE_MAIN
;
162 } elseif ($optpage != SMOPT_PAGE_MAIN
) {
163 /* Include the file for this optionpage. */
165 require_once($optpage_file);
167 /* Assemble the data for this option page. */
168 $optpage_data = array();
169 $optpage_data = $optpage_loader();
170 do_hook($optpage_loadhook, $null);
171 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
174 /***********************************************************/
175 /*** Next, process anything that needs to be processed. ***/
176 /***********************************************************/
178 $optpage_save_error=array();
180 if ( isset( $optpage_data ) ) {
182 case SMOPT_MODE_SUBMIT
:
183 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
185 case SMOPT_MODE_LINK
:
186 $max_refresh = process_optionmode_link($optpage, $optpage_data);
191 $optpage_title = _("Options");
192 if (isset($optpage_name) && ($optpage_name != '')) {
193 $optpage_title .= " - $optpage_name";
196 /*******************************************************************/
197 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
198 /*******************************************************************/
200 /* If in submit mode, select a save hook name and run it. */
201 if ($optmode == SMOPT_MODE_SUBMIT
) {
202 /* Select a save hook name. */
204 case SMOPT_PAGE_PERSONAL
:
205 $save_hook_name = 'options_personal_save';
207 case SMOPT_PAGE_DISPLAY
:
208 $save_hook_name = 'options_display_save';
210 case SMOPT_PAGE_COMPOSE
:
211 $save_hook_name = 'options_compose_save';
213 case SMOPT_PAGE_FOLDER
:
214 $save_hook_name = 'options_folder_save';
217 $save_hook_name = 'options_save';
221 /* Run the options save hook. */
222 do_hook($save_hook_name, $null);
225 /***************************************************************/
226 /* Apply logic to decide what optpage we want to display next. */
227 /***************************************************************/
229 /* If this is the result of an option page being submitted, then */
230 /* show the main page. Otherwise, show whatever page was called. */
232 if ($optmode == SMOPT_MODE_SUBMIT
) {
233 $optpage = SMOPT_PAGE_MAIN
;
236 /***************************************************************/
237 /* Finally, display whatever page we are supposed to show now. */
238 /***************************************************************/
240 displayPageHeader($color, null, (isset($optpage_data['xtra']) ?
$optpage_data['xtra'] : ''));
243 * The main option page has a different layout then the rest of the option
244 * pages. Therefore, we create it here first, then the others below.
246 if ($optpage == SMOPT_PAGE_MAIN
) {
247 /**********************************************************/
248 /* First, display the results of a submission, if needed. */
249 /**********************************************************/
251 if ($optmode == SMOPT_MODE_SUBMIT
) {
252 if (!isset($frame_top)) {
256 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
257 //FIXME: REMOVE HTML FROM CORE
258 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
259 foreach ($optpage_save_error as $error_message) {
260 $notice.= '<li><small>' . $error_message . "</small></li>\n";
262 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
264 /* Display a message indicating a successful save. */
265 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
268 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
269 if ( !isset( $max_refresh ) ) {
270 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST
) {
271 //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the folder list is in a separate sibling frame under the same parent, and it is called "left"
272 if (checkForJavascript()) {
273 $notice .= sprintf(_("Folder list should automatically %srefresh%s."), '<a href="../src/left_main.php" target="left">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.left.location = '../src/left_main.php';\n// -->\n</script>\n";
275 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
277 } else if ($max_refresh) {
278 if (checkForJavascript()) {
279 //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the parent is the top-most SM frame and is what should be refreshed with webmail.php
280 $notice .= sprintf(_("This page should automatically %srefresh%s."), '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.location = '../src/webmail.php?right_frame=options.php';\n// -->\n</script>\n";
282 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
287 if (!empty($notice)) {
288 $oTemplate->assign('note', $notice);
289 $oTemplate->display('note.tpl');
292 /******************************************/
293 /* Build our array of Option Page Blocks. */
294 /******************************************/
295 $optpage_blocks = array();
297 /* Build a section for Personal Options. */
298 $optpage_blocks[] = array(
299 'name' => _("Personal Information"),
300 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL
,
301 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
305 /* Build a section for Display Options. */
306 $optpage_blocks[] = array(
307 'name' => _("Display Preferences"),
308 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY
,
309 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
313 /* Build a section for Message Highlighting Options. */
314 $optpage_blocks[] = array(
315 'name' =>_("Message Highlighting"),
316 'url' => 'options_highlight.php',
317 '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."),
321 /* Build a section for Folder Options. */
322 $optpage_blocks[] = array(
323 'name' => _("Folder Preferences"),
324 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER
,
325 'desc' => _("These settings change the way your folders are displayed and manipulated."),
329 /* Build a section for Index Order Options. */
330 $optpage_blocks[] = array(
331 'name' => _("Index Order"),
332 'url' => 'options_order.php',
333 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
337 /* Build a section for Compose Options. */
338 $optpage_blocks[] = array(
339 'name' => _("Compose Preferences"),
340 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE
,
341 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
345 /* Build a section for plugins wanting to register an optionpage. */
346 do_hook('optpage_register_block', $null);
348 /*****************************************************/
349 /* Let's sort Javascript Option Pages to the bottom. */
350 /*****************************************************/
351 $js_optpage_blocks = array();
352 $reg_optpage_blocks = array();
353 foreach ($optpage_blocks as $cur_optpage) {
354 if (!isset($cur_optpage['js']) ||
!$cur_optpage['js']) {
355 $reg_optpage_blocks[] = $cur_optpage;
356 } else if (checkForJavascript()) {
357 $js_optpage_blocks[] = $cur_optpage;
360 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
362 /********************************************/
363 /* Now, print out each option page section. */
364 /********************************************/
365 $oTemplate->assign('page_title', $optpage_title);
366 $oTemplate->assign('options', $optpage_blocks);
368 $oTemplate->display('option_groups.tpl');
370 do_hook('options_link_and_description', $null);
373 /*************************************************************************/
374 /* If we are not looking at the main option page, display the page here. */
375 /*************************************************************************/
377 /* Set the inside_hook_name and submit_name. */
379 case SMOPT_PAGE_PERSONAL
:
380 $inside_hook_name = 'options_personal_inside';
381 $bottom_hook_name = 'options_personal_bottom';
382 $submit_name = 'submit_personal';
384 case SMOPT_PAGE_DISPLAY
:
385 $inside_hook_name = 'options_display_inside';
386 $bottom_hook_name = 'options_display_bottom';
387 $submit_name = 'submit_display';
389 case SMOPT_PAGE_COMPOSE
:
390 $inside_hook_name = 'options_compose_inside';
391 $bottom_hook_name = 'options_compose_bottom';
392 $submit_name = 'submit_compose';
394 case SMOPT_PAGE_HIGHLIGHT
:
395 $inside_hook_name = 'options_highlight_inside';
396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
399 case SMOPT_PAGE_FOLDER
:
400 $inside_hook_name = 'options_folder_inside';
401 $bottom_hook_name = 'options_folder_bottom';
402 $submit_name = 'submit_folder';
404 case SMOPT_PAGE_ORDER
:
405 $inside_hook_name = 'options_order_inside';
406 $bottom_hook_name = 'options_order_bottom';
407 $submit_name = 'submit_order';
410 $inside_hook_name = '';
411 $bottom_hook_name = '';
412 $submit_name = 'submit';
416 echo addForm('options.php', 'post', 'f')
417 . create_optpage_element($optpage)
418 . create_optmode_element(SMOPT_MODE_SUBMIT
);
420 //FIXME: NO HTML IN THE CORE!!
421 // Wrap the template in a table to keep from breaking the hooks below
422 echo "<table cellspacing=\"0\" class=\"table_blank\">\n" .
424 " <td colspan=\"2\">\n";
426 // This is the only variable that is needed by *just* the template.
427 $oTemplate->assign('options', $optpage_data['options']);
429 global $ask_user_info, $org_name;
430 if ( $optpage = SMOPT_PAGE_PERSONAL
&& $ask_user_info
431 && getPref($data_dir, $username,'email_address') == "" ) {
432 $oTemplate->assign('topmessage',
433 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
437 * The variables below should not be needed by the template since all plugin
438 * hooks are called here, not in the template. If we find otherwise, these
439 * variables can be passed to the template. Commenting out for now.
442 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
443 $oTemplate->assign('page_title', $optpage_title);
444 $oTemplate->assign('optpage',$optpage);
445 $oTemplate->assign('optpage_name',$optpage_name);
446 $oTemplate->assign('optmode',$optmode);
447 $oTemplate->assign('optpage_data',$optpage_data);
453 $oTemplate->assign('submit_name', $submit_name);
454 $oTemplate->display('options.tpl');
456 //FIXME: need to remove HTML from here!
460 /* If it is not empty, trigger the inside hook. */
461 if ($inside_hook_name != '') {
462 do_hook($inside_hook_name, $null);
465 //FIXME: need to remove HTML from here!
469 /* If it is not empty, trigger the bottom hook. */
470 if ($bottom_hook_name != '') {
471 do_hook($bottom_hook_name, $null);
476 $oTemplate->display('footer.tpl');