Use $org_name instead of hard-coding "SquirrelMail"
[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 /**
17 * Include the SquirrelMail initialization file.
18 */
19 require('../include/init.php');
20
21 /* SquirrelMail required files. */
22
23 //include(SM_PATH . 'functions/imap_general.php');
24 require_once(SM_PATH . 'functions/options.php');
25 require_once(SM_PATH . 'functions/forms.php');
26
27 /*********************************/
28 /*** Build the resultant page. ***/
29 /*********************************/
30
31 define('SMOPT_MODE_DISPLAY', 'display');
32 define('SMOPT_MODE_SUBMIT', 'submit');
33 define('SMOPT_MODE_LINK', 'link');
34
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');
42
43 function process_optionmode_submit($optpage, $optpage_data) {
44 /* Initialize the maximum option refresh level. */
45 $max_refresh = SMOPT_REFRESH_NONE;
46
47
48
49 /* Save each option in each option group. */
50 foreach ($optpage_data['options'] as $option_grp) {
51 foreach ($option_grp['options'] as $option) {
52
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('');
59 }
60
61 /* Remove Debug Mode Until Needed
62 echo "name = '$option->name', "
63 . "value = '$option->value', "
64 . "new_value = '$option->new_value'\n";
65 echo "<br />";
66 */
67 if ($option->changed()) {
68 $option->save();
69 $max_refresh = max($max_refresh, $option->refresh_level);
70 }
71 }
72 }
73
74 /* Return the max refresh level. */
75 return ($max_refresh);
76 }
77
78 function process_optionmode_link($optpage) {
79 /* There will be something here, later. */
80 }
81
82
83
84 /* ---------------------------- main ---------------------------- */
85
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 */
91
92 /* Make sure we have an Option Page set. Default to main. */
93 if ( !isset($optpage) || $optpage == '' ) {
94 $optpage = SMOPT_PAGE_MAIN;
95 } else {
96 $optpage = strip_tags( $optpage );
97 }
98
99 /* Make sure we have an Option Mode set. Default to display. */
100 if (!isset($optmode)) {
101 $optmode = SMOPT_MODE_DISPLAY;
102 }
103
104 /*
105 * First, set the load information for each option page.
106 */
107
108 /* Initialize load information variables. */
109 $optpage_name = '';
110 $optpage_file = '';
111 $optpage_loader = '';
112
113 /* Set the load information for each page. */
114 switch ($optpage) {
115 case SMOPT_PAGE_MAIN:
116 break;
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';
122 break;
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';
128 break;
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';
134 break;
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';
140 break;
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';
146 break;
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';
152 break;
153 default: do_hook('optpage_set_loadinfo', $null);
154 }
155
156 /**********************************************************/
157 /*** Second, load the option information for this page. ***/
158 /**********************************************************/
159
160 if ( !@is_file( $optpage_file ) ) {
161 $optpage = SMOPT_PAGE_MAIN;
162 } elseif ($optpage != SMOPT_PAGE_MAIN ) {
163 /* Include the file for this optionpage. */
164
165 require_once($optpage_file);
166
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']);
172 }
173
174 /***********************************************************/
175 /*** Next, process anything that needs to be processed. ***/
176 /***********************************************************/
177
178 $optpage_save_error=array();
179
180 if ( isset( $optpage_data ) ) {
181 switch ($optmode) {
182 case SMOPT_MODE_SUBMIT:
183 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
184 break;
185 case SMOPT_MODE_LINK:
186 $max_refresh = process_optionmode_link($optpage, $optpage_data);
187 break;
188 }
189 }
190
191 $optpage_title = _("Options");
192 if (isset($optpage_name) && ($optpage_name != '')) {
193 $optpage_title .= " - $optpage_name";
194 }
195
196 /*******************************************************************/
197 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
198 /*******************************************************************/
199
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. */
203 switch ($optpage) {
204 case SMOPT_PAGE_PERSONAL:
205 $save_hook_name = 'options_personal_save';
206 break;
207 case SMOPT_PAGE_DISPLAY:
208 $save_hook_name = 'options_display_save';
209 break;
210 case SMOPT_PAGE_COMPOSE:
211 $save_hook_name = 'options_compose_save';
212 break;
213 case SMOPT_PAGE_FOLDER:
214 $save_hook_name = 'options_folder_save';
215 break;
216 default:
217 $save_hook_name = 'options_save';
218 break;
219 }
220
221 /* Run the options save hook. */
222 do_hook($save_hook_name, $null);
223 }
224
225 /***************************************************************/
226 /* Apply logic to decide what optpage we want to display next. */
227 /***************************************************************/
228
229 /* If this is the result of an option page being submitted, then */
230 /* show the main page. Otherwise, show whatever page was called. */
231
232 if ($optmode == SMOPT_MODE_SUBMIT) {
233 $optpage = SMOPT_PAGE_MAIN;
234 }
235
236 /***************************************************************/
237 /* Finally, display whatever page we are supposed to show now. */
238 /***************************************************************/
239
240 displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
241
242 /*
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.
245 */
246 if ($optpage == SMOPT_PAGE_MAIN) {
247 /**********************************************************/
248 /* First, display the results of a submission, if needed. */
249 /**********************************************************/
250 $notice = '';
251 if ($optmode == SMOPT_MODE_SUBMIT) {
252 if (!isset($frame_top)) {
253 $frame_top = '_top';
254 }
255
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";
261 }
262 $notice.= "</ul>\n" . _("Some of your preference changes were not applied.") . "\n";
263 } else {
264 /* Display a message indicating a successful save. */
265 $notice = _("Successfully Saved Options") . ": $optpage_name</b><br />\n";
266 }
267
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";
274 } else {
275 $notice .= '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
276 }
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";
281 } else {
282 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
283 }
284 }
285 }
286
287 if (!empty($notice)) {
288 $oTemplate->assign('note', $notice, FALSE);
289 $oTemplate->display('note.tpl');
290 }
291
292 /******************************************/
293 /* Build our array of Option Page Blocks. */
294 /******************************************/
295 $optpage_blocks = array();
296
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."),
302 'js' => false
303 );
304
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."),
310 'js' => false
311 );
312
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."),
318 'js' => false
319 );
320
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."),
326 'js' => false
327 );
328
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."),
334 'js' => false
335 );
336
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."),
342 'js' => false
343 );
344
345 /* Build a section for plugins wanting to register an optionpage. */
346 do_hook('optpage_register_block', $null);
347
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;
358 }
359 }
360 $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
361
362 /********************************************/
363 /* Now, print out each option page section. */
364 /********************************************/
365 $oTemplate->assign('page_title', $optpage_title);
366 $oTemplate->assign('options', $optpage_blocks);
367
368 $oTemplate->display('option_groups.tpl');
369
370 do_hook('options_link_and_description', $null);
371
372
373 /*************************************************************************/
374 /* If we are not looking at the main option page, display the page here. */
375 /*************************************************************************/
376 } else {
377 /* Set the inside_hook_name and submit_name. */
378 switch ($optpage) {
379 case SMOPT_PAGE_PERSONAL:
380 $inside_hook_name = 'options_personal_inside';
381 $bottom_hook_name = 'options_personal_bottom';
382 $submit_name = 'submit_personal';
383 break;
384 case SMOPT_PAGE_DISPLAY:
385 $inside_hook_name = 'options_display_inside';
386 $bottom_hook_name = 'options_display_bottom';
387 $submit_name = 'submit_display';
388 break;
389 case SMOPT_PAGE_COMPOSE:
390 $inside_hook_name = 'options_compose_inside';
391 $bottom_hook_name = 'options_compose_bottom';
392 $submit_name = 'submit_compose';
393 break;
394 case SMOPT_PAGE_HIGHLIGHT:
395 $inside_hook_name = 'options_highlight_inside';
396 $bottom_hook_name = 'options_highlight_bottom';
397 $submit_name = 'submit_highlight';
398 break;
399 case SMOPT_PAGE_FOLDER:
400 $inside_hook_name = 'options_folder_inside';
401 $bottom_hook_name = 'options_folder_bottom';
402 $submit_name = 'submit_folder';
403 break;
404 case SMOPT_PAGE_ORDER:
405 $inside_hook_name = 'options_order_inside';
406 $bottom_hook_name = 'options_order_bottom';
407 $submit_name = 'submit_order';
408 break;
409 default:
410 $inside_hook_name = '';
411 $bottom_hook_name = '';
412 $submit_name = 'submit';
413 }
414
415 // Begin output form
416 echo addForm('options.php', 'post', 'f')
417 . create_optpage_element($optpage)
418 . create_optmode_element(SMOPT_MODE_SUBMIT);
419
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" .
423 " <tr>\n" .
424 " <td colspan=\"2\">\n";
425
426 // This is the only variable that is needed by *just* the template.
427 // No output sanitizing needed because all widgets added through
428 // template output already
429 $oTemplate->assign('options', $optpage_data['options'], FALSE);
430
431 global $ask_user_info, $org_name;
432 if ( $optpage = SMOPT_PAGE_PERSONAL && $ask_user_info
433 && getPref($data_dir, $username,'email_address') == "" ) {
434 $oTemplate->assign('topmessage',
435 sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) );
436 }
437
438 /**
439 * The variables below should not be needed by the template since all plugin
440 * hooks are called here, not in the template. If we find otherwise, these
441 * variables can be passed to the template. Commenting out for now.
442 */
443 /*
444 $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
445 $oTemplate->assign('page_title', $optpage_title);
446 $oTemplate->assign('optpage',$optpage);
447 $oTemplate->assign('optpage_name',$optpage_name);
448 $oTemplate->assign('optmode',$optmode);
449 $oTemplate->assign('optpage_data',$optpage_data);
450 */
451 /**
452 * END comment block
453 */
454
455 $oTemplate->assign('submit_name', $submit_name);
456 $oTemplate->display('options.tpl');
457
458 //FIXME: need to remove HTML from here!
459 echo " </td>\n" .
460 " </tr>\n";
461
462 /* If it is not empty, trigger the inside hook. */
463 if ($inside_hook_name != '') {
464 do_hook($inside_hook_name, $null);
465 }
466
467 //FIXME: need to remove HTML from here!
468 echo "</table>\n" .
469 "</form>\n";
470
471 /* If it is not empty, trigger the bottom hook. */
472 if ($bottom_hook_name != '') {
473 do_hook($bottom_hook_name, $null);
474 }
475
476 }
477
478 $oTemplate->display('footer.tpl');