Added the media field for page type "Shortcut" as well
[Packages/TYPO3.CMS.git] / typo3 / wizard_forms.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Wizard to help make forms (fx. for tt_content elements) of type 'form'.
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 175: class SC_wizard_forms
42 * 203: function init()
43 * 242: function main()
44 * 257: function printContent()
45 * 268: function formsWizard()
46 *
47 * SECTION: Helper functions
48 * 311: function getConfigCode(&$row)
49 * 382: function getFormHTML($formCfgArray,$row)
50 * 662: function changeFunc()
51 * 721: function cfgArray2CfgString($cfgArr)
52 * 803: function cfgString2CfgArray($cfgStr)
53 * 902: function cleanT($tArr)
54 * 920: function formatCells($fArr)
55 *
56 * TOTAL FUNCTIONS: 11
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61
62
63 $BACK_PATH='';
64 require ('init.php');
65 require ('template.php');
66 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
67
68
69
70
71
72
73
74
75
76
77
78
79 /**
80 * API comments:
81 *
82 * The form wizard can help you to create forms - it allows you to create almost any kind of HTML form elements and in any order and amount.
83 *
84 * The format for the resulting configuration code can be either a line-based configuration. That can look like this:
85 *
86 * Your name: | *name=input | (input your name here!)
87 * Your Email: | *email=input
88 * Your address: | address=textarea,40,10
89 * Your Haircolor: | hair=radio |
90 * upload | attachment=file
91 * | quoted_printable=hidden | 0
92 * | formtype_mail=submit | Send form
93 * | html_enabled=hidden
94 * | subject=hidden | This is the subject
95 *
96 *
97 * Alternatively it can be XML. The same configuration from above looks like this in XML:
98 *
99 * <T3FormWizard>
100 * <n2>
101 * <type>input</type>
102 * <label>Your name:</label>
103 * <required>1</required>
104 * <fieldname>name</fieldname>
105 * <size></size>
106 * <max></max>
107 * <default>(input your name here!)</default>
108 * </n2>
109 * <n4>
110 * <type>input</type>
111 * <label>Your Email:</label>
112 * <required>1</required>
113 * <fieldname>email</fieldname>
114 * <size></size>
115 * <max></max>
116 * <default></default>
117 * </n4>
118 * <n6>
119 * <type>textarea</type>
120 * <label>Your address:</label>
121 * <fieldname>address</fieldname>
122 * <cols>40</cols>
123 * <rows>10</rows>
124 * <default></default>
125 * </n6>
126 * <n8>
127 * <type>radio</type>
128 * <label>Your Haircolor:</label>
129 * <fieldname>hair</fieldname>
130 * <options></options>
131 * </n8>
132 * <n10>
133 * <type>file</type>
134 * <label>upload</label>
135 * <fieldname>attachment</fieldname>
136 * <size></size>
137 * </n10>
138 * <n12>
139 * <type>hidden</type>
140 * <label></label>
141 * <fieldname>quoted_printable</fieldname>
142 * <default>0</default>
143 * </n12>
144 * <n2000>
145 * <fieldname>formtype_mail</fieldname>
146 * <type>submit</type>
147 * <default>Send form</default>
148 * </n2000>
149 * <n2002>
150 * <fieldname>html_enabled</fieldname>
151 * <type>hidden</type>
152 * </n2002>
153 * <n2004>
154 * <fieldname>subject</fieldname>
155 * <type>hidden</type>
156 * <default>This is the subject</default>
157 * </n2004>
158 * <n20>
159 * <content></content>
160 * </n20>
161 * </T3FormWizard>
162 *
163 *
164 * The XML/phpArray structure is the internal format of the wizard.
165 */
166
167
168 /**
169 * Script Class for rendering the Form Wizard
170 *
171 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
172 * @package TYPO3
173 * @subpackage core
174 */
175 class SC_wizard_forms {
176
177 // Internal, dynamic:
178 /**
179 * document template object
180 *
181 * @var mediumDoc
182 */
183 var $doc;
184 var $content; // Content accumulation for the module.
185 var $include_once=array(); // List of files to include.
186 var $attachmentCounter = 0; // Used to numerate attachments automatically.
187
188
189 // Internal, static:
190 var $xmlStorage=0; // If set, the string version of the content is interpreted/written as XML instead of the original linebased kind. This variable still needs binding to the wizard parameters - but support is ready!
191
192
193 // Internal, static: GPvars
194 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
195 var $FORMCFG; // The array which is constantly submitted by the multidimensional form of this wizard.
196 var $special; // Indicates if the form is of a dedicated type, like "formtype_mail" (for tt_content element "Form")
197
198
199
200
201
202
203 /**
204 * Initialization the class
205 *
206 * @return void
207 */
208 function init() {
209 global $BACK_PATH;
210
211 // GPvars:
212 $this->P = t3lib_div::_GP('P');
213 $this->special = t3lib_div::_GP('special');
214 $this->FORMCFG = t3lib_div::_GP('FORMCFG');
215
216 // Setting options:
217 $this->xmlStorage = $this->P['params']['xmlOutput'];
218
219 // Document template object:
220 $this->doc = t3lib_div::makeInstance('mediumDoc');
221 $this->doc->docType = 'xhtml_trans';
222 $this->doc->backPath = $BACK_PATH;
223 $this->doc->JScode=$this->doc->wrapScriptTags('
224 function jumpToUrl(URL,formEl) { //
225 window.location.href = URL;
226 }
227 ');
228
229 // Setting form tag:
230 list($rUri) = explode('#',t3lib_div::getIndpEnv('REQUEST_URI'));
231 $this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
232
233 // Start page:
234 $this->content=$this->doc->startPage('Form Wizard');
235
236 // If save command found, include tcemain:
237 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
238 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
239 }
240 }
241
242 /**
243 * Main function for rendering the form wizard HTML
244 *
245 * @return void
246 */
247 function main() {
248 global $LANG;
249
250 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
251 $this->content.=$this->doc->section($LANG->getLL('forms_title'),$this->formsWizard(),0,1);
252 } else {
253 $this->content.=$this->doc->section($LANG->getLL('forms_title'),'<span class="typo3-red">'.$LANG->getLL('table_noData',1).'</span>',0,1);
254 }
255 }
256
257 /**
258 * Outputting the accumulated content to screen
259 *
260 * @return void
261 */
262 function printContent() {
263 $this->content.= $this->doc->endPage();
264 $this->content = $this->doc->insertStylesAndJS($this->content);
265 echo $this->content;
266 }
267
268 /**
269 * Draws the form wizard content
270 *
271 * @return string HTML content for the form.
272 */
273 function formsWizard() {
274
275 // First, check the references by selecting the record:
276 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
277 if (!is_array($row)) {
278 t3lib_BEfunc::typo3PrintError ('Wizard Error','No reference to record',0);
279 exit;
280 }
281
282 // 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.
283 $formCfgArray = $this->getConfigCode($row);
284
285 // Generation of the Form Wizards HTML code:
286 $content = $this->getFormHTML($formCfgArray,$row);
287
288 // Return content:
289 return $content;
290 }
291
292
293
294
295
296
297
298
299
300
301
302 /****************************
303 *
304 * Helper functions
305 *
306 ***************************/
307
308 /**
309 * Will get and return the configuration code string
310 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
311 *
312 * @param array Current parent record row (passed by value!)
313 * @return array Configuration Array
314 * @access private
315 */
316 function getConfigCode(&$row) {
317
318 // If some data has been submitted, then construct
319 if (isset($this->FORMCFG['c'])) {
320
321 // Process incoming:
322 $this->changeFunc();
323
324 // Convert to string (either line based or XML):
325 if ($this->xmlStorage) {
326 // Convert the input array to XML:
327 $bodyText = t3lib_div::array2xml_cs($this->FORMCFG['c'],'T3FormWizard');
328
329 // Setting cfgArr directly from the input:
330 $cfgArr = $this->FORMCFG['c'];
331 } else {
332 // Convert the input array to a string of configuration code:
333 $bodyText = $this->cfgArray2CfgString($this->FORMCFG['c']);
334
335 // Create cfgArr from the string based configuration - that way it is cleaned up and any incompatibilities will be removed!
336 $cfgArr = $this->cfgString2CfgArray($bodyText);
337 }
338
339 // If a save button has been pressed, then save the new field content:
340 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
341
342 // Make TCEmain object:
343 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
344 $tce->stripslashes_values=0;
345
346 // Put content into the data array:
347 $data=array();
348 $data[$this->P['table']][$this->P['uid']][$this->P['field']]=$bodyText;
349 if ($this->special=='formtype_mail') {
350 $data[$this->P['table']][$this->P['uid']]['subheader']=$this->FORMCFG['recipient'];
351 }
352
353 // Perform the update:
354 $tce->start($data,array());
355 $tce->process_datamap();
356
357 // Re-load the record content:
358 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
359
360 // If the save/close button was pressed, then redirect the screen:
361 if ($_POST['saveandclosedok_x']) {
362 header('Location: '.t3lib_div::locationHeaderUrl($this->P['returnUrl']));
363 exit;
364 }
365 }
366 } else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
367 if ($this->xmlStorage) {
368 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
369 } else { // Regular linebased form configuration:
370 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']]);
371 }
372 $cfgArr = is_array($cfgArr) ? $cfgArr : array();
373 }
374
375 // Return configuration code:
376 return $cfgArr;
377 }
378
379 /**
380 * Creates the HTML for the Form Wizard:
381 *
382 * @param string Form config array
383 * @param array Current parent record array
384 * @return string HTML for the form wizard
385 * @access private
386 */
387 function getFormHTML($formCfgArray,$row) {
388 global $LANG;
389
390 // Initialize variables:
391 $specParts=array();
392 $hiddenFields=array();
393 $tRows=array();
394
395 // Set header row:
396 $cells=array($LANG->getLL('forms_preview',1).':',
397 $LANG->getLL('forms_element',1).':',
398 $LANG->getLL('forms_config',1).':',
399 );
400 $tRows[]='
401 <tr class="bgColor2" id="typo3-formWizardHeader">
402 <td>&nbsp;</td>
403 <td>'.implode('</td>
404 <td>',$cells).'</td>
405 </tr>';
406
407 // Traverse the number of form elements:
408 $k=0;
409 foreach($formCfgArray as $confData) {
410
411 // Initialize:
412 $cells=array();
413
414 // If there is a configuration line which is active, then render it:
415 if (!isset($confData['comment'])) {
416
417 // Special parts:
418 if ($this->special=='formtype_mail' && t3lib_div::inList('formtype_mail,subject,html_enabled',$confData['fieldname'])) {
419 $specParts[$confData['fieldname']] = $confData['default'];
420 } else {
421
422 // Render title/field preview COLUMN
423 $cells[]=$confData['type']!='hidden' ? '<strong>'.htmlspecialchars($confData['label']).'</strong>' : '';
424
425
426 // Render general type/title COLUMN:
427 $temp_cells=array();
428
429 // Field type selector:
430 $opt=array();
431 $opt[]='<option value=""></option>';
432 $types = explode(',','input,textarea,select,check,radio,password,file,hidden,submit,property,label');
433 foreach($types as $t) {
434 $opt[]='
435 <option value="'.$t.'"'.($confData['type']==$t?' selected="selected"':'').'>'.$LANG->getLL('forms_type_'.$t,1).'</option>';
436 }
437 $temp_cells[$LANG->getLL('forms_type')]='
438 <select name="FORMCFG[c]['.(($k+1)*2).'][type]">
439 '.implode('
440 ',$opt).'
441 </select>';
442
443 // Title field:
444 if (!t3lib_div::inList('hidden,submit',$confData['type'])) {
445 $temp_cells[$LANG->getLL('forms_label')]='<input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(($k+1)*2).'][label]" value="'.htmlspecialchars($confData['label']).'" />';
446 }
447
448 // Required checkbox:
449 if (!t3lib_div::inList('check,hidden,submit,label',$confData['type'])) {
450 $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).'" />';
451 }
452
453 // Put sub-items together into table cell:
454 $cells[]=$this->formatCells($temp_cells);
455
456
457 // Render specific field configuration COLUMN:
458 $temp_cells=array();
459
460 // Fieldname
461 if ($this->special=='formtype_mail' && $confData['type']=='file') {
462 $confData['fieldname'] = 'attachment'.(++$this->attachmentCounter);
463 }
464 if (!t3lib_div::inList('label',$confData['type'])) {
465 $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).'" />';
466 }
467
468 // Field configuration depending on the fields type:
469 switch((string)$confData['type']) {
470 case 'textarea':
471 $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).'" />';
472 $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).'" />';
473 $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).'" />';
474 break;
475 case 'input':
476 case 'password':
477 $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).'" />';
478 $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).'" />';
479 break;
480 case 'file':
481 $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).'" />';
482 break;
483 case 'select':
484 $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).'" />';
485 $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).'" />';
486 $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).'" />';
487 break;
488 }
489
490 // Field configuration depending on the fields type:
491 switch((string)$confData['type']) {
492 case 'textarea':
493 case 'input':
494 case 'password':
495 if (strlen(trim($confData['specialEval']))) {
496 $hiddenFields[] = '<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][specialEval]" value="'.htmlspecialchars($confData['specialEval']).'" />';
497 }
498 break;
499 }
500
501 // Default data
502 if ($confData['type']=='select' || $confData['type']=='radio') {
503 $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>';
504 } elseif ($confData['type']=='check') {
505 $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).'" />';
506 } elseif ($confData['type'] && $confData['type']!='file') {
507 $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).'" />';
508 }
509
510 $cells[]=$confData['type']?$this->formatCells($temp_cells):'';
511
512 // CTRL panel for an item (move up/down/around):
513 $ctrl='';
514 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
515 $onClick=' onclick="'.htmlspecialchars($onClick).'"';
516 // FIXME $inputStyle undefined
517 $brTag=$inputStyle?'':'<br />';
518 if ($k!=0) {
519 $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;
520 } else {
521 $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;
522 }
523 $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;
524 // FIXME $tLines undefined
525 if (($k+1)!=count($tLines)) {
526 $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;
527 } else {
528 $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;
529 }
530 $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;
531
532 $ctrl='<span class="c-wizButtonsV">'.$ctrl.'</span>';
533
534 // Finally, put together the full row from the generated content above:
535 $bgC = $confData['type']?' class="bgColor5"':'';
536 $tRows[]='
537 <tr'.$bgC.'>
538 <td><a name="ANC_'.(($k+1)*2).'"></a>'.$ctrl.'</td>
539 <td class="bgColor4">'.implode('</td>
540 <td valign="top">',$cells).'</td>
541 </tr>';
542 }
543 } else {
544 $hiddenFields[]='<input type="hidden" name="FORMCFG[c]['.(($k+1)*2).'][comment]" value="'.htmlspecialchars($confData['comment']).'" />';
545 }
546
547 // Increment counter:
548 $k++;
549 }
550
551 // If the form is of the special type "formtype_mail" (used for tt_content elements):
552 if ($this->special=='formtype_mail') {
553
554 // Blank spacer:
555 $tRows[]='
556 <tr>
557 <td colspan="4">&nbsp;</td>
558 </tr>';
559
560 // Header:
561 $tRows[]='
562 <tr>
563 <td colspan="2" class="bgColor2">&nbsp;</td>
564 <td colspan="2" class="bgColor2"><strong>'.$LANG->getLL('forms_special_eform',1).':</strong>'.
565 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_formmail_info', $GLOBALS['BACK_PATH'],'').
566 '</td>
567 </tr>';
568
569 // "FORM type":
570 $tRows[]='
571 <tr class="bgColor5">
572 <td>&nbsp;</td>
573 <td class="bgColor4">&nbsp;</td>
574 <td>'.$LANG->getLL('forms_eform_formtype_mail',1).':</td>
575 <td>
576 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][fieldname]" value="formtype_mail" />
577 <input type="hidden" name="FORMCFG[c]['.(1000*2).'][type]" value="submit" />
578 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1000*2).'][default]" value="'.htmlspecialchars($specParts['formtype_mail']).'" />
579 </td>
580 </tr>';
581
582 // "Send HTML mail":
583 $tRows[]='
584 <tr class="bgColor5">
585 <td>&nbsp;</td>
586 <td class="bgColor4">&nbsp;</td>
587 <td>'.$LANG->getLL('forms_eform_html_enabled',1).':</td>
588 <td>
589 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][fieldname]" value="html_enabled" />
590 <input type="hidden" name="FORMCFG[c]['.(1001*2).'][type]" value="hidden" />
591 <input type="checkbox" name="FORMCFG[c]['.(1001*2).'][default]" value="1"'.($specParts['html_enabled']?' checked="checked"':'').' />
592 </td>
593 </tr>';
594
595 // "Subject":
596 $tRows[]='
597 <tr class="bgColor5">
598 <td>&nbsp;</td>
599 <td class="bgColor4">&nbsp;</td>
600 <td>'.$LANG->getLL('forms_eform_subject',1).':</td>
601 <td>
602 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][fieldname]" value="subject" />
603 <input type="hidden" name="FORMCFG[c]['.(1002*2).'][type]" value="hidden" />
604 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[c]['.(1002*2).'][default]" value="'.htmlspecialchars($specParts['subject']).'" />
605 </td>
606 </tr>';
607
608 // Recipient:
609 $tRows[]='
610 <tr class="bgColor5">
611 <td>&nbsp;</td>
612 <td class="bgColor4">&nbsp;</td>
613 <td>'.$LANG->getLL('forms_eform_recipient',1).':</td>
614 <td>
615 <input type="text"'.$this->doc->formWidth(15).' name="FORMCFG[recipient]" value="'.htmlspecialchars($row['subheader']).'" />
616 </td>
617 </tr>';
618 }
619
620 $content = '';
621
622 // Add CSH:
623 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz', $GLOBALS['BACK_PATH'],'');
624
625 // Implode all table rows into a string, wrapped in table tags.
626 $content.= '
627
628 <!--
629 Form wizard
630 -->
631 <table border="0" cellpadding="1" cellspacing="1" id="typo3-formwizard">
632 '.implode('',$tRows).'
633 </table>';
634
635 // Add saving buttons in the bottom:
636 $content.= '
637
638 <!--
639 Save buttons:
640 -->
641 <div id="c-saveButtonPanel">';
642 $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).'" />';
643 $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).'" />';
644 $content.= '<a href="#" onclick="'.htmlspecialchars('jumpToUrl(unescape(\''.rawurlencode($this->P['returnUrl']).'\')); return false;').'">'.
645 '<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="" />'.
646 '</a>';
647 $content.= '<input type="image" class="c-inputButton" name="_refresh"'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','').' title="'.$LANG->getLL('forms_refresh',1).'" />';
648 // Add CSH:
649 $content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_forms_wiz_buttons', $GLOBALS['BACK_PATH'],'');
650 $content.= '
651 </div>
652 ';
653
654 // Add hidden fields:
655 $content.= implode('',$hiddenFields);
656
657 // Return content:
658 return $content;
659 }
660
661 /**
662 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal FORMCFG array
663 *
664 * @return void
665 * @access private
666 */
667 function changeFunc() {
668 if ($this->FORMCFG['row_remove']) {
669 $kk = key($this->FORMCFG['row_remove']);
670 $cmd='row_remove';
671 } elseif ($this->FORMCFG['row_add']) {
672 $kk = key($this->FORMCFG['row_add']);
673 $cmd='row_add';
674 } elseif ($this->FORMCFG['row_top']) {
675 $kk = key($this->FORMCFG['row_top']);
676 $cmd='row_top';
677 } elseif ($this->FORMCFG['row_bottom']) {
678 $kk = key($this->FORMCFG['row_bottom']);
679 $cmd='row_bottom';
680 } elseif ($this->FORMCFG['row_up']) {
681 $kk = key($this->FORMCFG['row_up']);
682 $cmd='row_up';
683 } elseif ($this->FORMCFG['row_down']) {
684 $kk = key($this->FORMCFG['row_down']);
685 $cmd='row_down';
686 }
687
688 if ($cmd && t3lib_div::testInt($kk)) {
689 if (substr($cmd,0,4)=='row_') {
690 switch($cmd) {
691 case 'row_remove':
692 unset($this->FORMCFG['c'][$kk]);
693 break;
694 case 'row_add':
695 $this->FORMCFG['c'][$kk+1]=array();
696 break;
697 case 'row_top':
698 $this->FORMCFG['c'][1]=$this->FORMCFG['c'][$kk];
699 unset($this->FORMCFG['c'][$kk]);
700 break;
701 case 'row_bottom':
702 $this->FORMCFG['c'][1000000]=$this->FORMCFG['c'][$kk];
703 unset($this->FORMCFG['c'][$kk]);
704 break;
705 case 'row_up':
706 $this->FORMCFG['c'][$kk-3]=$this->FORMCFG['c'][$kk];
707 unset($this->FORMCFG['c'][$kk]);
708 break;
709 case 'row_down':
710 $this->FORMCFG['c'][$kk+3]=$this->FORMCFG['c'][$kk];
711 unset($this->FORMCFG['c'][$kk]);
712 break;
713 }
714 ksort($this->FORMCFG['c']);
715 }
716 }
717 }
718
719 /**
720 * Converts the input array to a configuration code string
721 *
722 * @param array Array of form configuration (follows the input structure from the form wizard POST form)
723 * @return string The array converted into a string with line-based configuration.
724 * @see cfgString2CfgArray()
725 */
726 function cfgArray2CfgString($cfgArr) {
727
728 // Initialize:
729 $inLines=array();
730
731 // Traverse the elements of the form wizard and transform the settings into configuration code.
732 foreach($cfgArr as $vv) {
733 if ($vv['comment']) { // If "content" is found, then just pass it over.
734 $inLines[]=trim($vv['comment']);
735 } else { // Begin to put together the single-line configuration code of this field:
736
737 // Reset:
738 $thisLine=array();
739
740 // Set Label:
741 $thisLine[0]=str_replace('|','',$vv['label']);
742
743 // Set Type:
744 if ($vv['type']) {
745 $thisLine[1]=($vv['required']?'*':'').str_replace(',','',($vv['fieldname']?$vv['fieldname'].'=':'').$vv['type']);
746
747 // Default:
748 $tArr=array('','','','','','');
749 switch((string)$vv['type']) {
750 case 'textarea':
751 if (intval($vv['cols'])) $tArr[0]=intval($vv['cols']);
752 if (intval($vv['rows'])) $tArr[1]=intval($vv['rows']);
753 if (trim($vv['extra'])) $tArr[2]=trim($vv['extra']);
754 if (strlen($vv['specialEval'])) {
755 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
756 $thisLine[3] = $vv['specialEval'];
757 }
758 break;
759 case 'input':
760 case 'password':
761 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
762 if (intval($vv['max'])) $tArr[1]=intval($vv['max']);
763 if (strlen($vv['specialEval'])) {
764 $thisLine[2] = ''; // Preset blank default value so position 3 can get a value...
765 $thisLine[3] = $vv['specialEval'];
766 }
767 break;
768 case 'file':
769 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
770 break;
771 case 'select':
772 if (intval($vv['size'])) $tArr[0]=intval($vv['size']);
773 if ($vv['autosize']) $tArr[0]='auto';
774 if ($vv['multiple']) $tArr[1]='m';
775 break;
776 }
777 $tArr = $this->cleanT($tArr);
778 if (count($tArr)) $thisLine[1].=','.implode(',',$tArr);
779
780 $thisLine[1]=str_replace('|','',$thisLine[1]);
781
782 // Default:
783 if ($vv['type']=='select' || $vv['type']=='radio') {
784 $thisLine[2]=str_replace(chr(10),', ',str_replace(',','',$vv['options']));
785 } elseif ($vv['type']=='check') {
786 if ($vv['default']) $thisLine[2]=1;
787 } elseif (strcmp(trim($vv['default']),'')) {
788 $thisLine[2]=$vv['default'];
789 }
790 if (isset($thisLine[2])) $thisLine[2]=str_replace('|','',$thisLine[2]);
791 }
792
793 // Compile the final line:
794 $inLines[]=ereg_replace("[\n\r]*",'',implode(' | ',$thisLine));
795 }
796 }
797 // Finally, implode the lines into a string, and return it:
798 return implode(chr(10),$inLines);
799 }
800
801 /**
802 * Converts the input configuration code string into an array
803 *
804 * @param string Configuration code
805 * @return array Configuration array
806 * @see cfgArray2CfgString()
807 */
808 function cfgString2CfgArray($cfgStr) {
809
810 // Traverse the number of form elements:
811 $tLines=explode(chr(10),$cfgStr);
812 foreach($tLines as $k => $v) {
813
814 // Initialize:
815 $confData=array();
816 $val=trim($v);
817
818 // Accept a line as configuration if a) it is blank(! - because blank lines indicates new, unconfigured fields) or b) it is NOT a comment.
819 if (!$val || strcspn($val,'#/')) {
820
821 // Split:
822 $parts = t3lib_div::trimExplode('|',$val);
823
824 // Label:
825 $confData['label'] = trim($parts[0]);
826
827 // Field:
828 $fParts = t3lib_div::trimExplode(',',$parts[1]);
829 $fParts[0]=trim($fParts[0]);
830 if (substr($fParts[0],0,1)=='*') {
831 $confData['required'] = 1;
832 $fParts[0] = substr($fParts[0],1);
833 }
834
835 $typeParts = t3lib_div::trimExplode('=',$fParts[0]);
836 $confData['type'] = trim(strtolower(end($typeParts)));
837
838 if ($confData['type']) {
839 if (count($typeParts)==1) {
840 $confData['fieldname'] = substr(ereg_replace('[^a-zA-Z0-9_]','',str_replace(' ','_',trim($parts[0]))),0,30);
841
842 // Attachment names...
843 if ($confData['type']=='file') {
844 $confData['fieldname']='attachment'.$attachmentCounter;
845 $attachmentCounter=intval($attachmentCounter)+1;
846 }
847 } else {
848 $confData['fieldname'] = str_replace(' ','_',trim($typeParts[0]));
849 }
850
851 switch((string)$confData['type']) {
852 case 'select':
853 case 'radio':
854 $confData['default'] = implode(chr(10),t3lib_div::trimExplode(',',$parts[2]));
855 break;
856 default:
857 $confData['default'] = trim($parts[2]);
858 break;
859 }
860
861 // Field configuration depending on the fields type:
862 switch((string)$confData['type']) {
863 case 'textarea':
864 $confData['cols'] = $fParts[1];
865 $confData['rows'] = $fParts[2];
866 $confData['extra'] = strtoupper($fParts[3])=='OFF' ? 'OFF' : '';
867 $confData['specialEval'] = trim($parts[3]);
868 break;
869 case 'input':
870 case 'password':
871 $confData['size'] = $fParts[1];
872 $confData['max'] = $fParts[2];
873 $confData['specialEval'] = trim($parts[3]);
874 break;
875 case 'file':
876 $confData['size'] = $fParts[1];
877 break;
878 case 'select':
879 $confData['size'] = intval($fParts[1])?$fParts[1]:'';
880 $confData['autosize'] = strtolower(trim($fParts[1]))=='auto' ? 1 : 0;
881 $confData['multiple'] = strtolower(trim($fParts[2]))=='m' ? 1 : 0;
882 break;
883 }
884 }
885 } else {
886 // No configuration, only a comment:
887 $confData=array(
888 'comment' => $val
889 );
890 }
891
892 // Adding config array:
893 $cfgArr[]=$confData;
894 }
895
896 // Return cfgArr
897 return $cfgArr;
898 }
899
900 /**
901 * Removes any "trailing elements" in the array which consists of whitespace (little like trim() does for strings, so this does for arrays)
902 *
903 * @param array Single dim array
904 * @return array Processed array
905 * @access private
906 */
907 function cleanT($tArr) {
908 for($a=count($tArr);$a>0;$a--) {
909 if (strcmp($tArr[$a-1],'')) {
910 break;
911 } else {
912 unset($tArr[$a-1]);
913 }
914 }
915 return $tArr;
916 }
917
918 /**
919 * Wraps items in $fArr in table cells/rows, displaying them vertically.
920 *
921 * @param array Array of label/HTML pairs.
922 * @return string HTML table
923 * @access private
924 */
925 function formatCells($fArr) {
926
927 // Traverse the elements in $fArr and wrap them in table cells:
928 $lines=array();
929 foreach($fArr as $l => $c) {
930 $lines[]='
931 <tr>
932 <td nowrap="nowrap">'.htmlspecialchars($l.':').'&nbsp;</td>
933 <td>'.$c.'</td>
934 </tr>';
935 }
936
937 // Add a cell which will set a minimum width:
938 $lines[]='
939 <tr>
940 <td nowrap="nowrap"><img src="clear.gif" width="70" height="1" alt="" /></td>
941 <td></td>
942 </tr>';
943
944 // Wrap in table and return:
945 return '
946 <table border="0" cellpadding="0" cellspacing="0">
947 '.implode('',$lines).'
948 </table>';
949 }
950 }
951
952 // Include extension?
953 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']) {
954 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_forms.php']);
955 }
956
957
958
959
960
961
962
963
964
965
966
967
968 // Make instance:
969 $SOBE = t3lib_div::makeInstance('SC_wizard_forms');
970 $SOBE->init();
971
972 // Include files?
973 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
974
975 $SOBE->main();
976 $SOBE->printContent();
977 ?>