From 4d8c087e023f69685c52a045df1a5f0e61f1819b Mon Sep 17 00:00:00 2001 From: donal72 Date: Tue, 16 Jan 2007 05:00:18 +0000 Subject: [PATCH] MNET: MyCourses block enriched with links to remote Moodles when roaming --- auth/mnet/auth.php | 49 ++++++++++++++++++++++-- blocks/course_list/block_course_list.php | 42 ++++++++++++-------- lang/en_utf8/mnet.php | 3 ++ 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index ba3fbb0c3fb..b02c74e2b71 100644 --- a/auth/mnet/auth.php +++ b/auth/mnet/auth.php @@ -75,8 +75,7 @@ class auth_plugin_mnet * @return array $userdata Array of user info for remote host */ function user_authorise($token, $useragent) { - global $CFG; - global $MNET; + global $CFG, $MNET, $SITE, $MNET_REMOTE_CLIENT; require_once $CFG->dirroot . '/mnet/xmlrpc/server.php'; $mnet_session = get_record('mnet_session', 'token', $token, 'useragent', $useragent); @@ -123,6 +122,37 @@ class auth_plugin_mnet $userdata['imagehash'] = sha1(file_get_contents($imagefile)); } } + + $userdata['myhosts'] = array(); + if($courses = get_my_courses($user->id, 'id', 'id, visible')) { + $userdata['myhosts'][] = array('name'=> $SITE->shortname, 'url' => $CFG->wwwroot, 'count' => count($courses)); + } + + $sql = " + SELECT + h.name as hostname, + h.wwwroot, + h.id as hostid, + count(c.id) as count + FROM + {$CFG->prefix}mnet_enrol_course c, + {$CFG->prefix}mnet_enrol_assignments a, + {$CFG->prefix}mnet_host h + WHERE + c.id = a.courseid AND + c.hostid = h.id AND + a.userid = '{$user->id}' AND + c.hostid != '{$MNET_REMOTE_CLIENT->id}' + GROUP BY + h.name, + h.id, + h.wwwroot"; + if ($courses = get_records_sql($sql)) { + foreach($courses as $course) { + $userdata['myhosts'][] = array('name'=> $course->hostname, 'url' => $CFG->wwwroot.'/auth/mnet/jump.php?hostid='.$course->hostid, 'count' => $course->count); + } + } + return $userdata; } @@ -209,7 +239,7 @@ class auth_plugin_mnet * @returns array The local user record. */ function confirm_mnet_session($token, $remotewwwroot) { - global $CFG, $MNET; + global $CFG, $MNET, $SESSION; require_once $CFG->dirroot . '/mnet/xmlrpc/client.php'; // verify the remote host is configured locally before attempting RPC call @@ -312,6 +342,19 @@ class auth_plugin_mnet } } + if($key == 'myhosts') { + $SESSION->mnet_foreign_host_array = array(); + foreach($val as $somecourse) { + $name = clean_param($somecourse['name'], PARAM_ALPHANUM); + $url = clean_param($somecourse['url'], PARAM_URL); + $count = clean_param($somecourse['count'], PARAM_INT); + $url_is_local = stristr($url , $CFG->wwwroot); + if (!empty($name) && !empty($count) && empty($url_is_local)) { + $SESSION->mnet_foreign_host_array[] = array('name' => $name, 'url' => $url, 'count' => $count); + } + } + } + $localuser->{$key} = $val; } diff --git a/blocks/course_list/block_course_list.php b/blocks/course_list/block_course_list.php index 0a59406469c..ce08b2655ab 100644 --- a/blocks/course_list/block_course_list.php +++ b/blocks/course_list/block_course_list.php @@ -99,23 +99,35 @@ class block_course_list extends block_list { } function get_remote_courses() { - global $THEME, $CFG, $USER; - $sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid - FROM {$CFG->prefix}mnet_enrol_course c - JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid - WHERE a.userid={$USER->id}"; - if ($courses = get_records_sql($sql)) { - $icon = "pixpath/i/mnethost.png\"". - " class=\"icon\" alt=\"".get_string("course")."\" />"; - $this->content->items[] = 'Remote Courses'; - $this->content->icons[] = ''; - foreach ($courses as $course) { - $this->content->items[]="shortname\" ". - "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname"; - $this->content->icons[]=$icon; + global $THEME, $CFG, $USER, $SESSION; + $icon = ''.get_string('course').''; + if ($USER->mnethostid != $CFG->mnet_localhost_id) { + if (!empty($SESSION->mnet_foreign_host_array) && is_array($SESSION->mnet_foreign_host_array)) { + $this->content->items[] = get_string('remotemoodles','mnet'); + $this->content->icons[] = ''; + foreach($SESSION->mnet_foreign_host_array as $somehost) { + $this->content->items[] = $somehost['count'].get_string('courseson','mnet').''.$somehost['name'].''; + $this->content->icons[] = $icon; + } + } else { + return false; } } else { - return false; + $sql = "SELECT c.remoteid, c.shortname, c.fullname, c.hostid + FROM {$CFG->prefix}mnet_enrol_course c + JOIN {$CFG->prefix}mnet_enrol_assignments a ON c.id=a.courseid + WHERE a.userid={$USER->id}"; + if ($courses = get_records_sql($sql)) { + $this->content->items[] = get_string('remotecourses','mnet'); + $this->content->icons[] = ''; + foreach ($courses as $course) { + $this->content->items[]="shortname\" ". + "href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$course->hostid}&wantsurl=/course/view.php?id={$course->remoteid}\">$course->fullname"; + $this->content->icons[]=$icon; + } + } else { + return false; + } } return true; } diff --git a/lang/en_utf8/mnet.php b/lang/en_utf8/mnet.php index 676394c93d6..18183e0d996 100644 --- a/lang/en_utf8/mnet.php +++ b/lang/en_utf8/mnet.php @@ -116,6 +116,9 @@ $string['RPC_HTTP_VERIFIED'] = 'HTTP (signed)'; $string['RPC_HTTP_SELF_SIGNED'] = 'HTTP (self-signed)'; $string['RPC_HTTP_PLAINTEXT'] = 'HTTP unencrypted'; $string['remotehosts'] = 'Remote hosts'; +$string['remotemoodles'] = 'Remote Moodles'; +$string['remotecourses'] = 'Remote Courses'; +$string['courseson'] = ' courses on '; $string['permittedtransports'] = 'Permitted transports'; $string['current_transport'] = 'Current transport'; $string['system'] = 'System';