12a03202784a4279d1cf2d56c013bcc8ed73e952
[siap.git] / siap_ws.php
1 <?php
2 // Pull in the NuSOAP code
3 require_once('nusoap/lib/nusoap.php');
4 require("siap_ws_utils.php");
5
6 // Create the server instance
7 $server = new soap_server();
8 // Initialize WSDL support
9 $server->configureWSDL('siapwsdl', 'urn:siapwsdl');
10
11
12 // Register the data structures used by the service
13 $server->wsdl->addComplexType(
14         'SearchRequest',
15         'complexType',
16         'struct',
17         'all',
18         '',
19         array
20         (
21          'palavra' => array('name' => 'palavra', 'type' => 'xsd:string'),
22          'procedencia' => array('name' => 'procedencia', 'type' => 'xsd:int'),
23          'sistema' => array('name' => 'sistema', 'type' => 'xsd:int'),
24          'patologia' => array('name' => 'patologia', 'type' => 'xsd:int'),
25         )
26         );
27
28 $server->wsdl->addComplexType(
29         'SearchResults',
30         'complexType',
31         'array',
32         'all',
33         '',
34         array
35         (
36          'nome' => array('name' => 'nome', 'type' => 'xsd:string'),
37          'url'=> array('name'=> 'url', 'type'=> 'xsd:string'),
38          'procedencia' => array('name' => 'procedencia', 'type' => 'xsd:string'),
39          'sistema' => array('name' => 'sistema', 'type' => 'xsd:string'),
40          'patologia' => array('name' => 'patologia', 'type' => 'xsd:string'),
41         )
42         );
43
44 $server->wsdl->addComplexType(
45         'WordList',
46         'complexType',
47         'array',
48         'sequence',
49         '',
50         array(
51             'id' => array('name' => 'id', 'type' => 'xsd:int'),
52             'nome' => array('name' => 'nome', 'type' => 'xsd:string')
53             )
54         );
55
56 $server->register('get_search_types',           // method name
57         array(),                // input parameters
58         array('return' => 'tns:WordList'),      // output parameters
59         'urn:siapwsdl',                                         // namespace
60         'urn:siapwsdl#get_search_types',                // soapaction
61         'rpc',                                                                  // style
62         'encoded',                                                              // use
63         'Get an image from the SIAP database'   // documentation
64         );
65
66 $server->register('get_search_type_keywords',           // method name
67         array('search_type' => 'xsd:int'),              // input parameters
68         array('return' => 'tns:WordList'),      // output parameters
69         'urn:siapwsdl',                                         // namespace
70         'urn:siapwsdl#get_search_type_keywords',                // soapaction
71         'rpc',                                                                  // style
72         'encoded',                                                              // use
73         'Get an image from the SIAP database'   // documentation
74         );
75
76 $server->register('search',                                     // method name
77         array('search_request' => 'tns:SearchRequest'), // input parameters
78         array('return' => 'tns:SearchResults'), // output parameters
79         'urn:siapwsdl',                                         // namespace
80         'urn:siapwsdl#search',                                  // soapaction
81         'rpc',                                                                  // style
82         'encoded',                                                              // use
83         'Perform a search in the SIAP database'         // documentation
84         );
85
86 function get_search_types()
87 {
88     // Not available in the database.
89     // Those are the search types available for images.
90     $search_types = array();
91     $search_types[] = array('id' => 1, 'nome' => 'Proced&ecirc;ncia');
92     $search_types[] = array('id' => 2, 'nome' => 'Sistema');
93     $search_types[] = array('id' => 3, 'nome' => 'Patologia');
94     return $search_types;
95 }
96
97 function get_search_type_keywords($search_type)
98 {
99     $ret = array();
100     switch($search_type)
101     {
102         case 1:
103             $ret = get_keywords_by_search_type("procedencia");
104             break;
105         case 2:
106             $ret = get_keywords_by_search_type("sistema");
107             break;
108         case 3:
109             $ret = get_keywords_by_search_type("patologia");
110             break;
111     }
112
113     return $ret;
114 }
115
116
117 function search($search_request) {
118     $result = simple_search($search_request['palavra'], $search_request['procedencia'], $search_request['sistema'], $search_request['patologia']);
119     return $result;
120 }
121
122
123 // Use the request to (try to) invoke the service
124 $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
125 $server->service($HTTP_RAW_POST_DATA);
126 ?>