Subversion Repositories Applications.papyrus

Rev

Rev 320 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 320 Rev 443
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +----------------------------------------------------------------------+
3
// +----------------------------------------------------------------------+
4
// | PHP version 4.0                                                      |
4
// | PHP version 4.0                                                      |
5
// +----------------------------------------------------------------------+
5
// +----------------------------------------------------------------------+
6
// | Copyright (c) 1997-2003 The PHP Group                                |
6
// | Copyright (c) 1997-2003 The PHP Group                                |
7
// +----------------------------------------------------------------------+
7
// +----------------------------------------------------------------------+
8
// | This source file is subject to version 2.0 of the PHP license,       |
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        |
9
// | that is bundled with this package in the file LICENSE, and is        |
10
// | available at through the world-wide-web at                           |
10
// | available at through the world-wide-web at                           |
11
// | http://www.php.net/license/2_02.txt.                                 |
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   |
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          |
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.               |
14
// | license@php.net so we can mail you a copy immediately.               |
15
// +----------------------------------------------------------------------+
15
// +----------------------------------------------------------------------+
16
// | Authors: Alexey Borzov <borz_off@cs.msu.su>                          |
16
// | Authors: Alexey Borzov <borz_off@cs.msu.su>                          |
17
// |          Adam Daniel <adaniel1@eesus.jnj.com>                        |
17
// |          Adam Daniel <adaniel1@eesus.jnj.com>                        |
18
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
18
// |          Bertrand Mansion <bmansion@mamasam.com>                     |
19
// +----------------------------------------------------------------------+
19
// +----------------------------------------------------------------------+
20
//
20
//
21
// $Id: Default.php,v 1.1 2005-03-30 08:50:33 jpm Exp $
21
// $Id: Default.php,v 1.2 2005-09-20 17:01:22 ddelon Exp $
22
 
22
 
23
require_once('HTML/QuickForm/Renderer.php');
23
require_once('HTML/QuickForm/Renderer.php');
24
 
24
 
25
/**
25
/**
26
 * A concrete renderer for HTML_QuickForm,
26
 * A concrete renderer for HTML_QuickForm,
27
 * based on QuickForm 2.x built-in one
27
 * based on QuickForm 2.x built-in one
28
 * 
28
 * 
29
 * @access public
29
 * @access public
30
 */
30
 */
