[BUGFIX] Warning in list module
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
old mode 100755 (executable)
new mode 100644 (file)
index f3404a1..e8518ee
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
  * Includes a wizard mode for visually pointing out the position of new pages
  *
  * $Id$
- * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
+ * Revised for TYPO3 3.6 November/2003 by Kasper Skårhøj
  * XHTML compliant
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  */
 /**
  * [CLASS/FUNCTION INDEX of SCRIPT]
@@ -69,21 +69,11 @@ require('init.php');
 require('template.php');
 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
 
-// ***************************
-// Including classes
-// ***************************
-require_once(PATH_t3lib.'class.t3lib_page.php');
-require_once(PATH_t3lib.'class.t3lib_positionmap.php');
-require_once(PATH_t3lib.'class.t3lib_pagetree.php');
-
-
-
-
 
 /**
  * Extension for the tree class that generates the tree of pages in the page-wizard mode
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -121,7 +111,7 @@ class localPageTree extends t3lib_pageTree {
 /**
  * Script class for 'db_new'
  *
- * @author     Kasper Skaarhoj <kasperYYYY@typo3.com>
+ * @author     Kasper Skårhøj <kasperYYYY@typo3.com>
  * @package TYPO3
  * @subpackage core
  */
@@ -133,8 +123,10 @@ class SC_db_new {
        var $newPagesAfter;
        var $web_list_modTSconfig;
        var $allowedNewTables;
+       var $deniedNewTables;
        var $web_list_modTSconfig_pid;
        var $allowedNewTables_pid;
+       var $deniedNewTables_pid;
        var $code;
        var $R_URI;
 
@@ -145,9 +137,15 @@ class SC_db_new {
 
                // Internal
        var $perms_clause;      // see init()
-       var $doc;                       // see init()
-       var $content;           // Accumulated HTML output
 
+       /**
+        * Document template object
+        *
+        * @var mediumDoc
+        */
+       var $doc;
+       var $content;           // Accumulated HTML output
+    var $tRows;
 
        /**
         * Constructor function for the class
@@ -168,18 +166,20 @@ class SC_db_new {
                }
                        // Setting GPvars:
                $this->id = intval(t3lib_div::_GP('id'));       // The page id to operate from
-               $this->returnUrl = t3lib_div::_GP('returnUrl');
+               $this->returnUrl = t3lib_div::sanitizeLocalUrl(t3lib_div::_GP('returnUrl'));
                $this->pagesOnly = t3lib_div::_GP('pagesOnly');
 
                        // Create instance of template class for output
-               $this->doc = t3lib_div::makeInstance('mediumDoc');
+               $this->doc = t3lib_div::makeInstance('template');
                $this->doc->backPath = $BACK_PATH;
-               $this->doc->docType= 'xhtml_trans';
+               $this->doc->setModuleTemplate('templates/db_new.html');
                $this->doc->JScode='';
 
+                       // Setting up the context sensitive menu:
+               $this->doc->getContextMenuCode();
+
                        // Creating content
                $this->content='';
-               $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
                $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
 
                        // Id a positive id is supplied, ask for the page record with permission information contained:
@@ -229,24 +229,34 @@ class SC_db_new {
                                // Acquiring TSconfig for this module/current page:
                        $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
                        $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
+                       $this->deniedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['deniedNewTables'],1);
 
                                // Acquiring TSconfig for this module/parent page:
                        $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
                        $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
+                       $this->deniedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['deniedNewTables'],1);
 
                                // More init:
                        if (!$this->showNewRecLink('pages'))    {
                                $this->newPagesInto=0;
                        }
-                       if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid))        {
+                       if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid))   {
                                $this->newPagesAfter=0;
                        }
 
 
                                // Set header-HTML and return_url
-                       $this->code=$this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
-                       ';
-                       $this->R_URI=$this->returnUrl;
+                       if (is_array($this->pageinfo) && $this->pageinfo['uid'])        {
+                               $iconImgTag = t3lib_iconWorks::getSpriteIconForRecord('pages', $this->pageinfo, array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
+                               $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
+                       } else {
+                               $iconImgTag = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
+                               $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
+                       }
+
+                       $this->code = '<span class="typo3-moduleHeader">' . $this->doc->wrapClickMenuOnIcon($iconImgTag, 'pages', $this->pageinfo['uid']) . htmlspecialchars(t3lib_div::fixed_lgd_cs($title, 45)) . '</span><br />';
+
+                       $this->R_URI = $this->returnUrl;
 
                                // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
                        if (!$this->pagesOnly)  {       // Regular new element:
@@ -255,17 +265,81 @@ class SC_db_new {
                                $this->pagesOnly();
                        }
 
-                               // Create go-back link.
-                       if ($this->R_URI)       {
-                               $this->code.='<br />
-               <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
-               '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
-               $LANG->getLL('goBack',1).
-               '</a>';
-                       }
                                // Add all the content to an output section
                        $this->content.=$this->doc->section('',$this->code);
+
+                                                       // Setting up the buttons and markers for docheader
+                       $docHeaderButtons = $this->getButtons();
+                       $markers['CSH'] = $docHeaderButtons['csh'];
+
+                       $markers['CONTENT'] = $this->content;
+
+                               // Build the <body> for the module
+                       $this->content = $this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
+                       $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
+                       $this->content.= $this->doc->endPage();
+                       $this->content = $this->doc->insertStylesAndJS($this->content);
+               }
+       }
+
+       /**
+        * Create the panel of buttons for submitting the form or otherwise perform operations.
+        *
+        * @return      array   all available buttons as an assoc. array
+        */
+       protected function getButtons() {
+               global $LANG, $BACK_PATH;
+
+               $buttons = array(
+                       'csh' => '',
+                       'back' => '',
+                       'view' => '',
+                       'new_page' => '',
+                       'record_list' => ''
+               );
+
+
+               if (!$this->pagesOnly)  {       // Regular new element:
+                               // New page
+                       if ($this->showNewRecLink('pages'))     {
+                               $buttons['new_page'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $LANG->sL('LLL:EXT:cms/layout/locallang.xml:newPage', 1) . '">' .
+                                               t3lib_iconWorks::getSpriteIcon('actions-page-new') .
+                                       '</a>';
+                       }
+                               // CSH
+                       $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'], '', TRUE);
+               } elseif($this->showNewRecLink('pages')) {      // Pages only wizard
+                               // CSH
+                       $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'], '', TRUE);
+               }
+
+                       // Back
+               if ($this->R_URI) {
+                       $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.goBack', 1) . '">' .
+                                       t3lib_iconWorks::getSpriteIcon('actions-view-go-back') .
+                               '</a>';
                }
+
+               if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
+                               // View
+                       $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) . '">' .
+                                       t3lib_iconWorks::getSpriteIcon('actions-document-view') .
+                               '</a>';
+
+                               // Record list
+                               // If access to Web>List for user, then link to that module.
+                       $buttons['record_list'] = t3lib_BEfunc::getListViewLink(
+                               array(
+                                       'id' => $this->pageinfo['uid'],
+                                       'returnUrl' => t3lib_div::getIndpEnv('REQUEST_URI'),
+                               ),
+                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList')
+                       );
+               }
+
+
+
+               return $buttons;
        }
 
        /**
@@ -275,15 +349,22 @@ class SC_db_new {
         */
        function pagesOnly()    {
                global $LANG;
-
-               $posMap = t3lib_div::makeInstance('t3lib_positionMap');
-               $this->code.='
-                       <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
-               ';
-               $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
-
-                               // Add CSH:
-               $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
+               $numberOfPages = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'pages', '1=1' . t3lib_BEfunc::deleteClause('pages'));
+               if ($numberOfPages > 0) {
+                       $posMap = t3lib_div::makeInstance('t3lib_positionMap');
+                       $this->code.='
+                               <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
+                       ';
+                       $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
+               } else {
+                       // No pages yet, no need to prompt for position, redirect to page creation.
+                       $javascript = t3lib_BEfunc::editOnClick('returnUrl=%2Ftypo3%2Fdb_new.php%3Fid%3D0%26pagesOnly%3D1&edit[pages][0]=new&returnNewPageId=1');
+                       $startPos = strpos($javascript, 'href=\'') + 6;
+                       $endPos = strpos($javascript, '\';');
+                       $url = substr($javascript, $startPos, $endPos - $startPos);
+                       @ob_end_clean();
+                       t3lib_utility_Http::redirect($url);
+               }
        }
 
        /**
@@ -292,162 +373,267 @@ class SC_db_new {
         * @return      void
         */
        function regularNew()   {
-               global $BE_USER,$LANG,$BACK_PATH,$TCA;
 
-               $doNotShowFullDescr = FALSE;
+               $doNotShowFullDescr = false;
+                       // Initialize array for accumulating table rows:
+               $this->tRows = array();
+
+                       // tree images
+               $halfLine = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif', 'width="18" height="8"') . ' alt="" />';
+               $firstLevel = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/join.gif', 'width="18" height="16"') . ' alt="" />';
+               $secondLevel = '<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/join.gif', 'width="18" height="16"') . ' alt="" />';
+               $secondLevelLast = '<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="" />';
 
                        // Slight spacer from header:
