Use (c) instead of the actual copyright symbol to avoid the really annoying character...
[isso.git] / PrinterRootElementForm.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-2007 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Printer Root Element: Form (PrinterRootElementForm.php)
24 *
25 * @package ISSO
26 */
27
28 require_once('ISSO/PrinterRootElement.php');
29
30 /**
31 * Printer Root Element: Form
32 *
33 * Represents a <form> object. This can have a parent or not: if it does,
34 * then it will be painted as a child, otherwise it will act as a root.
35 *
36 * @author Blue Static
37 * @copyright Copyright (c)2002 - 2007, Blue Static
38 * @package ISSO
39 *
40 */
41 class BSPrinterRootElementForm extends BSPrinterRootElement
42 {
43 /**
44 * The form's action (or the controller to respond to)
45 * @var string
46 */
47 private $controller;
48
49 /**
50 * Method to use
51 * @var string
52 */
53 private $action;
54
55 /**
56 * The form's name
57 * @var string
58 */
59 private $name;
60
61 /**
62 * This form is upload-ready
63 * @var bool
64 */
65 private $upload;
66
67 // ###################################################################
68 /**
69 * Constructor
70 */
71 public function __construct($controller, $action, $name = 'issoform')
72 {
73 $this->controller = $controller;
74 $this->action = $action;
75 $this->name = $name;
76 }
77
78 // ###################################################################
79 /**
80 * Should this form be used for upload?
81 *
82 * @param bool Upload?
83 */
84 public function setUpload($upload)
85 {
86 $this->upload = $upload;
87 }
88
89 // ###################################################################
90 /**
91 * Adds a table row into the child list
92 *
93 * @param BSPrinterElement Table element
94 */
95 public function addChild(BSPrinterElement $tr)
96 {
97 $this->children[] = $tr;
98 }
99
100 // ###################################################################
101 /**
102 * Returns the HTML for all printed children elements
103 *
104 * @return string Printed HTML
105 */
106 protected function _paintChildren()
107 {
108 $builder = '';
109
110 foreach ($this->children AS $child)
111 {
112 $builder .= "\n" . $child->paint();
113 }
114
115 return $builder;
116 }
117
118 // ###################################################################
119 /**
120 * Paints the <table>
121 *
122 * @return string Table HTML code
123 */
124 public function paint()
125 {
126 array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action));
127
128 return "\n<form name=\"" . $this->name . "\" action=\"" . $this->controller . "\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n</form>";
129 }
130 }
131
132 ?>