MDL-14967 DB upgrades. Not finished yet.
[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') ;
433c242f 6 $this->version = 2007101509;
6e6b8c85 7 }
8
9 function has_config() {
10 return false;
11 }
12
052ba1f5 13 function applicable_formats() {
14 if (has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
9591bc3c 15 return array('all' => true, 'mod' => false, 'tag' => false);
052ba1f5 16 } else {
1de58621 17 return array('site' => true);
052ba1f5 18 }
19 }
20
6e6b8c85 21 function get_content() {
22 global $THEME, $CFG, $USER;
23
f3203630 24 // only for logged in users!
25 if (!isloggedin() || isguest()) {
26 return false;
27 }
28
dd97c328 29 if (!is_enabled_auth('mnet')) {
30 // no need to query anything remote related
31 return '';
32 }
33
6e6b8c85 34 // check for outgoing roaming permission first
052ba1f5 35 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
6e6b8c85 36 return '';
37 }
38
39 if ($this->content !== NULL) {
40 return $this->content;
41 }
42
43 // TODO: Test this query - it's appropriate? It works?
44 // get the hosts and whether we are doing SSO with them
45 $sql = "
46 SELECT DISTINCT
47 h.id,
25202581 48 h.name,
49 h.wwwroot,
50 a.name as application,
51 a.display_name
6e6b8c85 52 FROM
53 {$CFG->prefix}mnet_host h,
25202581 54 {$CFG->prefix}mnet_application a,
6e6b8c85 55 {$CFG->prefix}mnet_host2service h2s_IDP,
56 {$CFG->prefix}mnet_service s_IDP,
57 {$CFG->prefix}mnet_host2service h2s_SP,
58 {$CFG->prefix}mnet_service s_SP
59 WHERE
60 h.id != '{$CFG->mnet_localhost_id}' AND
61 h.id = h2s_IDP.hostid AND
25202581 62 h.applicationid = a.id AND
6e6b8c85 63 h2s_IDP.serviceid = s_IDP.id AND
64 s_IDP.name = 'sso_idp' AND
65 h2s_IDP.publish = '1' AND
66 h.id = h2s_SP.hostid AND
67 h2s_SP.serviceid = s_SP.id AND
68 s_SP.name = 'sso_idp' AND
25202581 69 h2s_SP.publish = '1'
70 ORDER BY
71 a.display_name,
72 h.name";
6e6b8c85 73
74 $hosts = get_records_sql($sql);
75
76 $this->content = new stdClass;
77 $this->content->items = array();
78 $this->content->icons = array();
79 $this->content->footer = '';
80
d72fd695 81 if ($hosts) {
82 foreach ($hosts as $host) {
25202581 83 $icon = '<img src="'.$CFG->pixpath.'/i/'.$host->application.'_host.gif"'.
84 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />';
85
d72fd695 86 $this->content->icons[]=$icon;
25202581 87 if ($host->id == $USER->mnethostid) {
88 $this->content->items[]="<a title=\"" .s($host->name).
89 "\" href=\"{$host->wwwroot}\">". s($host->name) ."</a>";
90 } else {
91 $this->content->items[]="<a title=\"" .s($host->name).
92 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>";
93 }
d72fd695 94 }
6e6b8c85 95 }
96
97 return $this->content;
98 }
99}
100
052ba1f5 101?>