Merged fix for MDL-8093 from 1.8
[moodle.git] / blocks / mnet_hosts / block_mnet_hosts.php
CommitLineData
6e6b8c85 1<?PHP //$Id$
2
3class block_mnet_hosts extends block_list {
4 function init() {
5 $this->title = get_string('mnet_hosts','block_mnet_hosts') ;
6 $this->version = 2006112100;
7 }
8
9 function has_config() {
10 return false;
11 }
12
13 function get_content() {
14 global $THEME, $CFG, $USER;
15
f3203630 16 // only for logged in users!
17 if (!isloggedin() || isguest()) {
18 return false;
19 }
20
6e6b8c85 21 // check for outgoing roaming permission first
22 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
23 return '';
24 }
25
26 if ($this->content !== NULL) {
27 return $this->content;
28 }
29
30 // TODO: Test this query - it's appropriate? It works?
31 // get the hosts and whether we are doing SSO with them
32 $sql = "
33 SELECT DISTINCT
34 h.id,
35 h.name
36 FROM
37 {$CFG->prefix}mnet_host h,
38 {$CFG->prefix}mnet_host2service h2s_IDP,
39 {$CFG->prefix}mnet_service s_IDP,
40 {$CFG->prefix}mnet_host2service h2s_SP,
41 {$CFG->prefix}mnet_service s_SP
42 WHERE
43 h.id != '{$CFG->mnet_localhost_id}' AND
44 h.id = h2s_IDP.hostid AND
45 h2s_IDP.serviceid = s_IDP.id AND
46 s_IDP.name = 'sso_idp' AND
47 h2s_IDP.publish = '1' AND
48 h.id = h2s_SP.hostid AND
49 h2s_SP.serviceid = s_SP.id AND
50 s_SP.name = 'sso_idp' AND
51 h2s_SP.publish = '1'";
52
53 $hosts = get_records_sql($sql);
54
55 $this->content = new stdClass;
56 $this->content->items = array();
57 $this->content->icons = array();
58 $this->content->footer = '';
59
5e142a17 60 $icon = "<img src=\"$CFG->pixpath/i/mnethost.gif\"".
0d905d9f 61 " class=\"icon\" alt=\"".get_string('server', 'block_mnet_hosts')."\" />";
6e6b8c85 62
d72fd695 63 if ($hosts) {
64 foreach ($hosts as $host) {
65 $this->content->icons[]=$icon;
66 $this->content->items[]="<a title=\"" .s($host->name).
67 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>";
68 }
6e6b8c85 69 }
70
71 return $this->content;
72 }
73}
74
d72fd695 75?>