Please ignore the red for now :)
authorthomppj <thomppj@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 10 Nov 2001 22:03:15 +0000 (22:03 +0000)
committerthomppj <thomppj@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sat, 10 Nov 2001 22:03:15 +0000 (22:03 +0000)
git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1718 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/constants.php
functions/options.php
src/options.php
src/options_display.php

index fd98ff32d5fd8712dae2beb61fdab06777230999..50daeecf959855d9cc43678fdf341ba91a4b6c8e 100644 (file)
      * $Id$
      */
 
-    /******************************************************/
-    /* Set values for constants used in the options code. */
-    /******************************************************/
-
-    /* Define constants for the various option types. */
-    define('SMOPT_TYPE_STRING', 0);
-    define('SMOPT_TYPE_STRLIST', 1);
-    define('SMOPT_TYPE_TEXTAREA', 2);
-    define('SMOPT_TYPE_INTEGER', 3);
-    define('SMOPT_TYPE_FLOAT', 4);
-    define('SMOPT_TYPE_BOOLEAN', 5);
-
-    /* Define constants for the options refresh levels. */
-    define('SMOPT_REFRESH_NONE', 0);
-    define('SMOPT_REFRESH_FOLDERLIST', 1);
-    define('SMOPT_REFRESH_ALL', 2);
-
     /**************************************************************/
     /* Set values for constants used by Squirrelmail preferences. */
     /**************************************************************/
     define('SMPREF_JS_OFF', 2);
     define('SMPREF_JS_AUTODETECT', 3);
 
+    define('SMPREF_LOC_TOP', 'top');
+    define('SMPREF_LOC_BETWEEN', 'between');
+    define('SMPREF_LOC_BOTTOM', 'bottom');
+    define('SMPREF_LOC_LEFT', '');
+    define('SMPREF_LOC_RIGHT', 'right');
+
     do_hook("loading_constants");
 ?>
index 2f7d30365c12967a64f0f63a9bc2c7d8521fc13b..e5eeefffcb5f65bd37bce5867373bd82005e84ca 100644 (file)
@@ -9,6 +9,25 @@
      *
      * $Id$
      */
+
+/**********************************************/
+/* Define constants used in the options code. */
+/**********************************************/
+
+/* Define constants for the various option types. */
+define('SMOPT_TYPE_STRING', 0);
+define('SMOPT_TYPE_STRLIST', 1);
+define('SMOPT_TYPE_TEXTAREA', 2);
+define('SMOPT_TYPE_INTEGER', 3);
+define('SMOPT_TYPE_FLOAT', 4);
+define('SMOPT_TYPE_BOOLEAN', 5);
+define('SMOPT_TYPE_HIDDEN', 6);
+
+/* Define constants for the options refresh levels. */
+define('SMOPT_REFRESH_NONE', 0);
+define('SMOPT_REFRESH_FOLDERLIST', 1);
+define('SMOPT_REFRESH_ALL', 2);
+
 /**
  * SquirrelOption: An option for Squirrelmail.
  *
@@ -24,13 +43,13 @@ class SquirrelOption {
     /* The basic stuff. */
     var $name;
     var $caption;
-    var $refresh_level;
     var $type;
+    var $refresh_level;
 
     /* The various 'values' for this options. */
     var $value;
     var $new_value;
-    var $possible_vals;
+    var $possible_values;
 
     /* This variable needs to be made private so it can not be messed with. */
     /* I just don't remember how to do it right now and think it would be   */
