Browse Source

Now we can import questions using the Question tool from other courses (there's a filter for sessions) see BT#1917

Julio Montoya 14 years ago
parent
commit
5405279c86

+ 4 - 6
main/exercice/exercice.php

@@ -435,11 +435,8 @@ event_access_tool(TOOL_QUIZ);
 // Tool introduction
 Display :: display_introduction_section(TOOL_QUIZ);
 
-// selects $limitExPage exercises at the same time
-$from = $page * $limitExPage;
-$sql = "SELECT count(id) FROM $TBL_EXERCICES";
-$res = Database::query($sql);
-list ($nbrexerc) = Database :: fetch_array($res);
+
+
 
 HotPotGCt($documentPath, 1, $_user['user_id']);
 $tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
@@ -550,11 +547,12 @@ if ($is_allowedToEdit) {
 echo '<div class="actions">';
 
 // display the next and previous link if needed
+// selects $limitExPage exercises at the same time
 $from = $page * $limitExPage;
 $sql = "SELECT count(id) FROM $TBL_EXERCICES";
 $res = Database::query($sql);
 list ($nbrexerc) = Database :: fetch_array($res);
-HotPotGCt($documentPath, 1, $_user['user_id']);
+HotPotGCt($documentPath, 1, api_get_user_id());
 
 //condition for the session
 $session_id = api_get_session_id();

+ 1 - 1
main/exercice/exercise.class.php

@@ -63,7 +63,7 @@ class Exercise {
 		$this->expired_time 	= '0000-00-00 00:00:00';
         
         if (!empty($course_id)) {
-            $this->course_id        = intval($course_id);
+            $this->course_id        =  intval($course_id);
             $course_info            =  api_get_course_info_by_id($this->course_id);
         } else {            
         	$course_info = api_get_course_info();

+ 9 - 0
main/exercice/exercise.lib.php

@@ -1131,4 +1131,13 @@ function convert_score($score, $weight) {
 }
 
 
+function get_all_exercises($course_info = null) {
+    if(!empty($course_info)) {
+        $TBL_EXERCICES              = Database :: get_course_table(TABLE_QUIZ_TEST,$course_info['db_name']);	
+    } else {
+    	$TBL_EXERCICES              = Database :: get_course_table(TABLE_QUIZ_TEST);
+    }    
+    return Database::select('*',$TBL_EXERCICES, array('where'=>array('active <> ?'=>'-1'), 'order'=>'title'));
+}
+
 

+ 2 - 3
main/exercice/question.class.php

@@ -106,7 +106,7 @@ abstract class Question
 		$TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION,      $course_info['db_name']);
 		$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION, $course_info['db_name']);
         $id = intval($id);
-		$sql="SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE id='".$id."'";
+		$sql="SELECT question,description,ponderation,position,type,picture,level,extra FROM $TBL_QUESTIONS WHERE id= $id ";
 
 		$result=Database::query($sql);
 
@@ -953,8 +953,7 @@ abstract class Question
         }
         
         $options = self::readQuestionOption($this->id);
-        var_dump($options);
-        
+                
 		$sql="INSERT INTO $TBL_QUESTIONS(question, description, ponderation, position, type, level, extra ) VALUES('".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)."'  )";
 		Database::query($sql);    
             

+ 288 - 264
main/exercice/question_pool.php

@@ -14,11 +14,10 @@
 $language_file='exercice';
 
 require_once 'exercise.class.php';
+require_once 'exercise.lib.php';
 require_once 'question.class.php';
 require_once 'answer.class.php';
-
 require_once '../inc/global.inc.php';
-
 require_once api_get_path(LIBRARY_PATH).'course.lib.php';
 require_once api_get_path(LIBRARY_PATH).'sessionmanager.lib.php';
 
