Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / blocks / mnet_hosts / block_mnet_hosts.php
blob9363338312d6cbdb84e18ecf16406674c5182543
1 <?PHP //$Id$
3 class block_mnet_hosts extends block_list {
4 function init() {
5 $this->title = get_string('mnet_hosts','block_mnet_hosts') ;
6 $this->version = 2007101509;
9 function has_config() {
10 return false;
13 function applicable_formats() {
14 if (has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
15 return array('all' => true, 'mod' => false, 'tag' => false);
16 } else {
17 return array('site' => true);
21 function get_content() {
22 global $THEME, $CFG, $USER;
24 // only for logged in users!
25 if (!isloggedin() || isguest()) {
26 return false;
29 if (!is_enabled_auth('mnet')) {
30 // no need to query anything remote related
31 debugging( 'mnet authentication plugin is not enabled', DEBUG_ALL );
32 return '';
35 // check for outgoing roaming permission first
36 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
37 return '';
40 if ($this->content !== NULL) {
41 return $this->content;
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,
49 h.name,
50 h.wwwroot,
51 a.name as application,
52 a.display_name
53 FROM
54 {$CFG->prefix}mnet_host h,
55 {$CFG->prefix}mnet_application a,
56 {$CFG->prefix}mnet_host2service h2s_IDP,
57 {$CFG->prefix}mnet_service s_IDP,
58 {$CFG->prefix}mnet_host2service h2s_SP,
59 {$CFG->prefix}mnet_service s_SP
60 WHERE
61 h.id != '{$CFG->mnet_localhost_id}' AND
62 h.id = h2s_IDP.hostid AND
63 h.deleted = 0 AND
64 h.applicationid = a.id AND
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
71 h2s_SP.publish = '1'
72 ORDER BY
73 a.display_name,
74 h.name";
76 $hosts = get_records_sql($sql);
78 $this->content = new stdClass;
79 $this->content->items = array();
80 $this->content->icons = array();
81 $this->content->footer = '';
83 if ($hosts) {
84 foreach ($hosts as $host) {
85 $icon = '<img src="'.$CFG->pixpath.'/i/'.$host->application.'_host.gif"'.
86 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />';
88 $this->content->icons[]=$icon;
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>";
99 return $this->content;