<?php

$isEditing = false;
if (isset($_POST["startMatch"])) {
    if ($_POST["startMatch"] == true) {
        $team1 = LeagueAnalysis::findTeam(intval($_POST["team1"]));
        $team2 = LeagueAnalysis::findTeam(intval($_POST["team2"]));
        $_SESSION["live"]->createMatch($team1, $team2);
        $team1Name = $team1->getName();
        $team2Name = $team2->getName();
        $currentMatch = $_SESSION["live"]->getCurrentMatch();
        $team1score = $currentMatch->getTeam1Score();
        $team2score = $currentMatch->getTeam2Score();
        $team1players = $team1->getPlayers();
        $team2players = $team2->getPlayers();
        $_SESSION["live"]->startMatch();
        $isEditing = true;
    }
}
if (isset($_POST["addActionTeam1"])) {
    $currentMatch = $_SESSION["live"]->getCurrentMatch();
    $team1score = $currentMatch->getTeam1Score();
    $team2score = $currentMatch->getTeam2Score();
    if ($_POST["addActionTeam1"] == 'g') {
        $_SESSION["live"]->shoots(intval($_POST["playerSel"]), true);
    }
    if ($_POST["addActionTeam1"] == 's') {
        $_SESSION["live"]->shoots(intval($_POST["playerSel"]), false);
    }
    if ($_POST["addActionTeam1"] == 'y') {
        $_SESSION["live"]->addInfraction(intval($_POST["playerSel"]), InfractionType::YELLOW_CARD);
                <thead class="thead nav-bg">
                <tr>
                    <th>ID</th>
                    <th>Player Name</th>
                    <th>Team</th>
                    <th># of goals</th>
                    <th># of infractions</th>
                </tr>
                </thead>
                <tbody>
                <?php 
for ($i = 0; $i < count($playersInLeague); ++$i) {
    $player = $playersInLeague[$i];
    $ID = $player->getPLAYER_ID();
    $name = $player->getPLAYER_NAME();
    $teamName = LeagueAnalysis::findTeam($player->getTeamID())->getName();
    $numGoals = $player->getNumGoalsScored();
    $numInfractions = $player->getNumYellowCards() + $player->getNumRedCards() + $player->getNumPenaltyKicks();
    ?>
                    <tr>
                        <th scope="row"><?php 
    echo $ID;
    ?>
</th>
                        <td><?php 
    echo $name;
    ?>
</td>
                        <td><?php 
    echo $teamName;
    ?>
}
if (isset($_POST["returnToLeague"])) {
    $isEditingTeams = false;
}
if (isset($_POST["deleteTeam"])) {
    $_SESSION["league"]->removeTeamFromLeague($_SESSION["currentTeamEdit"]->getTEAM_ID());
    $_SESSION["league"]->saveDataToDisk();
    loadData();
    $isEditingTeams = false;
}
if (isset($_POST["transfer"])) {
    $_SESSION["league"]->transferPlayer($_POST["transfer"], $_SESSION["currentTeamEdit"]->getTEAM_ID(), $_POST["teamToTransfer"]);
    $_SESSION["league"]->saveDataToDisk();
    loadData();
    $isEditingTeams = false;
    $_SESSION["currentTeamEdit"] = LeagueAnalysis::findTeam($_SESSION["currentTeamEditID"]);
}
?>

<?php 
if (!$isEditingTeams) {
    ?>
    <div class="row">
        <h2 class="text-center">League Editor</h2>
        <hr />
    </div>
    <div class="row p-t">
        <div class="col-md-5">
            <h4 class="text-center">Select a team to edit</h4>
            <hr />
            <form method="post">