diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 190e415e..f6e20dce 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -3,8 +3,8 @@ $rep =''; // BD -$dsn = './scripted.db'; -// $dsn = 'C:\\wamp64\\www\\scripted.db'; +// $dsn = './scripted.db'; +$dsn = 'C:\\wamp64\\www\\scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/WEB/Controller/AdminController.php b/WEB/Controller/AdminController.php index eaeb780c..cb8649ef 100644 --- a/WEB/Controller/AdminController.php +++ b/WEB/Controller/AdminController.php @@ -124,19 +124,20 @@ class AdminController extends UserController $exemple = $_POST['exemple']; $test = $_POST['test']; $solution = $_POST['solution']; + $prompt = $_POST['prompt']; if (empty($nom) || empty($enonce) || empty($test) || empty($solution)) { throw new Exception("Les champs nom, enigme, test et solution doivent être remplis"); } - if (empty($aide)){ + if (empty($aide)) { $aide = "Il n'y a pas d'aide pour cette énigme"; } - if (empty($rappel)){ + if (empty($rappel)) { $rappel = "Il n'y a pas de rappel pour cette énigme"; } - if (empty($exemple)){ + if (empty($exemple)) { $exemple = "Il n'y a pas d'exemple pour cette énigme"; } - $enigme = $model->addNewEnigmeSolo($nom, $enonce, $aide, $rappel, $exemple, $test, $solution); + $enigme = $model->addNewEnigmeSolo($nom, $enonce, $aide, $rappel, $exemple, $test, $solution, $prompt); require($rep . $vues['enigmePage']); } catch (Exception $e) { $error = $e->getMessage(); diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 8887a53c..21f2e903 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -35,7 +35,7 @@ class EnigmeGateway */ public function insert(Enigme $enigme) { - $query = "INSERT INTO Enigme VALUES (NULL,:nom,:enonce,:aide,:rappel,:exemple,:solution,:test,:tempsDeResolution,:points)"; + $query = "INSERT INTO Enigme VALUES (NULL,:nom,:enonce,:aide,:rappel,:exemple,:solution,:test, :ordre,:tempsDeResolution,:points, :prompt)"; $this->con->executeQuery($query, array( ':nom' => array($enigme->getNom(), SQLITE3_TEXT), ':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT), @@ -44,8 +44,10 @@ class EnigmeGateway ':exemple' => array($enigme->getExemple(), SQLITE3_TEXT), ':solution' => array($enigme->getSolution(), SQLITE3_TEXT), ':test' => array($enigme->getTest(), SQLITE3_TEXT), + ':ordre' => array($enigme->getOrdre(), SQLITE3_INTEGER), ':tempsDeResolution' => array($enigme->getTempsDeResolution(), SQLITE3_INTEGER), - ':points' => array($enigme->getPoints(), SQLITE3_INTEGER) + ':points' => array($enigme->getPoints(), SQLITE3_INTEGER), + ':prompt' => array($enigme->getPrompt(), SQLITE3_TEXT) )); } @@ -129,6 +131,16 @@ class EnigmeGateway $tabEnigme=EnigmeFactory::create($results); return $tabEnigme; } + public function findByOrdre(int $ordre) : array + { + $query = "SELECT * FROM Enigme WHERE ordre = :ordre"; + $this->con->executequery($query,array( + ':ordre' => array($ordre,SQLITE3_INTEGER) + )); + $results = $this->con->getResults(); + $tabEnigme=EnigmeFactory::create($results); + return $tabEnigme; + } public function showAll(): void { $query = "SELECT * FROM Enigme"; diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 0e75c25f..522e8a00 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -35,7 +35,7 @@ class FrontController $_REQUEST['action'] = $action; new AdminController(); } else if (method_exists('AdminController', $action) == false) { - $error = "Action non valide " . $action; + $error = "Action non valide" . $action; require($rep . $view['erreur']); } else { //echo "action admin valide"; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index d7fdfec7..ae727ffb 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -24,7 +24,7 @@ class UserController case "goToTest": $this->goToTest(); break; - case "goToChouette" : + case "goToChouette": $this->goToChouette(); break; case "goToCesarEncrypt": @@ -33,10 +33,10 @@ class UserController case "goToCesarDecrypt": $this->goToCesarDecrypt(); break; - case "goToChuckNorris" : + case "goToChuckNorris": $this->goToChuckNorris(); break; - case "goToHanoi" : + case "goToHanoi": $this->goToHanoi(); break; case "goToTrianglePascal": @@ -96,12 +96,15 @@ class UserController $error = $e->getMessage(); require($rep . $vues['erreur']); } - } + } public function goToEnigme() { try { global $rep, $vues; - require($rep . $vues['enigme']); + $model = new UserModel(); + $ordre = $_REQUEST['ordre']; + $enigme = $model->getEnigmeByOrdre($ordre); + require($rep . $vues['enigmePage']); } catch (Exception $e) { $error = $e->getMessage(); require($rep . $vues['erreur']); @@ -167,7 +170,7 @@ class UserController require($rep . $vues['erreur']); } } - public function goToDoubleElement() + public function goToDoubleElement() { try { global $rep, $vues; @@ -183,7 +186,7 @@ class UserController global $rep, $vues, $error; $nettoyage = new Nettoyage(); $num = $nettoyage->cleanInt($_REQUEST['num']); - require($rep . $vues['next'].$num.".html"); + require($rep . $vues['next'] . $num . ".html"); } catch (Exception $e) { $error = "Erreur Inconnue"; require($rep . $vues['erreur']); @@ -191,7 +194,7 @@ class UserController } public function goToQueue() { - try { + try { global $rep, $vues, $error; //require($rep . $vues['Queue']); $model = new UserModel(); diff --git a/WEB/Factory/EnigmeFactory.php b/WEB/Factory/EnigmeFactory.php index 2ce602a1..cb0d3b2e 100644 --- a/WEB/Factory/EnigmeFactory.php +++ b/WEB/Factory/EnigmeFactory.php @@ -5,7 +5,8 @@ class EnigmeFactory{ $tabEnigme=array(); foreach($results as $row) { - $tabEnigme[]= new Enigme($row['id'],$row['nom'],$row['enonce'],$row['aide'],$row['rappel'],$row['exemple'],$row['solution'],$row['test'],$row['tempsDeResolution'],$row['points']); + $tabEnigme[]= new Enigme($row['id'],$row['nom'],$row['enonce'],$row['aide'],$row['rappel'], + $row['exemple'],$row['solution'],$row['test'],$row['ordre'],$row['tempsDeResolution'],$row['points'], $row['prompt']); } return $tabEnigme; } diff --git a/WEB/Metier/Enigme.php b/WEB/Metier/Enigme.php index e5dc3e1a..a07f2db9 100644 --- a/WEB/Metier/Enigme.php +++ b/WEB/Metier/Enigme.php @@ -10,8 +10,10 @@ class Enigme private string $exemple; private string $solution; private string $test; + private int $ordre; private int $tempsDeResolution; private int $points; + private string $prompt; /** * @param int $idEnigme @@ -22,10 +24,14 @@ class Enigme * @param string $exemple * @param string $solution * @param string $test + * @param int $ordre * @param int $tempsDeResolution * @param int $points + * @param string $prompt */ - public function __construct($idEnigme, $nom = "",$enonce = "", $aide = "", $rappel = "", $exemple = "",$solution = "", $test = "", $tempsDeResolution = 0, $points = 0) + public function __construct($idEnigme, $nom = "",$enonce = "", $aide = "", $rappel = "", + $exemple = "",$solution = "", $test = "", $ordre = -1, $tempsDeResolution = 0, $points = 0, + $prompt = "") { $this->idEnigme = $idEnigme; $this->nom = $nom; @@ -35,8 +41,10 @@ class Enigme $this->exemple = $exemple; $this->solution = $solution; $this->test = $test; + $this->ordre = $ordre; $this->tempsDeResolution = $tempsDeResolution; $this->points = $points; + $this->prompt = $prompt; } /** * @return int @@ -165,6 +173,14 @@ class Enigme { $this->test = $test; } + public function getOrdre(): int + { + return $this->ordre; + } + public function setOrdre(int $ordre): void + { + $this->ordre = $ordre; + } /** * @return int @@ -189,4 +205,13 @@ class Enigme { $this->points = $points; } + + public function getPrompt(): string + { + return $this->prompt; + } + public function setPrompt(string $prompt): void + { + $this->prompt = $prompt; + } } \ No newline at end of file diff --git a/WEB/Model/AdminModel.php b/WEB/Model/AdminModel.php index 1d74276c..6d10b579 100644 --- a/WEB/Model/AdminModel.php +++ b/WEB/Model/AdminModel.php @@ -14,10 +14,17 @@ class AdminModel $this->validation = new Validation(); } - public function addNewEnigmeSolo(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution) : Enigme + public function addNewEnigmeSolo(string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution, string $prompt) : Enigme { - $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test); + $last = $this->enigme_gateway->findLastEnigma(); + if ($last !== null){ + $ordre = $last[0]->getOrdre() + 1; + } else { + $ordre = 1; + } + $enigme = new Enigme(1,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt); $this->enigme_gateway->insert($enigme); + var_dump($enigme); $tabEnigme = $this->enigme_gateway->findLastEnigma(); $js = fopen("View/src/JS/$nom.js", "w"); if (is_resource($js)) { diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index b6b4c40a..e8c718eb 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -65,4 +65,13 @@ class UserModel $_SESSION['role'] = 'visitor'; header('Location: index.php'); } + + public function getEnigmeByOrdre(int $num) : Enigme + { + $tabEnigme = $this->enigme_gateway->findByOrdre($num); + if ($tabEnigme == null) { + throw new Exception("Enigme non trouvée"); + } + return $tabEnigme[0]; + } } \ No newline at end of file diff --git a/WEB/View/src/JS/chouette.js b/WEB/View/src/JS/chouette.js index a023c69f..58433f5c 100644 --- a/WEB/View/src/JS/chouette.js +++ b/WEB/View/src/JS/chouette.js @@ -10,8 +10,8 @@ def chouetteVerif(valeur): for k in range(j, 7): if (i+j+k) == valeur: res.append([i, j, k]) - return res - + return res + def test_chouette(n): chouette(1) listTest=[] diff --git a/WEB/View/src/JS/palindrome.js b/WEB/View/src/JS/palindrome.js index acdd8dc1..626552d0 100644 --- a/WEB/View/src/JS/palindrome.js +++ b/WEB/View/src/JS/palindrome.js @@ -2,13 +2,13 @@ async function submit(){ var test = editor.getValue()+`\n -import random as r def estPalindromeVerif(var): if(var == var[::-1]): return True else: return False +import random as r def testPalindrome(x): l=[1,2,3,2,1] if(estPalindrome(l)==False): diff --git a/WEB/View/src/pages/Admin/AddEnigmeSolo.php b/WEB/View/src/pages/Admin/AddEnigmeSolo.php index a9e09fc6..d9169459 100644 --- a/WEB/View/src/pages/Admin/AddEnigmeSolo.php +++ b/WEB/View/src/pages/Admin/AddEnigmeSolo.php @@ -63,6 +63,13 @@ +