[BUGFIX] Warning in list module
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
index 0ca4067..e8518ee 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2009 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
  */
@@ -176,7 +166,7 @@ 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
@@ -257,10 +247,10 @@ class SC_db_new {
 
                                // Set header-HTML and return_url
                        if (is_array($this->pageinfo) && $this->pageinfo['uid'])        {
-                               $iconImgTag = t3lib_iconWorks::getIconImage('pages', $this->pageinfo, $this->backPath, 'title="' . htmlspecialchars($this->pageinfo['_thePath']) . '"');
+                               $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 = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/_icon_website.gif') . ' title="' . htmlspecialchars($this->pageinfo['_thePath']) . '" alt="" />';
+                               $iconImgTag = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
                                $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
                        }
 
@@ -312,8 +302,8 @@ class SC_db_new {
                if (!$this->pagesOnly)  {       // Regular new element:
                                // New page
                        if ($this->showNewRecLink('pages'))     {
-                               $buttons['new_page'] = '<a href="' . htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly' => '1'))) . '">' .
-                                       '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/new_page.gif') . ' alt="" />' .
+                               $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
@@ -325,24 +315,26 @@ class SC_db_new {
 
                        // Back
                if ($this->R_URI) {
-                       $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack">' .
-                               '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/goback.gif') . ' alt="" />' .
+                       $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']))) . '">' .
-                               '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/zoom.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showPage', 1) . '" alt="" />' .
+                       $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 ($GLOBALS['BE_USER']->check('modules', 'web_list')) {
-                               $href = $this->backPath . 'db_list.php?id=' . $this->pageinfo['uid'] . '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
-                               $buttons['record_list'] = '<a href="' . htmlspecialchars($href) . '">' .
-                                       '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/list.gif') . ' title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.showList', 1) . '" alt="" />' .
-                                       '</a>';
-                       }
+                               // 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')
+                       );
                }
 
 
@@ -357,12 +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);
+               $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);
+               }
        }
 
        /**
@@ -371,11 +373,11 @@ class SC_db_new {
         * @return      void
         */
        function regularNew()   {
-               
+
                $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="" />';
@@ -383,17 +385,18 @@ class SC_db_new {
                                                <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 .= $halfLine;
 
                        // New Page
                $table = 'pages';
                $v = $GLOBALS['TCA'][$table];
-               $pageIcon = t3lib_iconWorks::getIconImage($table, array(), $this->doc->backPath, '');
-               $newPageIcon = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/new_page.gif', 'width="13" height="12"') . ' alt="" />';
+               $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')
@@ -402,53 +405,56 @@ class SC_db_new {
                        )       {
 
                                // Create link to new page inside:
-                       
+
                        $rowContent .= '<br />' . $secondLevel . $this->linkWrap(
-                                               '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/i/' . ($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $table . '.gif'), 'width="18" height="16"') . ' alt="" />' .
+                                               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 . 
+
+                               $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:
-               $startRows[]='
-                       <tr>
-                               <td nowrap="nowrap">' . $rowContent . '</td>
-                               <td>' . t3lib_BEfunc::cshItem($table, '', $this->doc->backPath, '', $doNotShowFullDescr) . '</td>
-                       </tr>
-               ';
-       
-        
+                       // 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::wrapInHelp($table, '') . '</td>
+                               </tr>
+                       ';
+               }
+
+
                        // New tables (but not pages) INSIDE this pages
-               
-               $newContentIcon = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/new_record.gif', 'width="16" height="12"') . ' alt="" />';
+               $isAdmin = $GLOBALS['BE_USER']->isAdmin();
+               $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
                if ($this->newContentInto)      {
                        if (is_array($GLOBALS['TCA']))  {
                                $groupName = '';
@@ -463,9 +469,9 @@ class SC_db_new {
                                                        && $GLOBALS['BE_USER']->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id, $table)
                                                        )       {
 
-                                               $newRecordIcon = t3lib_iconWorks::getIconImage($table ,array(), $this->doc->backPath, '');
+                                               $newRecordIcon = t3lib_iconWorks::getSpriteIconForRecord($table, array());
                                                $rowContent = '';
-                                               
+
                                                        // Create new link for record:
                                                $newLink = $this->linkWrap(
                                                        $newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'],1)
@@ -481,16 +487,22 @@ class SC_db_new {
                                                        $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(t3lib_div::getIndpEnv('REQUEST_URI'));
-                                                       $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' . 
+                                                       $rowContent.= '<br />' . $secondLevel . $newLink . '<br />' .
                                                                $secondLevelLast .
                                                                '<a href="' . htmlspecialchars($href) . '">' .
                                                                        $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) .
                                                                '</a>';
 
                                                                // Half-line added:
-                                                       $rowContent.= '<br />' . $halfLine;  
+                                                       $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') {
@@ -520,16 +532,16 @@ class SC_db_new {
                                                        } else {
                                                                $_EXTKEY = 'system';
                                                                $thisTitle = $GLOBALS['LANG']->getLL('system_records');
-                                                               $iconFile['system'] = '<img src="gfx/typo3.png" />';    
+                                                               $iconFile['system'] = t3lib_iconWorks::getSpriteIcon('apps-pagetree-root');
                                                        }
-                                                       
+
                                                        if($groupName == '' || $groupName != $_EXTKEY) {
                                                                $groupName = $_EXTKEY;
-                                                       } 
-                                                       
-                                                       $rowContent .= $newLink; 
+                                                       }
+
+                                                       $rowContent .= $newLink;
                                                        $counter++;
-                                                       
+
                                                }
 
 
@@ -538,7 +550,7 @@ class SC_db_new {
                                                        $startRows[] = '
                                                                <tr>
                                                                        <td nowrap="nowrap">' . $rowContent . '</td>
-                                                                       <td>' . t3lib_BEfunc::cshItem($table, '', $this->doc->backPath, '', $doNotShowFullDescr) . '</td>
+                                                                       <td>' . t3lib_BEfunc::wrapInHelp($table, '') . '</td>
                                                                </tr>';
                                                } else {
                                                        $this->tRows[$groupName]['title'] = $thisTitle;
@@ -552,31 +564,31 @@ class SC_db_new {
 
                        // user sort
                $pageTS = t3lib_BEfunc::getPagesTSconfig($this->id);
-               if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) { 
+               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); 
+               $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>'.t3lib_BEfunc::cshItem($t,'',$this->doc->backPath,'',$doNotShowFullDescr).'</td>
+                                               $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) { 
+                       $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::cshItem($value['table'][$recordKey], '', $this->doc->backPath, '', $doNotShowFullDescr) . '</td>
-                                       </tr>'; 
+                                               <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
+                                       </tr>';
                        }
-                       $finalRows[] = $row;                    
+                       $finalRows[] = $row;
                }
-               
+
                        // end of tree
                $finalRows[]='
                        <tr>
@@ -584,8 +596,8 @@ class SC_db_new {
                                <td></td>
                        </tr>
                ';
-               
-               
+
+
                        // Make table:
                $this->code.='
                        <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
@@ -623,7 +635,7 @@ class SC_db_new {
                        return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
                }
        }
-       
+
        /**
         * Ending page output and echo'ing content to browser.
         *
@@ -720,8 +732,8 @@ class SC_db_new {
 }
 
 
-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']);
 }