<?php

//This is the main script, present this to the public internet
include 'config.php';
include 'technika.class.php';
$Technika = new Technika($_config['mysql_server'], $_config['mysql_user'], $_config['mysql_pass'], $_config['mysql_db']);
?>

<html>
<head>
    <title>Crew Race Simulator</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php 
$Technika->load_songs();
$Technika->gui_race();
?>
</body>
</html>
<?php

//This script, ideally, should be moved out of the public web area, and run via cron
include 'config.php';
include 'technika.class.php';
header('Content-type: text/plain');
$Technika = new Technika($_config['mysql_server'], $_config['mysql_user'], $_config['mysql_pass'], $_config['mysql_db']);
$Technika->startScrape();
$pagenum = 1;
$page = "http://www.djmaxcrew.com/crewrace/crewrace_ing.asp?page=";
for ($pagenum = 1; $pagenum < 10; $pagenum++) {
    $html = file_get_contents($page . $pagenum);
    // Specify configuration
    $config = array('indent' => true, 'output-xhtml' => true, 'wrap' => 200);
    // Tidy
    $tidy = new tidy();
    $tidy->parseString($html, $config, 'utf8');
    $tidy->cleanRepair();
    //Aplogies for this next block, its a mess, and hard to ever clean up
    $dom = new DOMDocument();
    $dom->loadHTML($tidy);
    $xml = simplexml_import_dom($dom);
    $base = $xml->body->table[1]->tr->td->table[1]->tr[1]->td->table->tr->td->table->tr->td[2]->table->tr[1]->td->table->tr->td->table->tr[1]->td->table;
    unset($base->tr[0]);
    $rows = sizeof($base->tr) / 3;
    for ($row = 0; $row < $rows; $row++) {
        $r1 = $base->tr[$row * 3];
        if ((string) $r1->td->span == "Group does not exist in the crew.") {
            die;
        }
        $r2 = $base->tr[$row * 3 + 1];