<?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
 **/
unset($bodypage);
$bodypage = "lapcharts";
include 'header.php';
if ($raceFocus == "driver") {
    if ($XMLRACE['numClasses'] > 1) {
        echo "<a class='" . strtolower($XMLTEAM[$j]['team_data']['class']) .
            "' href='team_" . $XMLTEAM[$j]['team_data']['number'] . ".html'><h3>#" . $XMLTEAM[$j]['team_data']['number'] .
            " " . $XMLTEAM[$j]['team_data']['class'] . " &mdash; " . $XMLTEAM[$j]['team_data']['drivers'][0]['driver_full'];
        echo $XMLTEAM[$j]['team_data']['name'] ? " &mdash; " . $XMLTEAM[$j]['team_data']['name'] :
            "";
        echo "</h3></a>";
    } else
        echo "<a href='team_" . $XMLTEAM[$j]['team_data']['number'] . ".html'><h3>#" . $XMLTEAM[$j]['team_data']['number'] .
            " " . $XMLTEAM[$j]['team_data']['drivers'][0]['driver_full'];
    echo $XMLTEAM[$j]['team_data']['name'] ? " &mdash; " . $XMLTEAM[$j]['team_data']['name'] :
        "";
    echo "</h3></a>";
} else {
    if ($XMLRACE['numClasses'] > 1) {
        echo "<a class='" . strtolower($XMLTEAM[$j]['team_data']['class']) .
            "' href='team_" . $XMLTEAM[$j]['team_data']['number'] . ".html'><h3>#" . $XMLTEAM[$j]['team_data']['number'] .
            " " . $XMLTEAM[$j]['team_data']['class'] . " &mdash; " . $XMLTEAM[$j]['team_data']['name'] .
            "</h3></a>";
    } else
        echo "<a href='team_" . $XMLTEAM[$j]['team_data']['number'] . ".html'><h3>#" . $XMLTEAM[$j]['team_data']['number'] .
            " " . $XMLTEAM[$j]['team_data']['name'] . "</h3></a>";
}

$unfiltered2 = "<table id='unfiltered' class='" . strtolower($XMLTEAM[$j]['team_data']['class']) .
    "'>";
$unfiltered2 .= "<thead>";
$unfiltered2 .= "<tr><th><span title='including laps added via penalty laps (not removed)'>Lap";
if ($XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] > 0) {
    $unfiltered2 .= " (+" . $XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] .
        " lap";
    $unfiltered2 .= ($XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] > 1) ? "s)" :
        ")";
}
if (!$standingStart) {
    $start = "<th>Since rolling start</th>";
    $startLap = 0;
} elseif (is_numeric($standingStart)) {
    $start = "<th>Since rolling start ($standingStart)</th>";
    $startLap = $standingStart - 1;
} elseif ($standingStart == "formation") {
    $start = "<th>Since formation lap</th>";
    $startLap = 0;
} else {
    $start = "<th>Since race start</th>";
}
$unfiltered2 .= "</span></th><th>Server Lap</th><th>Lap time</th><th>Username</th><th>Session time</th>$start<th>Since last lap</th></tr>";
$unfiltered2 .= "</thead>";
$unfiltered2 .= "<tbody>";
for ($i = 0; $i < $XMLTEAM[$j]['race_data']['laps']; $i++) {
    $unfiltered2 .= "<tr>";
    $unfiltered2 .= "<td>" . ($i + $XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] +
        1) . "</td>";
    $unfiltered2 .= "<td>" . $XMLTEAM[$j]['filter_laps'][$i]['lap'] . "</td>";
    $unfiltered2 .= "<td>" . normalTime($XMLTEAM[$j]['filter_laps'][$i]['laptime'], true, false, false) .
        "</td>";
    $unfiltered2 .= "<td>" . $XMLTEAM[$j]['filter_laps'][$i]['driverUserName'] .
        "</td>";
    $unfiltered2 .= "<td>" . normalTime($XMLTEAM[$j]['filter_laps'][$i]['sessiontime'], true, false, true, true, true, false, true) .
        "</td>";
    if ($i > $startLap && (!$standingStart || $standingStart == "formation" ||
        is_numeric($standingStart))) {
        $unfiltered2 .= "<td>" . normalTime(($XMLTEAM[$j]['filter_laps'][$i]['sessiontime'] -
            $XMLTEAM[$j]['filter_laps'][$startLap]['sessiontime']), false, false, true) .
            "</td>";
    } elseif (!$standingStart || $standingStart == "formation" || is_numeric($standingStart)) {
        $unfiltered2 .= "<td></td>";
    } else {
        $unfiltered2 .= "<td>" . normalTime(($XMLTEAM[$j]['filter_laps'][$i]['logged'] -
            $XMLRACE['race_start']) * 1000, false, false, true) . "</td>";
    }

    if ($i > $startLap && ($XMLTEAM[$j]['filter_laps'][$i]['sessiontime'] - $XMLTEAM[$j]['filter_laps'][$i -
        1]['sessiontime'] != $XMLTEAM[$j]['filter_laps'][$i]['laptime'])) {
        $unfiltered2 .= "<td><strong>" . normalTime(($XMLTEAM[$j]['filter_laps'][$i]['sessiontime'] -
            $XMLTEAM[$j]['filter_laps'][$i - 1]['sessiontime']), true, false, false) .
            "</strong></td>";
    } elseif ($i > $startLap) {
        $unfiltered2 .= "<td>" . normalTime(($XMLTEAM[$j]['filter_laps'][$i]['sessiontime'] -
            $XMLTEAM[$j]['filter_laps'][$i - 1]['sessiontime']), true, false, false) .
            "</td>";
    } else {
        $unfiltered2 .= "<td></td>";
    }
    $unfiltered2 .= "</tr>";
}
$unfiltered2 .= "</tbody></table>";

