Julio Montoya 13 жил өмнө
parent
commit
17b948e574

+ 0 - 3
main/admin/session_list.php

@@ -152,10 +152,7 @@ $(function() {
     jQuery("#sessions").jqGrid('filterToolbar',options);    
     var sgrid = $("#sessions")[0];
     sgrid.triggerToolbar();
-    
-     
 });
-
 </script>
 <div class="actions">
 <?php 

+ 109 - 134
main/exercice/exercise.lib.php

@@ -763,20 +763,26 @@ function get_count_exam_results() {
  * Gets the exam'data results
  * @todo this function should be moved in a library  + no global calls 
  */
-function get_exam_results_data($from, $number_of_items, $column, $direction) {
+function get_exam_results_data($from, $number_of_items, $column, $direction, $extra_where_conditions = null) {
     //@todo replace all this globals
-    global  $is_allowedToEdit, $is_tutor, $filter_by_not_revised, $filter_by_revised, $documentPath, $filter, $filterByGroup;
+    global $documentPath, $filter, $filterByGroup;
+	
+	if (empty($extra_where_conditions)) {
+		$extra_where_conditions = "1 = 1 ";
+	}
     
-    $is_tutor                   = api_is_allowed_to_edit(true);
-    $is_tutor_course            = api_is_course_tutor();
+   	$is_allowedToEdit           = api_is_allowed_to_edit(null,true);
+	$is_tutor                   = api_is_allowed_to_edit(true);
     
     $TBL_USER                   = Database :: get_main_table(TABLE_MAIN_USER);    
     $TBL_EXERCICES              = Database :: get_course_table(TABLE_QUIZ_TEST);    
+	$TBL_GROUP_REL_USER         = Database :: get_course_table(TABLE_GROUP_USER);
+	
     $TBL_TRACK_EXERCICES        = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
     $TBL_TRACK_HOTPOTATOES      = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
     $TBL_TRACK_ATTEMPT          = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);    
-    $TBL_GROUP_REL_USER         = Database :: get_course_table(TABLE_GROUP_USER);
+    
     
     $session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
     
@@ -793,7 +799,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     }  
     
     if ($is_allowedToEdit || $is_tutor) {
-        
+        /*
         $user_id_and = '';
         if (!empty ($_REQUEST['filter_by_user'])) {
             if ($_REQUEST['filter_by_user'] == 'all') {
@@ -801,7 +807,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             } else {
                 $user_id_and = " AND user_id = '" . intval($_REQUEST['filter_by_user']) . "' ";
             }
-        }
+        }*/
         
           
         if ($_GET['gradebook'] == 'view') {
@@ -816,29 +822,9 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
 		
         //@todo fix to work with COURSE_RELATION_TYPE_RRHH in both queries
 
-        // 
-        // 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;    
@@ -868,36 +854,38 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
 		        break;
 		}
 		
-        $first_and_last_name = api_is_western_name_order() ? "firstname as col0, lastname col1" : "lastname as col0, firstname as col1";
+        $first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname";
          
-        // sql for chamilo-type tests for teacher / tutor view
-        
-        $sql = "SELECT
+        // sql for chamilo-type tests for teacher / tutor view		
+		$sql_inner_join_tbl_track_exercices = "(SELECT ttte.*, if(tr.exe_id,1, 0) as revised FROM $TBL_TRACK_EXERCICES  ttte LEFT JOIN $TBL_TRACK_ATTEMPT_RECORDING tr ON (ttte.exe_id = tr.exe_id) )";
+		        
+        $sql = "SELECT DISTINCT
                     user_id, 
                     $first_and_last_name, 
-                    ce.title as col3, 
-                    username as col2,
-                    te.exe_result as exresult , 
-                    te.exe_weighting as exweight,
-                    te.exe_date as exdate, 
-                    te.exe_id as exid, 
+                    ce.title, 
+                    username,
+                    te.exe_result, 
+                    te.exe_weighting,
+                    te.exe_date, 
+                    te.exe_id, 
                     email as exemail, 
-                    te.start_date as col6, 
-                    steps_counter as exstep, 
-                    exe_user_id as excruid,
-                    te.exe_duration as exduration, 
-                    propagate_neg
+                    te.start_date, 
+                    steps_counter, 
+                    exe_user_id,
+                    te.exe_duration, 
+                    propagate_neg,
+					revised
                 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 
+                WHERE $extra_where_conditions AND
                     te.status != 'incomplete' 
-                    AND te.exe_cours_id='" . api_get_course_id() . "'  $user_id_and  $session_id_and 
+                    AND te.exe_cours_id='" . api_get_course_id() . "'  $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()."
+                    AND ce.c_id=".api_get_course_int_id()."					
                     $exercise_where ";
 
          // sql for hotpotatoes tests for teacher / tutor view
@@ -918,46 +906,35 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                     AND tth.exe_cours_id = '" . api_get_course_id()."'  
                     $hotpotatoe_where 
                     $sqlWhereOption
+					AND $where_condition
                 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 
-                    ce.title as col0, 
-                    ce.title as col1, 
-                    te.exe_duration as exduration, 
+        
+        $sql = "SELECT DISTINCT                           
+                    te.exe_duration, 
+					te.start_date, 
                     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, 
+                    te.exe_result, 
+                    te.exe_weighting, 
+                    te.exe_date, 
+                    te.exe_id, 
+                    email as exemail,                    
+                    steps_counter, 
+                    exe_user_id,  
+                    ce.results_disabled, 
                     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 
+                WHERE $extra_where_conditions AND
                     te.status != 'incomplete' 
                     AND te.exe_cours_id='" . api_get_course_id() . "'  
-                    $user_id_and $session_id_and 
+                    AND te.exe_user_id = ".api_get_user_id() . " $session_id_and 
                     AND ce.active <>-1 
                     AND orig_lp_id = 0 
                     AND orig_lp_item_id = 0  
@@ -968,7 +945,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                   FROM $TBL_TRACK_HOTPOTATOES
                   WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' $hotpotatoe_where
                   ORDER BY exe_cours_id ASC, exe_date DESC";
-    }   
+    }
     
     $teacher_list = CourseManager::get_teacher_list_from_course_code(api_get_course_id());
     $teacher_id_list = array();
