Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 2/2003 by Kasper Skaarhoj
35 * XHTML compliant (not with pages wizard yet... position map and other classes needs cleaning)
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 * 123: class SC_db_new
50 * 149: function init()
51 * 206: function main()
52 * 263: function pagesOnly()
53 * 279: function regularNew()
54 * 412: function printContent()
55 * 426: function linkWrap($code,$table,$pid,$addContentTable=0)
56 * 446: function isTableAllowedForThisPage($pid_row, $checkTable)
57 * 476: 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 include ('sysext/lang/locallang_misc.php');
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 substr($icon,0,-1).' 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
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 * Script class for 'db_new'
118 *
119 * @author Kasper Skaarhoj <kasper@typo3.com>
120 * @package TYPO3
121 * @subpackage core
122 */
123 class SC_db_new {
124 var $pageinfo;
125 var $pidInfo;
126 var $newPagesInto;
127 var $newContentInto;
128 var $newPagesAfter;
129 var $web_list_modTSconfig;
130 var $allowedNewTables;
131 var $web_list_modTSconfig_pid;
132 var $allowedNewTables_pid;
133 var $code;
134 var $R_URI;
135 var $code;
136
137 // Internal
138 var $perms_clause; // see init()
139 var $id; // see init()
140 var $doc; // see init()
141 var $content; // Accumulated HTML output
142
143
144 /**
145 * Constructor
146 *
147 * @return void
148 */
149 function init() {
150 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA;
151
152 // page-selection permission clause (reading)
153 $this->perms_clause = $BE_USER->getPagePermsClause(1);
154 // The page id to operate from
155 $this->id = intval(t3lib_div::GPvar('id'));
156
157 // Create instance of template class for output
158 $this->doc = t3lib_div::makeInstance('smallDoc');
159 $this->doc->backPath = $BACK_PATH;
160 $this->doc->docType= 'xhtml_trans';
161 $this->doc->JScode='';
162
163 // Creating content
164 $this->content='';
165 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
166 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
167
168 // Id a positive id is supplied, ask for the page record with permission information contained:
169 if ($this->id > 0) {
170 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
171 }
172
173 // If a page-record was returned, the user had read-access to the page.
174 if ($this->pageinfo['uid']) {
175 // Get record of parent page
176 $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
177 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
178 if ($BE_USER->doesUserHaveAccess($this->pageinfo,8)) {
179 $this->newPagesInto=1;
180 }
181 if ($BE_USER->doesUserHaveAccess($this->pageinfo,16)) {
182 $this->newContentInto=1;
183 }
184
185 if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8)) {
186 $this->newPagesAfter=1;
187 }
188 } elseif ($BE_USER->isAdmin()) {
189 // Admins can do it all
190 $this->newPagesInto=1;
191 $this->newContentInto=1;
192 $this->newPagesAfter=0;
193 } else {
194 // People with no permission can do nothing
195 $this->newPagesInto=0;
196 $this->newContentInto=0;
197 $this->newPagesAfter=0;
198 }
199 }
200
201 /**
202 * Main processing
203 *
204 * @return void
205 */
206 function main() {
207 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA;
208
209 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
210 if ($this->pageinfo['uid'] || $BE_USER->isAdmin()) {
211 // Acquiring TSconfig for this module/current page:
212 $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
213 $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
214
215 // Acquiring TSconfig for this module/parent page:
216 $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
217 $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
218
219 // More init:
220 if (!$this->showNewRecLink('pages')) {
221 $this->newPagesInto=0;
222 }
223 if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid)) {
224 $this->newPagesAfter=0;
225 }
226
227
228 // Set header-HTML and return_url
229 $this->code=$this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
230 ';
231 $this->R_URI=t3lib_div::GPvar('returnUrl');
232
233 // If CSH is enabled (Context Sensitive Help), load descriptions for 'pages' in any case:
234 if ($BE_USER->uc['edit_showFieldHelp']) {
235 $LANG->loadSingleTableDescription('pages');
236 }
237
238 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
239 if (!t3lib_div::GPvar('pagesOnly')) { // Regular new element:
240 $this->regularNew();
241 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
242 $this->pagesOnly();
243 }
244
245 // Create go-back link.
246 if ($this->R_URI) {
247 $this->code.='<br />
248 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
249 '<img src="gfx/goback.gif" width="14" height="14" hspace="2" border="0" align="top" alt="" />'.
250 '<strong>'.$LANG->getLL('goBack').'</strong>'.
251 '</a>';
252 }
253 // Add all the content to an output section
254 $this->content.=$this->doc->section('',$this->code);
255 }
256 }
257
258 /**
259 * Creates the position map for pages wizard
260 *
261 * @return void
262 */
263 function pagesOnly() {
264 global $LANG;
265
266 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
267 $this->code.='<br />
268 <strong>'.htmlspecialchars($LANG->getLL('selectPosition')).':</strong><br />
269 <br />
270 ';
271 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
272 }
273
274 /**
275 * Create a regular new element (pages and records)
276 *
277 * @return void
278 */
279 function regularNew() {
280 global $SOBE,$BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA;
281
282 // Slight spacer from header:
283 $this->code.='<img src="'.$BACK_PATH.'t3lib/gfx/ol/halfline.gif" width="18" height="8" align="top" alt="" /><br />';
284
285 // New pages INSIDE this pages
286 if ($this->newPagesInto && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $BE_USER->check('tables_modify','pages')) {
287
288 // Create link to new page inside:
289 $t='pages';
290 $v=$TCA[$t];
291 $this->code.=$this->linkWrap(
292 '<img src="'.$BACK_PATH.'t3lib/gfx/ol/join.gif" width="18" height="16" align="top" border="0" alt="" />'.
293 '<img src="'.$BACK_PATH.'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif').'" width="18" height="16" align="top" border="0" alt="" /> '.
294 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
295 $t,
296 $this->id);
297
298 // Link to CSH:
299 if (isset($TCA_DESCR[$t]['columns'][''])) {
300 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
301 $this->code.='<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
302 '<img src="gfx/helpbubble.gif" width="14" height="14" hspace="4" border="0" align="absmiddle"'.$this->doc->helpStyle().' alt="" />'.
303 '</a>';
304 }
305 $this->code.='<br />
306 ';
307
308 // Link to page-wizard:
309 $this->code.='<img src="gfx/ol/line.gif" width="18" height="16" border="0" align="top" alt="" /><img src="gfx/ol/joinbottom.gif" width="18" height="16" border="0" align="top" alt="" />'.
310 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
311 '<img src="gfx/new_page.gif" width="13" height="12" border="0" align="top" alt="" /> '.
312 htmlspecialchars($LANG->getLL('clickForWizard')).
313 '</a><br />
314 ';
315 $this->code.='<img src="gfx/ol/halfline.gif" width="18" height="8" border="0" align="top" alt="" /><br />
316 ';
317 }
318
319 // New tables (but not pages) INSIDE this pages
320 if ($this->newContentInto) {
321 if (is_array($TCA)) {
322 reset($TCA);
323 while(list($t,$v)=each($TCA)) {
324 if ($t!='pages'
325 && $this->showNewRecLink($t)
326 && $this->isTableAllowedForThisPage($this->pageinfo, $t)
327 && $BE_USER->check('tables_modify',$t)
328 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
329 ) {
330
331 // Create new link for record:
332 $this->code.=$this->linkWrap(
333 '<img src="'.$BACK_PATH.'t3lib/gfx/ol/join.gif" width="18" height="16" align="top" border="0" alt="" />'.
334 '<img src="'.$BACK_PATH.t3lib_iconWorks::getIcon($t).'" width="18" height="16" align="top" border="0" alt="" /> '.
335 $LANG->sL($v['ctrl']['title'],1)
336 ,$t
337 ,$this->id);
338
339 // Create CSH link for table:
340 if ($BE_USER->uc['edit_showFieldHelp']) {
341 $LANG->loadSingleTableDescription($t);
342 if (isset($TCA_DESCR[$t]['columns'][''])) {
343 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
344 $this->code.='<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
345 '<img src="gfx/helpbubble.gif" width="14" height="14" hspace="4" border="0" align="absmiddle"'.$this->doc->helpStyle().' alt="" />'.
346 '</a>';
347 }
348 }
349 $this->code.='<br />
350 ';
351
352 // If the table is 'tt_content' (from "cms" extension), create link to wizard
353 if ($t=='tt_content') {
354 $href = 'db_new_content_el.php?id='.$this->id.'&returnUrl='.rawurlencode($this->R_URI);
355 $this->code.='<img src="gfx/ol/line.gif" width="18" height="16" border="0" align="top" alt="" />'.
356 '<img src="gfx/ol/joinbottom.gif" width="18" height="16" border="0" align="top" alt="" />'.
357 '<a href="'.htmlspecialchars($href).'"><img src="gfx/new_record.gif" width="16" height="12" border="0" align="top" alt="" /> '.
358 htmlspecialchars($LANG->getLL('clickForWizard')).
359 '</a><br />
360 ';
361 $this->code.='<img src="gfx/ol/halfline.gif" width="18" height="8" border="0" align="top" alt="" /><br />
362 ';
363 }
364 }
365 }
366 }
367 }
368
369 // New pages AFTER this pages
370 if ($this->newPagesAfter && $this->isTableAllowedForThisPage($this->pidInfo,'pages') && $BE_USER->check('tables_modify','pages')) {
371
372 // Create link to new page after
373 $t='pages';
374 $v=$TCA[$t];
375 $this->code.=$this->linkWrap(
376 '<img src="'.$BACK_PATH.t3lib_iconWorks::getIcon($t).'" width="18" height="16" align="top" border="0" alt="" /> '.
377 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
378 "pages",
379 -$this->id);
380
381 // Link to CSH for pages table:
382 if (isset($TCA_DESCR[$t]['columns'][''])) {
383 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
384 $this->code.='<a href="#" onclick="'.htmlspecialchars($onCLick).'">'.
385 '<img src="gfx/helpbubble.gif" width="14" height="14" hspace="4" border="0" align="absmiddle"'.$this->doc->helpStyle().' alt="" />'.
386 '</a>';
387 }
388 $this->code.='<br />
389 ';
390 } else {
391 $this->code.='<img src="'.$BACK_PATH.'t3lib/gfx/ol/stopper.gif" width="18" height="16" align="top" alt="" /><br />
392 ';
393 }
394
395 // Create a link to the new-pages wizard.
396 if ($this->showNewRecLink('pages')) {
397 $this->code.='<br />
398 <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
399 '<img src="gfx/new_page.gif" width="13" height="12" border="0" align="top" alt="" />'.
400 '<img src="clear.gif" width="3" height="1" align="top" border="0" alt="" /><strong>'.
401 htmlspecialchars($LANG->getLL('createNewPage')).
402 '</strong></a><br />
403 ';
404 }
405 }
406
407 /**
408 * Ending page output and echo'ing content to browser.
409 *
410 * @return void
411 */
412 function printContent() {
413 $this->content.= $this->doc->endPage();
414 echo $this->content;
415 }
416
417 /**
418 * Links the string $code to a create-new form for a record in $table created on page $pid
419 *
420 * @param string Link string
421 * @param string Table name (in which to create new record)
422 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
423 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
424 * @return string The link.
425 */
426 function linkWrap($code,$table,$pid,$addContentTable=0) {
427 $params = '&edit['.$table.']['.$pid.']=new'.
428 ($table=='pages'
429 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
430 && isset($GLOBALS["TCA"][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
431 && $addContentTable ?
432 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1' :
433 ''
434 );
435 $onClick = t3lib_BEfunc::editOnClick($params,'',t3lib_div::GPvar('returnUrl'));
436 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
437 }
438
439 /**
440 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
441 *
442 * @param array Record for parent page.
443 * @param string Table name to check
444 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
445 */
446 function isTableAllowedForThisPage($pid_row, $checkTable) {
447 global $TCA, $PAGES_TYPES;
448 if (!is_array($pid_row)) {
449 if ($GLOBALS['BE_USER']->user['admin']) {
450 return true;
451 } else {
452 return false;
453 }
454 }
455 // be_users and be_groups may not be created anywhere but in the root.
456 if ($checkTable=='be_users' || $checkTable=='be_groups') {
457 return false;
458 }
459 // Checking doktype:
460 $doktype = intval($pid_row['doktype']);
461 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
462 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
463 }
464 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
465 return true;
466 }
467 }
468
469 /**
470 * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
471 *
472 * @param string Table name to test if in allowedTables
473 * @param array Array of new tables that are allowed.
474 * @return boolean Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
475 */
476 function showNewRecLink($table,$allowedNewTables='') {
477 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
478 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
479 }
480 }
481
482 // Include extension?
483 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']) {
484 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
485 }
486
487
488
489
490
491 // Make instance:
492 $SOBE = t3lib_div::makeInstance('SC_db_new');
493 $SOBE->init();
494 $SOBE->main();
495 $SOBE->printContent();
496 ?>