-               $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
+               $this->code .= $halfLine;
 
-                       // Initialize array for accumulating table rows:
-               $tRows = array();
+                       // New Page
+               $table = 'pages';
+               $v = $GLOBALS['TCA'][$table];
+               $pageIcon = t3lib_iconWorks::getSpriteIconForRecord($table,array());
+
+               $newPageIcon = t3lib_iconWorks::getSpriteIcon('actions-page-new');
+               $rowContent = $firstLevel . $newPageIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewPage') . '</strong>';
 
                        // New pages INSIDE this pages
                if ($this->newPagesInto
                        && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
-                       && $BE_USER->check('tables_modify','pages')
-                       && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
+                       && $GLOBALS['BE_USER']->check('tables_modify','pages')
+                       && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
                        )       {
 
                                // Create link to new page inside:
-                       $t = 'pages';
-                       $v = $TCA[$t];
-                       $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
-                                       $this->linkWrap(
-                                               '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
-                                                       $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
-                                               $t,
-                                               $this->id).'<br/>';
-
-                               // Link to page-wizard:
-                       $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="" />'.
-                               '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
-                               '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
-                               htmlspecialchars($LANG->getLL('clickForWizard')).
-                               '</a>';
-                               // Half-line:
-                       $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
 
-                               // Compile table row:
-                       $tRows[]='
+                       $rowContent .= '<br />' . $secondLevel . $this->linkWrap(
+                                               t3lib_iconWorks::getSpriteIconForRecord($table, array()) .
+                                               $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside', 1) . ')',
+                                               $table,
+                                               $this->id);
+               }
+
+                               // New pages AFTER this pages
+               if ($this->newPagesAfter
+                               && $this->isTableAllowedForThisPage($this->pidInfo, 'pages')
+                               && $GLOBALS['BE_USER']->check('tables_modify', 'pages')
+                               && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
+                               )       {
+
+                               $rowContent .= '<br />' . $secondLevel .
+                               $this->linkWrap(
+                                       $pageIcon .
+                                               $GLOBALS['LANG']->sL($v['ctrl']['title'], 1) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1) . ')',
+                                       'pages',
+                                       -$this->id
+                               );
+
+               }
+
+                       // Link to page-wizard:
+               $rowContent.=  '<br />' . $secondLevelLast .
+                       '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => 1))) . '">' .
+                       $pageIcon .
+                       htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) .
+                       '</a>';
+
+                       // Half-line:
+               $rowContent.= '<br />' . $halfLine;
+
+                       // Compile table row to show the icon for "new page (select position)"
+               $startRows = array();
+               if ($this->showNewRecLink('pages')) {
+                       $startRows[] = '
                                <tr>
-                                       <td nowrap="nowrap">'.$rowContent.'</td>
-                                       <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
+                                       <td nowrap="nowrap">' . $rowContent . '</td>
+                                       <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
                                </tr>
                        ';
                }
 
