Skip to content

Commit

Permalink
Add new login/logou access report see BT#15826
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jul 17, 2019
1 parent 94c2959 commit 327bf12
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 43 deletions.
3 changes: 2 additions & 1 deletion main/inc/lib/course.lib.php
Expand Up @@ -3750,7 +3750,7 @@ public static function returnCoursesCategories(
$sql .= " AND access_url_id = $current_url_id";
}
// Use user's classification for courses (if any).
$sql .= " ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC";
$sql .= ' ORDER BY course_rel_user.user_course_cat, course_rel_user.sort ASC';
$result = Database::query($sql);

$showCustomIcon = api_get_setting('course_images_in_courses_list');
Expand Down Expand Up @@ -3866,6 +3866,7 @@ public static function returnCoursesCategories(
$params['category'] = $course_info['categoryName'];
$params['category_code'] = $course_info['categoryCode'];
$params['teachers'] = $teachers;
$params['real_id'] = $course_info['real_id'];

if ($course_info['visibility'] != COURSE_VISIBILITY_CLOSED) {
$params['notifications'] = $showNotification;
Expand Down
1 change: 1 addition & 0 deletions main/inc/lib/myspace.lib.php
Expand Up @@ -2992,6 +2992,7 @@ public static function get_connections_to_course_by_date(
$connections[] = [
'login' => $row['login_course_date'],
'logout' => $row['logout_course_date'],
'duration' => $row['duration'],
];
}
}
Expand Down
26 changes: 26 additions & 0 deletions main/inc/lib/pdf.lib.php
Expand Up @@ -990,4 +990,30 @@ private static function fixImagesPaths($documentHtml, array $courseInfo, $dirNam

return $doc->saveHTML();
}

/**
* @param string $theme
*
* @throws MpdfException
*/
public function setBackground($theme)
{
$themeName = empty($theme) ? api_get_visual_theme() : $theme;
$themeDir = \Template::getThemeDir($themeName);
$customLetterhead = $themeDir.'images/letterhead.png';
$urlPathLetterhead = api_get_path(SYS_CSS_PATH).$customLetterhead;

$urlWebLetterhead = '#FFFFFF';
$fullPage = false;
if (file_exists($urlPathLetterhead)) {
$fullPage = true;
$urlWebLetterhead = 'url('.api_get_path(WEB_CSS_PATH).$customLetterhead.')';
}

if ($fullPage) {
$this->pdf->SetDisplayMode('fullpage');
$this->pdf->SetDefaultBodyCSS('background', $urlWebLetterhead);
$this->pdf->SetDefaultBodyCSS('background-image-resize', '6');
}
}
}
10 changes: 4 additions & 6 deletions main/mySpace/access_details.php
Expand Up @@ -30,9 +30,8 @@
// the section (for the tabs)
$this_section = SECTION_TRACKING;

/* MAIN */
$user_id = intval($_REQUEST['student']);
$session_id = intval($_GET['id_session']);
$user_id = isset($_REQUEST['student']) ? (int) $_REQUEST['student'] : 0;
$session_id = (int) $_GET['id_session'];
$type = isset($_REQUEST['type']) ? Security::remove_XSS($_REQUEST['type']) : '';
$course_code = isset($_REQUEST['course']) ? Security::remove_XSS($_REQUEST['course']) : '';
$courseInfo = api_get_course_info($course_code);
Expand Down Expand Up @@ -127,10 +126,9 @@ function loadGraph() {
});
</script>';

//Changes END
$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')];

Display :: display_header('');
Display::display_header('');
$userInfo = api_get_user_info($user_id);
$result_to_print = '';
$sql_result = MySpace::get_connections_to_course($user_id, $courseInfo);
Expand Down Expand Up @@ -178,4 +176,4 @@ function loadGraph() {
</div>

<?php
Display:: display_footer();
Display::display_footer();
258 changes: 258 additions & 0 deletions main/mySpace/access_details_session.php
@@ -0,0 +1,258 @@
<?php
/* For licensing terms, see /license.txt */

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();

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);
}

$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 = api_get_local_time(
$session['access_start_date'],
null,
null,
true,
false
);
$endDate = api_get_local_time(
$session['access_end_date'],
null,
null,
true,
false
);
}
}

$form = new FormValidator(
'myform',
'get',
api_get_self().'?user_id='.$userId,
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(
'select',
'type',
get_lang('Type'),
['day' => get_lang('Day'), 'month' => get_lang('Month')],
['id' => 'type']
);*/
$form->addElement('hidden', 'user_id', $userId);
$form->addRule('from', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('to', get_lang('ThisFieldIsRequired'), 'required');
$form->addButtonSearch(get_lang('Search'));

if ($form->validate()) {
$values = $form->getSubmitValues();
$from = $values['from'];
$to = $values['to'];
$sessionCategories = UserManager::get_sessions_by_category($userId, false);

$sessionCourseList = [];
$report = [];
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,
$course,
$sessionId,
$from,
$to
);

foreach ($result as $item) {
$record = [
$courseInfo['name'],
$session['session_name'],
api_get_local_time($item['login']),
api_get_local_time($item['logout']),
api_format_time($item['duration'], 'js'),
];
$report[] = $record;
}
}
}
}

$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
);

foreach ($result as $item) {
$record = [
$courseInfo['name'],
'',
api_get_local_time($item['login']),
api_get_local_time($item['logout']),
api_format_time($item['duration'], 'js'),
];
$report[] = $record;
}
}

$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);
}
$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());
$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;
}
$htmlHeadXtra[] = "<script>
$(function() {
var dates = $('#date_from, #date_to').datepicker({
dateFormat: ".$quote_simple."yy-mm-dd".$quote_simple.",
changeMonth: true,
changeYear: true
});
});
</script>";

$interbreadcrumb[] = ['url' => '#', 'name' => get_lang('AccessDetails')];

Display::display_header('');
$userInfo = api_get_user_info($user_id);
$result_to_print = '';
//$sql_result = MySpace::get_connections_to_course($user_id, $courseInfo);
//$result_to_print = convert_to_string($sql_result);

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();
?>
<br />
<br />
<div class="text-center" id="graph"></div>
<br />
<br />
<div class="row">
<div id="cev_results" class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6">
<div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<?php echo get_lang('Statistics'); ?>
</div><br />
<div id="cev_cont_stats">
<?php
if ($result_to_print != '') {
$rst = get_stats($user_id, $courseInfo, $session_id);
$foo_stats = '<strong>'.get_lang('Total').': </strong>'.$rst['total'].'<br />';
$foo_stats .= '<strong>'.get_lang('Average').': </strong>'.$rst['avg'].'<br />';
$foo_stats .= '<strong>'.get_lang('Quantity').' : </strong>'.$rst['times'].'<br />';
echo $foo_stats;
} else {
echo Display::return_message(get_lang('NoDataAvailable'), 'warning');
}
?>
</div>
<br />
</div>
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all col-md-6 col-md-6">
<div class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<?php echo get_lang('Details'); ?>
</div><br />
<div id="messages"></div>
</div>
</div>

<?php
Display::display_footer();

0 comments on commit 327bf12

Please sign in to comment.