MDL-35275 - Left align INPUT boxes and TEXT boxes during Install process, when in...
[moodle.git] / admin / mnet / testclient.php
blob89734e39b14bcbd8d09ea2edc3649542ed398ea6
1 <?php
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 * @package core
9 * @subpackage mnet
10 * @author Donal McMullan donal@catalyst.net.nz
11 * @version 0.0.1
12 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
13 * @package mnet
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');
20 if ($CFG->mnet_dispatcher_mode === 'off') {
21 print_error('mnetdisabled', 'mnet');
24 require_login();
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');
46 $PAGE->set_url($url);
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;
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);
69 $services = $mnet_request->response;
70 $yesno = array('No', 'Yes');
71 $servicenames = array();
73 echo $OUTPUT->heading(get_string('servicesavailableonhost', 'mnet', $host->wwwroot));
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'),
84 $table->data = array();
86 $yesno = array(get_string('no'), get_string('yes'));
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';
103 $serviceinfo = array();
105 foreach ($DB->get_records_sql($sql) as $result) {
106 $serviceinfo[$result->name] = $result->plugintype . '_' . $result->pluginname;
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');
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'))
127 echo html_writer::table($table);
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));
139 $mnet_request->send($mnet_peer);
140 $methods = $mnet_request->response;
143 $table = new html_table();
144 $table->head = array(
145 get_string('method', 'mnet'),
146 get_string('options', 'mnet'),
148 $table->data = array();
150 foreach ($methods as $id => $method) {
151 $params = array('hostid' => $host->id, 'method' => $id+1);
152 if (isset($servicename)) {
153 $params['servicename'] = $servicename;
155 $newurl = new moodle_url($url, $params);
156 $table->data[] = array(
157 $method,
158 html_writer::link($newurl, get_string('inspect', 'mnet'))
161 echo html_writer::table($table);
163 if (isset($methodid) && array_key_exists($methodid-1, $methods)) {
164 $method = $methods[$methodid-1];
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;
172 echo $OUTPUT->heading(get_string('methodsignature', 'mnet', $method));
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'),
181 $table->data = array();
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'],
192 $table->data[] = array(
193 get_string('returnvalue', 'mnet'),
195 $signature['return']['type'],
196 $signature['return']['description']
199 echo html_writer::table($table);
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;
206 echo $OUTPUT->heading(get_string('methodhelp', 'mnet', $method));
207 echo(str_replace('\n', '<br />',$help));
211 echo $OUTPUT->footer();