+
                        // New tables (but not pages) INSIDE this pages
+               $isAdmin = $GLOBALS['BE_USER']->isAdmin();
+               $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
                if ($this->newContentInto)      {
-                       if (is_array($TCA))     {
-                               foreach($TCA as $t => $v)       {
-                                       if ($t!='pages'
-                                                       && $this->showNewRecLink($t)
-                                                       && $this->isTableAllowedForThisPage($this->pageinfo, $t)
-                                                       && $BE_USER->check('tables_modify',$t)
-                                                       && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
-                                                       && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, $t)
+                       if (is_array($GLOBALS['TCA']))  {
+                               $groupName = '';
+                               foreach($GLOBALS['TCA'] as $table => $v)        {
+                                       $count = count($GLOBALS['TCA'][$table]);
+                                       $counter = 1;
+                                       if ($table != 'pages'
+                                                       && $this->showNewRecLink($table)
+                                                       && $this->isTableAllowedForThisPage($this->pageinfo, $table)
+                                                       && $GLOBALS['BE_USER']->check('tables_modify', $table)
+                                                       && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
+                                                       && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
                                                        )       {
 
+                                               $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
+                                               $rowContent = '';
+
                                                        // Create new link for record:
-                                               $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
-                                                               $this->linkWrap(
-                                                               t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
-                                                               $LANG->sL($v['ctrl']['title'],1)
-                                                       ,$t
+                                               $newLink = $this->linkWrap(
+                                                       $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
+                                                       ,$table
                                                        ,$this->id);
 
                                                        // If the table is 'tt_content' (from "cms" extension), create link to wizard
-                                               if ($t=='tt_content')   {
-
+                                               if ($table == 'tt_content')     {
+                                                       $groupName = $GLOBALS['LANG']->getLL('createNewContent');
+                                                       $rowContent = $firstLevel . $newContentIcon . '&nbsp;<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong>';
                                                                // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
                                                        $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
                                                        $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
 
-                                                       $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode($this->R_URI);
-                                                       $rowContent.= '<br /><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="" />'.
-                                                                               '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
-                                                                               htmlspecialchars($LANG->getLL('clickForWizard')).
-                                                                               '</a>';
+                                                       $href = $pathToWizard . '?id=' . $this->id . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
+                                                       $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
+                                                               $secondLevelLast .
+                                                               '<a href="' . htmlspecialchars($href) . '">' .
+                                                                       $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
+                                                               '</a>';
 
                                                                // Half-line added:
-                                                       $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
+                                                       $rowContent.= '<br />' . $halfLine;
+                                               }  else {
+                                                       // get the title
+                                                       if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
+                                                               continue;
+                                                       }
+                                                       if ($v['ctrl']['adminOnly'] && !$isAdmin) {
+                                                               continue;
+                                                       }
+                                                       $nameParts = explode('_', $table);
+                                                       $thisTitle = '';
+                                                       if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
+                                                               // try to extract extension name
+                                                               if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
+                                                                       $_EXTKEY = substr($v['ctrl']['title'], 8);
+                                                                       $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
+                                                                       if ($_EXTKEY != '') {
+                                                                               // first try to get localisation of extension title
+                                                                               $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
+                                                                               $langFile = $temp[0];
+                                                                               $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
+                                                                               // if no localisation available, read title from ext_emconf.php
+                                                                               if (!$thisTitle && is_file(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php')) {
+                                                                                       include(t3lib_extMgm::extPath($_EXTKEY) . 'ext_emconf.php');
+                                                                                       $thisTitle = $EM_CONF[$_EXTKEY]['title'];
+                                                                               }
+                                                                               $iconFile[$_EXTKEY] = '<img src="' . t3lib_extMgm::extRelPath($_EXTKEY) . 'ext_icon.gif" />';
+                                                                       } else {
+                                                                               $thisTitle = $nameParts[1];
+                                                                               $iconFile[$_EXTKEY] = '';
+                                                                       }
+                                                               } else {
+                                                                       $thisTitle = $nameParts[1];
+                                                                       $iconFile[$_EXTKEY] = '';
+                                                               }
+                                                       } else {
+                                                               $_EXTKEY = 'system';
+                                                               $thisTitle = $GLOBALS['LANG']->getLL('system_records');
+                                                               $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
+                                                       }
+
+                                                       if($groupName == '' || $groupName != $_EXTKEY) {
+                                                               $groupName = $_EXTKEY;
+                                                       }
+
+                                                       $rowContent .= $newLink;
+                                                       $counter++;
+
                                                }
 
 
                                                        // Compile table row:
-                                               $tRows[] = '
-                               <tr>
-                                       <td nowrap="nowrap">'.$rowContent.'</td>
-                                       <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
-                               </tr>
-                       ';
-
+                                               if ($table == 'tt_content') {
+                                                       $startRows[] = '
+                                                               <tr>
+                                                                       <td nowrap="nowrap">' . $rowContent . '</td>
+                                                                       <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
+                                                               </tr>';
+                                               } else {
+                                                       $this->tRows[$groupName]['title'] = $thisTitle;
+                                                       $this->tRows[$groupName]['html'][] = $rowContent;
+                                                       $this->tRows[$groupName]['table'][] = $table;
+                                               }
                                        }
                                }
                        }
                }
 
-                       // New pages AFTER this pages
-               if ($this->newPagesAfter
-                       && $this->isTableAllowedForThisPage($this->pidInfo,'pages')
-                       && $BE_USER->check('tables_modify','pages')
-                       && $BE_USER->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
-                       )       {
+                       // user sort
+               $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
+               if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
+                       $this->newRecordSortList = t3lib_div::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
+               }
+               uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
+
+                       // Compile table row:
+               $finalRows = array();
+               $finalRows[] = implode('', $startRows);
+               foreach ($this->tRows as $key => $value) {
+                       $row = '<tr>
+                                               <td nowrap="nowrap">' . $halfLine . '<br />' .
+                                               $firstLevel . '' . $iconFile[$key] . '&nbsp;<strong>' . $value['title'] . '</strong>' .
+                                               '</td><td>&nbsp;<br />' . t3lib_BEfunc::wrapInHelp($key, '') . '</td>
+                                               </tr>';
+                       $count = count($value['html']) - 1;
+                       foreach ($value['html'] as $recordKey => $record) {
+                               $row .= '
+                                       <tr>
+                                               <td nowrap="nowrap">' . ($recordKey < $count ? $secondLevel : $secondLevelLast) . $record . '</td>
+                                               <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
+                                       </tr>';
+                       }
+                       $finalRows[] = $row;
+               }
 
-                               // Create link to new page after
-                       $t = 'pages';
-                       $v = $TCA[$t];
-                       $rowContent = $this->linkWrap(
-                                       t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
-                                               $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
-                                       'pages',
-                                       -$this->id
-                               );
+                       // end of tree
+               $finalRows[]='
+                       <tr>
+                               <td><img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/ol/stopper.gif','width="18" height="16"') . ' alt="" /></td>
+                               <td></td>
+                       </tr>
+               ';
 
-                               // Compile table row:
-                       $tRows[] = '
-                               <tr>
-                                       <td nowrap="nowrap">'.$rowContent.'</td>
-                                       <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
-                               </tr>
-                       ';
-               } else {
-                               // Compile table row:
-                       $tRows[]='
-                               <tr>
-                                       <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
-                                       <td></td>
-                               </tr>
-                       ';
-               }
 
                        // Make table:
                $this->code.='
                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
-                       '.implode('',$tRows).'
+                       ' . implode('', $finalRows) . '
                        </table>
                ';
+       }
 
