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