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