31
class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
31
class HTML_QuickForm_Renderer_Default extends HTML_QuickForm_Renderer
32
{
32
{
33
   /**
33
   /**
34
    * The HTML of the form  
34
    * The HTML of the form  
35
    * @var      string
35
    * @var      string
36
    * @access   private
36
    * @access   private
37
    */
37
    */
38
    var $_html;
38
    var $_html;
39
 
39
 
40
   /**
40
   /**
41
    * Header Template string
41
    * Header Template string
42
    * @var      string
42
    * @var      string
43
    * @access   private
43
    * @access   private
44
    */
44
    */
45
    var $_headerTemplate = 
45
    var $_headerTemplate = 
46
        "\n\t<tr>\n\t\t<td style=\"white-space: nowrap; background-color: #CCCCCC;\" align=\"left\" valign=\"top\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>";
46
        "\n\t<tr>\n\t\t<td style=\"white-space: nowrap; background-color: #CCCCCC;\" align=\"left\" valign=\"top\" colspan=\"2\"><b>{header}</b></td>\n\t</tr>";
47
 
47
 
48
   /**
48
   /**
49
    * Element template string
49
    * Element template string
50
    * @var      string
50
    * @var      string
51
    * @access   private
51
    * @access   private
52
    */
52
    */
53
    var $_elementTemplate = 
53
    var $_elementTemplate = 
54
        "\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
54
        "\n\t<tr>\n\t\t<td align=\"right\" valign=\"top\"><!-- BEGIN required --><span style=\"color: #ff0000\">*</span><!-- END required --><b>{label}</b></td>\n\t\t<td valign=\"top\" align=\"left\"><!-- BEGIN error --><span style=\"color: #ff0000\">{error}</span><br /><!-- END error -->\t{element}</td>\n\t</tr>";
55
 
55
 
56
   /**
56
   /**
57
    * Form template string
57
    * Form template string
58
    * @var      string
58
    * @var      string
59
    * @access   private
59
    * @access   private
60
    */
60
    */
61
    var $_formTemplate = 
61
    var $_formTemplate = 
62
        "\n<form{attributes}>\n<div>\n{hidden}<table border=\"0\">\n{content}\n</table>\n</div>\n</form>";
62
        "\n<form{attributes}>\n<div>\n{hidden}<table border=\"0\">\n{content}\n</table>\n</div>\n</form>";
63
 
63
 
64
   /**
64
   /**
65
    * Required Note template string
65
    * Required Note template string
66
    * @var      string
66
    * @var      string
67
    * @access   private
67
    * @access   private
68
    */
68
    */
69
    var $_requiredNoteTemplate = 
69
    var $_requiredNoteTemplate = 
70
        "\n\t<tr>\n\t\t<td></td>\n\t<td align=\"left\" valign=\"top\">{requiredNote}</td>\n\t</tr>";
70
        "\n\t<tr>\n\t\t<td></td>\n\t<td align=\"left\" valign=\"top\">{requiredNote}</td>\n\t</tr>";
71
 
71
 
72
   /**
72
   /**
73
    * Array containing the templates for customised elements
73
    * Array containing the templates for customised elements
74
    * @var      array
74
    * @var      array
75
    * @access   private
75
    * @access   private
76
    */
76
    */
77
    var $_templates = array();
77
    var $_templates = array();
78
 
78
 
79
   /**
79
   /**
80
    * Array containing the templates for group wraps.
80
    * Array containing the templates for group wraps.
81
    * 
81
    * 
82
    * These templates are wrapped around group elements and groups' own
82
    * These templates are wrapped around group elements and groups' own
83
    * templates wrap around them. This is set by setGroupTemplate().
83
    * templates wrap around them. This is set by setGroupTemplate().
84
    * 
84
    * 
85
    * @var      array
85
    * @var      array
86
    * @access   private
86
    * @access   private
87
    */
87
    */
88
    var $_groupWraps = array();
88
    var $_groupWraps = array();
89
 
89
 
90
   /**
90
   /**
91
    * Array containing the templates for elements within groups
91
    * Array containing the templates for elements within groups
92
    * @var      array
92
    * @var      array
93
    * @access   private
93
    * @access   private
94
    */
94
    */
95
    var $_groupTemplates = array();
95
    var $_groupTemplates = array();
96
 
96
 
97
   /**
97
   /**
98
    * True if we are inside a group 
98
    * True if we are inside a group 
99
    * @var      bool
99
    * @var      bool
100
    * @access   private
100
    * @access   private
101
    */
101
    */
102
    var $_inGroup = false;
102
    var $_inGroup = false;
103
 
103
 
104
   /**
104
   /**
105
    * Array with HTML generated for group elements
105
    * Array with HTML generated for group elements
106
    * @var      array
106
    * @var      array
107
    * @access   private
107
    * @access   private
108
    */
108
    */
109
    var $_groupElements = array();
109
    var $_groupElements = array();
110
 
110
 
111
   /**
111
   /**
112
    * Template for an element inside a group
112
    * Template for an element inside a group
113
    * @var      string
113
    * @var      string
114
    * @access   private
114
    * @access   private
115
    */
115
    */
116
    var $_groupElementTemplate = '';
116
    var $_groupElementTemplate = '';
117
 
117
 
118
   /**
118
   /**
119
    * HTML that wraps around the group elements
119
    * HTML that wraps around the group elements
120
    * @var      string
120
    * @var      string
121
    * @access   private
121
    * @access   private
122
    */
122
    */
123
    var $_groupWrap = '';
123
    var $_groupWrap = '';
124
 
124
 
125
   /**
125
   /**
126
    * HTML for the current group
126
    * HTML for the current group
127
    * @var      string
127
    * @var      string
128
    * @access   private
128
    * @access   private
129
    */
129
    */
130
    var $_groupTemplate = '';
130
    var $_groupTemplate = '';
131
    
131
    
132
   /**
132
   /**
133
    * Collected HTML of the hidden fields
133
    * Collected HTML of the hidden fields
134
    * @var      string
134
    * @var      string
135
    * @access   private
135
    * @access   private
136
    */
136
    */
137
    var $_hiddenHtml = '';
137
    var $_hiddenHtml = '';
138
 
138
 
139
   /**
139
   /**
140
    * Constructor
140
    * Constructor
141
    *
141
    *
142
    * @access public
142
    * @access public
143
    */
143
    */
144
    function HTML_QuickForm_Renderer_Default()
144
    function HTML_QuickForm_Renderer_Default()
145
    {
145
    {
146
        $this->HTML_QuickForm_Renderer();
146
        $this->HTML_QuickForm_Renderer();
147
    } // end constructor
147
    } // end constructor
148
 
148
 
149
   /**
149
   /**
150
    * returns the HTML generated for the form
150
    * returns the HTML generated for the form
151
    *
151
    *
152
    * @access public
152
    * @access public
153
    * @return string
153
    * @return string
154
    */
154
    */
155
    function toHtml()
155
    function toHtml()
156
    {
156
    {
-
 
157
        // _hiddenHtml is cleared in finishForm(), so this only matters when
-
 
158
        // finishForm() was not called (e.g. group::toHtml(), bug #3511)
157
        return $this->_html;
159
        return $this->_hiddenHtml . $this->_html;
158
    } // end func toHtml
160
    } // end func toHtml
159
    
161
    
160
   /**
162
   /**
161
    * Called when visiting a form, before processing any form elements
163
    * Called when visiting a form, before processing any form elements
162
    *
164
    *
163
    * @param    object      An HTML_QuickForm object being visited
165
    * @param    object      An HTML_QuickForm object being visited
164
    * @access   public
166
    * @access   public
165
    * @return   void
167
    * @return   void
166
    */
168
    */
167
    function startForm(&$form)
169
    function startForm(&$form)
168
    {
170
    {
169
        $this->_html = '';
171
        $this->_html = '';
170
        $this->_hiddenHtml = '';
172
        $this->_hiddenHtml = '';
171
    } // end func startForm
173
    } // end func startForm
172
 
174
 
173
   /**
175
   /**
174
    * Called when visiting a form, after processing all form elements
176
    * Called when visiting a form, after processing all form elements
175
    * Adds required note, form attributes, validation javascript and form content.
177
    * Adds required note, form attributes, validation javascript and form content.
176
    * 
178
    * 
177
    * @param    object      An HTML_QuickForm object being visited
179
    * @param    object      An HTML_QuickForm object being visited
178
    * @access   public
180
    * @access   public
179
    * @return   void
181
    * @return   void
180
    */
182
    */
181
    function finishForm(&$form)
183
    function finishForm(&$form)
182
    {
184
    {
183
        // add a required note, if one is needed
185
        // add a required note, if one is needed
184
        if (!empty($form->_required) && !$form->_freezeAll) {
186
        if (!empty($form->_required) && !$form->_freezeAll) {
185
            $this->_html .= str_replace('{requiredNote}', $form->getRequiredNote(), $this->_requiredNoteTemplate);
187
            $this->_html .= str_replace('{requiredNote}', $form->getRequiredNote(), $this->_requiredNoteTemplate);
186
        }
188
        }
187
        // add form attributes and content
189
        // add form attributes and content
188
        $html = str_replace('{attributes}', $form->getAttributes(true), $this->_formTemplate);
190
        $html = str_replace('{attributes}', $form->getAttributes(true), $this->_formTemplate);
189
        if (strpos($this->_formTemplate, '{hidden}')) {
191
        if (strpos($this->_formTemplate, '{hidden}')) {
190
            $html = str_replace('{hidden}', $this->_hiddenHtml, $html);
192
            $html = str_replace('{hidden}', $this->_hiddenHtml, $html);
191
        } else {
193
        } else {
192
            $this->_html .= $this->_hiddenHtml;
194
            $this->_html .= $this->_hiddenHtml;
193
        }
195
        }
-
 
196
        $this->_hiddenHtml = '';
194
        $this->_html = str_replace('{content}', $this->_html, $html);
197
        $this->_html = str_replace('{content}', $this->_html, $html);
195
        // add a validation script
198
        // add a validation script
196
        if ('' != ($script = $form->getValidationScript())) {
199
        if ('' != ($script = $form->getValidationScript())) {
197
            $this->_html = $script . "\n" . $this->_html;
200
            $this->_html = $script . "\n" . $this->_html;
198
        }
201
        }
199
    } // end func finishForm
202
    } // end func finishForm
200
      
203
      
201
   /**
204
   /**
202
    * Called when visiting a header element
205
    * Called when visiting a header element
203
    *
206
    *
204
    * @param    object     An HTML_QuickForm_header element being visited
207
    * @param    object     An HTML_QuickForm_header element being visited
205
    * @access   public
208
    * @access   public
206
    * @return   void
209
    * @return   void
207
    */
210
    */
208
    function renderHeader(&$header)
211
    function renderHeader(&$header)
209
    {
212
    {
210
        $name = $header->getName();
213
        $name = $header->getName();
211
        if (!empty($name) && isset($this->_templates[$name])) {
214
        if (!empty($name) && isset($this->_templates[$name])) {
212
            $this->_html .= str_replace('{header}', $header->toHtml(), $this->_templates[$name]);
215
            $this->_html .= str_replace('{header}', $header->toHtml(), $this->_templates[$name]);
213
        } else {
216
        } else {
214
            $this->_html .= str_replace('{header}', $header->toHtml(), $this->_headerTemplate);
217
            $this->_html .= str_replace('{header}', $header->toHtml(), $this->_headerTemplate);
215
        }
218
        }
216
    } // end func renderHeader
219
    } // end func renderHeader
217
 
220
 
218
   /**
221
   /**
219
    * Helper method for renderElement
222
    * Helper method for renderElement
220
    *
223
    *
221
    * @param    string      Element name
224
    * @param    string      Element name
222
    * @param    mixed       Element label (if using an array of labels, you should set the appropriate template)
225
    * @param    mixed       Element label (if using an array of labels, you should set the appropriate template)
223
    * @param    bool        Whether an element is required
226
    * @param    bool        Whether an element is required
224
    * @param    string      Error message associated with the element
227
    * @param    string      Error message associated with the element
225
    * @access   private
228
    * @access   private
226
    * @see      renderElement()
229
    * @see      renderElement()
227
    * @return   string      Html for element
230
    * @return   string      Html for element
228
    */
231
    */
229
    function _prepareTemplate($name, $label, $required, $error)
232
    function _prepareTemplate($name, $label, $required, $error)
230
    {
233
    {
231
        if (is_array($label)) {
234
        if (is_array($label)) {
232
            $nameLabel = array_shift($label);
235
            $nameLabel = array_shift($label);
233
        } else {
236
        } else {
234
            $nameLabel = $label;
237
            $nameLabel = $label;
235
        }
238
        }
236
        if (isset($this->_templates[$name])) {
239
        if (isset($this->_templates[$name])) {
237
            $html = str_replace('{label}', $nameLabel, $this->_templates[$name]);
240
            $html = str_replace('{label}', $nameLabel, $this->_templates[$name]);
238
        } else {
241
        } else {
239
            $html = str_replace('{label}', $nameLabel, $this->_elementTemplate);
242
            $html = str_replace('{label}', $nameLabel, $this->_elementTemplate);
240
        }
243
        }
241
        if ($required) {
244
        if ($required) {
242
            $html = str_replace('<!-- BEGIN required -->', '', $html);
245
            $html = str_replace('<!-- BEGIN required -->', '', $html);
243
            $html = str_replace('<!-- END required -->', '', $html);
246
            $html = str_replace('<!-- END required -->', '', $html);
244
        } else {
247
        } else {
245
            $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
248
            $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
246
        }
249
        }
247
        if (isset($error)) {
250
        if (isset($error)) {
248
            $html = str_replace('{error}', $error, $html);
251
            $html = str_replace('{error}', $error, $html);
249
            $html = str_replace('<!-- BEGIN error -->', '', $html);
252
            $html = str_replace('<!-- BEGIN error -->', '', $html);
250
            $html = str_replace('<!-- END error -->', '', $html);
253
            $html = str_replace('<!-- END error -->', '', $html);
251
        } else {
254
        } else {
252
            $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->(\s|\S)*<!-- END error -->([ \t\n\r]*)?/i", '', $html);
255
            $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN error -->(\s|\S)*<!-- END error -->([ \t\n\r]*)?/i", '', $html);
253
        }
256
        }
254
        if (is_array($label)) {
257
        if (is_array($label)) {
255
            foreach($label as $key => $text) {
258
            foreach($label as $key => $text) {
256
                $key  = is_int($key)? $key + 2: $key;
259
                $key  = is_int($key)? $key + 2: $key;
257
                $html = str_replace("{label_{$key}}", $text, $html);
260
                $html = str_replace("{label_{$key}}", $text, $html);
258
                $html = str_replace("<!-- BEGIN label_{$key} -->", '', $html);
261
                $html = str_replace("<!-- BEGIN label_{$key} -->", '', $html);
259
                $html = str_replace("<!-- END label_{$key} -->", '', $html);
262
                $html = str_replace("<!-- END label_{$key} -->", '', $html);
260
            }
263
            }
261
        }
264
        }
262
        if (strpos($html, '{label_')) {
265
        if (strpos($html, '{label_')) {
263
            $html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html);
266
            $html = preg_replace('/\s*<!-- BEGIN label_(\S+) -->.*<!-- END label_\1 -->\s*/i', '', $html);
264
        }
267
        }
265
        return $html;
268
        return $html;
266
    } // end func _prepareTemplate
269
    } // end func _prepareTemplate
267
 
270
 
268
   /**
271
   /**
269
    * Renders an element Html
272
    * Renders an element Html
270
    * Called when visiting an element
273
    * Called when visiting an element
271
    *
274
    *
272
    * @param object     An HTML_QuickForm_element object being visited
275
    * @param object     An HTML_QuickForm_element object being visited
273
    * @param bool       Whether an element is required
276
    * @param bool       Whether an element is required
274
    * @param string     An error message associated with an element
277
    * @param string     An error message associated with an element
275
    * @access public
278
    * @access public
276
    * @return void
279
    * @return void
277
    */
280
    */
278
    function renderElement(&$element, $required, $error)
281
    function renderElement(&$element, $required, $error)
279
    {
282
    {
280
        if (!$this->_inGroup) {
283
        if (!$this->_inGroup) {
281
            $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error);
284
            $html = $this->_prepareTemplate($element->getName(), $element->getLabel(), $required, $error);
282
            $this->_html .= str_replace('{element}', $element->toHtml(), $html);
285
            $this->_html .= str_replace('{element}', $element->toHtml(), $html);
283
 
286
 
284
        } elseif (!empty($this->_groupElementTemplate)) {
287
        } elseif (!empty($this->_groupElementTemplate)) {
285
            $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate);
288
            $html = str_replace('{label}', $element->getLabel(), $this->_groupElementTemplate);
286
            if ($required) {
289
            if ($required) {
287
                $html = str_replace('<!-- BEGIN required -->', '', $html);
290
                $html = str_replace('<!-- BEGIN required -->', '', $html);
288
                $html = str_replace('<!-- END required -->', '', $html);
291
                $html = str_replace('<!-- END required -->', '', $html);
289
            } else {
292
            } else {
290
                $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
293
                $html = preg_replace("/([ \t\n\r]*)?<!-- BEGIN required -->(\s|\S)*<!-- END required -->([ \t\n\r]*)?/i", '', $html);
291
            }
294
            }
292
            $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html);
295
            $this->_groupElements[] = str_replace('{element}', $element->toHtml(), $html);
293
 
296
 
294
        } else {
297
        } else {
295
            $this->_groupElements[] = $element->toHtml();
298
            $this->_groupElements[] = $element->toHtml();
296
        }
299
        }
