1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-03-16 22:34:45 +0000 (Thu, 16 Mar 2006) $ |
---|
10 | // | last modifier : $Author: plg $ |
---|
11 | // | revision : $Revision: 1084 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
28 | { |
---|
29 | die ("Hacking attempt!"); |
---|
30 | } |
---|
31 | |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | // | Check Access and exit when user status is not ok | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | check_status(ACCESS_ADMINISTRATOR); |
---|
38 | |
---|
39 | $url_img = PHPWG_ROOT_PATH.'admin/images/'; |
---|
40 | $nls_value_title = $lang['w_month']; |
---|
41 | $group_clause = "DATE_FORMAT(date,'%Y-%m') DESC"; |
---|
42 | $where_clause = "1"; |
---|
43 | |
---|
44 | |
---|
45 | if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) ) |
---|
46 | { |
---|
47 | $url_img .= 'daily_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month'].'&day='.$_GET['day']; |
---|
48 | $nls_value_title = $lang['w_day']; |
---|
49 | $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC"; |
---|
50 | $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )"; |
---|
51 | } |
---|
52 | elseif (isset($_GET['month']) && isset($_GET['year']) ) |
---|
53 | { |
---|
54 | $url_img .= 'monthly_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month']; |
---|
55 | $nls_value_title = $lang['w_day']; |
---|
56 | $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC"; |
---|
57 | $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )"; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | $url_img .= 'global_stats.img.php'; |
---|
62 | } |
---|
63 | |
---|
64 | |
---|
65 | //----------------------------------------------------- template initialization |
---|
66 | if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) ) |
---|
67 | { |
---|
68 | $date_of_day=$_GET['day'].' '.$lang['month'][$_GET['month']].' '.$_GET['year']; |
---|
69 | $title_page=$lang['stats_day_title'].' : '.$date_of_day; |
---|
70 | $url_back = PHPWG_ROOT_PATH."admin.php?page=stats"; |
---|
71 | $url_back = $url_back; |
---|
72 | $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>'; |
---|
73 | $title_day = $date_of_day; |
---|
74 | } |
---|
75 | elseif ( isset($_GET['month']) && isset($_GET['year']) ) |
---|
76 | { |
---|
77 | $date_of_day=$lang['month'][$_GET['month']].' '.$_GET['year']; |
---|
78 | $title_page=$lang['stats_month_title'].' : '.$date_of_day; |
---|
79 | $url_back = PHPWG_ROOT_PATH."admin.php?page=stats"; |
---|
80 | $url_back = $url_back; |
---|
81 | $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>'; |
---|
82 | $title_day=$lang['today']; |
---|
83 | } |
---|
84 | else |
---|
85 | { |
---|
86 | $date_of_day=''; |
---|
87 | $title_page=$lang['stats_title']; |
---|
88 | $title_details=$lang['stats_month_title']; |
---|
89 | $title_day=$lang['today']; |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | $template->set_filenames( array('stats'=>'admin/stats.tpl') ); |
---|
94 | |
---|
95 | $template->assign_vars(array( |
---|
96 | 'L_VALUE'=>$nls_value_title, |
---|
97 | 'L_PAGES_SEEN'=>$lang['stats_pages_seen'], |
---|
98 | 'L_VISITORS'=>$lang['visitors'], |
---|
99 | 'L_PICTURES'=>$lang['pictures'], |
---|
100 | 'L_STAT_TITLE'=>$lang['stats_title'], |
---|
101 | 'L_STAT_MONTH_TITLE'=>$lang['stats_month_title'], |
---|
102 | 'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'], |
---|
103 | 'L_STAT_TITLE'=>$title_page, |
---|
104 | 'L_STAT_DETAIL_TITLE'=>$title_details, |
---|
105 | 'L_DATE_TITLE'=>$title_day, |
---|
106 | 'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'], |
---|
107 | 'L_STAT_HOUR'=>$lang['stats_hour'], |
---|
108 | 'L_STAT_LOGIN'=>$lang['stats_login'], |
---|
109 | 'L_STAT_ADDR'=>$lang['stats_addr'], |
---|
110 | 'L_STAT_CATEGORY'=>$lang['stats_category'], |
---|
111 | 'L_STAT_FILE'=>$lang['stats_file'], |
---|
112 | 'L_STAT_PICTURE'=>$lang['stats_picture'], |
---|
113 | |
---|
114 | 'IMG_REPORT'=>$url_img |
---|
115 | )); |
---|
116 | |
---|
117 | //---------------------------------------------------------------- log history |
---|
118 | $query = ' |
---|
119 | SELECT DISTINCT COUNT(*) as p, |
---|
120 | DAYOFMONTH(date) as d, |
---|
121 | MONTH(date) as m, |
---|
122 | YEAR(date) as y |
---|
123 | FROM '.HISTORY_TABLE.' |
---|
124 | WHERE '.$where_clause.' |
---|
125 | GROUP BY '.$group_clause.';'; |
---|
126 | |
---|
127 | $result = pwg_query( $query ); |
---|
128 | $i=0; |
---|
129 | while ( $row = mysql_fetch_array( $result ) ) |
---|
130 | { |
---|
131 | $where_clause=""; |
---|
132 | $value = ''; |
---|
133 | if (isset($_GET['month']) && isset($_GET['year']) ) |
---|
134 | { |
---|
135 | $where_clause = 'DAYOFMONTH(date) = '.$row['d'].' |
---|
136 | AND MONTH(date) = '.$row['m'].' |
---|
137 | AND YEAR(date) = '.$row['y']; |
---|
138 | |
---|
139 | $week_day = |
---|
140 | $lang['day'][date('w', mktime(12,0,0,$row['m'],$row['d'],$row['y']))]; |
---|
141 | |
---|
142 | $url = |
---|
143 | PHPWG_ROOT_PATH.'admin.php' |
---|
144 | .'?page=stats' |
---|
145 | .'&year='.$row['y'] |
---|
146 | .'&month='.$row['m'] |
---|
147 | .'&day='.$row['d'] |
---|
148 | ; |
---|
149 | |
---|
150 | $value = '<a href="'.$url.'">'; |
---|
151 | $value.= $row['d'].' ('.$week_day.')'; |
---|
152 | $value.= "</a>"; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | $current_month = $row['y']."-"; |
---|
157 | if ($row['m'] <10) {$current_month.='0';} |
---|
158 | $current_month .= $row['m']; |
---|
159 | |
---|
160 | $where_clause = "DATE_FORMAT(date,'%Y-%m') = '".$current_month."'"; |
---|
161 | |
---|
162 | $url = |
---|
163 | PHPWG_ROOT_PATH.'admin.php' |
---|
164 | .'?page=stats' |
---|
165 | .'&year='.$row['y'] |
---|
166 | .'&month='.$row['m'] |
---|
167 | ; |
---|
168 | |
---|
169 | $value = '<a href="'.$url.'">'; |
---|
170 | $value.= $lang['month'][$row['m']].' '.$row['y']; |
---|
171 | $value.= "</a>"; |
---|
172 | } |
---|
173 | |
---|
174 | // Number of pictures seen |
---|
175 | $query = ' |
---|
176 | SELECT COUNT(*) as p |
---|
177 | FROM '.HISTORY_TABLE.' |
---|
178 | WHERE '.$where_clause.' |
---|
179 | AND FILE = \'picture\' |
---|
180 | ;'; |
---|
181 | $pictures = mysql_fetch_array(pwg_query( $query )); |
---|
182 | |
---|
183 | // Number of different visitors |
---|
184 | $query = ' |
---|
185 | SELECT COUNT(*) as p, login |
---|
186 | FROM '.HISTORY_TABLE.' |
---|
187 | WHERE '.$where_clause.' |
---|
188 | GROUP BY login, IP |
---|
189 | ;'; |
---|
190 | $user_results = pwg_query( $query ); |
---|
191 | $nb_visitors = 0; |
---|
192 | $auth_users = array(); |
---|
193 | while ( $user_array = mysql_fetch_array( $user_results ) ) |
---|
194 | { |
---|
195 | if ($user_array['login'] == 'guest') |
---|
196 | $nb_visitors += 1; |
---|
197 | else |
---|
198 | array_push($auth_users, $user_array['login']); |
---|
199 | } |
---|
200 | $nb_visitors +=count(array_unique($auth_users)); |
---|
201 | $class = ($i % 2)? 'row1':'row2'; $i++; |
---|
202 | |
---|
203 | $template->assign_block_vars('statrow',array( |
---|
204 | 'VALUE'=>$value, |
---|
205 | 'PAGES'=>$row['p'], |
---|
206 | 'VISITORS'=>$nb_visitors, |
---|
207 | 'IMAGES'=>$pictures['p'], |
---|
208 | |
---|
209 | 'T_CLASS'=>$class |
---|
210 | )); |
---|
211 | } |
---|
212 | $nb_visitors = mysql_num_rows( $result ); |
---|
213 | $days = array(); |
---|
214 | $max_nb_visitors = 0; |
---|
215 | $max_pages_seen = 0; |
---|
216 | |
---|
217 | //----------------------------------------------------------- stats / jour |
---|
218 | |
---|
219 | if ( isset( $_GET['month'] ) && isset( $_GET['month'] ) && isset( $_GET['day'] ) ) |
---|
220 | { if ($_GET['day'] <10) {$current_day='0'; |
---|
221 | $current_day.= $_GET['day'];} |
---|
222 | else {$current_day = $_GET['day'];} |
---|
223 | if ($_GET['month'] <10) {$current_month='0'; |
---|
224 | $current_month.= $_GET['month'];} |
---|
225 | else {$current_month = $_GET['month'];} |
---|
226 | $current_year = $_GET['year']; |
---|
227 | } |
---|
228 | |
---|
229 | else |
---|
230 | { $current_date = GetDate(); |
---|
231 | if ($current_date['mday'] <10) {$current_day='0'; |
---|
232 | $current_day.= $current_date['mday'];} |
---|
233 | else {$current_day = $current_date['mday'];} |
---|
234 | if ($current_date['mon'] <10) {$current_month='0'; |
---|
235 | $current_month.= $current_date['mon'];} |
---|
236 | else {$current_month = $current_date['mon'];} |
---|
237 | $current_year = $current_date['year']; |
---|
238 | } |
---|
239 | |
---|
240 | // Set WHERE clause |
---|
241 | $where = ' WHERE DATE_FORMAT(date,\'%Y-%m-%d\') = \''.$current_year."-".$current_month."-".$current_day.'\''; |
---|
242 | |
---|
243 | // Set LIMIT clause |
---|
244 | $limit = ' LIMIT '; |
---|
245 | $page['start'] = 0; |
---|
246 | if (isset($_GET['start']) and is_numeric($_GET['start'])) $page['start'] = abs($_GET['start']); |
---|
247 | $limit .= $page['start']; |
---|
248 | $limit .= ','.$conf['nb_logs_page']; |
---|
249 | |
---|
250 | $query = ' |
---|
251 | SELECT DATE_FORMAT(date,\'%H:%i:%s\') AS hour, |
---|
252 | login, |
---|
253 | IP, |
---|
254 | category, |
---|
255 | file, |
---|
256 | picture |
---|
257 | FROM '.HISTORY_TABLE. |
---|
258 | $where.' |
---|
259 | ORDER BY date DESC'. |
---|
260 | $limit. |
---|
261 | ';'; |
---|
262 | |
---|
263 | |
---|
264 | $result = pwg_query( $query ); |
---|
265 | |
---|
266 | $i=0; |
---|
267 | |
---|
268 | while ( $row = mysql_fetch_array( $result ) ) |
---|
269 | { |
---|
270 | $class = ($i % 2)? 'row1':'row2'; $i++; |
---|
271 | $template->assign_block_vars('detail',array( |
---|
272 | 'HOUR'=>$row['hour'], |
---|
273 | 'LOGIN'=>$row['login'], |
---|
274 | 'IP'=>$row['IP'], |
---|
275 | 'CATEGORY'=>$row['category'], |
---|
276 | 'FILE'=>$row['file'], |
---|
277 | 'PICTURE'=>$row['picture'], |
---|
278 | 'T_CLASS'=>$class |
---|
279 | )); |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | // Get total number of logs |
---|
284 | $query = ' |
---|
285 | SELECT COUNT(date) as nb_logs |
---|
286 | FROM '.HISTORY_TABLE. |
---|
287 | $where.' |
---|
288 | ;'; |
---|
289 | |
---|
290 | $result = pwg_query($query); |
---|
291 | $row = mysql_fetch_array($result); |
---|
292 | $page['nb_logs']=$row['nb_logs']; |
---|
293 | |
---|
294 | //display nav bar |
---|
295 | $url = $_SERVER['PHP_SELF'].'?page=stats'; |
---|
296 | $url.= isset($_GET['year']) ? '&year='.$_GET['year'] : ''; |
---|
297 | $url.= isset($_GET['month']) ? '&month='.$_GET['month'] : ''; |
---|
298 | $url.= isset($_GET['day']) ? '&day='.$_GET['day'] : ''; |
---|
299 | |
---|
300 | $page['navigation_bar'] = |
---|
301 | create_navigation_bar( |
---|
302 | $url, |
---|
303 | $page['nb_logs'], |
---|
304 | $page['start'], |
---|
305 | $conf['nb_logs_page'] |
---|
306 | ); |
---|
307 | |
---|
308 | $template->assign_block_vars( |
---|
309 | 'navigation', |
---|
310 | array( |
---|
311 | 'NAV_BAR' => $page['navigation_bar'] |
---|
312 | ) |
---|
313 | ); |
---|
314 | |
---|
315 | //----------------------------------------------------------- sending html code |
---|
316 | $template->assign_var_from_handle('ADMIN_CONTENT', 'stats'); |
---|
317 | ?> |
---|
318 | |
---|