git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@4872 709f56b5-9817-0410-a4d7...
authorKasper Skårhøj <kasper@typo3.org>
Tue, 27 Jan 2009 15:18:53 +0000 (15:18 +0000)
committerKasper Skårhøj <kasper@typo3.org>
Tue, 27 Jan 2009 15:18:53 +0000 (15:18 +0000)
ChangeLog
t3lib/class.t3lib_bedisplaylog.php
typo3/sysext/belog/mod/index.php

index 4f54f41..a4198a4 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-01-27     Kasper Sk\8crh¿j  <kasper@typo3.org>
+
+       * Made a number of changes to log-display (Tools > Log): Filter on workspace, users, grouping by pages, plus option to specify a time interval manually.
+       * Changed HH:MM format for log-display to HH:MM:SS (so it includes seconds). This way it can be assumed for most that all operations within in a single second for a given backend user represents a server request.
+
 2009-01-27  Steffen Kamper  <info@sk-typo3.de> 
 
        Fixed bug  #10263: Multiple calls to deprecated function "fixed_lgd_pre" (thanks to Susanne Moog)
index 6e47bf8..2c449e8 100644 (file)
@@ -121,11 +121,15 @@ class t3lib_BEDisplayLog {
         * @return      string          If the timestamp was also shown last time, then "." is returned. Otherwise the new timestamp formatted with ->doc->formatTime()
         */
        function getTimeLabel($code)    {
-               $t=$GLOBALS['SOBE']->doc->formatTime($code,1);
+               #$t=$GLOBALS['SOBE']->doc->formatTime($code,1);
+               $t = date('H:i:s',$code);
+               
                if ($this->lastTimeLabel!=$t)   {
                        $this->lastTimeLabel=$t;
                        return $t;
-               } else return '.';
+               } else {
+                       return '.';
+               }
 
        }
 
