[BUGFIX] missing parameter for implode
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / class.tx_belog_webinfo.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (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 * Extension classes for log display in Web > Info and Tools > Log modules
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32
33
34
35 /**
36 * Extending for Tools > Log. Just setting labels correctly
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 * @package TYPO3
40 * @subpackage tx_belog
41 */
42 class logFunctions_ext extends t3lib_BEDisplayLog {
43
44 /**
45 * Initialize the log table array with header labels.
46 *
47 * @return array
48 */
49 function initArray() {
50 $codeArr = array();
51 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_time');
52 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_user');
53 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_error');
54 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_action');
55 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_table');
56 $codeArr[0][] = $GLOBALS['LANG']->getLL('chLog_l_details');
57 return $codeArr;
58 }
59 }
60
61
62
63
64 /**
65 * Extending for Web>Info
66 *
67 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
68 * @package TYPO3
69 * @subpackage tx_belog
70 */
71 class tx_belog_webinfo extends t3lib_extobjbase {
72 var $localLangFile = 'locallang.php';
73
74 /**
75 * Setting up function menu
76 *
77 * @return array Menu items
78 */
79 function modMenu() {
80
81 return array(
82 'log_users' => array(
83 0 => $GLOBALS['LANG']->getLL('chLog_users_0'),
84 '-1' => $GLOBALS['LANG']->getLL('chLog_users_-1')
85 ),
86 'log_time' => array(
87 0 => $GLOBALS['LANG']->getLL('chLog_time_0'),
88 1 => $GLOBALS['LANG']->getLL('chLog_time_1'),
89 2 => $GLOBALS['LANG']->getLL('chLog_time_2'),
90 10 => $GLOBALS['LANG']->getLL('chLog_time_10'),
91 11 => $GLOBALS['LANG']->getLL('chLog_time_11'),
92 12 => $GLOBALS['LANG']->getLL('chLog_time_12'),
93 20 => $GLOBALS['LANG']->getLL('chLog_time_20')
94 ),
95 'depth' => array(
96 0 => $GLOBALS['LANG']->getLL('depth_0'),
97 1 => $GLOBALS['LANG']->getLL('depth_1'),
98 2 => $GLOBALS['LANG']->getLL('depth_2'),
99 3 => $GLOBALS['LANG']->getLL('depth_3')
100 )
101 );
102 }
103
104 /**
105 * Include locallang file
106 *
107 * @return void
108 */
109 function localLang() {
110 $LOCAL_LANG = $GLOBALS['LANG']->includeLLFile('EXT:belog/mod/locallang.xml',FALSE);
111
112 $GLOBALS['LOCAL_LANG']=t3lib_div::array_merge_recursive_overrule($GLOBALS['LOCAL_LANG'],$LOCAL_LANG);
113 }
114
115 /**
116 * Show the log entries for page
117 *
118 * @return string HTML output
119 */
120 function main() {
121
122 $this->localLang();
123
124 $displayLogInstance = t3lib_div::makeInstance('logFunctions_ext');
125
126 $theOutput='';
127 $menu='';
128 $menu .= '&nbsp;' . $GLOBALS['LANG']->getLL('chLog_menuUsers') . ': ' .
129 t3lib_BEfunc::getFuncMenu(
130 $this->pObj->id,
131 'SET[log_users]',
132 $this->pObj->MOD_SETTINGS['log_users'],
133 $this->pObj->MOD_MENU['log_users']
134 );
135 $menu .= '&nbsp;' . $GLOBALS['LANG']->getLL('chLog_menuDepth') . ': ' .
136 t3lib_BEfunc::getFuncMenu(
137 $this->pObj->id,
138 'SET[depth]',
139 $this->pObj->MOD_SETTINGS['depth'],
140 $this->pObj->MOD_MENU['depth']
141 );
142 $menu .= '&nbsp;' . $GLOBALS['LANG']->getLL('chLog_menuTime') . ': ' .
143 t3lib_BEfunc::getFuncMenu(
144 $this->pObj->id,
145 'SET[log_time]',
146 $this->pObj->MOD_SETTINGS['log_time'],
147 $this->pObj->MOD_MENU['log_time']
148 );
149 $theOutput .= $this->pObj->doc->header($GLOBALS['LANG']->getLL('chLog_title'));
150 $theOutput .= $this->pObj->doc->section(
151 '',
152 '<span class="nobr">' . $menu . '</span>',
153 0,
154 1
155 );
156
157 // Build query
158 $where_part='';
159
160 // Get the id-list of pages for the tree structure.
161 $tree = t3lib_div::makeInstance('t3lib_pageTree');
162 $tree->init('AND '.$this->pObj->perms_clause);
163 $tree->makeHTML=0;
164 $tree->fieldArray = array('uid');
165 if ($this->pObj->MOD_SETTINGS['depth']) {
166 $tree->getTree($this->pObj->id, $this->pObj->MOD_SETTINGS['depth'], '');
167 }
168 $tree->ids[]=$this->pObj->id;
169 $idList = implode($tree->ids,',');
170
171 $where_part.=' AND (event_pid in ('.$idList.'))'; // DB
172
173 // Time:
174 $starttime=0;
175 $endtime = $GLOBALS['EXEC_TIME'];
176 switch($this->pObj->MOD_SETTINGS['log_time']) {
177 case 0:
178 // This week
179 $week = (date('w') ? date('w') : 7)-1;
180 $starttime = mktime (0,0,0)-$week*3600*24;
181 break;
182 case 1:
183 // Last week
184 $week = (date('w') ? date('w') : 7)-1;
185 $starttime = mktime (0,0,0)-($week+7)*3600*24;
186 $endtime = mktime (0,0,0)-$week*3600*24;
187 break;
188 case 2:
189 // Last 7 days
190 $starttime = mktime (0,0,0)-7*3600*24;
191 break;
192 case 10:
193 // This month
194 $starttime = mktime (0,0,0, date('m'),1);
195 break;
196 case 11:
197 // Last month
198 $starttime = mktime (0,0,0, date('m')-1,1);
199 $endtime = mktime (0,0,0, date('m'),1);
200 break;
201 case 12:
202 // Last 31 days
203 $starttime = mktime (0,0,0)-31*3600*24;
204 break;
205 }
206 if ($starttime) {
207 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
208 }
209
210 $where_part.=' AND type=1'; // DB
211
212
213 // Users
214 $this->pObj->be_user_Array = t3lib_BEfunc::getUserNames();
215 if (!$this->pObj->MOD_SETTINGS['log_users']) { // All users
216 // Get usernames and groupnames
217 if (!$GLOBALS['BE_USER']->isAdmin()) {
218 $groupArray = explode(',',$GLOBALS['BE_USER']->user['usergroup_cached_list']);
219 $this->pObj->be_user_Array = t3lib_BEfunc::blindUserNames($this->pObj->be_user_Array,$groupArray,1);
220 }
221
222 if (is_array($this->pObj->be_user_Array)) {
223 foreach ($this->pObj->be_user_Array as $val) {
224 $selectUsers[]=$val['uid'];
225 }
226 }
227 $selectUsers[] = $GLOBALS['BE_USER']->user['uid'];
228 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
229 } else {
230 $where_part.=' AND userid='.$GLOBALS['BE_USER']->user['uid']; // Self user
231 }
232 $displayLogInstance->be_user_Array = &$this->pObj->be_user_Array;
233
234 if ($GLOBALS['BE_USER']->workspace!==0) {
235 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
236 }
237
238
239 // Select 100 recent log entries:
240 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', '1=1'.$where_part, '', 'uid DESC', 100);
241
242 $codeArr = $displayLogInstance->initArray();
243 $oldHeader = '';
244 $i = 0;
245 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
246 $header = $this->pObj->doc->formatTime($row['tstamp'],10);
247 if (!$oldHeader) $oldHeader = $header;
248
249 if ($header!=$oldHeader) {
250 $theOutput.=$this->pObj->doc->spacer(10);
251 $theOutput.=$this->pObj->doc->section($oldHeader,$this->pObj->doc->table($codeArr));
252 $codeArr = $displayLogInstance->initArray();
253 $oldHeader=$header;
254 $displayLogInstance->reset();
255 }
256
257 $i++;
258 $codeArr[$i][] = $displayLogInstance->getTimeLabel($row['tstamp']);
259 $codeArr[$i][] = $displayLogInstance->getUserLabel($row['userid'], $row['workspace']);
260 $codeArr[$i][] = $row['error'] ? $displayLogInstance->getErrorIcon($row['error']) : '';
261 $codeArr[$i][] = $displayLogInstance->getActionLabel($row['type'] . '_' . $row['action']);
262 $codeArr[$i][] = $row['tablename'];
263 $codeArr[$i][] = $displayLogInstance->formatDetailsForList($row);
264 }
265 $theOutput.=$this->pObj->doc->spacer(10);
266 $theOutput.=$this->pObj->doc->section($header,$this->pObj->doc->table($codeArr));
267
268 $GLOBALS['TYPO3_DB']->sql_free_result($log);
269
270 return $theOutput;
271 }
272 }
273
274 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php'])) {
275 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php']);
276 }
277
278 ?>