3 class block_mnet_hosts extends block_list {
5 $this->title = get_string('pluginname','block_mnet_hosts') ;
6 $this->version = 2007101509;
9 function has_config() {
13 function applicable_formats() {
14 if (has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
15 return array('all' => true, 'mod' => false, 'tag' => false);
17 return array('site' => true);
21 function get_content() {
22 global $CFG, $USER, $DB, $OUTPUT;
24 // shortcut - only for logged in users!
25 if (!isloggedin() || isguestuser()) {
29 // according to start_jump_session,
30 // remote users can't on-jump
31 // so don't show this block to them
32 if (is_mnet_remote_user($USER)) {
36 if (!is_enabled_auth('mnet')) {
37 // no need to query anything remote related
38 debugging( 'mnet authentication plugin is not enabled', DEBUG_ALL );
42 // check for outgoing roaming permission first
43 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
47 if ($this->content !== NULL) {
48 return $this->content;
51 // TODO: Test this query - it's appropriate? It works?
52 // get the hosts and whether we are doing SSO with them
58 a.name as application,
63 {mnet_host2service} h2s_IDP,
65 {mnet_host2service} h2s_SP,
69 h.id = h2s_IDP.hostid AND
71 h.applicationid = a.id AND
72 h2s_IDP.serviceid = s_IDP.id AND
73 s_IDP.name = 'sso_idp' AND
74 h2s_IDP.publish = '1' AND
75 h.id = h2s_SP.hostid AND
76 h2s_SP.serviceid = s_SP.id AND
77 s_SP.name = 'sso_idp' AND
83 $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id));
85 $this->content = new stdClass;
86 $this->content->items = array();
87 $this->content->icons = array();
88 $this->content->footer = '';
91 foreach ($hosts as $host) {
92 $icon = '<img src="'.$OUTPUT->pix_url('i/'.$host->application.'_host') . '"'.
93 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />';
95 $this->content->icons[]=$icon;
96 if ($host->id == $USER->mnethostid) {
97 $this->content->items[]="<a title=\"" .s($host->name).
98 "\" href=\"{$host->wwwroot}\">". s($host->name) ."</a>";
100 $this->content->items[]="<a title=\"" .s($host->name).
101 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>";
106 return $this->content;