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