831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
if ( !defined( "PHORUM_ADMIN" ) ) return;
|
|
|
21 |
|
|
|
22 |
class PhorumInputForm {
|
|
|
23 |
var $_rows;
|
|
|
24 |
var $_hiddens;
|
|
|
25 |
var $_action;
|
|
|
26 |
var $_method;
|
|
|
27 |
var $_target;
|
|
|
28 |
var $_enctype;
|
|
|
29 |
var $_events;
|
|
|
30 |
var $_submit;
|
|
|
31 |
var $_help;
|
|
|
32 |
|
|
|
33 |
function PhorumInputForm ( $action = "", $method = "get", $submit = "Submit", $target = "", $enctype = "", $events = "" )
|
|
|
34 |
{
|
|
|
35 |
$this->_action = ( empty( $action ) ) ? $_SERVER["PHP_SELF"] : $action;
|
|
|
36 |
$this->_method = $method;
|
|
|
37 |
$this->_target = $target;
|
|
|
38 |
$this->_enctype = $enctype;
|
|
|
39 |
$this->_events = $events;
|
|
|
40 |
$this->_submit = $submit;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
function hidden( $name, $value )
|
|
|
44 |
{
|
|
|
45 |
$this->_hiddens[$name] = $value;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
function addrow( $title, $contents = "", $valign = "middle", $align = "left" )
|
|
|
49 |
{
|
|
|
50 |
list( $talign, $calign ) = explode( ",", $align );
|
|
|
51 |
if ( empty( $calign ) ) $calign = $talign;
|
|
|
52 |
|
|
|
53 |
list( $tvalign, $cvalign ) = explode( ",", $valign );
|
|
|
54 |
if ( empty( $cvalign ) ) $cvalign = $tvalign;
|
|
|
55 |
|
|
|
56 |
$this->_rows[] = array( "title" => $title,
|
|
|
57 |
"contents" => $contents,
|
|
|
58 |
"title_valign" => $tvalign,
|
|
|
59 |
"content_valign" => $cvalign,
|
|
|
60 |
"title_align" => $talign,
|
|
|
61 |
"content_align" => $calign
|
|
|
62 |
);
|
|
|
63 |
|
|
|
64 |
end( $this->_rows );
|
|
|
65 |
|
|
|
66 |
return key( $this->_rows );
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
function addhelp( $row, $title, $text )
|
|
|
70 |
{
|
|
|
71 |
// Allow title and text to span multiple lines and
|
|
|
72 |
// do escaping for encapsulation within the help
|
|
|
73 |
// javascript code.
|
|
|
74 |
$title = addslashes(str_replace("\n", " ", $title));
|
|
|
75 |
$text = addslashes(str_replace("\n", " ", $text));
|
|
|
76 |
$this->_help[$row] = array( $title, $text );
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
function addbreak( $break = " " )
|
|
|
80 |
{
|
|
|
81 |
$this->_rows[] = array( "break" => $break );
|
|
|
82 |
end( $this->_rows );
|
|
|
83 |
return key( $this->_rows );
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
function addmessage( $message )
|
|
|
87 |
{
|
|
|
88 |
$this->_rows[] = array( "message" => $message );
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
function show()
|
|
|
92 |
{
|
|
|
93 |
if(count($this->_help)){
|
|
|
94 |
echo "<script type=\"text/javascript\">\nvar help = Array;\n";
|
|
|
95 |
foreach($this->_help as $key=>$data){
|
|
|
96 |
$title = str_replace('"', """, $data[0]);
|
|
|
97 |
$text = str_replace('"', '"', $data[1]);
|
|
|
98 |
$text = str_replace("\n", "\\n", $text);
|
|
|
99 |
echo "help[$key] = [\"$title\", \"$text\"];\n";
|
|
|
100 |
}
|
|
|
101 |
echo "</script>\n";
|
|
|
102 |
}
|
|
|
103 |
echo "<form style=\"display: inline;\" action=\"$this->_action\" method=\"$this->_method\"";
|
|
|
104 |
if ( !empty( $this->_target ) ) echo " target=\"$this->_target\"";
|
|
|
105 |
if ( !empty( $this->_enctype ) ) echo " enctype=\"$this->_enctype\"";
|
|
|
106 |
if ( !empty( $this->_events ) ) echo " $this->_events";
|
|
|
107 |
echo ">\n";
|
|
|
108 |
|
|
|
109 |
if ( is_array( $this->_hiddens ) ) foreach( $this->_hiddens as $name => $value ) {
|
|
|
110 |
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\">\n";
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" class=\"input-form-table\" width=\"100%\">\n";
|
|
|
114 |
|
|
|
115 |
if ( is_array( $this->_rows ) ) foreach( $this->_rows as $key => $row ) {
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
if ( $row["break"] ) {
|
|
|
119 |
$title = $row["break"];
|
|
|
120 |
if ( isset( $this->_help[$key] ) ) {
|
|
|
121 |
$title = $title . "<a href=\"javascript:show_help($key);\"><img class=\"question\" alt=\"Help\" title=\"Help\" border=\"0\" src=\"images/qmark.gif\" height=\"16\" width=\"16\" /></a>";
|
|
|
122 |
}
|
|
|
123 |
echo "<tr class=\"input-form-tr\">\n";
|
|
|
124 |
echo " <td colspan=\"2\" class=\"input-form-td-break\">$title</td>\n";
|
|
|
125 |
echo "</tr>\n";
|
|
|
126 |
} elseif ( $row["message"] ) {
|
|
|
127 |
echo "<tr class=\"input-form-tr\">\n";
|
|
|
128 |
echo " <td colspan=\"2\" class=\"input-form-td-message\">$row[message]</td>\n";
|
|
|
129 |
echo "</tr>\n";
|
|
|
130 |
} else {
|
|
|
131 |
$colspan = ( $row["contents"] == "" ) ? " colspan=2" : "";
|
|
|
132 |
|
|
|
133 |
$title = $row["title"];
|
|
|
134 |
|
|
|
135 |
if ( isset( $this->_help[$key] ) ) {
|
|
|
136 |
$title = $title . "<a href=\"javascript:show_help($key);\"><img class=\"question\" alt=\"Help\" title=\"Help\" border=\"0\" src=\"images/qmark.gif\" height=\"16\" width=\"16\" /></a>";
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
echo "<tr class=\"input-form-tr\">\n";
|
|
|
140 |
echo " <th valign=\"$row[title_valign]\" align=\"$row[title_align]\" class=\"input-form-th\"$colspan nowrap=\"nowrap\">$title</th>\n";
|
|
|
141 |
if ( !$colspan ) {
|
|
|
142 |
echo " <td valign=\"$row[content_valign]\" align=\"$row[content_align]\" class=\"input-form-td\">$row[contents]</td>\n";
|
|
|
143 |
}
|
|
|
144 |
echo "</tr>\n";
|
|
|
145 |
}
|
|
|
146 |
}
|
|
|
147 |
echo "<tr class=\"input-form-tr\">\n";
|
|
|
148 |
echo " <td class=\"input-form-td-break\" align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"$this->_submit\" class=\"input-form-submit\"></td>\n";
|
|
|
149 |
echo "</tr>\n";
|
|
|
150 |
|
|
|
151 |
echo "</table>\n";
|
|
|
152 |
|
|
|
153 |
echo "\n";
|
|
|
154 |
|
|
|
155 |
echo "</form>\n";
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
function time_select( $prefix, $blank_line = true, $time = "" )
|
|
|
159 |
{
|
|
|
160 |
if ( empty( $time ) ) $time = date( "H:i:s" );
|
|
|
161 |
list( $hour, $minute, $second ) = explode( "-", $time );
|
|
|
162 |
|
|
|
163 |
if ( $hour > 12 ) {
|
|
|
164 |
$hour -= 12;
|
|
|
165 |
$ampm = "PM";
|
|
|
166 |
} else {
|
|
|
167 |
$ampm = "AM";
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
for( $x = 0;$x <= 12;$x++ ) {
|
|
|
171 |
if ( $x == 0 && $blank_line ) {
|
|
|
172 |
$values[0] = "";
|
|
|
173 |
} else {
|
|
|
174 |
$key = ( $x < 10 ) ? "0$x" : $x;
|
|
|
175 |
$values[$key] = $x;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
$data = $this->select_tag( $prefix . "hour", $values, $hour ) . " : ";
|
|
|
179 |
|
|
|
180 |
array_merge( $values, range( 13, 60 ) );
|
|
|
181 |
|
|
|
182 |
$data .= $this->select_tag( $prefix . "minute", $values, $minute ) . " : ";
|
|
|
183 |
$data .= $this->select_tag( $prefix . "second", $values, $second ) . " ";
|
|
|
184 |
|
|
|
185 |
$data .= $this->select_tag( $prefix . "ampm", array( "AM" => "AM", "PM" => "PM" ), $ampm );
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
function date_select( $prefix, $blank_line = true, $date = "TODAY", $year_start = "", $year_end = "" )
|
|
|
189 |
{
|
|
|
190 |
if ( $date == "TODAY" ) $date = date( "Y-m-d" );
|
|
|
191 |
list( $year, $month, $day ) = explode( "-", $date );
|
|
|
192 |
|
|
|
193 |
if ( empty( $year_start ) ) $year_start = date( "Y" );
|
|
|
194 |
|
|
|
195 |
if ( empty( $year_end ) ) $year_end = date( "Y" ) + 2;
|
|
|
196 |
|
|
|
197 |
for( $x = 0;$x <= 12;$x++ ) {
|
|
|
198 |
if ( $x == 0 && $blank_line ) {
|
|
|
199 |
$values[0] = "";
|
|
|
200 |
} elseif ( $x > 0 ) {
|
|
|
201 |
$key = ( $x < 10 ) ? "0$x" : $x;
|
|
|
202 |
$values[$key] = date( "F", mktime( 0, 0, 0, $x ) );
|
|
|
203 |
}
|
|
|
204 |
}
|
|
|
205 |
$data = $this->select_tag( $prefix . "month", $values, $month ) . " ";
|
|
|
206 |
|
|
|
207 |
for( $x = 0;$x <= 31;$x++ ) {
|
|
|
208 |
if ( $x == 0 && $blank_line ) {
|
|
|
209 |
$values[0] = "";
|
|
|
210 |
} elseif ( $x > 0 ) {
|
|
|
211 |
$key = ( $x < 10 ) ? "0$x" : $x;
|
|
|
212 |
$values[$key] = $x;
|
|
|
213 |
}
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
$data .= $this->select_tag( $prefix . "day", $values, $day ) . ", ";
|
|
|
217 |
|
|
|
218 |
unset( $values );
|
|
|
219 |
if ( $blank_line ) $values = array( "" );
|
|
|
220 |
for( $x = $year_start;$x <= $year_end;$x++ ) {
|
|
|
221 |
$values[$x] = $x;
|
|
|
222 |
}
|
|
|
223 |
$data .= $this->select_tag( $prefix . "year", $values, $year );
|
|
|
224 |
|
|
|
225 |
return $data;
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
function text_box( $name, $value, $size = 0, $maxlength = 0, $password = false, $extra = "" )
|
|
|
229 |
{
|
|
|
230 |
$type = ( $password ) ? "password" : "text";
|
|
|
231 |
$data = "<input type=\"$type\" name=\"$name\"";
|
|
|
232 |
if ( $size > 0 ) $data .= " size=\"$size\"";
|
|
|
233 |
if ( $maxlength > 0 ) $data .= " maxlength=\"$maxlength\"";
|
|
|
234 |
$value = htmlspecialchars( $value );
|
|
|
235 |
$data .= " value=\"$value\" $extra>";
|
|
|
236 |
|
|
|
237 |
return $data;
|
|
|
238 |
}
|
|
|
239 |
|
|
|
240 |
function textarea( $name, $value, $cols = 30, $rows = 5, $extra = "" )
|
|
|
241 |
{
|
|
|
242 |
$value = htmlspecialchars( $value );
|
|
|
243 |
$data = "<textarea name=\"$name\" cols=\"$cols\" rows=\"$rows\" $extra>$value</textarea>";
|
|
|
244 |
|
|
|
245 |
return $data;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
function select_tag( $name, $values, $selected = "", $extra = "" )
|
|
|
249 |
{
|
|
|
250 |
$data = "<select name=\"$name\" $extra>\n";
|
|
|
251 |
foreach( $values as $value => $text ) {
|
|
|
252 |
$value = htmlspecialchars( $value );
|
|
|
253 |
$text = htmlspecialchars( $text );
|
|
|
254 |
$data .= "<option value=\"$value\"";
|
|
|
255 |
if ( $value == $selected ) $data .= " selected=\"selected\"";
|
|
|
256 |
$data .= ">$text</option>\n";
|
|
|
257 |
}
|
|
|
258 |
$data .= "</select>\n";
|
|
|
259 |
return $data;
|
|
|
260 |
}
|
|
|
261 |
|
|
|
262 |
function select_tag_valaskey( $name, $values, $selected = "", $extra = "" )
|
|
|
263 |
{
|
|
|
264 |
$data = "<select name=\"$name\" $extra>\n";
|
|
|
265 |
foreach( $values as $value => $text ) {
|
|
|
266 |
$data .= "<option value=\"$text\"";
|
|
|
267 |
$text = htmlspecialchars( $text );
|
|
|
268 |
if ( $text == $selected ) $data .= " selected";
|
|
|
269 |
$data .= ">$text</option>\n";
|
|
|
270 |
}
|
|
|
271 |
$data .= "</select>\n";
|
|
|
272 |
return $data;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
function radio_button( $name, $values, $selected = "", $separator = " ", $extra = "" )
|
|
|
276 |
{
|
|
|
277 |
foreach( $values as $value => $text ) {
|
|
|
278 |
$value = htmlspecialchars( $value );
|
|
|
279 |
$text = htmlspecialchars( $text );
|
|
|
280 |
$data .= "<input type=\"radio\" name=\"$name\" value=\"$value\"";
|
|
|
281 |
if ( $selected == $value ) $data .= " checked";
|
|
|
282 |
$data .= " $extra> $text$separator";
|
|
|
283 |
}
|
|
|
284 |
return $data;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
function checkbox( $name, $value, $caption, $checked = 0, $extra = "" )
|
|
|
288 |
{
|
|
|
289 |
$is_checked = ( !empty( $checked ) ) ? "checked" : "" ;
|
|
|
290 |
|
|
|
291 |
$value = htmlspecialchars( $value );
|
|
|
292 |
|
|
|
293 |
$data = "<nobr><input type=\"checkbox\" name=\"$name\" value=\"$value\" $is_checked $extra> $caption</nobr>";
|
|
|
294 |
|
|
|
295 |
return $data;
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
// $list and $checklist are both associative and should have the same indicies
|
|
|
299 |
function checkbox_list( $prefix, $list, $separator = " ", $checklist = 0 )
|
|
|
300 |
{
|
|
|
301 |
// Get the listing of options to check into a array function library usable format
|
|
|
302 |
if ( empty( $checklist ) ) {
|
|
|
303 |
$checked_items = array();
|
|
|
304 |
} else {
|
|
|
305 |
if ( !is_array( $checklist ) ) {
|
|
|
306 |
$checked_items = array( $checklist );
|
|
|
307 |
} else {
|
|
|
308 |
$checked_items = $checklist;
|
|
|
309 |
}
|
|
|
310 |
}
|
|
|
311 |
// Loop through all the array elements and call function to generate the appropriate input tag
|
|
|
312 |
foreach( $list as $index => $info ) {
|
|
|
313 |
$check_name = $prefix . "[" . $index . "]";
|
|
|
314 |
$check_value = $info["value"];
|
|
|
315 |
$check_caption = $info["caption"];
|
|
|
316 |
$is_checked = ( in_array( $check_value, $checked_items ) ) ? 1 : 0;
|
|
|
317 |
|
|
|
318 |
$data .= $this->checkbox( $check_name, $check_value, $check_caption, $is_checked ) . $separator;
|
|
|
319 |
}
|
|
|
320 |
|
|
|
321 |
return $data;
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
?>
|