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