diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index cc7bcf0..6c0ed8b 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -19,19 +19,20 @@ class ControllerAdminAdministrators session_start(); try { - if($_SESSION["idAdminConnected"] != null){ - $this->twig =$twig; + if ($_SESSION["idAdminConnected"] != null) { + $this->twig = $twig; $this->vues = $vues; - + $this->mdAdministrator = new ModelAdministrator(); - + $administrators = $this->mdAdministrator->getAdministrators(); - + echo $twig->render($vues["adminAdministrators"], [ 'administrators' => $administrators, + 'error' => $_SESSION["error"], ]); - } - else { + $_SESSION["error"] = null; + } else { header("Location:/loginAdmin"); } } catch (PDOException $e) { @@ -41,27 +42,40 @@ class ControllerAdminAdministrators } } - function delete($param) { + function delete($param) + { $this->mdAdministrator->deleteAdministratorByID($param["id"]); header("Location:/admin/administrators"); } - function add($param) { - - $username = $_POST['username']; - $password = $_POST['password']; - - $Admin = [ - 'username' => $username, - 'password' => $password, - ]; - - $this->mdAdministrator->addAdministrator($Admin); - - header("Location:/admin/administrators"); + function add($param) + { + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + $_SESSION["error"]="Méthode non autorisée."; + } else { + $username = $_POST['username']; + $password = $_POST['password']; + $username = trim($_POST['username']); + $password = trim($_POST['password']); + if (!isset($username) || !isset($password) || empty($username) || empty($password)) { + $_SESSION["error"]="Veuillez remplir tous les champs."; + } else { + $Admin = [ + 'username' => $username, + 'password' => $password, + ]; + if ($this->mdAdministrator->verifyAdministratorByName($Admin) != null) { + $_SESSION["error"]="Cet admin existe déjà."; + } else { + $this->mdAdministrator->addAdministrator($Admin); + header("Location:/admin/administrators"); + } + } + } } - function updatemodal($param) { + function updatemodal($param) + { $administrator = $this->mdAdministrator->getAdministratorByID($param["id"]); @@ -70,7 +84,8 @@ class ControllerAdminAdministrators ]); } - function update($param) { + function update($param) + { $id = $_POST['id']; $username = $_POST['username']; @@ -81,8 +96,8 @@ class ControllerAdminAdministrators 'password' => $password, ]; - $this->mdAdministrator->updateAdministrator($id,$Admin); + $this->mdAdministrator->updateAdministrator($id, $Admin); header("Location:/admin/administrators"); } -} \ No newline at end of file +} diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index d2aabb8..c4ab6cf 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -49,7 +49,9 @@ class ControllerUser function home() { - echo $this->twig->render($this->vues["home"]); + echo $this->twig->render($this->vues["home"], [ + 'idPlayerConnected' => $_SESSION["idPlayerConnected"] + ]); } function error() @@ -78,6 +80,10 @@ class ControllerUser function loginAdmin() { + if ($_SESSION["idAdminConnected"] != null){ + header("Location:/admin/administrators"); + } + echo $this->twig->render($this->vues["loginAdmin"], [ 'error' => $_SESSION["error"], ]); @@ -87,6 +93,10 @@ class ControllerUser function loginPlayer() { + if ($_SESSION["idPlayerConnected"] != null){ + header("Location:/userStatus"); + } + echo $this->twig->render($this->vues["loginPlayer"], [ 'error' => $_SESSION["error"], ]); @@ -94,6 +104,25 @@ class ControllerUser $_SESSION["error"] = ""; } + function userStatus(){ + if($_SESSION["idPlayerConnected"] != null){ + $this->mdPlayer = new ModelPlayer(); + $player = $this->mdPlayer->getPlayerByID($_SESSION["idPlayerConnected"]); + $maxscores = $this->mdPlayer->getMaxScoresWithChapter($player); + foreach ($maxscores as $maxscore) { + $maxscore["chapter"]=$this->mdChapter->getChapterByID($maxscore["idchapter"])->getName(); + } + echo $this->twig->render($this->vues["userStatus"], + [ + 'player' => $player, + 'maxscores' => $maxscores, + ]); + } + else { + header("Location:/loginPlayer"); + } + } + function verifyAdmin() { $username = $_POST['username']; @@ -258,21 +287,6 @@ class ControllerUser } } - function userStatus(){ - if($_SESSION["idPlayerConnected"] != null){ - - //$this->mdAdministrator = new ModelAdministrator(); - - //$administrators = $this->mdAdministrator->getAdministrators(); - - echo $this->twig->render($this->vues["userStatus"]); - - } - else { - header("Location:/loginPlayer"); - } - } - function passer() { $numQuestion = $_POST["numQuestion"]; diff --git a/Website/gateways/GatewayAdministrator.php b/Website/gateways/GatewayAdministrator.php index aa40056..ebc749f 100755 --- a/Website/gateways/GatewayAdministrator.php +++ b/Website/gateways/GatewayAdministrator.php @@ -87,6 +87,19 @@ class GatewayAdministrator ); $results = $this->con->getResults(); + return $results[0]; + } + public function verifyAdministratorByName($administrator) + { + $query = "SELECT administrators.id FROM administrators WHERE username = :username"; + $this->con->executeQuery( + $query, + array( + ':username' => array($administrator['username'], PDO::PARAM_STR), + ) + ); + $results = $this->con->getResults(); + return $results[0]; } } diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php index 608c5a5..dc032c2 100644 --- a/Website/gateways/GatewayJouer.php +++ b/Website/gateways/GatewayJouer.php @@ -71,4 +71,16 @@ class GatewayJouer $results = $this->con->getResults(); return $results[0]; } + public function getMaxScoresWithChapter($player) + { + $query = "SELECT maxscore,idchapter FROM jouer WHERE idplayer = :idplayer;"; + $this->con->executeQuery( + $query, + array( + ':idplayer' => array($player->getId(), PDO::PARAM_STR) + ) + ); + $results = $this->con->getResults(); + return $results; + } } \ No newline at end of file diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php index 33d14b0..aa6615a 100755 --- a/Website/gateways/GatewayPlayer.php +++ b/Website/gateways/GatewayPlayer.php @@ -93,7 +93,6 @@ class GatewayPlayer ) ); $results = $this->con->getResults(); - - return $results[0]; + return $results[0][0]; } } diff --git a/Website/models/ModelAdministrator.php b/Website/models/ModelAdministrator.php index 9d0b823..b0e2051 100644 --- a/Website/models/ModelAdministrator.php +++ b/Website/models/ModelAdministrator.php @@ -52,4 +52,9 @@ class ModelAdministrator $administratorsId = $this->gwAdministrator->verifyAdministrator($Administrator); return $administratorsId; } + public function verifyAdministratorByName($Administrator) + { + $administratorsId = $this->gwAdministrator->verifyAdministratorByName($Administrator); + return $administratorsId; + } } diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index b6d75fb..99a28d2 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -32,6 +32,7 @@ class ModelPlayer { $playerDataArray = $this->gwPlayer->getPlayerByID($id); $player = new Player($playerDataArray["id"], $playerDataArray["nickname"], $playerDataArray["password"]); + return $player; } public function updatePlayer($id, $player) @@ -60,6 +61,12 @@ class ModelPlayer $this->gwJouer->updateJouer($jouer); } + public function getMaxScoresWithChapter($player) + { + $maxScores = $this->gwJouer->getMaxScoresWithChapter($player); + return $maxScores; + } + public function verifyJouer($jouer) { $tabidjouer = $this->gwJouer->verifyJouer($jouer); diff --git a/Website/templates/addquestions.twig b/Website/templates/addquestions.twig index a6854eb..10dcc28 100644 --- a/Website/templates/addquestions.twig +++ b/Website/templates/addquestions.twig @@ -1,6 +1,5 @@ - diff --git a/Website/templates/adminAdministrators.twig b/Website/templates/adminAdministrators.twig index 228865d..a982a62 100644 --- a/Website/templates/adminAdministrators.twig +++ b/Website/templates/adminAdministrators.twig @@ -5,32 +5,33 @@ - - + - -
+ +
+ + Retour + +
+

Liste des administrators

-
- - +
+ ← Questions + + Chapitres →
diff --git a/Website/templates/adminChapters.twig b/Website/templates/adminChapters.twig index 934f0aa..10e4d53 100644 --- a/Website/templates/adminChapters.twig +++ b/Website/templates/adminChapters.twig @@ -6,31 +6,33 @@ - + - -
+ +
+ + Retour + +
+

Liste des chapitres

-
- - +
+ ← Administrateur + + Questions →
diff --git a/Website/templates/adminQuestions.twig b/Website/templates/adminQuestions.twig index 9faa79f..9d7e345 100644 --- a/Website/templates/adminQuestions.twig +++ b/Website/templates/adminQuestions.twig @@ -6,31 +6,33 @@ - + - -
+ + +

Liste des questions

-
- - +
+ ← Chapitres + + Administrateurs →
diff --git a/Website/templates/home.twig b/Website/templates/home.twig index 057f068..4bcb86c 100644 --- a/Website/templates/home.twig +++ b/Website/templates/home.twig @@ -10,7 +10,15 @@
- CONNEXION + {% if idPlayerConnected == null %} + + CONNEXION + + {% else %} + + PROFIL + + {% endif %}
@@ -21,7 +29,7 @@
- +

MULTIJOUEUR diff --git a/Website/templates/loginAdmin.twig b/Website/templates/loginAdmin.twig index 76b8f60..bf15da8 100644 --- a/Website/templates/loginAdmin.twig +++ b/Website/templates/loginAdmin.twig @@ -6,7 +6,12 @@ - + +
diff --git a/Website/templates/loginPlayer.twig b/Website/templates/loginPlayer.twig index 2d3cf8d..29d8a75 100644 --- a/Website/templates/loginPlayer.twig +++ b/Website/templates/loginPlayer.twig @@ -6,7 +6,12 @@ - + +
diff --git a/Website/templates/themeChoice.twig b/Website/templates/themeChoice.twig index ece9297..1619111 100644 --- a/Website/templates/themeChoice.twig +++ b/Website/templates/themeChoice.twig @@ -11,9 +11,11 @@ - - Retour - +

Difficulte :

diff --git a/Website/templates/userPlayerModal.twig b/Website/templates/userPlayerModal.twig index bc8013e..d2bfe8b 100644 --- a/Website/templates/userPlayerModal.twig +++ b/Website/templates/userPlayerModal.twig @@ -5,7 +5,6 @@ - diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 199b039..15c186d 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -1,16 +1,29 @@ - - Math'Educ + Maths Educ + + - + +
-
-

test

+
+

Player Nickname :

+

{{ player.nickname }}

+ {% for maxscore in maxscores %} +
+

Maxscore pour le chapitre {{ maxscore["chapter"] }} :

+

{{ maxscore["maxscore"] }}

+
+ {% endfor %} \ No newline at end of file