<?php
// ***************************************************************************
// *
// * PHP Dynamic Trivia -- Add your own trivia file.
// * Copyright (C) 2005 Robin van de Vusse (hide@address.com)
// *
// * This program is free software; you can redistribute it and/or
// * modify it under the terms of the GNU General Public License
// * as published by the Free Software Foundation; either version 2
// * of the License, or (at your option) any later version.
// *
// * This program is distributed in the hope that it will be useful,
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// * GNU General Public License for more details.
// *
// * You should have received a copy of the GNU General Public License
// * along with this program; if not, write to the Free Software
// * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// *
// ***************************************************************************
require_once "config.php";
if (strlen(trim($strSessionPath)) > 0)
session_save_path($strSessionPath);
session_start();
?>
<html>
<head>
<title>High Scores</title>
</head>
<body>
<table width='800'>
<tr>
<td width='160'><table></table></td>
<td width='640' align='center'>
<table>High Scores</table>
</td>
</tr>
</table>
<hr>
<table width='800'>
<tr>
<td width='160' valign='top' align='center' STYLE='background-color: #9999cc;'>
<table>
<tr><td STYLE='background-color: #ccccff; color: #000000;'><a href="main.php" accesskey='b'>[<span STYLE="color: red">B</span>ack]</a></td></tr>
</table>
</td>
<td width='640' align='center'>
<table>
<?php
$boolError = false;
$strMessage = "";
$strTempDBInfo1 = DBTYPE."_pconnect";
$conn = $strTempDBInfo1($DB_HOST,$DB_USER,$DB_PASS);
$strTableName = "";
if (!$conn)
{
$strTempDBInfo1 = DBTYPE."_error";
$strMessage = "Unable to connect to DB server: " . $strTempDBInfo1($conn);
$boolError = true;
}
$strTempDBInfo1 = DBTYPE."_select_db";
if (!$boolError && (!$strTempDBInfo1($DB_NAME)))
{
$strTempDBInfo1 = DBTYPE."_error";
$strMessage = "Unable to select DB name: " . $strTempDBInfo1($conn);
$boolError = true;
}
if (!$boolError)
{
$sql = "SELECT TableName FROM highscores GROUP BY TableName";
$strTempDBInfo1 = DBTYPE."_query";
$result1 = $strTempDBInfo1($sql);
if (!$result1)
{
$strTempDBInfo1 = DBTYPE."_error";
$strMessage = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo1($conn);
$boolError = true;
}
}
if (!$boolError)
{
$strTempDBInfo1 = DBTYPE."_num_rows";
if ($strTempDBInfo1($result1) > 0)
{
$strTempDBInfo1 = DBTYPE."_fetch_assoc";
while ($row = $strTempDBInfo1($result1))
{
if (!$boolError)
{
$strTableName = $row['TableName'];
$sql = "SELECT TableName, UserName, QuestionsAnswered, QuestionsCorrect, CurrentStreak, BestStreak " .
"FROM highscores INNER JOIN login ON highscores.UserNumber = login.UserNumber " .
"WHERE TableName = '$strTableName'";
$strTempDBInfo2 = DBTYPE."_query";
$result2 = $strTempDBInfo2($sql);
if ($result2)
{
echo "<tr STYLE='background-color: #9999cc; color: #000000;'>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>Trivia Game</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>User Name</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>Questions Answered</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>Questions Correct</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>Current Streak</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>Best Streak</td>\n";
echo "</tr>\n";
$strTempDBInfo2 = DBTYPE."_num_rows";
if ($strTempDBInfo2($result2) > 0)
{
$strTempDBInfo2 = DBTYPE."_fetch_assoc";
while ($row = $strTempDBInfo2($result2))
{
echo "<tr STYLE='background-color: #ccccff; color: #000000;'>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['TableName'] . "</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['UserName'] . "</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['QuestionsAnswered'] . "</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['QuestionsCorrect'] . "</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['CurrentStreak'] . "</td>\n";
echo "<td STYLE='border: 1px solid #000000;' align='center'>" . $row['BestStreak'] . "</td>\n";
echo "</tr>\n";
}
$strMessage = "";
$boolError = false;
}
}
else
{
$strTempDBInfo2 = DBTYPE."_error";
$strMessage = "Could not successfully run query ($sql) from DB: " . $strTempDBInfo1($conn);
$boolError = true;
break;
}
}
}
}
}
$_SESSION['Message'] = $strMessage;
?>
</table>
</td>
</tr>
</table>
<?php require_once "footer.php"; ?>
</body>
</html>
<script type="text/javascript">
<!--
document.onkeypress=keyevent;
function keyevent(e)
{
var c;
c=String.fromCharCode(window.event.keyCode).toUpperCase();
target=window.event.srcElement;
if (c == 'B') { window.location='main.php';; return false; }
}
//-->
</script>