fixed double code
[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 ?>