if ($XMLTEAM[$j]['raw_laps']) {
    $unfiltered1 = "<table id='unfiltered' class='" . strtolower($XMLTEAM[$j]['team_data']['class']) .
        "'>";
    $unfiltered1 .= "<thead>";
    $unfiltered1 .= "<tr><th><span title='including laps added via penalty laps (not removed)'>Lap";
    if ($XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] > 0) {
        $unfiltered1 .= " (+" . $XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] .
            " lap";
        $unfiltered1 .= ($XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] > 1) ? "s)" :
            ")";
    }
    if (!$standingStart) {
        $start = "<th>Since rolling start</th>";
        $startLap = 0;
    } elseif (is_numeric($standingStart)) {
        $start = "<th>Since rolling start ($standingStart)</th>";
        $startLap = $standingStart - 1;
    } elseif ($standingStart == "formation") {
        $start = "<th>Since formation lap</th>";
        $startLap = 0;
    } else {
        $start = "<th>Since race start</th>";
    }
    $unfiltered1 .= "</span></th><th>Server Lap</th><th>Lap time</th><th>Username</th><th>Session time</th>$start<th>Since last lap</th></tr>";
    $unfiltered1 .= "</thead>";
    $unfiltered1 .= "<tbody>";
    for ($i = 0; $i < $XMLTEAM[$j]['race_data']['laps']; $i++) {
        $unfiltered1 .= "<tr>";
        $unfiltered1 .= "<td>" . ($i + $XMLTEAM[$j]['race_data']['penalty_laps_teamstats'] +
            1) . "</td>";
        $unfiltered1 .= "<td>" . $XMLTEAM[$j]['raw_laps'][$i]['lap'] . "</td>";
        $unfiltered1 .= "<td>" . normalTime($XMLTEAM[$j]['raw_laps'][$i]['laptime'], true, false, false) .
            "</td>";
        $unfiltered1 .= "<td>" . $XMLTEAM[$j]['raw_laps'][$i]['driverUserName'] .
            "</td>";
        $unfiltered1 .= "<td>" . normalTime($XMLTEAM[$j]['raw_laps'][$i]['sessiontime'], true, false, true, true, true, false, true) .
            "</td>";
        if ($i > $startLap && (!$standingStart || $standingStart == "formation" ||
            is_numeric($standingStart))) {
            $unfiltered1 .= "<td>" . normalTime(($XMLTEAM[$j]['raw_laps'][$i]['sessiontime'] -
                $XMLTEAM[$j]['raw_laps'][$startLap]['sessiontime']), false, false, true) . "</td>";
        } elseif (!$standingStart || $standingStart == "formation" || is_numeric($standingStart)) {
            $unfiltered1 .= "<td></td>";
        } else {
            $unfiltered1 .= "<td>" . normalTime(($XMLTEAM[$j]['raw_laps'][$i]['logged'] - $XMLRACE['race_start']) *
                1000, false, false, true) . "</td>";
        }

        if ($i > $startLap && ($XMLTEAM[$j]['raw_laps'][$i]['sessiontime'] - $XMLTEAM[$j]['raw_laps'][$i -
            1]['sessiontime'] != $XMLTEAM[$j]['raw_laps'][$i]['laptime'])) {
            $unfiltered1 .= "<td><strong>" . normalTime(($XMLTEAM[$j]['raw_laps'][$i]['sessiontime'] -
                $XMLTEAM[$j]['raw_laps'][$i - 1]['sessiontime']), true, false, false) .
                "</strong></td>";
        } elseif ($i > $startLap) {
            $unfiltered1 .= "<td>" . normalTime(($XMLTEAM[$j]['raw_laps'][$i]['sessiontime'] -
                $XMLTEAM[$j]['raw_laps'][$i - 1]['sessiontime']), true, false, false) . "</td>";
        } else {
            $unfiltered1 .= "<td></td>";
        }
        $unfiltered1 .= "</tr>";
    }
    $unfiltered1 .= "</tbody></table>";
    echo $unfiltered1;
}
echo $unfiltered2;
include 'footer.php'; ?>