[FOLLOWUP][TASK] Make TYPO3 Core PSR-2 standard compliant
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / Wizard / TableController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller\Wizard;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use Psr\Http\Message\ServerRequestInterface;
18 use Psr\Http\Message\ResponseInterface;
19 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
21 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
22 use TYPO3\CMS\Core\DataHandling\DataHandler;
23 use TYPO3\CMS\Core\Imaging\Icon;
24 use TYPO3\CMS\Core\Imaging\IconFactory;
25 use TYPO3\CMS\Core\Utility\GeneralUtility;
26 use TYPO3\CMS\Core\Utility\HttpUtility;
27 use TYPO3\CMS\Core\Utility\MathUtility;
28 use TYPO3\CMS\Core\Utility\StringUtility;
29
30 /**
31 * Script Class for rendering the Table Wizard
32 */
33 class TableController extends AbstractWizardController
34 {
35 /**
36 * Content accumulation for the module.
37 *
38 * @var string
39 */
40 public $content;
41
42 /**
43 * If TRUE, <input> fields are shown instead of textareas.
44 *
45 * @var bool
46 */
47 public $inputStyle = false;
48
49 /**
50 * If set, the string version of the content is interpreted/written as XML
51 * instead of the original line-based kind. This variable still needs binding
52 * to the wizard parameters - but support is ready!
53 *
54 * @var int
55 */
56 public $xmlStorage = 0;
57
58 /**
59 * Number of new rows to add in bottom of wizard
60 *
61 * @var int
62 */
63 public $numNewRows = 1;
64
65 /**
66 * Name of field in parent record which MAY contain the number of columns for the table
67 * here hardcoded to the value of tt_content. Should be set by FormEngine parameters (from P)
68 *
69 * @var string
70 */
71 public $colsFieldName = 'cols';
72
73 /**
74 * Wizard parameters, coming from FormEngine linking to the wizard.
75 *
76 * @var array
77 */
78 public $P;
79
80 /**
81 * The array which is constantly submitted by the multidimensional form of this wizard.
82 *
83 * @var array
84 */
85 public $TABLECFG;
86
87 /**
88 * Table parsing
89 * quoting of table cells
90 *
91 * @var string
92 */
93 public $tableParsing_quote;
94
95 /**
96 * delimiter between table cells
97 *
98 * @var string
99 */
100 public $tableParsing_delimiter;
101
102 /**
103 * @var IconFactory
104 */
105 protected $iconFactory;
106
107 /**
108 * Constructor
109 */
110 public function __construct()
111 {
112 parent::__construct();
113 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_wizards.xlf');
114 $GLOBALS['SOBE'] = $this;
115
116 $this->init();
117 }
118
119 /**
120 * Initialization of the class
121 *
122 * @return void
123 */
124 protected function init()
125 {
126 // GPvars:
127 $this->P = GeneralUtility::_GP('P');
128 $this->TABLECFG = GeneralUtility::_GP('TABLE');
129 // Setting options:
130 $this->xmlStorage = $this->P['params']['xmlOutput'];
131 $this->numNewRows = MathUtility::forceIntegerInRange($this->P['params']['numNewRows'], 1, 50, 5);
132 // Textareas or input fields:
133 $this->inputStyle = isset($this->TABLECFG['textFields']) ? (bool)$this->TABLECFG['textFields'] : true;
134 // Setting form tag:
135 list($rUri) = explode('#', GeneralUtility::getIndpEnv('REQUEST_URI'));
136 $this->moduleTemplate->setForm(
137 '<form action="' . htmlspecialchars($rUri) . '" method="post" name="wizardForm">'
138 );
139 $this->tableParsing_delimiter = '|';
140 $this->tableParsing_quote = '';
141 }
142
143 /**
144 * Injects the request object for the current request or subrequest
145 * As this controller goes only through the main() method, it is rather simple for now
146 *
147 * @param ServerRequestInterface $request
148 * @param ResponseInterface $response
149 * @return ResponseInterface
150 */
151 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
152 {
153 $this->main();
154 $response->getBody()->write($this->moduleTemplate->renderContent());
155 return $response;
156 }
157
158 /**
159 * Main function, rendering the table wizard
160 *
161 * @return void
162 */
163 public function main()
164 {
165 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
166 $this->content .= $this->moduleTemplate->section(
167 $this->getLanguageService()->getLL('table_title'),
168 $this->tableWizard(),
169 0,
170 1
171 );
172 } else {
173 $this->content .= $this->moduleTemplate->section(
174 $this->getLanguageService()->getLL('table_title'),
175 '<span class="text-danger">' . $this->getLanguageService()->getLL('table_noData', true) . '</span>',
176 0,
177 1
178 );
179 }
180 // Setting up the buttons and markers for docHeader
181 $this->getButtons();
182 // Build the <body> for the module
183 $this->moduleTemplate->setContent($this->content);
184 }
185
186 /**
187 * Outputting the accumulated content to screen
188 *
189 * @return void
190 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use mainAction() instead
191 */
192 public function printContent()
193 {
194 GeneralUtility::logDeprecatedFunction();
195 echo $this->content;
196 }
197
198 /**
199 * Create the panel of buttons for submitting the form or otherwise perform operations.
200 */
201 protected function getButtons()
202 {
203 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
204 if ($this->P['table'] && $this->P['field'] && $this->P['uid']) {
205 // CSH
206 $cshButton = $buttonBar->makeHelpButton()
207 ->setModuleName('xMOD_csh_corebe')
208 ->setFieldName('wizard_table_wiz');
209 $buttonBar->addButton($cshButton);
210 // Close
211 $closeButton = $buttonBar->makeLinkButton()
212 ->setHref($this->P['returnUrl'])
213 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', true))
214 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-close', Icon::SIZE_SMALL));
215 $buttonBar->addButton($closeButton);
216 // Save
217 $saveButton = $buttonBar->makeInputButton()
218 ->setName('_savedok')
219 ->setValue('1')
220 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-document-save', Icon::SIZE_SMALL))
221 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', true));
222 // Save & Close
223 $saveAndCloseButton = $buttonBar->makeInputButton()
224 ->setName('_saveandclosedok')
225 ->setValue('1')
226 ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', true))
227 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
228 'actions-document-save-close',
229 Icon::SIZE_SMALL
230 ));
231 $splitButtonElement = $buttonBar->makeSplitButton()
232 ->addItem($saveButton)
233 ->addItem($saveAndCloseButton);
234
235 $buttonBar->addButton($splitButtonElement, ButtonBar::BUTTON_POSITION_LEFT, 3);
236 // Reload
237 $reloadButton = $buttonBar->makeInputButton()
238 ->setName('_refresh')
239 ->setValue('1')
240 ->setTitle($this->getLanguageService()->getLL('forms_refresh', true))
241 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-refresh', Icon::SIZE_SMALL));
242 $buttonBar->addButton($reloadButton);
243 }
244 }
245
246 /**
247 * Draws the table wizard content
248 *
249 * @return string HTML content for the form.
250 * @throws \RuntimeException
251 */
252 public function tableWizard()
253 {
254 if (!$this->checkEditAccess($this->P['table'], $this->P['uid'])) {
255 throw new \RuntimeException('Wizard Error: No access', 1349692692);
256 }
257 // First, check the references by selecting the record:
258 $row = BackendUtility::getRecord($this->P['table'], $this->P['uid']);
259 if (!is_array($row)) {
260 throw new \RuntimeException('Wizard Error: No reference to record', 1294587125);
261 }
262 // This will get the content of the form configuration code field to us - possibly cleaned up,
263 // saved to database etc. if the form has been submitted in the meantime.
264 $tableCfgArray = $this->getConfigCode($row);
265 // Generation of the Table Wizards HTML code:
266 $content = $this->getTableHTML($tableCfgArray);
267 // Return content:
268 return $content;
269 }
270
271 /*
272 *
273 * Helper functions
274 *
275 */
276
277 /**
278 * Will get and return the configuration code string
279 * Will also save (and possibly redirect/exit) the content if a save button has been pressed
280 *
281 * @param array $row Current parent record row
282 * @return array Table config code in an array
283 * @internal
284 */
285 public function getConfigCode($row)
286 {
287 // Get delimiter settings
288 $flexForm = GeneralUtility::xml2array($row['pi_flexform']);
289 if (is_array($flexForm)) {
290 $this->tableParsing_quote = $flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF'] ? chr((int)$flexForm['data']['s_parsing']['lDEF']['tableparsing_quote']['vDEF']) : '';
291 $this->tableParsing_delimiter = $flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF'] ? chr((int)$flexForm['data']['s_parsing']['lDEF']['tableparsing_delimiter']['vDEF']) : '|';
292 }
293 // If some data has been submitted, then construct
294 if (isset($this->TABLECFG['c'])) {
295 // Process incoming:
296 $this->changeFunc();
297 // Convert to string (either line based or XML):
298 if ($this->xmlStorage) {
299 // Convert the input array to XML:
300 $bodyText = GeneralUtility::array2xml_cs($this->TABLECFG['c'], 'T3TableWizard');
301 // Setting cfgArr directly from the input:
302 $configuration = $this->TABLECFG['c'];
303 } else {
304 // Convert the input array to a string of configuration code:
305 $bodyText = $this->cfgArray2CfgString($this->TABLECFG['c']);
306 // Create cfgArr from the string based configuration - that way it is cleaned up
307 // and any incompatibilities will be removed!
308 $configuration = $this->cfgString2CfgArray($bodyText, $row[$this->colsFieldName]);
309 }
310 // If a save button has been pressed, then save the new field content:
311 if ($_POST['_savedok'] || $_POST['_saveandclosedok']) {
312 // Get DataHandler object:
313 /** @var DataHandler $dataHandler */
314 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
315 $dataHandler->stripslashes_values = false;
316 // Put content into the data array:
317 $data = array();
318 if ($this->P['flexFormPath']) {
319 // Current value of flexForm path:
320 $currentFlexFormData = GeneralUtility::xml2array($row[$this->P['field']]);
321 /** @var FlexFormTools $flexFormTools */
322 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
323 $flexFormTools->setArrayValueByPath($this->P['flexFormPath'], $currentFlexFormData, $bodyText);
324 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $currentFlexFormData;
325 } else {
326 $data[$this->P['table']][$this->P['uid']][$this->P['field']] = $bodyText;
327 }
328 // Perform the update:
329 $dataHandler->start($data, array());
330 $dataHandler->process_datamap();
331 // If the save/close button was pressed, then redirect the screen:
332 if ($_POST['_saveandclosedok']) {
333 HttpUtility::redirect(GeneralUtility::sanitizeLocalUrl($this->P['returnUrl']));
334 }
335 }
336 } else {
337 // If nothing has been submitted, load the $bodyText variable from the selected database row:
338 if ($this->xmlStorage) {
339 $configuration = GeneralUtility::xml2array($row[$this->P['field']]);
340 } else {
341 if ($this->P['flexFormPath']) {
342 // Current value of flexForm path:
343 $currentFlexFormData = GeneralUtility::xml2array($row[$this->P['field']]);
344 /** @var FlexFormTools $flexFormTools */
345 $flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
346 $configuration = $flexFormTools->getArrayValueByPath(
347 $this->P['flexFormPath'],
348 $currentFlexFormData
349 );
350 $configuration = $this->cfgString2CfgArray($configuration, 0);
351 } else {
352 // Regular line based table configuration:
353 $configuration = $this->cfgString2CfgArray($row[$this->P['field']], $row[$this->colsFieldName]);
354 }
355 }
356 $configuration = is_array($configuration) ? $configuration : array();
357 }
358 return $configuration;
359 }
360
361 /**
362 * Creates the HTML for the Table Wizard:
363 *
364 * @param array $configuration Table config array
365 * @return string HTML for the table wizard
366 * @internal
367 */
368 public function getTableHTML($configuration)
369 {
370 // Traverse the rows:
371 $tRows = array();
372 $k = 0;
373 $countLines = count($configuration);
374 foreach ($configuration as $cellArr) {
375 if (is_array($cellArr)) {
376 // Initialize:
377 $cells = array();
378 $a = 0;
379 // Traverse the columns:
380 foreach ($cellArr as $cellContent) {
381 if ($this->inputStyle) {
382 $cells[] = '<input class="form-control" type="text" name="TABLE[c][' . ($k + 1) * 2 . '][' . ($a + 1) * 2 . ']" value="' . htmlspecialchars($cellContent) . '" />';
383 } else {
384 $cellContent = preg_replace('/<br[ ]?[\\/]?>/i', LF, $cellContent);
385 $cells[] = '<textarea class="form-control" rows="6" name="TABLE[c][' . ($k + 1) * 2 . '][' . ($a + 1) * 2 . ']">' . htmlspecialchars($cellContent) . '</textarea>';
386 }
387 // Increment counter:
388 $a++;
389 }
390 // CTRL panel for a table row (move up/down/around):
391 $onClick = 'document.wizardForm.action+=' . GeneralUtility::quoteJSvalue('#ANC_' . (($k + 1) * 2 - 2)) . ';';
392 $onClick = ' onclick="' . htmlspecialchars($onClick) . '"';
393 $ctrl = '';
394 if ($k !== 0) {
395 $ctrl .= '<button class="btn btn-default" name="TABLE[row_up][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_up', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-up"></span></button>';
396 } else {
397 $ctrl .= '<button class="btn btn-default" name="TABLE[row_bottom][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_bottom', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-double-down"></span></button>';
398 }
399 if ($k + 1 !== $countLines) {
400 $ctrl .= '<button class="btn btn-default" name="TABLE[row_down][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_down', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-down"></span></button>';
401 } else {
402 $ctrl .= '<button class="btn btn-default" name="TABLE[row_top][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_top', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-angle-double-up"></span></button>';
403 }
404 $ctrl .= '<button class="btn btn-default" name="TABLE[row_remove][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_removeRow', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-trash"></span></button>';
405 $ctrl .= '<button class="btn btn-default" name="TABLE[row_add][' . ($k + 1) * 2 . ']" title="' . $this->getLanguageService()->getLL('table_addRow', true) . '"' . $onClick . '><span class="t3-icon fa fa-fw fa-plus"></span></button>';
406 $tRows[] = '
407 <tr>
408 <td>
409 <a name="ANC_' . ($k + 1) * 2 . '"></a>
410 <span class="btn-group' . ($this->inputStyle ? '' : '-vertical') . '">' . $ctrl . '</span>
411 </td>
412 <td>' . implode('</td>
413 <td>', $cells) . '</td>
414 </tr>';
415 // Increment counter:
416 $k++;
417 }
418 }
419 // CTRL panel for a table column (move left/right/around/delete)
420 $cells = array();
421 $cells[] = '';
422 // Finding first row:
423 $firstRow = reset($configuration);
424 if (is_array($firstRow)) {
425 $cols = count($firstRow);
426 for ($a = 1; $a <= $cols; $a++) {
427 $b = $a * 2;
428 $ctrl = '';
429 if ($a !== 1) {
430 $ctrl .= '<button class="btn btn-default" name="TABLE[col_left][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_left', true) . '"><span class="t3-icon fa fa-fw fa-angle-left"></span></button>';
431 } else {
432 $ctrl .= '<button class="btn btn-default" name="TABLE[col_end][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_end', true) . '"><span class="t3-icon fa fa-fw fa-angle-double-right"></span></button>';
433 }
434 if ($a != $cols) {
435 $ctrl .= '<button class="btn btn-default" name="TABLE[col_right][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_right', true) . '"><span class="t3-icon fa fa-fw fa-angle-right"></span></button>';
436 } else {
437 $ctrl .= '<button class="btn btn-default" name="TABLE[col_start][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_start', true) . '"><span class="t3-icon fa fa-fw fa-angle-double-left"></span></button>';
438 }
439 $ctrl .= '<button class="btn btn-default" name="TABLE[col_remove][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_removeColumn', true) . '"><span class="t3-icon fa fa-fw fa-trash"></span></button>';
440 $ctrl .= '<button class="btn btn-default" name="TABLE[col_add][' . $b . ']" title="' . $this->getLanguageService()->getLL('table_addColumn', true) . '"><span class="t3-icon fa fa-fw fa-plus"></span></button>';
441 $cells[] = '<span class="btn-group">' . $ctrl . '</span>';
442 }
443 $tRows[] = '
444 <tfoot>
445 <tr>
446 <td>' . implode('</td>
447 <td>', $cells) . '</td>
448 </tr>
449 </tfoot>';
450 }
451 $content = '';
452 // Implode all table rows into a string, wrapped in table tags.
453 $content .= '
454
455 <!-- Table wizard -->
456 <div class="table-fit table-fit-inline-block">
457 <table id="typo3-tablewizard" class="table table-center">
458 ' . implode('', $tRows) . '
459 </table>
460 </div>';
461 // Input type checkbox:
462 $content .= '
463
464 <!-- Input mode check box: -->
465 <div class="checkbox">
466 <input type="hidden" name="TABLE[textFields]" value="0" />
467 <label for="textFields">
468 <input type="checkbox" name="TABLE[textFields]" id="textFields" value="1"' . ($this->inputStyle ? ' checked="checked"' : '') . ' />
469 ' . $this->getLanguageService()->getLL('table_smallFields') . '
470 </label>
471 </div>';
472 return $content;
473 }
474
475 /**
476 * Detects if a control button (up/down/around/delete) has been pressed for an item and accordingly it will
477 * manipulate the internal TABLECFG array
478 *
479 * @return void
480 * @internal
481 */
482 public function changeFunc()
483 {
484 if ($this->TABLECFG['col_remove']) {
485 $kk = key($this->TABLECFG['col_remove']);
486 $cmd = 'col_remove';
487 } elseif ($this->TABLECFG['col_add']) {
488 $kk = key($this->TABLECFG['col_add']);
489 $cmd = 'col_add';
490 } elseif ($this->TABLECFG['col_start']) {
491 $kk = key($this->TABLECFG['col_start']);
492 $cmd = 'col_start';
493 } elseif ($this->TABLECFG['col_end']) {
494 $kk = key($this->TABLECFG['col_end']);
495 $cmd = 'col_end';
496 } elseif ($this->TABLECFG['col_left']) {
497 $kk = key($this->TABLECFG['col_left']);
498 $cmd = 'col_left';
499 } elseif ($this->TABLECFG['col_right']) {
500 $kk = key($this->TABLECFG['col_right']);
501 $cmd = 'col_right';
502 } elseif ($this->TABLECFG['row_remove']) {
503 $kk = key($this->TABLECFG['row_remove']);
504 $cmd = 'row_remove';
505 } elseif ($this->TABLECFG['row_add']) {
506 $kk = key($this->TABLECFG['row_add']);
507 $cmd = 'row_add';
508 } elseif ($this->TABLECFG['row_top']) {
509 $kk = key($this->TABLECFG['row_top']);
510 $cmd = 'row_top';
511 } elseif ($this->TABLECFG['row_bottom']) {
512 $kk = key($this->TABLECFG['row_bottom']);
513 $cmd = 'row_bottom';
514 } elseif ($this->TABLECFG['row_up']) {
515 $kk = key($this->TABLECFG['row_up']);
516 $cmd = 'row_up';
517 } elseif ($this->TABLECFG['row_down']) {
518 $kk = key($this->TABLECFG['row_down']);
519 $cmd = 'row_down';
520 } else {
521 $kk = '';
522 $cmd = '';
523 }
524 if ($cmd && MathUtility::canBeInterpretedAsInteger($kk)) {
525 if (StringUtility::beginsWith($cmd, 'row_')) {
526 switch ($cmd) {
527 case 'row_remove':
528 unset($this->TABLECFG['c'][$kk]);
529 break;
530 case 'row_add':
531 for ($a = 1; $a <= $this->numNewRows; $a++) {
532 // Checking if set: The point is that any new row between existing rows
533 // will be TRUE after one row is added while if rows are added in the bottom
534 // of the table there will be no existing rows to stop the addition of new rows
535 // which means it will add up to $this->numNewRows rows then.
536 if (!isset($this->TABLECFG['c'][($kk + $a)])) {
537 $this->TABLECFG['c'][$kk + $a] = array();
538 } else {
539 break;
540 }
541 }
542 break;
543 case 'row_top':
544 $this->TABLECFG['c'][1] = $this->TABLECFG['c'][$kk];
545 unset($this->TABLECFG['c'][$kk]);
546 break;
547 case 'row_bottom':
548 $this->TABLECFG['c'][10000000] = $this->TABLECFG['c'][$kk];
549 unset($this->TABLECFG['c'][$kk]);
550 break;
551 case 'row_up':
552 $this->TABLECFG['c'][$kk - 3] = $this->TABLECFG['c'][$kk];
553 unset($this->TABLECFG['c'][$kk]);
554 break;
555 case 'row_down':
556 $this->TABLECFG['c'][$kk + 3] = $this->TABLECFG['c'][$kk];
557 unset($this->TABLECFG['c'][$kk]);
558 break;
559 }
560 ksort($this->TABLECFG['c']);
561 }
562 if (StringUtility::beginsWith($cmd, 'col_')) {
563 foreach ($this->TABLECFG['c'] as $cAK => $value) {
564 switch ($cmd) {
565 case 'col_remove':
566 unset($this->TABLECFG['c'][$cAK][$kk]);
567 break;
568 case 'col_add':
569 $this->TABLECFG['c'][$cAK][$kk + 1] = '';
570 break;
571 case 'col_start':
572 $this->TABLECFG['c'][$cAK][1] = $this->TABLECFG['c'][$cAK][$kk];
573 unset($this->TABLECFG['c'][$cAK][$kk]);
574 break;
575 case 'col_end':
576 $this->TABLECFG['c'][$cAK][1000000] = $this->TABLECFG['c'][$cAK][$kk];
577 unset($this->TABLECFG['c'][$cAK][$kk]);
578 break;
579 case 'col_left':
580 $this->TABLECFG['c'][$cAK][$kk - 3] = $this->TABLECFG['c'][$cAK][$kk];
581 unset($this->TABLECFG['c'][$cAK][$kk]);
582 break;
583 case 'col_right':
584 $this->TABLECFG['c'][$cAK][$kk + 3] = $this->TABLECFG['c'][$cAK][$kk];
585 unset($this->TABLECFG['c'][$cAK][$kk]);
586 break;
587 }
588 ksort($this->TABLECFG['c'][$cAK]);
589 }
590 }
591 }
592 // Convert line breaks to <br /> tags:
593 foreach ($this->TABLECFG['c'] as $a => $value) {
594 foreach ($this->TABLECFG['c'][$a] as $b => $value2) {
595 $this->TABLECFG['c'][$a][$b] = str_replace(
596 LF,
597 '<br />',
598 str_replace(CR, '', $this->TABLECFG['c'][$a][$b])
599 );
600 }
601 }
602 }
603
604 /**
605 * Converts the input array to a configuration code string
606 *
607 * @param array $cfgArr Array of table configuration (follows the input structure from the table wizard POST form)
608 * @return string The array converted into a string with line-based configuration.
609 * @see cfgString2CfgArray()
610 */
611 public function cfgArray2CfgString($cfgArr)
612 {
613 $inLines = array();
614 // Traverse the elements of the table wizard and transform the settings into configuration code.
615 foreach ($cfgArr as $valueA) {
616 $thisLine = array();
617 foreach ($valueA as $valueB) {
618 $thisLine[] = $this->tableParsing_quote
619 . str_replace($this->tableParsing_delimiter, '', $valueB) . $this->tableParsing_quote;
620 }
621 $inLines[] = implode($this->tableParsing_delimiter, $thisLine);
622 }
623 // Finally, implode the lines into a string:
624 return implode(LF, $inLines);
625 }
626
627 /**
628 * Converts the input configuration code string into an array
629 *
630 * @param string $configurationCode Configuration code
631 * @param int $columns Default number of columns
632 * @return array Configuration array
633 * @see cfgArray2CfgString()
634 */
635 public function cfgString2CfgArray($configurationCode, $columns)
636 {
637 // Explode lines in the configuration code - each line is a table row.
638 $tableLines = explode(LF, $configurationCode);
639 // Setting number of columns
640 // auto...
641 if (!$columns && trim($tableLines[0])) {
642 $columns = count(explode($this->tableParsing_delimiter, $tableLines[0]));
643 }
644 $columns = $columns ?: 4;
645 // Traverse the number of table elements:
646 $configurationArray = array();
647 foreach ($tableLines as $key => $value) {
648 // Initialize:
649 $valueParts = explode($this->tableParsing_delimiter, $value);
650 // Traverse columns:
651 for ($a = 0; $a < $columns; $a++) {
652 if ($this->tableParsing_quote
653 && $valueParts[$a][0] === $this->tableParsing_quote
654 && substr($valueParts[$a], -1, 1) === $this->tableParsing_quote
655 ) {
656 $valueParts[$a] = substr(trim($valueParts[$a]), 1, -1);
657 }
658 $configurationArray[$key][$a] = $valueParts[$a];
659 }
660 }
661 return $configurationArray;
662 }
663 }