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

class.t3lib_admin.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 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 ***************************************************************/
00093 class t3lib_admin {
00094         var $genTree_includeDeleted = TRUE;             // if set, genTree() includes deleted pages. This is default.
00095         var $genTree_includeVersions = TRUE;            // if set, genTree() includes verisonized pages/records. This is default.
00096         var $genTree_includeRecords = FALSE;            // if set, genTree() includes records from pages.
00097         var $perms_clause = '';                         // extra where-clauses for the tree-selection
00098         var $genTree_makeHTML = 0;                      // if set, genTree() generates HTML, that visualizes the tree.
00099 
00100                 // internal
00101         var $page_idArray = Array();            // Will hod id/rec pais from genTree()
00102         var $rec_idArray = Array();
00103         var $getTree_HTML = '';                 // Will hold the HTML-code visualising the tree. genTree()
00104         var $backPath = '';
00105 
00106                 // internal
00107         var $checkFileRefs = Array();
00108         var $checkSelectDBRefs = Array();       // From the select-fields
00109         var $checkGroupDBRefs = Array();        // From the group-fields
00110 
00111         var $recStats = Array(
00112                 'allValid' => array(),
00113                 'published_versions' => array(),
00114                 'deleted' => array(),
00115         );
00116         var $lRecords = Array();
00117         var $lostPagesList = '';
00118 
00119 
00128         function genTree($theID, $depthData, $versions=FALSE)   {
00129 
00130                 if ($versions)  {
00131                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00132                                 'uid,title,doktype,deleted,t3ver_wsid,t3ver_id,t3ver_count,t3ver_swapmode'.(t3lib_extMgm::isLoaded('cms')?',hidden':''),
00133                                 'pages',
00134                                 'pid=-1 AND t3ver_oid='.intval($theID).' '.((!$this->genTree_includeDeleted)?'AND deleted=0':'').$this->perms_clause,
00135                                 '',
00136                                 'sorting'
00137                         );
00138                 } else {
00139                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00140                                 'uid,title,doktype,deleted'.(t3lib_extMgm::isLoaded('cms')?',hidden':''),
00141                                 'pages',
00142                                 'pid='.intval($theID).' '.((!$this->genTree_includeDeleted)?'AND deleted=0':'').$this->perms_clause,
00143                                 '',
00144                                 'sorting'
00145                         );
00146                 }
00147 
00148                         // Traverse the records selected:
00149                 $a = 0;
00150                 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00151                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00152 
00153                                 // Prepare the additional label used in the HTML output in case of versions:
00154                         if ($versions)  {
00155                                 $versionLabel = '[v1.'.$row['t3ver_id'].'; WS#'.$row['t3ver_wsid'].']';
00156                         } else $versionLabel='';
00157 
00158                         $a++;
00159                         $newID = $row['uid'];
00160 
00161                                 // Build HTML output:
00162                         if ($this->genTree_makeHTML)    {
00163                                 $this->genTree_HTML.=chr(10).'<div><span class="nobr">';
00164                                 $PM = 'join';
00165                                 $LN = ($a==$c)?'blank':'line';
00166                                 $BTM = ($a==$c)?'bottom':'';
00167                                 $this->genTree_HTML.= $depthData.
00168                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" alt="" />'.
00169                                         $versionLabel.
00170                                         t3lib_iconWorks::getIconImage('pages',$row,$this->backPath,'align="top"').
00171                                         htmlspecialchars($row['uid'].': '.t3lib_div::fixed_lgd_cs(strip_tags($row['title']),50)).'</span></div>';
00172                         }
00173 
00174                                 // Register various data for this item:
00175                         $this->page_idArray[$newID]=$row;
00176 
00177                         $this->recStats['all_valid']['pages'][$newID] = $newID;
00178 #                       if ($versions)  $this->recStats['versions']['pages'][$newID] = $newID;
00179                         if ($row['deleted'])    $this->recStats['deleted']['pages'][$newID] = $newID;
00180                         if ($versions && $row['t3ver_count']>=1) {
00181                                 $this->recStats['published_versions']['pages'][$newID] = $newID;
00182                         }
00183 
00184                         if ($row['deleted']) {$this->recStat['deleted']++;}
00185                         if ($row['hidden']) {$this->recStat['hidden']++;}
00186                         $this->recStat['doktype'][$row['doktype']]++;
00187 
00188                                 // Create the HTML code prefix for recursive call:
00189                         $genHTML =  $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' align="top" alt="" />'.$versionLabel;
00190 
00191                                 // If all records should be shown, do so:
00192                         if ($this->genTree_includeRecords)      {
00193                                 foreach($GLOBALS['TCA'] as $tableName => $cfg)  {
00194                                         if ($tableName!='pages') {
00195                                                 $this->genTree_records($newID, $this->genTree_HTML ? $genHTML : '', $tableName);
00196                                         }
00197                                 }
00198                         }
00199 
00200                                 // Add sub pages:
00201                         $this->genTree($newID, $this->genTree_HTML ? $genHTML : '');
00202 
00203                                 // If versions are included in the tree, add those now:
00204                         if ($this->genTree_includeVersions)     {
00205                                 $this->genTree($newID, $this->genTree_HTML ? $genHTML : '', TRUE);
00206                         }
00207                 }
00208         }
00209 
00217         function genTree_records($theID, $depthData, $table='', $versions=FALSE)        {
00218                 global $TCA;
00219 
00220                 if ($versions)  {
00221                                 // Select all records from table pointing to this page:
00222                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00223                                 t3lib_BEfunc::getCommonSelectFields($table),
00224                                 $table,
00225                                 'pid=-1 AND t3ver_oid='.intval($theID).
00226                                         (!$this->genTree_includeDeleted?t3lib_BEfunc::deleteClause($table):'')
00227                         );
00228                 } else {
00229                                 // Select all records from table pointing to this page:
00230                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00231                                 t3lib_BEfunc::getCommonSelectFields($table),
00232                                 $table,
00233                                 'pid='.intval($theID).
00234                                         (!$this->genTree_includeDeleted?t3lib_BEfunc::deleteClause($table):'')
00235                         );
00236                 }
00237 
00238                         // Traverse selected:
00239                 $a = 0;
00240                 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00241                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))      {
00242 
00243                                 // Prepare the additional label used in the HTML output in case of versions:
00244                         if ($versions)  {
00245                                 $versionLabel = '[v1.'.$row['t3ver_id'].'; WS#'.$row['t3ver_wsid'].']';
00246                         } else $versionLabel='';
00247 
00248                         $a++;
00249                         $newID = $row['uid'];
00250 
00251                                 // Build HTML output:
00252                         if ($this->genTree_makeHTML)    {
00253                                 $this->genTree_HTML.=chr(10).'<div><span class="nobr">';
00254                                 $PM = 'join';
00255                                 $LN = ($a==$c)?'blank':'line';
00256                                 $BTM = ($a==$c)?'bottom':'';
00257                                 $this->genTree_HTML.= $depthData.
00258                                         '<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' align="top" alt="" />'.
00259                                         $versionLabel.
00260                                         t3lib_iconWorks::getIconImage($table,$row,$this->backPath,'align="top" title="'.$table.'"').htmlspecialchars($row['uid'].': '.t3lib_BEfunc::getRecordTitle($table,$row)).'</span></div>';
00261                         }
00262 
00263                                 // Register various data for this item:
00264                         $this->rec_idArray[$table][$newID]=$row;
00265 
00266                         $this->recStats['all_valid'][$table][$newID] = $newID;
00267 #                       $this->recStats[$versions?'versions':'live'][$table][$newID] = $newID;
00268                         if ($row['deleted'])    $this->recStats['deleted'][$table][$newID] = $newID;
00269                         if ($versions && $row['t3ver_count']>=1 && $row['t3ver_wsid']==0) {
00270                                 $this->recStats['published_versions'][$table][$newID] = $newID;
00271                         }
00272 
00273 #                       if ($row['deleted']) {$this->recStat['deleted']++;}
00274 #                       if ($row['hidden']) {$this->recStat['hidden']++;}
00275 
00276 
00277 
00278                                 // Select all versions of this record:
00279                         if ($this->genTree_includeVersions && $TCA[$table]['ctrl']['versioningWS']) {
00280                                 $genHTML =  $depthData.'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' align="top" alt="" />';
00281 
00282                                 $this->genTree_records($newID, $genHTML, $table, TRUE);
00283                         }
00284                 }
00285         }
00286 
00292         function genTreeStatus() {
00293                 $this->genTree_includeDeleted = TRUE;           // if set, genTree() includes deleted pages. This is default.
00294                 $this->genTree_includeVersions = TRUE;          // if set, genTree() includes verisonized pages/records. This is default.
00295                 $this->genTree_includeRecords = TRUE;           // if set, genTree() includes records from pages.
00296                 $this->perms_clause = '';                                       // extra where-clauses for the tree-selection
00297                 $this->genTree_makeHTML = 0;                            // if set, genTree() generates HTML, that visualizes the tree.
00298 
00299                 $this->genTree(537,'');
00300 
00301                 return $this->recStats;
00302         }
00303 
00304 
00305 
00306 
00307 
00308 
00315         function lostRecords($pid_list) {
00316                 global $TCA;
00317                 reset($TCA);
00318                 $this->lostPagesList='';
00319                 if ($pid_list)  {
00320                         while (list($table)=each($TCA)) {
00321                                 t3lib_div::loadTCA($table);
00322                                 $garbage = $GLOBALS['TYPO3_DB']->exec_SELECTquery (
00323                                                                 'uid,pid,'.$TCA[$table]['ctrl']['label'],
00324                                                                 $table,
00325                                                                 'pid NOT IN ('.$pid_list.')'
00326                                                         );
00327                                 $lostIdList=Array();
00328                                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($garbage))  {
00329                                         $this->lRecords[$table][$row['uid']]=Array('uid'=>$row['uid'], 'pid'=>$row['pid'], 'title'=> strip_tags($row[$TCA[$table]['ctrl']['label']]) );
00330                                         $lostIdList[]=$row['uid'];
00331                                 }
00332                                 if ($table=='pages')    {
00333                                         $this->lostPagesList=implode(',',$lostIdList);
00334                                 }
00335                         }
00336                 }
00337         }
00338 
00346         function fixLostRecord($table,$uid)     {
00347                 if ($table && $GLOBALS['TCA'][$table] && $uid && is_array($this->lRecords[$table][$uid]) && $GLOBALS['BE_USER']->user['admin']) {
00348 
00349                         $updateFields = array();
00350                         $updateFields['pid'] = 0;
00351                         if ($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])       {       // If possible a lost record restored is hidden as default
00352                                 $updateFields[$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled']] = 1;
00353                         }
00354 
00355                         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
00356 
00357                         return TRUE;
00358                 } else return FALSE;
00359         }
00360 
00367         function countRecords($pid_list)        {
00368                 global $TCA;
00369                 reset($TCA);
00370                 $list=Array();
00371                 $list_n=Array();
00372                 if ($pid_list)  {
00373                         while (list($table)=each($TCA)) {
00374                                 t3lib_div::loadTCA($table);
00375                                 $count = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid IN ('.$pid_list.')');
00376                                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($count)) {
00377                                         $list[$table]=$row[0];
00378                                 }
00379 
00380                                 $count = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', $table, 'pid IN ('.$pid_list.')'.t3lib_BEfunc::deleteClause($table));
00381                                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_row($count)) {
00382                                         $list_n[$table]=$row[0];
00383                                 }
00384                         }
00385                 }
00386                 return array('all' => $list, 'non_deleted' => $list_n);
00387         }
00388 
00395         function getGroupFields($mode)  {
00396                 global $TCA;
00397                 reset ($TCA);
00398                 $result = Array();
00399                 while (list($table)=each($TCA)) {
00400                         t3lib_div::loadTCA($table);
00401                         $cols = $TCA[$table]['columns'];
00402                         reset ($cols);
00403                         while (list($field,$config)=each($cols))        {
00404                                 if ($config['config']['type']=='group') {
00405                                         if (
00406                                                 ((!$mode||$mode=='file') && $config['config']['internal_type']=='file') ||
00407                                                 ((!$mode||$mode=='db') && $config['config']['internal_type']=='db')
00408                                                 )       {
00409                                                 $result[$table][]=$field;
00410                                         }
00411                                 }
00412                                 if ( (!$mode||$mode=='db') && $config['config']['type']=='select' && $config['config']['foreign_table'])        {
00413                                         $result[$table][]=$field;
00414                                 }
00415                         }
00416                         if ($result[$table])    {
00417                                 $result[$table] = implode(',',$result[$table]);
00418                         }
00419                 }
00420                 return $result;
00421         }
00422 
00429         function getFileFields($uploadfolder)   {
00430                 global $TCA;
00431                 reset ($TCA);
00432                 $result = Array();
00433                 while (list($table)=each($TCA)) {
00434                         t3lib_div::loadTCA($table);
00435                         $cols = $TCA[$table]['columns'];
00436                         reset ($cols);
00437                         while (list($field,$config)=each($cols))        {
00438                                 if ($config['config']['type']=='group' && $config['config']['internal_type']=='file' && $config['config']['uploadfolder']==$uploadfolder)       {
00439                                         $result[]=Array($table,$field);
00440                                 }
00441                         }
00442                 }
00443                 return $result;
00444         }
00445 
00452         function getDBFields($theSearchTable)   {
00453                 global $TCA;
00454                 $result = Array();
00455                 reset ($TCA);
00456                 while (list($table)=each($TCA)) {
00457                         t3lib_div::loadTCA($table);
00458                         $cols = $TCA[$table]['columns'];
00459                         reset ($cols);
00460                         while (list($field,$config)=each($cols))        {
00461                                 if ($config['config']['type']=='group' && $config['config']['internal_type']=='db')     {
00462                                         if (trim($config['config']['allowed'])=='*' || strstr($config['config']['allowed'],$theSearchTable))    {
00463                                                 $result[]=Array($table,$field);
00464                                         }
00465                                 } else if ($config['config']['type']=='select' && $config['config']['foreign_table']==$theSearchTable)  {
00466                                         $result[]=Array($table,$field);
00467                                 }
00468                         }
00469                 }
00470                 return $result;
00471         }
00472 
00480         function selectNonEmptyRecordsWithFkeys($fkey_arrays)   {
00481                 global $TCA;
00482                 if (is_array($fkey_arrays))     {
00483                         reset($fkey_arrays);
00484                         while (list($table,$field_list)=each($fkey_arrays))     {
00485                                 if ($TCA[$table] && trim($field_list))  {
00486                                         t3lib_div::loadTCA($table);
00487                                         $fieldArr = explode(',',$field_list);
00488 
00489                                         if(t3lib_extMgm::isLoaded('dbal')) {
00490                                                 $fields = $GLOBALS['TYPO3_DB']->admin_get_fields($table);
00491                                                 reset($fields);
00492                                                 list(,$field)=each($fieldArr);
00493                                                 $cl_fl = ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'I' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'N' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'R') ?
00494                                                 $field.'!=0' : $field.'!=\'\'';
00495                                                 while (list(,$field)=each($fieldArr))   {
00496                                                         $cl_fl .= ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'I' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'N' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'],$table) == 'R') ?
00497                                                         ' OR '.$field.'!=0' : ' OR '.$field.'!=\'\'';
00498                                                 }
00499                                                 unset($fields);
00500                                         }
00501                                         else {
00502                                         $cl_fl = implode ('!="" OR ',$fieldArr). '!=""';
00503                                         }
00504 
00505                                         $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,'.$field_list, $table, $cl_fl);
00506                                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))     {
00507                                                 reset($fieldArr);
00508                                                 while (list(,$field)=each($fieldArr))   {
00509                                                         if (trim($row[$field]))         {
00510                                                                 $fieldConf = $TCA[$table]['columns'][$field]['config'];
00511                                                                 if ($fieldConf['type']=='group')        {
00512                                                                         if ($fieldConf['internal_type']=='file')        {
00513                                                                                 // files...
00514                                                                                 if ($fieldConf['MM'])   {
00515                                                                                         $tempArr=array();
00516                                                                                         $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00517                                                                                         $dbAnalysis->start('','files',$fieldConf['MM'],$row['uid']);
00518                                                                                         reset($dbAnalysis->itemArray);
00519                                                                                         while (list($somekey,$someval)=each($dbAnalysis->itemArray))    {
00520                                                                                                 if ($someval['id'])     {
00521                                                                                                         $tempArr[]=$someval['id'];
00522                                                                                                 }
00523                                                                                         }
00524                                                                                 } else {
00525                                                                                         $tempArr = explode(',',trim($row[$field]));
00526                                                                                 }
00527                                                                                 reset($tempArr);
00528                                                                                 while (list(,$file)=each($tempArr))     {
00529                                                                                         $file = trim($file);
00530                                                                                         if ($file)      {
00531                                                                                                 $this->checkFileRefs[$fieldConf['uploadfolder']][$file]+=1;
00532                                                                                         }
00533                                                                                 }
00534                                                                         }
00535                                                                         if ($fieldConf['internal_type']=='db')  {
00536                                                                                 // dbs - group
00537                                                                                 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00538                                                                                 $dbAnalysis->start($row[$field],$fieldConf['allowed'],$fieldConf['MM'],$row['uid']);
00539                                                                                 reset($dbAnalysis->itemArray);
00540                                                                                 while (list(,$tempArr)=each($dbAnalysis->itemArray))    {
00541                                                                                         $this->checkGroupDBRefs[$tempArr['table']][$tempArr['id']]+=1;
00542                                                                                 }
00543                                                                         }
00544                                                                 }
00545                                                                 if ($fieldConf['type']=='select' && $fieldConf['foreign_table'])        {
00546                                                                         // dbs - select
00547                                                                         $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00548                                                                         $dbAnalysis->start($row[$field],$fieldConf['foreign_table'],$fieldConf['MM'],$row['uid']);
00549                                                                         reset($dbAnalysis->itemArray);
00550                                                                         while (list(,$tempArr)=each($dbAnalysis->itemArray))    {
00551                                                                                 if ($tempArr['id']>0)   {
00552                                                                                         $this->checkGroupDBRefs[$fieldConf['foreign_table']][$tempArr['id']]+=1;
00553                                                                                 }
00554                                                                         }
00555                                                                 }
00556                                                         }
00557                                                 }
00558                                         }
00559                                 }
00560                         }
00561                 }
00562         }
00563 
00569         function testFileRefs ()        {
00570                 $output=Array();
00571                 reset($this->checkFileRefs);
00572                 while(list($folder,$fileArr)=each($this->checkFileRefs))        {
00573                         $path = PATH_site.$folder;
00574                         if (@is_dir($path))     {
00575                                 $d = dir($path);
00576                                 while($entry=$d->read()) {
00577                                         if (@is_file($path.'/'.$entry)) {
00578                                                 if (isset($fileArr[$entry]))    {
00579                                                         if ($fileArr[$entry] > 1)       {
00580                                                                 $temp = $this->whereIsFileReferenced($folder,$entry);
00581                                                                 $tempList = '';
00582                                                                 while(list(,$inf)=each($temp))  {
00583                                                                         $tempList.='['.$inf['table'].']['.$inf['uid'].']['.$inf['field'].'] (pid:'.$inf['pid'].') - ';
00584                                                                 }
00585                                                                 $output['moreReferences'][] = Array($path,$entry,$fileArr[$entry],$tempList);
00586                                                         }
00587                                                         unset($fileArr[$entry]);
00588                                                 } else {
00589                                                         if (!strstr($entry,'index.htm'))        {
00590                                                                 $output['noReferences'][] = Array($path,$entry);
00591                                                         }
00592                                                 }
00593                                         }
00594                                 }
00595                                 $d->close();
00596                                 reset($fileArr);
00597                                 $tempCounter=0;
00598                                 while(list($file,)=each($fileArr))      {
00599                                         $temp = $this->whereIsFileReferenced($folder,$file);
00600                                         $tempList = '';
00601                                         while(list(,$inf)=each($temp))  {
00602                                                 $tempList.='['.$inf['table'].']['.$inf['uid'].']['.$inf['field'].'] (pid:'.$inf['pid'].') - ';
00603                                         }
00604                                         $tempCounter++;
00605                                         $output['noFile'][substr($path,-3).'_'.substr($file,0,3).'_'.$tempCounter] = Array($path,$file,$tempList);
00606                                 }
00607                         } else {
00608                                 $output['error'][] = Array($path);
00609                         }
00610                 }
00611                 return $output;
00612         }
00613 
00620         function testDBRefs($theArray)  {
00621                 global $TCA;
00622                 reset($theArray);
00623                 while(list($table,$dbArr)=each($theArray))      {
00624                         if ($TCA[$table])       {
00625                                 $idlist = Array();
00626                                 while(list($id,)=each($dbArr))  {
00627                                         $idlist[]=$id;
00628                                 }
00629                                 $theList = implode(',',$idlist);
00630                                 if ($theList)   {
00631                                         $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'uid IN ('.$theList.')'.t3lib_BEfunc::deleteClause($table));
00632                                         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))      {
00633                                                 if (isset($dbArr[$row['uid']])) {
00634                                                         unset ($dbArr[$row['uid']]);
00635                                                 } else {
00636                                                         $result.='Strange Error. ...<br />';
00637                                                 }
00638                                         }
00639                                         reset($dbArr);
00640                                         while (list($theId,$theC)=each($dbArr)) {
00641                                                 $result.='There are '.$theC.' records pointing to this missing or deleted record; ['.$table.']['.$theId.']<br />';
00642                                         }
00643                                 }
00644                         } else {
00645                                 $result.='Codeerror. Table is not a table...<br />';
00646                         }
00647                 }
00648                 return $result;
00649         }
00650 
00658         function whereIsRecordReferenced($searchTable,$id)      {
00659                 global $TCA;
00660                 $fileFields = $this->getDBFields($searchTable); // Gets tables / Fields that reference to files...
00661                 $theRecordList=Array();
00662                 while (list(,$info)=each($fileFields))  {
00663                         $table=$info[0];        $field=$info[1];
00664                         t3lib_div::loadTCA($table);
00665                         $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00666                                                         'uid,pid,'.$TCA[$table]['ctrl']['label'].','.$field,
00667                                                         $table,
00668                                                         $field.' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($id, $table).'%\''
00669                                                 );
00670                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))     {
00671                                         // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
00672                                 $fieldConf = $TCA[$table]['columns'][$field]['config'];
00673                                 $allowedTables = ($fieldConf['type']=='group') ? $fieldConf['allowed'] : $fieldConf['foreign_table'];
00674 
00675                                 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
00676                                 $dbAnalysis->start($row[$field],$allowedTables,$fieldConf['MM'],$row['uid']);
00677                                 reset($dbAnalysis->itemArray);
00678                                 while (list(,$tempArr)=each($dbAnalysis->itemArray))    {
00679                                         if ($tempArr['table']==$searchTable && $tempArr['id']==$id)     {
00680                                                 $theRecordList[]=Array('table'=>$table,'uid'=>$row['uid'],'field'=>$field,'pid'=>$row['pid']);
00681                                         }
00682                                 }
00683                         }
00684                 }
00685                 return $theRecordList;
00686         }
00687 
00695         function whereIsFileReferenced($uploadfolder,$filename) {
00696                 global $TCA;
00697                 $fileFields = $this->getFileFields($uploadfolder);      // Gets tables / Fields that reference to files...
00698                 $theRecordList=Array();
00699                 while (list(,$info)=each($fileFields))  {
00700                         $table=$info[0];        $field=$info[1];
00701                         $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00702                                                         'uid,pid,'.$TCA[$table]['ctrl']['label'].','.$field,
00703                                                         $table,
00704                                                         $field.' LIKE \'%'.$GLOBALS['TYPO3_DB']->quoteStr($filename, $table).'%\''
00705                                                 );
00706                         while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres))     {
00707                                 // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
00708                                 $tempArr = explode(',',trim($row[$field]));
00709                                 while (list(,$file)=each($tempArr))     {
00710                                         $file = trim($file);
00711                                         if ($file==$filename)   {
00712                                                 $theRecordList[]=Array('table'=>$table,'uid'=>$row['uid'],'field'=>$field,'pid'=>$row['pid']);
00713                                         }
00714                                 }
00715                         }
00716                 }
00717                 return $theRecordList;
00718         }
00719 }
00720 
00721 
00722 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php'])     {
00723         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php']);
00724 }
00725 ?>