[TASK] Follow-up: Remove record_list icon
[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 );
273
274 // Regular new element:
275 if (!$this->pagesOnly) {
276 // New page
277 if ($this->showNewRecLink('pages')) {
278 $buttons['new_page'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:newPage', 1) . '">' .
279 t3lib_iconWorks::getSpriteIcon('actions-page-new') .
280 '</a>';
281 }
282 // CSH
283 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'], '', TRUE);
284 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
285 // CSH
286 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'], '', TRUE);
287 }
288
289 // Back
290 if ($this->R_URI) {
291 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', 1) . '">' .
292 t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
293 '</a>';
294 }
295
296 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
297 // View
298 $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) . '">' .
299 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
300 '</a>';
301 }
302
303 return $buttons;
304 }
305
306 /**
307 * Creates the position map for pages wizard
308 *
309 * @return void
310 */
311 function pagesOnly() {
312 $numberOfPages = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'pages', '1=1' . t3lib_BEfunc::deleteClause('pages'));
313 if ($numberOfPages > 0) {
314 $this->code.='
315 <h3>' . htmlspecialchars($GLOBALS['LANG']->getLL('selectPosition')) . ':</h3>
316 ';
317 $positionMap = t3lib_div::makeInstance('t3lib_positionMap');
318 /** @var t3lib_positionMap $positionMap */
319 $this->code .= $positionMap->positionTree($this->id, $this->pageinfo, $this->perms_clause, $this->R_URI);
320 } else {
321 // No pages yet, no need to prompt for position, redirect to page creation.
322 $javascript = t3lib_BEfunc::editOnClick('returnUrl=%2Ftypo3%2Fdb_new.php%3Fid%3D0%26pagesOnly%3D1&edit[pages][0]=new&returnNewPageId=1');
323 $startPos = strpos($javascript, 'href=\'') + 6;
324 $endPos = strpos($javascript, '\';');
325 $url = substr($javascript, $startPos, $endPos - $startPos);
326 @ob_end_clean();
327 t3lib_utility_Http::redirect($url);
328 }
329 }
330
331 /**
332 * Create a regular new element (pages and records)
333 *
334 * @return void
335 */
336 function regularNew() {
337
338 $doNotShowFullDescr = FALSE;
339 // Initialize array for accumulating table rows:
340 $this->tRows = array();
341
342 // tree images
343 $halfLine = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/halfline.gif', 'width="18" height="8"') . ' alt="" />';
344 $firstLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
345 $secondLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
346 <img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
347 $secondLevelLast = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
348 <img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/joinbottom.gif', 'width="18" height="16"') . ' alt="" />';
349
350 // Get TSconfig for current page
351 $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
352 // Finish initializing new pages options with TSconfig
353 // Each new page option may be hidden by TSconfig
354
355 // Enabled option for the position of a new page
356 $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
357 // Pseudo-boolean (0/1) for backward compatibility
358 $this->newPagesInto = (!empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) ? 1 : 0);
359 $this->newPagesAfter = (!empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) ? 1 : 0);
360
361 // Slight spacer from header:
362 $this->code .= $halfLine;
363
364 // New Page
365 $table = 'pages';
366 $v = $GLOBALS['TCA'][$table];
367 $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
368
369 $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
370 $rowContent = '';
371
372 // New pages INSIDE this pages
373 $newPageLinks = array();
374 if ($this->newPagesInto
375 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
376 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
377 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
378 ) {
379
380 // Create link to new page inside:
381 $newPageLinks[] = $this->linkWrap(
382 t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
383 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
384 $table,
385 $this->id
386 );
387 }
388
389 // New pages AFTER this pages
390 if ($this->newPagesAfter
391 && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
392 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
393 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
394 ) {
395
396 $newPageLinks[] = $this->linkWrap(
397 $pageIcon .
398 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after', 1) . ')',
399 'pages',
400 -$this->id
401 );
402 }
403
404 // New pages at selection position
405 if ($this->newPagesSelectPosition) {
406 // Link to page-wizard:
407 $newPageLinks[] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
408 $pageIcon .
409 htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
410 '</a>';
411 }
412
413 // Assemble all new page links
414 $numPageLinks = count($newPageLinks);
415 for ($i = 0; $i < $numPageLinks; $i++) {
416 // For the last link, use the "branch bottom" icon
417 if ($i == $numPageLinks - 1) {
418 $treeComponent = $secondLevelLast;
419 } else {
420 $treeComponent = $secondLevel;
421 }
422 $rowContent .= '<br />' . $treeComponent . $newPageLinks[$i];
423 }
424 // Add row header and half-line if not empty
425 if (!empty($rowContent)) {
426 $rowContent.= '<br />' . $halfLine;
427 $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>' . $rowContent;
428 }
429
430 // Compile table row to show the icon for "new page (select position)"
431 $startRows = array();
432 if ($this->showNewRecLink('pages') && !empty($rowContent)) {
433 $startRows[] = '
434 <tr>
435 <td nowrap="nowrap">' . $rowContent . '</td>
436 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
437 </tr>
438 ';
439 }
440
441 // New tables (but not pages) INSIDE this pages
442 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
443 $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
444 if ($this->newContentInto) {
445 if (is_array($GLOBALS['TCA'])) {
446 $groupName = '';
447 foreach ($GLOBALS['TCA'] as $table => $v) {
448 $count = count($GLOBALS['TCA'][$table]);
449 $counter = 1;
450 if ($table != 'pages'
451 && $this->showNewRecLink($table)
452 && $this->isTableAllowedForThisPage($this->pageinfo, $table)
453 && $GLOBALS['BE_USER']->check('tables_modify', $table)
454 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
455 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
456 ) {
457
458 $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
459 $rowContent = '';
460
461 // Create new link for record:
462 $newLink = $this->linkWrap($newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'], 1), $table, $this->id);
463
464 // If the table is 'tt_content' (from "cms" extension), create link to wizard
465 if ($table == 'tt_content') {
466 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
467 $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
468 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
469 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
470 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
471
472 $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
473 $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
474 $secondLevelLast .
475 '<a href="' . htmlspecialchars($href) . '">' .
476 $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
477 '</a>';
478
479 // Half-line added:
480 $rowContent.= '<br />' . $halfLine;
481 } else {
482 // Get the title
483 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
484 continue;
485 }
486 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
487 continue;
488 }
489 $nameParts = explode('_', $table);
490 $thisTitle = '';
491 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
492 // Try to extract extension name
493 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
494 $_EXTKEY = substr($v['ctrl']['title'], 8);
495 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
496 if ($_EXTKEY != '') {
497 // First try to get localisation of extension title
498 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
499 $langFile = $temp[0];
500 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
501 // If no localisation available, read title from ext_emconf.php
502 if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
503 include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
504 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
505 }
506 $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
507 } else {
508 $thisTitle = $nameParts[1];
509 $iconFile[$_EXTKEY] = '';
510 }
511 } else {
512 $thisTitle = $nameParts[1];
513 $iconFile[$_EXTKEY] = '';
514 }
515 } else {
516 $_EXTKEY = 'system';
517 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
518 $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
519 }
520
521 if ($groupName == '' || $groupName != $_EXTKEY) {
522 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
523 }
524
525 $rowContent .= $newLink;
526 $counter++;
527
528 }
529
530 // Compile table row:
531 if ($table == 'tt_content') {
532 $startRows[] = '
533 <tr>
534 <td nowrap="nowrap">' . $rowContent . '</td>
535 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
536 </tr>';
537 } else {
538 $this->tRows[$groupName]['title'] = $thisTitle;
539 $this->tRows[$groupName]['html'][] = $rowContent;
540 $this->tRows[$groupName]['table'][] = $table;
541 }
542 }
543 }
544 }
545 }
546
547 // User sort
548 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
549 $this->newRecordSortList = t3lib_div::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], TRUE);
550 }
551 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
552
553 // Compile table row:
554 $finalRows = array();
555 $finalRows[] = implode('', $startRows);
556 foreach ($this->tRows as $key => $value) {
557 $row = '<tr>
558 <td nowrap="nowrap">' . $halfLine . '<br />' .
559 $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' .
560 '</td><td>&nbsp;<br />' . t3lib_BEfunc::wrapInHelp($key, '') . '</td>
561 </tr>';
562 $count = count($value['html']) - 1;
563 foreach ($value['html'] as $recordKey => $record) {
564 $row .= '
565 <tr>
566 <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
567 <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
568 </tr>';
569 }
570 $finalRows[] = $row;
571 }
572
573 // end of tree
574 $finalRows[] = '
575 <tr>
576 <td><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif', 'width="18" height="16"') . ' alt="" /></td>
577 <td></td>
578 </tr>
579 ';
580
581 // Make table:
582 $this->code .= '
583 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
584 ' . implode('', $finalRows) . '
585 </table>
586 ';
587 }
588
589 /**
590 * User array sort function used by regularNew
591 *
592 * @param string $a First array element for compare
593 * @param string $b First array element for compare
594 * @return integer -1 for lower, 0 for equal, 1 for greater
595 */
596 function sortNewRecordsByConfig($a, $b) {
597 if (count($this->newRecordSortList)) {
598 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
599 // Both are in the list, return relative to position in array
600 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
601 $ret = $sub < 0 ? -1 : $sub == 0 ? 0 : 1;
602 } elseif (in_array($a, $this->newRecordSortList)) {
603 // First element is in array, put to top
604 $ret = -1;
605 } elseif (in_array($b, $this->newRecordSortList)) {
606 // Second element is in array, put first to bottom
607 $ret = 1;
608 } else {
609 // No element is in array, return alphabetic order
610 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
611 }
612 return $ret;
613 } else {
614 // Return alphabetic order
615 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
616 }
617 }
618
619 /**
620 * Ending page output and echo'ing content to browser.
621 *
622 * @return void
623 */
624 function printContent() {
625 echo $this->content;
626 }
627
628 /**
629 * Links the string $code to a create-new form for a record in $table created on page $pid
630 *
631 * @param string $linkText Link text
632 * @param string $table Table name (in which to create new record)
633 * @param integer $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
634 * @param boolean $addContentTable If $addContentTable is set, then a new contentTable record is created together with pages
635 * @return string The link.
636 */
637 function linkWrap($linkText, $table, $pid, $addContentTable = FALSE) {
638 $parameters = '&edit[' . $table . '][' . $pid . ']=new';
639
640 if ($table == 'pages'
641 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
642 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
643 && $addContentTable) {
644 $parameters .= '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1';
645 } elseif ($table == 'pages_language_overlay') {
646 $parameters .= '&overrideVals[pages_language_overlay][doktype]='
647 . (int) $this->pageinfo['doktype'];
648 }
649
650 $onClick = t3lib_BEfunc::editOnClick($parameters, '', $this->returnUrl);
651
652 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">' . $linkText . '</a>';
653 }
654
655 /**
656 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
657 *
658 * @param array $pid_row Record for parent page.
659 * @param string $checkTable Table name to check
660 * @return boolean Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
661 */
662 function isTableAllowedForThisPage($pid_row, $checkTable) {
663 if (!is_array($pid_row)) {
664 if ($GLOBALS['BE_USER']->user['admin']) {
665 return TRUE;
666 } else {
667 return FALSE;
668 }
669 }
670 // be_users and be_groups may not be created anywhere but in the root.
671 if ($checkTable == 'be_users' || $checkTable == 'be_groups') {
672 return FALSE;
673 }
674 // Checking doktype:
675 $doktype = intval($pid_row['doktype']);
676 if (!$allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables']) {
677 $allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
678 }
679 // If all tables or the table is listed as a allowed type, return TRUE
680 if (strstr($allowedTableList, '*') || t3lib_div::inList($allowedTableList, $checkTable)) {
681 return TRUE;
682 }
683 }
684
685 /**
686 * Returns TRUE if:
687 * - $allowedNewTables and $deniedNewTables are empty
688 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
689 *
690 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
691 * has priority over $allowedNewTables.
692 *
693 * @param string $table Table name to test if in allowedTables
694 * @param array $allowedNewTables Array of new tables that are allowed.
695 * @param array $deniedNewTables Array of new tables that are not allowed.
696 * @return boolean Returns TRUE if a link for creating new records should be displayed for $table
697 */
698 function showNewRecLink($table, array $allowedNewTables = array(), array $deniedNewTables = array()) {
699 $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
700 $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
701 // No deny/allow tables are set:
702 if (!count($allowedNewTables) && !count($deniedNewTables)) {
703 return TRUE;
704 // If table is not denied (which takes precedence over allowed tables):
705 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
706 return TRUE;
707 // If table is denied or allowed tables are set, but table is not part of:
708 } else {
709 return FALSE;
710 }
711 }
712 }
713
714 // Make instance:
715 $SOBE = t3lib_div::makeInstance('SC_db_new');
716 $SOBE->init();
717 $SOBE->main();
718 $SOBE->printContent();
719
720 ?>