Updated copyright notices to show "2004"
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_bedisplaylog.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 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 * 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 <kasper@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 *
41 * 81: class t3lib_BEDisplayLog
42 * 100: function initArray()
43 * 117: function getTimeLabel($code)
44 * 132: function getUserLabel($code)
45 * 146: function getTypeLabel($code)
46 * 160: function getActionLabel($code)
47 * 178: function getDetails($code,$text,$data,$sys_log_uid=0)
48 * 211: function reset()
49 * 225: function getErrorFormatting($sign)
50 * 235: function formatDetailsForList($row)
51 * 252: 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 <kasper@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 => 'Secur!'
93 );
94
95 /**
96 * Initialize the log table array with header labels.
97 *
98 * @return array
99 */
100 function initArray() {
101 $codeArr=Array();
102 $codeArr[0][]='Time'; // Time
103 $codeArr[0][]='User';
104 $codeArr[0][]='Type';
105 $codeArr[0][]='E';
106 $codeArr[0][]='Action';
107 $codeArr[0][]='Details';
108 return $codeArr;
109 }
110
111 /**
112 * Get time label for log listing
113 *
114 * @param integer Timestamp to display
115 * @return string If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
116 */
117 function getTimeLabel($code) {
118 $t=$GLOBALS['SOBE']->doc->formatTime($code,1);
119 if ($this->lastTimeLabel!=$t) {
120 $this->lastTimeLabel=$t;
121 return $t;
122 } else return '.';
123
124 }
125
126 /**
127 * Get user name label for log listing
128 *
129 * @param integer be_user uid
130 * @return string If username is different from last username then the username, otherwise "."
131 */
132 function getUserLabel($code) {
133 if ($this->lastUserLabel!=$code) {
134 $this->lastUserLabel=$code;
135 $label=$GLOBALS['be_user_Array'][$code]['username'];
136 return $label ? $label : '['.$code.']';
137 } else return '.';
138 }
139
140 /**
141 * Get type label for log listing
142 *
143 * @param string Key for the type label in locallang
144 * @return string If labe is different from last type label then the label is returned, otherwise "."
145 */
146 function getTypeLabel($code) {
147 if ($this->lastTypeLabel!=$code) {
148 $this->lastTypeLabel=$code;
149 $label=$GLOBALS['LANG']->getLL('type_'.$code);
150 return $label ? $label : '['.$code.']';
151 } else return '.';
152 }
153
154 /**
155 * Get action label for log listing
156 *
157 * @param string Key for the action label in locallang
158 * @return string If labe is different from last action label then the label is returned, otherwise "."
159 */
160 function getActionLabel($code) {
161 if ($this->lastActionLabel!=$code) {
162 $this->lastActionLabel=$code;
163 $label=$GLOBALS['LANG']->getLL('action_'.$code);
164 return $label ? $label : '['.$code.']';
165 } else return '.';
166 }
167
168 /**
169 * Get details for the log entry
170 *
171 * @param string Suffix to "msg_" to get label from locallang.
172 * @param string Details text
173 * @param array Data array
174 * @param integer sys_log uid number
175 * @return string Text string
176 * @see formatDetailsForList()
177 */
178 function getDetails($code,$text,$data,$sys_log_uid=0) {
179 // $code is used later on to substitute errormessages with language-corrected values...
180 if (is_array($data)) {
181 if ($this->detailsOn) {
182 if (is_object($GLOBALS['LANG'])) {
183 $label=$GLOBALS['LANG']->getLL('msg_'.$code);
184 } else {
185 list($label)=explode(',',$text);
186 }
187 if ($label) {$text=$label;}
188 $text = sprintf($text, htmlspecialchars($data[0]),htmlspecialchars($data[1]),htmlspecialchars($data[2]),htmlspecialchars($data[3]),htmlspecialchars($data[4]));
189 } else {
190 $text = str_replace('%s','',$text);
191 }
192 }
193
194 // Finding the history for the record
195 $query='SELECT uid,fieldlist FROM sys_history WHERE sys_log_uid='.intval($sys_log_uid);
196 $res = mysql(TYPO3_db,$query);
197 $newRow = mysql_fetch_assoc($res);
198 if (is_array($newRow)) {
199 $text.=' Changes in fields: <em>'.$newRow['fieldlist'].'</em>.';
200 $text.=' <a href="'.htmlspecialchars($GLOBALS['BACK_PATH'].'show_rechis.php?sh_uid='.$newRow['uid'].'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'))).'"><b>->His</b></a>';
201 }
202
203 return $text;
204 }
205
206 /**
207 * Reset all internal "last..." variables to blank string.
208 *
209 * @return void
210 */
211 function reset() {
212 $this->lastTimeLabel='';
213 $this->lastUserLabel='';
214 $this->lastTypeLabel='';
215 $this->lastActionLabel='';
216 }
217
218 /**
219 * Formats input string in red-colored font tags
220 *
221 * @param string Input value
222 * @return string Input wrapped in red font-tag and bold
223 * @obsolete
224 */
225 function getErrorFormatting($sign) {
226 return '<font color="red"><b>'.$sign.'</b></font>';
227 }
228
229 /**
230 * Formatting details text for the sys_log row inputted
231 *
232 * @param array sys_log row
233 * @return string Details string
234 */
235 function formatDetailsForList($row) {
236 $data = unserialize($row['log_data']);
237 if ($row['type']==2) {
238 $data=$this->stripPath($data);
239 }
240
241 return $this->getDetails($row['type'].'_'.$row['action'].'_'.$row['details_nr'],$row['details'],$data,$row['uid']).' ('.$row['details_nr'].')';
242 }
243
244 /**
245 * For all entries in the $inArray (expected to be filepaths) the basename is extracted and set as value (if $this->stripPath is set)
246 * This is done for log-entries from the FILE modules
247 *
248 * @param array Array of file paths
249 * @return array
250 * @see formatDetailsForList()
251 */
252 function stripPath($inArr) {
253 if ($this->stripPath && is_array($inArr)) {
254 while(list($key,$val)=each($inArr)) {
255 $inArr[$key]=basename($val);
256 }
257 }
258 return $inArr;
259 }
260 }
261
262
263 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']) {
264 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);
265 }
266 ?>