<?php

require_once "../modeles/noter.php";
$noter = new Noter();
if (isset($_POST['note'])) {
    $note = $noter->getNoteUtilisateur(htmlspecialchars($_POST['idMovie']), htmlspecialchars($_POST['idUtilisateur']));
    if (!$note) {
        $noter->addNote(htmlspecialchars($_POST['idMovie']), htmlspecialchars($_POST['idUtilisateur']), htmlspecialchars($_POST['note']));
    } else {
        $noter->updateNote(htmlspecialchars($_POST['idMovie']), htmlspecialchars($_POST['idUtilisateur']), htmlspecialchars($_POST['note']));
    }
}
echo "<h4>Note du film : </h4>";
echo "<p>";
for ($i = 1; $i <= 5; $i++) {
    if ($i > $note) {
        echo "<span id='note" . $i . "' class='glyphicon glyphicon-star-empty' aria-hidden='true'></span> ";
    } else {
        echo "<span id='note" . $i . "' class='glyphicon glyphicon-star' aria-hidden='true'></span> ";
    }
}
echo "</p>";
?>
                        <h4>Votre note : </h4>
                        <p>
                        <?php 
echo "<p>";
$note = $noter->getNoteUtilisateur($_GET['id'], $_SESSION['utilisateur']['idUtilisateur']);
for ($i = 1; $i <= 5; $i++) {
    if ($i > $note) {
        echo "<span id='etoile" . $i . "' onclick='note(" . $i . "," . $_SESSION['utilisateur']['idUtilisateur'] . "," . $_GET['id'] . ")' class='glyphicon glyphicon-star-empty' aria-hidden='true'></span> ";
    } else {
        echo "<span id='etoile" . $i . "' onclick='note(" . $i . "," . $_SESSION['utilisateur']['idUtilisateur'] . "," . $_GET['id'] . ")' class='glyphicon glyphicon-star' aria-hidden='true'></span> ";
    }
}
echo "</p>";
?>
                        <p><a class="btn btn-primary btn-lg" href="http://localhost/mymovies-TyrkoDev/lib/administration.php" role="button"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Editer</a></p>
                    </div>
                </div>
                
            </div>
        </div>