297
    } // end func renderElement
300
    } // end func renderElement
298
   
301
   
299
   /**
302
   /**
300
    * Renders an hidden element
303
    * Renders an hidden element
301
    * Called when visiting a hidden element
304
    * Called when visiting a hidden element
302
    * 
305
    * 
303
    * @param object     An HTML_QuickForm_hidden object being visited
306
    * @param object     An HTML_QuickForm_hidden object being visited
304
    * @access public
307
    * @access public
305
    * @return void
308
    * @return void
306
    */
309
    */
307
    function renderHidden(&$element)
310
    function renderHidden(&$element)
308
    {
311
    {
309
        $this->_hiddenHtml .= $element->toHtml() . "\n";
312
        $this->_hiddenHtml .= $element->toHtml() . "\n";
310
    } // end func renderHidden
313
    } // end func renderHidden
311
 
314
 
312
   /**
315
   /**
313
    * Called when visiting a raw HTML/text pseudo-element
316
    * Called when visiting a raw HTML/text pseudo-element
314
    * 
317
    * 
315
    * @param  object     An HTML_QuickForm_html element being visited
318
    * @param  object     An HTML_QuickForm_html element being visited
316
    * @access public
319
    * @access public
317
    * @return void
320
    * @return void
318
    */
321
    */