@@ -62,14 +61,17 @@ if(!empty($_GET['type'])){
 
 $session_id = intval($_GET['session_id']);
 
+$selected_course = intval($_GET['selected_course']);
+
+
 // maximum number of questions on a same page
 $limitQuestPage=50;
 
-/*// document path
+// document path
 $documentPath=api_get_path(SYS_COURSE_PATH).$_course['path'].'/document';
 // picture path
 $picturePath=$documentPath.'/images';
-*/
+
 
 if(!($objExcercise instanceOf Exercise) && !empty($fromExercise)) {
     $objExercise = new Exercise();    
@@ -85,15 +87,14 @@ if ($is_allowedToEdit) {
 	//Duplicating a Question
     
 	if ($copy_question != 0 && isset($fromExercise)) {
-        $origin_course_id   = $_GET['course_id'];
+        $origin_course_id   = intval($_GET['course_id']);
         $origin_course_info = api_get_course_info_by_id($origin_course_id);
         $current_course     = api_get_course_info();     
         $old_question_id = $copy_question;       
         
         //Reading the source question
 		$old_question_obj = Question::read($old_question_id, $origin_course_id);
-		$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));
-     
+		$old_question_obj->updateTitle($old_question_obj->selectTitle().' - '.get_lang('Copy'));     
         
         //Duplicating question in the current course
 		$new_id = $old_question_obj->duplicate($current_course);
@@ -192,327 +193,354 @@ if (!empty($gradebook) && $gradebook=='view') {
 
 $nameTools=get_lang('QuestionPool');
 $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
-$selected_course = 0;
 // if admin of course
-if ($is_allowedToEdit) {
-    $htmlHeadXtra[] = ' <script type="text/javascript"> 
-                    
-    	function submit_form(obj) {            
-    		document.question_pool.submit();
-    	}
-    		
-    	</script>';
-	Display::display_header($nameTools,'Exercise');
-	echo '<h3>'.$nameTools.'</h3>';
-	echo '<div class="actions">';
-	if (isset($type)) {
-		$url = api_get_self().'?type=1';
-	} else {
-		$url = api_get_self();
+if (!$is_allowedToEdit) {
+    api_not_allowed(true);
+}
+
+$htmlHeadXtra[] = ' <script type="text/javascript"> 
+                
+	function submit_form(obj) {            
+		document.question_pool.submit();
 	}
-	echo '<form name="question_pool" method="GET" action="'.$url.'" style="display:inline;">';
-	 
-	if (isset($type)) {
-		echo '<input type="hidden" name="type" value="1">';
-	}    
+		
+	</script>';
+Display::display_header($nameTools,'Exercise');
+echo '<h3>'.$nameTools.'</h3>';
+echo '<div class="actions">';
+if (isset($type)) {
+	$url = api_get_self().'?type=1';
+} else {
+	$url = api_get_self();
+}
+echo '<form name="question_pool" method="GET" action="'.$url.'" style="display:inline;">';
+     
+    if (isset($type)) {
+    	echo '<input type="hidden" name="type" value="1">';
+    }    
     //echo '<input type="hidden" name="cidReq" value="'.api_get_cidreq().'">';
     echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
     
-        
+    //Session list  
     $session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
     $session_select_list = array();
     foreach($session_list as $item) {
         $session_select_list[$item['id']] = $item['name'];
     }
-    
-    
     echo get_lang('Session').' : ';
     echo Display::select('session_id', $session_select_list, $session_id, array('onchange'=>'submit_form(this);'));
     
+    //Course list
     if (!empty($session_id) && $session_id != '-1') {
         $course_list = SessionManager::get_course_list_by_session_id($session_id);
-    } else {
-        $course_list =CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());
-    }
+    } else {        
+        $course_list = CourseManager::get_course_list_of_user_as_course_admin(api_get_user_id());        
+    }    
     
     $course_select_list = array();
     foreach ($course_list as $item) {
     	$course_select_list[$item['id']] = $item['title'];
-    }
-    
-    $selected_course = intval($_GET['selected_course']);
-    
-    //echo Display::input('hidden', 'selected_course', $selected_course);
-    
+    }    
+         
     echo get_lang('Course').' : ';
     echo Display::select('selected_course', $course_select_list, $selected_course, array('onchange'=>'submit_form(this);'));    
     
-    if (empty($selected_course )) {
-        $current_course_info = api_get_course_info();
-        $db_name = $current_course_info ['db_name'];
-    } else {
-    	$course_info = CourseManager::get_course_information_by_id($selected_course);        
+    if (empty($selected_course) || $selected_course == '-1') {
+        $course_info = api_get_course_info();
+        $db_name = $course_info['db_name'];
+    } else {        
+    	$course_info = CourseManager::get_course_information_by_id($selected_course);                
         $db_name = $course_info['db_name'];
     }
     
+    
+    
+    //Redefining table calls
     $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION,   $db_name);
     $TBL_EXERCICES         = Database::get_course_table(TABLE_QUIZ_TEST,            $db_name);
     $TBL_QUESTIONS         = Database::get_course_table(TABLE_QUIZ_QUESTION,        $db_name);
     $TBL_REPONSES          = Database::get_course_table(TABLE_QUIZ_ANSWER,          $db_name);
     
+    $exercise_list         = get_all_exercises($course_info);
     
-	echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
-	echo get_lang('Exercice').' :';	
-	echo '<select name="exerciseId">';	
-	echo '<option value="0">'.get_lang('AllExercises').'</option>';
-	?>
-	<option value="-1" <?php if($exerciseId == -1) echo 'selected="selected"'; ?>><?php echo get_lang('OrphanQuestions'); ?></option>
-	<?php
-	$sql="SELECT id,title FROM $TBL_EXERCICES WHERE id<>'".Database::escape_string($fromExercise)."' AND active<>'-1' ORDER BY id";
-	$result=Database::query($sql);
-
-	// shows a list-box allowing to filter questions
-	while($row=Database::fetch_array($result)) {
-		?>
-		<option value="<?php echo $row['id']; ?>" <?php if($exerciseId == $row['id']) echo 'selected="selected"'; ?>><?php echo $row['title']; ?></option>
-		<?php
-	}
-	?>
-    </select>
-    &nbsp;
-    <?php
-    	echo get_lang('Difficulty');    	
-
-		//level difficulty only from 1 to 5                
-        echo Display::select('exerciseLevel', array(1,2,3,4,5), $exerciseLevel);
-
-		$question_list = Question::get_types_information();
-        $new_question_list = array();
-        foreach($question_list as $key=>$item) {
-        	$new_question_list[$key] = get_lang($item[1]);
-        }
-    	echo get_lang('AnswerType');
-    	echo ' : <select name="answerType">';
-		//answer type
-		if (!isset($answerType)) $answerType = -1; {
-			for ($answer_type = -1; $answer_type <=9; $answer_type++) {
-				$selected ='';
-				if ($answer_type!=0) {
-					if ($answerType == $answer_type)
-						$selected = ' selected="selected" ';
-					if ($answer_type==-1) {echo '<option value="-1" '.$selected.'>'.get_lang('Any').'</option>'; } // check 0 or -1
-					elseif ($answer_type==1) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('UniqueAnswer').'</option>'; }
-					elseif ($answer_type==2) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('MultipleAnswer').'</option>'; }
-					elseif ($answer_type==3) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('langFillBlanks').'</option>'; }
-					elseif ($answer_type==4) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('langMatching').'</option>'; }
-					elseif ($answer_type==5) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('FreeAnswer').'</option>'; }
-					elseif ($answer_type==6) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('HotSpot').'</option>'; }
-					elseif ($answer_type==9) {echo '<option value="'.$answer_type.'" '.$selected.'>'.get_lang('MultipleSelectCombination').'</option>'; }
-				}
-			}
-		}
         