@@ -977,12 +954,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
     }    
     
     if (empty($hotpotatoe_where)) {
-        $column             = intval($column);
+        $column             = empty($column) ? : Database::escape_string($column);
         $from               = intval($from);
         $number_of_items    = intval($number_of_items);
-        $sql               .= " ORDER BY col$column $direction ";
+        $sql               .= " ORDER BY $column $direction ";
         $sql               .= " LIMIT $from, $number_of_items";
-        
+			
+		//var_dump($sql);
         $results = array();
         
         $resx = Database::query($sql);
@@ -996,6 +974,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
         $lang_nostartdate = get_lang('NoStartDate') . ' / ';    
         
         if (is_array($results)) {
+			
             $users_array_id = array();
             if ($_GET['gradebook'] == 'view') {
                 $filter_by_no_revised = true;
@@ -1003,69 +982,62 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
             }
             $sizeof = count($results);
     
-            $user_list_id = array ();
-            $user_last_name = '';
-            $user_first_name = '';
+            $user_list_id = array ();            
             $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]['exid']) .' LIMIT 1';            
+                $revised = $results[$i]['revised'];
+				
+                /*$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 ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
-                    if (in_array($results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'], $users_array_id)) {
+                    if (in_array($results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'], $users_array_id)) {
                         continue;
                     }
-                    $users_array_id[] = $results[$i]['col2'] . $results[$i]['col0'] . $results[$i]['col1'];
+                    $users_array_id[] = $results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'];
                 }
-                if ($is_allowedToEdit || $is_tutor) {      
-                    $user_first_name = $results[$i]['col0'];
-                    $user_last_name = $results[$i]['col1'];
-                    $user_login = $results[$i]['col2'];
-                    $user = $results[$i]['col0'] . $results[$i]['col1'];
-                    $test = $results[$i]['col3'];                    
+                if ($is_allowedToEdit || $is_tutor) {                    
+                    $user = $results[$i]['firstname'] . $results[$i]['lastname'];
+                    //$test = $results[$i]['col3'];                    
                     $user_groups = displayGroupsForUser('<br/>', $results[$i]['user_id']);
-                } else {
-                    $user_first_name = $results[$i]['firstname'];
-                    $user_last_name = $results[$i]['lastname'];
+                } else {                    
                     $user = $results[$i]['firstname'] . $results[$i]['lastname'];
-                    $test = $results[$i]['col0'];                
+                    //$test = $results[$i]['col0'];                
                 }
-                $user_list_id[] = $results[$i]['excruid'];
-                $id = $results[$i]['exid'];   
+                $user_list_id[] = $results[$i]['exe_user_id'];
+                $id = $results[$i]['exe_id'];   
                
-                $quiz_name_list = $test;
-                $dt = api_convert_and_format_date($results[$i]['exweight']);
-                $res = $results[$i]['exresult'];
+                //$quiz_name_list = $test;
+                $dt = api_convert_and_format_date($results[$i]['exe_weighting']);
+                $res = $results[$i]['exe_result'];	
     
-                $duration = intval($results[$i]['exduration']);
                 
                 // we filter the results if we have the permission to
-                if (isset ($results[$i]['exdisabled']))
-                    $result_disabled = intval($results[$i]['exdisabled']);
+                if (isset ($results[$i]['results_disabled']))
+                    $result_disabled = intval($results[$i]['results_disabled']);
                 else
                     $result_disabled = 0;
     
                 if ($result_disabled == 0) {
                     $add_start_date = $lang_nostartdate;
     
-                    if ($is_allowedToEdit || $is_tutor) {
-                        //var_dump($results[$i]);
-                        $user = $results[$i]['col0'] . $results[$i]['col1'];
-                        $start_date = $results[$i]['col6'];
+                    if ($is_allowedToEdit || $is_tutor) {                        
+                        $user = $results[$i]['firstname'] . $results[$i]['lastname'];
+                        $start_date = $results[$i]['start_date'];
                     } else {
-                        $start_date = $results[$i]['col2'];
+                        $start_date = $results[$i]['start_date'];
                     }
                     
                     if ($start_date != "0000-00-00 00:00:00") {
                         $start_date_timestamp   = api_strtotime($start_date);
-                        $exe_date_timestamp     = api_strtotime($results[$i]['exdate']);                                                
+                        $exe_date_timestamp     = api_strtotime($results[$i]['exe_date']);                                                
     
                         $my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
                         //var_dump($start_date .' - '.$results[$i]['exdate'].' - '.$my_duration);
@@ -1074,9 +1046,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                         } else {
                             $duration_list =  $my_duration. ' ' . get_lang('MinMinutes');
                         }
-                        if ($results[$i]['exstep'] > 1) {
-                            //echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
-                            $duration_list = ' ( ' . $results[$i]['exstep'] . ' ' . get_lang('Steps') . ' )';
+                        if ($results[$i]['exstep'] > 1) {                            
+                            $duration_list = ' ( ' . $results[$i]['steps_counter'] . ' ' . get_lang('Steps') . ' )';
                         }
                         //$add_start_date = api_convert_and_format_date($start_date) . ' / ';
                     } else {
@@ -1084,28 +1055,24 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                         //echo get_lang('NoLogOfDuration');
                     }
                     // Date conversion
-                    if ($is_allowedToEdit || $is_tutor) {                        
-                        $date_list = api_get_local_time($results[$i]['col6']). ' / ' . api_get_local_time($results[$i]['exdate']);
-                    } else {                        
-                        $date_list = api_get_local_time($results[$i]['col2']). ' / ' . api_get_local_time($results[$i]['exdate']);
-                    }
+					
+					$date_list = api_get_local_time($results[$i]['start_date']). ' / ' . api_get_local_time($results[$i]['exe_date']);
+                    
                     // there are already a duration test period calculated??
                     //echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
     
                     // if the float look like 10.00 we show only 10
     
-                    $my_res     = $results[$i]['exresult'];
-                    $my_total   = $results[$i]['exweight'];
+                    $my_res     = $results[$i]['exe_result'];
+                    $my_total   = $results[$i]['exe_weighting'];
                     if (!$results[$i]['propagate_neg'] && $my_res < 0) {
                         $my_res = 0;
                     }
-                    $ex = show_score($my_res, $my_total);
+                    $score = show_score($my_res, $my_total);
                     
-                    $result_list = $ex;
-    
                     $html_link = '';
                     if ($is_allowedToEdit || $is_tutor) {
-                    	if (in_array($results[$i]['excruid'], $teacher_id_list)) {
+                    	if (in_array($results[$i]['exe_user_id'], $teacher_id_list)) {
                     		$html_link.= Display::return_icon('teachers.gif', get_lang('Teacher'));
                     	}
                         if ($revised) {
@@ -1126,23 +1093,30 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                             $html_link.='&nbsp;';
                         }
                     } else {
-                    	$attempt_url 	= api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&id='.$results[$i]['exid'].'&id_session='.api_get_session_id().'&height=500&width=750';
+                    	$attempt_url 	= api_get_path(WEB_CODE_PATH).'exercice/result.php?'.api_get_cidreq().'&id='.$results[$i]['exe_id'].'&id_session='.api_get_session_id().'&height=500&width=750';
                     	$attempt_link 	= Display::url(get_lang('Show'), $attempt_url, array('class'=>'thickbox a_button white small'))."&nbsp;&nbsp;&nbsp;";
                     	
                     	$html_link.= $attempt_link;
                     	
-                        if ($revised) {
-                        	$html_link.= Display::span(get_lang('Validated'), array('class'=>'label_tag success'));                            
-                        } else {
-                        	$html_link.= Display::span(get_lang('NotValidated'), array('class'=>'label_tag notice'));                            
-                        }
+                       
                     }
                     $more_details_list = $html_link;
-                    if ($is_allowedToEdit || $is_tutor) {
-                        $revised = $revised ? get_lang('Revised') : get_lang('NotRevised');
-                        $list_info[] = array($user_first_name,$user_last_name,$user_login,$user_groups,$quiz_name_list,$duration_list,$date_list,$result_list, $revised, $more_details_list);
+                    if ($is_allowedToEdit || $is_tutor) {                        
+						if ($revised) {
+                        	$revised = Display::span(get_lang('Validated'), array('class'=>'label_tag success'));                            
+                        } else {
+                        	$revised = Display::span(get_lang('NotValidated'), array('class'=>'label_tag notice'));                            
+                        }
+						
+                        //$list_info[] = array($user_first_name,$user_last_name,$user_login,$user_groups,$quiz_name_list,$duration_list,$date_list,$result_list, $revised, $more_details_list);
+						$results[$i]['status'] =  $revised;
+						$results[$i]['score'] =  $score;
+						$results[$i]['actions'] =  $more_details_list;
+						$list_info[] = $results[$i];
                     } else {
-                        $list_info[] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
+                        $results[$i]['status'] =  $revised;
+						$results[$i]['score'] =  $score;							
+						$list_info[] = $results[$i];
                     }
                 }
             }
@@ -1170,7 +1144,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction) {
                 }
             }
         }
-    }
+    }	
+	//var_dump($list_info);
     return $list_info;
 }
 

+ 116 - 4
main/exercice/exercise_report.php

@@ -13,7 +13,7 @@
  * Code
  */
 // name of the language file that needs to be included