-                       // Create a link to the new-pages wizard.
-               if ($this->showNewRecLink('pages'))     {
-                       $this->code.='
-
-                               <!--
-                                       Link; create new page:
-                               -->
-                               <div id="typo3-newPageLink">
-                                       <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
-                                       '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
-                                       htmlspecialchars($LANG->getLL('createNewPage')).
-                                       '</a>
-                               </div>
-                               ';
+       /**
+        * user array sort function used by regularNew
+        *
+        * @param       string          first array element for compare
+        * @param       string          first array element for compare
+        * @return      int                     -1 for lower, 0 for equal, 1 for greater
+        */
+       function sortNewRecordsByConfig($a, $b) {
+               if (count($this->newRecordSortList)) {
+                       if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
+                                       // both are in the list, return relative to position in array
+                               $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
+                               $ret = $sub < 0 ? -1 : $sub == 0 ? 0 : 1;
+                       } elseif (in_array($a, $this->newRecordSortList)) {
+                                       // first element is in array, put to top
+                               $ret = -1;
+                       } elseif (in_array($b, $this->newRecordSortList)) {
+                                       // second element is in array, put first to bottom
+                               $ret = 1;
+                       } else {
+                                       // no element is in array, return alphabetic order
+                               $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
+               }
+                       return $ret;
+               } else {
+                               // return alphabetic order
+                       return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
                }
-
-                       // Add CSH:
-               $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
        }
 
        /**
@@ -456,31 +642,34 @@ class SC_db_new {
         * @return      void
         */
        function printContent() {
-               $this->content.= $this->doc->endPage();
-               $this->content = $this->doc->insertStylesAndJS($this->content);
                echo $this->content;
        }
 
        /**
         * Links the string $code to a create-new form for a record in $table created on page $pid
         *
-        * @param       string          Link string
+        * @param       string          Link text
         * @param       string          Table name (in which to create new record)
         * @param       integer         PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
         * @param       boolean         If $addContentTable is set, then a new contentTable record is created together with pages
         * @return      string          The link.
         */
