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