|
@@ -5,7 +5,6 @@ require_once __DIR__.'/../inc/global.inc.php';
|
|
|
|
|
|
api_block_anonymous_users();
|
|
|
|
|
|
-// Access restrictions.
|
|
|
$is_allowedToTrack = api_is_platform_admin(true, true) ||
|
|
|
api_is_teacher() || api_is_course_tutor();
|
|
|
|
|
@@ -24,14 +23,39 @@ if (empty($userInfo)) {
|
|
|
api_not_allowed(true);
|
|
|
}
|
|
|
|
|
|
-$sessions = SessionManager::getSessionsFollowedByUser($userId,
|
|
|
- null,
|
|
|
+/**
|
|
|
+ * @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,
|
|
|
- false,
|
|
|
- false,
|
|
|
- 'ORDER BY s.access_end_date'
|
|
|
+ true,
|
|
|
+ $format
|
|
|
+ );
|
|
|
+
|
|
|
+ return $dateTime;
|
|
|
+}
|
|
|
+
|
|
|
+$sessions = SessionManager::getSessionsFollowedByUser($userId,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ false,
|
|
|
+ false,
|
|
|
+ false,
|
|
|
+ 'ORDER BY s.access_end_date'
|
|
|
);
|
|
|
|
|
|
$startDate = '';
|
|
@@ -50,33 +74,35 @@ $form = new FormValidator(
|
|
|
null,
|
|
|
['id' => 'myform']
|
|
|
);
|
|
|
-$form->addElement('text', 'from', get_lang('From'), ['id' => 'date_from']);
|
|
|
-$form->addElement('text', 'to', get_lang('Until'), ['id' => 'date_to']);
|
|
|
+$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'));
|
|
|
|
|
|
-function customDate($dateTime)
|
|
|
+/**
|
|
|
+ * @param string $value
|
|
|
+ *
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+function validateDate($value)
|
|
|
{
|
|
|
- $dateTime = api_get_local_time(
|
|
|
- $dateTime,
|
|
|
- null,
|
|
|
- null,
|
|
|
- true,
|
|
|
- false,
|
|
|
- true,
|
|
|
- 'd/m/Y'
|
|
|
- );
|
|
|
+ $value = DateTime::createFromFormat('d/m/Y', $value);
|
|
|
|
|
|
- return $dateTime;
|
|
|
+ if ($value === false) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
if ($form->validate()) {
|
|
|
$values = $form->getSubmitValues();
|
|
|
$from = $values['from'];
|
|
|
$to = $values['to'];
|
|
|
- $sessionCategories = UserManager::get_sessions_by_category($userId, false);
|
|
|
|
|
|
$from = DateTime::createFromFormat('d/m/Y', $from);
|
|
|
$to = DateTime::createFromFormat('d/m/Y', $to);
|
|
@@ -84,8 +110,9 @@ if ($form->validate()) {
|
|
|
$from = api_get_utc_datetime($from->format('Y-m-d'));
|
|
|
$to = api_get_utc_datetime($to->format('Y-m-d'));
|
|
|
|
|
|
- $sessionCourseList = [];
|
|
|
+ $sessionCategories = UserManager::get_sessions_by_category($userId, false);
|
|
|
$report = [];
|
|
|
+ $content = '';
|
|
|
foreach ($sessionCategories as $category) {
|
|
|
foreach ($category['sessions'] as $session) {
|
|
|
$sessionId = $session['session_id'];
|
|
@@ -94,7 +121,7 @@ if ($form->validate()) {
|
|
|
$courseInfo = api_get_course_info_by_id($course['real_id']);
|
|
|
$result = MySpace::get_connections_to_course_by_date(
|
|
|
$userId,
|
|
|
- $course,
|
|
|
+ $courseInfo,
|
|
|
$sessionId,
|
|
|
$from,
|
|
|
$to
|
|
@@ -102,13 +129,13 @@ if ($form->validate()) {
|
|
|
|
|
|
foreach ($result as $item) {
|
|
|
$record = [
|
|
|
- $courseInfo['title'],
|
|
|
- $session['session_name'],
|
|
|
- customDate($item['login']),
|
|
|
- customDate($item['logout']),
|
|
|
+ //$courseInfo['title'],
|
|
|
+ customDate($item['login'], true),
|
|
|
+ customDate($item['logout'], true),
|
|
|
api_format_time($item['duration'], 'js'),
|
|
|
];
|
|
|
- $report[] = $record;
|
|
|
+ $report[$sessionId]['courses'][$course['real_id']][] = $record;
|
|
|
+ $report[$sessionId]['name'][$course['real_id']] = $courseInfo['title'].' ('.$session['session_name'].')';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -128,43 +155,48 @@ if ($form->validate()) {
|
|
|
|
|
|
foreach ($result as $item) {
|
|
|
$record = [
|
|
|
- $course['title'],
|
|
|
- '',
|
|
|
- customDate($item['login']),
|
|
|
- customDate($item['logout']),
|
|
|
+ customDate($item['login'], true),
|
|
|
+ customDate($item['logout'], true),
|
|
|
api_format_time($item['duration'], 'js'),
|
|
|
];
|
|
|
- $report[] = $record;
|
|
|
+ $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('Course'),
|
|
|
- get_lang('Session'),
|
|
|
- get_lang('StartDate'),
|
|
|
- get_lang('EndDate'),
|
|
|
- get_lang('Duration'),
|
|
|
- ];
|
|
|
- $row = 0;
|
|
|
- $column = 0;
|
|
|
- foreach ($headers as $header) {
|
|
|
- $table->setHeaderContents($row, $column, $header);
|
|
|
- $column++;
|
|
|
- }
|
|
|
- $row++;
|
|
|
- foreach ($report as $record) {
|
|
|
- $column = 0;
|
|
|
- foreach ($record as $item) {
|
|
|
- $table->setCellContents($row, $column++, $item);
|
|
|
+ foreach ($report as $sessionId => $data) {
|
|
|
+ foreach ($data['courses'] as $courseId => $courseData) {
|
|
|
+ $content .= Display::page_subheader3($data['name'][$courseId]);
|
|
|
+ $table = new HTML_Table(['class' => 'data_table']);
|
|
|
+ $headers = [
|
|
|
+ //get_lang('Course'),
|
|
|
+ get_lang('StartDate'),
|
|
|
+ get_lang('EndDate'),
|
|
|
+ get_lang('Duration'),
|
|
|
+ ];
|
|
|
+ $row = 0;
|
|
|
+ $column = 0;
|
|
|
+ foreach ($headers as $header) {
|
|
|
+ $table->setHeaderContents($row, $column, $header);
|
|
|
+ $column++;
|
|
|
+ }
|
|
|
+ $row++;
|
|
|
+ foreach ($courseData as $record) {
|
|
|
+ $column = 0;
|
|
|
+ foreach ($record as $item) {
|
|
|
+ $table->setCellContents($row, $column++, $item);
|
|
|
+ }
|
|
|
+ $row++;
|
|
|
+ }
|
|
|
+ $content .= $table->toHtml();
|
|
|
}
|
|
|
- $row++;
|
|
|
}
|
|
|
|
|
|
$tpl = new Template('', false, false, false, true, false, false);
|
|
|
$tpl->assign('title', get_lang('AttestationOfAttendance'));
|
|
|
$tpl->assign('student', $userInfo['complete_name']);
|
|
|
- $tpl->assign('table_progress', $table->toHtml());
|
|
|
+ $tpl->assign('table_progress', $content);
|
|
|
+
|
|
|
$content = $tpl->fetch($tpl->get_template('my_space/pdf_export_student.tpl'));
|
|
|
$params = [
|
|
|
'pdf_title' => get_lang('Resume'),
|
|
@@ -178,7 +210,7 @@ if ($form->validate()) {
|
|
|
'orientation' => 'P',
|
|
|
];
|
|
|
|
|
|
- $pdf = @new PDF('A4', $params['orientation'], $params);
|
|
|
+ @$pdf = new PDF('A4', $params['orientation'], $params);
|
|
|
|
|
|
$pdf->setBackground($tpl->theme);
|
|
|
@$pdf->content_to_pdf(
|