Fixed issue #13670: Performance optimization: change while(list() to foreach() (thank...
[Packages/TYPO3.CMS.git] / typo3 / sysext / belog / class.tx_belog_webinfo.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 * Extension classes for log display in Web > Info and Tools > Log modules
29 *
30 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
31 */
32 /**
33 * [CLASS/FUNCTION INDEX of SCRIPT]
34 *
35 *
36 *
37 * 65: class logFunctions_ext extends t3lib_BEDisplayLog
38 * 72: function initArray()
39 *
40 *
41 * 97: class tx_belog_webinfo extends t3lib_extobjbase
42 * 105: function modMenu()
43 * 136: function localLang()
44 * 147: function main()
45 *
46 * TOTAL FUNCTIONS: 4
47 * (This index is automatically created/updated by the extension "extdeveval")
48 *
49 */
50
51
52
53 /**
54 * Extending for Tools > Log. Just setting labels correctly
55 *
56 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
57 * @package TYPO3
58 * @subpackage tx_belog
59 */
60 class logFunctions_ext extends t3lib_BEDisplayLog {
61
62 /**
63 * Initialize the log table array with header labels.
64 *
65 * @return array
66 */
67 function initArray() {
68 global $LANG;
69 $codeArr=Array();
70 $codeArr[$i][]=$LANG->getLL('chLog_l_time');
71 $codeArr[$i][]=$LANG->getLL('chLog_l_user');
72 $codeArr[$i][]=$LANG->getLL('chLog_l_error');
73 $codeArr[$i][]=$LANG->getLL('chLog_l_action');
74 $codeArr[$i][]=$LANG->getLL('chLog_l_table');
75 $codeArr[$i][]=$LANG->getLL('chLog_l_details');
76 return $codeArr;
77 }
78 }
79
80
81
82
83 /**
84 * Extending for Web>Info
85 *
86 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
87 * @package TYPO3
88 * @subpackage tx_belog
89 */
90 class tx_belog_webinfo extends t3lib_extobjbase {
91 var $localLangFile = 'locallang.php';
92
93 /**
94 * Setting up function menu
95 *
96 * @return array Menu items
97 */
98 function modMenu() {
99 global $LANG;
100
101 return array(
102 'log_users' => array(
103 0 => $LANG->getLL('chLog_users_0'),
104 '-1' => $LANG->getLL('chLog_users_-1')
105 ),
106 'log_time' => array(
107 0 => $LANG->getLL('chLog_time_0'),
108 1 => $LANG->getLL('chLog_time_1'),
109 2 => $LANG->getLL('chLog_time_2'),
110 10 => $LANG->getLL('chLog_time_10'),
111 11 => $LANG->getLL('chLog_time_11'),
112 12 => $LANG->getLL('chLog_time_12'),
113 20 => $LANG->getLL('chLog_time_20')
114 ),
115 'depth' => array(
116 0 => $LANG->getLL('depth_0'),
117 1 => $LANG->getLL('depth_1'),
118 2 => $LANG->getLL('depth_2'),
119 3 => $LANG->getLL('depth_3')
120 )
121 );
122 }
123
124 /**
125 * Include locallang file
126 *
127 * @return void
128 */
129 function localLang() {
130 $LOCAL_LANG = $GLOBALS['LANG']->includeLLFile('EXT:belog/mod/locallang.xml',FALSE);
131
132 $GLOBALS['LOCAL_LANG']=t3lib_div::array_merge_recursive_overrule($GLOBALS['LOCAL_LANG'],$LOCAL_LANG);
133 }
134
135 /**
136 * Show the log entries for page
137 *
138 * @return string HTML output
139 */
140 function main() {
141 global $SOBE,$LANG;
142
143 $this->localLang();
144
145 $lF = t3lib_div::makeInstance('logFunctions_ext');
146
147 $theOutput='';
148 $menu='';
149 $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']);
150 $menu.= '&nbsp;'.$LANG->getLL('chLog_menuDepth').': '.t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth']);
151 $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']);
152 $theOutput.=$this->pObj->doc->section($LANG->getLL('chLog_title'),'<span class="nobr">'.$menu.'</span>',0,1);
153
154 // Build query
155 $where_part='';
156
157 // Get the id-list of pages for the tree structure.
158 $tree = t3lib_div::makeInstance('t3lib_pageTree');
159 $tree->init('AND '.$this->pObj->perms_clause);
160 $tree->makeHTML=0;
161 $tree->fieldArray = Array('uid');
162 if ($this->pObj->MOD_SETTINGS['depth']) {
163 $tree->getTree($this->pObj->id, $this->pObj->MOD_SETTINGS['depth'], '');
164 }
165 $tree->ids[]=$this->pObj->id;
166 $idList = implode($tree->ids,',');
167
168 $where_part.=' AND (event_pid in ('.$idList.'))'; // DB
169
170 // Time:
171 $starttime=0;
172 $endtime = $GLOBALS['EXEC_TIME'];
173 switch($this->pObj->MOD_SETTINGS['log_time']) {
174 case 0:
175 // This week
176 $week = (date('w') ? date('w') : 7)-1;
177 $starttime = mktime (0,0,0)-$week*3600*24;
178 break;
179 case 1:
180 // Last week
181 $week = (date('w') ? date('w') : 7)-1;
182 $starttime = mktime (0,0,0)-($week+7)*3600*24;
183 $endtime = mktime (0,0,0)-$week*3600*24;
184 break;
185 case 2:
186 // Last 7 days
187 $starttime = mktime (0,0,0)-7*3600*24;
188 break;
189 case 10:
190 // This month
191 $starttime = mktime (0,0,0, date('m'),1);
192 break;
193 case 11:
194 // Last month
195 $starttime = mktime (0,0,0, date('m')-1,1);
196 $endtime = mktime (0,0,0, date('m'),1);
197 break;
198 case 12:
199 // Last 31 days
200 $starttime = mktime (0,0,0)-31*3600*24;
201 break;
202 }
203 if ($starttime) {
204 $where_part.=' AND tstamp>='.$starttime.' AND tstamp<'.$endtime;
205 }
206
207 $where_part.=' AND type=1'; // DB
208
209
210 // Users
211 $this->pObj->be_user_Array = t3lib_BEfunc::getUserNames();
212 if (!$this->pObj->MOD_SETTINGS['log_users']) { // All users
213 // Get usernames and groupnames
214 if (!$GLOBALS['BE_USER']->isAdmin()) {
215 $groupArray = explode(',',$GLOBALS['BE_USER']->user['usergroup_cached_list']);
216 $this->pObj->be_user_Array = t3lib_BEfunc::blindUserNames($this->pObj->be_user_Array,$groupArray,1);
217 }
218
219 if (is_array($this->pObj->be_user_Array)) {
220 foreach ($this->pObj->be_user_Array as $val) {
221 $selectUsers[]=$val['uid'];
222 }
223 }
224 $selectUsers[] = $GLOBALS['BE_USER']->user['uid'];
225 $where_part.=' AND userid in ('.implode($selectUsers,',').')';
226 } else {
227 $where_part.=' AND userid='.$GLOBALS['BE_USER']->user['uid']; // Self user
228 }
229 $lF->be_user_Array = &$this->pObj->be_user_Array;
230
231 if ($GLOBALS['BE_USER']->workspace!==0) {
232 $where_part.=' AND workspace='.intval($GLOBALS['BE_USER']->workspace);
233 }
234
235
236 // Select 100 recent log entries:
237 $log = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_log', '1=1'.$where_part, '', 'uid DESC', 100);
238
239 $codeArr = $lF->initArray();
240 $oldHeader = '';
241 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($log)) {
242 $header = $this->pObj->doc->formatTime($row['tstamp'],10);
243 if (!$oldHeader) $oldHeader = $header;
244
245 if ($header!=$oldHeader) {
246 $theOutput.=$this->pObj->doc->spacer(10);
247 $theOutput.=$this->pObj->doc->section($oldHeader,$this->pObj->doc->table($codeArr));
248 $codeArr=$lF->initArray();
249 $oldHeader=$header;
250 $lF->reset();
251 }
252
253 $i++;
254 $codeArr[$i][]=$lF->getTimeLabel($row['tstamp']);
255 $codeArr[$i][]=$lF->getUserLabel($row['userid'],$row['workspace']);
256 $codeArr[$i][]=$row['error'] ? $lF->getErrorFormatting($lF->errorSign[$row['error']],$row['error']) : '';
257 $codeArr[$i][]=$lF->getActionLabel($row['type'].'_'.$row['action']);
258 $codeArr[$i][]=$row['tablename'];
259 $codeArr[$i][]=$lF->formatDetailsForList($row);
260 }
261 $theOutput.=$this->pObj->doc->spacer(10);
262 $theOutput.=$this->pObj->doc->section($header,$this->pObj->doc->table($codeArr));
263
264 $GLOBALS['TYPO3_DB']->sql_free_result($log);
265
266 return $theOutput;
267 }
268 }
269
270 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php']) {
271 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/belog/class.tx_belog_webinfo.php']);
272 }
273
274 ?>