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.

72 lines
2.9 KiB

<?php
require_once('../BDD/SqliteDb.php');
require_once('../controleur/Controleur.php');
$db = new SqliteDb('o');
$lol = 'ok';
if (empty($_GET['tp']) || empty($_GET['bdd']) || empty($_GET['num']) || empty($_GET['consigne']) || empty($_GET['reponse']) || empty($_GET['points']) || empty($_GET['aleatoire']) || empty($_GET['type'])) {
echo '<strong>ERREUR : Veuillez remplir tous les champs </strong>';
}
else if(!is_numeric($_GET['tp']))
echo '<strong>ERREUR : une valeur non numérique à été détectée dans le champ \'Numéro de question :\' </strong>';
else if(!is_numeric($_GET['num']))
echo '<strong>ERREUR : une valeur non numérique à été détectée dans le champ \'TP n° :\' </strong>';
else if(!is_numeric($_GET['points']))
echo '<strong>ERREUR : une valeur non numérique à été détectée dans le champ \'Barème:\' </strong>';
else {
if(isset($_GET['modif'])){
if ($_GET["type"] == 'fonction')
$db->supprimerFonction ($_GET['num'], $_GET['tp']);
else if ($_GET["type"] == 'requete')
$db->supprimerRequete($_GET['num'], $_GET['tp']);
}
if ($_GET["type"] == 'requete'){
$isAdd = $db->ajouterRequete($_GET['bdd'],$_GET['tp'],$_GET['num'],$_GET['consigne'], $_GET['reponse'],$_GET['points']);
if(!$isAdd){
echo '<strong>ERREUR : la combinaison (numéro de tp, numéro de question) existe déjà dans la bdd</strong>';
}
else echo '<strong>AJOUT Requete avec succès</strong>';
}
else if ($_GET["type"] == 'fonction'){
if(empty($_GET['fonction']))
echo 'ERREUR : Veuillez remplir tous les champs ';
else {
if(isset($_GET['modif'])){
$reponse = $_GET['reponse'];
$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],$string, $reponse);
$fonction = $_GET['fonction'];
$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],$string2, $fonction);
}
else {
$freponse = $reponse;
$ffonction = $fonction;
}
$isAdd = $db->ajouterFonction($_GET['bdd'],$_GET['tp'],$_GET['num'],$_GET['consigne'], $freponse,$ffonction,$reponse,$_GET['points']);
if(!$isAdd){
echo '<strong>ERREUR : la combinaison (numéro de tp, numéro de question) existe déjà dans la bdd</strong>';
}
else echo '<strong>AJOUT Fonction avec succès</strong>';
}
}
}
//require_once('index.php');
//header("Location: ../index.php");