-$language_file = array('exercice','tracking');
+$language_file = array('exercice');
 
 // including the global library
 require_once '../inc/global.inc.php';
@@ -22,7 +22,7 @@ require_once '../gradebook/lib/be.inc.php';
 // Setting the tabs
 $this_section = SECTION_COURSES;
 
-$htmlHeadXtra[] = api_get_jquery_ui_js();
+$htmlHeadXtra[] = api_get_jquery_ui_js(true);
 
 // Access control
 api_protect_course_script(true);
@@ -316,8 +316,7 @@ if (api_is_allowed_to_edit(null,true)) {
         $actions .= "&nbsp;&nbsp;";
         $actions .= Display::return_icon('group.gif', get_lang("FilterByGroup"));
         $actions .= displayGroupMenu("groupFilter", $filterByGroup, "doFilterByGroup()")."&nbsp;";
-    }
-    
+    }    
 }
 
 $parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
@@ -400,6 +399,9 @@ $extra =  '<script type="text/javascript">
     });
     </script>';
 
+
+
+
 $extra .= '<div id="dialog-confirm" title="'.get_lang("ConfirmYourChoice").'">';
 $extra .= Display::tag('p', Display::input('radio', 'export_format', 'csv', array('checked'=>'1', 'id'=>'export_format_csv_label')). Display::tag('label', get_lang('ExportAsCSV'), array('for'=>'export_format_csv_label')));
 $extra .= Display::tag('p', Display::input('radio', 'export_format', 'xls', array('id'=>'export_format_xls_label')). Display::tag('label', get_lang('ExportAsXLS'), array('for'=>'export_format_xls_label')));   
