[BUGFIX] Reduce spacing CGL violations in /typo3/
[Packages/TYPO3.CMS.git] / typo3 / wizard_table.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 tables (eg. for tt_content elements) of type "table".
29 * Each line is a table row, each cell divided by a |
30 *
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
32 * XHTML compliant
33 *
34 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
35 */
36
37
38
39 $BACK_PATH='';
40 require ('init.php');
41 require ('template.php');
42 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_wizards.xml');
43
44
45
46
47
48
49
50
51
52
53
54 /**
55 * Script Class for rendering the Table Wizard
56 *
57 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
58 * @package TYPO3
59 * @subpackage core
60 */
61 class SC_wizard_table {
62
63 // Internal, dynamic:
64 /**
65 * document template object
66 *
67 * @var mediumDoc
68 */
69 var $doc;
70 var $content; // Content accumulation for the module.
71 var $include_once=array(); // List of files to include.
72 var $inputStyle=0; // TRUE, then <input> fields are shown, not textareas.
73
74
75 // Internal, static:
76 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!
77 var $numNewRows=1; // Number of new rows to add in bottom of wizard
78 var $colsFieldName='cols'; // Name of field in parent record which MAY contain the number of columns for the table - here hardcoded to the value of tt_content. Should be set by TCEform parameters (from P)
79
80
81 // Internal, static: GPvars
82 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
83 var $TABLECFG; // The array which is constantly submitted by the multidimensional form of this wizard.
84
85 // table parsing
86 var $tableParsing_quote; // quoting of table cells
87 var $tableParsing_delimiter; // delimiter between table cells
88
89
90
91
92
93 /**
94 * Initialization of the class
95 *
96 * @return void
97 */
98 function init() {
99 // GPvars:
100 $this->P = t3lib_div::_GP('P');
101 $this->TABLECFG = t3lib_div::_GP('TABLE');
102
103 // Setting options:
104 $this->xmlStorage = $this->P['params']['xmlOutput'];
105 $this->numNewRows = t3lib_utility_Math::forceIntegerInRange($this->P['params']['numNewRows'],1,50,5);
106
107 // Textareas or input fields:
108 $this->inputStyle=isset($this->TABLECFG['textFields']) ? $this->TABLECFG['textFields'] : 1;
109
110 // Document template object:
111 $this->doc = t3lib_div::makeInstance('template');
112 $this->doc->backPath = $GLOBALS['BACK_PATH'];
113 $this->doc->setModuleTemplate('templates/wizard_table.html');
114 $this->doc->JScode=$this->doc->wrapScriptTags('
115 function jumpToUrl(URL,formEl) { //
116 window.location.href = URL;
117 }
118 ');
119
120 // Setting form tag:
121 list($rUri) = explode('#',t3lib_div::getIndpEnv('REQUEST_URI'));
122 $this->doc->form ='<form action="'.htmlspecialchars($rUri).'" method="post" name="wizardForm">';
123
124 // If save command found, include tcemain:
125 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
126 $this->include_once[]=PATH_t3lib.'class.t3lib_tcemain.php';
127 }
128
129 $this->tableParsing_delimiter = '|';
130 $this->tableParsing_quote = '';
131 }
132
133 /**
134 * Main function, rendering the table wizard
135 *
136 * @return void
137 */
138 function main() {
139 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
140 $this->content.= $this->doc->section($GLOBALS['LANG']->getLL('table_title'), $this->tableWizard(), 0, 1);
141 } else {
142 $this->content.= $this->doc->section($GLOBALS['LANG']->getLL('table_title'), '<span class="typo3-red">' . $GLOBALS['LANG']->getLL('table_noData',1) . '</span>', 0, 1);
143 }
144
145 // Setting up the buttons and markers for docheader
146 $docHeaderButtons = $this->getButtons();
147 $markers['CSH'] = $docHeaderButtons['csh'];
148 $markers['CONTENT'] = $this->content;
149
150 // Build the <body> for the module
151 $this->content = $this->doc->startPage('Table');
152 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
153 $this->content.= $this->doc->endPage();
154 $this->content = $this->doc->insertStylesAndJS($this->content);
155 }
156
157 /**
158 * Outputting the accumulated content to screen
159 *
160 * @return void
161 */
162 function printContent() {
163 echo $this->content;
164 }
165
166 /**
167 * Create the panel of buttons for submitting the form or otherwise perform operations.
168 *
169 * @return array all available buttons as an assoc. array
170 */
171 protected function getButtons() {
172 $buttons = array(
173 'csh' => '',
174 'csh_buttons' => '',
175 'close' => '',
176 'save' => '',
177 'save_close' => '',
178 'reload' => '',
179 );
180
181 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
182 // CSH
183 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz', $GLOBALS['BACK_PATH'], '');
184
185 // CSH Buttons
186 $buttons['csh_buttons'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'wizard_table_wiz_buttons', $GLOBALS['BACK_PATH'], '');
187
188 // Close
189 $buttons['close'] = '<a href="#" onclick="' . htmlspecialchars('jumpToUrl(unescape(\'' . rawurlencode(t3lib_div::sanitizeLocalUrl($this->P['returnUrl'])) . '\')); return false;') . '">' .
190 t3lib_iconWorks::getSpriteIcon('actions-document-close', array('title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE))) .
191 '</a>';
192
193 // Save
194 $buttons['save'] = '<input type="image" class="c-inputButton" name="savedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/savedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', 1) . '" />';
195
196 // Save & Close
197 $buttons['save_close'] = '<input type="image" class="c-inputButton" name="saveandclosedok"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/saveandclosedok.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', 1) . '" />';
198
199 // Reload
200 $buttons['reload'] = '<input type="image" class="c-inputButton" name="_refresh"' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/refresh_n.gif') . ' title="' . $GLOBALS['LANG']->getLL('forms_refresh', 1) . '" />';
201 }
202
203 return $buttons;
204 }
205
206 /**
207 * Draws the table wizard content
208 *
209 * @return string HTML content for the form.
210 */
211 function tableWizard() {
212
213 // First, check the references by selecting the record:
214 $row = t3lib_BEfunc::getRecord($this->P['table'],$this->P['uid']);
215 if (!is_array($row)) {
216 throw new RuntimeException('Wizard Error: No reference to record', 1294587125);
217 }
218
219 // 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.
220 $tableCfgArray = $this->getConfigCode($row);
221
222 // Generation of the Table Wizards HTML code:
223 $content = $this->getTableHTML($tableCfgArray,$row);
224
225 // Return content:
226 return $content;
227 }
228
229
230
231
232
233
234
235 /***************************
236 *
237 * Helper functions
238 *
239 ***************************/
240
241 /**
242 * Will get and return the configuration code string
243 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
244 *
245 * @param array Current parent record row
246 * @return array Table config code in an array
247 * @access private
248 */
249 function getConfigCode($row) {
250
251 // get delimiter settings
252 $flexForm = t3lib_div::xml2array($row['pi_flexform']);
253
254 if (is_array($flexForm)) {
255 $this->tableParsing_quote = $flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF']?chr(intval($flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF'])):'';
256 $this->tableParsing_delimiter = $flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF']?chr(intval($flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF'])):'|';
257 }
258
259 // If some data has been submitted, then construct
260 if (isset($this->TABLECFG['c'])) {
261
262 // Process incoming:
263 $this->changeFunc();
264
265
266 // Convert to string (either line based or XML):
267 if ($this->xmlStorage) {
268 // Convert the input array to XML:
269 $bodyText = t3lib_div::array2xml_cs($this->TABLECFG['c'],'T3TableWizard');
270
271 // Setting cfgArr directly from the input:
272 $cfgArr = $this->TABLECFG['c'];
273 } else {
274 // Convert the input array to a string of configuration code:
275 $bodyText = $this->cfgArray2CfgString($this->TABLECFG['c']);
276
277 // Create cfgArr from the string based configuration - that way it is cleaned up and any incompatibilities will be removed!
278 $cfgArr = $this->cfgString2CfgArray($bodyText,$row[$this->colsFieldName]);
279 }
280
281 // If a save button has been pressed, then save the new field content:
282 if ($_POST['savedok_x'] || $_POST['saveandclosedok_x']) {
283
284 // Make TCEmain object:
285 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
286 $tce->stripslashes_values=0;
287
288 // Put content into the data array:
289 $data=array();
290 $data[$this->P['table']][$this->P['uid']][$this->P['field']]=$bodyText;
291
292 // Perform the update:
293 $tce->start($data,array());
294 $tce->process_datamap();
295
296 // If the save/close button was pressed, then redirect the screen:
297 if ($_POST['saveandclosedok_x']) {
298 t3lib_utility_Http::redirect(t3lib_div::sanitizeLocalUrl($this->P['returnUrl']));
299 }
300 }
301 } else { // If nothing has been submitted, load the $bodyText variable from the selected database row:
302 if ($this->xmlStorage) {
303 $cfgArr = t3lib_div::xml2array($row[$this->P['field']]);
304 } else { // Regular linebased table configuration:
305 $cfgArr = $this->cfgString2CfgArray($row[$this->P['field']],$row[$this->colsFieldName]);
306 }
307 $cfgArr = is_array($cfgArr) ? $cfgArr : array();
308 }
309
310 return $cfgArr;
311 }
312
313 /**
314 * Creates the HTML for the Table Wizard:
315 *
316 * @param array Table config array
317 * @param array Current parent record array
318 * @return string HTML for the table wizard
319 * @access private
320 */
321 function getTableHTML($cfgArr,$row) {
322 // Traverse the rows:
323 $tRows=array();
324 $k=0;
325 foreach($cfgArr as $cellArr) {
326 if (is_array($cellArr)) {
327 // Initialize:
328 $cells=array();
329 $a=0;
330
331 // Traverse the columns:
332 foreach($cellArr as $cellContent) {
333 if ($this->inputStyle) {
334 $cells[]='<input type="text"'.$this->doc->formWidth(20).' name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']" value="'.htmlspecialchars($cellContent).'" />';
335 } else {
336 $cellContent=preg_replace('/<br[ ]?[\/]?>/i',LF,$cellContent);
337 $cells[]='<textarea '.$this->doc->formWidth(20).' rows="5" name="TABLE[c]['.(($k+1)*2).']['.(($a+1)*2).']">'.t3lib_div::formatForTextarea($cellContent).'</textarea>';
338 }
339
340 // Increment counter:
341 $a++;
342 }
343
344 // CTRL panel for a table row (move up/down/around):
345 $onClick="document.wizardForm.action+='#ANC_".(($k+1)*2-2)."';";
346 $onClick=' onclick="'.htmlspecialchars($onClick).'"';
347 $ctrl='';
348
349 $brTag=$this->inputStyle?'':'<br />';
350 if ($k!=0) {
351 $ctrl.='<input type="image" name="TABLE[row_up]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2up.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_up',1).'" />'.$brTag;
352 } else {
353 $ctrl.='<input type="image" name="TABLE[row_bottom]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_up.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_bottom',1).'" />'.$brTag;
354 }
355 $ctrl.='<input type="image" name="TABLE[row_remove]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/garbage.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_removeRow',1).'" />'.$brTag;
356
357 // FIXME what is $tLines? See wizard_forms.php for the same.
358 if (($k+1)!=count($tLines)) {
359 $ctrl.='<input type="image" name="TABLE[row_down]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2down.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_down',1).'" />'.$brTag;
360 } else {
361 $ctrl.='<input type="image" name="TABLE[row_top]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_down.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_top',1).'" />'.$brTag;
362 }
363 $ctrl.='<input type="image" name="TABLE[row_add]['.(($k+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/add.gif','').$onClick.' title="'.$GLOBALS['LANG']->getLL('table_addRow',1).'" />'.$brTag;
364
365 $tRows[]='
366 <tr class="bgColor4">
367 <td class="bgColor5"><a name="ANC_'.(($k+1)*2).'"></a><span class="c-wizButtonsV">'.$ctrl.'</span></td>
368 <td>'.implode('</td>
369 <td>',$cells).'</td>
370 </tr>';
371
372 // Increment counter:
373 $k++;
374 }
375 }
376
377 // CTRL panel for a table column (move left/right/around/delete)
378 $cells=array();
379 $cells[]='';
380 // Finding first row:
381 $firstRow = reset($cfgArr);
382 if (is_array($firstRow)) {
383
384 // Init:
385 $a=0;
386 $cols=count($firstRow);
387
388 // Traverse first row:
389 foreach($firstRow as $temp) {
390 $ctrl='';
391 if ($a!=0) {
392 $ctrl.='<input type="image" name="TABLE[col_left]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2left.gif','').' title="'.$GLOBALS['LANG']->getLL('table_left',1).'" />';
393 } else {
394 $ctrl.='<input type="image" name="TABLE[col_end]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_left.gif','').' title="'.$GLOBALS['LANG']->getLL('table_end',1).'" />';
395 }
396 $ctrl.='<input type="image" name="TABLE[col_remove]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/garbage.gif','').' title="'.$GLOBALS['LANG']->getLL('table_removeColumn',1).'" />';
397 if (($a+1)!=$cols) {
398 $ctrl.='<input type="image" name="TABLE[col_right]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/pil2right.gif','').' title="'.$GLOBALS['LANG']->getLL('table_right',1).'" />';
399 } else {
400 $ctrl.='<input type="image" name="TABLE[col_start]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/turn_right.gif','').' title="'.$GLOBALS['LANG']->getLL('table_start',1).'" />';
401 }
402 $ctrl.='<input type="image" name="TABLE[col_add]['.(($a+1)*2).']"'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/add.gif','').' title="'.$GLOBALS['LANG']->getLL('table_addColumn',1).'" />';
403 $cells[]='<span class="c-wizButtonsH">'.$ctrl.'</span>';
404
405 // Incr. counter:
406 $a++;
407 }
408 $tRows[]='
409 <tr class="bgColor5">
410 <td align="center">'.implode('</td>
411 <td align="center">',$cells).'</td>
412 </tr>';
413 }
414
415 $content = '';
416
417 // Implode all table rows into a string, wrapped in table tags.
418 $content.= '
419
420
421 <!--
422 Table wizard
423 -->
424 <table border="0" cellpadding="0" cellspacing="1" id="typo3-tablewizard">
425 '.implode('',$tRows).'
426 </table>';
427
428 // Input type checkbox:
429 $content.= '
430
431 <!--
432 Input mode check box:
433 -->
434 <div id="c-inputMode">
435 '.
436 '<input type="hidden" name="TABLE[textFields]" value="0" />'.
437 '<input type="checkbox" name="TABLE[textFields]" id="textFields" value="1"'.($this->inputStyle?' checked="checked"':'').' /> <label for="textFields">'.
438 $GLOBALS['LANG']->getLL('table_smallFields').'</label>
439 </div>
440
441 <br /><br />
442 ';
443
444 // Return content:
445 return $content;
446 }
447
448 /**
449 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will manipulate the internal TABLECFG array
450 *
451 * @return void
452 * @access private
453 */
454 function changeFunc() {
455 if ($this->TABLECFG['col_remove']) {
456 $kk = key($this->TABLECFG['col_remove']);
457 $cmd='col_remove';
458 } elseif ($this->TABLECFG['col_add']) {
459 $kk = key($this->TABLECFG['col_add']);
460 $cmd='col_add';
461 } elseif ($this->TABLECFG['col_start']) {
462 $kk = key($this->TABLECFG['col_start']);
463 $cmd='col_start';
464 } elseif ($this->TABLECFG['col_end']) {
465 $kk = key($this->TABLECFG['col_end']);
466 $cmd='col_end';
467 } elseif ($this->TABLECFG['col_left']) {
468 $kk = key($this->TABLECFG['col_left']);
469 $cmd='col_left';
470 } elseif ($this->TABLECFG['col_right']) {
471 $kk = key($this->TABLECFG['col_right']);
472 $cmd='col_right';
473 } elseif ($this->TABLECFG['row_remove']) {
474 $kk = key($this->TABLECFG['row_remove']);
475 $cmd='row_remove';
476 } elseif ($this->TABLECFG['row_add']) {
477 $kk = key($this->TABLECFG['row_add']);
478 $cmd='row_add';
479 } elseif ($this->TABLECFG['row_top']) {
480 $kk = key($this->TABLECFG['row_top']);
481 $cmd='row_top';
482 } elseif ($this->TABLECFG['row_bottom']) {
483 $kk = key($this->TABLECFG['row_bottom']);
484 $cmd='row_bottom';
485 } elseif ($this->TABLECFG['row_up']) {
486 $kk = key($this->TABLECFG['row_up']);
487 $cmd='row_up';
488 } elseif ($this->TABLECFG['row_down']) {
489 $kk = key($this->TABLECFG['row_down']);
490 $cmd='row_down';
491 }
492
493 if ($cmd && t3lib_utility_Math::canBeInterpretedAsInteger($kk)) {
494 if (substr($cmd,0,4)=='row_') {
495 switch($cmd) {
496 case 'row_remove':
497 unset($this->TABLECFG['c'][$kk]);
498 break;
499 case 'row_add':
500 for($a=1;$a<=$this->numNewRows;$a++) {
501 if (!isset($this->TABLECFG['c'][$kk+$a])) { // Checking if set: The point is that any new row inbetween existing rows will be TRUE after one row is added while if rows are added in the bottom of the table there will be no existing rows to stop the addition of new rows which means it will add up to $this->numNewRows rows then.
502 $this->TABLECFG['c'][$kk+$a] = array();
503 } else {
504 break;
505 }
506 }
507 break;
508 case 'row_top':
509 $this->TABLECFG['c'][1]=$this->TABLECFG['c'][$kk];
510 unset($this->TABLECFG['c'][$kk]);
511 break;
512 case 'row_bottom':
513 $this->TABLECFG['c'][10000000]=$this->TABLECFG['c'][$kk];
514 unset($this->TABLECFG['c'][$kk]);
515 break;
516 case 'row_up':
517 $this->TABLECFG['c'][$kk-3]=$this->TABLECFG['c'][$kk];
518 unset($this->TABLECFG['c'][$kk]);
519 break;
520 case 'row_down':
521 $this->TABLECFG['c'][$kk+3]=$this->TABLECFG['c'][$kk];
522 unset($this->TABLECFG['c'][$kk]);
523 break;
524 }
525 ksort($this->TABLECFG['c']);
526 }
527 if (substr($cmd,0,4)=='col_') {
528 foreach ($this->TABLECFG['c'] as $cAK => $value) {
529 switch($cmd) {
530 case 'col_remove':
531 unset($this->TABLECFG['c'][$cAK][$kk]);
532 break;
533 case 'col_add':
534 $this->TABLECFG['c'][$cAK][$kk+1]='';
535 break;
536 case 'col_start':
537 $this->TABLECFG['c'][$cAK][1]=$this->TABLECFG['c'][$cAK][$kk];
538 unset($this->TABLECFG['c'][$cAK][$kk]);
539 break;
540 case 'col_end':
541 $this->TABLECFG['c'][$cAK][1000000]=$this->TABLECFG['c'][$cAK][$kk];
542 unset($this->TABLECFG['c'][$cAK][$kk]);
543 break;
544 case 'col_left':
545 $this->TABLECFG['c'][$cAK][$kk-3]=$this->TABLECFG['c'][$cAK][$kk];
546 unset($this->TABLECFG['c'][$cAK][$kk]);
547 break;
548 case 'col_right':
549 $this->TABLECFG['c'][$cAK][$kk+3]=$this->TABLECFG['c'][$cAK][$kk];
550 unset($this->TABLECFG['c'][$cAK][$kk]);
551 break;
552 }
553 ksort($this->TABLECFG['c'][$cAK]);
554 }
555 }
556 }
557
558 // Convert line breaks to <br /> tags:
559 foreach ($this->TABLECFG['c'] as $a => $value) {
560 foreach ($this->TABLECFG['c'][$a] as $b => $value2) {
561 $this->TABLECFG['c'][$a][$b] = str_replace(LF,'<br />',str_replace(CR,'',$this->TABLECFG['c'][$a][$b]));
562 }
563 }
564 }
565
566 /**
567 * Converts the input array to a configuration code string
568 *
569 * @param array Array of table configuration (follows the input structure from the table wizard POST form)
570 * @return string The array converted into a string with line-based configuration.
571 * @see cfgString2CfgArray()
572 */
573 function cfgArray2CfgString($cfgArr) {
574
575 // Initialize:
576 $inLines=array();
577
578 // Traverse the elements of the table wizard and transform the settings into configuration code.
579 foreach ($this->TABLECFG['c'] as $a => $value) {
580 $thisLine=array();
581 foreach ($this->TABLECFG['c'][$a] as $b => $value) {
582 $thisLine[]=$this->tableParsing_quote.str_replace($this->tableParsing_delimiter,'',$this->TABLECFG['c'][$a][$b]).$this->tableParsing_quote;
583 }
584 $inLines[]=implode($this->tableParsing_delimiter,$thisLine);
585 }
586
587 // Finally, implode the lines into a string:
588 $bodyText = implode(LF,$inLines);
589
590 // Return the configuration code:
591 return $bodyText;
592 }
593
594 /**
595 * Converts the input configuration code string into an array
596 *
597 * @param string Configuration code
598 * @param integer Default number of columns
599 * @return array Configuration array
600 * @see cfgArray2CfgString()
601 */
602 function cfgString2CfgArray($cfgStr,$cols) {
603
604 // Explode lines in the configuration code - each line is a table row.
605 $tLines=explode(LF,$cfgStr);
606
607 // Setting number of columns
608 if (!$cols && trim($tLines[0])) { // auto...
609 $cols = count(explode($this->tableParsing_delimiter,$tLines[0]));
610 }
611 $cols=$cols?$cols:4;
612
613 // Traverse the number of table elements:
614 $cfgArr=array();
615 foreach($tLines as $k => $v) {
616
617 // Initialize:
618 $vParts = explode($this->tableParsing_delimiter,$v);
619
620 // Traverse columns:
621 for ($a=0;$a<$cols;$a++) {
622 if ($this->tableParsing_quote && substr($vParts[$a],0,1) == $this->tableParsing_quote && substr($vParts[$a],-1,1) == $this->tableParsing_quote) {
623 $vParts[$a] = substr(trim($vParts[$a]),1,-1);
624 }
625 $cfgArr[$k][$a]=$vParts[$a];
626 }
627 }
628
629 // Return configuration array:
630 return $cfgArr;
631 }
632 }
633
634 // Make instance:
635 $SOBE = t3lib_div::makeInstance('SC_wizard_table');
636 $SOBE->init();
637
638 // Include files?
639 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
640
641 $SOBE->main();
642 $SOBE->printContent();
643
644 ?>