Ajout d'une page adminSolo + Page pour gérer les

enigme solo +
Modifcation d'un énigme sur le site +
Suppresion d'une énigme sur le site +
Modification de l'odre des énigmes (en cours) +
modification de la bd
ServeurDeTest
Noé GARNIER 2 years ago
parent 58ed04c563
commit 0ca3a99263

@ -1,6 +1,6 @@
<?php
//préfixe
$rep ='';
$rep = '';
// BD
$dsn = './scripted.db';
@ -20,6 +20,12 @@ $vues['next'] = 'View/src/pages/FirstTests/FirstTest';
$vues['admin'] = 'View/src/pages/Admin/Admin.php';
$vues['addEnigmeSolo'] = 'View/src/pages/Admin/AddEnigmeSolo.php';
$vues['enigmeMultiManager'] = 'View/src/pages/Admin/EnigmeMultiManager.php';
$vues['enigmeSoloManager'] = 'View/src/pages/Admin/EnigmeSoloManager.php';
$vues['detailEnigme'] = 'View/src/pages/Admin/DetailEnigme.php';
$vues['modifEnigmeSolo'] = 'View/src/pages/Admin/ModifEnigmeSolo.php';
$vues['adminSolo'] = 'View/src/pages/Admin/AdminSolo.php';
$vues['seeOrdre'] = 'View/src/pages/Admin/SeeOrdre.php';
$vues['modifOrdre'] = 'View/src/pages/Admin/ModifOrdre.php';
// Enigme
$vues['enigme'] = 'View/src/pages/Enigme/Palindrome.html';
$vues['enigmePage'] = 'View/src/pages/Enigme/EnigmePage.php';

