<?php
$time_start = microtime(true);
include '../config.php';
function display($title, $data, $width) {
echo '<div style="margin-bottom: 10px; float: left; width: '.$width.'px;">';
echo '<table style="width: '.$width.'px; table-layout: fixed; empty-cells: hide;">';
echo '<tr><td style="width: '.($width-100).'px;">'.$title.'</td></tr>';
foreach($data as $type => $value) {
echo '<tr><td>'.$type.'</td><td>'.$value.'</td></tr>';
echo "\n";
}
echo '</table></div>';
}
$total = $unique = array(
'overall' => 0,
'last 24 hours' => 0,
'last hour' => 0,
);
$os = array(
'intel mac os x' => 0,
'ppc mac os x' => 0,
'other linux' => 0,
'ubuntu' => 0,
'debian' => 0,
'fedora' => 0,
'other windows' => 0,
'windows 2000' => 0,
'windows xp' => 0,
'windows 2003' => 0,
'windows vista' => 0
);
$browser = array(
'firefox' => 0,
'opera' => 0,
'internet explorer' => 0,
'safari' => 0
);
$result1 = mysql_query("SELECT time FROM logs");
$total['overall'] = mysql_num_rows($result1);
while($row1 = mysql_fetch_array($result1)) {
if(time()-$row1['time'] < 86400) {
$total['last 24 hours']++;
}
if(time()-$row1['time'] < 3600) {
$total['last hour']++;
}
}
$result2 = mysql_query("SELECT agent, time FROM logs GROUP BY ip");
$unique['overall'] = mysql_num_rows($result2);
while($row2 = mysql_fetch_array($result2)) {
if(time()-$row2['time'] < 86400) {
$unique['last 24 hours']++;
}
if(time()-$row2['time'] < 3600) {
$unique['last hour']++;
}
if(strstr(strtolower($row2['agent']), "linux")) {
if(strstr(strtolower($row2['agent']), "debian")) {
$os['debian']++;
} elseif(strstr(strtolower($row2['agent']), "fedora")) {
$os['fedora']++;
} elseif(strstr(strtolower($row2['agent']), "ubuntu")) {
$os['ubuntu']++;
} else {
$os['other linux']++;
}
}
if(strstr(strtolower($row2['agent']), "intel mac os x")) {
$os['intel mac os x']++;
}
if(strstr(strtolower($row2['agent']), "ppc mac os x")) {
$os['ppc mac os x']++;
}
if(strstr(strtolower($row2['agent']), "windows")) {
if(strstr(strtolower($row2['agent']), "windows nt 5.0")) {
$os['windows 2000']++;
} elseif(strstr(strtolower($row2['agent']), "windows nt 5.1")) {
$os['windows xp']++;
} elseif(strstr(strtolower($row2['agent']), "windows nt 5.2")) {
$os['windows 2003']++;
} elseif(strstr(strtolower($row2['agent']), "windows nt 6.0")) {
$os['windows vista']++;
} else {
$os['other windows']++;
}
}
if(strstr(strtolower($row2['agent']), "firefox")) {
$browser['firefox']++;
}
if(strstr(strtolower($row2['agent']), "opera")) {
$browser['opera']++;
}
if(strstr(strtolower($row2['agent']), "msie")) {
$browser['internet explorer']++;
}
if(strstr(strtolower($row2['agent']), "safari")) {
$browser['safari']++;
}
}
array_multisort($os, SORT_DESC);
array_multisort($browser, SORT_DESC);
$result3 = mysql_query("SELECT COUNT(ref), ref FROM logs WHERE ref <> '' GROUP BY ref ORDER BY COUNT(ref) DESC LIMIT 10");
while($row3 = mysql_fetch_array($result3)) {
$row3['ref'] = htmlentities($row3['ref']);
$referrers['<a href="'.$row3['ref'].'">'.$row3['ref'].'</a>'] = $row3['COUNT(ref)'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php echo $_SERVER["SCRIPT_URI"]; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../css/style.css" />
</head>
<body>
<div style="height: 100%;" class="main">
<div style="padding: 4px;">
<p>my now playing signature viewing statistics summary (<a href="raw.php">view raw database data</a>)</p><br />
<?php
display('total views', $total, 350);
display('unique hits', $unique, 350);
display('top operating systems', $os, 350);
display('top browsers', $browser, 350);
display('top 10 referring pages', $referrers, 700);
$time_end = microtime(true);
$time = $time_end - $time_start;
echo '<div style="clear: left;"><p>script execution time - '.$time.' seconds</p></div>';
?>
</div>
</div>
</body>
</html>