Browse Source

#4031 #4027 #4026 add group filter in test answer list + minor bug

Hubert Borderiou 13 years ago
parent
commit
f7878d7036

+ 33 - 3
main/exercice/exercice.php

@@ -116,6 +116,20 @@ if (empty ($exerciseId)) {
 if (empty ($file)) {
 	$file = Database :: escape_string($_REQUEST['file']);
 }
+// ------------------------------- hubr
+// filter display by student group
+// if $_GET['filterByGroup'] = -1 => do not filter
+// else, filter by group_id (0 for no group)
+// -------------------------------
+$filterByGroup = -1;
+if (isset($_GET['filterByGroup']) && is_numeric($_GET['filterByGroup'])) {
+	$filterByGroup = Security::remove_XSS($_GET['filterByGroup']);
+	api_session_register('filterByGroup');
+}
+else if (isset($_SESSION['filterByGroup'])) {
+	$filterByGroup = $_SESSION['filterByGroup'];
+}
+// -------------------------------
 $learnpath_id       = intval($_REQUEST['learnpath_id']);
 $learnpath_item_id  = intval($_REQUEST['learnpath_item_id']);
 $page               = intval($_REQUEST['page']);
@@ -638,6 +652,21 @@ if ($show == 'result') {
     			$view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&id_session='.intval($_GET['id_session']).'&exerciseId='.intval($_GET['exerciseId']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('exercice_uncheck.png', get_lang('ShowUnCorrectedOnly'),'','32').'</a>';
     		}
     		echo $view_result;
+			// -----------------------------hubr
+			// filter by student group menu
+			// -----------------------------
+			$exercice_id = intval($_GET['exerciseId']);
+            echo "<script type='text/javascript'>";
+			echo "	    function doFilterByGroup() {";
+    		echo "			var IdGroup = document.getElementById('groupFilter').value;";
+    		echo "			var goToUrl = \"".api_get_self()."?".api_get_cidreq()."&show=result&filter=$filter&gradebook=$gradebook&exerciseId=$exercice_id;$quiz_results_per_page&filterByGroup=\"+IdGroup;";
+    		echo "			self.location.href=goToUrl;";
+			echo "	    }";
+			echo "        </script>";
+			echo "&nbsp;&nbsp;";
+			echo Display::return_icon('group.gif', '');
+			echo get_lang("FilterByGroup")."&nbsp;".displayGroupMenu("groupFilter", $filterByGroup, "doFilterByGroup()")."&nbsp;";
+			// -----------------------------    		
 		}
 	}
 }
