[24] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2006-01-15 13:45:42 +0000 (Sun, 15 Jan 2006) $ |
---|
| 10 | // | last modifier : $Author: nikrou $ |
---|
| 11 | // | revision : $Revision: 1004 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[527] | 27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
| 28 | { |
---|
| 29 | die ("Hacking attempt!"); |
---|
| 30 | } |
---|
| 31 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); |
---|
| 32 | |
---|
[766] | 33 | $url_img = PHPWG_ROOT_PATH.'admin/images/'; |
---|
| 34 | $nls_value_title = $lang['w_month']; |
---|
| 35 | $group_clause = "DATE_FORMAT(date,'%Y-%m') DESC"; |
---|
| 36 | $where_clause = "1"; |
---|
| 37 | |
---|
[894] | 38 | |
---|
| 39 | if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) ) |
---|
[766] | 40 | { |
---|
[918] | 41 | $url_img .= 'daily_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month'].'&day='.$_GET['day']; |
---|
[894] | 42 | $nls_value_title = $lang['w_day']; |
---|
| 43 | $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC"; |
---|
| 44 | $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )"; |
---|
| 45 | } |
---|
| 46 | elseif (isset($_GET['month']) && isset($_GET['year']) ) |
---|
| 47 | { |
---|
[766] | 48 | $url_img .= 'monthly_stats.img.php?year='.$_GET['year'].'&month='.$_GET['month']; |
---|
| 49 | $nls_value_title = $lang['w_day']; |
---|
| 50 | $group_clause = "DATE_FORMAT(date,'%Y-%m-%d') ASC"; |
---|
| 51 | $where_clause = "(YEAR(date) = ".$_GET['year']." AND MONTH(date) = ".$_GET['month']." )"; |
---|
| 52 | } |
---|
| 53 | else |
---|
| 54 | { |
---|
| 55 | $url_img .= 'global_stats.img.php'; |
---|
| 56 | } |
---|
| 57 | |
---|
[894] | 58 | |
---|
[24] | 59 | //----------------------------------------------------- template initialization |
---|
[894] | 60 | if (isset($_GET['day']) && isset($_GET['month']) && isset($_GET['year']) ) |
---|
| 61 | { |
---|
| 62 | $date_of_day=$_GET['day'].' '.$lang['month'][$_GET['month']].' '.$_GET['year']; |
---|
| 63 | $title_page=$lang['stats_day_title'].' du '.$date_of_day; |
---|
| 64 | $url_back = PHPWG_ROOT_PATH."admin.php?page=stats"; |
---|
[1004] | 65 | $url_back = $url_back; |
---|
[894] | 66 | $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>'; |
---|
[909] | 67 | $title_day = $date_of_day; |
---|
[894] | 68 | } |
---|
| 69 | elseif ( isset($_GET['month']) && isset($_GET['year']) ) |
---|
| 70 | { |
---|
| 71 | $date_of_day=$lang['month'][$_GET['month']].' '.$_GET['year']; |
---|
| 72 | $title_page=$lang['stats_month_title'].' : '.$date_of_day; |
---|
| 73 | $url_back = PHPWG_ROOT_PATH."admin.php?page=stats"; |
---|
[1004] | 74 | $url_back = $url_back; |
---|
[894] | 75 | $title_details='<a href='.$url_back.'>'.$lang['stats_day_title'].'</a>'; |
---|
| 76 | $title_day=$lang['today']; |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | $date_of_day=''; |
---|
| 81 | $title_page=$lang['stats_title']; |
---|
| 82 | $title_details=$lang['stats_month_title']; |
---|
| 83 | $title_day=$lang['today']; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | |
---|
[527] | 87 | $template->set_filenames( array('stats'=>'admin/stats.tpl') ); |
---|
| 88 | |
---|
| 89 | $template->assign_vars(array( |
---|
[766] | 90 | 'L_VALUE'=>$nls_value_title, |
---|
[566] | 91 | 'L_PAGES_SEEN'=>$lang['stats_pages_seen'], |
---|
| 92 | 'L_VISITORS'=>$lang['visitors'], |
---|
| 93 | 'L_PICTURES'=>$lang['pictures'], |
---|
| 94 | 'L_STAT_TITLE'=>$lang['stats_title'], |
---|
| 95 | 'L_STAT_MONTH_TITLE'=>$lang['stats_month_title'], |
---|
| 96 | 'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'], |
---|
[894] | 97 | 'L_STAT_TITLE'=>$title_page, |
---|
| 98 | 'L_STAT_DETAIL_TITLE'=>$title_details, |
---|
| 99 | 'L_DATE_TITLE'=>$title_day, |
---|
| 100 | 'L_STAT_MONTHLY_ALT'=>$lang['stats_global_graph_title'], |
---|
| 101 | 'L_STAT_HOUR'=>$lang['stats_hour'], |
---|
| 102 | 'L_STAT_LOGIN'=>$lang['stats_login'], |
---|
| 103 | 'L_STAT_ADDR'=>$lang['stats_addr'], |
---|
| 104 | 'L_STAT_CATEGORY'=>$lang['stats_category'], |
---|
| 105 | 'L_STAT_FILE'=>$lang['stats_file'], |
---|
| 106 | 'L_STAT_PICTURE'=>$lang['stats_picture'], |
---|
[566] | 107 | |
---|
[1004] | 108 | 'IMG_REPORT'=>$url_img |
---|
[527] | 109 | )); |
---|
| 110 | |
---|
[24] | 111 | //---------------------------------------------------------------- log history |
---|
[591] | 112 | $query = ' |
---|
| 113 | SELECT DISTINCT COUNT(*) as p, |
---|
[775] | 114 | DAYOFMONTH(date) as d, |
---|
[591] | 115 | MONTH(date) as m, |
---|
| 116 | YEAR(date) as y |
---|
| 117 | FROM '.HISTORY_TABLE.' |
---|
[766] | 118 | WHERE '.$where_clause.' |
---|
| 119 | GROUP BY '.$group_clause.';'; |
---|
| 120 | |
---|
[587] | 121 | $result = pwg_query( $query ); |
---|
[566] | 122 | $i=0; |
---|
| 123 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 124 | { |
---|
[766] | 125 | $where_clause=""; |
---|
| 126 | $value = ''; |
---|
| 127 | if (isset($_GET['month']) && isset($_GET['year']) ) |
---|
| 128 | { |
---|
[868] | 129 | $where_clause = 'DAYOFMONTH(date) = '.$row['d'].' |
---|
| 130 | AND MONTH(date) = '.$row['m'].' |
---|
| 131 | AND YEAR(date) = '.$row['y']; |
---|
[909] | 132 | |
---|
| 133 | $week_day = |
---|
| 134 | $lang['day'][date('w', mktime(12,0,0,$row['m'],$row['d'],$row['y']))]; |
---|
| 135 | |
---|
| 136 | $url = |
---|
| 137 | PHPWG_ROOT_PATH.'admin.php' |
---|
| 138 | .'?page=stats' |
---|
| 139 | .'&year='.$row['y'] |
---|
| 140 | .'&month='.$row['m'] |
---|
| 141 | .'&day='.$row['d'] |
---|
| 142 | ; |
---|
| 143 | |
---|
[1004] | 144 | $value = '<a href="'.$url.'">'; |
---|
[909] | 145 | $value.= $row['d'].' ('.$week_day.')'; |
---|
| 146 | $value.= "</a>"; |
---|
[766] | 147 | } |
---|
| 148 | else |
---|
| 149 | { |
---|
| 150 | $current_month = $row['y']."-"; |
---|
| 151 | if ($row['m'] <10) {$current_month.='0';} |
---|
| 152 | $current_month .= $row['m']; |
---|
[877] | 153 | |
---|
[766] | 154 | $where_clause = "DATE_FORMAT(date,'%Y-%m') = '".$current_month."'"; |
---|
[877] | 155 | |
---|
| 156 | $url = |
---|
| 157 | PHPWG_ROOT_PATH.'admin.php' |
---|
| 158 | .'?page=stats' |
---|
| 159 | .'&year='.$row['y'] |
---|
| 160 | .'&month='.$row['m'] |
---|
| 161 | ; |
---|
| 162 | |
---|
[1004] | 163 | $value = '<a href="'.$url.'">'; |
---|
[766] | 164 | $value.= $lang['month'][$row['m']].' '.$row['y']; |
---|
| 165 | $value.= "</a>"; |
---|
| 166 | } |
---|
| 167 | |
---|
[566] | 168 | // Number of pictures seen |
---|
[591] | 169 | $query = ' |
---|
[868] | 170 | SELECT COUNT(*) as p |
---|
[766] | 171 | FROM '.HISTORY_TABLE.' |
---|
| 172 | WHERE '.$where_clause.' |
---|
[591] | 173 | AND FILE = \'picture\' |
---|
| 174 | ;'; |
---|
[587] | 175 | $pictures = mysql_fetch_array(pwg_query( $query )); |
---|
[566] | 176 | |
---|
| 177 | // Number of different visitors |
---|
[591] | 178 | $query = ' |
---|
| 179 | SELECT COUNT(*) as p, login |
---|
| 180 | FROM '.HISTORY_TABLE.' |
---|
[766] | 181 | WHERE '.$where_clause.' |
---|
[591] | 182 | GROUP BY login, IP |
---|
| 183 | ;'; |
---|
[587] | 184 | $user_results = pwg_query( $query ); |
---|
[566] | 185 | $nb_visitors = 0; |
---|
| 186 | $auth_users = array(); |
---|
| 187 | while ( $user_array = mysql_fetch_array( $user_results ) ) |
---|
| 188 | { |
---|
| 189 | if ($user_array['login'] == 'guest') |
---|
| 190 | $nb_visitors += 1; |
---|
| 191 | else |
---|
| 192 | array_push($auth_users, $user_array['login']); |
---|
| 193 | } |
---|
| 194 | $nb_visitors +=count(array_unique($auth_users)); |
---|
| 195 | $class = ($i % 2)? 'row1':'row2'; $i++; |
---|
| 196 | |
---|
[766] | 197 | $template->assign_block_vars('statrow',array( |
---|
| 198 | 'VALUE'=>$value, |
---|
[566] | 199 | 'PAGES'=>$row['p'], |
---|
| 200 | 'VISITORS'=>$nb_visitors, |
---|
| 201 | 'IMAGES'=>$pictures['p'], |
---|
| 202 | |
---|
| 203 | 'T_CLASS'=>$class |
---|
| 204 | )); |
---|
| 205 | } |
---|
| 206 | $nb_visitors = mysql_num_rows( $result ); |
---|
[24] | 207 | $days = array(); |
---|
| 208 | $max_nb_visitors = 0; |
---|
| 209 | $max_pages_seen = 0; |
---|
[894] | 210 | |
---|
| 211 | //----------------------------------------------------------- stats / jour |
---|
| 212 | |
---|
| 213 | if ( isset( $_GET['month'] ) && isset( $_GET['month'] ) && isset( $_GET['day'] ) ) |
---|
| 214 | { if ($_GET['day'] <10) {$current_day='0'; |
---|
| 215 | $current_day.= $_GET['day'];} |
---|
| 216 | else {$current_day = $_GET['day'];} |
---|
| 217 | if ($_GET['month'] <10) {$current_month='0'; |
---|
| 218 | $current_month.= $_GET['month'];} |
---|
| 219 | else {$current_month = $_GET['month'];} |
---|
| 220 | $current_year = $_GET['year']; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | else |
---|
| 224 | { $current_date = GetDate(); |
---|
| 225 | if ($current_date['mday'] <10) {$current_day='0'; |
---|
| 226 | $current_day.= $current_date['mday'];} |
---|
| 227 | else {$current_day = $current_date['mday'];} |
---|
| 228 | if ($current_date['mon'] <10) {$current_month='0'; |
---|
| 229 | $current_month.= $current_date['mon'];} |
---|
| 230 | else {$current_month = $current_date['mon'];} |
---|
| 231 | $current_year = $current_date['year']; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | // Set WHERE clause |
---|
| 235 | $where = ' WHERE DATE_FORMAT(date,\'%Y-%m-%d\') = \''.$current_year."-".$current_month."-".$current_day.'\''; |
---|
| 236 | |
---|
| 237 | // Set LIMIT clause |
---|
| 238 | $limit = ' LIMIT '; |
---|
| 239 | $page['start'] = 0; |
---|
| 240 | if (isset($_GET['start']) and is_numeric($_GET['start'])) $page['start'] = abs($_GET['start']); |
---|
| 241 | $limit .= $page['start']; |
---|
| 242 | $limit .= ','.$conf['nb_logs_page']; |
---|
| 243 | |
---|
| 244 | $query = ' |
---|
| 245 | SELECT DATE_FORMAT(date,\'%H:%i:%s\') AS hour, |
---|
| 246 | login, |
---|
| 247 | IP, |
---|
| 248 | category, |
---|
| 249 | file, |
---|
| 250 | picture |
---|
| 251 | FROM '.HISTORY_TABLE. |
---|
| 252 | $where.' |
---|
| 253 | ORDER BY date DESC'. |
---|
| 254 | $limit. |
---|
| 255 | ';'; |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | $result = pwg_query( $query ); |
---|
| 259 | |
---|
| 260 | $i=0; |
---|
| 261 | |
---|
| 262 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 263 | { |
---|
| 264 | $class = ($i % 2)? 'row1':'row2'; $i++; |
---|
| 265 | $template->assign_block_vars('detail',array( |
---|
| 266 | 'HOUR'=>$row['hour'], |
---|
| 267 | 'LOGIN'=>$row['login'], |
---|
| 268 | 'IP'=>$row['IP'], |
---|
| 269 | 'CATEGORY'=>$row['category'], |
---|
| 270 | 'FILE'=>$row['file'], |
---|
| 271 | 'PICTURE'=>$row['picture'], |
---|
| 272 | 'T_CLASS'=>$class |
---|
| 273 | )); |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | |
---|
| 277 | // Get total number of logs |
---|
| 278 | $query = ' |
---|
| 279 | SELECT COUNT(date) as nb_logs |
---|
| 280 | FROM '.HISTORY_TABLE. |
---|
| 281 | $where.' |
---|
| 282 | ;'; |
---|
| 283 | |
---|
| 284 | $result = pwg_query($query); |
---|
| 285 | $row = mysql_fetch_array($result); |
---|
| 286 | $page['nb_logs']=$row['nb_logs']; |
---|
| 287 | |
---|
| 288 | //display nav bar |
---|
[904] | 289 | $url = $_SERVER['PHP_SELF'].'?page=stats'; |
---|
| 290 | $url.= isset($_GET['year']) ? '&year='.$_GET['year'] : ''; |
---|
| 291 | $url.= isset($_GET['month']) ? '&month='.$_GET['month'] : ''; |
---|
[909] | 292 | $url.= isset($_GET['day']) ? '&day='.$_GET['day'] : ''; |
---|
[894] | 293 | |
---|
[904] | 294 | $page['navigation_bar'] = |
---|
| 295 | create_navigation_bar( |
---|
| 296 | $url, |
---|
| 297 | $page['nb_logs'], |
---|
| 298 | $page['start'], |
---|
| 299 | $conf['nb_logs_page'], |
---|
| 300 | 'admin' |
---|
| 301 | ); |
---|
| 302 | |
---|
| 303 | $template->assign_block_vars( |
---|
| 304 | 'navigation', |
---|
| 305 | array( |
---|
| 306 | 'NAV_BAR' => $page['navigation_bar'] |
---|
| 307 | ) |
---|
| 308 | ); |
---|
| 309 | |
---|
[24] | 310 | //----------------------------------------------------------- sending html code |
---|
[527] | 311 | $template->assign_var_from_handle('ADMIN_CONTENT', 'stats'); |
---|
[362] | 312 | ?> |
---|
[894] | 313 | |
---|