addElement('select', 'session_id', get_lang('Sessions'), $my_session_list);
$form->addElement('style_submit_button','submit',get_lang('Filter'));
if (!empty($_REQUEST['score'])) $filter_score = intval($_REQUEST['score']); else $filter_score = 70;
if (!empty($_REQUEST['session_id'])) $session_id = intval($_REQUEST['session_id']); else $session_id = 0;
if (empty($session_id)) {
$session_id = key($my_session_list);
}
$form->setDefaults(array('session_id'=>$session_id));
$course_list = SessionManager::get_course_list_by_session_id($session_id);
if (!$export_to_xls) {
Display :: display_header(get_lang("MySpace"));
echo '
';
if ($global) {
$menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
$menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher');
$menu_items[] = Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32);
$menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
$nb_menu_items = count($menu_items);
if($nb_menu_items>1) {
foreach($menu_items as $key=> $item) {
echo $item;
}
echo '
';
}
} else {
echo '
';
}
echo '
';
if (api_is_platform_admin()) {
echo ''.get_lang('DisplayCoaches').' | ';
echo ''.get_lang('DisplayUserOverview').'';
echo ' | '.get_lang('DisplaySessionOverview').'';
echo ' | '.get_lang('DisplayCourseOverview').'';
echo ' | '.get_lang('LPQuestionListResults').'';
echo ' | '.get_lang('LPExerciseResultsBySession').'';
}
echo ''.get_lang('LPExerciseResultsBySession').'
';
$form->display();
Display::display_normal_message(get_lang('StudentScoreAverageIsCalculatedBaseInAllLPsAndAllAttempts'));
}
$users = SessionManager::get_users_by_session($session_id);
$course_average = $course_average_counter = array();
$counter = 0;
$main_result = array();
//Getting course list
foreach ($course_list as $current_course ) {
$course_info = api_get_course_info($current_course['code']);
$_course = $course_info;
$attempt_result = array();
//Getting LP list
$list = new LearnpathList('', $current_course['code'], $session_id);
$lp_list = $list->get_flat_list();
// Looping LPs
foreach ($lp_list as $lp_id =>$lp) {
$exercise_list = ExerciseLib::get_all_exercises_from_lp($lp_id, $course_info['real_id']);
//Looping Chamilo Exercises in LP
foreach ($exercise_list as $exercise) {
$exercise_stats = get_all_exercise_event_from_lp($exercise['path'], $course_info['real_id'], $session_id);
//Looping Exercise Attempts
foreach($exercise_stats as $stats) {
$attempt_result[$stats['exe_user_id']]['result'] += $stats['exe_result'] / $stats['exe_weighting'];
$attempt_result[$stats['exe_user_id']]['attempts']++;
}
}
}
$main_result[$current_course['code']] = $attempt_result;
}
$total_average_score = 0;
$total_average_score_count = 0;
if (!empty($users) && is_array($users)) {
$html_result .= '';
$html_result .= ''.get_lang('User').' | ';
foreach($course_list as $item ) {
$html_result .= ''.$item['title'].' '.get_lang('AverageScore').' % | ';
}
$html_result .= ''.get_lang('AverageScore').' % | ';
$html_result .= ''.get_lang('LastConnexionDate').' |
';
foreach ($users as $user) {
$total_student = 0;
$counter ++;
$s_css_class = 'row_even';
if ($counter % 2 ==0 ) {
$s_css_class = 'row_odd';
}
$html_result .= "
";
$html_result .= $user['firstname'].' '.$user['lastname'];
$html_result .= " | ";
//Getting course list
$counter = 0;
$total_result_by_user = 0;
foreach($course_list as $current_course ) {
$total_course = 0;
$user_info_stat = $main_result[$current_course['code']][$user['user_id']];
$html_result .= "";
if (!empty($user_info_stat['result']) && !empty($user_info_stat['attempts'])) {
$result =round($user_info_stat['result']/$user_info_stat['attempts'] * 100, 2);
$total_course +=$result;
$total_result_by_user +=$result;
$course_average[$current_course['code']] += $total_course;
$course_average_counter[$current_course['code']]++;
$result = $result .' ('.$user_info_stat['attempts'].' '.get_lang('Attempts').')';
$counter++;
} else {
$result = '-';
}
$html_result .= $result;
$html_result .= " | ";
}
if (empty($counter)) {
$total_student = '-';
} else {
$total_student = $total_result_by_user/$counter;
$total_average_score+=$total_student;
$total_average_score_count++;
}
$string_date=Tracking :: get_last_connection_date($user['user_id'],true);
$html_result .="$total_student | $string_date |
";
}
$html_result .="".get_lang('AverageScore')." | ";
$total_average = 0;
$counter = 0;
foreach($course_list as $course_item) {
if (!empty($course_average_counter[$course_item['code']])) {
$average_per_course = round($course_average[$course_item['code']]/($course_average_counter[$course_item['code']]*100)*100,2);
} else {
$average_per_course = '-';
}
if (!empty($average_per_course)) {
$counter++;
}
$total_average = $total_average + $average_per_course;
$html_result .="$average_per_course | ";
}
if (!empty($total_average_score_count)) {
$total_average = round($total_average_score/($total_average_score_count*100)*100,2);
} else {
$total_average = '-';
}
$html_result .=''.$total_average.' | ';
$html_result .="- | ";
$html_result .="
";
$html_result .= '
';
} else {
Display::display_warning_message(get_lang('NoResults'));
}
if (!$export_to_xls) {
echo $html_result;
}
$filename = 'exam-reporting-'.date('Y-m-d-h:i:s').'.xls';
if ($export_to_xls) {
echo $html_result;
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 '
';
if ($a['score'] < $b['score']) {
return 1;
}
return 0;
}
return 1;
}
function export_complete_report_xls($filename, $array) {
global $charset;
$workbook = new Spreadsheet_Excel_Writer();
$workbook ->setTempDir(api_get_path(SYS_ARCHIVE_PATH));
$workbook->send($filename);
$workbook->setVersion(8); // BIFF8
$worksheet =& $workbook->addWorksheet('Report');
//$worksheet->setInputEncoding(api_get_system_encoding());
$worksheet->setInputEncoding($charset);
/*
$line = 0;
$column = 1; // Skip the first column (row titles)
foreach ($array as $elem) {
$worksheet->write($line, $column, $elem);
$column++;
}
$workbook->close();*/
exit;
}
Display :: display_footer();