Browse Source

Fixing exercise result list + CSV and XLS exports by exercise

Julio Montoya 14 years ago
parent
commit
892592273e
3 changed files with 103 additions and 62 deletions
  1. 15 18
      main/exercice/exercice.php
  2. 5 2
      main/exercice/exercice_submit.php
  3. 83 42
      main/exercice/exercise.lib.php

+ 15 - 18
main/exercice/exercice.php

@@ -17,10 +17,10 @@ require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
 require_once '../gradebook/lib/be.inc.php';
 
-// setting the tabs
+// Setting the tabs
 $this_section = SECTION_COURSES;
 
-// access control
+// Access control
 api_protect_course_script(true);
 
 $show = (isset ($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
@@ -122,7 +122,7 @@ if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !emp
 	$sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . $_GET['did']; //_GET[did] filtered by entry condition
 	Database::query($sql);
 	$filter=Security::remove_XSS($_GET['filter']);
-	header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '');
+	header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '&exerciseId='.$exerciseId);
 	exit;
 }
 
@@ -381,13 +381,13 @@ if (!empty ($_POST['export_report']) && $_POST['export_report'] == 'export_repor
 		switch ($_POST['export_format']) {
 			case 'xls' :
 				$export = new ExerciseResult();               
-				$export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exercise_id']);
+				$export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exerciseId']);
 				exit;
 				break;
 			case 'csv' :
 			default :
 				$export = new ExerciseResult();
-				$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exercise_id']);
+				$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exerciseId']);
 				exit;
 				break;
 		}
@@ -608,7 +608,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
 			echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
 			echo '<input type="hidden" name="export_report" value="export_report">';
 			echo '<input type="hidden" name="export_format" value="csv">';
-            echo '<input type="hidden" name="exercise_id" value="'.intval($_GET['exercise_id']).'">';            
+            echo '<input type="hidden" name="exerciseId" value="'.intval($_GET['exerciseId']).'">';            
             
             if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
                 $filter = 1;
@@ -622,7 +622,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
 			echo '<input type="hidden" name="export_report" value="export_report">';
 			echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
 			echo '<input type="hidden" name="export_format" value="xls">';
-            echo '<input type="hidden" name="exercise_id" value="'.intval($_GET['exercise_id']).'">';
+            echo '<input type="hidden" name="exerciseId" value="'.intval($_GET['exerciseId']).'">';
 			echo '</form>';
 		}
 	}
@@ -656,9 +656,9 @@ if ($show == 'result') {
 				null;
 		}
 		if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
-			$view_result = '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=2&exercise_id='.intval($_GET['exercise_id']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('check.gif', get_lang('ShowCorrectedOnly')).get_lang('ShowCorrectedOnly').'</a>';
+			$view_result = '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=2&exerciseId='.intval($_GET['exerciseId']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('check.gif', get_lang('ShowCorrectedOnly')).get_lang('ShowCorrectedOnly').'</a>';
 		} else {
-			$view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&exercise_id='.intval($_GET['exercise_id']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('un_check.gif', get_lang('ShowUnCorrectedOnly')).get_lang('ShowUnCorrectedOnly').'</a>';
+			$view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&exerciseId='.intval($_GET['exerciseId']).'&gradebook='.$gradebook.'" >'.Display :: return_icon('un_check.gif', get_lang('ShowUnCorrectedOnly')).get_lang('ShowUnCorrectedOnly').'</a>';
 		}
 		echo $view_result;
 	}
@@ -791,9 +791,9 @@ if ($show == 'test') {
                         //Settings                                                                
                         //$actions  = Display::url(Display::return_icon('edit.gif',get_lang('Edit'), array('width'=>'20px')), 'exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$row['id']);
                         
-                        $actions =  Display::url(Display::return_icon('wizard_small.gif',get_lang('Edit'), array('width'=>'22px')), 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
+                        $actions =  Display::url(Display::return_icon('wizard.gif',get_lang('Edit'), array('width'=>'22px')), 'admin.php?'.api_get_cidreq().'&exerciseId='.$row['id']);
                         
-                        $actions .='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exercise_id='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
+                        $actions .='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exerciseId='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';
                         
                         //Export
                         $actions .= Display::url(Display::return_icon('cd.gif',          get_lang('CopyExercise')),       '', array('onclick'=>"javascript:if(!confirm('".addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset))." ".addslashes($row['title'])."?"."')) return false;",'href'=>'exercice.php?'.api_get_cidreq().'&choice=copy_exercise&sec_token='.$token.'&exerciseId='.$row['id']));
