| Línea 41... |
Línea 41... |
| 41 |
|
41 |
|
| 42 |
$context = context_user::instance($USER->id);
|
42 |
$context = context_user::instance($USER->id);
|
| Línea 43... |
Línea 43... |
| 43 |
require_capability('report/usersessions:manageownsessions', $context);
|
43 |
require_capability('report/usersessions:manageownsessions', $context);
|
| - |
|
44 |
|
| - |
|
45 |
$delete = optional_param('delete', 0, PARAM_INT);
|
| Línea 44... |
Línea 46... |
| 44 |
|
46 |
$deleteall = optional_param('deleteall', false, PARAM_BOOL);
|
| 45 |
$delete = optional_param('delete', 0, PARAM_INT);
|
47 |
$lastip = cleanremoteaddr(optional_param('lastip', '', PARAM_TEXT));
|
| 46 |
|
48 |
|
| 47 |
$PAGE->set_url('/report/usersessions/user.php');
|
49 |
$PAGE->set_url('/report/usersessions/user.php');
|
| 48 |
$PAGE->set_context($context);
|
50 |
$PAGE->set_context($context);
|
| Línea -... |
Línea 51... |
| - |
|
51 |
$PAGE->set_title(get_string('navigationlink', 'report_usersessions'));
|
| 49 |
$PAGE->set_title(get_string('navigationlink', 'report_usersessions'));
|
52 |
$PAGE->set_heading(fullname($USER));
|
| 50 |
$PAGE->set_heading(fullname($USER));
|
53 |
$PAGE->set_pagelayout('admin');
|
| - |
|
54 |
|
| 51 |
$PAGE->set_pagelayout('admin');
|
55 |
// Delete a specific session.
|
| - |
|
56 |
if ($delete && confirm_sesskey()) {
|
| - |
|
57 |
report_usersessions_kill_session($delete);
|
| - |
|
58 |
redirect(
|
| - |
|
59 |
url: $PAGE->url,
|
| - |
|
60 |
message: get_string('logoutsinglesessionsuccess', 'report_usersessions', $lastip),
|
| - |
|
61 |
messagetype: \core\output\notification::NOTIFY_SUCCESS,
|
| - |
|
62 |
);
|
| - |
|
63 |
}
|
| - |
|
64 |
|
| - |
|
65 |
// Delete all sessions except current.
|
| - |
|
66 |
if ($deleteall && confirm_sesskey()) {
|
| - |
|
67 |
\core\session\manager::destroy_user_sessions($USER->id, session_id());
|
| - |
|
68 |
redirect(
|
| 52 |
|
69 |
url: $PAGE->url,
|
| Línea 53... |
Línea 70... |
| 53 |
if ($delete and confirm_sesskey()) {
|
70 |
message: get_string('logoutothersessionssuccess', 'report_usersessions'),
|
| 54 |
report_usersessions_kill_session($delete);
|
71 |
messagetype: \core\output\notification::NOTIFY_SUCCESS,
|
| 55 |
redirect($PAGE->url);
|
72 |
);
|
| Línea 63... |
Línea 80... |
| 63 |
|
80 |
|
| 64 |
echo $OUTPUT->header();
|
81 |
echo $OUTPUT->header();
|
| Línea 65... |
Línea 82... |
| 65 |
echo $OUTPUT->heading(get_string('mysessions', 'report_usersessions'));
|
82 |
echo $OUTPUT->heading(get_string('mysessions', 'report_usersessions'));
|
| 66 |
|
83 |
|
| 67 |
$data = array();
|
84 |
$data = array();
|
| 68 |
$sql = "SELECT id, timecreated, timemodified, firstip, lastip, sid
|
85 |
$sessions = \core\session\manager::get_sessions_by_userid($USER->id);
|
| 69 |
FROM {sessions}
|
86 |
// Order records by timemodified DESC.
|
| 70 |
WHERE userid = :userid
|
- |
|
| 71 |
ORDER BY timemodified DESC";
|
87 |
usort($sessions, function($a, $b){
|
| 72 |
$params = array('userid' => $USER->id, 'sid' => session_id());
|
- |
|
| 73 |
|
88 |
return $b->timemodified <=> $a->timemodified;
|
| 74 |
$sessions = $DB->get_records_sql($sql, $params);
|
89 |
});
|
| 75 |
foreach ($sessions as $session) {
|
90 |
foreach ($sessions as $session) {
|
| 76 |
if ($session->sid === $params['sid']) {
|
91 |
if ($session->sid === session_id()) {
|
| Línea 77... |
Línea 92... |
| 77 |
$lastaccess = get_string('thissession', 'report_usersessions');
|
92 |
$lastaccess = get_string('thissession', 'report_usersessions');
|
| 78 |
$deletelink = '';
|
93 |
$deletelink = '';
|
| 79 |
|
94 |
|
| 80 |
} else {
|
95 |
} else {
|
| 81 |
$lastaccess = report_usersessions_format_duration(time() - $session->timemodified);
|
96 |
$lastaccess = report_usersessions_format_duration(time() - $session->timemodified);
|
| 82 |
$url = new moodle_url($PAGE->url, array('delete' => $session->id, 'sesskey' => sesskey()));
|
97 |
$url = new moodle_url($PAGE->url, ['delete' => $session->id, 'sesskey' => sesskey(), 'lastip' => $session->lastip]);
|
| 83 |
$deletelink = html_writer::link($url, get_string('logout'));
|
98 |
$deletelink = html_writer::link($url, get_string('logout'));
|
| Línea 89... |
Línea 104... |
| 89 |
$table->head = array(get_string('login'), get_string('lastaccess'), get_string('lastip'), get_string('action'));
|
104 |
$table->head = array(get_string('login'), get_string('lastaccess'), get_string('lastip'), get_string('action'));
|
| 90 |
$table->align = array('left', 'left', 'left', 'right');
|
105 |
$table->align = array('left', 'left', 'left', 'right');
|
| 91 |
$table->data = $data;
|
106 |
$table->data = $data;
|
| 92 |
echo html_writer::table($table);
|
107 |
echo html_writer::table($table);
|
| Línea -... |
Línea 108... |
| - |
|
108 |
|
| 93 |
|
109 |
// Provide button to log out all other sessions.
|
| - |
|
110 |
if (count($sessions) > 1) {
|
| - |
|
111 |
$url = new moodle_url($PAGE->url, ['deleteall' => true]);
|
| - |
|
112 |
echo $OUTPUT->single_button($url, get_string('logoutothersessions', 'report_usersessions'));
|
| Línea -... |
Línea 113... |
| - |
|
113 |
}
|