59177427 |
1 | <?php |
d3cdb279 |
2 | |
35586184 |
3 | /** |
4 | * options.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Displays the options page. Pulls from proper user preference files |
10 | * and config.php. Displays preferences as selected and other options. |
11 | * |
12 | * $Id$ |
13 | */ |
cbe5423b |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
20 | require_once(SM_PATH . 'functions/display_messages.php'); |
21 | require_once(SM_PATH . 'functions/imap.php'); |
22 | require_once(SM_PATH . 'functions/array.php'); |
23 | require_once(SM_PATH . 'functions/options.php'); |
24 | require_once(SM_PATH . 'functions/strings.php'); |
25 | require_once(SM_PATH . 'functions/html.php'); |
cbe5423b |
26 | |
cbe5423b |
27 | /*********************************/ |
28 | /*** Build the resultant page. ***/ |
29 | /*********************************/ |
30 | |
2d367c68 |
31 | displayPageHeader($color, 'None'); |
cbe5423b |
32 | |
33 | define('SMOPT_MODE_DISPLAY', 'display'); |
34 | define('SMOPT_MODE_SUBMIT', 'submit'); |
35 | define('SMOPT_MODE_LINK', 'link'); |
36 | |
37 | define('SMOPT_PAGE_MAIN', 'main'); |
38 | define('SMOPT_PAGE_PERSONAL', 'personal'); |
39 | define('SMOPT_PAGE_DISPLAY', 'display'); |
40 | define('SMOPT_PAGE_HIGHLIGHT', 'highlight'); |
41 | define('SMOPT_PAGE_FOLDER', 'folder'); |
42 | define('SMOPT_PAGE_ORDER', 'order'); |
43 | |
44 | function process_optionmode_submit($optpage, $optpage_data) { |
45 | /* Initialize the maximum option refresh level. */ |
46 | $max_refresh = SMOPT_REFRESH_NONE; |
47 | |
48 | /* Save each option in each option group. */ |
49 | foreach ($optpage_data['options'] as $option_grp) { |
50 | foreach ($option_grp['options'] as $option) { |
534367eb |
51 | /* Remove Debug Mode Until Needed |
cbe5423b |
52 | echo "name = '$option->name', " |
53 | . "value = '$option->value', " |
6206f6c4 |
54 | . "new_value = '$option->new_value'\n"; |
55 | echo "<br>"; |
534367eb |
56 | */ |
cbe5423b |
57 | if ($option->changed()) { |
58 | $option->save(); |
59 | $max_refresh = max($max_refresh, $option->refresh_level); |
60 | } |
61 | } |
62 | } |
1e0628fb |
63 | |
cbe5423b |
64 | /* Return the max refresh level. */ |
65 | return ($max_refresh); |
66 | } |
67 | |
68 | function process_optionmode_link($optpage) { |
69 | /* There will be something here, later. */ |
70 | } |
71 | |
0b0e96c5 |
72 | |
73 | /** |
74 | * This function prints out an option page row. |
75 | */ |
76 | function print_optionpages_row($leftopt, $rightopt = false) { |
77 | global $color; |
78 | |
0b0e96c5 |
79 | if ($rightopt) { |
545238b1 |
80 | $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' ); |
81 | $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' ); |
0b0e96c5 |
82 | } else { |
545238b1 |
83 | $rightopt_name = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' ); |
84 | $rightopt_desc = html_tag( 'td', ' ', 'left', $color[4], 'valign="top" width="49%"' ); |
0b0e96c5 |
85 | } |
86 | |
545238b1 |
87 | echo |
88 | html_tag( 'table', "\n" . |
89 | html_tag( 'tr', "\n" . |
90 | html_tag( 'td', "\n" . |
91 | html_tag( 'table', "\n" . |
92 | html_tag( 'tr', "\n" . |
93 | html_tag( 'td', |
94 | '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' , |
95 | 'left', $color[9], 'valign="top" width="49%"' ) . |
96 | html_tag( 'td', |
97 | ' ' , |
98 | 'left', $color[4], 'valign="top" width="2%"' ) . "\n" . |
99 | $rightopt_name |
100 | ) . "\n" . |
101 | html_tag( 'tr', "\n" . |
102 | html_tag( 'td', |
103 | $leftopt['desc'] , |
104 | 'left', $color[0], 'valign="top" width="49%"' ) . |
105 | html_tag( 'td', |
106 | ' ' , |
107 | 'left', $color[4], 'valign="top" width="2%"' ) . "\n" . |
108 | $rightopt_desc |
109 | ) , |
110 | '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) , |
111 | 'left', '', 'valign="top"' ) |
112 | ) , |
113 | '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ); |
0b0e96c5 |
114 | } |
115 | |
116 | /* ---------------------------- main ---------------------------- */ |
117 | |
cbe5423b |
118 | /* Make sure we have an Option Page set. Default to main. */ |
119 | if (!isset($optpage)) { |
120 | $optpage = 'main'; |
121 | } |
122 | |
123 | /* Make sure we have an Option Mode set. Default to display. */ |
124 | if (!isset($optmode)) { |
125 | $optmode = SMOPT_MODE_DISPLAY; |
126 | } |
127 | |
0b0e96c5 |
128 | /* |
129 | * First, set the load information for each option page. |
130 | */ |
cbe5423b |
131 | |
132 | /* Initialize load information variables. */ |
133 | $optpage_name = ''; |
134 | $optpage_file = ''; |
135 | $optpage_loader = ''; |
136 | |
137 | /* Set the load information for each page. */ |
138 | switch ($optpage) { |
139 | case SMOPT_PAGE_MAIN: break; |
140 | case SMOPT_PAGE_PERSONAL: |
a3439b27 |
141 | $optpage_name = _("Personal Information"); |
08185f2a |
142 | $optpage_file = SM_PATH . 'include/options/personal.php'; |
a3439b27 |
143 | $optpage_loader = 'load_optpage_data_personal'; |
144 | $optpage_loadhook = 'optpage_loadhook_personal'; |
cbe5423b |
145 | break; |
146 | case SMOPT_PAGE_DISPLAY: |
147 | $optpage_name = _("Display Preferences"); |
08185f2a |
148 | $optpage_file = SM_PATH . 'include/options/display.php'; |
cbe5423b |
149 | $optpage_loader = 'load_optpage_data_display'; |
a3439b27 |
150 | $optpage_loadhook = 'optpage_loadhook_display'; |
cbe5423b |
151 | break; |
152 | case SMOPT_PAGE_HIGHLIGHT: |
153 | $optpage_name = _("Message Highlighting"); |
08185f2a |
154 | $optpage_file = SM_PATH . 'include/options/highlight.php'; |
cbe5423b |
155 | $optpage_loader = 'load_optpage_data_highlight'; |
a3439b27 |
156 | $optpage_loadhook = 'optpage_loadhook_highlight'; |
cbe5423b |
157 | break; |
158 | case SMOPT_PAGE_FOLDER: |
159 | $optpage_name = _("Folder Preferences"); |
08185f2a |
160 | $optpage_file = SM_PATH . 'include/options/folder.php'; |
cbe5423b |
161 | $optpage_loader = 'load_optpage_data_folder'; |
a3439b27 |
162 | $optpage_loadhook = 'optpage_loadhook_folder'; |
cbe5423b |
163 | break; |
164 | case SMOPT_PAGE_ORDER: |
165 | $optpage_name = _("Index Order"); |
08185f2a |
166 | $optpage_file = SM_PATH . 'include/options/order.php'; |
cbe5423b |
167 | $optpage_loader = 'load_optpage_data_order'; |
a3439b27 |
168 | $optpage_loadhook = 'optpage_loadhook_order'; |
cbe5423b |
169 | break; |
2fad95fa |
170 | default: do_hook('optpage_set_loadinfo'); |
cbe5423b |
171 | } |
172 | |
173 | /**********************************************************/ |
174 | /*** Second, load the option information for this page. ***/ |
175 | /**********************************************************/ |
176 | |
177 | if ($optpage != SMOPT_PAGE_MAIN) { |
178 | /* Include the file for this optionpage. */ |
179 | require_once($optpage_file); |
180 | |
181 | /* Assemble the data for this option page. */ |
182 | $optpage_data = array(); |
183 | $optpage_data = $optpage_loader(); |
a3439b27 |
184 | do_hook($optpage_loadhook); |
cbe5423b |
185 | $optpage_data['options'] = |
186 | create_option_groups($optpage_data['grps'], $optpage_data['vals']); |
187 | } |
188 | |
189 | /***********************************************************/ |
190 | /*** Next, process anything that needs to be processed. ***/ |
191 | /***********************************************************/ |
192 | |
cc61478a |
193 | if ( isset( $optpage_data ) ) { |
194 | switch ($optmode) { |
195 | case SMOPT_MODE_SUBMIT: |
196 | $max_refresh = process_optionmode_submit($optpage, $optpage_data); |
197 | break; |
198 | case SMOPT_MODE_LINK: |
199 | $max_refresh = process_optionmode_link($optpage, $optpage_data); |
200 | break; |
201 | } |
cbe5423b |
202 | } |
cbe5423b |
203 | /*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/ |
204 | |
205 | $optpage_title = _("Options"); |
206 | if (isset($optpage_name) && ($optpage_name != '')) { |
207 | $optpage_title .= " - $optpage_name"; |
208 | } |
f740c049 |
209 | |
6206f6c4 |
210 | echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" . |
545238b1 |
211 | html_tag( 'tr' ) . "\n" . |
212 | html_tag( 'td', '', 'center' ) . |
213 | "<b>$optpage_title</b><br>\n". |
214 | html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" . |
215 | html_tag( 'tr' ) . "\n" . |
216 | html_tag( 'td', '', 'center', $color[4] ) . "\n"; |
b5efadfa |
217 | |
cbe5423b |
218 | /*******************************************************************/ |
219 | /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */ |
220 | /*******************************************************************/ |
221 | |
222 | /* If in submit mode, select a save hook name and run it. */ |
7e235a1a |
223 | if ($optmode == SMOPT_MODE_SUBMIT) { |
cbe5423b |
224 | /* Select a save hook name. */ |
225 | switch ($optpage) { |
226 | case SMOPT_PAGE_PERSONAL: |
227 | $save_hook_name = 'options_personal_save'; |
228 | break; |
229 | case SMOPT_PAGE_DISPLAY: |
230 | $save_hook_name = 'options_display_save'; |
231 | break; |
232 | case SMOPT_PAGE_FOLDER: |
233 | $save_hook_name = 'options_folder_save'; |
234 | break; |
cc61478a |
235 | default: |
236 | $save_hook_name = 'options_save'; |
cbe5423b |
237 | break; |
238 | } |
b5efadfa |
239 | |
cbe5423b |
240 | /* Run the options save hook. */ |
241 | do_hook($save_hook_name); |
242 | } |
243 | |
244 | /***************************************************************/ |
245 | /* Apply logic to decide what optpage we want to display next. */ |
246 | /***************************************************************/ |
247 | |
248 | /* If this is the result of an option page being submitted, then */ |
249 | /* show the main page. Otherwise, show whatever page was called. */ |
250 | |
251 | if ($optmode == SMOPT_MODE_SUBMIT) { |
252 | $optpage = SMOPT_PAGE_MAIN; |
253 | } |
254 | |
255 | /***************************************************************/ |
256 | /* Finally, display whatever page we are supposed to show now. */ |
257 | /***************************************************************/ |
258 | |
259 | /* |
260 | * The main option page has a different layout then the rest of the option |
261 | * pages. Therefore, we create it here first, then the others below. |
262 | */ |
263 | if ($optpage == SMOPT_PAGE_MAIN) { |
264 | /**********************************************************/ |
265 | /* First, display the results of a submission, if needed. */ |
266 | /**********************************************************/ |
267 | if ($optmode == SMOPT_MODE_SUBMIT) { |
e362fff6 |
268 | if (!isset($frame_top)) { |
d03f3582 |
269 | $frame_top = '_top'; |
270 | } |
cbe5423b |
271 | /* Display a message indicating a successful save. */ |
545238b1 |
272 | echo '<b>' . _("Successfully Saved Options") . ": $optpage_name</b><br>\n"; |
cbe5423b |
273 | |
274 | /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */ |
88cb1b4d |
275 | if ( !isset( $max_refresh ) ) { |
276 | } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) { |
545238b1 |
277 | echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br>'; |
cbe5423b |
278 | } else if ($max_refresh) { |
545238b1 |
279 | echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br>'; |
849bdf42 |
280 | } |
849bdf42 |
281 | } |
cbe5423b |
282 | /******************************************/ |
283 | /* Build our array of Option Page Blocks. */ |
284 | /******************************************/ |
285 | $optpage_blocks = array(); |
849bdf42 |
286 | |
287 | /* Build a section for Personal Options. */ |
cbe5423b |
288 | $optpage_blocks[] = array( |
849bdf42 |
289 | 'name' => _("Personal Information"), |
cbe5423b |
290 | 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL, |
849bdf42 |
291 | 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."), |
292 | 'js' => false |
293 | ); |
294 | |
295 | /* Build a section for Display Options. */ |
cbe5423b |
296 | $optpage_blocks[] = array( |
849bdf42 |
297 | 'name' => _("Display Preferences"), |
cbe5423b |
298 | 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY, |
849bdf42 |
299 | 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."), |
300 | 'js' => false |
301 | ); |
302 | |
303 | /* Build a section for Message Highlighting Options. */ |
cbe5423b |
304 | $optpage_blocks[] = array( |
849bdf42 |
305 | 'name' =>_("Message Highlighting"), |
306 | 'url' => 'options_highlight.php', |
307 | '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."), |
308 | 'js' => false |
309 | ); |
310 | |
311 | /* Build a section for Folder Options. */ |
cbe5423b |
312 | $optpage_blocks[] = array( |
849bdf42 |
313 | 'name' => _("Folder Preferences"), |
cbe5423b |
314 | 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER, |
849bdf42 |
315 | 'desc' => _("These settings change the way your folders are displayed and manipulated."), |
316 | 'js' => false |
317 | ); |
318 | |
319 | /* Build a section for Index Order Options. */ |
cbe5423b |
320 | $optpage_blocks[] = array( |
849bdf42 |
321 | 'name' => _("Index Order"), |
322 | 'url' => 'options_order.php', |
8aedb8c7 |
323 | 'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."), |
849bdf42 |
324 | 'js' => false |
325 | ); |
cbe5423b |
326 | |
849bdf42 |
327 | /* Build a section for plugins wanting to register an optionpage. */ |
cbe5423b |
328 | do_hook('optpage_register_block'); |
849bdf42 |
329 | |
330 | /*****************************************************/ |
331 | /* Let's sort Javascript Option Pages to the bottom. */ |
332 | /*****************************************************/ |
cbe5423b |
333 | $js_optpage_blocks = array(); |
334 | $reg_optpage_blocks = array(); |
335 | foreach ($optpage_blocks as $cur_optpage) { |
336 | if (!$cur_optpage['js']) { |
337 | $reg_optpage_blocks[] = $cur_optpage; |
23d6bd09 |
338 | } else if ($javascript_on == SMPREF_JS_ON) { |
cbe5423b |
339 | $js_optpage_blocks[] = $cur_optpage; |
849bdf42 |
340 | } |
341 | } |
cbe5423b |
342 | $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks); |
849bdf42 |
343 | |
344 | /********************************************/ |
345 | /* Now, print out each option page section. */ |
346 | /********************************************/ |
347 | $first_optpage = false; |
545238b1 |
348 | echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" . |
349 | html_tag( 'tr' ) . "\n" . |
350 | html_tag( 'td', '', 'left', '', 'valign="top"' ) . |
351 | html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" . |
352 | html_tag( 'tr' ) . "\n" . |
353 | html_tag( 'td', '', 'left' ); |
cbe5423b |
354 | foreach ($optpage_blocks as $next_optpage) { |
849bdf42 |
355 | if ($first_optpage == false) { |
356 | $first_optpage = $next_optpage; |
357 | } else { |
358 | print_optionpages_row($first_optpage, $next_optpage); |
359 | $first_optpage = false; |
360 | } |
361 | } |
362 | |
363 | if ($first_optpage != false) { |
364 | print_optionpages_row($first_optpage); |
365 | } |
366 | |
545238b1 |
367 | echo "</td></tr></table></td></tr></table>\n"; |
dfec863e |
368 | |
849bdf42 |
369 | do_hook('options_link_and_description'); |
370 | |
cbe5423b |
371 | |
372 | /*************************************************************************/ |
373 | /* If we are not looking at the main option page, display the page here. */ |
374 | /*************************************************************************/ |
375 | } else { |
545238b1 |
376 | echo '<form name="f" action="options.php" method="post"><br>' . "\n" |
cbe5423b |
377 | . create_optpage_element($optpage) |
bd9bbfef |
378 | . create_optmode_element(SMOPT_MODE_SUBMIT) |
545238b1 |
379 | . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n" |
380 | . html_tag( 'tr' ) . "\n" |
381 | . html_tag( 'td', '', 'left' ) . "\n"; |
cbe5423b |
382 | |
383 | /* Output the option groups for this page. */ |
384 | print_option_groups($optpage_data['options']); |
385 | |
cbe5423b |
386 | /* Set the inside_hook_name and submit_name. */ |
387 | switch ($optpage) { |
388 | case SMOPT_PAGE_PERSONAL: |
389 | $inside_hook_name = 'options_personal_inside'; |
390 | $bottom_hook_name = 'options_personal_bottom'; |
391 | $submit_name = 'submit_personal'; |
392 | break; |
393 | case SMOPT_PAGE_DISPLAY: |
394 | $inside_hook_name = 'options_display_inside'; |
395 | $bottom_hook_name = 'options_display_bottom'; |
396 | $submit_name = 'submit_display'; |
397 | break; |
398 | case SMOPT_PAGE_HIGHLIGHT: |
399 | $inside_hook_name = 'options_highlight_inside'; |
2fad95fa |
400 | $bottom_hook_name = 'options_highlight_bottom'; |
cbe5423b |
401 | $submit_name = 'submit_highlight'; |
402 | break; |
403 | case SMOPT_PAGE_FOLDER: |
404 | $inside_hook_name = 'options_folder_inside'; |
2fad95fa |
405 | $bottom_hook_name = 'options_folder_bottom'; |
cbe5423b |
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 | |
419 | /* If it is not empty, trigger the inside hook. */ |
420 | if ($inside_hook_name != '') { |
421 | do_hook($inside_hook_name); |
422 | } |
423 | |
424 | /* Spit out a submit button. */ |
425 | OptionSubmit($submit_name); |
545238b1 |
426 | echo '</td></tr></table></form>'; |
cbe5423b |
427 | |
428 | /* If it is not empty, trigger the bottom hook. */ |
429 | if ($bottom_hook_name != '') { |
430 | do_hook($bottom_hook_name); |
431 | } |
432 | } |
433 | |
545238b1 |
434 | echo '</td></tr>' . |
435 | '</table>'. |
436 | '</td></tr>'. |
437 | '</table>' . |
438 | '</body></html>'; |
e7db48af |
439 | |
2363ad39 |
440 | ?> |