Documentation TYPO3 par Ameos

class.show_rechis.inc

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2004 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']->quoteStr($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']->quoteStr($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']->quoteStr($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']->quoteStr($table, 'sys_history').'"
00365                                                         AND sys_history.recuid='.intval($elParts[1]),
00366                                                 '',
00367                                                 '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']->quoteStr($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']->quoteStr($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($res,$c);
00643                                 $c++;
00644                         }
00645                 }
00646 
00647                 $GLOBALS['TYPO3_DB']->sql_free_result($res);
00648 
00649                 return array($currentRecord,$cRecTypes);
00650         }
00651 
00660         function cmp($changeStatus,$oldRecord)  {
00661 
00662                         // Initialize:
00663                 $changes=array();
00664 
00665                         // Traverse $oldRecord
00666                 foreach($oldRecord as $fN => $fV)       {
00667                         if (isset($changeStatus[$fN]) && strcmp($fV,$changeStatus[$fN]))        {
00668                                 $changes['oldRecord'][$fN]=$changeStatus[$fN];
00669                                 $changes['newRecord'][$fN]=$fV;
00670                         }
00671                 }
00672                 return $changes;
00673         }
00674 
00683         function removeFilefields($table,$dataArray)    {
00684                 global $TCA;
00685 
00686                 if ($TCA[$table])       {
00687                         t3lib_div::loadTCA($table);
00688 
00689                         foreach($TCA[$table]['columns'] as $field => $config)   {
00690                                 if ($config['config']['type']=='group' && $config['config']['internal_type']=='file')   {
00691                                         unset($dataArray[$field]);
00692                                 }
00693                         }
00694                 }
00695                 return $dataArray;
00696         }
00697 
00706         function renderEntry($entry,$table)     {
00707                 global $SOBE, $LANG, $TCA;
00708 
00709                 $lines=array();
00710                 if (is_array($entry['newRecord']))      {
00711 
00712                         $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
00713 
00714                         $fieldsToDisplay = array_keys($entry['newRecord']);
00715                         foreach($fieldsToDisplay as $fN)        {
00716                                 if (is_array($TCA[$table]['columns'][$fN]) && $TCA[$table]['columns'][$fN]['config']['type']!='passthrough')    {
00717 
00718                                                 // Create diff-result:
00719                                         $diffres = $t3lib_diff_Obj->makeDiffDisplay(
00720                                                 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN],0,1),
00721                                                 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN],0,1)
00722                                         );
00723 
00724                                                 // Depending on list type, we make the row:
00725                                         switch($this->listType) {
00726                                                 case 1:
00727                                                         $lines[]='
00728                                                                 <tr class="bgColor4">
00729                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN),1).'</em></td>
00730                                                                         <td>'.nl2br($diffres).'</td>
00731                                                                         <td>&nbsp;</td>
00732                                                                 </tr>';
00733                                                 break;
00734                                                 case 2:
00735                                                         $lines[]='
00736                                                                 <tr class="bgColor4">
00737                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN)).'</em></td>
00738                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN])).'</td>
00739                                                                         <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>
00740                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN])).'</td>
00741                                                                         <td>'.nl2br($diffres).'</td>
00742                                                                 </tr>';
00743                                                 break;
00744                                                 default:
00745                                                         $lines[]='
00746                                                                 <tr class="bgColor4">
00747                                                                         <td><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN)).'</em></td>
00748                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN])).'</td>
00749                                                                         <td>'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN])).'</td>
00750                                                                         <td>'.nl2br($diffres).'</td>
00751                                                                 </tr>';
00752                                                 break;
00753                                         }
00754                                 }
00755                         }
00756                 }
00757                 return $lines;
00758         }
00759 
00766         function listHeader()   {
00767                 global $SOBE, $LANG;
00768 
00769                 switch($this->listType) {
00770                         case 1:
00771                                 $out='
00772                                         <tr class="bgColor5 c-head">
00773                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00774                                                 <td>'.$LANG->getLL('difference',1).':</td>
00775                                                 <td>&nbsp;</td>
00776                                         </tr>';
00777                         break;
00778                         case 2:
00779                                 $out='
00780                                         <tr class="bgColor5 c-head">
00781                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00782                                                 <td>'.$LANG->getLL('oldValue',1).':</td>
00783                                                 <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>
00784                                                 <td>'.$LANG->getLL('currentValue',1).':</td>
00785                                                 <td>'.$LANG->getLL('difference',1).':</td>
00786                                         </tr>';
00787                         break;
00788                         default:
00789                                 $out='
00790                                         <tr class="bgColor5 c-head">
00791                                                 <td>'.$LANG->getLL('fieldName',1).':</td>
00792                                                 <td>'.$LANG->getLL('oldValue',1).':</td>
00793                                                 <td>'.$LANG->getLL('newValue',1).':</td>
00794                                                 <td>'.$LANG->getLL('difference',1).':</td>
00795                                         </tr>';
00796                         break;
00797                 }
00798                 return $out;
00799         }
00800 
00810         function linkPage($str,$inparams=array(),$anchor='')    {
00811 
00812                         // Setting default values based on GET parameters:
00813                 $params['sh_uid']=$this->sh_uid;
00814                 $params['sumUp']=$this->sumUp;
00815                 $params['element']=$this->element;
00816                 $params['returnUrl']=$this->returnUrl;
00817 
00818                         // Mergin overriding values:
00819                 $params = array_merge($params,$inparams);
00820 
00821                         // Make the link:
00822                 $Ahref = 'show_rechis.php?'.t3lib_div::implodeArrayForUrl('',$params).($anchor?'#'.$anchor:'');
00823                 $link = '<a href="'.htmlspecialchars($Ahref).'">'.$str.'</a>';
00824 
00825                         // Return link:
00826                 return $link;
00827         }
00828 
00838         function getChangesSinceRecord($element,$hisUid=0,$hisUid_Stop=0)       {
00839                 global $TCA;
00840 
00841                         // Init:
00842                 $sumChangesArray=array();
00843                 $sumChangesArray['changes']=array();
00844                 $elParts = explode(':',$element);
00845 
00846                         // If there is a table by the requested name:
00847                 if ($TCA[$elParts[0]])  {
00848                         $times = array();
00849 
00850                                 // Create query for selecting sys_history records in time interval:
00851                         $addWhere = ' AND sys_history.uid>='.$hisUid;
00852                         if ($hisUid_Stop)       $addWhere.= ' AND sys_history.uid<='.$hisUid_Stop;
00853                                 // Make query:
00854                         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00855                                                         'sys_history.*,sys_log.userid',
00856                                                         'sys_history,sys_log',
00857                                                         'sys_history.sys_log_uid=sys_log.uid
00858                                                                 AND sys_history.tablename="'.$GLOBALS['TYPO3_DB']->quoteStr($elParts[0], 'sys_history').'"
00859                                                                 AND sys_history.recuid='.intval($elParts[1]).$addWhere,
00860                                                         '',
00861                                                         'uid DESC'
00862                                                 );
00863 
00864                                 // Travese results:
00865                         while ($newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00866                                 $hisDat = unserialize($newRow['history_data']);
00867                                 if (is_array($hisDat['newRecord']) && is_array($hisDat['oldRecord']))   {
00868                                         $sumChangesArray['changes']=array_merge($sumChangesArray['changes'],$hisDat['oldRecord']);
00869                                         $sumChangesArray['counter']++;
00870                                         $sumChangesArray['tstamp'][]=$newRow['tstamp'];
00871                                         $sumChangesArray['userList'][]=$newRow['userid'];
00872                                 } else {
00873                                         debug('ERROR!');
00874                                 }
00875 
00876                         }
00877                 }
00878                 return $sumChangesArray;
00879         }
00880 }
00881 
00882 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc'])     {
00883         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc']);
00884 }
00885 ?>


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