Browse Source

Minor - fixing PHP warnings.

Julio Montoya 10 years ago
parent
commit
bd1f34254c
1 changed files with 132 additions and 106 deletions
  1. 132 106
      main/tracking/exams.php

+ 132 - 106
main/tracking/exams.php

@@ -13,10 +13,9 @@ require_once '../inc/global.inc.php';
 require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
 
 $this_section = SECTION_TRACKING;
-
 $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
 
-if(!$is_allowedToTrack) {
+if (!$is_allowedToTrack) {
     api_not_allowed();
 }
 
@@ -25,7 +24,7 @@ if (isset($_GET['export'])) {
     $export_to_xls = true;
 }
 
-$tbl_stats_exercices     = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+$tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
 
 if (api_is_platform_admin() && empty($_GET['cidReq'])) {
     $global = true;
@@ -35,21 +34,23 @@ if (api_is_platform_admin() && empty($_GET['cidReq'])) {
 
 if ($global) {
     $temp_course_list = CourseManager :: get_courses_list();
-    foreach($temp_course_list  as $temp_course_item) {
+    foreach ($temp_course_list  as $temp_course_item) {
         $course_item = CourseManager ::get_course_information($temp_course_item['code']);
-        $course_list[]= array(    'db_name'     => $course_item['db_name'],
-                                'code'        => $course_item['code'],
-                                'real_id'    => $course_item['real_id'],
-                                'title'        => $course_item['title']);
+        $course_list[] = array(
+            'db_name' => $course_item['db_name'],
+            'code' => $course_item['code'],
+            'real_id' => $course_item['real_id'],
+            'title' => $course_item['title']
+        );
     }
 } else {
-    $current_course['db_name']     = $_course['dbName'];
-    $current_course['real_id']     = $_course['real_id'];
-    $current_course['code']     = $_course['id'];
+    $current_course['db_name'] = $_course['dbName'];
+    $current_course['real_id'] = $_course['real_id'];
+    $current_course['code'] = $_course['id'];
     $course_list = array($current_course);
 }
 
-$form = new FormValidator('search_simple','POST','','',null,false);
+$form = new FormValidator('search_simple', 'POST', '', '', null, false);
 $form->addElement('text','score',get_lang('Percentage'));
 if ($global) {
     $form->addElement('hidden','view','admin');
@@ -57,7 +58,9 @@ if ($global) {
     //Get exam lists
     $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
     $course_id = api_get_course_int_id();
-    $sqlExercices = "    SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id AND active='1' ORDER BY quiz.title ASC";
+    $sqlExercices = "SELECT quiz.title,id FROM ".$t_quiz." AS quiz
+                     WHERE c_id = $course_id AND active='1'
+                     ORDER BY quiz.title ASC";
     $resultExercices = Database::query($sqlExercices);
     $exercise_list[0] = get_lang('All');
     while($a_exercices = Database::fetch_array($resultExercices)) {
@@ -67,14 +70,23 @@ if ($global) {
     $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list);
 }
 
-//$form->addElement('submit','submit',get_lang('Filter'));
-$form->addElement('style_submit_button','submit', get_lang('Filter'),'class="search"' );
+$form->addElement('style_submit_button', 'submit', get_lang('Filter'), 'class="search"');
 
+if (!empty($_REQUEST['score'])) {
+    $filter_score = intval($_REQUEST['score']);
+} else {
+    $filter_score = 70;
+}
 
-if (!empty($_REQUEST['score']))    $filter_score = intval($_REQUEST['score']); else $filter_score = 70;
-if (!empty($_REQUEST['exercise_id']))    $exercise_id = intval($_REQUEST['exercise_id']); else $exercise_id = 0;
+if (!empty($_REQUEST['exercise_id'])) {
+    $exercise_id = intval($_REQUEST['exercise_id']);
+} else {
+    $exercise_id = 0;
+}
 
-$form->setDefaults(array('score'=>$filter_score));
+$form->setDefaults(
+    array('score' => $filter_score)
+);
 
 if (!$export_to_xls) {
     Display :: display_header(get_lang('Reporting'));
@@ -99,7 +111,7 @@ if (!$export_to_xls) {
         $menu_items[] = Display::return_icon('quiz_na.png', get_lang('ExamTracking'), array(), 32);
 
         $nb_menu_items = count($menu_items);
-        if($nb_menu_items>1) {
+        if ($nb_menu_items>1) {
             foreach($menu_items as $key=> $item) {
                 echo $item;
             }
@@ -117,6 +129,7 @@ if (!$export_to_xls) {
     echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
 }
 
+$html_result = null;
 if ($global) {
     $html_result .= '<table  class="data_table">';
     $html_result .= '<tr><th>'.get_lang('Courses').'</th>';
@@ -141,15 +154,17 @@ $table = Database::get_course_table(TABLE_TOOL_LIST);
 $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
 
 $export_array_global = $export_array =  array();
+$s_css_class = null;
 if(!empty($course_list) && is_array($course_list)) {
     foreach ($course_list as $current_course) {
         $global_row = $row_not_global = array();
         $course_id = $current_course['real_id'];
-    
+
         $a_students = CourseManager :: get_student_list_from_course_code($current_course['code'], false);
         $total_students = count($a_students);
-    
-        $sqlExercices        = "SELECT count(id) as count FROM ".$t_quiz." AS quiz WHERE active='1' AND c_id = $course_id ";
+
+        $sqlExercices = "SELECT count(id) as count FROM ".$t_quiz." AS quiz
+                         WHERE active='1' AND c_id = $course_id ";
         $resultExercices     = Database::query($sqlExercices);
         $data_exercises      = Database::store_result($resultExercices);
         $exercise_count     = $data_exercises[0]['count'];
@@ -157,21 +172,26 @@ if(!empty($course_list) && is_array($course_list)) {
             if ($exercise_count == 0) {
                 $exercise_count = 2;
             }
-            $html_result .= "<tr class='$s_css_class'>
+            $html_result .= "<tr class='".$s_css_class."'>
                                 <td rowspan=$exercise_count>";
             $html_result .= $current_course['title'];
             $html_result .= "</td>";
         }
-    
-        $sql = "SELECT visibility FROM $table WHERE c_id = $course_id AND name='quiz'";
+
+        $sql = "SELECT visibility FROM $table
+                WHERE c_id = $course_id AND name='quiz'";
         $resultVisibilityQuizz = Database::query($sql);
-    
+
         if (Database::result($resultVisibilityQuizz, 0 ,'visibility') == 1) {
-            $sqlExercices = "    SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id  AND active='1' ORDER BY quiz.title ASC";
+            $sqlExercices = " SELECT quiz.title, id
+                                FROM ".$t_quiz." AS quiz WHERE c_id = $course_id  AND active='1'
+                                ORDER BY quiz.title ASC";
             //Getting the exam list
             if (!$global) {
                 if (!empty($exercise_id)) {
-                    $sqlExercices = "    SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE c_id = $course_id  AND active='1' AND id = $exercise_id ORDER BY quiz.title ASC";
+                    $sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz
+                                      WHERE c_id = $course_id  AND active='1' AND id = $exercise_id
+                                      ORDER BY quiz.title ASC";
                 }
             }
             $resultExercices = Database::query($sqlExercices);
@@ -180,85 +200,86 @@ if(!empty($course_list) && is_array($course_list)) {
                 while($a_exercices = Database::fetch_array($resultExercices)) {
                     $global_row[]= $current_course['title'];
                     if (!$global) {
-                        $html_result .= "<tr class='$s_css_class'>";
+                        $html_result .= "<tr class='".$s_css_class."'>";
                     }
                     if (!$global) {
                         $html_result .= '<td ROWSPAN="'.$total_students.'">';
                     } else {
                         $html_result .= '<td>';
                     }
-    
+
                     $html_result .= $a_exercices['title'];
                     $html_result .= '</td>';
-    
+
                     $global_row[]=$a_exercices['title'];
                     $row_not_global['exercise']= $a_exercices['title'];
-    
+
                     $taken = 0;
                     $total_with_parameter = 0;
                     $fail = 0;
                     $not_taken = 0;
-    
+
                     $total_with_parameter_score = 0;
                     $total_with_parameter_porcentage = 0;
-    
+
                     $student_result = array();
-    
+
                     foreach ($a_students as $student ) {
                         $current_student_id = $student['user_id'];
-                        $sqlEssais = "    SELECT COUNT(ex.exe_id) as essais
+                        $sqlEssais = "  SELECT COUNT(ex.exe_id) as essais
                                         FROM $tbl_stats_exercices AS ex
-                                        WHERE  ex.exe_cours_id = '".$current_course['code']."'
-                                        AND ex.exe_exo_id = ".$a_exercices['id']."
-                                        AND exe_user_id='".$current_student_id."'";
-    
-    
+                                        WHERE
+                                            ex.exe_cours_id = '".$current_course['code']."' AND
+                                            ex.exe_exo_id = ".$a_exercices['id']." AND
+                                            exe_user_id='".$current_student_id."'";
+
                         $resultEssais = Database::query($sqlEssais);
                         $a_essais = Database::fetch_array($resultEssais);
-    
+
                         $sqlScore = "SELECT exe_id, exe_result,exe_weighting
-                                 FROM $tbl_stats_exercices
-                                 WHERE exe_user_id = ".$current_student_id."
-                                 AND exe_cours_id = '".$current_course['code']."'
-                                 AND exe_exo_id = ".$a_exercices['id']."
-                                 ORDER BY exe_result DESC LIMIT 1"; // we take the higher value
-                                 //ORDER BY exe_date DESC LIMIT 1";
-    
+                                     FROM $tbl_stats_exercices
+                                     WHERE
+                                        exe_user_id = ".$current_student_id." AND
+                                        exe_cours_id = '".$current_course['code']."' AND
+                                        exe_exo_id = ".$a_exercices['id']."
+                                     ORDER BY exe_result DESC
+                                     LIMIT 1";
+
                         $resultScore = Database::query($sqlScore);
                         $score = 0;
-    
+                        $weighting = 0;
                         while($a_score = Database::fetch_array($resultScore)) {
                             $score = $score + $a_score['exe_result'];
                             $weighting = $weighting + $a_score['exe_weighting'];
                             $exe_id = $a_score['exe_id'];
                         }
-    
-                        $pourcentageScore = 0;
-                        if ($weighting!=0) {
-                            $pourcentageScore = round(($score*100)/$weighting);
+
+                        $percentageScore = 0;
+                        if ($weighting != 0) {
+                            $percentageScore = round(($score*100)/$weighting);
                         }
-    
+
                         $weighting = 0;
-    
-                        if($i%2==0){
-                            $s_css_class="row_odd";
+
+                        if ($i % 2 == 0) {
+                            $s_css_class = "row_odd";
                         } else {
-                            $s_css_class="row_even";
+                            $s_css_class = "row_even";
                         }
                         $i++;
-    
+
                         /*echo "    <td align='right'>
                               ";
                         echo         $current_student_id.' ';
                         echo "    </td>";
                         */
-    
-                        //var_dump($pourcentageScore);
+
+                        //var_dump($percentageScore);
                 /*        echo "    <td align='right'>
                               ";
-                        echo         $pourcentageScore.' %';
+                        echo         $percentageScore.' %';
                         echo "    </td>";
-    
+
                         echo "<td align='right'>
                              ";
                              /*
@@ -266,48 +287,48 @@ if(!empty($course_list) && is_array($course_list)) {
                         echo "    </td>
                                 <td align='center'>
                              ";*/
-    
+
                         if ($a_essais['essais'] > 0 ) {
                             $taken++;
                         }
-    
-                        if ($pourcentageScore >= $parameter_porcentage) {
+
+                        /*if ($percentageScore >= $parameter_porcentage) {
                             $total_with_parameter_porcentage++;
-                        }
-    
-                        if ($pourcentageScore >= $filter_score) {
+                        }*/
+
+                        if ($percentageScore >= $filter_score) {
                             $total_with_parameter_score++;
                         }
-    
+
                         if (!$global) {
                             $user_info = api_get_user_info($current_student_id);
-    
-                            //User
+
+                            // User
                             $user_row = '<td >';
-                            $user_row .=         $user_info['firstName'].' '.$user_info['lastName'];
+                            $user_row .= $user_info['firstName'].' '.$user_info['lastName'];
                             $user_row .= '</td>';
                             $user_info = $user_info['firstName'].' '.$user_info['lastName'];
-    
-                            //Best result
+
+                            // Best result
                             if (!empty($a_essais['essais'])) {
                                 $user_row .= '<td  >';
-                                $user_row .=         $pourcentageScore;
-                                $temp_array [] =         $pourcentageScore;
+                                $user_row .=         $percentageScore;
+                                $temp_array [] =         $percentageScore;
                                 $user_row .= '</td>';
-    
-                                if ($pourcentageScore >= $filter_score ) {
+
+                                if ($percentageScore >= $filter_score ) {
                                     $user_row .= '<td  style="background-color:#DFFFA8">';
                                     $user_row .= get_lang('PassExam').'</td>';
-                                    $temp_array [] =         get_lang('PassExam');
+                                    $temp_array [] = get_lang('PassExam');
                                 } else {
                                     $user_row .= '<td  style="background-color:#FC9A9E"  >';
                                     $user_row .= get_lang('ExamFail').'</td>';
-                                    $temp_array [] =         get_lang('ExamFail');
+                                    $temp_array [] = get_lang('ExamFail');
                                 }
-    
+
                                 $user_row .= '<td >';
                                 $user_row .= $a_essais['essais'];
-                                $temp_array [] =         $a_essais['essais'];
+                                $temp_array [] = $a_essais['essais'];
                                 $user_row .= '</td>';
                             } else {
                                 $score = '-';
@@ -315,7 +336,7 @@ if(!empty($course_list) && is_array($course_list)) {
                                 $user_row .=  '-';
                                 $temp_array [] =         '-';
                                 $user_row .= '</td>';
-    
+
                                 $user_row .= '<td   style="background-color:#FCE89A">';
                                 $user_row .= get_lang('NoAttempt');
                                 $temp_array [] =     get_lang('NoAttempt');
@@ -326,11 +347,16 @@ if(!empty($course_list) && is_array($course_list)) {
                                 $user_row .= '</td>';
                             }
                             $user_row .= '</tr>';
-                            $student_result[$current_student_id]  = array('html'=>$user_row,'score'=>$score,'array'=>$temp_array,'user'=>$user_info);
+                            $student_result[$current_student_id] = array(
+                                'html' => $user_row,
+                                'score' => $score,
+                                'array' => $temp_array,
+                                'user' => $user_info
+                            );
                             $temp_array = array();
                         }
                     }
-    
+
                     if (!$global) {
                         if (!empty($student_result)) {
                             $student_result_empty = $student_result_content = array();
@@ -341,10 +367,11 @@ if(!empty($course_list) && is_array($course_list)) {
                                     $student_result_content[] = $row;
                                 }
                             }
-                            //Sort only users with content
+
+                            // Sort only users with content
                             usort($student_result_content, 'sort_user');
                             $student_result = array_merge($student_result_content, $student_result_empty );
-    
+
                             foreach($student_result as $row) {
                                 $html_result .=$row['html'];
                                 $row_not_global['results'][]= $row['array'];
@@ -354,43 +381,43 @@ if(!empty($course_list) && is_array($course_list)) {
                             $row_not_global = array();
                         }
                     }
+
                     if ($global) {
-                        //Exam taken
+                        // Exam taken
                         $html_result .= '<td >';
                         $html_result .=         $taken;
                         $global_row[]= $taken;
-                        //echo         $total.' /  '.$total_students;
                         $html_result .= '</td>';
-    
-                        //Exam NOT taken
+
+                        // Exam NOT taken
                         $html_result .= '<td >';
-                        $html_result .=         $not_taken = $total_students - $taken;
+                        $html_result .= $not_taken = $total_students - $taken;
                         $global_row[]= $not_taken;
                         $html_result .= '</td>';
-    
-                        //Examn pass
+
+                        // Exam pass
                         if (!empty($total_with_parameter_score)) {
                             $html_result .= '<td   style="background-color:#DFFFA8" >';
                         } else {
                             $html_result .= '<td   style="background-color:#FCE89A"  >';
                         }
-    
+
                         $html_result .= $total_with_parameter_score;
                         $global_row[]= $total_with_parameter_score;
                         $html_result .= '</td>';
-    
-                        //Exam fail
+
+                        // Exam fail
                         $html_result .= '<td >';
-    
-                        $html_result .=         $fail = $taken - $total_with_parameter_score;
+
+                        $html_result .= $fail = $taken - $total_with_parameter_score;
                         $global_row[]= $fail;
                         $html_result .= '</td>';
-    
+
                         $html_result .= '<td >';
-                        $html_result .=         $total_students;
+                        $html_result .= $total_students;
                         $global_row[]= $total_students;
-    
-                        $global_counter++;
+
+                        //$global_counter++;
                         $html_result .= '</td>';
                         $html_result .= '</tr>';
                         $export_array_global[] = $global_row;
@@ -433,7 +460,6 @@ if ($export_to_xls) {
 
 function sort_user($a, $b) {
     if (is_numeric($a['score']) && is_numeric($b['score'])) {
-        //echo $a['score'].' : '.$b['score']; echo '<br />';
         if ($a['score'] < $b['score']) {
             return 1;
         }