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