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