TYPO3 API  SVNRelease
db_new.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * New database item menu
00029  *
00030  * This script lets users choose a new database element to create.
00031  * Includes a wizard mode for visually pointing out the position of new pages
00032  *
00033  * $Id: db_new.php 10295 2011-01-25 09:33:06Z baschny $
00034  * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
00035  * XHTML compliant
00036  *
00037  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00038  */
00039 /**
00040  * [CLASS/FUNCTION INDEX of SCRIPT]
00041  *
00042  *
00043  *
00044  *   90: class localPageTree extends t3lib_pageTree
00045  *   99:     function wrapIcon($icon,$row)
00046  *  110:     function expandNext($id)
00047  *
00048  *
00049  *  128: class SC_db_new
00050  *  157:     function init()
00051  *  224:     function main()
00052  *  276:     function pagesOnly()
00053  *  294:     function regularNew()
00054  *  458:     function printContent()
00055  *  473:     function linkWrap($code,$table,$pid,$addContentTable=0)
00056  *  493:     function isTableAllowedForThisPage($pid_row, $checkTable)
00057  *  523:     function showNewRecLink($table,$allowedNewTables='')
00058  *
00059  * TOTAL FUNCTIONS: 10
00060  * (This index is automatically created/updated by the extension "extdeveval")
00061  *
00062  */
00063 
00064 
00065 
00066 
00067 $BACK_PATH='';
00068 require('init.php');
00069 require('template.php');
00070 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00071 
00072 
00073 /**
00074  * Extension for the tree class that generates the tree of pages in the page-wizard mode
00075  *
00076  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00077  * @package TYPO3
00078  * @subpackage core
00079  */
00080 class localPageTree extends t3lib_pageTree {
00081 
00082     /**
00083      * Inserting uid-information in title-text for an icon
00084      *
00085      * @param   string      Icon image
00086      * @param   array       Item row
00087      * @return  string      Wrapping icon image.
00088      */
00089     function wrapIcon($icon,$row)   {
00090         return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
00091     }
00092 
00093     /**
00094      * Determines whether to expand a branch or not.
00095      * Here the branch is expanded if the current id matches the global id for the listing/new
00096      *
00097      * @param   integer     The ID (page id) of the element
00098      * @return  boolean     Returns true if the IDs matches
00099      */
00100     function expandNext($id)    {
00101         return $id==$GLOBALS['SOBE']->id ? 1 : 0;
00102     }
00103 }
00104 
00105 
00106 
00107 
00108 
00109 
00110 
00111 /**
00112  * Script class for 'db_new'
00113  *
00114  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00115  * @package TYPO3
00116  * @subpackage core
00117  */
00118 class SC_db_new {
00119     var $pageinfo;
00120     var $pidInfo;
00121     var $newPagesInto;
00122     var $newContentInto;
00123     var $newPagesAfter;
00124     var $web_list_modTSconfig;
00125     var $allowedNewTables;
00126     var $deniedNewTables;
00127     var $web_list_modTSconfig_pid;
00128     var $allowedNewTables_pid;
00129     var $deniedNewTables_pid;
00130     var $code;
00131     var $R_URI;
00132 
00133         // Internal, static: GPvar
00134     var $id;            // see init()
00135     var $returnUrl;     // Return url.
00136     var $pagesOnly;     // pagesOnly flag.
00137 
00138         // Internal
00139     var $perms_clause;  // see init()
00140 
00141     /**
00142      * Document template object
00143      *
00144      * @var mediumDoc
00145      */
00146     var $doc;
00147     var $content;       // Accumulated HTML output
00148     var $tRows;
00149 
00150     /**
00151      * Constructor function for the class
00152      *
00153      * @return  void
00154      */
00155     function init() {
00156         global $BE_USER,$LANG,$BACK_PATH;
00157 
00158             // page-selection permission clause (reading)
00159         $this->perms_clause = $BE_USER->getPagePermsClause(1);
00160 
00161             // this will hide records from display - it has nothing todo with user rights!!
00162         if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
00163             if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
00164                 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
00165             }
00166         }
00167             // Setting GPvars:
00168         $this->id = intval(t3lib_div::_GP('id'));   // The page id to operate from
00169         $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
00170         $this->pagesOnly = t3lib_div::_GP('pagesOnly');
00171 
00172             // Create instance of template class for output
00173         $this->doc = t3lib_div::makeInstance('template');
00174         $this->doc->backPath = $BACK_PATH;
00175         $this->doc->setModuleTemplate('templates/db_new.html');
00176         $this->doc->JScode='';
00177 
00178             // Setting up the context sensitive menu:
00179         $this->doc->getContextMenuCode();
00180 
00181             // Creating content
00182         $this->content='';
00183         $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
00184 
00185             // Id a positive id is supplied, ask for the page record with permission information contained:
00186         if ($this->id > 0)  {
00187             $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
00188         }
00189 
00190             // If a page-record was returned, the user had read-access to the page.
00191         if ($this->pageinfo['uid']) {
00192                 // Get record of parent page
00193 
00194             $this->pidInfo=t3lib_BEfunc::getRecord('pages',$this->pageinfo['pid']);
00195                 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
00196             if ($BE_USER->doesUserHaveAccess($this->pageinfo,8))    {
00197                 $this->newPagesInto=1;
00198             }
00199             if ($BE_USER->doesUserHaveAccess($this->pageinfo,16))   {
00200                 $this->newContentInto=1;
00201             }
00202 
00203             if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8))  {
00204                 $this->newPagesAfter=1;
00205             }
00206         } elseif ($BE_USER->isAdmin())  {
00207                 // Admins can do it all
00208             $this->newPagesInto=1;
00209             $this->newContentInto=1;
00210             $this->newPagesAfter=0;
00211         } else {
00212                 // People with no permission can do nothing
00213             $this->newPagesInto=0;
00214             $this->newContentInto=0;
00215             $this->newPagesAfter=0;
00216         }
00217     }
00218 
00219     /**
00220      * Main processing, creating the list of new record tables to select from
00221      *
00222      * @return  void
00223      */
00224     function main() {
00225         global $BE_USER,$LANG;
00226 
00227             // If there was a page - or if the user is admin (admins has access to the root) we proceed:
00228         if ($this->pageinfo['uid'] || $BE_USER->isAdmin())  {
00229                 // Acquiring TSconfig for this module/current page:
00230             $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
00231             $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
00232             $this->deniedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['deniedNewTables'],1);
00233 
00234                 // Acquiring TSconfig for this module/parent page:
00235             $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
00236             $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
00237             $this->deniedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['deniedNewTables'],1);
00238 
00239                 // More init:
00240             if (!$this->showNewRecLink('pages'))    {
00241                 $this->newPagesInto=0;
00242             }
00243             if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid))   {
00244                 $this->newPagesAfter=0;
00245             }
00246 
00247 
00248                 // Set header-HTML and return_url
00249             if (is_array($this->pageinfo) && $this->pageinfo['uid'])    {
00250                 $iconImgTag = t3lib_iconWorks::getSpriteIconForRecord('pages', $this->pageinfo, array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
00251                 $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
00252             } else {
00253                 $iconImgTag = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
00254                 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
00255             }
00256 
00257             $this->code = '<span class="typo3-moduleHeader">' . $this->doc->wrapClickMenuOnIcon($iconImgTag, 'pages', $this->pageinfo['uid']) . htmlspecialchars(t3lib_div::fixed_lgd_cs($title, 45)) . '</span><br />';
00258 
00259             $this->R_URI = $this->returnUrl;
00260 
00261                 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
00262             if (!$this->pagesOnly)  {   // Regular new element:
00263                 $this->regularNew();
00264             } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
00265                 $this->pagesOnly();
00266             }
00267 
00268                 // Add all the content to an output section
00269             $this->content.=$this->doc->section('',$this->code);
00270 
00271                             // Setting up the buttons and markers for docheader
00272             $docHeaderButtons = $this->getButtons();
00273             $markers['CSH'] = $docHeaderButtons['csh'];
00274 
00275             $markers['CONTENT'] = $this->content;
00276 
00277                 // Build the <body> for the module
00278             $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
00279             $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
00280             $this->content.= $this->doc->endPage();
00281             $this->content = $this->doc->insertStylesAndJS($this->content);
00282         }
00283     }
00284 
00285     /**
00286      * Create the panel of buttons for submitting the form or otherwise perform operations.
00287      *
00288      * @return  array   all available buttons as an assoc. array
00289      */
00290     protected function getButtons() {
00291         global $LANG, $BACK_PATH;
00292 
00293         $buttons = array(
00294             'csh' => '',
00295             'back' => '',
00296             'view' => '',
00297             'new_page' => '',
00298             'record_list' => ''
00299         );
00300 
00301 
00302         if (!$this->pagesOnly)  {   // Regular new element:
00303                 // New page
00304             if ($this->showNewRecLink('pages')) {
00305                 $buttons['new_page'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $LANG->sL('LLL:EXT:cms/layout/locallang.xml:newPage', 1) . '">' .
00306                         t3lib_iconWorks::getSpriteIcon('actions-page-new') .
00307                     '</a>';
00308             }
00309                 // CSH
00310             $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'], '', TRUE);
00311         } elseif($this->showNewRecLink('pages')) {  // Pages only wizard
00312                 // CSH
00313             $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'], '', TRUE);
00314         }
00315 
00316             // Back
00317         if ($this->R_URI) {
00318             $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', 1) . '">' .
00319                     t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
00320                 '</a>';
00321         }
00322 
00323         if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
00324                 // View
00325             $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(t3lib_BEfunc::viewOnClick($this->pageinfo['uid'], $this->backPath, t3lib_BEfunc::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '">' .
00326                     t3lib_iconWorks::getSpriteIcon('actions-document-view') .
00327                 '</a>';
00328 
00329                 // Record list
00330                 // If access to Web>List for user, then link to that module.
00331             $buttons['record_list'] = t3lib_BEfunc::getListViewLink(
00332                 array(
00333                     'id' => $this->pageinfo['uid'],
00334                     'returnUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
00335                 ),
00336                 $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList')
00337             );
00338         }
00339 
00340 
00341 
00342         return $buttons;
00343     }
00344 
00345     /**
00346      * Creates the position map for pages wizard
00347      *
00348      * @return  void
00349      */
00350     function pagesOnly()    {
00351         global $LANG;
00352 
00353         $posMap = t3lib_div::makeInstance('t3lib_positionMap');
00354         $this->code.='
00355             <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
00356         ';
00357         $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
00358     }
00359 
00360     /**
00361      * Create a regular new element (pages and records)
00362      *
00363      * @return  void
00364      */
00365     function regularNew()   {
00366 
00367         $doNotShowFullDescr = false;
00368             // Initialize array for accumulating table rows:
00369         $this->tRows = array();
00370 
00371             // tree images
00372         $halfLine = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif', 'width="18" height="8"') . ' alt="" />';
00373         $firstLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
00374         $secondLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
00375                         <img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
00376         $secondLevelLast = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif', 'width="18" height="16"') . ' alt="" />
00377                         <img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/joinbottom.gif', 'width="18" height="16"') . ' alt="" />';
00378 
00379             // Slight spacer from header:
00380         $this->code .= $halfLine;
00381 
00382             // New Page
00383         $table = 'pages';
00384         $v = $GLOBALS['TCA'][$table];
00385         $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table,array());
00386 
00387         $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
00388         $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>';
00389 
00390             // New pages INSIDE this pages
00391         if ($this->newPagesInto
00392             && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
00393             && $GLOBALS['BE_USER']->check('tables_modify','pages')
00394             && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
00395             )   {
00396 
00397                 // Create link to new page inside:
00398 
00399             $rowContent .= '<br />' . $secondLevel . $this->linkWrap(
00400                         t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
00401                         $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
00402                         $table,
00403                         $this->id);
00404         }
00405 
00406                 // New pages AFTER this pages
00407         if ($this->newPagesAfter
00408                 && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
00409                 && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
00410                 && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
00411                 )   {
00412 
00413                 $rowContent .= '<br />' . $secondLevel .
00414                 $this->linkWrap(
00415                     $pageIcon .
00416                         $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1) . ')',
00417                     'pages',
00418                     -$this->id
00419                 );
00420 
00421         }
00422 
00423             // Link to page-wizard:
00424         $rowContent.=  '<br />' . $secondLevelLast .
00425             '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
00426             $pageIcon .
00427             htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
00428             '</a>';
00429 
00430             // Half-line:
00431         $rowContent.= '<br />' . $halfLine;
00432 
00433             // Compile table row to show the icon for "new page (select position)"
00434         $startRows = array();
00435         if ($this->showNewRecLink('pages')) {
00436             $startRows[] = '
00437                 <tr>
00438                     <td nowrap="nowrap">' . $rowContent . '</td>
00439                     <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
00440                 </tr>
00441             ';
00442         }
00443 
00444 
00445             // New tables (but not pages) INSIDE this pages
00446         $isAdmin = $GLOBALS['BE_USER']->isAdmin();
00447         $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
00448         if ($this->newContentInto)  {
00449             if (is_array($GLOBALS['TCA']))  {
00450                 $groupName = '';
00451                 foreach($GLOBALS['TCA'] as $table => $v)    {
00452                     $count = count($GLOBALS['TCA'][$table]);
00453                     $counter = 1;
00454                     if ($table != 'pages'
00455                             && $this->showNewRecLink($table)
00456                             && $this->isTableAllowedForThisPage($this->pageinfo, $table)
00457                             && $GLOBALS['BE_USER']->check('tables_modify', $table)
00458                             && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
00459                             && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
00460                             )   {
00461 
00462                         $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
00463                         $rowContent = '';
00464 
00465                             // Create new link for record:
00466                         $newLink = $this->linkWrap(
00467                             $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
00468                             ,$table
00469                             ,$this->id);
00470 
00471                             // If the table is 'tt_content' (from "cms" extension), create link to wizard
00472                         if ($table == 'tt_content') {
00473                             $groupName = $GLOBALS['LANG']->getLL('createNewContent');
00474                             $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
00475                                 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
00476                             $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
00477                             $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
00478 
00479                             $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
00480                             $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
00481                                 $secondLevelLast .
00482                                 '<a href="' . htmlspecialchars($href) . '">' .
00483                                     $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
00484                                 '</a>';
00485 
00486                                 // Half-line added:
00487                             $rowContent.= '<br />' . $halfLine;
00488                         }  else {
00489                             // get the title
00490                             if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
00491                                 continue;
00492                             }
00493                             if ($v['ctrl']['adminOnly'] && !$isAdmin) {
00494                                 continue;
00495                             }
00496                             $nameParts = explode('_', $table);
00497                             $thisTitle = '';
00498                             if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
00499                                 // try to extract extension name
00500                                 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
00501                                     $_EXTKEY = substr($v['ctrl']['title'], 8);
00502                                     $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
00503                                     if ($_EXTKEY != '') {
00504                                         // first try to get localisation of extension title
00505                                         $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
00506                                         $langFile = $temp[0];
00507                                         $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
00508                                         // if no localisation available, read title from ext_emconf.php
00509                                         if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
00510                                             include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
00511                                             $thisTitle = $EM_CONF[$_EXTKEY]['title'];
00512                                         }
00513                                         $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
00514                                     } else {
00515                                         $thisTitle = $nameParts[1];
00516                                         $iconFile[$_EXTKEY] = '';
00517                                     }
00518                                 } else {
00519                                     $thisTitle = $nameParts[1];
00520                                     $iconFile[$_EXTKEY] = '';
00521                                 }
00522                             } else {
00523                                 $_EXTKEY = 'system';
00524                                 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
00525                                 $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
00526                             }
00527 
00528                             if($groupName == '' || $groupName != $_EXTKEY) {
00529                                 $groupName = $_EXTKEY;
00530                             }
00531 
00532                             $rowContent .= $newLink;
00533                             $counter++;
00534 
00535                         }
00536 
00537 
00538                             // Compile table row:
00539                         if ($table == 'tt_content') {
00540                             $startRows[] = '
00541                                 <tr>
00542                                     <td nowrap="nowrap">' . $rowContent . '</td>
00543                                     <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
00544                                 </tr>';
00545                         } else {
00546                             $this->tRows[$groupName]['title'] = $thisTitle;
00547                             $this->tRows[$groupName]['html'][] = $rowContent;
00548                             $this->tRows[$groupName]['table'][] = $table;
00549                         }
00550                     }
00551                 }
00552             }
00553         }
00554 
00555             // user sort
00556         $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
00557         if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
00558             $this->newRecordSortList = t3lib_div::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
00559         }
00560         uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
00561 
00562             // Compile table row:
00563         $finalRows = array();
00564         $finalRows[] = implode('', $startRows);
00565         foreach ($this->tRows as $key => $value) {
00566             $row = '<tr>
00567                         <td nowrap="nowrap">' . $halfLine . '<br />' .
00568                         $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' .
00569                         '</td><td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
00570                         </tr>';
00571             $count = count($value['html']) - 1;
00572             foreach ($value['html'] as $recordKey => $record) {
00573                 $row .= '
00574                     <tr>
00575                         <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
00576                         <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
00577                     </tr>';
00578             }
00579             $finalRows[] = $row;
00580         }
00581 
00582             // end of tree
00583         $finalRows[]='
00584             <tr>
00585                 <td><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif','width="18" height="16"') . ' alt="" /></td>
00586                 <td></td>
00587             </tr>
00588         ';
00589 
00590 
00591             // Make table:
00592         $this->code.='
00593             <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
00594             ' . implode('', $finalRows) . '
00595             </table>
00596         ';
00597     }
00598 
00599     /**
00600      * user array sort function used by regularNew
00601      *
00602      * @param   string      first array element for compare
00603      * @param   string      first array element for compare
00604      * @return  int         -1 for lower, 0 for equal, 1 for greater
00605      */
00606     function sortNewRecordsByConfig($a, $b) {
00607         if (count($this->newRecordSortList)) {
00608             if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
00609                     // both are in the list, return relative to position in array
00610                 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
00611                 $ret = $sub < 0 ? -1 : $sub == 0 ? 0 : 1;
00612             } elseif (in_array($a, $this->newRecordSortList)) {
00613                     // first element is in array, put to top
00614                 $ret = -1;
00615             } elseif (in_array($b, $this->newRecordSortList)) {
00616                     // second element is in array, put first to bottom
00617                 $ret = 1;
00618             } else {
00619                     // no element is in array, return alphabetic order
00620                 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
00621         }
00622             return $ret;
00623         } else {
00624                 // return alphabetic order
00625             return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
00626         }
00627     }
00628 
00629     /**
00630      * Ending page output and echo'ing content to browser.
00631      *
00632      * @return  void
00633      */
00634     function printContent() {
00635         echo $this->content;
00636     }
00637 
00638     /**
00639      * Links the string $code to a create-new form for a record in $table created on page $pid
00640      *
00641      * @param   string      Link text
00642      * @param   string      Table name (in which to create new record)
00643      * @param   integer     PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
00644      * @param   boolean     If $addContentTable is set, then a new contentTable record is created together with pages
00645      * @return  string      The link.
00646      */
00647     function linkWrap($linkText, $table, $pid, $addContentTable = false) {
00648         $parameters = '&edit[' . $table . '][' . $pid . ']=new';
00649 
00650         if ($table == 'pages'
00651             && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
00652             && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
00653             && $addContentTable) {
00654             $parameters .= '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1';
00655         } elseif ($table == 'pages_language_overlay') {
00656             $parameters .= '&overrideVals[pages_language_overlay][doktype]='
00657                         . (int) $this->pageinfo['doktype'];
00658         }
00659 
00660         $onClick = t3lib_BEfunc::editOnClick($parameters, '', $this->returnUrl);
00661 
00662         return '<a href="#" onclick="'.htmlspecialchars($onClick).'">' . $linkText . '</a>';
00663     }
00664 
00665     /**
00666      * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
00667      *
00668      * @param   array       Record for parent page.
00669      * @param   string      Table name to check
00670      * @return  boolean     Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
00671      */
00672     function isTableAllowedForThisPage($pid_row, $checkTable)   {
00673         global $TCA, $PAGES_TYPES;
00674         if (!is_array($pid_row))    {
00675             if ($GLOBALS['BE_USER']->user['admin']) {
00676                 return true;
00677             } else {
00678                 return false;
00679             }
00680         }
00681             // be_users and be_groups may not be created anywhere but in the root.
00682         if ($checkTable=='be_users' || $checkTable=='be_groups')    {
00683             return false;
00684         }
00685             // Checking doktype:
00686         $doktype = intval($pid_row['doktype']);
00687         if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables'])   {
00688             $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
00689         }
00690         if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable))  {       // If all tables or the table is listed as a allowed type, return true
00691             return true;
00692         }
00693     }
00694 
00695     /**
00696      * Returns true if:
00697      * - $allowedNewTables and $deniedNewTables are empty
00698      * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
00699      *
00700      * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
00701      * has priority over $allowedNewTables.
00702      *
00703      * @param   string      Table name to test if in allowedTables
00704      * @param   array       Array of new tables that are allowed.
00705      * @param   array       Array of new tables that are not allowed.
00706      * @return  boolean     Returns true if a link for creating new records should be displayed for $table
00707      */
00708     function showNewRecLink($table, array $allowedNewTables=array(), array $deniedNewTables=array()) {
00709         $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
00710         $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
00711             // No deny/allow tables are set:
00712         if (!count($allowedNewTables) && !count($deniedNewTables)) {
00713             return true;
00714             // If table is not denied (which takes precedence over allowed tables):
00715         } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
00716             return true;
00717             // If table is denied or allowed tables are set, but table is not part of:
00718         } else {
00719             return false;
00720         }
00721     }
00722 }
00723 
00724 
00725 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php'])) {
00726     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
00727 }
00728 
00729 
00730 
00731 // Make instance:
00732 $SOBE = t3lib_div::makeInstance('SC_db_new');
00733 $SOBE->init();
00734 $SOBE->main();
00735 $SOBE->printContent();
00736 
00737 ?>