<?php
/**
 ********************************************
 * Masters of Endurance tracker / LFS-Tracker 
 ********************************************
 * 
 * Copyright © 2007 Wolfgang Tom (WolleT)
 * v1.0 originally written by Wolfgang Tom
 * 
 * Copyright © 2009-2011 Michael Booth (Boothy)
 * v2.0 tracker modified by Michael Booth
 * 
 * Thanks also to Casper Roescher (Kaspur).  
 * 
 * Latest tracker version available from the LFS forum thread - http://www.lfsforum.net/showthread.php?t=73414
 * Any code changes/improvements can be submitted for inclusion in the public tracker version. 
 * E-mail me at web@michaelbooth.me.uk or PM me via http://www.lfsforum.net/private.php?do=newpm&u=202039
 * 
 ********************************************
 * 
 * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 * Version 2, December 2004

 * Copyright © 2004 Sam Hocevar <sam@hocevar.net>

 * Everyone is permitted to copy and distribute verbatim or modified
 * copies of this license document, and changing it is allowed as long
 * as the name is changed.

 * DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 * TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 * 0. You just DO WHAT THE FUCK YOU WANT TO. 
 * 
 ******************************************** 
 * See http://sam.zoy.org/wtfpl/ for more information
 **/
ob_start();
$windowtitleadmin = "Tracker Admin - DB Server";
include '../header.admin.php';
// set file to read
$filename = "../currentserver.php";
$filename2 = "../currentprefix.php";

if (isset($_POST['server']) && $_POST['server'] != "") {
    $fp = fopen($filename, "w");
    // $server = '$server';
    $serverDefine = "<?php define(\"CURRENTSERVER\", '" . $_POST['server'] . "');?>";
    echo $serverDefine;
    fputs($fp, $serverDefine);
    fclose($fp);
    $fp = fopen($filename2, "w");
    $prefixDefine = "<?php define(\"CURRENTPREFIX\", '" . $_POST['prefix'] . "');?>";
    echo $prefixDefine;
    fputs($fp, $prefixDefine);
    fclose($fp);
    echo 'saved ' . $_POST['server'] . ' as current mysql server';

}
$userip = $_SERVER['REMOTE_ADDR'];
require "../currentserver.php";
require "../currentprefix.php";

echo "<h3>mysql server</h3>
<p><strong>Your IP: $userip</strong></p><h4>Other IPs:</h4>";
$max = count($dbServers);
for ($i = 0; $i < $max; $i++) {
    echo "<p>", $dbServers[$i], "</p>";
}
echo "<form method='post'>
<p>prefix:</p>
<input type='text' name='prefix' value='" . CURRENTPREFIX . "'/><br>
<p>server ip:</p>
<input type='text' name='server' value='" . CURRENTSERVER . "'/><br>
<input type='submit' value='save'>
</form>";
ob_end_flush();
echo "<h3>listing of race table</h3>";

require '../sql.php';
// CONNECT TO DB
$link = @mysql_connect(SQL_HOST, SQL_USER, SQL_PASS);
if (!$link) {
    die('Could not connect: ' . mysql_error());
} else {
    mysql_select_db(SQL_DB);
    $session_search2 = mysql_query("SELECT * FROM race");
    echo "<table id='raceStandings'><thead><tr><th>Id</th><th>Server</th><th>Track</th><th>Hours/Laps/Mins</th><th>Weather</th><th>Wind</th><th>Created on</th><th>Type</th></tr></thead><tbody>";
    while ($row = mysql_fetch_array($session_search2)) {
        echo "<tr>";
        echo "<td>" . $row['id'] . "</td><td>" . $row['server'] . "</td><td>" . $row['track'] .
            "</td><td>";
        if ($row['type'] == "prac") {
            echo "practice";
        } elseif ($row['laps'] < 100 && $row['type'] == "qual") {
            echo $row['laps'] . " mins";
        } elseif ($row['laps'] < 100) {
            echo $row['laps'] . " laps";
        } elseif ($row['laps'] <= 190) {
            echo ($row['laps'] - 100) * 10 + 100 . " laps";
        } else {
            echo $row['laps'] - 190 . " hours";
        }
        echo "</td><td>" . $row['weather'] . "</td><td>" . $row['wind'] . "</td><td>" .
            date("l, F jS Y \a\\t G:i O", $row['created_on']) . "</td><td>" . $row['type'] .
            "</td>";
        echo "</tr>";
    }

    echo "</tbody></table>";
}
?>
</div></div>
</body>
</html>
