[BUGFIX] Wrong icon in db_new tree
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / BackendLayoutWizardController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /**
5 * Script Class for grid wizard
6 *
7 * @author T3UXW09 Team1 <modernbe@cybercraft.de>
8 * @package TYPO3
9 * @subpackage core
10 */
11 class BackendLayoutWizardController {
12
13 // GET vars:
14 // Wizard parameters, coming from TCEforms linking to the wizard.
15 /**
16 * @todo Define visibility
17 */
18 public $P;
19
20 /**
21 * Document template object
22 *
23 * @var \TYPO3\CMS\Backend\Template\SmallDocumentTemplate
24 * @todo Define visibility
25 */
26 public $doc;
27
28 // Accumulated content.
29 /**
30 * @todo Define visibility
31 */
32 public $content;
33
34 /**
35 * Initialises the Class
36 *
37 * @return void
38 * @todo Define visibility
39 */
40 public function init() {
41 // Setting GET vars (used in frameset script):
42 $this->P = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('P', 1);
43 $this->formName = $this->P['formName'];
44 $this->fieldName = $this->P['itemName'];
45 $this->md5ID = $this->P['md5ID'];
46 $uid = intval($this->P['uid']);
47 // Initialize document object:
48 $this->doc = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\StandardDocumentTemplate');
49 $this->doc->backPath = $GLOBALS['BACK_PATH'];
50 $pageRenderer = $this->doc->getPageRenderer();
51 $pageRenderer->addJsFile(($GLOBALS['BACK_PATH'] . TYPO3_MOD_PATH) . 'res/grideditor.js');
52 $pageRenderer->addJsInlineCode('storeData', ((((((((((((('
53 function storeData(data) {
54 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName) . ' && parent.opener.document.') . $this->formName) . '["') . $this->fieldName) . '"]) {
55 parent.opener.document.') . $this->formName) . '["') . $this->fieldName) . '"].value = data;
56 parent.opener.TBE_EDITOR.fieldChanged("backend_layout","') . $uid) . '","config","data[backend_layout][') . $uid) . '][config]");
57 }
58 }
59 ', FALSE);
60 $languageLabels = array(
61 'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelSave', 1),
62 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_windowTitle', 1),
63 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelName', 1),
64 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_labelColumn', 1),
65 'editCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_editCell', 1),
66 'mergeCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_mergeCell', 1),
67 'splitCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_splitCell', 1),
68 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_name', 1),
69 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_column', 1),
70 'notSet' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_notSet', 1),
71 'nameHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_nameHelp', 1),
72 'columnHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xml:grid_columnHelp', 1)
73 );
74 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
75 // Select record
76 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . intval($this->P['uid']));
77 if (trim($record[0][$this->P['field']]) == '') {
78 $t3GridData = '[[{colspan:1,rowspan:1,spanned:false,name:\'\'}]]';
79 $colCount = 1;
80 $rowCount = 1;
81 } else {
82 // load TS parser
83 $parser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
84 $parser->parse($record[0][$this->P['field']]);
85 $data = $parser->setup['backend_layout.'];
86 $t3GridData = '[';
87 $colCount = $data['colCount'];
88 $rowCount = $data['rowCount'];
89 $dataRows = $data['rows.'];
90 $spannedMatrix = array();
91 for ($i = 1; $i <= $rowCount; $i++) {
92 $rowString = '';
93 for ($j = 1; $j <= $colCount; $j++) {
94 if ($j == 1) {
95 $row = array_shift($dataRows);
96 $columns = $row['columns.'];
97 $rowString = '[';
98 $cells = array();
99 }
100 if (!$spannedMatrix[$i][$j]) {
101 if (is_array($columns) && count($columns)) {
102 $column = array_shift($columns);
103 $cellString = '{';
104 $cellData = array();
105 if (isset($column['colspan'])) {
106 $cellData[] = 'colspan:' . intval($column['colspan']);
107 if (isset($column['rowspan'])) {
108 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
109 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
110 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
111 }
112 }
113 } else {
114 for ($spanColumn = 0; $spanColumn < intval($column['colspan']); $spanColumn++) {
115 $spannedMatrix[$i][$j + $spanColumn] = 1;
116 }
117 }
118 } else {
119 $cellData[] = 'colspan:1';
120 if (isset($column['rowspan'])) {
121 for ($spanRow = 0; $spanRow < intval($column['rowspan']); $spanRow++) {
122 $spannedMatrix[$i + $spanRow][$j] = 1;
123 }
124 }
125 }
126 if (isset($column['rowspan'])) {
127 $cellData[] = 'rowspan:' . intval($column['rowspan']);
128 } else {
129 $cellData[] = 'rowspan:1';
130 }
131 if (isset($column['name'])) {
132 $cellData[] = ('name:\'' . $column['name']) . '\'';
133 }
134 if (isset($column['colPos'])) {
135 $cellData[] = 'column:' . $column['colPos'];
136 }
137 $cellString .= implode(',', $cellData) . '}';
138 $cells[] = $cellString;
139 }
140 } else {
141 $cells[] = '{colspan:1,rowspan:1,spanned:1}';
142 }
143 }
144 $rowString .= implode(',', $cells);
145 if ($rowString) {
146 $rowString .= ']';
147 }
148 $rows[] = $rowString;
149 ksort($spannedMatrix[$i]);
150 }
151 $t3GridData .= implode(',', $rows) . ']';
152 }
153 $pageRenderer->enableExtJSQuickTips();
154 $pageRenderer->addExtOnReadyCode(((((('
155 t3Grid = new TYPO3.Backend.t3Grid({
156 data: ' . $t3GridData) . ',
157 colCount: ') . $colCount) . ',
158 rowCount: ') . $rowCount) . ',
159 targetElement: \'editor\'
160 });
161 t3Grid.drawTable();
162 ');
163 $this->doc->styleSheetFile_post = TYPO3_MOD_PATH . 'res/grideditor.css';
164 }
165
166 /**
167 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
168 *
169 * @return void
170 * @todo Define visibility
171 */
172 public function main() {
173 $content .= ((('<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveDoc', TRUE)) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">') . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-save')) . '</a>';
174 $content .= ((('<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.saveCloseDoc', TRUE)) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">') . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-save-close')) . '</a>';
175 $content .= ((('<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:rm.closeDoc', TRUE)) . '" onclick="window.close();return true;">') . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-close')) . '</a>';
176 $content .= $this->doc->spacer(10);
177 $content .= ((((((('
178 <table border="0" width="100%" height="100%" id="outer_container">
179 <tr>
180 <td class="editor_cell">
181 <div id="editor">
182 </div>
183 </td>
184 <td width="20" valign="center">
185 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn')) . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
186 <img src="res/t3grid-tableright.png" border="0" />
187 </a><br />
188 <a class="removeCol" href="#" title="') . $GLOBALS['LANG']->getLL('grid_removeColumn')) . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
189 <img src="res/t3grid-tableleft.png" border="0" />
190 </a>
191 </td>
192 </tr>
193 <tr>
194 <td colspan="2" height="20" align="center">
195 <a class="addCol" href="#" title="') . $GLOBALS['LANG']->getLL('grid_addRow')) . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
196 <img src="res/t3grid-tabledown.png" border="0" />
197 </a>
198 <a class="removeCol" href="#" title="') . $GLOBALS['LANG']->getLL('grid_removeRow')) . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
199 <img src="res/t3grid-tableup.png" border="0" />
200 </a>
201 </td>
202 </tr>
203 </table>
204 ';
205 $this->content = $content;
206 }
207
208 /**
209 * Returnes the sourcecode to the browser
210 *
211 * @return void
212 * @todo Define visibility
213 */
214 public function printContent() {
215 echo $this->doc->render('Grid wizard', $this->content);
216 }
217
218 }
219
220
221 ?>