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