瀏覽代碼

Adding c_id in some queries + some cosmetic changes

Julio Montoya 13 年之前
父節點
當前提交
567f36c136
共有 3 個文件被更改,包括 106 次插入147 次删除
  1. 13 22
      main/exercice/answer.class.php
  2. 5 16
      main/exercice/exercise.class.php
  3. 88 109
      main/exercice/question.class.php

+ 13 - 22
main/exercice/answer.class.php

@@ -63,7 +63,7 @@ class Answer {
 		$this->cancel();
         
         if (!empty($course_id)) {            
-            $course_info            =  api_get_course_info_by_id($course_id);
+            $course_info = api_get_course_info_by_id($course_id);
         } else {            
             $course_info = api_get_course_info();
         }
@@ -153,8 +153,6 @@ class Answer {
 		$sql = "SELECT type FROM $TBL_QUIZ WHERE c_id = {$this->course_id} AND id = $questionId";
 		$result_question=Database::query($sql);
 		$question_type=Database::fetch_array($result_question);
-		$remove_doubt_answer = ''; //
-	
 		
 		$sql="SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto " .
 				"FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id='".$questionId."'   " .
@@ -199,8 +197,7 @@ class Answer {
 	 * @author - Juan Carlos Ra�a
 	 * @return - integer - answer num
 	 */
-	function selectAutoId($id)
-	{
+	function selectAutoId($id) {
 		return $this->autoId[$id];
 	}
 
@@ -211,8 +208,7 @@ class Answer {
 	 * @author - Olivier Brouckaert
 	 * @return - integer - number of answers
 	 */
-	function selectNbrAnswers()
-	{
+	function selectNbrAnswers() {
 		return $this->nbrAnswers;
 	}
 
@@ -222,8 +218,7 @@ class Answer {
 	 * @author - Olivier Brouckaert
 	 * @return - integer - the question ID
 	 */
-	function selectQuestionId()
-	{
+	function selectQuestionId() {
 		return $this->questionId;
 	}
 
@@ -233,8 +228,7 @@ class Answer {
 	 * @author - Julio Montoya
 	 * @return - integer - the question ID
 	 */
-	function selectDestination($id)
-	{
+	function selectDestination($id) {
 		return $this->destination[$id];
 	}
 
@@ -245,8 +239,7 @@ class Answer {
 	 * @param - integer $id - answer ID
 	 * @return - string - answer title
 	 */
-	function selectAnswer($id)
-	{
+	function selectAnswer($id) {
 		return $this->answer[$id];
 	}
 
@@ -299,10 +292,10 @@ class Answer {
 	 			}
 	        	
 	 			$list[] = array(
-						'id'=>$i,
-						'answer'=>$this->answer[$i],
-						'comment'=>$this->comment[$i],
-						'grade' => $this->weighting[$i],
+						'id'            => $i,
+						'answer'        => $this->answer[$i],
+						'comment'       => $this->comment[$i],
+						'grade'         => $this->weighting[$i],
 						'hotspot_coord' => $this->hotspot_coordinates[$i],
 						'hotspot_type'	=> $this->hotspot_type[$i],
 						'correct'		=> $this->correct[$i],
@@ -317,8 +310,7 @@ class Answer {
 	 * @author Yannick Warnier <ywarnier@beeznest.org>
 	 * @return array	List of grades where grade=weighting (?)
 	 */
-	 function getGradesList()
-	 {
+	 function getGradesList() {
 	 	$list = array();
 	 	for($i = 0; $i<$this->nbrAnswers;$i++){
 	 		if(!empty($this->answer[$i])){
@@ -429,8 +421,7 @@ class Answer {
 	 * @param coordinates 	Coordinates for hotspot exercises (optional)
 	 * @param integer		Type for hotspot exercises (optional)
 	 */
-	function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = NULL, $new_hotspot_type = NULL,$destination='')
-	{
+	function createAnswer($answer,$correct,$comment,$weighting,$position,$new_hotspot_coordinates = NULL, $new_hotspot_type = NULL,$destination='') {
 		$this->new_nbrAnswers++;
 		$id=$this->new_nbrAnswers;
 		$this->new_answer[$id]=$answer;
@@ -588,4 +579,4 @@ class Answer {
 		}
 	}
 }
-endif;
+endif;

+ 5 - 16
main/exercice/exercise.class.php

@@ -246,15 +246,12 @@ class Exercise {
 		return $this->type;
 	}
 
-
-
 	/**
 	 * @author - hubert borderiou 30-11-11
 	 * @return - integer : do we display the question category name for students
 	 */
 	function selectDisplayCategoryName() {
 		return $this->display_category_name;
-
 	}
 
 	/**
@@ -273,7 +270,6 @@ class Exercise {
 	 */
 	function selectTextWhenFinished() {
 		return $this->text_when_finished;
-
 	}
 
 	/**
@@ -542,8 +538,7 @@ class Exercise {
 	function updateSound($sound,$delete) {
 		global $audioPath, $documentPath;
 		$TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
-		$TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
-
+        
 		if ($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video'))) {
 			$this->sound=$sound['name'];
 
@@ -753,7 +748,6 @@ class Exercise {
 
 	/* Updates question position */
 	function update_question_positions() {
-
 		$quiz_question_table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
 		//Fixes #3483 when updating order
 		$question_list = $this->selectQuestionList(true);
@@ -814,7 +808,6 @@ class Exercise {
 			}
 			// deletes the position from the array containing the wanted question ID
 			unset($this->questionList[$pos]);
-
 			return true;
 		}
 	}
@@ -825,8 +818,7 @@ class Exercise {
 	 *
 	 * @author - Olivier Brouckaert
 	 */
-	function delete() {
-		global $_course;
+	function delete() {		
 		$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
 		$sql="UPDATE $TBL_EXERCICES SET active='-1' WHERE c_id = ".$this->course_id." AND id='".Database::escape_string($this->id)."'";
 		Database::query($sql);
@@ -3504,11 +3496,8 @@ class Exercise {
 						$result .= $value;
 					}
 			}
-		}
-		
+		}		
 		return $result;
-	}
-	
-	
+	}	
 }
-endif;
+endif;

+ 88 - 109
main/exercice/question.class.php

@@ -56,17 +56,17 @@ abstract class Question
 	static $explanationLangVar = '';
     
 	static $questionTypes = array(
-							UNIQUE_ANSWER => 				array('unique_answer.class.php' , 	'UniqueAnswer'),
-							MULTIPLE_ANSWER => 				array('multiple_answer.class.php' , 'MultipleAnswer'),
-							FILL_IN_BLANKS => 				array('fill_blanks.class.php' , 	'FillBlanks'),
-							MATCHING => 					array('matching.class.php' , 		'Matching'),
-							FREE_ANSWER => 					array('freeanswer.class.php' , 		'FreeAnswer'),
-							HOT_SPOT => 					array('hotspot.class.php' , 		'HotSpot'),
-							HOT_SPOT_DELINEATION => 		array('hotspot.class.php' , 'HotspotDelineation'),
-							MULTIPLE_ANSWER_COMBINATION =>	array('multiple_answer_combination.class.php' , 'MultipleAnswerCombination'),
-                            UNIQUE_ANSWER_NO_OPTION =>      array('unique_answer_no_option.class.php' ,   'UniqueAnswerNoOption'),
-                            MULTIPLE_ANSWER_TRUE_FALSE =>   array('multiple_answer_true_false.class.php' , 'MultipleAnswerTrueFalse'),
-                            MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE =>   array('multiple_answer_combination_true_false.class.php' , 'MultipleAnswerCombinationTrueFalse'),
+                                UNIQUE_ANSWER => 				array('unique_answer.class.php' , 	'UniqueAnswer'),
+                                MULTIPLE_ANSWER => 				array('multiple_answer.class.php' , 'MultipleAnswer'),
+                                FILL_IN_BLANKS => 				array('fill_blanks.class.php' , 	'FillBlanks'),
+                                MATCHING => 					array('matching.class.php' , 		'Matching'),
+                                FREE_ANSWER => 					array('freeanswer.class.php' , 		'FreeAnswer'),
+                                HOT_SPOT => 					array('hotspot.class.php' , 		'HotSpot'),
+                                HOT_SPOT_DELINEATION =>         array('hotspot.class.php' , 'HotspotDelineation'),
+                                MULTIPLE_ANSWER_COMBINATION =>	array('multiple_answer_combination.class.php' , 'MultipleAnswerCombination'),
+                                UNIQUE_ANSWER_NO_OPTION =>      array('unique_answer_no_option.class.php' ,   'UniqueAnswerNoOption'),
+                                MULTIPLE_ANSWER_TRUE_FALSE =>   array('multiple_answer_true_false.class.php' , 'MultipleAnswerTrueFalse'),
+                                MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE =>   array('multiple_answer_combination_true_false.class.php' , 'MultipleAnswerCombinationTrueFalse'),
                             
 							);
 
@@ -109,8 +109,7 @@ abstract class Question
         
         if (!empty($course_id)) {            
             $course_info =  api_get_course_info_by_id($course_id);
-        } else {
-            global $course;
+        } else {            
             $course_info = api_get_course_info();
         }        
         
@@ -205,8 +204,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - integer - question position
 	 */
-	function selectPosition()
-	{
+	function selectPosition() {
 		return $this->position;
 	}
 
@@ -216,8 +214,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - integer - answer type
 	 */
-	function selectType()
-	{
+	function selectType() {
 		return $this->type;
 	}
 
@@ -227,8 +224,7 @@ abstract class Question
 	 * @author - Nicolas Raynaud
 	 * @return - integer - level of the question, 0 by default.
 	 */
-	function selectLevel()
-	{
+	function selectLevel() {
 		return $this->level;
 	}
 
@@ -238,8 +234,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - string - picture name
 	 */
-	function selectPicture()
-	{
+	function selectPicture() {
 		return $this->picture;
 	}
     
@@ -256,8 +251,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - array - list of exercise ID which the question is in
 	 */
-	function selectExerciseList()
-	{
+	function selectExerciseList() {
 		return $this->exerciseList;
 	}
 
@@ -267,8 +261,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - integer - number of exercises
 	 */
-	function selectNbrExercises()
-	{
+	function selectNbrExercises() {
 		return sizeof($this->exerciseList);
 	}
 
@@ -278,8 +271,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @param - string $title - question title
 	 */
-	function updateTitle($title)
-	{
+	function updateTitle($title) {
 		$this->question=$title;
 	}
 
@@ -289,8 +281,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @param - string $description - question description
 	 */
-	function updateDescription($description)
-	{
+	function updateDescription($description) {
 		$this->description=$description;
 	}
 
@@ -300,8 +291,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @param - integer $weighting - question weighting
 	 */
-	function updateWeighting($weighting)
-	{
+	function updateWeighting($weighting) {
 		$this->weighting=$weighting;
 	}
 
@@ -339,9 +329,9 @@ abstract class Question
 	function saveCategory($in_category) {
 		if ($in_category <= 0) {
 			$this->deleteCategory();
-		}
-		// update or add category for a question
-		else {
+		} else {
+            // update or add category for a question
+            
 			$TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
 			$category_id = Database::escape_string($in_category);
 			$question_id = Database::escape_string($this->id);
@@ -351,8 +341,7 @@ abstract class Question
 			if ($row['nb'] > 0){
 				$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id=$category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id();
 				$res = Database::query($sql);
-			}
-			else {
+			} else {
 				$sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id().", $question_id, $category_id)";
 				$res = Database::query($sql);
 			}
@@ -379,8 +368,7 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @param - integer $position - question position
 	 */
-	function updatePosition($position)
-	{
+	function updatePosition($position) {
 		$this->position=$position;
 	}
 
@@ -390,8 +378,7 @@ abstract class Question
 	 * @author - Nicolas Raynaud
 	 * @param - integer $level - question level
 	 */
-	function updateLevel($level)
-	{
+	function updateLevel($level) {
 		$this->level=$level;
 	}
 
@@ -403,14 +390,18 @@ abstract class Question
 	 * @param - integer $type - answer type
 	 */
 	function updateType($type) {
-		$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
-
+		$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER);
+        $course_id              = $this->course['real_id'];
+        
+        if (empty($course_id)) {
+            $course_id = api_get_course_int_id();
+        }
 		// if we really change the type
 		if($type != $this->type) {
 			// if we don't change from "unique answer" to "multiple answers" (or conversely)
 			if(!in_array($this->type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER)) || !in_array($type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER))) {
 				// removes old answers
-				$sql="DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($this->id)."'";
+				$sql="DELETE FROM $TBL_REPONSES WHERE c_id = $course_id  AND question_id='".Database::escape_string($this->id)."'";
 				Database::query($sql);
 			}
 
@@ -529,13 +520,11 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - boolean - true if removed, otherwise false
 	 */
-	function removePicture()
-	{
+	function removePicture() {
 		global $picturePath;
 
 		// if the question has got an ID and if the picture exists
-		if($this->id)
-		{
+		if($this->id) {
 			$picture=$this->picture;
 			$this->picture='';
 
@@ -592,20 +581,16 @@ abstract class Question
 	/**
 		Sets the title
 	*/
-	public function setTitle($title)
-	{
+	public function setTitle($title) {
 		$this->question = $title;
 	}
     
     /**
         Sets the title
     */
-    public function setExtra($extra)
-    {
+    public function setExtra($extra) {
         $this->extra = $extra;
     }
-    
-
 
 	/**
 	 * Moves the temporary question "tmp" to "quiz-$questionId"
@@ -615,15 +600,12 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @return - boolean - true if moved, otherwise false
 	 */
-	function getTmpPicture()
-	{
+	function getTmpPicture() {
 		global $picturePath;
 
 		// if the question has got an ID and if the picture exists
-		if($this->id)
-		{
-			if(file_exists($picturePath.'/tmp.jpg'))
-			{
+		if($this->id) {
+			if(file_exists($picturePath.'/tmp.jpg')) {
 				$Extension='jpg';
 			}
 			elseif(file_exists($picturePath.'/tmp.gif'))
@@ -664,7 +646,7 @@ abstract class Question
 		$level			= $this->level;
         $extra			= $this->extra;
         $c_id 			= $this->course['real_id'];
-        $category   = $this->category;	// hub 12-10-2011
+        $category       = $this->category;
      
     
 		// question already exists
@@ -684,26 +666,23 @@ abstract class Question
 			if (!empty($exerciseId)) {
 				api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionUpdated',api_get_user_id);
 			}
-      if (api_get_setting('search_enabled')=='true') {
-	      if ($exerciseId != 0) {
-	        $this -> search_engine_edit($exerciseId);
-	      } else {
-	        /**
-	         * actually there is *not* an user interface for
-	         * creating questions without a relation with an exercise
-	         */
-	      }
-      }
-
+            if (api_get_setting('search_enabled')=='true') {
+                if ($exerciseId != 0) {
+                    $this -> search_engine_edit($exerciseId);
+                } else {
+                    /**
+                    * actually there is *not* an user interface for
+                    * creating questions without a relation with an exercise
+                    */
+                }
+            }
 		} else {
 			// creates a new question
 			$sql	= "SELECT max(position) FROM $TBL_QUESTIONS as question, $TBL_EXERCICE_QUESTION as test_question 
 					   WHERE 	question.id					= test_question.question_id AND 
 								test_question.exercice_id	= '".Database::escape_string($exerciseId)."' AND
 								question.c_id 				= $c_id AND
-								test_question.c_id 			= $c_id
-								
-						";
+								test_question.c_id 			= $c_id ";
 			$result	= Database::query($sql);
 			$current_position = Database::result($result,0,0);
 			$this->updatePosition($current_position+1);
@@ -741,17 +720,16 @@ abstract class Question
 			}
 			
 
-      if (api_get_setting('search_enabled')=='true') {
-	      if ($exerciseId != 0) {
-	        $this -> search_engine_edit($exerciseId, TRUE);
-	      } 
-	      else {
-	        /**
-	         * actually there is *not* an user interface for
-	         * creating questions without a relation with an exercise
-	         */
-	      }
-      }
+            if (api_get_setting('search_enabled')=='true') {
+                if ($exerciseId != 0) {
+                    $this -> search_engine_edit($exerciseId, TRUE);
+                } else {
+                    /**
+                    * actually there is *not* an user interface for
+                    * creating questions without a relation with an exercise
+                    */
+                }
+            }
 		}
 
 		// if the question is created in an exercise
@@ -912,10 +890,12 @@ abstract class Question
 	function removeFromList($exerciseId) {
 		global $TBL_EXERCICE_QUESTION;
 
-		$id=$this->id;
+		$id = $this->id;
 
 		// searches the position of the exercise ID in the list
 		$pos=array_search($exerciseId,$this->exerciseList);
+        
+        $course_id = api_get_course_int_id();
 
 		// exercise not found
 		if($pos === false) {
@@ -924,17 +904,18 @@ abstract class Question
 			// deletes the position in the array containing the wanted exercise ID
 			unset($this->exerciseList[$pos]);
             //update order of other elements
-            $sql = "SELECT question_order FROM $TBL_EXERCICE_QUESTION WHERE question_id='".Database::escape_string($id)."' AND exercice_id='".Database::escape_string($exerciseId)."'";
+            $sql = "SELECT question_order FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND exercice_id='".Database::escape_string($exerciseId)."'";
             $res = Database::query($sql);
             if (Database::num_rows($res)>0) {
                 $row = Database::fetch_array($res);
                 if (!empty($row['question_order'])) {
-                    $sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 WHERE exercice_id='".Database::escape_string($exerciseId)."' AND question_order > ".$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($exerciseId)."' AND question_order > ".$row['question_order'];
                     $res = Database::query($sql);
                 }
             }
 
-			$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE question_id='".Database::escape_string($id)."' AND exercice_id='".Database::escape_string($exerciseId)."'";
+			$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND exercice_id='".Database::escape_string($exerciseId)."'";
 			Database::query($sql);
 
 			return true;
@@ -949,41 +930,40 @@ abstract class Question
 	 * @author - Olivier Brouckaert
 	 * @param - integer $deleteFromEx - exercise ID if the question is only removed from one exercise
 	 */
-	function delete($deleteFromEx=0) {
-		global $_course,$_user;
+	function delete($deleteFromEx=0) {		       
+        $course_id = api_get_course_int_id();
 
-		$TBL_EXERCICE_QUESTION	= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $this->course['db_name']);
-		$TBL_QUESTIONS			= Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
-		$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
-		$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY, $this->course['db_name']);	// hub 12-10-2011
+		$TBL_EXERCICE_QUESTION	= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+		$TBL_QUESTIONS			= Database::get_course_table(TABLE_QUIZ_QUESTION);
+		$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER);
+		$TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
 		
 		$id=$this->id;
 
 		// if the question must be removed from all exercises
-		if(!$deleteFromEx)
-		{
+		if(!$deleteFromEx) {
             //update the question_order of each question to avoid inconsistencies
-            $sql = "SELECT exercice_id, question_order FROM $TBL_EXERCICE_QUESTION WHERE question_id='".Database::escape_string($id)."'";
+            $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 exercice_id='".Database::escape_string($row['exercice_id'])."' AND question_order > ".$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="DELETE FROM $TBL_EXERCICE_QUESTION WHERE question_id='".Database::escape_string($id)."'";
+			$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
 			Database::query($sql);
 
-			$sql="DELETE FROM $TBL_QUESTIONS WHERE id='".Database::escape_string($id)."'";
+			$sql="DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id='".Database::escape_string($id)."'";
 			Database::query($sql);
 
-			$sql="DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($id)."'";
+			$sql="DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."'";
 			Database::query($sql);
 
 			// hub 12-10-2011 remove the category of this question in the question_rel_category table
-			$sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY WHERE question_id='".Database::escape_string($id)."' AND c_id=".api_get_course_int_id();
+			$sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY WHERE c_id = $course_id AND question_id='".Database::escape_string($id)."' AND c_id=".api_get_course_int_id();
 			Database::query($sql);
 			
 			api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id());
@@ -991,10 +971,8 @@ abstract class Question
 
 			// resets the object
 			$this->Question();
-		}
-		// just removes the exercise from the list
-		else
-		{
+		} else {
+            // just removes the exercise from the list            
 			$this->removeFromList($deleteFromEx);
             if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
                 // disassociate question with this exercise
@@ -1018,8 +996,8 @@ abstract class Question
         } else {
         	$course_info = $course_info;
         }
-        $TBL_QUESTIONS        = Database::get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
-        $TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION, $course_info['db_name']);
+        $TBL_QUESTIONS        = Database::get_course_table(TABLE_QUIZ_QUESTION);
+        $TBL_QUESTION_OPTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
 
 		$question     = $this->question;
 		$description  = $this->description;
@@ -1031,6 +1009,7 @@ abstract class Question
         
         //Using the same method used in the course copy to transform URLs
         require_once api_get_path(LIBRARY_PATH).'document.lib.php';
+        
         if ($course_info['db_name'] != $this->course['db_name']) {
             $description  = DocumentManager::replace_urls_inside_content_html_from_copy_course($description, $this->course['id'], $course_info['id']);
             $question     = DocumentManager::replace_urls_inside_content_html_from_copy_course($question, $this->course['id'], $course_info['id']);