source: trunk/admin/stats.php @ 29

Last change on this file since 29 was 29, checked in by z0rglub, 21 years ago

template as user_template for displaying pictures in the template

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