<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/



	// ========================================================================================
	// basic stats
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_stats.gif" width="24" height="18"> '.$MsgText[4][2];
	$BrowserTitle = $MsgText[4][2];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[4][2];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[401] == 'y') {
		
			
			$query = "select PageViews from `".$Settings['DBPrefix']."cs-AggregateData` where Year='".date('Y',GetTimestamp())."' and Month='".date('n',GetTimestamp())."' and Day='".date('j',GetTimestamp())."' limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
			
			$TodayPageViews = $row['PageViews'];
			
			
			
			$Days = 7;
			$TotalCount = 0;
						
			for ($x = 0; $x < $Days; $x++) {
			
				$Timestamp = (GetTimestamp() - (60*60*24*($Days-1)) + (60*60*24*$x));
				
				$Year = date('Y',$Timestamp);
				$Month = date('n',$Timestamp);
				$Day = date('j',$Timestamp);
			
			
				$query = "select * from `".$Settings['DBPrefix']."cs-AggregateData` where Year='".$Year."' and Month='".$Month."' and Day='".$Day."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				$Dates[] = date('M j', mktime(0,0,0,$Month,$Day,$Year));
				$Counts[] = $row['PageViews'];
				
				if ($row['PageViews'] > $LargestFound) {
					$LargestFound = $row['PageViews'];
				}
				
				$TotalCount += $row['PageViews'];
							
			}
			
			$SevenDaysPageViews = $TotalCount;
			
			
			
			
			
			$Days = 30;
			$TotalCount = 0;
						
			for ($x = 0; $x < $Days; $x++) {
			
				$Timestamp = (GetTimestamp() - (60*60*24*($Days-1)) + (60*60*24*$x));
				
				$Year = date('Y',$Timestamp);
				$Month = date('n',$Timestamp);
				$Day = date('j',$Timestamp);
			
			
				$query = "select * from `".$Settings['DBPrefix']."cs-AggregateData` where Year='".$Year."' and Month='".$Month."' and Day='".$Day."' limit 1";
				$result = mysql_query($query) or die (mysql_error());
				$row = mysql_fetch_array($result);
				
				$Dates[] = date('M j', mktime(0,0,0,$Month,$Day,$Year));
				$Counts[] = $row['PageViews'];
				
				if ($row['PageViews'] > $LargestFound) {
					$LargestFound = $row['PageViews'];
				}
				
				$TotalCount += $row['PageViews'];
							
			}
			
			$ThirtyDaysPageViews = $TotalCount;
			
		
		
			$query = "select sum(PageViews) as TotalPageViews from `".$Settings['DBPrefix']."cs-AggregateData`";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
		
			$TotalPageViews = $row['TotalPageViews'];
			
			
			
			$query = "select * from `".$Settings['DBPrefix']."cs-AggregateData` order by PageViews desc limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
		
			$HighestPageViews = $row['PageViews'];
			$HighestPageViewsDate = date('F j, Y',mktime(0,0,0,$row['Month'],$row['Day'],$row['Year']));
			
			
			$query = "select * from `".$Settings['DBPrefix']."cs-AggregateData` where PageViews>0 and (Year!='".date('Y',GetTimestamp())."' or Month!='".date('n',GetTimestamp())."' or Day!='".date('j',GetTimestamp())."') order by PageViews asc limit 1";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
		
			$LowestPageViews = $row['PageViews'];
			$LowestPageViewsDate = date('F j, Y',mktime(0,0,0,$row['Month'],$row['Day'],$row['Year']));
			
			
			
			$query = "select avg(PageViews) as PageViewsAverage from `".$Settings['DBPrefix']."cs-AggregateData`";
			$result = mysql_query($query) or die (mysql_error());
			$row = mysql_fetch_array($result);
		
			$PageViewsAverage = $row['PageViewsAverage'];
			
			
		
					
			$PageContents .= '<table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;</td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][10].'</b></td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][11].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($TodayPageViews,0).'</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][12].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($SevenDaysPageViews,0).'</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][13].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($ThirtyDaysPageViews,0).'</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][14].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($TotalPageViews,0).'</td>
    			</tr>
				<tr>
			      <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'" colspan="2">&nbsp;</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][15].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($HighestPageViews,0).' ('.$HighestPageViewsDate.')</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][16].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($LowestPageViews,0).' ('.$LowestPageViewsDate.')</td>
    			</tr>
				<tr>
			      <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'" colspan="2">&nbsp;</td>
    			</tr>
				<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'"><b>'.$MsgText[4][17].'</b></td>
			      <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">'.number_format($PageViewsAverage,0).'</td>
    			</tr>
				
				
				</table>';
					


			
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

	// ========================================================================================




?>
