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