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