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