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('MECON/defaults.php');
25 require_once('HTML/Image.php');
27 * Class to dynamically create HTML Select elements from a date
29 * @author Bertrand Mansion <bmansion@mamasam.com>
32 class HTML_QuickForm_caritas extends HTML_QuickForm_element
37 * Contains the select objects
41 var $radios = array();
44 * Default values of the SELECTs
48 var $_selected = null;
54 * Frozen flag tells if element is frozen or not
58 var $_flagFrozen = false;
62 * Lista archivos devolviendo un array apropiado para un SELECT.
64 * @param string $dir Directorio donde estan las imagenes.
65 * @param string $prepend Prefijo del archivo.
66 * @param string $append Postfijo del archivo.
70 function listarArchivos($dir = '.', $prepend = '', $append = '') // ~X2C
74 while (($file = $d->read()) !== false) {
75 if (preg_match("/$prepend(.*)$append/", $file, $m)) {
88 * @param string $elementName (optional)Input field name attribute
89 * @param string $value (optional)Input field value
90 * @param mixed $attributes (optional)Either a typical HTML attribute string
91 * or an associative array. Date format is passed along the attributes.
96 function HTML_QuickForm_caritas($elementName=null, $elementLabel=null, $options=array(), $attributes=null)
98 HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
99 $this->_persistantFreeze = true;
100 $this->_type = 'caritas';
101 $this->_setDefaults($options);
105 // {{{ _setDefaults()
108 * sets the defaults options
109 * Current options are:
115 * @param array $options array of options
119 function _setDefaults($options)
121 if (isset($options['cols'])) {
122 $this->setCols($options['cols']);
124 /* if (isset($options['language'])) {
125 $this->setLanguage($options['language']);
127 if (isset($options['minYear'])) {
128 $this->setMinYear($options['minYear']);
130 if (isset($options['maxYear'])) {
131 $this->setMaxYear($options['maxYear']);
134 } // end func _setDefaults
140 * Sets the number of cols (columns)
141 * @param string $name Input field name attribute
145 function setCols($cols)
147 $this->_cols = $cols;
151 * Sets the input field name
152 * @param string $name Input field name attribute
156 function setName($name)
165 * Sets the element value
169 function setValue($value)
171 $this->_selected = $value;
175 * Sets the element value
179 function setSelected($value)
181 $this->_selected = $value;
185 * Returns the element value
191 return $this->_selected;
195 * Returns the element value
199 function getSelected()
201 return $this->_selected;
205 * Returns the element name
215 // {{{ _createSelects()
218 * Creates the select objects
222 function _createRadios()
224 $this->caritas= array();
225 $elementName = $this->name;
226 $dir = MECON_DIR_FS_IMG.'/caritas';
229 foreach ($this->listarArchivos($dir,'','.gif') as $nombre)
231 $this->radios[$nombre] = &new HTML_QuickForm_radio($elementName, '', '', $nombre, $this->getAttributes());
233 } // end func _createSelects
236 // {{{ _createNumericOptionList()
241 * Returns the SELECT in HTML
248 $this->_createRadios();
251 foreach ($this->radios as $nombre => $element) {
252 if (@$this->_selected == $nombre) {
253 $element->setChecked(true);
255 if ($this->_flagFrozen) {
256 if (is_string($element)) {
257 $strHtml .= str_replace(' ', ' ', $element);
259 $strHtml .= $element->getFrozenHtml();
262 if (is_string($element)) {
263 $strHtml .= str_replace(' ', ' ', $element);
265 $strHtml .= $element->toHtml();
268 $imagen =& new HTML_Image(MECON_DIR_IMG."/caritas/$nombre");
269 $strHtml .= ' ' . $imagen->toHtml() . ' ';
270 if (!($i++ % $this->_cols))
277 // {{{ onQuickFormEvent()
280 * Called by HTML_QuickForm whenever form event is made on this element
282 * @param string $event Name of event
283 * @param mixed $arg event arguments
284 * @param object $caller calling object
290 function onQuickFormEvent($event, $arg, &$caller)
294 // constant values override both default and submitted ones
295 // default values are overriden by submitted
296 $value = $this->_findValue($caller->_constantValues);
297 if (null === $value) {
298 $value = $this->_findValue($caller->_submitValues);
299 if (null === $value) {
300 $value = $this->_findValue($caller->_defaultValues);
303 if (null !== $value) {
304 $this->setSelected($value);
307 case 'setGroupValue':
308 $this->setSelected($arg);
311 parent::onQuickFormEvent($event, $arg, $caller);
314 } // end func onQuickFormEvent
317 } // end class HTML_QuickForm_date