Just remove 'inside' hooks, which make no sense in templated output and were long...
[squirrelmail.git] / src / options.php
1 <?php
2
3 /**
4 * options.php
5 *
6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
8 *
9 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage prefs
14 */
15
16 /** This is the options page */
17 define('PAGE_NAME', 'options');
18
19 /**
20 * Include the SquirrelMail initialization file.
21 */
22 require('../include/init.php');
23
24 /* SquirrelMail required files. */
25
26 //include(SM_PATH . 'functions/imap_general.php');
27 require_once(SM_PATH . 'functions/options.php');
28 require_once(SM_PATH . 'functions/forms.php');
29
30 /*********************************/
31 /*** Build the resultant page. ***/
32 /*********************************/
33
34 define('SMOPT_MODE_DISPLAY', 'display');
35 define('SMOPT_MODE_SUBMIT', 'submit');
36 define('SMOPT_MODE_LINK', 'link');
37
38 define('SMOPT_PAGE_MAIN', 'main');
39 define('SMOPT_PAGE_PERSONAL', 'personal');
40 define('SMOPT_PAGE_DISPLAY', 'display');
41 define('SMOPT_PAGE_COMPOSE', 'compose');
42 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
43 define('SMOPT_PAGE_FOLDER', 'folder');
44 define('SMOPT_PAGE_ORDER', 'order');
45
46 function process_optionmode_submit($optpage, $optpage_data) {
47 /* Initialize the maximum option refresh level. */
48 $max_refresh = SMOPT_REFRESH_NONE;
49
50
51
52 /* Save each option in each option group. */
53 foreach ($optpage_data['options'] as $option_grp) {
54 foreach ($option_grp['options'] as $option) {
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
64 /* Remove Debug Mode Until Needed
65 echo "name = '$option->name', "
66 . "value = '$option->value', "
67 . "new_value = '$option->new_value'\n";
68 //FIXME: NO HTML IN THE CORE!
69 echo "<br />";
70 */
71 if ($option->changed()) {
72 $option->save();
73 $max_refresh = max($max_refresh, $option->refresh_level);
74 }
75 }
76 }
77
78 /* Return the max refresh level. */
79 return ($max_refresh);
80 }
81
82 function process_optionmode_link($optpage) {
83 /* There will be something here, later. */
84 }
85
86
87
88 /* ---------------------------- main ---------------------------- */
89
90 /* get the globals that we may need */
91 sqgetGlobalVar('optpage', $optpage);
92 sqgetGlobalVar('optmode', $optmode, SQ_FORM);
93 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
94 /* end of getting globals */
95
96 /* Make sure we have an Option Page set. Default to main. */
97 if ( !isset($optpage) || $optpage == '' ) {
98 $optpage = SMOPT_PAGE_MAIN;
99 } else {
100 $optpage = strip_tags( $optpage );
101 }
102
103 /* Make sure we have an Option Mode set. Default to display. */
104 if (!isset($optmode)) {
105 $optmode = SMOPT_MODE_DISPLAY;
106 }
107
108 /*
109 * First, set the load information for each option page.
110 */
111
112 /* Initialize load information variables. */
113 $optpage_name = '';
114 $optpage_file = '';
115 $optpage_loader = '';
116
117 /* Set the load information for each page. */
118 switch ($optpage) {
119 case SMOPT_PAGE_MAIN:
120 break;
121 case SMOPT_PAGE_PERSONAL:
122 $optpage_name = _("Personal Information");
123 $optpage_file = SM_PATH . 'include/options/personal.php';
124 $optpage_loader = 'load_optpage_data_personal';
125 $optpage_loadhook = 'optpage_loadhook_personal';
126 break;
127 case SMOPT_PAGE_DISPLAY:
128 $optpage_name = _("Display Preferences");
129 $optpage_file = SM_PATH . 'include/options/display.php';
130 $optpage_loader = 'load_optpage_data_display';
131 $optpage_loadhook = 'optpage_loadhook_display';
132 break;
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;
139 case SMOPT_PAGE_HIGHLIGHT:
140 $optpage_name = _("Message Highlighting");
141 $optpage_file = SM_PATH . 'include/options/highlight.php';
142 $optpage_loader = 'load_optpage_data_highlight';
143 $optpage_loadhook = 'optpage_loadhook_highlight';
144 break;
145 case SMOPT_PAGE_FOLDER:
146 $optpage_name = _("Folder Preferences");
147 $optpage_file = SM_PATH . 'include/options/folder.php';
148 $optpage_loader = 'load_optpage_data_folder';
149 $optpage_loadhook = 'optpage_loadhook_folder';
150 break;
151 case SMOPT_PAGE_ORDER:
152 $optpage_name = _("Index Order");
153 $optpage_file = SM_PATH . 'include/options/order.php';
154 $optpage_loader = 'load_optpage_data_order';
155 $optpage_loadhook = 'optpage_loadhook_order';
156 break;
157 default: do_hook('optpage_set_loadinfo', $null);
158 }
159
160 /**********************************************************/
161 /*** Second, load the option information for this page. ***/
162 /**********************************************************/
163
164 if ( !@is_file( $optpage_file ) ) {
165 $optpage = SMOPT_PAGE_MAIN;
166 } elseif ($optpage != SMOPT_PAGE_MAIN ) {
167 /* Include the file for this optionpage. */
168
169 require_once($optpage_file);
170
171 /* Assemble the data for this option page. */
172 $optpage_data = array();
173 $optpage_data = $optpage_loader();
174 do_hook($optpage_loadhook, $null);
175 $optpage_data['options'] = create_option_groups($optpage_data['grps'], $optpage_data['vals']);
176 }
177
178 /***********************************************************/
179 /*** Next, process anything that needs to be processed. ***/
180 /***********************************************************/
181
182 $optpage_save_error=array();
183
184 if ( 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 }
193 }
194
195 $optpage_title = _("Options");
196 if (isset($optpage_name) && ($optpage_name != '')) {
197 $optpage_title .= " - $optpage_name";
198 }
199
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. */
205 if ($optmode == SMOPT_MODE_SUBMIT) {
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;
214 case SMOPT_PAGE_COMPOSE:
215 $save_hook_name = 'options_compose_save';
216 break;
217 case SMOPT_PAGE_FOLDER:
218 $save_hook_name = 'options_folder_save';
219 break;
220 default:
221 $save_hook_name = 'options_save';
222 break;
223 }
224
225 /* Run the options save hook. */
226 do_hook($save_hook_name, $null);
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
236 if ($optmode == SMOPT_MODE_SUBMIT) {
237 $optpage = SMOPT_PAGE_MAIN;
238 }
239
240 /***************************************************************/
241 /* Finally, display whatever page we are supposed to show now. */
242 /***************************************************************/
243
244 displayPageHeader($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
245
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 */
250 if ($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()) {
261 //FIXME: REMOVE HTML FROM CORE
262 $notice = _("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
263 foreach ($optpage_save_error as $error_message) {
264 $notice.= '<li><small>' . $error_message . "</small></li>\n";
265 }
266 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
267 } else {
268 /* Display a message indicating a successful save. */
269 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
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) {
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 }
281 } else if ($max_refresh) {
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 }
288 }
289 }
290
291 if (!empty($notice)) {
292 $oTemplate->assign('note', $notice);
293 $oTemplate->display('note.tpl');
294 }
295
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. */
350 do_hook('optpage_register_block', $null);
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;
360 } else if (checkForJavascript()) {
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 /********************************************/
369 $oTemplate->assign('page_title', $optpage_title);
370 $oTemplate->assign('options', $optpage_blocks);
371
372 $oTemplate->display('option_groups.tpl');
373
374 do_hook('options_link_and_description', $null);
375
376
377 /*************************************************************************/
378 /* If we are not looking at the main option page, display the page here. */
379 /*************************************************************************/
380 } else {
381 /* Set the bottom_hook_name and submit_name. */
382 switch ($optpage) {
383 case SMOPT_PAGE_PERSONAL:
384 $bottom_hook_name = 'options_personal_bottom';
385 $submit_name = 'submit_personal';
386 break;
387 case SMOPT_PAGE_DISPLAY:
388 $bottom_hook_name = 'options_display_bottom';
389 $submit_name = 'submit_display';
390 break;
391 case SMOPT_PAGE_COMPOSE:
392 $bottom_hook_name = 'options_compose_bottom';
393 $submit_name = 'submit_compose';
394 break;
395 case SMOPT_PAGE_HIGHLIGHT:
396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
398 break;
399 case SMOPT_PAGE_FOLDER:
400 $bottom_hook_name = 'options_folder_bottom';
401 $submit_name = 'submit_folder';
402 break;
403 case SMOPT_PAGE_ORDER:
404 $bottom_hook_name = 'options_order_bottom';
405 $submit_name = 'submit_order';
406 break;
407 default:
408 $bottom_hook_name = '';
409 $submit_name = 'submit';
410 }
411
412 // Begin output form
413 echo addForm('options.php', 'post', 'f')
414 . create_optpage_element($optpage)
415 . create_optmode_element(SMOPT_MODE_SUBMIT);
416
417 // This is the only variable that is needed by *just* the template.
418 $oTemplate->assign('options', $optpage_data['options']);
419
420 global $ask_user_info, $org_name;
421 if ( $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info
422 && getPref($data_dir, $username,'email_address') == "" ) {
423 $oTemplate->assign('topmessage',
424 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
425 }
426
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 //
431 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
432 $oTemplate->assign('page_title', $optpage_title);
433 $oTemplate->assign('optpage', $optpage);
434 $oTemplate->assign('optpage_name', $optpage_name);
435 $oTemplate->assign('optmode', $optmode);
436 $oTemplate->assign('optpage_data', $optpage_data);
437
438 $oTemplate->assign('submit_name', $submit_name);
439 $oTemplate->display('options.tpl');
440
441 $oTemplate->display('form_close.tpl');
442
443 /* If it is not empty, trigger the bottom hook. */
444 if ($bottom_hook_name != '') {
445 do_hook($bottom_hook_name, $null);
446 }
447
448 }
449
450 $oTemplate->display('footer.tpl');