Cleanup: Updated copyright comments
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / mod / index.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 * 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 Skårhøj <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 3 => $GLOBALS['LANG']->getLL('actionCache'),
172 254 => $GLOBALS['LANG']->getLL('actionSettings'),
173 255 => $GLOBALS['LANG']->getLL('actionLogin'),
174 '-1' => $GLOBALS['LANG']->getLL('actionErrors')
175 ),
176 'manualdate' => '',
177 'manualdate_end' => '',
178 'groupByPage' => '',
179 );
180
181 // Add custom workspaces (selecting all, filtering by BE_USER check):
182 $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
183 if (count($workspaces)) {
184 foreach ($workspaces as $rec) {
185 $this->MOD_MENU['workspaces'][$rec['uid']] = $rec['uid'].': '.$rec['title'];
186 }
187 }
188
189 // Adding groups to the users_array
190 $groups = t3lib_BEfunc::getGroupNames();
191 if (is_array($groups)) {
192 foreach ($groups as $grVals) {
193 $this->MOD_MENU['users']['gr-' . $grVals['uid']] = $GLOBALS['LANG']->getLL('group') . ' ' . $grVals['title'];
194 }
195 }
196
197 $users = t3lib_BEfunc::getUserNames();
198 if (is_array($users)) {
199 foreach ($users as $grVals) {
200 $this->MOD_MENU['users']['us-' . $grVals['uid']] = $GLOBALS['LANG']->getLL('user') . ' ' . $grVals['username'];
201 }
202 }
203
204 // CLEANSE SETTINGS
205 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
206
207 // manual dates
208 if ($this->MOD_SETTINGS['time'] == 30) {
209 if (!trim($this->MOD_SETTINGS['manualdate'])) {
210 $this->theTime = $this->MOD_SETTINGS['manualdate'] = 0;
211 } else {
212 $this->theTime = $this->parseDate($this->MOD_SETTINGS['manualdate']);
213 if (!$this->theTime) {
214 $this->MOD_SETTINGS['manualdate'] = '';
215 } else {
216 $this->MOD_SETTINGS['manualdate'] = date($this->dateFormat, $this->theTime);
217 }
218 }
219
220 if (!trim($this->MOD_SETTINGS['manualdate_end'])) {
221 $this->theTime_end = $this->MOD_SETTINGS['manualdate_end'] = 0;
222 } else {
223 $this->theTime_end = $this->parseDate($this->MOD_SETTINGS['manualdate_end']);
224 if (!$this->theTime_end) {
225 $this->MOD_SETTINGS['manualdate_end'] = '';
226 } else {
227 $this->MOD_SETTINGS['manualdate_end'] = date($this->dateFormat, $this->theTime_end);
228 }
229 }
230 }
231 }
232
233 /**
234 * Main function
235 *
236 * @return void
237 */
238 function main() {
239 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
240
241 $this->content.= $this->doc->header($GLOBALS['LANG']->getLL('adminLog'));
242 $this->content.=$this->doc->spacer(5);
243
244
245 // Menu compiled:
246 $menuU= t3lib_BEfunc::getFuncMenu(0,'SET[users]',$this->MOD_SETTINGS['users'],$this->MOD_MENU['users']);
247 $menuM= t3lib_BEfunc::getFuncMenu(0,'SET[max]',$this->MOD_SETTINGS['max'],$this->MOD_MENU['max']);
248 $menuT= t3lib_BEfunc::getFuncMenu(0,'SET[time]',$this->MOD_SETTINGS['time'],$this->MOD_MENU['time']);
249 $menuA= t3lib_BEfunc::getFuncMenu(0,'SET[action]',$this->MOD_SETTINGS['action'],$this->MOD_MENU['action']);
250 $menuW= t3lib_BEfunc::getFuncMenu(0,'SET[workspaces]',$this->MOD_SETTINGS['workspaces'],$this->MOD_MENU['workspaces']);
251
252 $groupByPage= t3lib_BEfunc::getFuncCheck(0, 'SET[groupByPage]',$this->MOD_SETTINGS['groupByPage']);
253 $style = ' style="margin:4px 2px;padding:1px;vertical-align:middle;width: 115px;"';
254
255 $inputDate = '<input type="text" value="' . ($this->MOD_SETTINGS['manualdate'] ? $this->MOD_SETTINGS['manualdate'] : '') .'" name="SET[manualdate]" id="tceforms-datetimefield-manualdate"' . $style . ' />';
256 $pickerInputDate = '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/datepicker.gif', '', 0) . ' style="cursor:pointer; vertical-align:middle;" alt=""' . ' id="picker-tceforms-datetimefield-manualdate" />';
257
258 $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 . ' />';
259 $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" />';
260
261 $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);" />';
262
263 $this->content.=$this->doc->section('',$this->doc->menuTable(
264 array(
265 array($GLOBALS['LANG']->getLL('users'), $menuU),
266 array($GLOBALS['LANG']->getLL('time'), $menuT . ($this->MOD_SETTINGS['time'] == 30 ?
267 '<br />' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:from', true) . ' ' . $inputDate . $pickerInputDate .
268 ' ' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:to', true) . ' ' . $inputDate_end . $pickerInputDate_end . '&nbsp;' . $setButton : ''))
269 ),
270 array(
271 array($GLOBALS['LANG']->getLL('max'), $menuM),
272 array($GLOBALS['LANG']->getLL('action'), $menuA)
273 ),
274 array(
275 $GLOBALS['BE_USER']->workspace !== 0 ? array($GLOBALS['LANG']->getLL('workspace'), '<strong>'.$GLOBALS['BE_USER']->workspace . '</strong>') : array($GLOBALS['LANG']->getLL('workspace'), $menuW),
276 array($GLOBALS['LANG']->getLL('groupByPage'), $groupByPage)
277 )
278 ));
279
280
281 $codeArr = $this->lF->initArray();
282 $oldHeader='';
283 $c=0;
284
285 // Action (type):
286 $where_part='';
287 if ($this->MOD_SETTINGS['action'] > 0) {
288 $where_part.=' AND type='.intval($this->MOD_SETTINGS['action']);
289 } elseif ($this->MOD_SETTINGS['action'] == -1) {
290 $where_part .= ' AND error != 0';
291 }
292
293
294 $starttime=0;
295 $endtime = $GLOBALS['EXEC_TIME'];
296
297 // Time:
298 switch($this->MOD_SETTINGS['time']) {
299 case 0:
300 // This week
301 $week = (date('w') ? date('w') : 7)-1;
302 $starttime = mktime (0,0,0)-$week*3600*24;
303 break;
304 case 1:
305 // Last week
306 $week = (date('w') ? date('w') : 7)-1;
307 $starttime = mktime (0,0,0)-($week+7)*3600*24;
308 $endtime = mktime (0,0,0)-$week*3600*24;
309 break;
310 case 2:
311 // Last 7 days
312 $starttime = mktime (0,0,0)-7*3600*24;
313 break;
314 case 10:
315 // This month
316 $starttime = mktime (0,0,0, date('m'),1);
317 break;
318 case 11:
319 // Last month
320 $starttime = mktime (0,0,0, date('m')-1,1);
321 $endtime = mktime (0,0,0, date('m'),1);
322 break;
323 case 12:
324 // Last 31 days
325 $starttime = mktime (0,0,0)-31*3600*24;
326 break;
327 case 30:
328 $starttime = $this->theTime;
329 if ($this->theTime_end) {
330 $endtime = $this->theTime_end;
331 } else {
332 $endtime = $GLOBALS['EXEC_TIME'];
333 }
334 }
335
336 if ($starttime) {
337 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
338 }
339
340
341 // Users
342 $selectUsers = array();
343 if (substr($this->MOD_SETTINGS['users'],0,3) == "gr-") { // All users
344 $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array(substr($this->MOD_SETTINGS['users'],3)),1);
345 if (is_array($this->be_user_Array)) {
346 foreach ($this->be_user_Array as $val) {
347 if ($val['uid']!=$BE_USER->user['uid']) {
348 $selectUsers[]=$val['uid'];
349 }
350 }
351 }
352 $selectUsers[] = 0;
353 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
354 } elseif (substr($this->MOD_SETTINGS['users'],0,3) == "us-") { // All users
355 $selectUsers[] = intval(substr($this->MOD_SETTINGS['users'],3));
356 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
357 } elseif ($this->MOD_SETTINGS['users']==-1) {
358 $where_part.=' AND userid='.$BE_USER->user['uid']; // Self user
359 }
360
361 // Workspace
362 if ($GLOBALS['BE_USER']->workspace!==0) {
363 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
364 } elseif ($this->MOD_SETTINGS['workspaces']!=-99) {
365 $where_part.=' AND workspace='.intval($this->MOD_SETTINGS['workspaces']);
366 }
367
368 // Finding out which page ids are in the log:
369 $logPids = array();
370 if ($this->MOD_SETTINGS['groupByPage']) {
371 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('event_pid', 'sys_log', '1=1'.$where_part, 'event_pid');
372 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
373 $logPids[] = $row['event_pid'];
374 }
375
376 // Overview:
377 $overviewList = array();
378 foreach($logPids as $pid) {
379 if ((int)$pid>0) {
380 $overviewList[]= htmlspecialchars(
381 sprintf(
382 $GLOBALS['LANG']->getLL('pagenameWithUID'),
383 t3lib_BEfunc::getRecordPath($pid, '', 20),
384 $pid
385 )
386 );
387 }
388 }
389 sort($overviewList);
390 $this->content.=$this->doc->divider(5);
391 $this->content.= $this->doc->section(
392 $GLOBALS['LANG']->getLL('overview'),
393 sprintf($GLOBALS['LANG']->getLL('timeInfo'),
394 date($this->dateFormat, $starttime),
395 date($this->dateFormat, $endtime)) .
396 '<br /><br /><br />' . implode('<br />', $overviewList),
397 1, 1, 0
398 );
399
400 $this->content.=$this->doc->spacer(30);
401 } else $logPids[] = '_SINGLE';
402
403
404 foreach($logPids as $pid) {
405 $codeArr = $this->lF->initArray();
406 $this->lF->reset();
407 $oldHeader='';
408
409 $this->content.=$this->doc->divider(5);
410 switch($pid) {
411 case '_SINGLE':
412 $insertMsg = '';
413 break;
414 case '-1':
415 $insertMsg = ' ' . $GLOBALS['LANG']->getLL('forNonPageRelatedActions') . ' ';
416 break;
417 case '0':
418 $insertMsg = ' ' . $GLOBALS['LANG']->getLL('forRootLevel') . ' ';
419 break;
420 default:
421 $insertMsg = ' ' . sprintf($GLOBALS['LANG']->getLL('forPage'), t3lib_BEfunc::getRecordPath($pid, '', 20), $pid) . ' ';
422 break;
423 }
424 $this->content .= $this->doc->section(
425 sprintf($GLOBALS['LANG']->getLL('logForNonPageRelatedActionsOrRootLevelOrPage'),
426 $insertMsg,
427 date($this->dateFormat, $starttime),
428 date($this->dateFormat, $endtime)
429 ),
430 '', 1, 1, 0
431 );
432
433 $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']));
434
435 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
436 $header=$this->doc->formatTime($row['tstamp'],10);
437 if (!$oldHeader) $oldHeader=$header;
438
439 if ($header!=$oldHeader) {
440 $this->content.=$this->doc->spacer(10);
441 $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
442 $codeArr=$this->lF->initArray();
443 $oldHeader=$header;
444 $this->lF->reset();
445 }
446
447 $i++;
448 $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
449 $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
450 $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
451 $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
452 $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
453 $codeArr[$i][]=$this->lF->formatDetailsForList($row);
454 }
455 $this->content.=$this->doc->spacer(10);
456 $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
457
458 $GLOBALS['TYPO3_DB']->sql_free_result($log);
459 }
460
461 // Setting up the buttons and markers for docheader
462 $docHeaderButtons = $this->getButtons();
463 //$markers['CSH'] = $docHeaderButtons['csh'];
464 $markers['CONTENT'] = $this->content;
465
466 // Build the <body> for the module
467 $this->content = $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
468 // Renders the module page
469 $this->content = $this->doc->render(
470 $GLOBALS['LANG']->getLL('adminLog'),
471 $this->content
472 );
473
474 }
475
476 /**
477 * Parse the manual date
478 *
479 * @param string $date
480 * @return int timestamp
481 */
482 function parseDate($date) {
483 if (strpos($date, ' ') === FALSE) {
484 $date .= ' 0:00';
485 }
486 $parts = t3lib_div::trimExplode(' ', $date, TRUE);
487
488 $dateParts = preg_split('/[-\.\/]/', $parts[0]);
489 if (count($dateParts) < 3) {
490 return 0;
491 }
492 $timeParts = preg_split('/[\.:]/', $parts[1]);
493 return mktime($timeParts[0], $timeParts[1], 0, $dateParts[1], $dateParts[0], $dateParts[2]);
494 }
495
496 /**
497 * Output content
498 *
499 * @return string HTML
500 */
501 function printContent() {
502 echo $this->content;
503 }
504
505 /**
506 * Create the panel of buttons for submitting the form or otherwise perform operations.
507 *
508 * @return array all available buttons as an assoc. array
509 */
510 protected function getButtons() {
511
512 $buttons = array(
513 'csh' => '',
514 'shortcut' => ''
515 );
516 // CSH
517 //$buttons['csh'] = t3lib_BEfunc::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']);
518
519 // Shortcut
520 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
521 $buttons['shortcut'] = $this->doc->makeShortcutIcon('','users,time,max,action',$this->MCONF['name']);
522 }
523
524 return $buttons;
525 }
526 }
527
528
529 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php'])) {
530 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/mod/index.php']);
531 }
532
533
534
535 // Make instance:
536 $SOBE = t3lib_div::makeInstance('SC_mod_tools_log_index');
537 $SOBE->init();
538 $SOBE->main();
539 $SOBE->printContent();
540 ?>