diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 968e7f63..16c6853e 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -17,7 +17,7 @@ $vues['login'] = 'View/src/pages/LogSign/Login.php'; $vues['signUp'] = 'View/src/pages/LogSign/SignUp.php'; $vues['mail'] = 'View/src/pages/LogSign/Mail.php'; $vues['confirm'] = 'View/src/pages/LogSign/Confirm.php'; -$vues['test'] = 'View/src/pages/FirstTests/FirstTest1.html'; +$vues['test'] = 'View/src/pages/FirstTests/FirstTest1.php'; $vues['next'] = 'View/src/pages/FirstTests/FirstTest'; $vues['admin'] = 'View/src/pages/Admin/Admin.php'; $vues['addEnigmeSolo'] = 'View/src/pages/Admin/AddEnigmeSolo.php'; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 1883f360..3eecc8e1 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -44,6 +44,9 @@ class UserController case "saveCode": $this->saveCode(); break; + case "saveCodeInCookie": + $this->saveCodeInCookie(); + break; default: $error = "Action non valide"; require($rep . $vues['erreur']); @@ -142,7 +145,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 . ".php"); } catch (Exception $e) { $error = "Erreur Inconnue"; require($rep . $vues['erreur']); @@ -214,4 +217,18 @@ class UserController require($rep . $vues['erreur']); } } + public function saveCodeInCookie(){ + try { + global $rep, $vues, $error; + $model = new UserModel(); + $code = $_POST['code']; + $num = $_POST['num']; + setcookie("test".$num, $code, time() + 3600*24*365); + echo $code; + } + catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } + } } \ No newline at end of file diff --git a/WEB/View/src/JS/baseTest.js b/WEB/View/src/JS/baseTest.js new file mode 100644 index 00000000..63678324 --- /dev/null +++ b/WEB/View/src/JS/baseTest.js @@ -0,0 +1,155 @@ +function run() { + const terminal = document.getElementById("console"); + const runner = new BrythonRunner({ + stdout: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stderr: { + write(content) { + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + var code = editor.getValue(); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); + } + + function run_init() { + if (document.getElementById("console") != "") { + document.getElementById("console").innerHTML = ""; + } + run(); + } + + var editor = ace.edit("editor"); + editor.container.style.opacity = 0.85; + editor.setTheme("ace/theme/vibrant_ink"); + editor.getSession().setMode("ace/mode/python"); + editor.setFontSize("16px"); + editor.setOptions({ + enableLiveAutocompletion: true, + copyWithEmptySelection: true, + showGutter: true, + useWrapMode: true, // wrap text to view + indentedSoftWrap: false, + }); + + //Function that execute given code and return the result in a given element by id + + function exec(code, id) { + const terminal = document.getElementById("console"); + terminal.innerHTML = ""; + const runner = new BrythonRunner({ + stdout: { + write(content) { + if (id == "code") { + retourCode = content; + } + if (id == "solution") { + retourSolution = content; + } + }, + flush() {}, + }, + stderr: { + write(content) { + if (id == "solution") { + retourSolution = "ERROR"; + } + terminal.innerHTML += content; + terminal.scrollTop = terminal.scrollHeight; + }, + flush() {}, + }, + stdin: { + async readline() { + terminal.innerHTML += "\n"; + terminal.scrollTop = terminal.scrollHeight; + var userInput = prompt(); + return userInput; + }, + flush() {}, + }, + }); + runner.runCode(code); + setTimeout(() => { + runner.stopRunning(); + }, 10 * 1000); + } + + /** + * It checks if the code in the editor as the same result as the solution. + */ + function check() { + if (retourSolution == "ERROR") { + result.innerHTML = "Il semblerait qu'il y a une erreur dans ton code :/"; + } else if (retourSolution == retourCode) { + result.innerHTML = "Bien joué"; + document.getElementById("next").style.display = "flex"; + } else { + result.innerHTML = "Mauvaise réponse"; + } + } + + + + /** + * If the help is displayed, hide it. Otherwise, display it. + */ + function displayHelp() { + var help = document.getElementsByClassName("help"); + + if (help[0].style.display == "block") { + for (var i = 0; i < help.length; i++) { + help[i].style.display = "none"; + } + return; + } + + for (var i = 0; i < help.length; i++) { + help[i].style.display = "block"; + } + } + + function saveCode() { + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://localhost/Scripted/WEB/index.php?action=saveCodeInCookie', true); + // xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=saveCodeInCookie', true); + xhr.responseType = 'text'; + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onload = function () { + // console.log('saveCode'+xhr.responseText); + }; + var url = window.location.href; // récupère l'URL de la page + var elements = url.split("/"); // divise l'URL en un tableau de chaînes de caractères + var lastElement = elements.pop(); // récupère le dernier élément du tableau + if (lastElement == "index.php?action=goToTest") { + num = 1; + } + else { + var searchParams = new URLSearchParams(window.location.search); + var num = searchParams.get('num'); + } + xhr.send("code=" + editor.getValue() + "&num=" + num); + } + + document.getElementById ('editor').addEventListener('input', saveCode); + \ No newline at end of file diff --git a/WEB/View/src/pages/FirstTests/FirstTest1.html b/WEB/View/src/pages/FirstTests/FirstTest1.php similarity index 94% rename from WEB/View/src/pages/FirstTests/FirstTest1.html rename to WEB/View/src/pages/FirstTests/FirstTest1.php index d6d3ca50..0a9991cf 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest1.html +++ b/WEB/View/src/pages/FirstTests/FirstTest1.php @@ -103,7 +103,14 @@
-
print("Hello World !")
+
@@ -146,6 +153,6 @@ type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest10.html b/WEB/View/src/pages/FirstTests/FirstTest10.php similarity index 96% rename from WEB/View/src/pages/FirstTests/FirstTest10.html rename to WEB/View/src/pages/FirstTests/FirstTest10.php index 9e843212..18b61137 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest10.html +++ b/WEB/View/src/pages/FirstTests/FirstTest10.php @@ -108,8 +108,14 @@
-
def double_element(list): -
+
@@ -202,7 +208,7 @@ type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest2.html b/WEB/View/src/pages/FirstTests/FirstTest2.php similarity index 93% rename from WEB/View/src/pages/FirstTests/FirstTest2.html rename to WEB/View/src/pages/FirstTests/FirstTest2.php index 8311eb1a..acc7a3a5 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest2.html +++ b/WEB/View/src/pages/FirstTests/FirstTest2.php @@ -113,14 +113,21 @@
-
x = 1 -print("La varible 'x' :", x) +
+print("Le résultat de \'(x+2)*2\' :",x)'; + } + ?>
@@ -163,6 +170,6 @@ print("Le résultat de '(x+2)*2' :",x)
type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest3.html b/WEB/View/src/pages/FirstTests/FirstTest3.php similarity index 90% rename from WEB/View/src/pages/FirstTests/FirstTest3.html rename to WEB/View/src/pages/FirstTests/FirstTest3.php index aee00236..60b3fa28 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest3.html +++ b/WEB/View/src/pages/FirstTests/FirstTest3.php @@ -115,7 +115,12 @@
-
# Initialise une liste +
+# Ps l\'instruction \'len\' ne fonctionne pas que pour les listes +print("Longueur de la chaine de caractère \'toto\' :", len("toto"))'; + } + ?>
@@ -206,6 +213,6 @@ print("Longueur de la chaine de caractère 'toto' :", len("toto"))
type="text/javascript" charset="utf-8" > - + \ No newline at end of file diff --git a/WEB/View/src/pages/FirstTests/FirstTest4.html b/WEB/View/src/pages/FirstTests/FirstTest4.php similarity index 94% rename from WEB/View/src/pages/FirstTests/FirstTest4.html rename to WEB/View/src/pages/FirstTests/FirstTest4.php index 92638735..2124b901 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest4.html +++ b/WEB/View/src/pages/FirstTests/FirstTest4.php @@ -107,11 +107,17 @@
-
def say_somethings(message1, message2): +
+say_somethings("Hello", "World")'; + }?>
@@ -154,6 +160,6 @@ say_somethings("Hello", "World")
type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest5.html b/WEB/View/src/pages/FirstTests/FirstTest5.php similarity index 94% rename from WEB/View/src/pages/FirstTests/FirstTest5.html rename to WEB/View/src/pages/FirstTests/FirstTest5.php index 98947d0c..9aadb156 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest5.html +++ b/WEB/View/src/pages/FirstTests/FirstTest5.php @@ -97,11 +97,17 @@
-
def addition(a,b) : - return a+b +
+print(somme)'; + }?>
@@ -144,6 +150,6 @@ print(somme)
type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest6.html b/WEB/View/src/pages/FirstTests/FirstTest6.php similarity index 95% rename from WEB/View/src/pages/FirstTests/FirstTest6.html rename to WEB/View/src/pages/FirstTests/FirstTest6.php index 56cac282..3ebdd7b2 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest6.html +++ b/WEB/View/src/pages/FirstTests/FirstTest6.php @@ -97,8 +97,13 @@
-
def multiplication(a,b) : -
+
@@ -192,7 +197,7 @@ type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest7.html b/WEB/View/src/pages/FirstTests/FirstTest7.php similarity index 93% rename from WEB/View/src/pages/FirstTests/FirstTest7.html rename to WEB/View/src/pages/FirstTests/FirstTest7.php index 3cb5490c..ed8fc2d0 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest7.html +++ b/WEB/View/src/pages/FirstTests/FirstTest7.php @@ -107,13 +107,19 @@
-
a = 1; b = 2; +
b) : - print(a,"est plus grand que",b) + print(a,"est plus grand que",b) elif (a == b): - print("a et c sont éguax") + print("a et c sont éguax") else : - print(b,"est plus grand que",a)
+ print(b,"est plus grand que",a)'; + }?>
@@ -155,6 +161,6 @@ else : type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest8.html b/WEB/View/src/pages/FirstTests/FirstTest8.php similarity index 96% rename from WEB/View/src/pages/FirstTests/FirstTest8.html rename to WEB/View/src/pages/FirstTests/FirstTest8.php index acfbaedf..43d2a584 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest8.html +++ b/WEB/View/src/pages/FirstTests/FirstTest8.php @@ -113,8 +113,14 @@
-
def condition(list,a) : -
+
@@ -208,7 +214,7 @@ type="text/javascript" charset="utf-8" > - + diff --git a/WEB/View/src/pages/FirstTests/FirstTest9.html b/WEB/View/src/pages/FirstTests/FirstTest9.php similarity index 95% rename from WEB/View/src/pages/FirstTests/FirstTest9.html rename to WEB/View/src/pages/FirstTests/FirstTest9.php index 619643af..d006f721 100644 --- a/WEB/View/src/pages/FirstTests/FirstTest9.html +++ b/WEB/View/src/pages/FirstTests/FirstTest9.php @@ -121,35 +121,41 @@
-
list = [1, 2, 3, 4, 5] +
+ print(n)'; + }?>
@@ -191,6 +197,6 @@ for n in range(len("toto")): type="text/javascript" charset="utf-8" > - +