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