Fixing SVN directory structure
[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 $web_list_modTSconfig_pid;
137 var $allowedNewTables_pid;
138 var $code;
139 var $R_URI;
140
141 // Internal, static: GPvar
142 var $id; // see init()
143 var $returnUrl; // Return url.
144 var $pagesOnly; // pagesOnly flag.
145
146 // Internal
147 var $perms_clause; // see init()
148 var $doc; // see init()
149 var $content; // Accumulated HTML output
150
151
152 /**
153 * Constructor function for the class
154 *
155 * @return void
156 */
157 function init() {
158 global $BE_USER,$LANG,$BACK_PATH;
159
160 // page-selection permission clause (reading)
161 $this->perms_clause = $BE_USER->getPagePermsClause(1);
162
163 // this will hide records from display - it has nothing todo with user rights!!
164 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
165 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
166 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
167 }
168 }
169 // Setting GPvars:
170 $this->id = intval(t3lib_div::_GP('id')); // The page id to operate from
171 $this->returnUrl = t3lib_div::_GP('returnUrl');
172 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
173
174 // Create instance of template class for output
175 $this->doc = t3lib_div::makeInstance('mediumDoc');
176 $this->doc->backPath = $BACK_PATH;
177 $this->doc->docType= 'xhtml_trans';
178 $this->doc->JScode='';
179
180 // Creating content
181 $this->content='';
182 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
183 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
184
185 // Id a positive id is supplied, ask for the page record with permission information contained:
186 if ($this->id > 0) {
187 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
188 }
189
190 // If a page-record was returned, the user had read-access to the page.
191 if ($this->pageinfo['uid']) {
192 // Get record of parent page
193
194 $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
195 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
196 if ($BE_USER->doesUserHaveAccess($this->pageinfo,8)) {
197 $this->newPagesInto=1;
198 }
199 if ($BE_USER->doesUserHaveAccess($this->pageinfo,16)) {
200 $this->newContentInto=1;
201 }
202
203 if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8)) {
204 $this->newPagesAfter=1;
205 }
206 } elseif ($BE_USER->isAdmin()) {
207 // Admins can do it all
208 $this->newPagesInto=1;
209 $this->newContentInto=1;
210 $this->newPagesAfter=0;
211 } else {
212 // People with no permission can do nothing
213 $this->newPagesInto=0;
214 $this->newContentInto=0;
215 $this->newPagesAfter=0;
216 }
217 }
218
219 /**
220 * Main processing, creating the list of new record tables to select from
221 *
222 * @return void
223 */
224 function main() {
225 global $BE_USER,$LANG;
226
227 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
228 if ($this->pageinfo['uid'] || $BE_USER->isAdmin()) {
229 // Acquiring TSconfig for this module/current page:
230 $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
231 $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
232
233 // Acquiring TSconfig for this module/parent page:
234 $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
235 $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
236
237 // More init:
238 if (!$this->showNewRecLink('pages')) {
239 $this->newPagesInto=0;
240 }
241 if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid)) {
242 $this->newPagesAfter=0;
243 }
244
245
246 // Set header-HTML and return_url
247 $this->code=$this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
248 ';
249 $this->R_URI=$this->returnUrl;
250
251 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
252 if (!$this->pagesOnly) { // Regular new element:
253 $this->regularNew();
254 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
255 $this->pagesOnly();
256 }
257
258 // Create go-back link.
259 if ($this->R_URI) {
260 $this->code.='<br />
261 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
262 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
263 $LANG->getLL('goBack',1).
264 '</a>';
265 }
266 // Add all the content to an output section
267 $this->content.=$this->doc->section('',$this->code);
268 }
269 }
270
271 /**
272 * Creates the position map for pages wizard
273 *
274 * @return void
275 */
276 function pagesOnly() {
277 global $LANG;
278
279 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
280 $this->code.='
281 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
282 ';
283 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
284
285 // Add CSH:
286 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
287 }
288
289 /**
290 * Create a regular new element (pages and records)
291 *
292 * @return void
293 */
294 function regularNew() {
295 global $BE_USER,$LANG,$BACK_PATH,$TCA;
296
297 $doNotShowFullDescr = FALSE;
298
299 // Slight spacer from header:
300 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
301
302 // Initialize array for accumulating table rows:
303 $tRows = array();
304
305 // New pages INSIDE this pages
306 if ($this->newPagesInto
307 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
308 && $BE_USER->check('tables_modify','pages')
309 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
310 ) {
311
312 // Create link to new page inside:
313 $t = 'pages';
314 $v = $TCA[$t];
315 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
316 $this->linkWrap(
317 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
318 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
319 $t,
320 $this->id).'<br/>';
321
322 // Link to page-wizard:
323 $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="" />'.
324 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
325 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
326 htmlspecialchars($LANG->getLL('clickForWizard')).
327 '</a>';
328 // Half-line:
329 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
330
331 // Compile table row:
332 $tRows[]='
333 <tr>
334 <td nowrap="nowrap">'.$rowContent.'</td>
335 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
336 </tr>
337 ';
338 }
339
340 // New tables (but not pages) INSIDE this pages
341 if ($this->newContentInto) {
342 if (is_array($TCA)) {
343 foreach($TCA as $t => $v) {
344 if ($t!='pages'
345 && $this->showNewRecLink($t)
346 && $this->isTableAllowedForThisPage($this->pageinfo, $t)
347 && $BE_USER->check('tables_modify',$t)
348 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
349 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, $t)
350 ) {
351
352 // Create new link for record:
353 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
354 $this->linkWrap(
355 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
356 $LANG->sL($v['ctrl']['title'],1)
357 ,$t
358 ,$this->id);
359
360 // If the table is 'tt_content' (from "cms" extension), create link to wizard
361 if ($t=='tt_content') {
362
363 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
364 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
365 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
366
367 $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
368 $rowContent.= '<br /><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/joinbottom.gif','width="18" height="16"').' alt="" />'.
370 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
371 htmlspecialchars($LANG->getLL('clickForWizard')).
372 '</a>';
373
374 // Half-line added:
375 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
376 }
377
378
379 // Compile table row:
380 $tRows[] = '
381 <tr>
382 <td nowrap="nowrap">'.$rowContent.'</td>
383 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
384 </tr>
385 ';
386
387 }
388 }
389 }
390 }
391
392 // New pages AFTER this pages
393 if ($this->newPagesAfter
394 && $this->isTableAllowedForThisPage($this->pidInfo,'pages')
395 && $BE_USER->check('tables_modify','pages')
396 && $BE_USER->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
397 ) {
398
399 // Create link to new page after
400 $t = 'pages';
401 $v = $TCA[$t];
402 $rowContent = $this->linkWrap(
403 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
404 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
405 'pages',
406 -$this->id
407 );
408
409 // Compile table row:
410 $tRows[] = '
411 <tr>
412 <td nowrap="nowrap">'.$rowContent.'</td>
413 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
414 </tr>
415 ';
416 } else {
417 // Compile table row:
418 $tRows[]='
419 <tr>
420 <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
421 <td></td>
422 </tr>
423 ';
424 }
425
426 // Make table:
427 $this->code.='
428 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
429 '.implode('',$tRows).'
430 </table>
431 ';
432
433 // Create a link to the new-pages wizard.
434 if ($this->showNewRecLink('pages')) {
435 $this->code.='
436
437 <!--
438 Link; create new page:
439 -->
440 <div id="typo3-newPageLink">
441 <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
442 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
443 htmlspecialchars($LANG->getLL('createNewPage')).
444 '</a>
445 </div>
446 ';
447 }
448
449 // Add CSH:
450 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
451 }
452
453 /**
454 * Ending page output and echo'ing content to browser.
455 *
456 * @return void
457 */
458 function printContent() {
459 $this->content.= $this->doc->endPage();
460 $this->content = $this->doc->insertStylesAndJS($this->content);
461 echo $this->content;
462 }
463
464 /**
465 * Links the string $code to a create-new form for a record in $table created on page $pid
466 *
467 * @param string Link string
468 * @param string Table name (in which to create new record)
469 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
470 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
471 * @return string The link.
472 */
473 function linkWrap($code,$table,$pid,$addContentTable=0) {
474 $params = '&edit['.$table.']['.$pid.']=new'.
475 ($table=='pages'
476 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
477 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
478 && $addContentTable ?
479 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1' :
480 ''
481 );
482 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
483 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
484 }
485
486 /**
487 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
488 *
489 * @param array Record for parent page.
490 * @param string Table name to check
491 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
492 */
493 function isTableAllowedForThisPage($pid_row, $checkTable) {
494 global $TCA, $PAGES_TYPES;
495 if (!is_array($pid_row)) {
496 if ($GLOBALS['BE_USER']->user['admin']) {
497 return true;
498 } else {
499 return false;
500 }
501 }
502 // be_users and be_groups may not be created anywhere but in the root.
503 if ($checkTable=='be_users' || $checkTable=='be_groups') {
504 return false;
505 }
506 // Checking doktype:
507 $doktype = intval($pid_row['doktype']);
508 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
509 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
510 }
511 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
512 return true;
513 }
514 }
515
516 /**
517 * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
518 *
519 * @param string Table name to test if in allowedTables
520 * @param array Array of new tables that are allowed.
521 * @return boolean Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
522 */
523 function showNewRecLink($table,$allowedNewTables='') {
524 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
525 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
526 }
527 }
528
529 // Include extension?
530 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']) {
531 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
532 }
533
534
535
536
537
538 // Make instance:
539 $SOBE = t3lib_div::makeInstance('SC_db_new');
540 $SOBE->init();
541 $SOBE->main();
542 $SOBE->printContent();
543 ?>