Julio Montoya пре 13 година
родитељ
комит
0865dc337a

+ 4 - 2
main/coursecopy/classes/CourseRestorer.class.php

@@ -1134,11 +1134,13 @@ class CourseRestorer
 					$sql = "INSERT INTO ".$table_ans." SET c_id = ".$this->destination_course_id." , id= '". ($index +1)."',question_id = '".$new_id."', answer = '".self::DBUTF8escapestring($answer['answer'])."', correct = '".$answer['correct']."', comment = '".self::DBUTF8escapestring($answer['comment'])."', ponderation='".$answer['ponderation']."', position = '".$answer['position']."', hotspot_coordinates = '".$answer['hotspot_coordinates']."', hotspot_type = '".$answer['hotspot_type']."'";
 					Database::query($sql);
 				}
-			}           
+			}         
+            //@todo check this  
+            $course_id = api_get_course_int_id();
             
             //Moving quiz_question_options
             if ($question->quiz_type == MULTIPLE_ANSWER_TRUE_FALSE) {                
-                $question_option_list = Question::readQuestionOption($id);                
+                $question_option_list = Question::readQuestionOption($id, $course_id);                
                 $old_option_ids = array();            
                 foreach ($question_option_list  as $item) {
                     $old_id = $item['id'];                    

+ 0 - 11
main/exercice/addlimits.php

@@ -27,17 +27,6 @@ $this_section=SECTION_COURSES;
 
 api_protect_course_script();
 
-//Table definitions
-
-$TBL_EXERCICE_QUESTION 	= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-$TBL_EXERCICES        	= Database::get_course_table(TABLE_QUIZ_TEST);
-$TBL_QUESTIONS         	= Database::get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_REPONSES          	= Database::get_course_table(TABLE_QUIZ_ANSWER);
-$main_user_table 		= Database::get_main_table(TABLE_MAIN_USER);
-$main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
-$TBL_TRACK_EXERCICES	= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
-$TBL_TRACK_ATTEMPT		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
-
 $dsp_percent = false;
 $debug=0;
 if($debug>0)

+ 2 - 1
main/exercice/admin.php

@@ -132,9 +132,10 @@ $picturePath = $documentPath.'/images';
 $audioPath=$documentPath.'/audio';
 
 // the 5 types of answers
-$aType=array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('FillBlanks'),get_lang('Matching'),get_lang('FreeAnswer'));
+$aType = array(get_lang('UniqueSelect'),get_lang('MultipleSelect'),get_lang('FillBlanks'),get_lang('Matching'),get_lang('FreeAnswer'));
 
 // tables used in the exercise tool
+//@todo remove if this declarations are not used
 $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
 $TBL_EXERCICES         = Database::get_course_table(TABLE_QUIZ_TEST);
 $TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION);

+ 0 - 9
main/exercice/adminhp.php

@@ -51,16 +51,7 @@ $picturePath=$documentPath.'/images';
 // audio path
 $audioPath=$documentPath.'/audio';
 
-
-
 // Database table definitions
-$TBL_EXERCICE_QUESTION		= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-$TBL_EXERCICES				= Database::get_course_table(TABLE_QUIZ_TEST);
-$TBL_QUESTIONS				= Database::get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_REPONSES				= Database::get_course_table(TABLE_QUIZ_ANSWER);
-$TBL_DOCUMENT				= Database::get_course_table(TABLE_DOCUMENT);
-$dbTable					= $TBL_DOCUMENT;
-
 if (!$is_allowedToEdit) {
     api_not_allowed(true);
 }

+ 30 - 36
main/exercice/answer.class.php