319
    function renderHtml(&$data)
322
    function renderHtml(&$data)
320
    {
323
    {
321
        $this->_html .= $data->toHtml();
324
        $this->_html .= $data->toHtml();
322
    } // end func renderHtml
325
    } // end func renderHtml
323
 
326
 
324
   /**
327
   /**
325
    * Called when visiting a group, before processing any group elements
328
    * Called when visiting a group, before processing any group elements
326
    *
329
    *
327
    * @param object     An HTML_QuickForm_group object being visited
330
    * @param object     An HTML_QuickForm_group object being visited
328
    * @param bool       Whether a group is required
331
    * @param bool       Whether a group is required
329
    * @param string     An error message associated with a group
332
    * @param string     An error message associated with a group
330
    * @access public
333
    * @access public
331
    * @return void
334
    * @return void
332
    */
335
    */
333
    function startGroup(&$group, $required, $error)
336
    function startGroup(&$group, $required, $error)
334
    {
337
    {
335
        $name = $group->getName();
338
        $name = $group->getName();
336
        $this->_groupTemplate        = $this->_prepareTemplate($name, $group->getLabel(), $required, $error);
339
        $this->_groupTemplate        = $this->_prepareTemplate($name, $group->getLabel(), $required, $error);
337
        $this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name];
340
        $this->_groupElementTemplate = empty($this->_groupTemplates[$name])? '': $this->_groupTemplates[$name];
338
        $this->_groupWrap            = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name];
