[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/blocks/mnet_hosts/ -> block_mnet_hosts.php (source)

   1  <?PHP //$Id: block_mnet_hosts.php,v 1.9.2.4 2008/07/18 04:02:32 moodler Exp $
   2  
   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;
   7      }
   8  
   9      function has_config() {
  10          return false;
  11      }
  12  
  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);
  18          }
  19      }
  20  
  21      function get_content() {
  22          global $THEME, $CFG, $USER;
  23  
  24          // only for logged in users!
  25          if (!isloggedin() || isguest()) {
  26              return false;
  27          }
  28  
  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 '';
  33          }
  34  
  35          // check for outgoing roaming permission first
  36          if (!has_capability('moodle/site:mnetlogintoremote', get_context_instance(CONTEXT_SYSTEM), NULL, false)) {
  37              return '';
  38          }
  39  
  40          if ($this->content !== NULL) {
  41              return $this->content;
  42          }
  43  
  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";
  75  
  76          $hosts = get_records_sql($sql);
  77  
  78          $this->content = new stdClass;
  79          $this->content->items = array();
  80          $this->content->icons = array();
  81          $this->content->footer = '';
  82  
  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').'" />';
  87  
  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>";
  95                  }
  96              }
  97          }
  98  
  99          return $this->content;
 100      }
 101  }
 102  
 103  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7