MDL-11278 Admin settings page completed, implementation of settings in the gradebook...
[moodle-pu.git] / mnet / testclient.php
blobd8cdeecc73d3750d0f3df9741fe7bb8971b7705b
1 <?php // $Id$
2 /**
3 * A template to test Moodle's XML-RPC feature
5 * This script 'remotely' executes the mnet_concatenate_strings function in
6 * mnet/testlib.php
7 * It steps through each stage of the process, printing some data as it goes
8 * along. It should help you to get your remote method working.
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(__FILE__)) . '/config.php');
16 require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
18 error_reporting(E_ALL);
20 if (isset($_GET['func']) && is_numeric($_GET['func'])) {
21 $func = $_GET['func'];
24 // Some HTML sugar
25 echo '<?xml version="1.0" encoding="utf-8"?>';
27 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
28 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
29 <head><title>Moodle MNET Test Client</title></head><body>
30 <?php
32 // For the demo, our 'remote' host is actually our local host.
33 $wwwroot = $CFG->wwwroot;
35 // Enter the complete path to the file that contains the function you want to
36 // call on the remote server. In our example the function is in
37 // mnet/testlib/
38 // The function itself is added to that path to complete the $path_to_function
39 // variable
40 $path_to_function[0] = 'mnet/rpclib/mnet_concatenate_strings';
41 $path_to_function[1] = 'mod/scorm/rpclib/scorm_add_floats';
42 $path_to_function[2] = 'system/listMethods';
43 $path_to_function[3] = 'system/methodSignature';
44 $path_to_function[4] = 'system/methodHelp';
45 $path_to_function[5] = 'system/listServices';
46 $path_to_function[6] = 'system/listMethods';
47 $path_to_function[7] = 'system/listMethods';
49 $paramArray[0] = array(array('some string, ', 'string'),
50 array('some other string, ', 'string'),
51 array('and a final string', 'string'));
53 $paramArray[1] = array(array(5.3, 'string'),
54 array(7.1, 'string'),
55 array(8.25323, 'string'));
57 $paramArray[2] = array();
59 $paramArray[3] = array(array('auth/mnet/auth/user_authorise', 'string'));
61 $paramArray[4] = array(array('auth/mnet/auth/user_authorise', 'string'));
63 $paramArray[5] = array();
65 $paramArray[6] = array(array('sso', 'string'));
67 $paramArray[7] = array(array('concatenate', 'string'));
69 echo 'Your local wwwroot appears to be <strong>'. $wwwroot ."</strong>.<br />\n";
70 echo "We will use this as the local <em>and</em> remote hosts.<br /><br />\n";
71 flush();
73 // mnet_peer pulls information about a remote host from the database.
74 $mnet_peer = new mnet_peer();
75 $mnet_peer->set_wwwroot($wwwroot);
77 echo "Your \$mnet_peer from the database looks like:<br />\n<pre>";
78 $h2 = get_object_vars($mnet_peer);
79 while(list($key, $val) = each($h2)) {
80 if (!is_numeric($key)) echo '<strong>'.$key.':</strong> '. $val."\n";
82 echo "</pre><br/>It's ok if that info is not complete - the required field is:<br />\nwwwroot: <b>{$mnet_peer->wwwroot}</b>.<br /><br/>\n";
83 flush();
85 // The transport id is one of:
86 // RPC_HTTPS_VERIFIED 1
87 // RPC_HTTPS_SELF_SIGNED 2
88 // RPC_HTTP_VERIFIED 3
89 // RPC_HTTP_SELF_SIGNED 4
91 if (!$mnet_peer->transport) exit('No transport method is approved for this host in your DB table. Please enable a transport method and try again.');
92 $t[1] = 'http2 (port 443 encrypted) with a verified certificate.';
93 $t[2] = 'https (port 443 encrypted) with a self-signed certificate.';
94 $t[4] = 'http (port 80 unencrypted) with a verified certificate.';
95 $t[8] = 'http (port 80 unencrypted) with a self-signed certificate.';
96 $t[16] = 'http (port 80 unencrypted) unencrypted with no certificate.';
98 echo 'Your transportid is <strong>'.$mnet_peer->transport.'</strong> which represents <em>'.$t[$mnet_peer->transport]."</em><br /><br />\n";
99 flush();
101 // Create a new request object
102 $mnet_request = new mnet_xmlrpc_client();
104 // Tell it the path to the method that we want to execute
105 $mnet_request->set_method($path_to_function[$func]);
106 // Add parameters for your function. The mnet_concatenate_strings takes three
107 // parameters, like mnet_concatenate_strings($string1, $string2, $string3)
108 // PHP is weakly typed, so you can get away with calling most things strings,
109 // unless it's non-scalar (i.e. an array or object or something).
110 foreach($paramArray[$func] as $param) {
111 $mnet_request->add_param($param[0], $param[1]);
114 if (count($mnet_request->params)) {
115 echo 'Your parameters are:<br />';
116 while(list($key, $val) = each($mnet_request->params)) {
117 echo '&nbsp;&nbsp; <strong>'.$key.':</strong> '. $val."<br/>\n";
120 flush();
122 // We send the request:
123 $mnet_request->send($mnet_peer);
127 A var_dump of the decoded response: <strong><pre><?php var_dump($mnet_request->response); ?></pre></strong><br />
129 <?php
130 if (count($mnet_request->params)) {
132 A var_dump of the parameters you sent: <strong><pre><?php var_dump($mnet_request->params); ?></pre></strong><br />
133 <?php
138 Choose a function to call:<br />
139 <a href="testclient.php?func=2">system/listMethods</a><br />
140 <a href="testclient.php?func=3">system/methodSignature</a><br />
141 <a href="testclient.php?func=4">system/methodHelp</a><br />
142 <a href="testclient.php?func=5">listServices</a><br />
143 <a href="testclient.php?func=6">system/listMethods(SSO)</a><br />
144 <a href="testclient.php?func=7">system/listMethods(concatenate)</a><br />
146 </body></html>