@@ -188,7 +192,7 @@ class t3lib_BEDisplayLog {
                if (is_array($data))    {
                        if ($this->detailsOn)   {
                                if (is_object($GLOBALS['LANG']))        {
-                                       $label = $GLOBALS['LANG']->getLL('msg_'.$code);
+#                                      $label = $GLOBALS['LANG']->getLL('msg_'.$code);
                                } else {
                                        list($label) = explode(',',$text);
                                }
index 677c768..fb4368b 100755 (executable)
@@ -64,6 +64,9 @@ class SC_mod_tools_log_index {
        var $content;
        var $lF;
        var $be_user_Array;
+       
+       var $theTime = 0;
+       var $theTime_end = 0;
 
        /**
         * Initialize module
@@ -113,7 +116,7 @@ class SC_mod_tools_log_index {
         * @return      void
         */
        function menuConfig()   {
-               global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
+               global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS,$TYPO3_DB;
 
                        // MENU-ITEMS:
                        // If array, then it's a selector box menu
@@ -121,9 +124,14 @@ class SC_mod_tools_log_index {
                        // Values NOT in this array will not be saved in the settings-array for the module.
                $this->MOD_MENU = array(
                        'users' => array(
-                               0 => $GLOBALS['LANG']->getLL('allUsers'),
+                               0 => $GLOBALS['LANG']->getLL('any'),
                                '-1' => $GLOBALS['LANG']->getLL('self')
                        ),
+                       'workspaces' => array(
+                               '-99' => $GLOBALS['LANG']->getLL('any'),
+                               0 => $GLOBALS['LANG']->getLL('live'),
+                               '-1' => $GLOBALS['LANG']->getLL('draft'),
+                       ),
                        'time' => array(
                                0 => $GLOBALS['LANG']->getLL('thisWeek'),
                                1 => $GLOBALS['LANG']->getLL('lastWeek'),
@@ -138,28 +146,65 @@ class SC_mod_tools_log_index {
                                50 => $GLOBALS['LANG']->getLL('50'),
                                100 => $GLOBALS['LANG']->getLL('100'),
                                200 => $GLOBALS['LANG']->getLL('200'),
-                               500 => $GLOBALS['LANG']->getLL('500')
+                               500 => $GLOBALS['LANG']->getLL('500'),
+                               1000 => $GLOBALS['LANG']->getLL('1000'),
+                               1000000 => $GLOBALS['LANG']->getLL('any')
                        ),
                        'action' => array(
-                               0 => $GLOBALS['LANG']->getLL('actionAll'),
+                               0 => $GLOBALS['LANG']->getLL('any'),
                                1 => $GLOBALS['LANG']->getLL('actionDatabase'),
                                2 => $GLOBALS['LANG']->getLL('actionFile'),
                                254 => $GLOBALS['LANG']->getLL('actionSettings'),
                                255 => $GLOBALS['LANG']->getLL('actionLogin'),
                                '-1' => $GLOBALS['LANG']->getLL('actionErrors')
-                       )
+                       ),
+                       'manualdate' => '',
+                       'manualdate_end' => '',
+                       'groupByPage' => '',
                );
 
-                       // Adding groups to the users_array
+               // Add custom workspaces (selecting all, filtering by BE_USER check):
+               $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
+               if (count($workspaces)) {
+                       foreach ($workspaces as $rec)   {
+                               $this->MOD_MENU['workspaces'][$rec['uid']] = $rec['uid'].': '.$rec['title'];
+                       }
+               }
+       
+               // Adding groups to the users_array
                $groups = t3lib_BEfunc::getGroupNames();
-               if (is_array($groups))  {
+                       if (is_array($groups))  {
                        while(list(,$grVals)=each($groups))     {
-                               $this->MOD_MENU['users'][$grVals['uid']] = $GLOBALS['LANG']->getLL('userGroup') . ' ' . $grVals['title'];
+                               $this->MOD_MENU['users']['gr-'.$grVals['uid']] = 'Group: '.$grVals['title'];
+                       }
+               }
+
+               $users = t3lib_BEfunc::getUserNames();
+               if (is_array($users))   {
+                       while(list(,$grVals)=each($users))      {
+                               $this->MOD_MENU['users']['us-'.$grVals['uid']] = 'User: '.$grVals['username'];
                        }
                }
 
                        // CLEANSE SETTINGS
                $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
+               
+                       //
+               if (!trim($this->MOD_SETTINGS['manualdate']))   {
+                       $this->MOD_SETTINGS['manualdate'] = 'YYYY-MM-DD';//"-HH-MM-SS";
+               } else {
+                       $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate']));
+                       $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]);
+                       $this->MOD_SETTINGS['manualdate'] = date('Y-m-d-H-i-s',$this->theTime);
+               }               
+
+               if (!trim($this->MOD_SETTINGS['manualdate_end']))       {
+                       $this->MOD_SETTINGS['manualdate_end'] = 'YYYY-MM-DD';//"-HH-MM-SS";
+               } else {
+                       $parts = t3lib_div::trimExplode('-',trim($this->MOD_SETTINGS['manualdate_end']));
+                       $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]);
+                       $this->MOD_SETTINGS['manualdate_end'] = date('Y-m-d-H-i-s',$this->theTime_end);
+               }               
        }
 
        /**
@@ -179,19 +224,28 @@ class SC_mod_tools_log_index {
                $menuM= t3lib_BEfunc::getFuncMenu(0,'SET[max]',$this->MOD_SETTINGS['max'],$this->MOD_MENU['max']);
                $menuT= t3lib_BEfunc::getFuncMenu(0,'SET[time]',$this->MOD_SETTINGS['time'],$this->MOD_MENU['time']);
                $menuA= t3lib_BEfunc::getFuncMenu(0,'SET[action]',$this->MOD_SETTINGS['action'],$this->MOD_MENU['action']);
+               $menuW= t3lib_BEfunc::getFuncMenu(0,'SET[workspaces]',$this->MOD_SETTINGS['workspaces'],$this->MOD_MENU['workspaces']);
+               
+               $groupByPage= t3lib_BEfunc::getFuncCheck(0,'SET[groupByPage]',$this->MOD_SETTINGS['groupByPage']);
+               $inputDate= t3lib_BEfunc::getFuncInput(0,'SET[manualdate]',$this->MOD_SETTINGS['manualdate'],20);
+               $inputDate_end= t3lib_BEfunc::getFuncInput(0,'SET[manualdate_end]',$this->MOD_SETTINGS['manualdate_end'],20);
 
 
                $this->content.=$this->doc->section('',$this->doc->menuTable(
                        array(
                                array($GLOBALS['LANG']->getLL('users'), $menuU),
-                               array($GLOBALS['LANG']->getLL('time'), $menuT)
+                               array($GLOBALS['LANG']->getLL('time'), ($this->MOD_SETTINGS['manualdate']=='YYYY-MM-DD'?$menuT:'').$inputDate.($this->MOD_SETTINGS['manualdate']!='YYYY-MM-DD' ? '<br/> - '.$inputDate_end:''))
                        ),
                        array(
                                array($GLOBALS['LANG']->getLL('max'), $menuM),
                                array($GLOBALS['LANG']->getLL('action'), $menuA)
+                       ),
+                       array(
+                               $GLOBALS['BE_USER']->workspace!==0 ? array('Workspace:','<b>'.$GLOBALS['BE_USER']->workspace.'</b>') : array('Workspace:',$menuW),
+                               array('Group by page:',$groupByPage)
                        )
                ));
-               $this->content.=$this->doc->divider(5);
+               #$this->content.=$this->doc->divider(5);
 
 
                $codeArr = $this->lF->initArray();
@@ -211,35 +265,42 @@ class SC_mod_tools_log_index {
                $endtime=time();
 
                // Time:
-               switch($this->MOD_SETTINGS['time'])             {
-                       case 0:
-                               // This week
-                               $week = (date('w') ? date('w') : 7)-1;
-                               $starttime = mktime (0,0,0)-$week*3600*24;
-                       break;
-                       case 1:
-                               // Last week
-                               $week = (date('w') ? date('w') : 7)-1;
-                               $starttime = mktime (0,0,0)-($week+7)*3600*24;
-                               $endtime = mktime (0,0,0)-$week*3600*24;
-                       break;
-                       case 2:
-                               // Last 7 days
-                               $starttime = mktime (0,0,0)-7*3600*24;
-                       break;
-                       case 10:
-                               // This month
-                               $starttime = mktime (0,0,0, date('m'),1);
-                       break;
-                       case 11:
-                               // Last month
-                               $starttime = mktime (0,0,0, date('m')-1,1);
-                               $endtime = mktime (0,0,0, date('m'),1);
-                       break;
-                       case 12:
-                               // Last 31 days
-                               $starttime = mktime (0,0,0)-31*3600*24;
-                       break;
+               if ($this->theTime)     {
+                       $starttime = $this->theTime;
+                       if ($this->theTime_end) {
+                               $endtime = $this->theTime_end;
+                       } else $endtime = time();
+               } else {
+                       switch($this->MOD_SETTINGS['time'])             {
+                               case 0:
+                                       // This week
+                                       $week = (date('w') ? date('w') : 7)-1;
+                                       $starttime = mktime (0,0,0)-$week*3600*24;
+                               break;
+                               case 1:
+                                       // Last week
+                                       $week = (date('w') ? date('w') : 7)-1;
+                                       $starttime = mktime (0,0,0)-($week+7)*3600*24;
+                                       $endtime = mktime (0,0,0)-$week*3600*24;
+                               break;
+                               case 2:
+                                       // Last 7 days
+                                       $starttime = mktime (0,0,0)-7*3600*24;
+                               break;
+                               case 10:
+                                       // This month
+                                       $starttime = mktime (0,0,0, date('m'),1);
+                               break;
+                               case 11:
+                                       // Last month
+                                       $starttime = mktime (0,0,0, date('m')-1,1);
+                                       $endtime = mktime (0,0,0, date('m'),1);
+                               break;
+                               case 12:
+                                       // Last 31 days
+                                       $starttime = mktime (0,0,0)-31*3600*24;
+                               break;
+                       }
                }
                if ($starttime) {
                        $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
@@ -247,8 +308,9 @@ class SC_mod_tools_log_index {
 
 
                        // Users
-               if ($this->MOD_SETTINGS['users'] > 0)   {       // All users
-                       $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array($this->MOD_SETTINGS['users']),1);
+               $selectUsers = array();
+               if (substr($this->MOD_SETTINGS['users'],0,3) == "gr-")  {       // All users
+                       $this->be_user_Array = t3lib_BEfunc::blindUserNames($this->be_user_Array,array(substr($this->MOD_SETTINGS['users'],3)),1);
                        if (is_array($this->be_user_Array))     {
                                while(list(,$val)=each($this->be_user_Array))   {
                                        if ($val['uid']!=$BE_USER->user['uid']) {
@@ -258,43 +320,91 @@ class SC_mod_tools_log_index {
                        }
                        $selectUsers[] = 0;
                        $where_part.=' AND userid in ('.implode($selectUsers,',').')';
+               } elseif (substr($this->MOD_SETTINGS['users'],0,3) == "us-")    {       // All users
+                       $selectUsers[] = intval(substr($this->MOD_SETTINGS['users'],3));
+                       $where_part.=' AND userid in ('.implode($selectUsers,',').')';
                } elseif ($this->MOD_SETTINGS['users']==-1) {
                        $where_part.=' AND userid='.$BE_USER->user['uid'];      // Self user
                }
 
+                       // Workspace
                if ($GLOBALS['BE_USER']->workspace!==0) {
                        $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
+               } elseif ($this->MOD_SETTINGS['workspaces']!=-99)       {
+                       $where_part.=' AND workspace='.intval($this->MOD_SETTINGS['workspaces']);
                }
 
+                       // Finding out which page ids are in the log:
+               $logPids = array();
+               if ($this->MOD_SETTINGS['groupByPage']) {
+                       $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('event_pid', 'sys_log', '1=1'.$where_part, 'event_pid');
+                       while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log))       {
+                               $logPids[] = $row['event_pid'];
+                       }
 
+                               // Overview:
+                       $overviewList = array();
+                       foreach($logPids as $pid)       {
+                               if ((int)$pid>0)        {
+                                       $overviewList[]= htmlspecialchars(t3lib_BEfunc::getRecordPath($pid,'',20).'" [UID:'.$pid.']');
+                               }
+                       }
+                       sort($overviewList);
+                       $this->content.=$this->doc->divider(5);
+                       $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);
+                       $this->content.=$this->doc->spacer(30);
+               } else $logPids[] = '_SINGLE';
+
+
+               foreach($logPids as $pid)       {
+                       $codeArr = $this->lF->initArray();
+                       $this->lF->reset();
+                       $oldHeader='';
+
+                       $this->content.=$this->doc->divider(5);
+                       switch($pid)    {
+                               case '_SINGLE':
+                                       $insertMsg = '';
+                               break;
+                               case '-1':
+                                       $insertMsg = ' for NON-PAGE related actions ';
+                               break;
+                               case '0':
+                                       $insertMsg = ' for ROOT LEVEL ';
+                               break;
+                               default:
+                                       $insertMsg = ' for PAGE "'.t3lib_BEfunc::getRecordPath($pid,'',20).'" ('.$pid.') ';
+                               break;
+                       }
+                       $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);
 
+                       $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']));
 
-               $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', '1=1'.$where_part, '', 'uid DESC', intval($this->MOD_SETTINGS['max']));
+                       while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log))       {
+                               $header=$this->doc->formatTime($row['tstamp'],10);
+                               if (!$oldHeader)        $oldHeader=$header;
 
-               while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log))       {
-                       $header=$this->doc->formatTime($row['tstamp'],10);
-                       if (!$oldHeader)        $oldHeader=$header;
+                               if ($header!=$oldHeader)        {
+                                       $this->content.=$this->doc->spacer(10);
+                                       $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
+                                       $codeArr=$this->lF->initArray();
+                                       $oldHeader=$header;
+                                       $this->lF->reset();
+                               }
 
-                       if ($header!=$oldHeader)        {
-                               $this->content.=$this->doc->spacer(10);
-                               $this->content.=$this->doc->section($oldHeader,$this->doc->table($codeArr));
-                               $codeArr=$this->lF->initArray();
-                               $oldHeader=$header;
-                               $this->lF->reset();
+                               $i++;
+                               $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
+                               $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
+                               $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
+                               $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
+                               $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
+                               $codeArr[$i][]=$this->lF->formatDetailsForList($row);
                        }
+                       $this->content.=$this->doc->spacer(10);
+                       $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
 
-                       $i++;
-                       $codeArr[$i][]=$this->lF->getTimeLabel($row['tstamp']);
-                       $codeArr[$i][]=$this->lF->getUserLabel($row['userid'],$row['workspace']);
-                       $codeArr[$i][]=$this->lF->getTypeLabel($row['type']);
-                       $codeArr[$i][]=$row['error'] ? $this->lF->getErrorFormatting($this->lF->errorSign[$row['error']],$row['error']) : '';
-                       $codeArr[$i][]=$this->lF->getActionLabel($row['type'].'_'.$row['action']);
-                       $codeArr[$i][]=$this->lF->formatDetailsForList($row);
+                       $GLOBALS['TYPO3_DB']->sql_free_result($log);
                }
-               $this->content.=$this->doc->spacer(10);
-               $this->content.=$this->doc->section($header,$this->doc->table($codeArr));
-
-               $GLOBALS['TYPO3_DB']->sql_free_result($log);
 
                        // Setting up the buttons and markers for docheader
                $docHeaderButtons = $this->getButtons();