[FEATURE] Improve wizard for creating new records
[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 protected $newPagesSelectPosition = 1;
100 var $web_list_modTSconfig;
101 var $allowedNewTables;
102 var $deniedNewTables;
103 var $web_list_modTSconfig_pid;
104 var $allowedNewTables_pid;
105 var $deniedNewTables_pid;
106 var $code;
107 var $R_URI;
108
109 // Internal, static: GPvar
110 var $id; // see init()
111 var $returnUrl; // Return url.
112 var $pagesOnly; // pagesOnly flag.
113
114 // Internal
115 var $perms_clause; // see init()
116
117 /**
118 * Document template object
119 *
120 * @var mediumDoc
121 */
122 var $doc;
123 var $content; // Accumulated HTML output
124 var $tRows;
125
126 /**
127 * Constructor function for the class
128 *
129 * @return void
130 */
131 function init() {
132
133 // page-selection permission clause (reading)
134 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
135
136 // this will hide records from display - it has nothing to do with user rights!!
137 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
138 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
139 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
140 }
141 }
142 // Setting GPvars:
143 $this->id = intval(t3lib_div::_GP('id')); // The page id to operate from
144 $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
145 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
146
147 // Create instance of template class for output
148 $this->doc = t3lib_div::makeInstance('template');
149 $this->doc->backPath = $GLOBALS['BACK_PATH'];
150 $this->doc->setModuleTemplate('templates/db_new.html');
151 $this->doc->JScode='';
152
153 // Setting up the context sensitive menu:
154 $this->doc->getContextMenuCode();
155
156 // Creating content
157 $this->content='';
158 $this->content.=$this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
159
160 // Id a positive id is supplied, ask for the page record with permission information contained:
161 if ($this->id > 0) {
162 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
163 }
164
165 // If a page-record was returned, the user had read-access to the page.
166 if ($this->pageinfo['uid']) {
167 // Get record of parent page
168
169 $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
170 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
171 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 8)) {
172 $this->newPagesInto=1;
173 }
174 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 16)) {
175 $this->newContentInto=1;
176 }
177
178 if (($GLOBALS['BE_USER']->isAdmin() || is_array($this->pidInfo)) && $GLOBALS['BE_USER']->doesUserHaveAccess($this->pidInfo, 8)) {
179 $this->newPagesAfter=1;
180 }
181 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
182 // Admins can do it all
183 $this->newPagesInto=1;
184 $this->newContentInto=1;
185 $this->newPagesAfter=0;
186 } else {
187 // People with no permission can do nothing
188 $this->newPagesInto=0;
189 $this->newContentInto=0;
190 $this->newPagesAfter=0;
191 }
192 }
193
194 /**
195 * Main processing, creating the list of new record tables to select from
196 *
197 * @return void
198 */
199 function main() {
200
201 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
202 if ($this->pageinfo['uid'] || $GLOBALS['BE_USER']->isAdmin()) {
203 // Acquiring TSconfig for this module/current page:
204 $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
205 $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
206 $this->deniedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['deniedNewTables'],1);
207
208 // Acquiring TSconfig for this module/parent page:
209 $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
210 $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
211 $this->deniedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['deniedNewTables'],1);
212
213 // More init:
214 if (!$this->showNewRecLink('pages')) {
215 $this->newPagesInto=0;
216 }
217 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
218 $this->newPagesAfter=0;
219 }
220
221
222 // Set header-HTML and return_url
223 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
224 $iconImgTag = t3lib_iconWorks::getSpriteIconForRecord('pages', $this->pageinfo, array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
225 $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
226 } else {
227 $iconImgTag = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
228 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
229 }
230
231 $this->code = '<span class="typo3-moduleHeader">' . $this->doc->wrapClickMenuOnIcon($iconImgTag, 'pages', $this->pageinfo['uid']) . htmlspecialchars(t3lib_div::fixed_lgd_cs($title, 45)) . '</span><br />';
232
233 $this->R_URI = $this->returnUrl;
234
235 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
236 if (!$this->pagesOnly) { // Regular new element:
237 $this->regularNew();
238 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
239 $this->pagesOnly();
240 }
241
242 // Add all the content to an output section
243 $this->content.=$this->doc->section('',$this->code);
244
245 // Setting up the buttons and markers for docheader
246 $docHeaderButtons = $this->getButtons();
247 $markers['CSH'] = $docHeaderButtons['csh'];
248
249 $markers['CONTENT'] = $this->content;
250
251 // Build the <body> for the module
252 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
253 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
254 $this->content.= $this->doc->endPage();
255 $this->content = $this->doc->insertStylesAndJS($this->content);
256 }
257 }
258
259 /**
260 * Create the panel of buttons for submitting the form or otherwise perform operations.
261 *
262 * @return array all available buttons as an assoc. array
263 */
264 protected function getButtons() {
265 $buttons = array(
266 'csh' => '',
267 'back' => '',
268 'view' => '',
269 'new_page' => '',
270 'record_list' => ''
271 );
272
273
274 if (!$this->pagesOnly) { // Regular new element:
275 // New page
276 if ($this->showNewRecLink('pages')) {
277 $buttons['new_page'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xml:newPage', 1) . '">' .
278 t3lib_iconWorks::getSpriteIcon('actions-page-new') .
279 '</a>';
280 }
281 // CSH
282 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'], '', TRUE);
283 } elseif($this->showNewRecLink('pages')) { // Pages only wizard
284 // CSH
285 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'], '', TRUE);
286 }
287
288 // Back
289 if ($this->R_URI) {
290 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', 1) . '">' .
291 t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
292 '</a>';
293 }
294
295 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
296 // View
297 $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) . '">' .
298 t3lib_iconWorks::getSpriteIcon('actions-document-view') .
299 '</a>';
300
301 // Record list
302 // If access to Web>List for user, then link to that module.
303 $buttons['record_list'] = t3lib_BEfunc::getListViewLink(
304 array(
305 'id' => $this->pageinfo['uid'],
306 'returnUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
307 ),
308 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList')
309 );
310 }
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 /** @var $posMap t3lib_positionMap */
324 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
325 $this->code.='
326 <h3>' . htmlspecialchars($GLOBALS['LANG']->getLL('selectPosition')) . ':</h3>
327 ';
328 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
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 if (isset($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) && $pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside'] === '0') {
355 $this->newPagesInto = 0;
356 }
357 if (isset($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) && $pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter'] === '0') {
358 $this->newPagesAfter = 0;
359 }
360 if (isset($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']) && $pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition'] === '0') {
361 $this->newPagesSelectPosition = 0;
362 }
363
364 // Slight spacer from header:
365 $this->code .= $halfLine;
366
367 // New Page
368 $table = 'pages';
369 $v = $GLOBALS['TCA'][$table];
370 $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table,array());
371
372 $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
373 $rowContent = '';
374
375 // New pages INSIDE this pages
376 $newPageLinks = array();
377 if ($this->newPagesInto
378 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
379 && $GLOBALS['BE_USER']->check('tables_modify','pages')
380 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
381 ) {
382
383 // Create link to new page inside:
384 $newPageLinks[] = $this->linkWrap(
385 t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
386 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
387 $table,
388 $this->id
389 );
390 }
391
392 // New pages AFTER this pages
393 if ($this->newPagesAfter
394 && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
395 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
396 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
397 ) {
398
399 $newPageLinks[] = $this->linkWrap(
400 $pageIcon .
401 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1) . ')',
402 'pages',
403 -$this->id
404 );
405
406 }
407
408 // New pages at selection position
409 if ($this->newPagesSelectPosition) {
410 // Link to page-wizard:
411 $newPageLinks[] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
412 $pageIcon .
413 htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
414 '</a>';
415 }
416
417 // Assemble all new page links
418 $numPageLinks = count($newPageLinks);
419 for ($i = 0; $i < $numPageLinks; $i++) {
420 // For the last link, use the "branch bottom" icon
421 if ($i == $numPageLinks - 1) {
422 $treeComponent = $secondLevelLast;
423 } else {
424 $treeComponent = $secondLevel;
425 }
426 $rowContent .= '<br />' . $treeComponent . $newPageLinks[$i];
427 }
428 // Add row header and half-line if not empty
429 if (!empty($rowContent)) {
430 $rowContent.= '<br />' . $halfLine;
431 $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>' . $rowContent;
432 }
433
434 // Compile table row to show the icon for "new page (select position)"
435 $startRows = array();
436 if ($this->showNewRecLink('pages') && !empty($rowContent)) {
437 $startRows[] = '
438 <tr>
439 <td nowrap="nowrap">' . $rowContent . '</td>
440 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
441 </tr>
442 ';
443 }
444
445
446 // New tables (but not pages) INSIDE this pages
447 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
448 $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
449 if ($this->newContentInto) {
450 if (is_array($GLOBALS['TCA'])) {
451 $groupName = '';
452 foreach($GLOBALS['TCA'] as $table => $v) {
453 $count = count($GLOBALS['TCA'][$table]);
454 $counter = 1;
455 if ($table != 'pages'
456 && $this->showNewRecLink($table)
457 && $this->isTableAllowedForThisPage($this->pageinfo, $table)
458 && $GLOBALS['BE_USER']->check('tables_modify', $table)
459 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
460 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
461 ) {
462
463 $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
464 $rowContent = '';
465
466 // Create new link for record:
467 $newLink = $this->linkWrap(
468 $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
469 ,$table
470 ,$this->id);
471
472 // If the table is 'tt_content' (from "cms" extension), create link to wizard
473 if ($table == 'tt_content') {
474 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
475 $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
476 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
477 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
478 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
479
480 $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
481 $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
482 $secondLevelLast .
483 '<a href="' . htmlspecialchars($href) . '">' .
484 $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
485 '</a>';
486
487 // Half-line added:
488 $rowContent.= '<br />' . $halfLine;
489 } else {
490 // get the title
491 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
492 continue;
493 }
494 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
495 continue;
496 }
497 $nameParts = explode('_', $table);
498 $thisTitle = '';
499 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
500 // try to extract extension name
501 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
502 $_EXTKEY = substr($v['ctrl']['title'], 8);
503 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
504 if ($_EXTKEY != '') {
505 // first try to get localisation of extension title
506 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
507 $langFile = $temp[0];
508 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
509 // if no localisation available, read title from ext_emconf.php
510 if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
511 include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
512 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
513 }
514 $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
515 } else {
516 $thisTitle = $nameParts[1];
517 $iconFile[$_EXTKEY] = '';
518 }
519 } else {
520 $thisTitle = $nameParts[1];
521 $iconFile[$_EXTKEY] = '';
522 }
523 } else {
524 $_EXTKEY = 'system';
525 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
526 $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
527 }
528
529 if ($groupName == '' || $groupName != $_EXTKEY) {
530 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
531 }
532
533 $rowContent .= $newLink;
534 $counter++;
535
536 }
537
538
539 // Compile table row:
540 if ($table == 'tt_content') {
541 $startRows[] = '
542 <tr>
543 <td nowrap="nowrap">' . $rowContent . '</td>
544 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
545 </tr>';
546 } else {
547 $this->tRows[$groupName]['title'] = $thisTitle;
548 $this->tRows[$groupName]['html'][] = $rowContent;
549 $this->tRows[$groupName]['table'][] = $table;
550 }
551 }
552 }
553 }
554 }
555
556 // user sort
557 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
558 $this->newRecordSortList = t3lib_div::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], TRUE);
559 }
560 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
561
562 // Compile table row:
563 $finalRows = array();
564 $finalRows[] = implode('', $startRows);
565 foreach ($this->tRows as $key => $value) {
566 $row = '<tr>
567 <td nowrap="nowrap">' . $halfLine . '<br />' .
568 $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' .
569 '</td><td>&nbsp;<br />' . t3lib_BEfunc::wrapInHelp($key, '') . '</td>
570 </tr>';
571 $count = count($value['html']) - 1;
572 foreach ($value['html'] as $recordKey => $record) {
573 $row .= '
574 <tr>
575 <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
576 <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
577 </tr>';
578 }
579 $finalRows[] = $row;
580 }
581
582 // end of tree
583 $finalRows[]='
584 <tr>
585 <td><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif','width="18" height="16"') . ' alt="" /></td>
586 <td></td>
587 </tr>
588 ';
589
590
591 // Make table:
592 $this->code.='
593 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
594 ' . implode('', $finalRows) . '
595 </table>
596 ';
597 }
598
599 /**
600 * user array sort function used by regularNew
601 *
602 * @param string first array element for compare
603 * @param string first array element for compare
604 * @return int -1 for lower, 0 for equal, 1 for greater
605 */
606 function sortNewRecordsByConfig($a, $b) {
607 if (count($this->newRecordSortList)) {
608 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
609 // both are in the list, return relative to position in array
610 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
611 $ret = $sub < 0 ? -1 : $sub == 0 ? 0 : 1;
612 } elseif (in_array($a, $this->newRecordSortList)) {
613 // first element is in array, put to top
614 $ret = -1;
615 } elseif (in_array($b, $this->newRecordSortList)) {
616 // second element is in array, put first to bottom
617 $ret = 1;
618 } else {
619 // no element is in array, return alphabetic order
620 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
621 }
622 return $ret;
623 } else {
624 // return alphabetic order
625 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
626 }
627 }
628
629 /**
630 * Ending page output and echo'ing content to browser.
631 *
632 * @return void
633 */
634 function printContent() {
635 echo $this->content;
636 }
637
638 /**
639 * Links the string $code to a create-new form for a record in $table created on page $pid
640 *
641 * @param string Link text
642 * @param string Table name (in which to create new record)
643 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
644 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
645 * @return string The link.
646 */
647 function linkWrap($linkText, $table, $pid, $addContentTable = FALSE) {
648 $parameters = '&edit[' . $table . '][' . $pid . ']=new';
649
650 if ($table == 'pages'
651 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
652 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
653 && $addContentTable) {
654 $parameters .= '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1';
655 } elseif ($table == 'pages_language_overlay') {
656 $parameters .= '&overrideVals[pages_language_overlay][doktype]='
657 . (int) $this->pageinfo['doktype'];
658 }
659
660 $onClick = t3lib_BEfunc::editOnClick($parameters, '', $this->returnUrl);
661
662 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">' . $linkText . '</a>';
663 }
664
665 /**
666 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
667 *
668 * @param array Record for parent page.
669 * @param string Table name to check
670 * @return boolean Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
671 */
672 function isTableAllowedForThisPage($pid_row, $checkTable) {
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 = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables']) {
687 $allowedTableList = $GLOBALS['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 ?>