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
10 * @author Donal McMullan donal@catalyst.net.nz
12 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
15 require(__DIR__
.'/../../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');
20 if ($CFG->mnet_dispatcher_mode
=== 'off') {
21 print_error('mnetdisabled', 'mnet');
25 admin_externalpage_setup('mnettestclient');
27 $context = context_system
::instance();
28 require_capability('moodle/site:config', $context);
30 error_reporting(DEBUG_ALL
);
32 echo $OUTPUT->header();
33 if (!extension_loaded('openssl')) {
34 print_error('requiresopenssl', 'mnet', '', NULL, true);
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
);
42 $hosts = $DB->get_records('mnet_host');
43 $moodleapplicationid = $DB->get_field('mnet_application', 'id', array('name' => 'moodle'));
45 $url = new moodle_url('/admin/mnet/testclient.php');
48 echo $OUTPUT->heading(get_string('hostlist', 'mnet'));
49 foreach ($hosts as $id => $host) {
50 if (empty($host->wwwroot
) ||
$host->wwwroot
== $CFG->wwwroot
) {
53 $newurl = new moodle_url($url, array('hostid' => $host->id
));
54 echo '<p>' . html_writer
::link($newurl, $host->wwwroot
) . '</p>';
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'));
62 $mnet_peer = new mnet_peer();
63 $mnet_peer->set_wwwroot($host->wwwroot
);
65 $mnet_request = new mnet_xmlrpc_client();
67 $mnet_request->set_method('system/listServices');
68 $mnet_request->send($mnet_peer);
70 $services = $mnet_request->response
;
71 $yesno = array('No', 'Yes');
72 $servicenames = array();
74 echo $OUTPUT->heading(get_string('servicesavailableonhost', 'mnet', $host->wwwroot
));
76 if (!empty($mnet_request->error
)) {
77 echo $OUTPUT->heading(get_string('error'), 3);
78 echo html_writer
::alist($mnet_request->error
);
82 $table = new html_table();
84 get_string('serviceid', 'mnet'),
85 get_string('service', 'mnet'),
86 get_string('version', 'mnet'),
87 get_string('theypublish', 'mnet'),
88 get_string('theysubscribe', 'mnet'),
89 get_string('options', 'mnet'),
91 $table->data
= array();
93 $yesno = array(get_string('no'), get_string('yes'));
95 // this query is horrible and has to be remapped afterwards, because of the non-uniqueness
96 // of the remoterep service (it has two plugins so far that use it)
97 // it's possible to get a unique list back using a subquery with LIMIT but that would break oracle
98 // so it's best to just do this small query and then remap the results afterwards
101 ' . $DB->sql_concat('r.plugintype', "'_'", 'r.pluginname', "'_'", 's.name') . ' AS uniqueid,
107 JOIN {mnet_remote_service2rpc} s2r ON s2r.serviceid = s.id
108 JOIN {mnet_remote_rpc} r ON r.id = s2r.rpcid';
110 $serviceinfo = array();
112 foreach ($DB->get_records_sql($sql) as $result) {
113 $serviceinfo[$result->name
] = $result->plugintype
. '_' . $result->pluginname
;
116 foreach ($services as $id => $servicedata) {
117 if (array_key_exists($servicedata['name'], $serviceinfo)) {
118 $service = $serviceinfo[$servicedata['name']];
119 $servicedata['humanname'] = get_string($servicedata['name'].'_name', $service);
121 $servicedata['humanname'] = get_string('unknown', 'mnet');
123 $newurl = new moodle_url($url, array('hostid' => $host->id
, 'servicename' => $servicedata['name']));
124 $table->data
[] = array(
125 $servicedata['name'],
126 $servicedata['humanname'],
127 $servicedata['apiversion'],
128 $yesno[$servicedata['publish']],
129 $yesno[$servicedata['subscribe']],
130 html_writer
::link($newurl, get_string('listservices', 'mnet'))
134 echo html_writer
::table($table);
137 $mnet_request = new mnet_xmlrpc_client();
138 $mnet_request->set_method('system/listMethods');
139 if (isset($servicename) && array_key_exists($servicename, $serviceinfo)) {
140 echo $OUTPUT->heading(get_string('methodsavailableonhostinservice', 'mnet', (object)array('host' => $host->wwwroot
, 'service' => $servicename)));
141 $service = $serviceinfo[$servicename];
142 $mnet_request->add_param($servicename, 'string');
144 echo $OUTPUT->heading(get_string('methodsavailableonhost', 'mnet', $host->wwwroot
));
147 $mnet_request->send($mnet_peer);
148 $methods = $mnet_request->response
;
150 if (!empty($mnet_request->error
)) {
151 echo $OUTPUT->heading(get_string('error'), 3);
152 echo html_writer
::alist($mnet_request->error
);
156 $table = new html_table();
157 $table->head
= array(
158 get_string('method', 'mnet'),
159 get_string('options', 'mnet'),
161 $table->data
= array();
163 foreach ($methods as $id => $method) {
164 $params = array('hostid' => $host->id
, 'method' => $id+
1);
165 if (isset($servicename)) {
166 $params['servicename'] = $servicename;
168 $newurl = new moodle_url($url, $params);
169 $table->data
[] = array(
171 html_writer
::link($newurl, get_string('inspect', 'mnet'))
174 echo html_writer
::table($table);
176 if (isset($methodid) && array_key_exists($methodid-1, $methods)) {
177 $method = $methods[$methodid-1];
179 $mnet_request = new mnet_xmlrpc_client();
180 $mnet_request->set_method('system/methodSignature');
181 $mnet_request->add_param($method, 'string');
182 $mnet_request->send($mnet_peer);
183 $signature = $mnet_request->response
;
185 echo $OUTPUT->heading(get_string('methodsignature', 'mnet', $method));
187 if (!empty($mnet_request->error
)) {
188 echo $OUTPUT->heading(get_string('error'), 3);
189 echo html_writer
::alist($mnet_request->error
);
190 $signature = array();
193 $table = new html_table();
194 $table->head
= array(
195 get_string('position', 'mnet'),
196 get_string('name', 'mnet'),
197 get_string('type', 'mnet'),
198 get_string('description', 'mnet'),
200 $table->data
= array();
202 $params = $signature['parameters'];
203 foreach ($params as $pos => $details) {
204 $table->data
[] = array(
208 $details['description'],
211 $table->data
[] = array(
212 get_string('returnvalue', 'mnet'),
214 $signature['return']['type'],
215 $signature['return']['description']
218 echo html_writer
::table($table);
220 $mnet_request->set_method('system/methodHelp');
221 $mnet_request->add_param($method, 'string');
222 $mnet_request->send($mnet_peer);
223 $help = $mnet_request->response
;
225 echo $OUTPUT->heading(get_string('methodhelp', 'mnet', $method));
226 echo(str_replace('\n', '<br />',$help));
230 echo $OUTPUT->footer();