| // | Bertrand Mansion | // +----------------------------------------------------------------------+ // // $Id$ require_once('HTML/QuickForm/element.php'); require_once('HTML/QuickForm/radio.php'); require_once('MLIB/defaults.php'); require_once 'MLIB/HTML/Image.php'; /** * Class to dynamically create HTML Select elements from a date * * @author Bertrand Mansion * @access public */ class MLIB_HTML_QuickForm_caritas extends HTML_QuickForm_element { // {{{ properties /** * Contains the select objects * @var array * @access private */ var $radios = array(); /** * Default values of the SELECTs * @var array * @access private */ var $_selected = null; var $_cols = 5; /** * Frozen flag tells if element is frozen or not * @var bool * @access private */ var $_flagFrozen = false; // +X2C Operation 533 /** * Lista archivos devolviendo un array apropiado para un SELECT. * * @param string $dir Directorio donde estan las imagenes. * @param string $prepend Prefijo del archivo. * @param string $append Postfijo del archivo. * * @return array */ function listarArchivos($dir = '.', $prepend = '', $append = '') // ~X2C { $lista = array(); $d = dir($dir); while (($file = $d->read()) !== false) { if (preg_match("/$prepend(.*)$append/", $file, $m)) { $lista[] = $file; } } return $lista; } // -X2C // }}} // {{{ constructor /** * Class constructor * * @param string $elementName (optional)Input field name attribute * @param string $value (optional)Input field value * @param mixed $attributes (optional)Either a typical HTML attribute string * or an associative array. Date format is passed along the attributes. * @access public * @return void */ function MLIB_HTML_QuickForm_caritas($elementName=null, $elementLabel=null, $options=array(), $attributes=null) { HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'caritas'; $this->_setDefaults($options); } //end constructor // }}} // {{{ _setDefaults() /** * sets the defaults options * Current options are: * - format * - minYear * - maxYear * - language * * @param array $options array of options * @access private * @return void */ function _setDefaults($options) { if (isset($options['cols'])) { $this->setCols($options['cols']); } /* if (isset($options['language'])) { $this->setLanguage($options['language']); } if (isset($options['minYear'])) { $this->setMinYear($options['minYear']); } if (isset($options['maxYear'])) { $this->setMaxYear($options['maxYear']); } */ } // end func _setDefaults // }}} // {{{ setName() /** * Sets the number of cols (columns) * @param string $name Input field name attribute * @access public * @return void */ function setCols($cols) { $this->_cols = $cols; } //end func setCols /** * Sets the input field name * @param string $name Input field name attribute * @access public * @return void */ function setName($name) { $this->name = $name; } //end func setName // }}} // {{{ getName() /** * Sets the element value * @access public * @return string */ function setValue($value) { $this->_selected = $value; } //end func getName /** * Sets the element value * @access public * @return string */ function setSelected($value) { $this->_selected = $value; } //end func getName /** * Returns the element value * @access public * @return string */ function getValue() { return $this->_selected; } //end func getName /** * Returns the element value * @access public * @return string */ function getSelected() { return $this->_selected; } //end func getName /** * Returns the element name * @access public * @return string */ function getName() { return $this->name; } //end func getName // {{{ _createSelects() /** * Creates the select objects * @access public * @return void */ function _createRadios() { $this->caritas= array(); $elementName = $this->name; $dir = MLIB_DIR_FS_IMG.'/caritas'; $cant=5; $i=1; foreach ($this->listarArchivos($dir,'','.gif') as $nombre) { $this->radios[$nombre] = &new HTML_QuickForm_radio($elementName, '', '', $nombre, $this->getAttributes()); } } // end func _createSelects // }}} // {{{ _createNumericOptionList() // {{{ toHtml() /** * Returns the SELECT in HTML * @access public * @return string * @throws */ function toHtml() { $this->_createRadios(); $strHtml = ''; $i = 1; foreach ($this->radios as $nombre => $element) { if (@$this->_selected == $nombre) { $element->setChecked(true); } if ($this->_flagFrozen) { if (is_string($element)) { $strHtml .= str_replace(' ', ' ', $element); } else { $strHtml .= $element->getFrozenHtml(); } } else { if (is_string($element)) { $strHtml .= str_replace(' ', ' ', $element); } else { $strHtml .= $element->toHtml(); } } $imagen =& new MLIB_HTML_Image(MLIB_DIR_IMG."/caritas/$nombre"); $strHtml .= ' ' . $imagen->toHtml() . '     '; if (!($i++ % $this->_cols)) $strHtml .= '
'; } return $strHtml; } // end func toHtml // }}} // {{{ onQuickFormEvent() /** * Called by HTML_QuickForm whenever form event is made on this element * * @param string $event Name of event * @param mixed $arg event arguments * @param object $caller calling object * @since 1.0 * @access public * @return void * @throws */ function onQuickFormEvent($event, $arg, &$caller) { switch ($event) { case 'updateValue': // constant values override both default and submitted ones // default values are overriden by submitted $value = $this->_findValue($caller->_constantValues); if (null === $value) { $value = $this->_findValue($caller->_submitValues); if (null === $value) { $value = $this->_findValue($caller->_defaultValues); } } if (null !== $value) { $this->setSelected($value); } break; case 'setGroupValue': $this->setSelected($arg); break; default: parent::onQuickFormEvent($event, $arg, $caller); } return true; } // end func onQuickFormEvent // }}} } // end class HTML_QuickForm_date ?>