Jelajahi Sumber

Results by exercise see#2539 fixing sql errors

Julio Montoya 14 tahun lalu
induk
melakukan
edab380bee

+ 12 - 6
main/exercice/exercice.php

@@ -398,13 +398,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']);
+				$export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exercise_id']);
 				exit;
 				break;
 			case 'csv' :
 			default :
 				$export = new ExerciseResult();
-				$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter']);
+				$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter'],$_POST['exercise_id']);
 				exit;
 				break;
 		}
@@ -413,9 +413,9 @@ if (!empty ($_POST['export_report']) && $_POST['export_report'] == 'export_repor
 	}
 }
 
-$htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/cupertino/jquery-ui-1.8.7.custom.css" type="text/css">';
+$htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/smoothness/jquery-ui-1.8.7.custom.css" type="text/css">';
 $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-1.4.4.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
-$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/cupertino/jquery-ui-1.8.7.custom.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
+$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery-ui/smoothness/jquery-ui-1.8.7.custom.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
 
 
 if ($origin != 'learnpath') {
@@ -615,7 +615,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
 		echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('hotpotatoes_s.png', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
 		// link to import qti2 ...
 		echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_db.png', get_lang('ImportQtiQuiz')) . get_lang('ImportQtiQuiz') . '</a>';
-		//echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
+		echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result&exercise_id='.$row['id'].'">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
 	}
 
 	// the actions for the statistics
@@ -635,6 +635,8 @@ 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']).'">';
+            
             
             if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
                 $filter = 1;
@@ -647,6 +649,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 '</form>';
 		}
 	}
@@ -932,8 +935,11 @@ if ($show == 'test') {
 
 // if tracking is enabled
 if ($_configuration['tracking_enabled'] && ($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']);
+    if (!empty($exercise_id))
+        $parameters['exercise_id'] = $exercise_id;
+                        
 	$table = new SortableTable('quiz_results', 'get_count_exam_results', 'get_exam_results_data');
 	$table->set_additional_parameters($parameters);
     $secuence = 2;

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

@@ -790,7 +790,7 @@ function get_count_exam_results($exercise_id = null) {
 
         $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 = '" . Database :: escape_string($_cid) . "' $user_id_and  $exercise_where
                     ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 
 
@@ -871,7 +871,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
 
         $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 = '" . Database :: escape_string($_cid)."' $user_id_and $exercise_where 
                     ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 
 
@@ -933,7 +933,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             $filter_by_no_revised = true;
             $from_gradebook = true;
         }
-        $sizeof = sizeof($results);
+        $sizeof = count($results);
 
         $user_list_id = array ();
         $user_last_name = '';
@@ -945,8 +945,7 @@ 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) {
@@ -964,7 +963,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                 }
                 $users_array_id[] = $results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'];
             }
-
+                        
             $user_first_name = $results[$i]['col0'];
             $user_last_name = $results[$i]['col1'];
             $user_list_id[] = $results[$i]['excruid'];
@@ -1052,6 +1051,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);
                 } else {
                     $list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
@@ -1059,6 +1059,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             }
         }
     }
+    
+    
     // Print HotPotatoes test results.
         if (is_array($hpresults)) {
             $has_test_results = true;
@@ -1094,7 +1096,7 @@ function show_score($score, $weight, $show_porcentage = true) {
         $max_note =  api_get_setting('exercise_max_score');
         $min_note =  api_get_setting('exercise_min_score');
         if ($max_note != '' && $min_note != '') {
-           if (!empty($weight)) {
+           if (!empty($weight) && intval($weight) != 0) {
     	       $score        = $min_note + ($max_note - $min_note) * $score /$weight;
            } else {
            	 $score          = $min_note;

+ 12 - 6
main/exercice/exercise_result.class.php

@@ -90,7 +90,7 @@ class ExerciseResult
 	 * @param	string		The document path (for HotPotatoes retrieval)
 	 * @param	integer		User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
 	 */
-	function _getExercisesReporting($document_path,$user_id=null,$filter=0) {
+	function _getExercisesReporting($document_path,$user_id=null,$filter=0, $exercise_id = 0) {
 		$return = array();
     	$TBL_EXERCISES          = Database::get_course_table(TABLE_QUIZ_TEST);
     	$TBL_EXERCISE_QUESTION  = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
@@ -107,6 +107,12 @@ class ExerciseResult
     	$cid = api_get_course_id();
     	$user_id = intval($user_id);
     	$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
+        $exercise_id = intval($exercise_id);
+        
+        if (!empty($exercise_id)) {
+            $session_id_and .= " AND exe_exo_id = $exercise_id ";
+        }
+        
 		if (empty($user_id)) {			
 			 $sql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", 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, exe_user_id as excruid,te.exe_duration as exduration
@@ -115,7 +121,7 @@ class ExerciseResult
         
             $hpsql="SELECT ".(api_is_western_name_order() ? "firstname as userpart1, lastname userpart2" : "lastname as userpart1, firstname as userpart2").", 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 = '" . Database :: escape_string($cid) . "' 
                     ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 
 
@@ -234,10 +240,10 @@ class ExerciseResult
 	 * @param	boolean		Whether to include user fields or not
 	 * @return	boolean		False on error
 	 */
-	public function exportCompleteReportCSV($document_path='',$user_id=null, $export_user_fields = array(), $export_filter = 0)
+	public function exportCompleteReportCSV($document_path='',$user_id=null, $export_user_fields = array(), $export_filter = 0, $exercise_id = 0)
 	{
 		global $charset;
-		$this->_getExercisesReporting($document_path,$user_id,$export_filter);
+		$this->_getExercisesReporting($document_path,$user_id,$export_filter, $exercise_id);
 		$filename = 'exercise_results_'.date('YmdGis').'.csv';
 		if(!empty($user_id)) {
 			$filename = 'exercise_results_user_'.$user_id.'_'.date('YmdGis').'.csv';
@@ -314,9 +320,9 @@ class ExerciseResult
 	 * Exports the complete report as an XLS file
 	 * @return	boolean		False on error
 	 */
-	public function exportCompleteReportXLS($document_path='',$user_id=null, $export_user_fields=array(), $export_filter = 0) {
+	public function exportCompleteReportXLS($document_path='',$user_id=null, $export_user_fields=array(), $export_filter = 0, $exercise_id=0) {
 		global $charset;
-		$this->_getExercisesReporting($document_path,$user_id,$export_filter);
+		$this->_getExercisesReporting($document_path,$user_id,$export_filter, $exercise_id);
 		$filename = 'exercise_results_'.date('YmdGis').'.xls';
 		if(!empty($user_id))
 		{