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