';
$html_result .= ''.get_lang('Exercises').' | ';
$html_result .= ''.get_lang('User').' | ';
//$html_result .= ''.sprintf(get_lang('ExamPassX'), $filter_score).' | ';
$html_result .= ''.get_lang('Percentage').' % | ';
$html_result .= ''.get_lang('Status').' | ';
$html_result .= ''.get_lang('Attempts').' | ';
$html_result .= '
';
}
$export_array_global = $export_array = array();
if(!empty($course_list) && is_array($course_list))
foreach($course_list as $current_course ) {
$global_row = $row_not_global = array();
$a_students = CourseManager :: get_student_list_from_course_code($current_course['code'], false);
$total_students = count($a_students);
$t_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$current_course['db_name']);
$sqlExercices = "SELECT count(id) as count FROM ".$t_quiz." AS quiz WHERE active='1' ";
$resultExercices = Database::query($sqlExercices);
$data_exercises = Database::store_result($resultExercices);
$exercise_count = $data_exercises[0]['count'];
if ($global) {
if ($exercise_count == 0) {
$exercise_count = 2;
}
$html_result .= "
";
$html_result .= $current_course['title'];
$html_result .= " | ";
}
$sql='SELECT visibility FROM '.$current_course['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz" ';
$resultVisibilityQuizz = Database::query($sql);
if (Database::result($resultVisibilityQuizz, 0 ,'visibility') == 1) {
$sqlExercices = " SELECT quiz.title,id FROM ".$t_quiz." AS quiz WHERE 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 active='1' AND id = $exercise_id ORDER BY quiz.title ASC";
}
}
$resultExercices = Database::query($sqlExercices);
$i = 0;
if (Database::num_rows($resultExercices) > 0) {
while($a_exercices = Database::fetch_array($resultExercices)) {
$global_row[]= $current_course['title'];
if (!$global) {
$html_result .= "
";
}
if (!$global) {
$html_result .= '';
} else {
$html_result .= ' | ';
}
$html_result .= $a_exercices['title'];
$html_result .= ' | ';
$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
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."'";
$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";
$resultScore = Database::query($sqlScore);
$score = 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);
}
$weighting = 0;
if($i%2==0){
$s_css_class="row_odd";
} else {
$s_css_class="row_even";
}
$i++;
/*echo "
";
echo $current_student_id.' ';
echo " | ";
*/
//var_dump($pourcentageScore);
/* echo "
";
echo $pourcentageScore.' %';
echo " | ";
echo "
";
/*
echo $a_essais['essais'];
echo " |
";*/
if ($a_essais['essais'] > 0 ) {
$taken++;
}
if ($pourcentageScore >= $parameter_porcentage) {
$total_with_parameter_porcentage++;
}
if ($pourcentageScore >= $filter_score) {
$total_with_parameter_score++;
}
/*
$sql_last_attempt='SELECT exe_id FROM '.$tbl_stats_exercices.' WHERE exe_exo_id="'.$a_exercices['id'].'" AND exe_user_id="'.$current_student_id.'" AND exe_cours_id="'.$current_course['code'].'" ORDER BY exe_date DESC LIMIT 1';
$resultLastAttempt = Database::query($sql_last_attempt);
if(Database::num_rows($resultLastAttempt)>0) {
$id_last_attempt=Database::result($resultLastAttempt,0,0);
if($a_essais['essais']>0) {
/// echo ' ';
}
}
*/
if (!$global) {
$user_info = api_get_user_info($current_student_id);
//User
$user_row = ' | ';
$user_row .= $user_info['firstName'].' '.$user_info['lastName'];
$user_row .= ' | ';
$user_info = $user_info['firstName'].' '.$user_info['lastName'];
//Best result
if (!empty($a_essais['essais'])) {
$user_row .= '';
$user_row .= $pourcentageScore;
$temp_array [] = $pourcentageScore;
$user_row .= ' | ';
if ($pourcentageScore >= $filter_score ) {
$user_row .= '';
$user_row .= get_lang('PassExam').' | ';
$temp_array [] = get_lang('PassExam');
} else {
$user_row .= '';
$user_row .= get_lang('ExamFail').' | ';
$temp_array [] = get_lang('ExamFail');
}
$user_row .= '';
$user_row .= $a_essais['essais'];
$temp_array [] = $a_essais['essais'];
$user_row .= ' | ';
} else {
$score = '-';
$user_row .= '';
$user_row .= '-';
$temp_array [] = '-';
$user_row .= ' | ';
$user_row .= '';
$user_row .= get_lang('NoAttempt');
$temp_array [] = get_lang('NoAttempt');
$user_row .= ' | ';
$user_row .= '';
$user_row .= 0;
$temp_array [] = 0;
$user_row .= ' | ';
}
$user_row .= '
';
$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();
foreach($student_result as $row) {
if ($row['score'] == '-') {
$student_result_empty[] = $row;
} else {
$student_result_content[] = $row;
}
}
//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'];
$row_not_global['users'][] = $row['user'];
}
$export_array[] = $row_not_global;
$row_not_global = array();
}
}
if ($global) {
//Exam taken
$html_result .= '';
$html_result .= $taken;
$global_row[]= $taken;
//echo $total.' / '.$total_students;
$html_result .= ' | ';
//Exam NOT taken
$html_result .= '';
$html_result .= $not_taken = $total_students - $taken;
$global_row[]= $not_taken;
$html_result .= ' | ';
//Examn pass
if (!empty($total_with_parameter_score)) {
$html_result .= '';
} else {
$html_result .= ' | ';
}
$html_result .= $total_with_parameter_score;
$global_row[]= $total_with_parameter_score;
$html_result .= ' | ';
//Exam fail
$html_result .= '';
$html_result .= $fail = $taken - $total_with_parameter_score;
$global_row[]= $fail;
$html_result .= ' | ';
$html_result .= '';
$html_result .= $total_students;
$global_row[]= $total_students;
$global_counter++;
$html_result .= ' | ';
$html_result .= '';
$export_array_global[] = $global_row;
$global_row = array();
}
}
} else {
$html_result .= "
".get_lang('NoExercise')."
|
";
}
} else {
$html_result .= "
".get_lang('NoExercise')."
|
";
}
}
$html_result .= '
';
if (!$export_to_xls) {
echo $html_result;
}
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($export_to_xls) {
if ($global) {
export_complete_report_xls($filename, $export_array_global);
} else {
export_complete_report_xls($filename, $export_array);
}
exit;
}
function sort_user($a, $b) {
if (is_numeric($a['score']) && is_numeric($b['score'])) {
//echo $a['score'].' : '.$b['score']; echo '