Fixed bug #11127: Validation issue: End tag for "br" omitted, but OMITTAG NO was...
[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 require_once (PATH_t3lib.'class.t3lib_bedisplaylog.php');
38 require_once (PATH_t3lib.'class.t3lib_pagetree.php');
39
40 $BE_USER->modAccess($MCONF,1);
41
42
43
44
45 /**
46 * Tools log script class
47 *
48 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
49 * @package TYPO3
50 * @subpackage tx_belog
51 */
52 class SC_mod_tools_log_index {
53 var $MCONF=array();
54 var $MOD_MENU=array();
55 var $MOD_SETTINGS=array();
56
57 /**
58 * Document template object
59 *
60 * @var noDoc
61 */
62 var $doc;
63
64 var $content;
65 var $lF;
66 var $be_user_Array;
67
68 var $theTime = 0;
69 var $theTime_end = 0;
70
71 /**
72 * Initialize module
73 *
74 * @return void
75 */
76 function init() {
77 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
78 $this->MCONF = $GLOBALS['MCONF'];
79
80 $this->lF = t3lib_div::makeInstance('t3lib_BEDisplayLog');
81 $this->menuConfig();
82
83 $this->doc = t3lib_div::makeInstance('template');
84 $this->doc->backPath = $BACK_PATH;
85 $this->doc->setModuleTemplate('templates/belog.html');
86
87 // JavaScript
88 $this->doc->JScode = '
89 <script language="javascript" type="text/javascript">
90 script_ended = 0;
91 function jumpToUrl(URL) {
92 window.location.href = URL;
93 }
94 </script>
95 ';
96
97 $this->doc->tableLayout = Array (
98 '0' => Array (
99 '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>')
100 ),
101 'defRow' => Array (
102 '0' => Array('<td valign="top">','</td>'),
103 'defCol' => Array('<td><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td><td valign="top">', '</td>')
104 )
105 );
106 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">';
107 $this->doc->form = '<form action="" method="post">';
108
109 $this->be_user_Array = t3lib_BEfunc::getUserNames();
110 $this->lF->be_user_Array = &$this->be_user_Array;
111 }
112
113 /**
114 * Menu configuration
115 *
116 * @return void
117 */
118 function menuConfig() {
119 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS,$TYPO3_DB;
120
121 // MENU-ITEMS:
122 // If array, then it's a selector box menu
123 // If empty string it's just a variable, that'll be saved.
124 // Values NOT in this array will not be saved in the settings-array for the module.
125 $this->MOD_MENU = array(
126 'users' => array(
127 0 => $GLOBALS['LANG']->getLL('any'),
128 '-1' => $GLOBALS['LANG']->getLL('self')
129 ),
130 'workspaces' => array(
131 '-99' => $GLOBALS['LANG']->getLL('any'),
132 0 => $GLOBALS['LANG']->getLL('live'),
133 '-1' => $GLOBALS['LANG']->getLL('draft'),
134 ),
135 'time' => array(
136 0 => $GLOBALS['LANG']->getLL('thisWeek'),
137 1 => $GLOBALS['LANG']->getLL('lastWeek'),
138 2 => $GLOBALS['LANG']->getLL('last7Days'),
139 10 => $GLOBALS['LANG']->getLL('thisMonth'),
140 11 => $GLOBALS['LANG']->getLL('lastMonth'),
141 12 => $GLOBALS['LANG']->getLL('last31Days'),
142 20 => $GLOBALS['LANG']->getLL('noLimit')
143 ),
144 'max' => array(
145 20 => $GLOBALS['LANG']->getLL('20'),
146 50 => $GLOBALS['LANG']->getLL('50'),
147 100 => $GLOBALS['LANG']->getLL('100'),
148 200 => $GLOBALS['LANG']->getLL('200'),
149 500 => $GLOBALS['LANG']->getLL('500'),
150 1000 => $GLOBALS['LANG']->getLL('1000'),
151 1000000 => $GLOBALS['LANG']->getLL('any')
152 ),
153 'action' => array(
154 0 => $GLOBALS['LANG']->getLL('any'),
155 1 => $GLOBALS['LANG']->getLL('actionDatabase'),
156 2 => $GLOBALS['LANG']->getLL('actionFile'),
157 254 => $GLOBALS['LANG']->getLL('actionSettings'),
158 255 => $GLOBALS['LANG']->getLL('actionLogin'),
159 '-1' => $GLOBALS['LANG']->getLL('actionErrors')
160 ),
161 'manualdate' => '',
162 'manualdate_end' => '',
163 'groupByPage' => '',
164 );
165
166 // Add custom workspaces (selecting all, filtering by BE_USER check):
167 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
168 if (count($workspaces)) {
169 foreach ($workspaces as $rec) {
170 $this->MOD_MENU['workspaces'][$rec['uid']] = $rec['uid'].': '.$rec['title'];
171 }
172 }
173
174 // Adding groups to the users_array
175 $groups = t3lib_BEfunc::getGroupNames();
176 if (is_array($groups)) {
177 while(list(,$grVals)=each($groups)) {
178 $this->MOD_MENU['users']['gr-'.$grVals['uid']] = 'Group: '.$grVals['title'];
179 }
180 }
181
182 $users = t3lib_BEfunc::getUserNames();
183 if (is_array($users)) {
184 while(list(,$grVals)=each($users)) {
185 $this->MOD_MENU['users']['us-'.$grVals['uid']] = 'User: '.$grVals['username'];
186 }
187 }
188
189 // CLEANSE SETTINGS
190 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
191
192 //
193 if (!trim($this->MOD_SETTINGS['manualdate'])) {
194 $this->MOD_SETTINGS['manualdate'] = 'YYYY-MM-DD';//"-HH-MM-SS";
195 } else {
196 $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate']));
197 $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]);
198 $this->MOD_SETTINGS['manualdate'] = date('Y-m-d-H-i-s',$this->theTime);
199 }
200
201 if (!trim($this->MOD_SETTINGS['manualdate_end'])) {
202 $this->MOD_SETTINGS['manualdate_end'] = 'YYYY-MM-DD';//"-HH-MM-SS";
203 } else {
204 $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate_end']));
205 $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]);
206 $this->MOD_SETTINGS['manualdate_end'] = date('Y-m-d-H-i-s',$this->theTime_end);
207 }
208 }
209
210 /**
211 * Main function
212 *
213 * @return void
214 */
215 function main() {
216 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
217
218 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('adminLog'));
219 $this->content.=$this->doc->spacer(5);
220
221
222 // Menu compiled:
223 $menuU= t3lib_BEfunc::getFuncMenu(0,'SET[users]',$this->MOD_SETTINGS['users'],$this->MOD_MENU['users']);
224 $menuM= t3lib_BEfunc::getFuncMenu(0,'SET[max]',$this->MOD_SETTINGS['max'],$this->MOD_MENU['max']);
225 $menuT= t3lib_BEfunc::getFuncMenu(0,'SET[time]',$this->MOD_SETTINGS['time'],$this->MOD_MENU['time']);
226 $menuA= t3lib_BEfunc::getFuncMenu(0,'SET[action]',$this->MOD_SETTINGS['action'],$this->MOD_MENU['action']);
227 $menuW= t3lib_BEfunc::getFuncMenu(0,'SET[workspaces]',$this->MOD_SETTINGS['workspaces'],$this->MOD_MENU['workspaces']);
228
229 $groupByPage= t3lib_BEfunc::getFuncCheck(0,'SET[groupByPage]',$this->MOD_SETTINGS['groupByPage']);
230 $inputDate= t3lib_BEfunc::getFuncInput(0,'SET[manualdate]',$this->MOD_SETTINGS['manualdate'],20);
231 $inputDate_end= t3lib_BEfunc::getFuncInput(0,'SET[manualdate_end]',$this->MOD_SETTINGS['manualdate_end'],20);
232
233
234 $this->content.=$this->doc->section('',$this->doc->menuTable(
235 array(
236 array($GLOBALS['LANG']->getLL('users'), $menuU),
237 array($GLOBALS['LANG']->getLL('time'), ($this->MOD_SETTINGS['manualdate'] == 'YYYY-MM-DD' ? $menuT : '') . $inputDate . ($this->MOD_SETTINGS['manualdate'] != 'YYYY-MM-DD' ? '<br /> - ' . $inputDate_end : ''))
238 ),
239 array(
240 array($GLOBALS['LANG']->getLL('max'), $menuM),
241 array($GLOBALS['LANG']->getLL('action'), $menuA)
242 ),
243 array(
244 $GLOBALS['BE_USER']->workspace!==0 ? array('Workspace:','<b>'.$GLOBALS['BE_USER']->workspace.'</b>') : array('Workspace:',$menuW),
245 array('Group by page:',$groupByPage)
246 )
247 ));
248 #$this->content.=$this->doc->divider(5);
249
250
251 $codeArr = $this->lF->initArray();
252 $oldHeader='';
253 $c=0;
254
255 // Action (type):
256 $where_part='';
257 if ($this->MOD_SETTINGS['action'] > 0) {
258 $where_part.=' AND type='.intval($this->MOD_SETTINGS['action']);
259 } elseif ($this->MOD_SETTINGS['action'] == -1) {
260 $where_part.=' AND error';
261 }
262
263
264 $starttime=0;
265 $endtime=time();
266
267 // Time:
268 if ($this->theTime) {
269 $starttime = $this->theTime;
270 if ($this->theTime_end) {
271 $endtime = $this->theTime_end;
272 } else $endtime = time();
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 ?>