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