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 195 2003-10-11 14:16:21Z z0rglub $ |
---|
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 | ***************************************************************************/ |
---|
19 | include_once( './include/isadmin.inc.php' ); |
---|
20 | $max_pixels = 500; |
---|
21 | //------------------------------------------------------------ comment deletion |
---|
22 | if ( 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 |
---|
30 | if ( 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'); |
---|
42 | templatize_array( $tpl, 'lang', $sub ); |
---|
43 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
44 | //--------------------------------------------------- number of days to display |
---|
45 | if ( isset( $_GET['last_days'] ) ) define( MAX_DAYS, $_GET['last_days'] ); |
---|
46 | else define( MAX_DAYS, 0 ); |
---|
47 | |
---|
48 | foreach ( $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&expand='.$_GET['expand']; |
---|
52 | $url.= '&last_days='.($option - 1); |
---|
53 | $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) ); |
---|
54 | if ( $option == MAX_DAYS + 1 ) |
---|
55 | { |
---|
56 | $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;'); |
---|
57 | } |
---|
58 | $vtp->closeSession( $sub, 'last_day_option' ); |
---|
59 | } |
---|
60 | //---------------------------------------------------------------- log history |
---|
61 | // empty link |
---|
62 | $url = './admin.php?page=stats&last_days='.$_GET['last_days']; |
---|
63 | $url.= '&expand='.$_GET['expand']; |
---|
64 | $url.= '&act=empty'; |
---|
65 | $vtp->setVar( $sub, 'emply_url', add_session_id( $url ) ); |
---|
66 | // expand array management |
---|
67 | $expand_days = explode( ',', $_GET['expand'] ); |
---|
68 | $page['expand_days'] = array(); |
---|
69 | foreach ( $expand_days as $expand_day ) { |
---|
70 | if ( is_numeric( $expand_day ) ) |
---|
71 | { |
---|
72 | array_push( $page['expand_days'], $expand_day ); |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | $days = array(); |
---|
77 | $max_nb_visitors = 0; |
---|
78 | $max_pages_seen = 0; |
---|
79 | |
---|
80 | $starttime = mktime( 0, 0, 0,date('n'),date('j'),date('Y') ); |
---|
81 | $endtime = mktime( 23,59,59,date('n'),date('j'),date('Y') ); |
---|
82 | for ( $i = 0; $i <= MAX_DAYS; $i++ ) |
---|
83 | { |
---|
84 | $day = array(); |
---|
85 | $vtp->addSession( $sub, 'day' ); |
---|
86 | // link to open the day to see details |
---|
87 | $local_expand = $page['expand_days']; |
---|
88 | if ( in_array( $i, $page['expand_days'] ) ) |
---|
89 | { |
---|
90 | $vtp->addSession( $sub, 'expanded' ); |
---|
91 | $vtp->closeSession( $sub, 'expanded' ); |
---|
92 | $vtp->setVar( $sub, 'day.open_or_close', $lang['close'] ); |
---|
93 | $local_expand = array_remove( $local_expand, $i ); |
---|
94 | } |
---|
95 | else |
---|
96 | { |
---|
97 | $vtp->addSession( $sub, 'collapsed' ); |
---|
98 | $vtp->closeSession( $sub, 'collapsed' ); |
---|
99 | $vtp->setVar( $sub, 'day.open_or_close', $lang['open'] ); |
---|
100 | array_push( $local_expand, $i ); |
---|
101 | } |
---|
102 | $url = './admin.php?page=stats&last_days='.$_GET['last_days']; |
---|
103 | $url.= '&expand='.implode( ',', $local_expand ); |
---|
104 | $vtp->setVar( $sub, 'day.url', add_session_id( $url ) ); |
---|
105 | // date displayed like this (in English ) : |
---|
106 | // Sunday 15 June 2003 |
---|
107 | $date = $lang['day'][date( 'w', $starttime )]; // Sunday |
---|
108 | $date.= date( ' j ', $starttime ); // 15 |
---|
109 | $date.= $lang['month'][date( 'n', $starttime )]; // June |
---|
110 | $date.= date( ' Y', $starttime ); // 2003 |
---|
111 | $day['date'] = $date; |
---|
112 | $vtp->setVar( $sub, 'day.name', $date ); |
---|
113 | // number of visitors for this day |
---|
114 | $query = 'SELECT DISTINCT(IP) as nb_visitors'; |
---|
115 | $query.= ' FROM '.PREFIX_TABLE.'history'; |
---|
116 | $query.= ' WHERE date > '.$starttime; |
---|
117 | $query.= ' AND date < '.$endtime; |
---|
118 | $query.= ';'; |
---|
119 | $result = mysql_query( $query ); |
---|
120 | $nb_visitors = mysql_num_rows( $result ); |
---|
121 | $day['nb_visitors'] = $nb_visitors; |
---|
122 | if ( $nb_visitors > $max_nb_visitors ) $max_nb_visitors = $nb_visitors; |
---|
123 | $vtp->setVar( $sub, 'day.nb_visitors', $nb_visitors ); |
---|
124 | // log lines for this day |
---|
125 | $query = 'SELECT date,login,IP,category,file,picture'; |
---|
126 | $query.= ' FROM '.PREFIX_TABLE.'history'; |
---|
127 | $query.= ' WHERE date > '.$starttime; |
---|
128 | $query.= ' AND date < '.$endtime; |
---|
129 | $query.= ' ORDER BY date DESC'; |
---|
130 | $query.= ';'; |
---|
131 | $result = mysql_query( $query ); |
---|
132 | $nb_pages_seen = mysql_num_rows( $result ); |
---|
133 | $day['nb_pages_seen'] = $nb_pages_seen; |
---|
134 | if ( $nb_pages_seen > $max_pages_seen ) $max_pages_seen = $nb_pages_seen; |
---|
135 | $vtp->setVar( $sub, 'day.nb_pages', $nb_pages_seen ); |
---|
136 | if ( in_array( $i, $page['expand_days'] ) ) |
---|
137 | { |
---|
138 | while ( $row = mysql_fetch_array( $result ) ) |
---|
139 | { |
---|
140 | $vtp->addSession( $sub, 'line' ); |
---|
141 | $vtp->setVar( $sub, 'line.date', date( 'G:i:s', $row['date'] ) ); |
---|
142 | $vtp->setVar( $sub, 'line.login', $row['login'] ); |
---|
143 | $vtp->setVar( $sub, 'line.IP', $row['IP'] ); |
---|
144 | $vtp->setVar( $sub, 'line.category', $row['category'] ); |
---|
145 | $vtp->setVar( $sub, 'line.file', $row['file'] ); |
---|
146 | $vtp->setVar( $sub, 'line.picture', $row['picture'] ); |
---|
147 | $vtp->closeSession( $sub, 'line' ); |
---|
148 | } |
---|
149 | } |
---|
150 | $starttime-= 24*60*60; |
---|
151 | $endtime -= 24*60*60; |
---|
152 | $vtp->closeSession( $sub, 'day' ); |
---|
153 | array_push( $days, $day ); |
---|
154 | } |
---|
155 | //------------------------------------------------------------ pages seen graph |
---|
156 | foreach ( $days as $day ) { |
---|
157 | $vtp->addSession( $sub, 'pages_day' ); |
---|
158 | if ( $max_pages_seen > 0 ) |
---|
159 | $width = floor( ( $day['nb_pages_seen']*$max_pixels ) / $max_pages_seen ); |
---|
160 | else $width = 0; |
---|
161 | $vtp->setVar( $sub, 'pages_day.date', $day['date'] ); |
---|
162 | $vtp->setVar( $sub, 'pages_day.width', $width ); |
---|
163 | $vtp->setVar( $sub, 'pages_day.nb_pages', $day['nb_pages_seen'] ); |
---|
164 | $vtp->closeSession( $sub, 'pages_day' ); |
---|
165 | } |
---|
166 | //-------------------------------------------------------------- visitors grpah |
---|
167 | foreach ( $days as $day ) { |
---|
168 | $vtp->addSession( $sub, 'visitors_day' ); |
---|
169 | if ( $max_nb_visitors > 0 ) |
---|
170 | $width = floor( ( $day['nb_visitors'] * $max_pixels ) / $max_nb_visitors ); |
---|
171 | else $width = 0; |
---|
172 | $vtp->setVar( $sub, 'visitors_day.date', $day['date'] ); |
---|
173 | $vtp->setVar( $sub, 'visitors_day.width', $width ); |
---|
174 | $vtp->setVar( $sub, 'visitors_day.nb_visitors', $day['nb_visitors'] ); |
---|
175 | $vtp->closeSession( $sub, 'visitors_day' ); |
---|
176 | } |
---|
177 | //----------------------------------------------------------- sending html code |
---|
178 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
179 | ?> |
---|