2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * New database item menu
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
34 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
37 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
40 * [CLASS/FUNCTION INDEX of SCRIPT]
44 * 90: class localPageTree extends t3lib_pageTree
45 * 99: function wrapIcon($icon,$row)
46 * 110: function expandNext($id)
49 * 128: class SC_db_new
50 * 157: function init()
51 * 217: function main()
52 * 269: function pagesOnly()
53 * 287: function regularNew()
54 * 442: function printContent()
55 * 456: function linkWrap($code,$table,$pid,$addContentTable=0)
56 * 476: function isTableAllowedForThisPage($pid_row, $checkTable)
57 * 506: function showNewRecLink($table,$allowedNewTables='')
60 * (This index is automatically created/updated by the extension "extdeveval")
69 require('template.php');
70 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
72 // ***************************
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');
84 * Extension for the tree class that generates the tree of pages in the page-wizard mode
86 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
90 class localPageTree
extends t3lib_pageTree
{
93 * Inserting uid-information in title-text for an icon
95 * @param string Icon image
96 * @param array Item row
97 * @return string Wrapping icon image.
99 function wrapIcon($icon,$row) {
100 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
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
107 * @param integer The ID (page id) of the element
108 * @return boolean Returns true if the IDs matches
110 function expandNext($id) {
111 return $id==$GLOBALS['SOBE']->id ?
1 : 0;
122 * Script class for 'db_new'
124 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
134 var $web_list_modTSconfig;
135 var $allowedNewTables;
136 var $web_list_modTSconfig_pid;
137 var $allowedNewTables_pid;
141 // Internal, static: GPvar
142 var $id; // see init()
143 var $returnUrl; // Return url.
144 var $pagesOnly; // pagesOnly flag.
147 var $perms_clause; // see init()
148 var $doc; // see init()
149 var $content; // Accumulated HTML output
153 * Constructor function for the class
158 global $BE_USER,$LANG,$BACK_PATH;
160 // page-selection permission clause (reading)
161 $this->perms_clause
= $BE_USER->getPagePermsClause(1);
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');
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
='';
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'));
179 // Id a positive id is supplied, ask for the page record with permission information contained:
181 $this->pageinfo
= t3lib_BEfunc
::readPageAccess($this->id
,$this->perms_clause
);
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;
192 if ($BE_USER->doesUserHaveAccess($this->pageinfo
,16)) {
193 $this->newContentInto
=1;
196 if (($BE_USER->isAdmin()||
is_array($this->pidInfo
)) && $BE_USER->doesUserHaveAccess($this->pidInfo
,8)) {
197 $this->newPagesAfter
=1;
199 } elseif ($BE_USER->isAdmin()) {
200 // Admins can do it all
201 $this->newPagesInto
=1;
202 $this->newContentInto
=1;
203 $this->newPagesAfter
=0;
205 // People with no permission can do nothing
206 $this->newPagesInto
=0;
207 $this->newContentInto
=0;
208 $this->newPagesAfter
=0;
213 * Main processing, creating the list of new record tables to select from
218 global $BE_USER,$LANG;
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);
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);
231 if (!$this->showNewRecLink('pages')) {
232 $this->newPagesInto
=0;
234 if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid
)) {
235 $this->newPagesAfter
=0;
239 // Set header-HTML and return_url
240 $this->code
=$this->doc
->getHeader('pages',$this->pageinfo
,$this->pageinfo
['_thePath']).'<br />
242 $this->R_URI
=$this->returnUrl
;
244 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
245 if (!$this->pagesOnly
) { // Regular new element:
247 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
251 // Create go-back link.
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).
259 // Add all the content to an output section
260 $this->content
.=$this->doc
->section('',$this->code
);
265 * Creates the position map for pages wizard
269 function pagesOnly() {
272 $posMap = t3lib_div
::makeInstance('t3lib_positionMap');
274 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
276 $this->code
.= $posMap->positionTree($this->id
,$this->pageinfo
,$this->perms_clause
,$this->R_URI
);
279 $this->code
.= t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
283 * Create a regular new element (pages and records)
287 function regularNew() {
288 global $BE_USER,$LANG,$BACK_PATH,$TCA;
290 $doNotShowFullDescr = FALSE;
292 // Slight spacer from header:
293 $this->code
.='<img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
295 // Initialize array for accumulating table rows:
298 // New pages INSIDE this pages
299 if ($this->newPagesInto
&& $this->isTableAllowedForThisPage($this->pageinfo
, 'pages') && $BE_USER->check('tables_modify','pages')) {
301 // Create link to new page inside:
304 $rowContent = '<img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
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).')',
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')).
318 $rowContent.= '<br /><img'.t3lib_iconWorks
::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
320 // Compile table row:
323 <td nowrap="nowrap">'.$rowContent.'</td>
324 <td>'.t3lib_BEfunc
::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
329 // New tables (but not pages) INSIDE this pages
330 if ($this->newContentInto
) {
331 if (is_array($TCA)) {
332 foreach($TCA as $t => $v) {
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)
340 // Create new link for record:
341 $rowContent = '<img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
343 t3lib_iconWorks
::getIconImage($t,array(),$BACK_PATH,'').
344 $LANG->sL($v['ctrl']['title'],1)
348 // If the table is 'tt_content' (from "cms" extension), create link to wizard
349 if ($t=='tt_content') {
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';
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')).
363 $rowContent.= '<br /><img'.t3lib_iconWorks
::skinImg($this->doc
->backPath
,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
367 // Compile table row:
370 <td nowrap="nowrap">'.$rowContent.'</td>
371 <td>'.t3lib_BEfunc
::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
380 // New pages AFTER this pages
381 if ($this->newPagesAfter
&& $this->isTableAllowedForThisPage($this->pidInfo
,'pages') && $BE_USER->check('tables_modify','pages')) {
383 // Create link to new page after
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).')',
393 // Compile table row:
396 <td nowrap="nowrap">'.$rowContent.'</td>
397 <td>'.t3lib_BEfunc
::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
401 // Compile table row:
404 <td><img'.t3lib_iconWorks
::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
412 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
413 '.implode('',$tRows).'
417 // Create a link to the new-pages wizard.
418 if ($this->showNewRecLink('pages')) {
422 Link; create new page:
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')).
434 $this->code
.= t3lib_BEfunc
::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
438 * Ending page output and echo'ing content to browser.
442 function printContent() {
443 $this->content
.= $this->doc
->endPage();
448 * Links the string $code to a create-new form for a record in $table created on page $pid
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.
456 function linkWrap($code,$table,$pid,$addContentTable=0) {
457 $params = '&edit['.$table.']['.$pid.']=new'.
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' :
465 $onClick = t3lib_BEfunc
::editOnClick($params,'',$this->returnUrl
);
466 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
470 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
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
476 function isTableAllowedForThisPage($pid_row, $checkTable) {
477 global $TCA, $PAGES_TYPES;
478 if (!is_array($pid_row)) {
479 if ($GLOBALS['BE_USER']->user
['admin']) {
485 // be_users and be_groups may not be created anywhere but in the root.
486 if ($checkTable=='be_users' ||
$checkTable=='be_groups') {
490 $doktype = intval($pid_row['doktype']);
491 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
492 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
494 if (strstr($allowedTableList,'*') || t3lib_div
::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
500 * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
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)
506 function showNewRecLink($table,$allowedNewTables='') {
507 $allowedNewTables = is_array($allowedNewTables) ?
$allowedNewTables : $this->allowedNewTables
;
508 return !count($allowedNewTables) ||
in_array($table,$allowedNewTables);
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']);
522 $SOBE = t3lib_div
::makeInstance('SC_db_new');
525 $SOBE->printContent();