@@ -416,4 +418,114 @@ $tpl->assign('content', $content);
 $tpl->display_one_col_template();
 */
 
+
+
+
+$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_results';
+
+//$activeurl = '?sidx=session_active';
+//
+if ($is_allowedToEdit || $is_tutor) {
+	
+	//The order is important you need to check the the $column variable in the model.ajax.php file 
+	$columns        = array(get_lang('FirstName'), get_lang('LastName'), get_lang('LoginName'), 
+                        get_lang('Group'), get_lang('Duration'), get_lang('StartDate'),  get_lang('EndDate'), get_lang('Score'), get_lang('Status'), get_lang('Actions'));
+
+//Column config
+	$column_model   = array(
+                        array('name'=>'firstname',      'index'=>'firstname',		'width'=>'50',   'align'=>'left', 'search' => 'true'),                        
+                        array('name'=>'lastname',		'index'=>'lastname',		'width'=>'50',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'login',			'index'=>'username',		'width'=>'40',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'group',			'index'=>'s',				'width'=>'40',   'align'=>'left', 'search' => 'false'),
+                        array('name'=>'duration',       'index'=>'exe_duration',	'width'=>'30',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'start_date',		'index'=>'start_date',		'width'=>'60',   'align'=>'left', 'search' => 'true'),                        
+						array('name'=>'exe_date',		'index'=>'exe_date',		'width'=>'60',   'align'=>'left', 'search' => 'true'),                        
+						array('name'=>'score',			'index'=>'exe_result',	    'width'=>'50',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'status',         'index'=>'revised',			'width'=>'40',   'align'=>'left', 'search' => 'true', 'stype'=>'select',					          
+                              //for the bottom bar
+                              'searchoptions' => array(                                                
+                                                'defaultValue'  => '1', 
+                                                'value'         => ':'.get_lang('All').';1:'.get_lang('Revised').';0:'.get_lang('NotRevised')),
+                             
+                              //for the top bar                              
+                              'editoptions' => array('value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive'))),
+//issue fixed in jqgrid                         
+//                      array('name'=>'actions',        'index'=>'actions',         'width'=>'100',  'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false')
+						array('name'=>'actions',        'index'=>'actions',         'width'=>'60',  'align'=>'left', 'search' => 'false')
+                       );            
+} else {
+	
+	//The order is important you need to check the the $column variable in the model.ajax.php file 
+	$columns        = array(get_lang('Duration'), get_lang('StartDate'),  get_lang('EndDate'), get_lang('Score'), get_lang('Status'));
+	
+	//Column config
+	$column_model   = array(                        
+                        array('name'=>'duration',       'index'=>'exe_duration',	'width'=>'40',   'align'=>'left', 'search' => 'true'),
+                        array('name'=>'start_date',		'index'=>'start_date',		'width'=>'80',   'align'=>'left', 'search' => 'true'),                        
+						array('name'=>'exe_date',		'index'=>'exe_date',		'width'=>'80',   'align'=>'left', 'search' => 'true'),                        
+						array('name'=>'score',			'index'=>'exe_result',		'width'=>'40',   'align'=>'left', 'search' => 'true'),	
+                        array('name'=>'status',         'index'=>'revised',			'width'=>'40',   'align'=>'left', 'search' => 'false')
+						
+                       );   	
+}
+//Autowidth             
+$extra_params['autowidth'] = 'true';
+
+//height auto 
+$extra_params['height'] = 'auto';
+$extra_params['excel'] = 'excel';
+
+$extra_params['rowList'] = array(10, 20 ,30);
+
+?>
+<script>
+$(function() {
+    <?php 
+        echo Display::grid_js('results', $url,$columns,$column_model,$extra_params, array(), $action_links, true);      
+    ?>
+    
+    //setSearchSelect("status");    
+    
+    $("#results").jqGrid('navGrid','#results_pager', {edit:false,add:false,del:false},
+        {height:280,reloadAfterSubmit:false}, // edit options 
+        {height:280,reloadAfterSubmit:false}, // add options 
+        {reloadAfterSubmit:false}, // del options 
+        {width:500} // search options
+    );
+    /*
+    // add custom button to export the data to excel
+    jQuery("#sessions").jqGrid('navButtonAdd','#sessions_pager',{
+           caption:"", 
+           onClickButton : function () { 
+               jQuery("#sessions").excelExport();
+           } 
+    });
+    
+    jQuery('#sessions').jqGrid('navButtonAdd','#sessions_pager',{id:'pager_csv',caption:'',title:'Export To CSV',onClickButton : function(e)
+    {
+        try {
+            jQuery("#sessions").jqGrid('excelExport',{tag:'csv', url:'grid.php'});
+        } catch (e) {
+            window.location= 'grid.php?oper=csv';
+        }
+    },buttonicon:'ui-icon-document'})
+    */
+   
+    
+    //Adding search options
+    var options = {
+        'stringResult': true,
+        'autosearch' : true,
+        'searchOnEnter':false,        
+    }
+    jQuery("#results").jqGrid('filterToolbar',options);    
+    var sgrid = $("#results")[0];
+    sgrid.triggerToolbar();
+});
+</script>
+<?php
+
+echo Display::grid_html('results');
+
+
 Display :: display_footer();