@@ -62,13 +62,13 @@ class Answer {
 		// clears $new_* arrays
 		$this->cancel();
         
-        if (!empty($course_id)) {
-            $this->course_id        = intval($course_id);
-            $course_info            =  api_get_course_info_by_id($this->course_id);
+        if (!empty($course_id)) {            
+            $course_info            =  api_get_course_info_by_id($course_id);
         } else {            
             $course_info = api_get_course_info();
         }
-        $this->course   = $course_info; 
+        $this->course    = $course_info;
+        $this->course_id = $course_info['real_id'];
         
 
 		// fills arrays
@@ -104,16 +104,13 @@ class Answer {
 	 * @author - Olivier Brouckaert
 	 */
 	function read() {		
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
-
+		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
 		$questionId=$this->questionId;
-		//$answerType=$this->selectType();
-
+        
 		$sql="SELECT id,answer,correct,comment,ponderation, position, hotspot_coordinates, hotspot_type, destination, id_auto FROM
-		      $TBL_ANSWER WHERE question_id ='".$questionId."' ORDER BY position";
+		      $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id ='".$questionId."' ORDER BY position";
 
 		$result=Database::query($sql);
-
 		$i=1;
 
 		// while a record is found
@@ -138,7 +135,7 @@ class Answer {
 	 * @param	string	DESC or ASC
 	 * @author 	Frederic Vauthier
 	 */
-	function readOrderedBy($field,$order='ASC') {		
+	function readOrderedBy($field, $order='ASC') {		
 		$field = Database::escape_string($field);
 		if (empty($field)) {
 			$field = 'position';
@@ -147,18 +144,20 @@ class Answer {
 		if ($order != 'ASC' && $order!='DESC') {
 			$order = 'ASC';
 		}
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
-		$TBL_QUIZ= Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
+        
+                
+		$TBL_ANSWER   = Database::get_course_table(TABLE_QUIZ_ANSWER);
+		$TBL_QUIZ     = Database::get_course_table(TABLE_QUIZ_QUESTION);
 		$questionId=intval($this->questionId);
 		
-		$sql = "SELECT type FROM $TBL_QUIZ WHERE id = $questionId";
+		$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 question_id='".$questionId."'   " .
+				"FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id='".$questionId."'   " .
 				"ORDER BY $field $order";		
 		$result=Database::query($sql);	
 		
@@ -190,9 +189,7 @@ class Answer {
 			$this->autoId[$i]		= $doubt_data->id_auto;
 			$i++;		     
 	    }
-	
-		
-		$this->nbrAnswers=$i-1;
+        $this->nbrAnswers=$i-1;
 	}
 
 
@@ -257,9 +254,10 @@ class Answer {
 	 * return array answer by id else return a bool
 	 */
 	function selectAnswerByAutoId($auto_id) {
-		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
+		$TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);        
+        
 		$auto_id = intval($auto_id);
-		$sql="SELECT id, answer FROM $TBL_ANSWER WHERE id_auto='$auto_id'";
+		$sql="SELECT id, answer FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND id_auto='$auto_id'";
 		$rs = Database::query($sql);
 
 		if (Database::num_rows($rs)>0) {
@@ -267,7 +265,6 @@ class Answer {
 			return $row;
 		}
 		return false;
-
 	}
 
 	/**
@@ -336,10 +333,9 @@ class Answer {
 	  * @author	Yannick Warnier <ywarnier@beeznest.org>
 	  * @return	integer	The type of the question this answer is bound to
 	  */
-	 function getQuestionType()
-	 {
-	 	$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION, $this->course['db_name']);
-	 	$sql = "SELECT type FROM $TBL_QUESTIONS WHERE id = '".$this->questionId."'";
+	 function getQuestionType() {
+	 	$TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
+	 	$sql = "SELECT type FROM $TBL_QUESTIONS WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'";
 	 	$res = Database::query($sql);
 	 	if(Database::num_rows($res)<=0){
 	 		return null;
@@ -456,9 +452,8 @@ class Answer {
 	 * @param	integer	Answer weighting
 	 * @param	integer	Answer position
 	 */
-	function updateAnswers($answer,$comment,$weighting,$position,$destination)
-	{
-		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
+	function updateAnswers($answer,$comment,$weighting,$position,$destination) {
+		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
 
 		$questionId=$this->questionId;
 		$sql = "UPDATE $TBL_REPONSES SET " .
@@ -467,7 +462,7 @@ class Answer {
 				"ponderation = '".Database::escape_string($weighting)."', " .
 				"position = '".Database::escape_string($position)."', " .
 				"destination = '".Database::escape_string($destination)."' " .
-				"WHERE id = '".Database::escape_string($position)."' " .
+				"WHERE c_id = {$this->course_id} AND id = '".Database::escape_string($position)."' " .
 				"AND question_i = '".Database::escape_string($questionId)."'";
 
 		Database::query($sql);
@@ -479,12 +474,11 @@ class Answer {
 	 * @author - Olivier Brouckaert
 	 */
 	function save() {
-		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $this->course['db_name']);
-
-		$questionId=$this->questionId;
+		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
+		$questionId   = intval($this->questionId);
 
 		// removes old answers before inserting of new ones
-		$sql = "DELETE FROM $TBL_REPONSES WHERE question_id='".Database::escape_string($questionId)."'";
+		$sql = "DELETE FROM $TBL_REPONSES WHERE c_id = {$this->course_id} AND question_id = '".($questionId)."'";
 		Database::query($sql);
 		$c_id = $this->course['real_id'];
 		// inserts new answers into data base
@@ -535,12 +529,12 @@ class Answer {
             $course_info = $course_info;
         }
         
-		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER, $course_info['db_name']);
+		$TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
         
         if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE) {                
                            
             //Selecting origin options
-            $origin_options = Question::readQuestionOption($this->selectQuestionId(),$this->course['db_name']);
+            $origin_options = Question::readQuestionOption($this->selectQuestionId(), $course_info['real_id']);
             //var_dump($origin_options);
             if (!empty($origin_options)) {
                 foreach($origin_options as $item) {
@@ -548,7 +542,7 @@ class Answer {
                 }
             }            
             
-            $destination_options = Question::readQuestionOption($newQuestionId,$course_info['db_name']);
+            $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
             $i=0;
             $fixed_list = array();
             if (!empty($destination_options)) {

+ 6 - 14
main/exercice/answer_admin.inc.php

@@ -780,23 +780,15 @@ if($modifyAnswers)
         {
             $nbrMatches=2;
         }
-
-    }
-    elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
-    {
+    } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
 		if($debug>0){echo str_repeat('&nbsp;',2).'$answerType is HOT_SPOT'."<br />\n";}
 
-		$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
-
-		if(!$nbrAnswers)
-        {
-
+		if(!$nbrAnswers) {
             $nbrAnswers=$objAnswer->selectNbrAnswers();
-
-            $reponse=Array();
-            $comment=Array();
-            $weighting=Array();
-            $hotspot_coordinates=Array();
+            $reponse=array();
+            $comment=array();
+            $weighting=array();
+            $hotspot_coordinates=array();
             $hotspot_type=array();
 
 

+ 4 - 3
main/exercice/exercise.class.php

@@ -1757,7 +1757,8 @@ class Exercise {
 		$table_ans              = Database::get_course_table(TABLE_QUIZ_ANSWER);
 
 		// Creates a temporary Question object
-		$objQuestionTmp         = Question::read($questionId, api_get_course_int_id());
+		$course_id              = api_get_course_int_id();
+		$objQuestionTmp         = Question::read($questionId, $course_id);
 		
 		$questionName 			= $objQuestionTmp->selectTitle();
 		$questionDescription 	= $objQuestionTmp->selectDescription();
@@ -1798,7 +1799,7 @@ class Exercise {
 		$user_answer = '';
 
 		// Get answer list for matching
-		$sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id = "'.$questionId.'" ';
+		$sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE c_id = '.$course_id.' AND question_id = "'.$questionId.'" ';
 		$res_answer = Database::query($sql_answer);
 		$answer_matching =array();
 		while ($real_answer = Database::fetch_array($res_answer)) {
@@ -1806,7 +1807,7 @@ class Exercise {
 		}
 
 		$real_answers = array();
-		$quiz_question_options = Question::readQuestionOption($questionId);
+		$quiz_question_options = Question::readQuestionOption($questionId, $course_id);
 		
 		$organs_at_risk_hit = 0;
 

+ 16 - 3
main/exercice/exercise.lib.php

@@ -16,6 +16,19 @@
 // The initialization class for the online editor is needed here.
 require_once dirname(__FILE__).'/../inc/lib/fckeditor/fckeditor.php';
 
+$TBL_EXERCICE_QUESTION      = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+$TBL_EXERCICES              = Database::get_course_table(TABLE_QUIZ_TEST);
+$TBL_QUESTIONS              = Database::get_course_table(TABLE_QUIZ_QUESTION);
+$TBL_REPONSES               = Database::get_course_table(TABLE_QUIZ_ANSWER);
+$TBL_DOCUMENT               = Database::get_course_table(TABLE_DOCUMENT);
+
+$main_user_table        = Database::get_main_table(TABLE_MAIN_USER);
+$main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
+$TBL_TRACK_EXERCICES    = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+$TBL_TRACK_ATTEMPT      = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
+
+
+
 /**
  * Shows a question
  * 
@@ -77,8 +90,8 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
 		$objAnswerTmp = new Answer($questionId);
         
 		$nbrAnswers   = $objAnswerTmp->selectNbrAnswers();
-        
-        $quiz_question_options = Question::readQuestionOption($questionId);
+        $course_id = api_get_course_int_id();
+        $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
         
 		// For "matching" type here, we need something a little bit special
 		// because the match between the suggestions and the answers cannot be
@@ -1275,7 +1288,7 @@ function get_all_exercises_for_course_id($course_info = null, $session_id = 0, $
     	$session_id  = 0;
     }
     if ($session_id == 0) {
-    	$conditions = array('where'=>array('active = ? AND session_id = ? AND c_id=?'=>array('1', $session_id, $course_id)), 'order'=>'title');
+    	$conditions = array('where'=>array('active = ? AND session_id = ? AND c_id = ?'=>array('1', $session_id, $course_id)), 'order'=>'title');
     } else {
         //All exercises
     	$conditions = array('where'=>array('active = ? AND (session_id = 0 OR session_id = ? ) AND c_id=?' =>array('1', $session_id, $course_id)), 'order'=>'title');

+ 6 - 11
main/exercice/hotpotatoes.lib.php

@@ -9,6 +9,7 @@
 
 $dbTable = Database::get_course_table(TABLE_DOCUMENT); // TODO: This is a global variable with too simple name, conflicts are possible. Better eliminate it. Correct the test unit too.
 
+
 /**
  * Creates a hotpotato directory.
  *
@@ -45,9 +46,7 @@ function hotpotatoes_init($base_work_dir) {
  * @return  string    The exercise title
  */
 function GetQuizName($fname, $fpath) {
-
     $title = GetComment($fname);
-
     if (trim($title) == '') {
         if (file_exists($fpath.$fname)) {
             if (!($fp = @fopen($fpath.$fname, 'r'))) {
@@ -74,16 +73,11 @@ function GetQuizName($fname, $fpath) {
  * Added conditional to the table if is empty.
  */
 function GetComment($path, $course_code = '') {
-    global $dbTable;
-
-    if (!empty($course_code)) {
-        $course_info = api_get_course_info($course_code);
-        $dbTable     = Database::get_course_table(TABLE_DOCUMENT, $course_info['dbName']);
-    }
+    global $dbTable;    
+    $course_info = api_get_course_info($course_code);            
     $path = Database::escape_string($path);
-    $query = "SELECT comment FROM $dbTable WHERE path='$path'";
+    $query = "SELECT comment FROM $dbTable WHERE c_id = {$course_info['real_id']} AND path='$path'";
     $result = Database::query($query);
-
     while ($row = Database::fetch_array($result)) {
         return $row[0];
     }
@@ -100,7 +94,8 @@ function SetComment($path, $comment) {
     global $dbTable;
     $path = Database::escape_string($path);
     $comment = Database::escape_string($comment);
-    $query = "UPDATE $dbTable SET comment='$comment' WHERE path='$path'";
+    $course_id = api_get_course_int_id();
+    $query = "UPDATE $dbTable SET comment='$comment' WHERE $course_id AND path='$path'";
     $result = Database::query($query);
     return "$result";
 }

+ 2 - 1
main/exercice/hotpotatoes.php

@@ -46,6 +46,7 @@ $is_allowedToEdit = api_is_allowed_to_edit(null, true);
 
 // Database table definitions.
 $dbTable        = Database::get_course_table(TABLE_DOCUMENT);
+$course_id = api_get_course_int_id();
 
 // Setting some variables.
 $document_sys_path = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
@@ -149,7 +150,7 @@ if ((api_is_allowed_to_edit(null, true)) && (($finish == 0) || ($finish == 2)))
                     }
 
                     $title = @htmlspecialchars(GetQuizName($filename, $document_sys_path.$uploadPath.'/'.$fld.'/'), ENT_COMPAT, api_get_system_encoding());
-                    $query = "UPDATE $dbTable SET comment='".Database::escape_string($title)."' WHERE path=\"".$uploadPath."/".$fld."/".$filename."\"";
+                    $query = "UPDATE $dbTable SET comment='".Database::escape_string($title)."' WHERE c_id = $course_id AND path=\"".$uploadPath."/".$fld."/".$filename."\"";
                     Database::query($query);
                     api_item_property_update($_course, TOOL_QUIZ, $id, 'QuizAdded', api_get_user_id());
 

+ 7 - 4
main/exercice/hotspot_actionscript.as.php

@@ -31,11 +31,16 @@ $courseLang = $_course['language'];
 $courseCode = $_course['sysCode'];
 $coursePath = $_course['path'];
 
+
+$course_id = api_get_course_int_id();
+
 // Query db for answers
 if ($answer_type==HOT_SPOT_DELINEATION) {
-	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' AND hotspot_type = 'delineation' ORDER BY id";		
+	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS 
+	        WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' AND hotspot_type = 'delineation' ORDER BY id";		
 } else {
-	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' ORDER BY id";
+	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS 
+	        WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' ORDER BY id";
 }
 $result = Database::query($sql);
 // Init
@@ -78,10 +83,8 @@ while ($hotspot = Database::fetch_assoc($result))
 	{
 		$nmbrTries++;
 	}
-
 	$output .= "&hotspot_".$hotspot['id']."_coord=".$hotspot['hotspot_coordinates']."";
 	$i++;
-
 }
 
 // Generate empty

+ 1 - 5
main/exercice/hotspot_actionscript_admin.as.php

@@ -17,7 +17,6 @@ include('../inc/global.inc.php');
 $questionId    = intval($_GET['modifyAnswers']);
 $objQuestion   = Question::read($questionId);
 
-$TBL_ANSWERS   = Database::get_course_table(TABLE_QUIZ_ANSWER);
 $documentPath  = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 
 $picturePath   = $documentPath.'/images';
@@ -30,9 +29,6 @@ $courseLang    = $_course['language'];
 $courseCode    = $_course['sysCode'];
 $coursePath    = $_course['path'];
 
-// Query db for answers
-//$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type, ponderation FROM $TBL_ANSWERS WHERE question_id = '$questionId' ORDER BY id";
-//$result = Database::query($sql);
 
 // Init
 $output = "hotspot_lang=$courseLang&hotspot_image=$pictureName&hotspot_image_width=$pictureWidth&hotspot_image_height=$pictureHeight&courseCode=$coursePath";
@@ -40,7 +36,7 @@ $i = 0;
 $nmbrTries = 0;
 
 
-$answers=$_SESSION['tmp_answers'];
+$answers = $_SESSION['tmp_answers'];
 $nbrAnswers = count($answers['answer']);
 
 for($i=1;$i <= $nbrAnswers;$i++) {

+ 2 - 4
main/exercice/hotspot_admin.inc.php

@@ -297,8 +297,7 @@ if ($modifyAnswers) {
     $objAnswer=new Answer($objQuestion -> id);        
     api_session_register('objAnswer');
 	if($debug>0){echo str_repeat('&nbsp;',2).'$answerType is HOT_SPOT'."<br />\n";}
-	$TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
-	
+		
 	if ($answerType == HOT_SPOT_DELINEATION) {
 		$try=$_POST['try'];
 		
@@ -344,8 +343,7 @@ if ($modifyAnswers) {
             $hotspot_type[$i]=$objAnswer->selectHotspotType($i);
             
             if ($answerType==HOT_SPOT_DELINEATION) {            
-            	$destination[$i]=$objAnswer->selectDestination($i);
-            	
+            	$destination[$i]=$objAnswer->selectDestination($i);            	
 	                 
 	            $destination_items= explode('@@', $destination[$i]);                        
 	            $threadhold_total = $destination_items[0];            

+ 6 - 2
main/exercice/hotspot_answers.as.php

@@ -34,11 +34,15 @@ $courseCode    = $_course['sysCode'];
 $coursePath    = $_course['path'];
 $answer_type   = $objQuestion->selectType();
 
+$course_id     = api_get_course_int_id();
+
 if ($answer_type==HOT_SPOT_DELINEATION) {
 	// Query db for answers
-	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror' ORDER BY id";
+	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS 
+	        WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' AND hotspot_type <> 'noerror' ORDER BY id";
 } else {
-	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS WHERE question_id = '".Database::escape_string($questionId)."' ORDER BY id";
+	$sql = "SELECT id, answer, hotspot_coordinates, hotspot_type FROM $TBL_ANSWERS 
+	        WHERE c_id = $course_id AND question_id = '".Database::escape_string($questionId)."' ORDER BY id";
 }
 $result = Database::query($sql);
 // Init

+ 3 - 1
main/exercice/hotspot_save.inc.php

@@ -38,6 +38,8 @@ if ($_GET['type'] == "poly" || $_GET['type'] == "delineation" || $_GET['type'] =
 	}
 	$hotspot_coordinates = api_substr($hotspot_coordinates,0,-2);
 }
-$sql = "UPDATE $TBL_ANSWER SET hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',hotspot_type = '".Database::escape_string($hotspot_type)."' WHERE id = '".Database::escape_string($answerId)."' AND question_id ='".Database::escape_string($questionId)."' LIMIT 1 ;";
+$course_id = api_get_course_int_id();
+$sql = "UPDATE $TBL_ANSWER SET hotspot_coordinates = '".Database::escape_string($hotspot_coordinates)."',hotspot_type = '".Database::escape_string($hotspot_type)."' 
+        WHERE c_id = $course_id AND id = '".Database::escape_string($answerId)."' AND question_id ='".Database::escape_string($questionId)."' LIMIT 1 ;";
 $result = Database::query($sql);
 echo "done=done";

+ 5 - 15
main/exercice/mark_free_answer.php

@@ -31,15 +31,6 @@ define('MATCHING',		4);
 define('FREE_ANSWER', 5);
 define('MULTIPLE_ANSWER_COMBINATION', 9);
 
-
-
-
-/** @todo use the Database:: functions */
-$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-$TBL_EXERCICES         = Database::get_course_table(TABLE_QUIZ_TEST);
-$TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_REPONSES          = Database::get_course_table(TABLE_QUIZ_ANSWER);
-
 //debug param. 0: no display - 1: debug display
 $debug=0;
 if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
@@ -106,24 +97,23 @@ if ($action == 'mark') {
 		//mark the user mark into the database using something similar to the following function:
 
 		$exercise_table = Database::get_statistic_table('track_e_exercices');
-		#$tbl_learnpath_user = Database::get_course_table('learnpath_user');
 		#global $origin, $tbl_learnpath_user, $learnpath_id, $learnpath_item_id;
 		$sql = "SELECT * FROM $exercise_table
-			WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = '".Database::escape_string($my_exe)."'
-			ORDER BY exe_date DESC";
+			    WHERE exe_user_id = '".Database::escape_string($my_usr)."' AND exe_cours_id = '".Database::escape_string($my_cid)."' AND exe_exo_id = '".Database::escape_string($my_exe)."'
+			    ORDER BY exe_date DESC";
 		#echo $sql;
 		$res = Database::query($sql);
-		if(Database::num_rows($res)>0){
+		if (Database::num_rows($res)>0){
 			$row = Database::fetch_array($res);
 			//@todo Check that just summing past score and the new free answer mark doesn't come up
 			// with a score higher than the possible score for that exercise
 			$my_score = $row['exe_result'] + $_POST['score'];
 			$sql = "UPDATE $exercise_table SET exe_result = '$my_score'
-				WHERE exe_id = '".$row['exe_id']."'";
+				    WHERE exe_id = '".$row['exe_id']."'";
 			#echo $sql;
 			$res = Database::query($sql);
 			$my_msg = get_lang('MarkIsUpdated');
-		}else{
+		} else {
 			$my_score = $_POST['score'];
 			$reallyNow = time();
 			$sql = "INSERT INTO $exercise_table (

+ 11 - 11
main/exercice/multiple_answer_true_false.class.php

@@ -117,11 +117,12 @@ class MultipleAnswerTrueFalse extends Question {
 			$nb_answers = 1;
 			Display::display_normal_message(get_lang('YouHaveToCreateAtLeastOneAnswer'));
 		}
+		
+        $course_id = api_get_course_int_id();
         
         // Can be more options        
-        $option_data = Question::readQuestionOption($this->id);    
-                  
-  
+        $option_data = Question::readQuestionOption($this->id, $course_id);
+          
 		for ($i = 1 ; $i <= $nb_answers ; ++$i) {
             
             $renderer->setElementTemplate('<td><!-- BEGIN error --><span class="form_error">{error}</span><!-- END error -->{label} &nbsp;&nbsp;{element}</td>');            
@@ -220,30 +221,29 @@ class MultipleAnswerTrueFalse extends Question {
 	function processAnswersCreation($form) {
 		$questionWeighting = $nbrGoodAnswers = 0;
 		$objAnswer        = new Answer($this->id);
-		$nb_answers       = $form->getSubmitValue('nb_answers');     
-	 
-        $options_count    = $form->getSubmitValue('options_count');        
-            
+		$nb_answers       = $form->getSubmitValue('nb_answers');
+        $options_count    = $form->getSubmitValue('options_count');
+        $course_id        = api_get_course_int_id();
        
         $correct = array();
-        $options = Question::readQuestionOption($this->id);
+        $options = Question::readQuestionOption($this->id, $course_id);
         	
         
         if (!empty($options)) {
             foreach ($options as $option_data) {
                 $id = $option_data['id'];
                 unset($option_data['id']);
-                Question::updateQuestionOption($id, $option_data);
+                Question::updateQuestionOption($id, $option_data, $course_id);
             }
         } else {            
             for ($i=1 ; $i <= 3 ; $i++) {                
-        	   $last_id = Question::saveQuestionOption($this->id, $this->options[$i], $i);
+        	   $last_id = Question::saveQuestionOption($this->id, $this->options[$i], $course_id, $i);
                $correct[$i] = $last_id;
             }            
         }
   
         //Getting quiz_question_options (true, false, doubt) because it's possible that there are more options in the future
-        $new_options = Question::readQuestionOption($this->id);
+        $new_options = Question::readQuestionOption($this->id, $course_id);
         
         $sorted_by_position = array();
         foreach($new_options as $item) {

+ 28 - 32
main/exercice/question.class.php

@@ -51,10 +51,10 @@ abstract class Question
 	public $exerciseList;  // array with the list of exercises which this question is in
 	public $category;	// hub 12-10-2011
 	private $isContent;
-  public $course;
-    
+    public $course;        
 	static $typePicture = 'new_question.png';
 	static $explanationLangVar = '';
+    
 	static $questionTypes = array(
 							UNIQUE_ANSWER => 				array('unique_answer.class.php' , 	'UniqueAnswer'),
 							MULTIPLE_ANSWER => 				array('multiple_answer.class.php' , 'MultipleAnswer'),
@@ -84,7 +84,7 @@ abstract class Question
 		$this->picture='';
 		$this->level = 1;
 		$this->category=0;	// hub 12-10-2011
-    $this->extra='';
+        $this->extra='';
 		$this->exerciseList=array();
 		$this->course = api_get_course_info();
 	}
@@ -136,10 +136,10 @@ abstract class Question
 			$objQuestion->type			= $object->type;
 			$objQuestion->picture		= $object->picture;
 			$objQuestion->level			= (int) $object->level;
-      $objQuestion->extra         = $object->extra;
-      $objQuestion->course        = $course_info;
-      $objQuestion->category	=	Testcategory::getCategoryForQuestion($id);	// hub 12-10-2011
-            
+            $objQuestion->extra         = $object->extra;
+            $objQuestion->course        = $course_info;
+            $objQuestion->category	    = Testcategory::getCategoryForQuestion($id);	// hub 12-10-2011
+                    
 			$sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id";
 			$result_exercise_list = Database::query($sql);
 
@@ -1038,7 +1038,7 @@ abstract class Question
         
         $course_id = $course_info['real_id'];
                 
-        $options = self::readQuestionOption($this->id);  
+        $options = self::readQuestionOption($this->id, $course_id);  
         //Inserting in the new course db / or the same course db
 		$sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra ) 
 				VALUES('$course_id', '".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."'  )";
@@ -1336,10 +1336,7 @@ abstract class Question
 			echo Display::return_icon('database.png', get_lang('GetExistingQuestion'), '');
 		} else {
 			echo Display::return_icon('database_na.png', get_lang('GetExistingQuestion'), '');
-		}
-		//echo '<br>';
-		//echo $url;
-		//echo get_lang('GetExistingQuestion');
+		}	
 		echo '</a>';
 		echo '</div></li>';
 		echo '</ul>';
@@ -1353,35 +1350,32 @@ abstract class Question
 		return self::$questionTypes;
 	}
     
-    static function saveQuestionOption($question_id, $name, $position = 0) {
+    static function saveQuestionOption($question_id, $name, $course_id, $position = 0) {
         $TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);   
         $params['question_id']  = intval($question_id);
         $params['name']         = $name;        
-        $params['position']     = $position;             
-        $result  = self::readQuestionOption($question_id);
+        $params['position']     = $position;
+        $params['c_id']         = $course_id;                   
+        $result  = self::readQuestionOption($question_id, $course_id);
         $last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params);
         return $last_id; 
     }
     
-    static function deleteAllQuestionOptions($question_id) {
+    static function deleteAllQuestionOptions($question_id, $course_id) {
     	$TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
-        Database::delete($TBL_EXERCICE_QUESTION_OPTION, array('question_id = ?'=> $question_id));
+        Database::delete($TBL_EXERCICE_QUESTION_OPTION, array('c_id = ? AND question_id = ?'=> array($course_id, $question_id)));
     }
     
-    static function updateQuestionOption($id, $params) {
+    static function updateQuestionOption($id, $params, $course_id) {
         $TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);
-        $result = Database::update($TBL_EXERCICE_QUESTION_OPTION, $params, array('id = ?'=>$id));             
+        $result = Database::update($TBL_EXERCICE_QUESTION_OPTION, $params, array('c_id = ? AND id = ?'=>array($course_id, $id)));             
         return $result;        
     }
     
     
-    static function readQuestionOption($question_id, $db_name = null) {
-        if (empty($db_name)) {            
-            $TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);	
-        } else {
-            $TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION, $db_name);	
-        }        
-        $result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where'=>array('question_id = ?' =>$question_id), 'order'=>'id ASC'));
+    static function readQuestionOption($question_id, $course_id) {
+        $TBL_EXERCICE_QUESTION_OPTION    = Database::get_course_table(TABLE_QUIZ_QUESTION_OPTION);               
+        $result = Database::select('*', $TBL_EXERCICE_QUESTION_OPTION, array('where'=>array('c_id = ? AND question_id = ?' =>array($course_id, $question_id)), 'order'=>'id ASC'));
         return $result;        
     }
     
@@ -1402,6 +1396,8 @@ abstract class Question
      * @param   int     Question level/category
      */
     function create_question ($quiz_id, $question_name, $max_score = 0, $type = 1, $level = 1) {
+        $course_id = api_get_course_int_id();
+        
         $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
         $tbl_quiz_rel_question = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
         $quiz_id = filter_var($quiz_id,FILTER_SANITIZE_NUMBER_INT);
@@ -1412,29 +1408,29 @@ abstract class Question
         $sql = "SELECT max(position) as max_position"
                ." FROM $tbl_quiz_question q INNER JOIN $tbl_quiz_rel_question r"
                ." ON q.id = r.question_id"
-               ." AND exercice_id = $quiz_id";
+               ." AND exercice_id = $quiz_id AND q.c_id = $course_id AND r.c_id = $course_id";
         $rs_max = Database::query($sql, __FILE__, __LINE__);
         $row_max = Database::fetch_object($rs_max);
         $max_position = $row_max->max_position +1;
    
         // Insert the new question
         $sql = "INSERT INTO $tbl_quiz_question"
-              ." (question,ponderation,position,type,level) "
-              ." VALUES('".Database::escape_string($question_name)."',"
+              ." (c_id, question,ponderation,position,type,level) "
+              ." VALUES($course_id, '".Database::escape_string($question_name)."',"
               ." $max_score , $max_position, $type, $level)";
         $rs = Database::query($sql);
         // Get the question ID
         $question_id = Database::get_last_insert_id();
         // Get the max question_order
         $sql = "SELECT max(question_order) as max_order "
-              ."FROM $tbl_quiz_rel_question WHERE exercice_id = $quiz_id ";
+              ."FROM $tbl_quiz_rel_question WHERE c_id = $course_id AND exercice_id = $quiz_id ";
         $rs_max_order = Database::query($sql);
         $row_max_order = Database::fetch_object($rs_max_order);
         $max_order = $row_max_order->max_order + 1;
         // Attach questions to quiz
         $sql = "INSERT INTO $tbl_quiz_rel_question "
-              ."(question_id,exercice_id,question_order)"
-              ." VALUES($question_id, $quiz_id, $max_order)";
+              ."(c_id, question_id,exercice_id,question_order)"
+              ." VALUES($course_id, $question_id, $quiz_id, $max_order)";
         $rs = Database::query($sql);
         return $question_id;
     }

+ 4 - 3
main/exercice/question_admin.inc.php

@@ -11,22 +11,23 @@
 /**
  * Code
  */
-require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
 
 // ALLOWED_TO_INCLUDE is defined in admin.php
 if(!defined('ALLOWED_TO_INCLUDE')) {
 	exit();
 }
 
+$course_id = api_get_course_int_id();
+
 // INIT QUESTION
-if(isset($_GET['editQuestion'])) {
+if (isset($_GET['editQuestion'])) {
 	$objQuestion = Question::read ($_GET['editQuestion']);
 	$action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
 
 	if (isset($exerciseId) && !empty($exerciseId)) {
 		$TBL_LP_ITEM	= Database::get_course_table(TABLE_LP_ITEM);
 		$sql="SELECT max_score FROM $TBL_LP_ITEM
-			  WHERE item_type = '".TOOL_QUIZ."' AND path ='".Database::escape_string($exerciseId)."'";
+			  WHERE c_id = $course_id AND item_type = '".TOOL_QUIZ."' AND path ='".Database::escape_string($exerciseId)."'";
 		$result = Database::query($sql);
 		if (Database::num_rows($result) > 0) {
 			//Display::display_warning_message(get_lang('EditingScoreCauseProblemsToExercisesInLP'));

+ 4 - 2
main/exercice/question_create.php

@@ -45,7 +45,9 @@ $session_id  = api_get_session_id();
 
 // the exercices
 $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
-$sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
+$course_id = api_get_course_int_id();
+
+$sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE c_id = $course_id AND active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
 $result = Database::query($sql);
 $exercises['-'] = '-'.get_lang('SelectExercice').'-';
 while ($row = Database :: fetch_array($result)) {
@@ -77,7 +79,7 @@ if ($form->validate()) {
 	
 	// check feedback_type from current exercise for type of question delineation
 	$exercise_id = intval($values['exercice']);	
-	$sql = "SELECT feedback_type FROM $tbl_exercices WHERE id = '$exercise_id'";
+	$sql = "SELECT feedback_type FROM $tbl_exercices WHERE c_id = $course_id AND id = '$exercise_id'";
 	$rs_feedback_type = Database::query($sql,__FILE__,__LINE__);
 	$row_feedback_type = Database::fetch_row($rs_feedback_type);
 	$feedback_type = $row_feedback_type[0];

+ 12 - 17
main/exercice/question_pool.php

@@ -326,7 +326,7 @@ echo Display::form_row(get_lang('Course'), $select_course_html);
 $db_name = "";
 if (empty($selected_course) || $selected_course == '-1') {
     $course_info = api_get_course_info();
-    reset_menu_exo_lvl_type();    // no course selected, reset menu test / difficulté / type de reponse // hub 13-10-2011
+    reset_menu_exo_lvl_type();    // no course selected, reset menu test / difficult� / type de reponse // hub 13-10-2011
 } 
 else {   
 	$course_info = CourseManager::get_course_information_by_id($selected_course);                
@@ -337,26 +337,22 @@ if ($course_id_changed) {
 }
 $course_id = $course_info['real_id'];
 //Redefining table calls
-$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-$TBL_EXERCICES         = Database::get_course_table(TABLE_QUIZ_TEST);
-$TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION);
-$TBL_REPONSES          = Database::get_course_table(TABLE_QUIZ_ANSWER);
-$TBL_CATEGORY							= Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);		// hub 13-10-2011
+$TBL_EXERCICE_QUESTION      = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+$TBL_EXERCICES              = Database::get_course_table(TABLE_QUIZ_TEST);
+$TBL_QUESTIONS              = Database::get_course_table(TABLE_QUIZ_QUESTION);
+$TBL_REPONSES               = Database::get_course_table(TABLE_QUIZ_ANSWER);
+$TBL_CATEGORY               = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);		// hub 13-10-2011
 $TBL_COURSE_REL_CATEGORY	= Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);  // hub 13-10-2011
 
-
-// ---------------------------------------------
 // Get course categories for the selected course
-// ---------------------------------------------
 
 // get category list for the course $selected_course
 $tabCatList = Testcategory::getCategoriesIdAndName($selected_course);
 $selectCourseCateogry = Display::select('courseCategoryId', $tabCatList, $courseCategoryId, array('class'=>'chzn-select','onchange'=>'submit_form(this);'), false);
 echo Display::form_row(get_lang("QuestionCategory"), $selectCourseCateogry);
 
-// ---------------------------------------------
 // Get exercice list for this course
-// ---------------------------------------------
+
 $exercise_list         = get_all_exercises_for_course_id($course_info, $session_id, $selected_course);
 //Exercise List
 $my_exercise_list = array();
@@ -437,12 +433,11 @@ if ($exerciseId > 0) {
 		$where .= ' AND type='.$answerType;
 	}
 	$sql = "SELECT DISTINCT id,question,type,level FROM $TBL_EXERCICE_QUESTION qt,$TBL_QUESTIONS qu $from WHERE qt.question_id=qu.id AND qt.exercice_id=$exerciseId AND qt.c_id=$selected_course AND qu.c_id=$selected_course $where ORDER BY question_order";
-  $result=Database::query($sql);
-  while($row = Database::fetch_array($result, 'ASSOC')) {
-  	$main_question_list[] = $row;
-  }    
-} 
-elseif ($exerciseId == -1) {
+    $result=Database::query($sql);
+    while($row = Database::fetch_array($result, 'ASSOC')) {
+        $main_question_list[] = $row;
+    }    
+} elseif ($exerciseId == -1) {
 	// ---------------------------------------------------------------------------
 	// if we have selected the option 'Orphan questions' in the list-box 'Filter'
 	// ---------------------------------------------------------------------------

+ 6 - 5
main/exercice/unique_answer.class.php

@@ -399,27 +399,28 @@ class UniqueAnswer extends Question {
   function create_answer($id, $question_id, $answer_title, $comment, $score = 0, $correct = 0) {
     $tbl_quiz_answer = Database::get_course_table(TABLE_QUIZ_ANSWER);
     $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
+    $course_id = api_get_course_int_id();
     $position = 1;
     $question_id = filter_var($question_id,FILTER_SANITIZE_NUMBER_INT);
     $score = filter_var($score,FILTER_SANITIZE_NUMBER_FLOAT);
     $correct = filter_var($correct,FILTER_SANITIZE_NUMBER_INT);
     // Get the max position
     $sql = "SELECT max(position) as max_position FROM $tbl_quiz_answer "
-          ." WHERE question_id = $question_id";
+          ." WHERE c_id = $course_id AND question_id = $question_id";
     $rs_max  = Database::query($sql);
     $row_max = Database::fetch_object($rs_max);
     $position = $row_max->max_position + 1;
     // Insert a new answer
     $sql = "INSERT INTO $tbl_quiz_answer "
-    ."(id, question_id,answer,correct,comment,ponderation,position,destination)"
-    ."VALUES ($id,$question_id,'".Database::escape_string($answer_title)."',"
+    ."(c_id, id, question_id,answer,correct,comment,ponderation,position,destination)"
+    ."VALUES ($course_id, $id,$question_id,'".Database::escape_string($answer_title)."',"
     ."$correct,'".Database::escape_string($comment)."',$score,$position, "
     ." '0@@0@@0@@0')";
     $rs = Database::query($sql);
     if ($correct) {
         $sql = "UPDATE $tbl_quiz_question "
-        ." SET ponderation = (ponderation + $score) WHERE id = ".$question_id;
-        $rs = Database::query($sql, __FILE__, __LINE__);
+        ." SET ponderation = (ponderation + $score) WHERE c_id = $course_id AND id = ".$question_id;
+        $rs = Database::query($sql);
     }
   }
 }

+ 1 - 4
main/exercice/upload_exercise.php

@@ -85,10 +85,7 @@ function lp_upload_quiz_secondary_actions() {
 }
 
 function lp_upload_quiz_main() {
-    // Database table definition
-    global $_course;
-    $table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
-    $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
+        
     // variable initialisation
     $lp_id = Security::remove_XSS($_GET['lp_id']);
     

+ 7 - 4
main/forum/download.php

@@ -54,14 +54,17 @@ if (is_dir($full_file_name)) {
     header('Location: '.$document_explorer);
 }
 
-$tbl_forum_attachment 	= Database::get_course_table(TABLE_FORUM_ATTACHMENT);
-$tbl_forum_post 	= Database::get_course_table(TABLE_FORUM_POST);
+$tbl_forum_attachment  = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
+$tbl_forum_post 	   = Database::get_course_table(TABLE_FORUM_POST);
+
+$course_id = api_get_course_int_id();
 
 // launch event
 event_download($doc_url);
 
 $sql='SELECT thread_id, forum_id,filename FROM '.$tbl_forum_post.'  f  INNER JOIN '.$tbl_forum_attachment.' a
-        ON a.post_id=f.post_id WHERE path LIKE BINARY "'.$doc_url.'"';
+        ON a.post_id=f.post_id 
+      WHERE f.c_id = '.$course_id.' AND a.c_id = '.$course_id.' AND path LIKE BINARY "'.$doc_url.'"';
 
 $result = Database::query($sql);
 $row    = Database::fetch_array($result);
@@ -71,7 +74,7 @@ $forum_forum_visibility  = api_get_item_visibility(api_get_course_info($course_c
 
 if ($forum_thread_visibility==1 && $forum_forum_visibility==1) {
     if (Security::check_abs_path($full_file_name, api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/')) {
-       DocumentManager::file_send_for_download($full_file_name,TRUE, $row['filename']);
+       DocumentManager::file_send_for_download($full_file_name, TRUE, $row['filename']);
     }
 }
 exit;

+ 2 - 1
main/inc/lib/exercise_show_functions.lib.php

@@ -232,7 +232,8 @@ class ExerciseShowFunctions {
         <?php   
         
         $question 	 = new MultipleAnswerTrueFalse();        
-        $new_options = Question::readQuestionOption($questionId);
+        $course_id   = api_get_course_int_id();
+        $new_options = Question::readQuestionOption($questionId, $course_id);
         
         //Your choice        
         if (isset($new_options[$studentChoice])) {