Added feature #16396: Implement a Grid View + wizard to enable the backend layout...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / wizard_be_layout.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 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 * Grid wizard
29 *
30 * $Id $
31 */
32
33 require_once('conf.php');
34 require($BACK_PATH . 'init.php');
35 require($BACK_PATH . 'template.php');
36 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
37
38 /**
39 * Script Class for grid wizard
40 *
41 * @author T3UXW09 Team1 <modernbe@cybercraft.de>
42 * @package TYPO3
43 * @subpackage core
44 */
45 class SC_wizard_be_layout {
46
47 // GET vars:
48 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
49
50 /**
51 * document template object
52 *
53 * @var smallDoc
54 */
55 var $doc;
56 var $content; // Accumulated content.
57
58
59 /**
60 * Initialises the Class
61 *
62 * @return void
63 */
64 function init() {
65
66
67 // Setting GET vars (used in frameset script):
68 $this->P = t3lib_div::_GP('P', 1);
69
70 //data[layouts][2][config]
71 $this->formName = $this->P['formName'];
72 $this->fieldName = $this->P['itemName'];
73 $this->md5ID = $this->P['md5ID'];
74 $uid = intval($this->P['uid']);
75
76 // Initialize document object:
77 $this->doc = t3lib_div::makeInstance('noDoc');
78 $this->doc->backPath = $GLOBALS['BACK_PATH'];
79
80 $pageRenderer = $this->doc->getPageRenderer();
81 $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . TYPO3_MOD_PATH . 'res/grideditor.js');
82 $pageRenderer->addJsInlineCode('storeData', '
83 function storeData(data) {
84 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"]) {
85 parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"].value = data;
86 parent.opener.TBE_EDITOR.fieldChanged("be_layouts","' . $uid . '","config","data[be_layouts][' . $uid . '][config]");
87 }
88 }
89 ');
90
91 $languageLabels = array(
92 'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelSave', 1),
93 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_windowTitle', 1),
94 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelName', 1),
95 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelColumn', 1)
96 );
97 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
98
99 // select record
100 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . intval($this->P['uid']));
101 if (trim($record[0][$this->P['field']]) == '') {
102 $t3GridData = "[[{colspan:1,rowspan:1,spanned:false,name:''}]]";
103 $colCount = 1;
104 $rowCount = 1;
105 } else {
106
107 // load TS parser
108 $parser = t3lib_div::makeInstance('t3lib_TSparser');
109 $parser->parse($record[0][$this->P['field']]);
110 $data = $parser->setup['be_layout.'];
111 $t3GridData = '[';
112 $colCount = $data['colCount'];
113 $rowCount = $data['rowCount'];
114 $dataRows = $data['rows.'];
115 $spannedMatrix = array();
116
117 for ($i = 1; $i <= $rowCount; $i++) {
118 $rowString = '';
119 for ($j = 1; $j <= $colCount; $j++) {
120 if ($j == 1) {
121 $row = array_shift($dataRows);
122 $columns = $row['columns.'];
123 $rowString = '[';
124 $cells = array();
125 }
126 if (!$spannedMatrix[$i][$j]) {
127 if (is_array($columns) && count($columns)) {
128 $column = array_shift($columns);
129 $cellString = '{';
130 $cellData = array();
131 if (isset($column['colspan'])) {
132 $cellData[] = 'colspan:' . intval($column['colspan']);
133 if (isset($column['rowspan'])) {
134 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
135 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
136 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
137 }
138 }
139 } else {
140 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
141 $spannedMatrix[$i][$j + $spanColumn] = 1;
142 }
143 }
144 } else {
145 $cellData[] = 'colspan:1';
146 if (isset($column['rowspan'])) {
147 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
148 $spannedMatrix[$i + $spanRow][$j] = 1;
149 }
150 }
151 }
152 if (isset($column['rowspan'])) {
153 $cellData[] = 'rowspan:' . intval($column['rowspan']);
154 } else {
155 $cellData[] = 'rowspan:1';
156 }
157 if (isset($column['name'])) {
158 $cellData[] = 'name:\'' . $column['name'] . '\'';
159 }
160 if (isset($column['colPos'])) {
161 $cellData[] = 'column:' . $column['colPos'];
162 }
163
164 $cellString .= implode(',', $cellData) . '}';
165 $cells[] = $cellString;
166
167 }
168 } else {
169 $cells[] = '{colspan:1,rowspan:1,spanned:1}';
170 }
171 }
172 $rowString .= implode(',', $cells);
173 if ($rowString) {
174 $rowString .= ']';
175 }
176 $rows[] = $rowString;
177 ksort($spannedMatrix[$i]);
178 }
179
180 $t3GridData .= implode(',', $rows) . ']';
181
182
183 }
184
185 $this->doc->JScode .= '
186 <script type="text/javascript">
187 Ext.onReady(function() {
188 t3Grid = new TYPO3.Backend.t3Grid({
189 data: ' . $t3GridData . ',
190 colCount: ' . $colCount . ',
191 rowCount: ' . $rowCount . ',
192 targetElement: \'editor\'
193 });
194
195 t3Grid.drawTable();
196 });
197 </script>
198 ';
199
200
201 $this->doc->styleSheetFile_post = TYPO3_MOD_PATH . 'res/grideditor.css';
202 $this->doc->styleSheetFile2 = 'sysext/t3skin/stylesheets/extjs/xtheme-t3skin.css';
203 }
204
205 /**
206 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
207 *
208 * @return void
209 */
210 function main() {
211
212 $content .= '<a href="#" title="' .
213 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' .
214 t3lib_iconWorks::getSpriteIcon('actions-document-save') . '</a>';
215
216 $content .= '<a href="#" title="' .
217 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">' .
218 t3lib_iconWorks::getSpriteIcon('actions-document-save-close') . '</a>';
219
220 $content .= '<a href="#" title="'.
221 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE) . '" onclick="window.close();return true;">' .
222 t3lib_iconWorks::getSpriteIcon('actions-document-close') . '</a>';
223
224
225 $content .= $this->doc->spacer(10);
226
227 $content .= '
228 <table border="0" width="100%" height="100%" id="outer_container">
229 <tr>
230 <td class="editor_cell">
231 <div id="editor">
232 </div>
233 </td>
234 <td width="20" valign="center">
235 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
236 <img src="res/t3grid-tableright.png" border="0" />
237 </a><br />
238 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
239 <img src="res/t3grid-tableleft.png" border="0" />
240 </a>
241 </td>
242 </tr>
243 <tr>
244 <td colspan="2" height="20" align="center">
245 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
246 <img src="res/t3grid-tabledown.png" border="0" />
247 </a>
248 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
249 <img src="res/t3grid-tableup.png" border="0" />
250 </a>
251 </td>
252 </tr>
253 </table>
254 ';
255
256 $this->content = $content;
257 }
258
259 /**
260 * Returnes the sourcecode to the browser
261 *
262 * @return void
263 */
264 function printContent() {
265 echo $this->doc->render(
266 'Grid wizard',
267 $this->content
268 );
269 }
270
271 }
272
273
274 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php']) {
275 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php']);
276 }
277
278
279 // Make instance:
280 $SOBE = t3lib_div::makeInstance('SC_wizard_be_layout');
281 $SOBE->init();
282 $SOBE->main();
283 $SOBE->printContent();
284
285 ?>
286 <?php
287 /***************************************************************
288 * Copyright notice
289 *
290 * (c) 1999-2009 Kasper Sk?rh?j (kasperYYYY@typo3.com)
291 * All rights reserved
292 *
293 * This script is part of the TYPO3 project. The TYPO3 project is
294 * free software; you can redistribute it and/or modify
295 * it under the terms of the GNU General Public License as published by
296 * the Free Software Foundation; either version 2 of the License, or
297 * (at your option) any later version.
298 *
299 * The GNU General Public License can be found at
300 * http://www.gnu.org/copyleft/gpl.html.
301 * A copy is found in the textfile GPL.txt and important notices to the license
302 * from the author is found in LICENSE.txt distributed with these scripts.
303 *
304 *
305 * This script is distributed in the hope that it will be useful,
306 * but WITHOUT ANY WARRANTY; without even the implied warranty of
307 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
308 * GNU General Public License for more details.
309 *
310 * This copyright notice MUST APPEAR in all copies of the script!
311 ***************************************************************/
312 /**
313 * Grid wizard
314 *
315 * $Id $
316 */
317
318 require_once('conf.php');
319 require($BACK_PATH . 'init.php');
320 require($BACK_PATH . 'template.php');
321 $LANG->includeLLFile('EXT:lang/locallang_wizards.xml');
322
323 /**
324 * Script Class for grid wizard
325 *
326 * @author T3UXW09 Team1 <modernbe@cybercraft.de>
327 * @package TYPO3
328 * @subpackage core
329 */
330 class SC_wizard_be_layout {
331
332 // GET vars:
333 var $P; // Wizard parameters, coming from TCEforms linking to the wizard.
334
335 /**
336 * document template object
337 *
338 * @var smallDoc
339 */
340 var $doc;
341 var $content; // Accumulated content.
342
343
344 /**
345 * Initialises the Class
346 *
347 * @return void
348 */
349 function init() {
350
351
352 // Setting GET vars (used in frameset script):
353 $this->P = t3lib_div::_GP('P', 1);
354
355 //data[layouts][2][config]
356 $this->formName = $this->P['formName'];
357 $this->fieldName = $this->P['itemName'];
358 $this->md5ID = $this->P['md5ID'];
359
360 // Initialize document object:
361 $this->doc = t3lib_div::makeInstance('noDoc');
362 $this->doc->backPath = $GLOBALS['BACK_PATH'];
363
364 $pageRenderer = $this->doc->getPageRenderer();
365 $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . TYPO3_MOD_PATH . 'res/grideditor.js');
366 $pageRenderer->addJsInlineCode('storeData', '
367 function storeData(data) {
368 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"]) {
369 parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"].value = data;
370 }
371 }
372 ');
373
374 $languageLabels = array(
375 'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelSave', 1),
376 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_windowTitle', 1),
377 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelName', 1),
378 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelColumn', 1)
379 );
380 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
381
382 // select record
383 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . intval($this->P['uid']));
384 if (trim($record[0][$this->P['field']]) == '') {
385 $t3GridData = "[[{colspan:1,rowspan:1,spanned:false,name:''}]]";
386 $colCount = 1;
387 $rowCount = 1;
388 } else {
389
390 // load TS parser
391 $parser = t3lib_div::makeInstance('t3lib_TSparser');
392 $parser->parse($record[0][$this->P['field']]);
393 $data = $parser->setup['be_layout.'];
394 $t3GridData = '[';
395 $colCount = $data['colCount'];
396 $rowCount = $data['rowCount'];
397 $dataRows = $data['rows.'];
398 $spannedMatrix = array();
399
400 for ($i = 1; $i <= $rowCount; $i++) {
401 $rowString = '';
402 for ($j = 1; $j <= $colCount; $j++) {
403 if ($j == 1) {
404 $row = array_shift($dataRows);
405 $columns = $row['columns.'];
406 $rowString = '[';
407 $cells = array();
408 }
409 if (!$spannedMatrix[$i][$j]) {
410 if (is_array($columns) && count($columns)) {
411 $column = array_shift($columns);
412 $cellString = '{';
413 $cellData = array();
414 if (isset($column['colspan'])) {
415 $cellData[] = 'colspan:' . intval($column['colspan']);
416 if (isset($column['rowspan'])) {
417 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
418 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
419 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
420 }
421 }
422 } else {
423 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
424 $spannedMatrix[$i][$j + $spanColumn] = 1;
425 }
426 }
427 } else {
428 $cellData[] = 'colspan:1';
429 if (isset($column['rowspan'])) {
430 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
431 $spannedMatrix[$i + $spanRow][$j] = 1;
432 }
433 }
434 }
435 if (isset($column['rowspan'])) {
436 $cellData[] = 'rowspan:' . intval($column['rowspan']);
437 } else {
438 $cellData[] = 'rowspan:1';
439 }
440 if (isset($column['name'])) {
441 $cellData[] = 'name:\'' . $column['name'] . '\'';
442 }
443 if (isset($column['colPos'])) {
444 $cellData[] = 'column:' . $column['colPos'];
445 }
446
447 $cellString .= implode(',', $cellData) . '}';
448 $cells[] = $cellString;
449
450 }
451 } else {
452 $cells[] = '{colspan:1,rowspan:1,spanned:1}';
453 }
454 }
455 $rowString .= implode(',', $cells);
456 if ($rowString) {
457 $rowString .= ']';
458 }
459 $rows[] = $rowString;
460 ksort($spannedMatrix[$i]);
461 }
462
463 $t3GridData .= implode(',', $rows) . ']';
464
465
466 }
467
468 $this->doc->JScode .= '
469 <script type="text/javascript">
470 Ext.onReady(function() {
471 t3Grid = new TYPO3.Backend.t3Grid({
472 data: ' . $t3GridData . ',
473 colCount: ' . $colCount . ',
474 rowCount: ' . $rowCount . ',
475 targetElement: \'editor\'
476 });
477
478 t3Grid.drawTable();
479 });
480 </script>
481 ';
482
483
484 $this->doc->styleSheetFile_post = TYPO3_MOD_PATH . 'res/grideditor.css';
485 $this->doc->styleSheetFile2 = 'sysext/t3skin/stylesheets/extjs/xtheme-t3skin.css';
486 }
487
488 /**
489 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
490 *
491 * @return void
492 */
493 function main() {
494
495 $content .= '<a href="#" title="' .
496 $GLOBALS['LANG']->mainLang['rm']['saveDoc'] . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' .
497 t3lib_iconWorks::getSpriteIcon('actions-document-save') . '</a>';
498
499 $content .= '<a href="#" title="' .
500 $GLOBALS['LANG']->mainLang['rm']['saveCloseDoc'] . '" onclick="storeData(t3Grid.export2LayoutRecord());;return true;">' .
501 t3lib_iconWorks::getSpriteIcon('actions-document-save-close') . '</a>';
502
503 $content .= '<a href="#"' .
504 ' onclick="window.close();return true;">' .
505 t3lib_iconWorks::getSpriteIcon('actions-document-close') . '</a>';
506
507
508 $content .= $this->doc->spacer(10);
509
510 $content .= '
511 <table border="0" width="100%" height="100%" id="outer_container">
512 <tr>
513 <td class="editor_cell">
514 <div id="editor">
515 </div>
516 </td>
517 <td width="20" valign="center">
518 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
519 <img src="res/t3grid-tableright.png" border="0" />
520 </a><br />
521 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
522 <img src="res/t3grid-tableleft.png" border="0" />
523 </a>
524 </td>
525 </tr>
526 <tr>
527 <td colspan="2" height="20" align="center">
528 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
529 <img src="res/t3grid-tabledown.png" border="0" />
530 </a>
531 <a id="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
532 <img src="res/t3grid-tableup.png" border="0" />
533 </a>
534 </td>
535 </tr>
536 </table>
537 ';
538
539 $this->content = $content;
540 }
541
542 /**
543 * Returnes the sourcecode to the browser
544 *
545 * @return void
546 */
547 function printContent() {
548 echo $this->doc->render(
549 'Grid wizard',
550 $this->content
551 );
552 }
553
554 }
555
556
557 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php']) {
558 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php']);
559 }
560
561
562 // Make instance:
563 $SOBE = t3lib_div::makeInstance('SC_wizard_be_layout');
564 $SOBE->init();
565 $SOBE->main();
566 $SOBE->printContent();
567
568 ?>