These two files need to be swapped
[isso.git] / PrinterRootForm.php
1 <?php
2 /*=====================================================================*
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2008 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)2005 - 2008, 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 * Makes a new instance of the object in a static fashion
80 *
81 * @return object
82 */
83 public static function make()
84 {
85 $obj = new ReflectionClass(__CLASS__);
86 $args = func_get_args();
87 return $obj->newInstanceArgs($args);
88 }
89
90 // ###################################################################
91 /**
92 * Should this form be used for upload?
93 *
94 * @param bool Upload?
95 *
96 * @return fluent interface
97 */
98 public function setUpload($upload)
99 {
100 $this->upload = $upload;
101 return $this;
102 }
103
104 // ###################################################################
105 /**
106 * Adds a table row into the child list
107 *
108 * @param BSPrinterElement Table element
109 *
110 * @return fluent interface
111 */
112 public function addChild(BSPrinterElement $tr)
113 {
114 $this->children[] = $tr;
115 return $this;
116 }
117
118 // ###################################################################
119 /**
120 * Returns the HTML for all printed children elements
121 *
122 * @return string Printed HTML
123 */
124 protected function _paintChildren()
125 {
126 $builder = '';
127
128 foreach ($this->children as $child)
129 {
130 $builder .= "\n" . $child->paint();
131 }
132
133 return $builder;
134 }
135
136 // ###################################################################
137 /**
138 * Paints the <table>
139 *
140 * @return string Table HTML code
141 */
142 public function paint()
143 {
144 array_push($this->children, new BSPrinterBaseElement('hidden', 'action', $this->action));
145
146 return "\n<form name=\"" . $this->name . "\" action=\"" . $this->controller . "\" method=\"post\"" . ($this->upload ? ' enctype="mime/multi-part"' : '') . ">\n" . $this->_paintChildren() . "\n</form>";
147 }
148 }
149
150 ?>