MDL-15683, get query string instead of calling me().
[moodle-linuxchix.git] / blocks / mnet_hosts / block_mnet_hosts.php
blobfd4bdcc7dd4570d528718d24acf7d26ce24e4eaa
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.applicationid = a.id AND
64 h2s_IDP.serviceid = s_IDP.id AND
65 s_IDP.name = 'sso_idp' AND
66 h2s_IDP.publish = '1' AND
67 h.id = h2s_SP.hostid AND
68 h2s_SP.serviceid = s_SP.id AND
69 s_SP.name = 'sso_idp' AND
70 h2s_SP.publish = '1'
71 ORDER BY
72 a.display_name,
73 h.name";
75 $hosts = get_records_sql($sql);
77 $this->content = new stdClass;
78 $this->content->items = array();
79 $this->content->icons = array();
80 $this->content->footer = '';
82 if ($hosts) {
83 foreach ($hosts as $host) {
84 $icon = '<img src="'.$CFG->pixpath.'/i/'.$host->application.'_host.gif"'.
85 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />';
87 $this->content->icons[]=$icon;
88 if ($host->id == $USER->mnethostid) {
89 $this->content->items[]="<a title=\"" .s($host->name).
90 "\" href=\"{$host->wwwroot}\">". s($host->name) ."</a>";
91 } else {
92 $this->content->items[]="<a title=\"" .s($host->name).
93 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" . s($host->name) ."</a>";
98 return $this->content;