+    
+    echo '<input type="hidden" name="fromExercise" value="'.$fromExercise.'">';
+    
+    //Exercise List
+    echo get_lang('Exercice').' :';
+    
+    $my_exercise_list = array();
+    $my_exercise_list['0']  = get_lang('AllExercises');
+    $my_exercise_list['-1'] = get_lang('OrphanQuestions'); 
         
-		echo '</select> ';
-        
-	?>
-
-	<button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Filter') ?></button>
-	<?php
-	echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList')),get_lang('GoBackToQuestionList'),'</a>';
-	/*if(!empty($fromExercise)) {
-		echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId=',$fromExercise,'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList')),get_lang('GoBackToQuestionList'),'</a>';
-	} else {
-		echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes">'.Display::return_icon('more.png'),get_lang('NewQu').'</a>';
-	}*/
-	?>
+    if (is_array($exercise_list)) {
+        foreach($exercise_list as $row) {        
+            if ($row['id'] !=  $fromExercise) {       
+                $my_exercise_list[$row['id']] = $row['title'];
+            }
+        }
+    }    
+    
+    echo Display::select('exerciseId', $my_exercise_list, $exerciseId, array('onchange'=>'submit_form(this);'), false);
+    
+    echo get_lang('Difficulty');    	
+    
+    //Difficulty list (only from 1 to 5)                
+    echo Display::select('exerciseLevel', array(1=>1,2=>2,3=>3,4=>4,5=>5), $exerciseLevel, array('onchange'=>'submit_form(this);'));
+    
+    $question_list = Question::get_types_information();
+    $new_question_list = array();
+    foreach($question_list as $key=>$item) {
+    	$new_question_list[$key] = get_lang($item[1]);
+    }
+    //Answer type list
+    echo get_lang('AnswerType');
+    echo Display::select('answerType', $new_question_list, $answerType, array('onchange'=>'submit_form(this);'));
+    ?>
+    <button class="save" type="submit" name="name" value="<?php echo get_lang('Ok') ?>"><?php echo get_lang('Filter') ?></button>
+    <?php
+    echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId='.$fromExercise.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList')),get_lang('GoBackToQuestionList'),'</a>';
+    /*if(!empty($fromExercise)) {
+    	echo '<a href="admin.php?',api_get_cidreq(),'&exerciseId=',$fromExercise,'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList')),get_lang('GoBackToQuestionList'),'</a>';
+    } else {
+    	echo '<a href="admin.php?'.api_get_cidreq().'&newQuestion=yes">'.Display::return_icon('more.png'),get_lang('NewQu').'</a>';
+    }*/
+    ?>
     </form>
 </div>
 <form method="post" action="<?php echo $url.'?'.api_get_cidreq().'&fromExercise='.$fromExercise; ?>" >
