Fixed bug #496334
[squirrelmail.git] / src / options_display.php
index 5c862157a3717c1386f196bf604e0cd03d2ecc84..784b3487dfb41c2ca841eedf18596e47ce87e78d 100644 (file)
 <?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$
-    **/
-
-   include('../src/validate.php');
-   include('../functions/display_messages.php');
-   include('../functions/imap.php');
-   include('../functions/array.php');
-   include('../functions/plugin.php');
-   
-   displayPageHeader($color, 'None');
-   $chosen_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$
+ */
 
-   <table width="100%" border="0" cellpadding="1" cellspacing="1">
-   <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
+/* Define the group constants for the display options page. */
+define('SMOPT_GRP_GENERAL', 0);
+define('SMOPT_GRP_MAILBOX', 1);
+define('SMOPT_GRP_MESSAGE', 2);
 
-   <form name="f" action="options.php" method="post"><br>
-      <table width="100%" cellpadding="2" cellspacing="0" border="0">
-         <tr>
-            <td align="right" nowrap><?php echo _("Theme"); ?>:
-            </td><td>
-<?php
-   echo '         <tt><select name="chosentheme">' . "\n";
-   for ($i = 0; $i < count($theme); $i++) {
-      if ($theme[$i]['PATH'] == $chosen_theme)
-         echo '         <option selected value="'.$theme[$i]['PATH'].'">'.$theme[$i]['NAME']."\n";
-      else
-         echo '         <option value="'.$theme[$i]['PATH'].'">'.$theme[$i]['NAME']."\n";
-   }
-   echo '         </select></tt>';  
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?php echo _("Language"); ?>:
-            </td><td>
-<?php
-   echo '         <tt><select name="language">' . "\n";
-   foreach ($languages as $code => $name) {
-      if (! isset($name['ALIAS'])) {
-         if ($code==$chosen_language)
-            echo '         <OPTION SELECTED VALUE="'.$code.'">'.$name['NAME']."\n";
-         else
-            echo '         <OPTION VALUE="'.$code.'">'.$name['NAME']."\n";
-      }
-   }
-   echo '         </select></tt>';  
-   if (! $use_gettext)
-      echo '<br><small>This system doesn\'t support multiple languages</small>';
-      
-?>
-            </td>
-         <tr>
-            <td align=right nowrap>&nbsp;
-               <?php echo _("Use Javascript or HTML addressbook?") . '</td><td>'; 
-               if ($use_javascript_addr_book == true) {
-                  echo '         <input type="radio" name="javascript_abook" value="1" checked> ' . _("JavaScript") . '&nbsp;&nbsp;&nbsp;&nbsp;';
-                  echo '         <input type="radio" name="javascript_abook" value="0"> ' . _("HTML"); 
-               } else {
-                  echo '         <input type="radio" name="javascript_abook" value="1"> ' . _("JavaScript") . '&nbsp;&nbsp;&nbsp;&nbsp;';
-                  echo '         <input type="radio" name="javascript_abook" value="0" checked> ' . _("HTML"); 
-               }  
-               ?>
-            </td>
-         </tr>
-         <tr>
-            <td align=right nowrap><?php echo _("Number of Messages to Index"); ?>:
-            </td><td>
-<?php
-   if (isset($show_num))
-      echo '         <tt><input type="text" size="5" name="shownum" value="'.$show_num.'"></tt><br>';
-   else
-      echo '         <tt><input type="text" size="5" name="shownum" value="25"></tt><br>'; 
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?php echo _("Wrap incoming text at"); ?>:
-            </td><td>
-<?php
-   if (isset($wrap_at))
-      echo '         <tt><input type="text" size="5" name="wrapat" value="'.$wrap_at.'"></tt><br>';
-   else
-      echo '         <tt><input type="tex" size="5" name="wrapat" value="86"></tt><br>'; 
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?php echo _("Size of editor window"); ?>:
-            </td><td>
-<?php
-   if ($editor_size >= 10 && $editor_size <= 255)
-      echo '         <tt><input type="text" size="5" name="editorsize" value="'.$editor_size.'"></tt><br>';
-   else
-      echo '         <tt><input type="text" size="5" name="editorsize" value="76"></tt><br>'; 
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?PHP echo _("Reply Citation Style") ?>:</td>
-            <td><select name="new_reply_citation_style">
-                <option value="none"<?PHP
-                    if ($reply_citation_style == 'none') echo ' SELECTED';
-                    ?>>- <?PHP echo _("Not Used"); ?> -</option>
-                <option value="author_said"<?PHP
-                    if ($reply_citation_style == 'author_said') echo ' SELECTED';
-                    ?>><?PHP echo _("AUTHOR Said"); ?></option>
-                <option value="quote_who"<?PHP
-                    if ($reply_citation_style == 'quote_who') echo ' SELECTED';
-                    ?>><?PHP echo _("Quote Who XML"); ?></option>
-                <option value="user-defined"<?PHP
-                    if ($reply_citation_style == 'user-defined') echo ' SELECTED';
-                    ?>><?PHP echo _("User-Defined"); ?></option>
-                </select>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?php echo _("User-Defined Reply Citation"); ?>:</td>
-            <td>
-               <tt><input type="text" size="15" name="new_reply_citation_start" value="<?php
-                  echo $reply_citation_start;
-               ?>"></tt> &lt;<?PHP echo _("Author's Name"); ?>&gt;
-               <tt><input type="text" size="15" name="new_reply_citation_end" value="<?php
-                  echo $reply_citation_end;
-               ?>"></tt>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?PHP echo _("Location of buttons when composing") ?>:</td>
-            <td><select name="button_new_location">
-                <option value="top"<?PHP
-                    if ($location_of_buttons == 'top') echo ' SELECTED';
-                    ?>><?PHP echo _("Before headers"); ?></option>
-                <option value="between"<?PHP
-                    if ($location_of_buttons == 'between') echo ' SELECTED';
-                    ?>><?PHP echo _("Between headers and message body"); ?></option>
-                <option value="bottom"<?PHP
-                    if ($location_of_buttons == 'bottom') echo ' SELECTED';
-                    ?>><?PHP echo _("After message body"); ?></option>
-                </select>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?PHP echo _("Location of folder list") ?>:</td>
-            <td><select name="folder_new_location">
-                <option value="left"<?PHP
-                    if ($location_of_bar != 'right') echo ' SELECTED';
-                    ?>><?PHP echo _("Left"); ?></option>
-                <option value="right"<?PHP
-                    if ($location_of_bar == 'right') echo ' SELECTED';
-                    ?>><?PHP echo _("Right"); ?></option>
-                </select>
-            </td>
-         </tr>
-         <tr>
-            <td align=right nowrap><?php echo _("Width of folder list"); ?>:
-            </td><td>
-<?php
-   echo '         <select name="leftsize">' . "\n";
-   for ($i = 100; $i <= 300; $i += 10)
-   {
-       if ($left_size >= $i && $left_size < $i + 10)
-          echo "<option value=\"$i\" selected>$i pixels\n";
-       else
-          echo "<option value=\"$i\">$i pixels\n";
-   }
-   echo '         </select>';  
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right" nowrap><?php echo _("Auto refresh folder list"); ?>:
-            </td><td>
-<?php
-   $seconds_str = _("Seconds");
-   $none_str = _("None");
-   $minute_str = _("Minute");
-   $minutes_str = _("Minutes");
-
-   echo '               <SELECT name="leftrefresh">';
-   
-   if ($left_refresh == '')
-      $left_refresh = 'None';
-   if ($left_refresh > 600)
-      $left_refresh = 600;
-   RefreshOption($left_refresh, '', 'None', _("None"));
-   RefreshOption($left_refresh, 30);
-   RefreshOption($left_refresh, 60);
-   RefreshOption($left_refresh, 120);
-   RefreshOption($left_refresh, 180);
-   RefreshOption($left_refresh, 300);
-   RefreshOption($left_refresh, 600);
-   // Refreshes after the session auto-timeout (default 15 min) is pointless
-
-function RefreshOption(&$current, $val, $str = '') {
-   static $lastVal = 0;
-   
-   if (is_int($val) && is_int($current)) {
-      if ($current > $lastVal && $current <= $val)
-         $current = $val;
-   }
-   
-   if ($str == '') {
-      if ($val > 60) {
-         $str = ($val / 60) . ' ' . _("Minutes");
-      } elseif ($val == 60) {
-         $str = '1 ' . _("Minute");
-      } else {
-         $str = $val . ' ' . _("Seconds");
-      }
-   }
-   
-   echo '<option value="' . $val . '"';
-   if ($val == $current)
-      echo ' SELECTED';
-   echo '>' . $str . "\n";
+/* Define the optpage load function for the display options page. */
+function load_optpage_data_display() {
+    global $theme, $languages, $js_autodetect_results;
+
+    /* Build a simple array into which we will build options. */
+    $optgrps = array();
+    $optvals = array();
+
+    /******************************************************/
+    /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS 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['NAME']] = $theme_attributes['PATH'];
+    }
+    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,
+        'save'    => 'save_option_theme'
+    );
+
+    $language_values = array();
+    foreach ($languages as $lang_key => $lang_attributes) {
+        if (isset($lang_attributes['NAME'])) {
+            $language_values[$lang_attributes['NAME']] = $lang_key;
+        }
+    }
+    asort($language_values);
+    $language_values = array_flip($language_values);
+    $optvals[SMOPT_GRP_GENERAL][] = array(
+        'name'    => 'language',
+        'caption' => _("Language"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_ALL,
+        'posvals' => $language_values
+    );
+
+    /* Set values for the "use javascript" option. */
+    $optvals[SMOPT_GRP_GENERAL][] = array(
+        'name'    => 'javascript_setting',
+        'caption' => _("Use Javascript"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_ALL,
+        'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
+                           SMPREF_JS_ON         => _("Always"),
+                           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[SMOPT_GRP_GENERAL][] = array(
+        'name'    => 'js_autodetect_results',
+        'caption' => '',
+        'type'    => SMOPT_TYPE_HIDDEN,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'script'  => $js_autodetect_script,
+        'save'    => 'save_option_javascript_autodetect'
+    );
+
+    /*** 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[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,
+        'size'    => SMOPT_SIZE_TINY
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'editor_size',
+        'caption' => _("Size of Editor Window"),
+        'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'size'    => SMOPT_SIZE_TINY
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'location_of_buttons',
+        'caption' => _("Location of Buttons when Composing"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'posvals' => array(SMPREF_LOC_TOP     => _("Before headers"),
+                           SMPREF_LOC_BETWEEN => _("Between headers and message body"),
+                           SMPREF_LOC_BOTTOM  => _("After message body"))
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'use_javascript_addr_book',
+        'caption' => _("Addressbook Display Format"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_NONE,
+        'posvals' => array('1' => _("Javascript"),
+                           '0' => _("HTML"))
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'show_html_default',
+        'caption' => _("Show HTML Version by Default"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $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
+    );
+
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'show_xmailer_default',
+        'caption' => _("Enable Mailer Display"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $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);
 }
-      echo '               </SELECT>'; 
-?>
-            </td>
-         </tr>
-         <tr>
-            <td align="right">
-                <?php echo _("Use alternating row colors?") ?>
-            </td><td>
-<?php
-    if (isset($alt_index_colors) && $alt_index_colors == 1) {
-        $a = " checked";
-        $b = "";
+
+/******************************************************************/
+/** 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;
+        }
+    }
+
+    if (!$theme_in_array) {
+        $option->new_value = '';
+    }
+
+    /* Save the option like normal. */
+    save_option($option);
+}
+
+function save_option_javascript_autodetect($option) {
+    global $data_dir, $username, $new_javascript_setting;
+
+    /* 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 {
-        $a = "";
-        $b = " checked";
+        setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
     }
+}
+
 ?>
-                <input type="radio" name="altIndexColors" value="1"<?php echo $a ?>> <?php echo _("Yes") ?> &nbsp;&nbsp; 
-                <input type="radio" name="altIndexColors" value="0"<?php echo $b ?>> <?php echo _("No") ?><br>
-            </td>
-         </tr>
-         <tr>
-            <td align=right>
-               <?php echo _("Show HTML version by default"); ?>:
-            </td>
-            <td>
-               <input type=checkbox name=showhtmldefault <?php 
-              if (isset($show_html_default) && $show_html_default) 
-              echo " checked"; ?>>
-                <?php 
-echo _("Yes, show me the HTML version of a mail message, if it is available."); 
-                 ?>
-            </td>
-         </tr>
-         <tr>
-            <td align=right>
-               <?php echo _("Include Self"); ?>:
-            </td>
-            <td>
-               <input type=checkbox name=includeselfreplyall <?php 
-              if (getPref($data_dir, $username, 'include_self_reply_all')
-                  != '')
-              echo " checked"; ?>>
-                <?php 
-echo _("Don't remove me from the CC addresses when I use \"Reply All\"");
-                 ?>
-            </td>
-         </tr>
-         <?php do_hook('options_display_inside'); ?>
-         <tr>
-            <td>&nbsp;
-            </td><td>
-               <input type="submit" value="<?php echo _("Submit"); ?>"name="submit_display">
-            </td>
-         </tr>
-      </table>
-   </form>
-
-   <?php do_hook('options_display_bottom'); ?>
-
-    </td></tr>
-    </table>
-
-</td></tr>
-</table>
-</body></html>