341
        $this->_groupWrap            = empty($this->_groupWraps[$name])? '': $this->_groupWraps[$name];
339
        $this->_groupElements        = array();
342
        $this->_groupElements        = array();
340
        $this->_inGroup              = true;
343
        $this->_inGroup              = true;
341
    } // end func startGroup
344
    } // end func startGroup
342
 
345
 
343
   /**
346
   /**
344
    * Called when visiting a group, after processing all group elements
347
    * Called when visiting a group, after processing all group elements
345
    *
348
    *
346
    * @param    object      An HTML_QuickForm_group object being visited
349
    * @param    object      An HTML_QuickForm_group object being visited
347
    * @access   public
350
    * @access   public
348
    * @return   void
351
    * @return   void
349
    */
352
    */
350
    function finishGroup(&$group)
353
    function finishGroup(&$group)
351
    {
354
    {
352
        $separator = $group->_separator;
355
        $separator = $group->_separator;
353
        if (is_array($separator)) {
356
        if (is_array($separator)) {
354
            $count = count($separator);
357
            $count = count($separator);
355
            $html  = '';
358
            $html  = '';
356
            for ($i = 0; $i < count($this->_groupElements); $i++) {
359
            for ($i = 0; $i < count($this->_groupElements); $i++) {
357
                $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i];
360
                $html .= (0 == $i? '': $separator[($i - 1) % $count]) . $this->_groupElements[$i];
358
            }
361
            }
359
        } else {
362
        } else {
360
            if (is_null($separator)) {
363
            if (is_null($separator)) {
361
                $separator = '&nbsp;';
364
                $separator = '&nbsp;';
362
            }
365
            }
363
            $html = implode((string)$separator, $this->_groupElements);
366
            $html = implode((string)$separator, $this->_groupElements);
364
        }
367
        }
365
        if (!empty($this->_groupWrap)) {
368
        if (!empty($this->_groupWrap)) {
366
            $html = str_replace('{content}', $html, $this->_groupWrap);
369
            $html = str_replace('{content}', $html, $this->_groupWrap);
367
        }
370
        }
368
        $this->_html   .= str_replace('{element}', $html, $this->_groupTemplate);
371
        $this->_html   .= str_replace('{element}', $html, $this->_groupTemplate);
369
        $this->_inGroup = false;
372
        $this->_inGroup = false;
370
    } // end func finishGroup
