1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| case 'enregistrer_question_QUIZZ' :
$idQuizz = isset($_GET['idQUIZZ']) ? $_GET['idQUIZZ'] : $_POST['idQUIZZ'];
$limiteNbReponses = isset($_GET['limiteNbReponses']) ? $_GET['limiteNbReponses'] : $_POST['limiteNbReponses'];
$limiteNbQuestions = isset($_GET['limiteNbQuestions']) ? $_GET['limiteNbQuestions'] : $_POST['limiteNbQuestions'];
$numQuestion = isset($_GET['NumQuestion']) ? $_GET['NumQuestion'] : $_POST['NumQuestion'];
$Question = '';
$NbCheck = array();
$newQuestion = isset($_POST['newQuestion']) ? $_POST['newQuestion'] : -1;
if($newQuestion == -1 && isset($_POST['QUESTION_'.$numQuestion.''])){
$Question = isset($_POST['QUESTION_'.$numQuestion.'']) ? trim($_POST['QUESTION_'.$numQuestion.'']) : '';
$i=1;
for($i>=1; $i<=$limiteNbReponses; $i++){
$Reponse[$i] = isset($_POST['RESPONSE_'.$i.'']) ? trim($_POST['RESPONSE_'.$i.'']) : '';
$RepDefaut[$i] = isset($_POST['RESPONSE_CHECKBOX_'.$i.'']) ? 1 : 0;
}
$NbCheck = array_sum($RepDefaut);
if($numQuestion <= $limiteNbQuestions){
if($NbCheck >= 1){
if(isset($_POST['QUESTION_'.$numQuestion.''])){
if(trim($_POST['QUESTION_'.$numQuestion.'']) != ''){
$sel_question = " SELECT t_questions.NumeroQuestion
FROM db_quizz.tb_questions t_questions
WHERE t_questions.IdQuizz = '".$idQuizz."'
ORDER BY t_questions.NumeroQuestion DESC ";
// echo $sel_question;
$res_question = mysql_query($sel_question);
$row_question = mysql_fetch_array($res_question);
$numLastQuestion = $row_question['NumeroQuestion'] ? $row_question['NumeroQuestion'] : 0;
if($numLastQuestion < $numQuestion){
$description = addslashes(strip_tags(trim($_POST['QUESTION_'.$numQuestion.''])));
$ins_question = " INSERT
INTO db_quizz.tb_questions
(IdQuizz, DescriptionQuestion, NbReponseQuestion, NumeroQuestion)
VALUES
('".$idQuizz."', '".$description."', '".$limiteNbReponses."', '".$numQuestion."') ";
// echo $ins_question;
if(mysql_query($ins_question)){
$idQuestion = mysql_insert_id();
$numReponse = 1;
for($numReponse = 1; $numReponse <= $limiteNbReponses; $numReponse++){
if(isset($_POST['RESPONSE_'.$numReponse.''])){
if(trim($_POST['RESPONSE_'.$numReponse.''])){
$descriptionReponse = addslashes(strip_tags(trim($_POST['RESPONSE_'.$numReponse.''])));
$defautReponse = isset($_POST['RESPONSE_CHECKBOX_'.$numReponse.'']) ? 1 : 0;
$ins_response = " INSERT
INTO db_quizz.tb_reponses
( IdQuizz, IdQuestion, DescriptionReponse, DefautReponse, NumeroReponse)
VALUES
('".$idQuizz."', '".$idQuestion."', '".$descriptionReponse."', '".$defautReponse."', '".$numReponse."') ";
// echo $ins_response;
mysql_query($ins_response);
$Question = '';
$Reponse = array();
$RepDefaut = array();
}
else {
$_SESSION['message'] = '| Réponse '.$i.' obligatoire |';
}
}
else {
$_SESSION['message'] = '| Réponse '.$i.' obligatoire |';
}
}
$etatQuizz = 1;
$up_quizz = " UPDATE db_quizz.tb_quizz
SET NbQuestionQuizz = '".$numQuestion."', EtatQUizz = '".$etatQuizz."'
WHERE IdQuizz = '".$idQuizz."' ";
// echo $up_quizz;
mysql_query($up_quizz);
}
else {
$_SESSION['message'] = 'Erreur d\'enregistrement';
}
}
else {
$Question = '';
$Reponse = array();
$RepDefaut = array();
$_SESSION['message'] = 'Question '.$numQuestion.' est déjà enregistrer';
}
}
else {
$_SESSION['message'] = 'La question est obligatoire';
}
}
else {
$_SESSION['message'] = 'La question est obligatoire';
}
}
else {
$_SESSION['message'] = 'Merci de choisir au minimun une réponse possible (case à cocher)';
}
}
else {
$_SESSION['message'] = 'Le nombre maximal de question est atteint';
}
}
include 'vues/liste/modifier_quizz.php';
break; |
Partager