Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / blocks / mnet_hosts / block_mnet_hosts.php
blob6ddf1e601e705a58c7bc41db1b8e978e234ca813
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 = 2006112100;
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);
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 // check for outgoing roaming permission first
30 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
31 return '';
34 if ($this->content !== NULL) {
35 return $this->content;
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,
43 h.name,
44 h.wwwroot,
45 a.name as application,
46 a.display_name
47 FROM
48 {$CFG->prefix}mnet_host h,
49 {$CFG->prefix}mnet_application a,
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
57 h.applicationid = a.id AND
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
64 h2s_SP.publish = '1'
65 ORDER BY
66 a.display_name,
67 h.name";
69 $hosts = get_records_sql($sql);
71 $this->content = new stdClass;
72 $this->content->items = array();
73 $this->content->icons = array();
74 $this->content->footer = '';
76 if ($hosts) {
77 foreach ($hosts as $host) {
78 $icon = '<img src="'.$CFG->pixpath.'/i/'.$host->application.'_host.gif"'.
79 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" />';
81 $this->content->icons[]=$icon;
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>";
92 return $this->content;