373
    } // end func finishGroup
371
 
374
 
372
    /**
375
    /**
373
     * Sets element template 
376
     * Sets element template 
374
     *
377
     *
375
     * @param       string      The HTML surrounding an element 
378
     * @param       string      The HTML surrounding an element 
376
     * @param       string      (optional) Name of the element to apply template for
379
     * @param       string      (optional) Name of the element to apply template for
377
     * @access      public
380
     * @access      public
378
     * @return      void
381
     * @return      void
379
     */
382
     */
380
    function setElementTemplate($html, $element = null)
383
    function setElementTemplate($html, $element = null)
381
    {
384
    {
382
        if (is_null($element)) {
385
        if (is_null($element)) {
383
            $this->_elementTemplate = $html;
386
            $this->_elementTemplate = $html;
384
        } else {
387
        } else {
385
            $this->_templates[$element] = $html;
388
            $this->_templates[$element] = $html;
386
        }
389
        }
387
    } // end func setElementTemplate
390
    } // end func setElementTemplate
388
 
391
 
389
 
392
 
390
    /**
393
    /**
391
     * Sets template for a group wrapper 
394
     * Sets template for a group wrapper 
392
     * 
395
     * 
393
     * This template is contained within a group-as-element template 
396
     * This template is contained within a group-as-element template 
394
     * set via setTemplate() and contains group's element templates, set
397
     * set via setTemplate() and contains group's element templates, set
395
     * via setGroupElementTemplate()
398
     * via setGroupElementTemplate()
396
     *
399
     *
397
     * @param       string      The HTML surrounding group elements
400
     * @param       string      The HTML surrounding group elements
398
     * @param       string      Name of the group to apply template for
401
     * @param       string      Name of the group to apply template for
399
     * @access      public
402
     * @access      public
400
     * @return      void
403
     * @return      void
401
     */
