You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
4.7 KiB

<?php
require_once('SqliteDb.php');
header('Content-type: text/plain');
$db = new SqliteDb();
$conn = oci_connect('u_prems', '123456','localhost/orcl');
$cmpt = 0;
$numQuestion = 0;
foreach ($_POST['textbox'] as $textbox) {
$numQuestion++;
$UserQuery = oci_parse($conn, $textbox);
$reponseUser = oci_execute($UserQuery);
$typeQuery = $db->prepare('SELECT type FROM Correct WHERE rowid = ?');
$typeQuery->bindParam(1, $numQuestion);
$resultType = $typeQuery->execute();
$typeRow = $resultType->fetchArray();
$err = 0;
$verif =0;
//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;
}
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;
}
}
}
else {
$err = -2;
break;
}
}
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";
}
//si la question attend une modification
else if($typeRow['type'] == 'tablemodification'){
$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);
$sqliteQuery = $db->prepare('SELECT fonctioncorrect FROM Correct WHERE rowid= ? ');
$sqliteQuery->bindParam(1, $numQuestion);
$result = $sqliteQuery->execute();
$sqliteRow = $result->fetchArray();
$t = oci_fetch_all($vraiReponse, $vraiReponseRow);
print_r($vraiReponseRow);
$err = 1;
foreach ($vraiReponseRow as $v){
for($i = 0 ; $i < sizeof($v, OCI_NUM) ; $i++){
if($v[$i] == $sqliteRow[0]){
$err = 0;
}
}
}
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";
}
//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;
}
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;
}
}
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";
}
}
echo 'Résultat : ' . $cmpt . '/' . $numQuestion;