Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / wizard_be_layout.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 * 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 'editCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_editCell', 1),
97 'mergeCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_mergeCell', 1),
98 'splitCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_splitCell', 1),
99 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_name', 1),
100 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_column', 1),
101 'notSet' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_notSet', 1),
102 'nameHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_nameHelp', 1),
103 'columnHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_columnHelp', 1),
104 );
105 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
106
107 // select record
108 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . intval($this->P['uid']));
109 if (trim($record[0][$this->P['field']]) == '') {
110 $t3GridData = "[[{colspan:1,rowspan:1,spanned:false,name:''}]]";
111 $colCount = 1;
112 $rowCount = 1;
113 } else {
114
115 // load TS parser
116 $parser = t3lib_div::makeInstance('t3lib_TSparser');
117 $parser->parse($record[0][$this->P['field']]);
118 $data = $parser->setup['be_layout.'];
119 $t3GridData = '[';
120 $colCount = $data['colCount'];
121 $rowCount = $data['rowCount'];
122 $dataRows = $data['rows.'];
123 $spannedMatrix = array();
124
125 for ($i = 1; $i <= $rowCount; $i++) {
126 $rowString = '';
127 for ($j = 1; $j <= $colCount; $j++) {
128 if ($j == 1) {
129 $row = array_shift($dataRows);
130 $columns = $row['columns.'];
131 $rowString = '[';
132 $cells = array();
133 }
134 if (!$spannedMatrix[$i][$j]) {
135 if (is_array($columns) && count($columns)) {
136 $column = array_shift($columns);
137 $cellString = '{';
138 $cellData = array();
139 if (isset($column['colspan'])) {
140 $cellData[] = 'colspan:' . intval($column['colspan']);
141 if (isset($column['rowspan'])) {
142 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
143 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
144 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
145 }
146 }
147 } else {
148 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
149 $spannedMatrix[$i][$j + $spanColumn] = 1;
150 }
151 }
152 } else {
153 $cellData[] = 'colspan:1';
154 if (isset($column['rowspan'])) {
155 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
156 $spannedMatrix[$i + $spanRow][$j] = 1;
157 }
158 }
159 }
160 if (isset($column['rowspan'])) {
161 $cellData[] = 'rowspan:' . intval($column['rowspan']);
162 } else {
163 $cellData[] = 'rowspan:1';
164 }
165 if (isset($column['name'])) {
166 $cellData[] = 'name:\'' . $column['name'] . '\'';
167 }
168 if (isset($column['colPos'])) {
169 $cellData[] = 'column:' . $column['colPos'];
170 }
171
172 $cellString .= implode(',', $cellData) . '}';
173 $cells[] = $cellString;
174
175 }
176 } else {
177 $cells[] = '{colspan:1,rowspan:1,spanned:1}';
178 }
179 }
180 $rowString .= implode(',', $cells);
181 if ($rowString) {
182 $rowString .= ']';
183 }
184 $rows[] = $rowString;
185 ksort($spannedMatrix[$i]);
186 }
187
188 $t3GridData .= implode(',', $rows) . ']';
189
190
191 }
192
193 $pageRenderer->enableExtJSQuickTips();
194
195 $pageRenderer->addExtOnReadyCode('
196 t3Grid = new TYPO3.Backend.t3Grid({
197 data: ' . $t3GridData . ',
198 colCount: ' . $colCount . ',
199 rowCount: ' . $rowCount . ',
200 targetElement: \'editor\'
201 });
202 t3Grid.drawTable();
203 ');
204
205
206 $this->doc->styleSheetFile_post = TYPO3_MOD_PATH . 'res/grideditor.css';
207 $this->doc->styleSheetFile2 = 'sysext/t3skin/stylesheets/extjs/xtheme-t3skin.css';
208 }
209
210 /**
211 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
212 *
213 * @return void
214 */
215 function main() {
216
217 $content .= '<a href="#" title="' .
218 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' .
219 t3lib_iconWorks::getSpriteIcon('actions-document-save') . '</a>';
220
221 $content .= '<a href="#" title="' .
222 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">' .
223 t3lib_iconWorks::getSpriteIcon('actions-document-save-close') . '</a>';
224
225 $content .= '<a href="#" title="'.
226 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE) . '" onclick="window.close();return true;">' .
227 t3lib_iconWorks::getSpriteIcon('actions-document-close') . '</a>';
228
229
230 $content .= $this->doc->spacer(10);
231
232 $content .= '
233 <table border="0" width="100%" height="100%" id="outer_container">
234 <tr>
235 <td class="editor_cell">
236 <div id="editor">
237 </div>
238 </td>
239 <td width="20" valign="center">
240 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
241 <img src="res/t3grid-tableright.png" border="0" />
242 </a><br />
243 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
244 <img src="res/t3grid-tableleft.png" border="0" />
245 </a>
246 </td>
247 </tr>
248 <tr>
249 <td colspan="2" height="20" align="center">
250 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
251 <img src="res/t3grid-tabledown.png" border="0" />
252 </a>
253 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
254 <img src="res/t3grid-tableup.png" border="0" />
255 </a>
256 </td>
257 </tr>
258 </table>
259 ';
260
261 $this->content = $content;
262 }
263
264 /**
265 * Returnes the sourcecode to the browser
266 *
267 * @return void
268 */
269 function printContent() {
270 echo $this->doc->render(
271 'Grid wizard',
272 $this->content
273 );
274 }
275
276 }
277
278
279 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php'])) {
280 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/wizard_be_layout.php']);
281 }
282
283
284 // Make instance:
285 $SOBE = t3lib_div::makeInstance('SC_wizard_be_layout');
286 $SOBE->init();
287 $SOBE->main();
288 $SOBE->printContent();
289
290 ?>