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