@@ -38,24 +57,113 @@ class SquirrelOption {
     var $changed;
 
     function SquirrelOption
-    ($name, $caption, $value, $refresh_level = SMOPT_REFRESH_NONE,
-     $type = SMOPT_TYPE_STRING, $possible_values = '') {
+    ($name, $caption, $type, $refresh_level, $possible_values = '') {
         /* Set the basic stuff. */
         $this->name = $name;
         $this->caption = $caption;
-        $this->value = $value;
-
-        /* Set the optional parameters. */
-        $this->refresh_level = $refresh_level;
         $this->type = $type;
-        $this->value = $value;
-        $this->possible_values = $possible_value;
+        $this->refresh_level = $refresh_level;
+        $this->possible_values = $possible_values;
+
+        /* Check for a current value. */
+        if (isset($GLOBALS[$name])) {
+            $this->value = $GLOBALS[$name];
+        } else {
+            $this->value = '';
+        }
 
-        /* Lastly, check for a new value. */
+        /* Check for a new value. */
         if (isset($GLOBALS["new_$name"])) {
             $this->new_value = $GLOBALS["new_$name"];
             $this->changed = ($this->value !== $this->new_value);
+        } else {
+            $this->new_value = '';
+            $this->changed = false;
+        }
+    }
+
+    function createHTMLWidget() {
+        switch ($this->type) {
+            case SMOPT_TYPE_STRING:
+                $result = $this->createWidget_String();
+                break;
+            case SMOPT_TYPE_STRLIST:
+                $result = $this->createWidget_StrList();
+                break;
+            case SMOPT_TYPE_TEXTAREA:
+                $result = $this->createWidget_TextArea();
+                break;
+            case SMOPT_TYPE_INTEGER:
+                $result = $this->createWidget_Integer();
+                break;
+            case SMOPT_TYPE_FLOAT:
+                $result = $this->createWidget_Float();
+                break;
+            case SMOPT_TYPE_BOOLEAN:
+                $result = $this->createWidget_Boolean();
+                break;
+            case SMOPT_TYPE_HIDDEN:
+                $result = $this->createWidget_Hidden();
+                break;
+            default:
+               $result = '<FONT COLOR=RED>'
+                       . sprintf(_("Option Type '%s' Not Found"), $this->type)
+                       . '</FONT>';
+        }
+
+        /* Now, return the created widget. */
+        return ($result);
+    }
+
+    function createWidget_String() {
+        $result = "<INPUT NAME=\"new_$this->name\" value=\"$this->value\" size=\"5\">";
+        return ($result);
+    }
+
+    function createWidget_StrList() {
+        /* Begin the select tag. */
+        $result = "<SELECT NAME=\"new_$this->name\">";
+
+        /* Add each possible value to the select list. */
+        foreach ($this->possible_values as $real_value => $disp_value) {
+            /* Start the next new option string. */
+            $new_option = "<OPTION VALUE=\"$real_value\"";
+
+            /* If this value is the current value, select it. */
+            if ($real_value == $this->value) {
+               $new_option .= ' SELECTED';
+            }
+
+            /* Add the display value to our option string. */
+            $new_option .= ">$disp_value</OPTION>";
+
+            /* And add the new option string to our select tag. */
+            $result .= $new_option;
         }
+
+        /* Close the select tag and return our happy result. */
+        $result .= '</SELECT>';
+        return ($result);
+    }
+
+    function createWidget_TextArea() {
+    }
+
+    function createWidget_Integer() {
+        return ($this->createWidget_String());
+    }
+
+    function createWidget_Float() {
+        return ($this->createWidget_String());
+    }
+
+    function createWidget_Boolean() {
+    }
+
+    function createWidget_Hidden() {
+        $result = '<INPUT TYPE="HIDDEN" NAME="new_' . $this->name
+                . '" VALUE="' . $this->value . '">';
+        return ($result);
     }
 
     function hasChanged() {
@@ -63,6 +171,36 @@ class SquirrelOption {
     }
 }
 
+function createOptionArray($optvals) {
+    /* Build a simple array with which to start. */
+    $result = array();
+
+     /* Create a new SquirrelOption for each set of option values. */
+    foreach ($optvals as $optset) {
+        if (isset($optset['posvals'])) {
+            /* Create a new option with all values given. */
+            $result[] = new SquirrelOption(
+                $optset['name'],
+                $optset['caption'],
+                $optset['type'],
+                $optset['refresh'],
+                $optset['posvals']
+            );
+        } else {
+            /* Create a new option with all but possible values given. */
+            $result[] = new SquirrelOption(
+                $optset['name'],
+                $optset['caption'],
+                $optset['type'],
+                $optset['refresh']
+            );
+        }
+    }
+
+    /* Return our resulting array. */
+    return ($result);
+}
+
 function OptionSelect( $title, $name, $data, $default, $show = '', $store = '' ) {
 
     echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
index bf0c796b46751cc8dc609d20cd900cb1053396f9..5e33327892e1e14cb468edbd658da444f870cc7f 100644 (file)
         setPref($data_dir, $username, 'language', $language);
         setPref($data_dir, $username, 'use_javascript_addr_book', $javascript_abook);
         setPref($data_dir, $username, 'javascript_setting', $new_javascript_setting);
-        setPref($data_dir, $username, 'show_num', $shownum);
-        setPref($data_dir, $username, 'wrap_at', $wrapat);
-        setPref($data_dir, $username, 'editor_size', $editorsize);
+        setPref($data_dir, $username, 'show_num', $new_show_num);
+        setPref($data_dir, $username, 'wrap_at', $new_wrap_at);
+        setPref($data_dir, $username, 'editor_size', $new_editor_size);
         setPref($data_dir, $username, 'left_refresh', $leftrefresh);
-        setPref($data_dir, $username, 'location_of_bar', $folder_new_location);
-        setPref($data_dir, $username, 'location_of_buttons', $button_new_location);
+        setPref($data_dir, $username, 'location_of_buttons', $new_location_of_buttons);
+        setPref($data_dir, $username, 'location_of_bar', $new_location_of_bar);
         setPref($data_dir, $username, 'left_size', $leftsize);
 
         if (isset($altIndexColors) && $altIndexColors == 1) {
             setPref($data_dir, $username, 'page_selector', 1);
         }
 
-        $js_autodetect_results = (isset($js_autodetect_results) ? $js_autodetect_results : SMPREF_JS_OFF);
+        $js_autodetect_results = (isset($new_js_autodetect_results) ? $new_js_autodetect_results : SMPREF_JS_OFF);
         if ($new_javascript_setting == SMPREF_JS_AUTODETECT) {
             if ($js_autodetect_results == SMPREF_JS_ON) {
                 setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON);
              "</table>\n";
     }
 
-?>
\ No newline at end of file
+?>
index 69cba54bea73de561481ddf1d78e3ac8ea3fb278..540cbf71aed377b9b562ad908e7ad93bd481b438 100644 (file)
                  array( '1' => _("JavaScript"),
                         '0' => _("HTML") ),
                  $use_javascript_addr_book );
-    OptionSelect( _("Use Javascript"), 'new_javascript_setting',
-                 array(SMPREF_JS_AUTODETECT => _("Autodetect"),
-                       SMPREF_JS_ON         => _("Always"),
-                       SMPREF_JS_OFF        => _("Never") ),
-                 $javascript_setting );
-    OptionHidden('js_autodetect_results', SMPREF_JS_OFF);
-    OptionText( _("Number of Messages to Index"), 'shownum', $show_num, 5 );
-    OptionText( _("Wrap incoming text at"), 'wrapat', $wrap_at, 5 );
-    OptionText( _("Size of editor window"), 'editorsize', $editor_size, 5 );
+
+    /*** BEGIN OPTIONS CLASS EXPERMINENTATION ***/
+
+    /* Build a simple array with which to start. */
+    $optvals = array();
+
+    /* Set values for the "use javascript" option. */
+    $optvals[] = 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_results = SMPREF_JS_OFF;
+    $optvals[] = array(
+        'name'    => 'js_autodetect_results',
+        'caption' => '',
+        'type'    => SMOPT_TYPE_HIDDEN,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[] = array(
+        'name'    => 'show_num',
+        'caption' => _("Number of Messages to Index"),
+        'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[] = array(
+        'name'    => 'wrap_at',
+        'caption' => _("Wrap Incoming Text At"),
+        'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
+    $optvals[] = array(
+        'name'    => 'editor_size',
+        'caption' => _("Size of Editor Window"),
+        'type'    => SMOPT_TYPE_INTEGER,
+        'refresh' => SMOPT_REFRESH_NONE
+    );
+
     OptionSelect( _("Location of buttons when composing"),
                   'button_new_location',
                   array( 'top' => _("Before headers"),
                          'between' => _("Between headers and message body"),
                          'bottom' => _("After message body") ),
                   $location_of_buttons );
-    OptionSelect( _("Location of folder list"),
-                  'folder_new_location',
-                  array( '' => _("Left"),
-                         'right' => _("Right") ),
-                  $location_of_bar );
+
+    $optvals[] = 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[] = array(
+        'name'    => 'location_of_bar',
+        'caption' =>_("Location of Folder List"),
+        'type'    => SMOPT_TYPE_STRLIST,
+        'refresh' => SMOPT_REFRESH_ALL,
+        'posvals' => array(SMPREF_LOC_LEFT   => _("Left"),
+                           SMPREF_LOC_RIGHT  => _("Right"))
+    );
+
+    /* Now, build the complete options array. */
+    $options = createOptionArray($optvals);
+
+    /* 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();
+        }
+    }
+
+    /*** END OPTIONS CLASS EXPERMINENTATION ***/
+
    for ($i = 100; $i <= 300; $i += 10) {
         $res[$i] = $i . _("pixels");
    }
     </table>
 
 <SCRIPT LANGUAGE="JavaScript"><!--
-  document.forms[0].js_autodetect_results.value = '<?php echo SMPREF_JS_ON; ?>';
+  document.forms[0].new_js_autodetect_results.value = '<?php echo SMPREF_JS_ON; ?>';
 // --></SCRIPT>
 
 </td></tr>