Fixing delete question + cosmetic changes

skala
Julio Montoya 13 years ago
parent d9d4802998
commit 97aae33521
  1. 11
      main/exercice/question.class.php
  2. 8
      main/exercice/question_pool.php

@ -130,7 +130,8 @@ abstract class Question
$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
$sql = "SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id ";
$sql = "SELECT question,description,ponderation,position,type,picture,level,extra
FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id ";
$result = Database::query($sql);
@ -958,15 +959,19 @@ abstract class Question
if (!$deleteFromEx) {
//update the question_order of each question to avoid inconsistencies
$sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
$res = Database::query($sql);
if (Database::num_rows($res) > 0) {
while ($row = Database::fetch_array($res)) {
if (!empty($row['question_order'])) {
$sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order'];
$res = Database::query($sql);
$sql = "UPDATE $TBL_EXERCICE_QUESTION
SET question_order = question_order-1
WHERE c_id = $course_id AND exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$row['question_order'];
Database::query($sql);
}
}
}
$sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
Database::query($sql);

@ -122,9 +122,10 @@ if ($is_allowedToEdit) {
}
// deletes a question from the database and all exercises
if ($delete) {
// construction of the Question object
// Construction of the Question object
$objQuestionTmp = Question::read($delete);
// if the question exists
if ($objQuestionTmp = Question::read($delete)) {
if ($objQuestionTmp) {
// deletes the question from all exercises
$objQuestionTmp->delete();
}
@ -134,7 +135,7 @@ if ($is_allowedToEdit) {
// gets an existing question and copies it into a new exercise
$objQuestionTmp = Question :: read($recup);
// if the question exists
if($objQuestionTmp = Question :: read($recup)) {
if ($objQuestionTmp) {
// adds the exercise ID represented by $fromExercise into the list of exercises for the current question
$objQuestionTmp->addToList($fromExercise);
}
@ -148,7 +149,6 @@ if ($is_allowedToEdit) {
// adds the question ID represented by $recup into the list of questions for the current exercise
$objExercise->addToList($recup);
Session::write('objExercise', $objExercise);
// header("Location: admin.php?".api_get_cidreq()."&exerciseId=$fromExercise");
// exit();
}

Loading…
Cancel
Save