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