[24] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
| 3 | * stats.php * |
---|
| 4 | * ------------------- * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[24] | 7 | * * |
---|
[57] | 8 | * $Id: stats.php 157 2003-09-21 18:27:13Z z0rglub $ |
---|
| 9 | * * |
---|
[24] | 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 ); |
---|
[29] | 43 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[24] | 44 | //--------------------------------------------------- number of days to display |
---|
[32] | 45 | if ( isset( $_GET['last_days'] ) ) define( MAX_DAYS, $_GET['last_days'] ); |
---|
| 46 | else define( MAX_DAYS, 0 ); |
---|
| 47 | |
---|
[24] | 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 | $local_expand = array_remove( $local_expand, $i ); |
---|
| 93 | } |
---|
| 94 | else |
---|
| 95 | { |
---|
| 96 | $vtp->addSession( $sub, 'collapsed' ); |
---|
| 97 | $vtp->closeSession( $sub, 'collapsed' ); |
---|
| 98 | array_push( $local_expand, $i ); |
---|
| 99 | } |
---|
| 100 | $url = './admin.php?page=stats&last_days='.$_GET['last_days']; |
---|
| 101 | $url.= '&expand='.implode( ',', $local_expand ); |
---|
| 102 | $vtp->setVar( $sub, 'day.url', add_session_id( $url ) ); |
---|
| 103 | // date displayed like this (in English ) : |
---|
| 104 | // Sunday 15 June 2003 |
---|
| 105 | $date = $lang['day'][date( 'w', $starttime )]; // Sunday |
---|
| 106 | $date.= date( ' j ', $starttime ); // 15 |
---|
| 107 | $date.= $lang['month'][date( 'n', $starttime )]; // June |
---|
| 108 | $date.= date( ' Y', $starttime ); // 2003 |
---|
| 109 | $day['date'] = $date; |
---|
| 110 | $vtp->setVar( $sub, 'day.name', $date ); |
---|
| 111 | // number of visitors for this day |
---|
| 112 | $query = 'SELECT DISTINCT(IP) as nb_visitors'; |
---|
| 113 | $query.= ' FROM '.PREFIX_TABLE.'history'; |
---|
| 114 | $query.= ' WHERE date > '.$starttime; |
---|
| 115 | $query.= ' AND date < '.$endtime; |
---|
| 116 | $query.= ';'; |
---|
| 117 | $result = mysql_query( $query ); |
---|
| 118 | $nb_visitors = mysql_num_rows( $result ); |
---|
| 119 | $day['nb_visitors'] = $nb_visitors; |
---|
| 120 | if ( $nb_visitors > $max_nb_visitors ) $max_nb_visitors = $nb_visitors; |
---|
| 121 | $vtp->setVar( $sub, 'day.nb_visitors', $nb_visitors ); |
---|
| 122 | // log lines for this day |
---|
| 123 | $query = 'SELECT date,login,IP,category,file,picture'; |
---|
| 124 | $query.= ' FROM '.PREFIX_TABLE.'history'; |
---|
| 125 | $query.= ' WHERE date > '.$starttime; |
---|
| 126 | $query.= ' AND date < '.$endtime; |
---|
[152] | 127 | $query.= ' ORDER BY date DESC'; |
---|
[24] | 128 | $query.= ';'; |
---|
| 129 | $result = mysql_query( $query ); |
---|
| 130 | $nb_pages_seen = mysql_num_rows( $result ); |
---|
| 131 | $day['nb_pages_seen'] = $nb_pages_seen; |
---|
| 132 | if ( $nb_pages_seen > $max_pages_seen ) $max_pages_seen = $nb_pages_seen; |
---|
| 133 | $vtp->setVar( $sub, 'day.nb_pages', $nb_pages_seen ); |
---|
| 134 | if ( in_array( $i, $page['expand_days'] ) ) |
---|
| 135 | { |
---|
| 136 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 137 | { |
---|
| 138 | $vtp->addSession( $sub, 'line' ); |
---|
[157] | 139 | $vtp->setVar( $sub, 'line.date', date( 'G:i:s', $row['date'] ) ); |
---|
[24] | 140 | $vtp->setVar( $sub, 'line.login', $row['login'] ); |
---|
| 141 | $vtp->setVar( $sub, 'line.IP', $row['IP'] ); |
---|
| 142 | $vtp->setVar( $sub, 'line.category', $row['category'] ); |
---|
| 143 | $vtp->setVar( $sub, 'line.file', $row['file'] ); |
---|
| 144 | $vtp->setVar( $sub, 'line.picture', $row['picture'] ); |
---|
| 145 | $vtp->closeSession( $sub, 'line' ); |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | $starttime-= 24*60*60; |
---|
| 149 | $endtime -= 24*60*60; |
---|
| 150 | $vtp->closeSession( $sub, 'day' ); |
---|
| 151 | array_push( $days, $day ); |
---|
| 152 | } |
---|
| 153 | //------------------------------------------------------------ pages seen graph |
---|
| 154 | foreach ( $days as $day ) { |
---|
| 155 | $vtp->addSession( $sub, 'pages_day' ); |
---|
[52] | 156 | if ( $max_pages_seen > 0 ) |
---|
| 157 | $width = floor( ( $day['nb_pages_seen']*$max_pixels ) / $max_pages_seen ); |
---|
| 158 | else $width = 0; |
---|
[24] | 159 | $vtp->setVar( $sub, 'pages_day.date', $day['date'] ); |
---|
| 160 | $vtp->setVar( $sub, 'pages_day.width', $width ); |
---|
| 161 | $vtp->setVar( $sub, 'pages_day.nb_pages', $day['nb_pages_seen'] ); |
---|
| 162 | $vtp->closeSession( $sub, 'pages_day' ); |
---|
| 163 | } |
---|
| 164 | //-------------------------------------------------------------- visitors grpah |
---|
| 165 | foreach ( $days as $day ) { |
---|
| 166 | $vtp->addSession( $sub, 'visitors_day' ); |
---|
[52] | 167 | if ( $max_nb_visitors > 0 ) |
---|
| 168 | $width = floor( ( $day['nb_visitors'] * $max_pixels ) / $max_nb_visitors ); |
---|
| 169 | else $width = 0; |
---|
[24] | 170 | $vtp->setVar( $sub, 'visitors_day.date', $day['date'] ); |
---|
| 171 | $vtp->setVar( $sub, 'visitors_day.width', $width ); |
---|
| 172 | $vtp->setVar( $sub, 'visitors_day.nb_visitors', $day['nb_visitors'] ); |
---|
| 173 | $vtp->closeSession( $sub, 'visitors_day' ); |
---|
| 174 | } |
---|
| 175 | //----------------------------------------------------------- sending html code |
---|
| 176 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 177 | ?> |
---|