diff --git a/main/attendance/attendance_controller.php b/main/attendance/attendance_controller.php
index 6d35d5efec..6e3479e67f 100755
--- a/main/attendance/attendance_controller.php
+++ b/main/attendance/attendance_controller.php
@@ -536,10 +536,46 @@ class AttendanceController
'pdf_teachers' => $teacherName,
'pdf_course_category' => $courseCategory['name'],
'format' => 'A4-L',
- 'orientation' => 'L'
+ 'orientation' => 'L'
);
Export::export_html_to_pdf($content, $params);
exit;
}
+
+ /**
+ * Gets attendace base in the table:
+ * TABLE_STATISTIC_TRACK_E_COURSE_ACCESS
+ * @throws ViewException
+ */
+ public function calendarLogins()
+ {
+ $form = new FormValidator(
+ 'search',
+ 'post',
+ api_get_self().'?'.api_get_cidreq().'&action=calendar_logins'
+ );
+ $form->addDateRangePicker('range', get_lang('Range'));
+ $form->add_button('submit', get_lang('submit'));
+ $table = null;
+
+ if ($form->validate()) {
+ $values = $form->getSubmitValues();
+
+ $startDate = api_get_utc_datetime($values['range_start']);
+ $endDate = api_get_utc_datetime($values['range_end']);
+
+ $attendance = new Attendance();
+ $table = $attendance->getAttendanceLogins($startDate, $endDate);
+ }
+
+ $data = array(
+ 'form' => $form->return_form(),
+ 'table' => $table
+ );
+ $this->view->set_data($data);
+ $this->view->set_layout('layout');
+ $this->view->set_template('calendar_logins');
+ $this->view->render();
+ }
}
diff --git a/main/attendance/attendance_list.php b/main/attendance/attendance_list.php
index f871895e89..772b548abe 100755
--- a/main/attendance/attendance_list.php
+++ b/main/attendance/attendance_list.php
@@ -16,7 +16,12 @@ if (api_is_allowed_to_edit(null, true)) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
echo '
';
}
$attendance = new Attendance();
diff --git a/main/attendance/calendar_logins.php b/main/attendance/calendar_logins.php
new file mode 100644
index 0000000000..bfb44b1705
--- /dev/null
+++ b/main/attendance/calendar_logins.php
@@ -0,0 +1,11 @@
+';
+echo ''.
+ Display::return_icon('back.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).'';
+echo '';
+
+echo $form;
+echo $table;
diff --git a/main/attendance/index.php b/main/attendance/index.php
index 12c6bab4b6..94f2b69917 100755
--- a/main/attendance/index.php
+++ b/main/attendance/index.php
@@ -48,7 +48,8 @@ $actions = array(
'attendance_delete_select',
'attendance_restore',
'attendance_sheet_export_to_pdf',
- 'attendance_sheet_list_no_edit'
+ 'attendance_sheet_list_no_edit',
+ 'calendar_logins'
);
$actions_calendar = array(
@@ -303,6 +304,11 @@ switch ($action) {
case 'calendar_list' :
$attendance_controller->attendance_calendar($action, $attendance_id, $calendar_id);
break;
+ case 'calendar_logins':
+ if (api_is_allowed_to_edit(null, true)) {
+ $attendance_controller->calendarLogins();
+ }
+ break;
default :
$attendance_controller->attendance_list();
}
diff --git a/main/inc/lib/attendance.lib.php b/main/inc/lib/attendance.lib.php
index 4eb5cef78a..d09a875ec1 100755
--- a/main/inc/lib/attendance.lib.php
+++ b/main/inc/lib/attendance.lib.php
@@ -1483,4 +1483,101 @@ class Attendance
{
return $this->attendance_weight;
}
+
+ /**
+ * @param string $startDate in UTC time
+ * @param string $endDate in UTC time
+ *
+ * @return string
+ */
+ public function getAttendanceLogins($startDate, $endDate)
+ {
+ $sessionId = api_get_session_id();
+ $courseCode = api_get_course_id();
+ if (!empty($sessionId)) {
+ $users = CourseManager:: get_user_list_from_course_code(
+ $courseCode,
+ $sessionId,
+ '',
+ 'lastname'
+ );
+ } else {
+ $users = CourseManager:: get_user_list_from_course_code(
+ $courseCode,
+ 0,
+ '',
+ 'lastname'
+ );
+ }
+
+ $dateTimeStartOriginal = new DateTime($startDate);
+ $dateTimeStart = new DateTime($startDate);
+ $dateTimeEnd= new DateTime($endDate);
+ $interval = $dateTimeStart->diff($dateTimeEnd);
+ $days = intval($interval->format('%a'));
+
+ $dateList = array($dateTimeStart->format('Y-m-d'));
+ $headers = array(
+ get_lang('User'),
+ $dateTimeStart->format('Y-m-d')
+ );
+
+ for ($i = 0; $i < $days; $i++) {
+ $dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
+ $date = $dateTimeStart->format('Y-m-d');
+ $dateList[] = $date;
+ $headers[] = $date;
+ }
+
+ $accessData = CourseManager::getCourseAccessPerCourseAndSession(
+ $courseCode,
+ $sessionId,
+ $dateTimeStartOriginal->format('Y-m-d H:i:s'),
+ $dateTimeEnd->format('Y-m-d H:i:s')
+ );
+
+ $results = array();
+ if (!empty($accessData)) {
+ foreach ($accessData as $data) {
+ $onlyDate = substr($data['login_course_date'], 0, 10);
+ $results[$data['user_id']][$onlyDate] = true;
+ }
+ }
+
+ $table = new HTML_Table(array('class' => 'data_table'));
+ $row = 0;
+ $column = 0;
+ foreach ($headers as $header) {
+ $table->setHeaderContents($row, $column, $header);
+ $column++;
+ }
+ $row = 1;
+ foreach ($users as $user) {
+ $table->setCellContents(
+ $row,
+ 0,
+ $user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
+ );
+ $row ++;
+ }
+
+ $column = 1;
+ $row = 1;
+ foreach ($users as $user) {
+ foreach ($dateList as $date) {
+ $status = null;
+ if (isset($results[$user['user_id']]) &&
+ isset($results[$user['user_id']][$date])
+ ) {
+ $status = 'X';
+ }
+ $table->setCellContents($row, $column, $status);
+ $column++;
+ }
+ $row++;
+ $column = 1;
+ }
+
+ return $table->toHtml();
+ }
}
diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php
index a57e70b365..fcba4c1fa8 100755
--- a/main/inc/lib/course.lib.php
+++ b/main/inc/lib/course.lib.php
@@ -1382,7 +1382,6 @@ class CourseManager
// if the $order_by does not contain 'ORDER BY' we have to check if it is a valid field that can be sorted on
if (!strstr($order_by,'ORDER BY')) {
- $order_by = Database::escape_string($order_by);
if (!empty($order_by)) {
$order_by = 'ORDER BY '.$order_by;
} else {
@@ -1415,7 +1414,6 @@ class CourseManager
if (SessionManager::orderCourseIsEnabled()) {
//$order_by = "ORDER BY position";
}
-
} else {
if ($return_count) {
$sql = " SELECT COUNT(*) as count";
@@ -1424,9 +1422,21 @@ class CourseManager
}
} else {
if (empty($course_code)) {
- $sql = 'SELECT DISTINCT course.title, course.code, course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.* ';
+ $sql = 'SELECT DISTINCT
+ course.title,
+ course.code,
+ course_rel_user.status as status_rel,
+ user.user_id,
+ course_rel_user.role,
+ course_rel_user.tutor_id,
+ user.* ';
} else {
- $sql = 'SELECT DISTINCT course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.* ';
+ $sql = 'SELECT DISTINCT
+ course_rel_user.status as status_rel,
+ user.user_id,
+ course_rel_user.role,
+ course_rel_user.tutor_id,
+ user.* ';
}
}
@@ -1490,6 +1500,7 @@ class CourseManager
}
$sql .= ' '.$order_by.' '.$limit;
+
$rs = Database::query($sql);
$users = array();
@@ -5055,6 +5066,10 @@ class CourseManager
public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null)
{
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
+
+ $sessionId = intval($sessionId);
+ $userId = intval($userId);
+
$sql = "SELECT * FROM $table
WHERE session_id = $sessionId AND user_id = $userId";
@@ -5067,6 +5082,38 @@ class CourseManager
return Database::store_result($result);
}
+ /**
+ * Get information from the track_e_course_access table
+ * @param string $courseCode
+ * @param int $sessionId
+ * @param string $startDate
+ * @param string $endDate
+ * @return array
+ */
+ public static function getCourseAccessPerCourseAndSession(
+ $courseCode,
+ $sessionId,
+ $startDate,
+ $endDate
+ ) {
+ $table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
+ $courseCode = Database::escape_string($courseCode);
+ $sessionId = intval($sessionId);
+ $startDate = Database::escape_string($startDate);
+ $endDate = Database::escape_string($endDate);
+
+ $sql = "SELECT * FROM $table
+ WHERE
+ course_code = $courseCode AND
+ session_id = $sessionId AND
+ login_course_date BETWEEN $startDate AND $endDate
+ ";
+
+ $result = Database::query($sql);
+
+ return Database::store_result($result);
+ }
+
/**
* Get login information from the track_e_course_access table, for any
* course in the given session
@@ -5076,6 +5123,9 @@ class CourseManager
*/
public static function getFirstCourseAccessPerSessionAndUser($sessionId, $userId)
{
+ $sessionId = intval($sessionId);
+ $userId = intval($userId);
+
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sql = "SELECT * FROM $table
WHERE session_id = $sessionId AND user_id = $userId