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