source: trunk/admin/stats.php @ 591

Last change on this file since 591 was 591, checked in by z0rglub, 19 years ago

in queries table names use the constant and not hard coded table name

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                               stats.php                               |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-04 23:26:22 +0000 (Thu, 04 Nov 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 591 $
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_global_report = PHPWG_ROOT_PATH.'admin/images/global_stats.img.php';
34//----------------------------------------------------- template initialization
35$template->set_filenames( array('stats'=>'admin/stats.tpl') );
36
37$template->assign_vars(array(
38  'L_MONTH'=>$lang['w_month'],
39  'L_PAGES_SEEN'=>$lang['stats_pages_seen'],
40  'L_VISITORS'=>$lang['visitors'],
41  'L_PICTURES'=>$lang['pictures'],
42  'L_STAT_TITLE'=>$lang['stats_title'],
43  'L_STAT_MONTH_TITLE'=>$lang['stats_month_title'],
44  'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'],
45 
46  'IMG_MONTHLY_REPORT'=>add_session_id($url_img_global_report)
47  ));
48
49//---------------------------------------------------------------- log  history
50$query = '
51SELECT DISTINCT COUNT(*) as p,
52       MONTH(date) as m,
53       YEAR(date) as y
54  FROM '.HISTORY_TABLE.'
55  GROUP BY DATE_FORMAT(date,\'%Y-%m\') DESC
56;';
57$result = pwg_query( $query );
58$i=0;
59while ( $row = mysql_fetch_array( $result ) )
60{
61  $current_month = $row['y']."-";
62  if ($row['m'] <10) {$current_month.='0';}
63  $current_month .= $row['m'];
64  // Number of pictures seen
65  $query = '
66SELECT COUNT(*) as p,
67       FILE as f
68  FROM '.HISTORY_TABLE.'
69  WHERE DATE_FORMAT(date,\'%Y-%m\') = \''.$current_month.'\'
70    AND FILE = \'picture\'
71  GROUP BY FILE
72;';
73  $pictures = mysql_fetch_array(pwg_query( $query ));
74 
75  // Number of different visitors
76  $query = '
77SELECT COUNT(*) as p, login
78  FROM '.HISTORY_TABLE.'
79  WHERE DATE_FORMAT(date,\'%Y-%m\') = \''.$current_month.'\'
80  GROUP BY login, IP
81;';
82  $user_results = pwg_query( $query );
83  $nb_visitors = 0;
84  $auth_users = array();
85  while ( $user_array = mysql_fetch_array( $user_results ) )
86  {
87    if ($user_array['login'] == 'guest') 
88          $nb_visitors += 1;
89        else
90          array_push($auth_users, $user_array['login']);
91  }
92  $nb_visitors +=count(array_unique($auth_users));
93  $class = ($i % 2)? 'row1':'row2'; $i++;
94 
95  $template->assign_block_vars('month',array(
96    'MONTH'=>$lang['month'][$row['m']].' '.$row['y'],
97        'PAGES'=>$row['p'],
98        'VISITORS'=>$nb_visitors,
99        'IMAGES'=>$pictures['p'],
100       
101        'T_CLASS'=>$class
102    ));
103}
104$nb_visitors = mysql_num_rows( $result );
105$days = array();
106$max_nb_visitors = 0;
107$max_pages_seen = 0;
108
109$starttime = mktime(  0, 0, 0,date('n'),date('j'),date('Y') );
110$endtime   = mktime( 23,59,59,date('n'),date('j'),date('Y') );
111//for ( $i = 0; $i <= MAX_DAYS; $i++ )
112{
113  /*
114  // log lines for this day
115  $query = 'SELECT date,login,IP,category,file,picture';
116  $query.= ' FROM '.PREFIX_TABLE.'history';
117  $query.= ' WHERE date > '.$starttime;
118  $query.= ' AND date < '.$endtime;
119  $query.= ' ORDER BY date DESC';
120  $query.= ';';
121  $result = pwg_query( $query );
122  $nb_pages_seen = mysql_num_rows( $result );
123  $day['nb_pages_seen'] = $nb_pages_seen;
124  if ( $nb_pages_seen > $max_pages_seen ) $max_pages_seen = $nb_pages_seen;
125  $vtp->setVar( $sub, 'day.nb_pages', $nb_pages_seen );
126  if ( in_array( $i, $page['expand_days'] ) )
127  {
128    while ( $row = mysql_fetch_array( $result ) )
129    {
130      $vtp->addSession( $sub, 'line' );
131      $vtp->setVar( $sub, 'line.date', date( 'G:i:s', $row['date'] ) );
132      $vtp->setVar( $sub, 'line.login', $row['login'] );
133      $vtp->setVar( $sub, 'line.IP', $row['IP'] );
134      $vtp->setVar( $sub, 'line.category', $row['category'] );
135      $vtp->setVar( $sub, 'line.file', $row['file'] );
136      $vtp->setVar( $sub, 'line.picture', $row['picture'] );
137      $vtp->closeSession( $sub, 'line' );
138    }
139  }
140  $starttime-= 24*60*60;
141  $endtime  -= 24*60*60;
142  $vtp->closeSession( $sub, 'day' );
143  array_push( $days, $day );*/
144}
145//------------------------------------------------------------ pages seen graph
146foreach ( $days as $day ) {
147  /*$vtp->addSession( $sub, 'pages_day' );
148  if ( $max_pages_seen > 0 )
149    $width = floor( ( $day['nb_pages_seen']*$max_pixels ) / $max_pages_seen );
150  else $width = 0;
151  $vtp->setVar( $sub, 'pages_day.date', $day['date'] );
152  $vtp->setVar( $sub, 'pages_day.width', $width );
153  $vtp->setVar( $sub, 'pages_day.nb_pages', $day['nb_pages_seen'] );
154  $vtp->closeSession( $sub, 'pages_day' );*/
155}
156//-------------------------------------------------------------- visitors grpah
157foreach ( $days as $day ) {
158  /*$vtp->addSession( $sub, 'visitors_day' );
159  if ( $max_nb_visitors > 0 )
160    $width = floor( ( $day['nb_visitors'] * $max_pixels ) / $max_nb_visitors );
161  else $width = 0;
162  $vtp->setVar( $sub, 'visitors_day.date', $day['date'] );
163  $vtp->setVar( $sub, 'visitors_day.width', $width );
164  $vtp->setVar( $sub, 'visitors_day.nb_visitors', $day['nb_visitors'] );
165  $vtp->closeSession( $sub, 'visitors_day' );*/
166}
167//----------------------------------------------------------- sending html code
168$template->assign_var_from_handle('ADMIN_CONTENT', 'stats');
169?>
Note: See TracBrowser for help on using the repository browser.