diff options
author | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
---|---|---|
committer | matt <matt@59fd770c-687e-43c8-a1e3-f5a4ff64c105> | 2010-06-23 07:45:36 +0400 |
commit | 7e1b5d6b762340cbff1bb928d15815980c7649a7 (patch) | |
tree | e07da179b9e1372866d2349777bd1cc6b4c9e8cf /libs/HTML/QuickForm | |
parent | 999f46479294713104c962bfe7469e9b6e7a4bbf (diff) | |
parent | c98ea06f2cccec81c6ccce49162a583494e44d91 (diff) |
Diffstat (limited to 'libs/HTML/QuickForm')
40 files changed, 194 insertions, 70 deletions
diff --git a/libs/HTML/QuickForm/Renderer/Array.php b/libs/HTML/QuickForm/Renderer/Array.php index 28f5893102..dfb04647f5 100644 --- a/libs/HTML/QuickForm/Renderer/Array.php +++ b/libs/HTML/QuickForm/Renderer/Array.php @@ -27,7 +27,7 @@ /** * An abstract base class for QuickForm renderers */ -require_once 'HTML/QuickForm/Renderer.php'; +require_once dirname(__FILE__) . '/../Renderer.php'; /** * A concrete renderer for HTML_QuickForm, makes an array of form contents @@ -337,4 +337,4 @@ class HTML_QuickForm_Renderer_Array extends HTML_QuickForm_Renderer } } } -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Renderer/ArraySmarty.php b/libs/HTML/QuickForm/Renderer/ArraySmarty.php index 89b59e7dee..d7433d0150 100644 --- a/libs/HTML/QuickForm/Renderer/ArraySmarty.php +++ b/libs/HTML/QuickForm/Renderer/ArraySmarty.php @@ -27,7 +27,7 @@ /** * A concrete renderer for HTML_QuickForm, makes an array of form contents */ -require_once 'HTML/QuickForm/Renderer/Array.php'; +require_once dirname(__FILE__) . '/Array.php'; /** * A static renderer for HTML_QuickForm, makes an array of form content @@ -400,4 +400,4 @@ class HTML_QuickForm_Renderer_ArraySmarty extends HTML_QuickForm_Renderer_Array $this->_error = $template; } // end func setErrorTemplate } -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Renderer/Default.php b/libs/HTML/QuickForm/Renderer/Default.php index 0801105ba8..0ec24a6454 100644 --- a/libs/HTML/QuickForm/Renderer/Default.php +++ b/libs/HTML/QuickForm/Renderer/Default.php @@ -26,7 +26,7 @@ /** * An abstract base class for QuickForm renderers */ -require_once 'HTML/QuickForm/Renderer.php'; +require_once dirname(__FILE__) . '/../Renderer.php'; /** * A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one diff --git a/libs/HTML/QuickForm/Renderer/ITDynamic.php b/libs/HTML/QuickForm/Renderer/ITDynamic.php index f554203dfa..de0dec577b 100644 --- a/libs/HTML/QuickForm/Renderer/ITDynamic.php +++ b/libs/HTML/QuickForm/Renderer/ITDynamic.php @@ -24,7 +24,7 @@ /** * An abstract base class for QuickForm renderers */ -require_once 'HTML/QuickForm/Renderer.php'; +require_once dirname(__FILE__) . '/../Renderer.php'; /** * A concrete renderer for HTML_QuickForm, using Integrated Templates. diff --git a/libs/HTML/QuickForm/Renderer/ITStatic.php b/libs/HTML/QuickForm/Renderer/ITStatic.php index 56c9d1fed2..94be06a1d5 100644 --- a/libs/HTML/QuickForm/Renderer/ITStatic.php +++ b/libs/HTML/QuickForm/Renderer/ITStatic.php @@ -25,7 +25,7 @@ /** * An abstract base class for QuickForm renderers */ -require_once 'HTML/QuickForm/Renderer.php'; +require_once dirname(__FILE__) . '/../Renderer.php'; /** * A static renderer for HTML_QuickForm compatible @@ -501,4 +501,4 @@ class HTML_QuickForm_Renderer_ITStatic extends HTML_QuickForm_Renderer return $ret; } } // end class HTML_QuickForm_Renderer_ITStatic -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Renderer/Object.php b/libs/HTML/QuickForm/Renderer/Object.php index eb84fd78e6..9613931835 100644 --- a/libs/HTML/QuickForm/Renderer/Object.php +++ b/libs/HTML/QuickForm/Renderer/Object.php @@ -24,7 +24,7 @@ /** * An abstract base class for QuickForm renderers */ -require_once 'HTML/QuickForm/Renderer.php'; +require_once dirname(__FILE__) . '/../Renderer.php'; /** * A concrete renderer for HTML_QuickForm, makes an object from form contents @@ -138,7 +138,10 @@ class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer { $hobj = new StdClass; $hobj->header = $header->toHtml(); - $this->_obj->sections[$this->_sectionCount] = $hobj; + // $this->_obj->sections[$this->_sectionCount] = $hobj; + $tmp = $this->_obj->sections; + $tmp[$this->_sectionCount] = $hobj; + $this->_obj->sections = $tmp; $this->_currentSection = $this->_sectionCount++; } @@ -231,11 +234,24 @@ class HTML_QuickForm_Renderer_Object extends HTML_QuickForm_Renderer { $name = $elObj->name; if(is_object($this->_currentGroup) && $elObj->type != 'group') { - $this->_currentGroup->elements[] = $elObj; + // $this->_currentGroup->elements[] = $elObj; + $tmp = $this->_currentGroup->elements; + $tmp[] = $elObj; + $this->_currentGroup->elements = $tmp; } elseif (isset($this->_currentSection)) { - $this->_obj->sections[$this->_currentSection]->elements[] = $elObj; + // $this->_obj->sections[$this->_currentSection]->elements[] = $elObj; + $tmpSections = $this->_obj->sections; + $tmpCurrentSection = $tmpSections[$this->_currentSection]; + $tmpElements = $tmpCurrentSection->elements; + $tmpElements[] = $elObj; + $tmpCurrentSection->elements = $tmpElements; + $tmpSections[$this->_currentSection] = $tmpCurrentSection; + $this->_obj->sections = $tmpSections; } else { - $this->_obj->elements[] = $elObj; + // $this->_obj->elements[] = $elObj; + $tmp = $this->_obj->elements; + $tmp[] = $elObj; + $this->_obj->elements = $tmp; } } diff --git a/libs/HTML/QuickForm/Renderer/ObjectFlexy.php b/libs/HTML/QuickForm/Renderer/ObjectFlexy.php index 6a232ca04e..37d45e38d6 100644 --- a/libs/HTML/QuickForm/Renderer/ObjectFlexy.php +++ b/libs/HTML/QuickForm/Renderer/ObjectFlexy.php @@ -24,7 +24,7 @@ /** * A concrete renderer for HTML_QuickForm, makes an object from form contents */ -require_once 'HTML/QuickForm/Renderer/Object.php'; +require_once dirname(__FILE__) . '/Object.php'; /** * QuickForm renderer for Flexy template engine, static version. @@ -116,7 +116,10 @@ class HTML_QuickForm_Renderer_ObjectFlexy extends HTML_QuickForm_Renderer_Object if($name = $header->getName()) { $this->_obj->header->$name = $header->toHtml(); } else { - $this->_obj->header[$this->_sectionCount] = $header->toHtml(); + // $this->_obj->header[$this->_sectionCount] = $header->toHtml(); + $tmp = $this->_obj->header; + $tmp[$this->_sectionCount] = $header->toHtml(); + $this->_obj->header = $tmp; } $this->_currentSection = $this->_sectionCount++; } // end func renderHeader diff --git a/libs/HTML/QuickForm/Renderer/QuickHtml.php b/libs/HTML/QuickForm/Renderer/QuickHtml.php index ca067daa70..f71d3c109b 100644 --- a/libs/HTML/QuickForm/Renderer/QuickHtml.php +++ b/libs/HTML/QuickForm/Renderer/QuickHtml.php @@ -24,7 +24,7 @@ /** * A concrete renderer for HTML_QuickForm, based on QuickForm 2.x built-in one */ -require_once 'HTML/QuickForm/Renderer/Default.php'; +require_once dirname(__FILE__) . '/Default.php'; /** * A renderer that makes it quick and easy to create customized forms. diff --git a/libs/HTML/QuickForm/Rule/Callback.php b/libs/HTML/QuickForm/Rule/Callback.php index d6e9eab35e..8796dedaa0 100644 --- a/libs/HTML/QuickForm/Rule/Callback.php +++ b/libs/HTML/QuickForm/Rule/Callback.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Validates values using callback functions or methods @@ -121,4 +121,4 @@ class HTML_QuickForm_Rule_Callback extends HTML_QuickForm_Rule } // end func getValidationScript } // end class HTML_QuickForm_Rule_Callback -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Rule/Compare.php b/libs/HTML/QuickForm/Rule/Compare.php index df4f86b795..6eeda4b65e 100644 --- a/libs/HTML/QuickForm/Rule/Compare.php +++ b/libs/HTML/QuickForm/Rule/Compare.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Rule to compare two form fields diff --git a/libs/HTML/QuickForm/Rule/Email.php b/libs/HTML/QuickForm/Rule/Email.php index 6f79653378..d9fc49ec62 100644 --- a/libs/HTML/QuickForm/Rule/Email.php +++ b/libs/HTML/QuickForm/Rule/Email.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Email validation rule @@ -70,4 +70,4 @@ class HTML_QuickForm_Rule_Email extends HTML_QuickForm_Rule } // end func getValidationScript } // end class HTML_QuickForm_Rule_Email -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Rule/Range.php b/libs/HTML/QuickForm/Rule/Range.php index 97a8806dc6..e466e3d120 100644 --- a/libs/HTML/QuickForm/Rule/Range.php +++ b/libs/HTML/QuickForm/Rule/Range.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Checks that the length of value is within range @@ -72,4 +72,4 @@ class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule } // end func getValidationScript } // end class HTML_QuickForm_Rule_Range -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Rule/Regex.php b/libs/HTML/QuickForm/Rule/Regex.php index f496a3fb1c..a43aea22dc 100644 --- a/libs/HTML/QuickForm/Rule/Regex.php +++ b/libs/HTML/QuickForm/Rule/Regex.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Validates values using regular expressions @@ -104,4 +104,4 @@ class HTML_QuickForm_Rule_Regex extends HTML_QuickForm_Rule } // end func getValidationScript } // end class HTML_QuickForm_Rule_Regex -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/Rule/Required.php b/libs/HTML/QuickForm/Rule/Required.php index 28ccc604ac..e73af090b0 100644 --- a/libs/HTML/QuickForm/Rule/Required.php +++ b/libs/HTML/QuickForm/Rule/Required.php @@ -24,7 +24,7 @@ /** * Abstract base class for QuickForm validation rules */ -require_once 'HTML/QuickForm/Rule.php'; +require_once dirname(__FILE__) . '/../Rule.php'; /** * Required elements validation diff --git a/libs/HTML/QuickForm/RuleRegistry.php b/libs/HTML/QuickForm/RuleRegistry.php index 89e98144e6..c257fc328d 100644 --- a/libs/HTML/QuickForm/RuleRegistry.php +++ b/libs/HTML/QuickForm/RuleRegistry.php @@ -123,7 +123,7 @@ class HTML_QuickForm_RuleRegistry if (!isset($this->_rules[$class])) { if (!empty($path)) { - include_once($path); + include_once(dirname(__FILE__) . '/../../' . $path); } $this->_rules[$class] = new $class(); } diff --git a/libs/HTML/QuickForm/advcheckbox.php b/libs/HTML/QuickForm/advcheckbox.php index 9951e79885..fada1e70ae 100644 --- a/libs/HTML/QuickForm/advcheckbox.php +++ b/libs/HTML/QuickForm/advcheckbox.php @@ -25,7 +25,7 @@ /** * HTML class for a checkbox type field */ -require_once 'HTML/QuickForm/checkbox.php'; +require_once dirname(__FILE__) . '/checkbox.php'; /** * HTML class for an advanced checkbox type field diff --git a/libs/HTML/QuickForm/autocomplete.php b/libs/HTML/QuickForm/autocomplete.php index 57d1e4311c..0275ceafb1 100644 --- a/libs/HTML/QuickForm/autocomplete.php +++ b/libs/HTML/QuickForm/autocomplete.php @@ -24,7 +24,7 @@ /** * HTML class for a text field */ -require_once 'HTML/QuickForm/text.php'; +require_once dirname(__FILE__) . '/text.php'; /** * HTML class for an autocomplete element diff --git a/libs/HTML/QuickForm/button.php b/libs/HTML/QuickForm/button.php index cae1888c18..d0ee0157f3 100644 --- a/libs/HTML/QuickForm/button.php +++ b/libs/HTML/QuickForm/button.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for an <input type="button" /> elements diff --git a/libs/HTML/QuickForm/checkbox.php b/libs/HTML/QuickForm/checkbox.php index 4cf1de238f..5bfc361a17 100644 --- a/libs/HTML/QuickForm/checkbox.php +++ b/libs/HTML/QuickForm/checkbox.php @@ -26,7 +26,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a checkbox type field diff --git a/libs/HTML/QuickForm/date.php b/libs/HTML/QuickForm/date.php index 5fe3320aba..60811ab347 100644 --- a/libs/HTML/QuickForm/date.php +++ b/libs/HTML/QuickForm/date.php @@ -24,11 +24,11 @@ /** * Class for a group of form elements */ -require_once 'HTML/QuickForm/group.php'; +require_once dirname(__FILE__) . '/group.php'; /** * Class for <select></select> elements */ -require_once 'HTML/QuickForm/select.php'; +require_once dirname(__FILE__) . '/select.php'; /** * Class for a group of elements used to input dates (and times). @@ -494,7 +494,7 @@ class HTML_QuickForm_date extends HTML_QuickForm_group function toHtml() { - include_once('HTML/QuickForm/Renderer/Default.php'); + include_once(dirname(__FILE__) . '/Renderer/Default.php'); $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); parent::accept($renderer); diff --git a/libs/HTML/QuickForm/element.php b/libs/HTML/QuickForm/element.php index 3a5e2b97a6..93761f2740 100644 --- a/libs/HTML/QuickForm/element.php +++ b/libs/HTML/QuickForm/element.php @@ -26,7 +26,7 @@ /** * Base class for all HTML classes */ -require_once 'HTML/Common.php'; +require_once dirname(__FILE__) . '/../Common.php'; /** * Base class for form elements @@ -491,4 +491,4 @@ class HTML_QuickForm_element extends HTML_Common // }}} } // end class HTML_QuickForm_element -?>
\ No newline at end of file +?> diff --git a/libs/HTML/QuickForm/file.php b/libs/HTML/QuickForm/file.php index afdf585962..f271cc5a72 100644 --- a/libs/HTML/QuickForm/file.php +++ b/libs/HTML/QuickForm/file.php @@ -26,7 +26,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; // register file-related rules if (class_exists('HTML_QuickForm')) { diff --git a/libs/HTML/QuickForm/group.php b/libs/HTML/QuickForm/group.php index 6a538ea8f5..9ecda4958d 100644 --- a/libs/HTML/QuickForm/group.php +++ b/libs/HTML/QuickForm/group.php @@ -26,7 +26,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * HTML class for a form element group @@ -298,7 +298,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element */ function toHtml() { - include_once('HTML/QuickForm/Renderer/Default.php'); + include_once(dirname(__FILE__) . '/Renderer/Default.php'); $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); $this->accept($renderer); diff --git a/libs/HTML/QuickForm/header.php b/libs/HTML/QuickForm/header.php index b1bd222003..49b5679fb9 100644 --- a/libs/HTML/QuickForm/header.php +++ b/libs/HTML/QuickForm/header.php @@ -24,7 +24,7 @@ /** * HTML class for static data */ -require_once 'HTML/QuickForm/static.php'; +require_once dirname(__FILE__) . '/static.php'; /** * A pseudo-element used for adding headers to form diff --git a/libs/HTML/QuickForm/hidden.php b/libs/HTML/QuickForm/hidden.php index e0bb7e1d1f..bd77c36ad5 100644 --- a/libs/HTML/QuickForm/hidden.php +++ b/libs/HTML/QuickForm/hidden.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a hidden type element diff --git a/libs/HTML/QuickForm/hiddenselect.php b/libs/HTML/QuickForm/hiddenselect.php index 0c16e96494..56212db090 100644 --- a/libs/HTML/QuickForm/hiddenselect.php +++ b/libs/HTML/QuickForm/hiddenselect.php @@ -24,7 +24,7 @@ /** * Class for <select></select> elements */ -require_once 'HTML/QuickForm/select.php'; +require_once dirname(__FILE__) . '/select.php'; /** * Hidden select pseudo-element diff --git a/libs/HTML/QuickForm/hierselect.php b/libs/HTML/QuickForm/hierselect.php index fa92cc64a4..5889cca2d0 100644 --- a/libs/HTML/QuickForm/hierselect.php +++ b/libs/HTML/QuickForm/hierselect.php @@ -26,11 +26,11 @@ /** * Class for a group of form elements */ -require_once 'HTML/QuickForm/group.php'; +require_once dirname(__FILE__) . '/group.php'; /** * Class for <select></select> elements */ -require_once 'HTML/QuickForm/select.php'; +require_once dirname(__FILE__) . '/select.php'; /** * Hierarchical select element @@ -461,7 +461,7 @@ JAVASCRIPT; $this->_js .= "_hs_defaults['" . $this->_escapeString($this->getName()) . "'] = " . $this->_convertArrayToJavascript($values, false) . ";\n"; } - include_once('HTML/QuickForm/Renderer/Default.php'); + include_once(dirname(__FILE__) . '/Renderer/Default.php'); $renderer = new HTML_QuickForm_Renderer_Default(); $renderer->setElementTemplate('{element}'); parent::accept($renderer); diff --git a/libs/HTML/QuickForm/html.php b/libs/HTML/QuickForm/html.php index 7310f5f150..6cba2dabb2 100644 --- a/libs/HTML/QuickForm/html.php +++ b/libs/HTML/QuickForm/html.php @@ -24,7 +24,7 @@ /** * HTML class for static data */ -require_once 'HTML/QuickForm/static.php'; +require_once dirname(__FILE__) . '/static.php'; /** * A pseudo-element used for adding raw HTML to form diff --git a/libs/HTML/QuickForm/image.php b/libs/HTML/QuickForm/image.php index 52190ec446..d63169aa2b 100644 --- a/libs/HTML/QuickForm/image.php +++ b/libs/HTML/QuickForm/image.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for an <input type="image" /> element diff --git a/libs/HTML/QuickForm/input.php b/libs/HTML/QuickForm/input.php index 354f050f45..01407e0e63 100644 --- a/libs/HTML/QuickForm/input.php +++ b/libs/HTML/QuickForm/input.php @@ -25,7 +25,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * Base class for <input /> form elements diff --git a/libs/HTML/QuickForm/link.php b/libs/HTML/QuickForm/link.php index d5d3d46c1f..7ae6638828 100644 --- a/libs/HTML/QuickForm/link.php +++ b/libs/HTML/QuickForm/link.php @@ -25,7 +25,7 @@ /** * HTML class for static data */ -require_once 'HTML/QuickForm/static.php'; +require_once dirname(__FILE__) . '/static.php'; /** * HTML class for a link type field diff --git a/libs/HTML/QuickForm/password.php b/libs/HTML/QuickForm/password.php index 7c6b3902d3..214b362202 100644 --- a/libs/HTML/QuickForm/password.php +++ b/libs/HTML/QuickForm/password.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a password type field diff --git a/libs/HTML/QuickForm/radio.php b/libs/HTML/QuickForm/radio.php index c9d340fcbb..6f8af6e2f1 100644 --- a/libs/HTML/QuickForm/radio.php +++ b/libs/HTML/QuickForm/radio.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a radio type element diff --git a/libs/HTML/QuickForm/reset.php b/libs/HTML/QuickForm/reset.php index bf2cbef908..41f8368b9a 100644 --- a/libs/HTML/QuickForm/reset.php +++ b/libs/HTML/QuickForm/reset.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a reset type element diff --git a/libs/HTML/QuickForm/select.php b/libs/HTML/QuickForm/select.php index 1708fcadb6..7a94ce8bed 100644 --- a/libs/HTML/QuickForm/select.php +++ b/libs/HTML/QuickForm/select.php @@ -26,7 +26,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * Class to dynamically create an HTML SELECT @@ -299,8 +299,27 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { * @access public * @return void */ - function addOption($text, $value, $attributes=null) - { + + // CLY - modification to allow optgroups + // function addOption($text, $value, $attributes=null) + function addOption($text, $value, $attributes=null, &$optGroup=null) { + // if text is an array, start an optgroup + if (is_array($text)) { + if (is_array($optGroup)) { + $optGroup[$value]['options'] = array(); + $optGroup =& $optGroup[$value]['options']; + } + else { + $this->_options[$value]['options'] = array(); + $optGroup =& $this->_options[$value]['options']; + }; + foreach($text as $key=>$val) { + $this->addOption($val, $key, null, $optGroup); + } + // done all the options in the optgroup + return; + } + // end mod if (null === $attributes) { $attributes = array('value' => (string)$value); } else { @@ -316,7 +335,33 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { } $this->_updateAttrArray($attributes, array('value' => (string)$value)); } - $this->_options[] = array('text' => $text, 'attr' => $attributes); + // CLY - modification to allow optgroups + // if $optGroup is an array, add the option to it + if (is_array($optGroup)) { + $optGroup[$text]['attr'] = $attributes; + } + // if $optGroup is a string, add the option to the option group + // used if directly adding an option to an optgroup + elseif (is_string($optGroup)) { + $optGroups = explode($optGroup, ','); + $target =& $this->_options; + foreach($optGroups as $group) { + // create the option group if it does not exist + if (empty($target[$group]['options'])) { + $target[$group]['options'] = array(); + } + $target =& $target[$group]['options']; + } + // foreach + // add the option + $target[$text]['attr'] = $attributes; + } + // else if there are attributes, add them to the option + elseif (is_array($attributes)) { + $this->_options[$text]['attr'] = $attributes; + } + // $this->_options[] = array('text' => $text, 'attr' => $attributes); + // end mod } // end func addOption // }}} @@ -402,7 +447,7 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { function loadQuery(&$conn, $sql, $textCol=null, $valueCol=null, $values=null) { if (is_string($conn)) { - require_once('DB.php'); + require_once(dirname(__FILE__) . '/../../DB.php'); $dbConn = &DB::connect($conn, true); if (DB::isError($dbConn)) { return $dbConn; @@ -493,7 +538,11 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { } $strHtml .= $tabs . '<select' . $attrString . ">\n"; - $strValues = is_array($this->_values)? array_map('strval', $this->_values): array(); + // CLY - modified to allow optgroups + foreach ($this->_options as $text=>$option) { + $strHtml .= $tabs . $this->_optionToHtml($text, $option); + } + /* $strValues = is_array($this->_values)? array_map('strval', $this->_values): array(); foreach ($this->_options as $option) { if (!empty($strValues) && in_array($option['attr']['value'], $strValues, true)) { $option['attr']['selected'] = 'selected'; @@ -501,7 +550,8 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { $strHtml .= $tabs . "\t<option" . $this->_getAttrString($option['attr']) . '>' . $option['text'] . "</option>\n"; } - + */ + // end mod return $strHtml . $tabs . '</select>'; } } //end func toHtml @@ -509,6 +559,40 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { // }}} // {{{ getFrozenHtml() +// CLY - new function to allow optgroups + /** + * Returns an OPTION in HTML + * + * This function is called recursively to support optgroups + * + * @param string $text Display text for the option + * @param array $option The option + * @since ?? + * @access private + * @return string + */ + // Creates the HTML for an option + function _optionToHtml($text, $option) + { + $tabs = $this->_getTabs(); + // if an option has options it's an optgroup + if (isset($option['options'])) { + $strHtml = $tabs . "<optgroup label=\"$text\">\n"; + foreach($option['options'] as $txt=>$opt) { + $strHtml .= $tabs . $this->_optionToHtml($txt, $opt); + } + $strHtml .= $tabs . "</optgroup>\n"; + return($strHtml); + } + // else it's an option + else { + if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) { + $this->_updateAttrArray($option['attr'], array('selected' => 'selected')); + } + return("\t<option" . $this->_getAttrString($option['attr']) . ">$text</option>\n"); + } + } + /** * Returns the value of field without HTML tags * @@ -568,12 +652,17 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { if (is_array($value) && !empty($this->_options)) { $cleanValue = null; foreach ($value as $v) { - for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) { - if (0 == strcmp($v, $this->_options[$i]['attr']['value'])) { - $cleanValue[] = $v; - break; - } - } + // CLY - modified to allow optgroups + if ($this->_isInOptGroup($v, $this->_options)) { + $cleanValue[] = $v; + } +// for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) { +// if (0 == strcmp($v, $this->_options[$i]['attr']['value'])) { +// $cleanValue[] = $v; +// break; +// } +// } + // end mod } } else { $cleanValue = $value; @@ -608,6 +697,22 @@ class HTML_QuickForm_select extends HTML_QuickForm_element { return parent::onQuickFormEvent($event, $arg, $caller); } } + + function _isInOptGroup($v, $opts) { + $isInOptGroup = false; + foreach ($opts as $opt) { + if (isset($opt['options'])) { + $isInOptGroup = $this->_isInOptGroup($v, $opt['options']); + } + else { + if ($v == $opt['attr']['value']) { + $isInOptGroup = true; + } + } + if ($isInOptGroup) break; + } + return $isInOptGroup; + } // }}} } //end class HTML_QuickForm_select diff --git a/libs/HTML/QuickForm/static.php b/libs/HTML/QuickForm/static.php index f5ce3cdca2..ef388cc456 100644 --- a/libs/HTML/QuickForm/static.php +++ b/libs/HTML/QuickForm/static.php @@ -24,7 +24,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * HTML class for static data diff --git a/libs/HTML/QuickForm/submit.php b/libs/HTML/QuickForm/submit.php index a9fa99d65b..25a98e8a26 100644 --- a/libs/HTML/QuickForm/submit.php +++ b/libs/HTML/QuickForm/submit.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a submit type element diff --git a/libs/HTML/QuickForm/text.php b/libs/HTML/QuickForm/text.php index 8d99735850..3240c41d5f 100644 --- a/libs/HTML/QuickForm/text.php +++ b/libs/HTML/QuickForm/text.php @@ -25,7 +25,7 @@ /** * Base class for <input /> form elements */ -require_once 'HTML/QuickForm/input.php'; +require_once dirname(__FILE__) . '/input.php'; /** * HTML class for a text field diff --git a/libs/HTML/QuickForm/textarea.php b/libs/HTML/QuickForm/textarea.php index a675e973bf..7aaac4c6ad 100644 --- a/libs/HTML/QuickForm/textarea.php +++ b/libs/HTML/QuickForm/textarea.php @@ -25,7 +25,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * HTML class for a textarea type field diff --git a/libs/HTML/QuickForm/xbutton.php b/libs/HTML/QuickForm/xbutton.php index c795fa53bc..98524cca89 100644 --- a/libs/HTML/QuickForm/xbutton.php +++ b/libs/HTML/QuickForm/xbutton.php @@ -24,7 +24,7 @@ /** * Base class for form elements */ -require_once 'HTML/QuickForm/element.php'; +require_once dirname(__FILE__) . '/element.php'; /** * Class for HTML 4.0 <button> element |