-       function linkWrap($code,$table,$pid,$addContentTable=0) {
-               $params = '&edit['.$table.']['.$pid.']=new'.
-                       ($table=='pages'
-                               && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
-                               && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
-                               && $addContentTable     ?
-                               '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1'     :
-                               ''
-                       );
-               $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
-               return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
+       function linkWrap($linkText, $table, $pid, $addContentTable = false) {
+               $parameters = '&edit[' . $table . '][' . $pid . ']=new';
+
+               if ($table == 'pages'
+                       && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
+                       && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
+                       && $addContentTable) {
+                       $parameters .= '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1';
+               } elseif ($table == 'pages_language_overlay') {
+                       $parameters .= '&overrideVals[pages_language_overlay][doktype]='
+                                               . (int) $this->pageinfo['doktype'];
+               }
+
+               $onClick = t3lib_BEfunc::editOnClick($parameters, '', $this->returnUrl);
+
+               return '<a href="#" onclick="'.htmlspecialchars($onClick).'">' . $linkText . '</a>';
        }
 
        /**
@@ -514,24 +703,38 @@ class SC_db_new {
        }
 
        /**
-        * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
+        * Returns true if:
+        * - $allowedNewTables and $deniedNewTables are empty
+        * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
+        *
+        * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
+        * has priority over $allowedNewTables.
         *
         * @param       string          Table name to test if in allowedTables
         * @param       array           Array of new tables that are allowed.
-        * @return      boolean         Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
+        * @param       array           Array of new tables that are not allowed.
+        * @return      boolean         Returns true if a link for creating new records should be displayed for $table
         */
-       function showNewRecLink($table,$allowedNewTables='')    {
-               $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
-               return !count($allowedNewTables) || in_array($table,$allowedNewTables);
+       function showNewRecLink($table, array $allowedNewTables=array(), array $deniedNewTables=array()) {
+               $allowedNewTables = ($allowedNewTables ? $allowedNewTables : $this->allowedNewTables);
+               $deniedNewTables = ($deniedNewTables ? $deniedNewTables : $this->deniedNewTables);
+                       // No deny/allow tables are set:
+               if (!count($allowedNewTables) && !count($deniedNewTables)) {
+                       return true;
+                       // If table is not denied (which takes precedence over allowed tables):
+               } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
+                       return true;
+                       // If table is denied or allowed tables are set, but table is not part of:
+               } else {
+                       return false;
+               }
        }
 }
 
-// Include extension?
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php'])       {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
-}
-
 
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
+}
 
 
 
@@ -540,4 +743,5 @@ $SOBE = t3lib_div::makeInstance('SC_db_new');
 $SOBE->init();
 $SOBE->main();
 $SOBE->printContent();
-?>
\ No newline at end of file
+
+?>