Getting ready for 1.2.0 release.
[squirrelmail.git] / src / options_display.php
index edaaf3c4ea123e33cdd26ab7b8dca75d2910de48..75184af5c7a4706eadce28ec835832fcd46ee068 100644 (file)
@@ -1,37 +1,24 @@
 <?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>
 
-   <table width="100%" border="0" cellpadding="1" cellspacing="1">
-   <tr><td bgcolor="<?php echo $color[4] ?>" align="center">
-
-   <form name="f" action="options.php" method="post"><br>
-      <table width="100%" cellpadding="2" cellspacing="0" border="0">
-<?php
+/**
+ * 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;
 
     /* Build a simple array into which we will build options. */
     $optgrps = array();
@@ -40,9 +27,6 @@
     /******************************************************/
     /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
     /******************************************************/
-    define('SMOPT_GRP_GENERAL', 0);
-    define('SMOPT_GRP_MAILBOX', 1);
-    define('SMOPT_GRP_MESSAGE', 2);
 
     /*** Load the General Options into the array ***/
     $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
     /* 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'];
     }
+    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();
+    $language_values = array('');
     foreach ($languages as $lang_key => $lang_attributes) {
         if (isset($lang_attributes['NAME'])) {
             $language_values[$lang_key] = $lang_attributes['NAME'];
                            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
+        'refresh' => SMOPT_REFRESH_NONE,
+        'script'  => $js_autodetect_script,
+        'save'    => 'save_option_javascript_autodetect'
     );
 
     /*** Load the General Options into the array ***/
 
     $optvals[SMOPT_GRP_MESSAGE][] = array(
         'name'    => 'attachment_common_show_images',
-        'caption' => _("Enable display of images with email, below attachment box"),
+        'caption' => _("Display Attached Images with Message"),
         'type'    => SMOPT_TYPE_BOOLEAN,
         'refresh' => SMOPT_REFRESH_NONE
     );
 
-    /* Build and output the option groups. */
-    $option_groups = createOptionGroups($optgrps, $optvals);
-    printOptionGroups($option_groups);
-    
-    do_hook('options_display_inside');
-    echo "<TR><TD>&nbsp;</TD></TR>\n";
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'pf_subtle_link',
+        'caption' => _("Enable Subtle Printer Friendly Link"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
 
-    OptionSubmit( 'submit_display' );
-?>
+    $optvals[SMOPT_GRP_MESSAGE][] = array(
+        'name'    => 'pf_cleandisplay',
+        'caption' => _("Enable Printer Friendly Clean Display"),
+        'type'    => SMOPT_TYPE_BOOLEAN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
 
-      </table>
-   </form>
+    /* Assemble all this together and return it as our result. */
+    $result = array(
+        'grps' => $optgrps,
+        'vals' => $optvals
+    );
+    return ($result);
+}
 
-   <?php do_hook('options_display_bottom'); ?>
+/******************************************************************/
+/** Define any specialized save functions for this option page. ***/
+/******************************************************************/
 
-    </td></tr>
-    </table>
+function save_option_theme($option) {
+    global $theme;
 
-<SCRIPT LANGUAGE="JavaScript"><!--
-  document.forms[0].new_js_autodetect_results.value = '<?php echo SMPREF_JS_ON; ?>';
-// --></SCRIPT>
+    /* 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 = '';
+    }
 
-</td></tr>
-</table>
-</body></html>
+    /* 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 {
+        setPref($data_dir, $username, 'javascript_on', $new_javascript_setting);
+    }
+}
+
+?>