@ -66,6 +66,30 @@ class AdminController extends UserController
case "goToEnigmeMultiManager":
$this->goToEnigmeMultiManager();
break;
case "goToEnigmeSoloManager":
$this->goToEnigmeSoloManager();
break;
case "goToDetailEnigme":
$this->goToDetailEnigme();
break;
case "goToModifEnigmeSolo":
$this->goToModifEnigmeSolo();
break;
case "goToAdminSolo":
$this->goToAdminSolo();
break;
case "goToSeeOrdre":
$this->goToSeeOrdre();
break;
case "goToModifOrdre":
$this->goToModifOrdre();
break;
case "editEnigme":
$this->editEnigme();
break;
case "deleteEnigme":
$this->deleteEnigme();
break;
default:
$error = "Action non valide";
require($rep . $vues['erreur']);
@ -111,6 +135,113 @@ class AdminController extends UserController
require($rep . $vues['erreur']);
}
}
public function goToEnigmeSoloManager()
{
try {
global $rep, $vues;
$model = new AdminModel();
$lesEnigmes = $model->getEnigmesSolo();
require($rep . $vues['enigmeSoloManager']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function goToDetailEnigme()
{
try {
global $rep, $vues;
$model = new AdminModel();
$enigme = $model->getEnigmeById($_GET['id']);
require($rep . $vues['detailEnigme']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function goToModifEnigmeSolo()
{
try {
global $rep, $vues;
$model = new AdminModel();
$enigme = $model->getEnigmeById($_GET['id']);
require($rep . $vues['modifEnigmeSolo']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function goToAdminSolo()
{
try {
global $rep, $vues;
require($rep . $vues['adminSolo']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function goToSeeOrdre()
{
try {
global $rep, $vues;
$model = new AdminModel();
$lesEnigmes = $model->getEnigmesSolo();
require($rep . $vues['seeOrdre']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function goToModifOrdre()
{
try {
global $rep, $vues;
$model = new AdminModel();
$lesEnigmes = $model->getEnigmesSolo();
require($rep . $vues['modifOrdre']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function editEnigme()
{
try{
global $rep, $vues;
$model = new AdminModel();
$id = $_GET['id'];
$nom = $_POST['nom'];
$enonce = $_POST['enigme'];
$aide = $_POST['aide'];
$rappel = $_POST['rappel'];
$exemple = $_POST['exemple'];
$test = $_POST['test'];
$solution = $_POST['solution'];
$prompt = $_POST['prompt'];
$enigme = $model->editEnigme($id, $nom, $enonce, $aide, $rappel, $exemple, $test, $solution, $prompt);
echo '<script>alert("L\'énigme a bien été modifier.");</script>';
require($rep . $vues['detailEnigme']);
}
catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function deleteEnigme(){
try{
global $rep, $vues;
$model = new AdminModel();
$id = $_GET['id'];
$model->deleteEnigme($id);
echo '<script>alert("L\'énigme a bien été supprimé.");</script>';
$this->goToEnigmeSoloManager();
}
catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);
}
}
public function addNewEnigmeSolo()
{
@ -138,7 +269,8 @@ class AdminController extends UserController
$exemple = "Il n'y a pas d'exemple pour cette énigme";
}
$enigme = $model->addNewEnigmeSolo($nom, $enonce, $aide, $rappel, $exemple, $test, $solution, $prompt);
require($rep . $vues['enigmePage']);
echo '<script>alert("L\'énigme a bien été ajouté.");</script>';
require($rep . $vues['adminSolo']);
} catch (Exception $e) {
$error = $e->getMessage();
require($rep . $vues['erreur']);

@ -51,6 +51,26 @@ class EnigmeGateway
));
}
// function that upadate enigme in database
public function update(Enigme $enigme)
{
$query = "UPDATE Enigme SET nom=:nom, enonce=:enonce, aide=:aide, rappel=:rappel, exemple=:exemple, solution=:solution, test=:test, ordre=:ordre, tempsDeResolution=:tempsDeResolution, points=:points, prompt=:prompt WHERE id=:id";
$this->con->executeQuery($query, array(
':id' => array($enigme->getIdEnigme(), SQLITE3_INTEGER),
':nom' => array($enigme->getNom(), SQLITE3_TEXT),
':enonce' => array($enigme->getEnonce(), SQLITE3_TEXT),
':aide' => array($enigme->getAide(), SQLITE3_TEXT),
':rappel' => array($enigme->getRappel(), SQLITE3_TEXT),
':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),
':prompt' => array($enigme->getPrompt(), SQLITE3_TEXT)
));
}
/**
* It deletes a row from the table Enigme where the idEnigme is equal to the idEnigme passed as a
* parameter
@ -59,7 +79,7 @@ class EnigmeGateway
*/
public function delete(string $idEnigme)
{
$query= "DELETE FROM Enigme WHERE idEnigme=:idEnigme";
$query= "DELETE FROM Enigme WHERE id=:idEnigme";
$this->con->executequery($query, array(
':idEnigme' => array($idEnigme,SQLITE3_INTEGER)
));

@ -24,7 +24,6 @@ class AdminModel
}
$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)) {
@ -44,4 +43,43 @@ async function submit(){
}
return $tabEnigme[0];
}
public function deleteEnigme(int $id) : void
{
$nom = $this->enigme_gateway->findById($id)[0]->getNom();
$this->enigme_gateway->delete($id);
unlink('View/src/JS/'.$nom.'.js');
}
public function getEnigmesSolo() : array
{
return $this->enigme_gateway->findSoloEnigma();
}
public function getEnigmeById (int $id) : Enigme
{
return $this->enigme_gateway->findById($id)[0];
}
public function editEnigme(int $id, string $nom,string $enonce,string $aide,string $rappel,string $exemple,string $test,string $solution, string $prompt) : Enigme
{
$ordre = $this->enigme_gateway->findById($id)[0]->getOrdre();
$enigme = new Enigme($id,$nom, $enonce, $aide, $rappel, $exemple, $solution, $test, $ordre, 0, 0, $prompt);
$this->enigme_gateway->update($enigme);
$js = fopen("View/src/JS/$nom.js", "w");
if (is_resource($js)) {
fwrite($js, "//~ Function that test the user code
async function submit(){
var test = editor.getValue()+`\\n\n". $solution . "\n". $test . "\n`;
exec(\"print ('True')\", \"code\");
exec(test, \"solution\");
result.innerHTML = \"Test en cours...\";
await new Promise(r => setTimeout(r, 1500));
check();
}");
fclose($js);
} else {
throw new Exception("Impossible d'ouvrir le fichier");
}
return $enigme;
}
}

@ -1,8 +1,7 @@
//~ Function that test the user code
async function submit(){
var test = editor.getValue()+`\n
import random as r
def chouetteVerif(valeur):
res=list()
for i in range(1, 7):
@ -11,7 +10,7 @@ def chouetteVerif(valeur):
if (i+j+k) == valeur:
res.append([i, j, k])
return res
import random as r
def test_chouette(n):
chouette(1)
listTest=[]
@ -23,11 +22,10 @@ def test_chouette(n):
return True
print(test_chouette(5))
`;
`;
exec("print ('True')", "code");
exec(test, "solution");
result.innerHTML = "Test en cours...";
await new Promise(r => setTimeout(r, 1500));
check();
}
}

@ -57,7 +57,7 @@
<a
id="enigmeSoloManager"
class="mb-3 text-uppercase text-center d-flex justify-content-center align-items-center"
href="index.php?action=goToAddEnigmeSolo"
href="index.php?action=goToAdminSolo"
style="width: 300px; height: 150px"
>
Gestion Enigme Solo

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<h1 class="text-center">Enigme Solo</h1>
<div class="d-flex justify-content-center">
<a class="btn btn-primary m-3" href="index.php?action=goToAddEnigmeSolo">Ajouter une enigme</a>
<a class="btn btn-primary m-3" href="index.php?action=goToEnigmeSoloManager">Gérer les enigmes</a>
</div>
</div>
</body>

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Enigme</h1>
</div>
</div>
<div class="row">
<div class="col">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Champ</th>
<th scope="col">Donnée</th>
</tr>
</thead>
<tbody><tr>
<td>Ordre</td>
<?php echo "<td>".$enigme->getOrdre()."</td>"; ?>
</tr>
<tr>
<td>Nom</td>
<?php echo "<td>".$enigme->getNom()."</td>"; ?>
</tr>
<tr>
<td>Enonce</td>
<?php echo "<td>".$enigme->getEnonce()."</td>"; ?>
</tr>
<tr>
<td>Aide</td>
<?php echo "<td>".$enigme->getAide()."</td>"; ?>
</tr>
<tr>
<td>Rappel</td>
<?php echo "<td>".$enigme->getRappel()."</td>"; ?>
</tr>
<tr>
<td>Exemple</td>
<?php echo "<td>".$enigme->getExemple()."</td>"; ?>
</tr>
<tr>
<td>Solution</td>
<?php echo "<td>".$enigme->getSolution()."</td>"; ?>
</tr>
<tr>
<td>Test</td>
<?php echo "<td>".$enigme->getTest()."</td>"; ?>
</tr>
<tr>
<td>Prompt</td>
<?php echo "<td>".$enigme->getPrompt()."</td>"; ?>
</tr>
<tr>
<td>Modifier</td>
<?php echo "<td><a href=\"index.php?action=goToModifEnigmeSolo&id=".$enigme->getIdEnigme()."\">Modifier</a></td>"; ?>
</tr>
<tr>
<td>Supprimer</td>
<?php echo "<td><a href=\"index.php?action=deleteEnigme&id=".$enigme->getIdEnigme()."\">Supprimer</a></td>"; ?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>

@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<h1 class="text-center">Enigme Solo Manager</h1>
<div class="d-flex justify-content-center">
<a class="btn btn-primary m-3" href="index.php?action=goToSeeOrdre" role="button">Modifier l'ordre</a>
<?php
foreach ($lesEnigmes as $enigme){
echo "<a class=\"btn btn-primary m-3\" href=\"index.php?action=goToDetailEnigme&id=".$enigme->getIdEnigme()."\" role=\"button\">".$enigme->getNom() ."</a>";
}
?>
</div>
</div>
</body>

@ -0,0 +1,77 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body class="m-3">
<form
<?php echo 'action="index.php?action=editEnigme&id='. $enigme->getIdEnigme() .'"'; ?>
method="POST">
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Nom</label>
<textarea class="form-control" name="nom" id="nom" rows="3" required><?php echo $enigme->getNom(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Enigme</label>
<textarea class="form-control" name="enigme" id="enigme" rows="3" required><?php echo $enigme->getEnonce(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Rappel</label>
<textarea class="form-control" name="rappel" id="rappel" rows="3"><?php echo $enigme->getRappel(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Aide</label>
<textarea class="form-control" name="aide" id="aide" rows="3"><?php echo $enigme->getAide(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Exemple</label>
<textarea class="form-control" name="exemple" id="exemple" rows="3"> <?php echo $enigme->getExemple(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Solution</label>
<textarea class="form-control" name="solution" id="solution" rows="3" required><?php echo $enigme->getSolution(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Test</label>
<textarea class="form-control" name="test" id="test" rows="3" required> <?php echo $enigme->getTest(); ?></textarea>
</div>
</div>
<div class="col">
<div class="mb-3">
<label for="" class="form-label">Prompt, ce qu'il sera écrit par défaut dans l'éditeur</label>
<textarea class="form-control" name="prompt" id="prompt" rows="3" required><?php echo $enigme->getPrompt(); ?></textarea>
</div>
</div>
<button class="left" type="submit">
Submit
</button>
</form>
</body>

@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Ordre des énigmes</h1>
</div>
</div>
<div class="row">
<div class="col">
<form action="" method="POST">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Enigme</th>
<th scope="col">Ordre</th>
</tr>
</thead>
<tbody>
<?php
foreach ($lesEnigmes as $enigme) {
echo "<tr>";
echo "<td>".$enigme->getNom()."</td>";
echo '<td><input type="number" name="ordre'. $enigme->getNom() .'" value="'. $enigme->getOrdre() .'"></td>';
echo "</tr>";
}
?>
</tbody>
</table>
<button class="btn btn-primary m-3" type="submit">
Modifier
</button>
</form>
</div>
</div>
</div>
</body>

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Admin</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<!-- CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU"
crossorigin="anonymous"
/>
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h1>Ordre des énigmes</h1>
</div>
</div>
<div class="row">
<div class="col">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Enigme</th>
<th scope="col">Ordre</th>
</tr>
</thead>
<tbody>
<?php
foreach ($lesEnigmes as $enigme) {
echo "<tr>";
echo "<td>".$enigme->getNom()."</td>";
echo "<td>".$enigme->getOrdre()."</td>";
echo "</tr>";
}
?>
<tr>
<td>Modifier</td>
<?php echo '<td><a href="index.php?action=goToModifOrdre">Modifier</a></td>'; ?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>

@ -26,7 +26,7 @@ rappel varchar(250),
exemple varchar(250),
solution varchar(250) NOT NULL,
test varchar(250) NOT NULL,
ordre integer CHECK (ordre >=-1),
ordre integer UNIQUE CHECK (ordre >=-1),
tempsDeResolution numeric CHECK (tempsDeResolution >=0),
points numeric CHECK (points >=0),
prompt varchar(250)

Loading…
Cancel
Save