<?php
/* GZip compress the page */
ob_start( 'ob_gzhandler' );
/* XML doctype */
echo('<?xml version="1.0" encoding="ISO-8859-1"?>');
/* database info */
$username = "xxx";
$password = "xxx";
$db = "stats";
/* get variables */
$stat = $_GET['stat'];
$sortby = $_GET['sortby'];
/* check for null value of sortby */
if (is_null($sortby)) {
$sortby = 'total';
}
/* check for SQL injections */
$sort_test = array("team", "start", "end", "total");
$stat_test = array("sb", "rbi", "so", "sv", "runs", "wins");
/* do some replacing if they aren't found */
if (!in_array($sort, $sort_test)) {
$sort = 'total';
}
if (!in_array($stat, $stat_test)) {
$stat = 'sb';
}
/* Connect to the db */
mysql_connect(localhost,$username,$password);
@mysql_select_db($db) or die( "Unable to connect to the database");
/* Order results by variable */
if ($sortby == 'team') {
$query = "SELECT * FROM $stat ORDER BY $sortby ASC";
}
else {
$query = "SELECT * FROM $stat ORDER BY '$sortby' DESC";
}
/* Store query info */
$result = mysql_query($query);
$num = mysql_numrows($result);
/* Set categories and months */
if ($stat == 'sb') {
$cat = 'Stolen Bases';
$month = 'April';
}
if ($stat == 'rbi') {
$cat = 'RBI\'s';
$month = 'May';
}
if ($stat == 'so') {
$cat = 'Strikeouts';
$month = 'June';
}
if ($stat == 'sv') {
$cat = 'Saves';
$month = 'July';
}
if ($stat == 'runs') {
$cat = 'Runs';
$month = 'August';
}
if ($stat == 'wins') {
$cat = 'Wins';
$month = 'September';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>xxx :: <?php echo "$month"; ?> Stats</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="icon" type="image/x-icon" href="favicon.ico" />
</head>
<body>
<table >
<tr>
<td class="page">
<?php
include('blocks/top.html');
?>
<table class="content">
<tr>
<th>Links</th>
<th><?php echo "$month"; ?> Stats</th>
</tr>
<tr>
<td class="nav">
<?php
include('blocks/nav.html');
?>
</td>
<td class="body">
<?php
echo "<table class=\"stats\">\n";
echo "<tr class=\"header\">\n";
echo "<td><a href=\"monthly.php?stat=$stat&sortby=team\">Team</a></td>\n";
echo "<td><a href=\"monthly.php?stat=$stat&sortby=start\">Starting $cat</a></td>\n";
echo "<td><a href=\"monthly.php?stat=$stat&sortby=end\">Ending $cat</a></td>\n";
echo "<td><a href=\"monthly.php?stat=$stat&sortby=total\">Total $cat</a></td>\n";
echo "</tr>\n";
$i=0;
while ($i < $num) {
$id = mysql_result($result,$i,"id");
$team = mysql_result($result,$i,"team");
$start = mysql_result($result,$i,"start");
$end = mysql_result($result,$i,"end");
$total = mysql_result($result,$i,"total");
echo "<tr class=\"hl\">\n";
echo "<td>$team</td>\n";
echo "<td>$start</td>\n";
echo "<td>$end</td>\n";
echo "<td>$total</td>\n";
echo "</tr>\n";
++$i;
}
echo "</table>\n";
mysql_close();
?>
</td>
</tr>
</table>
<?php
include('blocks/bottom.html');
?>
</td>
</tr>
</table>
</body>
</html>