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