404
     */
402
    function setGroupTemplate($html, $group)
405
    function setGroupTemplate($html, $group)
403
    {
406
    {
404
        $this->_groupWraps[$group] = $html;
407
        $this->_groupWraps[$group] = $html;
405
    } // end func setGroupTemplate
408
    } // end func setGroupTemplate
406
 
409
 
407
    /**
410
    /**
408
     * Sets element template for elements within a group
411
     * Sets element template for elements within a group
409
     *
412
     *
410
     * @param       string      The HTML surrounding an element 
413
     * @param       string      The HTML surrounding an element 
411
     * @param       string      Name of the group to apply template for
414
     * @param       string      Name of the group to apply template for
412
     * @access      public
415
     * @access      public
413
     * @return      void
416
     * @return      void
414
     */
417
     */
415
    function setGroupElementTemplate($html, $group)
418
    function setGroupElementTemplate($html, $group)
416
    {
419
    {
417
        $this->_groupTemplates[$group] = $html;
420
        $this->_groupTemplates[$group] = $html;
418
    } // end func setGroupElementTemplate
421
    } // end func setGroupElementTemplate
419
 
422
 
420
    /**
423
    /**
421
     * Sets header template
424
     * Sets header template
422
     *
425
     *
423
     * @param       string      The HTML surrounding the header 
426
     * @param       string      The HTML surrounding the header 
424
     * @access      public
427
     * @access      public
425
     * @return      void
428
     * @return      void
426
     */
