Fixed bug #496334
[squirrelmail.git] / src / options_display.php
index f0aede33a7e19e36e770bfae55234b2f400b2a59..784b3487dfb41c2ca841eedf18596e47ce87e78d 100644 (file)
@@ -1,60 +1,62 @@
 <?php
-   /**
-    **  options_display.php
-    **
-    **  Copyright (c) 1999-2000 The SquirrelMail development team
-    **  Licensed under the GNU GPL. For full terms see the file COPYING.
-    **
-    **  Displays all optinos about display preferences
-    **
-    **  $Id$
-    **/
-
-   require_once('../src/validate.php');
-   require_once('../functions/display_messages.php');
-   require_once('../functions/imap.php');
-   require_once('../functions/array.php');
-   require_once('../functions/plugin.php');
-   require_once('../functions/options.php');
-
-   displayPageHeader($color, 'None');
-   $language = getPref($data_dir, $username, 'language');
-?>
-   <br>
-<table width="95%" align="center" border="0" cellpadding="2" cellspacing="0">
-<tr><td bgcolor="<?php echo $color[0] ?>" align="center">
 
-   <b><?php echo _("Options") . ' - ' . _("Display Preferences"); ?></b><br>
+/**
+ * options_display.php
+ *
+ * Copyright (c) 1999-2002 The SquirrelMail Project Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * Displays all optinos about display preferences
+ *
+ * $Id$
+ */
+
+/* Define the group constants for the display options page. */
+define('SMOPT_GRP_GENERAL', 0);
+define('SMOPT_GRP_MAILBOX', 1);
+define('SMOPT_GRP_MESSAGE', 2);
+
+/* Define the optpage load function for the display options page. */
+function load_optpage_data_display() {
+    global $theme, $languages, $js_autodetect_results;
 
-   <table width="100%" border="0" cellpadding="1" cellspacing="1">
-   <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
+    /* Build a simple array into which we will build options. */
+    $optgrps = array();
+    $optvals = array();
 
-   <form name="f" action="options.php" method="post"><br>
-      <table width="100%" cellpadding="2" cellspacing="0" border="0">
-<?php
+    /******************************************************/
+    /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
+    /******************************************************/
 
-    /* Build a simple array into which we will build options. */
-    $optvals = array(); 
+    /*** Load the General Options into the array ***/
+    $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
+    $optvals[SMOPT_GRP_GENERAL] = array();
 
+    /* Load the theme option. */
     $theme_values = array();
     foreach ($theme as $theme_key => $theme_attributes) {
-        $theme_values[$theme_attributes['PATH']] = $theme_attributes['NAME'];
+        $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
     }
-    $optvals[] = array(
+    ksort($theme_values);
+    $theme_values = array_flip($theme_values);
+    $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'chosen_theme',
         'caption' => _("Theme"),
         'type'    => SMOPT_TYPE_STRLIST,
         'refresh' => SMOPT_REFRESH_ALL,
-        'posvals' => $theme_values
+        'posvals' => $theme_values,
+        'save'    => 'save_option_theme'
     );
 
     $language_values = array();
     foreach ($languages as $lang_key => $lang_attributes) {
         if (isset($lang_attributes['NAME'])) {
-            $language_values[$lang_key] = $lang_attributes['NAME'];
+            $language_values[$lang_attributes['NAME']] = $lang_key;
         }
     }
-    $optvals[] = array(
+    asort($language_values);
+    $language_values = array_flip($language_values);
+    $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'language',
         'caption' => _("Language"),
         'type'    => SMOPT_TYPE_STRLIST,
         'posvals' => $language_values
     );
 
-    $optvals[] = array(
-        'name'    => 'use_javascript_addr_book',
-        'caption' => _("Addressbook Display Format"),
-        'type'    => SMOPT_TYPE_STRLIST,
-        'refresh' => SMOPT_REFRESH_NONE,
-        'posvals' => array('1' => _("Javascript"),
-                           '0' => _("HTML"))
-    );
-
     /* Set values for the "use javascript" option. */
-    $optvals[] = array(
+    $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'javascript_setting',
         'caption' => _("Use Javascript"),
         'type'    => SMOPT_TYPE_STRLIST,
                            SMPREF_JS_OFF        => _("Never"))
     );
 
+    $js_autodetect_script =
+        "<SCRIPT LANGUAGE=\"JavaScript\"><!--\n".
+           "document.forms[0].new_js_autodetect_results.value = '" . SMPREF_JS_ON . "';\n".
+        "// --></SCRIPT>\n";
     $js_autodetect_results = SMPREF_JS_OFF;
