6e6b8c85 |
1 | <?PHP //$Id$ |
2 | |
3 | class 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 | |
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 | |
6e6b8c85 |
29 | // check for outgoing roaming permission first |
052ba1f5 |
30 | if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) { |
6e6b8c85 |
31 | return ''; |
32 | } |
33 | |
34 | if ($this->content !== NULL) { |
35 | return $this->content; |
36 | } |
37 | |
38 | // TODO: Test this query - it's appropriate? It works? |
39 | // get the hosts and whether we are doing SSO with them |
40 | $sql = " |
41 | SELECT DISTINCT |
42 | h.id, |
25202581 |
43 | h.name, |
44 | h.wwwroot, |
45 | a.name as application, |
46 | a.display_name |
6e6b8c85 |
47 | FROM |
48 | {$CFG->prefix}mnet_host h, |
25202581 |
49 | {$CFG->prefix}mnet_application a, |
6e6b8c85 |
50 | {$CFG->prefix}mnet_host2service h2s_IDP, |
51 | {$CFG->prefix}mnet_service s_IDP, |
52 | {$CFG->prefix}mnet_host2service h2s_SP, |
53 | {$CFG->prefix}mnet_service s_SP |
54 | WHERE |
55 | h.id != '{$CFG->mnet_localhost_id}' AND |
56 | h.id = h2s_IDP.hostid AND |
25202581 |
57 | h.applicationid = a.id AND |
6e6b8c85 |
58 | h2s_IDP.serviceid = s_IDP.id AND |
59 | s_IDP.name = 'sso_idp' AND |
60 | h2s_IDP.publish = '1' AND |
61 | h.id = h2s_SP.hostid AND |
62 | h2s_SP.serviceid = s_SP.id AND |
63 | s_SP.name = 'sso_idp' AND |
25202581 |
64 | h2s_SP.publish = '1' |
65 | ORDER BY |
66 | a.display_name, |
67 | h.name"; |
6e6b8c85 |
68 | |
69 | $hosts = get_records_sql($sql); |
70 | |
71 | $this->content = new stdClass; |
72 | $this->content->items = array(); |
73 | $this->content->icons = array(); |
74 | $this->content->footer = ''; |
75 | |
d72fd695 |
76 | if ($hosts) { |
77 | foreach ($hosts as $host) { |
25202581 |
78 | $icon = '<img src="'.$CFG->pixpath.'/i/'.$host->application.'_host.gif"'. |
79 | ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />'; |
80 | |
d72fd695 |
81 | $this->content->icons[]=$icon; |
25202581 |
82 | if ($host->id == $USER->mnethostid) { |
83 | $this->content->items[]="<a title=\"" .s($host->name). |
84 | "\" href=\"{$host->wwwroot}\">". s($host->name) ."</a>"; |
85 | } else { |
86 | $this->content->items[]="<a title=\"" .s($host->name). |
87 | "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>"; |
88 | } |
d72fd695 |
89 | } |
6e6b8c85 |
90 | } |
91 | |
92 | return $this->content; |
93 | } |
94 | } |
95 | |
052ba1f5 |
96 | ?> |