123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- <?php
- /* For licensing terms, see /license.txt */
- require_once __DIR__.'/../inc/global.inc.php';
- api_block_anonymous_users();
- $is_allowedToTrack = api_is_platform_admin(true, true) ||
- api_is_teacher() || api_is_course_tutor();
- if (!$is_allowedToTrack) {
- api_not_allowed(true);
- exit;
- }
- // the section (for the tabs)
- $this_section = SECTION_TRACKING;
- $quote_simple = "'";
- $userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0;
- $userInfo = api_get_user_info($userId);
- if (empty($userInfo)) {
- api_not_allowed(true);
- }
- /**
- * @param string $dateTime
- * @param bool $showTime
- *
- * @return string
- */
- function customDate($dateTime, $showTime = false)
- {
- $format = 'd/m/Y';
- if ($showTime) {
- $format = 'd/m/Y H:i:s';
- }
- $dateTime = api_get_local_time(
- $dateTime,
- null,
- null,
- true,
- false,
- true,
- $format
- );
- return $dateTime;
- }
- $sessions = SessionManager::getSessionsFollowedByUser($userId,
- null,
- null,
- null,
- false,
- false,
- false,
- 'ORDER BY s.access_end_date'
- );
- $startDate = '';
- $endDate = '';
- if (!empty($sessions)) {
- foreach ($sessions as $session) {
- $startDate = customDate($session['access_start_date']);
- $endDate = customDate($session['access_end_date']);
- }
- }
- $form = new FormValidator(
- 'myform',
- 'get',
- api_get_self().'?user_id='.$userId,
- null,
- ['id' => 'myform']
- );
- $form->addElement('text', 'from', get_lang('From'));
- $form->addElement('text', 'to', get_lang('Until'));
- $form->addElement('hidden', 'user_id', $userId);
- $form->addRule('from', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('from', get_lang('ThisFieldIsRequired').' dd/mm/yyyy', 'callback', 'validateDate');
- $form->addRule('to', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('to', get_lang('ThisFieldIsRequired').' dd/mm/yyyy', 'callback', 'validateDate');
- $form->addButtonSearch(get_lang('GenerateReport'));
- /**
- * @param string $value
- *
- * @return bool
- */
- function validateDate($value)
- {
- $value = DateTime::createFromFormat('d/m/Y', $value);
- if ($value === false) {
- return false;
- }
- return true;
- }
- if ($form->validate()) {
- $values = $form->getSubmitValues();
- $from = $values['from'];
- $to = $values['to'];
- $from = DateTime::createFromFormat('d/m/Y', $from);
- $to = DateTime::createFromFormat('d/m/Y', $to);
- $from = api_get_utc_datetime($from->format('Y-m-d'));
- $to = api_get_utc_datetime($to->format('Y-m-d'));
- $sessionCategories = UserManager::get_sessions_by_category($userId, false);
- $report = [];
- $minLogin = 0;
- $maxLogin = 0;
- $totalDuration = 0;
- foreach ($sessionCategories as $category) {
- foreach ($category['sessions'] as $session) {
- $sessionId = $session['session_id'];
- $courseList = $session['courses'];
- foreach ($courseList as $course) {
- $courseInfo = api_get_course_info_by_id($course['real_id']);
- $result = MySpace::get_connections_to_course_by_date(
- $userId,
- $courseInfo,
- $sessionId,
- $from,
- $to
- );
- $partialDuration = 0;
- foreach ($result as $item) {
- $record = [
- customDate($item['login'], true),
- customDate($item['logout'], true),
- api_format_time($item['duration'], 'js'),
- ];
- $totalDuration += $item['duration'];
- if (empty($minLogin)) {
- $minLogin = api_strtotime($item['login'], 'UTC');
- }
- if ($minLogin > api_strtotime($item['login'], 'UTC')) {
- $minLogin = api_strtotime($item['login'], 'UTC');
- }
- if (api_strtotime($item['logout']) > $maxLogin) {
- $maxLogin = api_strtotime($item['logout'], 'UTC');
- }
- // Partials
- $partialDuration += $item['duration'];
- $report[$sessionId]['courses'][$course['real_id']][] = $record;
- $report[$sessionId]['name'][$course['real_id']] = $courseInfo['title'].' ('.$session['session_name'].')';
- }
- if (!empty($result)) {
- $record = [
- '',
- '',
- api_format_time($partialDuration, 'js'),
- ];
- $report[$sessionId]['courses'][$course['real_id']][] = $record;
- $report[$sessionId]['name'][$course['real_id']] = $courseInfo['title'].' ('.$session['session_name'].')';
- }
- }
- }
- }
- $courses = CourseManager::returnCourses($userId);
- $courses = array_merge($courses['in_category'], $courses['not_category']);
- foreach ($courses as $course) {
- $result = MySpace::get_connections_to_course_by_date(
- $userId,
- $course,
- 0,
- $from,
- $to
- );
- $partialDuration = 0;
- foreach ($result as $item) {
- $record = [
- customDate($item['login'], true),
- customDate($item['logout'], true),
- api_format_time($item['duration'], 'js'),
- ];
- $report[0]['courses'][$course['course_id']][] = $record;
- $report[0]['name'][$course['course_id']] = $course['title'];
- $totalDuration += $item['duration'];
- if (empty($minLogin)) {
- $minLogin = api_strtotime($item['login'], 'UTC');
- }
- if ($minLogin > api_strtotime($item['login'], 'UTC')) {
- $minLogin = api_strtotime($item['login'], 'UTC');
- }
- if (api_strtotime($item['logout'], 'UTC') > $maxLogin) {
- $maxLogin = api_strtotime($item['logout'], 'UTC');
- }
- // Partials
- $partialDuration += $item['duration'];
- }
- if (!empty($result)) {
- $record = [
- '',
- '',
- api_format_time($partialDuration, 'js'),
- ];
- $report[0]['courses'][$course['course_id']][] = $record;
- $report[0]['name'][$course['course_id']] = $course['title'];
- }
- }
- $table = new HTML_Table(['class' => 'data_table']);
- $headers = [
- get_lang('MinStartDate'),
- get_lang('MaxEndDate'),
- get_lang('TotalDuration'),
- ];
- $row = 0;
- $column = 0;
- foreach ($headers as $header) {
- $table->setHeaderContents($row, $column, $header);
- $column++;
- }
- $row++;
- $column = 0;
- $table->setCellContents($row, $column++, customDate($minLogin));
- $table->setCellContents($row, $column++, customDate($maxLogin));
- $table->setRowAttributes($row, ['style' => 'font-weight:bold']);
- $table->setCellContents($row, $column++, api_format_time($totalDuration, 'js'));
- $totalTable = Display::page_subheader3(sprintf(get_lang('ExtractionFromX'), api_get_local_time()));
- $totalTable .= $table->toHtml();
- $courseSessionTable = '';
- $courseSessionTableData = [];
- foreach ($report as $sessionId => $data) {
- foreach ($data['courses'] as $courseId => $courseData) {
- $courseSessionTable .= Display::page_subheader3($data['name'][$courseId]);
- $table = new HTML_Table(['class' => 'data_table']);
- $headers = [
- get_lang('StartDate'),
- get_lang('EndDate'),
- get_lang('Duration'),
- ];
- $row = 0;
- $column = 0;
- foreach ($headers as $header) {
- $table->setHeaderContents($row, $column, $header);
- $column++;
- }
- $row++;
- $countData = count($courseData);
- foreach ($courseData as $record) {
- $column = 0;
- foreach ($record as $item) {
- $table->setCellContents($row, $column++, $item);
- if ($row == $countData) {
- $courseSessionTableData[$data['name'][$courseId]] = $item;
- $table->setRowAttributes($row, ['style' => 'font-weight:bold']);
- }
- }
- $row++;
- }
- $courseSessionTable .= $table->toHtml();
- }
- }
- $table = new HTML_Table(['class' => 'data_table']);
- $headers = [
- get_lang('Course'),
- get_lang('TotalDuration'),
- ];
- $row = 0;
- $column = 0;
- foreach ($headers as $header) {
- $table->setHeaderContents($row, $column, $header);
- $column++;
- }
- $row++;
- foreach ($courseSessionTableData as $name => $duration) {
- $column = 0;
- $table->setCellContents($row, $column++, $name);
- $table->setCellContents($row, $column++, $duration);
- $row++;
- }
- $totalCourseSessionTable = $table->toHtml();
- $tpl = new Template('', false, false, false, true, false, false);
- $tpl->assign('title', get_lang('RealisationCertificate'));
- $tpl->assign('student', $userInfo['complete_name']);
- $tpl->assign('table_progress', $totalTable.$totalCourseSessionTable.'<pagebreak>'.$courseSessionTable);
- $content = $tpl->fetch($tpl->get_template('my_space/pdf_export_student.tpl'));
- $params = [
- 'pdf_title' => get_lang('Resume'),
- //'session_info' => $sessionInfo,
- 'course_info' => '',
- 'pdf_date' => '',
- 'student_info' => $userInfo,
- 'show_grade_generated_date' => true,
- 'show_real_course_teachers' => false,
- 'show_teacher_as_myself' => false,
- 'orientation' => 'P',
- ];
- @$pdf = new PDF('A4', $params['orientation'], $params);
- $pdf->setBackground($tpl->theme);
- @$pdf->content_to_pdf(
- $content,
- '',
- '',
- null,
- 'D',
- false,
- null,
- false,
- true,
- false
- );
- exit;
- }
- $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')];
- Display::display_header('');
- $userInfo = api_get_user_info($userId);
- echo Display::page_header(get_lang('DetailsStudentInCourse'));
- echo Display::page_subheader(
- get_lang('User').': '.$userInfo['complete_name']
- );
- $form->setDefaults(['from' => $startDate, 'to' => $endDate]);
- $form->display();
- Display::display_footer();
|