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"; |
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 | |
82 | function 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 |
91 | sqgetGlobalVar('optpage', $optpage); |
5ccba4f3 |
92 | sqgetGlobalVar('optmode', $optmode, SQ_FORM); |
1e12d1ff |
93 | sqgetGlobalVar('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 |
97 | if ( !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. */ |
104 | if (!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. */ |
118 | switch ($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 |
164 | if ( !@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 |
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 | } |
cbe5423b |
193 | } |
cbe5423b |
194 | |
2de8b87f |
195 | $optpage_title = _("Options"); |
196 | if (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 |
205 | if ($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 | |
236 | if ($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 |
244 | displayPageHeader($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 | */ |
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()) { |
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 { |
2de8b87f |
381 | /* Set the inside_hook_name and submit_name. */ |
382 | switch ($optpage) { |
383 | case SMOPT_PAGE_PERSONAL: |
384 | $inside_hook_name = 'options_personal_inside'; |
385 | $bottom_hook_name = 'options_personal_bottom'; |
386 | $submit_name = 'submit_personal'; |
387 | break; |
388 | case SMOPT_PAGE_DISPLAY: |
389 | $inside_hook_name = 'options_display_inside'; |
390 | $bottom_hook_name = 'options_display_bottom'; |
391 | $submit_name = 'submit_display'; |
392 | break; |
393 | case SMOPT_PAGE_COMPOSE: |
394 | $inside_hook_name = 'options_compose_inside'; |
395 | $bottom_hook_name = 'options_compose_bottom'; |
396 | $submit_name = 'submit_compose'; |
397 | break; |
398 | case SMOPT_PAGE_HIGHLIGHT: |
399 | $inside_hook_name = 'options_highlight_inside'; |
400 | $bottom_hook_name = 'options_highlight_bottom'; |
401 | $submit_name = 'submit_highlight'; |
402 | break; |
403 | case SMOPT_PAGE_FOLDER: |
404 | $inside_hook_name = 'options_folder_inside'; |
405 | $bottom_hook_name = 'options_folder_bottom'; |
406 | $submit_name = 'submit_folder'; |
407 | break; |
408 | case SMOPT_PAGE_ORDER: |
409 | $inside_hook_name = 'options_order_inside'; |
410 | $bottom_hook_name = 'options_order_bottom'; |
411 | $submit_name = 'submit_order'; |
412 | break; |
413 | default: |
414 | $inside_hook_name = ''; |
415 | $bottom_hook_name = ''; |
416 | $submit_name = 'submit'; |
417 | } |
418 | |
64033e1c |
419 | // Begin output form |
420 | echo addForm('options.php', 'post', 'f') |
421 | . create_optpage_element($optpage) |
422 | . create_optmode_element(SMOPT_MODE_SUBMIT); |
423 | |
424 | // Wrap the template in a table to keep from breaking the hooks below |
244a64a4 |
425 | $oTemplate->assign('attributes', array('cellspacing' => 0, 'class' => 'table_blank')); |
426 | $oTemplate->display('table.tpl'); |
427 | $oTemplate->display('table_row.tpl'); |
428 | $oTemplate->assign('attributes', array('colspan' => 2)); |
429 | $oTemplate->display('table_data.tpl'); |
64033e1c |
430 | |
431 | // This is the only variable that is needed by *just* the template. |
203f4ab0 |
432 | $oTemplate->assign('options', $optpage_data['options']); |
64033e1c |
433 | |
ad3aa533 |
434 | global $ask_user_info, $org_name; |
75b4ac6f |
435 | if ( $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info |
209e24bb |
436 | && getPref($data_dir, $username,'email_address') == "" ) { |
437 | $oTemplate->assign('topmessage', |
ad3aa533 |
438 | sprintf(_("Welcome to %s. Please supply your full name and email address."), $org_name) ); |
209e24bb |
439 | } |
440 | |
64033e1c |
441 | /** |
442 | * The variables below should not be needed by the template since all plugin |
443 | * hooks are called here, not in the template. If we find otherwise, these |
835db280 |
444 | * variables can be passed to the template. Commenting out for now. |
64033e1c |
445 | */ |
446 | /* |
447 | $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL); |
448 | $oTemplate->assign('page_title', $optpage_title); |
449 | $oTemplate->assign('optpage',$optpage); |
450 | $oTemplate->assign('optpage_name',$optpage_name); |
451 | $oTemplate->assign('optmode',$optmode); |
452 | $oTemplate->assign('optpage_data',$optpage_data); |
453 | */ |
454 | /** |
455 | * END comment block |
456 | */ |
457 | |
835db280 |
458 | $oTemplate->assign('submit_name', $submit_name); |
64033e1c |
459 | $oTemplate->display('options.tpl'); |
460 | |
244a64a4 |
461 | $oTemplate->display('table_data_close.tpl'); |
462 | $oTemplate->display('table_row_close.tpl'); |
64033e1c |
463 | |
2de8b87f |
464 | /* If it is not empty, trigger the inside hook. */ |
465 | if ($inside_hook_name != '') { |
6e515418 |
466 | do_hook($inside_hook_name, $null); |
2de8b87f |
467 | } |
468 | |
244a64a4 |
469 | $oTemplate->display('table_close.tpl'); |
470 | $oTemplate->display('form_close.tpl'); |
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'); |