source: trunk/admin/stats.php @ 903

Last change on this file since 903 was 894, checked in by volcom, 19 years ago
  • new: history details by month,day
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
Line 
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: 2005-10-17 07:21:30 +0000 (Mon, 17 Oct 2005) $
10// | last modifier : $Author: volcom $
11// | revision      : $Revision: 894 $
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// +-----------------------------------------------------------------------+
27if( !defined("PHPWG_ROOT_PATH") )
28{
29        die ("Hacking attempt!");
30}
31include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
32
33$url_img = PHPWG_ROOT_PATH.'admin/images/'; 
34$nls_value_title = $lang['w_month'];
35$group_clause = "DATE_FORMAT(date,'%Y-%m') DESC";
36$where_clause = "1";
37
38
39if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) )
40{
41  $url_img .= 'dayly_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month'].'&day='.$_GET['day'];
42  $nls_value_title = $lang['w_day'];
43  $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC";
44  $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )";
45}
46elseif (isset($_GET['month']) && isset($_GET['year']) )
47{
48  $url_img .= 'monthly_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month'];
49  $nls_value_title = $lang['w_day'];
50  $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC";
51  $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )";
52}
53else 
54{
55  $url_img .= 'global_stats.img.php';
56}
57
58
59//----------------------------------------------------- template initialization
60if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) )
61{
62  $date_of_day=$_GET['day'].' '.$lang['month'][$_GET['month']].' '.$_GET['year'];
63  $title_page=$lang['stats_day_title'].' du '.$date_of_day;
64  $url_back = PHPWG_ROOT_PATH."admin.php?page=stats";
65  $url_back = add_session_id($url_back);
66  $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>';
67  $title_day=$lang['stats_day_details_title']." ".$date_of_day;
68}
69elseif ( isset($_GET['month']) && isset($_GET['year']) )
70{
71  $date_of_day=$lang['month'][$_GET['month']].' '.$_GET['year'];
72  $title_page=$lang['stats_month_title'].' : '.$date_of_day;
73  $url_back = PHPWG_ROOT_PATH."admin.php?page=stats";
74  $url_back = add_session_id($url_back);
75  $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>';
76  $title_day=$lang['today'];
77}
78else
79{
80  $date_of_day='';
81  $title_page=$lang['stats_title'];
82  $title_details=$lang['stats_month_title'];
83  $title_day=$lang['today'];
84}
85
86
87$template->set_filenames( array('stats'=>'admin/stats.tpl') );
88
89$template->assign_vars(array(
90  'L_VALUE'=>$nls_value_title,
91  'L_PAGES_SEEN'=>$lang['stats_pages_seen'],
92  'L_VISITORS'=>$lang['visitors'],
93  'L_PICTURES'=>$lang['pictures'],
94  'L_STAT_TITLE'=>$lang['stats_title'],
95  'L_STAT_MONTH_TITLE'=>$lang['stats_month_title'],
96  'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'],
97  'L_STAT_TITLE'=>$title_page,
98  'L_STAT_DETAIL_TITLE'=>$title_details,
99  'L_DATE_TITLE'=>$title_day,
100  'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'],
101  'L_STAT_HOUR'=>$lang['stats_hour'],
102  'L_STAT_LOGIN'=>$lang['stats_login'],
103  'L_STAT_ADDR'=>$lang['stats_addr'],
104  'L_STAT_CATEGORY'=>$lang['stats_category'],
105  'L_STAT_FILE'=>$lang['stats_file'],
106  'L_STAT_PICTURE'=>$lang['stats_picture'],
107 
108  'IMG_REPORT'=>add_session_id($url_img)
109  ));
110
111//---------------------------------------------------------------- log  history
112$query = '
113SELECT DISTINCT COUNT(*) as p,
114       DAYOFMONTH(date) as d,
115       MONTH(date) as m,
116       YEAR(date) as y
117  FROM '.HISTORY_TABLE.'
118  WHERE '.$where_clause.'
119  GROUP BY '.$group_clause.';';
120
121$result = pwg_query( $query );
122$i=0;
123while ( $row = mysql_fetch_array( $result ) )
124{
125  $where_clause="";
126  $value = '';
127  if (isset($_GET['month']) && isset($_GET['year']) )
128  {
129    $where_clause = 'DAYOFMONTH(date) = '.$row['d'].'
130    AND MONTH(date) = '.$row['m'].'
131    AND YEAR(date) = '.$row['y'];
132    $week_day = $lang['day'][date('w', mktime(12,0,0,$row['m'],$row['d'],$row['y']))];
133    $value = $row['d'].' ('.$week_day.')';
134  }
135  else
136  {
137    $current_month = $row['y']."-";
138    if ($row['m'] <10) {$current_month.='0';}
139    $current_month .= $row['m'];
140   
141    $where_clause = "DATE_FORMAT(date,'%Y-%m') = '".$current_month."'";
142
143    $url =
144      PHPWG_ROOT_PATH.'admin.php'
145      .'?page=stats'
146      .'&amp;year='.$row['y']
147      .'&amp;month='.$row['m']
148      ;
149   
150    $value = '<a href="'.add_session_id($url).'">';
151    $value.= $lang['month'][$row['m']].' '.$row['y'];
152    $value.= "</a>";
153  }
154 
155  // Number of pictures seen
156  $query = '
157SELECT COUNT(*) as p
158    FROM '.HISTORY_TABLE.'
159    WHERE '.$where_clause.'
160    AND FILE = \'picture\'
161;';
162  $pictures = mysql_fetch_array(pwg_query( $query ));
163 
164  // Number of different visitors
165  $query = '
166SELECT COUNT(*) as p, login
167  FROM '.HISTORY_TABLE.'
168  WHERE '.$where_clause.'
169  GROUP BY login, IP
170;';
171  $user_results = pwg_query( $query );
172  $nb_visitors = 0;
173  $auth_users = array();
174  while ( $user_array = mysql_fetch_array( $user_results ) )
175  {
176    if ($user_array['login'] == 'guest') 
177          $nb_visitors += 1;
178        else
179          array_push($auth_users, $user_array['login']);
180  }
181  $nb_visitors +=count(array_unique($auth_users));
182  $class = ($i % 2)? 'row1':'row2'; $i++;
183 
184  $template->assign_block_vars('statrow',array(
185      'VALUE'=>$value,
186        'PAGES'=>$row['p'],
187        'VISITORS'=>$nb_visitors,
188        'IMAGES'=>$pictures['p'],
189       
190        'T_CLASS'=>$class
191    ));
192}
193$nb_visitors = mysql_num_rows( $result );
194$days = array();
195$max_nb_visitors = 0;
196$max_pages_seen = 0;
197
198//----------------------------------------------------------- stats / jour
199
200if ( isset( $_GET['month'] ) && isset( $_GET['month'] ) && isset( $_GET['day'] ) )
201{  if ($_GET['day'] <10) {$current_day='0';
202        $current_day.= $_GET['day'];}
203  else {$current_day = $_GET['day'];}
204  if ($_GET['month'] <10) {$current_month='0';
205        $current_month.= $_GET['month'];}
206  else {$current_month = $_GET['month'];}
207  $current_year = $_GET['year'];
208}
209
210else
211{  $current_date = GetDate();
212  if ($current_date['mday'] <10) {$current_day='0';
213        $current_day.= $current_date['mday'];}
214  else {$current_day = $current_date['mday'];}
215  if ($current_date['mon'] <10) {$current_month='0';
216        $current_month.= $current_date['mon'];}
217  else {$current_month = $current_date['mon'];}
218  $current_year = $current_date['year']; 
219}
220
221// Set WHERE clause
222$where = ' WHERE DATE_FORMAT(date,\'%Y-%m-%d\') = \''.$current_year."-".$current_month."-".$current_day.'\'';
223 
224// Set LIMIT clause
225$limit = ' LIMIT ';
226$page['start'] = 0;
227if (isset($_GET['start']) and is_numeric($_GET['start'])) $page['start'] = abs($_GET['start']);
228$limit .= $page['start'];
229$limit .= ','.$conf['nb_logs_page'];
230
231$query = '
232SELECT DATE_FORMAT(date,\'%H:%i:%s\') AS hour,
233     login,
234     IP,
235     category,
236     file,
237     picture
238  FROM '.HISTORY_TABLE.
239  $where.'
240  ORDER BY date DESC'.
241  $limit.
242  ';';
243
244
245$result = pwg_query( $query );
246
247$i=0;
248 
249while ( $row = mysql_fetch_array( $result ) )
250{
251  $class = ($i % 2)? 'row1':'row2'; $i++;
252    $template->assign_block_vars('detail',array(
253    'HOUR'=>$row['hour'],
254    'LOGIN'=>$row['login'],
255    'IP'=>$row['IP'],
256    'CATEGORY'=>$row['category'],
257    'FILE'=>$row['file'],
258    'PICTURE'=>$row['picture'],
259    'T_CLASS'=>$class
260  ));
261  }
262
263
264// Get total number of logs
265$query = '
266    SELECT COUNT(date) as nb_logs
267     FROM '.HISTORY_TABLE.
268  $where.'
269    ;';
270
271  $result = pwg_query($query);
272  $row = mysql_fetch_array($result);
273  $page['nb_logs']=$row['nb_logs'];
274
275  //display nav bar
276  $url = $_SERVER['PHP_SELF'].'?page=stats&year='.$_GET['year'];
277  $url .= '&month='.$_GET['month'].'&day='.$_GET['day'];
278  $page['navigation_bar'] =
279  create_navigation_bar( $url, $page['nb_logs'],$page['start'],$conf['nb_logs_page'], 'admin' );
280$template->assign_block_vars('navigation',
281    array('NAV_BAR' => $page['navigation_bar'])
282    );
283
284//----------------------------------------------------------- sending html code
285$template->assign_var_from_handle('ADMIN_CONTENT', 'stats');
286?>
287
Note: See TracBrowser for help on using the repository browser.