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