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