commit | author | age
|
836f83
|
1 |
<?php |
T |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class tform_tpl_generator { |
b1a6a5
|
32 |
|
MC |
33 |
function buildHTML($formDef, $tab) { |
|
34 |
|
836f83
|
35 |
global $app; |
b1a6a5
|
36 |
|
836f83
|
37 |
$module = $_SESSION["s"]["module"]["name"]; |
b1a6a5
|
38 |
|
836f83
|
39 |
$html = '<h2><tmpl_var name="list_head_txt"></h2> |
T |
40 |
<p><tmpl_var name="list_desc_txt"></p> |
|
41 |
|
|
42 |
<div class="panel panel_'.$formDef['name'].'"> |
|
43 |
|
|
44 |
<div class="pnl_formsarea"> |
|
45 |
<fieldset class="inlineLabels"><legend>'.$formDef['tabs'][$tab]['title'].'</legend>'; |
|
46 |
|
|
47 |
$lang = array(); |
|
48 |
$html_reqestedelement = "<em>*</em> "; |
|
49 |
|
|
50 |
foreach($formDef['tabs'][$tab]['fields'] as $key => $field) { |
|
51 |
if ($field['required'] == true ) { $html_reqcode = $html_reqestedelement; } else { $html_reqcode = ''; } |
|
52 |
|
|
53 |
switch ($field['formtype']) { |
b1a6a5
|
54 |
case 'TEXT': |
MC |
55 |
$html .= " |
836f83
|
56 |
<div class=\"ctrlHolder\"> |
T |
57 |
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> |
|
58 |
<input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"text\" class=\"textInput\" /> |
|
59 |
</div>"; |
|
60 |
break; |
b1a6a5
|
61 |
case 'TEXTAREA': |
MC |
62 |
$html .= " |
836f83
|
63 |
<div class=\"ctrlHolder\"> |
T |
64 |
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> |
|
65 |
<textarea name=\"".$key."\" id=\"".$key."\" rows='".$field['rows']."' cols='".$field['cols']."'>{tmpl_var name='".$key."'}</textarea> |
|
66 |
</div>"; |
|
67 |
break; |
b1a6a5
|
68 |
case 'SELECT': |
MC |
69 |
$html .= " |
836f83
|
70 |
<div class=\"ctrlHolder\"> |
T |
71 |
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> |
|
72 |
<select name=\"".$key."\" id=\"".$key."\" class=\"selectInput\"> |
|
73 |
{tmpl_var name='".$key."'} |
|
74 |
</select> |
|
75 |
</div>"; |
|
76 |
break; |
b1a6a5
|
77 |
case 'MULTIPLE': |
MC |
78 |
$html .= " |
836f83
|
79 |
<div class=\"ctrlHolder\"> |
T |
80 |
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> |
|
81 |
<select multiple name=\"".$key."\" id=\"".$key."\" class=\"selectInput\"> |
|
82 |
{tmpl_var name='".$key."'} |
|
83 |
</select> |
|
84 |
</div>"; |
|
85 |
break; |
b1a6a5
|
86 |
case 'PASSWORD': |
MC |
87 |
$html .= " |
836f83
|
88 |
<div class=\"ctrlHolder\"> |
T |
89 |
<label for=\"".$key."\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</label> |
|
90 |
<input name=\"".$key."\" id=\"".$key."\" value=\"{tmpl_var name='".$key."'}\" size=\"".$field['width']."\" maxlength=\"".$field['maxlength']."\" type=\"password\" class=\"textInput\" /> |
|
91 |
</div>"; |
|
92 |
break; |
b1a6a5
|
93 |
case 'CHECKBOX': |
MC |
94 |
$html .= " |
836f83
|
95 |
<div class=\"ctrlHolder\"> |
T |
96 |
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> |
|
97 |
<div class=\"multiField\"> |
|
98 |
{tmpl_var name='".$key."'} |
|
99 |
</div> |
|
100 |
</div>"; |
|
101 |
break; |
b1a6a5
|
102 |
case 'CHECKBOXARRAY': |
MC |
103 |
$html .= " |
836f83
|
104 |
<div class=\"ctrlHolder\"> |
T |
105 |
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> |
|
106 |
<div class=\"multiField\"> |
|
107 |
{tmpl_var name='".$key."'} |
|
108 |
</div> |
|
109 |
</div>"; |
|
110 |
break; |
b1a6a5
|
111 |
case 'RADIO': |
MC |
112 |
$html .= " |
836f83
|
113 |
<div class=\"ctrlHolder\"> |
T |
114 |
<p class=\"label\">".$html_reqcode."{tmpl_var name='".$key."_txt'}</p> |
|
115 |
<div class=\"multiField\"> |
|
116 |
{tmpl_var name='".$key."'} |
|
117 |
</div> |
|
118 |
</div>"; |
|
119 |
break; |
|
120 |
} |
b1a6a5
|
121 |
|
a9d0b2
|
122 |
// Language File Eintrag für "Feld-Titel" anlegen |
836f83
|
123 |
$lang[$key."_txt"] = $key; |
b1a6a5
|
124 |
|
a9d0b2
|
125 |
// language File Eintrag, für error-Text anlegen |
836f83
|
126 |
if(isset($field["errmsg"]) && $field["errmsg"] != '') { |
T |
127 |
$errmsg = $field["errmsg"]; |
|
128 |
$lang[$errmsg] = $errmsg; |
|
129 |
} |
b1a6a5
|
130 |
|
836f83
|
131 |
} |
b1a6a5
|
132 |
|
836f83
|
133 |
$html .= " |
T |
134 |
</fieldset> |
|
135 |
|
|
136 |
<input type=\"hidden\" name=\"id\" value=\"{tmpl_var name='id'}\"> |
|
137 |
|
|
138 |
<div class=\"buttonHolder buttons\"> |
e27086
|
139 |
<button class=\"positive iconstxt icoPositive\" type=\"button\" value=\"{tmpl_var name='btn_save_txt'}\" onclick=\"submitForm('pageForm','".$module."/".$formDef["action"]."');\"><span>{tmpl_var name='btn_save_txt'}</span></button> |
M |
140 |
<button class=\"negative iconstxt icoNegative\" type=\"button\" value=\"{tmpl_var name='btn_cancel_txt'}\" onclick=\"loadContent('".$module."/".$formDef["list_default"]."');\"><span>{tmpl_var name='btn_cancel_txt'}</span></button> |
836f83
|
141 |
</div> |
T |
142 |
</div> |
b1a6a5
|
143 |
|
836f83
|
144 |
</div> |
T |
145 |
"; |
|
146 |
|
b1a6a5
|
147 |
|
836f83
|
148 |
// speichere Template |
b1a6a5
|
149 |
if (!$handle = fopen($formDef['tabs'][$tab]['template'], 'w')) { |
MC |
150 |
print "Cannot open file (".$formDef['tabs'][$tab]['template'].")"; |
|
151 |
exit; |
|
152 |
} |
|
153 |
|
|
154 |
if (!fwrite($handle, $html)) { |
|
155 |
print "Cannot write to file ($filename)"; |
|
156 |
exit; |
836f83
|
157 |
} |
T |
158 |
fclose($handle); |
b1a6a5
|
159 |
|
MC |
160 |
$this->lng_add($lang, $formDef); |
|
161 |
|
a9d0b2
|
162 |
// überprüfe, ob es die Tabelle schon gibt, |
836f83
|
163 |
// ansonsten wird sie angelegt |
T |
164 |
$tables = $app->db->getTables(); |
b1a6a5
|
165 |
|
MC |
166 |
if(!@in_array($formDef['db_table'], $tables)) { |
836f83
|
167 |
// Datenbank noch nicht vorhanden |
b1a6a5
|
168 |
|
836f83
|
169 |
$columns = array(); |
b1a6a5
|
170 |
|
a9d0b2
|
171 |
// füge ID Feld hinzu |
b1a6a5
|
172 |
$col = array( 'action' => 'add', |
MC |
173 |
'name' => $formDef["db_table_idx"], |
|
174 |
'type' => 'int64', |
|
175 |
'typeValue' => '', |
|
176 |
'defaultValue' => false, |
|
177 |
'notNull' => true, |
|
178 |
'autoInc' => true, |
|
179 |
'option' => 'primary' |
|
180 |
); |
|
181 |
|
836f83
|
182 |
$columns[] = $col; |
T |
183 |
$app->db->show_error_messages = true; |
b1a6a5
|
184 |
|
836f83
|
185 |
if($formDef["auth"] == 'yes') { |
b1a6a5
|
186 |
|
MC |
187 |
$col = array( 'action' => 'add', |
|
188 |
'name' => 'sys_userid', |
|
189 |
'type' => 'int32', |
|
190 |
'typeValue' => '', |
|
191 |
'defaultValue' => '0', |
|
192 |
'notNull' => true |
|
193 |
); |
836f83
|
194 |
$columns[] = $col; |
b1a6a5
|
195 |
$col = array( 'action' => 'add', |
MC |
196 |
'name' => 'sys_groupid', |
|
197 |
'type' => 'int32', |
|
198 |
'typeValue' => '', |
|
199 |
'defaultValue' => '0', |
|
200 |
'notNull' => true |
|
201 |
); |
836f83
|
202 |
$columns[] = $col; |
b1a6a5
|
203 |
$col = array( 'action' => 'add', |
MC |
204 |
'name' => 'sys_perm_user', |
|
205 |
'type' => 'varchar', |
|
206 |
'typeValue' => '5', |
|
207 |
'defaultValue' => 'NULL', |
|
208 |
'notNull' => true |
|
209 |
); |
836f83
|
210 |
$columns[] = $col; |
b1a6a5
|
211 |
$col = array( 'action' => 'add', |
MC |
212 |
'name' => 'sys_perm_group', |
|
213 |
'type' => 'varchar', |
|
214 |
'typeValue' => '5', |
|
215 |
'defaultValue' => 'NULL', |
|
216 |
'notNull' => true |
|
217 |
); |
836f83
|
218 |
$columns[] = $col; |
b1a6a5
|
219 |
$col = array( 'action' => 'add', |
MC |
220 |
'name' => 'sys_perm_other', |
|
221 |
'type' => 'varchar', |
|
222 |
'typeValue' => '5', |
|
223 |
'defaultValue' => 'NULL', |
|
224 |
'notNull' => true |
|
225 |
); |
836f83
|
226 |
$columns[] = $col; |
b1a6a5
|
227 |
|
836f83
|
228 |
} |
b1a6a5
|
229 |
|
MC |
230 |
|
836f83
|
231 |
foreach($formDef['tabs'] as $tab) { |
T |
232 |
foreach($tab["fields"] as $name => $field) { |
|
233 |
/* |
|
234 |
$columns = array(action => add | alter | drop |
|
235 |
name => Spaltenname |
|
236 |
name_new => neuer Spaltenname, nur bei 'alter' belegt |
|
237 |
type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob |
|
238 |
typeValue => Wert z.B. bei Varchar |
|
239 |
defaultValue => Default Wert |
|
240 |
notNull => true | false |
|
241 |
autoInc => true | false |
|
242 |
option => unique | primary | index) |
b1a6a5
|
243 |
|
MC |
244 |
|
836f83
|
245 |
*/ |
T |
246 |
switch ($field["datatype"]) { |
b1a6a5
|
247 |
case 'INTEGER': |
MC |
248 |
$type = 'int32'; |
|
249 |
$typevalue = ''; |
|
250 |
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; |
836f83
|
251 |
break; |
b1a6a5
|
252 |
case 'DOUBLE': |
MC |
253 |
$type = 'double'; |
|
254 |
$typevalue = ''; |
|
255 |
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; |
836f83
|
256 |
break; |
b1a6a5
|
257 |
case 'CURRENCY': |
MC |
258 |
$type = 'double'; |
|
259 |
$typevalue = ''; |
|
260 |
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; |
836f83
|
261 |
break; |
b1a6a5
|
262 |
case 'VARCHAR': |
MC |
263 |
$type = 'varchar'; |
|
264 |
$typeValue = ($field["maxlength"] > 0 and $field["maxlength"] <= 256)?$field["maxlength"]:255; |
|
265 |
// $defaultValue = ($field["default"] != '')?$field["default"]:'NOT NULL'; |
|
266 |
$defaultValue = ($field["default"] != '')?$field["default"]:'NULL'; |
836f83
|
267 |
break; |
b1a6a5
|
268 |
case 'TEXT': |
MC |
269 |
$type = 'text'; |
|
270 |
$typevalue = ''; |
|
271 |
$defaultValue = 'NULL'; |
836f83
|
272 |
break; |
b1a6a5
|
273 |
case 'DATE': |
MC |
274 |
$type = 'int64'; |
|
275 |
$typevalue = ''; |
|
276 |
$defaultValue = ($field["default"] != '')?$field["default"]:'0'; |
836f83
|
277 |
break; |
T |
278 |
} |
b1a6a5
|
279 |
|
MC |
280 |
|
|
281 |
$col = array( 'action' => 'add', |
|
282 |
'name' => $name, |
|
283 |
'type' => $type, |
|
284 |
'typeValue' => $typeValue, |
|
285 |
'defaultValue' => $defaultValue, |
|
286 |
'notNull' => true |
|
287 |
); |
|
288 |
|
836f83
|
289 |
$columns[] = $col; |
T |
290 |
} |
|
291 |
} |
b1a6a5
|
292 |
|
MC |
293 |
$app->db->createTable($formDef["db_table"], $columns); |
|
294 |
|
836f83
|
295 |
} |
9ac2fa
|
296 |
} |
b1a6a5
|
297 |
|
MC |
298 |
function lng_add($lang, $formDef) { |
|
299 |
global $go_api, $go_info, $conf; |
|
300 |
|
836f83
|
301 |
$lng_file = "lib/lang/".$conf["language"]."_".$formDef['name'].".lng"; |
T |
302 |
if(is_file($lng_file)) { |
b1a6a5
|
303 |
include $lng_file; |
836f83
|
304 |
} else { |
T |
305 |
$wb = array(); |
|
306 |
} |
b1a6a5
|
307 |
|
MC |
308 |
$wb_out = array_merge($lang, $wb); |
|
309 |
|
836f83
|
310 |
if(is_array($wb_out)) { |
b1a6a5
|
311 |
$fp = fopen($lng_file, "w"); |
MC |
312 |
fwrite($fp, "<?php\n"); |
836f83
|
313 |
foreach($wb_out as $key => $val) { |
28d1b5
|
314 |
$new_line = '$wb["'.$key.'"] = '."'$val';\n"; |
b1a6a5
|
315 |
fwrite($fp, $new_line); |
MC |
316 |
|
836f83
|
317 |
} |
b1a6a5
|
318 |
fwrite($fp, "?>"); |
836f83
|
319 |
fclose($fp); |
T |
320 |
} |
|
321 |
} |
b1a6a5
|
322 |
|
836f83
|
323 |
} |
T |
324 |
|
b1a6a5
|
325 |
?> |