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