-<table class="data_table">
-<?php
-	$from=$page*$limitQuestPage;
-	// if we have selected an exercise in the list-box 'Filter'
-    var_dump($exerciseId);
-	if ($exerciseId > 0) {
-		//$sql="SELECT id,question,type FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ORDER BY question_order LIMIT $from, ".($limitQuestPage + 1);
-		$where = '';
-		if (isset($type) && $type==1) {
-			$where = ' type = 1 AND ';
-		}
 
-		if (isset($exerciseLevel) && $exerciseLevel != -1) {
-			$where .= ' level='.$exerciseLevel.' AND ';
-		}
+<?php
+echo '<table class="data_table">';
+$from=$page*$limitQuestPage;
+// if we have selected an exercise in the list-box 'Filter'
+
+if ($exerciseId > 0) {
+	//$sql="SELECT id,question,type FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($exerciseId)."' ORDER BY question_order LIMIT $from, ".($limitQuestPage + 1);
+	$where = '';
+	if (isset($type) && $type==1) {
+		$where = ' type = 1 AND ';
+	}
 
-		if (isset($answerType) && $answerType != -1) {
-			$where .= ' type='.$answerType.' AND ';
-		}
+	if (isset($exerciseLevel) && $exerciseLevel != -1) {
+		$where .= ' level='.$exerciseLevel.' AND ';
+	}
 
-		$sql="SELECT id,question,type,level
-				FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS
-			  	WHERE $where question_id=id AND exercice_id='".Database::escape_string($exerciseId)."'
-				ORDER BY question_order";
+	if (isset($answerType) && $answerType != -1) {
+		$where .= ' type='.$answerType.' AND ';
+	}
 
+	echo $sql="SELECT id,question,type,level
+			FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS
+		  	WHERE $where question_id=id AND exercice_id='".Database::escape_string($exerciseId)."'
+			ORDER BY question_order";
+            
+    $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'
+} elseif($exerciseId == -1) {
 
-		// 1. Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted.
-		//$sql='SELECT id, question, type, exercice_id FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id WHERE exercice_id IS NULL LIMIT $from, '.($limitQuestPage + 1);
+	// if we have selected the option 'Orphan questions' in the list-box 'Filter'
 
-		// 2. New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table).
-		//$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
-		//	' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
-		//	' as exercices ON exercice_id=exercices.id WHERE exercices.active = -1 LIMIT $from, '.($limitQuestPage + 1);
+	// 1. Old logic: When a test is deleted, the correspondent records in 'quiz' and 'quiz_rel_question' tables are deleted.
+	//$sql='SELECT id, question, type, exercice_id FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id WHERE exercice_id IS NULL LIMIT $from, '.($limitQuestPage + 1);
 
-		// 3. This is more safe to changes, it is a mix between old and new logic.
+	// 2. New logic: When a test is deleted, the field 'active' takes value -1 (it is in the correspondent record in 'quiz' table).
+	//$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
+	//	' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
+	//	' as exercices ON exercice_id=exercices.id WHERE exercices.active = -1 LIMIT $from, '.($limitQuestPage + 1);
 
-		/*$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
-			' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
-			' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1);
-		*/
+	// 3. This is more safe to changes, it is a mix between old and new logic.
 
-		/*	4. Query changed because of the Level feature implemented
-		$sql='SELECT id, question, type, exercice_id,level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
-			ON questions.id=quizz_questions.question_id AND exercice_id IS NULL '.
-			(!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : '');
-		*/
-		// 5. this is the combination of the 3 and 4 query because of the level feature implementation
+	/*$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id FROM '.$TBL_QUESTIONS.
+		' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.
+		' as exercices ON exercice_id=exercices.id WHERE quizz_questions.exercice_id IS NULL OR exercices.active = -1 LIMIT '.$from.', '.($limitQuestPage + 1);
+	*/
 
-		// we filter the type of question, because in the DirectFeedback we can only add questions with type=1 = UNIQUE_ANSWER
-		$type_where= '';
-		if (isset($type) && $type==1) {
-			$type_where = ' AND questions.type = 1 ';
-		}
+	/*	4. Query changed because of the Level feature implemented
+	$sql='SELECT id, question, type, exercice_id,level FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
+		ON questions.id=quizz_questions.question_id AND exercice_id IS NULL '.
+		(!is_null($exerciseLevel) && $exerciseLevel >= 0 ? 'WHERE level=\''.$exerciseLevel.'\' ' : '');
+	*/
+	// 5. this is the combination of the 3 and 4 query because of the level feature implementation
 
-		$level_where = '';
-		if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
-			$level_where = ' level='.$exerciseLevel.' AND ';
-		}
+	// we filter the type of question, because in the DirectFeedback we can only add questions with type=1 = UNIQUE_ANSWER
+	$type_where= '';
+	if (isset($type) && $type==1) {
+		$type_where = ' AND questions.type = 1 ';
+	}
 
-		$answer_where = '';
-		if (isset($answerType) && $answerType!= -1 ) {
-			$answer_where = ' questions.type='.$answerType.' AND ';
-		}
+	$level_where = '';
+	if (isset($exerciseLevel) && $exerciseLevel!= -1 ) {
+		$level_where = ' level='.$exerciseLevel.' AND ';
+	}
 
-		$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level, session_id
-				FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
-				ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.' as exercices
-				ON exercice_id=exercices.id
-				WHERE '.$answer_where.' '.$level_where.' (quizz_questions.exercice_id IS NULL OR exercices.active = -1 )  '.$type_where.'
-				LIMIT '.$from.', '.($limitQuestPage + 1);
+	$answer_where = '';
+	if (isset($answerType) && $answerType!= -1 ) {
+		$answer_where = ' questions.type='.$answerType.' AND ';
+	}
 
-	} else {
-		// if we have not selected any option in the list-box 'Filter'
+	$sql='SELECT questions.id, questions.question, questions.type, quizz_questions.exercice_id , level, session_id
+			FROM '.$TBL_QUESTIONS.' as questions LEFT JOIN '.$TBL_EXERCICE_QUESTION.' as quizz_questions
+			ON questions.id=quizz_questions.question_id LEFT JOIN '.$TBL_EXERCICES.' as exercices
+			ON exercice_id=exercices.id
+			WHERE '.$answer_where.' '.$level_where.' (quizz_questions.exercice_id IS NULL OR exercices.active = -1 )  '.$type_where.'
+			LIMIT '.$from.', '.($limitQuestPage + 1);
 
-		//$sql="SELECT id,question,type FROM $TBL_QUESTIONS LIMIT $from, ".($limitQuestPage + 1);
-		$filter = '';
+} else {
+	// if we have not selected any option in the list-box 'Filter'
 
-		if (isset($type) && $type==1){
-			$filter  .= ' AND qu.type = 1 ';
-		}
+	//$sql="SELECT id,question,type FROM $TBL_QUESTIONS LIMIT $from, ".($limitQuestPage + 1);
+	$filter = '';
 
+	if (isset($type) && $type==1){
+		$filter  .= ' AND qu.type = 1 ';
+	}
 
-		if (isset($exerciseLevel) && $exerciseLevel != -1) {
-			$filter .= ' AND level='.$exerciseLevel.' ';
-		}
+	if (isset($exerciseLevel) && $exerciseLevel != -1) {
+		$filter .= ' AND level='.$exerciseLevel.' ';
+	}
 
-		if (isset($answerType) && $answerType != -1) {
-			$filter .= ' AND qu.type='.$answerType.' ';
-		}
-		$new_limit_page = $limitQuestPage + 1;
-        var_dump($session_id);
-		echo $sql="SELECT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q
-			  WHERE q.id=qt.exercice_id AND qu.id=qt.question_id AND qt.exercice_id<>".$fromExercise." $filter ORDER BY session_id ASC LIMIT $from, $new_limit_page";
-		// forces the value to 0
-		//echo $sql;
-		$exerciseId=0;
+	if (isset($answerType) && $answerType != -1) {
+		$filter .= ' AND qu.type='.$answerType.' ';
 	}
+	$new_limit_page = $limitQuestPage + 1;
+    if ($session_id != 0) {        
+
+        $main_question_list = array();
+        //$exerciseId
+        
+        foreach ($course_list as $course_item) {        
+            if (!empty($selected_course) && $selected_course != '-1')
+                if ($selected_course != $course_item['id']) {                
+                	continue;
+                }
+            $exercise_list = get_all_exercises($course_item);
+            
+            if (!empty($exercise_list)) {        
+                foreach ($exercise_list as $exercise) {                    
+                    $my_exercise = new Exercise($course_item['id']);
+                    $my_exercise->read($exercise['id']);
+            
+                    if (!empty($my_exercise)) {
+                        foreach ($my_exercise->questionList as $question) {
+                            
+                        	$question_obj = Question::read($question['id'], $course_item['id']);
+                            if ($exerciseLevel != '-1')
+                            if ($exerciseLevel != $question_obj->level) {
+                            	continue;
+                            }
+                            
+                            if ($answerType != '-1')
+                            if ($answerType != $question_obj->type) {
+                            	continue;
+                            }                        
+                            $question_row       = array('id'=>$question_obj->id, 'question'=>$question_obj->question, 'type'=>$question_obj->type, 'level'=>$question_obj->level, 'exercise_id'=>$exercise['id']);                            
+                            $main_question_list[]    = $question_row;                        
+                        }
+                    }                    
+                }
+            }           	
+        }    
+      
+    } else {
+        //By default
+    	$sql="SELECT qu.id, question, qu.type, level, q.session_id FROM $TBL_QUESTIONS as qu, $TBL_EXERCICE_QUESTION as qt, $TBL_EXERCICES as q
+          WHERE q.id=qt.exercice_id AND qu.id=qt.question_id AND qt.exercice_id<>".$fromExercise." $filter ORDER BY session_id ASC LIMIT $from, $new_limit_page";
+    }
+	// forces the value to 0
+	//echo $sql;
+	$exerciseId=0;
+}
+
+$result=Database::query($sql);
+//$nbrQuestions=Database::num_rows($result);
+$nbrQuestions=count($main_question_list);
+
+echo '<tr>',
+  '<td colspan="',($fromExercise?4:4),'">',
+	'<table border="0" cellpadding="0" cellspacing="0" width="100%">',
+	'<tr>',
+	  '<td>';
+echo '</td>',
+ '<td align="right">';
+
+if(!empty($page)) {
+	echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page-1),'&answerType=',$answerType,'&exerciseLevel='.$exerciseLevel.'">';
+	echo Display::return_icon('action_prev.png');
+	echo '&nbsp;'.get_lang('PreviousPage'),'</a> | ';
 	
