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