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