This commit was manufactured by cvs2svn to create tag
[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 * 210: function reset()
49 * 224: function getErrorFormatting($sign)
50 * 234: function formatDetailsForList($row)
51 * 251: 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 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,fieldlist', 'sys_history', 'sys_log_uid='.intval($sys_log_uid));
196 $newRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
197 if (is_array($newRow)) {
198 $text.=' Changes in fields: <em>'.$newRow['fieldlist'].'</em>.';
199 $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>';
200 }
201
202 return $text;
203 }
204
205 /**
206 * Reset all internal "last..." variables to blank string.
207 *
208 * @return void
209 */
210 function reset() {
211 $this->lastTimeLabel='';
212 $this->lastUserLabel='';
213 $this->lastTypeLabel='';
214 $this->lastActionLabel='';
215 }
216
217 /**
218 * Formats input string in red-colored font tags
219 *
220 * @param string Input value
221 * @return string Input wrapped in red font-tag and bold
222 * @obsolete
223 */
224 function getErrorFormatting($sign) {
225 return '<font color="red"><b>'.$sign.'</b></font>';
226 }
227
228 /**
229 * Formatting details text for the sys_log row inputted
230 *
231 * @param array sys_log row
232 * @return string Details string
233 */
234 function formatDetailsForList($row) {
235 $data = unserialize($row['log_data']);
236 if ($row['type']==2) {
237 $data=$this->stripPath($data);
238 }
239
240 return $this->getDetails($row['type'].'_'.$row['action'].'_'.$row['details_nr'],$row['details'],$data,$row['uid']).' ('.$row['details_nr'].')';
241 }
242
243 /**
244 * For all entries in the $inArray (expected to be filepaths) the basename is extracted and set as value (if $this->stripPath is set)
245 * This is done for log-entries from the FILE modules
246 *
247 * @param array Array of file paths
248 * @return array
249 * @see formatDetailsForList()
250 */
251 function stripPath($inArr) {
252 if ($this->stripPath && is_array($inArr)) {
253 while(list($key,$val)=each($inArr)) {
254 $inArr[$key]=basename($val);
255 }
256 }
257 return $inArr;
258 }
259 }
260
261
262 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']) {
263 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_bedisplaylog.php']);
264 }
265 ?>