[BUGFIX] Pootle: Multi-line labels are not rendered properly
[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 /** @var $posMap t3lib_positionMap */
330 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
331 $this->code.='
332 <h3>' . htmlspecialchars($GLOBALS['LANG']->getLL('selectPosition')) . ':</h3>
333 ';
334 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
335 }
336
337 /**
338 * Create a regular new element (pages and records)
339 *
340 * @return void
341 */
342 function regularNew() {
343
344 $doNotShowFullDescr = FALSE;
345 // Initialize array for accumulating table rows:
346 $this->tRows = array();
347
348 // tree images
349 $halfLine = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif', 'width="18" height="8"') . ' alt="" />';
350 $firstLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
351 $secondLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
352 <img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
353 $secondLevelLast = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
354 <img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/joinbottom.gif', 'width="18" height="16"') . ' alt="" />';
355
356 // Get TSconfig for current page
357 $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
358 // Finish initializing new pages options with TSconfig
359 // Each new page option may be hidden by TSconfig
360
361 // Enabled option for the position of a new page
362 $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
363 // pseudo-boolean (0/1) for backward compatibility
364 $this->newPagesInto = (!empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) ? 1 : 0);
365 $this->newPagesAfter = (!empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) ? 1 : 0);
366
367
368 // Slight spacer from header:
369 $this->code .= $halfLine;
370
371 // New Page
372 $table = 'pages';
373 $v = $GLOBALS['TCA'][$table];
374 $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table,array());
375
376 $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
377 $rowContent = '';
378
379 // New pages INSIDE this pages
380 $newPageLinks = array();
381 if ($this->newPagesInto
382 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
383 && $GLOBALS['BE_USER']->check('tables_modify','pages')
384 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
385 ) {
386
387 // Create link to new page inside:
388 $newPageLinks[] = $this->linkWrap(
389 t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
390 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
391 $table,
392 $this->id
393 );
394 }
395
396 // New pages AFTER this pages
397 if ($this->newPagesAfter
398 && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
399 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
400 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
401 ) {
402
403 $newPageLinks[] = $this->linkWrap(
404 $pageIcon .
405 $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1) . ')',
406 'pages',
407 -$this->id
408 );
409
410 }
411
412 // New pages at selection position
413 if ($this->newPagesSelectPosition) {
414 // Link to page-wizard:
415 $newPageLinks[] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
416 $pageIcon .
417 htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
418 '</a>';
419 }
420
421 // Assemble all new page links
422 $numPageLinks = count($newPageLinks);
423 for ($i = 0; $i < $numPageLinks; $i++) {
424 // For the last link, use the "branch bottom" icon
425 if ($i == $numPageLinks - 1) {
426 $treeComponent = $secondLevelLast;
427 } else {
428 $treeComponent = $secondLevel;
429 }
430 $rowContent .= '<br />' . $treeComponent . $newPageLinks[$i];
431 }
432 // Add row header and half-line if not empty
433 if (!empty($rowContent)) {
434 $rowContent.= '<br />' . $halfLine;
435 $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>' . $rowContent;
436 }
437
438 // Compile table row to show the icon for "new page (select position)"
439 $startRows = array();
440 if ($this->showNewRecLink('pages') && !empty($rowContent)) {
441 $startRows[] = '
442 <tr>
443 <td nowrap="nowrap">' . $rowContent . '</td>
444 <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
445 </tr>
446 ';
447 }
448
449
450 // New tables (but not pages) INSIDE this pages
451 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
452 $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
453 if ($this->newContentInto) {
454 if (is_array($GLOBALS['TCA'])) {
455 $groupName = '';
456 foreach($GLOBALS['TCA'] as $table => $v) {
457 $count = count($GLOBALS['TCA'][$table]);
458 $counter = 1;
459 if ($table != 'pages'
460 && $this->showNewRecLink($table)
461 && $this->isTableAllowedForThisPage($this->pageinfo, $table)
462 && $GLOBALS['BE_USER']->check('tables_modify', $table)
463 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
464 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
465 ) {
466
467 $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
468 $rowContent = '';
469
470 // Create new link for record:
471 $newLink = $this->linkWrap(
472 $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
473 ,$table
474 ,$this->id);
475
476 // If the table is 'tt_content' (from "cms" extension), create link to wizard
477 if ($table == 'tt_content') {
478 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
479 $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
480 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
481 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
482 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
483
484 $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
485 $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
486 $secondLevelLast .
487 '<a href="' . htmlspecialchars($href) . '">' .
488 $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
489 '</a>';
490
491 // Half-line added:
492 $rowContent.= '<br />' . $halfLine;
493 } else {
494 // get the title
495 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
496 continue;
497 }
498 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
499 continue;
500 }
501 $nameParts = explode('_', $table);
502 $thisTitle = '';
503 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
504 // try to extract extension name
505 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
506 $_EXTKEY = substr($v['ctrl']['title'], 8);
507 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
508 if ($_EXTKEY != '') {
509 // first try to get localisation of extension title
510 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
511 $langFile = $temp[0];
512 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
513 // if no localisation available, read title from ext_emconf.php
514 if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
515 include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
516 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
517 }
518 $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
519 } else {
520 $thisTitle = $nameParts[1];
521 $iconFile[$_EXTKEY] = '';
522 }
523 } else {
524 $thisTitle = $nameParts[1];
525 $iconFile[$_EXTKEY] = '';
526 }
527 } else {
528 $_EXTKEY = 'system';
529 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
530 $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
531 }
532
533 if ($groupName == '' || $groupName != $_EXTKEY) {
534 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
535 }
536
537 $rowContent .= $newLink;
538 $counter++;
539
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 first array element for compare
607 * @param string first array element for compare
608 * @return int -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 Link text
646 * @param string Table name (in which to create new record)
647 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
648 * @param boolean 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 Record for parent page.
673 * @param string 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 (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return TRUE
694 return TRUE;
695 }
696 }
697
698 /**
699 * Returns TRUE if:
700 * - $allowedNewTables and $deniedNewTables are empty
701 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
702 *
703 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
704 * has priority over $allowedNewTables.
705 *
706 * @param string Table name to test if in allowedTables
707 * @param array Array of new tables that are allowed.
708 * @param array Array of new tables that are not allowed.
709 * @return boolean Returns TRUE if a link for creating new records should be displayed for $table
710 */
711 function showNewRecLink($table, array $allowedNewTables=array(), array $deniedNewTables=array()) {
712 $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
713 $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
714 // No deny/allow tables are set:
715 if (!count($allowedNewTables) && !count($deniedNewTables)) {
716 return TRUE;
717 // If table is not denied (which takes precedence over allowed tables):
718 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
719 return TRUE;
720 // If table is denied or allowed tables are set, but table is not part of:
721 } else {
722 return FALSE;
723 }
724 }
725 }
726
727
728 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php'])) {
729 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
730 }
731
732
733
734 // Make instance:
735 $SOBE = t3lib_div::makeInstance('SC_db_new');
736 $SOBE->init();
737 $SOBE->main();
738 $SOBE->printContent();
739
740 ?>