Changed lots of stuff...
[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 * 158: function init()
51 * 218: function main()
52 * 275: function pagesOnly()
53 * 290: function regularNew()
54 * 428: function printContent()
55 * 442: function linkWrap($code,$table,$pid,$addContentTable=0)
56 * 462: function isTableAllowedForThisPage($pid_row, $checkTable)
57 * 492: 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 $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('smallDoc');
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 // If CSH is enabled (Context Sensitive Help), load descriptions for 'pages' in any case:
245 if ($BE_USER->uc['edit_showFieldHelp']) {
246 $LANG->loadSingleTableDescription('pages');
247 }
248
249 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
250 if (!$this->pagesOnly) { // Regular new element:
251 $this->regularNew();
252 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
253 $this->pagesOnly();
254 }
255
256 // Create go-back link.
257 if ($this->R_URI) {
258 $this->code.='<br />
259 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
260 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
261 $LANG->getLL('goBack',1).
262 '</a>';
263 }
264 // Add all the content to an output section
265 $this->content.=$this->doc->section('',$this->code);
266 }
267 }
268
269 /**
270 * Creates the position map for pages wizard
271 *
272 * @return void
273 */
274 function pagesOnly() {
275 global $LANG;
276
277 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
278 $this->code.='
279 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
280 ';
281 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
282 }
283
284 /**
285 * Create a regular new element (pages and records)
286 *
287 * @return void
288 */
289 function regularNew() {
290 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA;
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 // New pages INSIDE this pages
296 if ($this->newPagesInto && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $BE_USER->check('tables_modify','pages')) {
297
298 // Create link to new page inside:
299 $t='pages';
300 $v=$TCA[$t];
301 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
302 $this->linkWrap(
303 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
304 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
305 $t,
306 $this->id);
307
308 // Link to CSH:
309 if (isset($TCA_DESCR[$t]['columns'][''])) {
310 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
311 $this->code.='<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
312 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/helpbubble.gif','width="14" height="14"').' class="c-helpImg" align="right"'.$this->doc->helpStyle().' alt="" />'.
313 '</a>';
314 }
315 $this->code.='<br />
316 ';
317
318 // Link to page-wizard:
319 $this->code.='<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="" />'.
320 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
321 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
322 htmlspecialchars($LANG->getLL('clickForWizard')).
323 '</a><br />
324 ';
325 $this->code.='<img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />
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 $this->code.='<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 // Create CSH link for table:
349 if ($BE_USER->uc['edit_showFieldHelp']) {
350 $LANG->loadSingleTableDescription($t);
351 if (isset($TCA_DESCR[$t]['columns'][''])) {
352 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
353 $this->code.='<a href="#" onclick="'.htmlspecialchars($onClick).'">'.
354 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/helpbubble.gif','width="14" height="14"').' class="c-helpImg" align="right"'.$this->doc->helpStyle().' alt="" />'.
355 '</a>';
356 }
357 }
358 $this->code.='<br />
359 ';
360
361 // If the table is 'tt_content' (from "cms" extension), create link to wizard
362 if ($t=='tt_content') {
363
364 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
365 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
366 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
367
368 $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode($this->R_URI);
369 $this->code.='<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
370 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
371 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
372 htmlspecialchars($LANG->getLL('clickForWizard')).
373 '</a><br />
374 ';
375 $this->code.='<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />
376 ';
377 }
378 }
379 }
380 }
381 }
382
383 // New pages AFTER this pages
384 if ($this->newPagesAfter && $this->isTableAllowedForThisPage($this->pidInfo,'pages') && $BE_USER->check('tables_modify','pages')) {
385
386 // Create link to new page after
387 $t='pages';
388 $v=$TCA[$t];
389 $this->code.=$this->linkWrap(
390 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
391 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
392 'pages',
393 -$this->id
394 );
395
396 // Link to CSH for pages table:
397 if (isset($TCA_DESCR[$t]['columns'][''])) {
398 $onClick = 'vHWin=window.open(\'view_help.php?tfID='.$t.'.\',\'viewFieldHelp\',\'height=300,width=250,status=0,menubar=0,scrollbars=1\');vHWin.focus();return false;';
399 $this->code.='<a href="#" onclick="'.htmlspecialchars($onCLick).'">'.
400 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/helpbubble.gif','width="14" height="14"').' class="c-helpImg" align="right"'.$this->doc->helpStyle().' alt="" />'.
401 '</a>';
402 }
403 $this->code.='<br />
404 ';
405 } else {
406 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /><br />
407 ';
408 }
409
410 // Create a link to the new-pages wizard.
411 if ($this->showNewRecLink('pages')) {
412 $this->code.='
413
414 <!--
415 Link; create new page:
416 -->
417 <div id="typo3-newPageLink">
418 <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
419 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
420 htmlspecialchars($LANG->getLL('createNewPage')).
421 '</a>
422 </div>
423 ';
424 }
425 }
426
427 /**
428 * Ending page output and echo'ing content to browser.
429 *
430 * @return void
431 */
432 function printContent() {
433 $this->content.= $this->doc->endPage();
434 echo $this->content;
435 }
436
437 /**
438 * Links the string $code to a create-new form for a record in $table created on page $pid
439 *
440 * @param string Link string
441 * @param string Table name (in which to create new record)
442 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
443 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
444 * @return string The link.
445 */
446 function linkWrap($code,$table,$pid,$addContentTable=0) {
447 $params = '&edit['.$table.']['.$pid.']=new'.
448 ($table=='pages'
449 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
450 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
451 && $addContentTable ?
452 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1' :
453 ''
454 );
455 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
456 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
457 }
458
459 /**
460 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
461 *
462 * @param array Record for parent page.
463 * @param string Table name to check
464 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
465 */
466 function isTableAllowedForThisPage($pid_row, $checkTable) {
467 global $TCA, $PAGES_TYPES;
468 if (!is_array($pid_row)) {
469 if ($GLOBALS['BE_USER']->user['admin']) {
470 return true;
471 } else {
472 return false;
473 }
474 }
475 // be_users and be_groups may not be created anywhere but in the root.
476 if ($checkTable=='be_users' || $checkTable=='be_groups') {
477 return false;
478 }
479 // Checking doktype:
480 $doktype = intval($pid_row['doktype']);
481 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
482 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
483 }
484 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
485 return true;
486 }
487 }
488
489 /**
490 * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
491 *
492 * @param string Table name to test if in allowedTables
493 * @param array Array of new tables that are allowed.
494 * @return boolean Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
495 */
496 function showNewRecLink($table,$allowedNewTables='') {
497 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
498 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
499 }
500 }
501
502 // Include extension?
503 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']) {
504 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
505 }
506
507
508
509
510
511 // Make instance:
512 $SOBE = t3lib_div::makeInstance('SC_db_new');
513 $SOBE->init();
514 $SOBE->main();
515 $SOBE->printContent();
516 ?>