[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/admin/mnet/ -> testclient.php (source)

   1  <?php
   2  /**
   3   * A service browser for remote Moodles
   4   *
   5   * This script 'remotely' executes the reflection methods on a remote Moodle,
   6   * and publishes the details of the available services
   7   *
   8   * @package    core
   9   * @subpackage mnet
  10   * @author  Donal McMullan  [email protected]
  11   * @version 0.0.1
  12   * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
  13   * @package mnet
  14   */
  15  require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
  16  require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
  17  require_once($CFG->libdir.'/adminlib.php');
  18  include_once($CFG->dirroot.'/mnet/lib.php');
  19  
  20  if ($CFG->mnet_dispatcher_mode === 'off') {
  21      print_error('mnetdisabled', 'mnet');
  22  }
  23  
  24  require_login();
  25  admin_externalpage_setup('mnettestclient');
  26  
  27  $context = context_system::instance();
  28  require_capability('moodle/site:config', $context);
  29  
  30  error_reporting(DEBUG_ALL);
  31  
  32  echo $OUTPUT->header();
  33  if (!extension_loaded('openssl')) {
  34      print_error('requiresopenssl', 'mnet', '', NULL, true);
  35  }
  36  
  37  // optional drilling down parameters
  38  $hostid = optional_param('hostid', 0, PARAM_INT);
  39  $servicename = optional_param('servicename', '', PARAM_SAFEDIR);
  40  $methodid = optional_param('method', 0, PARAM_INT);
  41  
  42  $hosts = $DB->get_records('mnet_host');
  43  $moodleapplicationid = $DB->get_field('mnet_application', 'id', array('name' => 'moodle'));
  44  
  45  $url = new moodle_url('/admin/mnet/testclient.php');
  46  $PAGE->set_url($url);
  47  
  48  echo $OUTPUT->heading(get_string('hostlist', 'mnet'));
  49  foreach ($hosts as $id => $host) {
  50      if (empty($host->wwwroot) || $host->wwwroot == $CFG->wwwroot) {
  51          continue;
  52      }
  53      $newurl = new moodle_url($url, array('hostid' => $host->id));
  54      echo '<p>' . html_writer::link($newurl, $host->wwwroot) . '</p>';
  55  }
  56  
  57  if (!empty($hostid) && array_key_exists($hostid, $hosts)) {
  58      $host = $hosts[$hostid];
  59      if ($host->applicationid != $moodleapplicationid) {
  60          echo $OUTPUT->notification(get_string('notmoodleapplication', 'mnet'));
  61      }
  62      $mnet_peer = new mnet_peer();
  63      $mnet_peer->set_wwwroot($host->wwwroot);
  64  
  65      $mnet_request = new mnet_xmlrpc_client();
  66  
  67      $mnet_request->set_method('system/listServices');
  68      $mnet_request->send($mnet_peer);
  69      $services = $mnet_request->response;
  70      $yesno = array('No', 'Yes');
  71      $servicenames = array();
  72  
  73      echo $OUTPUT->heading(get_string('servicesavailableonhost', 'mnet', $host->wwwroot));
  74  
  75      $table = new html_table();
  76      $table->head = array(
  77          get_string('serviceid', 'mnet'),
  78          get_string('service', 'mnet'),
  79          get_string('version', 'mnet'),
  80          get_string('theypublish', 'mnet'),
  81          get_string('theysubscribe', 'mnet'),
  82          get_string('options', 'mnet'),
  83      );
  84      $table->data = array();
  85  
  86      $yesno = array(get_string('no'), get_string('yes'));
  87  
  88      // this query is horrible and has to be remapped afterwards, because of the non-uniqueness
  89      // of the remoterep service (it has two plugins so far that use it)
  90      // it's possible to get a unique list back using a subquery with LIMIT but that would break oracle
  91      // so it's best to just do this small query and then remap the results afterwards
  92      $sql = '
  93          SELECT DISTINCT
  94              ' . $DB->sql_concat('r.plugintype', "'_'", 'r.pluginname', "'_'", 's.name')  . ' AS uniqueid,
  95               s.name,
  96               r.plugintype,
  97               r.pluginname
  98          FROM
  99              {mnet_service} s
 100         JOIN {mnet_remote_service2rpc} s2r ON s2r.serviceid = s.id
 101         JOIN {mnet_remote_rpc} r ON r.id = s2r.rpcid';
 102  
 103      $serviceinfo = array();
 104  
 105      foreach ($DB->get_records_sql($sql) as $result) {
 106          $serviceinfo[$result->name] = $result->plugintype . '_' . $result->pluginname;
 107      }
 108  
 109      foreach ($services as $id => $servicedata) {
 110          if (array_key_exists($servicedata['name'], $serviceinfo)) {
 111              $service = $serviceinfo[$servicedata['name']];
 112              $servicedata['humanname'] = get_string($servicedata['name'].'_name', $service);
 113          } else {
 114              $servicedata['humanname'] = get_string('unknown', 'mnet');
 115          }
 116          $newurl = new moodle_url($url, array('hostid' => $host->id, 'servicename' => $servicedata['name']));
 117          $table->data[] = array(
 118              $servicedata['name'],
 119              $servicedata['humanname'],
 120              $servicedata['apiversion'],
 121              $yesno[$servicedata['publish']],
 122              $yesno[$servicedata['subscribe']],
 123              html_writer::link($newurl, get_string('listservices', 'mnet'))
 124          );
 125  
 126      }
 127      echo html_writer::table($table);
 128  
 129  
 130      $mnet_request->set_method('system/listMethods');
 131      if (isset($servicename) && array_key_exists($servicename, $serviceinfo)) {
 132          echo $OUTPUT->heading(get_string('methodsavailableonhostinservice', 'mnet', (object)array('host' => $host->wwwroot, 'service' => $servicename)));
 133          $service = $serviceinfo[$servicename];
 134          $mnet_request->add_param($servicename, 'string');
 135      } else {
 136          echo $OUTPUT->heading(get_string('methodsavailableonhost', 'mnet', $host->wwwroot));
 137      }
 138  
 139      $mnet_request->send($mnet_peer);
 140      $methods = $mnet_request->response;
 141  
 142  
 143      $table = new html_table();
 144      $table->head = array(
 145          get_string('method', 'mnet'),
 146          get_string('options', 'mnet'),
 147      );
 148      $table->data = array();
 149  
 150      foreach ($methods as $id => $method) {
 151          $params = array('hostid' => $host->id, 'method' => $id+1);
 152          if (isset($servicename)) {
 153              $params['servicename'] = $servicename;
 154          }
 155          $newurl = new moodle_url($url, $params);
 156          $table->data[] = array(
 157              $method,
 158              html_writer::link($newurl, get_string('inspect', 'mnet'))
 159          );
 160      }
 161      echo html_writer::table($table);
 162  
 163      if (isset($methodid) && array_key_exists($methodid-1, $methods)) {
 164          $method = $methods[$methodid-1];
 165  
 166          $mnet_request = new mnet_xmlrpc_client();
 167          $mnet_request->set_method('system/methodSignature');
 168          $mnet_request->add_param($method, 'string');
 169          $mnet_request->send($mnet_peer);
 170          $signature = $mnet_request->response;
 171  
 172          echo $OUTPUT->heading(get_string('methodsignature', 'mnet', $method));
 173  
 174          $table = new html_table();
 175          $table->head = array(
 176              get_string('position', 'mnet'),
 177              get_string('name', 'mnet'),
 178              get_string('type', 'mnet'),
 179              get_string('description', 'mnet'),
 180          );
 181          $table->data = array();
 182  
 183          $params = $signature['parameters'];
 184          foreach ($params as $pos => $details) {
 185              $table->data[] = array(
 186                  $pos,
 187                  $details['name'],
 188                  $details['type'],
 189                  $details['description'],
 190              );
 191          }
 192          $table->data[] = array(
 193              get_string('returnvalue', 'mnet'),
 194              '',
 195              $signature['return']['type'],
 196              $signature['return']['description']
 197          );
 198  
 199          echo html_writer::table($table);
 200  
 201          $mnet_request->set_method('system/methodHelp');
 202          $mnet_request->add_param($method, 'string');
 203          $mnet_request->send($mnet_peer);
 204          $help = $mnet_request->response;
 205  
 206          echo $OUTPUT->heading(get_string('methodhelp', 'mnet', $method));
 207          echo(str_replace('\n', '<br />',$help));
 208      }
 209  }
 210  
 211  echo $OUTPUT->footer();
 212  ?>


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1