@@ -1080,7 +1109,8 @@ if ($show == 'result') {
     if (!empty($_GET['path'])) {
         $parameters['path'] = Security::remove_XSS($_GET['path']);
     }
-	$table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data');
+    
+	$table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data', 1, 10);
 	$table->set_additional_parameters($parameters);
     
     if ($is_allowedToEdit || $is_tutor) {
@@ -1123,11 +1153,11 @@ if ($origin != 'learnpath') { //so we are not in learnpath tool
 //          $in_default : default value for option
 // @return : the html code of the <select>
 // ---------------------------------------------------------
-function displayGroupMenu($in_name, $in_default) {
+function displayGroupMenu($in_name, $in_default, $in_onchange="") {
 	// check the default value of option
 	$tabSelected = array($in_default => " selected='selected' ");
 	$res = "";
-	$res .= "<select name='$in_name' id='$in_name' >";
+	$res .= "<select name='$in_name' id='$in_name' onchange='".$in_onchange."' >";
 	$res .= "<option value='-1'".$tabSelected["-1"].">-- ".get_lang('AllGroups')." --</option>";
 	$res .= "<option value='0'".$tabSelected["0"].">- ".get_lang('NotInAGroup')." -</option>";
 	$tabGroups = GroupManager::get_group_list();

+ 159 - 161
main/exercice/exercise.lib.php

@@ -735,142 +735,17 @@ function get_session_time_control_key($exercise_id) {
     return $return_value;
 }
 
-
-
-
 /**
  * Gets count of exam results
  * @todo this function should be moved in a library  + no global calls 
+ * Modified by hubert borderiou 08-11-2011
  */
-function get_count_exam_results($exercise_id = null) {
-    //@todo replace all this globals
-    global $is_allowedToEdit, $is_tutor,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_HOTPOTATOES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath;
-    $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
-    
-    $exercise_id = intval($_GET['exerciseId']);
-    $exercise_where = '';
-    if (!empty($exercise_id)) {
-        $exercise_where = ' AND te.exe_exo_id = '.$exercise_id.'  ';
-    }
-    
-    $hotpotatoe_where = '';
-    if (!empty($_GET['path'])) {
-        $hotpotatoe_path = Database::escape_string($_GET['path']);
-        $hotpotatoe_where .= ' AND exe_name = "'.$hotpotatoe_path.'"  ';
-    }
-         
-    $user_id_hotpotato_and = ' AND exe_user_id = ' . api_get_user_id() . ' ';
-    
-    if ($is_allowedToEdit || $is_tutor) {
-        $user_id_and = '';
-        if (!empty ($_POST['filter_by_user'])) {
-            if ($_POST['filter_by_user'] == 'all') {
-                $user_id_and = " AND user_id like '%'";
-            } else {
-                $user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
-            }
-        }
-        if ($_GET['gradebook'] == 'view') {
-            $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
-        }        
-
-
-        //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
-
-        /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname col1" : "lastname as userpart1, firstname as col1").", ce.title as extitle, te.exe_result as exresult ,
-                             te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration
-                      FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
-                      WHERE  user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
-                      $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
-                      AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
-        
-        $sql="SELECT DISTINCT te.exe_id
-                FROM $TBL_EXERCICES  AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN  $TBL_USER  AS user ON (user.user_id = exe_user_id)
-                WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and  $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
-                
-        //Seems that the $TBL_TRACK_HOTPOTATOES does not have an exercise id that's weird ... we are removing $exercise_where
-        $hpsql="SELECT  count(*) as count
-                    FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
-                    WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id() . "' $user_id_hotpotato_and  $hotpotatoe_where
-                    ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
-
-    } else {
-        // get only this user's results
-        $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';        
-
-        /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult, " .
-                            "te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
-                            "te.start_date as exstart, steps_counter as exstep, cuser.user_id as excruid, te.exe_duration as exduration, ce.results_disabled as exdisabled
-                            FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
-                    WHERE  user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id 
-                    AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
-                    AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
-                    " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
-
-      $sql="SELECT count(*) as count
-            FROM $TBL_EXERCICES  AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN  $TBL_USER  AS user ON (user.user_id = exe_user_id)
-            WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where";
-
-      $hpsql = "SELECT count(*) as count
-                FROM $TBL_TRACK_HOTPOTATOES
-                WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' $user_id_hotpotato_and $hotpotatoe_where
-                ORDER BY exe_cours_id ASC, exe_date DESC";
-    }
-    
-    $count = 0;
-    //Chamilo results
-    if (empty($hotpotatoe_where)) {
-        $resx = Database::query($sql);
-        if (Database::num_rows($resx) > 0) {
-            if ($is_allowedToEdit || $is_tutor) {
-                while ($rowx = Database::fetch_array($resx,'ASSOC')) {
-                    $results[] = $rowx;
-                }
-                //Special modification to show corretly the pagination
-                if (is_array($results)) {          
-                    if ($_GET['gradebook'] == 'view') {
-                        $filter_by_no_revised = true;
-                        $from_gradebook = true;
-                    }
-                    $sizeof = count($results);        
-                    $user_list_id = array ();
-                    $user_last_name = '';
-                    $user_first_name = '';
-                    $quiz_name_list = '';
-                    $duration_list = '';
-                    $date_list = '';
-                    $result_list = '';
-                    $more_details_list = '';
-                    for ($i = 0; $i < $sizeof; $i++) {
-                        $revised = false;                
-                        $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . ' WHERE author != "" AND exe_id = ' . Database :: escape_string($results[$i]['exe_id']) .' LIMIT 1';            
-                        $query = Database::query($sql_exe);
-                        if (Database :: num_rows($query) > 0) {
-                            $revised = true;
-                        }
-                        if ($filter_by_not_revised && $revised) {
-                            continue;
-                        }
-                        if ($filter_by_revised && !$revised) {
-                            continue;
-                        }
-                        $count++;           
-                    }
-                }        
-            } else {            
-            	$rowx = Database::fetch_array($resx,'ASSOC');
-                $count = $rowx['count'];
-            }
-        }
-    } else {
-        //Hotpotatoes results
-        $hpres = Database::query($hpsql);
-        if (Database::num_rows($hpres) > 0) {
-            $rowx = Database::fetch_array($hpres,'ASSOC');
-            $count += $rowx['count'];
-        }
-    }
-    return $count;
+function get_count_exam_results() {
+    // I know it's bad to add a static integer here... but
+    // it factorise function get_exam_results_data
+    // and I think it worths it.
+    $tabres = get_exam_results_data(0, 9999999, 0, "ASC");
+    return count($tabres);
 }
 
 
@@ -880,7 +755,11 @@ function get_count_exam_results($exercise_id = null) {
  */
 function get_exam_results_data($from, $number_of_items, $column, $direction) {
     //@todo replace all this globals
-    global $is_allowedToEdit, $is_tutor,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_HOTPOTATOES, $TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath,$filter;
+    global  $is_allowedToEdit, $is_tutor,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_HOTPOTATOES, 
+            $TBL_TRACK_EXERCICES, $TBL_TRACK_ATTEMPT_RECORDING,
+            $filter_by_not_revised, $filter_by_revised, $documentPath, $filter, 
+            $filterByGroup, $TBL_GROUP_REL_USER;
+    
     $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
     
     $exercise_id = intval($_GET['exerciseId']);
@@ -911,24 +790,123 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             $exercise_where_query = ' te.exe_exo_id =ce.id AND ';
         }
 
+		$sqlFromOption = "";
+		$sqlWhereOption = "";           // for hpsql
+	    $sql_inner_join_tbl_user = "";    
+	    $sql_inner_join_tbl_track_exercices = "";
+		$filterByGroup = intval($filterByGroup);
+		
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
 
-        /*$sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as extitle, te.exe_result as exresult ,
-                             te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as exstart, steps_counter as exstep,cuser.user_id as excruid,te.exe_duration as exduration
-                      FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
-                      WHERE  user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string(api_get_course_id()) . "'
-                      $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
-                      AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
-        $sql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", ce.title as col2, te.exe_result as exresult , te.exe_weighting as exweight,
-                te.exe_date as exdate, te.exe_id as exid, email as exemail, te.start_date as col4, steps_counter as exstep, exe_user_id as excruid,te.exe_duration as exduration, propagate_neg
-                FROM $TBL_EXERCICES  AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN  $TBL_USER  AS user ON (user.user_id = exe_user_id)
-                WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and  $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 $exercise_where ";
-
-        $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1").", tth.exe_name, tth.exe_result , tth.exe_weighting, tth.exe_date
-                FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
-                WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id()."'  $hotpotatoe_where
-                ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
-    } else {
+        // -----------------------------
+        // Filter by test revised or not
+        // -----------------------------
+        switch ($filter) {
+            case 0 :    // filter_by_not_revised
+            case 1 :
+                $sql_inner_join_tbl_track_exercices = "
+                    (SELECT * FROM $TBL_TRACK_EXERCICES AS tte
+                    WHERE tte.exe_id NOT IN (SELECT DISTINCT exe_id FROM $TBL_TRACK_ATTEMPT_RECORDING))";
+                break;
+            case 2 :    // filter_by_revised
+                $sql_inner_join_tbl_track_exercices = "
+                    (SELECT * FROM $TBL_TRACK_EXERCICES AS tte
+                    WHERE tte.exe_id IN (SELECT DISTINCT exe_id FROM $TBL_TRACK_ATTEMPT_RECORDING))";
+                break;
+           default :    // no filter for revised
+                $sql_inner_join_tbl_track_exercices = $TBL_TRACK_EXERCICES;
+                break;
+        }
+		
+		// -----------------------------
+		// Filter by group
+		// -----------------------------
+		switch ($filterByGroup) {
+		    case -1 : // no filter
+        	    $sql_inner_join_tbl_user = $TBL_USER;    
+		        break;
+		    case 0 : // user not in any group
+    		    $sql_inner_join_tbl_user = " 
+                    (SELECT u.user_id, firstname, lastname, email 
+                    FROM $TBL_USER u 
+                    WHERE 
+                    u.user_id NOT IN (
+                        SELECT user_id 
+                        FROM $TBL_GROUP_REL_USER
+                        WHERE c_id=".api_get_course_int_id()."))";
+    			$sqlFromOption = " ,$TBL_GROUP_REL_USER AS gru ";
+    			$sqlWhereOption = " AND user.user_id NOT IN	( SELECT user_id FROM $TBL_GROUP_REL_USER WHERE c_id=".api_get_course_int_id().") ";
+		        break;
+		    default : // user in group $filterByGroup
+    		    $sql_inner_join_tbl_user = " 
+                    (SELECT u.user_id, firstname, lastname, email 
+                    FROM $TBL_USER u 
+                    INNER JOIN $TBL_GROUP_REL_USER gru ON (
+                        gru.user_id=u.user_id 
+                        AND gru.group_id=$filterByGroup 
+                        AND gru.c_id=".api_get_course_int_id()."))";
+    			$sqlFromOption = " ,$TBL_GROUP_REL_USER AS gru ";
+    			$sqlWhereOption = "  AND gru.c_id=".api_get_course_int_id()." AND gru.user_id=user.user_id AND gru.group_id=".Database :: escape_string($filterByGroup);
+		        break;
+		}
+		
+        $first_and_last_name = api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1";
+        
+        // ---------------------------------------------------
+        // sql for chamilo-type tests for teacher / tutor view
+        // ---------------------------------------------------
+        $sql="  
+                SELECT
+                    user_id, 
+                    $first_and_last_name, 
+                    ce.title as col2, 
+                    te.exe_result as exresult , 
+                    te.exe_weighting as exweight,
+                    te.exe_date as exdate, 
+                    te.exe_id as exid, 
+                    email as exemail, 
+                    te.start_date as col4, 
+                    steps_counter as exstep, 
+                    exe_user_id as excruid,
+                    te.exe_duration as exduration, 
+                    propagate_neg
+                FROM 
+                    $TBL_EXERCICES  AS ce 
+                INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.id) 
+                INNER JOIN $sql_inner_join_tbl_user  AS user ON (user.user_id = exe_user_id)
+                WHERE 
+                    te.status != 'incomplete' 
+                    AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and  $session_id_and 
+                    AND ce.active <>-1 
+                    AND orig_lp_id = 0 
+                    AND orig_lp_item_id = 0
+                    AND ce.c_id=".api_get_course_int_id()."
+                    $exercise_where ";
+
+        // --------------------------------------------------
+        // sql for hotpotatoes tests for teacher / tutor view
+        // --------------------------------------------------
+        $hpsql="
+                SELECT 
+                    $first_and_last_name , 
+                    tth.exe_name, 
+                    tth.exe_result , 
+                    tth.exe_weighting, 
+                    tth.exe_date
+                FROM 
+                    $TBL_TRACK_HOTPOTATOES tth, 
+                    $TBL_USER user
+                    $sqlFromOption
+                WHERE  
+                    user.user_id=tth.exe_user_id 
+                    AND tth.exe_cours_id = '" . api_get_course_id()."'  
+                    $hotpotatoe_where 
+                    $sqlWhereOption
+                ORDER BY 
+                    tth.exe_cours_id ASC, 
+                    tth.exe_date DESC";
+    } 
+    else {
         // get only this user's results
         $user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
    
@@ -941,10 +919,36 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND" .
             " orig_lp_id = 0 AND orig_lp_item_id = 0 AND cuser.course_code=te.exe_cours_id ORDER BY col1, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";*/
 
-        $sql="SELECT ce.title as col0, ce.title as col1, te.exe_duration as exduration, firstname, lastname, te.exe_result as exresult, te.exe_weighting as exweight, te.exe_date as exdate, te.exe_id as exid, email as exemail, " .
-            "te.start_date as col2, steps_counter as exstep, exe_user_id as excruid,  ce.results_disabled as exdisabled, propagate_neg
-              FROM $TBL_EXERCICES  AS ce INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) INNER JOIN  $TBL_USER  AS user ON (user.user_id = exe_user_id)
-              WHERE te.status != 'incomplete' AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0  $exercise_where";
+        $sql="
+                SELECT 
+                    ce.title as col0, 
+                    ce.title as col1, 
+                    te.exe_duration as exduration, 
+                    firstname, 
+                    lastname, 
+                    te.exe_result as exresult, 
+                    te.exe_weighting as exweight, 
+                    te.exe_date as exdate, 
+                    te.exe_id as exid, 
+                    email as exemail,
+                    te.start_date as col2, 
+                    steps_counter as exstep, 
+                    exe_user_id as excruid,  
+                    ce.results_disabled as exdisabled, 
+                    propagate_neg
+                FROM 
+                    $TBL_EXERCICES  AS ce 
+                    INNER JOIN $TBL_TRACK_EXERCICES AS te ON (te.exe_exo_id = ce.id) 
+                    INNER JOIN  $TBL_USER  AS user ON (user.user_id = exe_user_id)
+                WHERE 
+                    te.status != 'incomplete' 
+                    AND te.exe_cours_id='" . api_get_course_id() . "'  
+                    $user_id_and $session_id_and 
+                    AND ce.active <>-1 
+                    AND orig_lp_id = 0 
+                    AND orig_lp_item_id = 0  
+                    AND ce.c_id= ".api_get_course_int_id()."
+                    $exercise_where";
 
         $hpsql = "SELECT '', '', exe_name, exe_result , exe_weighting, exe_date
                   FROM $TBL_TRACK_HOTPOTATOES
@@ -1000,13 +1004,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                 if (Database :: num_rows($query) > 0) {
                     $revised = true;
                 }
-                if ($filter_by_not_revised && $revised) {
-                    continue;
-                }
-                if ($filter_by_revised && !$revised) {
-                    continue;
-                }
-                
                 if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
                     if (in_array($results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'], $users_array_id)) {
                         continue;
@@ -1018,6 +1015,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                     $user_last_name = $results[$i]['col1'];
                     $user = $results[$i]['col0'] . $results[$i]['col1'];
                     $test = $results[$i]['col2'];                    
+                    $user_groups = displayGroupsForUser('<br/>', $results[$i]['user_id']);
                 } else {
                     $user_first_name = $results[$i]['firstname'];
                     $user_last_name = $results[$i]['lastname'];
@@ -1126,7 +1124,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                     }
                     $more_details_list = $html_link;
                     if ($is_allowedToEdit || $is_tutor) {
-                        $list_info[] = array($user_first_name,$user_last_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
+                        $list_info[] = array($user_first_name,$user_last_name,$user_groups,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
                     } else {
                         $list_info[] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
                     }

+ 12 - 6
main/exercice/exercise_show.php

@@ -228,12 +228,18 @@ $arrques = array();
 $arrans  = array();
 
 $user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($student_id)." ";
-$query = "SELECT attempts.question_id, answer  from ".$TBL_TRACK_ATTEMPT." as attempts
-				INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
-				INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
-				INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
+$query = "SELECT attempts.question_id, answer  FROM ".$TBL_TRACK_ATTEMPT." as attempts
+				INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices ON stats_exercices.exe_id=attempts.exe_id
+				INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions 
+				    ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id 
+				    AND quizz_rel_questions.question_id = attempts.question_id
+				    AND quizz_rel_questions.c_id=".api_get_course_int_id()."
+				INNER JOIN ".$TBL_QUESTIONS." AS questions 
+				    ON questions.id=quizz_rel_questions.question_id
+				    AND questions.c_id = ".api_get_course_int_id()."
 		  WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
 		  GROUP BY quizz_rel_questions.question_order, attempts.question_id";
+
 			//GROUP BY questions.position, attempts.question_id";
 
 $result = Database::query($query);	
@@ -264,7 +270,7 @@ $counter = 1;
 foreach ($questionList as $questionId) {
 	
 	$choice = $exerciseResult[$questionId];
-		// destruction of the Question object
+	// destruction of the Question object
 	unset($objQuestionTmp);
 	
 	// creates a temporary Question object
@@ -276,7 +282,7 @@ foreach ($questionList as $questionId) {
 	$quesId 			= $objQuestionTmp->selectId();	
 	        	
  	if ($show_results) { 	    
-	    echo $objQuestionTmp->return_header($counter);
+	    echo $objQuestionTmp->return_header("", $counter);
 	}
 	$counter++;
 	

+ 2 - 2
main/inc/lib/events.lib.inc.php

@@ -988,13 +988,13 @@ function get_exercise_results_by_attempt($exe_id) {
 			$row['attempt_revised'] = 1;
 		}
 		$list[$exe_id] = $row;
-		$sql = "SELECT * FROM $table_track_attempt WHERE exe_id = $exe_id";
+		$sql = "SELECT * FROM $table_track_attempt WHERE exe_id = $exe_id ORDER BY tms ASC";
 		$res_question = Database::query($sql);
 		while ($row_q = Database::fetch_array($res_question,'ASSOC')) {
 			$list[$exe_id]['question_list'][$row_q['question_id']] = $row_q;
 		}
 	}
-	//echo '<pre>'; print_r($list);
+	// echo '<pre>'; print_r($list); echo "</pre>";
 	return $list;
 }