Initial revision
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_bedisplaylog.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasper@typo3.com>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 80: class t3lib_BEDisplayLog
43 * 99: function initArray()
44 * 116: function getTimeLabel($code)
45 * 131: function getUserLabel($code)
46 * 145: function getTypeLabel($code)
47 * 159: function getActionLabel($code)
48 * 177: function getDetails($code,$text,$data,$sys_log_uid=0)
49 * 210: function reset()
50 * 224: function getErrorFormatting($sign)
51 * 234: function formatDetailsForList($row)
52 * 251: function stripPath($inArr)
53 *
54 * TOTAL FUNCTIONS: 10
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
72
73 /**
74 * This class holds some functions used to display the sys_log table-content.
75 * Used in the status-scripts and the log-module.
76 *
77 * @author Kasper Skårhøj <kasper@typo3.com>
78 * @see tx_belog_webinfo, SC_mod_tools_log_index
79 */
80 class t3lib_BEDisplayLog {
81 var $lastTimeLabel='';
82 var $lastUserLabel='';
83 var $lastTypeLabel='';
84 var $lastActionLabel='';
85
86 var $detailsOn = 1; // If detailsOn, %s is substituted with values from the data-array (see getDetails())
87 var $stripPath = 1; // This strips the path from any value in the data-array when the data-array is parsed through stripPath()
88 var $errorSign = Array(
89 1 => '!',
90 2 => 'Sys!',
91 3 => 'Secur!'
92 );
93
94 /**
95 * Initialize the log table array with header labels.
96 *
97 * @return array
98 */
99 function initArray() {
100 $codeArr=Array();
101 $codeArr[0][]='Time'; // Time
102 $codeArr[0][]='User';
103 $codeArr[0][]='Type';
104 $codeArr[0][]='E';
105 $codeArr[0][]='Action';
106 $codeArr[0][]='Details';
107 return $codeArr;
108 }
109
110 /**
111 * Get time label
112 *
113 * @param integer Timestamp to display
114 * @return string If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
115 */
116 function getTimeLabel($code) {
117 $t=$GLOBALS['SOBE']->doc->formatTime($code,1);
118 if ($this->lastTimeLabel!=$t) {
119 $this->lastTimeLabel=$t;
120 return $t;
121 } else return '.';
122
123 }
124
125 /**
126 * Get user name label
127 *
128 * @param integer be_user uid
129 * @return string If username is different from last username then the username, otherwise "."
130 */
131 function getUserLabel($code) {
132 if ($this->lastUserLabel!=$code) {
133 $this->lastUserLabel=$code;
134 $label=$GLOBALS['be_user_Array'][$code]['username'];
135 return $label ? $label : '['.$code.']';
136 } else return '.';
137 }
138
139 /**
140 * Get type label
141 *
142 * @param string Key for the type label in locallang
143 * @return string If labe is different from last type label then the label is returned, otherwise "."
144 */
145 function getTypeLabel($code) {
146 if ($this->lastTypeLabel!=$code) {
147 $this->lastTypeLabel=$code;
148 $label=$GLOBALS['LANG']->getLL('type_'.$code);
149 return $label ? $label : '['.$code.']';
150 } else return '.';
151 }
152
153 /**
154 * Get action label
155 *
156 * @param string Key for the action label in locallang
157 * @return string If labe is different from last action label then the label is returned, otherwise "."
158 */
159 function getActionLabel($code) {
160 if ($this->lastActionLabel!=$code) {
161 $this->lastActionLabel=$code;
162 $label=$GLOBALS['LANG']->getLL('action_'.$code);
163 return $label ? $label : '['.$code.']';
164 } else return '.';
165 }
166
167 /**
168 * Get details for the log entry
169 *
170 * @param string Suffix to "msg_" to get label from locallang.
171 * @param string Details text
172 * @param array Data array
173 * @param integer sys_log uid number
174 * @return string Text string
175 * @see formatDetailsForList()
176 */
177 function getDetails($code,$text,$data,$sys_log_uid=0) {
178 // $code is used later on to substitute errormessages with language-corrected values...
179 if (is_array($data)) {
180 if ($this->detailsOn) {
181 if (is_object($GLOBALS['LANG'])) {
182 $label=$GLOBALS['LANG']->getLL('msg_'.$code);
183 } else {
184 list($label)=explode(',',$text);
185 }
186 if ($label) {$text=$label;}
187 $text = sprintf($text, htmlspecialchars($data[0]),htmlspecialchars($data[1]),htmlspecialchars($data[2]),htmlspecialchars($data[3]),htmlspecialchars($data[4]));
188 } else {
189 $text = str_replace('%s','',$text);
190 }
191 }
192
193 // Finding the history for the record
194 $query='SELECT uid,fieldlist FROM sys_history WHERE sys_log_uid='.intval($sys_log_uid);
195 $res = mysql(TYPO3_db,$query);
196 $newRow = mysql_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
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
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 ?>