[TASK] Remove require statements for classes
[Packages/TYPO3.CMS.git] / typo3 / wizard_forms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Wizard to help make forms (fx. for tt_content elements) of type 'form'.
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36
37 $BACK_PATH = '';
38 require('init.php');
39 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xml');
40
41 /**
42 * API comments:
43 *
44 * The form wizard can help you to create forms - it allows you to create almost any kind of HTML form elements and in any order and amount.
45 *
46 * The format for the resulting configuration code can be either a line-based configuration. That can look like this:
47 *
48 * Your name: | *name=input | (input your name here!)
49 * Your Email: | *email=input
50 * Your address: | address=textarea,40,10
51 * Your Haircolor: | hair=radio |
52 * upload | attachment=file
53 * | quoted_printable=hidden | 0
54 * | formtype_mail=submit | Send form
55 * | html_enabled=hidden
56 * | subject=hidden | This is the subject
57 *
58 *
59 * Alternatively it can be XML. The same configuration from above looks like this in XML:
60 *
61 * <T3FormWizard>
62 * <n2>
63 * <type>input</type>
64 * <label>Your name:</label>
65 * <required>1</required>
66 * <fieldname>name</fieldname>
67 * <size></size>
68 * <max></max>
69 * <default>(input your name here!)</default>
70 * </n2>
71 * <n4>
72 * <type>input</type>
73 * <label>Your Email:</label>
74 * <required>1</required>
75 * <fieldname>email</fieldname>
76 * <size></size>
77 * <max></max>
78 * <default></default>
79 * </n4>
80 * <n6>
81 * <type>textarea</type>
82 * <label>Your address:</label>
83 * <fieldname>address</fieldname>
84 * <cols>40</cols>
85 * <rows>10</rows>
86 * <default></default>
87 * </n6>
88 * <n8>
89 * <type>radio</type>
90 * <label>Your Haircolor:</label>
91 * <fieldname>hair</fieldname>
92 * <options></options>
93 * </n8>
94 * <n10>
95 * <type>file</type>
96 * <label>upload</label>
97 * <fieldname>attachment</fieldname>
98 * <size></size>
99 * </n10>
100 * <n12>
101 * <type>hidden</type>
102 * <label></label>
103 * <fieldname>quoted_printable</fieldname>
104 * <default>0</default>
105 * </n12>
106 * <n2000>
107 * <fieldname>formtype_mail</fieldname>
108 * <type>submit</type>
109 * <default>Send form</default>
110 * </n2000>
111 * <n2002>
112 * <fieldname>html_enabled</fieldname>
113 * <type>hidden</type>
114 * </n2002>
115 * <n2004>
116 * <fieldname>subject</fieldname>
117 * <type>hidden</type>
118 * <default>This is the subject</default>
119 * </n2004>
120 * <n20>
121 * <content></content>
122 * </n20>
123 * </T3FormWizard>
124 *
125 *
126 * The XML/phpArray structure is the internal format of the wizard.
127 */
128
129
130 /**
131 * Script Class for rendering the Form Wizard
132 *
133 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
134 * @package TYPO3
135 * @subpackage core
136 */
137 class SC_wizard_forms {
138
139 // Internal, dynamic:
140 /**
141 * document template object
142 *
143 * @var mediumDoc
144 */
145 var $doc;
146 // Content accumulation for the module.
147 var $content;
148 // List of files to include.
149 var $include_once = array();
150 // Used to numerate attachments automatically.
151 var $attachmentCounter = 0;
152
153 // Internal, static:
154 // If set, the string version of the content is interpreted/written as XML instead of
155 // the original linebased kind. This variable still needs binding to the wizard parameters
156 // - but support is ready!
157 var $xmlStorage = 0;
158
159 // Internal, static: GPvars
160 // Wizard parameters, coming from TCEforms linking to the wizard.
161 var $P;
162 // The array which is constantly submitted by the multidimensional form of this wizard.
163 var $FORMCFG;
164 // Indicates if the form is of a dedicated type, like "formtype_mail" (for tt_content element "Form")
165 var $special;
166
167 /**
168 * Initialization the class
169 *
170 * @return void
171 */
172 function init() {
173 // GPvars:
174 $this->P = t3lib_div::_GP('P');
175 $this->special = t3lib_div::_GP('special');
176 $this->FORMCFG = t3lib_div::_GP('FORMCFG');
177
178 // Setting options:
179 $this->xmlStorage = $this->P['params']['xmlOutput'];
180
181 // Document template object:
182 $this->doc = t3lib_div::makeInstance('template');
183 $this->doc->backPath = $GLOBALS['BACK_PATH'];
184 $this->doc->setModuleTemplate('templates/wizard_forms.html');
185 $this->doc->JScode=$this->doc->wrapScriptTags('
186 function jumpToUrl(URL,formEl) { //
187 window.location.href = URL;
188 }
189 ');
190
191 // Setting form tag:
192 list($rUri) = explode('#', t3lib_div::getIndpEnv('REQUEST_URI'));
193 $this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
194 }
195
196 /**
197 * Main function for rendering the form wizard HTML
198 *
199 * @return void
200 */
201 function main() {
202 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
203 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), $this->formsWizard(), 0, 1);
204 } else {
205 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('forms_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData', 1) . '</span>', 0, 1);
206 }
207
208 // Setting up the buttons and markers for docheader
209 $docHeaderButtons = $this->getButtons();
210 $markers['CSH'] = $docHeaderButtons['csh'];
211 $markers['CONTENT'] = $this->content;
212
213 // Build the <body> for the module
214 $this->content = $this->doc->startPage('Form Wizard');
215 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
216 $this->content .= $this->doc->endPage();
217 $this->content = $this->doc->insertStylesAndJS($this->content);
218 }
219
220 /**
221 * Outputting the accumulated content to screen
222 *
223 * @return void
224 */
225 function printContent() {
226 echo $this->content;
227 }
228
229 /**
230 * Create the panel of buttons for submitting the form or otherwise perform operations.
231 *
232 * @return array All available buttons as an assoc. array
233 */
234 protected function getButtons() {
235 $buttons = array(
236 'csh' => '',
237 'csh_buttons' => '',
238 'close' => '',
239 'save' => '',
240 'save_close' => '',
241 'reload' => '',
242 );
243
244 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
245 // CSH
246 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'], '');
247
248 // CSH Buttons
249 $buttons['csh_buttons'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'], '');
250
251 // Close
252 $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(unescape(\'' . rawurlencode(t3lib_div::sanitizeLocalUrl($this->P['returnUrl'])) . '\')); return false;') . '">' .
253 t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE))) .
254 '</a>';
255
256 // Save
257 $buttons['save'] = '<input type="image" class="c-inputButton" name="savedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
258
259 // Save & Close
260 $buttons['save_close'] = '<input type="image" class="c-inputButton" name="saveandclosedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', 1) . '" />';
261
262 // Reload
263 $buttons['reload'] = '<input type="image" class="c-inputButton" name="_refresh"' . t3lib_iconWorks::skinImg('', 'gfx/refresh_n.gif') . ' title="' . $GLOBALS['LANG']->getLL('forms_refresh', 1) . '" />';
264 }
265
266 return $buttons;
267 }
268
269 /**
270 * Draws the form wizard content
271 *
272 * @return string HTML content for the form.
273 */
274 function formsWizard() {
275
276 // First, check the references by selecting the record:
277 $row = t3lib_BEfunc::getRecord($this->P['table'], $this->P['uid']);
278 if (!is_array($row)) {
279 throw new RuntimeException('Wizard Error: No reference to record', 1294587124);
280 }
281
282 // This will get the content of the form configuration code field to us - possibly
283 // cleaned up, saved to database etc. if the form has been submitted in the meantime.
284 $formCfgArray = $this->getConfigCode($row);
285
286 // Generation of the Form Wizards HTML code:
287 $content = $this->getFormHTML($formCfgArray, $row);
288
289 // Return content:
290 return $content;
291 }
292
293 /****************************
294 *
295 * Helper functions
296 *
297 ***************************/
298
299 /**
300 * Will get and return the configuration code string
301 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
302 *
303 * @param array $row Current parent record row (passed by value!)
304 * @return array Configuration Array
305 * @access private
306 */
307 function getConfigCode(&$row) {
308
309 // If some data has been submitted, then construct
310 if (isset($this->FORMCFG['c'])) {
311
312 // Process incoming:
313 $this->changeFunc();
314
315 // Convert to string (either line based or XML):
316 if ($this->xmlStorage) {
317 // Convert the input array to XML:
318 $bodyText = t3lib_div::array2xml_cs($this->FORMCFG['c'], 'T3FormWizard');
319
320 // Setting cfgArr directly from the input:
321 $cfgArr = $this->FORMCFG['c'];
322 } else {
323 // Convert the input array to a string of configuration code:
324 $bodyText = $this->cfgArray2CfgString($this->FORMCFG['c']);
325
326 // Create cfgArr from the string based configuration - that way it is cleaned
327 // up and any incompatibilities will be removed!
328 $cfgArr = $this->cfgString2CfgArray($bodyText);
329 }
330
331 // If a save button has been pressed, then save the new field content:
332 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
333
334 // Make TCEmain object:
335 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
336 $tce->stripslashes_values = 0;
337
338 // Put content into the data array:
339 $data = array();
340 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $bodyText;
341 if ($this->special == 'formtype_mail') {
342 $data[$this->P['table']][$this->P['uid']]['subheader'] = $this->FORMCFG['recipient'];
343 }
344
345 // Perform the update:
346 $tce->start($data, array());
347 $tce->process_datamap();
348
349 // Re-load the record content:
350 $row = t3lib_BEfunc::getRecord($this->P['table'], $this->P['uid']);
351
352 // If the save/close button was pressed, then redirect the screen:
353 if ($_POST['saveandclosedok_x']) {
354 t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
355 }
356 }
357 } else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
358 if ($this->xmlStorage) {
359 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
360 } else { // Regular linebased form configuration:
361 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
362 }
363 $cfgArr = is_array($cfgArr) ? $cfgArr : array();
364 }
365
366 // Return configuration code:
367 return $cfgArr;
368 }
369
370 /**
371 * Creates the HTML for the Form Wizard:
372 *
373 * @param string $formCfgArray Form config array
374 * @param array $row Current parent record array
375 * @return string HTML for the form wizard
376 * @access private
377 */
378 function getFormHTML($formCfgArray, $row) {
379 // Initialize variables:
380 $specParts = array();
381 $hiddenFields = array();
382 $tRows = array();
383
384 // Set header row:
385 $cells = array($GLOBALS['LANG']->getLL('forms_preview', 1).':',
386 $GLOBALS['LANG']->getLL('forms_element', 1).':',
387 $GLOBALS['LANG']->getLL('forms_config', 1).':',
388 );
389 $tRows[] = '
390 <tr class="bgColor2" id="typo3-formWizardHeader">
391 <td>&nbsp;</td>
392 <td>' . implode('</td>
393 <td>', $cells) . '</td>
394 </tr>';
395
396 // Traverse the number of form elements:
397 $k = 0;
398 foreach ($formCfgArray as $confData) {
399
400 // Initialize:
401 $cells = array();
402
403 // If there is a configuration line which is active, then render it:
404 if (!isset($confData['comment'])) {
405
406 // Special parts:
407 if ($this->special == 'formtype_mail' && t3lib_div::inList('formtype_mail,subject,html_enabled', $confData['fieldname'])) {
408 $specParts[$confData['fieldname']] = $confData['default'];
409 } else {
410
411 // Render title/field preview COLUMN
412 $cells[] = $confData['type'] != 'hidden' ? '<strong>'.htmlspecialchars($confData['label']).'</strong>' : '';
413
414
415 // Render general type/title COLUMN:
416 $temp_cells = array();
417
418 // Field type selector:
419 $opt = array();
420 $opt[] = '<option value=""></option>';
421 $types = explode(',', 'input,textarea,select,check,radio,password,file,hidden,submit,property,label');
422 foreach ($types as $t) {
423 $opt[] = '
424 <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$GLOBALS['LANG']->getLL('forms_type_'.$t, 1).'</option>';
425 }
426 $temp_cells[$GLOBALS['LANG']->getLL('forms_type')]='
427 <select name="FORMCFG[c]['.(($k+1)*2).'][type]">
428 ' . implode('
429 ', $opt) . '
430 </select>';
431
432 // Title field:
433 if (!t3lib_div::inList('hidden,submit', $confData['type'])) {
434 $temp_cells[$GLOBALS['LANG']->getLL('forms_label')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][label]" value="'.htmlspecialchars($confData['label']).'" />';
435 }
436
437 // Required checkbox:
438 if (!t3lib_div::inList('check,hidden,submit,label', $confData['type'])) {
439 $temp_cells[$GLOBALS['LANG']->getLL('forms_required')]='<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][required]" value="1"'.($confData['required']?' checked="checked"':'').' title="'.$GLOBALS['LANG']->getLL('forms_required', 1).'" />';
440 }
441
442 // Put sub-items together into table cell:
443 $cells[] = $this->formatCells($temp_cells);
444
445
446 // Render specific field configuration COLUMN:
447 $temp_cells = array();
448
449 // Fieldname
450 if ($this->special == 'formtype_mail' && $confData['type'] == 'file') {
451 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
452 }
453 if (!t3lib_div::inList('label', $confData['type'])) {
454 $temp_cells[$GLOBALS['LANG']->getLL('forms_fieldName')]='<input type="text"'.$this->doc->formWidth(10).' name="FORMCFG[c]['.(($k+1)*2).'][fieldname]" value="'.htmlspecialchars($confData['fieldname']).'" title="'.$GLOBALS['LANG']->getLL('forms_fieldName', 1).'" />';
455 }
456
457 // Field configuration depending on the fields type:
458 switch((string)$confData['type']) {
459 case 'textarea':
460 $temp_cells[$GLOBALS['LANG']->getLL('forms_cols')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][cols]" value="'.htmlspecialchars($confData['cols']).'" title="'.$GLOBALS['LANG']->getLL('forms_cols', 1).'" />';
461 $temp_cells[$GLOBALS['LANG']->getLL('forms_rows')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][rows]" value="'.htmlspecialchars($confData['rows']).'" title="'.$GLOBALS['LANG']->getLL('forms_rows', 1).'" />';
462 $temp_cells[$GLOBALS['LANG']->getLL('forms_extra')] = '<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][extra]" value="OFF"'.($confData['extra']=='OFF'?' checked="checked"':'').' title="'.$GLOBALS['LANG']->getLL('forms_extra', 1).'" />';
463 break;
464 case 'input':
465 case 'password':
466 $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$GLOBALS['LANG']->getLL('forms_size', 1).'" />';
467 $temp_cells[$GLOBALS['LANG']->getLL('forms_max')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][max]" value="'.htmlspecialchars($confData['max']).'" title="'.$GLOBALS['LANG']->getLL('forms_max', 1).'" />';
468 break;
469 case 'file':
470 $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$GLOBALS['LANG']->getLL('forms_size', 1).'" />';
471 break;
472 case 'select':
473 $temp_cells[$GLOBALS['LANG']->getLL('forms_size')] = '<input type="text"'.$this->doc->formWidth(5).' name="FORMCFG[c]['.(($k+1)*2).'][size]" value="'.htmlspecialchars($confData['size']).'" title="'.$GLOBALS['LANG']->getLL('forms_size', 1).'" />';
474 $temp_cells[$GLOBALS['LANG']->getLL('forms_autosize')] = '<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][autosize]" value="1"'.($confData['autosize']?' checked="checked"':'').' title="'.$GLOBALS['LANG']->getLL('forms_autosize', 1).'" />';
475 $temp_cells[$GLOBALS['LANG']->getLL('forms_multiple')] = '<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][multiple]" value="1"'.($confData['multiple']?' checked="checked"':'').' title="'.$GLOBALS['LANG']->getLL('forms_multiple', 1).'" />';
476 break;
477 }
478
479 // Field configuration depending on the fields type:
480 switch((string)$confData['type']) {
481 case 'textarea':
482 case 'input':
483 case 'password':
484 if (strlen(trim($confData['specialEval']))) {
485 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
486 }
487 break;
488 }
489
490 // Default data
491 if ($confData['type'] == 'select' || $confData['type'] == 'radio') {
492 $temp_cells[$GLOBALS['LANG']->getLL('forms_options')] = '<textarea '.$this->doc->formWidthText(15).' rows="4" name="FORMCFG[c]['.(($k+1)*2).'][options]" title="'.$GLOBALS['LANG']->getLL('forms_options', 1).'">'.t3lib_div::formatForTextarea($confData['default']).'</textarea>';
493 } elseif ($confData['type'] == 'check') {
494 $temp_cells[$GLOBALS['LANG']->getLL('forms_checked')] = '<input type="checkbox" name="FORMCFG[c]['.(($k+1)*2).'][default]" value="1"'.(trim($confData['default'])?' checked="checked"':'').' title="'.$GLOBALS['LANG']->getLL('forms_checked', 1).'" />';
495 } elseif ($confData['type'] && $confData['type'] != 'file') {
496 $temp_cells[$GLOBALS['LANG']->getLL('forms_default')] = '<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][default]" value="'.htmlspecialchars($confData['default']).'" title="'.$GLOBALS['LANG']->getLL('forms_default', 1).'" />';
497 }
498
499 $cells[] = $confData['type']?$this->formatCells($temp_cells):'';
500
501 // CTRL panel for an item (move up/down/around):
502 $ctrl = '';
503 $onClick ="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
504 $onClick = ' onclick="'.htmlspecialchars($onClick).'"';
505 // FIXME $inputStyle undefined
506 $brTag = $inputStyle?'':'<br />';
507 if ($k != 0) {
508 $ctrl .= '<input type="image" name="FORMCFG[row_up]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/pil2up.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_up', 1).'" />'.$brTag;
509 } else {
510 $ctrl .= '<input type="image" name="FORMCFG[row_bottom]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/turn_up.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_bottom', 1).'" />'.$brTag;
511 }
512 $ctrl .= '<input type="image" name="FORMCFG[row_remove]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/garbage.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_removeRow', 1).'" />'.$brTag;
513 // FIXME $tLines undefined
514 if (($k+1) != count($tLines)) {
515 $ctrl.='<input type="image" name="FORMCFG[row_down]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/pil2down.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_down', 1).'" />'.$brTag;
516 } else {
517 $ctrl.='<input type="image" name="FORMCFG[row_top]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/turn_down.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_top', 1).'" />'.$brTag;
518 }
519 $ctrl .= '<input type="image" name="FORMCFG[row_add]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/add.gif', '').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_addRow', 1).'" />'.$brTag;
520
521 $ctrl = '<span class="c-wizButtonsV">'.$ctrl.'</span>';
522
523 // Finally, put together the full row from the generated content above:
524 $bgC = $confData['type']?' class="bgColor5"':'';
525 $tRows[] = '
526 <tr' . $bgC . '>
527 <td><a name="ANC_' . (($k + 1) * 2) . '"></a>' . $ctrl . '</td>
528 <td class="bgColor4">' . implode('</td>
529 <td valign="top">', $cells) . '</td>
530 </tr>';
531 }
532 } else {
533 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
534 }
535
536 // Increment counter:
537 $k++;
538 }
539
540 // If the form is of the special type "formtype_mail" (used for tt_content elements):
541 if ($this->special == 'formtype_mail') {
542
543 // Blank spacer:
544 $tRows[] = '
545 <tr>
546 <td colspan="4">&nbsp;</td>
547 </tr>';
548
549 // Header:
550 $tRows[] = '
551 <tr>
552 <td colspan="2" class="bgColor2">&nbsp;</td>
553 <td colspan="2" class="bgColor2"><strong>'.$GLOBALS['LANG']->getLL('forms_special_eform', 1).':</strong>'.
554 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'], '').
555 '</td>
556 </tr>';
557
558 // "FORM type":
559 $tRows[] = '
560 <tr class="bgColor5">
561 <td>&nbsp;</td>
562 <td class="bgColor4">&nbsp;</td>
563 <td>'.$GLOBALS['LANG']->getLL('forms_eform_formtype_mail', 1).':</td>
564 <td>
565 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
566 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
567 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
568 </td>
569 </tr>';
570
571 // "Send HTML mail":
572 $tRows[] = '
573 <tr class="bgColor5">
574 <td>&nbsp;</td>
575 <td class="bgColor4">&nbsp;</td>
576 <td>'.$GLOBALS['LANG']->getLL('forms_eform_html_enabled', 1).':</td>
577 <td>
578 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
579 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
580 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
581 </td>
582 </tr>';
583
584 // "Subject":
585 $tRows[] = '
586 <tr class="bgColor5">
587 <td>&nbsp;</td>
588 <td class="bgColor4">&nbsp;</td>
589 <td>'.$GLOBALS['LANG']->getLL('forms_eform_subject', 1).':</td>
590 <td>
591 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
592 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
593 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
594 </td>
595 </tr>';
596
597 // Recipient:
598 $tRows[] = '
599 <tr class="bgColor5">
600 <td>&nbsp;</td>
601 <td class="bgColor4">&nbsp;</td>
602 <td>'.$GLOBALS['LANG']->getLL('forms_eform_recipient', 1).':</td>
603 <td>
604 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
605 </td>
606 </tr>';
607 }
608
609 $content = '';
610
611 // Implode all table rows into a string, wrapped in table tags.
612 $content .= '
613
614 <!--
615 Form wizard
616 -->
617 <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
618 '.implode('', $tRows).'
619 </table>';
620
621 // Add hidden fields:
622 $content .= implode('', $hiddenFields);
623
624 // Return content:
625 return $content;
626 }
627
628 /**
629 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal FORMCFG array
630 *
631 * @return void
632 * @access private
633 */
634 function changeFunc() {
635 if ($this->FORMCFG['row_remove']) {
636 $kk = key($this->FORMCFG['row_remove']);
637 $cmd='row_remove';
638 } elseif ($this->FORMCFG['row_add']) {
639 $kk = key($this->FORMCFG['row_add']);
640 $cmd='row_add';
641 } elseif ($this->FORMCFG['row_top']) {
642 $kk = key($this->FORMCFG['row_top']);
643 $cmd='row_top';
644 } elseif ($this->FORMCFG['row_bottom']) {
645 $kk = key($this->FORMCFG['row_bottom']);
646 $cmd='row_bottom';
647 } elseif ($this->FORMCFG['row_up']) {
648 $kk = key($this->FORMCFG['row_up']);
649 $cmd='row_up';
650 } elseif ($this->FORMCFG['row_down']) {
651 $kk = key($this->FORMCFG['row_down']);
652 $cmd='row_down';
653 }
654
655 if ($cmd && t3lib_utility_Math::canBeInterpretedAsInteger($kk)) {
656 if (substr($cmd, 0, 4)=='row_') {
657 switch($cmd) {
658 case 'row_remove':
659 unset($this->FORMCFG['c'][$kk]);
660 break;
661 case 'row_add':
662 $this->FORMCFG['c'][$kk+1]=array();
663 break;
664 case 'row_top':
665 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
666 unset($this->FORMCFG['c'][$kk]);
667 break;
668 case 'row_bottom':
669 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
670 unset($this->FORMCFG['c'][$kk]);
671 break;
672 case 'row_up':
673 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
674 unset($this->FORMCFG['c'][$kk]);
675 break;
676 case 'row_down':
677 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
678 unset($this->FORMCFG['c'][$kk]);
679 break;
680 }
681 ksort($this->FORMCFG['c']);
682 }
683 }
684 }
685
686 /**
687 * Converts the input array to a configuration code string
688 *
689 * @param array $cfgArr Array of form configuration (follows the input structure from the form wizard POST form)
690 * @return string The array converted into a string with line-based configuration.
691 * @see cfgString2CfgArray()
692 */
693 function cfgArray2CfgString($cfgArr) {
694
695 // Initialize:
696 $inLines = array();
697
698 // Traverse the elements of the form wizard and transform the settings into configuration code.
699 foreach ($cfgArr as $vv) {
700 // If "content" is found, then just pass it over.
701 if ($vv['comment']) {
702 $inLines[]=trim($vv['comment']);
703 } else { // Begin to put together the single-line configuration code of this field:
704
705 // Reset:
706 $thisLine = array();
707
708 // Set Label:
709 $thisLine[0] = str_replace('|', '', $vv['label']);
710
711 // Set Type:
712 if ($vv['type']) {
713 $thisLine[1] = ($vv['required']?'*':'').str_replace(',', '', ($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
714
715 // Default:
716 $tArr = array('', '', '', '', '', '');
717 switch((string)$vv['type']) {
718 case 'textarea':
719 if (intval($vv['cols'])) $tArr[0] = intval($vv['cols']);
720 if (intval($vv['rows'])) $tArr[1] = intval($vv['rows']);
721 if (trim($vv['extra'])) $tArr[2] = trim($vv['extra']);
722 if (strlen($vv['specialEval'])) {
723 // Preset blank default value so position 3 can get a value...
724 $thisLine[2] = '';
725 $thisLine[3] = $vv['specialEval'];
726 }
727 break;
728 case 'input':
729 case 'password':
730 if (intval($vv['size'])) $tArr[0] = intval($vv['size']);
731 if (intval($vv['max'])) $tArr[1] = intval($vv['max']);
732 if (strlen($vv['specialEval'])) {
733 // Preset blank default value so position 3 can get a value...
734 $thisLine[2] = '';
735 $thisLine[3] = $vv['specialEval'];
736 }
737 break;
738 case 'file':
739 if (intval($vv['size'])) $tArr[0] = intval($vv['size']);
740 break;
741 case 'select':
742 if (intval($vv['size'])) $tArr[0] = intval($vv['size']);
743 if ($vv['autosize']) $tArr[0] = 'auto';
744 if ($vv['multiple']) $tArr[1] = 'm';
745 break;
746 }
747 $tArr = $this->cleanT($tArr);
748 if (count($tArr)) $thisLine[1].=','.implode(',', $tArr);
749
750 $thisLine[1] = str_replace('|', '', $thisLine[1]);
751
752 // Default:
753 if ($vv['type'] == 'select' || $vv['type'] == 'radio') {
754 $thisLine[2] = str_replace(LF, ', ', str_replace(',', '', $vv['options']));
755 } elseif ($vv['type'] == 'check') {
756 if ($vv['default']) $thisLine[2] = 1;
757 } elseif (strcmp(trim($vv['default']), '')) {
758 $thisLine[2] = $vv['default'];
759 }
760 if (isset($thisLine[2])) $thisLine[2] = str_replace('|', '', $thisLine[2]);
761 }
762
763 // Compile the final line:
764 $inLines[] = preg_replace("/[\n\r]*/", '', implode(' | ', $thisLine));
765 }
766 }
767 // Finally, implode the lines into a string, and return it:
768 return implode(LF, $inLines);
769 }
770
771 /**
772 * Converts the input configuration code string into an array
773 *
774 * @param string $cfgStr Configuration code
775 * @return array Configuration array
776 * @see cfgArray2CfgString()
777 */
778 function cfgString2CfgArray($cfgStr) {
779
780 // Traverse the number of form elements:
781 $tLines = explode(LF, $cfgStr);
782 foreach ($tLines as $k => $v) {
783
784 // Initialize:
785 $confData = array();
786 $val = trim($v);
787
788 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new,
789 // unconfigured fields) or b) it is NOT a comment.
790 if (!$val || strcspn($val, '#/')) {
791
792 // Split:
793 $parts = t3lib_div::trimExplode('|', $val);
794
795 // Label:
796 $confData['label'] = trim($parts[0]);
797
798 // Field:
799 $fParts = t3lib_div::trimExplode(',', $parts[1]);
800 $fParts[0] = trim($fParts[0]);
801 if (substr($fParts[0], 0, 1) == '*') {
802 $confData['required'] = 1;
803 $fParts[0] = substr($fParts[0], 1);
804 }
805
806 $typeParts = t3lib_div::trimExplode('=', $fParts[0]);
807 $confData['type'] = trim(strtolower(end($typeParts)));
808
809 if ($confData['type']) {
810 if (count($typeParts) == 1) {
811 $confData['fieldname'] = substr(preg_replace('/[^a-zA-Z0-9_]/', '', str_replace(' ', '_', trim($parts[0]))), 0, 30);
812
813 // Attachment names...
814 if ($confData['type'] == 'file') {
815 $confData['fieldname'] = 'attachment'.$attachmentCounter;
816 $attachmentCounter = intval($attachmentCounter)+1;
817 }
818 } else {
819 $confData['fieldname'] = str_replace(' ', '_', trim($typeParts[0]));
820 }
821
822 switch((string)$confData['type']) {
823 case 'select':
824 case 'radio':
825 $confData['default'] = implode(LF, t3lib_div::trimExplode(',', $parts[2]));
826 break;
827 default:
828 $confData['default'] = trim($parts[2]);
829 break;
830 }
831
832 // Field configuration depending on the fields type:
833 switch((string)$confData['type']) {
834 case 'textarea':
835 $confData['cols'] = $fParts[1];
836 $confData['rows'] = $fParts[2];
837 $confData['extra'] = strtoupper($fParts[3]) == 'OFF' ? 'OFF' : '';
838 $confData['specialEval'] = trim($parts[3]);
839 break;
840 case 'input':
841 case 'password':
842 $confData['size'] = $fParts[1];
843 $confData['max'] = $fParts[2];
844 $confData['specialEval'] = trim($parts[3]);
845 break;
846 case 'file':
847 $confData['size'] = $fParts[1];
848 break;
849 case 'select':
850 $confData['size'] = intval($fParts[1])?$fParts[1]:'';
851 $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
852 $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
853 break;
854 }
855 }
856 } else {
857 // No configuration, only a comment:
858 $confData = array(
859 'comment' => $val
860 );
861 }
862
863 // Adding config array:
864 $cfgArr[] = $confData;
865 }
866
867 // Return cfgArr
868 return $cfgArr;
869 }
870
871 /**
872 * Removes any "trailing elements" in the array which consists of whitespace (little like trim() does for strings, so this does for arrays)
873 *
874 * @param array $tArr Single dim array
875 * @return array Processed array
876 * @access private
877 */
878 function cleanT($tArr) {
879 for($a = count($tArr); $a > 0; $a--) {
880 if (strcmp($tArr[$a-1], '')) {
881 break;
882 } else {
883 unset($tArr[$a-1]);
884 }
885 }
886 return $tArr;
887 }
888
889 /**
890 * Wraps items in $fArr in table cells/rows, displaying them vertically.
891 *
892 * @param array $fArr Array of label/HTML pairs.
893 * @return string HTML table
894 * @access private
895 */
896 function formatCells($fArr) {
897
898 // Traverse the elements in $fArr and wrap them in table cells:
899 $lines = array();
900 foreach ($fArr as $l => $c) {
901 $lines[] = '
902 <tr>
903 <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
904 <td>'.$c.'</td>
905 </tr>';
906 }
907
908 // Add a cell which will set a minimum width:
909 $lines[] = '
910 <tr>
911 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
912 <td></td>
913 </tr>';
914
915 // Wrap in table and return:
916 return '
917 <table border="0" cellpadding="0" cellspacing="0">
918 '.implode('', $lines).'
919 </table>';
920 }
921 }
922
923 // Make instance:
924 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
925 $SOBE->init();
926
927 // Include files?
928 foreach ($SOBE->include_once as $INC_FILE) {
929 include_once($INC_FILE);
930 }
931
932 $SOBE->main();
933 $SOBE->printContent();
934
935 ?>