source: trunk/admin/stats.php @ 1006

Last change on this file since 1006 was 1004, checked in by nikrou, 19 years ago

Improve security of sessions:

  • use only cookies to store session id on client side
  • use default php session system with database handler to store sessions on server side
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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: 2006-01-15 13:45:42 +0000 (Sun, 15 Jan 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1004 $
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 .= 'daily_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 = $url_back;
66  $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>';
67  $title_day = $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 = $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'=>$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   
133    $week_day =
134      $lang['day'][date('w', mktime(12,0,0,$row['m'],$row['d'],$row['y']))];
135
136    $url =
137      PHPWG_ROOT_PATH.'admin.php'
138      .'?page=stats'
139      .'&amp;year='.$row['y']
140      .'&amp;month='.$row['m']
141      .'&amp;day='.$row['d']
142      ;
143
144    $value = '<a href="'.$url.'">';
145    $value.= $row['d'].' ('.$week_day.')';
146    $value.= "</a>";
147  }
148  else
149  {
150    $current_month = $row['y']."-";
151    if ($row['m'] <10) {$current_month.='0';}
152    $current_month .= $row['m'];
153   
154    $where_clause = "DATE_FORMAT(date,'%Y-%m') = '".$current_month."'";
155
156    $url =
157      PHPWG_ROOT_PATH.'admin.php'
158      .'?page=stats'
159      .'&amp;year='.$row['y']
160      .'&amp;month='.$row['m']
161      ;
162   
163    $value = '<a href="'.$url.'">';
164    $value.= $lang['month'][$row['m']].' '.$row['y'];
165    $value.= "</a>";
166  }
167 
168  // Number of pictures seen
169  $query = '
170SELECT COUNT(*) as p
171    FROM '.HISTORY_TABLE.'
172    WHERE '.$where_clause.'
173    AND FILE = \'picture\'
174;';
175  $pictures = mysql_fetch_array(pwg_query( $query ));
176 
177  // Number of different visitors
178  $query = '
179SELECT COUNT(*) as p, login
180  FROM '.HISTORY_TABLE.'
181  WHERE '.$where_clause.'
182  GROUP BY login, IP
183;';
184  $user_results = pwg_query( $query );
185  $nb_visitors = 0;
186  $auth_users = array();
187  while ( $user_array = mysql_fetch_array( $user_results ) )
188  {
189    if ($user_array['login'] == 'guest') 
190          $nb_visitors += 1;
191        else
192          array_push($auth_users, $user_array['login']);
193  }
194  $nb_visitors +=count(array_unique($auth_users));
195  $class = ($i % 2)? 'row1':'row2'; $i++;
196 
197  $template->assign_block_vars('statrow',array(
198      'VALUE'=>$value,
199        'PAGES'=>$row['p'],
200        'VISITORS'=>$nb_visitors,
201        'IMAGES'=>$pictures['p'],
202       
203        'T_CLASS'=>$class
204    ));
205}
206$nb_visitors = mysql_num_rows( $result );
207$days = array();
208$max_nb_visitors = 0;
209$max_pages_seen = 0;
210
211//----------------------------------------------------------- stats / jour
212
213if ( isset( $_GET['month'] ) && isset( $_GET['month'] ) && isset( $_GET['day'] ) )
214{  if ($_GET['day'] <10) {$current_day='0';
215        $current_day.= $_GET['day'];}
216  else {$current_day = $_GET['day'];}
217  if ($_GET['month'] <10) {$current_month='0';
218        $current_month.= $_GET['month'];}
219  else {$current_month = $_GET['month'];}
220  $current_year = $_GET['year'];
221}
222
223else
224{  $current_date = GetDate();
225  if ($current_date['mday'] <10) {$current_day='0';
226        $current_day.= $current_date['mday'];}
227  else {$current_day = $current_date['mday'];}
228  if ($current_date['mon'] <10) {$current_month='0';
229        $current_month.= $current_date['mon'];}
230  else {$current_month = $current_date['mon'];}
231  $current_year = $current_date['year']; 
232}
233
234// Set WHERE clause
235$where = ' WHERE DATE_FORMAT(date,\'%Y-%m-%d\') = \''.$current_year."-".$current_month."-".$current_day.'\'';
236 
237// Set LIMIT clause
238$limit = ' LIMIT ';
239$page['start'] = 0;
240if (isset($_GET['start']) and is_numeric($_GET['start'])) $page['start'] = abs($_GET['start']);
241$limit .= $page['start'];
242$limit .= ','.$conf['nb_logs_page'];
243
244$query = '
245SELECT DATE_FORMAT(date,\'%H:%i:%s\') AS hour,
246     login,
247     IP,
248     category,
249     file,
250     picture
251  FROM '.HISTORY_TABLE.
252  $where.'
253  ORDER BY date DESC'.
254  $limit.
255  ';';
256
257
258$result = pwg_query( $query );
259
260$i=0;
261 
262while ( $row = mysql_fetch_array( $result ) )
263{
264  $class = ($i % 2)? 'row1':'row2'; $i++;
265    $template->assign_block_vars('detail',array(
266    'HOUR'=>$row['hour'],
267    'LOGIN'=>$row['login'],
268    'IP'=>$row['IP'],
269    'CATEGORY'=>$row['category'],
270    'FILE'=>$row['file'],
271    'PICTURE'=>$row['picture'],
272    'T_CLASS'=>$class
273  ));
274  }
275
276
277// Get total number of logs
278$query = '
279    SELECT COUNT(date) as nb_logs
280     FROM '.HISTORY_TABLE.
281  $where.'
282    ;';
283
284  $result = pwg_query($query);
285  $row = mysql_fetch_array($result);
286  $page['nb_logs']=$row['nb_logs'];
287
288  //display nav bar
289$url = $_SERVER['PHP_SELF'].'?page=stats';
290$url.= isset($_GET['year']) ? '&amp;year='.$_GET['year'] : '';
291$url.= isset($_GET['month']) ? '&amp;month='.$_GET['month'] : '';
292$url.= isset($_GET['day']) ? '&amp;day='.$_GET['day'] : '';
293
294$page['navigation_bar'] =
295create_navigation_bar(
296  $url,
297  $page['nb_logs'],
298  $page['start'],
299  $conf['nb_logs_page'],
300  'admin'
301  );
302
303$template->assign_block_vars(
304  'navigation',
305  array(
306    'NAV_BAR' => $page['navigation_bar']
307    )
308  );
309
310//----------------------------------------------------------- sending html code
311$template->assign_var_from_handle('ADMIN_CONTENT', 'stats');
312?>
313
Note: See TracBrowser for help on using the repository browser.