weblib MDL-20725 Fixed string formatting issue in nested selects
[moodle.git] / mnet / testclient.php
blob69e3fe769ddc06e4771eabca09a3a20fc642f08c
1 <?php // $Id$
2 /**
3 * A service browser for remote Moodles
5 * This script 'remotely' executes the reflection methods on a remote Moodle,
6 * and publishes the details of the available services
8 * @author Donal McMullan donal@catalyst.net.nz
9 * @version 0.0.1
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 * @package mnet
13 require_once(dirname(dirname(__FILE__)) . '/config.php');
14 require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
16 // Site admins only, thanks.
17 $context = get_context_instance(CONTEXT_SYSTEM);
18 require_capability('moodle/site:config', $context);
20 error_reporting(E_ALL);
22 // Some HTML sugar
23 echo '<?xml version="1.0" encoding="utf-8"?>';
25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
26 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
27 <head><title>Moodle MNET Test Client</title></head><body>
28 <H1>Hosts</H1>
29 <?php
31 $hosts = get_records('mnet_host');
33 foreach ($hosts as $id => $host) {
34 // Skip the 'all hosts' option
35 if(empty($host->wwwroot)) continue;
36 // Skip localhost
37 if($host->wwwroot == $CFG->wwwroot) continue;
38 // Skip non-moodle hosts
39 if($host->applicationid != 1 && $host->applicationid != 2) continue; //TODO: get rid of magic numbers.
40 echo '<p><a href="testclient.php?hostid='.$host->id.'">'.$host->wwwroot."</a></p>\n";
43 if (!empty($_GET['hostid']) && array_key_exists($_GET['hostid'], $hosts)) {
44 $host = $hosts[$_GET['hostid']];
45 $mnet_peer = new mnet_peer();
46 $mnet_peer->set_wwwroot($host->wwwroot);
48 $mnet_request = new mnet_xmlrpc_client();
50 // Tell it the path to the method that we want to execute
51 $mnet_request->set_method('system/listServices');
52 $mnet_request->send($mnet_peer);
53 $services = $mnet_request->response;
54 $yesno = array('No', 'Yes');
55 $servicenames = array();
57 echo '<hr /><br /><h3>Services available on host: '.$host->wwwroot .'</h3><table><tr valign="top"><th>&nbsp;&nbsp;Service ID&nbsp;&nbsp;</th><th>&nbsp;&nbsp;Service&nbsp;&nbsp;</th><th>&nbsp;&nbsp;Version&nbsp;&nbsp;</th><th>&nbsp;&nbsp;They Publish&nbsp;&nbsp;</th><th>&nbsp;&nbsp;They Subscribe&nbsp;&nbsp;</th><th></th></tr>';
58 foreach ($services as $id => $service) {
59 $sql = 'select c.id, c.parent_type, c.parent from '.$CFG->prefix.'mnet_service2rpc a,'.$CFG->prefix.'mnet_service b, '.$CFG->prefix.'mnet_rpc c where a.serviceid = b.id and b.name=\''.addslashes($service['name']).'\' and c.id = a.rpcid ';
61 echo '<tr valign="top">
62 <td>'.$service['name'].'</td>';
63 if ($detail = get_record_sql($sql)) {
64 $service['humanname'] = get_string($service['name'].'_name', $detail->parent_type.'_'.$detail->parent);
65 echo '<td>'.$service['humanname'].'</td>';
66 } else {
67 $service['humanname'] = $service['name'];
68 echo '<td> unknown </td>';
70 echo '
71 <td>'.$service['apiversion'].'</td>
72 <td>'.$yesno[$service['publish']].'</td>
73 <td>'.$yesno[$service['subscribe']].'</td>
74 <td><a href="testclient.php?hostid='.$host->id.'&service='.$service['name'].'">List methods</a></td>
75 </tr>'."\n";
76 $servicenames[$service['name']] = $service;
78 echo '</table>';
82 if (isset($_GET['service']) && array_key_exists($_GET['service'], $servicenames)) {
83 $service = $servicenames[$_GET['service']];
84 // Tell it the path to the method that we want to execute
85 $mnet_request->set_method('system/listMethods');
86 $mnet_request->add_param($service['name'], 'string');
87 $mnet_request->send($mnet_peer);
88 $methods = $mnet_request->response;
90 echo '<hr /><br /><h3>Methods in the '.$service['humanname'] .' service</h3><table><th>Method</th><th colspan="2">Options</th>';
91 foreach ($methods as $id => $method) {
92 echo '<tr><td>'.$method.'</td><td> <a href="testclient.php?hostid='.$host->id.'&service='.$service['name'].'&method='.$id.'&show=sig">Inspect</a></td></tr>'."\n";
94 echo '</table>';
95 } else {
96 // Tell it the path to the method that we want to execute
97 $mnet_request->set_method('system/listMethods');
98 $mnet_request->send($mnet_peer);
99 $methods = $mnet_request->response;
101 echo '<hr /><br /><h3>Methods '.$host->wwwroot .'</h3><table><th>Method</th><th colspan="2">Options</th>';
102 foreach ($methods as $id => $method) {
103 echo '<tr><td>'.$method.'</td><td> <a href="testclient.php?hostid='.$host->id.'&method='.$id.'&show=sig">Inspect</a></td></tr>'."\n";
105 echo '</table>';
108 if (isset($_GET['method']) && array_key_exists($_GET['method'], $methods)) {
109 $method = $methods[$_GET['method']];
111 $mnet_request = new mnet_xmlrpc_client();
113 // Tell it the path to the method that we want to execute
114 $mnet_request->set_method('system/methodSignature');
115 $mnet_request->add_param($method, 'string');
116 $mnet_request->send($mnet_peer);
117 $signature = $mnet_request->response;
118 echo '<hr /><br /><h3>Method signature for '.$method.':</h3><table border="1"><th>Position</th><th>Type</th><th>Description</th>';
119 $params = array_pop($signature);
120 foreach ($params as $pos => $details) {
121 echo '<tr><td>'.$pos.'</td><td>'.$details['type'].'</td><td>'.$details['description'].'</td></tr>';
123 echo '</table>';
125 // Tell it the path to the method that we want to execute
126 $mnet_request->set_method('system/methodHelp');
127 $mnet_request->add_param($method, 'string');
128 $mnet_request->send($mnet_peer);
129 $help = $mnet_request->response;
130 echo '<hr /><br /><h3>Help details from docblock for '.$method.':</h3>';
131 echo(str_replace('\n', '<br />',$help));
132 echo '</pre>';
138 </body>
139 </html>