[ 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 series of HTML <option>s. 11 * 12 * $Id: Savant2_Plugin_options.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_options extends Savant2_Plugin { 33 34 35 /** 36 * 37 * Outputs a series of HTML <option>s. 38 * 39 * Outputs a series of HTML <option>s based on an associative array 40 * where the key is the option value and the value is the option 41 * label. You can pass a "selected" value as well to tell the 42 * function which option value(s) should be marked as selected. 43 * 44 * @access public 45 * 46 * @param array $options An associative array of key-value pairs; the 47 * key is the option value, the value is the option label. 48 * 49 * @param string|array $selected A string or array that matches one 50 * or more option values, to tell the function what options should be 51 * marked as selected. Defaults to an empty array. 52 * 53 * @param string|array $attr Extra attributes to apply to the option 54 * tag. If a string, they are added as-is; if an array, the key is 55 * the attribute name and the value is the attribute value. 56 * 57 * @return string A set of HTML <option> tags. 58 * 59 */ 60 61 function plugin($options, $selected = array(), $attr = null, 62 $labelIsValue = false) 63 { 64 $html = ''; 65 66 // force $selected to be an array. this allows multi-selects to 67 // have multiple selected options. 68 settype($selected, 'array'); 69 settype($options, 'array'); 70 71 // loop through the options array 72 foreach ($options as $value => $label) { 73 74 // is the label being used as the value? 75 if ($labelIsValue) { 76 $value = $label; 77 } 78 79 // set the value and label in the tag 80 $html .= '<option value="' . htmlspecialchars($value) . '"'; 81 $html .= ' label="' . htmlspecialchars($label) . '"'; 82 83 // is the option one of the selected values? 84 if (in_array($value, $selected)) { 85 $html .= ' selected="selected"'; 86 } 87 88 // are we adding extra attributes? 89 if (is_array($attr)) { 90 // yes, from an array 91 foreach ($attr as $key => $val) { 92 $val = htmlspecialchars($val); 93 $html .= " $key=\"$val\""; 94 } 95 } elseif (! is_null($attr)) { 96 // yes, from a string 97 $html .= ' ' . $attr; 98 } 99 100 // add the label and close the tag 101 $html .= '>' . htmlspecialchars($label) . "</option>\n"; 102 } 103 104 return $html; 105 } 106 } 107 ?>
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 |