mnet: new mnet_hosts block
[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
16 // check for outgoing roaming permission first
17 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
18 return '';
19 }
20
21 if ($this->content !== NULL) {
22 return $this->content;
23 }
24
25 // TODO: Test this query - it's appropriate? It works?
26 // get the hosts and whether we are doing SSO with them
27 $sql = "
28 SELECT DISTINCT
29 h.id,
30 h.name
31 FROM
32 {$CFG->prefix}mnet_host h,
33 {$CFG->prefix}mnet_host2service h2s_IDP,
34 {$CFG->prefix}mnet_service s_IDP,
35 {$CFG->prefix}mnet_host2service h2s_SP,
36 {$CFG->prefix}mnet_service s_SP
37 WHERE
38 h.id != '{$CFG->mnet_localhost_id}' AND
39 h.id = h2s_IDP.hostid AND
40 h2s_IDP.serviceid = s_IDP.id AND
41 s_IDP.name = 'sso_idp' AND
42 h2s_IDP.publish = '1' AND
43 h.id = h2s_SP.hostid AND
44 h2s_SP.serviceid = s_SP.id AND
45 s_SP.name = 'sso_idp' AND
46 h2s_SP.publish = '1'";
47
48 $hosts = get_records_sql($sql);
49
50 $this->content = new stdClass;
51 $this->content->items = array();
52 $this->content->icons = array();
53 $this->content->footer = '';
54
55 $icon = "<img src=\"$CFG->pixpath/i/mnethost.png\"".
56 " height=\"16\" width=\"16\" alt=\"".get_string('server', 'block_mnet_hosts')."\" />";
57
58 foreach ($hosts as $host) {
59 $this->content->icons[]=$icon;
60 $this->content->items[]="<a title=\"" .s($host->name).
61 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>";
62 }
63
64 return $this->content;
65 }
66}
67
68?>