[FEATURE] Improve livesearch results
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / BackendLayoutWizardController.php
1 <?php
2 namespace TYPO3\CMS\Backend\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Sk?rh?j (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\IconUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Script Class for grid wizard
35 *
36 * @author T3UXW09 Team1 <modernbe@cybercraft.de>
37 */
38 class BackendLayoutWizardController {
39
40 // GET vars:
41 // Wizard parameters, coming from TCEforms linking to the wizard.
42 /**
43 * @todo Define visibility
44 */
45 public $P;
46
47 /**
48 * Document template object
49 *
50 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
51 * @todo Define visibility
52 */
53 public $doc;
54
55 // Accumulated content.
56 /**
57 * @todo Define visibility
58 */
59 public $content;
60
61 /**
62 * Initialises the Class
63 *
64 * @return void
65 * @todo Define visibility
66 */
67 public function init() {
68 // Setting GET vars (used in frameset script):
69 $this->P = GeneralUtility::_GP('P', 1);
70 $this->formName = $this->P['formName'];
71 $this->fieldName = $this->P['itemName'];
72 $this->md5ID = $this->P['md5ID'];
73 $uid = intval($this->P['uid']);
74 // Initialize document object:
75 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
76 $this->doc->backPath = $GLOBALS['BACK_PATH'];
77 $pageRenderer = $this->doc->getPageRenderer();
78 $pageRenderer->addJsFile($GLOBALS['BACK_PATH'] . TYPO3_MOD_PATH . 'res/grideditor.js');
79 $pageRenderer->addJsInlineCode('storeData', '
80 function storeData(data) {
81 if (parent.opener && parent.opener.document && parent.opener.document.' . $this->formName . ' && parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"]) {
82 parent.opener.document.' . $this->formName . '["' . $this->fieldName . '"].value = data;
83 parent.opener.TBE_EDITOR.fieldChanged("backend_layout","' . $uid . '","config","data[backend_layout][' . $uid . '][config]");
84 }
85 }
86 ', FALSE);
87 $languageLabels = array(
88 'save' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_labelSave', 1),
89 'title' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_windowTitle', 1),
90 'editCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_editCell', 1),
91 'mergeCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_mergeCell', 1),
92 'splitCell' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_splitCell', 1),
93 'name' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_name', 1),
94 'column' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_column', 1),
95 'notSet' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_notSet', 1),
96 'nameHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_nameHelp', 1),
97 'columnHelp' => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_wizards.xlf:grid_columnHelp', 1)
98 );
99 $pageRenderer->addInlineLanguageLabelArray($languageLabels);
100 // Select record
101 $record = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($this->P['field'], $this->P['table'], 'uid=' . intval($this->P['uid']));
102 if (trim($record[0][$this->P['field']]) == '') {
103 $t3GridData = '[[{colspan:1,rowspan:1,spanned:false,name:\'\'}]]';
104 $colCount = 1;
105 $rowCount = 1;
106 } else {
107 // load TS parser
108 $parser = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
109 $parser->parse($record[0][$this->P['field']]);
110 $data = $parser->setup['backend_layout.'];
111 $t3GridData = '[';
112 $colCount = $data['colCount'];
113 $rowCount = $data['rowCount'];
114 $dataRows = $data['rows.'];
115 $spannedMatrix = array();
116 for ($i = 1; $i <= $rowCount; $i++) {
117 $rowString = '';
118 for ($j = 1; $j <= $colCount; $j++) {
119 if ($j == 1) {
120 $row = array_shift($dataRows);
121 $columns = $row['columns.'];
122 $rowString = '[';
123 $cells = array();
124 }
125 if (!$spannedMatrix[$i][$j]) {
126 if (is_array($columns) && count($columns)) {
127 $column = array_shift($columns);
128 $cellString = '{';
129 $cellData = array();
130 if (isset($column['colspan'])) {
131 $cellData[] = 'colspan:' . intval($column['colspan']);
132 $columnColSpan = intval($column['colspan']);
133 if (isset($column['rowspan'])) {
134 $columnRowSpan = intval($column['rowspan']);
135 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
136 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
137 $spannedMatrix[$i + $spanRow][$j + $spanColumn] = 1;
138 }
139 }
140 } else {
141 for ($spanColumn = 0; $spanColumn < $columnColSpan; $spanColumn++) {
142 $spannedMatrix[$i][$j + $spanColumn] = 1;
143 }
144 }
145 } else {
146 $cellData[] = 'colspan:1';
147 if (isset($column['rowspan'])) {
148 $columnRowSpan = intval($column['rowspan']);
149 for ($spanRow = 0; $spanRow < $columnRowSpan; $spanRow++) {
150 $spannedMatrix[$i + $spanRow][$j] = 1;
151 }
152 }
153 }
154 if (isset($column['rowspan'])) {
155 $cellData[] = 'rowspan:' . intval($column['rowspan']);
156 } else {
157 $cellData[] = 'rowspan:1';
158 }
159 if (isset($column['name'])) {
160 $cellData[] = 'name:\'' . $column['name'] . '\'';
161 }
162 if (isset($column['colPos'])) {
163 $cellData[] = 'column:' . $column['colPos'];
164 }
165 $cellString .= implode(',', $cellData) . '}';
166 $cells[] = $cellString;
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 $t3GridData .= implode(',', $rows) . ']';
180 }
181 $pageRenderer->enableExtJSQuickTips();
182 $pageRenderer->addExtOnReadyCode('
183 t3Grid = new TYPO3.Backend.t3Grid({
184 data: ' . $t3GridData . ',
185 colCount: ' . $colCount . ',
186 rowCount: ' . $rowCount . ',
187 targetElement: \'editor\'
188 });
189 t3Grid.drawTable();
190 ');
191 $this->doc->styleSheetFile_post = TYPO3_MOD_PATH . 'res/grideditor.css';
192 }
193
194 /**
195 * Main Method, rendering either colorpicker or frameset depending on ->showPicker
196 *
197 * @return void
198 * @todo Define visibility
199 */
200 public function main() {
201 $content .= '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());return true;">' . IconUtility::getSpriteIcon('actions-document-save') . '</a>';
202 $content .= '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc', TRUE) . '" onclick="storeData(t3Grid.export2LayoutRecord());window.close();return true;">' . IconUtility::getSpriteIcon('actions-document-save-close') . '</a>';
203 $content .= '<a href="#" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc', TRUE) . '" onclick="window.close();return true;">' . IconUtility::getSpriteIcon('actions-document-close') . '</a>';
204 $content .= $this->doc->spacer(10);
205 $content .= '
206 <table border="0" width="100%" height="100%" id="outer_container">
207 <tr>
208 <td class="editor_cell">
209 <div id="editor">
210 </div>
211 </td>
212 <td width="20" valign="center">
213 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addColumn') . '" onclick="t3Grid.addColumn(); t3Grid.drawTable(\'editor\');">
214 <img src="res/t3grid-tableright.png" border="0" />
215 </a><br />
216 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeColumn') . '" onclick="t3Grid.removeColumn(); t3Grid.drawTable(\'editor\');">
217 <img src="res/t3grid-tableleft.png" border="0" />
218 </a>
219 </td>
220 </tr>
221 <tr>
222 <td colspan="2" height="20" align="center">
223 <a class="addCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_addRow') . '" onclick="t3Grid.addRow(); t3Grid.drawTable(\'editor\');">
224 <img src="res/t3grid-tabledown.png" border="0" />
225 </a>
226 <a class="removeCol" href="#" title="' . $GLOBALS['LANG']->getLL('grid_removeRow') . '" onclick="t3Grid.removeRow(); t3Grid.drawTable(\'editor\');">
227 <img src="res/t3grid-tableup.png" border="0" />
228 </a>
229 </td>
230 </tr>
231 </table>
232 ';
233 $this->content = $content;
234 }
235
236 /**
237 * Returnes the sourcecode to the browser
238 *
239 * @return void
240 * @todo Define visibility
241 */
242 public function printContent() {
243 echo $this->doc->render('Grid wizard', $this->content);
244 }
245
246 }
247
248 ?>