Fixed #11430: Performance improvement: use $GLOBALS['EXEC_TIME'] instead of time...
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / mod / index.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 * Module: Log-viewing
29 *
30 * This module lets you view the changelog.
31 *
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 */
34
35
36 $GLOBALS['LANG']->includeLLFile('EXT:belog/mod/locallang.xml');
37
38 $BE_USER->modAccess($MCONF,1);
39
40
41
42
43 /**
44 * Tools log script class
45 *
46 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
47 * @package TYPO3
48 * @subpackage tx_belog
49 */
50 class SC_mod_tools_log_index {
51 var $MCONF=array();
52 var $MOD_MENU=array();
53 var $MOD_SETTINGS=array();
54
55 /**
56 * Document template object
57 *
58 * @var noDoc
59 */
60 var $doc;
61
62 var $content;
63 var $lF;
64 var $be_user_Array;
65
66 var $theTime = 0;
67 var $theTime_end = 0;
68
69 /**
70 * Initialize module
71 *
72 * @return void
73 */
74 function init() {
75 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
76 $this->MCONF = $GLOBALS['MCONF'];
77
78 $this->lF = t3lib_div::makeInstance('t3lib_BEDisplayLog');
79 $this->menuConfig();
80
81 $this->doc = t3lib_div::makeInstance('template');
82 $this->doc->backPath = $BACK_PATH;
83 $this->doc->setModuleTemplate('templates/belog.html');
84
85 // JavaScript
86 $this->doc->JScode = '
87 <script language="javascript" type="text/javascript">
88 script_ended = 0;
89 function jumpToUrl(URL) {
90 window.location.href = URL;
91 }
92 </script>
93 ';
94
95 $this->doc->tableLayout = Array (
96 '0' => Array (
97 'defCol' => Array('<td valign="top" class="c-headLineTable"><b>', '</b></td><td class="c-headLineTable"><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td>')
98 ),
99 'defRow' => Array (
100 '0' => Array('<td valign="top">','</td>'),
101 'defCol' => Array('<td><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td><td valign="top">', '</td>')
102 )
103 );
104 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">';
105 $this->doc->form = '<form action="" method="post">';
106
107 $this->be_user_Array = t3lib_BEfunc::getUserNames();
108 $this->lF->be_user_Array = &$this->be_user_Array;
109 }
110
111 /**
112 * Menu configuration
113 *
114 * @return void
115 */
116 function menuConfig() {
117 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS,$TYPO3_DB;
118
119 // MENU-ITEMS:
120 // If array, then it's a selector box menu
121 // If empty string it's just a variable, that'll be saved.
122 // Values NOT in this array will not be saved in the settings-array for the module.
123 $this->MOD_MENU = array(
124 'users' => array(
125 0 => $GLOBALS['LANG']->getLL('any'),
126 '-1' => $GLOBALS['LANG']->getLL('self')
127 ),
128 'workspaces' => array(
129 '-99' => $GLOBALS['LANG']->getLL('any'),
130 0 => $GLOBALS['LANG']->getLL('live'),
131 '-1' => $GLOBALS['LANG']->getLL('draft'),
132 ),
133 'time' => array(
134 0 => $GLOBALS['LANG']->getLL('thisWeek'),
135 1 => $GLOBALS['LANG']->getLL('lastWeek'),
136 2 => $GLOBALS['LANG']->getLL('last7Days'),
137 10 => $GLOBALS['LANG']->getLL('thisMonth'),
138 11 => $GLOBALS['LANG']->getLL('lastMonth'),
139 12 => $GLOBALS['LANG']->getLL('last31Days'),
140 20 => $GLOBALS['LANG']->getLL('noLimit')
141 ),
142 'max' => array(
143 20 => $GLOBALS['LANG']->getLL('20'),
144 50 => $GLOBALS['LANG']->getLL('50'),
145 100 => $GLOBALS['LANG']->getLL('100'),
146 200 => $GLOBALS['LANG']->getLL('200'),
147 500 => $GLOBALS['LANG']->getLL('500'),
148 1000 => $GLOBALS['LANG']->getLL('1000'),
149 1000000 => $GLOBALS['LANG']->getLL('any')
150 ),
151 'action' => array(
152 0 => $GLOBALS['LANG']->getLL('any'),
153 1 => $GLOBALS['LANG']->getLL('actionDatabase'),
154 2 => $GLOBALS['LANG']->getLL('actionFile'),
155 254 => $GLOBALS['LANG']->getLL('actionSettings'),
156 255 => $GLOBALS['LANG']->getLL('actionLogin'),
157 '-1' => $GLOBALS['LANG']->getLL('actionErrors')
158 ),
159 'manualdate' => '',
160 'manualdate_end' => '',
161 'groupByPage' => '',
162 );
163
164 // Add custom workspaces (selecting all, filtering by BE_USER check):
165 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
166 if (count($workspaces)) {
167 foreach ($workspaces as $rec) {
168 $this->MOD_MENU['workspaces'][$rec['uid']] = $rec['uid'].': '.$rec['title'];
169 }
170 }
171
172 // Adding groups to the users_array
173 $groups = t3lib_BEfunc::getGroupNames();
174 if (is_array($groups)) {
175 while(list(,$grVals)=each($groups)) {
176 $this->MOD_MENU['users']['gr-'.$grVals['uid']] = 'Group: '.$grVals['title'];
177 }
178 }
179
180 $users = t3lib_BEfunc::getUserNames();
181 if (is_array($users)) {
182 while(list(,$grVals)=each($users)) {
183 $this->MOD_MENU['users']['us-'.$grVals['uid']] = 'User: '.$grVals['username'];
184 }
185 }
186
187 // CLEANSE SETTINGS
188 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
189
190 //
191 if (!trim($this->MOD_SETTINGS['manualdate'])) {
192 $this->MOD_SETTINGS['manualdate'] = 'YYYY-MM-DD';//"-HH-MM-SS";
193 } else {
194 $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate']));
195 $this->theTime = mktime((int)$parts[3],(int)$parts[4],(int)$parts[5],$parts[1]?(int)$parts[1]:1,$parts[2]?(int)$parts[2]:1,(int)$parts[0]);
196 $this->MOD_SETTINGS['manualdate'] = date('Y-m-d-H-i-s',$this->theTime);
197 }
198
199 if (!trim($this->MOD_SETTINGS['manualdate_end'])) {
200 $this->MOD_SETTINGS['manualdate_end'] = 'YYYY-MM-DD';//"-HH-MM-SS";
201 } else {
202 $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate_end']));
203 $this->theTime_end = mktime((int)$parts[3],(int)$parts[4],(int)$parts[5],$parts[1]?(int)$parts[1]:1,$parts[2]?(int)$parts[2]:1,(int)$parts[0]);
204 $this->MOD_SETTINGS['manualdate_end'] = date('Y-m-d-H-i-s',$this->theTime_end);
205 }
206 }
207
208 /**
209 * Main function
210 *
211 * @return void
212 */
213 function main() {
214 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
215
216 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('adminLog'));
217 $this->content.=$this->doc->spacer(5);
218
219
220 // Menu compiled:
221 $menuU= t3lib_BEfunc::getFuncMenu(0,'SET[users]',$this->MOD_SETTINGS['users'],$this->MOD_MENU['users']);
222 $menuM= t3lib_BEfunc::getFuncMenu(0,'SET[max]',$this->MOD_SETTINGS['max'],$this->MOD_MENU['max']);
223 $menuT= t3lib_BEfunc::getFuncMenu(0,'SET[time]',$this->MOD_SETTINGS['time'],$this->MOD_MENU['time']);
224 $menuA= t3lib_BEfunc::getFuncMenu(0,'SET[action]',$this->MOD_SETTINGS['action'],$this->MOD_MENU['action']);
225 $menuW= t3lib_BEfunc::getFuncMenu(0,'SET[workspaces]',$this->MOD_SETTINGS['workspaces'],$this->MOD_MENU['workspaces']);
226
227 $groupByPage= t3lib_BEfunc::getFuncCheck(0,'SET[groupByPage]',$this->MOD_SETTINGS['groupByPage']);
228 $inputDate= t3lib_BEfunc::getFuncInput(0,'SET[manualdate]',$this->MOD_SETTINGS['manualdate'],20);
229 $inputDate_end= t3lib_BEfunc::getFuncInput(0,'SET[manualdate_end]',$this->MOD_SETTINGS['manualdate_end'],20);
230
231
232 $this->content.=$this->doc->section('',$this->doc->menuTable(
233 array(
234 array($GLOBALS['LANG']->getLL('users'), $menuU),
235 array($GLOBALS['LANG']->getLL('time'), ($this->MOD_SETTINGS['manualdate'] == 'YYYY-MM-DD' ? $menuT : '') . $inputDate . ($this->MOD_SETTINGS['manualdate'] != 'YYYY-MM-DD' ? '<br /> - ' . $inputDate_end : ''))
236 ),
237 array(
238 array($GLOBALS['LANG']->getLL('max'), $menuM),
239 array($GLOBALS['LANG']->getLL('action'), $menuA)
240 ),
241 array(
242 $GLOBALS['BE_USER']->workspace!==0 ? array('Workspace:','<b>'.$GLOBALS['BE_USER']->workspace.'</b>') : array('Workspace:',$menuW),
243 array('Group by page:',$groupByPage)
244 )
245 ));
246 #$this->content.=$this->doc->divider(5);
247
248
249 $codeArr = $this->lF->initArray();
250 $oldHeader='';
251 $c=0;
252
253 // Action (type):
254 $where_part='';
255 if ($this->MOD_SETTINGS['action'] > 0) {
256 $where_part.=' AND type='.intval($this->MOD_SETTINGS['action']);
257 } elseif ($this->MOD_SETTINGS['action'] == -1) {
258 $where_part.=' AND error';
259 }
260
261
262 $starttime=0;
263 $endtime = $GLOBALS['EXEC_TIME'];
264
265 // Time:
266 if ($this->theTime) {
267 $starttime = $this->theTime;
268 if ($this->theTime_end) {
269 $endtime = $this->theTime_end;
270 } else {
271 $endtime = $GLOBALS['EXEC_TIME'];
272 }
273 } else {
274 switch($this->MOD_SETTINGS['time']) {
275 case 0:
276 // This week
277 $week = (date('w') ? date('w') : 7)-1;
278 $starttime = mktime (0,0,0)-$week*3600*24;
279 break;
280 case 1:
281 // Last week
282 $week = (date('w') ? date('w') : 7)-1;
283 $starttime = mktime (0,0,0)-($week+7)*3600*24;
284 $endtime = mktime (0,0,0)-$week*3600*24;
285 break;
286 case 2:
287 // Last 7 days
288 $starttime = mktime (0,0,0)-7*3600*24;
289 break;
290 case 10:
291 // This month
292 $starttime = mktime (0,0,0, date('m'),1);
293 break;
294 case 11:
295 // Last month
296 $starttime = mktime (0,0,0, date('m')-1,1);
297 $endtime = mktime (0,0,0, date('m'),1);
298 break;
299 case 12:
300 // Last 31 days
301 $starttime = mktime (0,0,0)-31*3600*24;
302 break;
303 }
304 }
305 if ($starttime) {
306 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
307 }
308
309
310 // Users
311 $selectUsers = array();
312 if (substr($this->MOD_SETTINGS['users'],0,3) == "gr-") { // All users
313 $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array(substr($this->MOD_SETTINGS['users'],3)),1);
314 if (is_array($this->be_user_Array)) {
315 while(list(,$val)=each($this->be_user_Array)) {
316 if ($val['uid']!=$BE_USER->user['uid']) {
317 $selectUsers[]=$val['uid'];
318 }
319 }
320 }
321 $selectUsers[] = 0;
322 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
323 } elseif (substr($this->MOD_SETTINGS['users'],0,3) == "us-") { // All users
324 $selectUsers[] = intval(substr($this->MOD_SETTINGS['users'],3));
325 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
326 } elseif ($this->MOD_SETTINGS['users']==-1) {
327 $where_part.=' AND userid='.$BE_USER->user['uid']; // Self user
328 }
329
330 // Workspace
331 if ($GLOBALS['BE_USER']->workspace!==0) {
332 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
333 } elseif ($this->MOD_SETTINGS['workspaces']!=-99) {
334 $where_part.=' AND workspace='.intval($this->MOD_SETTINGS['workspaces']);
335 }
336
337 // Finding out which page ids are in the log:
338 $logPids = array();
339 if ($this->MOD_SETTINGS['groupByPage']) {
340 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('event_pid', 'sys_log', '1=1'.$where_part, 'event_pid');
341 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
342 $logPids[] = $row['event_pid'];
343 }
344
345 // Overview:
346 $overviewList = array();
347 foreach($logPids as $pid) {
348 if ((int)$pid>0) {
349 $overviewList[]= htmlspecialchars(t3lib_BEfunc::getRecordPath($pid,'',20).'" [UID:'.$pid.']');
350 }
351 }
352 sort($overviewList);
353 $this->content.=$this->doc->divider(5);
354 $this->content.= $this->doc->section('Overview', 'These pages have log messages from ' . date('Y-m-d H:i:s', $starttime) . ' to ' . date('Y-m-d H:i:s', $endtime) . '<br /><br /><br />' . implode('<br />', $overviewList), 1, 1, 0);
355 $this->content.=$this->doc->spacer(30);
356 } else $logPids[] = '_SINGLE';
357
358
359 foreach($logPids as $pid) {
360 $codeArr = $this->lF->initArray();
361 $this->lF->reset();
362 $oldHeader='';
363
364 $this->content.=$this->doc->divider(5);
365 switch($pid) {
366 case '_SINGLE':
367 $insertMsg = '';
368 break;
369 case '-1':
370 $insertMsg = ' for NON-PAGE related actions ';
371 break;
372 case '0':
373 $insertMsg = ' for ROOT LEVEL ';
374 break;
375 default:
376 $insertMsg = ' for PAGE "'.t3lib_BEfunc::getRecordPath($pid,'',20).'" ('.$pid.') ';
377 break;
378 }
379 $this->content.=$this->doc->section('Log '.$insertMsg.'from '.date('Y-m-d H:i:s',$starttime).' to '.date('Y-m-d H:i:s',$endtime),'',1,1,0);
380
381 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', '1=1'.$where_part.($pid!='_SINGLE'?' AND event_pid='.intval($pid):''), '', 'uid DESC', intval($this->MOD_SETTINGS['max']));
382
383 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
384 $header=$this->doc->formatTime($row['tstamp'],10);
385 if (!$oldHeader) $oldHeader=$header;
386
387 if ($header!=$oldHeader) {
388 $this->content.=$this->doc->spacer(10);
389 $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
390 $codeArr=$this->lF->initArray();
391 $oldHeader=$header;
392 $this->lF->reset();
393 }
394
395 $i++;
396 $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
397 $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
398 $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
399 $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
400 $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
401 $codeArr[$i][]=$this->lF->formatDetailsForList($row);
402 }
403 $this->content.=$this->doc->spacer(10);
404 $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
405
406 $GLOBALS['TYPO3_DB']->sql_free_result($log);
407 }
408
409 // Setting up the buttons and markers for docheader
410 $docHeaderButtons = $this->getButtons();
411 //$markers['CSH'] = $docHeaderButtons['csh'];
412 $markers['CONTENT'] = $this->content;
413
414 // Build the <body> for the module
415 $this->content = $this->doc->startPage('Administration log');
416 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
417 $this->content.= $this->doc->endPage();
418 $this->content = $this->doc->insertStylesAndJS($this->content);
419 }
420
421 /**
422 * Output content
423 *
424 * @return string HTML
425 */
426 function printContent() {
427 echo $this->content;
428 }
429
430 /**
431 * Create the panel of buttons for submitting the form or otherwise perform operations.
432 *
433 * @return array all available buttons as an assoc. array
434 */
435 protected function getButtons() {
436
437 $buttons = array(
438 'csh' => '',
439 'shortcut' => ''
440 );
441 // CSH
442 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
443
444 // Shortcut
445 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
446 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','users,time,max,action',$this->MCONF['name']);
447 }
448
449 return $buttons;
450 }
451 }
452
453
454 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']) {
455 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']);
456 }
457
458
459
460 // Make instance:
461 $SOBE = t3lib_div::makeInstance('SC_mod_tools_log_index');
462 $SOBE->init();
463 $SOBE->main();
464 $SOBE->printContent();
465 ?>