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