a964d6344f3a33279ea414e45a278463d9a0f9a8
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / NewRecordController.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\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
33 use TYPO3\CMS\Core\Utility\GeneralUtility;
34
35 /**
36 * Script class for 'db_new'
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 */
40 class NewRecordController {
41
42 /**
43 * @todo Define visibility
44 */
45 public $pageinfo;
46
47 /**
48 * @todo Define visibility
49 */
50 public $pidInfo;
51
52 /**
53 * @todo Define visibility
54 */
55 public $newPagesInto;
56
57 /**
58 * @todo Define visibility
59 */
60 public $newContentInto;
61
62 /**
63 * @todo Define visibility
64 */
65 public $newPagesAfter;
66
67 /**
68 * Determines, whether "Select Position" for new page should be shown
69 *
70 * @var boolean $newPagesSelectPosition
71 */
72 protected $newPagesSelectPosition = TRUE;
73
74 /**
75 * @todo Define visibility
76 */
77 public $web_list_modTSconfig;
78
79 /**
80 * @todo Define visibility
81 */
82 public $allowedNewTables;
83
84 /**
85 * @todo Define visibility
86 */
87 public $deniedNewTables;
88
89 /**
90 * @todo Define visibility
91 */
92 public $web_list_modTSconfig_pid;
93
94 /**
95 * @todo Define visibility
96 */
97 public $allowedNewTables_pid;
98
99 /**
100 * @todo Define visibility
101 */
102 public $deniedNewTables_pid;
103
104 /**
105 * @todo Define visibility
106 */
107 public $code;
108
109 /**
110 * @todo Define visibility
111 */
112 public $R_URI;
113
114 // Internal, static: GPvar
115 // see init()
116 /**
117 * @todo Define visibility
118 */
119 public $id;
120
121 // Return url.
122 /**
123 * @todo Define visibility
124 */
125 public $returnUrl;
126
127 // pagesOnly flag.
128 /**
129 * @todo Define visibility
130 */
131 public $pagesOnly;
132
133 // Internal
134 // see init()
135 /**
136 * @todo Define visibility
137 */
138 public $perms_clause;
139
140 /**
141 * Document template object
142 *
143 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
144 * @todo Define visibility
145 */
146 public $doc;
147
148 // Accumulated HTML output
149 /**
150 * @todo Define visibility
151 */
152 public $content;
153
154 /**
155 * @todo Define visibility
156 */
157 public $tRows;
158
159 /**
160 * Constructor function for the class
161 *
162 * @return void
163 * @todo Define visibility
164 */
165 public function init() {
166 // Page-selection permission clause (reading)
167 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
168 // This will hide records from display - it has nothing to do with user rights!!
169 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
170 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
171 $this->perms_clause .= ' AND pages.uid NOT IN (' . $pidList . ')';
172 }
173 }
174 // Setting GPvars:
175 // The page id to operate from
176 $this->id = intval(GeneralUtility::_GP('id'));
177 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
178 $this->pagesOnly = GeneralUtility::_GP('pagesOnly');
179 // Create instance of template class for output
180 $this->doc = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\DocumentTemplate');
181 $this->doc->backPath = $GLOBALS['BACK_PATH'];
182 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_new.html');
183 $this->doc->JScode = '';
184 // Setting up the context sensitive menu:
185 $this->doc->getContextMenuCode();
186 // Creating content
187 $this->content = '';
188 $this->content .= $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle'));
189 // Id a positive id is supplied, ask for the page record with permission information contained:
190 if ($this->id > 0) {
191 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
192 }
193 // If a page-record was returned, the user had read-access to the page.
194 if ($this->pageinfo['uid']) {
195 // Get record of parent page
196 $this->pidInfo = BackendUtility::getRecord('pages', $this->pageinfo['pid']);
197 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
198 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 8)) {
199 $this->newPagesInto = 1;
200 }
201 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 16)) {
202 $this->newContentInto = 1;
203 }
204 if (($GLOBALS['BE_USER']->isAdmin() || is_array($this->pidInfo)) && $GLOBALS['BE_USER']->doesUserHaveAccess($this->pidInfo, 8)) {
205 $this->newPagesAfter = 1;
206 }
207 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
208 // Admins can do it all
209 $this->newPagesInto = 1;
210 $this->newContentInto = 1;
211 $this->newPagesAfter = 0;
212 } else {
213 // People with no permission can do nothing
214 $this->newPagesInto = 0;
215 $this->newContentInto = 0;
216 $this->newPagesAfter = 0;
217 }
218 }
219
220 /**
221 * Main processing, creating the list of new record tables to select from
222 *
223 * @return void
224 * @todo Define visibility
225 */
226 public function main() {
227 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
228 if ($this->pageinfo['uid'] || $GLOBALS['BE_USER']->isAdmin()) {
229 // Acquiring TSconfig for this module/current page:
230 $this->web_list_modTSconfig = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
231 $this->allowedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['properties']['allowedNewTables'], 1);
232 $this->deniedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['properties']['deniedNewTables'], 1);
233 // Acquiring TSconfig for this module/parent page:
234 $this->web_list_modTSconfig_pid = BackendUtility::getModTSconfig($this->pageinfo['pid'], 'mod.web_list');
235 $this->allowedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['properties']['allowedNewTables'], 1);
236 $this->deniedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['properties']['deniedNewTables'], 1);
237 // More init:
238 if (!$this->showNewRecLink('pages')) {
239 $this->newPagesInto = 0;
240 }
241 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
242 $this->newPagesAfter = 0;
243 }
244 // Set header-HTML and return_url
245 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
246 $iconImgTag = IconUtility::getSpriteIconForRecord('pages', $this->pageinfo, array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
247 $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
248 } else {
249 $iconImgTag = IconUtility::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
250 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
251 }
252 $this->code = '<span class="typo3-moduleHeader">' . $this->doc->wrapClickMenuOnIcon($iconImgTag, 'pages', $this->pageinfo['uid']) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, 45)) . '</span><br />';
253 $this->R_URI = $this->returnUrl;
254 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
255 // Regular new element:
256 if (!$this->pagesOnly) {
257 $this->regularNew();
258 } elseif ($this->showNewRecLink('pages')) {
259 // Pages only wizard
260 $this->pagesOnly();
261 }
262 // Add all the content to an output section
263 $this->content .= $this->doc->section('', $this->code);
264 // Setting up the buttons and markers for docheader
265 $docHeaderButtons = $this->getButtons();
266 $markers['CSH'] = $docHeaderButtons['csh'];
267 $markers['CONTENT'] = $this->content;
268 // Build the <body> for the module
269 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle'));
270 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
271 $this->content .= $this->doc->endPage();
272 $this->content = $this->doc->insertStylesAndJS($this->content);
273 }
274 }
275
276 /**
277 * Create the panel of buttons for submitting the form or otherwise perform operations.
278 *
279 * @return array All available buttons as an assoc. array
280 */
281 protected function getButtons() {
282 $buttons = array(
283 'csh' => '',
284 'back' => '',
285 'view' => '',
286 'new_page' => ''
287 );
288 // Regular new element:
289 if (!$this->pagesOnly) {
290 // New page
291 if ($this->showNewRecLink('pages')) {
292 $buttons['new_page'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:newPage', 1) . '">' . IconUtility::getSpriteIcon('actions-page-new') . '</a>';
293 }
294 // CSH
295 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'], '', TRUE);
296 } elseif ($this->showNewRecLink('pages')) {
297 // Pages only wizard
298 // CSH
299 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'], '', TRUE);
300 }
301 // Back
302 if ($this->R_URI) {
303 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', 1) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
304 }
305 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
306 // View
307 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $this->backPath, BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', 1) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
308 }
309 return $buttons;
310 }
311
312 /**
313 * Creates the position map for pages wizard
314 *
315 * @return void
316 * @todo Define visibility
317 */
318 public function pagesOnly() {
319 $numberOfPages = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'pages', '1=1' . BackendUtility::deleteClause('pages'));
320 if ($numberOfPages > 0) {
321 $this->code .= '
322 <h3>' . htmlspecialchars($GLOBALS['LANG']->getLL('selectPosition')) . ':</h3>
323 ';
324 $positionMap = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Tree\\View\\PagePositionMap');
325 /** @var $positionMap \TYPO3\CMS\Backend\Tree\View\PagePositionMap */
326 $this->code .= $positionMap->positionTree($this->id, $this->pageinfo, $this->perms_clause, $this->R_URI);
327 } else {
328 // No pages yet, no need to prompt for position, redirect to page creation.
329 $javascript = BackendUtility::editOnClick('returnUrl=%2Ftypo3%2Fdb_new.php%3Fid%3D0%26pagesOnly%3D1&edit[pages][0]=new&returnNewPageId=1');
330 $startPos = strpos($javascript, 'href=\'') + 6;
331 $endPos = strpos($javascript, '\';');
332 $url = substr($javascript, $startPos, $endPos - $startPos);
333 @ob_end_clean();
334 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
335 }
336 }
337
338 /**
339 * Create a regular new element (pages and records)
340 *
341 * @return void
342 * @todo Define visibility
343 */
344 public function regularNew() {
345 $doNotShowFullDescr = FALSE;
346 // Initialize array for accumulating table rows:
347 $this->tRows = array();
348 // tree images
349 $halfLine = '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />';
350 $firstLevel = '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
351 $secondLevel = '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
352 <img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
353 $secondLevelLast = '<img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
354 <img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/joinbottom.gif', 'width="18" height="16"') . ' alt="" />';
355 // Get TSconfig for current page
356 $pageTS = BackendUtility::getPagesTSconfig($this->id);
357 // Finish initializing new pages options with TSconfig
358 // Each new page option may be hidden by TSconfig
359 // Enabled option for the position of a new page
360 $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
361 // Pseudo-boolean (0/1) for backward compatibility
362 $this->newPagesInto = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) ? 1 : 0;
363 $this->newPagesAfter = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) ? 1 : 0;
364 // Slight spacer from header:
365 $this->code .= $halfLine;
366 // New Page
367 $table = 'pages';
368 $v = $GLOBALS['TCA'][$table];
369 $pageIcon = IconUtility::getSpriteIconForRecord($table, array());
370 $newPageIcon = IconUtility::getSpriteIcon('actions-page-new');
371 $rowContent = '';
372 // New pages INSIDE this pages
373 $newPageLinks = array();
374 if ($this->newPagesInto && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $GLOBALS['BE_USER']->check('tables_modify', 'pages') && $GLOBALS['BE_USER']->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id), 'pages')) {
375 // Create link to new page inside:
376 $newPageLinks[] = $this->linkWrap(IconUtility::getSpriteIconForRecord($table, array()) . $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.inside', 1) . ')', $table, $this->id);
377 }
378 // New pages AFTER this pages
379 if ($this->newPagesAfter && $this->isTableAllowedForThisPage($this->pidInfo, 'pages') && $GLOBALS['BE_USER']->check('tables_modify', 'pages') && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')) {
380 $newPageLinks[] = $this->linkWrap($pageIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.after', 1) . ')', 'pages', -$this->id);
381 }
382 // New pages at selection position
383 if ($this->newPagesSelectPosition) {
384 // Link to page-wizard:
385 $newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('pagesOnly' => 1))) . '">' . $pageIcon . htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) . '</a>';
386 }
387 // Assemble all new page links
388 $numPageLinks = count($newPageLinks);
389 for ($i = 0; $i < $numPageLinks; $i++) {
390 // For the last link, use the "branch bottom" icon
391 if ($i == $numPageLinks - 1) {
392 $treeComponent = $secondLevelLast;
393 } else {
394 $treeComponent = $secondLevel;
395 }
396 $rowContent .= '<br />' . $treeComponent . $newPageLinks[$i];
397 }
398 // Add row header and half-line if not empty
399 if (!empty($rowContent)) {
400 $rowContent .= '<br />' . $halfLine;
401 $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>' . $rowContent;
402 }
403 // Compile table row to show the icon for "new page (select position)"
404 $startRows = array();
405 if ($this->showNewRecLink('pages') && !empty($rowContent)) {
406 $startRows[] = '
407 <tr>
408 <td nowrap="nowrap">' . $rowContent . '</td>
409 <td>' . BackendUtility::wrapInHelp($table, '') . '</td>
410 </tr>
411 ';
412 }
413 // New tables (but not pages) INSIDE this pages
414 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
415 $newContentIcon = IconUtility::getSpriteIcon('actions-document-new');
416 if ($this->newContentInto) {
417 if (is_array($GLOBALS['TCA'])) {
418 $groupName = '';
419 foreach ($GLOBALS['TCA'] as $table => $v) {
420 $count = count($GLOBALS['TCA'][$table]);
421 $counter = 1;
422 if ($table != 'pages' && $this->showNewRecLink($table) && $this->isTableAllowedForThisPage($this->pageinfo, $table) && $GLOBALS['BE_USER']->check('tables_modify', $table) && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1) && $GLOBALS['BE_USER']->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id), $table)) {
423 $newRecordIcon = IconUtility::getSpriteIconForRecord($table, array());
424 $rowContent = '';
425 // Create new link for record:
426 $newLink = $this->linkWrap($newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'], 1), $table, $this->id);
427 // If the table is 'tt_content' (from "cms" extension), create link to wizard
428 if ($table == 'tt_content') {
429 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
430 $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
431 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
432 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
433 $pathToWizard = ExtensionManagementUtility::isLoaded($overrideExt) ? ExtensionManagementUtility::extRelPath($overrideExt) . 'mod1/db_new_content_el.php' : 'sysext/cms/layout/db_new_content_el.php';
434 $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
435 $rowContent .= '<br />' . $secondLevel . $newLink . '<br />' . $secondLevelLast . '<a href="' . htmlspecialchars($href) . '">' . $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) . '</a>';
436 // Half-line added:
437 $rowContent .= '<br />' . $halfLine;
438 } else {
439 // Get the title
440 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
441 continue;
442 }
443 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
444 continue;
445 }
446 $nameParts = explode('_', $table);
447 $thisTitle = '';
448 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
449 // Try to extract extension name
450 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
451 $_EXTKEY = substr($v['ctrl']['title'], 8);
452 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
453 if ($_EXTKEY != '') {
454 // First try to get localisation of extension title
455 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
456 $langFile = $temp[0];
457 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
458 // If no localisation available, read title from ext_emconf.php
459 if (!$thisTitle && is_file(ExtensionManagementUtility::extPath($_EXTKEY) . 'ext_emconf.php')) {
460 include ExtensionManagementUtility::extPath($_EXTKEY) . 'ext_emconf.php';
461 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
462 }
463 $iconFile[$_EXTKEY] = '<img ' . 'src="' . ExtensionManagementUtility::extRelPath($_EXTKEY) . $GLOBALS['TYPO3_LOADED_EXT'][$_EXTKEY]['ext_icon'] . '" ' . 'width="16" height="16" ' . 'alt="' . $thisTitle . '" />';
464 } else {
465 $thisTitle = $nameParts[1];
466 $iconFile[$_EXTKEY] = '';
467 }
468 } else {
469 $thisTitle = $nameParts[1];
470 $iconFile[$_EXTKEY] = '';
471 }
472 } else {
473 $_EXTKEY = 'system';
474 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
475 $iconFile['system'] = IconUtility::getSpriteIcon('apps-pagetree-root');
476 }
477 if ($groupName == '' || $groupName != $_EXTKEY) {
478 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
479 }
480 $rowContent .= $newLink;
481 $counter++;
482 }
483 // Compile table row:
484 if ($table == 'tt_content') {
485 $startRows[] = '
486 <tr>
487 <td nowrap="nowrap">' . $rowContent . '</td>
488 <td>' . BackendUtility::wrapInHelp($table, '') . '</td>
489 </tr>';
490 } else {
491 $this->tRows[$groupName]['title'] = $thisTitle;
492 $this->tRows[$groupName]['html'][] = $rowContent;
493 $this->tRows[$groupName]['table'][] = $table;
494 }
495 }
496 }
497 }
498 }
499 // User sort
500 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
501 $this->newRecordSortList = GeneralUtility::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], TRUE);
502 }
503 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
504 // Compile table row:
505 $finalRows = array();
506 $finalRows[] = implode('', $startRows);
507 foreach ($this->tRows as $key => $value) {
508 $row = '<tr>
509 <td nowrap="nowrap">' . $halfLine . '<br />' . $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' . '</td><td>&nbsp;<br />' . BackendUtility::wrapInHelp($key, '') . '</td>
510 </tr>';
511 $count = count($value['html']) - 1;
512 foreach ($value['html'] as $recordKey => $record) {
513 $row .= '
514 <tr>
515 <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
516 <td>' . BackendUtility::wrapInHelp($value['table'][$recordKey], '') . '</td>
517 </tr>';
518 }
519 $finalRows[] = $row;
520 }
521 // end of tree
522 $finalRows[] = '
523 <tr>
524 <td><img' . IconUtility::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" /></td>
525 <td></td>
526 </tr>
527 ';
528 // Make table:
529 $this->code .= '
530 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
531 ' . implode('', $finalRows) . '
532 </table>
533 ';
534 }
535
536 /**
537 * User array sort function used by regularNew
538 *
539 * @param string $a First array element for compare
540 * @param string $b First array element for compare
541 * @return integer -1 for lower, 0 for equal, 1 for greater
542 * @todo Define visibility
543 */
544 public function sortNewRecordsByConfig($a, $b) {
545 if (count($this->newRecordSortList)) {
546 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
547 // Both are in the list, return relative to position in array
548 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
549 $ret = ($sub < 0 ? -1 : $sub == 0) ? 0 : 1;
550 } elseif (in_array($a, $this->newRecordSortList)) {
551 // First element is in array, put to top
552 $ret = -1;
553 } elseif (in_array($b, $this->newRecordSortList)) {
554 // Second element is in array, put first to bottom
555 $ret = 1;
556 } else {
557 // No element is in array, return alphabetic order
558 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
559 }
560 return $ret;
561 } else {
562 // Return alphabetic order
563 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
564 }
565 }
566
567 /**
568 * Ending page output and echo'ing content to browser.
569 *
570 * @return void
571 * @todo Define visibility
572 */
573 public function printContent() {
574 echo $this->content;
575 }
576
577 /**
578 * Links the string $code to a create-new form for a record in $table created on page $pid
579 *
580 * @param string $linkText Link text
581 * @param string $table Table name (in which to create new record)
582 * @param integer $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
583 * @param boolean $addContentTable If $addContentTable is set, then a new contentTable record is created together with pages
584 * @return string The link.
585 * @todo Define visibility
586 */
587 public function linkWrap($linkText, $table, $pid, $addContentTable = FALSE) {
588 $parameters = '&edit[' . $table . '][' . $pid . ']=new';
589 if ($table == 'pages' && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'] && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']]) && $addContentTable) {
590 $parameters .= '&edit[' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'] . '][prev]=new&returnNewPageId=1';
591 } elseif ($table == 'pages_language_overlay') {
592 $parameters .= '&overrideVals[pages_language_overlay][doktype]=' . (int) $this->pageinfo['doktype'];
593 }
594 $onClick = BackendUtility::editOnClick($parameters, '', $this->returnUrl);
595 return '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $linkText . '</a>';
596 }
597
598 /**
599 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
600 *
601 * @param array $pid_row Record for parent page.
602 * @param string $checkTable Table name to check
603 * @return boolean Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
604 * @todo Define visibility
605 */
606 public function isTableAllowedForThisPage($pid_row, $checkTable) {
607 if (!is_array($pid_row)) {
608 if ($GLOBALS['BE_USER']->user['admin']) {
609 return TRUE;
610 } else {
611 return FALSE;
612 }
613 }
614 // be_users and be_groups may not be created anywhere but in the root.
615 if ($checkTable == 'be_users' || $checkTable == 'be_groups') {
616 return FALSE;
617 }
618 // Checking doktype:
619 $doktype = intval($pid_row['doktype']);
620 if (!($allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'])) {
621 $allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
622 }
623 // If all tables or the table is listed as a allowed type, return TRUE
624 if (strstr($allowedTableList, '*') || GeneralUtility::inList($allowedTableList, $checkTable)) {
625 return TRUE;
626 }
627 }
628
629 /**
630 * Returns TRUE if:
631 * - $allowedNewTables and $deniedNewTables are empty
632 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
633 *
634 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
635 * has priority over $allowedNewTables.
636 *
637 * @param string $table Table name to test if in allowedTables
638 * @param array $allowedNewTables Array of new tables that are allowed.
639 * @param array $deniedNewTables Array of new tables that are not allowed.
640 * @return boolean Returns TRUE if a link for creating new records should be displayed for $table
641 * @todo Define visibility
642 */
643 public function showNewRecLink($table, array $allowedNewTables = array(), array $deniedNewTables = array()) {
644 $allowedNewTables = $allowedNewTables ? $allowedNewTables : $this->allowedNewTables;
645 $deniedNewTables = $deniedNewTables ? $deniedNewTables : $this->deniedNewTables;
646 // No deny/allow tables are set:
647 if (!count($allowedNewTables) && !count($deniedNewTables)) {
648 return TRUE;
649 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
650 return TRUE;
651 } else {
652 return FALSE;
653 }
654 }
655
656 }
657
658 ?>