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