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
45 # Level 1: Basic Discovery Interfaces
46 # 'HarvestBibliographicRecords', # OAI-PMH
47 # 'HarvestExpandedRecords', # OAI-PMH
48 'GetAvailability', # FIXME Add bibbliographic level
49 # 'GoToBibliographicRequestPage' # I don't understant this one
50 # Level 2: Elementary OPAC supplement
51 # 'HarvestAuthorityRecords', # OAI-PMH
52 # 'HarvestHoldingsRecords', # OAI-PMH
53 'GetRecords', # Note that we can use OAI-PMH for this too
56 'GetAuthorityRecords',
57 # 'OutputRewritablePage', # I don't understant this one
58 # 'OutputIntermediateFormat', # I don't understant this one
59 # Level 3: Elementary OPAC alternative
64 'GetServices', # FIXME Loans
66 'HoldTitle', # FIXME Add dates support
67 'HoldItem', # FIXME Add dates support
69 # 'RecallItem', # Not supported by Koha
70 # 'CancelRecall', # Not supported by Koha
71 # Level 4: Robust/domain specific discovery platforms
72 # 'SearchCourseReserves', # TODO
76 # List of required arguments
78 'Describe' => ['verb'],
79 'GetAvailability' => ['id', 'id_type'],
80 'GetRecords' => ['id'],
81 'GetAuthorityRecords' => ['id'],
82 'LookupPatron' => ['id'],
83 'AuthenticatePatron' => ['username', 'password'],
84 'GetPatronInfo' => ['patron_id'],
85 'GetPatronStatus' => ['patron_id'],
86 'GetServices' => ['patron_id', 'item_id'],
87 'RenewLoan' => ['patron_id', 'item_id'],
88 'HoldTitle' => ['patron_id', 'bib_id', 'request_location'],
89 'HoldItem' => ['patron_id', 'bib_id', 'item_id'],
90 'CancelHold' => ['patron_id', 'item_id'],
93 # List of optional arguments
96 'GetAvailability' => ['return_type', 'return_fmt'],
97 'GetRecords' => ['schema'],
98 'GetAuthorityRecords' => ['schema'],
99 'LookupPatron' => ['id_type'],
100 'AuthenticatePatron' => [],
101 'GetPatronInfo' => ['show_contact', 'show_fines', 'show_holds', 'show_loans'],
102 'GetPatronStatus' => [],
104 'RenewLoan' => ['desired_due_date'],
105 'HoldTitle' => ['pickup_location', 'needed_before_date', 'pickup_expiry_date'],
106 'HoldItem' => ['pickup_location', 'needed_before_date', 'pickup_expiry_date'],
110 # If ILS-DI module is disabled in System->Preferences, redirect to 404
111 if (not C4::Context->preference('ILS-DI')) {
112 print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
115 # If no service is requested, display the online documentation
116 if (not $cgi->param('service')) {
117 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
119 template_name => "ilsdi.tmpl",
122 authnotrequired => 1,
126 output_html_with_http_headers $cgi, $cookie, $template->output;
130 # If user requested a service description, then display it
131 if ($cgi->param('service') eq "Describe" and grep {$cgi->param('verb') eq $_} @services) {
132 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
134 template_name => "ilsdi.tmpl",
137 authnotrequired => 1,
141 $template->param( $cgi->param('verb') => 1 );
142 output_html_with_http_headers $cgi, $cookie, $template->output;
146 my $service = $cgi->param('service') || "ilsdi";
150 # Check if the requested service is in the list
151 if ($service and grep {$service eq $_} @services) {
153 my @parmsrequired = @{$required{$service}};
154 my @parmsoptional = @{$optional{$service}};
155 my @parmsall = (@parmsrequired, @parmsoptional);
156 my @names = $cgi->param;
158 foreach my $name (@names) {
159 $paramhash{$name} = 1;
162 # check for missing parameters
163 foreach my $name (@parmsrequired) {
164 if ((! exists $paramhash{$name})) {
165 $out->{'message'} = "missing $name parameter";
169 # check for illegal parameters
170 foreach my $name (@names) {
172 foreach my $name2 (@parmsall) {
173 if ($name eq $name2) {
177 if (($found == 0) && ($name ne 'service')) {
178 $out->{'message'} = "$name is an illegal parameter";
182 # check for multiple parameters
183 foreach my $name (@names) {
184 my @values = $cgi->param($name);
186 $out->{'message'} = "multiple values are not allowed for the $name parameter";
190 if (! $out->{'message'}) {
191 # GetAvailability is a special case, as it cannot use XML::Simple
192 if ($service eq "GetAvailability") {
193 print CGI::header('text/xml');
194 print C4::ILSDI::Services::GetAvailability($cgi);
201 my $symbol = 'C4::ILSDI::Services::'.$service;
204 # Call the requested service, and get its return value
210 $out->{'message'} = "NotSupported";
213 # Output XML by passing the hashref to XMLOut
214 print CGI::header('text/xml');
219 xmldecl => '<?xml version="1.0" encoding="ISO-8859-1" ?>',
220 RootName => $service,