3 # Copyright 2009 SARL Biblibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
23 use C4
::ILSDI
::Services
;
30 =head1 DLF ILS-DI for Koha
32 This script is a basic implementation of ILS-DI protocol for Koha.
33 It acts like a dispatcher, that get the CGI request, check required and
34 optionals arguments, call a function from C4::ILS-DI::Services, and finaly
35 outputs the returned hashref as XML.
39 # Instanciate the CGI request
42 # List of available services, sorted by level
44 'Describe', # Not part of ILS-DI, online API doc
46 # Level 1: Basic Discovery Interfaces
47 # 'HarvestBibliographicRecords', # OAI-PMH
48 # 'HarvestExpandedRecords', # OAI-PMH
49 'GetAvailability', # FIXME Add bibbliographic level
51 # 'GoToBibliographicRequestPage' # I don't understant this one
52 # Level 2: Elementary OPAC supplement
53 # 'HarvestAuthorityRecords', # OAI-PMH
54 # 'HarvestHoldingsRecords', # OAI-PMH
55 'GetRecords', # Note that we can use OAI-PMH for this too
59 'GetAuthorityRecords',
61 # 'OutputRewritablePage', # I don't understant this one
62 # 'OutputIntermediateFormat', # I don't understant this one
63 # Level 3: Elementary OPAC alternative
68 'GetServices', # FIXME Loans
70 'HoldTitle', # FIXME Add dates support
71 'HoldItem', # FIXME Add dates support
74 # 'RecallItem', # Not supported by Koha
75 # 'CancelRecall', # Not supported by Koha
76 # Level 4: Robust/domain specific discovery platforms
77 # 'SearchCourseReserves', # TODO
81 # List of required arguments
83 'Describe' => ['verb'],
84 'GetAvailability' => [ 'id', 'id_type' ],
85 'GetRecords' => ['id'],
86 'GetAuthorityRecords' => ['id'],
87 'LookupPatron' => ['id'],
88 'AuthenticatePatron' => [ 'username', 'password' ],
89 'GetPatronInfo' => ['patron_id'],
90 'GetPatronStatus' => ['patron_id'],
91 'GetServices' => [ 'patron_id', 'item_id' ],
92 'RenewLoan' => [ 'patron_id', 'item_id' ],
93 'HoldTitle' => [ 'patron_id', 'bib_id', 'request_location' ],
94 'HoldItem' => [ 'patron_id', 'bib_id', 'item_id' ],
95 'CancelHold' => [ 'patron_id', 'item_id' ],
98 # List of optional arguments
101 'GetAvailability' => [ 'return_type', 'return_fmt' ],
102 'GetRecords' => ['schema'],
103 'GetAuthorityRecords' => ['schema'],
104 'LookupPatron' => ['id_type'],
105 'AuthenticatePatron' => [],
106 'GetPatronInfo' => [ 'show_contact', 'show_fines', 'show_holds', 'show_loans' ],
107 'GetPatronStatus' => [],
109 'RenewLoan' => ['desired_due_date'],
110 'HoldTitle' => [ 'pickup_location', 'needed_before_date', 'pickup_expiry_date' ],
111 'HoldItem' => [ 'pickup_location', 'needed_before_date', 'pickup_expiry_date' ],
115 # If ILS-DI module is disabled in System->Preferences, redirect to 404
116 if ( not C4
::Context
->preference('ILS-DI') ) {
117 print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
120 # If no service is requested, display the online documentation
121 if ( not $cgi->param('service') ) {
122 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
123 { template_name
=> "ilsdi.tmpl",
126 authnotrequired
=> 1,
130 output_html_with_http_headers
$cgi, $cookie, $template->output;
134 # If user requested a service description, then display it
135 if ( $cgi->param('service') eq "Describe" and grep { $cgi->param('verb') eq $_ } @services ) {
136 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
137 { template_name
=> "ilsdi.tmpl",
140 authnotrequired
=> 1,
144 $template->param( $cgi->param('verb') => 1 );
145 output_html_with_http_headers
$cgi, $cookie, $template->output;
149 my $service = $cgi->param('service') || "ilsdi";
153 # Check if the requested service is in the list
154 if ( $service and grep { $service eq $_ } @services ) {
156 my @parmsrequired = @
{ $required{$service} };
157 my @parmsoptional = @
{ $optional{$service} };
158 my @parmsall = ( @parmsrequired, @parmsoptional );
159 my @names = $cgi->param;
161 foreach my $name (@names) {
162 $paramhash{$name} = 1;
165 # check for missing parameters
166 foreach my $name (@parmsrequired) {
167 if ( ( !exists $paramhash{$name} ) ) {
168 $out->{'message'} = "missing $name parameter";
172 # check for illegal parameters
173 foreach my $name (@names) {
175 foreach my $name2 (@parmsall) {
176 if ( $name eq $name2 ) {
180 if ( ( $found == 0 ) && ( $name ne 'service' ) ) {
181 $out->{'message'} = "$name is an illegal parameter";
185 # check for multiple parameters
186 foreach my $name (@names) {
187 my @values = $cgi->param($name);
188 if ( $#values != 0 ) {
189 $out->{'message'} = "multiple values are not allowed for the $name parameter";
193 if ( !$out->{'message'} ) {
195 # GetAvailability is a special case, as it cannot use XML::Simple
196 if ( $service eq "GetAvailability" ) {
197 print CGI
::header
('text/xml');
198 print C4
::ILSDI
::Services
::GetAvailability
($cgi);
205 my $symbol = 'C4::ILSDI::Services::' . $service;
209 # Call the requested service, and get its return value
214 $out->{'message'} = "NotSupported";
217 # Output XML by passing the hashref to XMLOut
218 print CGI
::header
('-type'=>'text/xml', '-charset'=>'utf-8');
224 xmldecl
=> '<?xml version="1.0" encoding="UTF-8" ?>',
225 RootName
=> $service,