correction avec plusieurs bdd sqlite + Timer + vue pour ajouter des consignes

master
Mehdi 5 years ago
parent 7ba790ac6f
commit 30054c6273

@ -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'){
// <editor-fold desc="vérification avec la vraie BDD">
$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");
// </editor-fold>
// <editor-fold desc="vérification avec bdd aléatoire">
@ -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) {
}
}
// </editor-fold>
//echo nl2br("\n ------------testerr : ".$err." test2verif : ".$verif."\n");
// <editor-fold desc="Résultat">
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();

@ -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;
}

@ -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(){

@ -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;
}
}

@ -12,6 +12,8 @@ and open the template in the editor.
<body>
<?php //chargement config
//phpinfo();
/*$remote_user = $_SERVER['REMOTE_USER'];
echo $remote_user;*/
require_once(__DIR__.'/config/config.php');
//chargement autoloader pour autochargement des classes

Binary file not shown.

@ -0,0 +1,24 @@
<link rel="stylesheet" href="../css/VueAdmin.css">
<form style="border:1px solid #ccc" method="POST">
<div class="container">
<h1>Ajouter Une Question</h1>
<hr>
<label><b>Consigne : </b></label>
<input type="text" placeholder="Ecrire la consigne..." name="consigne" required>
<label><b>Réponse : </b></label>
<input type="text" placeholder="SELECT ..." name="reponse" required>
<label>
<input type="radio" name="type" style="margin-bottom:15px"> requête
<input type="radio" name="type" style="margin-bottom:15px"> fonction
</label>
<div class="clearfix">
<a href="?action=Valider" class="btnvalider"> Se déconnecter</a>
</div>
</div>
</form>

@ -39,16 +39,17 @@
</div>
</header>
<div style="font-weight: bold" id="Temps-Restant"></div>
<section id="TP2">
<div class="container">
<div class="row">
<div class="col-lg-8 mx-auto">
<h2>TP 2</h2>
<form method="post" action="Correcteur.php">
<form method="post" action="Correcteur.php" name="Exam">
<?php $i=0;
foreach ($dVueQuestions as $q) { ?>
<p><?php $i++; echo $q->getQuestion(); ?> <br/>
<p><?php $i++; echo $q->getNumQuestion() .'.'.$q->getQuestion(); $_SESSION['num']=array(); $_SESSION['num'][$i] =$q->getNumQuestion(); ?> <br/>
<textarea rows="5" cols="70" name="textbox[]" >
<?php echo (isset($_SESSION['fi'][$i]) ? $_SESSION['fi'][$i] : '') ?>
</textarea>
@ -56,7 +57,9 @@
</p>
<?php } //fin foreach ?>
<p><input type="submit"></p>
<p><input type="submit" ></p>
</form>
</div>
</div>
@ -64,15 +67,44 @@
</section>
<form method="post" class="frm">
<input type="submit" name="test" id="test" value="Générer Base de données aléatoire" /><br/>
</form>
<a href="vues/VueAdmin.php"><button>Ajouter Une Question</button></a>
<?php
if(array_key_exists('test',$_POST)){
$oraDb = new OracleDb;
}
?>
?>
<script type="text/javascript">
var tempsMin =0.5 ;
var total_secondes =60*tempsMin;
tempsMin = parseInt(total_secondes/60);
secondes = parseInt(total_secondes%60);
document.getElementById("Temps-Restant").innerHTML='Temps restant: ' + tempsMin + ' minutes ' + secondes + ' secondes';
function init(){
document.getElementById("Temps-Restant").innerHTML='Temps restant: ' + tempsMin + ' minutes ' + secondes + ' secondes';
setTimeout("TempsRestant()",999);
}
function TempsRestant(){
document.getElementById("Temps-Restant").innerHTML='Temps restant: ' + tempsMin + ' minutes ' + secondes + ' secondes' ;
if(total_secondes <=0){
setTimeout('document.Exam.submit()',1);
}
else {
total_secondes = total_secondes -1;
tempsMin = parseInt(total_secondes/60);
secondes = parseInt(total_secondes%60);
setTimeout("TempsRestant()",999);
}
}
init();
</script>
<!-- Footer -->
<footer class="py-5 bg-dark">
<div class="container">

Loading…
Cancel
Save