141
141
global $CFG, $USER, $DB;
142
142
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
144
if (session_is_loggedinas()) {
144
if (\core\session\manager::is_loggedinas()) {
145
145
print_error('notpermittedtojumpas', 'mnet');
148
148
// check remote login permissions
149
if (! has_capability('moodle/site:mnetlogintoremote', get_system_context())
149
if (! has_capability('moodle/site:mnetlogintoremote', context_system::instance())
150
150
or is_mnet_remote_user($USER)
152
152
or !isloggedin()) {
216
216
global $CFG, $DB;
217
217
require_once $CFG->dirroot . '/mnet/xmlrpc/client.php';
218
218
require_once $CFG->libdir . '/gdlib.php';
219
require_once($CFG->dirroot.'/user/lib.php');
220
221
// verify the remote host is configured locally before attempting RPC call
221
222
if (! $remotehost = $DB->get_record('mnet_host', array('wwwroot' => $remotepeer->wwwroot, 'deleted' => 0))) {
361
362
if (empty($localuser->firstaccess)) { // Now firstaccess, grab it here
362
363
$localuser->firstaccess = time();
365
$DB->update_record('user', $localuser);
365
user_update_user($localuser, false);
367
367
if (!$firsttime) {
368
368
// repeat customer! let the IDP know about enrolments
767
767
$mnethostlogssql = "
769
mhostlogs.remoteid, mhostlogs.time, mhostlogs.userid, mhostlogs.ip,
770
mhostlogs.course, mhostlogs.module, mhostlogs.cmid, mhostlogs.action,
771
mhostlogs.url, mhostlogs.info, mhostlogs.username, c.fullname as coursename,
769
l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
770
l.action, l.url, l.info, u.username
776
l.id as remoteid, l.time, l.userid, l.ip, l.course, l.module, l.cmid,
777
l.action, l.url, l.info, u.username
780
INNER JOIN {log} l on l.userid = u.id
784
ORDER BY remoteid ASC
787
INNER JOIN {course} c on c.id = mhostlogs.course
788
ORDER by mhostlogs.remoteid ASC";
773
INNER JOIN {log} l on l.userid = u.id
777
AND l.course IS NOT NULL
790
$mnethostlogs = $DB->get_records_sql($mnethostlogssql, array($mnethostid, $mnet_request->response['last log id']));
780
$mnethostlogs = $DB->get_records_sql($mnethostlogssql, array($mnethostid, $mnet_request->response['last log id']), 0, 500);
792
782
if ($mnethostlogs == false) {
796
786
$processedlogs = array();
798
788
foreach($mnethostlogs as $hostlog) {
799
// Extract the name of the relevant module instance from the
800
// course modinfo if possible.
801
if (!empty($hostlog->modinfo) && !empty($hostlog->cmid)) {
802
$modinfo = unserialize($hostlog->modinfo);
803
unset($hostlog->modinfo);
804
$modulearray = array();
805
foreach($modinfo as $module) {
806
$modulearray[$module->cm] = $module->name;
790
// Get impersonalised course information. If it is cached there will be no DB queries.
791
$modinfo = get_fast_modinfo($hostlog->course, -1);
792
$hostlog->coursename = $modinfo->get_course()->fullname;
793
if (!empty($hostlog->cmid) && isset($modinfo->cms[$hostlog->cmid])) {
794
$hostlog->resource_name = $modinfo->cms[$hostlog->cmid]->name;
796
$hostlog->resource_name = '';
808
$hostlog->resource_name = $modulearray[$hostlog->cmid];
810
$hostlog->resource_name = '';
798
} catch (moodle_exception $e) {
813
803
$processedlogs[] = array (
928
918
$returnString .= "We failed to refresh the session for the following usernames: \n".implode("\n", $subArray)."\n\n";
930
920
foreach($results as $emigrant) {
931
session_touch($emigrant->session_id);
921
\core\session\manager::touch_session($emigrant->session_id);
1084
1074
array('useragent'=>$useragent, 'userid'=>$userid));
1086
1076
if (isset($remoteclient) && isset($remoteclient->id)) {
1087
session_kill_user($userid);
1077
\core\session\manager::kill_user_sessions($userid);
1089
1079
return $returnstring;
1104
1094
$session = $DB->get_record('mnet_session', array('username'=>$username, 'mnethostid'=>$remoteclient->id, 'useragent'=>$useragent));
1105
1095
$DB->delete_records('mnet_session', array('username'=>$username, 'mnethostid'=>$remoteclient->id, 'useragent'=>$useragent));
1106
1096
if (false != $session) {
1107
session_kill($session->session_id);
1097
\core\session\manager::kill_session($session->session_id);