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