[TASK] Use table styles for wizard "Create new pages"
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / Classes / Controller / CreatePagesWizardModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\WizardCrpages\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 text file 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\BackendUtility;
31 use TYPO3\CMS\Core\Utility\GeneralUtility;
32
33 /**
34 * Creates the "Create pages" wizard
35 *
36 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
37 */
38 class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
39
40 /**
41 * Holds reference of lorem ipsum class
42 *
43 * @var tx_loremipsum_wiz
44 */
45 protected $loremIpsumObject = NULL;
46
47 /**
48 * Complete tsConfig
49 *
50 * @var array
51 */
52 protected $tsConfig = array();
53
54 /**
55 * Part of tsConfig with TCEFORM.pages. settings
56 *
57 * @var array
58 */
59 protected $pagesTsConfig = array();
60
61 /**
62 * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
63 *
64 * @return array
65 * @ignore
66 * @todo Define visibility
67 */
68 public function modMenu() {
69 global $LANG;
70 $modMenuAdd = array(
71 'cr_333' => array(
72 '0' => 'nul',
73 '1' => 'et'
74 )
75 );
76 return $modMenuAdd;
77 }
78
79 /**
80 * Main function creating the content for the module.
81 *
82 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
83 * @todo Define visibility
84 */
85 public function main() {
86 $GLOBALS['LANG']->includeLLFile('EXT:wizard_crpages/locallang.xlf');
87 $theCode = '';
88 $this->tsConfig = BackendUtility::getPagesTSconfig($this->pObj->id);
89 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
90 // Create loremIpsum code:
91 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('lorem_ipsum')) {
92 $this->loremIpsumObject = GeneralUtility::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
93 }
94 // Create new pages here?
95 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);
96 $pRec = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $m_perms_clause);
97 $sys_pages = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
98 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
99 if (is_array($pRec)) {
100 $data = GeneralUtility::_GP('data');
101 if (is_array($data['pages'])) {
102 if (GeneralUtility::_GP('createInListEnd')) {
103 $endI = end($menuItems);
104 $thePid = -(int)$endI['uid'];
105 if (!$thePid) {
106 $thePid = $this->pObj->id;
107 }
108 } else {
109 $thePid = $this->pObj->id;
110 }
111 $firstRecord = TRUE;
112 $previousIdentifier = '';
113 foreach ($data['pages'] as $identifier => $dat) {
114 if (!trim($dat['title'])) {
115 unset($data['pages'][$identifier]);
116 } else {
117 $data['pages'][$identifier]['hidden'] = GeneralUtility::_GP('hidePages') ? 1 : 0;
118 $data['pages'][$identifier]['nav_hide'] = GeneralUtility::_GP('hidePagesInMenus') ? 1 : 0;
119 if ($firstRecord) {
120 $firstRecord = FALSE;
121 $data['pages'][$identifier]['pid'] = $thePid;
122 } else {
123 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
124 }
125 $previousIdentifier = $identifier;
126 }
127 }
128 if (count($data['pages'])) {
129 reset($data);
130 $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
131 $tce->stripslashes_values = 0;
132 // set default TCA values specific for the user
133 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
134 if (is_array($TCAdefaultOverride)) {
135 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
136 }
137 $tce->start($data, array());
138 $tce->process_datamap();
139 BackendUtility::setUpdateSignal('updatePageTree');
140 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_create'));
141 } else {
142 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
143 }
144 $theCode .= $flashMessage->render();
145 // Display result:
146 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
147 $lines = array();
148 foreach ($menuItems as $rec) {
149 BackendUtility::workspaceOL('pages', $rec);
150 if (is_array($rec)) {
151 $lines[] = '<nobr>' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec, array('title' => BackendUtility::titleAttribForPages($rec, '', FALSE))) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</nobr>';
152 }
153 }
154 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
155 } else {
156 // Display create form
157 $lines = array();
158 $tableData = array();
159 for ($a = 0; $a < 9; $a++) {
160 $tableData[] = $this->getFormLine($a);
161 }
162 $lines[] = '<table id="formFieldContainer" class="t3-table"><tbody id="formFieldContainerBody">' . implode(LF, $tableData) . '</tbody></table>';
163 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages') . ':</h4>' . implode('', $lines) . '<br class="clearLeft" />' . '<input type="button" id="createNewFormFields" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_addMoreLines') . '" />' . '<br /><br />
164 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">' . $GLOBALS['LANG']->getLL('wiz_newPages_listEnd') . '</label><br />
165 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePages') . '</label><br />
166 <input type="checkbox" name="hidePagesInMenus" id="hidePagesInMenus" value="1" /> <label for="hidePagesInMenus">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePagesInMenus') . '</label><br /><br />
167 <input type="submit" name="create" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lCreate') . '" />&nbsp;<input type="reset" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lReset') . '" /><br />';
168 // Add ExtJS inline code
169 $extCode = '
170 var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;
171 var lineCounter = 9;
172 Ext.get("createNewFormFields").on("click", function() {
173 div = Ext.get("formFieldContainerBody");
174 for (i = 0; i < 5; i++) {
175 label = lineCounter + i + 1;
176 line = String.format(tpl, (lineCounter + i), label);
177 div.insertHtml("beforeEnd", line);
178 }
179 lineCounter += 5;
180 });
181 ';
182 /** @var \TYPO3\CMS\Core\Page\PageRenderer */
183 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
184 $pageRenderer->loadExtJS();
185 $pageRenderer->addExtOnReadyCode($extCode);
186 $pageRenderer->addCssInlineBlock('TYPO3\CMS\WizardCrpages\Controller\CreatePagesWizardModuleFunctionController', '
187 #formFieldContainer {float: left; margin: 0 0 10px 0;}
188 .clearLeft {clear: left;}
189 #formFieldContainer label {width: 70px; display: inline-block;}
190 #formFieldContainer span {padding: 0 3px;}
191 ');
192 }
193 } else {
194 $theCode .= GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_errorMsg1'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR)->render();
195 }
196 // CSH
197 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
198 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_crMany'));
199 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
200 return $out;
201 }
202
203 /**
204 * Return one line in the form
205 *
206 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
207 * @return string HTML code for one input line for one new page
208 */
209 protected function getFormLine($index) {
210 $backPath = $GLOBALS['BACK_PATH'];
211 if (is_numeric($index)) {
212 $label = $index + 1;
213 } else {
214 // used as template for ExtJS
215 $index = '{0}';
216 $label = '{1}';
217 }
218 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') . ' ' . $label;
219 $content .= ':&nbsp;</label>';
220 // Title
221 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
222 // Lorem ipsum link, if available
223 $content .= is_object($this->loremIpsumObject) ? '<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS(('document.forms[0][\'data[pages][NEW' . $index . '][title]\'].value'), 'title')) . '">' . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath) . '</a>' : '';
224 // type selector
225 $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.type') . '</span>';
226 $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
227 $content .= 'class="select icon-select" name="data[pages][NEW' . $index . '][doktype]" style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); padding: 1px 1px 1px 24px;">';
228 // dokType
229 $types = $GLOBALS['PAGES_TYPES'];
230 unset($types['default']);
231 $types = array_keys($types);
232 $types[] = 1;
233 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
234 $types = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
235 }
236 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
237 $group = '';
238 if (in_array(1, $types) && !in_array(1, $removeItems)) {
239 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" selected="selected" value="1">Standard</option>';
240 }
241 if (in_array(6, $types) && !in_array(6, $removeItems)) {
242 $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/be_users_section.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="6">Backend User Section</option>';
243 }
244 $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
245 $group = '';
246 if (in_array(4, $types) && !in_array(4, $removeItems)) {
247 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_shortcut.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="4">Shortcut</option>';
248 }
249 if (in_array(7, $types) && !in_array(7, $removeItems)) {
250 $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/pages_mountpoint.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="7">Mount Point</option>';
251 }
252 if (in_array(3, $types) && !in_array(3, $removeItems)) {
253 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_link.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="3">Link to external URL</option>';
254 }
255 $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
256 $group = '';
257 if (in_array(254, $types) && !in_array(254, $removeItems)) {
258 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/sysf.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="254">Folder</option>';
259 }
260 if (in_array(255, $types) && !in_array(255, $removeItems)) {
261 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/recycler.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="255">Recycler</option>';
262 }
263 if (in_array(199, $types) && !in_array(199, $removeItems)) {
264 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/spacer_icon.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="199">Visual menu separator</option>';
265 }
266 $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
267 $content .= '</select>';
268 return '<tr id="form-line-' . $index . '"><td>' . $content . '</td></tr>';
269 }
270
271 }