Minor - format code.

1.9.x
Julio Montoya 12 years ago
parent 5ddc3c00d6
commit ef2e630894
  1. 244
      main/tracking/exams.php

@ -8,7 +8,7 @@
* Code * Code
*/ */
$language_file = array ('registration', 'index', 'tracking', 'exercice','survey'); $language_file = array('registration', 'index', 'tracking', 'exercice','survey');
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php'; require_once api_get_path(LIBRARY_PATH).'pear/Spreadsheet_Excel_Writer/Writer.php';
@ -31,62 +31,49 @@ if (api_is_platform_admin() && empty($_GET['cidReq'])) {
} else { } else {
$global = false; $global = false;
} }
$courseList = array();
if ($global) { if ($global) {
$temp_course_list = CourseManager :: get_courses_list(); $temp = CourseManager::get_courses_list();
foreach ($temp_course_list as $temp_course_item) { foreach ($temp as $tempCourse) {
$course_item = CourseManager ::get_course_information($temp_course_item['code']); $courseInfo = api_get_course_info($tempCourse['code']);
$course_list[] = array( $courseList[] = $courseInfo;
'db_name' => $course_item['db_name'],
'code' => $course_item['code'],
'real_id' => $course_item['real_id'],
'title' => $course_item['title']
);
} }
} else { } else {
$current_course['db_name'] = $_course['dbName']; $courseList = array(api_get_course_info());
$current_course['real_id'] = $_course['real_id'];
$current_course['code'] = $_course['id'];
$course_list = array($current_course);
} }
$sessionId = api_get_session_id();
$form = new FormValidator('search_simple', 'POST', '', '', null, false); $form = new FormValidator('search_simple', 'POST', '', '', null, false);
$form->addElement('text','score',get_lang('Percentage')); $form->addElement('text', 'score', get_lang('Percentage'));
if ($global) { if ($global) {
$form->addElement('hidden','view','admin'); $form->addElement('hidden', 'view', 'admin');
} else { } else {
//Get exam lists // Get exam lists
$t_quiz = Database::get_course_table(TABLE_QUIZ_TEST); $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sqlExercices = "SELECT quiz.title,id FROM ".$t_quiz." AS quiz $sql = "SELECT quiz.title,id FROM $t_quiz AS quiz
WHERE c_id = $course_id AND active='1' WHERE
ORDER BY quiz.title ASC"; c_id = $course_id AND
$resultExercices = Database::query($sqlExercices); active='1'
$exercise_list[0] = get_lang('All'); ORDER BY quiz.title ASC";
while($a_exercices = Database::fetch_array($resultExercices)) { $result = Database::query($sql);
$exercise_list[$a_exercices['id']] = $a_exercices['title'];
$exerciseList = array(get_lang('All'));
while ($row = Database::fetch_array($result)) {
$exerciseList[$row['id']] = $row['title'];
} }
$form->addElement('select', 'exercise_id', get_lang('Exercise'), $exercise_list); $form->addElement('select', 'exercise_id', get_lang('Exercise'), $exerciseList);
} }
$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 = isset($_REQUEST['score']) ? intval($_REQUEST['score']) : 70;
$filter_score = intval($_REQUEST['score']); $exercise_id = isset($_REQUEST['exercise_id']) ? intval($_REQUEST['exercise_id']) : 0;
} else {
$filter_score = 70;
}
if (!empty($_REQUEST['exercise_id'])) { $form->setDefaults(array('score' => $filter_score));
$exercise_id = intval($_REQUEST['exercise_id']);
} else {
$exercise_id = 0;
}
$form->setDefaults(
array('score' => $filter_score)
);
if (!$export_to_xls) { if (!$export_to_xls) {
Display :: display_header(get_lang('Reporting')); Display :: display_header(get_lang('Reporting'));
@ -94,7 +81,7 @@ if (!$export_to_xls) {
if ($global) { if ($global) {
echo '<a href="'.api_get_path(WEB_CODE_PATH).'auth/my_progress.php">'. echo '<a href="'.api_get_path(WEB_CODE_PATH).'auth/my_progress.php">'.
Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM); Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM);
echo '</a>'; echo '</a>';
echo '<span style="float:right">'; echo '<span style="float:right">';
@ -112,7 +99,7 @@ if (!$export_to_xls) {
$nb_menu_items = count($menu_items); $nb_menu_items = count($menu_items);
if ($nb_menu_items>1) { if ($nb_menu_items>1) {
foreach($menu_items as $key=> $item) { foreach ($menu_items as $key=> $item) {
echo $item; echo $item;
} }
} }
@ -129,38 +116,38 @@ if (!$export_to_xls) {
echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>'; echo '<h3>'.sprintf(get_lang('FilteringWithScoreX'), $filter_score).'%</h3>';
} }
$html_result = null; $html = null;
if ($global) { if ($global) {
$html_result .= '<table class="data_table">'; $html .= '<table class="data_table">';
$html_result .= '<tr><th>'.get_lang('Courses').'</th>'; $html .= '<tr><th>'.get_lang('Courses').'</th>';
$html_result .= '<th>'.get_lang('Quiz').'</th>'; $html .= '<th>'.get_lang('Quiz').'</th>';
$html_result .= '<th>'.get_lang('ExamTaken').'</th>'; $html .= '<th>'.get_lang('ExamTaken').'</th>';
$html_result .= '<th>'.get_lang('ExamNotTaken').'</th>'; $html .= '<th>'.get_lang('ExamNotTaken').'</th>';
$html_result .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'%</th>'; $html .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'%</th>';
$html_result .= '<th>'.get_lang('ExamFail').'</th>'; $html .= '<th>'.get_lang('ExamFail').'</th>';
$html_result .= '<th>'.get_lang('TotalStudents').'</th>'; $html .= '<th>'.get_lang('TotalStudents').'</th>';
$html_result .= '</tr>'; $html .= '</tr>';
} else { } else {
$html_result .= '<table class="data_table">'; $html .= '<table class="data_table">';
$html_result .= '<tr><th>'.get_lang('Quiz').'</th>'; $html .= '<tr><th>'.get_lang('Quiz').'</th>';
$html_result .= '<th>'.get_lang('User').'</th>'; $html .= '<th>'.get_lang('User').'</th>';
//$html_result .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'</th>'; //$html .= '<th>'.sprintf(get_lang('ExamPassX'), $filter_score).'</th>';
$html_result .= '<th>'.get_lang('Percentage').' %</th>'; $html .= '<th>'.get_lang('Percentage').' %</th>';
$html_result .= '<th>'.get_lang('Status').'</th>'; $html .= '<th>'.get_lang('Status').'</th>';
$html_result .= '<th>'.get_lang('Attempts').'</th>'; $html .= '<th>'.get_lang('Attempts').'</th>';
$html_result .= '</tr>'; $html .= '</tr>';
} }
$table = Database::get_course_table(TABLE_TOOL_LIST); $table = Database::get_course_table(TABLE_TOOL_LIST);
$t_quiz = Database::get_course_table(TABLE_QUIZ_TEST); $t_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
$export_array_global = $export_array = array(); $export_array_global = $export_array = array();
$s_css_class = null; $s_css_class = null;
if(!empty($course_list) && is_array($course_list)) { if(!empty($courseList) && is_array($courseList)) {
foreach ($course_list as $current_course) { foreach ($courseList as $courseInfo) {
$global_row = $row_not_global = array(); $global_row = $row_not_global = array();
$course_id = $current_course['real_id']; $course_id = $courseInfo['real_id'];
$a_students = CourseManager :: get_student_list_from_course_code($current_course['code'], false); $a_students = CourseManager :: get_student_list_from_course_code($courseInfo['code'], false);
$total_students = count($a_students); $total_students = count($a_students);
$sqlExercices = "SELECT count(id) as count FROM ".$t_quiz." AS quiz $sqlExercices = "SELECT count(id) as count FROM ".$t_quiz." AS quiz
@ -172,10 +159,10 @@ if(!empty($course_list) && is_array($course_list)) {
if ($exercise_count == 0) { if ($exercise_count == 0) {
$exercise_count = 2; $exercise_count = 2;
} }
$html_result .= "<tr class='".$s_css_class."'> $html .= "<tr class='".$s_css_class."'>
<td rowspan=$exercise_count>"; <td rowspan=$exercise_count>";
$html_result .= $current_course['title']; $html .= $courseInfo['title'];
$html_result .= "</td>"; $html .= "</td>";
} }
$sql = "SELECT visibility FROM $table $sql = "SELECT visibility FROM $table
@ -198,18 +185,18 @@ if(!empty($course_list) && is_array($course_list)) {
$i = 0; $i = 0;
if (Database::num_rows($resultExercices) > 0) { if (Database::num_rows($resultExercices) > 0) {
while($a_exercices = Database::fetch_array($resultExercices)) { while($a_exercices = Database::fetch_array($resultExercices)) {
$global_row[]= $current_course['title']; $global_row[]= $courseInfo['title'];
if (!$global) { if (!$global) {
$html_result .= "<tr class='".$s_css_class."'>"; $html .= "<tr class='".$s_css_class."'>";
} }
if (!$global) { if (!$global) {
$html_result .= '<td ROWSPAN="'.$total_students.'">'; $html .= '<td ROWSPAN="'.$total_students.'">';
} else { } else {
$html_result .= '<td>'; $html .= '<td>';
} }
$html_result .= $a_exercices['title']; $html .= $a_exercices['title'];
$html_result .= '</td>'; $html .= '</td>';
$global_row[]=$a_exercices['title']; $global_row[]=$a_exercices['title'];
$row_not_global['exercise']= $a_exercices['title']; $row_not_global['exercise']= $a_exercices['title'];
@ -229,7 +216,7 @@ if(!empty($course_list) && is_array($course_list)) {
$sqlEssais = " SELECT COUNT(ex.exe_id) as essais $sqlEssais = " SELECT COUNT(ex.exe_id) as essais
FROM $tbl_stats_exercices AS ex FROM $tbl_stats_exercices AS ex
WHERE WHERE
ex.exe_cours_id = '".$current_course['code']."' AND ex.exe_cours_id = '".$courseInfo['code']."' AND
ex.exe_exo_id = ".$a_exercices['id']." AND ex.exe_exo_id = ".$a_exercices['id']." AND
exe_user_id='".$current_student_id."'"; exe_user_id='".$current_student_id."'";
@ -240,7 +227,7 @@ if(!empty($course_list) && is_array($course_list)) {
FROM $tbl_stats_exercices FROM $tbl_stats_exercices
WHERE WHERE
exe_user_id = ".$current_student_id." AND exe_user_id = ".$current_student_id." AND
exe_cours_id = '".$current_course['code']."' AND exe_cours_id = '".$courseInfo['code']."' AND
exe_exo_id = ".$a_exercices['id']." exe_exo_id = ".$a_exercices['id']."
ORDER BY exe_result DESC ORDER BY exe_result DESC
LIMIT 1"; LIMIT 1";
@ -268,34 +255,10 @@ if(!empty($course_list) && is_array($course_list)) {
} }
$i++; $i++;
/*echo " <td align='right'>
";
echo $current_student_id.' ';
echo " </td>";
*/
//var_dump($percentageScore);
/* echo " <td align='right'>
";
echo $percentageScore.' %';
echo " </td>";
echo "<td align='right'>
";
/*
echo $a_essais['essais'];
echo " </td>
<td align='center'>
";*/
if ($a_essais['essais'] > 0 ) { if ($a_essais['essais'] > 0 ) {
$taken++; $taken++;
} }
/*if ($percentageScore >= $parameter_porcentage) {
$total_with_parameter_porcentage++;
}*/
if ($percentageScore >= $filter_score) { if ($percentageScore >= $filter_score) {
$total_with_parameter_score++; $total_with_parameter_score++;
} }
@ -304,46 +267,46 @@ if(!empty($course_list) && is_array($course_list)) {
$user_info = api_get_user_info($current_student_id); $user_info = api_get_user_info($current_student_id);
// User // User
$user_row = '<td >'; $user_row = '<td>';
$user_row .= $user_info['firstName'].' '.$user_info['lastName']; $user_row .= $user_info['firstName'].' '.$user_info['lastName'];
$user_row .= '</td>'; $user_row .= '</td>';
$user_info = $user_info['firstName'].' '.$user_info['lastName']; $user_info = $user_info['firstName'].' '.$user_info['lastName'];
// Best result // Best result
if (!empty($a_essais['essais'])) { if (!empty($a_essais['essais'])) {
$user_row .= '<td >'; $user_row .= '<td>';
$user_row .= $percentageScore; $user_row .= $percentageScore;
$temp_array [] = $percentageScore; $temp_array [] = $percentageScore;
$user_row .= '</td>'; $user_row .= '</td>';
if ($percentageScore >= $filter_score ) { if ($percentageScore >= $filter_score ) {
$user_row .= '<td style="background-color:#DFFFA8">'; $user_row .= '<td style="background-color:#DFFFA8">';
$user_row .= get_lang('PassExam').'</td>'; $user_row .= get_lang('PassExam').'</td>';
$temp_array [] = get_lang('PassExam'); $temp_array[] = get_lang('PassExam');
} else { } else {
$user_row .= '<td style="background-color:#FC9A9E" >'; $user_row .= '<td style="background-color:#FC9A9E" >';
$user_row .= get_lang('ExamFail').'</td>'; $user_row .= get_lang('ExamFail').'</td>';
$temp_array [] = get_lang('ExamFail'); $temp_array[] = get_lang('ExamFail');
} }
$user_row .= '<td >'; $user_row .= '<td>';
$user_row .= $a_essais['essais']; $user_row .= $a_essais['essais'];
$temp_array [] = $a_essais['essais']; $temp_array[] = $a_essais['essais'];
$user_row .= '</td>'; $user_row .= '</td>';
} else { } else {
$score = '-'; $score = '-';
$user_row .= '<td >'; $user_row .= '<td >';
$user_row .= '-'; $user_row .= '-';
$temp_array [] = '-'; $temp_array[] = '-';
$user_row .= '</td>'; $user_row .= '</td>';
$user_row .= '<td style="background-color:#FCE89A">'; $user_row .= '<td style="background-color:#FCE89A">';
$user_row .= get_lang('NoAttempt'); $user_row .= get_lang('NoAttempt');
$temp_array [] = get_lang('NoAttempt'); $temp_array[] = get_lang('NoAttempt');
$user_row .= '</td>'; $user_row .= '</td>';
$user_row .= '<td >'; $user_row .= '<td>';
$user_row .= 0; $user_row .= 0;
$temp_array [] = 0; $temp_array[] = 0;
$user_row .= '</td>'; $user_row .= '</td>';
} }
$user_row .= '</tr>'; $user_row .= '</tr>';
@ -373,7 +336,7 @@ if(!empty($course_list) && is_array($course_list)) {
$student_result = array_merge($student_result_content, $student_result_empty ); $student_result = array_merge($student_result_content, $student_result_empty );
foreach($student_result as $row) { foreach($student_result as $row) {
$html_result .=$row['html']; $html .=$row['html'];
$row_not_global['results'][]= $row['array']; $row_not_global['results'][]= $row['array'];
$row_not_global['users'][] = $row['user']; $row_not_global['users'][] = $row['user'];
} }
@ -384,48 +347,48 @@ if(!empty($course_list) && is_array($course_list)) {
if ($global) { if ($global) {
// Exam taken // Exam taken
$html_result .= '<td >'; $html .= '<td>';
$html_result .= $taken; $html .= $taken;
$global_row[]= $taken; $global_row[]= $taken;
$html_result .= '</td>'; $html .= '</td>';
// Exam NOT taken // Exam NOT taken
$html_result .= '<td >'; $html .= '<td>';
$html_result .= $not_taken = $total_students - $taken; $html .= $not_taken = $total_students - $taken;
$global_row[]= $not_taken; $global_row[]= $not_taken;
$html_result .= '</td>'; $html .= '</td>';
// Exam pass // Exam pass
if (!empty($total_with_parameter_score)) { if (!empty($total_with_parameter_score)) {
$html_result .= '<td style="background-color:#DFFFA8" >'; $html .= '<td style="background-color:#DFFFA8" >';
} else { } else {
$html_result .= '<td style="background-color:#FCE89A" >'; $html .= '<td style="background-color:#FCE89A" >';
} }
$html_result .= $total_with_parameter_score; $html .= $total_with_parameter_score;
$global_row[]= $total_with_parameter_score; $global_row[]= $total_with_parameter_score;
$html_result .= '</td>'; $html .= '</td>';
// Exam fail // Exam fail
$html_result .= '<td >'; $html .= '<td>';
$html_result .= $fail = $taken - $total_with_parameter_score; $html .= $fail = $taken - $total_with_parameter_score;
$global_row[]= $fail; $global_row[]= $fail;
$html_result .= '</td>'; $html .= '</td>';
$html_result .= '<td >'; $html .= '<td>';
$html_result .= $total_students; $html .= $total_students;
$global_row[]= $total_students; $global_row[]= $total_students;
//$global_counter++; //$global_counter++;
$html_result .= '</td>'; $html .= '</td>';
$html_result .= '</tr>'; $html .= '</tr>';
$export_array_global[] = $global_row; $export_array_global[] = $global_row;
$global_row = array(); $global_row = array();
} }
} }
} else { } else {
$html_result .= " <tr> $html .= "<tr>
<td colspan='6'> <td colspan='6'>
".get_lang('NoExercise')." ".get_lang('NoExercise')."
</td> </td>
@ -433,7 +396,7 @@ if(!empty($course_list) && is_array($course_list)) {
"; ";
} }
} else { } else {
$html_result .= " <tr> $html .= "<tr>
<td colspan='6'> <td colspan='6'>
".get_lang('NoExercise')." ".get_lang('NoExercise')."
</td> </td>
@ -443,10 +406,10 @@ if(!empty($course_list) && is_array($course_list)) {
} }
} }
$html_result .= '</table>'; $html .= '</table>';
if (!$export_to_xls) { if (!$export_to_xls) {
echo $html_result; echo $html;
} }
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls'; $filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($export_to_xls) { if ($export_to_xls) {
@ -482,20 +445,21 @@ function export_complete_report_xls($filename, $array) {
$column = 0; //skip the first column (row titles) $column = 0; //skip the first column (row titles)
if ($global) { if ($global) {
$worksheet->write($line,$column,get_lang('Courses')); $worksheet->write($line, $column, get_lang('Courses'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('Exercises')); $worksheet->write($line, $column, get_lang('Exercises'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('ExamTaken')); $worksheet->write($line, $column, get_lang('ExamTaken'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('ExamNotTaken')); $worksheet->write($line, $column, get_lang('ExamNotTaken'));
$column++; $column++;
$worksheet->write($line,$column,sprintf(get_lang('ExamPassX'), $filter_score).'%'); $worksheet->write($line, $column, sprintf(get_lang('ExamPassX'), $filter_score) . '%');
$column++; $column++;
$worksheet->write($line,$column,get_lang('ExamFail')); $worksheet->write($line, $column, get_lang('ExamFail'));
$column++; $column++;
$worksheet->write($line,$column,get_lang('TotalStudents')); $worksheet->write($line, $column, get_lang('TotalStudents'));
$column++; $column++;
$line++; $line++;
foreach ($array as $row) { foreach ($array as $row) {
$column = 0; $column = 0;

Loading…
Cancel
Save