TYPO3 API  SVNRelease
class.tx_belog_webinfo.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 /**
00028  * Extension classes for log display in Web > Info and Tools > Log modules
00029  *
00030  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00031  */
00032 /**
00033  * [CLASS/FUNCTION INDEX of SCRIPT]
00034  *
00035  *
00036  *
00037  *   65: class logFunctions_ext extends t3lib_BEDisplayLog
00038  *   72:     function initArray()
00039  *
00040  *
00041  *   97: class tx_belog_webinfo extends t3lib_extobjbase
00042  *  105:     function modMenu()
00043  *  136:     function localLang()
00044  *  147:     function main()
00045  *
00046  * TOTAL FUNCTIONS: 4
00047  * (This index is automatically created/updated by the extension "extdeveval")
00048  *
00049  */
00050 
00051 
00052 
00053 /**
00054  * Extending for Tools > Log. Just setting labels correctly
00055  *
00056  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00057  * @package TYPO3
00058  * @subpackage tx_belog
00059  */
00060 class logFunctions_ext extends t3lib_BEDisplayLog {
00061 
00062     /**
00063      * Initialize the log table array with header labels.
00064      *
00065      * @return  array
00066      */
00067     function initArray()    {
00068         global $LANG;
00069         $codeArr=Array();
00070         $codeArr[$i][]=$LANG->getLL('chLog_l_time');
00071         $codeArr[$i][]=$LANG->getLL('chLog_l_user');
00072         $codeArr[$i][]=$LANG->getLL('chLog_l_error');
00073         $codeArr[$i][]=$LANG->getLL('chLog_l_action');
00074         $codeArr[$i][]=$LANG->getLL('chLog_l_table');
00075         $codeArr[$i][]=$LANG->getLL('chLog_l_details');
00076         return $codeArr;
00077     }
00078 }
00079 
00080 
00081 
00082 
00083 /**
00084  * Extending for Web>Info
00085  *
00086  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00087  * @package TYPO3
00088  * @subpackage tx_belog
00089  */
00090 class tx_belog_webinfo extends t3lib_extobjbase {
00091     var $localLangFile = 'locallang.php';
00092 
00093     /**
00094      * Setting up function menu
00095      *
00096      * @return  array       Menu items
00097      */
00098     function modMenu()  {
00099         global $LANG;
00100 
00101         return array(
00102             'log_users' => array(
00103                 0 => $LANG->getLL('chLog_users_0'),
00104                 '-1' => $LANG->getLL('chLog_users_-1')
00105             ),
00106             'log_time' => array(
00107                 0 => $LANG->getLL('chLog_time_0'),
00108                 1 => $LANG->getLL('chLog_time_1'),
00109                 2 => $LANG->getLL('chLog_time_2'),
00110                 10 => $LANG->getLL('chLog_time_10'),
00111                 11 => $LANG->getLL('chLog_time_11'),
00112                 12 => $LANG->getLL('chLog_time_12'),
00113                 20 => $LANG->getLL('chLog_time_20')
00114             ),
00115             'depth' => array(
00116                 0 => $LANG->getLL('depth_0'),
00117                 1 => $LANG->getLL('depth_1'),
00118                 2 => $LANG->getLL('depth_2'),
00119                 3 => $LANG->getLL('depth_3')
00120             )
00121         );
00122     }
00123 
00124     /**
00125      * Include locallang file
00126      *
00127      * @return  void
00128      */
00129     function localLang()    {
00130         $LOCAL_LANG = $GLOBALS['LANG']->includeLLFile('EXT:belog/mod/locallang.xml',FALSE);
00131 
00132         $GLOBALS['LOCAL_LANG']=t3lib_div::array_merge_recursive_overrule($GLOBALS['LOCAL_LANG'],$LOCAL_LANG);
00133     }
00134 
00135     /**
00136      * Show the log entries for page
00137      *
00138      * @return  string      HTML output
00139      */
00140     function main() {
00141         global $SOBE,$LANG;
00142 
00143         $this->localLang();
00144 
00145         $lF = t3lib_div::makeInstance('logFunctions_ext');
00146 
00147         $theOutput='';
00148         $menu='';
00149         $menu.=  '&nbsp;'.$LANG->getLL('chLog_menuUsers').': '.t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[log_users]',$this->pObj->MOD_SETTINGS['log_users'],$this->pObj->MOD_MENU['log_users']);
00150         $menu.=  '&nbsp;'.$LANG->getLL('chLog_menuDepth').': '.t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth']);
00151         $menu.=  '&nbsp;'.$LANG->getLL('chLog_menuTime').': '.t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[log_time]',$this->pObj->MOD_SETTINGS['log_time'],$this->pObj->MOD_MENU['log_time']);
00152         $theOutput.=$this->pObj->doc->section($LANG->getLL('chLog_title'),'<span class="nobr">'.$menu.'</span>',0,1);
00153 
00154             // Build query
00155         $where_part='';
00156 
00157             // Get the id-list of pages for the tree structure.
00158         $tree = t3lib_div::makeInstance('t3lib_pageTree');
00159         $tree->init('AND '.$this->pObj->perms_clause);
00160         $tree->makeHTML=0;
00161         $tree->fieldArray = Array('uid');
00162         if ($this->pObj->MOD_SETTINGS['depth']) {
00163             $tree->getTree($this->pObj->id, $this->pObj->MOD_SETTINGS['depth'], '');
00164         }
00165         $tree->ids[]=$this->pObj->id;
00166         $idList = implode($tree->ids,',');
00167 
00168         $where_part.=' AND (event_pid in ('.$idList.'))';       // DB
00169 
00170             // Time:
00171         $starttime=0;
00172         $endtime = $GLOBALS['EXEC_TIME'];
00173         switch($this->pObj->MOD_SETTINGS['log_time'])       {
00174             case 0:
00175                 // This week
00176                 $week = (date('w') ? date('w') : 7)-1;
00177                 $starttime = mktime (0,0,0)-$week*3600*24;
00178             break;
00179             case 1:
00180                 // Last week
00181                 $week = (date('w') ? date('w') : 7)-1;
00182                 $starttime = mktime (0,0,0)-($week+7)*3600*24;
00183                 $endtime = mktime (0,0,0)-$week*3600*24;
00184             break;
00185             case 2:
00186                 // Last 7 days
00187                 $starttime = mktime (0,0,0)-7*3600*24;
00188             break;
00189             case 10:
00190                 // This month
00191                 $starttime = mktime (0,0,0, date('m'),1);
00192             break;
00193             case 11:
00194                 // Last month
00195                 $starttime = mktime (0,0,0, date('m')-1,1);
00196                 $endtime = mktime (0,0,0, date('m'),1);
00197             break;
00198             case 12:
00199                 // Last 31 days
00200                 $starttime = mktime (0,0,0)-31*3600*24;
00201             break;
00202         }
00203         if ($starttime) {
00204             $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
00205         }
00206 
00207         $where_part.=' AND type=1';     // DB
00208 
00209 
00210             // Users
00211         $this->pObj->be_user_Array = t3lib_BEfunc::getUserNames();
00212         if (!$this->pObj->MOD_SETTINGS['log_users'])    {   // All users
00213                 // Get usernames and groupnames
00214             if (!$GLOBALS['BE_USER']->isAdmin())        {
00215                 $groupArray = explode(',',$GLOBALS['BE_USER']->user['usergroup_cached_list']);
00216                 $this->pObj->be_user_Array = t3lib_BEfunc::blindUserNames($this->pObj->be_user_Array,$groupArray,1);
00217             }
00218 
00219             if (is_array($this->pObj->be_user_Array))   {
00220                 foreach ($this->pObj->be_user_Array as $val) {
00221                     $selectUsers[]=$val['uid'];
00222                 }
00223             }
00224             $selectUsers[] = $GLOBALS['BE_USER']->user['uid'];
00225             $where_part.=' AND userid in ('.implode($selectUsers,',').')';
00226         } else {
00227             $where_part.=' AND userid='.$GLOBALS['BE_USER']->user['uid'];   // Self user
00228         }
00229         $lF->be_user_Array = &$this->pObj->be_user_Array;
00230 
00231         if ($GLOBALS['BE_USER']->workspace!==0) {
00232             $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
00233         }
00234 
00235 
00236             // Select 100 recent log entries:
00237         $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', '1=1'.$where_part, '', 'uid DESC', 100);
00238 
00239         $codeArr = $lF->initArray();
00240         $oldHeader = '';
00241         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log))   {
00242             $header = $this->pObj->doc->formatTime($row['tstamp'],10);
00243             if (!$oldHeader)    $oldHeader = $header;
00244 
00245             if ($header!=$oldHeader)    {
00246                 $theOutput.=$this->pObj->doc->spacer(10);
00247                 $theOutput.=$this->pObj->doc->section($oldHeader,$this->pObj->doc->table($codeArr));
00248                 $codeArr=$lF->initArray();
00249                 $oldHeader=$header;
00250                 $lF->reset();
00251             }
00252 
00253             $i++;
00254             $codeArr[$i][]=$lF->getTimeLabel($row['tstamp']);
00255             $codeArr[$i][]=$lF->getUserLabel($row['userid'],$row['workspace']);
00256             $codeArr[$i][]=$row['error'] ? $lF->getErrorFormatting($lF->errorSign[$row['error']],$row['error']) : '';
00257             $codeArr[$i][]=$lF->getActionLabel($row['type'].'_'.$row['action']);
00258             $codeArr[$i][]=$row['tablename'];
00259             $codeArr[$i][]=$lF->formatDetailsForList($row);
00260         }
00261         $theOutput.=$this->pObj->doc->spacer(10);
00262         $theOutput.=$this->pObj->doc->section($header,$this->pObj->doc->table($codeArr));
00263 
00264         $GLOBALS['TYPO3_DB']->sql_free_result($log);
00265 
00266         return $theOutput;
00267     }
00268 }
00269 
00270 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php'])) {
00271     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php']);
00272 }
00273 
00274 ?>