<?

/*
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
*/



	// ========================================================================================
	// stats - systems information
	// ========================================================================================
	
	$PageTitle = '<img src="'.$ImagesURL.'/admin/admincp_stats.gif" width="24" height="18"> '.$MsgText[4][7];
	$BrowserTitle = $MsgText[4][7];
	$LocationBar = '<a href="'.$IndexURL.'">'.$MsgText[0][1].'</a> > <a href="' . $MainURL . '/options.html">'.$MsgText[0][4].'</a> > '.$MsgText[4][7];
	
	if ($LoggedIn == 'y') {
		
		ReadPermissions();
		Global $Permissions;
		
		if ($Permissions[401] == 'y') {
		
		
		
			$query = "select * from `".$Settings['DBPrefix']."cs-Recent` order by DateCode desc limit 5000";
			$result = mysql_query($query) or die (mysql_error());
			while ($row = mysql_fetch_array($result)) {
			
				$DataRows[] = $row;
			
			}
			
			
					
			
			$PageContents .= '<br><b>('.$MsgText[4][30].')</b><br><br><br><b>'.$MsgText[4][47].':</b><br><br>';

			
			$Resolutions = '';
			$Counts = '';
			$TotalCount = '';
			
			$LargestFound = -1;
			
			
			
			
			for ($DRCount = 0; $DRCount < count($DataRows); $DRCount++) {
			
				$row = $DataRows[$DRCount];
			
			
				if ($row['ScreenResolution'] == '') {
					$row['ScreenResolution'] = $MsgText[4][48];
				}
				else if (strpos($row['ScreenResolution'],'x') === false) {
					$row['ScreenResolution'] = $MsgText[4][48];
				}
			
				$Counts[$row['ScreenResolution']]++;
				$TotalCount++;
				
				if ($ResolutionAddedToList[$row['ScreenResolution']] == '') {
					$ResolutionAddedToList[$row['ScreenResolution']] = 'y';
					$ResolutionsList[] = $row['ScreenResolution'];
				}
				
				if ($Counts[$row['ScreenResolution']] > $LargestFound) {
					$LargestFound = $Counts[$row['ScreenResolution']];
				}
			
			}
			
			// sort by title
			for ($k = 0; $k < count($ResolutionsList); $k++) {
				for ($j = 0; $j < (count($ResolutionsList)-1); $j++) {
				
					if ($ResolutionsList[$j] > $ResolutionsList[$j+1]) {
					
						$Swap2 = $ResolutionsList[$j+1];
						
						$ResolutionsList[$j+1] = $ResolutionsList[$j];
						
						$ResolutionsList[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($ResolutionsList); $k++) {
				for ($j = 0; $j < (count($ResolutionsList)-1); $j++) {
				
					if ($Counts[$ResolutionsList[$j]] < $Counts[$ResolutionsList[$j+1]]) {
					
						$Swap2 = $ResolutionsList[$j+1];
						
						$ResolutionsList[$j+1] = $ResolutionsList[$j];
						
						$ResolutionsList[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$ResolutionsBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][49].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][50].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>%</b>&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($ResolutionsList); $j++) {
			
				$ThisPercent = ($Counts[$ResolutionsList[$j]]/$TotalCount);
				$ThisWidth = number_format($ThisPercent * 180 * $SizeMultiplier,0);
				
							 
			
				$ResolutionsBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">' .$ResolutionsList[$j]. '&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($Counts[$ResolutionsList[$j]],0).'&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($ThisPercent*100,1).'%&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    			</tr>';
			
			}
			
			$ResolutionsBreakdown .= '</table></td></tr></table>';
				
			$PageContents .= $ResolutionsBreakdown;
			
			
			
			
			
			$PageContents .= '<br><br><b>'.$MsgText[4][51].':</b><br><br>';

			
			$ColorDepths = '';
			$Counts = '';
			$TotalCount = '';
			
			$LargestFound = -1;
			
			
			for ($DRCount = 0; $DRCount < count($DataRows); $DRCount++) {
			
				$row = $DataRows[$DRCount];
			
				if ($row['ColorDepth'] == '' || $row['ColorDepth'] == '0') {
					$row['ColorDepth'] = $MsgText[4][48];				
				}
				else {
					$row['ColorDepth'] .= ' bit';
					
					if ($row['ColorDepth'] == '8 bit') {
						$row['ColorDepth'] .= ' (256 '.$MsgText[4][52].')';
					}
					else if ($row['ColorDepth'] == '4 bit') {
						$row['ColorDepth'] .= ' (16 '.$MsgText[4][52].')';
					}
					else if ($row['ColorDepth'] == '1 bit') {
						$row['ColorDepth'] .= ' (B&W)';
					}
				}
			
				$Counts[$row['ColorDepth']]++;
				$TotalCount++;
				
				if ($ColorDepthAddedToList[$row['ColorDepth']] == '') {
					$ColorDepthAddedToList[$row['ColorDepth']] = 'y';
					$ColorDepthsList[] = $row['ColorDepth'];
				}
				
				if ($Counts[$row['ColorDepth']] > $LargestFound) {
					$LargestFound = $Counts[$row['ColorDepth']];
				}
			
			}
			
			// sort by title
			for ($k = 0; $k < count($ColorDepthsList); $k++) {
				for ($j = 0; $j < (count($ColorDepthsList)-1); $j++) {
				
					if ($ColorDepthsList[$j] > $ColorDepthsList[$j+1]) {
					
						$Swap2 = $ColorDepthsList[$j+1];
						
						$ColorDepthsList[$j+1] = $ColorDepthsList[$j];
						
						$ColorDepthsList[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($ColorDepthsList); $k++) {
				for ($j = 0; $j < (count($ColorDepthsList)-1); $j++) {
				
					if ($Counts[$ColorDepthsList[$j]] < $Counts[$ColorDepthsList[$j+1]]) {
					
						$Swap2 = $ColorDepthsList[$j+1];
						
						$ColorDepthsList[$j+1] = $ColorDepthsList[$j];
						
						$ColorDepthsList[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$ColorDepthsBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][53].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][50].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>%</b>&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($ColorDepthsList); $j++) {
			
				$ThisPercent = ($Counts[$ColorDepthsList[$j]]/$TotalCount);
				$ThisWidth = number_format($ThisPercent * 180 * $SizeMultiplier,0);
				
							 
			
				$ColorDepthsBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">' .$ColorDepthsList[$j]. '&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($Counts[$ColorDepthsList[$j]],0).'&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($ThisPercent*100,1).'%&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    			</tr>';
			
			}
			
			$ColorDepthsBreakdown .= '</table></td></tr></table>';
				
			$PageContents .= $ColorDepthsBreakdown;
			
			
			
			
			
			
			$PageContents .= '<br><br><b>'.$MsgText[4][54].':</b><br><br>';

			
			$Browsers = '';
			$Counts = '';
			$TotalCount = '';
			
			$LargestFound = -1;
			
			
			for ($DRCount = 0; $DRCount < count($DataRows); $DRCount++) {
			
				$row = $DataRows[$DRCount];
			
				if ($row['BrowserName'] == '') {
					$ThisBrowser = $MsgText[4][48];				
				}
				else if (is_numeric(substr($row['BrowserName'],0,1)) == true) {
					$ThisBrowser = $MsgText[4][48];
				}
				else {
					if ($row['BrowserVersion'] == '') {
						$row['BrowserVersion'] = $MsgText[4][55];			
					}
					
					
					if ($row['BrowserName'] == 'IE') {
						$row['BrowserName'] = 'Internet Explorer';
					}
					else if ($row['BrowserName'] == 'NS') {
						$row['BrowserName'] = 'Netscape Navigator';
					}
					else if ($row['BrowserName'] == 'Moz' || $row['BrowserName'] == 'MZ') {
						$row['BrowserName'] = 'Mozilla';
					}
					else if ($row['BrowserName'] == 'FF') {
						$row['BrowserName'] = 'Firefox';
					}
					else if ($row['BrowserName'] == 'SF') {
						$row['BrowserName'] = 'Safari';
					}
					else if ($row['BrowserName'] == 'OP') {
						$row['BrowserName'] = 'Opera';
					}
					

					$ThisBrowser = $row['BrowserName'].' '.$row['BrowserVersion'];
				}
			
				$Counts[$ThisBrowser]++;
				$TotalCount++;
				
				if ($BrowserAddedToList[$ThisBrowser] == '') {
					$BrowserAddedToList[$ThisBrowser] = 'y';
					$BrowsersList[] = $ThisBrowser;
				}
				
				if ($Counts[$ThisBrowser] > $LargestFound) {
					$LargestFound = $Counts[$ThisBrowser];
				}
			
			}
			
			// sort by title
			for ($k = 0; $k < count($BrowsersList); $k++) {
				for ($j = 0; $j < (count($BrowsersList)-1); $j++) {
				
					if ($BrowsersList[$j] > $BrowsersList[$j+1]) {
					
						$Swap2 = $BrowsersList[$j+1];
						
						$BrowsersList[$j+1] = $BrowsersList[$j];
						
						$BrowsersList[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($BrowsersList); $k++) {
				for ($j = 0; $j < (count($BrowsersList)-1); $j++) {
				
					if ($Counts[$BrowsersList[$j]] < $Counts[$BrowsersList[$j+1]]) {
					
						$Swap2 = $BrowsersList[$j+1];
						
						$BrowsersList[$j+1] = $BrowsersList[$j];
						
						$BrowsersList[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$BrowsersBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][56].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][50].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>%</b>&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($BrowsersList); $j++) {
			
				$ThisPercent = ($Counts[$BrowsersList[$j]]/$TotalCount);
				$ThisWidth = number_format($ThisPercent * 180 * $SizeMultiplier,0);
				
							 
			
				$BrowsersBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">' .$BrowsersList[$j]. '&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($Counts[$BrowsersList[$j]],0).'&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($ThisPercent*100,1).'%&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    			</tr>';
			
			}
			
			$BrowsersBreakdown .= '</table></td></tr></table>';
				
			$PageContents .= $BrowsersBreakdown;
			
			
			
			
			
			$PageContents .= '<br><br><b>'.$MsgText[4][57].':</b><br><br>';

			
			$OSList = '';
			$Counts = '';
			$TotalCount = '';
			
			$LargestFound = -1;
			
			
			for ($DRCount = 0; $DRCount < count($DataRows); $DRCount++) {
			
				$row = $DataRows[$DRCount];
			
				if ($row['OperatingSystem'] == '') {
					$row['OperatingSystem'] = $MsgText[4][48];				
				}
				else if (is_numeric(substr($row['OperatingSystem'],0,1)) == true) {
					$row['OperatingSystem'] = $MsgText[4][48];
				}
				else {
										
					if ($row['OperatingSystem'] == 'Win98') {
						$row['OperatingSystem'] = 'Windows 98';
					}
					else if ($row['OperatingSystem'] == 'WinME') {
						$row['OperatingSystem'] = 'Windows ME';
					}
					else if ($row['OperatingSystem'] == 'Win2000') {
						$row['OperatingSystem'] = 'Windows 2000';
					}
					else if ($row['OperatingSystem'] == 'WinXP') {
						$row['OperatingSystem'] = 'Windows XP';
					}
					else if ($row['OperatingSystem'] == 'Win2003x64') {
						$row['OperatingSystem'] = 'Windows Server 2003 / XP x64';
					}
					else if ($row['OperatingSystem'] == 'WinVista') {
						$row['OperatingSystem'] = 'Windows Vista';
					}
					else if ($row['OperatingSystem'] == 'Win95') {
						$row['OperatingSystem'] = 'Windows 95';
					}
					else if ($row['OperatingSystem'] == 'WinNT4') {
						$row['OperatingSystem'] = 'Windows NT 4.0';
					}
					else if ($row['OperatingSystem'] == 'WinNT') {
						$row['OperatingSystem'] = 'Windows ('.$MsgText[4][55].')';
					}
										

				}
			
				$Counts[$row['OperatingSystem']]++;
				$TotalCount++;
				
				if ($OSAddedToList[$row['OperatingSystem']] == '') {
					$OSAddedToList[$row['OperatingSystem']] = 'y';
					$OSList[] = $row['OperatingSystem'];
				}
				
				if ($Counts[$row['OperatingSystem']] > $LargestFound) {
					$LargestFound = $Counts[$row['OperatingSystem']];
				}
			
			}
			
			// sort by title
			for ($k = 0; $k < count($OSList); $k++) {
				for ($j = 0; $j < (count($OSList)-1); $j++) {
				
					if ($OSList[$j] > $OSList[$j+1]) {
					
						$Swap2 = $OSList[$j+1];
						
						$OSList[$j+1] = $OSList[$j];
						
						$OSList[$j] = $Swap2;
					
					}
					
				}
			}
			
			// sort by count
			for ($k = 0; $k < count($OSList); $k++) {
				for ($j = 0; $j < (count($OSList)-1); $j++) {
				
					if ($Counts[$OSList[$j]] < $Counts[$OSList[$j+1]]) {
					
						$Swap2 = $OSList[$j+1];
						
						$OSList[$j+1] = $OSList[$j];
						
						$OSList[$j] = $Swap2;
					
					}
					
				}
			}
			
			
			$OSBreakdown .= '<table border="0" cellpadding="3" cellspacing="0" border="0"><tr><td width="10">&nbsp;</td><td><table border="0" cellpadding="2" cellspacing="0" border="0"><tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][58].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>'.$MsgText[4][50].'</b>&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.($FontSize-1).'">&nbsp;&nbsp;<b>%</b>&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.($FontSize-1).'"><b>'.$MsgText[4][29].'</b></td>
    			</tr>';
			
			$SizeMultiplier = (100/(($LargestFound/$TotalCount)*100));
						
			
			for ($j = 0; $j < count($OSList); $j++) {
			
				$ThisPercent = ($Counts[$OSList[$j]]/$TotalCount);
				$ThisWidth = number_format($ThisPercent * 180 * $SizeMultiplier,0);
				
							 
			
				$OSBreakdown .= '<tr>
			      <td align="left"><font face="'.$FontFace.'" size="'.$FontSize.'">' .$OSList[$j]. '&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($Counts[$OSList[$j]],0).'&nbsp;&nbsp;</td>
				  <td align="center"><font face="'.$FontFace.'" size="'.$FontSize.'">&nbsp;&nbsp;'.number_format($ThisPercent*100,1).'%&nbsp;&nbsp;</td>
			      <td width="200"><font face="'.$FontFace.'" size="'.$FontSize.'"><table width="'.$ThisWidth.'" height="8" border="0" cellpadding="0" cellspacing="0" border="0"><tr><td bgcolor="'.$Colors['Text'].'"><img src="'.$ImagesURL.'/admin/spacer.gif" width="1" height="1" border="0" alt=""></td></tr></table></td>
    			</tr>';
			
			}
			
			$OSBreakdown .= '</table></td></tr></table>';
				
			$PageContents .= $OSBreakdown;
			
			
			
					
		
		} // end if permissions are sufficient
		else {
		
			$PageContents = $MsgText[0][97];
		
		}

	}
	else {
	
		RedirectToLogin();
	
	}

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




?>