+ 0 - 1
main/exercice/exercise_submit.php

@@ -31,7 +31,6 @@ require_once 'exercise.class.php';
 require_once 'question.class.php';
 require_once 'answer.class.php';
 
-
 $debug = 1; //debug value is set in the exercise.class.php file
 
 // name of the language file that needs to be included

+ 2 - 0
main/inc/ajax/exercise.ajax.php

@@ -9,7 +9,9 @@ require_once '../../exercice/question.class.php';
 require_once '../../exercice/answer.class.php';
 require_once '../global.inc.php';
 require_once '../../exercice/exercise.lib.php';
+
 api_protect_course_script(true);
+
 $action = $_REQUEST['a'];
 $course_id = api_get_course_int_id();
 

+ 31 - 9
main/inc/ajax/model.ajax.php

@@ -3,13 +3,14 @@
 
 //@todo this could be integrated in the inc/lib/model.lib.php + try to clean this file
 
-$language_file = array('admin');
+$language_file = array('admin','exercice');
 
 require_once '../global.inc.php';
 
-api_protect_admin_script(true);
+
 
 $libpath = api_get_path(LIBRARY_PATH);
+
 require_once $libpath.'array.lib.php';
 
 // 1. Setting variables needed by jqgrid
@@ -22,6 +23,9 @@ if (!in_array($sord, array('asc','desc'))) {
     $sord = 'desc'; 
 }
 