-	$result=Database::query($sql);
-	$nbrQuestions=Database::num_rows($result);
-
-    echo '<tr>',
-      '<td colspan="',($fromExercise?4:4),'">',
-    	'<table border="0" cellpadding="0" cellspacing="0" width="100%">',
-    	'<tr>',
-    	  '<td>';
-	echo '</td>',
-	 '<td align="right">';
-
-	if(!empty($page)) {
-		echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page-1),'&answerType=',$answerType,'&exerciseLevel='.$exerciseLevel.'">';
-		echo Display::return_icon('action_prev.png');
-		echo '&nbsp;'.get_lang('PreviousPage'),'</a> | ';
-		
-	} elseif($nbrQuestions > $limitQuestPage) {
-		echo Display::return_icon('action_prev_na.png');
-		echo '&nbsp;'.get_lang('PreviousPage'),' | ';
-	}
+} elseif($nbrQuestions > $limitQuestPage) {
+	echo Display::return_icon('action_prev_na.png');
+	echo '&nbsp;'.get_lang('PreviousPage'),' | ';
+}
 
-	if($nbrQuestions > $limitQuestPage) {
-    	echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page+1),'&answerType=',$answerType,'&exerciseLevel='.$exerciseLevel.'">',get_lang('NextPage').'&nbsp;';
-    	echo Display::return_icon('action_next.png');
-    	echo '</a>';
-    	
-	} elseif($page) {
-	   echo get_lang('NextPage');
-	   echo '&nbsp;'.Display::return_icon('action_next_na.png');
-	}
-    echo '</td>
+if($nbrQuestions > $limitQuestPage) {
+	echo '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&fromExercise=',$fromExercise,'&page=',($page+1),'&answerType=',$answerType,'&exerciseLevel='.$exerciseLevel.'">',get_lang('NextPage').'&nbsp;';
+	echo Display::return_icon('action_next.png');
+	echo '</a>';
+	
+} elseif($page) {
+   echo get_lang('NextPage');
+   echo '&nbsp;'.Display::return_icon('action_next_na.png');
+}
+echo '</td>
 	</tr>
 	</table>
   </td>
 </tr>
 <tr bgcolor="#e6e6e6">';
 
