diff --git a/BddCorrect/BDD/SqliteDb.php b/BddCorrect/BDD/SqliteDb.php index 0fcbca0..3665e87 100644 --- a/BddCorrect/BDD/SqliteDb.php +++ b/BddCorrect/BDD/SqliteDb.php @@ -144,33 +144,58 @@ class SqliteDb extends SQLite3 } function createQCM(){ + $this->exec('DROP TABLE Qcm'); + $this->exec('CREATE TABLE Qcm ( numQcm NUMBER, nom STRING,type STRING)'); + $this->exec('DROP TABLE QcmQuestion'); - $this->exec('CREATE TABLE QcmQuestion ( numQuestion NUMBER, question STRING)'); + $this->exec('CREATE TABLE QcmQuestion ( numQuestion NUMBER,numQcm NUMBER, question STRING,bareme NUMBER)'); $this->exec('DROP TABLE QcmReponse'); - $this->exec('CREATE TABLE QcmReponse ( numReponse NUMBER, reponse STRING, numQuestion NUMBER)'); + $this->exec('CREATE TABLE QcmReponse ( numQcm NUMBER, numReponse NUMBER, reponse STRING, numQuestion NUMBER, points NUMBER)'); $this->exec('DROP TABLE QcmCorrection'); - $this->exec('CREATE TABLE QcmCorrection ( numQuestion NUMBER, numReponse NUMBER)'); + $this->exec('CREATE TABLE QcmCorrection (numQcm NUMBER, numQuestion NUMBER, numReponse NUMBER)'); + + //------QCM sql --------------// + $this->exec("INSERT INTO Qcm VALUES(1,'sql','vraifaux')"); //Question 1 - $this->exec("INSERT INTO QcmQuestion VALUES(1,'Ceci est la question 1')"); + $this->exec("INSERT INTO QcmQuestion VALUES(1,1,'Ceci est la question 1',10)"); - $this->exec("INSERT INTO QcmReponse VALUES(1,'Ceci est la reponse 1 de la question 1(fausse)',1)"); - $this->exec("INSERT INTO QcmReponse VALUES(2,'Ceci est la reponse 2 de la question 1(Vraie)',1)"); - $this->exec("INSERT INTO QcmReponse VALUES(3,'Ceci est la reponse 3 de la question 1(Vraie)',1)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,1,'Ceci est la reponse 1 de la question 1(fausse)',1)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,2,'Ceci est la reponse 2 de la question 1(Vraie)',1)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,3,'Ceci est la reponse 3 de la question 1(Vraie)',1)"); - $this->exec("INSERT INTO QcmCorrection VALUES(1,2)"); - $this->exec("INSERT INTO QcmCorrection VALUES(1,3)"); + $this->exec("INSERT INTO QcmCorrection VALUES(1,1,2)"); + $this->exec("INSERT INTO QcmCorrection VALUES(1,1,3)"); //Question 2 - $this->exec("INSERT INTO QcmQuestion VALUES(2,'Ceci est la question 2')"); + $this->exec("INSERT INTO QcmQuestion VALUES(2,1,'Ceci est la question 2',9)"); + + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,1,'Ceci est la reponse 1 de la question 2(Vraie)',2)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,2,'Ceci est la reponse 2 de la question 2(fausse)',2)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,3,'Ceci est la reponse 3 de la question 2(fausse)',2)"); + $this->exec("INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES(1,4,'Ceci est la reponse 4 de la question 2(fausse)',2)"); + + $this->exec("INSERT INTO QcmCorrection VALUES(1,2,1)"); - $this->exec("INSERT INTO QcmReponse VALUES(1,'Ceci est la reponse 1 de la question 2(Vraie)',2)"); - $this->exec("INSERT INTO QcmReponse VALUES(2,'Ceci est la reponse 2 de la question 2(fausse)',2)"); - $this->exec("INSERT INTO QcmReponse VALUES(3,'Ceci est la reponse 3 de la question 2(fausse)',2)"); + //------QCM EPSWORTH --------------// + $this->exec("INSERT INTO Qcm VALUES(2,'EPSWORTH','test')"); + + //Question 1 + $this->exec("INSERT INTO QcmQuestion(numQuestion,numQcm,question) VALUES(1,2,'Ceci est la question 1')"); + + $this->exec("INSERT INTO QcmReponse VALUES(2,1,'Ceci est la reponse 1 de la question 1(5)',1,5)"); + $this->exec("INSERT INTO QcmReponse VALUES(2,2,'Ceci est la reponse 2 de la question 1(11)',1,11)"); + $this->exec("INSERT INTO QcmReponse VALUES(2,3,'Ceci est la reponse 3 de la question 1(12)',1,12)"); - $this->exec("INSERT INTO QcmCorrection VALUES(2,1)"); + + //Question 2 + $this->exec("INSERT INTO QcmQuestion(numQuestion,numQcm,question) VALUES(2,2,'Ceci est la question 2')"); + + $this->exec("INSERT INTO QcmReponse VALUES(2,1,'Ceci est la reponse 1 de la question 2(5)',2,5)"); + $this->exec("INSERT INTO QcmReponse VALUES(2,2,'Ceci est la reponse 2 de la question 2(11)',2,11)"); + $this->exec("INSERT INTO QcmReponse VALUES(2,3,'Ceci est la reponse 3 de la question 2(12)',2,12)"); } @@ -257,47 +282,69 @@ class SqliteDb extends SQLite3 return true; } - function ajouterQCM($numQuestion,$consigne,$choix1,$choix2,$choix3,$reponses){ - if($this->verificationExistenceQCM($numQuestion)) return false; - - $qt = "INSERT INTO QcmQuestion VALUES(?,?)"; + function ajouterQCM($numQcm,$numQuestion,$consigne,$choix,$reponses){ + if($this->verificationExistenceQCM($numQcm,$numQuestion)) return false; + $qt = "INSERT INTO QcmQuestion VALUES(?,?,?,20)"; $prp=$this->prepare($qt); $prp->bindParam(1, $numQuestion); - $prp->bindParam(2, $consigne); + $prp->bindParam(2, $numQcm); + $prp->bindParam(3, $consigne); $prp->execute(); - $q = "INSERT INTO QcmReponse VALUES (1,?,?)"; - $stmt = $this->prepare($q); - $stmt->bindParam(1,$choix1); - $stmt->bindParam(2,$numQuestion); - $stmt->execute(); - - $q = "INSERT INTO QcmReponse VALUES (2,?,?)"; - $stmt = $this->prepare($q); - $stmt->bindParam(1,$choix2); - $stmt->bindParam(2,$numQuestion); - $stmt->execute(); - - $q = "INSERT INTO QcmReponse VALUES (3,?,?)"; - $stmt = $this->prepare($q); - $stmt->bindParam(1,$choix3); - $stmt->bindParam(2,$numQuestion); - $stmt->execute(); - + $i=1; + foreach($choix as $c){ + $q = "INSERT INTO QcmReponse(numQcm,numReponse,reponse,numQuestion) VALUES (?,?,?,?)"; + $stmt = $this->prepare($q); + $stmt->bindParam(1,$numQcm); + $stmt->bindParam(2,$i); + $stmt->bindParam(3,$c); + $stmt->bindParam(4,$numQuestion); + $stmt->execute(); + $i++; + } + foreach($reponses as $numReponse){ - $qt = "INSERT INTO QcmCorrection VALUES(?,?)"; + $qt = "INSERT INTO QcmCorrection VALUES(?,?,?)"; $prp=$this->prepare($qt); - $prp->bindParam(1, $numQuestion); - $prp->bindParam(2, $numReponse); + $prp->bindParam(1,$numQcm); + $prp->bindParam(2, $numQuestion); + $prp->bindParam(3, $numReponse); $prp->execute(); } return true; } - function verificationExistenceQCM($numQuestion){ - $q = "SELECT count(*) FROM QcmQuestion WHERE numQuestion = ? "; + function ajouterQCMTest($numQcm,$numQuestion,$consigne,$choixEtPoints){ + if($this->verificationExistenceQCM($numQcm,$numQuestion)) return false; + $qt = "INSERT INTO QcmQuestion(numQuestion,numQcm,question) VALUES(?,?,?)"; + $prp=$this->prepare($qt); + $prp->bindParam(1, $numQuestion); + $prp->bindParam(2, $numQcm); + $prp->bindParam(3, $consigne); + $prp->execute(); + + $i=1; + foreach($choixEtPoints as $c ){ + + $res = explode("---",$c); + $q = "INSERT INTO QcmReponse VALUES (?,?,?,?,?)"; + $stmt = $this->prepare($q); + $stmt->bindParam(1,$numQcm); + $stmt->bindParam(2,$i); + $stmt->bindParam(3,$res[0]); + $stmt->bindParam(4,$numQuestion); + $stmt->bindParam(5,$res[1]); + $stmt->execute(); + $i++; + } + return true; + + } + function verificationExistenceQCM($numQcm,$numQuestion){ + $q = "SELECT count(*) FROM QcmQuestion WHERE numQuestion = ? AND numQcm=?"; $prp=$this->prepare($q); $prp->bindParam(1, $numQuestion); + $prp->bindParam(2, $numQcm); $result = $prp->execute(); $row = $result->fetchArray(); if($row['count(*)'] == 0) return false; @@ -395,7 +442,7 @@ class SqliteDb extends SQLite3 $prp->execute(); } - function supprimerQCM($numQuestion){ + function supprimerQCM($numQuestion,$type){ $qt = "DELETE FROM QcmQuestion WHERE numQuestion=? "; $prp=$this->prepare($qt); $prp->bindParam(1, $numQuestion); @@ -406,6 +453,7 @@ class SqliteDb extends SQLite3 $prp->bindParam(1, $numQuestion); $prp->execute(); + if($type == 'test') return; $qt = "DELETE FROM QcmCorrection WHERE numQuestion=? "; $prp=$this->prepare($qt); $prp->bindParam(1, $numQuestion); diff --git a/BddCorrect/DAL/QCMGateway.php b/BddCorrect/DAL/QCMGateway.php index 339e9cb..048ff7a 100644 --- a/BddCorrect/DAL/QCMGateway.php +++ b/BddCorrect/DAL/QCMGateway.php @@ -1,4 +1,5 @@ -db->prepare($query); - $result = $query->execute(); - $tabQuestions = array(); - //$resultats = $this->db->query('SELECT found_rows()'); - while($q = $result->fetchArray()){ - $i= $i+1; - $reponseQuery = 'SELECT * FROM QcmReponse WHERE numQuestion=? ORDER BY numReponse'; - $stmt = $this->db->prepare($reponseQuery); - $stmt->bindParam(1, $q['numQuestion']); - $reponseResult = $stmt->execute(); - $i=0; - $tabReponses =array(); - while ($r = $reponseResult->fetchArray()){ - - $i++; - $tabReponses[] = new ReponseQCM($r['numReponse'], $r['reponse'], $r['numQuestion']) ; + $resultqcm = $query->execute(); + while($qcm = $resultqcm->fetchArray()){ + $query = 'SELECT * FROM QcmQuestion WHERE numQcm = ? ORDER BY numQuestion '; + $query = $this->db->prepare($query); + $query->bindParam(1, $qcm['numQcm']); + $result = $query->execute(); + $tabQuestions = array(); + //$resultats = $this->db->query('SELECT found_rows()'); + while($q = $result->fetchArray()){ + $reponseQuery = 'SELECT * FROM QcmReponse WHERE numQuestion=? AND numQcm = ? ORDER BY numReponse'; + $stmt = $this->db->prepare($reponseQuery); + $stmt->bindParam(1, $q['numQuestion']); + $stmt->bindParam(2, $qcm['numQcm']); + $reponseResult = $stmt->execute(); + $tabReponses =array(); + while ($r = $reponseResult->fetchArray()){ + $tabReponses[] = new ReponseQCM($r['numReponse'], $r['reponse'], $r['numQuestion']) ; + } + $tabQuestions[] = new QuestionQCM($q['numQuestion'],$q['question'],$tabReponses,$q['bareme']); } - //die(print_r($i, true )); - $tabQuestions[] = new QCM($q['numQuestion'],$q['question'],$tabReponses); + $tabQcm[] = new QCM($qcm['numQcm'], $qcm['nom'], $qcm['type'], $tabQuestions) ; + } - //die(print_r($tabQuestions, true )); - return $tabQuestions; + //die(print_r($tabQcm, true )); + //+die(print_r($tabQuestions, true )); + return $tabQcm; + //die('ook'); } } diff --git a/BddCorrect/Traitement/AjoutDemonstration.php b/BddCorrect/Traitement/AjoutDemonstration.php index c240e45..2b08b34 100644 --- a/BddCorrect/Traitement/AjoutDemonstration.php +++ b/BddCorrect/Traitement/AjoutDemonstration.php @@ -30,7 +30,27 @@ else { if(!$isAdd){ echo 'ERREUR : la combinaison (numéro de chapitre, numéro de démonstration) existe déjà dans la bdd'; } - else echo 'AJOUT Démonstration avec succès'; + else{ + $trouve=0; + $file = fopen('..\imports\demonstration\demo_historiqueAuto.txt', "a"); + $ligne = $_GET['bdd'].'**'.$_GET['chapitre'].'**'.$_GET['description'].'**'.$_GET['reponse']; + $handle = @fopen('..\imports\demonstration\demo_historiqueAuto.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + $trouve = 0; + fclose($file); + + echo 'AJOUT Démonstration n°'.$numDemo.' au chapitre '.$_GET['chapitre'].' avec succès'; + } diff --git a/BddCorrect/Traitement/AjoutQCM.php b/BddCorrect/Traitement/AjoutQCM.php index f998e32..0a890b4 100644 --- a/BddCorrect/Traitement/AjoutQCM.php +++ b/BddCorrect/Traitement/AjoutQCM.php @@ -4,30 +4,48 @@ require_once('../BDD/SqliteDb.php'); require_once('../controleur/Controleur.php'); $db = new SqliteDb('o'); +$query = $db->prepare('SELECT count(*) FROM Qcm WHERE numQcm= ?'); +$query->bindParam(1, $_GET['numQcm']); +$result = $query->execute(); +$countRow = $result->fetchArray(); -$reponseQuery = $db->prepare('SELECT count(*) FROM QcmQuestion'); + +if($_GET['nomQcm'] == 'existe' && $countRow['count(*)'] == 0){ + exit("Le numéro de qcm n'existe pas : veuillez remplir le champ 'Nom du Qcm' ou utiliser un numéro de qcm existant"); +} +else if($countRow['count(*)'] == 0){ + $query = $db->prepare('INSERT INTO Qcm VALUES(?,?,?)'); + $query->bindParam(1, $_GET['numQcm']); + $query->bindParam(2, $_GET['nomQcm']); + $query->bindParam(3, $_GET['type']); + $result = $query->execute(); +} + + +$reponseQuery = $db->prepare('SELECT count(*) FROM QcmQuestion WHERE numQcm= ?'); +$reponseQuery->bindParam(1, $_GET['numQcm']); $reponseResult = $reponseQuery->execute(); $reponseRow = $reponseResult->fetchArray(); $numQuestion = $reponseRow['count(*)'] + 1; $reponses = array(); if(isset($_GET['modif'])){ - $db->supprimerQCM ($numQuestion); + $db->supprimerQCM ($numQuestion,$_GET['type']); } -//die($_GET['rep1'].'-'.$_GET['rep2'].'-'.$_GET['rep3']); -if($_GET['rep1'] == 'true'){ - $reponses[] = 1; -} -if($_GET['rep2'] == 'true'){ - $reponses[] =2; -} -if($_GET['rep3'] == 'true'){ - $reponses[] = 3; +if($_GET['type']=='test'){ + + $isAdd = $db->ajouterQCMTest($_GET['numQcm'],$numQuestion,$_GET['consigne'],$_GET['choix']); + if(!$isAdd){ + echo 'ERREUR : le numéro de question '.$numQuestion.' existe déjà dans le qcm '.$_GET['numQcm'].''; + } + else echo 'AJOUT QCM avec succès'; } -$isAdd = $db->ajouterQCM($numQuestion,$_GET['consigne'],$_GET['choix1'],$_GET['choix2'],$_GET['choix3'],$reponses); +else{ + $isAdd = $db->ajouterQCM($_GET['numQcm'],$numQuestion,$_GET['consigne'],$_GET['choix'],$_GET['reponse']); if(!$isAdd){ echo 'ERREUR : le numéro de question existe déjà dans la bdd'; } -else echo 'AJOUT QCM avec succès'; + else echo 'AJOUT QCM avec succès'; +} diff --git a/BddCorrect/Traitement/AjoutQuestion.php b/BddCorrect/Traitement/AjoutQuestion.php index ab13951..ce76b16 100644 --- a/BddCorrect/Traitement/AjoutQuestion.php +++ b/BddCorrect/Traitement/AjoutQuestion.php @@ -7,7 +7,7 @@ require_once('../controleur/Controleur.php'); $db = new SqliteDb('o'); if (empty($_GET['tp']) || empty($_GET['bdd']) || empty($_GET['consigne']) || empty($_GET['reponse']) || empty($_GET['points']) || empty($_GET['aleatoire']) || empty($_GET['type'])) { - echo 'ERREUR : Veuillez remplir tous les champs '; + echo 'ERREUR1 : Veuillez remplir tous les champs '; } else if(!is_numeric($_GET['tp'])) echo 'ERREUR : une valeur non numérique à été détectée dans le champ \'TP n° :\' '; @@ -34,14 +34,33 @@ else { if(!$isAdd){ echo 'ERREUR : la combinaison (numéro de tp, numéro de question) existe déjà dans la bdd'; } - else echo 'AJOUT Requete avec succès'; + else{ + $trouve=0; + $file = fopen('..\imports\tp\tp_historiqueAuto.txt', "a"); + $ligne = 'requete**'.$_GET['bdd'].'**'.$_GET['tp'].'**'.$_GET['consigne'].'**'.$_GET['reponse'].'**'.$_GET['points'].'**'.'n'; + $handle = @fopen('..\imports\tp\tp_historiqueAuto.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + $trouve = 0; + fclose($file); + echo 'AJOUT Requete avec succès'; + } } else if ($_GET["type"] == 'fonction'){ if(empty($_GET['fonction'])) echo 'ERREUR : Veuillez remplir tous les champs '; else { - if(isset($_GET['modif'])){ + if(!isset($_GET['modif'])){ $reponse = $_GET['reponse']; $re = '/^\s*SELECT\s*([a-z0-9]*)/i'; preg_match($re, $reponse, $matches, PREG_OFFSET_CAPTURE); @@ -53,18 +72,37 @@ else { preg_match($re, $fonction, $matches2, PREG_OFFSET_CAPTURE); $string2 = 'f'.$matches2[1][0]; - $ffonction = str_replace($matches2[1][0],$string2, $fonction); + $ffonction = str_replace($matches2[1][0],$string2, $fonction); } else { - $freponse = $reponse; - $ffonction = $fonction; + $freponse = $_GET['reponse']; + $ffonction = $_GET['fonction']; } $isAdd = $db->ajouterFonction($_GET['bdd'],$_GET['tp'],$numQuestion,$_GET['consigne'], $freponse,$ffonction,$reponse,$_GET['points']); if(!$isAdd){ echo 'ERREUR : la combinaison (numéro de tp, numéro de question) existe déjà dans la bdd'; } - else echo 'AJOUT Fonction avec succès'; + else{ + $trouve=0; + $file = fopen('..\imports\tp\tp_historiqueAuto.txt', "a"); + $ligne = 'fonction**'.$_GET['bdd'].'**'.$_GET['tp'].'**'.$_GET['consigne'].'**'.$freponse.'**'.$_GET['points'].'**'.'n**'.$ffonction; + $handle = @fopen('..\imports\tp\tp_historiqueAuto.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + $trouve = 0; + fclose($file); + echo 'AJOUT Fonction avec succès'; + } } } diff --git a/BddCorrect/Traitement/CorrectionQCM.php b/BddCorrect/Traitement/CorrectionQCM.php index 32504b8..16ce223 100644 --- a/BddCorrect/Traitement/CorrectionQCM.php +++ b/BddCorrect/Traitement/CorrectionQCM.php @@ -10,68 +10,63 @@ $conn = $oracleDb->getConn(); $numReponseRow = array(); -/*echo $_GET['rep1']; -echo $_GET['rep2']; -echo $_GET['rep3'];*/ - - -$query = $db->prepare('SELECT numReponse FROM QcmCorrection WHERE numQuestion=?'); -$query->bindParam(1, $_GET['numQuestion']); -$result = $query->execute(); - -while($r = $result->fetchArray() ){ - $numReponseRow[] = $r['numReponse']; -} - - -$err = 0; - -//reponse 1 -if(in_array(1, $numReponseRow) ) { - if($_GET['rep1']!='true'){ - $err++; - } -} -else if($_GET['rep1']=='true'){ - $err++; -} - -//reponse 2 -if(in_array(2, $numReponseRow) ) { - if($_GET['rep2']!='true'){ - $err++; +if(!isset($_GET['type'])){ + $query = $db->prepare('SELECT numReponse FROM QcmCorrection WHERE numQuestion=? AND numQcm= ?'); + $query->bindParam(1, $_GET['numQuestion']); + $query->bindParam(2, $_GET['numQcm']); + $result = $query->execute(); + + while($r = $result->fetchArray() ){ + $numReponseRow[] = $r['numReponse']; } -} -else if($_GET['rep2']=='true'){ - $err++; -} -//reponse 2 -if(in_array(3, $numReponseRow) ) { - if($_GET['rep3']!='true'){ - $err++; - } -} -else if($_GET['rep3']=='true'){ - $err++; -} + // Sort the array elements + sort($numReponseRow); + sort( $_GET['rep']); -if($err == 0){ - echo 'Bonne réponse !'; + // Check for equality + if ($numReponseRow == $_GET['rep']) + echo "Bonne réponse ! \n"; + else + echo "Mauvaise réponse.\n"; } -else echo 'Mauvaise réponse.'; -/*$reponseQuery = $db->prepare('SELECT reponse FROM QcmReponse WHERE numReponse=? AND numQuestion=?'); -$reponseQuery->bindParam(1, $numReponseRow['numReponse']); -$reponseQuery->bindParam(2, $_GET['numQuestion']); -$reponseResult = $reponseQuery->execute(); -$reponseRow = $reponseResult->fetchArray(); - -if($_GET['textbox'] == $reponseRow['reponse']){ - echo 'Bonne réponse !'; +else{ + $query = $db->prepare('SELECT count(*) FROM QcmQuestion WHERE numQcm= ? '); + $query->bindParam(1, $_GET['numQcm']); + $result = $query->execute(); + $nbQuestionRow = $result->fetchArray(); + + $total = 0; + for($i = 1 ; $i<=$nbQuestionRow['count(*)'] ; $i++ ){ + $query = $db->prepare('SELECT max(points) FROM QcmReponse WHERE numQcm= ? AND numQuestion=?'); + $query->bindParam(1, $_GET['numQcm']); + $query->bindParam(2, $i); + $result = $query->execute(); + $totalRow = $result->fetchArray(); + + $total += $totalRow['max(points)']; + } + + $query = $db->prepare('SELECT * FROM QcmReponse WHERE numQcm= ? '); + $query->bindParam(1, $_GET['numQcm']); + $result = $query->execute(); + $totalRow = $result->fetchArray(); + + + $points = 0; + for ($i = 1 ; $i < sizeof($_GET['rep']) ; $i++){ + $query = $db->prepare('SELECT * FROM QcmReponse WHERE numQuestion=? AND numQcm= ? AND numReponse= ?'); + $query->bindParam(1, $i); + $query->bindParam(2, $_GET['numQcm']); + $query->bindParam(3, $_GET['rep'][$i][0]); + $result = $query->execute(); + $pointRow = $result->fetchArray(); + $points +=$pointRow['points']; + } + echo 'Résultat : '.$points.' sur '.$total.''; } -else echo $reponseRow['reponse'].'Mauvaise Réponse.';*/ diff --git a/BddCorrect/Traitement/Export.php b/BddCorrect/Traitement/Export.php new file mode 100644 index 0000000..3fec55f --- /dev/null +++ b/BddCorrect/Traitement/Export.php @@ -0,0 +1,161 @@ +prepare('SELECT * FROM demonstration'); + $reponseResult = $reponseQuery->execute(); + while ($r = $reponseResult->fetchArray()){ + $ligne = $r['bddconcernee'].'**'.$r['chapitre'].'**'.$r['description'].'**'.$r['reponse']; + $handle = @fopen('..\imports\demonstration\demo_exportes.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + $trouve = 0; + //fwrite($file, $ligne."\n"); + } + fclose($file); + // file_put_contents('..\imports\demonstration\demo_exportes.txt', rtrim(file_get_contents('..\imports\demonstration\demo_exportes.txt'))); +} + +else if ($_GET['type']=='tp'){ + $file = fopen('..\imports\tp\tpexportes.txt', "a"); + $matches = array(); + $trouve = 0; + $reponseQuery = $db->prepare('SELECT bddConcernee,numTp,numquestion,question,reponse,points FROM Correct UNION SELECT bddConcernee,numTp,numquestion,question,reponse,points FROM FunctionCorrect'); + $reponseResult = $reponseQuery->execute(); + while ($r = $reponseResult->fetchArray()){ + $questionQuery = 'SELECT type FROM type WHERE numQuestion = ? AND numTp=? '; + $questionQuery = $db->prepare($questionQuery); + $questionQuery->bindParam(1, $r['numquestion']); + $questionQuery->bindParam(2, $r['numTp']); + $questionResult = $questionQuery->execute(); + $typeRow = $questionResult->fetchArray(); + $reponse = $r['reponse']; + if($typeRow['type'] == 'functionCorrect'){ + $questionQuery = 'SELECT fonctionCorrect FROM functionCorrect WHERE numQuestion = ? AND numTp=? '; + $questionQuery = $db->prepare($questionQuery); + $questionQuery->bindParam(1, $r['numquestion']); + $questionQuery->bindParam(2, $r['numTp']); + $questionResult = $questionQuery->execute(); + $fonctionRow = $questionResult->fetchArray(); + $type='fonction'; + + + $re = '/^\s*SELECT\s*([a-z0-9])/i'; + preg_match($re, $reponse, $matches, PREG_OFFSET_CAPTURE); + $string = 'f'.$matches[1][0]; + $freponse = str_replace($matches[1][0],'', $reponse); + + $fonction = $fonctionRow['fonctionCorrect']; + $re = '/^\s*CREATE OR REPLACE FUNCTION\s*([a-z0-9])/i'; + preg_match($re, $fonction, $matches2, PREG_OFFSET_CAPTURE); + + $string2 = 'f'.$matches2[1][0]; + $ffonction = str_replace($matches2[1][0],'', $fonction); + } + else{ + $freponse = $reponse; + $type='requete'; + } + $ligne = $type.'**'.$r['bddConcernee'].'**'.$r['numTp'].'**'.$r['question'].'**'.$freponse.'**'.$r['points'].'**n'; + + if($typeRow['type'] == 'functionCorrect'){ + $ligne = $ligne.'**'.$ffonction; + } + $handle = @fopen('..\imports\tp\tp_exportes.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + $trouve = 0; + //fwrite($file, $ligne."\n"); + } + fclose($file); + // file_put_contents('..\imports\demonstration\demo_exportes.txt', rtrim(file_get_contents('..\imports\demonstration\demo_exportes.txt'))); + + + +} + +else if($_GET['type']=='qcm'){ + $file = fopen('..\imports\qcm\qcm_exportes.txt', "a"); + $matches = array(); + $trouve = 0; + $reponseQuery = $db->prepare('SELECT * FROM Qcm ORDER By numQcm'); + $reponseResult = $reponseQuery->execute(); + while ($qcm = $reponseResult->fetchArray()){ + $ligne = $qcm['numQcm'].'**'.$qcm['nom'].'**'.$qcm['type']; + $reponseQuery = $db->prepare('SELECT * FROM QcmQuestion WHERE numQcm=? ORDER By question'); + $reponseQuery->bindParam(1, $qcm['numQcm']); + $questionResult = $reponseQuery->execute(); + + while ($question = $questionResult->fetchArray()){ + $ligne = $qcm['numQcm'].'**'.$qcm['nom'].'**'.$qcm['type']; + $ligne = $ligne.'**'.$question['question']; + + $reponseQuery = $db->prepare('SELECT * FROM QcmReponse WHERE numQcm=? AND numQuestion=? ORDER BY numReponse'); + $reponseQuery->bindParam(1, $qcm['numQcm']); + $reponseQuery->bindParam(2, $question['numQuestion']); + $reponsResult = $reponseQuery->execute(); + if($qcm['type'] == 'test'){ + $ligne = $ligne.'**'; + while ($reponseTest = $reponsResult->fetchArray()){ + $ligne = $ligne.$reponseTest['reponse'].'---'.$reponseTest['points'].'+++'; + } + $ligne = substr($ligne, 0, -3); + } + else{ + $ligne = $ligne.'**'; + while ($reponseV = $reponsResult->fetchArray()){ + $ligne = $ligne.$reponseV['reponse'].'+++'; + } + $ligne = substr($ligne, 0, -3); + $ligne = $ligne.'**'; + $reponseQuery = $db->prepare('SELECT * FROM QcmCorrection WHERE numQcm=? AND numQuestion=? ORDER BY numQcm,numQuestion'); + $reponseQuery->bindParam(1, $qcm['numQcm']); + $reponseQuery->bindParam(2, $question['numQuestion']); + $reponsResult = $reponseQuery->execute(); + while ($reponse = $reponsResult->fetchArray()){ + $ligne = $ligne.$reponse['numReponse'].',,'; + } + $ligne = substr($ligne, 0, -2); + + } + $trouve = 0; + $handle = @fopen('..\imports\qcm\qcm_exportes.txt', "r"); + if ($handle) + { + while (!feof($handle)) + { + $buffer = fgets($handle); + if(strpos($buffer, $ligne) !== FALSE) + $trouve = 1; + } + fclose($handle); + } + if($trouve==0) fwrite($file, $ligne."\n"); + + } + } + fclose($file); +} \ No newline at end of file diff --git a/BddCorrect/Traitement/ModificationQCM.php b/BddCorrect/Traitement/ModificationQCM.php index 86acd75..c908e0b 100644 --- a/BddCorrect/Traitement/ModificationQCM.php +++ b/BddCorrect/Traitement/ModificationQCM.php @@ -7,20 +7,38 @@ require_once('../BDD/OracleDb.php'); $db = new SqliteDb('o'); -$stmt = $db->prepare('SELECT * FROM QcmQuestion WHERE numQuestion= ?'); +$stmt = $db->prepare('SELECT * FROM Qcm WHERE numQcm= ?'); +$stmt->bindParam(1, $_GET['numQcm']); +$resultQuestion = $stmt->execute(); +$qcmRow = $resultQuestion->fetchArray(); + +$stmt = $db->prepare('SELECT * FROM QcmQuestion WHERE numQuestion= ? AND numQcm=?'); $stmt->bindParam(1, $_GET['numQuestion']); +$stmt->bindParam(2, $_GET['numQcm']); $resultQuestion = $stmt->execute(); $questionRow = $resultQuestion->fetchArray(); -$stmt = $db->prepare('SELECT reponse FROM QcmReponse WHERE numQuestion= ?'); +$stmt = $db->prepare('SELECT reponse FROM QcmReponse WHERE numQuestion= ? AND numQcm=?'); +$stmt->bindParam(1, $_GET['numQuestion']); +$stmt->bindParam(2, $_GET['numQcm']); +$resultQuestion = $stmt->execute(); +while($r = $resultQuestion->fetchArray(SQLITE3_NUM)){ + $reponseRow[] = $r[0]; +} + +$stmt = $db->prepare('SELECT count(*) FROM QcmReponse WHERE numQuestion= ? AND numQcm=?'); $stmt->bindParam(1, $_GET['numQuestion']); +$stmt->bindParam(2, $_GET['numQcm']); $resultQuestion = $stmt->execute(); +$countRow = $resultQuestion->fetchArray(); + while($r = $resultQuestion->fetchArray(SQLITE3_NUM)){ $reponseRow[] = $r[0]; } -$stmt = $db->prepare('SELECT * FROM QcmCorrection WHERE numQuestion= ?'); +$stmt = $db->prepare('SELECT * FROM QcmCorrection WHERE numQuestion= ? AND numQcm=?'); $stmt->bindParam(1, $_GET['numQuestion']); +$stmt->bindParam(2, $_GET['numQcm']); $resultQuestion = $stmt->execute(); $correctRow = $resultQuestion->fetchArray(); @@ -32,26 +50,66 @@ $correctRow = $resultQuestion->fetchArray();
@@ -87,7 +87,6 @@ if(mot == 0){ var tp = $('#tp').val() ; - var num = $('#num').val() ; var points = $('#points').val() ; var consigne = $('#consigne').val() ; var reponse = $('#reponse').val() ; @@ -100,34 +99,32 @@ var type = mot[0]; var bdd = mot[1]; var tp = mot[2]; - var num = mot[3]; - var consigne = mot[4]; - var reponse = mot[5]; - var points = mot[6]; - var aleatoire = mot[7]; - var fonction = mot[8]; + var consigne = mot[3]; + var reponse = mot[4]; + var points = mot[5]; + var aleatoire = mot[6]; + var fonction = mot[7]; if(fonction != null){ //alert(type+'-'+bdd+'-'+tp+'-'+num+'-'+consigne+'-'+reponse+'-'+points+'-'+aleatoire+'-'+fonction); //alert() + alert('ok'); } //else alert(type+'-'+bdd+'-'+tp+'-'+num+'-'+consigne+'-'+reponse+'-'+points+'-'+aleatoire); } - $.get("Traitement/AjoutQuestion.php", { tp: tp,num: num,points: points,consigne: consigne,reponse: reponse,type: type,aleatoire: aleatoire,bdd: bdd, fonction : fonction}, + $.get("Traitement/AjoutQuestion.php", { tp: tp,points: points,consigne: consigne,reponse: reponse,type: type,aleatoire: aleatoire,bdd: bdd, fonction : fonction}, function(data) { - $('#erreur').html(data); - if (data.includes("AJOUT") == true){ - //alert("La question a été ajoutée"); - if(mot == 0){ - var result = confirm("La question a été ajoutée. Afficher les Questions ?"); - if(result) $('#inp-questions').trigger("click"); - } - } - //else alert("Erreur"); + if(mot != 0){ + $('#erreur').append('
');
+ }
+ else{
+ $('#erreur').empty();
+ setTimeout( function(){ $('#erreur').html(data); } , 400 );
+ }
//$('#demoForm')[0].reset();
- });
+ });
}
function wait(ms){
@@ -156,12 +153,12 @@
var lignes = content.split('\n');
for(var line = 0; line < lignes.length; line++){
var mot = lignes[line].split('**');
- SubmitAjoutQuestion(mot);
+ if (mot != "") SubmitAjoutQuestion(mot);
//mots.push(mot);
console.log(mot[0]);console.log(mot[1]);console.log(mot[2]);console.log(mot[3]);
}
- $('#inp-questions').trigger("click");
+ //$('#inp-questions').trigger("click");
}
reader.readAsText(file);
diff --git a/BddCorrect/vues/VueAjoutDemo.php b/BddCorrect/vues/VueAjoutDemo.php
index 8741bcb..fbe9d90 100644
--- a/BddCorrect/vues/VueAjoutDemo.php
+++ b/BddCorrect/vues/VueAjoutDemo.php
@@ -44,15 +44,17 @@
+
diff --git a/BddCorrect/vues/VueGestionTp.php b/BddCorrect/vues/VueGestionTp.php deleted file mode 100644 index daefc40..0000000 --- a/BddCorrect/vues/VueGestionTp.php +++ /dev/null @@ -1,64 +0,0 @@ - - -
- -
- - - - - -
- - -