Just remove 'inside' hooks, which make no sense in templated output and were long...
[squirrelmail.git] / src / options.php
CommitLineData
59177427 1<?php
d3cdb279 2
35586184 3/**
4 * options.php
5 *
35586184 6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
8 *
4b5049de 9 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
ca479ad1 13 * @subpackage prefs
35586184 14 */
cbe5423b 15
ebd2391c 16/** This is the options page */
17define('PAGE_NAME', 'options');
18
30967a1e 19/**
202bcbcc 20 * Include the SquirrelMail initialization file.
30967a1e 21 */
202bcbcc 22require('../include/init.php');
86725763 23
24/* SquirrelMail required files. */
202bcbcc 25
26//include(SM_PATH . 'functions/imap_general.php');
27require_once(SM_PATH . 'functions/options.php');
28require_once(SM_PATH . 'functions/forms.php');
cbe5423b 29
cbe5423b 30/*********************************/
31/*** Build the resultant page. ***/
32/*********************************/
33
cbe5423b 34define('SMOPT_MODE_DISPLAY', 'display');
35define('SMOPT_MODE_SUBMIT', 'submit');
36define('SMOPT_MODE_LINK', 'link');
37
38define('SMOPT_PAGE_MAIN', 'main');
39define('SMOPT_PAGE_PERSONAL', 'personal');
40define('SMOPT_PAGE_DISPLAY', 'display');
5ed9d4fd 41define('SMOPT_PAGE_COMPOSE', 'compose');
cbe5423b 42define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
43define('SMOPT_PAGE_FOLDER', 'folder');
44define('SMOPT_PAGE_ORDER', 'order');
45
46function process_optionmode_submit($optpage, $optpage_data) {
47 /* Initialize the maximum option refresh level. */
48 $max_refresh = SMOPT_REFRESH_NONE;
49
209e24bb 50
51
cbe5423b 52 /* Save each option in each option group. */
53 foreach ($optpage_data['options'] as $option_grp) {
54 foreach ($option_grp['options'] as $option) {
209e24bb 55
56 /* Special case: need to make sure emailaddress
57 * is saved if we use it as a test for ask_user_info */
58 global $ask_user_info;
59 if ( $optpage = SMOPT_PAGE_PERSONAL && $ask_user_info &&
60 $option->name == 'email_address' ) {
61 $option->setValue('');
62 }
63
534367eb 64 /* Remove Debug Mode Until Needed
cbe5423b 65 echo "name = '$option->name', "
66 . "value = '$option->value', "
6206f6c4 67 . "new_value = '$option->new_value'\n";
244a64a4 68//FIXME: NO HTML IN THE CORE!
39bfea8f 69 echo "<br />";
534367eb 70 */
cbe5423b 71 if ($option->changed()) {
72 $option->save();
73 $max_refresh = max($max_refresh, $option->refresh_level);
74 }
75 }
76 }
1e0628fb 77
cbe5423b 78 /* Return the max refresh level. */
79 return ($max_refresh);
80}
81
82function process_optionmode_link($optpage) {
83 /* There will be something here, later. */
84}
85
0b0e96c5 86
0b0e96c5 87
88/* ---------------------------- main ---------------------------- */
89
a32985a5 90/* get the globals that we may need */
1e12d1ff 91sqgetGlobalVar('optpage', $optpage);
5ccba4f3 92sqgetGlobalVar('optmode', $optmode, SQ_FORM);
1e12d1ff 93sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
a32985a5 94/* end of getting globals */
95
cbe5423b 96/* Make sure we have an Option Page set. Default to main. */
c1f7790a 97if ( !isset($optpage) || $optpage == '' ) {
98 $optpage = SMOPT_PAGE_MAIN;
99} else {
100 $optpage = strip_tags( $optpage );
cbe5423b 101}
102
103/* Make sure we have an Option Mode set. Default to display. */
104if (!isset($optmode)) {
105 $optmode = SMOPT_MODE_DISPLAY;
106}
107
0b0e96c5 108/*
91e0dccc 109 * First, set the load information for each option page.
0b0e96c5 110 */
cbe5423b 111
112/* Initialize load information variables. */
113$optpage_name = '';
114$optpage_file = '';
115$optpage_loader = '';
116
117/* Set the load information for each page. */
118switch ($optpage) {
91e0dccc 119 case SMOPT_PAGE_MAIN:
c1f7790a 120 break;
cbe5423b 121 case SMOPT_PAGE_PERSONAL:
a3439b27 122 $optpage_name = _("Personal Information");
08185f2a 123 $optpage_file = SM_PATH . 'include/options/personal.php';
a3439b27 124 $optpage_loader = 'load_optpage_data_personal';
125 $optpage_loadhook = 'optpage_loadhook_personal';
cbe5423b 126 break;
127 case SMOPT_PAGE_DISPLAY:
128 $optpage_name = _("Display Preferences");
08185f2a 129 $optpage_file = SM_PATH . 'include/options/display.php';
cbe5423b 130 $optpage_loader = 'load_optpage_data_display';
a3439b27 131 $optpage_loadhook = 'optpage_loadhook_display';
cbe5423b 132 break;
5ed9d4fd 133 case SMOPT_PAGE_COMPOSE:
134 $optpage_name = _("Compose Preferences");
135 $optpage_file = SM_PATH . 'include/options/compose.php';
136 $optpage_loader = 'load_optpage_data_compose';
137 $optpage_loadhook = 'optpage_loadhook_compose';
138 break;
cbe5423b 139 case SMOPT_PAGE_HIGHLIGHT:
140 $optpage_name = _("Message Highlighting");
08185f2a 141 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 142 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 143 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 144 break;
145 case SMOPT_PAGE_FOLDER:
146 $optpage_name = _("Folder Preferences");
08185f2a 147 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 148 $optpage_loader = 'load_optpage_data_folder';
a3439b27 149 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 150 break;
151 case SMOPT_PAGE_ORDER:
152 $optpage_name = _("Index Order");
08185f2a 153 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 154 $optpage_loader = 'load_optpage_data_order';
a3439b27 155 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 156 break;
6e515418 157 default: do_hook('optpage_set_loadinfo', $null);
cbe5423b 158}
159
160/**********************************************************/
161/*** Second, load the option information for this page. ***/
162/**********************************************************/
163
a32985a5 164if ( !@is_file( $optpage_file ) ) {
c1f7790a 165 $optpage = SMOPT_PAGE_MAIN;
64033e1c 166} elseif ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 167 /* Include the file for this optionpage. */
91e0dccc 168
cbe5423b 169 require_once($optpage_file);
170
171 /* Assemble the data for this option page. */
172 $optpage_data = array();
173 $optpage_data = $optpage_loader();
6e515418 174 do_hook($optpage_loadhook, $null);
64033e1c 175 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
cbe5423b 176}
177
178/***********************************************************/
179/*** Next, process anything that needs to be processed. ***/
180/***********************************************************/
181
288df1a0 182$optpage_save_error=array();
183
cc61478a 184if ( isset( $optpage_data ) ) {
185 switch ($optmode) {
186 case SMOPT_MODE_SUBMIT:
187 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
188 break;
189 case SMOPT_MODE_LINK:
190 $max_refresh = process_optionmode_link($optpage, $optpage_data);
191 break;
192 }
cbe5423b 193}
cbe5423b 194
2de8b87f 195$optpage_title = _("Options");
196if (isset($optpage_name) && ($optpage_name != '')) {
197 $optpage_title .= " - $optpage_name";
198}
199
cbe5423b 200/*******************************************************************/
201/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
202/*******************************************************************/
203
204/* If in submit mode, select a save hook name and run it. */
7e235a1a 205if ($optmode == SMOPT_MODE_SUBMIT) {
cbe5423b 206 /* Select a save hook name. */
207 switch ($optpage) {
208 case SMOPT_PAGE_PERSONAL:
209 $save_hook_name = 'options_personal_save';
210 break;
211 case SMOPT_PAGE_DISPLAY:
212 $save_hook_name = 'options_display_save';
213 break;
10ad5e30 214 case SMOPT_PAGE_COMPOSE:
215 $save_hook_name = 'options_compose_save';
216 break;
cbe5423b 217 case SMOPT_PAGE_FOLDER:
218 $save_hook_name = 'options_folder_save';
219 break;
91e0dccc 220 default:
cc61478a 221 $save_hook_name = 'options_save';
cbe5423b 222 break;
223 }
b5efadfa 224
cbe5423b 225 /* Run the options save hook. */
6e515418 226 do_hook($save_hook_name, $null);
cbe5423b 227}
228
229/***************************************************************/
230/* Apply logic to decide what optpage we want to display next. */
231/***************************************************************/
232
233/* If this is the result of an option page being submitted, then */
234/* show the main page. Otherwise, show whatever page was called. */
235
236if ($optmode == SMOPT_MODE_SUBMIT) {
237 $optpage = SMOPT_PAGE_MAIN;
238}
239
2de8b87f 240/***************************************************************/
241/* Finally, display whatever page we are supposed to show now. */
242/***************************************************************/
243
876fdb60 244displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
2de8b87f 245
2de8b87f 246/*
247 * The main option page has a different layout then the rest of the option
248 * pages. Therefore, we create it here first, then the others below.
249 */
250if ($optpage == SMOPT_PAGE_MAIN) {
251 /**********************************************************/
252 /* First, display the results of a submission, if needed. */
253 /**********************************************************/
254 $notice = '';
255 if ($optmode == SMOPT_MODE_SUBMIT) {
256 if (!isset($frame_top)) {
257 $frame_top = '_top';
258 }
259
260 if (isset($optpage_save_error) && $optpage_save_error!=array()) {
8befffa8 261//FIXME: REMOVE HTML FROM CORE
64033e1c 262 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
2de8b87f 263 foreach ($optpage_save_error as $error_message) {
264 $notice.= '<li><small>' . $error_message . "</small></li>\n";
265 }
64033e1c 266 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
2de8b87f 267 } else {
268 /* Display a message indicating a successful save. */
64033e1c 269 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
2de8b87f 270 }
271
272 /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
273 if ( !isset( $max_refresh ) ) {
274 } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
8befffa8 275//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"
276 if (checkForJavascript()) {
277 $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";
278 } else {
279 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
280 }
2de8b87f 281 } else if ($max_refresh) {
8befffa8 282 if (checkForJavascript()) {
283//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
284 $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";
285 } else {
286 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
287 }
2de8b87f 288 }
289 }
64033e1c 290
291 if (!empty($notice)) {
203f4ab0 292 $oTemplate->assign('note', $notice);
64033e1c 293 $oTemplate->display('note.tpl');
294 }
295
2de8b87f 296 /******************************************/
297 /* Build our array of Option Page Blocks. */
298 /******************************************/
299 $optpage_blocks = array();
300
301 /* Build a section for Personal Options. */
302 $optpage_blocks[] = array(
303 'name' => _("Personal Information"),
304 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
305 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
306 'js' => false
307 );
308
309 /* Build a section for Display Options. */
310 $optpage_blocks[] = array(
311 'name' => _("Display Preferences"),
312 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
313 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
314 'js' => false
315 );
316
317 /* Build a section for Message Highlighting Options. */
318 $optpage_blocks[] = array(
319 'name' =>_("Message Highlighting"),
320 'url' => 'options_highlight.php',
321 '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."),
322 'js' => false
323 );
324
325 /* Build a section for Folder Options. */
326 $optpage_blocks[] = array(
327 'name' => _("Folder Preferences"),
328 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
329 'desc' => _("These settings change the way your folders are displayed and manipulated."),
330 'js' => false
331 );
332
333 /* Build a section for Index Order Options. */
334 $optpage_blocks[] = array(
335 'name' => _("Index Order"),
336 'url' => 'options_order.php',
337 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
338 'js' => false
339 );
340
341 /* Build a section for Compose Options. */
342 $optpage_blocks[] = array(
343 'name' => _("Compose Preferences"),
344 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE,
345 'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
346 'js' => false
347 );
348
349 /* Build a section for plugins wanting to register an optionpage. */
6e515418 350 do_hook('optpage_register_block', $null);
2de8b87f 351
352 /*****************************************************/
353 /* Let's sort Javascript Option Pages to the bottom. */
354 /*****************************************************/
355 $js_optpage_blocks = array();
356 $reg_optpage_blocks = array();
357 foreach ($optpage_blocks as $cur_optpage) {
358 if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
359 $reg_optpage_blocks[] = $cur_optpage;
457e8593 360 } else if (checkForJavascript()) {
2de8b87f 361 $js_optpage_blocks[] = $cur_optpage;
362 }
363 }
364 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
365
366 /********************************************/
367 /* Now, print out each option page section. */
368 /********************************************/
64033e1c 369 $oTemplate->assign('page_title', $optpage_title);
370 $oTemplate->assign('options', $optpage_blocks);
2de8b87f 371
2de8b87f 372 $oTemplate->display('option_groups.tpl');
64033e1c 373
6e515418 374 do_hook('options_link_and_description', $null);
cbe5423b 375
cbe5423b 376
2de8b87f 377/*************************************************************************/
378/* If we are not looking at the main option page, display the page here. */
379/*************************************************************************/
380} else {
fcc81e7a 381 /* Set the bottom_hook_name and submit_name. */
2de8b87f 382 switch ($optpage) {
383 case SMOPT_PAGE_PERSONAL:
2de8b87f 384 $bottom_hook_name = 'options_personal_bottom';
385 $submit_name = 'submit_personal';
386 break;
387 case SMOPT_PAGE_DISPLAY:
2de8b87f 388 $bottom_hook_name = 'options_display_bottom';
389 $submit_name = 'submit_display';
390 break;
391 case SMOPT_PAGE_COMPOSE:
2de8b87f 392 $bottom_hook_name = 'options_compose_bottom';
393 $submit_name = 'submit_compose';
394 break;
395 case SMOPT_PAGE_HIGHLIGHT:
2de8b87f 396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
398 break;
399 case SMOPT_PAGE_FOLDER:
2de8b87f 400 $bottom_hook_name = 'options_folder_bottom';
401 $submit_name = 'submit_folder';
402 break;
403 case SMOPT_PAGE_ORDER:
2de8b87f 404 $bottom_hook_name = 'options_order_bottom';
405 $submit_name = 'submit_order';
406 break;
407 default:
2de8b87f 408 $bottom_hook_name = '';
409 $submit_name = 'submit';
410 }
411
64033e1c 412 // Begin output form
413 echo addForm('options.php', 'post', 'f')
414 . create_optpage_element($optpage)
415 . create_optmode_element(SMOPT_MODE_SUBMIT);
416
64033e1c 417 // This is the only variable that is needed by *just* the template.
203f4ab0 418 $oTemplate->assign('options', $optpage_data['options']);
64033e1c 419
ad3aa533 420 global $ask_user_info, $org_name;
75b4ac6f 421 if ( $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info
209e24bb 422 && getPref($data_dir, $username,'email_address') == "" ) {
423 $oTemplate->assign('topmessage',
ad3aa533 424 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
209e24bb 425 }
426
fcc81e7a 427 // These variables are not specifically needed by the template,
428 // but they are relevant to the page being built, so we'll add
429 // them in case some plugin is modifying the page, etc....
430 //
64033e1c 431 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
432 $oTemplate->assign('page_title', $optpage_title);
fcc81e7a 433 $oTemplate->assign('optpage', $optpage);
434 $oTemplate->assign('optpage_name', $optpage_name);
435 $oTemplate->assign('optmode', $optmode);
436 $oTemplate->assign('optpage_data', $optpage_data);
64033e1c 437
835db280 438 $oTemplate->assign('submit_name', $submit_name);
64033e1c 439 $oTemplate->display('options.tpl');
440
244a64a4 441 $oTemplate->display('form_close.tpl');
2de8b87f 442
443 /* If it is not empty, trigger the bottom hook. */
444 if ($bottom_hook_name != '') {
6e515418 445 do_hook($bottom_hook_name, $null);
2de8b87f 446 }
64033e1c 447
2de8b87f 448}
a2b193bc 449
6e4bf7c9 450$oTemplate->display('footer.tpl');