[BUGFIX] Warning in list module
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
index 7d3fbc7..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]
@@ -73,7 +73,7 @@ $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
 /**
  * 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
  */
@@ -111,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
  */
@@ -166,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
@@ -247,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'];
                        }
 
@@ -302,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
@@ -315,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')
+                       );
                }
 
 
@@ -347,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);
+               }
        }
 
        /**
@@ -380,8 +392,9 @@ class SC_db_new {
                        // 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
@@ -394,7 +407,7 @@ 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);
@@ -427,18 +440,21 @@ class SC_db_new {
                        // 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
                $isAdmin = $GLOBALS['BE_USER']->isAdmin();
-               $newContentIcon = '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/new_record.gif', 'width="16" height="12"') . ' alt="" />';
+               $newContentIcon = t3lib_iconWorks::getSpriteIcon('actions-document-new');
                if ($this->newContentInto)      {
                        if (is_array($GLOBALS['TCA']))  {
                                $groupName = '';
@@ -453,7 +469,7 @@ 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:
@@ -516,7 +532,7 @@ 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) {
@@ -534,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;
@@ -560,14 +576,14 @@ class SC_db_new {
                        $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>
+                                               '</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::cshItem($value['table'][$recordKey], '', $this->doc->backPath, '', $doNotShowFullDescr) . '</td>
+                                               <td>' . t3lib_BEfunc::wrapInHelp($value['table'][$recordKey], '') . '</td>
                                        </tr>';
                        }
                        $finalRows[] = $row;
@@ -716,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']);
 }