Documentation TYPO3 par Ameos

class.show_rechis.inc

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 ***************************************************************/
00083 class recordHistory {
00084 
00085                 // External, static:
00086         var $maxSteps=20;               // Maximum number of sys_history steps to show.
00087 
00088                 // Internal, dynamic:
00089         var $listType = 0;              // This value determines the kind of list build. The variable is used as a parameter from some functions.
00090 
00091                 // Internal, static. GPvars:
00092         var $sh_uid;                    // sh_uid is the id-number of the sys_history log item to SHOW
00093         var $element;                   // Element reference, syntax [tablename]:[uid]
00094         var $saveState;                 // Saving states: Points to a sys_history UID which should be saved.
00095         var $returnUrl;                 // Return URL - kept in links, used to link back to calling module.
00096         var $revert;                    // String identifying mode of reverting: Either all fields or only a single field to revert. See function revertToPreviousValues()
00097         var $sumUp;                     // Generally used as a pointer to a sys_history uid as a state.
00098         var $doReturn;                  // If set, function revertToPreviousValues() will perform a redirect to returnUrl
00099 
00100 
00106         function recordHistory()        {
00107 
00108                         // GPvars:
00109                 $this->sh_uid = t3lib_div::_GP('sh_uid');
00110                 $this->element = t3lib_div::_GP('element');
00111                 $this->saveState = t3lib_div::_GP('saveState');
00112                 $this->returnUrl = t3lib_div::_GP('returnUrl');
00113                 $this->revert = t3lib_div::_GP('revert');
00114                 $this->sumUp = t3lib_div::_GP('sumUp');
00115                 $this->doReturn = t3lib_div::_GP('doReturn');
00116         }
00117 
00124         function main() {
00125 
00126                 $content='';
00127 
00128                         // If link from sys log:
00129                         // sh_uid is the id-number of the sys_history log item
00130                 if ($this->sh_uid)      {
00131                         $content.=$this->displaySysHistoryEntry($this->sh_uid);
00132                 }
00133 
00134                         // If link to element:
00135                 if ($this->element)     {
00136                         if ($this->revert && $this->sumUp)      {
00137                                 $content.=$this->revertToPreviousValues($this->element,$this->revert);
00138                         }
00139                         if ($this->saveState)   {
00140                                 $content.=$this->saveState($this->element,$this->saveState);
00141                         }
00142                         $content.=$this->displayHistory($this->element);
00143                 }
00144 
00145                         // Return content variable:
00146                 return $content;
00147         }
00148 
00155         function displaySysHistoryEntry($sh_uid)        {
00156                 global $SOBE, $LANG, $TCA;
00157 
00158                         // Select the entry from the table:
00159                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_history', 'uid='.intval($sh_uid));
00160                 $newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00161 
00162                         // If an entry was found:
00163                 if (is_array($newRow))  {
00164 
00165                                 // Init:
00166                         $this->listType=0;
00167                         $lines=array();
00168 
00169                                 // Create header:
00170                         $recIdentString = $LANG->sL($TCA[$newRow['tablename']]['ctrl']['title']).'/'.$newRow['recuid'];
00171                         $recIdentString = $this->linkPage(htmlspecialchars($recIdentString),array('sh_uid'=>'','element'=>$newRow['tablename'].':'.$newRow['recuid']),'uid_'.$sh_uid);
00172                         $theTime = t3lib_BEfunc::datetime($newRow['tstamp']).', '.t3lib_BEfunc::calcAge(time()-$newRow['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'));
00173                         $lines[]='
00174                                 <tr class="bgColor5">
00175                                         <td colspan="4">
00176                                                 <strong>'.$LANG->getLL('tableUid',1).':</strong> '.$recIdentString.'<br />
00177                                                 <strong>'.$LANG->getLL('time',1).':</strong> '.htmlspecialchars($theTime).'<br />
00178                                         </td>
00179                                 </tr>';
00180 
00181                                 // Add header to accumulation:
00182                         $lines[]=$this->listHeader();
00183 
00184                                 // Get the entry data and add it:
00185                         $historyData = unserialize($newRow['history_data']);
00186                         $lines = array_merge($lines,$this->renderEntry($historyData,$newRow['tablename']));
00187 
00188                                 // Combine all content into a table for layout:
00189                         $theCode='
00190 
00191                                 <!--
00192                                         History for item:
00193                                 -->
00194                                 <table border="0" cellpadding="2" cellspacing="2" id="typo3-history-item">
00195                                         '.implode('',$lines).'
00196                                 </table>';
00197 
00198                         $theCode.='
00199                                 <br /><img'.t3lib_iconWorks::skinImg('','gfx/icon_note.gif','width="18" height="16"').' align="top" alt="" />'.$LANG->getLL('differenceMsg').'<br /><br />';
00200 
00201                                 // Add CSH:
00202                         $theCode.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'history_entry', $GLOBALS['BACK_PATH'],'');
00203 
00204                                 // Create the module section:
00205                         $content.=$SOBE->doc->section($LANG->getLL('changes'),$theCode,0,1);
00206                 }
00207 
00208                         // Return content:
00209                 return $content;
00210         }
00211 
00219         function revertToPreviousValues($element,$field)        {
00220                 $sumUp = $this->sumUp;  // sys_history uid from which to get previous values
00221 
00222                 $elParts = explode(':',$element);
00223                 $redirect = intval($this->doReturn);
00224                 if ($sumUp==-1) {       // Undo/Redo
00225                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00226                                                 'uid',
00227                                                 'sys_history',
00228                                                 'sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($elParts[0], 'sys_history').'
00229                                                         AND sys_history.recuid='.intval($elParts[1]),
00230                                                 '',
00231                                                 'uid DESC',
00232                                                 '1'
00233                                         );
00234                         if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00235                                 $sumUp=$row['uid'];
00236                         }
00237                         $redirect = 1;
00238                 }
00239                 if ($sumUp!=-1) {
00240                         $changeRec=$this->compareChangesWithCurrent($element,$this->getChangesSinceRecord($element,$sumUp));
00241 
00242                         $data =array();
00243                         if (t3lib_BEfunc::getRecord($elParts[0],$elParts[1]))   {
00244 
00245                                         // Fields field(s) to restore:
00246                                 if ($field=='ALL_FIELDS')       {
00247                                         $data=$changeRec['oldRecord'];
00248                                 } elseif(substr($field,0,6)=='field:') {
00249                                         $data[substr($field,6)]=$changeRec['oldRecord'][substr($field,6)];
00250                                 }
00251                                         // Removing fields:
00252                                 $data = $this->removeFilefields($elParts[0],$data);
00253 
00254                                         // If there are fields to write:
00255                                 if (count($data))       {
00256 
00257                                                 // Setting data right:
00258                                         $inData=array();
00259                                         $inData[$elParts[0]][$elParts[1]]=$data;
00260 
00261                                                 // Writes the data:
00262                                         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00263                                         $tce->stripslashes_values=0;
00264                                         $tce->debug=0;
00265                                         $tce->dontProcessTransformations=1;
00266                                         $tce->start($inData,array());
00267                                         $tce->process_datamap();
00268                                 }
00269                         }
00270                 }
00271 
00272                 if ($redirect)  {
00273                         Header ('Location: '.t3lib_div::locationHeaderUrl($this->returnUrl));
00274                         exit;
00275                 }
00276         }
00277 
00285         function saveState($element,$sumUp)     {
00286                 $elParts = explode(':',$element);
00287 
00288                         // Find the changes since $sumUp sys_history uid
00289                 $changeRec = $this->getChangesSinceRecord($element,$sumUp);
00290 
00291                         // Select most recent sys_history record for the element:
00292                 $lastestData = array();
00293                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00294                                         'history_data',
00295                                         'sys_history',
00296                                         'sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($elParts[0], 'sys_history').'
00297                                                 AND sys_history.recuid='.intval($elParts[1]),
00298                                         '',
00299                                         'uid DESC',
00300                                         '1'
00301                                 );
00302                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00303                         $lastestData = unserialize($row['history_data']);
00304                 }
00305 
00306                         // Create forged history data from the most recent state and the previous state to save:
00307                 $historyRecords=array();
00308                 $historyRecords['oldRecord'] = $changeRec['changes'];
00309                 $historyRecords['newRecord'] = array();
00310 
00311                 reset($historyRecords['oldRecord']);
00312                 while(list($kk)=each($historyRecords['oldRecord']))     {
00313                         $historyRecords['newRecord'][$kk]=$lastestData['newRecord'][$kk];
00314                 }
00315 
00316                         // Update log:
00317                 $updateID = $GLOBALS['BE_USER']->writelog(3,1,0,1,'Saved state','');
00318 
00319                         // Create query for inserting into sys_history table:
00320                 $fields_values = array(
00321                         'history_data' => serialize($historyRecords),
00322                         'fieldlist' => implode(',',array_keys($historyRecords['oldRecord'])),
00323                         'tstamp' => time(),
00324                         'tablename' => $elParts[0],
00325                         'recuid' => $elParts[1],
00326                         'sys_log_uid' => $updateID,
00327                         'snapshot' => 1
00328                 );
00329                         // Save state by executing this query:
00330                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_history', $fields_values);
00331         }
00332 
00339         function displayHistory($element)       {
00340                 global $SOBE, $LANG, $TCA;
00341 
00342                         // Initialize:
00343                 $elParts = explode(':',$element);
00344                 $table = $elParts[0];
00345 
00346                         // If table is found in $TCA:
00347                 if ($TCA[$table])       {
00348 
00349                                 // Counting number of states:
00350                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00351                                                 'COUNT(*)',
00352                                                 'sys_history,sys_log',
00353                                                 'sys_history.sys_log_uid=sys_log.uid
00354                                                         AND sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history').'
00355                                                         AND sys_history.recuid='.intval($elParts[1])
00356                                         );
00357                         list($Rcount) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00358 
00359                                 // Selecting the $this->maxSteps most recent states:
00360                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00361                                                 'sys_history.*,sys_log.userid',
00362                                                 'sys_history,sys_log',
00363                                                 'sys_history.sys_log_uid=sys_log.uid
00364                                                         AND sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history').'
00365                                                         AND sys_history.recuid='.intval($elParts[1]),
00366                                                 '',
00367                                                 'sys_log.uid',
00368                                                 t3lib_div::intInRange($Rcount-$this->maxSteps,0).','.$this->maxSteps
00369                                         );
00370 
00371                                 // Traversing the result, building up changesArray / changeLog:
00372                         $changesArray=array();
00373                         $changeLog=array();
00374                         while ($newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00375                                 $hisDat = unserialize($newRow['history_data']);
00376                                 if (is_array($hisDat['newRecord']) && is_array($hisDat['oldRecord']))   {
00377                                                 // If intermedia changes:
00378                                         $intermediaChanges = $this->cmp($changesArray,$hisDat['oldRecord']);
00379                                         if (count($intermediaChanges) && !$newRow['snapshot'])  {
00380                                                 $changeLog[]=$intermediaChanges;
00381                                         }
00382 
00383                                                 // Add hisDat to the changeLog
00384                                         $hisDat['uid']=$newRow['uid'];
00385                                         $hisDat['tstamp']=$newRow['tstamp'];
00386                                         $hisDat['user']=$newRow['userid'];
00387                                         $hisDat['snapshot']=$newRow['snapshot'];
00388                                         $changeLog[]=$hisDat;
00389 
00390                                                 // Update change array
00391                                                 // This is used to detect if any intermedia changes has been made.
00392                                         $changesArray = array_merge($changesArray,$hisDat['newRecord']);
00393                                 } else {
00394                                         debug('ERROR: [displayHistory]');
00395                                 }
00396                         }
00397 
00398 
00399                         $lines=array();
00400                         $darkerBgColor_interM = '#cccccc';
00401                         if ($this->sumUp)       {       // Show details for a single point in the list:
00402 
00403                                         // Initialize:
00404                                 $changeLog=array();             // array is reset here because we want to show only one item (and therefore we will build it all over again...)
00405                                 $changeLog[]=$this->compareChangesWithCurrent($element,$this->getChangesSinceRecord($element,$this->sumUp));
00406                                 $this->listType=2;
00407                                 $lines[]=$this->listHeader();
00408                                 $be_users = t3lib_BEfunc::getUserNames();
00409 
00410                                         // Get the previous/next uids:
00411                                 list($prevHisUid,$nextHisUid) = $this->nextHisUid($element,$this->sumUp);
00412 
00413                                         // Create the set of navigation links:
00414                                 $linkPack =
00415                                         ($prevHisUid ? $this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/pilup.gif','width="14" height="14"').' title="'.$LANG->getLL('prev',1).'" alt="" />', array('sumUp'=>$prevHisUid)) : '').        // previous
00416                                         ($nextHisUid ? $this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/pildown.gif','width="14" height="14"').' title="'.$LANG->getLL('next',1).'" alt="" />', array('sumUp'=>$nextHisUid)) : '').      // next
00417                                         '<br />'.$this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/history2.gif','width="13" height="12"').' title="'.$LANG->getLL('historyList',1).'" alt="" />', array('sumUp'=>''), 'uid_'.$this->sumUp).      // back to list
00418                                         $this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/savesnapshot.gif','width="17" height="12"').' title="'.$LANG->getLL('saveState',1).'" alt="" />', array('saveState'=>$this->sumUp,'sumUp'=>''), 'latest');      // save state
00419 
00420                                         // Traverse changelog array:
00421                                 foreach($changeLog as $entry)   {
00422 
00423                                                 // Set user-names:
00424                                         if (!is_array($entry['userList']))      $entry['userList']=array();
00425                                         foreach($entry['userList'] as $uLk => $uV)      {
00426                                                 $entry['userList'][$uLk]=$be_users[$uV]['username'];
00427                                         }
00428 
00429                                                 // Add the header:
00430                                         $theTime = t3lib_BEfunc::datetime($entry['tstamp']).', '.t3lib_BEfunc::calcAge(time()-$entry['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'));
00431                                         $lines[]='
00432                                                 <tr class="bgColor4-20">
00433                                                         <td valign="top">'.$linkPack.'</td>
00434                                                         <td colspan="4"><b>'.$LANG->getLL('time',1).':</b> '.htmlspecialchars($theTime).' &nbsp; - &nbsp; <b>'.$LANG->getLL('changeCount',1).':</b> '.$entry['counter'].'<br />
00435                                                                 <b>'.$LANG->getLL('users',1).':</b> '.implode(', ',$entry['userList']).'
00436                                                         </td>
00437                                                 </tr>';
00438 
00439                                                 // Add content:
00440                                         if (isset($entry['oldRecord']) && isset($entry['newRecord']))   {       // If there ARE differences to show, then add lines for each changed field:
00441                                                 $lines = array_merge($lines,$this->renderEntry($entry,$table));
00442                                         } else {        // Otherwise, if no changes - show a message about that!
00443                                                 $lines[]='
00444                                                         <tr class="bgColor4">
00445                                                                 <td colspan="5" align="center"><br /><b>'.$LANG->getLL('similar',1).'</b><br /><br /></td>
00446                                                         </tr>';
00447                                         }
00448                                 }
00449                         } else {        // Show the full change Log:
00450 
00451                                         // Initialize:
00452                                 $this->listType=1;
00453                                 $be_users = t3lib_BEfunc::getUserNames();
00454                                 $lines[]=$this->listHeader();
00455 
00456                                         // Traverse changelog array:
00457                                 foreach($changeLog as $c => $entry)     {
00458 
00459                                                 // Add spacer line:
00460                                         $lines[]='
00461                                                 <tr>
00462                                                         <td colspan="3">&nbsp;</td>
00463                                                 </tr>';
00464 
00465                                                 // Anchor to latest entry:
00466                                         $lastAnchor = ($c+1==count($changeLog)?'<a name="latest"></a>':'');
00467 
00468                                                 // Render state header:
00469                                         if ($entry['uid'])      {       // This state was made by the backend:
00470                                                 $theTime = $this->linkPage(t3lib_BEfunc::datetime($entry['tstamp']),array('sh_uid'=>$entry['uid'],'element'=>''));
00471                                                 $theAge = ', '.t3lib_BEfunc::calcAge(time()-$entry['tstamp'],$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'));
00472                                                 $bgColorClass = $entry['snapshot'] ? 'bgColor2' : 'bgColor4-20';
00473                                                 $lines[]='
00474                                                         <tr class="'.$bgColorClass.'">
00475                                                                 <td colspan="2">'.
00476                                                                         $lastAnchor.
00477                                                                         '<a name="uid_'.$entry['uid'].'"></a>'.
00478                                                                         ($entry['snapshot'] ? '<img'.t3lib_iconWorks::skinImg('','gfx/snapshot.gif','width="12" height="12"').' alt="" />':'').
00479                                                                         '<b>'.$LANG->getLL('time',1).':</b> '.$theTime.htmlspecialchars($theAge).' &nbsp; - &nbsp; <b>'.$LANG->getLL('user',1).':</b> '.$be_users[$entry['user']]['username'].
00480                                                                 '</td>
00481                                                                 <td>'.
00482                                                                         $this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/history.gif','width="13" height="12"').' title="'.$LANG->getLL('revertAllFields',1).'" alt="" />', array('revert'=>'ALL_FIELDS','sumUp'=>$entry['uid'],'doReturn'=>1)).
00483                                                                         $this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/history_details.gif','width="12" height="12"').' title="'.$LANG->getLL('sumUpChanges',1).'" alt="" />', array('sumUp'=>$entry['uid'])).
00484                                                                 '</td>
00485                                                         </tr>';
00486                                         } else {        // This state must have been some external change:
00487                                                 $lines[]='
00488                                                         <tr bgcolor="'.$darkerBgColor_interM.'">
00489                                                                 <td colspan="3"><strong>'.$LANG->getLL('externalChange',1).'</strong></td>
00490                                                         </tr>';
00491                                         }
00492                                                 // Merge state header with all entries in the state:
00493                                         $lines = array_merge($lines,$this->renderEntry($entry,$table));
00494                                 }
00495                         }
00496 
00497                                 // Finally, put it all together:
00498                         $theCode='
00499 
00500                                 <!--
00501                                         Item history (either list or single):
00502                                 -->
00503                                 <table border="0" cellpadding="2" cellspacing="2" id="typo3-history">
00504                                         '.implode('',$lines).'
00505                                 </table>';
00506 
00507                                 // Add message about the difference view.
00508                         $theCode.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/icon_note.gif','width="18" height="16"').' align="top" alt="" />'.$LANG->getLL('differenceMsg').'<br /><br />';
00509 
00510                                 // Add CSH:
00511                         $theCode.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'history_'.($this->sumUp ? 'sum' : 'log'), $GLOBALS['BACK_PATH'],'');
00512 
00513                                 // Add the whole content as a module section:
00514                         return $SOBE->doc->section($LANG->getLL('changes'),$theCode,0,1);
00515                 }
00516         }
00517 
00518 
00519 
00520 
00521 
00522 
00523 
00524 
00525 
00526         /*******************************
00527          *
00528          * Various helper functions
00529          *
00530          *******************************/
00531 
00540         function nextHisUid($element,$hisUid)   {
00541                 $elParts = explode(':',$element);
00542 
00543                         // Prev:
00544                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00545                                         'uid',
00546                                         'sys_history',
00547                                         'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($elParts[0], 'sys_history').'
00548                                                 AND recuid='.intval($elParts[1]).'
00549                                                 AND uid<'.intval($hisUid),
00550                                         '',
00551                                         'uid DESC',
00552                                         '1'
00553                                 );
00554                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00555                         $prevUid = $row['uid'];
00556                 }
00557 
00558                         // Next:
00559                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00560                                         'uid',
00561                                         'sys_history',
00562                                         'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($elParts[0], 'sys_history').'
00563                                                 AND recuid='.intval($elParts[1]).'
00564                                                 AND uid>'.intval($hisUid),
00565                                         '',
00566                                         'uid',
00567                                         '1'
00568                                 );
00569                 if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00570                         $nextUid = $row['uid'];
00571                 }
00572 
00573                         // Return next and previous ids:
00574                 return array($prevUid,$nextUid);
00575         }
00576 
00586         function compareChangesWithCurrent($element,$changeRec) {
00587                 global $TCA;
00588 
00589                         // Initialize:
00590                 $sumChangesArray=array();
00591                 $elParts = explode(':',$element);
00592                 $newChangeRec=array();
00593 
00594                         // If tablename is found in $TCA:
00595                 if ($TCA[$elParts[0]])  {
00596 
00597                                 // Select current record content of element:
00598                         $currentRecord = t3lib_BEfunc::getRecord($elParts[0],$elParts[1]);
00599 
00600                                 // If that is found and the "changes" entry of the $changeRec is an array, then proceed:
00601                         if (is_array($currentRecord) && is_array($changeRec['changes']))        {
00602 
00603                                         // For each entry in "changes" we compare the field content with the current and if there is a difference, it is tracked in the array $newChangeRec
00604                                 foreach($changeRec['changes'] as $fN => $fV)    {
00605                                         if (strcmp($fV,$currentRecord[$fN]))    {
00606                                                 $newChangeRec['oldRecord'][$fN]=$fV;
00607                                                 $newChangeRec['newRecord'][$fN]=$currentRecord[$fN];
00608                                         }
00609                                 }
00610                                         // Finally, setting some general information fields:
00611                                 $newChangeRec['tstamp']=min($changeRec['tstamp']);
00612                                 $newChangeRec['counter']=$changeRec['counter'];
00613                                 $newChangeRec['userList']=array_unique($changeRec['userList']);
00614                         } else {
00615                                 return false;   // No arrays, possibly no record
00616                         }
00617                 }
00618 
00619                         // Returns the array of changes detected:
00620                 return $newChangeRec;
00621         }
00622 
00631         function readFieldTypes($table,$id)     {
00632 
00633                         // Select record:
00634                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, 'uid='.intval($id));
00635 
00636                         // Fetch the types of the fields.
00637                 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res))   {
00638                         $currentRecord = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00639                         $c=0;
00640                         $cRecTypes=array();
00641                         foreach($currentRecord as $col => $val) {
00642                                 //$cRecTypes[$col] = $GLOBALS['TYPO3_DB']->sql_field_type($table,$col);
00643 // DBAL
00644                                 $cRecTypes[$col] = $GLOBALS['TYPO3_DB']->sql_field_type($res,$c);
00645                                 $c++;
00646                         }
00647                 }
00648 
00649                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00650 
00651                 return array($currentRecord,$cRecTypes);
00652         }
00653 
00662         function cmp($changeStatus,$oldRecord)  {
00663 
00664                         // Initialize:
00665                 $changes=array();
00666 
00667                         // Traverse $oldRecord
00668                 foreach($oldRecord as $fN => $fV)       {
00669                         if (isset($changeStatus[$fN]) && strcmp($fV,$changeStatus[$fN]))        {
00670                                 $changes['oldRecord'][$fN]=$changeStatus[$fN];
00671                                 $changes['newRecord'][$fN]=$fV;
00672                         }
00673                 }
00674                 return $changes;
00675         }
00676 
00685         function removeFilefields($table,$dataArray)    {
00686                 global $TCA;
00687 
00688                 if ($TCA[$table])       {
00689                         t3lib_div::loadTCA($table);
00690 
00691                         foreach($TCA[$table]['columns'] as $field => $config)   {
00692                                 if ($config['config']['type']=='group' && $config['config']['internal_type']=='file')   {
00693                                         unset($dataArray[$field]);
00694                                 }
00695                         }
00696                 }
00697                 return $dataArray;
00698         }
00699 
00708         function renderEntry($entry,$table)     {
00709                 global $SOBE, $LANG, $TCA;
00710 
00711                 $lines=array();
00712                 if (is_array($entry['newRecord']))      {
00713 
00714                         $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
00715 
00716                         $fieldsToDisplay = array_keys($entry['newRecord']);
00717                         foreach($fieldsToDisplay as $fN)        {
00718                                 t3lib_div::loadTCA($table);
00719                                 if (is_array($TCA[$table]['columns'][$fN]) && $TCA[$table]['columns'][$fN]['config']['type']!='passthrough')    {
00720 
00721                                                 // Create diff-result:
00722                                         $diffres = $t3lib_diff_Obj->makeDiffDisplay(
00723                                                 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN],0,1),
00724                                                 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN],0,1)
00725                                         );
00726 
00727                                                 // Depending on list type, we make the row:
00728                                         switch($this->listType) {
00729                                                 case 1:
00730                                                         $lines[]='
00731                                                                 <tr class="bgColor4">
00732                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN),1).'</em></td>
00733                                                                         <td>'.nl2br($diffres).'</td>
00734                                                                         <td>&nbsp;</td>
00735                                                                 </tr>';
00736                                                 break;
00737                                                 case 2:
00738                                                         $lines[]='
00739                                                                 <tr class="bgColor4">
00740                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN)).'</em></td>
00741                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN])).'</td>
00742                                                                         <td>'.$this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/history.gif','width="13" height="12"').' title="'.$LANG->getLL('revertField',1).'" alt="" />', array('revert'=>'field:'.$fN)).'</td>
00743                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN])).'</td>
00744                                                                         <td>'.nl2br($diffres).'</td>
00745                                                                 </tr>';
00746                                                 break;
00747                                                 default:
00748                                                         $lines[]='
00749                                                                 <tr class="bgColor4">
00750                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN)).'</em></td>
00751                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN])).'</td>
00752                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN])).'</td>
00753                                                                         <td>'.nl2br($diffres).'</td>
00754                                                                 </tr>';
00755                                                 break;
00756                                         }
00757                                 }
00758                         }
00759                 }
00760                 return $lines;
00761         }
00762 
00769         function listHeader()   {
00770                 global $SOBE, $LANG;
00771 
00772                 switch($this->listType) {
00773                         case 1:
00774                                 $out='
00775                                         <tr class="bgColor5 c-head">
00776                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00777                                                 <td>'.$LANG->getLL('difference',1).':</td>
00778                                                 <td>&nbsp;</td>
00779                                         </tr>';
00780                         break;
00781                         case 2:
00782                                 $out='
00783                                         <tr class="bgColor5 c-head">
00784                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00785                                                 <td>'.$LANG->getLL('oldValue',1).':</td>
00786                                                 <td>'.$this->linkPage('<img'.t3lib_iconWorks::skinImg('','gfx/history.gif','width="13" height="12"').' title="'.$LANG->getLL('revertAllFields',1).'" alt="" />', array('revert'=>'ALL_FIELDS')).'</td>
00787                                                 <td>'.$LANG->getLL('currentValue',1).':</td>
00788                                                 <td>'.$LANG->getLL('difference',1).':</td>
00789                                         </tr>';
00790                         break;
00791                         default:
00792                                 $out='
00793                                         <tr class="bgColor5 c-head">
00794                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00795                                                 <td>'.$LANG->getLL('oldValue',1).':</td>
00796                                                 <td>'.$LANG->getLL('newValue',1).':</td>
00797                                                 <td>'.$LANG->getLL('difference',1).':</td>
00798                                         </tr>';
00799                         break;
00800                 }
00801                 return $out;
00802         }
00803 
00813         function linkPage($str,$inparams=array(),$anchor='')    {
00814 
00815                         // Setting default values based on GET parameters:
00816                 $params['sh_uid']=$this->sh_uid;
00817                 $params['sumUp']=$this->sumUp;
00818                 $params['element']=$this->element;
00819                 $params['returnUrl']=$this->returnUrl;
00820 
00821                         // Mergin overriding values:
00822                 $params = array_merge($params,$inparams);
00823 
00824                         // Make the link:
00825                 $Ahref = 'show_rechis.php?'.t3lib_div::implodeArrayForUrl('',$params).($anchor?'#'.$anchor:'');
00826                 $link = '<a href="'.htmlspecialchars($Ahref).'">'.$str.'</a>';
00827 
00828                         // Return link:
00829                 return $link;
00830         }
00831 
00841         function getChangesSinceRecord($element,$hisUid=0,$hisUid_Stop=0)       {
00842                 global $TCA;
00843 
00844                         // Init:
00845                 $sumChangesArray=array();
00846                 $sumChangesArray['changes']=array();
00847                 $elParts = explode(':',$element);
00848 
00849                         // If there is a table by the requested name:
00850                 if ($TCA[$elParts[0]])  {
00851                         $times = array();
00852 
00853                                 // Create query for selecting sys_history records in time interval:
00854                         $addWhere = ' AND sys_history.uid>='.$hisUid;
00855                         if ($hisUid_Stop)       $addWhere.= ' AND sys_history.uid<='.$hisUid_Stop;
00856                                 // Make query:
00857                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00858                                                         'sys_history.*,sys_log.userid',
00859                                                         'sys_history,sys_log',
00860                                                         'sys_history.sys_log_uid=sys_log.uid
00861                                                                 AND sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($elParts[0], 'sys_history').'
00862                                                                 AND sys_history.recuid='.intval($elParts[1]).$addWhere,
00863                                                         '',
00864                                                         'uid DESC'
00865                                                 );
00866 
00867                                 // Travese results:
00868                         while ($newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00869                                 $hisDat = unserialize($newRow['history_data']);
00870                                 if (is_array($hisDat['newRecord']) && is_array($hisDat['oldRecord']))   {
00871                                         $sumChangesArray['changes']=array_merge($sumChangesArray['changes'],$hisDat['oldRecord']);
00872                                         $sumChangesArray['counter']++;
00873                                         $sumChangesArray['tstamp'][]=$newRow['tstamp'];
00874                                         $sumChangesArray['userList'][]=$newRow['userid'];
00875                                 } else {
00876                                         debug('ERROR!');
00877                                 }
00878 
00879                         }
00880                 }
00881                 return $sumChangesArray;
00882         }
00883 }
00884 
00885 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc'])     {
00886         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc']);
00887 }
00888 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6