-    $optvals[] = array(
+    $optvals[SMOPT_GRP_GENERAL][] = array(
         'name'    => 'js_autodetect_results',
         'caption' => '',
         'type'    => SMOPT_TYPE_HIDDEN,
-        'refresh' => SMOPT_REFRESH_NONE
+        'refresh' => SMOPT_REFRESH_NONE,
+        'script'  => $js_autodetect_script,
+        'save'    => 'save_option_javascript_autodetect'
     );
 
-    $optvals[] = array(
+    /*** Load the General Options into the array ***/
+    $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
+    $optvals[SMOPT_GRP_MAILBOX] = array();
+
+    $optvals[SMOPT_GRP_MAILBOX][] = array(
         'name'    => 'show_num',
         'caption' => _("Number of Messages to Index"),
         'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'size'    => SMOPT_SIZE_TINY
+    );
+
+    $optvals[SMOPT_GRP_MAILBOX][] = array(
+        'name'    => 'alt_index_colors',
+        'caption' => _("Enable Alternating Row Colors"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[SMOPT_GRP_MAILBOX][] = array(
+        'name'    => 'page_selector',
+        'caption' => _("Enable Page Selector"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
         'refresh' => SMOPT_REFRESH_NONE
     );
 
-    $optvals[] = array(
+    $optvals[SMOPT_GRP_MAILBOX][] = array(
+        'name'    => 'page_selector_max',
+        'caption' => _("Maximum Number of Pages to Show"),
+        'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'size'    => SMOPT_SIZE_TINY
+    );
+
+    /*** Load the General Options into the array ***/
+    $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display and Composition");
+    $optvals[SMOPT_GRP_MESSAGE] = array();
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
         'name'    => 'wrap_at',
         'caption' => _("Wrap Incoming Text At"),
         'type'    => SMOPT_TYPE_INTEGER,
-        'refresh' => SMOPT_REFRESH_NONE
+        'refresh' => SMOPT_REFRESH_NONE,
+        'size'    => SMOPT_SIZE_TINY
     );
 
-    $optvals[] = array(
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
         'name'    => 'editor_size',
         'caption' => _("Size of Editor Window"),
         'type'    => SMOPT_TYPE_INTEGER,
-        'refresh' => SMOPT_REFRESH_NONE
+        'refresh' => SMOPT_REFRESH_NONE,
+        'size'    => SMOPT_SIZE_TINY
     );
 
-    $optvals[] = array(
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
         'name'    => 'location_of_buttons',
         'caption' => _("Location of Buttons when Composing"),
         'type'    => SMOPT_TYPE_STRLIST,
                            SMPREF_LOC_BOTTOM  => _("After message body"))
     );
 
-    $optvals[] = array(
-        'name'    => 'location_of_bar',
-        'caption' => _("Location of Folder List"),
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'use_javascript_addr_book',
+        'caption' => _("Addressbook Display Format"),
         'type'    => SMOPT_TYPE_STRLIST,
-        'refresh' => SMOPT_REFRESH_ALL,
-        'posvals' => array(SMPREF_LOC_LEFT  => _("Left"),
-                           SMPREF_LOC_RIGHT => _("Right"))
+        'refresh' => SMOPT_REFRESH_NONE,
+        'posvals' => array('1' => _("Javascript"),
+                           '0' => _("HTML"))
     );
 
-    $left_size_values = array();
-    for ($lsv = 100; $lsv <= 300; $lsv += 10) {
-        $left_size_values[$lsv] = "$lsv " . _("pixels");
-    }
-    $optvals[] = array(
-        'name'    => 'left_size',
-        'caption' => _("Width of Folder List"),
-        'type'    => SMOPT_TYPE_STRLIST,
-        'refresh' => SMOPT_REFRESH_ALL,
-        'posvals' => $left_size_values
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'show_html_default',
+        'caption' => _("Show HTML Version by Default"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
     );
 
-    $minute_str = _("Minutes");
-    $left_refresh_values = array(SMPREF_NONE => _("Never"));
-    foreach (array(30,60,120,180,300,600) as $lr_val) {
-        if ($lr_val < 60) {
-            $left_refresh_values[$lr_val] = "$lr_val " . _("Seconds");
-        } else if ($lr_val == 60) {
-            $left_refresh_values[$lr_val] = "1 " . _("Minute");
-        } else {
-            $left_refresh_values[$lr_val] = ($lr_val/60) . " $minute_str";
-        }
-    }
-    $optvals[] = array(
-        'name'    => 'left_refresh',
-        'caption' => _("Auto Refresh Folder List"),
-        'type'    => SMOPT_TYPE_STRLIST,
-        'refresh' => SMOPT_REFRESH_FOLDERLIST,
-        'posvals' => $left_refresh_values
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'include_self_reply_all',
+        'caption' => _("Include Me in CC when I Reply All"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
     );
 
-    /* Build all these values into an array of SquirrelOptions objects. */
-    $options = createOptionArray($optvals);
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'show_xmailer_default',
+        'caption' => _("Enable Mailer Display"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
 
-    /* Print the row for each option. */
-    foreach ($options as $option) {
-        if ($option->type != SMOPT_TYPE_HIDDEN) {
-            echo "<TR>\n";
-            echo '  <TD ALIGN="RIGHT" VALIGN="MIDDLE" NOWRAP><font color=red><b>'
-               . $option->caption . "</b></font>:</TD>\n";
-            echo '  <TD>' . $option->createHTMLWidget() . "</TD>\n";
-            echo "</TR>\n";
-        } else {
-            echo $option->createHTMLWidget();
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'attachment_common_show_images',
+        'caption' => _("Display Attached Images with Message"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'pf_subtle_link',
+        'caption' => _("Enable Subtle Printer Friendly Link"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'pf_cleandisplay',
+        'caption' => _("Enable Printer Friendly Clean Display"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    /* Assemble all this together and return it as our result. */
+    $result = array(
+        'grps' => $optgrps,
+        'vals' => $optvals
+    );
+    return ($result);
+}
+
+/******************************************************************/
+/** Define any specialized save functions for this option page. ***/
+/******************************************************************/
+
+function save_option_theme($option) {
+    global $theme;
+
+    /* Do checking to make sure $new_theme is in the array. */
+    $theme_in_array = false;
+    for ($i = 0; $i < count($theme); ++$i) {
+        if ($theme[$i]['PATH'] == $option->new_value) {
+            $theme_in_array = true;
+            break;
         }
     }
 
-    /*** NOT YET CONVERTED TO OPTION OBJECTS ***/
-
-   OptionRadio( _("Use alternating row colors?"),
-                'altIndexColors',
-                array( 1 => _("Yes"),
-                       0 => _("No") ),
-                $alt_index_colors );
-   OptionCheck( _("Show HTML version by default"),
-                'showhtmldefault',
-                $show_html_default,
-                _("Yes, show me the HTML version of a mail message, if it is available.") );
-   OptionCheck( _("Include Self"),
-                'includeselfreplyall',
-                getPref($data_dir, $username, 'include_self_reply_all', FALSE ),
-                _("Don't remove me from the CC addresses when I use \"Reply All\"") );
-   $psw = getPref($data_dir, $username, 'page_selector_max', 10 );
-   OptionCheck( _("Page Selector"),
-                'pageselector',
-                !getPref($data_dir, $username, 'page_selector', FALSE ),
-                _("Show page selector") .
-                " <input name=pageselectormax size=3  value=\"$psw\"> &nbsp;" .
-                _("pages max") );
-
-   echo '<tr><td colspan=2><hr noshade></td></tr>';
-   do_hook('options_display_inside');
-   OptionSubmit( 'submit_display' );
-?>
-
-      </table>
-   </form>
+    if (!$theme_in_array) {
+        $option->new_value = '';
+    }
 
-   <?php do_hook('options_display_bottom'); ?>
+    /* Save the option like normal. */
+    save_option($option);
+}
 
-    </td></tr>
-    </table>
+function save_option_javascript_autodetect($option) {
+    global $data_dir, $username, $new_javascript_setting;
 
-<SCRIPT LANGUAGE="JavaScript"><!--
-  document.forms[0].new_js_autodetect_results.value = '<?php echo SMPREF_JS_ON; ?>';
-// --></SCRIPT>
+    /* Set javascript either on or off. */
+    if ($new_javascript_setting == SMPREF_JS_AUTODETECT) {
+        if ($option->new_value == SMPREF_JS_ON) {
+            setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
+        } else {
+            setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF);
+        }
+    } else {
+        setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
+    }
+}
 
-</td></tr>
-</table>
-</body></html>
+?>