[TASK] Unify backend: header/section
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / class.tx_wizardcrpages_webfunc_2.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 * Contains class for "Create pages" wizard
29 *
30 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35
36 /**
37 * Creates the "Create pages" wizard
38 *
39 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
40 * @package TYPO3
41 * @subpackage tx_wizardcrpages
42 */
43 class tx_wizardcrpages_webfunc_2 extends t3lib_extobjbase {
44
45 /**
46 * Holds reference of lorem ipsum class
47 *
48 * @var tx_loremipsum_wiz
49 */
50 protected $loremIpsumObject = NULL;
51
52 /**
53 * Complete tsConfig
54 *
55 * @var array
56 */
57 protected $tsConfig = array();
58
59 /**
60 * Part of tsConfig with TCEFORM.pages. settings
61 *
62 * @var array
63 */
64 protected $pagesTsConfig = array();
65
66
67 /**
68 * 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...
69 *
70 * @return array
71 * @ignore
72 */
73 function modMenu() {
74 global $LANG;
75
76 $modMenuAdd = array(
77 'cr_333' => array(
78 '0' => 'nul',
79 '1' => 'et'
80 )
81 );
82 return $modMenuAdd;
83 }
84
85 /**
86 * Main function creating the content for the module.
87 *
88 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
89 */
90 function main() {
91 global $SOBE,$LANG;
92
93 $theCode='';
94
95 $this->tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pObj->id);
96 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
97
98
99 // Create loremIpsum code:
100 if (t3lib_extMgm::isLoaded('lorem_ipsum')) {
101 $this->loremIpsumObject = t3lib_div::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
102 }
103
104 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8); // create new pages here?
105 $pRec = t3lib_BEfunc::getRecord('pages',$this->pObj->id,'uid',' AND '.$m_perms_clause);
106 $sys_pages = t3lib_div::makeInstance('t3lib_pageSelect');
107 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
108 if (is_array($pRec)) {
109 $data = t3lib_div::_GP('data');
110 if (is_array($data['pages'])) {
111 if (t3lib_div::_GP('createInListEnd')) {
112 $endI = end($menuItems);
113 $thePid = -intval($endI['uid']);
114 if (!$thePid) $thePid = $this->pObj->id;
115 } else {
116 $thePid = $this->pObj->id;
117 }
118
119 $firstRecord = TRUE;
120 $previousIdentifier = '';
121
122 foreach ($data['pages'] as $identifier => $dat) {
123 if (!trim($dat['title'])) {
124 unset($data['pages'][$identifier]);
125 } else {
126 $data['pages'][$identifier]['hidden'] = t3lib_div::_GP('hidePages') ? 1 : 0;
127 if ($firstRecord) {
128 $firstRecord = FALSE;
129 $data['pages'][$identifier]['pid'] = $thePid;
130 } else {
131 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
132 }
133 $previousIdentifier = $identifier;
134 }
135 }
136
137 if (count($data['pages'])) {
138 reset($data);
139 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
140 $tce->stripslashes_values=0;
141
142 // set default TCA values specific for the user
143 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
144 if (is_array($TCAdefaultOverride)) {
145 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
146 }
147
148 $tce->start($data,array());
149 $tce->process_datamap();
150 t3lib_BEfunc::setUpdateSignal('updatePageTree');
151
152 $flashMessage = t3lib_div::makeInstance(
153 't3lib_FlashMessage',
154 '',
155 $GLOBALS['LANG']->getLL('wiz_newPages_create')
156 );
157 } else {
158 $flashMessage = t3lib_div::makeInstance(
159 't3lib_FlashMessage',
160 '',
161 $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'),
162 t3lib_FlashMessage::ERROR
163 );
164 }
165
166 $theCode.= $flashMessage->render();
167
168 // Display result:
169 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
170 $lines=array();
171 foreach ($menuItems as $rec) {
172 t3lib_BEfunc::workspaceOL('pages',$rec);
173 if (is_array($rec)) {
174 $lines[] = '<nobr>' . t3lib_iconWorks::getSpriteIconForRecord('pages', $rec, array('title' => t3lib_BEfunc::titleAttribForPages($rec , '', FALSE))) .
175 htmlspecialchars(t3lib_div::fixed_lgd_cs($rec['title'],$GLOBALS['BE_USER']->uc['titleLen'])).'</nobr>';
176 }
177 }
178 $theCode.= '<h4>' . $LANG->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
179 } else {
180
181 // Display create form
182 $lines = array();
183 for ($a = 0; $a < 9; $a++) {
184 $lines[] = $this->getFormLine($a);
185 }
186
187 $theCode .= '<h4>' . $LANG->getLL('wiz_newPages') . ':</h4>' .
188 '<div id="formFieldContainer">' . implode('', $lines) . '</div>' .
189 '<br class="clearLeft" />' .
190 '<input type="button" id="createNewFormFields" value="' . $LANG->getLL('wiz_newPages_addMoreLines') . '" />' .
191
192 '<br /><br />
193 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">'.$LANG->getLL('wiz_newPages_listEnd').'</label><br />
194 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">'.$LANG->getLL('wiz_newPages_hidePages').'</label><br /><br />
195 <input type="submit" name="create" value="' . $LANG->getLL('wiz_newPages_lCreate') . '" />&nbsp;<input type="reset" value="' . $LANG->getLL('wiz_newPages_lReset') . '" /><br />';
196
197 // Add ExtJS inline code
198 $extCode = '
199 var tpl = "' . addslashes(str_replace(
200 array(LF, TAB),
201 array('', ''),
202 $this->getFormLine('#')
203 )) . '", i, line, div, bg, label;
204 var lineCounter = 9;
205 Ext.get("createNewFormFields").on("click", function() {
206 div = Ext.get("formFieldContainer");
207 for (i = 0; i < 5; i++) {
208 label = lineCounter + i + 1;
209 bg = label % 2 === 0 ? 6 : 4;
210 line = String.format(tpl, (lineCounter + i), label, bg);
211 div.insertHtml("beforeEnd", line);
212 }
213 lineCounter += 5;
214 });
215 ';
216
217 /** @var t3lib_pageRenderer **/
218 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
219
220 $pageRenderer->loadExtJS();
221 $pageRenderer->addExtOnReadyCode($extCode);
222 $pageRenderer->addCssInlineBlock('tx_wizardcrpages_webfunc_2', '
223 #formFieldContainer {float: left; margin: 0 0 10px 0;}
224 .clearLeft {clear: left;}
225 #formFieldContainer label {width: 70px; display: inline-block;}
226 #formFieldContainer input {margin:4px 2px; padding:1px; vertical-align:middle}
227 #formFieldContainer span {padding: 0 3px;}
228 ');
229 }
230 } else {
231 $theCode.=$GLOBALS['TBE_TEMPLATE']->rfw($LANG->getLL('wiz_newPages_errorMsg1'));
232 }
233
234 // CSH
235 $theCode.= t3lib_BEfunc::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
236
237 $out = $this->pObj->doc->header($LANG->getLL('wiz_crMany'));
238 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
239 return $out;
240 }
241
242 /**
243 * Return the helpbubble image tag.
244 *
245 * @return string HTML code for a help-bubble image.
246 */
247 function helpBubble() {
248 return '<img src="'.$GLOBALS['BACK_PATH'].'gfx/helpbubble.gif" width="14" height="14" hspace="2" align="top" alt="" />';
249 }
250
251 /**
252 * Return one line in the form
253 *
254 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
255 * @return string HTML code for one input line for one new page
256 */
257 protected function getFormLine($index) {
258 $backPath = $GLOBALS['BACK_PATH'];
259
260 if (is_numeric(($index))) {
261 $backgroundClass = ($index % 2 === 0 ? 'bgColor4' : 'bgColor6');
262 $label = $index + 1;
263 } else {
264 // used as template for ExtJS
265 $index = '{0}';
266 $backgroundClass = 'bgColor{2}';
267 $label = '{1}';
268 }
269
270 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') .' '. $label;
271 $content .= ':&nbsp;</label>';
272
273 // title
274 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
275
276 // lorem ipsum link, if available
277 $content .= (is_object($this->loremIpsumObject) ?
278 '<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS('document.forms[0][\'data[pages][NEW' .
279 $index . '][title]\'].value', 'title')) . '">' . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath) . '</a>'
280 : '');
281
282 // type selector
283 $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.php:LGL.type') . '</span>';
284 $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
285 $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;">';
286
287 // dokType
288 $types = $GLOBALS['PAGES_TYPES'];
289 unset($types['default']);
290 $types = array_keys($types);
291 $types[] = 1;
292 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
293 $types = t3lib_div::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
294 }
295
296 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? t3lib_div::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
297
298 $group = '';
299 if (in_array(1, $types) && !in_array(1, $removeItems)) {
300 $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>';
301 }
302 if (in_array(6, $types) && !in_array(6, $removeItems)) {
303 $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>';
304 }
305 $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
306
307 $group = '';
308 if (in_array(4, $types) && !in_array(4, $removeItems)) {
309 $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>';
310 }
311 if (in_array(7, $types) && !in_array(7, $removeItems)) {
312 $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>';
313 }
314 if (in_array(3, $types) && !in_array(3, $removeItems)) {
315 $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>';
316 }
317 $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
318
319 $group = '';
320 if (in_array(254, $types) && !in_array(254, $removeItems)) {
321 $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>';
322 }
323 if (in_array(255, $types) && !in_array(255, $removeItems)) {
324 $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>';
325 }
326 if (in_array(199, $types) && !in_array(199, $removeItems)) {
327 $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>';
328 }
329 $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
330 $content .= '</select>';
331
332 return '<div id="form-line-' . $index . '" class="' . $backgroundClass . '">' . $content . '</div>';
333 }
334 }
335
336 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php'])) {
337 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php']);
338 }
339 ?>