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