<?php

require_once 'Matchup.inc.php';
if (isset($_POST["submit"])) {
    MUDebug($_POST);
    $match = new MUMatch();
    if ($match->createMatchesForFreeTournament($_POST["tournament_id"], $_POST["day"], $_POST["players"])) {
        $tournament = new MUTournaments();
        $type = $tournament->getType($_POST["tournament_id"]);
        header("location: match.php?tournament=" . $_POST["tournament_id"] . "&tipo=" . $type);
        exit;
    }
}
             echo "<td class='td'>" . $allMatches[$i]["casa"] . "</td>";
             echo "<td class='td'>" . $allMatches[$i]["trasferta"] . "</td>";
             echo "<td class='td'><form method='POST'>";
             echo "<input type='hidden' name='turno' value='" . $allMatches[$i]["giornata"] . "'/><input type='hidden' name='torneo_id' value='" . $allMatches[$i]["torneo"] . "'/><input type='hidden' name='match_id' value='" . $allMatches[$i]["ID"] . "'/><input type='text' placeholder='formato: 0-0' name='score' value='" . $allMatches[$i]["risultato"] . "'/></td>";
             echo "<td class='td'><input type='submit' name='aggiorna' value='Aggiorna' /></form></td>";
             echo "<td class='td'>" . $allMatches[$i]["vincitore"] . "</td></tr>";
         }
         echo "</table>";
     }
 } else {
     ?>
       <table class="table">
              
         <?php 
     $tournament = new MUTournaments();
     $type = $tournament->getType($_GET["tournament"]);
     if ($type === "libero") {
         ?>
             <tr><td class='td'>
                     Giornata
                 </td><td class='td'>
                     Casa
                 </td><td class='td'>
                     Risultato
                 </td><td class='td'>
                     Punti
                 </td></tr>
             <?php 
         $allMatches = $match->getAllMatchesFromFreeTournament($_GET["tournament"]);
         for ($i = 0; $i < count($allMatches); $i++) {
             echo "<tr><td class='td'>" . $allMatches[$i]["giornata"] . "</td>";