Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/mnet/testclient.php
Go to the documentation of this file.
00001 <?php
00015 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
00016 require_once $CFG->dirroot.'/mnet/xmlrpc/client.php';
00017 require_once($CFG->libdir.'/adminlib.php');
00018 include_once($CFG->dirroot.'/mnet/lib.php');
00019 
00020 if ($CFG->mnet_dispatcher_mode === 'off') {
00021     print_error('mnetdisabled', 'mnet');
00022 }
00023 
00024 require_login();
00025 admin_externalpage_setup('mnettestclient');
00026 
00027 $context = get_context_instance(CONTEXT_SYSTEM);
00028 require_capability('moodle/site:config', $context);
00029 
00030 error_reporting(DEBUG_ALL);
00031 
00032 echo $OUTPUT->header();
00033 if (!extension_loaded('openssl')) {
00034     print_error('requiresopenssl', 'mnet', '', NULL, true);
00035 }
00036 
00037 // optional drilling down parameters
00038 $hostid = optional_param('hostid', 0, PARAM_INT);
00039 $servicename = optional_param('servicename', '', PARAM_SAFEDIR);
00040 $methodid = optional_param('method', 0, PARAM_INT);
00041 
00042 $hosts = $DB->get_records('mnet_host');
00043 $moodleapplicationid = $DB->get_field('mnet_application', 'id', array('name' => 'moodle'));
00044 
00045 $url = new moodle_url('/admin/mnet/testclient.php');
00046 $PAGE->set_url($url);
00047 
00048 echo $OUTPUT->heading(get_string('hostlist', 'mnet'));
00049 foreach ($hosts as $id => $host) {
00050     if (empty($host->wwwroot) || $host->wwwroot == $CFG->wwwroot) {
00051         continue;
00052     }
00053     $newurl = new moodle_url($url, array('hostid' => $host->id));
00054     echo '<p>' . html_writer::link($newurl, $host->wwwroot) . '</p>';
00055 }
00056 
00057 if (!empty($hostid) && array_key_exists($hostid, $hosts)) {
00058     $host = $hosts[$hostid];
00059     if ($host->applicationid != $moodleapplicationid) {
00060         echo $OUTPUT->notification(get_string('notmoodleapplication', 'mnet'));
00061     }
00062     $mnet_peer = new mnet_peer();
00063     $mnet_peer->set_wwwroot($host->wwwroot);
00064 
00065     $mnet_request = new mnet_xmlrpc_client();
00066 
00067     $mnet_request->set_method('system/listServices');
00068     $mnet_request->send($mnet_peer);
00069     $services = $mnet_request->response;
00070     $yesno = array('No', 'Yes');
00071     $servicenames = array();
00072 
00073     echo $OUTPUT->heading(get_string('servicesavailableonhost', 'mnet', $host->wwwroot));
00074 
00075     $table = new html_table();
00076     $table->head = array(
00077         get_string('serviceid', 'mnet'),
00078         get_string('service', 'mnet'),
00079         get_string('version', 'mnet'),
00080         get_string('theypublish', 'mnet'),
00081         get_string('theysubscribe', 'mnet'),
00082         get_string('options', 'mnet'),
00083     );
00084     $table->data = array();
00085 
00086     $yesno = array(get_string('no'), get_string('yes'));
00087 
00088     // this query is horrible and has to be remapped afterwards, because of the non-uniqueness
00089     // of the remoterep service (it has two plugins so far that use it)
00090     // it's possible to get a unique list back using a subquery with LIMIT but that would break oracle
00091     // so it's best to just do this small query and then remap the results afterwards
00092     $sql = '
00093         SELECT DISTINCT
00094             ' . $DB->sql_concat('r.plugintype', "'_'", 'r.pluginname', "'_'", 's.name')  . ' AS uniqueid,
00095              s.name,
00096              r.plugintype,
00097              r.pluginname
00098         FROM
00099             {mnet_service} s
00100        JOIN {mnet_remote_service2rpc} s2r ON s2r.serviceid = s.id
00101        JOIN {mnet_remote_rpc} r ON r.id = s2r.rpcid';
00102 
00103     $serviceinfo = array();
00104 
00105     foreach ($DB->get_records_sql($sql) as $result) {
00106         $serviceinfo[$result->name] = $result->plugintype . '_' . $result->pluginname;
00107     }
00108 
00109     foreach ($services as $id => $servicedata) {
00110         if (array_key_exists($servicedata['name'], $serviceinfo)) {
00111             $service = $serviceinfo[$servicedata['name']];
00112             $servicedata['humanname'] = get_string($servicedata['name'].'_name', $service);
00113         } else {
00114             $servicedata['humanname'] = get_string('unknown', 'mnet');
00115         }
00116         $newurl = new moodle_url($url, array('hostid' => $host->id, 'servicename' => $servicedata['name']));
00117         $table->data[] = array(
00118             $servicedata['name'],
00119             $servicedata['humanname'],
00120             $servicedata['apiversion'],
00121             $yesno[$servicedata['publish']],
00122             $yesno[$servicedata['subscribe']],
00123             html_writer::link($newurl, get_string('listservices', 'mnet'))
00124         );
00125 
00126     }
00127     echo html_writer::table($table);
00128 
00129 
00130     $mnet_request->set_method('system/listMethods');
00131     if (isset($servicename) && array_key_exists($servicename, $serviceinfo)) {
00132         echo $OUTPUT->heading(get_string('methodsavailableonhostinservice', 'mnet', (object)array('host' => $host->wwwroot, 'service' => $servicename)));
00133         $service = $serviceinfo[$servicename];
00134         $mnet_request->add_param($servicename, 'string');
00135     } else {
00136         echo $OUTPUT->heading(get_string('methodsavailableonhost', 'mnet', $host->wwwroot));
00137     }
00138 
00139     $mnet_request->send($mnet_peer);
00140     $methods = $mnet_request->response;
00141 
00142 
00143     $table = new html_table();
00144     $table->head = array(
00145         get_string('method', 'mnet'),
00146         get_string('options', 'mnet'),
00147     );
00148     $table->data = array();
00149 
00150     foreach ($methods as $id => $method) {
00151         $params = array('hostid' => $host->id, 'method' => $id+1);
00152         if (isset($servicename)) {
00153             $params['servicename'] = $servicename;
00154         }
00155         $newurl = new moodle_url($url, $params);
00156         $table->data[] = array(
00157             $method,
00158             html_writer::link($newurl, get_string('inspect', 'mnet'))
00159         );
00160     }
00161     echo html_writer::table($table);
00162 
00163     if (isset($methodid) && array_key_exists($methodid-1, $methods)) {
00164         $method = $methods[$methodid-1];
00165 
00166         $mnet_request = new mnet_xmlrpc_client();
00167         $mnet_request->set_method('system/methodSignature');
00168         $mnet_request->add_param($method, 'string');
00169         $mnet_request->send($mnet_peer);
00170         $signature = $mnet_request->response;
00171 
00172         echo $OUTPUT->heading(get_string('methodsignature', 'mnet', $method));
00173 
00174         $table = new html_table();
00175         $table->head = array(
00176             get_string('position', 'mnet'),
00177             get_string('name', 'mnet'),
00178             get_string('type', 'mnet'),
00179             get_string('description', 'mnet'),
00180         );
00181         $table->data = array();
00182 
00183         $params = $signature['parameters'];
00184         foreach ($params as $pos => $details) {
00185             $table->data[] = array(
00186                 $pos,
00187                 $details['name'],
00188                 $details['type'],
00189                 $details['description'],
00190             );
00191         }
00192         $table->data[] = array(
00193             get_string('returnvalue', 'mnet'),
00194             '',
00195             $signature['return']['type'],
00196             $signature['return']['description']
00197         );
00198 
00199         echo html_writer::table($table);
00200 
00201         $mnet_request->set_method('system/methodHelp');
00202         $mnet_request->add_param($method, 'string');
00203         $mnet_request->send($mnet_peer);
00204         $help = $mnet_request->response;
00205 
00206         echo $OUTPUT->heading(get_string('methodhelp', 'mnet', $method));
00207         echo(str_replace('\n', '<br />',$help));
00208     }
00209 }
00210 
00211 echo $OUTPUT->footer();
00212 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations