2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2003 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.0 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
17 // | Bertrand Mansion <bmansion@mamasam.com> |
18 // +----------------------------------------------------------------------+
22 require_once('HTML/QuickForm/element.php');
23 require_once('HTML/QuickForm/radio.php');
24 require_once('MLIB/defaults.php');
25 require_once 'MLIB/HTML/Image.php';
27 * Class to dynamically create HTML Select elements from a date
29 * @author Bertrand Mansion <bmansion@mamasam.com>
32 class MLIB_HTML_QuickForm_caritas extends HTML_QuickForm_element {
36 * Contains the select objects
40 var $radios = array();
43 * Default values of the SELECTs
47 var $_selected = null;
53 * Frozen flag tells if element is frozen or not
57 var $_flagFrozen = false;
61 * Lista archivos devolviendo un array apropiado para un SELECT.
63 * @param string $dir Directorio donde estan las imagenes.
64 * @param string $prepend Prefijo del archivo.
65 * @param string $append Postfijo del archivo.
69 function listarArchivos($dir = '.', $prepend = '', $append = '') // ~X2C
73 while (($file = $d->read()) !== false) {
74 if (preg_match("/$prepend(.*)$append/", $file, $m)) {
87 * @param string $elementName (optional)Input field name attribute
88 * @param string $value (optional)Input field value
89 * @param mixed $attributes (optional)Either a typical HTML attribute string
90 * or an associative array. Date format is passed along the attributes.
95 function MLIB_HTML_QuickForm_caritas($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
96 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
97 $this->_persistantFreeze = true;
98 $this->_type = 'caritas';
99 $this->_setDefaults($options);
103 // {{{ _setDefaults()
106 * sets the defaults options
107 * Current options are:
113 * @param array $options array of options
117 function _setDefaults($options) {
118 if (isset($options['cols'])) {
119 $this->setCols($options['cols']);
121 /* if (isset($options['language'])) {
122 $this->setLanguage($options['language']);
124 if (isset($options['minYear'])) {
125 $this->setMinYear($options['minYear']);
127 if (isset($options['maxYear'])) {
128 $this->setMaxYear($options['maxYear']);
131 } // end func _setDefaults
137 * Sets the number of cols (columns)
138 * @param string $name Input field name attribute
142 function setCols($cols) {
143 $this->_cols = $cols;
147 * Sets the input field name
148 * @param string $name Input field name attribute
152 function setName($name) {
160 * Sets the element value
164 function setValue($value) {
165 $this->_selected = $value;
169 * Sets the element value
173 function setSelected($value) {
174 $this->_selected = $value;
178 * Returns the element value
182 function getValue() {
183 return $this->_selected;
187 * Returns the element value
191 function getSelected() {
192 return $this->_selected;
196 * Returns the element name
205 // {{{ _createSelects()
208 * Creates the select objects
212 function _createRadios() {
213 $this->caritas= array();
214 $elementName = $this->name;
215 $dir = MLIB_DIR_FS_IMG.'/caritas';
218 foreach ($this->listarArchivos($dir,'','.gif') as $nombre) {
219 $this->radios[$nombre] = &new HTML_QuickForm_radio($elementName, '', '', $nombre, $this->getAttributes());
221 } // end func _createSelects
224 // {{{ _createNumericOptionList()
229 * Returns the SELECT in HTML
235 $this->_createRadios();
238 foreach ($this->radios as $nombre => $element) {
239 if (@$this->_selected == $nombre) {
240 $element->setChecked(true);
242 if ($this->_flagFrozen) {
243 if (is_string($element)) {
244 $strHtml .= str_replace(' ', ' ', $element);
246 $strHtml .= $element->getFrozenHtml();
249 if (is_string($element)) {
250 $strHtml .= str_replace(' ', ' ', $element);
252 $strHtml .= $element->toHtml();
255 $imagen =& new MLIB_HTML_Image(MLIB_DIR_IMG."/caritas/$nombre");
256 $strHtml .= ' ' . $imagen->toHtml() . ' ';
257 if (!($i++ % $this->_cols))
264 // {{{ onQuickFormEvent()
267 * Called by HTML_QuickForm whenever form event is made on this element
269 * @param string $event Name of event
270 * @param mixed $arg event arguments
271 * @param object $caller calling object
277 function onQuickFormEvent($event, $arg, &$caller) {
280 // constant values override both default and submitted ones
281 // default values are overriden by submitted
282 $value = $this->_findValue($caller->_constantValues);
283 if (null === $value) {
284 $value = $this->_findValue($caller->_submitValues);
285 if (null === $value) {
286 $value = $this->_findValue($caller->_defaultValues);
289 if (null !== $value) {
290 $this->setSelected($value);
293 case 'setGroupValue':
294 $this->setSelected($arg);
297 parent::onQuickFormEvent($event, $arg, $caller);
300 } // end func onQuickFormEvent
303 } // end class HTML_QuickForm_date