+if ($action != 'get_exercise_results')
+	api_protect_admin_script(true);
+
 //Search features
 
 $ops = array(
@@ -92,7 +96,13 @@ if (!$sidx) $sidx = 1;
  
 //2. Selecting the count FIRST
 //@todo rework this
-switch ($action) {
+
+switch ($action) {	
+	case 'get_exercise_results':
+		require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
+		require_once $libpath.'groupmanager.lib.php';
+		$count = get_count_exam_results();
+		break;
     case 'get_sessions':
         require_once $libpath.'sessionmanager.lib.php';        
         $count = SessionManager::get_count_admin();
@@ -135,8 +145,7 @@ if ($page > $total_pages) {
 $start = $limit * $page - $limit;
 if ($start < 0 ) {
 	$start = 0;
-}
- 
+} 
 
 //4. Deleting an element if the user wants to
 if ($_REQUEST['oper'] == 'del') {
@@ -146,6 +155,22 @@ if ($_REQUEST['oper'] == 'del') {
 //4. Querying the DB for the elements
 $columns = array();
 switch ($action) {    
+	case 'get_exercise_results':	
+		
+		
+		
+		$is_allowedToEdit           = api_is_allowed_to_edit(null,true);
+		$is_tutor                   = api_is_allowed_to_edit(true);
+		$documentPath				= api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
+		
+		if ($is_allowedToEdit || $is_tutor) {
+			$columns = array('firstname', 'lastname', 'username', 'groups', 'exe_duration', 'start_date', 'exe_date', 'score','status','actions');
+		} else {
+			$columns = array('exe_duration', 'start_date', 'exe_date', 'score','status');
+		}
+		$result = get_exam_results_data($start, $limit, $sidx, $sord, $where_condition);
+		
+		break;
     case 'get_sessions':
         $columns = array('name', 'nbr_courses','category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility');        
         $result = SessionManager::get_sessions_admin(array('where'=> $where_condition, 'order'=>"$sidx $sord", 'limit'=> "$start , $limit"));        
@@ -186,9 +211,6 @@ switch ($action) {
                     $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));  
                 }
             }
-            
-           
-                    
             $new_result[] = $item;
         } 
         $result = $new_result;
@@ -250,7 +272,7 @@ switch ($action) {
 //var_dump($result);
 
 //5. Creating an obj to return a json
-if (in_array($action, array('get_careers','get_promotions','get_usergroups','get_gradebooks', 'get_sessions'))) { 
+if (in_array($action, array('get_careers','get_promotions','get_usergroups','get_gradebooks', 'get_sessions','get_exercise_results'))) { 
     $response = new stdClass();           
     $response->page     = $page; 
     $response->total    = $total_pages; 

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

@@ -1241,8 +1241,8 @@ class Database {
                     $order_array = $condition_data;                
                     
                     if (!empty($order_array)) {                           
-                        if (count($order_array) >= 1 && !empty($order_array[0])) {                            
-                            $order_array = self::escape_string($order_array[0]);
+                        if (is_array($order_array) && count($order_array) >= 1 && !empty($order_array[0])) {                            							
+                            $order_array = self::escape_string($order_array[0]);							
                             
                             $new_order_array = explode(',', $order_array);
                             

+ 1 - 1
main/inc/lib/database.mysqli.lib.php

@@ -1159,7 +1159,7 @@ class Database {
                     $order_array = $condition_data;                
                     
                     if (!empty($order_array)) {                           
-                        if (count($order_array) >= 1 && !empty($order_array[0])) {                            
+                        if (is_array($order_array) && count($order_array) >= 1 && !empty($order_array[0])) {                            
                             $order_array = self::escape_string($order_array[0]);
                             
                             $new_order_array = explode(',', $order_array);

+ 20 - 0
main/survey/survey.lib.php

@@ -1179,6 +1179,25 @@ class survey_manager {
 		Database::query("DELETE FROM $table_survey_answer WHERE c_id = $course_id AND survey_id=$survey_id");
 		return true;
 	}
+	
+	function is_user_filled_survey($user_id, $survey_id, $course_id) {		
+		$table_survey_answer 		= Database :: get_course_table(TABLE_SURVEY_ANSWER);
+		
+		$user_id	= intval($user_id);
+		$course_id	= intval($course_id);
+		$survey_id	= intval($survey_id);
+		
+		$sql = "SELECT DISTINCT user FROM $table_survey_answer 
+			        WHERE	c_id		= $course_id AND 
+							user		= $user_id AND 
+							survey_id	= $survey_id";
+		$result = Database::query($sql);
+		if (Database::num_rows($result)) {
+			return true;
+		}
+		return false;
+		
+	}
 
 	/**
 	 * This function gets all the persons who have filled the survey
@@ -1191,6 +1210,7 @@ class survey_manager {
 	 */
 	function get_people_who_filled_survey($survey_id, $all_user_info = false, $course_id = null) {
 		global $_course;
+		api_get_path(SYS_COURSE_PATH);
 
 		// Database table definition
 		$table_survey_answer 		= Database :: get_course_table(TABLE_SURVEY_ANSWER);