429
     */
427
    function setHeaderTemplate($html)
430
    function setHeaderTemplate($html)
428
    {
431
    {
429
        $this->_headerTemplate = $html;
432
        $this->_headerTemplate = $html;
430
    } // end func setHeaderTemplate
433
    } // end func setHeaderTemplate
431
 
434
 
432
    /**
435
    /**
433
     * Sets form template 
436
     * Sets form template 
434
     *
437
     *
435
     * @param     string    The HTML surrounding the form tags 
438
     * @param     string    The HTML surrounding the form tags 
436
     * @access    public
439
     * @access    public
437
     * @return    void
440
     * @return    void
438
     */
441
     */
439
    function setFormTemplate($html)
442
    function setFormTemplate($html)
440
    {
443
    {
441
        $this->_formTemplate = $html;
444
        $this->_formTemplate = $html;
442
    } // end func setFormTemplate
445
    } // end func setFormTemplate
443
 
446
 
444
    /**
447
    /**
445
     * Sets the note indicating required fields template
448
     * Sets the note indicating required fields template
446
     *
449
     *
447
     * @param       string      The HTML surrounding the required note 
450
     * @param       string      The HTML surrounding the required note 
448
     * @access      public
451
     * @access      public
449
     * @return      void
452
     * @return      void
450
     */
453
     */
451
    function setRequiredNoteTemplate($html)
454
    function setRequiredNoteTemplate($html)
452
    {
455
    {
453
        $this->_requiredNoteTemplate = $html;
456
        $this->_requiredNoteTemplate = $html;
454
    } // end func setRequiredNoteTemplate
457
    } // end func setRequiredNoteTemplate
455
 
458
 
456
    /**
459
    /**
457
     * Clears all the HTML out of the templates that surround notes, elements, etc.
460
     * Clears all the HTML out of the templates that surround notes, elements, etc.
458
     * Useful when you want to use addData() to create a completely custom form look
461
     * Useful when you want to use addData() to create a completely custom form look
459
     *
462
     *
460
     * @access  public
463
     * @access  public
461
     * @return  void
464
     * @return  void
462
     */
465
     */
463
    function clearAllTemplates()
466
    function clearAllTemplates()
464
    {
467
    {
465
        $this->setElementTemplate('{element}');
468
        $this->setElementTemplate('{element}');
466
        $this->setFormTemplate("\n\t<form{attributes}>{content}\n\t</form>\n");
469
        $this->setFormTemplate("\n\t<form{attributes}>{content}\n\t</form>\n");
467
        $this->setRequiredNoteTemplate('');
470
        $this->setRequiredNoteTemplate('');
468
        $this->_templates = array();
471
        $this->_templates = array();
469
    } // end func clearAllTemplates
472
    } // end func clearAllTemplates
470
} // end class HTML_QuickForm_Renderer_Default
473
} // end class HTML_QuickForm_Renderer_Default
471
?>
474
?>