7a6990e678fd42b9e3679c3c7535b5c61f346bf6
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / mod / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2010 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 protected $dateFormat;
69
70 /**
71 * Initialize module
72 *
73 * @return void
74 */
75 function init() {
76 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
77 $this->MCONF = $GLOBALS['MCONF'];
78
79 $this->lF = t3lib_div::makeInstance('t3lib_BEDisplayLog');
80
81 $this->doc = t3lib_div::makeInstance('template');
82 $this->doc->backPath = $BACK_PATH;
83 $this->doc->setModuleTemplate('templates/belog.html');
84
85 // Load necessary JavaScript
86 /** @var $pageRenderer t3lib_PageRenderer */
87 $pageRenderer = $this->doc->getPageRenderer();
88 $pageRenderer->loadExtJS();
89 $pageRenderer->addJsFile($this->backPath . '../t3lib/js/extjs/tceforms.js');
90
91 // Define settings for Date Picker
92 $dateFormat = $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'];
93 $this->dateFormat = $dateFormat . ' ' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'];
94 $typo3Settings = array(
95 'datePickerUSmode' => 0,
96 'dateFormat' => array($dateFormat, $this->dateFormat),
97 );
98 $pageRenderer->addInlineSettingArray('', $typo3Settings);
99
100 $this->doc->JScode = '
101 <script language="javascript" type="text/javascript">
102 script_ended = 0;
103 function jumpToUrl(URL) {
104 window.location.href = URL;
105 }
106 </script>
107 ';
108
109 $this->doc->tableLayout = Array (
110 '0' => Array (
111 'defCol' => array('<td valign="top" class="t3-row-header"><strong>', '</strong></td><td class="t3-row-header"><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td>')
112 ),
113 'defRow' => Array (
114 '0' => Array('<td valign="top">','</td>'),
115 'defCol' => Array('<td><img src="' . $this->doc->backPath . 'clear.gif" width="10" height="1" alt="" /></td><td valign="top">', '</td>')
116 )
117 );
118 $this->doc->table_TABLE = '<table border="0" cellspacing="0" cellpadding="0" class="typo3-dblist">';
119 $this->doc->form = '<form action="" method="post">';
120
121 $this->menuConfig();
122 $this->be_user_Array = t3lib_BEfunc::getUserNames();
123 $this->lF->be_user_Array = &$this->be_user_Array;
124 }
125
126 /**
127 * Menu configuration
128 *
129 * @return void
130 */
131 function menuConfig() {
132 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS,$TYPO3_DB;
133
134 // MENU-ITEMS:
135 // If array, then it's a selector box menu
136 // If empty string it's just a variable, that'll be saved.
137 // Values NOT in this array will not be saved in the settings-array for the module.
138 $this->MOD_MENU = array(
139 'users' => array(
140 0 => $GLOBALS['LANG']->getLL('any'),
141 '-1' => $GLOBALS['LANG']->getLL('self')
142 ),
143 'workspaces' => array(
144 '-99' => $GLOBALS['LANG']->getLL('any'),
145 0 => $GLOBALS['LANG']->getLL('live'),
146 '-1' => $GLOBALS['LANG']->getLL('draft'),
147 ),
148 'time' => array(
149 0 => $GLOBALS['LANG']->getLL('thisWeek'),
150 1 => $GLOBALS['LANG']->getLL('lastWeek'),
151 2 => $GLOBALS['LANG']->getLL('last7Days'),
152 10 => $GLOBALS['LANG']->getLL('thisMonth'),
153 11 => $GLOBALS['LANG']->getLL('lastMonth'),
154 12 => $GLOBALS['LANG']->getLL('last31Days'),
155 20 => $GLOBALS['LANG']->getLL('noLimit'),
156 30 => $GLOBALS['LANG']->getLL('userdefined')
157 ),
158 'max' => array(
159 20 => $GLOBALS['LANG']->getLL('20'),
160 50 => $GLOBALS['LANG']->getLL('50'),
161 100 => $GLOBALS['LANG']->getLL('100'),
162 200 => $GLOBALS['LANG']->getLL('200'),
163 500 => $GLOBALS['LANG']->getLL('500'),
164 1000 => $GLOBALS['LANG']->getLL('1000'),
165 1000000 => $GLOBALS['LANG']->getLL('any')
166 ),
167 'action' => array(
168 0 => $GLOBALS['LANG']->getLL('any'),
169 1 => $GLOBALS['LANG']->getLL('actionDatabase'),
170 2 => $GLOBALS['LANG']->getLL('actionFile'),
171 254 => $GLOBALS['LANG']->getLL('actionSettings'),
172 255 => $GLOBALS['LANG']->getLL('actionLogin'),
173 '-1' => $GLOBALS['LANG']->getLL('actionErrors')
174 ),
175 'manualdate' => '',
176 'manualdate_end' => '',
177 'groupByPage' => '',
178 );
179
180 // Add custom workspaces (selecting all, filtering by BE_USER check):
181 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
182 if (count($workspaces)) {
183 foreach ($workspaces as $rec) {
184 $this->MOD_MENU['workspaces'][$rec['uid']] = $rec['uid'].': '.$rec['title'];
185 }
186 }
187
188 // Adding groups to the users_array
189 $groups = t3lib_BEfunc::getGroupNames();
190 if (is_array($groups)) {
191 foreach ($groups as $grVals) {
192 $this->MOD_MENU['users']['gr-' . $grVals['uid']] = $GLOBALS['LANG']->getLL('group') . ' ' . $grVals['title'];
193 }
194 }
195
196 $users = t3lib_BEfunc::getUserNames();
197 if (is_array($users)) {
198 foreach ($users as $grVals) {
199 $this->MOD_MENU['users']['us-' . $grVals['uid']] = $GLOBALS['LANG']->getLL('user') . ' ' . $grVals['username'];
200 }
201 }
202
203 // CLEANSE SETTINGS
204 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
205
206 // manual dates
207 if ($this->MOD_SETTINGS['time'] == 30) {
208 if (!trim($this->MOD_SETTINGS['manualdate'])) {
209 $this->theTime = $this->MOD_SETTINGS['manualdate'] = 0;
210 } else {
211 $this->theTime = $this->parseDate($this->MOD_SETTINGS['manualdate']);
212 if (!$this->theTime) {
213 $this->MOD_SETTINGS['manualdate'] = '';
214 } else {
215 $this->MOD_SETTINGS['manualdate'] = date($this->dateFormat, $this->theTime);
216 }
217 }
218
219 if (!trim($this->MOD_SETTINGS['manualdate_end'])) {
220 $this->theTime_end = $this->MOD_SETTINGS['manualdate_end'] = 0;
221 } else {
222 $this->theTime_end = $this->parseDate($this->MOD_SETTINGS['manualdate_end']);
223 if (!$this->theTime_end) {
224 $this->MOD_SETTINGS['manualdate_end'] = '';
225 } else {
226 $this->MOD_SETTINGS['manualdate_end'] = date($this->dateFormat, $this->theTime_end);
227 }
228 }
229 }
230 }
231
232 /**
233 * Main function
234 *
235 * @return void
236 */
237 function main() {
238 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
239
240 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('adminLog'));
241 $this->content.=$this->doc->spacer(5);
242
243
244 // Menu compiled:
245 $menuU= t3lib_BEfunc::getFuncMenu(0,'SET[users]',$this->MOD_SETTINGS['users'],$this->MOD_MENU['users']);
246 $menuM= t3lib_BEfunc::getFuncMenu(0,'SET[max]',$this->MOD_SETTINGS['max'],$this->MOD_MENU['max']);
247 $menuT= t3lib_BEfunc::getFuncMenu(0,'SET[time]',$this->MOD_SETTINGS['time'],$this->MOD_MENU['time']);
248 $menuA= t3lib_BEfunc::getFuncMenu(0,'SET[action]',$this->MOD_SETTINGS['action'],$this->MOD_MENU['action']);
249 $menuW= t3lib_BEfunc::getFuncMenu(0,'SET[workspaces]',$this->MOD_SETTINGS['workspaces'],$this->MOD_MENU['workspaces']);
250
251 $groupByPage= t3lib_BEfunc::getFuncCheck(0, 'SET[groupByPage]',$this->MOD_SETTINGS['groupByPage']);
252 $style = ' style="margin:4px 2px;padding:1px;vertical-align:middle;width: 115px;"';
253
254 $inputDate = '<input type="text" value="' . ($this->MOD_SETTINGS['manualdate'] ? $this->MOD_SETTINGS['manualdate'] : '') .'" name="SET[manualdate]" id="tceforms-datetimefield-manualdate"' . $style . ' />';
255 $pickerInputDate = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/datepicker.gif', '', 0) . ' style="cursor:pointer; vertical-align:middle;" alt=""' . ' id="picker-tceforms-datetimefield-manualdate" />';
256
257 $inputDate_end = '<input type="text" value="' . ($this->MOD_SETTINGS['manualdate_end'] ? $this->MOD_SETTINGS['manualdate_end'] : '') .'" name="SET[manualdate]" id="tceforms-datetimefield-manualdate_end"' . $style . ' />';
258 $pickerInputDate_end = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/datepicker.gif', '', 0) . ' style="cursor:pointer; vertical-align:middle;" alt=""' . ' id="picker-tceforms-datetimefield-manualdate_end" />';
259
260 $setButton = '<input type="button" value="' . $GLOBALS['LANG']->getLL('set') . '" onclick="jumpToUrl(\'mod.php?&amp;id=0&amp;M=tools_log&amp;SET[manualdate]=\'+escape($(\'tceforms-datetimefield-manualdate\').value)+\'&amp;SET[manualdate_end]=\'+escape($(\'tceforms-datetimefield-manualdate_end\').value),this);" />';
261
262 $this->content.=$this->doc->section('',$this->doc->menuTable(
263 array(
264 array($GLOBALS['LANG']->getLL('users'), $menuU),
265 array($GLOBALS['LANG']->getLL('time'), $menuT . ($this->MOD_SETTINGS['time'] == 30 ?
266 '<br />' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:from', true) . ' ' . $inputDate . $pickerInputDate .
267 ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:to', true) . ' ' . $inputDate_end . $pickerInputDate_end . '&nbsp;' . $setButton : ''))
268 ),
269 array(
270 array($GLOBALS['LANG']->getLL('max'), $menuM),
271 array($GLOBALS['LANG']->getLL('action'), $menuA)
272 ),
273 array(
274 $GLOBALS['BE_USER']->workspace !== 0 ? array($GLOBALS['LANG']->getLL('workspace'), '<strong>'.$GLOBALS['BE_USER']->workspace . '</strong>') : array($GLOBALS['LANG']->getLL('workspace'), $menuW),
275 array($GLOBALS['LANG']->getLL('groupByPage'), $groupByPage)
276 )
277 ));
278
279
280 $codeArr = $this->lF->initArray();
281 $oldHeader='';
282 $c=0;
283
284 // Action (type):
285 $where_part='';
286 if ($this->MOD_SETTINGS['action'] > 0) {
287 $where_part.=' AND type='.intval($this->MOD_SETTINGS['action']);
288 } elseif ($this->MOD_SETTINGS['action'] == -1) {
289 $where_part .= ' AND error != 0';
290 }
291
292
293 $starttime=0;
294 $endtime = $GLOBALS['EXEC_TIME'];
295
296 // Time:
297 switch($this->MOD_SETTINGS['time']) {
298 case 0:
299 // This week
300 $week = (date('w') ? date('w') : 7)-1;
301 $starttime = mktime (0,0,0)-$week*3600*24;
302 break;
303 case 1:
304 // Last week
305 $week = (date('w') ? date('w') : 7)-1;
306 $starttime = mktime (0,0,0)-($week+7)*3600*24;
307 $endtime = mktime (0,0,0)-$week*3600*24;
308 break;
309 case 2:
310 // Last 7 days
311 $starttime = mktime (0,0,0)-7*3600*24;
312 break;
313 case 10:
314 // This month
315 $starttime = mktime (0,0,0, date('m'),1);
316 break;
317 case 11:
318 // Last month
319 $starttime = mktime (0,0,0, date('m')-1,1);
320 $endtime = mktime (0,0,0, date('m'),1);
321 break;
322 case 12:
323 // Last 31 days
324 $starttime = mktime (0,0,0)-31*3600*24;
325 break;
326 case 30:
327 $starttime = $this->theTime;
328 if ($this->theTime_end) {
329 $endtime = $this->theTime_end;
330 } else {
331 $endtime = $GLOBALS['EXEC_TIME'];
332 }
333 }
334
335 if ($starttime) {
336 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
337 }
338
339
340 // Users
341 $selectUsers = array();
342 if (substr($this->MOD_SETTINGS['users'],0,3) == "gr-") { // All users
343 $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array(substr($this->MOD_SETTINGS['users'],3)),1);
344 if (is_array($this->be_user_Array)) {
345 foreach ($this->be_user_Array as $val) {
346 if ($val['uid']!=$BE_USER->user['uid']) {
347 $selectUsers[]=$val['uid'];
348 }
349 }
350 }
351 $selectUsers[] = 0;
352 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
353 } elseif (substr($this->MOD_SETTINGS['users'],0,3) == "us-") { // All users
354 $selectUsers[] = intval(substr($this->MOD_SETTINGS['users'],3));
355 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
356 } elseif ($this->MOD_SETTINGS['users']==-1) {
357 $where_part.=' AND userid='.$BE_USER->user['uid']; // Self user
358 }
359
360 // Workspace
361 if ($GLOBALS['BE_USER']->workspace!==0) {
362 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
363 } elseif ($this->MOD_SETTINGS['workspaces']!=-99) {
364 $where_part.=' AND workspace='.intval($this->MOD_SETTINGS['workspaces']);
365 }
366
367 // Finding out which page ids are in the log:
368 $logPids = array();
369 if ($this->MOD_SETTINGS['groupByPage']) {
370 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('event_pid', 'sys_log', '1=1'.$where_part, 'event_pid');
371 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
372 $logPids[] = $row['event_pid'];
373 }
374
375 // Overview:
376 $overviewList = array();
377 foreach($logPids as $pid) {
378 if ((int)$pid>0) {
379 $overviewList[]= htmlspecialchars(
380 sprintf(
381 $GLOBALS['LANG']->getLL('pagenameWithUID'),
382 t3lib_BEfunc::getRecordPath($pid, '', 20),
383 $pid
384 )
385 );
386 }
387 }
388 sort($overviewList);
389 $this->content.=$this->doc->divider(5);
390 $this->content.= $this->doc->section(
391 $GLOBALS['LANG']->getLL('overview'),
392 sprintf($GLOBALS['LANG']->getLL('timeInfo'),
393 date($this->dateFormat, $starttime),
394 date($this->dateFormat, $endtime)) .
395 '<br /><br /><br />' . implode('<br />', $overviewList),
396 1, 1, 0
397 );
398
399 $this->content.=$this->doc->spacer(30);
400 } else $logPids[] = '_SINGLE';
401
402
403 foreach($logPids as $pid) {
404 $codeArr = $this->lF->initArray();
405 $this->lF->reset();
406 $oldHeader='';
407
408 $this->content.=$this->doc->divider(5);
409 switch($pid) {
410 case '_SINGLE':
411 $insertMsg = '';
412 break;
413 case '-1':
414 $insertMsg = ' ' . $GLOBALS['LANG']->getLL('forNonPageRelatedActions') . ' ';
415 break;
416 case '0':
417 $insertMsg = ' ' . $GLOBALS['LANG']->getLL('forRootLevel') . ' ';
418 break;
419 default:
420 $insertMsg = ' ' . sprintf($GLOBALS['LANG']->getLL('forPage'), t3lib_BEfunc::getRecordPath($pid, '', 20), $pid) . ' ';
421 break;
422 }
423 $this->content .= $this->doc->section(
424 sprintf($GLOBALS['LANG']->getLL('logForNonPageRelatedActionsOrRootLevelOrPage'),
425 $insertMsg,
426 date($this->dateFormat, $starttime),
427 date($this->dateFormat, $endtime)
428 ),
429 '', 1, 1, 0
430 );
431
432 $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']));
433
434 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
435 $header=$this->doc->formatTime($row['tstamp'],10);
436 if (!$oldHeader) $oldHeader=$header;
437
438 if ($header!=$oldHeader) {
439 $this->content.=$this->doc->spacer(10);
440 $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
441 $codeArr=$this->lF->initArray();
442 $oldHeader=$header;
443 $this->lF->reset();
444 }
445
446 $i++;
447 $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
448 $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
449 $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
450 $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
451 $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
452 $codeArr[$i][]=$this->lF->formatDetailsForList($row);
453 }
454 $this->content.=$this->doc->spacer(10);
455 $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
456
457 $GLOBALS['TYPO3_DB']->sql_free_result($log);
458 }
459
460 // Setting up the buttons and markers for docheader
461 $docHeaderButtons = $this->getButtons();
462 //$markers['CSH'] = $docHeaderButtons['csh'];
463 $markers['CONTENT'] = $this->content;
464
465 // Build the <body> for the module
466 $this->content = $this->doc->startPage($GLOBALS['LANG']->getLL('adminLog'));
467 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
468 $this->content.= $this->doc->endPage();
469 $this->content = $this->doc->insertStylesAndJS($this->content);
470 }
471
472 /**
473 * Parse the manual date
474 *
475 * @param string $date
476 * @return int timestamp
477 */
478 function parseDate($date) {
479 if (strpos($date, ' ') === FALSE) {
480 $date .= ' 0:00';
481 }
482 $parts = t3lib_div::trimExplode(' ', $date, TRUE);
483
484 $dateParts = preg_split('/[-\.\/]/', $parts[0]);
485 if (count($dateParts) < 3) {
486 return 0;
487 }
488 $timeParts = preg_split('/[\.:]/', $parts[1]);
489 return mktime($timeParts[0], $timeParts[1], 0, $dateParts[1], $dateParts[0], $dateParts[2]);
490 }
491
492 /**
493 * Output content
494 *
495 * @return string HTML
496 */
497 function printContent() {
498 echo $this->content;
499 }
500
501 /**
502 * Create the panel of buttons for submitting the form or otherwise perform operations.
503 *
504 * @return array all available buttons as an assoc. array
505 */
506 protected function getButtons() {
507
508 $buttons = array(
509 'csh' => '',
510 'shortcut' => ''
511 );
512 // CSH
513 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
514
515 // Shortcut
516 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
517 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','users,time,max,action',$this->MCONF['name']);
518 }
519
520 return $buttons;
521 }
522 }
523
524
525 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']) {
526 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']);
527 }
528
529
530
531 // Make instance:
532 $SOBE = t3lib_div::makeInstance('SC_mod_tools_log_index');
533 $SOBE->init();
534 $SOBE->main();
535 $SOBE->printContent();
536 ?>