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);
25 define('SMOPT_TYPE_COMMENT', 7);
27 /* Define constants for the options refresh levels. */
28 define('SMOPT_REFRESH_NONE', 0);
29 define('SMOPT_REFRESH_FOLDERLIST', 1);
30 define('SMOPT_REFRESH_ALL', 2);
32 /* Define constants for the options size. */
33 define('SMOPT_SIZE_TINY', 0);
34 define('SMOPT_SIZE_SMALL', 1);
35 define('SMOPT_SIZE_MEDIUM', 2);
36 define('SMOPT_SIZE_LARGE', 3);
37 define('SMOPT_SIZE_HUGE', 4);
40 * SquirrelOption: An option for Squirrelmail.
42 * This class is a work in progress. When complete, it will handle
43 * presentation and saving of Squirrelmail user options in a simple,
44 * streamline manner. Stay tuned for more stuff.
46 * Also, I'd like to ask that people leave this alone (mostly :) until
47 * I get it a little further along. That should only be a day or two or
48 * three. I will remove this message when it is ready for primetime usage.
50 class SquirrelOption
{
51 /* The basic stuff. */
59 /* The various 'values' for this options. */
64 /* This variable needs to be made private so it can not be messed with. */
65 /* I just don't remember how to do it right now and think it would be */
66 /* better to keep coding. Someone can fix it, if they want. Or I will. */
69 function SquirrelOption
70 ($name, $caption, $type, $refresh_level, $possible_values = '') {
71 /* Set the basic stuff. */
73 $this->caption
= $caption;
75 $this->refresh_level
= $refresh_level;
76 $this->possible_values
= $possible_values;
77 $this->size
= SMOPT_SIZE_MEDIUM
;
80 /* Check for a current value. */
81 if (isset($GLOBALS[$name])) {
82 $this->value
= $GLOBALS[$name];
87 /* Check for a new value. */
88 if (isset($GLOBALS["new_$name"])) {
89 $this->new_value
= $GLOBALS["new_$name"];
90 $this->changed
= ($this->value
!== $this->new_value
);
92 $this->new_value
= '';
93 $this->changed
= false;
97 /* Set the size for this option. */
98 function setSize($size) {
102 /* Set the comment for this option. */
103 function setComment($comment) {
104 $this->comment
= $comment;
107 function createHTMLWidget() {
108 switch ($this->type
) {
109 case SMOPT_TYPE_STRING
:
110 $result = $this->createWidget_String();
112 case SMOPT_TYPE_STRLIST
:
113 $result = $this->createWidget_StrList();
115 case SMOPT_TYPE_TEXTAREA
:
116 $result = $this->createWidget_TextArea();
118 case SMOPT_TYPE_INTEGER
:
119 $result = $this->createWidget_Integer();
121 case SMOPT_TYPE_FLOAT
:
122 $result = $this->createWidget_Float();
124 case SMOPT_TYPE_BOOLEAN
:
125 $result = $this->createWidget_Boolean();
127 case SMOPT_TYPE_HIDDEN
:
128 $result = $this->createWidget_Hidden();
130 case SMOPT_TYPE_COMMENT
:
131 $result = $this->createWidget_Comment();
134 $result = '<FONT COLOR=RED>'
135 . sprintf(_("Option Type '%s' Not Found"), $this->type
)
139 /* Now, return the created widget. */
143 function createWidget_String() {
144 switch ($this->size
) {
145 case SMOPT_SIZE_TINY
: $width = 5; break;
146 case SMOPT_SIZE_SMALL
: $width = 12; break;
147 case SMOPT_SIZE_LARGE
: $width = 38; break;
148 case SMOPT_SIZE_HUGE
: $width = 50; break;
149 case SMOPT_SIZE_NORMAL
:
150 default: $width = 25;
153 $result = "<INPUT NAME=\"new_$this->name\" VALUE=\"$this->value\" SIZE=\"$width\">";
157 function createWidget_StrList() {
158 /* Begin the select tag. */
159 $result = "<SELECT NAME=\"new_$this->name\">";
161 /* Add each possible value to the select list. */
162 foreach ($this->possible_values
as $real_value => $disp_value) {
163 /* Start the next new option string. */
164 $new_option = "<OPTION VALUE=\"$real_value\"";
166 /* If this value is the current value, select it. */
167 if ($real_value == $this->value
) {
168 $new_option .= ' SELECTED';
171 /* Add the display value to our option string. */
172 $new_option .= ">$disp_value</OPTION>";
174 /* And add the new option string to our select tag. */
175 $result .= $new_option;
178 /* Close the select tag and return our happy result. */
179 $result .= '</SELECT>';
183 function createWidget_TextArea() {
184 switch ($this->size
) {
185 case SMOPT_SIZE_TINY
: $rows = 3; $cols = 10; break;
186 case SMOPT_SIZE_SMALL
: $rows = 4; $cols = 30; break;
187 case SMOPT_SIZE_LARGE
: $rows = 10; $cols = 60; break;
188 case SMOPT_SIZE_HUGE
: $rows = 20; $cols = 80; break;
189 case SMOPT_SIZE_NORMAL
:
190 default: $rows = 5; $cols = 50;
192 $result = "<TEXTAREA NAME=\"new_$this->name\" ROWS=\"$rows\" "
193 . "COLS=\"$cols\">$this->value</TEXTAREA>";
197 function createWidget_Integer() {
198 return ($this->createWidget_String());
201 function createWidget_Float() {
202 return ($this->createWidget_String());
205 function createWidget_Boolean() {
206 /* Do the whole current value thing. */
207 if ($this->value
!= SMPREF_NO
) {
208 $yes_chk = ' CHECKED';
212 $no_chk = ' CHECKED';
215 /* Build the yes choice. */
216 $yes_option = '<INPUT TYPE="RADIO" NAME="new_' . $this->name
217 . '" VALUE="' . SMPREF_YES
. "\"$yes_chk> "
220 /* Build the no choice. */
221 $no_option = '<INPUT TYPE="RADIO" NAME="new_' . $this->name
222 . '" VALUE="' . SMPREF_NO
. "\"$no_chk> "
225 /* Build and return the combined "boolean widget". */
226 $result = "$yes_option $no_option";
230 function createWidget_Hidden() {
231 $result = '<INPUT TYPE="HIDDEN" NAME="new_' . $this->name
232 . '" VALUE="' . $this->value
. '">';
236 function createWidget_Comment() {
237 $result = $this->comment
;
241 function hasChanged() {
242 return ($this->changed
);
246 function createOptionGroups($optgrps, $optvals) {
247 /* Build a simple array with which to start. */
250 /* Create option group for each option group name. */
251 foreach ($optgrps as $grpkey => $grpname) {
252 $result[$grpkey] = array();
253 $result[$grpkey]['name'] = $grpname;
254 $result[$grpkey]['options'] = array();
257 /* Create a new SquirrelOption for each set of option values. */
258 foreach ($optvals as $grpkey => $grpopts) {
259 foreach ($grpopts as $optset) {
260 if (isset($optset['posvals'])) {
261 /* Create a new option with all values given. */
262 $next_option = new SquirrelOption(
270 /* Create a new option with all but possible values given. */
271 $next_option = new SquirrelOption(
279 /* If provided, set the size for this option. */
280 if (isset($optset['size'])) {
281 $next_option->setSize($optset['size']);
284 /* If provided, set the comment for this option. */
285 if (isset($optset['comment'])) {
286 $next_option->setComment($optset['comment']);
289 /* Add this option to the option array. */
290 $result[$grpkey]['options'][] = $next_option;
294 /* Return our resulting array. */
298 function printOptionGroups($option_groups) {
299 foreach ($option_groups as $next_optgrp) {
300 echo '<TR><TD ALIGN="CENTER" VALIGN="MIDDLE" COLSPAN="2" NOWRAP><B>'
301 . $next_optgrp['name'] . "</B></TD></TR>\n";
302 foreach ($next_optgrp['options'] as $option) {
303 if ($option->type
!= SMOPT_TYPE_HIDDEN
) {
305 echo ' <TD ALIGN="RIGHT" VALIGN="MIDDLE">'
306 . $option->caption
. ":</TD>\n";
307 echo ' <TD>' . $option->createHTMLWidget() . "</TD>\n";
310 echo $option->createHTMLWidget();
313 echo "<TR><TD COLSPAN=\"2\"> </TD></TR>\n";
317 function OptionSelect( $title, $name, $data, $default, $show = '', $store = '' ) {
319 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
320 "<select name=\"$name\">";
321 foreach( $data as $key => $opt ) {
322 if ( $store == '' ) {
333 echo "<option value=\"$vl\"";
334 if( $vl == $default ) {
337 echo ">$nm</option>\n";
340 echo "</select></td></tr>\n";
343 function OptionRadio( $title, $name, $data, $default, $show = '', $store = '', $sep = ' ' ) {
344 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>";
345 foreach( $data as $key => $opt ) {
346 if ( $store == '' ) {
357 echo "<input type=\"radio\" name=\"$name\" value=\"$vl\"";
358 if( $vl == $default ) {
367 function OptionText( $title, $name, $value, $size ) {
368 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
369 "<input name=\"$name\" value=\"$value\" size=\"$size\">" .
373 function OptionHidden( $name, $value ) {
374 echo "<INPUT TYPE=HIDDEN NAME=\"$name\" VALUE=\"$value\">\n";
377 function OptionCheck( $title, $name, $value, $comment ) {
380 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
381 "<input type=\"checkbox\" name=\"$name\" $chk> $comment" .
385 function OptionTitle( $title ) {
386 echo "<tr><td colspan=2 align=left valign=middle nowrap><b>$title</b></td></tr>\n";
389 function OptionSubmit( $name ) {
390 echo '<tr><td> </td><td><input type="submit" value="' . _("Submit") . '" name="' . $name . '">' .