Directory structure refactoring.
[siap.git] / ws / siacc_wsclient.php
CommitLineData
1c21f490
MS
1<?php
2// Pull in the NuSOAP code
3require_once('nusoap/lib/nusoap.php');
4// Create the client instance
5
6function create_soap_client() {
7 $client = new soapclient(
8 'http://siap.ufcspa.edu.br/ws/siap_ws.php?wsdl', true);
9 $err = $client->getError();
10 if ($err) {
11 // Display the error
12 echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
13 // At this point, you know the call that follows will fail
14 }
15 return $client;
16}
17
18function call_soap_method($client, $method, $parameters) {
19 $result = $client->call($method, $parameters);
20 // Check for a fault
21 if ($client->fault) {
22 echo '<h2>Fault</h2><pre>';
23 print_r($result);
24 echo '</pre>';
25 $result = NULL;
26 } else {
27 // Check for errors
28 $err = $client->getError();
29 if ($err) {
30 // Display the error
31 echo '<h2>Error</h2><pre>' . $err . '</pre>';
32 $result = NULL;
33 }
34 }
35 return $result;
36}
37
38function print_wordlist($wordlist){
39 foreach($wordlist as $word){
40 echo '<p>'.$word['id'].' => '.$word['nome'].'</p>';
41 }
42}
43
44
45header('Content-type: text/html; charset=ISO-8859-1');
46
47$client = create_soap_client();
48
49$search_types = call_soap_method($client, 'get_search_types', array());
50if ($search_types) {
51 echo '<h2>Tipos de busca para Imagem</h2><pre>';
52 print_wordlist($search_types);
53 echo '</pre>';
54}
55
56foreach ($search_types as &$search_type) {
57 $result = call_soap_method($client, 'get_search_type_keywords', array('search_type' => $search_type['id']));
58 if ($result) {
59 echo '<h2>Palavras-chave para '.$search_type['nome'].':</h2><pre>';
60 print_wordlist($result);
61 echo '</pre>';
62 }
63}
64
65
66$search_results = call_soap_method($client, 'search', array('search_request' => array(
67 'palavra'=>'abscesso', 'sistema'=>8, 'procedencia'=>15, 'patologia'=>'')));
68
69if ($search_results) {
70 echo '<h2>Resultados da busca para "abscesso" no sistema nervoso:</h2><pre>';
71 echo 'Mostrando ' .sizeof($search_results).' resultados. <br><br>';
72 foreach($search_results as &$result){
73 echo 'Nome: '.$result['nome'].'<br>';
74 echo 'Sistema: '.$result['sistema'].'<br>';
75 echo 'Procedencia: '.$result['procedencia'].'<br>';
76 echo 'Patologia: '.$result['patologia'].'<br>';
77 echo 'URL: '.$result['url'].'<br>';
78 echo '<br>';
79
80 }
81 echo '</pre>';
82}
83
84
85// Display the request and response
86echo '<h2>Request</h2>';
87echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
88echo '<h2>Response</h2>';
89echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
90
91?>