From 30054c6273f5d1129fc78ffb633b345a5dca3e86 Mon Sep 17 00:00:00 2001 From: Mehdi Date: Tue, 7 Jul 2020 06:33:30 +0200 Subject: [PATCH] correction avec plusieurs bdd sqlite + Timer + vue pour ajouter des consignes --- BddCorrect/Correcteur.php | 20 ++++----- BddCorrect/DAL/QuestionsGateway.php | 4 +- BddCorrect/SqliteDb.php | 58 +++++++++++++++++++----- BddCorrect/css/VueAdmin.css | 66 ++++++++++++++++++++++++++++ BddCorrect/index.php | 2 + BddCorrect/test.db | Bin 12288 -> 24576 bytes BddCorrect/vues/VueAdmin.php | 24 ++++++++++ BddCorrect/vues/VuePrincipale.php | 44 ++++++++++++++++--- 8 files changed, 189 insertions(+), 29 deletions(-) create mode 100644 BddCorrect/css/VueAdmin.css create mode 100644 BddCorrect/vues/VueAdmin.php diff --git a/BddCorrect/Correcteur.php b/BddCorrect/Correcteur.php index da1ec52..5c31cc6 100644 --- a/BddCorrect/Correcteur.php +++ b/BddCorrect/Correcteur.php @@ -24,7 +24,7 @@ foreach ($_POST['textbox'] as $textbox) { $UserQuery = oci_parse($conn, $textbox); $reponseUser = oci_execute($UserQuery); - $typeQuery = $db->prepare('SELECT type FROM Correct WHERE rowid = ?'); + $typeQuery = $db->prepare('SELECT type FROM Type WHERE numQuestion = ?'); $typeQuery->bindParam(1, $numQuestion); $resultType = $typeQuery->execute(); $typeRow = $resultType->fetchArray(); @@ -35,7 +35,8 @@ foreach ($_POST['textbox'] as $textbox) { if($typeRow['type'] == 'query'){ // - $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); + + $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE numquestion= ? '); $sqliteQuery->bindParam(1, $numQuestion); $result = $sqliteQuery->execute(); $sqliteRow = $result->fetchArray(); @@ -50,7 +51,6 @@ foreach ($_POST['textbox'] as $textbox) { while( ($oracleRow = oci_fetch_array($UserQuery, OCI_NUM)) && $err == 0 ){ $vraiReponseRow = oci_fetch_array($vraiReponse,OCI_NUM ); $verif = 1; - if(sizeof($oracleRow) == sizeof($vraiReponseRow)){ for($i=0 ; $i< sizeof($vraiReponseRow) ; $i++){ @@ -64,7 +64,8 @@ foreach ($_POST['textbox'] as $textbox) { $err = -2; break; } - } + } + //echo nl2br("\n ------------test : ".$err." test2 : ".$verif."\n"); // // @@ -103,8 +104,7 @@ foreach ($_POST['textbox'] as $textbox) { $vraiReponseRowRandom = oci_fetch_array($vraiReponseRandom,OCI_NUM ); $verif = 1; - if(sizeof($oracleRowRandom) == sizeof($vraiReponseRowRandom)){ - + if(sizeof($oracleRowRandom) == sizeof($vraiReponseRowRandom)){ for($i=0 ; $i< sizeof($vraiReponseRowRandom) ; $i++){ if($oracleRowRandom[$i] != $vraiReponseRowRandom[$i]){ $err = -1; @@ -118,7 +118,7 @@ foreach ($_POST['textbox'] as $textbox) { } } // - + //echo nl2br("\n ------------testerr : ".$err." test2verif : ".$verif."\n"); // if($err == 0 && $verif==1){ echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n"; @@ -130,14 +130,14 @@ foreach ($_POST['textbox'] as $textbox) { //si la question attend une modification else if($typeRow['type'] == 'tablemodification'){ - $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? '); + $sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE numquestion= ? '); $sqliteQuery->bindParam(1, $numQuestion); $result = $sqliteQuery->execute(); $sqliteRow = $result->fetchArray(); $vraiReponse = oci_parse($conn, $sqliteRow['reponse']); $enAttente = oci_execute($vraiReponse); - $sqliteQuery = $db->prepare('SELECT fonctioncorrect FROM Correct WHERE rowid= ? '); + $sqliteQuery = $db->prepare('SELECT fonctioncorrect FROM Correct WHERE numquestion= ? '); $sqliteQuery->bindParam(1, $numQuestion); $result = $sqliteQuery->execute(); $sqliteRow = $result->fetchArray(); @@ -165,7 +165,7 @@ foreach ($_POST['textbox'] as $textbox) { } //si la question attend un CREATE FUNCTION else{ - $fonctionQuery = $db->prepare('SELECT * FROM Correct WHERE rowid= ? '); + $fonctionQuery = $db->prepare('SELECT * FROM FunctionCorrect WHERE rowid= ? '); $fonctionQuery->bindParam(1, $numQuestion); $result = $fonctionQuery->execute(); $fonctionRow = $result->fetchArray(); diff --git a/BddCorrect/DAL/QuestionsGateway.php b/BddCorrect/DAL/QuestionsGateway.php index 961aa93..65b6e64 100644 --- a/BddCorrect/DAL/QuestionsGateway.php +++ b/BddCorrect/DAL/QuestionsGateway.php @@ -10,13 +10,13 @@ class QuestionsGateway { public function afficherQuestions() { $i = 0; - $query = 'SELECT * FROM Correct'; + $query = 'SELECT * FROM Correct UNION SELECT * FROM functionCorrect'; $query = $this->db->prepare($query); $result = $query->execute(); //$resultats = $this->db->query('SELECT found_rows()'); while($q = $result->fetchArray()){ $i= $i+1; - $tabQuestions[] = new Question($i,$q['question'],$q['reponse']); + $tabQuestions[] = new Question($q['numquestion'],$q['question'],$q['reponse']); } return $tabQuestions; } diff --git a/BddCorrect/SqliteDb.php b/BddCorrect/SqliteDb.php index 96f07f9..f2ef129 100644 --- a/BddCorrect/SqliteDb.php +++ b/BddCorrect/SqliteDb.php @@ -13,27 +13,44 @@ class SqliteDb extends SQLite3 function createTable(){ //Création De La Table $this->exec('DROP TABLE Correct'); - $this->exec('CREATE TABLE Correct ( question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)'); + $this->exec('CREATE TABLE Correct ( numquestion NUMBER,question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)'); + $this->exec('DROP TABLE FunctionCorrect'); + $this->exec('CREATE TABLE FunctionCorrect (numquestion NUMBER, question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)'); + + $this->exec('DROP TABLE TriggerCorrect'); + $this->exec('CREATE TABLE TriggerCorrect ( numquestion NUMBER,question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)'); + + $this->exec('DROP TABLE Type'); + $this->exec('CREATE TABLE Type ( numquestion NUMBER,type STRING)'); + + $this->exec("INSERT INTO Type VALUES(1,'query')"); + $this->exec("INSERT INTO Type VALUES(2,'query')"); + $this->exec("INSERT INTO Type VALUES(3,'query')"); + $this->exec("INSERT INTO Type VALUES(4,'query')"); + $this->exec("INSERT INTO Type VALUES(5,'query')"); + $this->exec("INSERT INTO Type VALUES(6,'functionCorrect')"); + + //Question 1 - $type = 'query'; + $type = 'query'; $fonctionCorrect = null; $testU = null; $reponse = 'SELECT count(*) FROM STATS WHERE prenomnoms=\'Kevin Durant\' '; - $q = "INSERT INTO Correct VALUES ('Trouver le nombre de matchs joués par Kevin Durant', ? ,?,?,?)"; + $q = "INSERT INTO Correct VALUES (1,'Trouver le nombre de matchs joués par Kevin Durant', ? ,?,?,?)"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); $stmt->bindParam(3,$fonctionCorrect); $stmt->bindParam(4,$testU); $stmt->execute(); - + //Question 2 $type = 'query'; $fonctionCorrect = null; $testU = null; $reponse = ' SELECT prenomnoms,datematch,points,equipeadverse FROM STATS WHERE points = (SELECT max(points) FROM STATS)'; - $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant marqué le plus de points dans la saison en indiquant son nom, la date du match, le nombre de points, l équipe adverse et le nombre de points marqués ', ? ,?,?,?)"; + $q = "INSERT INTO Correct VALUES (2,'Lister le(s) joueur(s) ayant marqué le plus de points dans la saison en indiquant son nom, la date du match, le nombre de points, l équipe adverse et le nombre de points marqués ', ? ,?,?,?)"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); @@ -46,7 +63,7 @@ class SqliteDb extends SQLite3 $fonctionCorrect = null; $testU = null; $reponse = ' SELECT prenomnoms, COUNT(*) FROM STATS GROUP BY prenomnoms HAVING count(*) = (SELECT MAX(c) FROM (SELECT COUNT(*) AS c FROM STATS GROUP BY prenomnoms))'; - $q = "INSERT INTO Correct VALUES ('Lister le(s) joueur(s) ayant joué le plus de match pendant la saison', ? ,?,?,?)"; + $q = "INSERT INTO Correct VALUES (3,'Lister le(s) joueur(s) ayant joué le plus de match pendant la saison', ? ,?,?,?)"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); @@ -59,7 +76,7 @@ class SqliteDb extends SQLite3 $fonctionCorrect = null; $testU = null; $reponse = 'SELECT nom FROM EQUIPE, STATS WHERE datematch = \'30-OCT-17\' AND prenomnoms = \'Kevin Durant\' AND idequipe = CASE WHEN locationjoueur = \'Away\' THEN equipeadverse WHEN locationjoueur = \'Home\' THEN equipejoueur END '; - $q = "INSERT INTO Correct VALUES ('Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ?,?,?,? )"; + $q = "INSERT INTO Correct VALUES (4,'Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ?,?,?,? )"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); @@ -74,7 +91,7 @@ class SqliteDb extends SQLite3 $fonctionCorrect = 'CREATE OR REPLACE FUNCTION fpointsmarques(date_match IN VARCHAR2, joueur IN VARCHAR2 ) RETURN NUMBER IS nbPoints NUMBER ; BEGIN SELECT DISTINCT points INTO nbPoints FROM STATS WHERE datematch = date_match AND prenomnoms=joueur; RETURN nbPoints; END;' ; $reponse = 'SELECT fpointsmarques(\''.$dateRandom.'\', \''.$joueurRandom.'\') FROM DUAL'; $testU = 'SELECT pointsmarques(\''.$dateRandom.'\', \''.$joueurRandom.'\') FROM DUAL' ; - $q = "INSERT INTO Correct VALUES ('Ecrire une fonction pointsmarques qui détermine pour une date de match et un joueur donnés quelle est le nombre de points marqués par ce joueur', ?,?,?,? )"; + $q = "INSERT INTO FunctionCorrect VALUES (5,'Ecrire une fonction pointsmarques qui détermine pour une date de match et un joueur donnés quelle est le nombre de points marqués par ce joueur', ?,?,?,? )"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); @@ -82,19 +99,38 @@ class SqliteDb extends SQLite3 $stmt->bindParam(4,$testU); $stmt->execute(); - //Question 9 - /*$type = 'tablemodification'; + /* //Question 9 + $type = 'tablemodification'; $fonctionCorrect = 'IDJOUEUR'; $testU = null; + $testP = 'SELECT data_type FROM all_TAB_COLUMNS WHERE table_name = \'JOUEUR\' '; //pour vérifier l $reponse = 'SELECT column_name FROM all_TAB_COLUMNS WHERE table_name = \'TEST\' '; - $q = "INSERT INTO Correct VALUES ('Modifier la table JOUEUR pour ajouter un champ idjoueur', ?,?,?,? )"; + $q = "INSERT INTO Correct VALUES (6,'Modifier la table JOUEUR pour ajouter un champ idjoueur', ?,?,?,? )"; $stmt = $this->prepare($q); $stmt->bindParam(1,$reponse); $stmt->bindParam(2,$type); $stmt->bindParam(3,$fonctionCorrect); $stmt->bindParam(4,$testU); + //Question 10 + $type = 'query'; + $fonctionCorrect = null; + $testU = null; + $testP = null; + $reponse = 'SELECT id_joueur FROM STATS WHERE table_name = \'TEST\' '; + $q = "INSERT INTO Correct VALUES (7,'Modifier la table JOUEUR pour ajouter un champ idjoueur', ?,?,?,? )"; + $stmt = $this->prepare($q); + $stmt->bindParam(1,$reponse); + $stmt->bindParam(2,$type); + $stmt->bindParam(3,$fonctionCorrect); + $stmt->bindParam(4,$testU); $stmt->execute();*/ + + //QUESITION 1 TP2 + $type='trigger'; + $fonctionCorrect = 'CREATE OR REPLACE TRIGGER supprJ BEFORE DELETE ON joueur FOR EACH ROW DECLARE duser varchar2(30); ddate date; BEGIN SELECT user,sysdate INTO duser,ddate FROM DUAL; INSERT INTO TRACE VALUES(ddate, duser,\'Suppression de \' || :old.prenomnomj); END;' ; + // + } function createLogin(){ diff --git a/BddCorrect/css/VueAdmin.css b/BddCorrect/css/VueAdmin.css new file mode 100644 index 0000000..63fcca3 --- /dev/null +++ b/BddCorrect/css/VueAdmin.css @@ -0,0 +1,66 @@ + + +* {box-sizing: border-box} + + input[type=text] { + width: 100%; + padding: 15px; + margin: 5px 0 22px 0; + display: inline-block; + border: none; + background: #f1f1f1; +} + +input[type=text]:focus { + background-color: #ddd; + outline: none; +} + +hr { + border: 1px solid #f1f1f1; + margin-bottom: 25px; +} + + +button { + background-color: #4CAF50; + color: white; + padding: 14px 20px; + margin: 8px 0; + border: none; + cursor: pointer; + width: 100%; + opacity: 0.9; +} + +button:hover { + opacity:1; +} + +.btnvalider { + float: left; + width: 25%; + margin-left: auto; + margin-right: auto; + text-align: center; +} + +.container { + padding: 16px; + +} + +.clearfix::after { + content: ""; + clear: both; + display: table; + margin-left: auto; + margin-right: auto;} + +@media screen and (max-width: 300px) { + .btnvalider { + width: 100%; + margin-left: auto; + margin-right: auto; + } +} \ No newline at end of file diff --git a/BddCorrect/index.php b/BddCorrect/index.php index 83afbca..d8257f5 100644 --- a/BddCorrect/index.php +++ b/BddCorrect/index.php @@ -12,6 +12,8 @@ and open the template in the editor. (Oc=4b|<0s|OG2>~2kj)JbOYz3+Q@-@G@oyS)1vJht}^ zJtGLhfOmUYUmbYH1~BWpj4YVbTb2pSG7MXvSfiF-P5z$3m z5(GAlbHBG)$q(JboLJ;VcB7mxaVVCI1}WO3#x;B6_CJYz9TKHQcuUh*ln!BJC)BuS zu=V$Y4aJM8uCwwsOw&|=p%4=YM(~LlG=e%*D$7cOp|8h6&e~|>uF>Xng8BuumXOb8 zSwX#inK>2d|JHY^2B*Z%R`}A%<=R-|j?w0JgZiN2F)MOuc?4~fGokLUi(+y{L?a#g zkv>|Jt>5qi3{6&Io8yJtTxDgmkg05PNndD!6SG$;D-4a<;9Bu!I#jBbb389@@xFM3 z3ym+xFRC*S5OB{Lx1`Jirl(E*D=GbSzOnl!z2QL2>%Z#oAjeE4pUss~P^_lcHl$1hjgP-9i_#Pf%@j1NFXV3z-VfFNXA@y2d b(UY8Hk~P%VVOB5lB?eM1dD5#>B72z`v1SZL^?&9v>&8D7(0{ zG-G4xWEo!V$*cK8xEtA90#U_6nSELUCNuK+Y!W!l@9t^rR$1YbQx@PJ=@R8wSmKvf zVv&@ZY8e_38tGZ(8y4&yW$03wofcVgg1>xo{Mc` z;|tEozcdd?85!%kxH{_^nyc$5sJrNS=_xptrk56%Wae$&W~ahvfKyssQ^76B-&esU z)X}HOg@vOru-ROkfnl?%jx8fsHZw<~c#}PlKRHkL370MtM^kxYGDtd3PnD6mijjSC HyM84Ai5N{S diff --git a/BddCorrect/vues/VueAdmin.php b/BddCorrect/vues/VueAdmin.php new file mode 100644 index 0000000..ab629ec --- /dev/null +++ b/BddCorrect/vues/VueAdmin.php @@ -0,0 +1,24 @@ + + + + +
+
+

Ajouter Une Question

+
+ + + + + + + + +
+
+ diff --git a/BddCorrect/vues/VuePrincipale.php b/BddCorrect/vues/VuePrincipale.php index bdc6cee..3cb10db 100644 --- a/BddCorrect/vues/VuePrincipale.php +++ b/BddCorrect/vues/VuePrincipale.php @@ -39,16 +39,17 @@ - +
+

TP 2

-
+ -

getQuestion(); ?>
+

getNumQuestion() .'.'.$q->getQuestion(); $_SESSION['num']=array(); $_SESSION['num'][$i] =$q->getNumQuestion(); ?>
@@ -56,7 +57,9 @@

-

+

+ +
@@ -64,15 +67,44 @@

+
+ + + + + ?> + +