|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 class block_mnet_hosts extends block_list { 00004 function init() { 00005 $this->title = get_string('pluginname','block_mnet_hosts') ; 00006 } 00007 00008 function has_config() { 00009 return false; 00010 } 00011 00012 function applicable_formats() { 00013 if (has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) { 00014 return array('all' => true, 'mod' => false, 'tag' => false); 00015 } else { 00016 return array('site' => true); 00017 } 00018 } 00019 00020 function get_content() { 00021 global $CFG, $USER, $DB, $OUTPUT; 00022 00023 // shortcut - only for logged in users! 00024 if (!isloggedin() || isguestuser()) { 00025 return false; 00026 } 00027 00028 if (session_is_loggedinas()) { 00029 $this->content = new stdClass(); 00030 $this->content->footer = html_writer::tag('span', 00031 get_string('notpermittedtojumpas', 'mnet')); 00032 return $this->content; 00033 } 00034 00035 // according to start_jump_session, 00036 // remote users can't on-jump 00037 // so don't show this block to them 00038 if (is_mnet_remote_user($USER)) { 00039 if (debugging() and !empty($CFG->debugdisplay)) { 00040 $this->content = new stdClass(); 00041 $this->content->footer = html_writer::tag('span', 00042 get_string('error_localusersonly', 'block_mnet_hosts'), 00043 array('class' => 'error')); 00044 return $this->content; 00045 } else { 00046 return ''; 00047 } 00048 } 00049 00050 if (!is_enabled_auth('mnet')) { 00051 if (debugging() and !empty($CFG->debugdisplay)) { 00052 $this->content = new stdClass(); 00053 $this->content->footer = html_writer::tag('span', 00054 get_string('error_authmnetneeded', 'block_mnet_hosts'), 00055 array('class' => 'error')); 00056 return $this->content; 00057 } else { 00058 return ''; 00059 } 00060 } 00061 00062 if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) { 00063 if (debugging() and !empty($CFG->debugdisplay)) { 00064 $this->content = new stdClass(); 00065 $this->content->footer = html_writer::tag('span', 00066 get_string('error_roamcapabilityneeded', 'block_mnet_hosts'), 00067 array('class' => 'error')); 00068 return $this->content; 00069 } else { 00070 return ''; 00071 } 00072 } 00073 00074 if ($this->content !== NULL) { 00075 return $this->content; 00076 } 00077 00078 // TODO: Test this query - it's appropriate? It works? 00079 // get the hosts and whether we are doing SSO with them 00080 $sql = " 00081 SELECT DISTINCT 00082 h.id, 00083 h.name, 00084 h.wwwroot, 00085 a.name as application, 00086 a.display_name 00087 FROM 00088 {mnet_host} h, 00089 {mnet_application} a, 00090 {mnet_host2service} h2s_IDP, 00091 {mnet_service} s_IDP, 00092 {mnet_host2service} h2s_SP, 00093 {mnet_service} s_SP 00094 WHERE 00095 h.id <> ? AND 00096 h.id <> ? AND 00097 h.id = h2s_IDP.hostid AND 00098 h.deleted = 0 AND 00099 h.applicationid = a.id AND 00100 h2s_IDP.serviceid = s_IDP.id AND 00101 s_IDP.name = 'sso_idp' AND 00102 h2s_IDP.publish = '1' AND 00103 h.id = h2s_SP.hostid AND 00104 h2s_SP.serviceid = s_SP.id AND 00105 s_SP.name = 'sso_idp' AND 00106 h2s_SP.publish = '1' 00107 ORDER BY 00108 a.display_name, 00109 h.name"; 00110 00111 $hosts = $DB->get_records_sql($sql, array($CFG->mnet_localhost_id, $CFG->mnet_all_hosts_id)); 00112 00113 $this->content = new stdClass(); 00114 $this->content->items = array(); 00115 $this->content->icons = array(); 00116 $this->content->footer = ''; 00117 00118 if ($hosts) { 00119 foreach ($hosts as $host) { 00120 $icon = '<img src="'.$OUTPUT->pix_url('i/'.$host->application.'_host') . '"'. 00121 ' class="icon" alt="'.get_string('server', 'block_mnet_hosts').'" /> '; 00122 00123 if ($host->id == $USER->mnethostid) { 00124 $this->content->items[]="<a title=\"" .s($host->name). 00125 "\" href=\"{$host->wwwroot}\">".$icon. s($host->name) ."</a>"; 00126 } else { 00127 $this->content->items[]="<a title=\"" .s($host->name). 00128 "\" href=\"{$CFG->wwwroot}/auth/mnet/jump.php?hostid={$host->id}\">" .$icon. s($host->name) ."</a>"; 00129 } 00130 } 00131 } 00132 00133 return $this->content; 00134 } 00135 }