*** empty log message ***
[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 * 258: function printContent()
45 * 267: function formsWizard()
46 *
47 * SECTION: Helper functions
48 * 310: function getConfigCode(&$row)
49 * 381: function getFormHTML($formCfgArray,$row)
50 * 660: function changeFunc()
51 * 719: function cfgArray2CfgString($cfgArr)
52 * 801: function cfgString2CfgArray($cfgStr)
53 * 900: function cleanT($tArr)
54 * 918: 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 document.location = 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 $this->content.=$this->doc->endPage();
251 }
252
253 /**
254 * Outputting the accumulated content to screen
255 *
256 * @return void
257 */
258 function printContent() {
259 echo $this->content;
260 }
261
262 /**
263 * Draws the form wizard content
264 *
265 * @return string HTML content for the form.
266 */
267 function formsWizard() {
268
269 // First, check the references by selecting the record:
270 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
271 if (!is_array($row)) {
272 t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
273 exit;
274 }
275
276 // 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.
277 $formCfgArray = $this->getConfigCode($row);
278
279 // Generation of the Form Wizards HTML code:
280 $content = $this->getFormHTML($formCfgArray,$row);
281
282 // Return content:
283 return $content;
284 }
285
286
287
288
289
290
291
292
293
294
295
296 /****************************
297 *
298 * Helper functions
299 *
300 ***************************/
301
302 /**
303 * Will get and return the configuration code string
304 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
305 *
306 * @param array Current parent record row (passed by value!)
307 * @return array Configuration Array
308 * @access private
309 */
310 function getConfigCode(&$row) {
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 ($_POST['savedok_x'] || $_POST['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 ($_POST['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,property,label');
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('check,hidden,submit,label',$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 if ($this->special=='formtype_mail' && $confData['type']=='file') {
456 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
457 }
458 if (!t3lib_div::inList('label',$confData['type'])) {
459 $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).'" />';
460 }
461
462 // Field configuration depending on the fields type:
463 switch((string)$confData['type']) {
464 case 'textarea':
465 $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).'" />';
466 $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).'" />';
467 $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).'" />';
468 break;
469 case 'input':
470 case 'password':
471 $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).'" />';
472 $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).'" />';
473 break;
474 case 'file':
475 $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).'" />';
476 break;
477 case 'select':
478 $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).'" />';
479 $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).'" />';
480 $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).'" />';
481 break;
482 }
483
484 // Field configuration depending on the fields type:
485 switch((string)$confData['type']) {
486 case 'textarea':
487 case 'input':
488 case 'password':
489 if (strlen(trim($confData['specialEval']))) {
490 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
491 }
492 break;
493 }
494
495 // Default data
496 if ($confData['type']=='select' || $confData['type']=='radio') {
497 $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>';
498 } elseif ($confData['type']=='check') {
499 $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).'" />';
500 } elseif ($confData['type'] && $confData['type']!='file') {
501 $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).'" />';
502 }
503
504 $cells[]=$confData['type']?$this->formatCells($temp_cells):'';
505
506 // CTRL panel for an item (move up/down/around):
507 $ctrl='';
508 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
509 $onClick=' onclick="'.htmlspecialchars($onClick).'"';
510
511 $brTag=$inputStyle?'':'<br />';
512 if ($k!=0) {
513 $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;
514 } else {
515 $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;
516 }
517 $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;
518 if (($k+1)!=count($tLines)) {
519 $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;
520 } else {
521 $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;
522 }
523 $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;
524
525 $ctrl='<span class="c-wizButtonsV">'.$ctrl.'</span>';
526
527 // Finally, put together the full row from the generated content above:
528 $bgC = $confData['type']?' class="bgColor5"':'';
529 $tRows[]='
530 <tr'.$bgC.'>
531 <td><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td>
532 <td class="bgColor4">'.implode('</td>
533 <td valign="top">',$cells).'</td>
534 </tr>';
535 }
536 } else {
537 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
538 }
539
540 // Increment counter:
541 $k++;
542 }
543
544 // If the form is of the special type "formtype_mail" (used for tt_content elements):
545 if ($this->special=='formtype_mail') {
546
547 // Blank spacer:
548 $tRows[]='
549 <tr>
550 <td colspan="4">&nbsp;</td>
551 </tr>';
552
553 // Header:
554 $tRows[]='
555 <tr>
556 <td colspan="2" class="bgColor2">&nbsp;</td>
557 <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
558 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
559 '</td>
560 </tr>';
561
562 // "FORM type":
563 $tRows[]='
564 <tr class="bgColor5">
565 <td>&nbsp;</td>
566 <td class="bgColor4">&nbsp;</td>
567 <td>'.$LANG->getLL('forms_eform_formtype_mail',1).':</td>
568 <td>
569 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
570 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
571 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
572 </td>
573 </tr>';
574
575 // "Send HTML mail":
576 $tRows[]='
577 <tr class="bgColor5">
578 <td>&nbsp;</td>
579 <td class="bgColor4">&nbsp;</td>
580 <td>'.$LANG->getLL('forms_eform_html_enabled',1).':</td>
581 <td>
582 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
583 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
584 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
585 </td>
586 </tr>';
587
588 // "Subject":
589 $tRows[]='
590 <tr class="bgColor5">
591 <td>&nbsp;</td>
592 <td class="bgColor4">&nbsp;</td>
593 <td>'.$LANG->getLL('forms_eform_subject',1).':</td>
594 <td>
595 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
596 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
597 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
598 </td>
599 </tr>';
600
601 // Recipient:
602 $tRows[]='
603 <tr class="bgColor5">
604 <td>&nbsp;</td>
605 <td class="bgColor4">&nbsp;</td>
606 <td>'.$LANG->getLL('forms_eform_recipient',1).':</td>
607 <td>
608 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
609 </td>
610 </tr>';
611 }
612
613 $content = '';
614
615 // Add CSH:
616 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'],'');
617
618 // Implode all table rows into a string, wrapped in table tags.
619 $content.= '
620
621 <!--
622 Form wizard
623 -->
624 <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
625 '.implode('',$tRows).'
626 </table>';
627
628 // Add saving buttons in the bottom:
629 $content.= '
630
631 <!--
632 Save buttons:
633 -->
634 <div id="c-saveButtonPanel">';
635 $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).'" />';
636 $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).'" />';
637 $content.= '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($this->P['returnUrl']).'\')); return false;').'">'.
638 '<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="" />'.
639 '</a>';
640 $content.= '<input type="image" class="c-inputButton" name="_refresh"'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
641 // Add CSH:
642 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'],'');
643 $content.= '
644 </div>
645 ';
646
647 // Add hidden fields:
648 $content.= implode('',$hiddenFields);
649
650 // Return content:
651 return $content;
652 }
653
654 /**
655 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal FORMCFG array
656 *
657 * @return void
658 * @access private
659 */
660 function changeFunc() {
661 if ($this->FORMCFG['row_remove']) {
662 $kk = key($this->FORMCFG['row_remove']);
663 $cmd='row_remove';
664 } elseif ($this->FORMCFG['row_add']) {
665 $kk = key($this->FORMCFG['row_add']);
666 $cmd='row_add';
667 } elseif ($this->FORMCFG['row_top']) {
668 $kk = key($this->FORMCFG['row_top']);
669 $cmd='row_top';
670 } elseif ($this->FORMCFG['row_bottom']) {
671 $kk = key($this->FORMCFG['row_bottom']);
672 $cmd='row_bottom';
673 } elseif ($this->FORMCFG['row_up']) {
674 $kk = key($this->FORMCFG['row_up']);
675 $cmd='row_up';
676 } elseif ($this->FORMCFG['row_down']) {
677 $kk = key($this->FORMCFG['row_down']);
678 $cmd='row_down';
679 }
680
681 if ($cmd && t3lib_div::testInt($kk)) {
682 if (substr($cmd,0,4)=='row_') {
683 switch($cmd) {
684 case 'row_remove':
685 unset($this->FORMCFG['c'][$kk]);
686 break;
687 case 'row_add':
688 $this->FORMCFG['c'][$kk+1]=array();
689 break;
690 case 'row_top':
691 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
692 unset($this->FORMCFG['c'][$kk]);
693 break;
694 case 'row_bottom':
695 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
696 unset($this->FORMCFG['c'][$kk]);
697 break;
698 case 'row_up':
699 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
700 unset($this->FORMCFG['c'][$kk]);
701 break;
702 case 'row_down':
703 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
704 unset($this->FORMCFG['c'][$kk]);
705 break;
706 }
707 ksort($this->FORMCFG['c']);
708 }
709 }
710 }
711
712 /**
713 * Converts the input array to a configuration code string
714 *
715 * @param array Array of form configuration (follows the input structure from the form wizard POST form)
716 * @return string The array converted into a string with line-based configuration.
717 * @see cfgString2CfgArray()
718 */
719 function cfgArray2CfgString($cfgArr) {
720
721 // Initialize:
722 $inLines=array();
723
724 // Traverse the elements of the form wizard and transform the settings into configuration code.
725 foreach($cfgArr as $vv) {
726 if ($vv['comment']) { // If "content" is found, then just pass it over.
727 $inLines[]=trim($vv['comment']);
728 } else { // Begin to put together the single-line configuration code of this field:
729
730 // Reset:
731 $thisLine=array();
732
733 // Set Label:
734 $thisLine[0]=str_replace('|','',$vv['label']);
735
736 // Set Type:
737 if ($vv['type']) {
738 $thisLine[1]=($vv['required']?'*':'').str_replace(',','',($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
739
740 // Default:
741 $tArr=array('','','','','','');
742 switch((string)$vv['type']) {
743 case 'textarea':
744 if (intval($vv['cols'])) $tArr[0]=intval($vv['cols']);
745 if (intval($vv['rows'])) $tArr[1]=intval($vv['rows']);
746 if (trim($vv['extra'])) $tArr[2]=trim($vv['extra']);
747 if (strlen($vv['specialEval'])) {
748 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
749 $thisLine[3] = $vv['specialEval'];
750 }
751 break;
752 case 'input':
753 case 'password':
754 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
755 if (intval($vv['max'])) $tArr[1]=intval($vv['max']);
756 if (strlen($vv['specialEval'])) {
757 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
758 $thisLine[3] = $vv['specialEval'];
759 }
760 break;
761 case 'file':
762 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
763 break;
764 case 'select':
765 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
766 if ($vv['autosize']) $tArr[0]='auto';
767 if ($vv['multiple']) $tArr[1]='m';
768 break;
769 }
770 $tArr = $this->cleanT($tArr);
771 if (count($tArr)) $thisLine[1].=','.implode(',',$tArr);
772
773 $thisLine[1]=str_replace('|','',$thisLine[1]);
774
775 // Default:
776 if ($vv['type']=='select' || $vv['type']=='radio') {
777 $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
778 } elseif ($vv['type']=='check') {
779 if ($vv['default']) $thisLine[2]=1;
780 } elseif (strcmp(trim($vv['default']),'')) {
781 $thisLine[2]=$vv['default'];
782 }
783 if (isset($thisLine[2])) $thisLine[2]=str_replace('|','',$thisLine[2]);
784 }
785
786 // Compile the final line:
787 $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
788 }
789 }
790 // Finally, implode the lines into a string, and return it:
791 return implode(chr(10),$inLines);
792 }
793
794 /**
795 * Converts the input configuration code string into an array
796 *
797 * @param string Configuration code
798 * @return array Configuration array
799 * @see cfgArray2CfgString()
800 */
801 function cfgString2CfgArray($cfgStr) {
802
803 // Traverse the number of form elements:
804 $tLines=explode(chr(10),$cfgStr);
805 foreach($tLines as $k => $v) {
806
807 // Initialize:
808 $confData=array();
809 $val=trim($v);
810
811 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new, unconfigured fields) or b) it is NOT a comment.
812 if (!$val || strcspn($val,'#/')) {
813
814 // Split:
815 $parts = t3lib_div::trimExplode('|',$val);
816
817 // Label:
818 $confData['label'] = trim($parts[0]);
819
820 // Field:
821 $fParts = t3lib_div::trimExplode(',',$parts[1]);
822 $fParts[0]=trim($fParts[0]);
823 if (substr($fParts[0],0,1)=='*') {
824 $confData['required'] = 1;
825 $fParts[0] = substr($fParts[0],1);
826 }
827
828 $typeParts = t3lib_div::trimExplode('=',$fParts[0]);
829 $confData['type'] = trim(strtolower(end($typeParts)));
830
831 if ($confData['type']) {
832 if (count($typeParts)==1) {
833 $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
834
835 // Attachment names...
836 if ($confData['type']=='file') {
837 $confData['fieldname']='attachment'.$attachmentCounter;
838 $attachmentCounter=intval($attachmentCounter)+1;
839 }
840 } else {
841 $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
842 }
843
844 switch((string)$confData['type']) {
845 case 'select':
846 case 'radio':
847 $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
848 break;
849 default:
850 $confData['default'] = trim($parts[2]);
851 break;
852 }
853
854 // Field configuration depending on the fields type:
855 switch((string)$confData['type']) {
856 case 'textarea':
857 $confData['cols'] = $fParts[1];
858 $confData['rows'] = $fParts[2];
859 $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
860 $confData['specialEval'] = trim($parts[3]);
861 break;
862 case 'input':
863 case 'password':
864 $confData['size'] = $fParts[1];
865 $confData['max'] = $fParts[2];
866 $confData['specialEval'] = trim($parts[3]);
867 break;
868 case 'file':
869 $confData['size'] = $fParts[1];
870 break;
871 case 'select':
872 $confData['size'] = intval($fParts[1])?$fParts[1]:'';
873 $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
874 $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
875 break;
876 }
877 }
878 } else {
879 // No configuration, only a comment:
880 $confData=array(
881 'comment' => $val
882 );
883 }
884
885 // Adding config array:
886 $cfgArr[]=$confData;
887 }
888
889 // Return cfgArr
890 return $cfgArr;
891 }
892
893 /**
894 * Removes any "trailing elements" in the array which consists of whitespace (little like trim() does for strings, so this does for arrays)
895 *
896 * @param array Single dim array
897 * @return array Processed array
898 * @access private
899 */
900 function cleanT($tArr) {
901 for($a=count($tArr);$a>0;$a--) {
902 if (strcmp($tArr[$a-1],'')) {
903 break;
904 } else {
905 unset($tArr[$a-1]);
906 }
907 }
908 return $tArr;
909 }
910
911 /**
912 * Wraps items in $fArr in table cells/rows, displaying them vertically.
913 *
914 * @param array Array of label/HTML pairs.
915 * @return string HTML table
916 * @access private
917 */
918 function formatCells($fArr) {
919
920 // Traverse the elements in $fArr and wrap them in table cells:
921 $lines=array();
922 foreach($fArr as $l => $c) {
923 $lines[]='
924 <tr>
925 <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
926 <td>'.$c.'</td>
927 </tr>';
928 }
929
930 // Add a cell which will set a minimum width:
931 $lines[]='
932 <tr>
933 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
934 <td></td>
935 </tr>';
936
937 // Wrap in table and return:
938 return '
939 <table border="0" cellpadding="0" cellspacing="0">
940 '.implode('',$lines).'
941 </table>';
942 }
943 }
944
945 // Include extension?
946 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']) {
947 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
948 }
949
950
951
952
953
954
955
956
957
958
959
960
961 // Make instance:
962 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
963 $SOBE->init();
964
965 // Include files?
966 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
967
968 $SOBE->main();
969 $SOBE->printContent();
970 ?>