Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / class.show_rechis.inc
1 <?php
2 /***************************************************************
3 *  Copyright notice
4 *  
5 *  (c) 1999-2003 Kasper Skaarhoj (kasper@typo3.com)
6 *  All rights reserved
7 *
8 *  This script is part of the TYPO3 project. The TYPO3 project is 
9 *  free software; you can redistribute it and/or modify
10 *  it under the terms of the GNU General Public License as published by
11 *  the Free Software Foundation; either version 2 of the License, or
12 *  (at your option) any later version.
13
14 *  The GNU General Public License can be found at
15 *  http://www.gnu.org/copyleft/gpl.html.
16 *  A copy is found in the textfile GPL.txt and important notices to the license 
17 *  from the author is found in LICENSE.txt distributed with these scripts.
18 *
19
20 *  This script is distributed in the hope that it will be useful,
21 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 *  GNU General Public License for more details.
24 *
25 *  This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /** 
28  * Class for the record history display script (show_rechis.php)
29  *
30  * $Id$
31  *
32  * @author      Kasper Skaarhoj <kasper@typo3.com>
33  */
34 /**
35  * [CLASS/FUNCTION INDEX of SCRIPT]
36  *
37  *
38  *
39  *   77: class recordHistory 
40  *   88:     function getChangesSinceRecord($element,$hisUid=0,$hisUid_Stop=0)  
41  *  133:     function nextHisUid($element,$hisUid)      
42  *  167:     function compareChangesWithCurrent($element,$changeRec,$discardFileLists=0)        
43  *  203:     function readFieldTypes($table,$id)        
44  *  226:     function cmp($changeStatus,$oldRecord)     
45  *  245:     function revertToPreviousValues($element,$field)   
46  *  298:     function saveState($element,$sumUp)        
47  *  343:     function removeFilefields($table,$dataArray)       
48  *  363:     function displayHistory($element)  
49  *  487:     function renderEntry($entry,$table)        
50  *  537:     function displaySysHistoryEntry($sh_uid)   
51  *  573:     function listHeader()      
52  *  613:     function linkPage($str,$inparams=array(),$anchor="")       
53  *
54  * TOTAL FUNCTIONS: 13
55  * (This index is automatically created/updated by the extension "extdeveval")
56  *
57  */
58
59
60
61
62
63
64
65
66
67
68
69
70 /**
71  * Class for the record history display script (show_rechis.php)
72  * 
73  * @author      Kasper Skaarhoj <kasper@typo3.com>
74  * @package TYPO3
75  * @subpackage core
76  */
77 class recordHistory {
78         var $listType = 0;
79         var $maxSteps=20;
80         
81         
82         /**
83          * @param       [type]          $element: ...
84          * @param       [type]          $hisUid: ...
85          * @param       [type]          $hisUid_Stop: ...
86          * @return      [type]          ...
87          */
88         function getChangesSinceRecord($element,$hisUid=0,$hisUid_Stop=0)       {
89                 global $TCA;
90
91                 $sumChangesArray=array();
92                 $sumChangesArray["changes"]=array();
93                 $elParts = explode(":",$element);
94                 if ($TCA[$elParts[0]])  {
95                         $addWhere = " AND sys_history.uid>=".$hisUid;
96                         if ($hisUid_Stop)       $addWhere.= " AND sys_history.uid<=".$hisUid_Stop;
97                         $query="SELECT sys_history.*,sys_log.userid FROM sys_history,sys_log WHERE 
98                                 sys_history.sys_log_uid=sys_log.uid
99                                 AND sys_history.tablename='".$elParts[0]."' 
100                                 AND sys_history.recuid=".intval($elParts[1]).$addWhere." 
101                                 ORDER BY uid DESC";
102
103                         $res = mysql(TYPO3_db,$query);
104                         $times=array();
105                         while ($newRow = mysql_fetch_assoc($res))       {
106                                 $hisDat = unserialize($newRow["history_data"]);
107                                 if (is_array($hisDat["newRecord"]) && is_array($hisDat["oldRecord"]))   {
108 //                                      if ($newRow["uid"]!=$hisUid)    {       // Overlay the old-record values... 
109 //debug($hisDat["oldRecord"]);
110                                                 $sumChangesArray["changes"]=array_merge($sumChangesArray["changes"],$hisDat["oldRecord"]);
111         //                              } else {        // ... unless the record is the one we're waiting for..
112                 //                              $sumChangesArray["changes"]=array_merge($sumChangesArray["changes"],$hisDat["newRecord"]);
113                         //              }
114                                         $sumChangesArray["counter"]++;
115                                         $sumChangesArray["tstamp"][]=$newRow["tstamp"];
116                                         $sumChangesArray["userList"][]=$newRow["userid"];
117                                 } else {
118                                         debug("ERROR!");
119                                 }
120                                 
121                         }
122                 }       
123                 return $sumChangesArray;
124         }
125
126         /**
127          * [Describe function...]
128          * 
129          * @param       [type]          $element: ...
130          * @param       [type]          $hisUid: ...
131          * @return      [type]          ...
132          */
133         function nextHisUid($element,$hisUid)   {
134                 $elParts = explode(":",$element);
135                 // Prev:
136                         $query="SELECT uid FROM sys_history WHERE 
137                                 tablename='".$elParts[0]."' 
138                                 AND recuid=".intval($elParts[1])." 
139                                 AND uid<".intval($hisUid)."
140                                 ORDER BY uid DESC LIMIT 1";
141                         $res = mysql(TYPO3_db,$query);
142                         if ($row = mysql_fetch_assoc($res))     {
143                                 $prevUid=$row["uid"];
144                         }
145                 // Next         
146                         $query="SELECT uid FROM sys_history WHERE 
147                                 tablename='".$elParts[0]."' 
148                                 AND recuid=".intval($elParts[1])." 
149                                 AND uid>".intval($hisUid)."
150                                 ORDER BY uid LIMIT 1";
151                         $res = mysql(TYPO3_db,$query);
152                         if ($row = mysql_fetch_assoc($res))     {
153                                 $nextUid=$row["uid"];
154                         }
155
156                 return array($prevUid,$nextUid);
157         }
158
159         /**
160          * [Describe function...]
161          * 
162          * @param       [type]          $element: ...
163          * @param       [type]          $changeRec: ...
164          * @param       [type]          $discardFileLists: ...
165          * @return      [type]          ...
166          */
167         function compareChangesWithCurrent($element,$changeRec,$discardFileLists=0)     {
168                 global $TCA;
169
170                 $sumChangesArray=array();
171                 $elParts = explode(":",$element);
172                 $newChangeRec=array();
173                 if ($TCA[$elParts[0]])  {
174                         $currentRecord = t3lib_BEfunc::getRecord($elParts[0],$elParts[1]);
175                                                         // list($currentRecord,$DB_fieldTypes) = $this->readFieldTypes($elParts[0],$elParts[1]);
176                                                 // || ($cRecTypes[$col]=="int" && $currentRecord[$col]==0 && !strcmp($val,"")
177                         if (is_array($currentRecord) && is_array($changeRec["changes"]))        {
178                                 reset($changeRec["changes"]);
179                                 while(list($fN,$fV)=each($changeRec["changes"]))        {
180                                         if (strcmp($fV,$currentRecord[$fN]))    {
181                                                 $newChangeRec["oldRecord"][$fN]=$fV;
182                                                 $newChangeRec["newRecord"][$fN]=$currentRecord[$fN];
183                                         }
184                                 }
185                                 $newChangeRec["tstamp"]=min($changeRec["tstamp"]);
186                                 $newChangeRec["counter"]=$changeRec["counter"];
187                                 $newChangeRec["userList"]=array_unique($changeRec["userList"]);
188                         } else {
189                                 return false;   // No arrays, possibly no record
190                         }
191                 }       
192                 
193                 return $newChangeRec;
194         }
195
196         /**
197          * [Describe function...]
198          * 
199          * @param       [type]          $table: ...
200          * @param       [type]          $id: ...
201          * @return      [type]          ...
202          */
203         function readFieldTypes($table,$id)     {
204                 $res = mysql(TYPO3_db,"SELECT * FROM $table WHERE uid=".intval($id));
205                         // Fetch the types of the fields.
206                 if (mysql_num_rows($res))       {
207                         $currentRecord = mysql_fetch_assoc($res);
208                         $c=0;
209                         reset($currentRecord);
210                         $cRecTypes=array();
211                         while (list($col,$val)=each($currentRecord))    {
212                                 $cRecTypes[$col]=mysql_field_type($res,$c);
213                                 $c++;
214                         }
215                 }
216                 return array($currentRecord,$cRecTypes);
217         }
218
219         /**
220          * [Describe function...]
221          * 
222          * @param       [type]          $changeStatus: ...
223          * @param       [type]          $oldRecord: ...
224          * @return      [type]          ...
225          */
226         function cmp($changeStatus,$oldRecord)  {
227                 reset($oldRecord);
228                 $changes=array();
229                 while(list($fN,$fV)=each($oldRecord))   {
230                         if (isset($changeStatus[$fN]) && strcmp($fV,$changeStatus[$fN]))        {
231                                 $changes["oldRecord"][$fN]=$changeStatus[$fN];
232                                 $changes["newRecord"][$fN]=$fV;
233                         }
234                 }
235                 return $changes;
236         }
237
238         /**
239          * [Describe function...]
240          * 
241          * @param       [type]          $element: ...
242          * @param       [type]          $field: ...
243          * @return      [type]          ...
244          */
245         function revertToPreviousValues($element,$field)        {
246                 $sumUp = t3lib_div::GPvar("sumUp");
247
248                 $elParts = explode(":",$element);
249                 $redirect=intval(t3lib_div::GPvar("doReturn"));
250                 if ($sumUp==-1) {       // Undo/Redo
251                         $query="SELECT uid FROM sys_history WHERE 
252                                 sys_history.tablename='".$elParts[0]."' 
253                                 AND sys_history.recuid=".intval($elParts[1])." 
254                                 ORDER BY uid DESC LIMIT 1";
255                         $res = mysql(TYPO3_db,$query);
256                         if ($row = mysql_fetch_assoc($res))     {
257                                 $sumUp=$row["uid"];
258                         }
259                         $redirect=1;
260                 }
261                 if ($sumUp!=-1) {
262                         $changeRec=$this->compareChangesWithCurrent($element,$this->getChangesSinceRecord($element,$sumUp));
263
264                         $data =array();
265                         if (t3lib_BEfunc::getRecord($elParts[0],$elParts[1]))   {
266                                 if ($field=="ALL_FIELDS")       {
267                                         $data=$changeRec["oldRecord"];
268                                 } elseif(substr($field,0,6)=="field:") {
269                                         $data[substr($field,6)]=$changeRec["oldRecord"][substr($field,6)];
270                                 }
271                                 $data = $this->removeFilefields($elParts[0],$data);
272                                 if (count($data))       {
273                                         $inData=array();
274                                         $inData[$elParts[0]][$elParts[1]]=$data;
275                                         $tce = t3lib_div::makeInstance("t3lib_TCEmain");
276                                         $tce->stripslashes_values=0;
277                                         $tce->debug=0;
278                                         $tce->dontProcessTransformations=1;
279                                         $tce->start($inData,array());
280                                         $tce->process_datamap();
281                                 }
282                         }
283                 }
284
285                 if ($redirect)  {
286                         Header ("Location: ".t3lib_div::locationHeaderUrl(t3lib_div::GPvar("returnUrl")));
287                         exit;
288                 }
289         }
290
291         /**
292          * [Describe function...]
293          * 
294          * @param       [type]          $element: ...
295          * @param       [type]          $sumUp: ...
296          * @return      [type]          ...
297          */
298         function saveState($element,$sumUp)     {
299                 $elParts = explode(":",$element);
300
301                 $changeRec = $this->getChangesSinceRecord($element,$sumUp);
302
303                 $query="SELECT history_data FROM sys_history WHERE 
304                         sys_history.tablename='".$elParts[0]."' 
305                         AND sys_history.recuid=".intval($elParts[1])." 
306                         ORDER BY uid DESC LIMIT 1";
307                 $res = mysql(TYPO3_db,$query);
308                 if ($row = mysql_fetch_assoc($res))     {
309                         $lastestData = unserialize($row["history_data"]);
310 //                      debug($lastestData);
311                 }
312
313
314                 $historyRecords=array();
315                 $historyRecords["oldRecord"] = $changeRec["changes"];
316                 $historyRecords["newRecord"] = array();
317                 reset($historyRecords["oldRecord"]);
318                 while(list($kk)=each($historyRecords["oldRecord"]))     {
319                         $historyRecords["newRecord"][$kk]=$lastestData["newRecord"][$kk];
320                 }
321
322                 $updateID = $GLOBALS["BE_USER"]->writelog(3,1,0,1,"Saved state","");
323                 
324                 $fields_values=array();
325                 $fields_values["history_data"]=serialize($historyRecords);
326                 $fields_values["fieldlist"]=implode(",",array_keys($historyRecords["oldRecord"]));
327                 $fields_values["tstamp"]=time();
328                 $fields_values["tablename"]=$elParts[0];
329                 $fields_values["recuid"]=$elParts[1];
330                 $fields_values["sys_log_uid"]=$updateID;
331                 $fields_values["snapshot"]=1;
332                 $query = t3lib_BEfunc::DBcompileInsert("sys_history",$fields_values);
333                 $res = mysql(TYPO3_db,$query);
334         }
335
336         /**
337          * [Describe function...]
338          * 
339          * @param       [type]          $table: ...
340          * @param       [type]          $dataArray: ...
341          * @return      [type]          ...
342          */
343         function removeFilefields($table,$dataArray)    {
344                 global $TCA;
345                 if ($TCA[$table])       {
346                         t3lib_div::loadTCA($table);
347                         reset($TCA[$table]["columns"]);
348                         while(list($field,$config)=each($TCA[$table]["columns"]))       {
349                                 if ($config["config"]["type"]=="group" && $config["config"]["internal_type"]=="file")   {
350                                         unset($dataArray[$field]);
351                                 }
352                         }
353                 }
354                 return $dataArray;
355         }
356
357         /**
358          * [Describe function...]
359          * 
360          * @param       [type]          $element: ...
361          * @return      [type]          ...
362          */
363         function displayHistory($element)       {
364                 global $SOBE, $LANG, $TCA;
365                 
366                 $elParts = explode(":",$element);
367                 $table = $elParts[0];
368                 if ($TCA[$table])       {
369                         $mainQBody = "FROM sys_history,sys_log WHERE 
370                                 sys_history.sys_log_uid=sys_log.uid
371                                 AND sys_history.tablename='".$table."' 
372                                 AND sys_history.recuid=".intval($elParts[1]);
373                         $query="SELECT count(*) ".$mainQBody; 
374                         $res = mysql(TYPO3_db,$query);
375                         list($Rcount)=mysql_fetch_row($res);
376
377                         $max = $this->maxSteps; // How many steps back...
378                         $query="SELECT sys_history.*,sys_log.userid ".$mainQBody." 
379                                 ORDER BY uid LIMIT ".t3lib_div::intInRange($Rcount-$max,0).",".$max;
380                         $res = mysql(TYPO3_db,$query);
381
382                         $changesArray=array();
383                         $changeLog=array();
384                         while ($newRow = mysql_fetch_assoc($res))       {
385                                 $hisDat = unserialize($newRow["history_data"]);
386                                 if (is_array($hisDat["newRecord"]) && is_array($hisDat["oldRecord"]))   {
387                                                 // If intermedia changes:
388                                         $intermediaChanges = $this->cmp($changesArray,$hisDat["oldRecord"]);
389                                         if (count($intermediaChanges) && !$newRow["snapshot"])  {
390                                                 $changeLog[]=$intermediaChanges;
391                                         }
392
393                                                 // Add hisDat to the changeLog
394                                         $hisDat["uid"]=$newRow["uid"];
395                                         $hisDat["tstamp"]=$newRow["tstamp"];
396                                         $hisDat["user"]=$newRow["userid"];
397                                         $hisDat["snapshot"]=$newRow["snapshot"];
398                                         $changeLog[]=$hisDat;
399
400                                                 // Update change array
401                                                 // this is used to detect if any intermedia changes has been made.
402                                         $changesArray = array_merge($changesArray,$hisDat["newRecord"]);
403                                 } else {
404                                         debug("ERROR: [displayHistory]");
405                                 }
406                         }
407                         
408                         $lines=array();
409                         $darkerBgColor = t3lib_div::modifyHTMLcolor($SOBE->doc->bgColor4,-30,-30,-30);
410                         $darkerBgColor_interM = "#cccccc";
411                         if (t3lib_div::GPvar("sumUp"))  {
412                                 
413                                 $changeLog=array();
414                                 $changeLog[]=$this->compareChangesWithCurrent($element,$this->getChangesSinceRecord($element,t3lib_div::GPvar("sumUp")));
415                                 $this->listType=2;
416                                 $lines[]=$this->listHeader();
417                                 $be_users = t3lib_BEfunc::getUserNames();
418                                 
419                                 list($prevHisUid,$nextHisUid) = $this->nextHisUid($element,t3lib_div::GPvar("sumUp"));
420                                 
421                                 $linkPack=      ($prevHisUid ? $this->linkPage('<img src="gfx/pilup.gif" width="14" height="14" hspace=1 border="0" title="'.$LANG->getLL("prev").'">', array("sumUp"=>$prevHisUid)) : "").
422                                 ($nextHisUid ? $this->linkPage('<img src="gfx/pildown.gif" width="14" height="14" hspace=1 border="0" title="'.$LANG->getLL("next").'">', array("sumUp"=>$nextHisUid)) : "").
423                                 '<BR>'.$this->linkPage('<img src="gfx/history2.gif" width="13" height="12" hspace=1 vspace=3 border="0" title="'.$LANG->getLL("historyList").'">', array("sumUp"=>""), "uid_".t3lib_div::GPvar("sumUp")).
424                                 
425                                 $this->linkPage('<img src="gfx/savesnapshot.gif" width="17" height="12" hspace=1 vspace=3 border="0" title="'.$LANG->getLL("saveState").'">', array("saveState"=>t3lib_div::GPvar("sumUp"),"sumUp"=>""), "latest");
426                                 
427                                 reset($changeLog);
428                                 while(list(,$entry)=each($changeLog))   {
429                                         if (!is_array($entry["userList"]))      $entry["userList"]=array();
430                                         reset($entry["userList"]);
431                                         while(list($uLk,$uV)=each($entry["userList"]))  {
432                                                 $entry["userList"][$uLk]=$be_users[$uV]["username"];
433                                         }
434                                         
435                                         $lines[]='<tr bgColor="'.$darkerBgColor.'">
436                                                 <td valign=top>'.$linkPack.'</td>
437                                                 <td colspan=4><B>'.$LANG->getLL("time").':</B> '.t3lib_BEfunc::datetime($entry["tstamp"]).', '.t3lib_BEfunc::calcAge(time()-$entry["tstamp"],$GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears")).' &nbsp; - &nbsp; <B>'.$LANG->getLL("changeCount").':</B> '.$entry["counter"].'<BR>
438                                                         <B>'.$LANG->getLL("users").':</B> '.implode(", ",$entry["userList"]).' 
439                                                 </td>
440                                         </tr>';
441                                         if (isset($entry["oldRecord"]) && isset($entry["newRecord"]))   {
442                                                 $lines = array_merge($lines,$this->renderEntry($entry,$table));
443                                         } else {
444                                                 $lines[]='<tr bgColor="'.$SOBE->doc->bgColor4.'"><td colspan=5 align=center><BR><B>'.$LANG->getLL("similar").'</B><BR><BR></td></tr>';
445                                         }
446                                 }
447                         } else {                        
448                                         // Change Log:
449                                 $this->listType=1;
450                                 $be_users = t3lib_BEfunc::getUserNames();
451                                 $lines[]=$this->listHeader();
452                                 reset($changeLog);
453                                 
454                                 while(list($c,$entry)=each($changeLog)) {
455                                         $lines[]='<tr><td colspan=3>&nbsp;</td></tr>';
456                                         $lastAnchor = ($c+1==count($changeLog)?'<a name="latest"></a>':"");
457                                         if ($entry["uid"])      {
458                                                 $theTime = $this->linkPage(t3lib_BEfunc::datetime($entry["tstamp"]),array("sh_uid"=>$entry["uid"],"element"=>""));
459                                                 $lines[]='<tr bgColor="'.($entry["snapshot"]?$SOBE->doc->bgColor2:$darkerBgColor).'">
460                                                         <td colspan=2>'.$lastAnchor.'<a name="uid_'.$entry["uid"].'"></a>'.($entry["snapshot"]?'<img src="gfx/napshot.gif" width="12" height="12" border="0" align=top>':'').'<B>'.$LANG->getLL("time").':</B> '.$theTime.', '.t3lib_BEfunc::calcAge(time()-$entry["tstamp"],$GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears")).' &nbsp; - &nbsp; <B>'.$LANG->getLL("user").':</B> '.$be_users[$entry["user"]]["username"].'</td>
461                                                         <td>'.
462                                                         $this->linkPage('<img src="gfx/history.gif" width="13" height="12" hspace=2 border="0" title="'.$LANG->getLL("revertAllFields").'">', array("revert"=>"ALL_FIELDS","sumUp"=>$entry["uid"],"doReturn"=>1)).
463                                                         $this->linkPage('<img src="gfx/history_details.gif" width="12" height="12" hspace=2 border="0" title="'.$LANG->getLL("sumUpChanges").'">', array("sumUp"=>$entry["uid"])).'</td>
464                                                 </tr>';
465                                         } else {
466                                                 $lines[]='<tr bgColor="'.$darkerBgColor_interM.'">
467                                                         <td colspan=3><strong>'.$LANG->getLL("externalChange").'</strong></td>
468                                                         </tr>';
469                                         }
470                                         $lines = array_merge($lines,$this->renderEntry($entry,$table));
471                                 }
472                         }
473                         
474                         $theCode='<table border=0 cellpadding=2 cellspacing=2>'.implode("",$lines).'</table>';
475                         $theCode.='<BR><img src="gfx/icon_note.gif" width="18" height="16" border="0" align="top">'.$LANG->getLL("differenceMsg")."<BR><BR>";
476                         return $SOBE->doc->section($LANG->getLL("changes"),$theCode,0,1);
477                 }
478         }
479
480         /**
481          * [Describe function...]
482          * 
483          * @param       [type]          $entry: ...
484          * @param       [type]          $table: ...
485          * @return      [type]          ...
486          */
487         function renderEntry($entry,$table)     {
488                 global $SOBE, $LANG, $TCA;
489                 $lines=array();
490                 if (is_array($entry["newRecord"]))      {
491                         $fieldsToDisplay = array_keys($entry["newRecord"]);
492                         reset($fieldsToDisplay);
493                         $t3lib_diff_Obj = t3lib_div::makeInstance("t3lib_diff");
494                         while(list(,$fN)=each($fieldsToDisplay))        {
495                                 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
496                                         t3lib_BEfunc::getProcessedValue($table,$fN,$entry["oldRecord"][$fN],0,1),
497                                         t3lib_BEfunc::getProcessedValue($table,$fN,$entry["newRecord"][$fN],0,1)
498                                 );
499
500                                 switch($this->listType) {
501                                         case 1:
502                                                 $lines[]='<tr bgColor="'.$SOBE->doc->bgColor4.'">
503                                                         <td valign=top>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN,"<i>|</i>")).'</td>
504                                                         <td valign=top>'.nl2br($diffres).'</td>
505                                                         <td valign=top>&nbsp;</td>
506                                                 </tr>';
507                                         break;
508                                         case 2:
509                                                 $lines[]='<tr bgColor="'.$SOBE->doc->bgColor4.'">
510                                                         <td valign=top>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN,"<i>|</i>")).'</td>
511                                                         <td valign=top>'.t3lib_BEfunc::getProcessedValue($table,$fN,$entry["oldRecord"][$fN]).'</td>
512                                                         <td valign=top>'.$this->linkPage('<img src="gfx/history.gif" width="13" height="12" border="0" title="'.$LANG->getLL("revertField").'">', array("revert"=>"field:".$fN)).'</td>
513                                                         <td valign=top>'.t3lib_BEfunc::getProcessedValue($table,$fN,$entry["newRecord"][$fN]).'</td>
514                                                         <td valign=top>'.nl2br($diffres).'</td>
515                                                 </tr>';
516                                         break;
517                                         default:
518                                                 $lines[]='<tr bgColor="'.$SOBE->doc->bgColor4.'">
519                                                         <td valign=top>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN,"<i>|</i>")).'</td>
520                                                         <td valign=top>'.t3lib_BEfunc::getProcessedValue($table,$fN,$entry["oldRecord"][$fN]).'</td>
521                                                         <td valign=top>'.t3lib_BEfunc::getProcessedValue($table,$fN,$entry["newRecord"][$fN]).'</td>
522                                                         <td valign=top>'.nl2br($diffres).'</td>
523                                                 </tr>';
524                                         break;
525                                 }
526                         }
527                 }
528                 return $lines;
529         }
530
531         /**
532          * [Describe function...]
533          * 
534          * @param       [type]          $sh_uid: ...
535          * @return      [type]          ...
536          */
537         function displaySysHistoryEntry($sh_uid)        {
538                 global $SOBE, $LANG, $TCA;
539
540                 $query="SELECT * FROM sys_history WHERE uid=".intval($sh_uid);
541                 $res = mysql(TYPO3_db,$query);
542                 $newRow = mysql_fetch_assoc($res);
543                 if (is_array($newRow))  {
544                         $this->listType=0;
545                         $lines=array();
546
547                         $recIdentString = $LANG->sL($TCA[$newRow["tablename"]]["ctrl"]["title"])."/".$newRow["recuid"];
548                         $recIdentString = $this->linkPage($recIdentString,array("sh_uid"=>"","element"=>$newRow["tablename"].":".$newRow["recuid"]),"uid_".$sh_uid);
549                         $lines[]='<tr bgColor="'.$SOBE->doc->bgColor5.'">
550                                 <td colspan=4>
551                                         <strong>'.$LANG->getLL("tableUid").':</strong> '.$recIdentString.'<br>
552                                         <strong>'.$LANG->getLL("time").':</strong> '.t3lib_BEfunc::datetime($newRow["tstamp"]).', '.t3lib_BEfunc::calcAge(time()-$newRow["tstamp"],$GLOBALS["LANG"]->sL("LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears")).'<br>
553                                         </td>
554                         </tr>';
555
556                         $lines[]=$this->listHeader();
557
558                         $historyData = unserialize($newRow["history_data"]);
559                         $lines = array_merge($lines,$this->renderEntry($historyData,$newRow["tablename"]));
560                         
561                         $theCode='<table border=0 cellpadding=2 cellspacing=2>'.implode("",$lines).'</table>';
562                         $theCode.='<BR><img src="gfx/icon_note.gif" width="18" height="16" border="0" align="top">'.$LANG->getLL("differenceMsg")."<BR><BR>";
563                         $content.=$SOBE->doc->section($LANG->getLL("changes"),$theCode,0,1);
564                 }
565                 return $content;
566         }
567
568         /**
569          * [Describe function...]
570          * 
571          * @return      [type]          ...
572          */
573         function listHeader()   {
574                 global $SOBE, $LANG, $TCA;
575
576                 switch($this->listType) {
577                         case 1:
578                                 $out='<tr bgColor="'.$SOBE->doc->bgColor5.'">
579                                         <td valign=top nowrap><strong>'.$LANG->getLL("fieldName").':</strong></td>
580                                         <td valign=top nowrap><strong>'.$LANG->getLL("difference").':</strong></td>
581                                         <td valign=top>&nbsp;</td>
582                                 </tr>'; 
583                         break;
584                         case 2:
585                                 $out='<tr bgColor="'.$SOBE->doc->bgColor5.'">
586                                         <td valign=top nowrap><strong>'.$LANG->getLL("fieldName").':</strong></td>
587                                         <td valign=top nowrap><strong>'.$LANG->getLL("oldValue").':</strong></td>
588                                         <td valign=top nowrap><strong>'.$this->linkPage('<img src="gfx/history.gif" width="13" height="12" border="0" title="'.$LANG->getLL("revertAllFields").'">', array("revert"=>"ALL_FIELDS")).'</strong></td>
589                                         <td valign=top nowrap><strong>'.$LANG->getLL("currentValue").':</strong></td>
590                                         <td valign=top nowrap><strong>'.$LANG->getLL("difference").':</strong></td>
591                                 </tr>'; 
592                         break;
593                         default:
594                                 $out='<tr bgColor="'.$SOBE->doc->bgColor5.'">
595                                         <td valign=top nowrap><strong>'.$LANG->getLL("fieldName").':</strong></td>
596                                         <td valign=top nowrap><strong>'.$LANG->getLL("oldValue").':</strong></td>
597                                         <td valign=top nowrap><strong>'.$LANG->getLL("newValue").':</strong></td>
598                                         <td valign=top nowrap><strong>'.$LANG->getLL("difference").':</strong></td>
599                                 </tr>'; 
600                         break;
601                 }
602                 return $out;
603         }
604
605         /**
606          * [Describe function...]
607          * 
608          * @param       [type]          $str: ...
609          * @param       [type]          $inparams: ...
610          * @param       [type]          $anchor: ...
611          * @return      [type]          ...
612          */
613         function linkPage($str,$inparams=array(),$anchor="")    {
614                 $params["sh_uid"]=t3lib_div::GPvar("sh_uid");
615                 $params["sumUp"]=t3lib_div::GPvar("sumUp");
616                 $params["element"]=t3lib_div::GPvar("element");
617                 $params["returnUrl"]=t3lib_div::GPvar("returnUrl");
618                 $params = array_merge($params,$inparams);                       // Candidate for t3lib_div::array_merge() if integer-keys will some day make trouble...
619                 $link = '<a href="show_rechis.php?'.t3lib_div::implodeArrayForUrl("",$params).($anchor?"#".$anchor:"").'">'.$str.'</a>';
620                 return $link;
621         }
622 }
623
624 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc'])     {
625         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class.show_rechis.inc']);
626 }
627 ?>