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
20 use C4::ILSDI::Services;
27 =head1 DLF ILS-DI for Koha
29 This script is a basic implementation of ILS-DI protocol for Koha.
30 It acts like a dispatcher, that get the CGI request, check required and
31 optionals arguments, call a function from C4::ILS-DI::Services, and finaly
32 outputs the returned hashref as XML.
36 # Instanciate the CGI request
39 # List of available services, sorted by level
41 'Describe', # Not part of ILS-DI, online API doc
42 # Level 1: Basic Discovery Interfaces
43 # 'HarvestBibliographicRecords', # OAI-PMH
44 # 'HarvestExpandedRecords', # OAI-PMH
45 'GetAvailability', # FIXME Add bibbliographic level
46 # 'GoToBibliographicRequestPage' # I don't understant this one
47 # Level 2: Elementary OPAC supplement
48 # 'HarvestAuthorityRecords', # OAI-PMH
49 # 'HarvestHoldingsRecords', # OAI-PMH
50 'GetRecords', # Note that we can use OAI-PMH for this too
53 'GetAuthorityRecords',
54 # 'OutputRewritablePage', # I don't understant this one
55 # 'OutputIntermediateFormat', # I don't understant this one
56 # Level 3: Elementary OPAC alternative
61 'GetServices', # FIXME Loans
63 'HoldTitle', # FIXME Add dates support
64 'HoldItem', # FIXME Add dates support
66 # 'RecallItem', # Not supported by Koha
67 # 'CancelRecall', # Not supported by Koha
68 # Level 4: Robust/domain specific discovery platforms
69 # 'SearchCourseReserves', # TODO
73 # List of required arguments
75 'Describe' => ['verb'],
76 'GetAvailability' => ['id', 'id_type'],
77 'GetRecords' => ['id'],
78 'GetAuthorityRecords' => ['id'],
79 'LookupPatron' => ['id'],
80 'AuthenticatePatron' => ['username', 'password'],
81 'GetPatronInfo' => ['patron_id'],
82 'GetPatronStatus' => ['patron_id'],
83 'GetServices' => ['patron_id', 'item_id'],
84 'RenewLoan' => ['patron_id', 'item_id'],
85 'HoldTitle' => ['patron_id', 'bib_id', 'request_location'],
86 'HoldItem' => ['patron_id', 'bib_id', 'item_id'],
87 'CancelHold' => ['patron_id', 'item_id'],
90 # List of optional arguments
93 'GetAvailability' => ['return_type', 'return_fmt'],
94 'GetRecords' => ['schema'],
95 'GetAuthorityRecords' => ['schema'],
96 'LookupPatron' => ['id_type'],
97 'AuthenticatePatron' => [],
98 'GetPatronInfo' => ['show_contact', 'show_fines', 'show_holds', 'show_loans'],
99 'GetPatronStatus' => [],
101 'RenewLoan' => ['desired_due_date'],
102 'HoldTitle' => ['pickup_location', 'needed_before_date', 'pickup_expiry_date'],
103 'HoldItem' => ['pickup_location', 'needed_before_date', 'pickup_expiry_date'],
107 # If ILS-DI module is disabled in System->Preferences, redirect to 404
108 if (not C4::Context->preference('ILS-DI')) {
109 print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
112 # If no service is requested, display the online documentation
113 if (not $cgi->param('service')) {
114 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
116 template_name => "ilsdi.tmpl",
119 authnotrequired => 1,
123 output_html_with_http_headers $cgi, $cookie, $template->output;
127 # If user requested a service description, then display it
128 if ($cgi->param('service') eq "Describe" and grep {$cgi->param('verb') eq $_} @services) {
129 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
131 template_name => "ilsdi.tmpl",
134 authnotrequired => 1,
138 $template->param( $cgi->param('verb') => 1 );
139 output_html_with_http_headers $cgi, $cookie, $template->output;
143 my $service = $cgi->param('service') || "ilsdi";
147 # Check if the requested service is in the list
148 if ($service and grep {$service eq $_} @services) {
150 my @parmsrequired = @{$required{$service}};
151 my @parmsoptional = @{$optional{$service}};
152 my @parmsall = (@parmsrequired, @parmsoptional);
153 my @names = $cgi->param;
155 foreach my $name (@names) {
156 $paramhash{$name} = 1;
159 # check for missing parameters
160 foreach my $name (@parmsrequired) {
161 if ((! exists $paramhash{$name})) {
162 $out->{'message'} = "missing $name parameter";
166 # check for illegal parameters
167 foreach my $name (@names) {
169 foreach my $name2 (@parmsall) {
170 if ($name eq $name2) {
174 if (($found == 0) && ($name ne 'service')) {
175 $out->{'message'} = "$name is an illegal parameter";
179 # check for multiple parameters
180 foreach my $name (@names) {
181 my @values = $cgi->param($name);
183 $out->{'message'} = "multiple values are not allowed for the $name parameter";
187 if (! $out->{'message'}) {
188 # GetAvailability is a special case, as it cannot use XML::Simple
189 if ($service eq "GetAvailability") {
190 print CGI::header('text/xml');
191 print C4::ILSDI::Services::GetAvailability($cgi);
198 my $symbol = 'C4::ILSDI::Services::'.$service;
201 # Call the requested service, and get its return value
207 $out->{'message'} = "NotSupported";
210 # Output XML by passing the hashref to XMLOut
211 print CGI::header('text/xml');
216 xmldecl => '<?xml version="1.0" encoding="ISO-8859-1" ?>',
217 RootName => $service,