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