[BUGFIX] Warning in list module
[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 $numberOfPages = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'pages', '1=1' . t3lib_BEfunc::deleteClause('pages'));
353 if ($numberOfPages > 0) {
354 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
355 $this->code.='
356 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
357 ';
358 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
359 } else {
360 // No pages yet, no need to prompt for position, redirect to page creation.
361 $javascript = t3lib_BEfunc::editOnClick('returnUrl=%2Ftypo3%2Fdb_new.php%3Fid%3D0%26pagesOnly%3D1&edit[pages][0]=new&returnNewPageId=1');
362 $startPos = strpos($javascript, 'href=\'') + 6;
363 $endPos = strpos($javascript, '\';');
364 $url = substr($javascript, $startPos, $endPos - $startPos);
365 @ob_end_clean();
366 t3lib_utility_Http::redirect($url);
367 }
368 }
369
370 /**
371 * Create a regular new element (pages and records)
372 *
373 * @return void
374 */
375 function regularNew() {
376
377 $doNotShowFullDescr = false;
378 // Initialize array for accumulating table rows:
379 $this->tRows = array();
380
381 // tree images
382 $halfLine = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif', 'width="18" height="8"') . ' alt="" />';
383 $firstLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
384 $secondLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
385 <img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
386 $secondLevelLast = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
387 <img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/joinbottom.gif', 'width="18" height="16"') . ' alt="" />';
388
389 // Slight spacer from header:
390 $this->code .= $halfLine;
391
392 // New Page
393 $table = 'pages';
394 $v = $GLOBALS['TCA'][$table];
395 $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table,array());
396
397 $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
398 $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>';
399
400 // New pages INSIDE this pages
401 if ($this->newPagesInto
402 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
403 && $GLOBALS['BE_USER']->check('tables_modify','pages')
404 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
405 ) {
406
407 // Create link to new page inside:
408
409 $rowContent .= '<br />' . $secondLevel . $this->linkWrap(
410 t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
411 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
412 $table,
413 $this->id);
414 }
415
416 // New pages AFTER this pages
417 if ($this->newPagesAfter
418 && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
419 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
420 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
421 ) {
422
423 $rowContent .= '<br />' . $secondLevel .
424 $this->linkWrap(
425 $pageIcon .
426 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1) . ')',
427 'pages',
428 -$this->id
429 );
430
431 }
432
433 // Link to page-wizard:
434 $rowContent.= '<br />' . $secondLevelLast .
435 '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
436 $pageIcon .
437 htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
438 '</a>';
439
440 // Half-line:
441 $rowContent.= '<br />' . $halfLine;
442
443 // Compile table row to show the icon for "new page (select position)"
444 $startRows = array();
445 if ($this->showNewRecLink('pages')) {
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(
477 $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
478 ,$table
479 ,$this->id);
480
481 // If the table is 'tt_content' (from "cms" extension), create link to wizard
482 if ($table == 'tt_content') {
483 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
484 $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
485 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
486 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
487 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
488
489 $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
490 $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
491 $secondLevelLast .
492 '<a href="' . htmlspecialchars($href) . '">' .
493 $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
494 '</a>';
495
496 // Half-line added:
497 $rowContent.= '<br />' . $halfLine;
498 } else {
499 // get the title
500 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
501 continue;
502 }
503 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
504 continue;
505 }
506 $nameParts = explode('_', $table);
507 $thisTitle = '';
508 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
509 // try to extract extension name
510 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
511 $_EXTKEY = substr($v['ctrl']['title'], 8);
512 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
513 if ($_EXTKEY != '') {
514 // first try to get localisation of extension title
515 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
516 $langFile = $temp[0];
517 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
518 // if no localisation available, read title from ext_emconf.php
519 if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
520 include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
521 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
522 }
523 $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
524 } else {
525 $thisTitle = $nameParts[1];
526 $iconFile[$_EXTKEY] = '';
527 }
528 } else {
529 $thisTitle = $nameParts[1];
530 $iconFile[$_EXTKEY] = '';
531 }
532 } else {
533 $_EXTKEY = 'system';
534 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
535 $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
536 }
537
538 if($groupName == '' || $groupName != $_EXTKEY) {
539 $groupName = $_EXTKEY;
540 }
541
542 $rowContent .= $newLink;
543 $counter++;
544
545 }
546
547
548 // Compile table row:
549 if ($table == 'tt_content') {
550 $startRows[] = '
551 <tr>
552 <td nowrap="nowrap">' . $rowContent . '</td>
553 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
554 </tr>';
555 } else {
556 $this->tRows[$groupName]['title'] = $thisTitle;
557 $this->tRows[$groupName]['html'][] = $rowContent;
558 $this->tRows[$groupName]['table'][] = $table;
559 }
560 }
561 }
562 }
563 }
564
565 // user sort
566 $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
567 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
568 $this->newRecordSortList = t3lib_div::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
569 }
570 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
571
572 // Compile table row:
573 $finalRows = array();
574 $finalRows[] = implode('', $startRows);
575 foreach ($this->tRows as $key => $value) {
576 $row = '<tr>
577 <td nowrap="nowrap">' . $halfLine . '<br />' .
578 $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' .
579 '</td><td>&nbsp;<br />' . t3lib_BEfunc::wrapInHelp($key, '') . '</td>
580 </tr>';
581 $count = count($value['html']) - 1;
582 foreach ($value['html'] as $recordKey => $record) {
583 $row .= '
584 <tr>
585 <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
586 <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
587 </tr>';
588 }
589 $finalRows[] = $row;
590 }
591
592 // end of tree
593 $finalRows[]='
594 <tr>
595 <td><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif','width="18" height="16"') . ' alt="" /></td>
596 <td></td>
597 </tr>
598 ';
599
600
601 // Make table:
602 $this->code.='
603 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
604 ' . implode('', $finalRows) . '
605 </table>
606 ';
607 }
608
609 /**
610 * user array sort function used by regularNew
611 *
612 * @param string first array element for compare
613 * @param string first array element for compare
614 * @return int -1 for lower, 0 for equal, 1 for greater
615 */
616 function sortNewRecordsByConfig($a, $b) {
617 if (count($this->newRecordSortList)) {
618 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
619 // both are in the list, return relative to position in array
620 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
621 $ret = $sub < 0 ? -1 : $sub == 0 ? 0 : 1;
622 } elseif (in_array($a, $this->newRecordSortList)) {
623 // first element is in array, put to top
624 $ret = -1;
625 } elseif (in_array($b, $this->newRecordSortList)) {
626 // second element is in array, put first to bottom
627 $ret = 1;
628 } else {
629 // no element is in array, return alphabetic order
630 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
631 }
632 return $ret;
633 } else {
634 // return alphabetic order
635 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
636 }
637 }
638
639 /**
640 * Ending page output and echo'ing content to browser.
641 *
642 * @return void
643 */
644 function printContent() {
645 echo $this->content;
646 }
647
648 /**
649 * Links the string $code to a create-new form for a record in $table created on page $pid
650 *
651 * @param string Link text
652 * @param string Table name (in which to create new record)
653 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
654 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
655 * @return string The link.
656 */
657 function linkWrap($linkText, $table, $pid, $addContentTable = false) {
658 $parameters = '&edit[' . $table . '][' . $pid . ']=new';
659
660 if ($table == 'pages'
661 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
662 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
663 && $addContentTable) {
664 $parameters .= '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1';
665 } elseif ($table == 'pages_language_overlay') {
666 $parameters .= '&overrideVals[pages_language_overlay][doktype]='
667 . (int) $this->pageinfo['doktype'];
668 }
669
670 $onClick = t3lib_BEfunc::editOnClick($parameters, '', $this->returnUrl);
671
672 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">' . $linkText . '</a>';
673 }
674
675 /**
676 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
677 *
678 * @param array Record for parent page.
679 * @param string Table name to check
680 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
681 */
682 function isTableAllowedForThisPage($pid_row, $checkTable) {
683 global $TCA, $PAGES_TYPES;
684 if (!is_array($pid_row)) {
685 if ($GLOBALS['BE_USER']->user['admin']) {
686 return true;
687 } else {
688 return false;
689 }
690 }
691 // be_users and be_groups may not be created anywhere but in the root.
692 if ($checkTable=='be_users' || $checkTable=='be_groups') {
693 return false;
694 }
695 // Checking doktype:
696 $doktype = intval($pid_row['doktype']);
697 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
698 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
699 }
700 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
701 return true;
702 }
703 }
704
705 /**
706 * Returns true if:
707 * - $allowedNewTables and $deniedNewTables are empty
708 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
709 *
710 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
711 * has priority over $allowedNewTables.
712 *
713 * @param string Table name to test if in allowedTables
714 * @param array Array of new tables that are allowed.
715 * @param array Array of new tables that are not allowed.
716 * @return boolean Returns true if a link for creating new records should be displayed for $table
717 */
718 function showNewRecLink($table, array $allowedNewTables=array(), array $deniedNewTables=array()) {
719 $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
720 $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
721 // No deny/allow tables are set:
722 if (!count($allowedNewTables) && !count($deniedNewTables)) {
723 return true;
724 // If table is not denied (which takes precedence over allowed tables):
725 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
726 return true;
727 // If table is denied or allowed tables are set, but table is not part of:
728 } else {
729 return false;
730 }
731 }
732 }
733
734
735 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php'])) {
736 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
737 }
738
739
740
741 // Make instance:
742 $SOBE = t3lib_div::makeInstance('SC_db_new');
743 $SOBE->init();
744 $SOBE->main();
745 $SOBE->printContent();
746
747 ?>