Fixed bug #14005: Moving a page with IRRE records misplaces IRRE records
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_bedisplaylog.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@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 * Contains class for display of backend log
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 81: class t3lib_BEDisplayLog
42 * 106: function initArray()
43 * 123: function getTimeLabel($code)
44 * 139: function getUserLabel($code,$workspace=0)
45 * 154: function getTypeLabel($code)
46 * 168: function getActionLabel($code)
47 * 186: function getDetails($code,$text,$data,$sys_log_uid=0)
48 * 220: function reset()
49 * 234: function getErrorFormatting($sign, $error=0)
50 * 244: function formatDetailsForList($row)
51 * 261: function stripPath($inArr)
52 *
53 * TOTAL FUNCTIONS: 10
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72 /**
73 * This class holds some functions used to display the sys_log table-content.
74 * Used in the status-scripts and the log-module.
75 *
76 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
77 * @package TYPO3
78 * @subpackage t3lib
79 * @see tx_belog_webinfo, SC_mod_tools_log_index
80 */
81 class t3lib_BEDisplayLog {
82 var $lastTimeLabel = '';
83 var $lastUserLabel = '';
84 var $lastTypeLabel = '';
85 var $lastActionLabel = '';
86
87 var $detailsOn = 1; // If detailsOn, %s is substituted with values from the data-array (see getDetails())
88 var $stripPath = 1; // This strips the path from any value in the data-array when the data-array is parsed through stripPath()
89 var $errorSign = Array(
90 1 => '!',
91 2 => 'Sys!',
92 3 => 'Security!'
93 );
94 var $wsArray = array(
95 0 => 'LIVE',
96 -1 => 'Draft',
97 );
98
99 var $be_user_Array = array(); // Username array (set externally)
100
101 /**
102 * Initialize the log table array with header labels.
103 *
104 * @return array
105 */
106 function initArray() {
107 $codeArr=Array();
108 $codeArr[0][]='Time'; // Time
109 $codeArr[0][]='User';
110 $codeArr[0][]='Type';
111 $codeArr[0][]='Error';
112 $codeArr[0][]='Action';
113 $codeArr[0][]='Details';
114 return $codeArr;
115 }
116
117 /**
118 * Get time label for log listing
119 *
120 * @param integer Timestamp to display
121 * @return string If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
122 */
123 function getTimeLabel($code) {
124 #$t=$GLOBALS['SOBE']->doc->formatTime($code,1);
125 $t = date('H:i:s',$code);
126
127 if ($this->lastTimeLabel!=$t) {
128 $this->lastTimeLabel=$t;
129 return $t;
130 } else {
131 return '.';
132 }
133
134 }
135
136 /**
137 * Get user name label for log listing
138 *
139 * @param integer be_user uid
140 * @param integer Workspace ID
141 * @return string If username is different from last username then the username, otherwise "."
142 */
143 function getUserLabel($code,$workspace=0) {
144 if ($this->lastUserLabel!=$code.'_'.$workspace) {
145 $this->lastUserLabel=$code.'_'.$workspace;
146 $label = $this->be_user_Array[$code]['username'];
147 $ws = $this->wsArray[$workspace];
148 return ($label ? htmlspecialchars($label) : '['.$code.']').'@'.($ws?$ws:$workspace);
149 } else return '.';
150 }
151
152 /**
153 * Get type label for log listing
154 *
155 * @param string Key for the type label in locallang
156 * @return string If labe is different from last type label then the label is returned, otherwise "."
157 */
158 function getTypeLabel($code) {
159 if ($this->lastTypeLabel!=$code) {
160 $this->lastTypeLabel=$code;
161 $label=$GLOBALS['LANG']->getLL('type_'.$code);
162 return $label ? $label : '['.$code.']';
163 } else return '.';
164 }
165
166 /**
167 * Get action label for log listing
168 *
169 * @param string Key for the action label in locallang
170 * @return string If label is different from last action label then the label is returned, otherwise "."
171 */
172 function getActionLabel($code) {
173 if ($this->lastActionLabel!=$code) {
174 $this->lastActionLabel=$code;
175 $label=$GLOBALS['LANG']->getLL('action_'.$code);
176 return $label ? htmlspecialchars($label) : '['.$code.']';
177 } else return '.';
178 }
179
180 /**
181 * Get details for the log entry
182 *
183 * @param string Suffix to "msg_" to get label from locallang.
184 * @param string Details text
185 * @param array Data array
186 * @param integer sys_log uid number
187 * @return string Text string
188 * @see formatDetailsForList()
189 */
190 function getDetails($code,$text,$data,$sys_log_uid=0) {
191 // $code is used later on to substitute errormessages with language-corrected values...
192 if (is_array($data)) {
193 if ($this->detailsOn) {
194 if (is_object($GLOBALS['LANG'])) {
195 # $label = $GLOBALS['LANG']->getLL('msg_'.$code);
196 } else {
197 list($label) = explode(',',$text);
198 }
199 if ($label) {
200 $text=$label;
201 }
202 $text = sprintf($text, htmlspecialchars($data[0]),htmlspecialchars($data[1]),htmlspecialchars($data[2]),htmlspecialchars($data[3]),htmlspecialchars($data[4]));
203 } else {
204 $text = str_replace('%s','',$text);
205 }
206 }
207
208 // Finding the history for the record
209 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,fieldlist', 'sys_history', 'sys_log_uid='.intval($sys_log_uid));
210 $newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
211 if (is_array($newRow)) {
212 $text .= ' ' . sprintf($GLOBALS['LANG']->getLL('changesInFields'), '<em>' . $newRow['fieldlist'] . '</em>');
213 $text .= ' <a href="' . htmlspecialchars($GLOBALS['BACK_PATH'] . 'show_rechis.php?sh_uid=' . $newRow['uid'] .
214 '&returnUrl=' . rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))) . '">' .
215 '<img' . t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'], 'gfx/history2.gif', 'width="13" height="12"') .
216 ' title="' . $GLOBALS['LANG']->getLL('showHistory') . '" alt="" />' .
217 '</a>';
218 }
219
220 return $text;
221 }
222
223 /**
224 * Reset all internal "last..." variables to blank string.
225 *
226 * @return void
227 */
228 function reset() {
229 $this->lastTimeLabel='';
230 $this->lastUserLabel='';
231 $this->lastTypeLabel='';
232 $this->lastActionLabel='';
233 }
234
235 /**
236 * Formats input string in red-colored font tags
237 *
238 * @param string Input value
239 * @param integer Error value
240 * @return string Input wrapped in red font-tag and bold
241 */
242 function getErrorFormatting($sign, $error=0) {
243 return $GLOBALS['SOBE']->doc->icons($error>=2 ? 3:2).' '.$sign;
244 }
245
246 /**
247 * Formatting details text for the sys_log row inputted
248 *
249 * @param array sys_log row
250 * @return string Details string
251 */
252 function formatDetailsForList($row) {
253 $data = unserialize($row['log_data']);
254 if ($row['type']==2) {
255 $data=$this->stripPath($data);
256 }
257
258 return $this->getDetails($row['type'].'_'.$row['action'].'_'.$row['details_nr'],$row['details'],$data,$row['uid']).($row['details_nr']>0?' (msg#'.$row['type'].'.'.$row['action'].'.'.$row['details_nr'].')':'');
259 }
260
261 /**
262 * For all entries in the $inArray (expected to be filepaths) the basename is extracted and set as value (if $this->stripPath is set)
263 * This is done for log-entries from the FILE modules
264 *
265 * @param array Array of file paths
266 * @return array
267 * @see formatDetailsForList()
268 */
269 function stripPath($inArr) {
270 if ($this->stripPath && is_array($inArr)) {
271 while(list($key,$val)=each($inArr)) {
272 $inArr[$key]=basename($val);
273 }
274 }
275 return $inArr;
276 }
277 }
278
279
280 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']) {
281 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);
282 }
283 ?>