source: tags/release-1_3_2/admin/stats.php @ 27538

Last change on this file since 27538 was 280, checked in by gweltas, 20 years ago

Correction of php warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1<?php
2/***************************************************************************
3 *                                 stats.php                               *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: stats.php 280 2004-01-15 17:06:45Z gweltas $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19include_once( './include/isadmin.inc.php' );
20$max_pixels = 500;
21//------------------------------------------------------------ comment deletion
22if ( isset( $_GET['del'] ) and is_numeric( $_GET['del'] ) )
23{
24  $query = 'DELETE FROM '.PREFIX_TABLE.'comments';
25  $query.= ' WHERE id = '.$_GET['del'];
26  $query.= ';';
27  mysql_query( $query );
28}
29//--------------------------------------------------------- history table empty
30if ( isset( $_GET['act'] ) and $_GET['act'] == 'empty' )
31{
32  $query = 'DELETE FROM '.PREFIX_TABLE.'history';
33  $query.= ';';
34  mysql_query( $query );
35}
36//----------------------------------------------------- template initialization
37$sub = $vtp->Open( '../template/'.$user['template'].'/admin/stats.vtp' );
38$tpl = array( 'stats_last_days','date','login',
39              'IP','file','picture','category','stats_pages_seen',
40              'stats_visitors','stats_empty', 'stats_pages_seen_graph_title',
41              'stats_visitors_graph_title');
42templatize_array( $tpl, 'lang', $sub );
43$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
44//--------------------------------------------------- number of days to display
45if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
46else                               define( 'MAX_DAYS', 0 );
47
48foreach ( $conf['last_days'] as $option ) {
49  $vtp->addSession( $sub, 'last_day_option' );
50  $vtp->setVar( $sub, 'last_day_option.option', $option );
51  $url = './admin.php?page=stats';
52  if (isset($_GET['expand']))
53          $url .='&amp;expand='.$_GET['expand'];
54  $url.= '&amp;last_days='.($option - 1);
55  $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) );
56  if ( $option == MAX_DAYS + 1 )
57  {
58    $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;');
59  }
60  $vtp->closeSession( $sub, 'last_day_option' );
61}
62//---------------------------------------------------------------- log  history
63// empty link
64$url = './admin.php?page=stats';
65if (isset($_GET['last_days']))
66        $url .='&amp;last_days='.$_GET['last_days'];
67// expand array management
68$expand_days = array();
69if (isset($_GET['expand']))
70{
71        $url.= '&amp;expand='.$_GET['expand'];
72        $expand_days = explode( ',', $_GET['expand'] );
73}
74$url.= '&amp;act=empty';
75$vtp->setVar( $sub, 'emply_url', add_session_id( $url ) );
76$page['expand_days'] = array();
77foreach ( $expand_days as $expand_day ) {
78  if ( is_numeric( $expand_day ) )
79  {
80    array_push( $page['expand_days'], $expand_day );
81  }
82}
83
84$days = array();
85$max_nb_visitors = 0;
86$max_pages_seen = 0;
87
88$starttime = mktime(  0, 0, 0,date('n'),date('j'),date('Y') );
89$endtime   = mktime( 23,59,59,date('n'),date('j'),date('Y') );
90for ( $i = 0; $i <= MAX_DAYS; $i++ )
91{
92  $day = array();
93  $vtp->addSession( $sub, 'day' );
94  // link to open the day to see details
95  $local_expand = $page['expand_days'];
96  if ( in_array( $i, $page['expand_days'] ) )
97  {
98    $vtp->addSession( $sub, 'expanded' );
99    $vtp->closeSession( $sub, 'expanded' );
100    $vtp->setVar( $sub, 'day.open_or_close', $lang['close'] );
101    $local_expand = array_remove( $local_expand, $i );
102  }
103  else
104  {
105    $vtp->addSession( $sub, 'collapsed' );
106    $vtp->closeSession( $sub, 'collapsed' );
107    $vtp->setVar( $sub, 'day.open_or_close', $lang['open'] );
108    array_push( $local_expand, $i );
109  }
110  $url = './admin.php?page=stats';
111  if (isset($_GET['last_days']))
112        $url.= '&amp;last_days='.$_GET['last_days'];
113  $url.= '&amp;expand='.implode( ',', $local_expand );
114  $vtp->setVar( $sub, 'day.url', add_session_id( $url ) );
115  // date displayed like this (in English ) :
116  //                     Sunday 15 June 2003
117  $date = $lang['day'][date( 'w', $starttime )];   // Sunday
118  $date.= date( ' j ', $starttime );               // 15
119  $date.= $lang['month'][date( 'n', $starttime )]; // June
120  $date.= date( ' Y', $starttime );                // 2003
121  $day['date'] = $date;
122  $vtp->setVar( $sub, 'day.name', $date );
123  // number of visitors for this day
124  $query = 'SELECT DISTINCT(IP) as nb_visitors';
125  $query.= ' FROM '.PREFIX_TABLE.'history';
126  $query.= ' WHERE date > '.$starttime;
127  $query.= ' AND date < '.$endtime;
128  $query.= ';';
129  $result = mysql_query( $query );
130  $nb_visitors = mysql_num_rows( $result );
131  $day['nb_visitors'] = $nb_visitors;
132  if ( $nb_visitors > $max_nb_visitors ) $max_nb_visitors = $nb_visitors;
133  $vtp->setVar( $sub, 'day.nb_visitors', $nb_visitors );
134  // log lines for this day
135  $query = 'SELECT date,login,IP,category,file,picture';
136  $query.= ' FROM '.PREFIX_TABLE.'history';
137  $query.= ' WHERE date > '.$starttime;
138  $query.= ' AND date < '.$endtime;
139  $query.= ' ORDER BY date DESC';
140  $query.= ';';
141  $result = mysql_query( $query );
142  $nb_pages_seen = mysql_num_rows( $result );
143  $day['nb_pages_seen'] = $nb_pages_seen;
144  if ( $nb_pages_seen > $max_pages_seen ) $max_pages_seen = $nb_pages_seen;
145  $vtp->setVar( $sub, 'day.nb_pages', $nb_pages_seen );
146  if ( in_array( $i, $page['expand_days'] ) )
147  {
148    while ( $row = mysql_fetch_array( $result ) )
149    {
150      $vtp->addSession( $sub, 'line' );
151      $vtp->setVar( $sub, 'line.date', date( 'G:i:s', $row['date'] ) );
152      $vtp->setVar( $sub, 'line.login', $row['login'] );
153      $vtp->setVar( $sub, 'line.IP', $row['IP'] );
154      $vtp->setVar( $sub, 'line.category', $row['category'] );
155      $vtp->setVar( $sub, 'line.file', $row['file'] );
156      $vtp->setVar( $sub, 'line.picture', $row['picture'] );
157      $vtp->closeSession( $sub, 'line' );
158    }
159  }
160  $starttime-= 24*60*60;
161  $endtime  -= 24*60*60;
162  $vtp->closeSession( $sub, 'day' );
163  array_push( $days, $day );
164}
165//------------------------------------------------------------ pages seen graph
166foreach ( $days as $day ) {
167  $vtp->addSession( $sub, 'pages_day' );
168  if ( $max_pages_seen > 0 )
169    $width = floor( ( $day['nb_pages_seen']*$max_pixels ) / $max_pages_seen );
170  else $width = 0;
171  $vtp->setVar( $sub, 'pages_day.date', $day['date'] );
172  $vtp->setVar( $sub, 'pages_day.width', $width );
173  $vtp->setVar( $sub, 'pages_day.nb_pages', $day['nb_pages_seen'] );
174  $vtp->closeSession( $sub, 'pages_day' );
175}
176//-------------------------------------------------------------- visitors grpah
177foreach ( $days as $day ) {
178  $vtp->addSession( $sub, 'visitors_day' );
179  if ( $max_nb_visitors > 0 )
180    $width = floor( ( $day['nb_visitors'] * $max_pixels ) / $max_nb_visitors );
181  else $width = 0;
182  $vtp->setVar( $sub, 'visitors_day.date', $day['date'] );
183  $vtp->setVar( $sub, 'visitors_day.width', $width );
184  $vtp->setVar( $sub, 'visitors_day.nb_visitors', $day['nb_visitors'] );
185  $vtp->closeSession( $sub, 'visitors_day' );
186}
187//----------------------------------------------------------- sending html code
188$vtp->Parse( $handle , 'sub', $sub );
189?>
Note: See TracBrowser for help on using the repository browser.