Ajout vérification des fonctions créees par l'utilisateur

master
Mehdi 5 years ago
parent b840cf12ab
commit 16990453b7

@ -8,12 +8,7 @@ header('Content-type: text/plain');
$db = new SqliteDb();
$conn = oci_connect('u_prems', '123456','localhost/orcl');
/*if(!$conn){
echo 'conn ERRROROR';
}
else {
echo 'conn SUCCCESSSS';
}*/
$cmpt = 0;
$numQuestion = 0;
foreach ($_POST['textbox'] as $textbox) {
@ -21,66 +16,89 @@ foreach ($_POST['textbox'] as $textbox) {
$UserQuery = oci_parse($conn, $textbox);
$reponseUser = oci_execute($UserQuery);
$sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? ');
$sqliteQuery->bindParam(1, $numQuestion);
$result = $sqliteQuery->execute();
$sqliteRow = $result->fetchArray();
$vraiReponse = oci_parse($conn, $sqliteRow['reponse']);
$enAttente = oci_execute($vraiReponse);
/*$spool = $db->prepare('SPOOL ? ');
$spool->bindParam(1, 'jytdj');
$result = $spol->execute();
$fileUser = fopen("fileus.txt","w");*/
$typeQuery = $db->prepare('SELECT type FROM Correct WHERE rowid = ?');
$typeQuery->bindParam(1, $numQuestion);
$resultType = $typeQuery->execute();
$typeRow = $resultType->fetchArray();
$err = 0;
$verif =0;
while( ($oracleRow = oci_fetch_array($UserQuery, OCI_NUM)) && $err == 0 ){
$verif = 1;
$vraiReponseRow = oci_fetch_array($vraiReponse,OCI_NUM );
/*echo oci_num_rows($UserQuery) . " lignes insérées.<br />\n";
echo oci_num_rows($vraiReponse) . " lignes insérées sqlite.<br />\n";*/
//si la question attend un SELECT
if($typeRow['type'] == 'query'){
$sqliteQuery = $db->prepare('SELECT reponse FROM Correct WHERE rowid= ? ');
$sqliteQuery->bindParam(1, $numQuestion);
$result = $sqliteQuery->execute();
$sqliteRow = $result->fetchArray();
$vraiReponse = oci_parse($conn, $sqliteRow['reponse']);
$enAttente = oci_execute($vraiReponse);
if(oci_num_rows($UserQuery) != oci_num_rows($vraiReponse)){
$err=-3;
break;
}
if(sizeof($oracleRow) == sizeof($vraiReponseRow)){
/*foreach($vraiReponseRow as $key => $value)
{
echo $key." has the value " . $value ."\n";
while( ($oracleRow = oci_fetch_array($UserQuery, OCI_NUM)) && $err == 0 ){
$verif = 1;
$vraiReponseRow = oci_fetch_array($vraiReponse,OCI_NUM );
if(sizeof($oracleRow) == sizeof($vraiReponseRow)){
for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){
if($oracleRow[$i] != $vraiReponseRow[$i]){
$err = -1;
break;
}
}
}
foreach($oracleRow as $key => $value)
{
echo $key." BLASE the value " . $value ."\n";
}*/
for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){
if($oracleRow[$i] != $vraiReponseRow[$i]){
$err = -1;
break;
}
else {
$err = -2;
break;
}
}
if($err == 0 ){
echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n";
$cmpt++;
}
else {
$err = -2;
break;
else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n";
}
//si la question attend un CREATE FUNCTION
else{
$fonctionQuery = $db->prepare('SELECT * FROM Correct WHERE rowid= ? ');
$fonctionQuery->bindParam(1, $numQuestion);
$result = $fonctionQuery->execute();
$fonctionRow = $result->fetchArray();
$creationFonction = oci_parse($conn, $fonctionRow['fonctionCorrect']);
$creatF = oci_execute($creationFonction);
$testUser = oci_parse($conn, $fonctionRow['testUser']);
$testu = oci_execute($testUser);
$testF = oci_parse($conn, $fonctionRow['reponse']);
$testf = oci_execute($testF);
if(oci_num_rows($testUser) != oci_num_rows($testF)){
$err=-3;
}
/*for($i=0 ; $i< sizeof($vraiReponseRow)-2 ; $i++){
echo $vraiReponseRow[$i];
fwrite($fileUser,$vraiReponseRow[$i] . "\t");
while( ($reponseRow = oci_fetch_array($testUser,OCI_NUM)) && $err == 0){
$vraiReponseRow = oci_fetch_array($testF,OCI_NUM );
if(sizeof($reponseRow) == sizeof($vraiReponseRow)){
for($i=0 ; $i< sizeof($vraiReponseRow)-1 ; $i++){
if($reponseRow[$i] != $vraiReponseRow[$i]){
$err = -1;
break;
}
}
}
else {
$err = -2;
break;
}
}
fwrite($fileUser, "\n");*/
/* echo 'vrai ' . $vraiReponseRow[0] . ' || ora = ' . $oracleRow[0] . "\n";
if ($vraiReponseRow[0] == $oracleRow[0]) {
echo "La réponse à la question n° " . $i . " est JUSTE\n";
$cmpt++;
} else {
echo 'La réponse à la question n° ' . $i . " est FAUSSE\n\n";
}*/
}
if($err == 0 && $verif==1){
echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n";
$cmpt++;
if($err == 0 ){
echo "La réponse à la question " .$numQuestion. " est JUSTE ! \n";
$cmpt++;
}
else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n";
}
else echo "La réponse à la question " .$numQuestion. " est FAUSSE ! \n";
}
echo 'Résultat : ' . $cmpt . '/' . $numQuestion;

@ -1,4 +1,5 @@
<?php
//header('Content-type: text/plain');
class SqliteDb extends SQLite3
{
@ -11,36 +12,86 @@ 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)');
$this->exec('CREATE TABLE Correct ( question STRING, reponse STRING, type STRING, fonctionCorrect STRING,testUser STRING)');
//Question 1
$test = 'SELECT count(*) FROM stats WHERE prenomnoms=\'Kevin Durant\' ';
$q = "INSERT INTO Correct VALUES ('Trouver le nombre de matchs joués par Kevin Durant', ? )";
/* //Question 1
$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', ? ,?,?,?)";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$test);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();
//Question 2
$test = ' 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 ', ? )";
//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 ', ? ,?,?,?)";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$test);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();
//Question 3
$test = ' 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', ? )";
//Question 3
$type = 'query';
$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', ? ,?,?,?)";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$test);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();
//Question 5
$test = 'SELECT * FROM equipe WHERE nom= \'Hawks\' ';
$q = "INSERT INTO Correct VALUES ('Déterminer pour Kevin Durant pour le match du 30-oct-17 quelle est l équipe qui joue à domicile', ? )";
$type = 'query';
$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', ?,?,?,? )";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$test);
$stmt->execute();
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();*/
//Question 6
$this->joueurEtDateRandom($joueurRandom, $dateRandom);
$type = 'fonction';
$fonctionCorrect = 'CREATE OR REPLACE FUNCTION fpointsmarques(date_match IN VARCHAR2, joueur IN VARCHAR2 ) RETURN NUMBER IS nbPoints NUMBER ; BEGIN SELECT 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', ?,?,?,? )";
$stmt = $this->prepare($q);
$stmt->bindParam(1,$reponse);
$stmt->bindParam(2,$type);
$stmt->bindParam(3,$fonctionCorrect);
$stmt->bindParam(4,$testU);
$stmt->execute();
}
function joueurEtDateRandom(&$nomRandom, &$dateRandom){
$conn = oci_connect('u_prems', '123456','localhost/orcl');
$listeJoueurQuery = oci_parse($conn, 'SELECT prenomnoms,datematch FROM stats');
oci_execute($listeJoueurQuery);
$listeJoueurRows = oci_fetch_all($listeJoueurQuery, $listeJoueurArray);
//print_r($listeJoueurArray);
$rand_keys = array_rand($listeJoueurArray['PRENOMNOMS'], 1);
$nomRandom = $listeJoueurArray['PRENOMNOMS'][$rand_keys];
$dateRandom = $listeJoueurArray['DATEMATCH'][$rand_keys];
}
}

@ -3,9 +3,8 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/xampp/htdocs/BddCorrect/index.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/SqliteDb.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/vues/VuePrincipale.php</file>
<file>file:/C:/xampp/htdocs/BddCorrect/Correcteur.php</file>
</group>
</open-files>

Binary file not shown.

@ -10,19 +10,10 @@ and open the template in the editor.
<title></title>
</head>
<body>
<?php
/*$db = new SqliteDb();
$result = $db->prepare('SELECT question FROM Correct');
$result->execute(array());
$listeQuestion = $result->fetchAll();*/
//$Question1 = $db->querySingle('SELECT question FROM Correct');
?>
<form action="Correcteur.php" method="post">
<?php foreach ($dVueQuestions as $q) { ?>
<p><?php $i=0; $i++; echo $q->getQuestion(); ?> <br/> <input type="text" name="textbox[]" size="100" /></p><?php }?>
<p><?php $i=0; $i++; echo $q->getQuestion(); ?> <br/> <textarea rows="10" cols="70" name="textbox[]" ></textarea></p><?php }?>
<p><input type="submit" value="Valider"></p>
</form>
</body>

Loading…
Cancel
Save