Parcourir la source

Showing latest attempt exercise results to students if he reached the max count of attemptssee BT#1628

Julio Montoya il y a 14 ans
Parent
commit
7c47815e71

+ 4 - 1
documentation/changelog.html

@@ -51,8 +51,11 @@
    <li>Added admin feature to hide tools from all courses - BT#1942</li>
    <li>New voice generator tool. Mp3 audio files generation from a text. Mp3 audio files generation from a text. Teachers, students (into his/her user folder) and groups can create and save mp3 audio files from a text through external service support speech synthesis of Google (build and save), Pediaphon (build and save) and vozMe (build and download)(Feature #2497)</li>
    <li>jqgrid library added (Feature #340)</li>
-   <li>Careers and promotions funcionality added Feature #2706</li>
+   <li>Careers and promotions funcionality added see #2706</li>
    <li>Session start date can be left in blank as well as the end date see BT#1911 </li>
+   <li>Exercises: Question list interface was changed, new drag and drop behaviour added</li>
+   <li>New Session page added when clicking in the session name in the Course list</li>
+   <li>Social notifications added in the Social tab</li>
 </ul>
 <h3>Debugging</h3>
 <ul>

+ 16 - 11
main/exercice/exercice.php

@@ -521,8 +521,8 @@ if ($is_allowedToEdit) {
 // Actions div bar
 echo '<div class="actions">';
 
-// display the next and previous link if needed
-// selects $limitExPage exercises at the same time
+// 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);
@@ -533,9 +533,9 @@ HotPotGCt($documentPath, 1, api_get_user_id());
 $session_id         = api_get_session_id();
 $condition_session  = api_get_session_condition($session_id,true,true);
 
-if ($show == 'test') {	
+if ($show == 'test') {
     
-    // Only for administrator
+    // Only for administrators
     if ($is_allowedToEdit) {
         $sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time, end_time, random, max_attempt FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
         $result = Database::query($sql);   
@@ -614,8 +614,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
                 $filter = 1;
             } else {
             	$filter = 2;
-            }
-            
+            }            
             echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
 			echo '</form>';
 			echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
@@ -631,7 +630,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
 	if ($show == 'result') {
 		echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
 	} else {
-		echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=result') . '">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
+		echo '<a href="' . api_get_self() .'?'.api_get_cidreq().'&show=result'.'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
 	}
 }
 
@@ -731,7 +730,7 @@ if ($show == 'test') {
             if ($is_allowedToEdit) {
                 $headers = array(get_lang('ExerciseName'),get_lang('QuantityQuestions'), get_lang('Actions'));
             } else {
-            	$headers = array(get_lang('ExerciseName'), get_lang('Attempts'), get_lang('Status'));
+            	$headers = array(get_lang('ExerciseName'), get_lang('Attempts'), get_lang('Status'), get_lang('Actions'));
             }
             $header_list = '';
             foreach($headers as $header) {
@@ -764,7 +763,7 @@ if ($show == 'test') {
                     }
                 }                
                       
-                // prof only
+                // Teacher only
                 if ($is_allowedToEdit) {
                                     
                     //Showing exercise title
@@ -846,6 +845,7 @@ if ($show == 'test') {
                 } else {
                      
                     // Student only
+                    
                     $row['title'] = text_filter($row['title']);                 
     
                     // if time is actived show link to exercise
@@ -884,7 +884,7 @@ if ($show == 'test') {
                     $qryres = Database::query($qry);
                     $num    = Database :: num_rows($qryres);
             
-                    //hide the results
+                    //Hide the results
                     $my_result_disabled = $row['results_disabled'];
                             
                     if ($time_limits) {
@@ -916,6 +916,7 @@ if ($show == 'test') {
                             $attempt_text = get_lang('CantShowResults');
                         }
                     }
+                    
                     //User Attempts    
                     if (empty($row['max_attempt'])) {
                         $item .=  Display::tag('td',$num);     
@@ -926,6 +927,10 @@ if ($show == 'test') {
                         $item .=  Display::tag('td',$num.' / '.$row['max_attempt']);                        
                     }
                     $item .=  Display::tag('td', $attempt_text);                    
+                    //See results
+                    $actions ='<a href="exercice.php?' . api_get_cidreq() . '&show=result&exerciseId='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')).'</a>';                    
+                    $item .=  Display::tag('td', $actions);
+                                     
                     echo Display::tag('tr',$item);                  
                 }
                 /*echo '</p>';
@@ -936,7 +941,7 @@ if ($show == 'test') {
             echo '</div>';
         }         
     } else {
-          echo Display::display_warning_message(get_lang('NoExercises'));
+        echo Display::display_warning_message(get_lang('NoExercises'));
     }
     Display :: display_footer();    
     exit;

+ 27 - 17
main/exercice/exercice_submit.php

@@ -38,20 +38,6 @@ $this_section = SECTION_COURSES;
 // Notice for unauthorized people.
 api_protect_course_script(true);
 $is_allowedToEdit = api_is_allowed_to_edit(null,true);
-
-//Blocking access in LPs
-//This funcionality has been moved to the get_link function in the learnpath_class.php
-/*
-if ($origin == 'learnpath' && isset ($_GET['not_multiple_attempt']) && $_GET['not_multiple_attempt'] == strval(intval($_GET['not_multiple_attempt']))) {
-    $not_multiple_attempt = (int) $_GET['not_multiple_attempt'];
-    if ($not_multiple_attempt === 1) {
-        require_once '../inc/reduced_header.inc.php';
-        echo '<div style="height:10px">&nbsp;</div>';
-        Display :: display_warning_message(get_lang('ReachedOneAttempt'));
-        exit;
-    }
-}*/
-
 $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
 
 if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
@@ -393,7 +379,7 @@ if ($formSent && isset($_POST)) {
                     if (exercise_time_control_is_valid($exerciseId)) {
                     	$sql_exe_result = "";                    	
                     } else {
-                    	$sql_exe_result = ",exe_result = 0";
+                    	$sql_exe_result = ", exe_result = 0";
                     }
                     //Clean incomplete - @todo why setting to blank the data_tracking?
                     //$update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . api_get_utc_datetime() . "' $sql_exe_result " . ' WHERE exe_id = ' . Database::escape_string($exe_id);
@@ -501,9 +487,33 @@ if ($objExercise->selectAttempts() > 0) {
     if ($attempt_count >= $objExercise->selectAttempts()) {
     	$show_clock = false;
         if (!api_is_allowed_to_edit(null,true)) {
-            Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $objExercise->selectAttempts()), false);
-            
             
+            if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
+                //Showing latest attempt according with task BT#1628
+                $exercise_stat_info = get_all_exercise_results_by_user(api_get_user_id(), $exerciseId, api_get_course_id(), api_get_session_id());
+                if (!empty($exercise_stat_info )) {
+                    $max_exe_id = max(array_keys($exercise_stat_info));
+                    $last_attempt_info = $exercise_stat_info[$max_exe_id];
+                    
+                    //echo '<pre>';    //var_dump($last_attempt_info);  
+                    if (!empty($last_attempt_info['question_list'])) {               
+                        foreach($last_attempt_info['question_list'] as $question_data) {
+                            $question_id = $question_data['question_id'];
+                            $marks       = $question_data['marks'];
+                            
+                            $question_info = Question::read($question_id);                                                        
+                            echo Display::div($question_info->question, array('id'=>'question_title','class'=>'sectiontitle'));                            
+                            echo Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score'));
+                        }
+                    }                    
+                    $score =  show_score($last_attempt_info['exe_result'],$last_attempt_info['exe_weighting']);
+                    echo Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
+                } else {
+                    Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $objExercise->selectAttempts()), false);	
+                }
+            } else {
+                Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $objExercise->selectAttempts()), false);
+            }
             
             if ($origin != 'learnpath')
                 Display :: display_footer();

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

@@ -1382,7 +1382,7 @@ class Exercise {
 		$this->active = $status;
 	}
 	
-	public function get_stat_track_exercise_info($lp_id = 0, $lp_item_id = 0, $lp_item_view_id = 0) {		
+	public function get_stat_track_exercise_info($lp_id = 0, $lp_item_id = 0, $lp_item_view_id = 0, $status = 'incomplete') {		
 		$track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
 		if (empty($lp_id)) {
 			$lp_id = 0;
@@ -1392,11 +1392,11 @@ class Exercise {
 		}	
         if (empty($lp_item_view_id)) {
             $lp_item_view_id = 0;
-        }   	
+        }   
 		$condition = ' WHERE exe_exo_id 	= ' . "'" . $this->id . "'" .' AND 
 					   exe_user_id 			= ' . "'" . api_get_user_id() . "'" . ' AND 
 					   exe_cours_id 		= ' . "'" . api_get_course_id() . "'" . ' AND 
-					   status 				= ' . "'incomplete'" . ' AND 
+					   status 				= ' . "'" . Database::escape_string($status). "'" . ' AND 
 					   orig_lp_id 			= ' . "'" . $lp_id . "'" . ' AND 
 					   orig_lp_item_id 		= ' . "'" . $lp_item_id . "'" . ' AND
                        orig_lp_item_view_id = ' . "'" . $lp_item_view_id . "'" . ' AND

+ 67 - 70
main/exercice/exercise.lib.php

@@ -739,6 +739,13 @@ 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.'  ';
+    }
+    
     if ($is_allowedToEdit || $is_tutor) {
         $user_id_and = '';
         if (!empty ($_POST['filter_by_user'])) {
@@ -751,11 +758,7 @@ 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 (!empty($exercise_id)) {
-            $exercise_where = ' AND te.exe_exo_id = '.$exercise_id.'  ';
-        }
+
 
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
 
@@ -791,56 +794,57 @@ 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='" . 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 ";
+            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 '',exe_name, exe_result , exe_weighting, exe_date
                 FROM $TBL_TRACK_HOTPOTATOES
                 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);
     $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;
+    if (Database::num_rows($resx) > 0) {
+        if ($is_allowedToEdit || $is_tutor) {
+            while ($rowx = Database::fetch_array($resx,'ASSOC')) {
+                $results[] = $rowx;
             }
-            $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;
+            //Special modification to corretly show the pagination
+            if (is_array($results)) {          
+                if ($_GET['gradebook'] == 'view') {
+                    $filter_by_no_revised = true;
+                    $from_gradebook = true;
                 }
-                if ($filter_by_revised && !$revised) {
-                    continue;
+                $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++;           
                 }
-                $count++;           
-            }
+            }        
+        } else {            
+        	$rowx = Database::fetch_array($resx,'ASSOC');
+            $count = $rowx['count'];
         }
     }
     if (Database::num_rows($hpres) > 0) {
@@ -851,8 +855,6 @@ function get_count_exam_results($exercise_id = null) {
 }
 
 
-
-
 /**
  * Gets the exam'data results
  * @todo this function should be moved in a library  + no global calls 
@@ -863,6 +865,10 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     $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.'  ';
+    }    
     
     if ($is_allowedToEdit || $is_tutor) {
         $user_id_and = '';
@@ -870,19 +876,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             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']) . "' ";
+                $user_id_and = " AND user_id = '" . intval($_POST['filter_by_user']) . "' ";
             }
         }
         
         if ($_GET['gradebook'] == 'view') {
             $exercise_where_query = ' te.exe_exo_id =ce.id AND ';
         }
-        
-        $exercise_where = '';
-        if (!empty($exercise_id)) {
-            $exercise_where .= ' AND te.exe_exo_id = '.$exercise_id.'  ';
-        }
-        
 
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
 
@@ -921,7 +921,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                             "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='" . 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 ";
+              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 '', exe_name, exe_result , exe_weighting, exe_date
                   FROM $TBL_TRACK_HOTPOTATOES
@@ -929,7 +929,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                   ORDER BY exe_cours_id ASC, exe_date DESC";
     }
 
-
     $column             = intval($column);
     $from               = intval($from);
     $number_of_items    = intval($number_of_items);
@@ -945,14 +944,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     
     $hpresults = getManyResultsXCol($hpsql, 5);
 
-    $has_test_results = false;
     $list_info = array();
 
     // Print test results.
     $lang_nostartdate = get_lang('NoStartDate') . ' / ';    
     
     if (is_array($results)) {
-        $has_test_results = true;
         $users_array_id = array ();
         if ($_GET['gradebook'] == 'view') {
             $filter_by_no_revised = true;
@@ -1087,23 +1084,23 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     
     
     // Print HotPotatoes test results.
-        if (is_array($hpresults)) {
-            $has_test_results = true;
-            for ($i = 0; $i < sizeof($hpresults); $i++) {
-                $hp_title = GetQuizName($hpresults[$i][1], $documentPath);
-                if ($hp_title == '') {
-                    $hp_title = basename($hpresults[$i][1]);
-                }
-                //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
-                $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get());
-                $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')';
-                if ($is_allowedToEdit) {
-                    $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-');
-                } else {
-                    $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
-                }
+    if (is_array($hpresults)) {
+        
+        for ($i = 0; $i < sizeof($hpresults); $i++) {
+            $hp_title = GetQuizName($hpresults[$i][1], $documentPath);
+            if ($hp_title == '') {
+                $hp_title = basename($hpresults[$i][1]);
+            }
+            //$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
+            $hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get());
+            $hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')';
+            if ($is_allowedToEdit) {
+                $list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-');
+            } else {
+                $list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
             }
         }
+    }
     return $list_info;
 }
 

+ 4 - 1
main/inc/lib/display.lib.php

@@ -713,6 +713,9 @@ class Display {
         return self::tag('a', $name, $extra_attributes);    	
     }
     
+    /**
+     * Creates a div tag
+     */
     public static function div($content, $extra_attributes = array()) {      
         return self::tag('div', $content, $extra_attributes);        
     }
@@ -721,7 +724,7 @@ class Display {
      * Displays an HTML input tag
      * 
      */
-    public static function input($type, $name,  $value, $extra_attributes = array()) {
+    public static function input($type, $name, $value, $extra_attributes = array()) {
     	 if (!empty($type)) {
             $extra_attributes['type']= $type;
          }

+ 17 - 9
main/inc/lib/events.lib.inc.php

@@ -589,6 +589,9 @@ function event_system($event_type, $event_value_type, $event_value, $timestamp =
 	return true;
 }
 
+/**
+ * Gets the last attempt of an exercise based in the exe_id
+ */
 function get_last_attempt_date_of_exercise($exe_id) {
 	$exe_id = intval($exe_id);
 	$track_attempts 		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@@ -603,7 +606,12 @@ function get_last_attempt_date_of_exercise($exe_id) {
 }
 
 /**
- * Gets how many attempts exists
+ * Gets how many attempts exists by user, exercise
+ * @param   int user id
+ * @param   int exercise id
+ * @param   int lp id
+ * @param   int lp item id
+ * @param   int lp item view id
  */
 function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id,$lp_item_view_id) {
 	$stat_table 	= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
@@ -688,12 +696,12 @@ function get_all_exercise_results($exercise_id, $course_code, $session_id = 0) {
 	
 	$sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = ''  AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id  AND orig_lp_id =0 AND orig_lp_item_id = 0 ORDER BY exe_id";
 	
-	$res = api_sql_query($sql,__FILE__,__LINE__);
+	$res = Database::query($sql);
 	$list = array();	
 	while($row = Database::fetch_array($res,'ASSOC')) {		
 		$list[$row['exe_id']] = $row;		
 		$sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}";
-		$res_question = api_sql_query($sql,__FILE__,__LINE__);
+		$res_question = Database::query($sql);
 		while($row_q = Database::fetch_array($res_question,'ASSOC')) {
 			$list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
 		}		
@@ -720,12 +728,12 @@ function get_all_exercise_results_by_user($user_id, $exercise_id, $course_code,
     
     $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = ''  AND exe_cours_id = '$course_code' AND exe_exo_id = $exercise_id AND session_id = $session_id AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND exe_user_id = $user_id  ORDER by exe_id";    
     
-    $res = api_sql_query($sql,__FILE__,__LINE__);
+    $res = Database::query($sql);
     $list = array();    
     while($row = Database::fetch_array($res,'ASSOC')) {     
         $list[$row['exe_id']] = $row;       
         $sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}";
-        $res_question = api_sql_query($sql,__FILE__,__LINE__);
+        $res_question = Database::query($sql);
         while($row_q = Database::fetch_array($res_question,'ASSOC')) {
             $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
         }       
@@ -746,12 +754,12 @@ function get_all_exercise_event_from_lp($exercise_id, $course_code, $session_id
   
     $sql = "SELECT * FROM $TABLETRACK_EXERCICES WHERE status = ''  AND exe_cours_id = '$course_code' AND exe_exo_id = '$exercise_id' AND session_id = $session_id AND orig_lp_id !=0 AND orig_lp_item_id != 0";
     
-    $res = api_sql_query($sql,__FILE__,__LINE__);
+    $res = Database::query($sql);
     $list = array();    
     while($row = Database::fetch_array($res,'ASSOC')) {     
         $list[$row['exe_id']] = $row;       
         $sql = "SELECT * FROM $TBL_TRACK_ATTEMPT WHERE exe_id = {$row['exe_id']}";
-        $res_question = api_sql_query($sql,__FILE__,__LINE__);
+        $res_question = Database::query($sql);
         while($row_q = Database::fetch_array($res_question,'ASSOC')) {
             $list[$row['exe_id']]['question_list'][$row_q['question_id']] = $row_q;
         }       
@@ -770,7 +778,7 @@ function get_all_exercise_event_from_lp($exercise_id, $course_db, $session_id )
 	$sql = "SELECT  title, user_id, score , iv.max_score, status, session_id 
 			FROM $lp_item_table as i INNER JOIN $lp_item_view_table iv ON (i.id = iv.lp_item_id ) INNER JOIN $lp_view_table v ON iv.lp_view_id = v.id 
 			WHERE path = $exercise_id AND status ='completed' AND session_id = $session_id";
-	$res = api_sql_query($sql,__FILE__,__LINE__);
+	$res = Database::query($sql);
 	$list = array();	
 	
 	while($row = Database::fetch_array($res,'ASSOC')) {		
@@ -786,7 +794,7 @@ function get_all_exercises_from_lp($lp_id, $course_db) {
 	$lp_item_table = Database  :: get_course_table(TABLE_LP_ITEM,$course_db);
 	$lp_id = intval($lp_id);
 	$sql = "SELECT * FROM $lp_item_table WHERE lp_id = '".$lp_id."'  ORDER BY parent_item_id, display_order";
-	$res = api_sql_query($sql, __FILE__, __LINE__);
+	$res = Database::query($sql);
 	$my_exercise_list = array();	
 	while($row = Database::fetch_array($res,'ASSOC')) {
 		if ($row['item_type'] == 'quiz') {