<?php

$db = new Mypdo();
$spectacleManager = new spectacleManager($db);
$listeSpectacles = $spectacleManager->listerSpectacles();
?>
<link rel="stylesheet" href="css/styleAdmin/styleFormSpectacle.css" />
<h1>Supprimer un spectacle</h1>
<?php 
if (!isset($_GET['numSpec'])) {
    ?>
  <table>
    <tr>
      <th>Titre du spectacle</th>
      <th>Supprimer</th>
    </tr>
    <?php 
    foreach ($listeSpectacles as $spectacle) {
        ?>
      <tr>
        <td><?php 
        echo $spectacle->getSpec_titre();
        ?>
</td>
        <td><a href="index.php?page=21&amp;numSpec=<?php 
        echo $spectacle->getSpec_id();
        ?>
"><img src="./images/erreur.png" /></a></td>
      </tr>

    <?php 
    <p class="pure-control-group">
      <label for="noteBas">Note du bas : </label>
      <input type="text" name="noteBas" required />
    </p>

    <p class="pure-control-group">
      <label for="Image">Charger une image : </label>
      <input type="file" name="img" required />
    </p>

    <p class="pure-control-group">
      <input type="submit" value="Envoyer" />
    </p>
  </form>
<?php 
} else {
    $spectacleManager = new spectacleManager($db);
    $titre = htmlspecialchars($_POST['titre']);
    $noteHaut = htmlspecialchars($_POST['noteHaut']);
    $description = htmlspecialchars($_POST['description']);
    $noteBas = htmlspecialchars($_POST['noteBas']);
    $img = htmlspecialchars($_POST['img']);
    $spectacleTab = array('titre_spectacle' => $titre, 'note_haut_spectacle' => $noteHaut, 'description' => $description, 'note_bas_spectacle' => $noteBas, 'image_spectacle' => $img);
    $spectacle = new Spectacle($spectacleTab);
    if ($spectacleManager->ajouterSpectacle($spectacle)) {
        ?>
<p><img src="./images/valid.png" alt="Valide" /> Spectacle bien ajouté !</p> <?php 
        header("refresh:2;url=index.php");
    }
}