| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * options_display.php |
| 5 | * |
| 6 | * Displays all optinos about display preferences |
| 7 | * |
| 8 | * @copyright © 1999-2006 The SquirrelMail Project Team |
| 9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
| 10 | * @version $Id$ |
| 11 | * @package squirrelmail |
| 12 | */ |
| 13 | |
| 14 | /** Define the group constants for the display options page. */ |
| 15 | define('SMOPT_GRP_GENERAL', 0); |
| 16 | define('SMOPT_GRP_MAILBOX', 1); |
| 17 | define('SMOPT_GRP_MESSAGE', 2); |
| 18 | |
| 19 | // load icon themes if in use |
| 20 | global $use_icons; |
| 21 | if ($use_icons) { |
| 22 | global $icon_themes; |
| 23 | $dirName = SM_PATH . 'images/themes'; |
| 24 | if (is_readable($dirName) && is_dir($dirName)) { |
| 25 | $d = dir($dirName); |
| 26 | while($dir = $d->read()) { |
| 27 | if ($dir != "." && $dir != "..") { |
| 28 | if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php")) |
| 29 | include("$dirName/$dir/theme.php"); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | global $use_iframe; |
| 36 | if (! isset($use_iframe)) $use_iframe=false; |
| 37 | |
| 38 | /** |
| 39 | * This function builds an array with all the information about |
| 40 | * the options available to the user, and returns it. The options |
| 41 | * are grouped by the groups in which they are displayed. |
| 42 | * For each option, the following information is stored: |
| 43 | * - name: the internal (variable) name |
| 44 | * - caption: the description of the option in the UI |
| 45 | * - type: one of SMOPT_TYPE_* |
| 46 | * - refresh: one of SMOPT_REFRESH_* |
| 47 | * - size: one of SMOPT_SIZE_* |
| 48 | * - save: the name of a function to call when saving this option |
| 49 | * @return array all option information |
| 50 | */ |
| 51 | function load_optpage_data_display() { |
| 52 | global $theme, $fontsets, $language, $languages,$aTemplateSet, |
| 53 | $default_use_mdn, $squirrelmail_language, $allow_thread_sort, |
| 54 | $show_alternative_names, $use_icons, $use_iframe, $sTplDir; |
| 55 | |
| 56 | /* Build a simple array into which we will build options. */ |
| 57 | $optgrps = array(); |
| 58 | $optvals = array(); |
| 59 | |
| 60 | /******************************************************/ |
| 61 | /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */ |
| 62 | /******************************************************/ |
| 63 | |
| 64 | /*** Load the General Options into the array ***/ |
| 65 | $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options"); |
| 66 | $optvals[SMOPT_GRP_GENERAL] = array(); |
| 67 | |
| 68 | /* load the template set option */ |
| 69 | $templateset_values = array(); |
| 70 | |
| 71 | foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes) { |
| 72 | $templateset_values[$aTemplateSetAttributes['NAME']] = $aTemplateSetAttributes['PATH']; |
| 73 | } |
| 74 | ksort($templateset_values); |
| 75 | $templateset_values = array_flip($templateset_values); |
| 76 | // display template options only when there is more than one template |
| 77 | if (count($templateset_values)>1) { |
| 78 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 79 | 'name' => 'sTplDir', |
| 80 | 'caption' => _("Template"), |
| 81 | 'type' => SMOPT_TYPE_STRLIST, |
| 82 | 'refresh' => SMOPT_REFRESH_ALL, |
| 83 | 'posvals' => $templateset_values, |
| 84 | 'save' => 'save_option_template' |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /* Load the theme option. */ |
| 89 | $theme_values = array(); |
| 90 | foreach ($theme as $theme_key => $theme_attributes) { |
| 91 | $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH']; |
| 92 | } |
| 93 | ksort($theme_values); |
| 94 | $theme_values = array_flip($theme_values); |
| 95 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 96 | 'name' => 'chosen_theme', |
| 97 | 'caption' => _("Theme"), |
| 98 | 'type' => SMOPT_TYPE_STRLIST, |
| 99 | 'refresh' => SMOPT_REFRESH_ALL, |
| 100 | 'posvals' => $theme_values, |
| 101 | 'save' => 'save_option_theme' |
| 102 | ); |
| 103 | |
| 104 | $css_values = array( 'none' => _("Default" ) ); |
| 105 | $css_dir = SM_PATH . 'themes/css'; |
| 106 | if (is_readable($css_dir) && is_dir($css_dir)) { |
| 107 | $handle=opendir($css_dir); |
| 108 | while ($file = readdir($handle) ) { |
| 109 | if ( substr( $file, -4 ) == '.css' ) { |
| 110 | $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 ); |
| 111 | } |
| 112 | } |
| 113 | closedir($handle); |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | if ( count( $css_values ) > 1 ) { |
| 118 | |
| 119 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 120 | 'name' => 'custom_css', |
| 121 | 'caption' => _("Custom Stylesheet"), |
| 122 | 'type' => SMOPT_TYPE_STRLIST, |
| 123 | 'refresh' => SMOPT_REFRESH_ALL, |
| 124 | 'posvals' => $css_values |
| 125 | ); |
| 126 | |
| 127 | } |
| 128 | */ |
| 129 | |
| 130 | $fontset_values = array(); |
| 131 | $fontset_list = array(); |
| 132 | |
| 133 | if (!empty($fontsets) && is_array($fontsets)) { |
| 134 | |
| 135 | foreach (array_keys($fontsets) as $fontset_key) { |
| 136 | $fontset_list[$fontset_key]=$fontset_key; |
| 137 | } |
| 138 | ksort($fontset_list); |
| 139 | } |
| 140 | |
| 141 | if (count($fontset_list) > 1) { |
| 142 | $fontset_list = array_merge(array('' => _("Default font style")), $fontset_list); |
| 143 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 144 | 'name' => 'chosen_fontset', |
| 145 | 'caption' => _("Font style"), |
| 146 | 'type' => SMOPT_TYPE_STRLIST, |
| 147 | 'refresh' => SMOPT_REFRESH_ALL, |
| 148 | 'posvals' => $fontset_list |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 153 | 'name' => 'chosen_fontsize', |
| 154 | 'caption' => _("Font size"), |
| 155 | 'type' => SMOPT_TYPE_STRLIST, |
| 156 | 'refresh' => SMOPT_REFRESH_ALL, |
| 157 | 'posvals' => array('' => _("Default font size"), |
| 158 | '8' => '8 px', |
| 159 | '10' => '10 px', |
| 160 | '12' => '12 px', |
| 161 | '14' => '14 px') |
| 162 | ); |
| 163 | |
| 164 | $language_values = array(); |
| 165 | foreach ($languages as $lang_key => $lang_attributes) { |
| 166 | if (isset($lang_attributes['NAME'])) { |
| 167 | $language_values[$lang_key] = $lang_attributes['NAME']; |
| 168 | if ( isset($show_alternative_names) && |
| 169 | $show_alternative_names && |
| 170 | isset($lang_attributes['ALTNAME']) ) { |
| 171 | $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME']; |
| 172 | } |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | asort($language_values); |
| 177 | $language_values = |
| 178 | array_merge(array('' => _("Default")), $language_values); |
| 179 | $language = $squirrelmail_language; |
| 180 | |
| 181 | // add language selection only when more than 2 languages are available |
| 182 | // (default, English and some other) |
| 183 | if (count($language_values)>2) { |
| 184 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 185 | 'name' => 'language', |
| 186 | 'caption' => _("Language"), |
| 187 | 'type' => SMOPT_TYPE_STRLIST, |
| 188 | 'refresh' => SMOPT_REFRESH_ALL, |
| 189 | 'posvals' => $language_values, |
| 190 | 'htmlencoded' => true |
| 191 | ); |
| 192 | } |
| 193 | |
| 194 | /* Set values for the "use javascript" option. */ |
| 195 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 196 | 'name' => 'javascript_setting', |
| 197 | 'caption' => _("Use Javascript"), |
| 198 | 'type' => SMOPT_TYPE_STRLIST, |
| 199 | 'refresh' => SMOPT_REFRESH_ALL, |
| 200 | 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"), |
| 201 | SMPREF_JS_ON => _("Always"), |
| 202 | SMPREF_JS_OFF => _("Never")), |
| 203 | 'save' => 'save_option_javascript_autodetect', |
| 204 | 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"' |
| 205 | ); |
| 206 | |
| 207 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 208 | 'name' => 'js_autodetect_results', |
| 209 | 'caption' => '', |
| 210 | 'type' => SMOPT_TYPE_HIDDEN, |
| 211 | 'refresh' => SMOPT_REFRESH_NONE |
| 212 | //'post_script' => $js_autodetect_script, |
| 213 | ); |
| 214 | |
| 215 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 216 | 'name' => 'hour_format', |
| 217 | 'caption' => _("Hour Format"), |
| 218 | 'type' => SMOPT_TYPE_STRLIST, |
| 219 | 'refresh' => SMOPT_REFRESH_FOLDERLIST, |
| 220 | 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"), |
| 221 | SMPREF_TIME_24HR => _("24-hour clock")) |
| 222 | ); |
| 223 | |
| 224 | /* Icon theme selection */ |
| 225 | if ($use_icons) { |
| 226 | global $icon_themes, $icon_theme; |
| 227 | |
| 228 | $temp = array(); |
| 229 | for ($count = 0; $count < sizeof($icon_themes); $count++) { |
| 230 | $temp[$count] = $icon_themes[$count]['NAME']; |
| 231 | if ($icon_theme == $icon_themes[$count]['PATH'] || |
| 232 | (($icon_theme == $sTplDir.'images/') && ($icon_themes[$count]['PATH']=='template')) |
| 233 | ) { |
| 234 | $value = $count; |
| 235 | } |
| 236 | } |
| 237 | if (sizeof($icon_themes) > 0) { |
| 238 | $optvals[SMOPT_GRP_GENERAL][] = array( |
| 239 | 'name' => 'icon_theme', |
| 240 | 'caption' => _("Icon Theme"), |
| 241 | 'type' => SMOPT_TYPE_STRLIST, |
| 242 | 'refresh' => SMOPT_REFRESH_NONE, |
| 243 | 'posvals' => $temp, |
| 244 | 'initial_value' => $value, |
| 245 | 'save' => 'icon_theme_save' |
| 246 | ); |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | |
| 251 | /*** Load the General Options into the array ***/ |
| 252 | $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options"); |
| 253 | $optvals[SMOPT_GRP_MAILBOX] = array(); |
| 254 | |
| 255 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 256 | 'name' => 'show_num', |
| 257 | 'caption' => _("Number of Messages per Page"), |
| 258 | 'type' => SMOPT_TYPE_INTEGER, |
| 259 | 'refresh' => SMOPT_REFRESH_NONE, |
| 260 | 'size' => SMOPT_SIZE_TINY |
| 261 | ); |
| 262 | |
| 263 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 264 | 'name' => 'alt_index_colors', |
| 265 | 'caption' => _("Enable Alternating Row Colors"), |
| 266 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 267 | 'refresh' => SMOPT_REFRESH_NONE |
| 268 | ); |
| 269 | |
| 270 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 271 | 'name' => 'fancy_index_highlite', |
| 272 | 'caption' => _("Enable Fancy Row Mouseover Highlighting"), |
| 273 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 274 | 'refresh' => SMOPT_REFRESH_NONE |
| 275 | ); |
| 276 | |
| 277 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 278 | 'name' => 'show_flag_buttons', |
| 279 | 'caption' => _("Show Flag / Unflag Buttons"), |
| 280 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 281 | 'refresh' => SMOPT_REFRESH_NONE |
| 282 | ); |
| 283 | |
| 284 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 285 | 'name' => 'page_selector', |
| 286 | 'caption' => _("Enable Page Selector"), |
| 287 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 288 | 'refresh' => SMOPT_REFRESH_NONE |
| 289 | ); |
| 290 | |
| 291 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 292 | 'name' => 'compact_paginator', |
| 293 | 'caption' => _("Use Compact Page Selector"), |
| 294 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 295 | 'refresh' => SMOPT_REFRESH_NONE |
| 296 | ); |
| 297 | |
| 298 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 299 | 'name' => 'page_selector_max', |
| 300 | 'caption' => _("Maximum Number of Pages to Show"), |
| 301 | 'type' => SMOPT_TYPE_INTEGER, |
| 302 | 'refresh' => SMOPT_REFRESH_NONE, |
| 303 | 'size' => SMOPT_SIZE_TINY |
| 304 | ); |
| 305 | |
| 306 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 307 | 'name' => 'show_full_date', |
| 308 | 'caption' => _("Always Show Full Date"), |
| 309 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 310 | 'refresh' => SMOPT_REFRESH_NONE |
| 311 | ); |
| 312 | |
| 313 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 314 | 'name' => 'truncate_sender', |
| 315 | 'caption' => _("Length of From/To Field (0 for full)"), |
| 316 | 'type' => SMOPT_TYPE_INTEGER, |
| 317 | 'refresh' => SMOPT_REFRESH_NONE, |
| 318 | 'size' => SMOPT_SIZE_TINY |
| 319 | ); |
| 320 | |
| 321 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 322 | 'name' => 'truncate_subject', |
| 323 | 'caption' => _("Length of Subject Field (0 for full)"), |
| 324 | 'type' => SMOPT_TYPE_INTEGER, |
| 325 | 'refresh' => SMOPT_REFRESH_NONE, |
| 326 | 'size' => SMOPT_SIZE_TINY |
| 327 | ); |
| 328 | /* |
| 329 | disabled because the template doesn't support it (yet?) |
| 330 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 331 | 'name' => 'show_recipient_instead', |
| 332 | 'caption' => _("Show recipient name if the message is from your default identity"), |
| 333 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 334 | 'refresh' => SMOPT_REFRESH_NONE, |
| 335 | 'size' => SMOPT_SIZE_TINY |
| 336 | ); |
| 337 | */ |
| 338 | |
| 339 | if ($allow_thread_sort == TRUE) { |
| 340 | $optvals[SMOPT_GRP_MAILBOX][] = array( |
| 341 | 'name' => 'sort_by_ref', |
| 342 | 'caption' => _("Enable Thread Sort by References Header"), |
| 343 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 344 | 'refresh' => SMOPT_REFRESH_ALL |
| 345 | ); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | |
| 350 | /*** Load the General Options into the array ***/ |
| 351 | $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options"); |
| 352 | $optvals[SMOPT_GRP_MESSAGE] = array(); |
| 353 | |
| 354 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 355 | 'name' => 'wrap_at', |
| 356 | 'caption' => _("Wrap Incoming Text At"), |
| 357 | 'type' => SMOPT_TYPE_INTEGER, |
| 358 | 'refresh' => SMOPT_REFRESH_NONE, |
| 359 | 'size' => SMOPT_SIZE_TINY |
| 360 | ); |
| 361 | |
| 362 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 363 | 'name' => 'show_html_default', |
| 364 | 'caption' => _("Show HTML Version by Default"), |
| 365 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 366 | 'refresh' => SMOPT_REFRESH_NONE |
| 367 | ); |
| 368 | |
| 369 | if ($use_iframe) { |
| 370 | // Type is set to string in order to be able to use 100%. |
| 371 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 372 | 'name' => 'iframe_height', |
| 373 | 'caption' => _("Height of inline frame"), |
| 374 | 'type' => SMOPT_TYPE_STRING, |
| 375 | 'size' => SMOPT_SIZE_TINY, |
| 376 | 'refresh' => SMOPT_REFRESH_NONE |
| 377 | ); |
| 378 | } |
| 379 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 380 | 'name' => 'enable_forward_as_attachment', |
| 381 | 'caption' => _("Enable Forward as Attachment"), |
| 382 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 383 | 'refresh' => SMOPT_REFRESH_NONE |
| 384 | ); |
| 385 | |
| 386 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 387 | 'name' => 'show_xmailer_default', |
| 388 | 'caption' => _("Enable Mailer Display"), |
| 389 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 390 | 'refresh' => SMOPT_REFRESH_NONE |
| 391 | ); |
| 392 | |
| 393 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 394 | 'name' => 'attachment_common_show_images', |
| 395 | 'caption' => _("Display Attached Images with Message"), |
| 396 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 397 | 'refresh' => SMOPT_REFRESH_NONE |
| 398 | ); |
| 399 | |
| 400 | if ($default_use_mdn) { |
| 401 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 402 | 'name' => 'mdn_user_support', |
| 403 | 'caption' => _("Enable Mail Delivery Notification"), |
| 404 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 405 | 'refresh' => SMOPT_REFRESH_NONE |
| 406 | ); |
| 407 | } |
| 408 | |
| 409 | $optvals[SMOPT_GRP_MESSAGE][] = array( |
| 410 | 'name' => 'delete_prev_next_display', |
| 411 | 'caption' => _("Show 'Delete & Prev/Next' Links"), |
| 412 | 'type' => SMOPT_TYPE_BOOLEAN, |
| 413 | 'refresh' => SMOPT_REFRESH_ALL |
| 414 | ); |
| 415 | |
| 416 | /* Assemble all this together and return it as our result. */ |
| 417 | $result = array( |
| 418 | 'grps' => $optgrps, |
| 419 | 'vals' => $optvals |
| 420 | ); |
| 421 | return ($result); |
| 422 | } |
| 423 | |
| 424 | /******************************************************************/ |
| 425 | /** Define any specialized save functions for this option page. ***/ |
| 426 | /******************************************************************/ |
| 427 | |
| 428 | /** |
| 429 | * This function saves a new template setting. |
| 430 | * It updates the template array. |
| 431 | */ |
| 432 | function save_option_template($option) { |
| 433 | global $aTemplateSet; |
| 434 | |
| 435 | /* Do checking to make sure $new_theme is in the array. */ |
| 436 | $templateset_in_array = false; |
| 437 | for ($i = 0; $i < count($aTemplateSet); ++$i) { |
| 438 | if ($aTemplateSet[$i]['PATH'] == $option->new_value) { |
| 439 | $templateset_in_array = true; |
| 440 | break; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (!$templateset_in_array) { |
| 445 | $option->new_value = ''; |
| 446 | } |
| 447 | /* Save the option like normal. */ |
| 448 | save_option($option); |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * This function saves a new theme setting. |
| 453 | * It updates the theme array. |
| 454 | */ |
| 455 | function save_option_theme($option) { |
| 456 | global $theme; |
| 457 | |
| 458 | /* Do checking to make sure $new_theme is in the array. */ |
| 459 | $theme_in_array = false; |
| 460 | for ($i = 0; $i < count($theme); ++$i) { |
| 461 | if ($theme[$i]['PATH'] == $option->new_value) { |
| 462 | $theme_in_array = true; |
| 463 | break; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | if (!$theme_in_array) { |
| 468 | $option->new_value = ''; |
| 469 | } |
| 470 | |
| 471 | /* Save the option like normal. */ |
| 472 | save_option($option); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * This function saves the javascript detection option. |
| 477 | */ |
| 478 | function save_option_javascript_autodetect($option) { |
| 479 | save_option($option); |
| 480 | checkForJavascript(TRUE); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * This function saves the user's icon theme setting |
| 485 | */ |
| 486 | function icon_theme_save($option) { |
| 487 | |
| 488 | global $icon_themes, $data_dir, $username; |
| 489 | |
| 490 | |
| 491 | // Don't assume the new value is there, double check |
| 492 | // and only save if found |
| 493 | // |
| 494 | if (isset($icon_themes[$option->new_value]['PATH'])) |
| 495 | setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']); |
| 496 | else |
| 497 | setPref($data_dir, $username, 'icon_theme', 'none'); |
| 498 | |
| 499 | } |
| 500 | |
| 501 | ?> |