2 /***************************************************************
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * (c) 2006-2009 Sebastian Kurfuerst (sebastian@garbage-group.de)
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 * A copy is found in the textfile GPL.txt and important notices to the license
18 * from the author is found in LICENSE.txt distributed with these scripts.
21 * This script is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * This copyright notice MUST APPEAR in all copies of the script!
27 ***************************************************************/
29 * Class for the record history display script (show_rechis.php)
34 * @author Sebastian Kurfuerst <sebastian@garbage-group.de>
39 * Class for the record history display script (show_rechis.php)
41 * @author Sebastian Kurfuerst <sebastian@garbage-group.de>
47 var $maxSteps=20; // Maximum number of sys_history steps to show.
48 var $showDiff=1; // display diff or not (0-no diff, 1-inline)
49 var $showSubElements=1; // on a pages table - show sub elements as well.
50 var $showInsertDelete=1; // show inserts and deletes as well
53 var $element; // Element reference, syntax [tablename]:[uid]
54 var $lastSyslogId; // syslog ID which is not shown anymore
59 var $showMarked=FALSE;
61 * Constructor for the class
65 function recordHistory() {
67 $this->element = t3lib_div::_GP('element');
68 $this->returnUrl = t3lib_div::_GP('returnUrl');
69 $this->lastSyslogId = t3lib_div::_GP('diff');
70 $this->rollbackFields = t3lib_div::_GP('rollbackFields');
71 // resolve sh_uid if set
72 $this->resolveShUid();
76 * Main function for the listing of history.
77 * It detects incoming variables like element reference, history element uid etc. and renders the correct screen.
79 * @return HTML content for the module
84 // single-click rollback
85 if (t3lib_div::_GP('revert') && t3lib_div::_GP('sumUp')) {
86 $this->rollbackFields = t3lib_div::_GP('revert');
87 $this->showInsertDelete = 0;
88 $this->showSubElements = 0;
90 $element = explode(':',$this->element);
91 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','sys_history', 'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($element[0], 'sys_history').' AND recuid='.intval($element[1]), '', 'uid DESC', '1');
92 $record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
93 $this->lastSyslogId = $record['sys_log_uid'];
95 $this->createChangeLog();
96 $completeDiff = $this->createMultipleDiff();
97 $this->performRollback($completeDiff);
98 t3lib_utility_Http::redirect($this->returnUrl);
102 if (t3lib_div::_GP('highlight') && !t3lib_div::_GP('settings')) {
103 $this->toggleHighlight(t3lib_div::_GP('highlight'));
106 $content .= $this->displaySettings();
107 if ($this->createChangeLog()) {
108 if ($this->rollbackFields) {
109 $completeDiff = $this->createMultipleDiff();
110 $content .= $this->performRollback($completeDiff);
113 if ($this->lastSyslogId) {
114 $completeDiff = $this->createMultipleDiff();
115 $content .= $this->displayMultipleDiff($completeDiff);
117 if ($this->element) {
118 $content .= $this->displayHistory();
124 /*******************************
128 *******************************/
131 * toggles highlight state of record
133 * @param integer uid of sys_history entry
136 function toggleHighlight($uid) {
137 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('snapshot','sys_history','uid='.intval($uid));
138 $tmp = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
139 if ($tmp['snapshot']) {
144 $updateFields = array('snapshot' => $tmp);
145 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_history','uid='.intval($uid),$updateFields);
151 * @param array diff array to rollback
155 function performRollback($diff) {
156 if (!$this->rollbackFields) {
161 $rollbackData = explode(':',$this->rollbackFields);
163 // PROCESS INSERTS AND DELETES
164 // rewrite inserts and deletes
165 $cmdmapArray = array();
166 if ($diff['insertsDeletes']) {
168 switch (count($rollbackData)) {
169 case 1: // all tables
170 $data = $diff['insertsDeletes'];
172 case 2: // one record
173 if ($diff['insertsDeletes'][$this->rollbackFields]) {
174 $data[$this->rollbackFields] = $diff['insertsDeletes'][$this->rollbackFields];
177 case 3: // one field in one record -- ignore!
181 foreach ($data as $key => $action) {
182 $elParts = explode(':',$key);
183 if ($action == 1) { // inserted records should be deleted
184 $cmdmapArray[$elParts[0]][$elParts[1]]['delete'] = 1;
185 // when the record is deleted, the contents of the record do not need to be updated
186 unset($diff['oldData'][$key]);
187 unset($diff['newData'][$key]);
188 } elseif ($action == -1) { // deleted records should be inserted again
189 $cmdmapArray[$elParts[0]][$elParts[1]]['undelete'] = 1;
196 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
197 $tce->stripslashes_values=0;
199 $tce->dontProcessTransformations=1;
200 $tce->start(array(),$cmdmapArray);
201 $tce->process_cmdmap();
203 if (isset($cmdmapArray['pages'])) {
209 // create an array for process_datamap
210 $diff_modified = array();
211 foreach ($diff['oldData'] as $key => $value) {
212 $splitKey = explode(':',$key);
213 $diff_modified[$splitKey[0]][$splitKey[1]] = $value;
215 switch (count($rollbackData)) {
216 case 1: // all tables
217 $data = $diff_modified;
219 case 2: // one record
220 $data[$rollbackData[0]][$rollbackData[1]] = $diff_modified[$rollbackData[0]][$rollbackData[1]];
222 case 3: // one field in one record
223 $data[$rollbackData[0]][$rollbackData[1]][$rollbackData[2]] = $diff_modified[$rollbackData[0]][$rollbackData[1]][$rollbackData[2]];
227 $data = $this->removeFilefields($rollbackData[0],$data);
230 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
231 $tce->stripslashes_values=0;
233 $tce->dontProcessTransformations=1;
234 $tce->start($data,array());
235 $tce->process_datamap();
237 if (isset($data['pages'])) {
241 // return to normal operation
242 $this->lastSyslogId = FALSE;
243 $this->rollbackFields = FALSE;
244 $this->createChangeLog();
246 // reload page frame if necessary
247 if ($reloadPageFrame) {
248 return '<script type="text/javascript">
250 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
251 top.content.nav_frame.refresh_nav();
258 /*******************************
262 *******************************/
267 * @return string HTML code to modify settings
269 function displaySettings() {
270 global $BE_USER, $LANG, $SOBE;
271 // get current selection from UC, merge data, write it back to UC
272 $currentSelection = is_array($BE_USER->uc['moduleData']['history']) ? $BE_USER->uc['moduleData']['history'] : array('maxSteps' => '', 'showDiff' => 1, 'showSubElements' => 1, 'showInsertDelete' => 1);
274 $currentSelectionOverride = t3lib_div::_GP('settings');
275 if ($currentSelectionOverride) {
276 $currentSelection = array_merge($currentSelection,$currentSelectionOverride);
277 $BE_USER->uc['moduleData']['history'] = $currentSelection;
278 $BE_USER->writeUC($BE_USER->uc);
281 // display selector for number of history entries
282 $selector['maxSteps'] = array(
287 '' => 'maxSteps_all',
288 'marked' => 'maxSteps_marked'
290 $selector['showDiff'] = array(
292 1 => 'showDiff_inline'
294 $selector['showSubElements'] = array(
298 $selector['showInsertDelete'] = array(
304 foreach ($selector as $key => $values) {
305 $displayCode .= '<tr><td>'.$LANG->getLL($key,1).'</td><td><select name="settings['.$key.']" onChange="document.settings.submit()" style="width:100px">';
306 foreach ($values as $singleKey => $singleVal) {
307 $caption = $LANG->getLL($singleVal,1)?$LANG->getLL($singleVal,1):$singleVal;
308 $displayCode .= '<option value="'.$singleKey.'" '.(($singleKey == $currentSelection[$key])?'selected':'').'> '.$caption.'</option>';
310 $displayCode .= '</select></td></tr>';
312 // set values correctly
313 if ($currentSelection['maxSteps'] != 'marked') {
314 $this->maxSteps = $currentSelection['maxSteps']?intval($currentSelection['maxSteps']):'';
316 $this->showMarked = TRUE;
317 $this->maxSteps = FALSE;
319 $this->showDiff = intval($currentSelection['showDiff']);
320 $this->showSubElements = intval($currentSelection['showSubElements']);
321 $this->showInsertDelete = intval($currentSelection['showInsertDelete']);
324 // get link to page history if the element history is shown
325 $elParts = explode(':',$this->element);
326 if ($elParts[0] != 'pages') {
327 $content .= '<strong>'.$LANG->getLL('elementHistory',1).'</strong><br />';
328 $pid = t3lib_BEfunc::getRecordRaw($elParts[0],'uid='.intval($elParts[1]));
329 $content .= $this->linkPage($LANG->getLL('elementHistory_link',1),array('element' => 'pages:'.$pid['pid']));
331 $content .= '<form name="settings" action="'.t3lib_div::getIndpEnv('TYPO3_REQUEST_URL').'" method="post"><table>'.$displayCode.'</table></form>';
332 return $SOBE->doc->section($LANG->getLL('settings',1),$content,0,1,0,0);
337 * Shows the full change log
339 * @return string HTML for list, wrapped in a table.
341 function displayHistory() {
349 $lines[] = '<tr class="bgColor5 c-head">
351 <td>'.$LANG->getLL('time',1).'</td>
352 <td>'.$LANG->getLL('age',1).'</td>
353 <td>'.$LANG->getLL('user',1).'</td>
354 <td>'.$LANG->getLL('tableUid',1).'</td>
355 <td>'.$LANG->getLL('differences',1).'</td>
359 // get default page TSconfig expiration time
360 $elParts = explode(':',$this->element);
361 if ($elParts[0] != 'pages') {
362 $tmp = t3lib_BEfunc::getRecordRaw($elParts[0],'uid='.intval($elParts[1]));
367 $tmpTsConfig = $GLOBALS['BE_USER']->getTSConfig('TCEMAIN',t3lib_BEfunc::getPagesTSconfig($pid));
368 $expirationTime = isset($tmpTsConfig['properties']['default.']['history.']['maxAgeDays']) ? $tmpTsConfig['properties']['default.']['history.']['maxAgeDays'] : 30;
370 $expirationTimestamp = $expirationTime ? ($GLOBALS['EXEC_TIME'] - 60 * 60 * 24 * $expirationTime) : 0;
371 $expirationWarning = 0;
373 $be_user_array = t3lib_BEfunc::getUserNames();
375 // Traverse changelog array:
376 if (!$this->changeLog) {
380 foreach ($this->changeLog as $sysLogUid => $entry) {
381 // stop after maxSteps
382 if ($i > $this->maxSteps && $this->maxSteps) {
386 // display inconsistency warning
387 if ($entry['tstamp'] < $expirationTimestamp && !$expirationWarning) {
388 $expirationWarning = 1;
391 <tr class="bgColor4-20">
392 <td colspan="7"><strong>'.$LANG->getLL('consistenceWarning',1).'</strong></td>
396 // show only marked states
397 if (!$entry['snapshot'] && $this->showMarked) {
402 $userName = ($entry['user']?$be_user_array[$entry['user']]['username']:$LANG->getLL('externalChange',1));
404 // build up single line
405 $singleLine = array();
408 $image = t3lib_iconWorks::getSpriteIcon('actions-view-go-forward', array('title' => $LANG->getLL('sumUpChanges', TRUE)));
409 $singleLine[] = '<span>'.$this->linkPage($image,array('diff' => $sysLogUid)).'</span>'; // remove first link
411 $singleLine[] = htmlspecialchars(t3lib_BEfunc::datetime($entry['tstamp'])); // add time
412 $singleLine[] = htmlspecialchars(t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME'] - $entry['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))); // add age
413 $singleLine[] = htmlspecialchars($userName); // add user name
414 $singleLine[] = $this->linkPage($this->generateTitle($entry['tablename'],$entry['recuid']),array('element' => $entry['tablename'].':'.$entry['recuid']),'',$LANG->getLL('linkRecordHistory',1)); // add record UID
416 // show insert/delete/diff/changed field names
417 if ($entry['action']) { // insert or delete of element
418 $singleLine[] = '<strong>'.htmlspecialchars($LANG->getLL($entry['action'],1)).'</strong>';
420 if (!$this->showDiff) { // display field names instead of full diff
421 // re-write field names with labels
422 $tmpFieldList = explode(',',$entry['fieldlist']);
423 foreach ($tmpFieldList as $key => $value) {
424 $tmp = str_replace(':','',$LANG->sl(t3lib_BEfunc::getItemLabel($entry['tablename'],$value),1));
425 if($tmp) $tmpFieldList[$key] = $tmp;
426 else unset($tmpFieldList[$key]); // remove fields if no label available
428 $singleLine[] = htmlspecialchars(implode(',',$tmpFieldList));
429 } else { // display diff
430 $diff = $this->renderDiff($entry,$entry['tablename']);
431 $singleLine[] = $diff;
434 // show link to mark/unmark state
435 if (!$entry['action']) {
436 if ($entry['snapshot']) {
437 $image = '<img'.t3lib_iconWorks::skinImg('','gfx/unmarkstate.gif').' align="top" alt="'.$LANG->getLL('unmarkState',1).'" title="'.$LANG->getLL('unmarkState',1).'" />';
439 $image = '<img'.t3lib_iconWorks::skinImg('','gfx/markstate.gif').' align="top" alt="'.$LANG->getLL('markState',1).'" title="'.$LANG->getLL('markState',1).'" />';
441 $singleLine[] = $this->linkPage($image,array('highlight' => $entry['uid']));
446 $bgColorClass = $entry['snapshot'] ? 'bgColor2' : 'bgColor4-20';
449 <tr class="'.$bgColorClass.'">
450 <td>'.implode('</td><td>',$singleLine).'</td>
454 // Finally, put it all together:
459 <table border="0" cellpadding="2" cellspacing="2" id="typo3-history">
460 '.implode('',$lines).'
463 if ($this->lastSyslogId) {
464 $theCode .= '<br />' . $this->linkPage(t3lib_iconWorks::getSpriteIcon('actions-move-to-bottom', array('title' => $LANG->getLL('fullView', TRUE))), array('diff' => ''));
467 // Add message about the difference view.
468 $flashMessage = t3lib_div::makeInstance(
469 't3lib_FlashMessage',
470 $GLOBALS['LANG']->getLL('differenceMsg'),
472 t3lib_FlashMessage::INFO
475 $theCode .= '<br /><br />' . $flashMessage->render() . '<br />';
478 $theCode .= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'history_'.($this->sumUp ? 'sum' : 'log'), $GLOBALS['BACK_PATH'],'');
480 // Add the whole content as a module section:
481 return $SOBE->doc->section($LANG->getLL('changes'),$theCode,0,1);
485 * Displays a diff over multiple fields including rollback links
487 * @param array difference array
488 * @return string HTML output
490 function displayMultipleDiff($diff) {
494 // get all array keys needed
495 $arrayKeys = array_merge(array_keys($diff['newData']),array_keys($diff['insertsDeletes']),array_keys($diff['oldData']));
496 $arrayKeys = array_unique($arrayKeys);
499 foreach ($arrayKeys as $key) {
501 $elParts = explode(':',$key);
502 // turn around diff because it should be a "rollback preview"
503 if ($diff['insertsDeletes'][$key] == 1) { // insert
504 $record .= '<strong>'.$LANG->getLL('delete',1).'</strong>';
506 } elseif ($diff['insertsDeletes'][$key] == -1) {
507 $record .= '<strong>'.$LANG->getLL('insert',1).'</strong>';
510 // build up temporary diff array
511 // turn around diff because it should be a "rollback preview"
512 if ($diff['newData'][$key]) {
513 $tmpArr['newRecord'] = $diff['oldData'][$key];
514 $tmpArr['oldRecord'] = $diff['newData'][$key];
515 $record .= $this->renderDiff($tmpArr, $elParts[0],$elParts[1]);
518 $elParts = explode(':',$key);
519 $titleLine = $this->createRollbackLink($key, $LANG->getLL('revertRecord',1),1) . $this->generateTitle($elParts[0],$elParts[1]);
520 $record = '<div style="margin-left:10px;padding-left:5px;border-left:1px solid black;border-bottom:1px dotted black;padding-bottom:2px;">'.$record.'</div>';
522 $content .= $SOBE->doc->section($titleLine,$record,0,0,0,1);
524 $content = $this->createRollbackLink('ALL', $LANG->getLL('revertAll',1),0) . '<div style="margin-left:10px;padding-left:5px;border-left:1px solid black;border-bottom:1px dotted black;padding-bottom:2px;">'.$content.'</div>';
526 $content = $LANG->getLL('noDifferences',1);
528 return $SOBE->doc->section($LANG->getLL('mergedDifferences',1),$content,0,1,0,1);
532 * Renders HTML table-rows with the comparison information of an sys_history entry record
534 * @param array sys_history entry record.
535 * @param string The table name
536 * @param integer If set to UID of record, display rollback links
537 * @return string HTML table
540 function renderDiff($entry,$table,$rollbackUid=0) {
541 global $SOBE, $LANG, $TCA;
543 if (is_array($entry['newRecord'])) {
545 $t3lib_diff_Obj = t3lib_div::makeInstance('t3lib_diff');
547 $fieldsToDisplay = array_keys($entry['newRecord']);
548 foreach($fieldsToDisplay as $fN) {
549 t3lib_div::loadTCA($table);
550 if (is_array($TCA[$table]['columns'][$fN]) && $TCA[$table]['columns'][$fN]['config']['type']!='passthrough') {
552 // Create diff-result:
553 $diffres = $t3lib_diff_Obj->makeDiffDisplay(
554 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['oldRecord'][$fN],0,1),
555 t3lib_BEfunc::getProcessedValue($table,$fN,$entry['newRecord'][$fN],0,1)
558 <tr class="bgColor4">
559 '.($rollbackUid?'<td style="width:33px">'.$this->createRollbackLink($table.':'.$rollbackUid.':'.$fN, $LANG->getLL('revertField',1),2).'</td>':'').'
560 <td style="width:90px"><em>'.$LANG->sl(t3lib_BEfunc::getItemLabel($table,$fN),1).'</em></td>
561 <td style="width:300px">'.nl2br($diffres).'</td>
567 $content = '<table border="0" cellpadding="2" cellspacing="2" id="typo3-history-item">
568 '.implode('',$lines).'
572 return NULL; // error fallback
575 /*******************************
579 *******************************/
582 * Creates a diff between the current version of the records and the selected version
584 * @return array diff for many elements
586 function createMultipleDiff() {
587 $insertsDeletes = array();
589 $differences = array();
590 if (!$this->changeLog) {
594 // traverse changelog array
595 foreach ($this->changeLog as $key => $value) {
596 $field = $value['tablename'].':'.$value['recuid'];
598 if ($value['action']) {
599 if (!$insertsDeletes[$field]) {
600 $insertsDeletes[$field] = 0;
602 if ($value['action'] == 'insert') {
603 $insertsDeletes[$field]++;
605 $insertsDeletes[$field]--;
607 // unset not needed fields
608 if ($insertsDeletes[$field] == 0) {
609 unset($insertsDeletes[$field]);
613 if (!isset($newArr[$field])) { // first row of field
614 $newArr[$field] = $value['newRecord'];
615 $differences[$field] = $value['oldRecord'];
617 $differences[$field] = array_merge($differences[$field],$value['oldRecord']);
622 // remove entries where there were no changes effectively
623 foreach ($newArr as $record => $value) {
624 foreach ($value as $key => $innerVal) {
625 if ($newArr[$record][$key] == $differences[$record][$key]) {
626 unset($newArr[$record][$key]);
627 unset($differences[$record][$key]);
630 if (empty($newArr[$record]) && empty($differences[$record])) {
631 unset($newArr[$record]);
632 unset($differences[$record]);
636 'newData' => $newArr,
637 'oldData' => $differences,
638 'insertsDeletes' => $insertsDeletes
643 * Creates change log including sub-elements, filling $this->changeLog
647 function createChangeLog() {
650 $elParts = explode(':',$this->element);
651 $changeLog = $this->getHistoryData($elParts[0],$elParts[1]);
653 // get history of tables of this page and merge it into changelog
654 if ($elParts[0] == 'pages' && $this->showSubElements) {
655 foreach ($TCA as $tablename => $value) {
656 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid',$tablename,'pid='.intval($elParts[1])); // check if there are records on the page
657 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
658 if ($newChangeLog = $this->getHistoryData($tablename, $row['uid'])) { // if there is history data available, merge it into changelog
659 foreach ($newChangeLog as $key => $value) {
660 $changeLog[$key] = $value;
671 $this->changeLog = $changeLog;
677 * Gets history and delete/insert data from sys_log and sys_history
679 * @param string DB table name
680 * @param integer UID of record
681 * @return array history data of the record
683 function getHistoryData($table,$uid) {
685 $uid = $this->resolveElement($table,$uid);
686 // If table is found in $TCA:
688 // Selecting the $this->maxSteps most recent states:
689 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
690 'sys_history.*,sys_log.userid',
691 'sys_history,sys_log',
692 'sys_history.sys_log_uid=sys_log.uid
693 AND sys_history.tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_history').'
694 AND sys_history.recuid='.intval($uid),
700 // Traversing the result, building up changesArray / changeLog:
701 #$changesArray=array(); // used temporarily to track intermedia changes
703 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
704 // only history until a certain syslog ID needed
705 if ($row['sys_log_uid'] < $this->lastSyslogId && $this->lastSyslogId) {
708 $hisDat = unserialize($row['history_data']);
709 if (is_array($hisDat['newRecord']) && is_array($hisDat['oldRecord'])) {
711 // Add hisDat to the changeLog
712 $hisDat['uid']=$row['uid'];
713 $hisDat['tstamp']=$row['tstamp'];
714 $hisDat['user']=$row['userid'];
715 $hisDat['snapshot']=$row['snapshot'];
716 $hisDat['fieldlist']=$row['fieldlist'];
717 $hisDat['tablename']=$row['tablename'];
718 $hisDat['recuid']=$row['recuid'];
720 $changeLog[$row['sys_log_uid']]=$hisDat;
722 // Update change array
723 // This is used to detect if any intermedia changes have been made.
724 #$changesArray = array_merge($changesArray,$hisDat['oldRecord']);
726 debug('ERROR: [getHistoryData]');
727 return 0; // error fallback
730 // SELECT INSERTS/DELETES
731 if ($this->showInsertDelete) {
732 // Select most recent inserts and deletes // WITHOUT snapshots
733 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
734 'uid,userid,action,tstamp',
737 AND ( action=1 OR action=3 )
738 AND tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table, 'sys_log').'
739 AND recuid='.intval($uid),
744 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
746 if ($row['uid'] < $this->lastSyslogId && $this->lastSyslogId) {
751 switch ($row['action']) {
753 $hisDat['action'] = 'insert';
756 $hisDat['action'] = 'delete';
759 $hisDat['tstamp']=$row['tstamp'];
760 $hisDat['user']=$row['userid'];
761 $hisDat['tablename'] = $table;
762 $hisDat['recuid'] = $uid;
763 $changeLog[$row['uid']] = $hisDat;
768 return 0; // error fallback
772 /*******************************
774 * Various helper functions
776 *******************************/
779 * generates the title and puts the record title behind
781 * @param [type] $table: ...
782 * @param [type] $uid: ...
785 function generateTitle($table, $uid) {
788 $out = $table.':'.$uid;
789 if ($labelField = $TCA[$table]['ctrl']['label']) {
790 $record = t3lib_BEfunc::getRecordRaw($table, 'uid='.intval($uid));
791 $out .= ' ('.t3lib_BEfunc::getRecordTitle($table, $record, TRUE).')';
796 * creates a link for the rollback
798 * @param sting parameter which is set to rollbackFields
799 * @param string optional, alternative label and title tag of image
800 * @param integer optional, type of rollback: 0 - ALL; 1 - element; 2 - field
801 * @return string HTML output
803 function createRollbackLink($key, $alt='', $type=0) {
806 return $this->linkPage('<img '.t3lib_iconWorks::skinImg('','gfx/revert_'.$type.'.gif','width="33" height="33"').' alt="'.$alt.'" title="'.$alt.'" align="middle" />',array('rollbackFields'=>$key));
810 * Creates a link to the same page.
812 * @param string String to wrap in <a> tags (must be htmlspecialchars()'ed prior to calling function)
813 * @param array Array of key/value pairs to override the default values with.
814 * @param string Possible anchor value.
815 * @param string Possible title.
816 * @return string Link.
819 function linkPage($str,$inparams=array(),$anchor='',$title='') {
821 // Setting default values based on GET parameters:
822 $params['element']=$this->element;
823 $params['returnUrl']=$this->returnUrl;
824 $params['diff']=$this->lastSyslogId;
825 // Mergin overriding values:
826 $params = array_merge($params,$inparams);
829 $Ahref = 'show_rechis.php?'.t3lib_div::implodeArrayForUrl('',$params).($anchor?'#'.$anchor:'');
830 $link = '<a href="'.htmlspecialchars($Ahref).'"'.($title?' title="'.$title.'"':'').'>'.$str.'</a>';
837 * Will traverse the field names in $dataArray and look in $TCA if the fields are of types which cannot be handled by the sys_history (that is currently group types with internal_type set to "file")
839 * @param string Table name
840 * @param array The data array
841 * @return array The modified data array
844 function removeFilefields($table,$dataArray) {
848 t3lib_div::loadTCA($table);
850 foreach($TCA[$table]['columns'] as $field => $config) {
851 if ($config['config']['type']=='group' && $config['config']['internal_type']=='file') {
852 unset($dataArray[$field]);
860 * Convert input element reference to workspace version if any.
862 * @param string table of input element
863 * @param integer UID of record
864 * @return integer converted UID of record
866 function resolveElement($table,$uid) {
867 if (isset($GLOBALS['TCA'][$table])) {
868 if ($workspaceVersion = t3lib_BEfunc::getWorkspaceVersionOfRecord($GLOBALS['BE_USER']->workspace, $table, $uid, 'uid')) {
869 $uid = $workspaceVersion['uid'];
876 * resolve sh_uid (used from log)
880 function resolveShUid() {
881 if (t3lib_div::_GP('sh_uid')) {
882 $sh_uid = t3lib_div::_GP('sh_uid');
883 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','sys_history', 'uid='.intval($sh_uid));
884 $record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
885 $this->element = $record['tablename'].':'.$record['recuid'];
886 $this->lastSyslogId = $record['sys_log_uid']-1;