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['format'])) {
122 $this->setFormat($options['format']);
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 input field name
141 * @param string $name Input field name attribute
145 function setName($name)
154 * Sets the element value
158 function setValue($value)
160 $this->_selected = $value;
164 * Sets the element value
168 function setSelected($value)
170 $this->_selected = $value;
174 * Returns the element value
180 return $this->_selected;
184 * Returns the element value
188 function getSelected()
190 return $this->_selected;
194 * Returns the element name
204 // {{{ _createSelects()
207 * Creates the select objects
211 function _createRadios()
213 $this->caritas= array();
214 $elementName = $this->name;
215 $dir = MECON_DIR_FS_IMG.'/caritas';
218 foreach ($this->listarArchivos($dir,'','.gif') as $nombre)
220 $this->radios[$nombre] = &new HTML_QuickForm_radio($elementName, '', '', $nombre, $this->getAttributes());
222 } // end func _createSelects
225 // {{{ _createNumericOptionList()
230 * Returns the SELECT in HTML
237 $this->_createRadios();
240 foreach ($this->radios as $nombre => $element) {
241 if (@$this->_selected == $nombre) {
242 $element->setChecked(true);
244 if ($this->_flagFrozen) {
245 if (is_string($element)) {
246 $strHtml .= str_replace(' ', ' ', $element);
248 $strHtml .= $element->getFrozenHtml();
251 if (is_string($element)) {
252 $strHtml .= str_replace(' ', ' ', $element);
254 $strHtml .= $element->toHtml();
257 $imagen =& new HTML_Image(MECON_DIR_IMG."/caritas/$nombre");
258 $strHtml .= ' ' . $imagen->toHtml() . ' ';
259 if (!($i++ % $this->_numRows))
266 // {{{ onQuickFormEvent()
269 * Called by HTML_QuickForm whenever form event is made on this element
271 * @param string $event Name of event
272 * @param mixed $arg event arguments
273 * @param object $caller calling object
279 function onQuickFormEvent($event, $arg, &$caller)
283 // constant values override both default and submitted ones
284 // default values are overriden by submitted
285 $value = $this->_findValue($caller->_constantValues);
286 if (null === $value) {
287 $value = $this->_findValue($caller->_submitValues);
288 if (null === $value) {
289 $value = $this->_findValue($caller->_defaultValues);
292 if (null !== $value) {
293 $this->setSelected($value);
296 case 'setGroupValue':
297 $this->setSelected($arg);
300 parent::onQuickFormEvent($event, $arg, $caller);
303 } // end func onQuickFormEvent
306 } // end class HTML_QuickForm_date