Fixed bug #10796: Click on (WS 48hour-) preview link in versioning module causes...
[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 header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
405 exit;
406 }
407 }
408 } else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
409 if ($this->xmlStorage) {
410 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
411 } else { // Regular linebased form configuration:
412 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
413 }
414 $cfgArr = is_array($cfgArr) ? $cfgArr : array();
415 }
416
417 // Return configuration code:
418 return $cfgArr;
419 }
420
421 /**
422 * Creates the HTML for the Form Wizard:
423 *
424 * @param string Form config array
425 * @param array Current parent record array
426 * @return string HTML for the form wizard
427 * @access private
428 */
429 function getFormHTML($formCfgArray,$row) {
430 global $LANG;
431
432 // Initialize variables:
433 $specParts=array();
434 $hiddenFields=array();
435 $tRows=array();
436
437 // Set header row:
438 $cells=array($LANG->getLL('forms_preview',1).':',
439 $LANG->getLL('forms_element',1).':',
440 $LANG->getLL('forms_config',1).':',
441 );
442 $tRows[]='
443 <tr class="bgColor2" id="typo3-formWizardHeader">
444 <td>&nbsp;</td>
445 <td>'.implode('</td>
446 <td>',$cells).'</td>
447 </tr>';
448
449 // Traverse the number of form elements:
450 $k=0;
451 foreach($formCfgArray as $confData) {
452
453 // Initialize:
454 $cells=array();
455
456 // If there is a configuration line which is active, then render it:
457 if (!isset($confData['comment'])) {
458
459 // Special parts:
460 if ($this->special=='formtype_mail' && t3lib_div::inList('formtype_mail,subject,html_enabled',$confData['fieldname'])) {
461 $specParts[$confData['fieldname']] = $confData['default'];
462 } else {
463
464 // Render title/field preview COLUMN
465 $cells[]=$confData['type']!='hidden' ? '<strong>'.htmlspecialchars($confData['label']).'</strong>' : '';
466
467
468 // Render general type/title COLUMN:
469 $temp_cells=array();
470
471 // Field type selector:
472 $opt=array();
473 $opt[]='<option value=""></option>';
474 $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property,label');
475 foreach($types as $t) {
476 $opt[]='
477 <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
478 }
479 $temp_cells[$LANG->getLL('forms_type')]='
480 <select name="FORMCFG[c]['.(($k+1)*2).'][type]">
481 '.implode('
482 ',$opt).'
483 </select>';
484
485 // Title field:
486 if (!t3lib_div::inList('hidden,submit',$confData['type'])) {
487 $temp_cells[$LANG->getLL('forms_label')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][label]" value="'.htmlspecialchars($confData['label']).'" />';
488 }
489
490 // Required checkbox:
491 if (!t3lib_div::inList('check,hidden,submit,label',$confData['type'])) {
492 $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).'" />';
493 }
494
495 // Put sub-items together into table cell:
496 $cells[]=$this->formatCells($temp_cells);
497
498
499 // Render specific field configuration COLUMN:
500 $temp_cells=array();
501
502 // Fieldname
503 if ($this->special=='formtype_mail' && $confData['type']=='file') {
504 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
505 }
506 if (!t3lib_div::inList('label',$confData['type'])) {
507 $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).'" />';
508 }
509
510 // Field configuration depending on the fields type:
511 switch((string)$confData['type']) {
512 case 'textarea':
513 $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).'" />';
514 $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).'" />';
515 $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).'" />';
516 break;
517 case 'input':
518 case 'password':
519 $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).'" />';
520 $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).'" />';
521 break;
522 case 'file':
523 $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).'" />';
524 break;
525 case 'select':
526 $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).'" />';
527 $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).'" />';
528 $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).'" />';
529 break;
530 }
531
532 // Field configuration depending on the fields type:
533 switch((string)$confData['type']) {
534 case 'textarea':
535 case 'input':
536 case 'password':
537 if (strlen(trim($confData['specialEval']))) {
538 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
539 }
540 break;
541 }
542
543 // Default data
544 if ($confData['type']=='select' || $confData['type']=='radio') {
545 $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>';
546 } elseif ($confData['type']=='check') {
547 $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).'" />';
548 } elseif ($confData['type'] && $confData['type']!='file') {
549 $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).'" />';
550 }
551
552 $cells[]=$confData['type']?$this->formatCells($temp_cells):'';
553
554 // CTRL panel for an item (move up/down/around):
555 $ctrl='';
556 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
557 $onClick=' onclick="'.htmlspecialchars($onClick).'"';
558 // FIXME $inputStyle undefined
559 $brTag=$inputStyle?'':'<br />';
560 if ($k!=0) {
561 $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;
562 } else {
563 $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;
564 }
565 $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;
566 // FIXME $tLines undefined
567 if (($k+1)!=count($tLines)) {
568 $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;
569 } else {
570 $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;
571 }
572 $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;
573
574 $ctrl='<span class="c-wizButtonsV">'.$ctrl.'</span>';
575
576 // Finally, put together the full row from the generated content above:
577 $bgC = $confData['type']?' class="bgColor5"':'';
578 $tRows[]='
579 <tr'.$bgC.'>
580 <td><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td>
581 <td class="bgColor4">'.implode('</td>
582 <td valign="top">',$cells).'</td>
583 </tr>';
584 }
585 } else {
586 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
587 }
588
589 // Increment counter:
590 $k++;
591 }
592
593 // If the form is of the special type "formtype_mail" (used for tt_content elements):
594 if ($this->special=='formtype_mail') {
595
596 // Blank spacer:
597 $tRows[]='
598 <tr>
599 <td colspan="4">&nbsp;</td>
600 </tr>';
601
602 // Header:
603 $tRows[]='
604 <tr>
605 <td colspan="2" class="bgColor2">&nbsp;</td>
606 <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
607 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
608 '</td>
609 </tr>';
610
611 // "FORM type":
612 $tRows[]='
613 <tr class="bgColor5">
614 <td>&nbsp;</td>
615 <td class="bgColor4">&nbsp;</td>
616 <td>'.$LANG->getLL('forms_eform_formtype_mail',1).':</td>
617 <td>
618 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
619 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
620 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
621 </td>
622 </tr>';
623
624 // "Send HTML mail":
625 $tRows[]='
626 <tr class="bgColor5">
627 <td>&nbsp;</td>
628 <td class="bgColor4">&nbsp;</td>
629 <td>'.$LANG->getLL('forms_eform_html_enabled',1).':</td>
630 <td>
631 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
632 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
633 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
634 </td>
635 </tr>';
636
637 // "Subject":
638 $tRows[]='
639 <tr class="bgColor5">
640 <td>&nbsp;</td>
641 <td class="bgColor4">&nbsp;</td>
642 <td>'.$LANG->getLL('forms_eform_subject',1).':</td>
643 <td>
644 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
645 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
646 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
647 </td>
648 </tr>';
649
650 // Recipient:
651 $tRows[]='
652 <tr class="bgColor5">
653 <td>&nbsp;</td>
654 <td class="bgColor4">&nbsp;</td>
655 <td>'.$LANG->getLL('forms_eform_recipient',1).':</td>
656 <td>
657 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
658 </td>
659 </tr>';
660 }
661
662 $content = '';
663
664 // Implode all table rows into a string, wrapped in table tags.
665 $content.= '
666
667 <!--
668 Form wizard
669 -->
670 <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
671 '.implode('',$tRows).'
672 </table>';
673
674 // Add hidden fields:
675 $content.= implode('',$hiddenFields);
676
677 // Return content:
678 return $content;
679 }
680
681 /**
682 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal FORMCFG array
683 *
684 * @return void
685 * @access private
686 */
687 function changeFunc() {
688 if ($this->FORMCFG['row_remove']) {
689 $kk = key($this->FORMCFG['row_remove']);
690 $cmd='row_remove';
691 } elseif ($this->FORMCFG['row_add']) {
692 $kk = key($this->FORMCFG['row_add']);
693 $cmd='row_add';
694 } elseif ($this->FORMCFG['row_top']) {
695 $kk = key($this->FORMCFG['row_top']);
696 $cmd='row_top';
697 } elseif ($this->FORMCFG['row_bottom']) {
698 $kk = key($this->FORMCFG['row_bottom']);
699 $cmd='row_bottom';
700 } elseif ($this->FORMCFG['row_up']) {
701 $kk = key($this->FORMCFG['row_up']);
702 $cmd='row_up';
703 } elseif ($this->FORMCFG['row_down']) {
704 $kk = key($this->FORMCFG['row_down']);
705 $cmd='row_down';
706 }
707
708 if ($cmd && t3lib_div::testInt($kk)) {
709 if (substr($cmd,0,4)=='row_') {
710 switch($cmd) {
711 case 'row_remove':
712 unset($this->FORMCFG['c'][$kk]);
713 break;
714 case 'row_add':
715 $this->FORMCFG['c'][$kk+1]=array();
716 break;
717 case 'row_top':
718 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
719 unset($this->FORMCFG['c'][$kk]);
720 break;
721 case 'row_bottom':
722 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
723 unset($this->FORMCFG['c'][$kk]);
724 break;
725 case 'row_up':
726 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
727 unset($this->FORMCFG['c'][$kk]);
728 break;
729 case 'row_down':
730 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
731 unset($this->FORMCFG['c'][$kk]);
732 break;
733 }
734 ksort($this->FORMCFG['c']);
735 }
736 }
737 }
738
739 /**
740 * Converts the input array to a configuration code string
741 *
742 * @param array Array of form configuration (follows the input structure from the form wizard POST form)
743 * @return string The array converted into a string with line-based configuration.
744 * @see cfgString2CfgArray()
745 */
746 function cfgArray2CfgString($cfgArr) {
747
748 // Initialize:
749 $inLines=array();
750
751 // Traverse the elements of the form wizard and transform the settings into configuration code.
752 foreach($cfgArr as $vv) {
753 if ($vv['comment']) { // If "content" is found, then just pass it over.
754 $inLines[]=trim($vv['comment']);
755 } else { // Begin to put together the single-line configuration code of this field:
756
757 // Reset:
758 $thisLine=array();
759
760 // Set Label:
761 $thisLine[0]=str_replace('|','',$vv['label']);
762
763 // Set Type:
764 if ($vv['type']) {
765 $thisLine[1]=($vv['required']?'*':'').str_replace(',','',($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
766
767 // Default:
768 $tArr=array('','','','','','');
769 switch((string)$vv['type']) {
770 case 'textarea':
771 if (intval($vv['cols'])) $tArr[0]=intval($vv['cols']);
772 if (intval($vv['rows'])) $tArr[1]=intval($vv['rows']);
773 if (trim($vv['extra'])) $tArr[2]=trim($vv['extra']);
774 if (strlen($vv['specialEval'])) {
775 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
776 $thisLine[3] = $vv['specialEval'];
777 }
778 break;
779 case 'input':
780 case 'password':
781 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
782 if (intval($vv['max'])) $tArr[1]=intval($vv['max']);
783 if (strlen($vv['specialEval'])) {
784 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
785 $thisLine[3] = $vv['specialEval'];
786 }
787 break;
788 case 'file':
789 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
790 break;
791 case 'select':
792 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
793 if ($vv['autosize']) $tArr[0]='auto';
794 if ($vv['multiple']) $tArr[1]='m';
795 break;
796 }
797 $tArr = $this->cleanT($tArr);
798 if (count($tArr)) $thisLine[1].=','.implode(',',$tArr);
799
800 $thisLine[1]=str_replace('|','',$thisLine[1]);
801
802 // Default:
803 if ($vv['type']=='select' || $vv['type']=='radio') {
804 $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
805 } elseif ($vv['type']=='check') {
806 if ($vv['default']) $thisLine[2]=1;
807 } elseif (strcmp(trim($vv['default']),'')) {
808 $thisLine[2]=$vv['default'];
809 }
810 if (isset($thisLine[2])) $thisLine[2]=str_replace('|','',$thisLine[2]);
811 }
812
813 // Compile the final line:
814 $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
815 }
816 }
817 // Finally, implode the lines into a string, and return it:
818 return implode(chr(10),$inLines);
819 }
820
821 /**
822 * Converts the input configuration code string into an array
823 *
824 * @param string Configuration code
825 * @return array Configuration array
826 * @see cfgArray2CfgString()
827 */
828 function cfgString2CfgArray($cfgStr) {
829
830 // Traverse the number of form elements:
831 $tLines=explode(chr(10),$cfgStr);
832 foreach($tLines as $k => $v) {
833
834 // Initialize:
835 $confData=array();
836 $val=trim($v);
837
838 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new, unconfigured fields) or b) it is NOT a comment.
839 if (!$val || strcspn($val,'#/')) {
840
841 // Split:
842 $parts = t3lib_div::trimExplode('|',$val);
843
844 // Label:
845 $confData['label'] = trim($parts[0]);
846
847 // Field:
848 $fParts = t3lib_div::trimExplode(',',$parts[1]);
849 $fParts[0]=trim($fParts[0]);
850 if (substr($fParts[0],0,1)=='*') {
851 $confData['required'] = 1;
852 $fParts[0] = substr($fParts[0],1);
853 }
854
855 $typeParts = t3lib_div::trimExplode('=',$fParts[0]);
856 $confData['type'] = trim(strtolower(end($typeParts)));
857
858 if ($confData['type']) {
859 if (count($typeParts)==1) {
860 $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
861
862 // Attachment names...
863 if ($confData['type']=='file') {
864 $confData['fieldname']='attachment'.$attachmentCounter;
865 $attachmentCounter=intval($attachmentCounter)+1;
866 }
867 } else {
868 $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
869 }
870
871 switch((string)$confData['type']) {
872 case 'select':
873 case 'radio':
874 $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
875 break;
876 default:
877 $confData['default'] = trim($parts[2]);
878 break;
879 }
880
881 // Field configuration depending on the fields type:
882 switch((string)$confData['type']) {
883 case 'textarea':
884 $confData['cols'] = $fParts[1];
885 $confData['rows'] = $fParts[2];
886 $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
887 $confData['specialEval'] = trim($parts[3]);
888 break;
889 case 'input':
890 case 'password':
891 $confData['size'] = $fParts[1];
892 $confData['max'] = $fParts[2];
893 $confData['specialEval'] = trim($parts[3]);
894 break;
895 case 'file':
896 $confData['size'] = $fParts[1];
897 break;
898 case 'select':
899 $confData['size'] = intval($fParts[1])?$fParts[1]:'';
900 $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
901 $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
902 break;
903 }
904 }
905 } else {
906 // No configuration, only a comment:
907 $confData=array(
908 'comment' => $val
909 );
910 }
911
912 // Adding config array:
913 $cfgArr[]=$confData;
914 }
915
916 // Return cfgArr
917 return $cfgArr;
918 }
919
920 /**
921 * Removes any "trailing elements" in the array which consists of whitespace (little like trim() does for strings, so this does for arrays)
922 *
923 * @param array Single dim array
924 * @return array Processed array
925 * @access private
926 */
927 function cleanT($tArr) {
928 for($a=count($tArr);$a>0;$a--) {
929 if (strcmp($tArr[$a-1],'')) {
930 break;
931 } else {
932 unset($tArr[$a-1]);
933 }
934 }
935 return $tArr;
936 }
937
938 /**
939 * Wraps items in $fArr in table cells/rows, displaying them vertically.
940 *
941 * @param array Array of label/HTML pairs.
942 * @return string HTML table
943 * @access private
944 */
945 function formatCells($fArr) {
946
947 // Traverse the elements in $fArr and wrap them in table cells:
948 $lines=array();
949 foreach($fArr as $l => $c) {
950 $lines[]='
951 <tr>
952 <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
953 <td>'.$c.'</td>
954 </tr>';
955 }
956
957 // Add a cell which will set a minimum width:
958 $lines[]='
959 <tr>
960 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
961 <td></td>
962 </tr>';
963
964 // Wrap in table and return:
965 return '
966 <table border="0" cellpadding="0" cellspacing="0">
967 '.implode('',$lines).'
968 </table>';
969 }
970 }
971
972
973 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']) {
974 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
975 }
976
977
978
979 // Make instance:
980 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
981 $SOBE->init();
982
983 // Include files?
984 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
985
986 $SOBE->main();
987 $SOBE->printContent();
988
989 ?>