Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/pear/HTML/QuickForm/Renderer/Tableless.php
Go to the documentation of this file.
00001 <?php
00026 require_once 'HTML/QuickForm/Renderer/Default.php';
00027 
00045 class HTML_QuickForm_Renderer_Tableless extends HTML_QuickForm_Renderer_Default
00046 {
00052     var $_headerTemplate = 
00053         "\n\t\t<legend>{header}</legend>";
00054 
00060     var $_elementTemplate = 
00061         "\n\t\t<div class=\"qfrow\"><label class=\"qflabel\"><!-- BEGIN required --><span class=\"required\">*</span><!-- END required -->{label}</label><div class=\"qfelement<!-- BEGIN error --> error<!-- END error -->\"><!-- BEGIN error --><span class=\"error\">{error}</span><br /><!-- END error -->{element}</div></div><br />";
00062 
00068     var $_formTemplate = 
00069         "\n<form{attributes}>\n\t<div style=\"display: none;\">{hidden}</div>\n{content}\n</form>";
00070 
00076     var $_openFieldsetTemplate = "\n\t<fieldset{id}>";
00077 
00084     var $_openHiddenFieldsetTemplate = "\n\t<fieldset class=\"hidden\">";
00085 
00091     var $_closeFieldsetTemplate = "\n\t</fieldset>";
00092 
00098     var $_requiredNoteTemplate = 
00099         "\n\t\t<div class=\"qfreqnote\">{requiredNote}</div>";
00100 
00106    var $_fieldsetsOpen = 0;
00107 
00114     var $_stopFieldsetElements = array();
00115 
00121     function HTML_QuickForm_Renderer_Tableless()
00122     {
00123         $this->HTML_QuickForm_Renderer_Default();
00124     } // end constructor
00125 
00133     function renderHeader(&$header)
00134     {
00135         $name = $header->getName();
00136         $id = empty($name) ? '' : ' id="' . $name . '"';
00137         if (is_null($header->_text)) {
00138             $header_html = '';
00139         }
00140         elseif (!empty($name) && isset($this->_templates[$name])) {
00141             $header_html = str_replace('{header}', $header->toHtml(), $this->_templates[$name]);
00142         } else {
00143             $header_html = str_replace('{header}', $header->toHtml(), $this->_headerTemplate);
00144         }
00145         if ($this->_fieldsetsOpen > 0) {
00146             $this->_html .= $this->_closeFieldsetTemplate;
00147             $this->_fieldsetsOpen--;
00148         }
00149         $openFieldsetTemplate = str_replace('{id}', $id, $this->_openFieldsetTemplate);
00150         $this->_html .= $openFieldsetTemplate . $header_html;
00151         $this->_fieldsetsOpen++;
00152     } // end func renderHeader
00153 
00164     function renderElement(&$element, $required, $error)
00165     {
00166         // if the element name indicates the end of a fieldset, close the fieldset
00167         if (   in_array($element->getName(), $this->_stopFieldsetElements)
00168             && $this->_fieldsetsOpen > 0
00169            ) {
00170             $this->_html .= $this->_closeFieldsetTemplate;
00171             $this->_fieldsetsOpen--;
00172         }
00173         // if no fieldset was opened, we need to open a hidden one here to get
00174         // XHTML validity
00175         if ($this->_fieldsetsOpen === 0) {
00176             $this->_html .= $this->_openHiddenFieldsetTemplate;
00177             $this->_fieldsetsOpen++;
00178         }
00179         if (!$this->_inGroup) {
00180             $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error);
00181             // the following lines (until the "elseif") were changed / added
00182             // compared to the default renderer
00183             $element_html = $element->toHtml();
00184             if (!is_null($element->getAttribute('id'))) {
00185                 $id = $element->getAttribute('id');
00186             } else {
00187                 $id = $element->getName();
00188             }
00189             if (!empty($id) and !$element->isFrozen() and !is_a($element, 'MoodleQuickForm_group') and !is_a($element, 'HTML_QuickForm_static')) { // moodle hack
00190                 $html = str_replace('<label', '<label for="' . $id . '"', $html);
00191                 $element_html = preg_replace('#name="' . $id . '#',
00192                                              'id="' . $id . '" name="' . $id . '',
00193                                              $element_html,
00194                                              1);
00195             }
00196             $this->_html .= str_replace('{element}', $element_html, $html);
00197         } elseif (!empty($this->_groupElementTemplate)) {
00198             $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate);
00199             if ($required) {
00200                 $html = str_replace('<!-- BEGIN required -->', '', $html);
00201                 $html = str_replace('<!-- END required -->', '', $html);
00202             } else {
00203                 $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
00204             }
00205             $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html);
00206 
00207         } else {
00208             $this->_groupElements[] = $element->toHtml();
00209         }
00210     } // end func renderElement
00211 
00219     function startForm(&$form)
00220     {
00221         $this->_fieldsetsOpen = 0;
00222         parent::startForm($form);
00223     } // end func startForm
00224 
00233     function finishForm(&$form)
00234     {
00235         // add a required note, if one is needed
00236         if (!empty($form->_required) && !$form->_freezeAll) {
00237             $requiredNote = $form->getRequiredNote();
00238             // replace default required note by DOM/XHTML optimized note
00239             if ($requiredNote == '<span style="font-size:80%; color:#ff0000;">*</span><span style="font-size:80%;"> denotes required field</span>') {
00240                 $requiredNote = '<span class="required">*</span> denotes required field';
00241             }
00242             $this->_html .= str_replace('{requiredNote}', $requiredNote, $this->_requiredNoteTemplate);
00243         }
00244         // close the open fieldset
00245         if ($this->_fieldsetsOpen > 0) {
00246             $this->_html .= $this->_closeFieldsetTemplate;
00247             $this->_fieldsetsOpen--;
00248         }
00249         // add form attributes and content
00250         $html = str_replace('{attributes}', $form->getAttributes(true), $this->_formTemplate);
00251         if (strpos($this->_formTemplate, '{hidden}')) {
00252             $html = str_replace('{hidden}', $this->_hiddenHtml, $html);
00253         } else {
00254             $this->_html .= $this->_hiddenHtml;
00255         }
00256         $this->_hiddenHtml = '';
00257         $this->_html = str_replace('{content}', $this->_html, $html);
00258         $this->_html = str_replace('></label>', '>&nbsp;</label>', $this->_html);
00259         // add a validation script
00260         if ('' != ($script = $form->getValidationScript())) {
00261             $this->_html = $script . "\n" . $this->_html;
00262         }
00263     } // end func finishForm
00264 
00272     function setOpenFieldsetTemplate($html)
00273     {
00274         $this->_openFieldsetTemplate = $html;
00275     } // end func setOpenFieldsetTemplate
00276 
00285     function setOpenHiddenFieldsetTemplate($html)
00286     {
00287         $this->_openHiddenFieldsetTemplate = $html;
00288     } // end func setOpenHiddenFieldsetTemplate
00289 
00297     function setCloseFieldsetTemplate($html)
00298     {
00299         $this->_closeFieldsetTemplate = $html;
00300     } // end func setCloseFieldsetTemplate
00301 
00310     function addStopFieldsetElements($element)
00311     {
00312         if (is_array($element)) {
00313             $this->_stopFieldsetElements = array_merge($this->_stopFieldsetElements,
00314                                                        $element);
00315         } else {
00316             $this->_stopFieldsetElements[] = $element;
00317         }
00318     } // end func addStopFieldsetElements
00319 
00320 } // end class HTML_QuickForm_Renderer_Default
00321 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations