"TYPO3 4.0.1: typo3_src-4.0.1/typo3/db_new.php Source File", "datetime" => "Sat Dec 2 19:22:21 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

db_new.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (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 ***************************************************************/
00067 $BACK_PATH='';
00068 require('init.php');
00069 require('template.php');
00070 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00071 
00072 // ***************************
00073 // Including classes
00074 // ***************************
00075 require_once(PATH_t3lib.'class.t3lib_page.php');
00076 require_once(PATH_t3lib.'class.t3lib_positionmap.php');
00077 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
00078 
00079 
00080 
00081 
00082 
00090 class localPageTree extends t3lib_pageTree {
00091 
00099         function wrapIcon($icon,$row)   {
00100                 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
00101         }
00102 
00110         function expandNext($id)        {
00111                 return $id==$GLOBALS['SOBE']->id ? 1 : 0;
00112         }
00113 }
00114 
00115 
00116 
00117 
00118 
00119 
00120 
00128 class SC_db_new {
00129         var $pageinfo;
00130         var $pidInfo;
00131         var $newPagesInto;
00132         var $newContentInto;
00133         var $newPagesAfter;
00134         var $web_list_modTSconfig;
00135         var $allowedNewTables;
00136         var $web_list_modTSconfig_pid;
00137         var $allowedNewTables_pid;
00138         var $code;
00139         var $R_URI;
00140 
00141                 // Internal, static: GPvar
00142         var $id;                        // see init()
00143         var $returnUrl;         // Return url.
00144         var $pagesOnly;         // pagesOnly flag.
00145 
00146                 // Internal
00147         var $perms_clause;      // see init()
00148         var $doc;                       // see init()
00149         var $content;           // Accumulated HTML output
00150 
00151 
00157         function init() {
00158                 global $BE_USER,$LANG,$BACK_PATH;
00159 
00160                         // page-selection permission clause (reading)
00161                 $this->perms_clause = $BE_USER->getPagePermsClause(1);
00162 
00163                         // this will hide records from display - it has nothing todo with user rights!!
00164                 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
00165                         if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
00166                                 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
00167                         }
00168                 }
00169                         // Setting GPvars:
00170                 $this->id = intval(t3lib_div::_GP('id'));       // The page id to operate from
00171                 $this->returnUrl = t3lib_div::_GP('returnUrl');
00172                 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
00173 
00174                         // Create instance of template class for output
00175                 $this->doc = t3lib_div::makeInstance('mediumDoc');
00176                 $this->doc->backPath = $BACK_PATH;
00177                 $this->doc->docType= 'xhtml_trans';
00178                 $this->doc->JScode='';
00179 
00180                         // Creating content
00181                 $this->content='';
00182                 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
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 
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 
00233                                 // Acquiring TSconfig for this module/parent page:
00234                         $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
00235                         $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
00236 
00237                                 // More init:
00238                         if (!$this->showNewRecLink('pages'))    {
00239                                 $this->newPagesInto=0;
00240                         }
00241                         if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid))        {
00242                                 $this->newPagesAfter=0;
00243                         }
00244 
00245 
00246                                 // Set header-HTML and return_url
00247                         $this->code=$this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
00248                         ';
00249                         $this->R_URI=$this->returnUrl;
00250 
00251                                 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
00252                         if (!$this->pagesOnly)  {       // Regular new element:
00253                                 $this->regularNew();
00254                         } elseif ($this->showNewRecLink('pages')) {     // Pages only wizard
00255                                 $this->pagesOnly();
00256                         }
00257 
00258                                 // Create go-back link.
00259                         if ($this->R_URI)       {
00260                                 $this->code.='<br />
00261                 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
00262                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
00263                 $LANG->getLL('goBack',1).
00264                 '</a>';
00265                         }
00266                                 // Add all the content to an output section
00267                         $this->content.=$this->doc->section('',$this->code);
00268                 }
00269         }
00270 
00276         function pagesOnly()    {
00277                 global $LANG;
00278 
00279                 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
00280                 $this->code.='
00281                         <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
00282                 ';
00283                 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
00284 
00285                                 // Add CSH:
00286                 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
00287         }
00288 
00294         function regularNew()   {
00295                 global $BE_USER,$LANG,$BACK_PATH,$TCA;
00296 
00297                 $doNotShowFullDescr = FALSE;
00298 
00299                         // Slight spacer from header:
00300                 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
00301 
00302                         // Initialize array for accumulating table rows:
00303                 $tRows = array();
00304 
00305                         // New pages INSIDE this pages
00306                 if ($this->newPagesInto
00307                         && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
00308                         && $BE_USER->check('tables_modify','pages')
00309                         && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
00310                         )       {
00311 
00312                                 // Create link to new page inside:
00313                         $t = 'pages';
00314                         $v = $TCA[$t];
00315                         $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
00316                                         $this->linkWrap(
00317                                                 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
00318                                                         $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
00319                                                 $t,
00320                                                 $this->id).'<br/>';
00321 
00322                                 // Link to page-wizard:
00323                         $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="" />'.
00324                                 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
00325                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
00326                                 htmlspecialchars($LANG->getLL('clickForWizard')).
00327                                 '</a>';
00328                                 // Half-line:
00329                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
00330 
00331                                 // Compile table row:
00332                         $tRows[]='
00333                                 <tr>
00334                                         <td nowrap="nowrap">'.$rowContent.'</td>
00335                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00336                                 </tr>
00337                         ';
00338                 }
00339 
00340                         // New tables (but not pages) INSIDE this pages
00341                 if ($this->newContentInto)      {
00342                         if (is_array($TCA))     {
00343                                 foreach($TCA as $t => $v)       {
00344                                         if ($t!='pages'
00345                                                         && $this->showNewRecLink($t)
00346                                                         && $this->isTableAllowedForThisPage($this->pageinfo, $t)
00347                                                         && $BE_USER->check('tables_modify',$t)
00348                                                         && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
00349                                                         && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, $t)
00350                                                         )       {
00351 
00352                                                         // Create new link for record:
00353                                                 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
00354                                                                 $this->linkWrap(
00355                                                                 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
00356                                                                 $LANG->sL($v['ctrl']['title'],1)
00357                                                         ,$t
00358                                                         ,$this->id);
00359 
00360                                                         // If the table is 'tt_content' (from "cms" extension), create link to wizard
00361                                                 if ($t=='tt_content')   {
00362 
00363                                                                 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
00364                                                         $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
00365                                                         $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
00366 
00367                                                         $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode($this->R_URI);
00368                                                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
00369                                                                                 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
00370                                                                                 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
00371                                                                                 htmlspecialchars($LANG->getLL('clickForWizard')).
00372                                                                                 '</a>';
00373 
00374                                                                 // Half-line added:
00375                                                         $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
00376                                                 }
00377 
00378 
00379                                                         // Compile table row:
00380                                                 $tRows[] = '
00381                                 <tr>
00382                                         <td nowrap="nowrap">'.$rowContent.'</td>
00383                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00384                                 </tr>
00385                         ';
00386 
00387                                         }
00388                                 }
00389                         }
00390                 }
00391 
00392                         // New pages AFTER this pages
00393                 if ($this->newPagesAfter
00394                         && $this->isTableAllowedForThisPage($this->pidInfo,'pages')
00395                         && $BE_USER->check('tables_modify','pages')
00396                         && $BE_USER->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
00397                         )       {
00398 
00399                                 // Create link to new page after
00400                         $t = 'pages';
00401                         $v = $TCA[$t];
00402                         $rowContent = $this->linkWrap(
00403                                         t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
00404                                                 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
00405                                         'pages',
00406                                         -$this->id
00407                                 );
00408 
00409                                 // Compile table row:
00410                         $tRows[] = '
00411                                 <tr>
00412                                         <td nowrap="nowrap">'.$rowContent.'</td>
00413                                         <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
00414                                 </tr>
00415                         ';
00416                 } else {
00417                                 // Compile table row:
00418                         $tRows[]='
00419                                 <tr>
00420                                         <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
00421                                         <td></td>
00422                                 </tr>
00423                         ';
00424                 }
00425 
00426                         // Make table:
00427                 $this->code.='
00428                         <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
00429                         '.implode('',$tRows).'
00430                         </table>
00431                 ';
00432 
00433                         // Create a link to the new-pages wizard.
00434                 if ($this->showNewRecLink('pages'))     {
00435                         $this->code.='
00436 
00437                                 <!--
00438                                         Link; create new page:
00439                                 -->
00440                                 <div id="typo3-newPageLink">
00441                                         <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
00442                                         '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
00443                                         htmlspecialchars($LANG->getLL('createNewPage')).
00444                                         '</a>
00445                                 </div>
00446                                 ';
00447                 }
00448 
00449                         // Add CSH:
00450                 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
00451         }
00452 
00458         function printContent() {
00459                 $this->content.= $this->doc->endPage();
00460                 $this->content = $this->doc->insertStylesAndJS($this->content);
00461                 echo $this->content;
00462         }
00463 
00473         function linkWrap($code,$table,$pid,$addContentTable=0) {
00474                 $params = '&edit['.$table.']['.$pid.']=new'.
00475                         ($table=='pages'
00476                                 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
00477                                 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
00478                                 && $addContentTable     ?
00479                                 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1'     :
00480                                 ''
00481                         );
00482                 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
00483                 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
00484         }
00485 
00493         function isTableAllowedForThisPage($pid_row, $checkTable)       {
00494                 global $TCA, $PAGES_TYPES;
00495                 if (!is_array($pid_row))        {
00496                         if ($GLOBALS['BE_USER']->user['admin']) {
00497                                 return true;
00498                         } else {
00499                                 return false;
00500                         }
00501                 }
00502                         // be_users and be_groups may not be created anywhere but in the root.
00503                 if ($checkTable=='be_users' || $checkTable=='be_groups')        {
00504                         return false;
00505                 }
00506                         // Checking doktype:
00507                 $doktype = intval($pid_row['doktype']);
00508                 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables'])       {
00509                         $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
00510                 }
00511                 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable))  {               // If all tables or the table is listed as a allowed type, return true
00512                         return true;
00513                 }
00514         }
00515 
00523         function showNewRecLink($table,$allowedNewTables='')    {
00524                 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
00525                 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
00526         }
00527 }
00528 
00529 // Include extension?
00530 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php'])        {
00531         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
00532 }
00533 
00534 
00535 
00536 
00537 
00538 // Make instance:
00539 $SOBE = t3lib_div::makeInstance('SC_db_new');
00540 $SOBE->init();
00541 $SOBE->main();
00542 $SOBE->printContent();
00543 ?>