Added feature #7150: Add pageUnavailable_handling for system problems and maintenance
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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 * $Id$
34 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
35 * XHTML compliant
36 *
37 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 90: class localPageTree extends t3lib_pageTree
45 * 99: function wrapIcon($icon,$row)
46 * 110: function expandNext($id)
47 *
48 *
49 * 128: class SC_db_new
50 * 157: function init()
51 * 224: function main()
52 * 276: function pagesOnly()
53 * 294: function regularNew()
54 * 458: function printContent()
55 * 473: function linkWrap($code,$table,$pid,$addContentTable=0)
56 * 493: function isTableAllowedForThisPage($pid_row, $checkTable)
57 * 523: function showNewRecLink($table,$allowedNewTables='')
58 *
59 * TOTAL FUNCTIONS: 10
60 * (This index is automatically created/updated by the extension "extdeveval")
61 *
62 */
63
64
65
66
67 $BACK_PATH='';
68 require('init.php');
69 require('template.php');
70 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
71
72 // ***************************
73 // Including classes
74 // ***************************
75 require_once(PATH_t3lib.'class.t3lib_page.php');
76 require_once(PATH_t3lib.'class.t3lib_positionmap.php');
77 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
78
79
80
81
82
83 /**
84 * Extension for the tree class that generates the tree of pages in the page-wizard mode
85 *
86 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
87 * @package TYPO3
88 * @subpackage core
89 */
90 class localPageTree extends t3lib_pageTree {
91
92 /**
93 * Inserting uid-information in title-text for an icon
94 *
95 * @param string Icon image
96 * @param array Item row
97 * @return string Wrapping icon image.
98 */
99 function wrapIcon($icon,$row) {
100 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
101 }
102
103 /**
104 * Determines whether to expand a branch or not.
105 * Here the branch is expanded if the current id matches the global id for the listing/new
106 *
107 * @param integer The ID (page id) of the element
108 * @return boolean Returns true if the IDs matches
109 */
110 function expandNext($id) {
111 return $id==$GLOBALS['SOBE']->id ? 1 : 0;
112 }
113 }
114
115
116
117
118
119
120
121 /**
122 * Script class for 'db_new'
123 *
124 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
125 * @package TYPO3
126 * @subpackage core
127 */
128 class SC_db_new {
129 var $pageinfo;
130 var $pidInfo;
131 var $newPagesInto;
132 var $newContentInto;
133 var $newPagesAfter;
134 var $web_list_modTSconfig;
135 var $allowedNewTables;
136 var $deniedNewTables;
137 var $web_list_modTSconfig_pid;
138 var $allowedNewTables_pid;
139 var $deniedNewTables_pid;
140 var $code;
141 var $R_URI;
142
143 // Internal, static: GPvar
144 var $id; // see init()
145 var $returnUrl; // Return url.
146 var $pagesOnly; // pagesOnly flag.
147
148 // Internal
149 var $perms_clause; // see init()
150
151 /**
152 * Document template object
153 *
154 * @var mediumDoc
155 */
156 var $doc;
157 var $content; // Accumulated HTML output
158
159
160 /**
161 * Constructor function for the class
162 *
163 * @return void
164 */
165 function init() {
166 global $BE_USER,$LANG,$BACK_PATH;
167
168 // page-selection permission clause (reading)
169 $this->perms_clause = $BE_USER->getPagePermsClause(1);
170
171 // this will hide records from display - it has nothing todo with user rights!!
172 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
173 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
174 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
175 }
176 }
177 // Setting GPvars:
178 $this->id = intval(t3lib_div::_GP('id')); // The page id to operate from
179 $this->returnUrl = t3lib_div::_GP('returnUrl');
180 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
181
182 // Create instance of template class for output
183 $this->doc = t3lib_div::makeInstance('mediumDoc');
184 $this->doc->backPath = $BACK_PATH;
185 $this->doc->docType= 'xhtml_trans';
186 $this->doc->JScode='';
187
188 // Creating content
189 $this->content='';
190 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
191 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
192
193 // Id a positive id is supplied, ask for the page record with permission information contained:
194 if ($this->id > 0) {
195 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
196 }
197
198 // If a page-record was returned, the user had read-access to the page.
199 if ($this->pageinfo['uid']) {
200 // Get record of parent page
201
202 $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
203 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
204 if ($BE_USER->doesUserHaveAccess($this->pageinfo,8)) {
205 $this->newPagesInto=1;
206 }
207 if ($BE_USER->doesUserHaveAccess($this->pageinfo,16)) {
208 $this->newContentInto=1;
209 }
210
211 if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8)) {
212 $this->newPagesAfter=1;
213 }
214 } elseif ($BE_USER->isAdmin()) {
215 // Admins can do it all
216 $this->newPagesInto=1;
217 $this->newContentInto=1;
218 $this->newPagesAfter=0;
219 } else {
220 // People with no permission can do nothing
221 $this->newPagesInto=0;
222 $this->newContentInto=0;
223 $this->newPagesAfter=0;
224 }
225 }
226
227 /**
228 * Main processing, creating the list of new record tables to select from
229 *
230 * @return void
231 */
232 function main() {
233 global $BE_USER,$LANG;
234
235 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
236 if ($this->pageinfo['uid'] || $BE_USER->isAdmin()) {
237 // Acquiring TSconfig for this module/current page:
238 $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
239 $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
240 $this->deniedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['deniedNewTables'],1);
241
242 // Acquiring TSconfig for this module/parent page:
243 $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
244 $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
245 $this->deniedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['deniedNewTables'],1);
246
247 // More init:
248 if (!$this->showNewRecLink('pages')) {
249 $this->newPagesInto=0;
250 }
251 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
252 $this->newPagesAfter=0;
253 }
254
255
256 // Set header-HTML and return_url
257 $this->code = $this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
258 ';
259 $this->R_URI = $this->returnUrl;
260
261 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
262 if (!$this->pagesOnly) { // Regular new element:
263 $this->regularNew();
264 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
265 $this->pagesOnly();
266 }
267
268 // Create go-back link.
269 if ($this->R_URI) {
270 $this->code.='<br />
271 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
272 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
273 $LANG->getLL('goBack',1).
274 '</a>';
275 }
276 // Add all the content to an output section
277 $this->content.=$this->doc->section('',$this->code);
278 }
279 }
280
281 /**
282 * Creates the position map for pages wizard
283 *
284 * @return void
285 */
286 function pagesOnly() {
287 global $LANG;
288
289 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
290 $this->code.='
291 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
292 ';
293 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
294
295 // Add CSH:
296 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
297 }
298
299 /**
300 * Create a regular new element (pages and records)
301 *
302 * @return void
303 */
304 function regularNew() {
305 global $BE_USER,$LANG,$BACK_PATH,$TCA;
306
307 $doNotShowFullDescr = FALSE;
308
309 // Slight spacer from header:
310 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
311
312 // Initialize array for accumulating table rows:
313 $tRows = array();
314
315 // New pages INSIDE this pages
316 if ($this->newPagesInto
317 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
318 && $BE_USER->check('tables_modify','pages')
319 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
320 ) {
321
322 // Create link to new page inside:
323 $t = 'pages';
324 $v = $TCA[$t];
325 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
326 $this->linkWrap(
327 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
328 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
329 $t,
330 $this->id).'<br/>';
331
332 // Link to page-wizard:
333 $rowContent.= '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
334 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
335 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
336 htmlspecialchars($LANG->getLL('clickForWizard')).
337 '</a>';
338 // Half-line:
339 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
340
341 // Compile table row:
342 $tRows[]='
343 <tr>
344 <td nowrap="nowrap">'.$rowContent.'</td>
345 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
346 </tr>
347 ';
348 }
349
350 // New tables (but not pages) INSIDE this pages
351 if ($this->newContentInto) {
352 if (is_array($TCA)) {
353 foreach($TCA as $t => $v) {
354 if ($t!='pages'
355 && $this->showNewRecLink($t)
356 && $this->isTableAllowedForThisPage($this->pageinfo, $t)
357 && $BE_USER->check('tables_modify',$t)
358 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
359 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, $t)
360 ) {
361
362 // Create new link for record:
363 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
364 $this->linkWrap(
365 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
366 $LANG->sL($v['ctrl']['title'],1)
367 ,$t
368 ,$this->id);
369
370 // If the table is 'tt_content' (from "cms" extension), create link to wizard
371 if ($t=='tt_content') {
372
373 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
374 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
375 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
376
377 $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
378 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
379 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
380 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
381 htmlspecialchars($LANG->getLL('clickForWizard')).
382 '</a>';
383
384 // Half-line added:
385 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
386 }
387
388
389 // Compile table row:
390 $tRows[] = '
391 <tr>
392 <td nowrap="nowrap">'.$rowContent.'</td>
393 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
394 </tr>
395 ';
396
397 }
398 }
399 }
400 }
401
402 // New pages AFTER this pages
403 if ($this->newPagesAfter
404 && $this->isTableAllowedForThisPage($this->pidInfo,'pages')
405 && $BE_USER->check('tables_modify','pages')
406 && $BE_USER->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
407 ) {
408
409 // Create link to new page after
410 $t = 'pages';
411 $v = $TCA[$t];
412 $rowContent = $this->linkWrap(
413 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
414 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
415 'pages',
416 -$this->id
417 );
418
419 // Compile table row:
420 $tRows[] = '
421 <tr>
422 <td nowrap="nowrap">'.$rowContent.'</td>
423 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
424 </tr>
425 ';
426 } else {
427 // Compile table row:
428 $tRows[]='
429 <tr>
430 <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
431 <td></td>
432 </tr>
433 ';
434 }
435
436 // Make table:
437 $this->code.='
438 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
439 '.implode('',$tRows).'
440 </table>
441 ';
442
443 // Create a link to the new-pages wizard.
444 if ($this->showNewRecLink('pages')) {
445 $this->code.='
446
447 <!--
448 Link; create new page:
449 -->
450 <div id="typo3-newPageLink">
451 <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
452 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
453 htmlspecialchars($LANG->getLL('createNewPage')).
454 '</a>
455 </div>
456 ';
457 }
458
459 // Add CSH:
460 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
461 }
462
463 /**
464 * Ending page output and echo'ing content to browser.
465 *
466 * @return void
467 */
468 function printContent() {
469 $this->content.= $this->doc->endPage();
470 $this->content = $this->doc->insertStylesAndJS($this->content);
471 echo $this->content;
472 }
473
474 /**
475 * Links the string $code to a create-new form for a record in $table created on page $pid
476 *
477 * @param string Link string
478 * @param string Table name (in which to create new record)
479 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
480 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
481 * @return string The link.
482 */
483 function linkWrap($code,$table,$pid,$addContentTable=0) {
484 $params = '&edit['.$table.']['.$pid.']=new'.
485 ($table=='pages'
486 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
487 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
488 && $addContentTable ?
489 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1' :
490 ''
491 );
492 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
493 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
494 }
495
496 /**
497 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
498 *
499 * @param array Record for parent page.
500 * @param string Table name to check
501 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
502 */
503 function isTableAllowedForThisPage($pid_row, $checkTable) {
504 global $TCA, $PAGES_TYPES;
505 if (!is_array($pid_row)) {
506 if ($GLOBALS['BE_USER']->user['admin']) {
507 return true;
508 } else {
509 return false;
510 }
511 }
512 // be_users and be_groups may not be created anywhere but in the root.
513 if ($checkTable=='be_users' || $checkTable=='be_groups') {
514 return false;
515 }
516 // Checking doktype:
517 $doktype = intval($pid_row['doktype']);
518 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
519 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
520 }
521 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
522 return true;
523 }
524 }
525
526 /**
527 * Returns true if:
528 * - $allowedNewTables and $deniedNewTables are empty
529 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
530 *
531 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
532 * has priority over $allowedNewTables.
533 *
534 * @param string Table name to test if in allowedTables
535 * @param array Array of new tables that are allowed.
536 * @param array Array of new tables that are not allowed.
537 * @return boolean Returns true if a link for creating new records should be displayed for $table
538 */
539 function showNewRecLink($table, array $allowedNewTables=array(), array $deniedNewTables=array()) {
540 $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
541 $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
542 // No deny/allow tables are set:
543 if (!count($allowedNewTables) && !count($deniedNewTables)) {
544 return true;
545 // If table is not denied (which takes precedence over allowed tables):
546 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
547 return true;
548 // If table is denied or allowed tables are set, but table is not part of:
549 } else {
550 return false;
551 }
552 }
553 }
554
555 // Include extension?
556 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']) {
557 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
558 }
559
560
561
562
563
564 // Make instance:
565 $SOBE = t3lib_div::makeInstance('SC_db_new');
566 $SOBE->init();
567 $SOBE->main();
568 $SOBE->printContent();
569 ?>