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') ; |
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() { |
666e8458 |
22 | global $CFG, $USER, $DB, $OUTPUT; |
6e6b8c85 |
23 | |
f3203630 |
24 | // only for logged in users! |
4cdb8d70 |
25 | if (!isloggedin() || isguestuser()) { |
f3203630 |
26 | return false; |
27 | } |
28 | |
dd97c328 |
29 | if (!is_enabled_auth('mnet')) { |
30 | // no need to query anything remote related |
ffed6d83 |
31 | debugging( 'mnet authentication plugin is not enabled', DEBUG_ALL ); |
dd97c328 |
32 | return ''; |
33 | } |
34 | |
6e6b8c85 |
35 | // check for outgoing roaming permission first |
052ba1f5 |
36 | if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) { |
6e6b8c85 |
37 | return ''; |
38 | } |
39 | |
40 | if ($this->content !== NULL) { |
41 | return $this->content; |
42 | } |
43 | |
44 | // TODO: Test this query - it's appropriate? It works? |
45 | // get the hosts and whether we are doing SSO with them |
46 | $sql = " |
47 | SELECT DISTINCT |
48 | h.id, |
25202581 |
49 | h.name, |
50 | h.wwwroot, |
51 | a.name as application, |
52 | a.display_name |
6e6b8c85 |
53 | FROM |
f28f2d90 |
54 | {mnet_host} h, |
55 | {mnet_application} a, |
56 | {mnet_host2service} h2s_IDP, |
57 | {mnet_service} s_IDP, |
58 | {mnet_host2service} h2s_SP, |
59 | {mnet_service} s_SP |
6e6b8c85 |
60 | WHERE |
f28f2d90 |
61 | h.id <> ? AND |
6e6b8c85 |
62 | h.id = h2s_IDP.hostid AND |
5c0700a6 |
63 | h.deleted = 0 AND |
25202581 |
64 | h.applicationid = a.id AND |
6e6b8c85 |
65 | h2s_IDP.serviceid = s_IDP.id AND |
66 | s_IDP.name = 'sso_idp' AND |
67 | h2s_IDP.publish = '1' AND |
68 | h.id = h2s_SP.hostid AND |
69 | h2s_SP.serviceid = s_SP.id AND |
70 | s_SP.name = 'sso_idp' AND |
25202581 |
71 | h2s_SP.publish = '1' |
72 | ORDER BY |
73 | a.display_name, |
74 | h.name"; |
6e6b8c85 |
75 | |
f28f2d90 |
76 | $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id)); |
6e6b8c85 |
77 | |
78 | $this->content = new stdClass; |
79 | $this->content->items = array(); |
80 | $this->content->icons = array(); |
81 | $this->content->footer = ''; |
82 | |
d72fd695 |
83 | if ($hosts) { |
84 | foreach ($hosts as $host) { |
666e8458 |
85 | $icon = '<img src="'.$OUTPUT->old_icon_url('i/'.$host->application.'_host') . '"'. |
25202581 |
86 | ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />'; |
87 | |
d72fd695 |
88 | $this->content->icons[]=$icon; |
25202581 |
89 | if ($host->id == $USER->mnethostid) { |
90 | $this->content->items[]="<a title=\"" .s($host->name). |
91 | "\" href=\"{$host->wwwroot}\">". s($host->name) ."</a>"; |
92 | } else { |
93 | $this->content->items[]="<a title=\"" .s($host->name). |
94 | "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>"; |
95 | } |
d72fd695 |
96 | } |
6e6b8c85 |
97 | } |
98 | |
99 | return $this->content; |
100 | } |
101 | } |
102 | |
052ba1f5 |
103 | ?> |