-	if(!empty($fromExercise)) {
-		if (api_get_session_id() == 0 ){
-        	echo '<th width="4%"> </th>';
-		}
-        echo '<th>',get_lang('Question'),'</th>',
-            '<th>',get_lang('Level'),'</th>',
-            '<th>',get_lang('Reuse'),'</th>';
-	} else {
-        echo '<td width="60%" align="center">',get_lang('Question'),'</td>',
-            '<td width="20%" align="center">',get_lang('Modify'),'</td>',
-            '<td width="16%" align="center">',get_lang('Delete'),'</td>';
+if(!empty($fromExercise)) {
+	if (api_get_session_id() == 0 ){
+    	echo '<th width="4%"> </th>';
 	}
-    echo '</tr>';
-	$i=1;
+    echo '<th>',get_lang('Question'),'</th>',
+        '<th>',get_lang('Level'),'</th>',
+        '<th>',get_lang('Reuse'),'</th>';
+} else {
+    echo '<td width="60%" align="center">',get_lang('Question'),'</td>',
+        '<td width="20%" align="center">',get_lang('Modify'),'</td>',
+        '<td width="16%" align="center">',get_lang('Delete'),'</td>';
+}
+echo '</tr>';
+$i=1;
 
-	$session_id  = api_get_session_id();
-	while ($row = Database::fetch_array($result,'ASSOC')) {
-        
-		
-		// if we come from the exercise administration to get a question,
-        // don't show the questions already used by that exercise
-
-        /*if (!$fromExercise) {echo '1'; }
-        if (!isset($objExercise)){echo '2';}
-        if (!($objExercise instanceOf Exercise)){echo '3';}
-        if (!$objExercise->isInList($row['id'])) {echo '4';}
-        */
-
-        // original recipe -
-      //if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (!$objExercise->isInList($row['id'])))
-		if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) ) {
-            echo '<tr ',($i%2==0?'class="row_odd"':'class="row_even"'),'>';
-            if (api_get_session_id() == 0 ){
-            	echo '<td align="center"> <input type="checkbox" value="'.$row['id'].'" name="recup[]"/></td>';
-            }
-            echo '  <td><a href="admin.php?',api_get_cidreq(),'&editQuestion=',$row['id'],'&fromExercise='.$fromExercise.'&answerType='.$row['type'].'">',$row['question'],'</a></td>';
-            echo '  <td align="center" >';
-			if (empty($fromExercise)) {
-                echo '<a href="admin.php?'.api_get_cidreq().'&amp;editQuestion=',$row['id'],'"><img src="../img/edit.gif" border="0" alt="',get_lang('Modify'),'"></a>',
-                    '</td>',
-                    '<td align="center">',
-                    '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
-                    //'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
-			} else {
-                //echo $row['level'],'</td>',
+$session_id  = api_get_session_id();
+if (!empty($main_question_list))
+foreach ($main_question_list as $row) {
+    
+	
+	// if we come from the exercise administration to get a question,
+    // don't show the questions already used by that exercise
+
+    /*if (!$fromExercise) {echo '1'; }
+    if (!isset($objExercise)){echo '2';}
+    if (!($objExercise instanceOf Exercise)){echo '3';}
+    if (!$objExercise->isInList($row['id'])) {echo '4';}
+    */
+
+    // original recipe -
+  //if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (!$objExercise->isInList($row['id'])))
+	if (!$fromExercise || !isset($objExercise) || !($objExercise instanceOf Exercise) || (is_array($objExercise->questionList)) ) {
+        echo '<tr ',($i%2==0?'class="row_odd"':'class="row_even"'),'>';
+        if (api_get_session_id() == 0 ){
+        	echo '<td align="center"> <input type="checkbox" value="'.$row['id'].'" name="recup[]"/></td>';
+        }
+        echo '  <td><a href="admin.php?',api_get_cidreq(),'&editQuestion=',$row['id'],'&fromExercise='.$fromExercise.'&answerType='.$row['type'].'">',$row['question'],'</a></td>';
+        echo '  <td align="center" >';
+		if (empty($fromExercise)) {
+            echo '<a href="admin.php?'.api_get_cidreq().'&amp;editQuestion=',$row['id'],'"><img src="../img/edit.gif" border="0" alt="',get_lang('Modify'),'"></a>',
+                '</td>',
+                '<td align="center">',
+                '<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
+                //'<a href="',api_get_self(),'?',api_get_cidreq(),'&exerciseId=',$exerciseId,'&delete=',$row['id'],'" onclick="javascript:if(!confirm(\'',addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)),'\')) return false;"><img src="../img/delete.gif" border="0" alt="',get_lang('Delete'),'"></a>';
+		} else {
+            //echo $row['level'],'</td>',
 //					'<td><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'"><img src="../img/view_more_stats.gif" border="0" alt="',get_lang('Reuse'),'"></a>';
 				echo $row['level'],'</td>',
 							'<td align="center"><a href="',api_get_self(),'?',api_get_cidreq(),'&recup=',$row['id'],'&fromExercise=',$fromExercise,'">';
@@ -547,7 +575,3 @@ if ($is_allowedToEdit) {
     	  	</div></form>';
     }
 	Display::display_footer();
-} else {
-	// if not admin of course
-	api_not_allowed(true);
-}

+ 3 - 3
main/inc/lib/course.lib.php

@@ -141,7 +141,7 @@ class CourseManager {
 
      */
     public static function get_course_information_by_id($course_id) {
-        return Database::select('*', Database::get_main_table(TABLE_MAIN_COURSE), array('id = ?' =>intval($course_id)) );        
+        return Database::select('*', Database::get_main_table(TABLE_MAIN_COURSE), array('where'=>array('id = ?' =>intval($course_id))),'first');        
     }
     
 
@@ -623,7 +623,7 @@ class CourseManager {
         $user_id = intval($user_id);
         $data = array();
 
-        $sql_nb_cours = "SELECT course_rel_user.course_code, course.title, course.id
+        $sql_nb_cours = "SELECT course_rel_user.course_code, course.title, course.id, course.db_name
             FROM $tbl_course_user as course_rel_user
             INNER JOIN $tbl_course as course
                 ON course.code = course_rel_user.course_code
@@ -634,7 +634,7 @@ class CourseManager {
             $tbl_course_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
             $access_url_id = api_get_current_access_url_id();
             if ($access_url_id != -1) {
-                $sql_nb_cours = "	SELECT course_rel_user.course_code, course.title, course.id
+                $sql_nb_cours = "	SELECT course_rel_user.course_code, course.title, course.id, course.db_name
                     FROM $tbl_course_user as course_rel_user
                     INNER JOIN $tbl_course as course
                         ON course.code = course_rel_user.course_code

+ 12 - 5
main/inc/lib/database.lib.php

@@ -1328,8 +1328,10 @@ class Database {
      * @todo lot of stuff to do here
     */
     
-    public static function select($columns = '*' , $table_name,  $conditions = array(), $option = 'ASSOC') {        
-    	$conditions = self::parse_conditions($conditions);        
+    public static function select($columns = '*' , $table_name,  $conditions = array(), $type_result = 'all', $option = 'ASSOC') {        
+    	$conditions = self::parse_conditions($conditions); 
+        
+        //@todo we could do a describe here to check the columns ...       
         $clean_columns = '';
         if (is_array($columns)) {
         	$clean_columns = implode(',', $columns);
@@ -1340,18 +1342,23 @@ class Database {
         		$clean_columns = (string)$columns;
         	}
         }
+        
              
-        $sql    = "SELECT $clean_columns FROM $table_name $conditions";
+         $sql    = "SELECT $clean_columns FROM $table_name $conditions";
+      
+               
+        
         $result = self::query($sql);        
         $array = array();        
-        if (self::num_rows($result) > 1 ) {          
+        //if (self::num_rows($result) > 0 ) {        
+        if ($type_result == 'all') {  
             while ($row = self::fetch_array($result, $option)) {
                 if (isset($row['id'])) {
                     $array[$row['id']] = $row;
                 } else {
                 	$array[] = $row;
                 }                    
-            }            
+            }         
         } else {
         	$array = self::fetch_array($result, $option);
         }

+ 13 - 26
main/inc/lib/main_api.lib.php

@@ -1049,6 +1049,7 @@ function api_get_course_info($course_code = null) {
             global $_configuration;
             $cData = Database::fetch_array($result);
             $_course['id'           ]         = $cData['code'           ];
+            $_course['code'         ]         = $cData['code'           ];
             $_course['name'         ]         = $cData['title'          ];
             $_course['official_code']         = $cData['visual_code'    ]; // Use in echo statements.
             $_course['sysCode'      ]         = $cData['code'           ]; // Use as key in db.
@@ -1061,40 +1062,26 @@ function api_get_course_info($course_code = null) {
             $_course['extLink'      ]['name'] = $cData['department_name'];
             $_course['categoryCode' ]         = $cData['faCode'         ];
             $_course['categoryName' ]         = $cData['faName'         ];
-
-            $_course['visibility'   ]        = $cData['visibility'      ];
-            $_course['subscribe_allowed']    = $cData['subscribe'       ];
-            $_course['unubscribe_allowed']   = $cData['unsubscribe'     ];
+            $_course['visibility'   ]         = $cData['visibility'      ];
+            $_course['subscribe_allowed']     = $cData['subscribe'       ];
+            $_course['unubscribe_allowed']    = $cData['unsubscribe'     ];
 
             // The real_id is an integer. It is mandatory for future implementations.
-            $_course['real_id'     ]         = $cData['id'              ];
+            $_course['real_id'     ]          = $cData['id'              ];
         }
         return $_course;
     }
-    global $_course;
+    global $_course;    
     return $_course;
 }
 
 
 /**
  * Returns the current course info array.
- * Array elements:
- * ['name']
- * ['official_code']
- * ['sysCode']
- * ['path']
- * ['dbName']
- * ['dbNameGlu']
- * ['titular']
- * ['language']
- * ['extLink']['url' ]
- * ['extLink']['name']
- * ['categoryCode']
- * ['categoryName']
+
  * Now if the course_code is given, the returned array gives info about that
  * particular course, not specially the current one.
  */
-
 function api_get_course_info_by_id($id = null) {
     if (!empty($id)) {
         $id = intval($id);
@@ -1127,13 +1114,13 @@ function api_get_course_info_by_id($id = null) {
             $_course['categoryCode' ]         = $cData['faCode'         ];
             $_course['categoryName' ]         = $cData['faName'         ];
 
-            $_course['visibility'   ]        = $cData['visibility'      ];
-            $_course['subscribe_allowed']    = $cData['subscribe'       ];
-            $_course['unubscribe_allowed']   = $cData['unsubscribe'     ];
+            $_course['visibility'   ]         = $cData['visibility'      ];
+            $_course['subscribe_allowed']     = $cData['subscribe'       ];
+            $_course['unubscribe_allowed']    = $cData['unsubscribe'     ];
 
-            $_course['real_id'      ]        = $cData['id'              ];
-            $_course['db_name'      ]        = $cData['db_name'         ];
-            $_course['title'        ]        = $cData['title'           ];
+            $_course['real_id'      ]         = $cData['id'              ];
+            $_course['db_name'      ]         = $cData['db_name'         ];
+            $_course['title'        ]         = $cData['title'           ];
 
         }
         return $_course;

+ 1 - 1
main/inc/lib/sessionmanager.lib.php

@@ -1233,7 +1233,7 @@ class SessionManager {
     
     public static function get_sessions_by_coach($user_id) {
         $session_table = Database::get_main_table(TABLE_MAIN_SESSION);
-        return Database::select('*', $session_table, array('id_coach = ?'=>$user_id));    	
+        return Database::select('*', $session_table, array('where'=>array('id_coach = ?'=>$user_id)));    	
     }
     
 }