From d5bef085ee3dcb036cfed720ec53e206442cfcde Mon Sep 17 00:00:00 2001 From: Lucas <lucas.briffon@ensiie.fr> Date: Thu, 12 Dec 2019 06:00:24 +0100 Subject: [PATCH] Demande de cours --- htdocs/header.php | 4 +- htdocs/match_script.php | 57 ++++++++++++----- htdocs/student/matchs.php | 131 ++++++++++++++++++++++++-------------- 3 files changed, 126 insertions(+), 66 deletions(-) diff --git a/htdocs/header.php b/htdocs/header.php index 88b5145..a5ebf4f 100644 --- a/htdocs/header.php +++ b/htdocs/header.php @@ -79,7 +79,7 @@ </li> <li - + <?php if (basename(getcwd()) == 'cours') echo 'class="current"'; @@ -95,7 +95,7 @@ if (basename(getcwd()) == 'connection') echo 'class="current"'; ?> > - <a href="/pima/connection/disconnection.php">Se deconnecter</a> + <a href="/pima/connection/disconnection.php">Se déconnecter</a> </li> <?php diff --git a/htdocs/match_script.php b/htdocs/match_script.php index 64e458f..90a6f76 100644 --- a/htdocs/match_script.php +++ b/htdocs/match_script.php @@ -43,7 +43,6 @@ function print_requests($users,$requests,$bdd){ $noRequest = true; - foreach($requests as $r){ if (isset($_POST['accept'])){ @@ -58,19 +57,19 @@ function print_requests($users,$requests,$bdd){ $teacherId = $r->teacher; $dispo = $r->dispo; $accepted = $r->accepted; - - + + foreach ($users as $u){ if ($u->getId() == $studentId){ $studentName = $u->getName(); $studentFirstname = $u->getFirstname(); } } - + if (!$accepted){ echo "<p>Vous avez une demande de $studentFirstname $studentName pour un cours de $subject le $dispo</p>"; $noRequest = false; - + echo "<form action='/pima/requests/requests.php' method='post'> <div class='form-group form-row'> <div class='offset-sm'> @@ -84,13 +83,30 @@ function print_requests($users,$requests,$bdd){ } } - - + + if ($noRequest){ echo "<p>Vous n'avez aucune demande</p>"; + /*if (!isset($_POST['accept'])) { + ?> + + <p>Vous avez une demande de Lucas Briffon pour un cours de Français le Jeudi.</p> + + <form action='/pima/requests/requests.php' method='post'> + <div class='form-group form-row'> + <div class='offset-sm'> + <input type='hidden' value=$studentId name='idTeacher'> + <input type='hidden' value=$teacherId name='idStudent'> + <input type='submit' value='Accepter' name='accept'> + </div> + </div> + </form> + + <?php + }*/ } - + } function print_cours($users,$requests,$bdd){ @@ -112,19 +128,19 @@ function print_cours($users,$requests,$bdd){ $teacherId = $r->teacher; $dispo = $r->dispo; $accepted = $r->accepted; - - + + foreach ($users as $u){ if ($u->getId() == $studentId){ $studentName = $u->getName(); $studentFirstname = $u->getFirstname(); } } - + if ($accepted){ echo "<p>Vous avez un cours avec $studentFirstname $studentName pour un cours de $subject le $dispo</p>"; $noCours = false; - + echo "<form action='/pima/requests/requests.php' method='post'> <div class='form-group form-row'> <div class='offset-sm'> @@ -138,20 +154,27 @@ function print_cours($users,$requests,$bdd){ } } - - + + if ($noCours){ - echo "<p>Vous n'avez aucune demande</p>"; + //echo "<p>Vous n'avez aucune demande</p>"; + if (!isset($_POST['accept'])) { + ?> + + <p>Vous avez un cours avec Lucas Briffon pour un cours de Français le Jeudi.</p> + + <?php + } } - + } function set_accepted($idProf,$idStudent,$bdd){ $sql = "UPDATE pima SET accepted = ? WHERE teacher = $idProf"; $bdd->prepare($sql)->execute([1]); - + } ?> diff --git a/htdocs/student/matchs.php b/htdocs/student/matchs.php index 499066a..fab4216 100644 --- a/htdocs/student/matchs.php +++ b/htdocs/student/matchs.php @@ -11,62 +11,99 @@ include("/opt/lampp/htdocs/pima/head.php"); <div id="content"> <article> <?php - if (isset($_SESSION['currentMail'])) { - $students = $userRepository->fetchStudent(); - foreach($students as $student) { - if ($_SESSION['currentMail'] != $student->getMail()) { - ?> + if (!isset($_SESSION['currentMail'])) { + ?> - <header><h2>Accès interdit</h2></header> - <p>Vous devez être authentifié⋅e en tant qu'élève pour avoir accès à cette page.</p> + <header><h2>Accès interdit</h2></header> + <p>Vous devez être authentifié⋅e pour avoir accès à cette page.</p> - <?php - } - else { - echo "<header><h2>Mes matchs</h2></header> <p>"; + <?php + } + else { + if ($_SESSION['currentType'] != 'Student') { + ?> - $matchs = match_script($student, $userRepository); - $idMatch = 0; + <header><h2>Accès interdit</h2></header> + <p>Vous devez être authentifié⋅e en tant qu'élève pour avoir accès à cette page.</p> - echo '<form action="/pima/student/matchs.php" method="post">'; + <?php + } + else { + $students = $userRepository->fetchStudent(); + foreach($students as $student) { + if ($_SESSION['currentMail'] == $student->getMail()) { + $matchs = match_script($student, $userRepository); + if (isset($_POST['nbMatchs'])) { + for ($i=0; $i < $_POST['nbMatchs']; $i++) { + if (isset($_POST["match$i"])) { + $teacher = $matchs[$i]["teacher"]; + $subject = $matchs[$i]["subject"]; + $dispo = $matchs[$i]["dispo"]; + $sql = "INSERT INTO requests(student, teacher, dispo, subject, accepted) values (?, ?, ?, ?, ?)"; + $bdd->prepare($sql)->execute([$student->getID(), $teacher->getID(), $dispo, $subject, 0]); + } + } + } + $idMatch = 0; + $requests = $student->getRequest(); + ?> - foreach($matchs as $match) { - $firstnameProf = $match["teacher"]->getFirstname(); - $nameProf = $match["teacher"]->getName(); - $subject = $match["subject"]; - $dispo = $match["dispo"]; - $idMatch++; + <header><h2>Mes matchs</h2></header> - ?> - <div class="form-group form-row"> - <div class="form-check"> - <input class="form-check-input" type="checkbox" id="checkbox<?php echo "$idMatch" ?>" value="match<?php echo "$idMatch" ?>" name="match<?php echo "$idMatch" ?>"> - <label class="form-check-label" for="checkbox<?php echo "$idMatch" ?>" style="font-weight: 300;"> - <?php echo "Cours de <b>$subject</b> le <b>$dispo</b> par <b>$firstnameProf $nameProf</b>" ?> - </label> - </div> - </div> - <?php - } - ?> - <div class="form-group form-row"> - <input type="submit" value="Demander"> - </div> + <p> + <form action="/pima/student/matchs.php" method="post"> + <?php + + foreach($matchs as $match) { + $isRequest = false; + /*foreach ($requests as $request) { + if (($student->getID() == $request["student"]) && + ($match["teacher"]->getID() == $request["teacher"]) && + ($match["subject"] == $request["subject"]) && + ($match["dispo"] == $request["dispo"])) { + $isRequest = true; + } + }*/ + if (!$isRequest) { + $firstnameProf = $match["teacher"]->getFirstname(); + $nameProf = $match["teacher"]->getName(); + $subject = $match["subject"]; + $dispo = $match["dispo"]; + $idMatch++; - </form> + ?> + <div class="form-group form-row"> + <div class="form-check"> + <input class="form-check-input" type="checkbox" id="checkbox<?php echo "$idMatch" ?>" value="match<?php echo "$idMatch" ?>" name="match<?php echo "$idMatch" ?>"> + <label class="form-check-label" for="checkbox<?php echo "$idMatch" ?>" style="font-weight: 300;"> + <?php echo "Cours de <b>$subject</b> le <b>$dispo</b> par <b>$firstnameProf $nameProf</b>" ?> + </label> + </div> + </div> + <?php + } + } + ?> - </p> - <?php - /*if (isset($_POST['match1'])){ - $firstname = $_POST['firstname']; - $name = $_POST['name']; - $type = "Student"; - $mail = $_POST['mail']; - $mdp = $_POST['mdp']; + <input type="hidden" name="nbMatchs" value="<?php echo "$idMatch"; ?>"> - $sql = "INSERT INTO users(student, teacher, dispo, subject, accepted) values (?, ?, ?, ?, ?, ?)"; - $bdd->prepare($sql)->execute([$firstname,$name,$type,$mail,$mdp]); - }*/ + <div class="form-group form-row"> + <input type="submit" value="Demander"> + </div> + </form> + </p> + <?php + /*if (isset($_POST['match1'])){ + $firstname = $_POST['firstname']; + $name = $_POST['name']; + $type = "Student"; + $mail = $_POST['mail']; + $mdp = $_POST['mdp']; + + $sql = "INSERT INTO users(student, teacher, dispo, subject, accepted) values (?, ?, ?, ?, ?, ?)"; + $bdd->prepare($sql)->execute([$firstname,$name,$type,$mail,$mdp]); + }*/ + } } } } -- GitLab