Working on code that will provide for more standardized code, presentation, etc,...
[squirrelmail.git] / functions / options.php
CommitLineData
44ef0f47 1<?php
9962527a 2 /**
3 * options.php
4 *
5 * Copyright (c) 1999-2001 The Squirrelmail Development Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * Functions needed to display the options pages.
9 *
10 * $Id$
11 */
12/**
13 * SquirrelOption: An option for Squirrelmail.
14 *
15 * This class is a work in progress. When complete, it will handle
16 * presentation and saving of Squirrelmail user options in a simple,
17 * streamline manner. Stay tuned for more stuff.
18 *
19 * Also, I'd like to ask that people leave this alone (mostly :) until
20 * I get it a little further along. That should only be a day or two or
21 * three. I will remove this message when it is ready for primetime usage.
22 */
23class SquirrelOption {
24 /* The basic stuff. */
25 var $name;
26 var $caption;
27 var $refresh_level;
28 var $type;
29
30 /* The various 'values' for this options. */
31 var $value;
32 var $new_value;
33 var $possible_vals;
34
35 /* This variable needs to be made private so it can not be messed with. */
36 /* I just don't remember how to do it right now and think it would be */
37 /* better to keep coding. Someone can fix it, if they want. Or I will. */
38 var $changed;
39
40 function SquirrelOption
41 ($name, $caption, $value, $refresh_level = SMOPT_REFRESH_NONE,
42 $type = SMOPT_TYPE_STRING, $possible_values = '') {
43 /* Set the basic stuff. */
44 $this->name = $name;
45 $this->caption = $caption;
46 $this->value = $value;
47
48 /* Set the optional parameters. */
49 $this->refresh_level = $refresh_level;
50 $this->type = $type;
51 $this->value = $value;
52 $this->possible_values = $possible_value;
53
54 /* Lastly, check for a new value. */
55 if (isset($GLOBALS["new_$name"])) {
56 $this->new_value = $GLOBALS["new_$name"];
57 $this->changed = ($this->value !== $this->new_value);
44ef0f47 58 }
9962527a 59 }
44ef0f47 60
9962527a 61 function hasChanged() {
62 return ($this->changed);
44ef0f47 63 }
9962527a 64}
44ef0f47 65
9962527a 66function OptionSelect( $title, $name, $data, $default, $show = '', $store = '' ) {
44ef0f47 67
9962527a 68 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
69 "<select name=\"$name\">";
70 foreach( $data as $key => $opt ) {
71 if ( $store == '' ) {
72 $vl = $key;
73 } else{
74 $vl = $opt[$store];
75 }
76 if ( $show == '' ) {
77 $nm = $opt;
78 } else{
79 $nm = $opt[$show];
80 }
81 if ( $nm <> '') {
82 echo "<option value=\"$vl\"";
83 if( $vl == $default ) {
84 echo ' selected';
44ef0f47 85 }
9962527a 86 echo ">$nm</option>\n";
44ef0f47 87 }
44ef0f47 88 }
9962527a 89 echo "</select></td></tr>\n";
90}
91
92function OptionRadio( $title, $name, $data, $default, $show = '', $store = '', $sep = '&nbsp; &nbsp;' ) {
93 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>";
94 foreach( $data as $key => $opt ) {
95 if ( $store == '' ) {
96 $vl = $key;
97 } else{
98 $vl = $opt[$store];
99 }
100 if ( $show == '' ) {
101 $nm = $opt;
102 } else{
103 $nm = $opt[$show];
104 }
105 if ( $nm <> '') {
106 echo "<input type=\"radio\" name=\"$name\" value=\"$vl\"";
107 if( $vl == $default ) {
108 echo ' checked';
109 }
110 echo ">$nm $sep\n";
111 }
02ddcd00 112 }
9962527a 113 echo "</td></tr>\n";
114}
115
116function OptionText( $title, $name, $value, $size ) {
117 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
118 "<input name=\"$name\" value=\"$value\" size=\"$size\">" .
119 "</td></tr>\n";
120}
121
122function OptionHidden( $name, $value ) {
123 echo "<INPUT TYPE=HIDDEN NAME=\"$name\" VALUE=\"$value\">\n";
124}
125
126function OptionCheck( $title, $name, $value, $comment ) {
127 if ( $value )
128 $chk = 'checked';
129 echo "<tr><td align=right valign=middle nowrap>$title: </td><td>" .
130 "<input type=\"checkbox\" name=\"$name\" $chk> $comment" .
131 "</td></tr>\n";
132}
133
134function OptionTitle( $title ) {
135 echo "<tr><td colspan=2 align=left valign=middle nowrap><b>$title</b></td></tr>\n";
136}
137
138function OptionSubmit( $name ) {
139 echo '<tr><td>&nbsp;</td><td><input type="submit" value="' . _("Submit") . '" name="' . $name . '">' .
140 '</td></tr>';
141}
02ddcd00 142
23d6bd09 143?>