@@ -916,10 +916,9 @@ if ($show == 'test') {
                             $attempt_text = get_lang('CantShowResults');
                         }
                     }
-                                
                     //User Attempts    
-                    if (empty($row['max_attempt'])) {                        
-                        $item .=  Display::tag('td','-');
+                    if (empty($row['max_attempt'])) {
+                        $item .=  Display::tag('td',$num);     
                     } else {
                         if (empty($num)) {
                         	$num = 0;
@@ -944,16 +943,14 @@ if ($show == 'test') {
 }
     
 
-    
-
 /* Exercise Results (uses tracking tool) */
 
 // if tracking is enabled
 if ($show == 'result') {
 	$parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
-    $exercise_id = intval($_GET['exercise_id']);
+    $exercise_id = intval($_GET['exerciseId']);
     if (!empty($exercise_id))
-        $parameters['exercise_id'] = $exercise_id;
+        $parameters['exerciseId'] = $exercise_id;
                         
 	$table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data');
 	$table->set_additional_parameters($parameters);

+ 5 - 2
main/exercice/exercice_submit.php

@@ -26,7 +26,7 @@ require_once 'answer.class.php';
 require_once 'exercise.lib.php';
 
 // debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages.
-$debug = 1;
+$debug = 0;
 
 // name of the language file that needs to be included
 $language_file = 'exercice';
@@ -493,7 +493,7 @@ if (api_is_course_admin() && $origin != 'learnpath') {
 }
 
 $exerciseTitle = text_filter($objExercise->selectTitle());
-echo "<h2>" . $exerciseTitle . "</h2>";
+echo Display::tag('h2', $exerciseTitle);
 $show_clock = true;
 $user_id = api_get_user_id();
 if ($objExercise->selectAttempts() > 0) {	
@@ -502,6 +502,9 @@ if ($objExercise->selectAttempts() > 0) {
     	$show_clock = false;
         if (!api_is_allowed_to_edit(null,true)) {
             Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $objExercise->selectAttempts()), false);
+            
+            
+            
             if ($origin != 'learnpath')
                 Display :: display_footer();
             exit;

+ 83 - 42
main/exercice/exercise.lib.php

@@ -737,7 +737,7 @@ function get_session_time_control_key($exercise_id) {
  */
 function get_count_exam_results($exercise_id = null) {
     //@todo replace all this globals
-    global $is_allowedToEdit, $is_tutor,$_cid,$_user,$TBL_USER, $TBL_EXERCICES,$TBL_TRACK_EXERCICES, $TBL_TRACK_HOTPOTATOES, $TBL_TRACK_ATTEMPT_RECORDING,$filter_by_not_revised,$filter_by_revised,$documentPath;
+    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() . ' ';
     if ($is_allowedToEdit || $is_tutor) {
         $user_id_and = '';
@@ -750,15 +750,11 @@ function get_count_exam_results($exercise_id = null) {
         }
         if ($_GET['gradebook'] == 'view') {
             $exercise_where_query = 'te.exe_exo_id =ce.id AND ';
-        }       
-                
+        }        
+        $exercise_id = intval($_GET['exerciseId']);
         $exercise_where = '';
-        if (isset($_GET['exerciseId'])) {
-            $exercise_where = ' AND te.exe_exo_id = '.intval($_GET['exerciseId']).'  ';
-        }
-        
         if (!empty($exercise_id)) {
-            $exercise_where = ' AND te.exe_exo_id = '.intval($exercise_id).'  ';
+            $exercise_where = ' AND te.exe_exo_id = '.$exercise_id.'  ';
         }
 
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
@@ -769,15 +765,15 @@ function get_count_exam_results($exercise_id = null) {
                       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 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='" . 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 $exercise_where ";
-
+        
+        $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) INNER JOIN $TBL_TRACK_ATTEMPT_RECORDING re ON(re.exe_id = te.exe_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 ".(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 = '" . Database :: escape_string($_cid) . "' $user_id_and  
+                    WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id() . "' $user_id_and  
                     ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 
     } else {
@@ -795,18 +791,63 @@ function get_count_exam_results($exercise_id = null) {
 
       $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='" . Database :: escape_string($_cid) . "'  $user_id_and $session_id_and AND ce.active <>-1 AND" .
+            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 ";
 
       $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
                 FROM $TBL_TRACK_HOTPOTATOES
-                WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
+                WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "'
                 ORDER BY exe_cours_id ASC, exe_date DESC";
     }
-
     $resx = Database::query($sql);
-    $rowx = Database::fetch_array($resx,'ASSOC');
-    return $rowx['count'];
+    $hpres = Database::query($hpsql);
+    
+    $count = 0;
+    if (Database::num_rows($resx) > 0) {        
+        while ($rowx = Database::fetch_array($resx,'ASSOC')) {
+            $results[] = $rowx;
+        }
+        $has_test_results = false;
+       
+        if (is_array($results)) {
+            $has_test_results = true;
+            $users_array_id = array ();
+            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++;           
+            }
+        }
+    }
+    if (Database::num_rows($hpres) > 0) {
+        $rowx = Database::fetch_array($hpres,'ASSOC');
+        $count += $rowx['count'];
+    }
+    return $count;
 }
 
 
@@ -818,8 +859,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,$_cid,$_user,$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;
     $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
+    
+    $exercise_id = intval($_GET['exerciseId']);
+    
     if ($is_allowedToEdit || $is_tutor) {
         $user_id_and = '';
         if (!empty ($_POST['filter_by_user'])) {
@@ -835,8 +879,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
         }
         
         $exercise_where = '';
-        if (isset($_GET['exerciseId'])) {
-            $exercise_where .= ' AND te.exe_exo_id = '.intval($_GET['exerciseId']).'  ';
+        if (!empty($exercise_id)) {
+            $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.'  ';
         }
         
 
@@ -845,18 +889,17 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
         /*$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($_cid) . "'
+                      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
                 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='" . 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 $exercise_where ";
+                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 = '" . Database :: escape_string($_cid)."' $user_id_and $exercise_where 
+                WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . api_get_course_id()."' $user_id_and $exercise_where 
                 ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 
 
@@ -874,26 +917,24 @@ 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 ".(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, ce.results_disabled as exdisabled
               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='" . 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 ";
+              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 ";
 
-        $hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
+        $hpsql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date
                   FROM $TBL_TRACK_HOTPOTATOES
-                  WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
+                  WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "'
                   ORDER BY exe_cours_id ASC, exe_date DESC";
     }
 
 
-    $column = intval($column);
-    $from = intval($from);
-    $number_of_items = intval($number_of_items);
-    $sql .= " ORDER BY col$column $direction ";
-    $sql .= " LIMIT $from,$number_of_items";
+    $column             = intval($column);
+    $from               = intval($from);
+    $number_of_items    = intval($number_of_items);
+    $sql               .= " ORDER BY col$column $direction ";
+    $sql               .= " LIMIT $from, $number_of_items";
 
     $results = array();
 
@@ -901,14 +942,14 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     while ($rowx = Database::fetch_array($resx,'ASSOC')) {
         $results[] = $rowx;
     }
+    
     $hpresults = getManyResultsXCol($hpsql, 5);
 
     $has_test_results = false;
     $list_info = array();
 
     // Print test results.
-    $lang_nostartdate = get_lang('NoStartDate') . ' / ';
-    
+    $lang_nostartdate = get_lang('NoStartDate') . ' / ';    
     
     if (is_array($results)) {
         $has_test_results = true;
@@ -929,9 +970,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
         $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]['exid']) .' LIMIT 1';
+            $sql_exe = 'SELECT exe_id FROM ' . $TBL_TRACK_ATTEMPT_RECORDING . ' WHERE author != "" AND exe_id = ' . Database :: escape_string($results[$i]['exid']) .' LIMIT 1';            
             $query = Database::query($sql_exe);
-
             if (Database :: num_rows($query) > 0) {
                 $revised = true;
             }
@@ -941,6 +981,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             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;
@@ -1013,12 +1054,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                         $html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&id=$id'>".Display :: return_icon('edit.gif', get_lang('Edit'));
                         $html_link.= '&nbsp;';
                     } else {
-                        $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
+                        $html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&id=$id'>".Display :: return_icon('quiz.gif', get_lang('Qualify'));
                         $html_link.='&nbsp;';
                     }
                     $html_link.="</a>";
                     if (api_is_platform_admin() || $is_tutor) {
-                        $html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.gif', get_lang('Delete')).'</a>';
+                        $html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&exerciseId='.$exercise_id.'&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.png', get_lang('Delete')).'</a>';
                         $html_link.='&nbsp;';
                     }
                     if ($is_allowedToEdit) {