5 * Copyright (c) 1999-2001 The Squirrelmail Development Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 * Functions needed to display the options pages.
13 /**********************************************/
14 /* Define constants used in the options code. */
15 /**********************************************/
17 /* Define constants for the various option types. */
18 define('SMOPT_TYPE_STRING', 0);
19 define('SMOPT_TYPE_STRLIST', 1);
20 define('SMOPT_TYPE_TEXTAREA', 2);
21 define('SMOPT_TYPE_INTEGER', 3);
22 define('SMOPT_TYPE_FLOAT', 4);
23 define('SMOPT_TYPE_BOOLEAN', 5);
24 define('SMOPT_TYPE_HIDDEN', 6);
26 /* Define constants for the options refresh levels. */
27 define('SMOPT_REFRESH_NONE', 0);
28 define('SMOPT_REFRESH_FOLDERLIST', 1);
29 define('SMOPT_REFRESH_ALL', 2);
32 * SquirrelOption: An option for Squirrelmail.
34 * This class is a work in progress. When complete, it will handle
35 * presentation and saving of Squirrelmail user options in a simple,
36 * streamline manner. Stay tuned for more stuff.
38 * Also, I'd like to ask that people leave this alone (mostly :) until
39 * I get it a little further along. That should only be a day or two or
40 * three. I will remove this message when it is ready for primetime usage.
42 class SquirrelOption
{
43 /* The basic stuff. */
49 /* The various 'values' for this options. */
54 /* This variable needs to be made private so it can not be messed with. */
55 /* I just don't remember how to do it right now and think it would be */
56 /* better to keep coding. Someone can fix it, if they want. Or I will. */
59 function SquirrelOption
60 ($name, $caption, $type, $refresh_level, $possible_values = '') {
61 /* Set the basic stuff. */
63 $this->caption
= $caption;
65 $this->refresh_level
= $refresh_level;
66 $this->possible_values
= $possible_values;
68 /* Check for a current value. */
69 if (isset($GLOBALS[$name])) {
70 $this->value
= $GLOBALS[$name];
75 /* Check for a new value. */
76 if (isset($GLOBALS["new_$name"])) {
77 $this->new_value
= $GLOBALS["new_$name"];
78 $this->changed
= ($this->value
!== $this->new_value
);
80 $this->new_value
= '';
81 $this->changed
= false;
85 function createHTMLWidget() {
86 switch ($this->type
) {
87 case SMOPT_TYPE_STRING
:
88 $result = $this->createWidget_String();
90 case SMOPT_TYPE_STRLIST
:
91 $result = $this->createWidget_StrList();
93 case SMOPT_TYPE_TEXTAREA
:
94 $result = $this->createWidget_TextArea();
96 case SMOPT_TYPE_INTEGER
:
97 $result = $this->createWidget_Integer();
99 case SMOPT_TYPE_FLOAT
:
100 $result = $this->createWidget_Float();
102 case SMOPT_TYPE_BOOLEAN
:
103 $result = $this->createWidget_Boolean();
105 case SMOPT_TYPE_HIDDEN
:
106 $result = $this->createWidget_Hidden();
109 $result = '<FONT COLOR=RED>'
110 . sprintf(_("Option Type '%s' Not Found"), $this->type
)
114 /* Now, return the created widget. */
118 function createWidget_String() {
119 $result = "<INPUT NAME=\"new_$this->name\" value=\"$this->value\" size=\"5\">";
123 function createWidget_StrList() {
124 /* Begin the select tag. */
125 $result = "<SELECT NAME=\"new_$this->name\">";
127 /* Add each possible value to the select list. */
128 foreach ($this->possible_values
as $real_value => $disp_value) {
129 /* Start the next new option string. */
130 $new_option = "<OPTION VALUE=\"$real_value\"";
132 /* If this value is the current value, select it. */
133 if ($real_value == $this->value
) {
134 $new_option .= ' SELECTED';
137 /* Add the display value to our option string. */
138 $new_option .= ">$disp_value</OPTION>";
140 /* And add the new option string to our select tag. */
141 $result .= $new_option;
144 /* Close the select tag and return our happy result. */
145 $result .= '</SELECT>';
149 function createWidget_TextArea() {
152 function createWidget_Integer() {
153 return ($this->createWidget_String());
156 function createWidget_Float() {
157 return ($this->createWidget_String());
160 function createWidget_Boolean() {
161 /* Do the whole current value thing. */
162 if ($this->value
!= SMPREF_NO
) {
163 $yes_chk = ' CHECKED';
167 $no_chk = ' CHECKED';
170 /* Build the yes choice. */
171 $yes_option = '<INPUT TYPE="RADIO" NAME="new_' . $this->name
172 . '" VALUE="' . SMPREF_YES
. "\"$yes_chk> "
175 /* Build the no choice. */
176 $no_option = '<INPUT TYPE="RADIO" NAME="new_' . $this->name
177 . '" VALUE="' . SMPREF_NO
. "\"$no_chk> "
180 /* Build and return the combined "boolean widget". */
181 $result = "$yes_option $no_option";
185 function createWidget_Hidden() {
186 $result = '<INPUT TYPE="HIDDEN" NAME="new_' . $this->name
187 . '" VALUE="' . $this->value
. '">';
191 function hasChanged() {
192 return ($this->changed
);
196 function createOptionArray($optvals) {
197 /* Build a simple array with which to start. */
200 /* Create a new SquirrelOption for each set of option values. */
201 foreach ($optvals as $optset) {
202 if (isset($optset['posvals'])) {
203 /* Create a new option with all values given. */
204 $result[] = new SquirrelOption(
212 /* Create a new option with all but possible values given. */
213 $result[] = new SquirrelOption(
222 /* Return our resulting array. */
226 function OptionSelect( $title, $name, $data, $default, $show = '', $store = '' ) {
228 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
229 "<select name=\"$name\">";
230 foreach( $data as $key => $opt ) {
231 if ( $store == '' ) {
242 echo "<option value=\"$vl\"";
243 if( $vl == $default ) {
246 echo ">$nm</option>\n";
249 echo "</select></td></tr>\n";
252 function OptionRadio( $title, $name, $data, $default, $show = '', $store = '', $sep = ' ' ) {
253 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>";
254 foreach( $data as $key => $opt ) {
255 if ( $store == '' ) {
266 echo "<input type=\"radio\" name=\"$name\" value=\"$vl\"";
267 if( $vl == $default ) {
276 function OptionText( $title, $name, $value, $size ) {
277 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
278 "<input name=\"$name\" value=\"$value\" size=\"$size\">" .
282 function OptionHidden( $name, $value ) {
283 echo "<INPUT TYPE=HIDDEN NAME=\"$name\" VALUE=\"$value\">\n";
286 function OptionCheck( $title, $name, $value, $comment ) {
289 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
290 "<input type=\"checkbox\" name=\"$name\" $chk> $comment" .
294 function OptionTitle( $title ) {
295 echo "<tr><td colspan=2 align=left valign=middle nowrap><b>$title</b></td></tr>\n";
298 function OptionSubmit( $name ) {
299 echo '<tr><td> </td><td><input type="submit" value="' . _("Submit") . '" name="' . $name . '">' .