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