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