[ 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 set of radio <input>s with the same name. 11 * 12 * $Id: Savant2_Plugin_radios.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_radios extends Savant2_Plugin { 33 34 35 /** 36 * 37 * Outputs a set of radio <input>s with the same name. 38 * 39 * @access public 40 * 41 * @param string $name The HTML "name=" value of all the radio <input>s. 42 * 43 * @param array $radios An array of key-value pairs where the key is the 44 * radio button value and the value is the radio button label. 45 * 46 * @param string $checked A comparison string; if any of the $option 47 * element values and $checked are the same, that radio button will 48 * be marked as "checked" (otherwise not). 49 * 50 * @param array $default The value to return if no radio buttons are 51 * checked. 52 * 53 * @param string|array $attr Any extra HTML attributes to place 54 * within the checkbox element. 55 * 56 * @param string $sep The HTML text to place between every radio 57 * button in the set. 58 * 59 * @return string 60 * 61 */ 62 63 function plugin( 64 $name, 65 $radios, 66 $checked = null, 67 $default = null, 68 $sep = "<br />\n", 69 $attr = null, 70 $labelIsValue = false 71 ) 72 { 73 settype($radios, 'array'); 74 $html = ''; 75 76 // define the hidden default value (if any) when no buttons are checked 77 if (! is_null($default)) { 78 $html .= '<input type="hidden"'; 79 $html .= ' name="' . htmlspecialchars($name) . '"'; 80 $html .= ' value="' . htmlspecialchars($default) . '" />'; 81 $html .= "\n"; 82 } 83 84 // the array of individual radio buttons 85 $radio = array(); 86 87 // build the full set of radio buttons 88 foreach ($radios as $value => $label) { 89 90 // reset to blank HTML for this radio button 91 $tmp = ''; 92 93 // is the label being used as the value? 94 if ($labelIsValue) { 95 $value = $label; 96 } 97 98 // start the radio button tag 99 $tmp .= '<input type="radio"'; 100 $tmp .= ' name="' . htmlspecialchars($name) . '"'; 101 $tmp .= ' value="' . htmlspecialchars($value) . '"'; 102 103 // is the radio button selected? 104 if ($value == $checked) { 105 $tmp .= ' checked="checked"'; 106 } 107 108 // add extra attributes 109 if (is_array($attr)) { 110 // add from array 111 foreach ($attr as $key => $val) { 112 $key = htmlspecialchars($key); 113 $val = htmlspecialchars($val); 114 $tmp .= " $key=\"$val\""; 115 } 116 } elseif (! is_null($attr)) { 117 // add from scalar 118 $tmp .= " $attr"; 119 } 120 121 // add the label and save the button in the array 122 $tmp .= ' />' . htmlspecialchars($label); 123 $radio[] = $tmp; 124 } 125 126 // return the radio buttons with separators 127 return $html . implode($sep, $radio); 128 } 129 } 130 ?>
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 |