Fixed bug #9095: xhtml in the backend by default (Thanks to Christian Kuhn)
[Packages/TYPO3.CMS.git] / typo3 / wizard_forms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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 global $BACK_PATH;
210
211 // GPvars:
212 $this->P = t3lib_div::_GP('P');
213 $this->special = t3lib_div::_GP('special');
214 $this->FORMCFG = t3lib_div::_GP('FORMCFG');
215
216 // Setting options:
217 $this->xmlStorage = $this->P['params']['xmlOutput'];
218
219 // Document template object:
220 $this->doc = t3lib_div::makeInstance('mediumDoc');
221 $this->doc->backPath = $BACK_PATH;
222 $this->doc->JScode=$this->doc->wrapScriptTags('
223 function jumpToUrl(URL,formEl) { //
224 window.location.href = URL;
225 }
226 ');
227
228 // Setting form tag:
229 list($rUri) = explode('#',t3lib_div::getIndpEnv('REQUEST_URI'));
230 $this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
231
232 // Start page:
233 $this->content=$this->doc->startPage('Form Wizard');
234
235 // If save command found, include tcemain:
236 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
237 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
238 }
239 }
240
241 /**
242 * Main function for rendering the form wizard HTML
243 *
244 * @return void
245 */
246 function main() {
247 global $LANG;
248
249 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
250 $this->content.=$this->doc->section($LANG->getLL('forms_title'),$this->formsWizard(),0,1);
251 } else {
252 $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
253 }
254 }
255
256 /**
257 * Outputting the accumulated content to screen
258 *
259 * @return void
260 */
261 function printContent() {
262 $this->content.= $this->doc->endPage();
263 $this->content = $this->doc->insertStylesAndJS($this->content);
264 echo $this->content;
265 }
266
267 /**
268 * Draws the form wizard content
269 *
270 * @return string HTML content for the form.
271 */
272 function formsWizard() {
273
274 // First, check the references by selecting the record:
275 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
276 if (!is_array($row)) {
277 t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
278 exit;
279 }
280
281 // 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.
282 $formCfgArray = $this->getConfigCode($row);
283
284 // Generation of the Form Wizards HTML code:
285 $content = $this->getFormHTML($formCfgArray,$row);
286
287 // Return content:
288 return $content;
289 }
290
291
292
293
294
295
296
297
298
299
300
301 /****************************
302 *
303 * Helper functions
304 *
305 ***************************/
306
307 /**
308 * Will get and return the configuration code string
309 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
310 *
311 * @param array Current parent record row (passed by value!)
312 * @return array Configuration Array
313 * @access private
314 */
315 function getConfigCode(&$row) {
316
317 // If some data has been submitted, then construct
318 if (isset($this->FORMCFG['c'])) {
319
320 // Process incoming:
321 $this->changeFunc();
322
323 // Convert to string (either line based or XML):
324 if ($this->xmlStorage) {
325 // Convert the input array to XML:
326 $bodyText = t3lib_div::array2xml_cs($this->FORMCFG['c'],'T3FormWizard');
327
328 // Setting cfgArr directly from the input:
329 $cfgArr = $this->FORMCFG['c'];
330 } else {
331 // Convert the input array to a string of configuration code:
332 $bodyText = $this->cfgArray2CfgString($this->FORMCFG['c']);
333
334 // Create cfgArr from the string based configuration - that way it is cleaned up and any incompatibilities will be removed!
335 $cfgArr = $this->cfgString2CfgArray($bodyText);
336 }
337
338 // If a save button has been pressed, then save the new field content:
339 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
340
341 // Make TCEmain object:
342 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
343 $tce->stripslashes_values=0;
344
345 // Put content into the data array:
346 $data=array();
347 $data[$this->P['table']][$this->P['uid']][$this->P['field']]=$bodyText;
348 if ($this->special=='formtype_mail') {
349 $data[$this->P['table']][$this->P['uid']]['subheader']=$this->FORMCFG['recipient'];
350 }
351
352 // Perform the update:
353 $tce->start($data,array());
354 $tce->process_datamap();
355
356 // Re-load the record content:
357 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
358
359 // If the save/close button was pressed, then redirect the screen:
360 if ($_POST['saveandclosedok_x']) {
361 header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
362 exit;
363 }
364 }
365 } else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
366 if ($this->xmlStorage) {
367 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
368 } else { // Regular linebased form configuration:
369 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
370 }
371 $cfgArr = is_array($cfgArr) ? $cfgArr : array();
372 }
373
374 // Return configuration code:
375 return $cfgArr;
376 }
377
378 /**
379 * Creates the HTML for the Form Wizard:
380 *
381 * @param string Form config array
382 * @param array Current parent record array
383 * @return string HTML for the form wizard
384 * @access private
385 */
386 function getFormHTML($formCfgArray,$row) {
387 global $LANG;
388
389 // Initialize variables:
390 $specParts=array();
391 $hiddenFields=array();
392 $tRows=array();
393
394 // Set header row:
395 $cells=array($LANG->getLL('forms_preview',1).':',
396 $LANG->getLL('forms_element',1).':',
397 $LANG->getLL('forms_config',1).':',
398 );
399 $tRows[]='
400 <tr class="bgColor2" id="typo3-formWizardHeader">
401 <td>&nbsp;</td>
402 <td>'.implode('</td>
403 <td>',$cells).'</td>
404 </tr>';
405
406 // Traverse the number of form elements:
407 $k=0;
408 foreach($formCfgArray as $confData) {
409
410 // Initialize:
411 $cells=array();
412
413 // If there is a configuration line which is active, then render it:
414 if (!isset($confData['comment'])) {
415
416 // Special parts:
417 if ($this->special=='formtype_mail' && t3lib_div::inList('formtype_mail,subject,html_enabled',$confData['fieldname'])) {
418 $specParts[$confData['fieldname']] = $confData['default'];
419 } else {
420
421 // Render title/field preview COLUMN
422 $cells[]=$confData['type']!='hidden' ? '<strong>'.htmlspecialchars($confData['label']).'</strong>' : '';
423
424
425 // Render general type/title COLUMN:
426 $temp_cells=array();
427
428 // Field type selector:
429 $opt=array();
430 $opt[]='<option value=""></option>';
431 $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property,label');
432 foreach($types as $t) {
433 $opt[]='
434 <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
435 }
436 $temp_cells[$LANG->getLL('forms_type')]='
437 <select name="FORMCFG[c]['.(($k+1)*2).'][type]">
438 '.implode('
439 ',$opt).'
440 </select>';
441
442 // Title field:
443 if (!t3lib_div::inList('hidden,submit',$confData['type'])) {
444 $temp_cells[$LANG->getLL('forms_label')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][label]" value="'.htmlspecialchars($confData['label']).'" />';
445 }
446
447 // Required checkbox:
448 if (!t3lib_div::inList('check,hidden,submit,label',$confData['type'])) {
449 $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).'" />';
450 }
451
452 // Put sub-items together into table cell:
453 $cells[]=$this->formatCells($temp_cells);
454
455
456 // Render specific field configuration COLUMN:
457 $temp_cells=array();
458
459 // Fieldname
460 if ($this->special=='formtype_mail' && $confData['type']=='file') {
461 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
462 }
463 if (!t3lib_div::inList('label',$confData['type'])) {
464 $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).'" />';
465 }
466
467 // Field configuration depending on the fields type:
468 switch((string)$confData['type']) {
469 case 'textarea':
470 $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).'" />';
471 $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).'" />';
472 $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).'" />';
473 break;
474 case 'input':
475 case 'password':
476 $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).'" />';
477 $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).'" />';
478 break;
479 case 'file':
480 $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).'" />';
481 break;
482 case 'select':
483 $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).'" />';
484 $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).'" />';
485 $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).'" />';
486 break;
487 }
488
489 // Field configuration depending on the fields type:
490 switch((string)$confData['type']) {
491 case 'textarea':
492 case 'input':
493 case 'password':
494 if (strlen(trim($confData['specialEval']))) {
495 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
496 }
497 break;
498 }
499
500 // Default data
501 if ($confData['type']=='select' || $confData['type']=='radio') {
502 $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>';
503 } elseif ($confData['type']=='check') {
504 $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).'" />';
505 } elseif ($confData['type'] && $confData['type']!='file') {
506 $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).'" />';
507 }
508
509 $cells[]=$confData['type']?$this->formatCells($temp_cells):'';
510
511 // CTRL panel for an item (move up/down/around):
512 $ctrl='';
513 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
514 $onClick=' onclick="'.htmlspecialchars($onClick).'"';
515 // FIXME $inputStyle undefined
516 $brTag=$inputStyle?'':'<br />';
517 if ($k!=0) {
518 $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;
519 } else {
520 $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;
521 }
522 $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;
523 // FIXME $tLines undefined
524 if (($k+1)!=count($tLines)) {
525 $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;
526 } else {
527 $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;
528 }
529 $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;
530
531 $ctrl='<span class="c-wizButtonsV">'.$ctrl.'</span>';
532
533 // Finally, put together the full row from the generated content above:
534 $bgC = $confData['type']?' class="bgColor5"':'';
535 $tRows[]='
536 <tr'.$bgC.'>
537 <td><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td>
538 <td class="bgColor4">'.implode('</td>
539 <td valign="top">',$cells).'</td>
540 </tr>';
541 }
542 } else {
543 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
544 }
545
546 // Increment counter:
547 $k++;
548 }
549
550 // If the form is of the special type "formtype_mail" (used for tt_content elements):
551 if ($this->special=='formtype_mail') {
552
553 // Blank spacer:
554 $tRows[]='
555 <tr>
556 <td colspan="4">&nbsp;</td>
557 </tr>';
558
559 // Header:
560 $tRows[]='
561 <tr>
562 <td colspan="2" class="bgColor2">&nbsp;</td>
563 <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
564 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
565 '</td>
566 </tr>';
567
568 // "FORM type":
569 $tRows[]='
570 <tr class="bgColor5">
571 <td>&nbsp;</td>
572 <td class="bgColor4">&nbsp;</td>
573 <td>'.$LANG->getLL('forms_eform_formtype_mail',1).':</td>
574 <td>
575 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
576 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
577 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
578 </td>
579 </tr>';
580
581 // "Send HTML mail":
582 $tRows[]='
583 <tr class="bgColor5">
584 <td>&nbsp;</td>
585 <td class="bgColor4">&nbsp;</td>
586 <td>'.$LANG->getLL('forms_eform_html_enabled',1).':</td>
587 <td>
588 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
589 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
590 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
591 </td>
592 </tr>';
593
594 // "Subject":
595 $tRows[]='
596 <tr class="bgColor5">
597 <td>&nbsp;</td>
598 <td class="bgColor4">&nbsp;</td>
599 <td>'.$LANG->getLL('forms_eform_subject',1).':</td>
600 <td>
601 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
602 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
603 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
604 </td>
605 </tr>';
606
607 // Recipient:
608 $tRows[]='
609 <tr class="bgColor5">
610 <td>&nbsp;</td>
611 <td class="bgColor4">&nbsp;</td>
612 <td>'.$LANG->getLL('forms_eform_recipient',1).':</td>
613 <td>
614 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
615 </td>
616 </tr>';
617 }
618
619 $content = '';
620
621 // Add CSH:
622 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'],'');
623
624 // Implode all table rows into a string, wrapped in table tags.
625 $content.= '
626
627 <!--
628 Form wizard
629 -->
630 <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
631 '.implode('',$tRows).'
632 </table>';
633
634 // Add saving buttons in the bottom:
635 $content.= '
636
637 <!--
638 Save buttons:
639 -->
640 <div id="c-saveButtonPanel">';
641 $content.= '<input type="image" class="c-inputButton" name="savedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/savedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc',1).'" />';
642 $content.= '<input type="image" class="c-inputButton" name="saveandclosedok"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/saveandclosedok.gif','').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc',1).'" />';
643 $content.= '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($this->P['returnUrl']).'\')); return false;').'">'.
644 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/closedok.gif','width="21" height="16"').' class="c-inputButton" title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc',1).'" alt="" />'.
645 '</a>';
646 $content.= '<input type="image" class="c-inputButton" name="_refresh"'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
647 // Add CSH:
648 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'],'');
649 $content.= '
650 </div>
651 ';
652
653 // Add hidden fields:
654 $content.= implode('',$hiddenFields);
655
656 // Return content:
657 return $content;
658 }
659
660 /**
661 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal FORMCFG array
662 *
663 * @return void
664 * @access private
665 */
666 function changeFunc() {
667 if ($this->FORMCFG['row_remove']) {
668 $kk = key($this->FORMCFG['row_remove']);
669 $cmd='row_remove';
670 } elseif ($this->FORMCFG['row_add']) {
671 $kk = key($this->FORMCFG['row_add']);
672 $cmd='row_add';
673 } elseif ($this->FORMCFG['row_top']) {
674 $kk = key($this->FORMCFG['row_top']);
675 $cmd='row_top';
676 } elseif ($this->FORMCFG['row_bottom']) {
677 $kk = key($this->FORMCFG['row_bottom']);
678 $cmd='row_bottom';
679 } elseif ($this->FORMCFG['row_up']) {
680 $kk = key($this->FORMCFG['row_up']);
681 $cmd='row_up';
682 } elseif ($this->FORMCFG['row_down']) {
683 $kk = key($this->FORMCFG['row_down']);
684 $cmd='row_down';
685 }
686
687 if ($cmd && t3lib_div::testInt($kk)) {
688 if (substr($cmd,0,4)=='row_') {
689 switch($cmd) {
690 case 'row_remove':
691 unset($this->FORMCFG['c'][$kk]);
692 break;
693 case 'row_add':
694 $this->FORMCFG['c'][$kk+1]=array();
695 break;
696 case 'row_top':
697 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
698 unset($this->FORMCFG['c'][$kk]);
699 break;
700 case 'row_bottom':
701 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
702 unset($this->FORMCFG['c'][$kk]);
703 break;
704 case 'row_up':
705 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
706 unset($this->FORMCFG['c'][$kk]);
707 break;
708 case 'row_down':
709 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
710 unset($this->FORMCFG['c'][$kk]);
711 break;
712 }
713 ksort($this->FORMCFG['c']);
714 }
715 }
716 }
717
718 /**
719 * Converts the input array to a configuration code string
720 *
721 * @param array Array of form configuration (follows the input structure from the form wizard POST form)
722 * @return string The array converted into a string with line-based configuration.
723 * @see cfgString2CfgArray()
724 */
725 function cfgArray2CfgString($cfgArr) {
726
727 // Initialize:
728 $inLines=array();
729
730 // Traverse the elements of the form wizard and transform the settings into configuration code.
731 foreach($cfgArr as $vv) {
732 if ($vv['comment']) { // If "content" is found, then just pass it over.
733 $inLines[]=trim($vv['comment']);
734 } else { // Begin to put together the single-line configuration code of this field:
735
736 // Reset:
737 $thisLine=array();
738
739 // Set Label:
740 $thisLine[0]=str_replace('|','',$vv['label']);
741
742 // Set Type:
743 if ($vv['type']) {
744 $thisLine[1]=($vv['required']?'*':'').str_replace(',','',($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
745
746 // Default:
747 $tArr=array('','','','','','');
748 switch((string)$vv['type']) {
749 case 'textarea':
750 if (intval($vv['cols'])) $tArr[0]=intval($vv['cols']);
751 if (intval($vv['rows'])) $tArr[1]=intval($vv['rows']);
752 if (trim($vv['extra'])) $tArr[2]=trim($vv['extra']);
753 if (strlen($vv['specialEval'])) {
754 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
755 $thisLine[3] = $vv['specialEval'];
756 }
757 break;
758 case 'input':
759 case 'password':
760 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
761 if (intval($vv['max'])) $tArr[1]=intval($vv['max']);
762 if (strlen($vv['specialEval'])) {
763 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
764 $thisLine[3] = $vv['specialEval'];
765 }
766 break;
767 case 'file':
768 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
769 break;
770 case 'select':
771 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
772 if ($vv['autosize']) $tArr[0]='auto';
773 if ($vv['multiple']) $tArr[1]='m';
774 break;
775 }
776 $tArr = $this->cleanT($tArr);
777 if (count($tArr)) $thisLine[1].=','.implode(',',$tArr);
778
779 $thisLine[1]=str_replace('|','',$thisLine[1]);
780
781 // Default:
782 if ($vv['type']=='select' || $vv['type']=='radio') {
783 $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
784 } elseif ($vv['type']=='check') {
785 if ($vv['default']) $thisLine[2]=1;
786 } elseif (strcmp(trim($vv['default']),'')) {
787 $thisLine[2]=$vv['default'];
788 }
789 if (isset($thisLine[2])) $thisLine[2]=str_replace('|','',$thisLine[2]);
790 }
791
792 // Compile the final line:
793 $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
794 }
795 }
796 // Finally, implode the lines into a string, and return it:
797 return implode(chr(10),$inLines);
798 }
799
800 /**
801 * Converts the input configuration code string into an array
802 *
803 * @param string Configuration code
804 * @return array Configuration array
805 * @see cfgArray2CfgString()
806 */
807 function cfgString2CfgArray($cfgStr) {
808
809 // Traverse the number of form elements:
810 $tLines=explode(chr(10),$cfgStr);
811 foreach($tLines as $k => $v) {
812
813 // Initialize:
814 $confData=array();
815 $val=trim($v);
816
817 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new, unconfigured fields) or b) it is NOT a comment.
818 if (!$val || strcspn($val,'#/')) {
819
820 // Split:
821 $parts = t3lib_div::trimExplode('|',$val);
822
823 // Label:
824 $confData['label'] = trim($parts[0]);
825
826 // Field:
827 $fParts = t3lib_div::trimExplode(',',$parts[1]);
828 $fParts[0]=trim($fParts[0]);
829 if (substr($fParts[0],0,1)=='*') {
830 $confData['required'] = 1;
831 $fParts[0] = substr($fParts[0],1);
832 }
833
834 $typeParts = t3lib_div::trimExplode('=',$fParts[0]);
835 $confData['type'] = trim(strtolower(end($typeParts)));
836
837 if ($confData['type']) {
838 if (count($typeParts)==1) {
839 $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
840
841 // Attachment names...
842 if ($confData['type']=='file') {
843 $confData['fieldname']='attachment'.$attachmentCounter;
844 $attachmentCounter=intval($attachmentCounter)+1;
845 }
846 } else {
847 $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
848 }
849
850 switch((string)$confData['type']) {
851 case 'select':
852 case 'radio':
853 $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
854 break;
855 default:
856 $confData['default'] = trim($parts[2]);
857 break;
858 }
859
860 // Field configuration depending on the fields type:
861 switch((string)$confData['type']) {
862 case 'textarea':
863 $confData['cols'] = $fParts[1];
864 $confData['rows'] = $fParts[2];
865 $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
866 $confData['specialEval'] = trim($parts[3]);
867 break;
868 case 'input':
869 case 'password':
870 $confData['size'] = $fParts[1];
871 $confData['max'] = $fParts[2];
872 $confData['specialEval'] = trim($parts[3]);
873 break;
874 case 'file':
875 $confData['size'] = $fParts[1];
876 break;
877 case 'select':
878 $confData['size'] = intval($fParts[1])?$fParts[1]:'';
879 $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
880 $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
881 break;
882 }
883 }
884 } else {
885 // No configuration, only a comment:
886 $confData=array(
887 'comment' => $val
888 );
889 }
890
891 // Adding config array:
892 $cfgArr[]=$confData;
893 }
894
895 // Return cfgArr
896 return $cfgArr;
897 }
898
899 /**
900 * Removes any "trailing elements" in the array which consists of whitespace (little like trim() does for strings, so this does for arrays)
901 *
902 * @param array Single dim array
903 * @return array Processed array
904 * @access private
905 */
906 function cleanT($tArr) {
907 for($a=count($tArr);$a>0;$a--) {
908 if (strcmp($tArr[$a-1],'')) {
909 break;
910 } else {
911 unset($tArr[$a-1]);
912 }
913 }
914 return $tArr;
915 }
916
917 /**
918 * Wraps items in $fArr in table cells/rows, displaying them vertically.
919 *
920 * @param array Array of label/HTML pairs.
921 * @return string HTML table
922 * @access private
923 */
924 function formatCells($fArr) {
925
926 // Traverse the elements in $fArr and wrap them in table cells:
927 $lines=array();
928 foreach($fArr as $l => $c) {
929 $lines[]='
930 <tr>
931 <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
932 <td>'.$c.'</td>
933 </tr>';
934 }
935
936 // Add a cell which will set a minimum width:
937 $lines[]='
938 <tr>
939 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
940 <td></td>
941 </tr>';
942
943 // Wrap in table and return:
944 return '
945 <table border="0" cellpadding="0" cellspacing="0">
946 '.implode('',$lines).'
947 </table>';
948 }
949 }
950
951 // Include extension?
952 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']) {
953 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
954 }
955
956
957
958
959
960
961
962
963
964
965
966
967 // Make instance:
968 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
969 $SOBE->init();
970
971 // Include files?
972 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
973
974 $SOBE->main();
975 $SOBE->printContent();
976 ?>