2c38efe69dd54f66c98a0b482df87fc6e7cc46f7
[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=time();
264
265 // Time:
266 if ($this->theTime) {
267 $starttime = $this->theTime;
268 if ($this->theTime_end) {
269 $endtime = $this->theTime_end;
270 } else $endtime = time();
271 } else {
272 switch($this->MOD_SETTINGS['time']) {
273 case 0:
274 // This week
275 $week = (date('w') ? date('w') : 7)-1;
276 $starttime = mktime (0,0,0)-$week*3600*24;
277 break;
278 case 1:
279 // Last week
280 $week = (date('w') ? date('w') : 7)-1;
281 $starttime = mktime (0,0,0)-($week+7)*3600*24;
282 $endtime = mktime (0,0,0)-$week*3600*24;
283 break;
284 case 2:
285 // Last 7 days
286 $starttime = mktime (0,0,0)-7*3600*24;
287 break;
288 case 10:
289 // This month
290 $starttime = mktime (0,0,0, date('m'),1);
291 break;
292 case 11:
293 // Last month
294 $starttime = mktime (0,0,0, date('m')-1,1);
295 $endtime = mktime (0,0,0, date('m'),1);
296 break;
297 case 12:
298 // Last 31 days
299 $starttime = mktime (0,0,0)-31*3600*24;
300 break;
301 }
302 }
303 if ($starttime) {
304 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
305 }
306
307
308 // Users
309 $selectUsers = array();
310 if (substr($this->MOD_SETTINGS['users'],0,3) == "gr-") { // All users
311 $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array(substr($this->MOD_SETTINGS['users'],3)),1);
312 if (is_array($this->be_user_Array)) {
313 while(list(,$val)=each($this->be_user_Array)) {
314 if ($val['uid']!=$BE_USER->user['uid']) {
315 $selectUsers[]=$val['uid'];
316 }
317 }
318 }
319 $selectUsers[] = 0;
320 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
321 } elseif (substr($this->MOD_SETTINGS['users'],0,3) == "us-") { // All users
322 $selectUsers[] = intval(substr($this->MOD_SETTINGS['users'],3));
323 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
324 } elseif ($this->MOD_SETTINGS['users']==-1) {
325 $where_part.=' AND userid='.$BE_USER->user['uid']; // Self user
326 }
327
328 // Workspace
329 if ($GLOBALS['BE_USER']->workspace!==0) {
330 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
331 } elseif ($this->MOD_SETTINGS['workspaces']!=-99) {
332 $where_part.=' AND workspace='.intval($this->MOD_SETTINGS['workspaces']);
333 }
334
335 // Finding out which page ids are in the log:
336 $logPids = array();
337 if ($this->MOD_SETTINGS['groupByPage']) {
338 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('event_pid', 'sys_log', '1=1'.$where_part, 'event_pid');
339 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
340 $logPids[] = $row['event_pid'];
341 }
342
343 // Overview:
344 $overviewList = array();
345 foreach($logPids as $pid) {
346 if ((int)$pid>0) {
347 $overviewList[]= htmlspecialchars(t3lib_BEfunc::getRecordPath($pid,'',20).'" [UID:'.$pid.']');
348 }
349 }
350 sort($overviewList);
351 $this->content.=$this->doc->divider(5);
352 $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);
353 $this->content.=$this->doc->spacer(30);
354 } else $logPids[] = '_SINGLE';
355
356
357 foreach($logPids as $pid) {
358 $codeArr = $this->lF->initArray();
359 $this->lF->reset();
360 $oldHeader='';
361
362 $this->content.=$this->doc->divider(5);
363 switch($pid) {
364 case '_SINGLE':
365 $insertMsg = '';
366 break;
367 case '-1':
368 $insertMsg = ' for NON-PAGE related actions ';
369 break;
370 case '0':
371 $insertMsg = ' for ROOT LEVEL ';
372 break;
373 default:
374 $insertMsg = ' for PAGE "'.t3lib_BEfunc::getRecordPath($pid,'',20).'" ('.$pid.') ';
375 break;
376 }
377 $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);
378
379 $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']));
380
381 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
382 $header=$this->doc->formatTime($row['tstamp'],10);
383 if (!$oldHeader) $oldHeader=$header;
384
385 if ($header!=$oldHeader) {
386 $this->content.=$this->doc->spacer(10);
387 $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
388 $codeArr=$this->lF->initArray();
389 $oldHeader=$header;
390 $this->lF->reset();
391 }
392
393 $i++;
394 $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
395 $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
396 $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
397 $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
398 $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
399 $codeArr[$i][]=$this->lF->formatDetailsForList($row);
400 }
401 $this->content.=$this->doc->spacer(10);
402 $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
403
404 $GLOBALS['TYPO3_DB']->sql_free_result($log);
405 }
406
407 // Setting up the buttons and markers for docheader
408 $docHeaderButtons = $this->getButtons();
409 //$markers['CSH'] = $docHeaderButtons['csh'];
410 $markers['CONTENT'] = $this->content;
411
412 // Build the <body> for the module
413 $this->content = $this->doc->startPage('Administration log');
414 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
415 $this->content.= $this->doc->endPage();
416 $this->content = $this->doc->insertStylesAndJS($this->content);
417 }
418
419 /**
420 * Output content
421 *
422 * @return string HTML
423 */
424 function printContent() {
425 echo $this->content;
426 }
427
428 /**
429 * Create the panel of buttons for submitting the form or otherwise perform operations.
430 *
431 * @return array all available buttons as an assoc. array
432 */
433 protected function getButtons() {
434
435 $buttons = array(
436 'csh' => '',
437 'shortcut' => ''
438 );
439 // CSH
440 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
441
442 // Shortcut
443 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
444 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','users,time,max,action',$this->MCONF['name']);
445 }
446
447 return $buttons;
448 }
449 }
450
451
452 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']) {
453 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']);
454 }
455
456
457
458 // Make instance:
459 $SOBE = t3lib_div::makeInstance('SC_mod_tools_log_index');
460 $SOBE->init();
461 $SOBE->main();
462 $SOBE->printContent();
463 ?>