[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 /** 4 * Base plugin class. 5 */ 6 require_once 'Savant2/Plugin.php'; 7 8 /** 9 * 10 * Outputs a single checkbox <input> element. 11 * 12 * $Id: Savant2_Plugin_checkbox.php 18360 2005-05-26 19:38:09Z mipmip $ 13 * 14 * @author Paul M. Jones <pmjones@ciaweb.net> 15 * 16 * @package Savant2 17 * 18 * @license http://www.gnu.org/copyleft/lesser.html LGPL 19 * 20 * This program is free software; you can redistribute it and/or modify 21 * it under the terms of the GNU Lesser General Public License as 22 * published by the Free Software Foundation; either version 2.1 of the 23 * License, or (at your option) any later version. 24 * 25 * This program is distributed in the hope that it will be useful, but 26 * WITHOUT ANY WARRANTY; without even the implied warranty of 27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 28 * Lesser General Public License for more details. 29 * 30 */ 31 32 class Savant2_Plugin_checkbox extends Savant2_Plugin { 33 34 /** 35 * 36 * Outputs a single checkbox <input> element. 37 * 38 * @access public 39 * 40 * @param string $name The HTML "name=" value for the checkbox. 41 * 42 * @param string $value The value of the checkbox when checked. 43 * 44 * @param array $checked If $value is in this array of values, 45 * mark the checkbox as checked. 46 * 47 * @param array $default The value to return if the checkbox is not 48 * checked. 49 * 50 * @param string|array $attr Any extra HTML attributes to place 51 * within the checkbox element. 52 * 53 * @return string 54 * 55 */ 56 57 function plugin( 58 $name, 59 $value = '1', 60 $checked = null, 61 $default = null, 62 $attr = null) 63 { 64 $html = ''; 65 66 // define the hidden default value (if any) when not checked 67 if (! is_null($default)) { 68 $html .= '<input type="hidden"'; 69 $html .= ' name="' . htmlspecialchars($name) . '"'; 70 $html .= ' value="' .htmlspecialchars($default) . '" />'; 71 $html .= "\n"; 72 } 73 74 // start the checkbox tag with name and value 75 $html .= '<input type="checkbox"'; 76 $html .= ' name="' . htmlspecialchars($name) . '"'; 77 $html .= ' value="' . htmlspecialchars($value) . '"'; 78 79 // is the checkbox checked? 80 settype($checked, 'array'); 81 if (in_array($value, $checked)) { 82 $html .= ' checked="checked"'; 83 } 84 85 // add extra attributes 86 if (is_array($attr)) { 87 // add from array 88 foreach ($attr as $key => $val) { 89 $key = htmlspecialchars($key); 90 $val = htmlspecialchars($val); 91 $html .= " $key=\"$val\""; 92 } 93 } elseif (! is_null($attr)) { 94 // add from scalar 95 $html .= " $attr"; 96 } 97 98 // close the checkbox tag and return 99 $html .= ' />'; 100 return $html; 101 } 102 } 103 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |