source: trunk/admin/stats.php @ 587

Last change on this file since 587 was 587, checked in by z0rglub, 19 years ago
  • function mysql_query replaced by pwg_query : the same with debugging features
  • by default, DEBUG is set to 0 (off)
  • 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-10-30 15:42:29 +0000 (Sat, 30 Oct 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 587 $
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 = "SELECT DISTINCT COUNT(*) as p,
51  MONTH(date) as m,
52  YEAR(date) as y
53  FROM phpwg_history
54  GROUP BY DATE_FORMAT(date,'%Y-%m') DESC;";
55$result = pwg_query( $query );
56$i=0;
57while ( $row = mysql_fetch_array( $result ) )
58{
59  $current_month = $row['y']."-";
60  if ($row['m'] <10) {$current_month.='0';}
61  $current_month .= $row['m'];
62  // Number of pictures seen
63  $query = "SELECT COUNT(*) as p,
64    FILE as f
65    FROM phpwg_history
66    WHERE DATE_FORMAT(date,'%Y-%m') = '$current_month'
67        AND FILE = 'picture'
68        GROUP BY FILE;";
69  $pictures = mysql_fetch_array(pwg_query( $query ));
70 
71  // Number of different visitors
72  $query = "SELECT COUNT(*) as p, login
73    FROM phpwg_history
74    WHERE DATE_FORMAT(date,'%Y-%m') = '$current_month'
75        GROUP BY login, IP;";
76  $user_results = pwg_query( $query );
77  $nb_visitors = 0;
78  $auth_users = array();
79  while ( $user_array = mysql_fetch_array( $user_results ) )
80  {
81    if ($user_array['login'] == 'guest') 
82          $nb_visitors += 1;
83        else
84          array_push($auth_users, $user_array['login']);
85  }
86  $nb_visitors +=count(array_unique($auth_users));
87  $class = ($i % 2)? 'row1':'row2'; $i++;
88 
89  $template->assign_block_vars('month',array(
90    'MONTH'=>$lang['month'][$row['m']].' '.$row['y'],
91        'PAGES'=>$row['p'],
92        'VISITORS'=>$nb_visitors,
93        'IMAGES'=>$pictures['p'],
94       
95        'T_CLASS'=>$class
96    ));
97}
98$nb_visitors = mysql_num_rows( $result );
99$days = array();
100$max_nb_visitors = 0;
101$max_pages_seen = 0;
102
103$starttime = mktime(  0, 0, 0,date('n'),date('j'),date('Y') );
104$endtime   = mktime( 23,59,59,date('n'),date('j'),date('Y') );
105//for ( $i = 0; $i <= MAX_DAYS; $i++ )
106{
107  /*
108  // log lines for this day
109  $query = 'SELECT date,login,IP,category,file,picture';
110  $query.= ' FROM '.PREFIX_TABLE.'history';
111  $query.= ' WHERE date > '.$starttime;
112  $query.= ' AND date < '.$endtime;
113  $query.= ' ORDER BY date DESC';
114  $query.= ';';
115  $result = pwg_query( $query );
116  $nb_pages_seen = mysql_num_rows( $result );
117  $day['nb_pages_seen'] = $nb_pages_seen;
118  if ( $nb_pages_seen > $max_pages_seen ) $max_pages_seen = $nb_pages_seen;
119  $vtp->setVar( $sub, 'day.nb_pages', $nb_pages_seen );
120  if ( in_array( $i, $page['expand_days'] ) )
121  {
122    while ( $row = mysql_fetch_array( $result ) )
123    {
124      $vtp->addSession( $sub, 'line' );
125      $vtp->setVar( $sub, 'line.date', date( 'G:i:s', $row['date'] ) );
126      $vtp->setVar( $sub, 'line.login', $row['login'] );
127      $vtp->setVar( $sub, 'line.IP', $row['IP'] );
128      $vtp->setVar( $sub, 'line.category', $row['category'] );
129      $vtp->setVar( $sub, 'line.file', $row['file'] );
130      $vtp->setVar( $sub, 'line.picture', $row['picture'] );
131      $vtp->closeSession( $sub, 'line' );
132    }
133  }
134  $starttime-= 24*60*60;
135  $endtime  -= 24*60*60;
136  $vtp->closeSession( $sub, 'day' );
137  array_push( $days, $day );*/
138}
139//------------------------------------------------------------ pages seen graph
140foreach ( $days as $day ) {
141  /*$vtp->addSession( $sub, 'pages_day' );
142  if ( $max_pages_seen > 0 )
143    $width = floor( ( $day['nb_pages_seen']*$max_pixels ) / $max_pages_seen );
144  else $width = 0;
145  $vtp->setVar( $sub, 'pages_day.date', $day['date'] );
146  $vtp->setVar( $sub, 'pages_day.width', $width );
147  $vtp->setVar( $sub, 'pages_day.nb_pages', $day['nb_pages_seen'] );
148  $vtp->closeSession( $sub, 'pages_day' );*/
149}
150//-------------------------------------------------------------- visitors grpah
151foreach ( $days as $day ) {
152  /*$vtp->addSession( $sub, 'visitors_day' );
153  if ( $max_nb_visitors > 0 )
154    $width = floor( ( $day['nb_visitors'] * $max_pixels ) / $max_nb_visitors );
155  else $width = 0;
156  $vtp->setVar( $sub, 'visitors_day.date', $day['date'] );
157  $vtp->setVar( $sub, 'visitors_day.width', $width );
158  $vtp->setVar( $sub, 'visitors_day.nb_visitors', $day['nb_visitors'] );
159  $vtp->closeSession( $sub, 'visitors_day' );*/
160}
161//----------------------------------------------------------- sending html code
162$template->assign_var_from_handle('ADMIN_CONTENT', 'stats');
163?>
Note: See TracBrowser for help on using the repository browser.