[ Index ] |
|
Code source de Phorum 5.1.25 |
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 = array() ) 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 $this->_module = NULL; 42 } 43 44 function add_formevent($event, $code) 45 { 46 $event = strtolower($event); 47 if (substr($event, 0, 2) != "on") $event = "on$event"; 48 if (!isset($this->_events[$event])) { 49 $this->_events[$event] = $code; 50 } else { 51 $this->_events[$event] .= ";" . $code; 52 } 53 } 54 55 function hidden( $name, $value ) 56 { 57 $this->_hiddens[$name] = $value; 58 } 59 60 function _called_from_module() 61 { 62 // Should be available, because Phorum requires PHP 4.3.0 or higher, 63 // but skip the functionality for those who are using an older 64 // version of PHP. 65 if (!function_exists('debug_backtrace')) return NULL; 66 67 $bt = debug_backtrace(); 68 if (preg_match('!^.*/mods/([^/]+)/.+$!', $bt[2]["file"], $m)) { 69 $module = $m[1]; 70 if (isset($GLOBALS["PHORUM"]["mods"][$module])) return $module; 71 } 72 73 return NULL; 74 } 75 76 function _add_module_header() 77 { 78 // Only add module headers for forms that are created outside 79 // the settings screen(s) for a module. 80 if (isset($_REQUEST["module"]) && $_REQUEST["module"] == "modsettings") 81 return; 82 83 $module = $this->_called_from_module(); 84 if ($module === NULL) { $this->_module = NULL; return; } 85 86 if ($this->_module === NULL || $this->_module != $module) { 87 $this->addbreak("Configuration for module " . 88 '"' . htmlspecialchars($module) . '"'); 89 $this->_module = $module; 90 } 91 } 92 93 function addrow( $title, $contents = "", $valign = "middle", $align = "left" ) 94 { 95 $this->_add_module_header(); 96 97 list( $talign, $calign ) = explode( ",", $align ); 98 if ( empty( $calign ) ) $calign = $talign; 99 100 list( $tvalign, $cvalign ) = explode( ",", $valign ); 101 if ( empty( $cvalign ) ) $cvalign = $tvalign; 102 103 $this->_rows[] = array( "title" => $title, 104 "contents" => $contents, 105 "title_valign" => $tvalign, 106 "content_valign" => $cvalign, 107 "title_align" => $talign, 108 "content_align" => $calign 109 ); 110 111 end( $this->_rows ); 112 113 return key( $this->_rows ); 114 } 115 116 function addhelp( $row, $title, $text ) 117 { 118 // Allow title and text to span multiple lines and 119 // do escaping for encapsulation within the help 120 // javascript code. 121 $title = str_replace("\r", " ", $title); 122 $title = addslashes(str_replace("\n", " ", $title)); 123 $text = str_replace("\r", " ", $text); 124 $text = addslashes(str_replace("\n", " ", $text)); 125 $this->_help[$row] = array( $title, $text ); 126 } 127 128 function addbreak( $break = " " ) 129 { 130 $this->_add_module_header(); 131 132 // If a module is calling addbreak() from outside the 133 // modsettings module, then replace the addbreak by 134 // addsubbreak() to make it visually clear that the 135 // options below the break do not belong to the Phorum 136 // admin core. 137 $type = 'break'; 138 if ($this->_module !== NULL && 139 isset($_REQUEST["module"]) && 140 $_REQUEST["module"] != "modsettings") { 141 $type = 'subbreak'; 142 } 143 144 $this->_rows[] = array( $type => $break ); 145 end( $this->_rows ); 146 return key( $this->_rows ); 147 } 148 149 function addsubbreak( $break = " " ) 150 { 151 $this->_add_module_header(); 152 $this->_rows[] = array( "subbreak" => $break ); 153 end( $this->_rows ); 154 return key( $this->_rows ); 155 } 156 157 function addmessage( $message ) 158 { 159 $this->_add_module_header(); 160 161 $this->_rows[] = array( "message" => $message ); 162 } 163 164 function show() 165 { 166 if(count($this->_help)){ 167 echo "<script type=\"text/javascript\">\nvar help = Array;\n"; 168 foreach($this->_help as $key=>$data){ 169 $title = str_replace('"', """, $data[0]); 170 $text = str_replace('"', '"', $data[1]); 171 $text = str_replace("\n", "\\n", $text); 172 echo "help[$key] = [\"$title\", \"$text\"];\n"; 173 } 174 echo "</script>\n"; 175 } 176 177 echo "<form style=\"display: inline;\" " . 178 "action=\"".htmlspecialchars($this->_action)."\" " . 179 "method=\"$this->_method\""; 180 if ( !empty( $this->_target ) ) echo " target=\"$this->_target\""; 181 if ( !empty( $this->_enctype ) ) echo " enctype=\"$this->_enctype\""; 182 foreach ($this->_events as $event => $code) { 183 echo " $event=\"".htmlspecialchars($code)."\""; 184 } 185 echo ">\n"; 186 187 if ( is_array( $this->_hiddens ) ) foreach( $this->_hiddens as $name => $value ) { 188 echo "<input type=\"hidden\" name=\"$name\" value=\"".htmlspecialchars($value)."\">\n"; 189 } 190 191 echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" class=\"input-form-table\" width=\"100%\">\n"; 192 193 if ( is_array( $this->_rows ) ) foreach( $this->_rows as $key => $row ) { 194 195 196 if ( $row["break"] || $row["subbreak"]) { 197 $extra_class = ''; 198 if ($row["subbreak"]) { 199 $row["break"] = $row["subbreak"]; 200 $extra_class = "input-form-td-subbreak"; 201 } 202 $title = $row["break"]; 203 if ( isset( $this->_help[$key] ) ) { 204 $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>"; 205 } 206 echo "<tr class=\"input-form-tr\">\n"; 207 echo " <td colspan=\"2\" class=\"input-form-td-break $extra_class\">$title</td>\n"; 208 echo "</tr>\n"; 209 } elseif ( $row["message"] ) { 210 echo "<tr class=\"input-form-tr\">\n"; 211 echo " <td colspan=\"2\" class=\"input-form-td-message\">$row[message]</td>\n"; 212 echo "</tr>\n"; 213 } else { 214 $colspan = ( $row["contents"] == "" ) ? " colspan=2" : ""; 215 216 $title = $row["title"]; 217 218 if ( isset( $this->_help[$key] ) ) { 219 $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>"; 220 } 221 222 echo "<tr class=\"input-form-tr\">\n"; 223 echo " <th valign=\"$row[title_valign]\" align=\"$row[title_align]\" class=\"input-form-th\"$colspan nowrap=\"nowrap\">$title</th>\n"; 224 if ( !$colspan ) { 225 echo " <td valign=\"$row[content_valign]\" align=\"$row[content_align]\" class=\"input-form-td\">$row[contents]</td>\n"; 226 } 227 echo "</tr>\n"; 228 } 229 } 230 echo "<tr class=\"input-form-tr\">\n"; 231 echo " <td class=\"input-form-td-break\" align=\"center\" colspan=\"2\"><input type=\"submit\" value=\"$this->_submit\" class=\"input-form-submit\"></td>\n"; 232 echo "</tr>\n"; 233 234 echo "</table>\n"; 235 236 echo "\n"; 237 238 echo "</form>\n"; 239 } 240 241 function time_select( $prefix, $blank_line = true, $time = "" ) 242 { 243 if ( empty( $time ) ) $time = date( "H:i:s" ); 244 list( $hour, $minute, $second ) = explode( "-", $time ); 245 246 if ( $hour > 12 ) { 247 $hour -= 12; 248 $ampm = "PM"; 249 } else { 250 $ampm = "AM"; 251 } 252 253 for( $x = 0;$x <= 12;$x++ ) { 254 if ( $x == 0 && $blank_line ) { 255 $values[0] = ""; 256 } else { 257 $key = ( $x < 10 ) ? "0$x" : $x; 258 $values[$key] = $x; 259 } 260 } 261 $data = $this->select_tag( $prefix . "hour", $values, $hour ) . " : "; 262 263 array_merge( $values, range( 13, 60 ) ); 264 265 $data .= $this->select_tag( $prefix . "minute", $values, $minute ) . " : "; 266 $data .= $this->select_tag( $prefix . "second", $values, $second ) . " "; 267 268 $data .= $this->select_tag( $prefix . "ampm", array( "AM" => "AM", "PM" => "PM" ), $ampm ); 269 } 270 271 function date_select( $prefix, $blank_line = true, $date = "TODAY", $year_start = "", $year_end = "" ) 272 { 273 if ( $date == "TODAY" ) $date = date( "Y-m-d" ); 274 list( $year, $month, $day ) = explode( "-", $date ); 275 276 if ( empty( $year_start ) ) $year_start = date( "Y" ); 277 278 if ( empty( $year_end ) ) $year_end = date( "Y" ) + 2; 279 280 for( $x = 0;$x <= 12;$x++ ) { 281 if ( $x == 0 && $blank_line ) { 282 $values[0] = ""; 283 } elseif ( $x > 0 ) { 284 $key = ( $x < 10 ) ? "0$x" : $x; 285 $values[$key] = date( "F", mktime( 0, 0, 0, $x ) ); 286 } 287 } 288 $data = $this->select_tag( $prefix . "month", $values, $month ) . " "; 289 290 for( $x = 0;$x <= 31;$x++ ) { 291 if ( $x == 0 && $blank_line ) { 292 $values[0] = ""; 293 } elseif ( $x > 0 ) { 294 $key = ( $x < 10 ) ? "0$x" : $x; 295 $values[$key] = $x; 296 } 297 } 298 299 $data .= $this->select_tag( $prefix . "day", $values, $day ) . ", "; 300 301 unset( $values ); 302 if ( $blank_line ) $values = array( "" ); 303 for( $x = $year_start;$x <= $year_end;$x++ ) { 304 $values[$x] = $x; 305 } 306 $data .= $this->select_tag( $prefix . "year", $values, $year ); 307 308 return $data; 309 } 310 311 function text_box( $name, $value, $size = 0, $maxlength = 0, $password = false, $extra = "" ) 312 { 313 $type = ( $password ) ? "password" : "text"; 314 $data = "<input type=\"$type\" name=\"$name\""; 315 if ( $size > 0 ) $data .= " size=\"$size\""; 316 if ( $maxlength > 0 ) $data .= " maxlength=\"$maxlength\""; 317 $value = htmlspecialchars( $value ); 318 $data .= " value=\"$value\" $extra>"; 319 320 return $data; 321 } 322 323 function textarea( $name, $value, $cols = 30, $rows = 5, $extra = "" ) 324 { 325 $value = htmlspecialchars( $value ); 326 $data = "<textarea name=\"$name\" cols=\"$cols\" rows=\"$rows\" $extra>$value</textarea>"; 327 328 return $data; 329 } 330 331 function select_tag( $name, $values, $selected = "", $extra = "" ) 332 { 333 $data = "<select name=\"$name\" $extra>\n"; 334 foreach( $values as $value => $text ) { 335 $value = htmlspecialchars( $value ); 336 $text = htmlspecialchars( $text ); 337 $data .= "<option value=\"$value\""; 338 if ( $value == $selected ) $data .= " selected=\"selected\""; 339 $data .= ">$text</option>\n"; 340 } 341 $data .= "</select>\n"; 342 return $data; 343 } 344 345 function select_tag_valaskey( $name, $values, $selected = "", $extra = "" ) 346 { 347 $data = "<select name=\"$name\" $extra>\n"; 348 foreach( $values as $value => $text ) { 349 $data .= "<option value=\"$text\""; 350 $text = htmlspecialchars( $text ); 351 if ( $text == $selected ) $data .= " selected"; 352 $data .= ">$text</option>\n"; 353 } 354 $data .= "</select>\n"; 355 return $data; 356 } 357 358 function radio_button( $name, $values, $selected = "", $separator = " ", $extra = "" ) 359 { 360 foreach( $values as $value => $text ) { 361 $value = htmlspecialchars( $value ); 362 $text = htmlspecialchars( $text ); 363 $data .= "<input type=\"radio\" name=\"$name\" value=\"$value\""; 364 if ( $selected == $value ) $data .= " checked"; 365 $data .= " $extra> $text$separator"; 366 } 367 return $data; 368 } 369 370 function checkbox( $name, $value, $caption, $checked = 0, $extra = "" ) 371 { 372 $is_checked = ( !empty( $checked ) ) ? "checked" : "" ; 373 374 $value = htmlspecialchars( $value ); 375 376 $data = "<nobr><input type=\"checkbox\" name=\"$name\" value=\"$value\" $is_checked $extra> $caption</nobr>"; 377 378 return $data; 379 } 380 381 // $list and $checklist are both associative and should have the same indicies 382 function checkbox_list( $prefix, $list, $separator = " ", $checklist = 0 ) 383 { 384 // Get the listing of options to check into a array function library usable format 385 if ( empty( $checklist ) ) { 386 $checked_items = array(); 387 } else { 388 if ( !is_array( $checklist ) ) { 389 $checked_items = array( $checklist ); 390 } else { 391 $checked_items = $checklist; 392 } 393 } 394 // Loop through all the array elements and call function to generate the appropriate input tag 395 foreach( $list as $index => $info ) { 396 $check_name = $prefix . "[" . $index . "]"; 397 $check_value = $info["value"]; 398 $check_caption = $info["caption"]; 399 $is_checked = ( in_array( $check_value, $checked_items ) ) ? 1 : 0; 400 401 $data .= $this->checkbox( $check_name, $check_value, $check_caption, $is_checked ) . $separator; 402 } 403 404 return $data; 405 } 406 407 } 408 409 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:22:27 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |