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