add support for number inputs to ExtendedDocument
[php-utility-classes.git] / include / cbsm / util / document.php-class
1 <?php
2 /* ***** BEGIN LICENSE BLOCK *****
3  *
4  * The contents of this file are subject to Austrian copyright reegulations
5  * ("Urheberrecht"); you may not use this file except in compliance with
6  * those laws.
7  * This contents and any derived work, if it gets distributed in any way,
8  * is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND,
9  * either express or implied.
10  *
11  * The Original Code is KaiRo's extended DOM document classes.
12  *
13  * The Initial Developer of the Original Code is
14  * KaiRo - Robert Kaiser.
15  * Portions created by the Initial Developer are Copyright (C) 2010
16  * the Initial Developer. All Rights Reserved.
17  *
18  * Contributor(s): Robert Kaiser <kairo@kairo.at>
19  *
20  * ***** END LICENSE BLOCK ***** */
21
22 class ExtendedDocument extends DOMDocument {
23   // ExtendedDocument PHP class
24   // this extends the general PHP DOM Document class to simplify some usual constructs
25   //
26   // function __construct([$version], [$encoding])
27   //   CONSTRUCTOR
28   //   construct a new DOM Document that uses our element definitions
29   //
30   // private $xmheader
31   //   the default XML header
32   //
33   // private $xhtmldtype
34   //   the XHTML doctype to use by default
35   //
36   // function appendElement($name, [$value])
37   //   appends a DOMDocument::createElement() as a child of this document (see there for params)
38   //     returns the new child
39   //
40   // function appendElementXML($name, $xmldata)
41   //   appends a DOMDocument::createElement() with the given name as a child of this document,
42   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
43   //     returns the new child
44   //
45   // function appendLink($target, [$value])
46   //   appends an ExtendedDocument::createElementLink() as a child of this document (see there for params)
47   //     returns the new child
48   //
49   // function appendImage($src, [$alt_text])
50   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
51   //     returns the new child
52   //
53   // function appendForm($action, $method, $name, [$id])
54   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
55   //     returns the new child
56   //
57   // function appendFormDiv($action, $method, $name, [$id])
58   //   appends an ExtendedDocument::createElementForm() as a child of this document (see there for params)
59   //     returns an HTML <div> that is a child of the new child
60   //
61   // function appendInputHidden($name, $value)
62   //   appends an ExtendedDocument::createElementInputHidden() as a child of this document (see there for params)
63   //     returns the new child
64   //
65   // function appendInputText($name, $maxlength, $size, [$id], [$value])
66   //   appends an ExtendedDocument::createElementInputText() as a child of this document (see there for params)
67   //     returns the new child
68   //
69   // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
70   //   appends an ExtendedDocument::createElementInputNumber() as a child of this document (see there for params)
71   //     returns the new child
72   //
73   // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
74   //   appends an ExtendedDocument::createElementInputPassword() as a child of this document (see there for params)
75   //     returns the new child
76   //
77   // function appendInputRadio($name, $id, $value, $checked)
78   //   appends an ExtendedDocument::createElementInputRadio() as a child of this document (see there for params)
79   //     returns the new child
80   //
81   // function appendInputCheckbox($name, $id, $value, $checked)
82   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this document (see there for params)
83   //     returns the new child
84   //
85   // function appendInputSubmit($value)
86   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this document (see there for params)
87   //     returns the new child
88   //
89   // function appendButton($value, $onclick = null)
90   //   appends an ExtendedDocument::createElementButton() as a child of this document (see there for params)
91   //     returns the new child
92   //
93   // function appendTextArea($name, $columns, $rows, [$id], [$value])
94   //   appends an ExtendedDocument::createElementTextArea() as a child of this document (see there for params)
95   //     returns the new child
96   //
97   // function appendElementSelect($name, [$id], [$options], [$default])
98   //   appends an ExtendedDocument::createElementSelect() as a child of this document (see there for params)
99   //     returns the new child
100   //
101   // function appendElementOption($key, $desc, [$selected])
102   //   appends an ExtendedDocument::createElementOption() as a child of this document (see there for params)
103   //     returns the new child
104   //
105   // function appendLabel($for_id, $value)
106   //   appends an ExtendedDocument::createElementLabel() as a child of this document (see there for params)
107   //     returns the new child
108   //
109   // function appendText($text)
110   //   appends a DOMDocument::createTextNode() as a child of this document (see there for params)
111   //     returns the new child
112   //
113   // function appendComment($comment_data)
114   //   appends a DOMDocument::createComment() as a child of this document (see there for params)
115   //     returns the new child
116   //
117   // function appendHTMLMarkup($htmldata, [$parentNode])
118   //   appends a representation of the HTML data as children of the given parent node, by default this document
119   //     NO return value!
120   //
121   // function appendXMLMarkup($xmldata, [$parentNode])
122   //   appends a representation of the XML data as children of the given parent node, by default this document
123   //     NO return value!
124   //
125   // function appendJSElement($jsdata)
126   //   appends an ExtendedDocument::createElementJS() as a child of this document (see there for params)
127   //     NO return value!
128   //
129   // function appendCOMElement($module, $attributes)
130   //   appends an ExtendedDocument::createCOMElement() as a child of this document (see there for params)
131   //     returns the new child
132   //
133   // function createElementLink($target, [$value])
134   //   returns an ExtendedElement that is an HTML <a> with the given target (href) and (optional) value
135   //
136   // function createElementImage($src, [$alt_text])
137   //   returns an ExtendedElement that is an HTML <img> with the given (src) and alt attributes (set to '' by default)
138   //
139   // function createElementForm($action, $method, $name)
140   //   returns an ExtendedElement that is an HTML <div> that is a child of an HTML <form>
141   //   with the given action, method, and name
142   //
143   // function createElementInputHidden($name, $value)
144   //   returns an ExtendedElement that is an HTML <input> of type 'hidden' with the given name and value
145   //
146   // function createElementInputText($name, $maxlength, $size, [$id], [$value])
147   //   returns an ExtendedElement that is an HTML <input> of type 'text' with the given name, maxlength, size,
148   //   and optionally id and value
149   //
150   // function createElementInputNumber($name, $maxlength, $size, [$id], [$value])
151   //   returns an ExtendedElement that is an HTML <input> of type 'number' with the given name, maxlength, size,
152   //   and optionally id and value
153   //
154   // function createElementInputPassword($name, $maxlength, $size, [$id], [$value])
155   //   returns an ExtendedElement that is an HTML <input> of type 'password' with the given name, maxlength, size,
156   //   and optionally id and value
157   //
158   // function createElementInputRadio($name, $id, $value, $checked)
159   //   returns an ExtendedElement that is an HTML <input> of type 'radio' with the given name, id, value and
160   //   checked state
161   //
162   // function createElementInputCheckbox($name, $id, $value, $checked)
163   //   returns an ExtendedElement that is an HTML <input> of type 'checkbox' with the given name, id, value and
164   //   checked state
165   //
166   // function createElementInputSubmit($value)
167   //   returns an ExtendedElement that is an HTML <input> of type 'submit' with the given value as label
168   //
169   // function createElementButton($value, $onclick = null)
170   //   returns an ExtendedElement that is an HTML button with the given value as label and optionally onclick attribute
171   //
172   // function createElementTextArea($name, $columns, $rows, [$id], [$value])
173   //   returns an ExtendedElement that is an HTML <textarea> with the given name, columns, rows,
174   //   and optionally id and value
175   //
176   // function createElementSelect($name, [$id], [$options], [$default])
177   //   returns an ExtendedElement that is an HTML <select> with the given name, and optionally id,
178   //   array of options (key => description) and key of the by-default selected entry
179   //
180   // function createElementOption($key, $desc, [$selected])
181   //   returns an ExtendedElement that is an HTML <option> with the given key (value) and description (content)
182   //   and optionally bool that tells if the entry is selected
183   //
184   // function createElementLabel($for_id, $value)
185   //   returns an ExtendedElement that is an HTML <label> with the given 'for' and value
186   //
187   // function createElementJS($jsdata)
188   //   returns an ExtendedElement that is an HTML <script> of JavaScript type with the JS data inside
189   //
190   // function createCOMElement($module, $attributes)
191   //   returns an ExtendedElement that is in COM_NS namespace, with the given module as name and the
192   //     given name=>value array as attributes
193
194   function __construct($version = '1.0', $encoding = 'utf-8') {
195     // make sure the default DOMDocument constructor runs
196     parent::__construct($version, $encoding);
197     $this->registerNodeClass('DOMElement', 'ExtendedElement');
198     $this->registerNodeClass('DOMDocumentFragment', 'ExtendedDocumentFragment');
199   }
200
201   function appendElement($name, $value = '') {
202     // Adding the $value in createElement does NOT escape it, so use appendText to support that.
203     $aelem = $this->appendChild($this->createElement($name));
204     $aelem->appendText($value);
205     return $aelem;
206   }
207   function appendElementXML($name, $xmldata) {
208     $aelem = $this->appendChild($this->createElement($name));
209     $aelem->appendXMLMarkup($xmldata);
210     //$aelem->appendChild($this->createXMLFragment($xmldata));
211     return $aelem;
212   }
213   function appendLink($target, $value = '') {
214     return $this->appendChild($this->createElementLink($target, $value));
215   }
216   function appendImage($src, $alt_text = '') {
217     return $this->appendChild($this->createElementImage($src, $alt_text));
218   }
219   function appendForm($action, $method, $name, $id = null) {
220     return $this->appendChild($this->createElementForm($action, $method, $name, $id));
221   }
222   function appendFormDiv($action, $method, $name, $id = null) {
223     $formelem = $this->appendChild($this->createElementForm($action, $method, $name, $id));
224     return $formelem->appendElement('div');
225   }
226   function appendInputHidden($name, $value) {
227     return $this->appendChild($this->createElementInputHidden($name, $value));
228   }
229   function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
230     return $this->appendChild($this->createElementInputText($name, $maxlength, $size, $id, $value));
231   }
232   function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
233     return $this->appendChild($this->createElementInputNumber($name, $maxlength, $size, $id, $value));
234   }
235   function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
236     return $this->appendChild($this->createElementInputPassword($name, $maxlength, $size, $id, $value));
237   }
238   function appendInputRadio($name, $id, $value, $checked) {
239     return $this->appendChild($this->createElementInputRadio($name, $id, $value, $checked));
240   }
241   function appendInputCheckbox($name, $id, $value, $checked) {
242     return $this->appendChild($this->createElementInputCheckbox($name, $id, $value, $checked));
243   }
244   function appendInputSubmit($value) {
245     return $this->appendChild($this->createElementInputSubmit($value));
246   }
247   function appendButton($value, $onclick = null) {
248     return $this->appendChild($this->createElementButton($value, $onclick));
249   }
250   function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
251     return $this->appendChild($this->createElementTextArea($name, $columns, $rows, $id, $value));
252   }
253   function appendElementSelect($name, $id = null, $options = array(), $default = null) {
254     return $this->appendChild($this->createElementSelect($name, $id, $options, $default));
255   }
256   function appendElementOption($key, $desc, $selected = false) {
257     return $this->appendChild($this->createElementOption($key, $desc, $selected));
258   }
259   function appendLabel($for_id, $value) {
260     return $this->appendChild($this->createElementLabel($for_id, $value));
261   }
262   function appendText($text) {
263     return $this->appendChild($this->createTextNode($text));
264   }
265   function appendComment($comment_data) {
266     return $this->appendChild($this->createComment($comment_data));
267   }
268   function appendJSElement($jsdata) {
269     $this->appendChild($this->createElementJS($jsdata));
270   }
271   function appendCOMElement($module, $attributes) {
272     $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
273   }
274
275   function appendHTMLMarkup($htmldata, $parentNode = null) {
276     if (is_null($parentNode)) { $parentNode =& $this; }
277     // XXX: just a workaround for now!
278     $parentNode->appendChild($this->createCDATASection($htmldata));
279   }
280
281   function appendXMLMarkup($xmldata, $parentNode = null) {
282     if (is_null($parentNode)) { $parentNode =& $this; }
283     $tmpdoc = new ExtendedDocument;
284     $tmpxml = '<?xml version="1.0" encoding="utf-8"?>'."\n";
285     $tmpxml .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n";
286     $tmpxml .= '<root>'.$xmldata.'</root>';
287     $tmpdoc->loadXML($tmpxml);
288     foreach ($tmpdoc->getElementsByTagName('root')->item(0)->childNodes as $child) {
289       $parentNode->appendChild($this->importNode($child, true));
290     }
291   }
292
293   function createElementLink($target, $value = '') {
294     $link = $this->createElement('a');
295     $link->appendText($value);
296     $link->setAttribute('href', $target); // XXX: take care of & etc. in links
297     return $link;
298   }
299
300   function createElementImage($src, $alt_text = '') {
301     $img = $this->createElement('img');
302     $img->setAttribute('src', $src);
303     $img->setAttribute('alt', $alt_text);
304     return $img;
305   }
306
307   function createElementForm($action, $method, $name, $id = null) {
308     $formelem = $this->createElement('form');
309     $formelem->setAttribute('action', $action);
310     $formelem->setAttribute('method', $method);
311     $formelem->setAttribute('name', $name);
312     $formelem->setAttribute('id', $id);
313     return $formelem;
314   }
315
316   function createElementInputHidden($name, $value) {
317     $hidden = $this->createElement('input');
318     $hidden->setAttribute('type', 'hidden');
319     $hidden->setAttribute('name', $name);
320     $hidden->setAttribute('value', $value);
321     return $hidden;
322   }
323
324   function createElementInputText($name, $maxlength, $size, $id = null, $value = null) {
325     $txfield = $this->createElement('input');
326     $txfield->setAttribute('type', 'text');
327     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
328     $txfield->setAttribute('name', $name);
329     $txfield->setAttribute('maxlength', $maxlength);
330     $txfield->setAttribute('size', $size);
331     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
332     return $txfield;
333   }
334
335   function createElementInputNumber($name, $maxlength, $size, $id = null, $value = null) {
336     $txfield = $this->createElement('input');
337     $txfield->setAttribute('type', 'number');
338     if (!is_null($id)) { $txfield->setAttribute('id', $id); }
339     $txfield->setAttribute('name', $name);
340     $txfield->setAttribute('maxlength', $maxlength);
341     $txfield->setAttribute('size', $size);
342     if (!is_null($value)) { $txfield->setAttribute('value', $value); }
343     return $txfield;
344   }
345
346   function createElementInputPassword($name, $maxlength, $size, $id = null, $value = null) {
347     $pwfield = $this->createElement('input');
348     $pwfield->setAttribute('type', 'password');
349     if (!is_null($id)) { $pwfield->setAttribute('id', $id); }
350     $pwfield->setAttribute('name', $name);
351     $pwfield->setAttribute('maxlength', $maxlength);
352     $pwfield->setAttribute('size', $size);
353     if (!is_null($value)) { $pwfield->setAttribute('value', $value); }
354     return $pwfield;
355   }
356
357   function createElementInputRadio($name, $id, $value, $checked) {
358     $radio = $this->createElement('input');
359     $radio->setAttribute('type', 'radio');
360     $radio->setAttribute('name', $name);
361     $radio->setAttribute('id', $id);
362     $radio->setAttribute('value', $value);
363     if ($checked) { $radio->setAttribute('checked', ''); }
364     return $radio;
365   }
366
367   function createElementInputCheckbox($name, $id, $value, $checked) {
368     $cbox = $this->createElement('input');
369     $cbox->setAttribute('type', 'checkbox');
370     $cbox->setAttribute('name', $name);
371     $cbox->setAttribute('id', $id);
372     $cbox->setAttribute('value', $value);
373     if ($checked) { $cbox->setAttribute('checked', ''); }
374     return $cbox;
375   }
376
377   function createElementInputSubmit($value) {
378     $submitbtn = $this->createElement('input');
379     $submitbtn->setAttribute('type', 'submit');
380     $submitbtn->setAttribute('value', $value);
381     return $submitbtn;
382   }
383
384   function createElementButton($value, $onclick = null) {
385     $btn = $this->createElement('input');
386     $btn->setAttribute('type', 'button');
387     $btn->setAttribute('value', $value);
388     if (!is_null($onclick)) { $btn->setAttribute('onclick', $onclick); }
389     return $btn;
390   }
391
392   function createElementTextArea($name, $columns, $rows, $id = null, $value = null) {
393     $txtarea = $this->createElement('textarea', $value);
394     $txtarea->setAttribute('name', $name);
395     $txtarea->setAttribute('cols', $columns);
396     $txtarea->setAttribute('rows', $rows);
397     if (!is_null($id)) { $txtarea->setAttribute('id', $id); }
398     return $txtarea;
399   }
400
401   function createElementSelect($name, $id = null, $options = array(), $default = null) {
402     $select = $this->createElement('select');
403     $select->setAttribute('name', $name);
404     if (!is_null($id)) { $select->setAttribute('id', $id); }
405     foreach ($options as $key => $desc) {
406       $select->appendElementOption($key, $desc, ($key == $default));
407     }
408     return $select;
409   }
410
411   function createElementOption($key, $desc, $selected = false) {
412     $option = $this->createElement('option', $desc);
413     $option->setAttribute('value', $key);
414     if ($selected) { $option->setAttribute('selected', ''); }
415     return $option;
416   }
417
418   function createElementLabel($for_id, $value) {
419     $label = $this->createElement('label', $value);
420     $label->setAttribute('for', $for_id);
421     return $label;
422   }
423
424   function createElementJS($jsdata) {
425     $jselem = $this->createElement('script');
426     $jselem->setAttribute('type', 'text/javascript');
427     $jselem->appendChild($this->createCDATASection($jsdata));
428     return $jselem;
429   }
430
431   function createCOMElement($module, $attributes) {
432     $com_elem = $this->createElementNS(COM_NS, $module);
433     if (is_array($attributes) && count($attributes)) {
434       foreach ($attributes as $name=>$value) {
435         $com_elem->setAttribute($name, $value);
436       }
437     }
438     return $com_elem;
439   }
440 }
441
442 class ExtendedElement extends DOMElement {
443   // ExtendedElement PHP class
444   // this extends the general PHP DOM Element class to simplify some usual constructs
445   //
446   // function appendElement($name, [$value])
447   //   appends a DOMDocument::createElement() as a child of this element (see there for params)
448   //     returns the new child
449   //
450   // function appendElementXML($name, $xmldata)
451   //   appends a DOMDocument::createElement() with the given name as a child of this element,
452   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
453   //     returns the new child
454   //
455   // function appendLink($target, [$value])
456   //   appends an ExtendedDocument::createElementLink() as a child of this element (see there for params)
457   //     returns the new child
458   //
459   // function appendImage($src, [$alt_text])
460   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
461   //     returns the new child
462   //
463   // function appendForm($action, $method, $name, [$id])
464   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
465   //     returns the new child
466   //
467   // function appendFormDiv($action, $method, $name, [$id])
468   //   appends an ExtendedDocument::createElementForm() as a child of this element (see there for params)
469   //     returns an HTML <div> that is a child of the new child
470   //
471   // function appendInputHidden($name, $value)
472   //   appends an ExtendedDocument::createElementInputHidden() as a child of this element (see there for params)
473   //     returns the new child
474   //
475   // function appendInputText($name, $maxlength, $size, [$id], [$value])
476   //   appends an ExtendedDocument::createElementInputText() as a child of this element (see there for params)
477   //     returns the new child
478   //
479   // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
480   //   appends an ExtendedDocument::createElementInputNumber() as a child of this element (see there for params)
481   //     returns the new child
482   //
483   // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
484   //   appends an ExtendedDocument::createElementInputPassword() as a child of this element (see there for params)
485   //     returns the new child
486   //
487   // function appendInputRadio($name, $id, $value, $checked)
488   //   appends an ExtendedDocument::createElementInputRadio() as a child of this element (see there for params)
489   //     returns the new child
490   //
491   // function appendInputCheckbox($name, $id, $value, $checked)
492   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this element (see there for params)
493   //     returns the new child
494   //
495   // function appendInputSubmit($value)
496   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this element (see there for params)
497   //     returns the new child
498   //
499   // function appendButton($value, $onclick = null)
500   //   appends an ExtendedDocument::createElementButton() as a child of this element (see there for params)
501   //     returns the new child
502   //
503   // function appendTextArea($name, $columns, $rows, [$id], [$value])
504   //   appends an ExtendedDocument::createElementTextArea() as a child of this element (see there for params)
505   //     returns the new child
506   //
507   // function appendElementSelect($name, [$id], [$options], [$default])
508   //   appends an ExtendedDocument::createElementSelect() as a child of this element (see there for params)
509   //     returns the new child
510   //
511   // function appendElementOption($key, $desc, [$selected])
512   //   appends an ExtendedDocument::createElementOption() as a child of this element (see there for params)
513   //     returns the new child
514   //
515   // function appendLabel($for_id, $value)
516   //   appends an ExtendedDocument::createElementLabel() as a child of this element (see there for params)
517   //     returns the new child
518   //
519   // function appendText($text)
520   //   appends a DOMDocument::createTextNode() as a child of this element (see there for params)
521   //     returns the new child
522   //
523   // function appendComment($comment_data)
524   //   appends a DOMDocument::createComment() as a child of this element (see there for params)
525   //     returns the new child
526   //
527   // function appendHTMLMarkup($htmldata)
528   //   appends a representation of the HTML data as children of this element
529   //     NO return value!
530   //
531   // function appendXMLMarkup($xmldata)
532   //   appends a representation of the XML data as children of this element
533   //     NO return value!
534   //
535   // function appendJSElement($jsdata)
536   //   appends an ExtendedDocument::createElementJS() as a child of this element (see there for params)
537   //     NO return value!
538   //
539   // function appendCOMElement($module, $attributes)
540   //   appends an ExtendedDocument::createCOMElement() as a child of this element (see there for params)
541   //     returns the new child
542
543   function appendElement($name, $value = '') {
544     // Adding the $value in createElement does NOT escape it, so use appendText to support that.
545     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
546     $aelem->appendText($value);
547     return $aelem;
548   }
549   function appendElementXML($name, $xmldata) {
550     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
551     $aelem->appendXMLMarkup($xmldata);
552     return $aelem;
553   }
554   function appendLink($target, $value = '') {
555     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
556   }
557   function appendImage($src, $alt_text = '') {
558     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
559   }
560   function appendForm($action, $method, $name, $id = null) {
561     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
562   }
563   function appendFormDiv($action, $method, $name, $id = null) {
564     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
565     return $formelem->appendElement('div');
566   }
567   function appendInputHidden($name, $value) {
568     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
569   }
570   function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
571     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
572   }
573   function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
574     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
575   }
576   function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
577     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
578   }
579   function appendInputRadio($name, $id, $value, $checked) {
580     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
581   }
582   function appendInputCheckbox($name, $id, $value, $checked) {
583     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
584   }
585   function appendInputSubmit($value) {
586     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
587   }
588   function appendButton($value, $onclick = null) {
589     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
590   }
591   function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
592     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
593   }
594   function appendElementSelect($name, $id = null, $options = array(), $default = null) {
595     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
596   }
597   function appendElementOption($key, $desc, $selected = false) {
598     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
599   }
600   function appendLabel($for_id, $value) {
601     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
602   }
603   function appendText($text) {
604     return $this->appendChild($this->ownerDocument->createTextNode($text));
605   }
606   function appendComment($comment_data) {
607     return $this->appendChild($this->ownerDocument->createComment($comment_data));
608   }
609   function appendHTMLMarkup($htmldata) {
610     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
611   }
612   function appendXMLMarkup($xmldata) {
613     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
614   }
615   function appendJSElement($jsdata) {
616     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
617   }
618   function appendCOMElement($module, $attributes) {
619     $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
620   }
621 }
622
623 class ExtendedDocumentFragment extends DOMDocumentFragment {
624   // ExtendedDocumentFragment PHP class
625   // this extends the general PHP DOM Document Fragment class to simplify some usual constructs
626   //
627   // function appendElement($name, [$value])
628   //   appends a DOMDocument::createElement() as a child of this fragment (see there for params)
629   //     returns the new child
630   //
631   // function appendElementXML($name, $xmldata)
632   //   appends a DOMDocument::createElement() with the given name as a child of this fragment,
633   //   with an ExtendedDocument::createXMLFragment() of the given XML data inside
634   //     returns the new child
635   //
636   // function appendLink($target, [$value])
637   //   appends an ExtendedDocument::createElementLink() as a child of this fragment (see there for params)
638   //     returns the new child
639   //
640   // function appendImage($src, [$alt_text])
641   //   appends an ExtendedDocument::createElementImage() as a child of this document (see there for params)
642   //     returns the new child
643   //
644   // function appendForm($action, $method, $name, [$id])
645   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
646   //     returns the new child
647   //
648   // function appendFormDiv($action, $method, $name, [$id])
649   //   appends an ExtendedDocument::createElementForm() as a child of this fragment (see there for params)
650   //     returns an HTML <div> that is a child of the new child
651   //
652   // function appendInputHidden($name, $value)
653   //   appends an ExtendedDocument::createElementInputHidden() as a child of this fragment (see there for params)
654   //     returns the new child
655   //
656   // function appendInputText($name, $maxlength, $size, [$id], [$value])
657   //   appends an ExtendedDocument::createElementInputText() as a child of this fragment (see there for params)
658   //     returns the new child
659   //
660   // function appendInputNumber($name, $maxlength, $size, [$id], [$value])
661   //   appends an ExtendedDocument::createElementInputNumber() as a child of this fragment (see there for params)
662   //     returns the new child
663   //
664   // function appendInputPassword($name, $maxlength, $size, [$id], [$value])
665   //   appends an ExtendedDocument::createElementInputPassword() as a child of this fragment (see there for params)
666   //     returns the new child
667   //
668   // function appendInputRadio($name, $id, $value, $checked)
669   //   appends an ExtendedDocument::createElementInputRadio() as a child of this fragment (see there for params)
670   //     returns the new child
671   //
672   // function appendInputCheckbox($name, $id, $value, $checked)
673   //   appends an ExtendedDocument::createElementInputCheckbox() as a child of this fragment (see there for params)
674   //     returns the new child
675   //
676   // function appendInputSubmit($value)
677   //   appends an ExtendedDocument::createElementInputSubmit() as a child of this fragment (see there for params)
678   //     returns the new child
679   //
680   // function appendButton($value, $onclick = null)
681   //   appends an ExtendedDocument::createElementButton() as a child of this fragment (see there for params)
682   //     returns the new child
683   //
684   // function appendTextArea($name, $columns, $rows, [$id], [$value])
685   //   appends an ExtendedDocument::createElementTextArea() as a child of this fragment (see there for params)
686   //     returns the new child
687   //
688   // function appendElementSelect($name, [$id], [$options], [$default])
689   //   appends an ExtendedDocument::createElementSelect() as a child of this fragment (see there for params)
690   //     returns the new child
691   //
692   // function appendElementOption($key, $desc, [$selected])
693   //   appends an ExtendedDocument::createElementOption() as a child of this fragment (see there for params)
694   //     returns the new child
695   //
696   // function appendLabel($for_id, $value)
697   //   appends an ExtendedDocument::createElementLabel() as a child of this fragment (see there for params)
698   //     returns the new child
699   //
700   // function appendText($text)
701   //   appends a DOMDocument::createTextNode() as a child of this fragment (see there for params)
702   //     returns the new child
703   //
704   // function appendComment($comment_data)
705   //   appends a DOMDocument::createComment() as a child of this fragment (see there for params)
706   //     returns the new child
707   //
708   // function appendHTMLMarkup($htmldata)
709   //   appends a representation of the HTML data as children of this fragment
710   //     NO return value!
711   //
712   // function appendXMLMarkup($xmldata)
713   //   appends a representation of the XML data as children of this fragment
714   //     NO return value!
715   //
716   // function appendJSElement($jsdata)
717   //   appends an ExtendedDocument::createElementJS() as a child of this fragment (see there for params)
718   //     NO return value!
719   //
720   // function appendCOMElement($module, $attributes)
721   //   appends an ExtendedDocument::createCOMElement() as a child of this fragment (see there for params)
722   //     returns the new child
723
724   function appendElement($name, $value = '') {
725     // Adding the $value in createElement does NOT escape it, so use appendText to support that.
726     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
727     $aelem->appendText($value);
728     return $aelem;
729   }
730   function appendElementXML($name, $xmldata) {
731     $aelem = $this->appendChild($this->ownerDocument->createElement($name));
732     $aelem->appendXMLMarkup($xmldata);
733     return $aelem;
734   }
735   function appendLink($target, $value = '') {
736     return $this->appendChild($this->ownerDocument->createElementLink($target, $value));
737   }
738   function appendImage($src, $alt_text = '') {
739     return $this->appendChild($this->ownerDocument->createElementImage($src, $alt_text));
740   }
741   function appendForm($action, $method, $name, $id = null) {
742     return $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
743   }
744   function appendFormDiv($action, $method, $name, $id = null) {
745     $formelem = $this->appendChild($this->ownerDocument->createElementForm($action, $method, $name, $id));
746     return $formelem->appendElement('div');
747   }
748   function appendInputHidden($name, $value) {
749     return $this->appendChild($this->ownerDocument->createElementInputHidden($name, $value));
750   }
751   function appendInputText($name, $maxlength, $size, $id = null, $value = null) {
752     return $this->appendChild($this->ownerDocument->createElementInputText($name, $maxlength, $size, $id, $value));
753   }
754   function appendInputNumber($name, $maxlength, $size, $id = null, $value = null) {
755     return $this->appendChild($this->ownerDocument->createElementInputNumber($name, $maxlength, $size, $id, $value));
756   }
757   function appendInputPassword($name, $maxlength, $size, $id = null, $value = null) {
758     return $this->appendChild($this->ownerDocument->createElementInputPassword($name, $maxlength, $size, $id, $value));
759   }
760   function appendInputRadio($name, $id, $value, $checked) {
761     return $this->appendChild($this->ownerDocument->createElementInputRadio($name, $id, $value, $checked));
762   }
763   function appendInputCheckbox($name, $id, $value, $checked) {
764     return $this->appendChild($this->ownerDocument->createElementInputCheckbox($name, $id, $value, $checked));
765   }
766   function appendInputSubmit($value) {
767     return $this->appendChild($this->ownerDocument->createElementInputSubmit($value));
768   }
769   function appendButton($value, $onclick = null) {
770     return $this->appendChild($this->ownerDocument->createElementButton($value, $onclick));
771   }
772   function appendTextArea($name, $columns, $rows, $id = null, $value = null) {
773     return $this->appendChild($this->ownerDocument->createElementTextArea($name, $columns, $rows, $id, $value));
774   }
775   function appendElementSelect($name, $id = null, $options = array(), $default = null) {
776     return $this->appendChild($this->ownerDocument->createElementSelect($name, $id, $options, $default));
777   }
778   function appendElementOption($key, $desc, $selected = false) {
779     return $this->appendChild($this->ownerDocument->createElementOption($key, $desc, $selected));
780   }
781   function appendLabel($for_id, $value) {
782     return $this->appendChild($this->ownerDocument->createElementLabel($for_id, $value));
783   }
784   function appendText($text) {
785     return $this->appendChild($this->ownerDocument->createTextNode($text));
786   }
787   function appendComment($comment_data) {
788     return $this->appendChild($this->ownerDocument->createComment($comment_data));
789   }
790   function appendHTMLMarkup($htmldata) {
791     $this->ownerDocument->appendHTMLMarkup($htmldata, $this);
792   }
793   function appendXMLMarkup($xmldata) {
794     $this->ownerDocument->appendXMLMarkup($xmldata, $this);
795   }
796   function appendJSElement($jsdata) {
797     $this->appendChild($this->ownerDocument->createElementJS($jsdata));
798   }
799   function appendCOMElement($module, $attributes) {
800     $this->appendChild($this->ownerDocument->createCOMElement($module, $attributes));
801   }
802 }
803 ?>