Merge commit 'koha-public/biblibre-sopac' into to-master

[Merge the ILS-DI web services used for integration with SOPAC]

Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
This commit is contained in:
Galen Charlton 2009-09-29 20:30:17 -04:00
commit ef6f41c329
5 changed files with 1915 additions and 0 deletions

792
C4/ILSDI/Services.pm Normal file
View File

@ -0,0 +1,792 @@
package C4::ILSDI::Services;
# Copyright 2009 SARL Biblibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use warnings;
use C4::Members;
use C4::Items;
use C4::Circulation;
use C4::Branch;
use C4::Accounts;
use C4::Biblio;
use C4::Reserves;
use C4::Context;
use C4::AuthoritiesMarc;
use C4::ILSDI::Utility;
use XML::Simple;
use HTML::Entities;
use CGI;
=head1 NAME
C4::ILS-DI::Services - ILS-DI Services
=head1 DESCRIPTION
Each function in this module represents an ILS-DI service.
They all takes a CGI instance as argument and most of them return a
hashref that will be printed by XML::Simple in opac/ilsdi.pl
=head1 SYNOPSIS
use C4::ILSDI::Services;
use XML::Simple;
use CGI;
my $cgi = new CGI;
$out = LookupPatron($cgi);
print CGI::header('text/xml');
print XMLout($out,
noattr => 1,
noescape => 1,
nosort => 1,
xmldecl => '<?xml version="1.0" encoding="ISO-8859-1" ?>',
RootName => 'LookupPatron',
SuppressEmpty => 1);
=cut
=head2 GetAvailability
Given a set of biblionumbers or itemnumbers, returns a list with
availability of the items associated with the identifiers.
Parameters :
- id (Required)
list of either biblionumbers or itemnumbers
- id_type (Required)
defines the type of record identifier being used in the request,
possible values:
- bib
- item
- return_type (Optional)
requests a particular level of detail in reporting availability,
possible values:
- bib
- item
- return_fmt (Optional)
requests a particular format or set of formats in reporting
availability
=cut
sub GetAvailability {
my ($cgi) = @_;
my $out = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
$out .= "<dlf:collection\n";
$out .= " xmlns:dlf=\"http://diglib.org/ilsdi/1.1\"\n";
$out .= " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
$out .= " xsi:schemaLocation=\"http://diglib.org/ilsdi/1.1\n";
$out .= " http://diglib.org/architectures/ilsdi/schemas/1.1/dlfexpanded.xsd\">\n";
foreach my $id ( split( / /, $cgi->param('id') ) ) {
if ( $cgi->param('id_type') eq "item" ) {
my ( $biblionumber, $status, $msg, $location ) = Availability($id);
$out .= " <dlf:record>\n";
$out .= " <dlf:bibliographic id=\"" . ( $biblionumber || $id ) . "\" />\n";
$out .= " <dlf:items>\n";
$out .= " <dlf:item id=\"" . $id . "\">\n";
$out .= " <dlf:simpleavailability>\n";
$out .= " <dlf:identifier>" . $id . "</dlf:identifier>\n";
$out .= " <dlf:availabilitystatus>" . $status . "</dlf:availabilitystatus>\n";
if ($msg) { $out .= " <dlf:availabilitymsg>" . $msg . "</dlf:availabilitymsg>\n"; }
if ($location) { $out .= " <dlf:location>" . $location . "</dlf:location>\n"; }
$out .= " </dlf:simpleavailability>\n";
$out .= " </dlf:item>\n";
$out .= " </dlf:items>\n";
$out .= " </dlf:record>\n";
} else {
my $status;
my $msg;
my $biblioitem = ( GetBiblioItemByBiblioNumber( $id, undef ) )[0];
if ($biblioitem) {
} else {
$status = "unknown";
$msg = "Error: could not retrieve availability for this ID";
}
$out .= " <dlf:record>\n";
$out .= " <dlf:bibliographic id=\"" . $id . "\" />\n";
$out .= " <dlf:simpleavailability>\n";
$out .= " <dlf:identifier>" . $id . "</dlf:identifier>\n";
$out .= " <dlf:availabilitystatus>" . $status . "</dlf:availabilitystatus>\n";
$out .= " <dlf:availabilitymsg>" . $msg . "</dlf:availabilitymsg>\n";
$out .= " </dlf:simpleavailability>\n";
$out .= " </dlf:record>\n";
}
}
$out .= "</dlf:collection>\n";
return $out;
}
=head2 GetRecords
Given a list of biblionumbers, returns a list of record objects that
contain bibliographic information, as well as associated holdings and item
information. The caller may request a specific metadata schema for the
record objects to be returned.
This function behaves similarly to HarvestBibliographicRecords and
HarvestExpandedRecords in Data Aggregation, but allows quick, real time
lookup by bibliographic identifier.
You can use OAI-PMH ListRecords instead of this service.
Parameters:
- id (Required)
list of system record identifiers
- id_type (Optional)
Defines the metadata schema in which the records are returned,
possible values:
- MARCXML
=cut
sub GetRecords {
my ($cgi) = @_;
# Check if the schema is supported. For now, GetRecords only supports MARCXML
if ( $cgi->param('schema') and $cgi->param('schema') ne "MARCXML" ) {
return { message => 'UnsupportedSchema' };
}
my @records;
# Loop over biblionumbers
foreach my $biblionumber ( split( / /, $cgi->param('id') ) ) {
# Get the biblioitem from the biblionumber
my $biblioitem = ( GetBiblioItemByBiblioNumber( $biblionumber, undef ) )[0];
if ( not $biblioitem->{'biblionumber'} ) {
$biblioitem = "RecordNotFound";
}
# We don't want MARC to be displayed
delete $biblioitem->{'marc'};
# nor the XML declaration of MARCXML
$biblioitem->{'marcxml'} =~ s/<\?xml version="1.0" encoding="UTF-8"\?>//go;
# Get most of the needed data
my $biblioitemnumber = $biblioitem->{'biblioitemnumber'};
my @reserves = GetReservesFromBiblionumber( $biblionumber, undef, undef );
my $issues = GetBiblioIssues($biblionumber);
my $items = GetItemsByBiblioitemnumber($biblioitemnumber);
# We loop over the items to clean them
foreach my $item (@$items) {
# This hides additionnal XML subfields, we don't need these info
delete $item->{'more_subfields_xml'};
# Display branch names instead of branch codes
$item->{'homebranchname'} = GetBranchName( $item->{'homebranch'} );
$item->{'holdingbranchname'} = GetBranchName( $item->{'holdingbranch'} );
}
# Hashref building...
$biblioitem->{'items'}->{'item'} = $items;
$biblioitem->{'reserves'}->{'reserve'} = $reserves[1];
$biblioitem->{'issues'}->{'issue'} = $issues;
map { $biblioitem->{$_} = encode_entities( $biblioitem->{$_}, '&' ) } grep( !/marcxml/, keys %$biblioitem );
push @records, $biblioitem;
}
return { record => \@records };
}
=head2 GetAuthorityRecords
Given a list of authority record identifiers, returns a list of record
objects that contain the authority records. The function user may request
a specific metadata schema for the record objects.
Parameters:
- id (Required)
list of authority record identifiers
- schema (Optional)
specifies the metadata schema of records to be returned, possible values:
- MARCXML
=cut
sub GetAuthorityRecords {
my ($cgi) = @_;
# If the user asks for an unsupported schema, return an error code
if ( $cgi->param('schema') and $cgi->param('schema') ne "MARCXML" ) {
return { message => 'UnsupportedSchema' };
}
my $records;
# Let's loop over the authority IDs
foreach my $authid ( split( / /, $cgi->param('id') ) ) {
# Get the record as XML string, or error code
my $record = GetAuthorityXML($authid) || "<record>RecordNotFound</record>";
$record =~ s/<\?xml version="1.0" encoding="UTF-8"\?>//go;
$records .= $record;
}
return $records;
}
=head2 LookupPatron
Looks up a patron in the ILS by an identifier, and returns the borrowernumber.
Parameters:
- id (Required)
an identifier used to look up the patron in Koha
- id_type (Optional)
the type of the identifier, possible values:
- cardnumber
- firstname
- userid
- borrowernumber
=cut
sub LookupPatron {
my ($cgi) = @_;
# Get the borrower...
my $borrower = GetMember( $cgi->param('id'), $cgi->param('id_type') );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Build the hashref
my $patron->{'id'} = $borrower->{'borrowernumber'};
# ...and return his ID
return $patron;
}
=head2 AuthenticatePatron
Authenticates a user's login credentials and returns the identifier for
the patron.
Parameters:
- username (Required)
user's login identifier
- password (Required)
user's password
=cut
sub AuthenticatePatron {
my ($cgi) = @_;
# Check if borrower exists, using a C4::ILSDI::Utility function...
if ( not( BorrowerExists( $cgi->param('username'), $cgi->param('password') ) ) ) {
return { message => 'PatronNotFound' };
}
# Get the borrower
my $borrower = GetMember( $cgi->param('username'), "userid" );
# Build the hashref
my $patron->{'id'} = $borrower->{'borrowernumber'};
# ... and return his ID
return $patron;
}
=head2 GetPatronInfo
Returns specified information about the patron, based on options in the
request. This function can optionally return patron's contact information,
fine information, hold request information, and loan information.
Parameters:
- patron_id (Required)
the borrowernumber
- show_contact (Optional, default 1)
whether or not to return patron's contact information in the response
- show_fines (Optional, default 0)
whether or not to return fine information in the response
- show_holds (Optional, default 0)
whether or not to return hold request information in the response
- show_loans (Optional, default 0)
whether or not to return loan information request information in the response
=cut
sub GetPatronInfo {
my ($cgi) = @_;
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Cleaning the borrower hashref
$borrower->{'charges'} = $borrower->{'flags'}->{'CHARGES'}->{'amount'};
$borrower->{'branchname'} = GetBranchName( $borrower->{'branchcode'} );
delete $borrower->{'flags'};
delete $borrower->{'userid'};
delete $borrower->{'password'};
# Contact fields management
if ( $cgi->param('show_contact') eq "0" ) {
# Define contact fields
my @contactfields = (
'email', 'emailpro', 'fax', 'mobile', 'phone', 'phonepro',
'streetnumber', 'zipcode', 'city', 'streettype', 'B_address', 'B_city',
'B_email', 'B_phone', 'B_zipcode', 'address', 'address2', 'altcontactaddress1',
'altcontactaddress2', 'altcontactaddress3', 'altcontactfirstname', 'altcontactphone', 'altcontactsurname', 'altcontactzipcode'
);
# and delete them
foreach my $field (@contactfields) {
delete $borrower->{$field};
}
}
# Fines management
if ( $cgi->param('show_fines') eq "1" ) {
my @charges;
for ( my $i = 1 ; my @charge = getcharges( $borrowernumber, undef, $i ) ; $i++ ) {
push( @charges, @charge );
}
$borrower->{'fines'}->{'fine'} = \@charges;
}
# Reserves management
if ( $cgi->param('show_holds') eq "1" ) {
# Get borrower's reserves
my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
foreach my $reserve (@reserves) {
# Get additional informations
my $item = GetBiblioFromItemNumber( $reserve->{'itemnumber'}, undef );
my $branchname = GetBranchName( $reserve->{'branchcode'} );
# Remove unwanted fields
delete $item->{'marc'};
delete $item->{'marcxml'};
delete $item->{'more_subfields_xml'};
# Add additional fields
$reserve->{'item'} = $item;
$reserve->{'branchname'} = $branchname;
$reserve->{'title'} = ( GetBiblio( $reserve->{'biblionumber'} ) )[1]->{'title'};
}
$borrower->{'holds'}->{'hold'} = \@reserves;
}
# Issues management
if ( $cgi->param('show_loans') eq "1" ) {
my $issues = GetPendingIssues($borrowernumber);
$borrower->{'loans'}->{'loan'} = $issues;
}
return $borrower;
}
=head2 GetPatronStatus
Returns a patron's status information.
Parameters:
- patron_id (Required)
the borrower ID
=cut
sub GetPatronStatus {
my ($cgi) = @_;
# Get Member details
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Hashref building
my $patron;
$patron->{'type'} = $borrower->{'categorycode'};
$patron->{'status'} = 0; #TODO
$patron->{'expiry'} = $borrower->{'dateexpiry'};
return $patron;
}
=head2 GetServices
Returns information about the services available on a particular item for
a particular patron.
Parameters:
- patron_id (Required)
a borrowernumber
- item_id (Required)
an itemnumber
=cut
sub GetServices {
my ($cgi) = @_;
# Get the member, or return an error code if not found
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Get the item, or return an error code if not found
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber, undef, undef );
if ( not $item->{'itemnumber'} ) {
return { message => 'RecordNotFound' };
}
my @availablefor;
# Reserve level management
my $biblionumber = $item->{'biblionumber'};
my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
if ($canbookbereserved) {
push @availablefor, 'title level hold';
my $canitembereserved = IsAvailableForItemLevelRequest($itemnumber);
if ($canitembereserved) {
push @availablefor, 'item level hold';
}
}
# Reserve cancellation management
my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
my @reserveditems;
foreach my $reserve (@reserves) {
push @reserveditems, $reserve->{'itemnumber'};
}
if ( grep { $itemnumber eq $_ } @reserveditems ) {
push @availablefor, 'hold cancellation';
}
# Renewal management
my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
if ( $renewal[0] ) {
push @availablefor, 'loan renewal';
}
# Issuing management
my $barcode = $item->{'barcode'} || '';
$barcode = barcodedecode($barcode) if ( $barcode && C4::Context->preference('itemBarcodeInputFilter') );
if ($barcode) {
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $borrower, $barcode );
# TODO push @availablefor, 'loan';
}
my $out;
$out->{'AvailableFor'} = \@availablefor;
return $out;
}
=head2 RenewLoan
Extends the due date for a borrower's existing issue.
Parameters:
- patron_id (Required)
a borrowernumber
- item_id (Required)
an itemnumber
- desired_due_date (Required)
the date the patron would like the item returned by
=cut
sub RenewLoan {
my ($cgi) = @_;
# Get borrower infos or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Get the item, or return an error code
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber, undef, undef );
if ( not $item->{'itemnumber'} ) {
return { message => 'RecordNotFound' };
}
# Add renewal if possible
my @renewal = CanBookBeRenewed( $borrowernumber, $itemnumber );
if ( $renewal[0] ) { AddRenewal( $borrowernumber, $itemnumber ); }
my $issue = GetItemIssue($itemnumber);
# Hashref building
my $out;
$out->{'renewals'} = $issue->{'renewals'};
$out->{'date_due'} = $issue->{'date_due'};
$out->{'success'} = $renewal[0];
$out->{'error'} = $renewal[1];
return $out;
}
=head2 HoldTitle
Creates, for a borrower, a biblio-level hold reserve.
Parameters:
- patron_id (Required)
a borrowernumber
- bib_id (Required)
a biblionumber
- request_location (Required)
IP address where the end user request is being placed
- pickup_location (Optional)
a branch code indicating the location to which to deliver the item for pickup
- needed_before_date (Optional)
date after which hold request is no longer needed
- pickup_expiry_date (Optional)
date after which item returned to shelf if item is not picked up
=cut
sub HoldTitle {
my ($cgi) = @_;
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Get the biblio record, or return an error code
my $biblionumber = $cgi->param('bib_id');
my ( $count, $biblio ) = GetBiblio($biblionumber);
if ( not $biblio->{'biblionumber'} ) {
return { message => 'RecordNotFound' };
}
my $title = $biblio->{'title'};
# Check if the biblio can be reserved
my $canbereserved = CanBookBeReserved( $borrower, $biblionumber );
if ( not $canbereserved ) {
return { message => 'NotHoldable' };
}
my $branch;
# Pickup branch management
if ( $cgi->param('pickup_location') ) {
$branch = $cgi->param('pickup_location');
my $branches = GetBranches();
if ( not $branches->{$branch} ) {
return { message => 'LocationNotFound' };
}
} else { # if user provide no branch, use his own
$branch = $borrower->{'branchcode'};
}
# Add the reserve
# $branch, $borrowernumber, $biblionumber, $constraint, $bibitems, $priority, $notes, $title, $checkitem, $found
AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, 0, undef, $title, undef, undef );
# Hashref building
my $out;
$out->{'title'} = $title;
$out->{'pickup_location'} = GetBranchName($branch);
# TODO $out->{'date_available'} = '';
return $out;
}
=head2 HoldItem
Creates, for a borrower, an item-level hold request on a specific item of
a bibliographic record in Koha.
Parameters:
- patron_id (Required)
a borrowernumber
- bib_id (Required)
a biblionumber
- item_id (Required)
an itemnumber
- pickup_location (Optional)
a branch code indicating the location to which to deliver the item for pickup
- needed_before_date (Optional)
date after which hold request is no longer needed
- pickup_expiry_date (Optional)
date after which item returned to shelf if item is not picked up
=cut
sub HoldItem {
my ($cgi) = @_;
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Get the biblio or return an error code
my $biblionumber = $cgi->param('bib_id');
my ( $count, $biblio ) = GetBiblio($biblionumber);
if ( not $biblio->{'biblionumber'} ) {
return { message => 'RecordNotFound' };
}
my $title = $biblio->{'title'};
# Get the item or return an error code
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber, undef, undef );
if ( not $item->{'itemnumber'} ) {
return { message => 'RecordNotFound' };
}
# if the biblio does not match the item, return an error code
if ( $item->{'biblionumber'} ne $biblio->{'biblionumber'} ) {
return { message => 'RecordNotFound' };
}
# Check for item disponibility
my $canitembereserved = IsAvailableForItemLevelRequest($itemnumber);
my $canbookbereserved = CanBookBeReserved( $borrower, $biblionumber );
if ( ( not $canbookbereserved ) or not($canitembereserved) ) {
return { message => 'NotHoldable' };
}
my $branch;
# Pickup branch management
if ( $cgi->param('pickup_location') ) {
$branch = $cgi->param('pickup_location');
my $branches = GetBranches();
if ( not $branches->{$branch} ) {
return { message => 'LocationNotFound' };
}
} else { # if user provide no branch, use his own
$branch = $borrower->{'branchcode'};
}
my $rank;
my $found;
# Get rank and found
$rank = '0' unless C4::Context->preference('ReservesNeedReturns');
if ( $item->{'holdingbranch'} eq $branch ) {
$found = 'W' unless C4::Context->preference('ReservesNeedReturns');
}
# Add the reserve
# $branch, $borrowernumber, $biblionumber, $constraint, $bibitems, $priority, $notes, $title, $checkitem, $found
AddReserve( $branch, $borrowernumber, $biblionumber, 'a', undef, $rank, undef, $title, $itemnumber, $found );
# Hashref building
my $out;
$out->{'pickup_location'} = GetBranchName($branch);
# TODO $out->{'date_available'} = '';
return $out;
}
=head2 CancelHold
Cancels an active reserve request for the borrower.
Parameters:
- patron_id (Required)
a borrowernumber
- item_id (Required)
an itemnumber
=cut
sub CancelHold {
my ($cgi) = @_;
# Get the borrower or return an error code
my $borrowernumber = $cgi->param('patron_id');
my $borrower = GetMemberDetails( $borrowernumber, undef );
if ( not $borrower->{'borrowernumber'} ) {
return { message => 'PatronNotFound' };
}
# Get the item or return an error code
my $itemnumber = $cgi->param('item_id');
my $item = GetItem( $itemnumber, undef, undef );
if ( not $item->{'itemnumber'} ) {
return { message => 'RecordNotFound' };
}
# Get borrower's reserves
my @reserves = GetReservesFromBorrowernumber( $borrowernumber, undef );
my @reserveditems;
# ...and loop over it to build an array of reserved itemnumbers
foreach my $reserve (@reserves) {
push @reserveditems, $reserve->{'itemnumber'};
}
# if the item was not reserved by the borrower, returns an error code
if ( not grep { $itemnumber eq $_ } @reserveditems ) {
return { message => 'NotCanceled' };
}
# Cancel the reserve
CancelReserve( $itemnumber, undef, $borrowernumber );
return { message => 'Canceled' };
}
1;

155
C4/ILSDI/Utility.pm Normal file
View File

@ -0,0 +1,155 @@
package C4::ILSDI::Utility;
# Copyright 2009 SARL Biblibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use warnings;
use C4::Members;
use C4::Items;
use C4::Circulation;
use C4::Biblio;
use C4::Reserves;
use C4::Context;
use C4::Branch qw/GetBranchName/;
use Digest::MD5 qw(md5_base64);
use vars qw($VERSION @ISA @EXPORT);
BEGIN {
# set the version for version checking
$VERSION = 3.00;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&BorrowerExists &CanBookBeReserved &Availability
);
}
=head1 NAME
C4::ILS-DI::Utility - ILS-DI Utilities
=cut
=head2 BorrowerExists
Checks, for a given userid and password, if the borrower exists.
if ( BorrowerExists($userid, $password) ) {
# Do stuff
}
=cut
sub BorrowerExists {
my ( $userid, $password ) = @_;
$password = md5_base64($password);
my $dbh = C4::Context->dbh;
my $sth = $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? ");
$sth->execute( $userid, $password );
return $sth->fetchrow;
}
=head2 CanBookBeReserved
Checks if a book (at bibliographic level) can be reserved by a borrower.
if ( CanBookBeReserved($borrower, $biblionumber) ) {
# Do stuff
}
=cut
sub CanBookBeReserved {
my ( $borrower, $biblionumber ) = @_;
my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
my $MAXOUTSTANDING = C4::Context->preference("maxoutstanding");
my $out = 1;
if ( $borrower->{'amountoutstanding'} > $MAXOUTSTANDING ) {
$out = undef;
}
if ( $borrower->{gonenoaddress} eq 1 ) {
$out = undef;
}
if ( $borrower->{lost} eq 1 ) {
$out = undef;
}
if ( $borrower->{debarred} eq 1 ) {
$out = undef;
}
my @reserves = GetReservesFromBorrowernumber( $borrower->{'borrowernumber'} );
if ( scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES ) {
$out = undef;
}
foreach my $res (@reserves) {
if ( $res->{'biblionumber'} == $biblionumber ) {
$out = undef;
}
}
my $issues = GetPendingIssues( $borrower->{'borrowernumber'} );
foreach my $issue (@$issues) {
if ( $issue->{'biblionumber'} == $biblionumber ) {
$out = undef;
}
}
return $out;
}
=head2 Availability
Returns, for an itemnumber, an array containing availability information.
my ($biblionumber, $status, $msg, $location) = Availability($id);
=cut
sub Availability {
my ($itemnumber) = @_;
my $item = GetItem( $itemnumber, undef, undef );
if ( not $item->{'itemnumber'} ) {
return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
}
my $biblionumber = $item->{'biblioitemnumber'};
my $location = GetBranchName( $item->{'holdingbranch'} );
if ( $item->{'notforloan'} ) {
return ( $biblionumber, 'not available', 'Not for loan', $location );
} elsif ( $item->{'onloan'} ) {
return ( $biblionumber, 'not available', 'Checked out', $location );
} elsif ( $item->{'itemlost'} ) {
return ( $biblionumber, 'not available', 'Item lost', $location );
} elsif ( $item->{'wthdrawn'} ) {
return ( $biblionumber, 'not available', 'Item withdrawn', $location );
} elsif ( $item->{'damaged'} ) {
return ( $biblionumber, 'not available', 'Item damaged', $location );
} else {
return ( $biblionumber, 'available', undef, $location );
}
die Data::Dumper::Dumper($item);
}
1;

View File

@ -373,6 +373,8 @@ $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
$tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
$tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
# ILS-DI variables
$tabsysprefs{'ILS-DI'} = "ILS-DI";
sub StringSearch {
my ( $searchstring, $type ) = @_;
my $dbh = C4::Context->dbh;

View File

@ -0,0 +1,738 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><!-- TMPL_VAR NAME="LibraryNameTitle" DEFAULT="Koha Online" --> Catalog &rsaquo; ISBD
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
</head>
<body>
<div id="doc3" class="yui-t<!-- TMPL_IF NAME="OpacNav" -->1<!-- TMPL_ELSE -->7<!-- /TMPL_IF -->">
<div id="bd">
<!-- TMPL_INCLUDE name="masthead.inc" -->
<div id="yui-main">
<div class="yui-b"><div class="yui-g">
<h1>ILS-DI</h1>
<!-- TMPL_IF NAME="GetAvailability" -->
<h2>GetAvailability</h2>
<p>Given a set of bibliographic or item identifiers, returns a
list with availability of the items associated with the identifiers.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>id</strong> (Required)</dt>
<dd>list of either bibliographic or item identifiers</dd>
<dt><strong>id_type</strong> (Required)</dt>
<dd>defines the type of record identifier being used in the request, possible values:
<ul>
<li>bib</li>
<li>item</li>
</ul>
</dd>
<dt><strong>return_type</strong> (Optional)</dt>
<dd>requests a particular level of detail in reporting availability, possible values:
<ul>
<li>bib</li>
<li>item</li>
</ul>
</dd>
<dt><strong>return_fmt</strong> (Optional)</dt>
<dd>requests a particular format or set of formats in reporting availability</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetAvailability&id=1+2+99999&id_type=item">
ilsdi.pl?service=GetAvailability&id=1+2+99999&id_type=item
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;dlf:collection
xmlns:dlf="http://diglib.org/ilsdi/1.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://diglib.org/ilsdi/1.1
http://diglib.org/architectures/ilsdi/schemas/1.1/dlfexpanded.xsd"&gt;
&lt;dlf:record&gt;
&lt;dlf:bibliographic id="1" /&gt;
&lt;dlf:items&gt;
&lt;dlf:item id="1"&gt;
&lt;dlf:simpleavailability&gt;
&lt;dlf:identifier&gt;1&lt;/dlf:identifier&gt;
&lt;dlf:availabilitystatus&gt;available&lt;/dlf:availabilitystatus&gt;
&lt;dlf:location&gt;Bibliothèque Jean Prunier&lt;/dlf:location&gt;
&lt;/dlf:simpleavailability&gt;
&lt;/dlf:item&gt;
&lt;/dlf:items&gt;
&lt;/dlf:record&gt;
&lt;dlf:record&gt;
&lt;dlf:bibliographic id="2" /&gt;
&lt;dlf:items&gt;
&lt;dlf:item id="2"&gt;
&lt;dlf:simpleavailability&gt;
&lt;dlf:identifier&gt;2&lt;/dlf:identifier&gt;
&lt;dlf:availabilitystatus&gt;available&lt;/dlf:availabilitystatus&gt;
&lt;dlf:location&gt;Bibliothèque Jean Prunier&lt;/dlf:location&gt;
&lt;/dlf:simpleavailability&gt;
&lt;/dlf:item&gt;
&lt;/dlf:items&gt;
&lt;/dlf:record&gt;
&lt;dlf:record&gt;
&lt;dlf:bibliographic id="99999" /&gt;
&lt;dlf:items&gt;
&lt;dlf:item id="99999"&gt;
&lt;dlf:simpleavailability&gt;
&lt;dlf:identifier&gt;99999&lt;/dlf:identifier&gt;
&lt;dlf:availabilitystatus&gt;unknown&lt;/dlf:availabilitystatus&gt;
&lt;dlf:availabilitymsg&gt;Error: could not retrieve availability for this ID&lt;/dlf:availabilitymsg&gt;
&lt;/dlf:simpleavailability&gt;
&lt;/dlf:item&gt;
&lt;/dlf:items&gt;
&lt;/dlf:record&gt;
&lt;/dlf:collection&gt;</pre>
<!-- TMPL_ELSIF NAME="GetRecords" -->
<h2>GetRecords</h2>
<p>Given a list of record identifiers, returns a list of record
objects that contain bibliographic information, as well as
associated holdings and item information. The caller may request
a specific metadata schema for the record objects to be returned.
This function behaves similarly to HarvestBibliographicRecords and
HarvestExpandedRecords in Data Aggregation, but allows quick, real
time lookup by bibliographic identifier.</p>
<p>You can use OAI-PMH ListRecords instead of this service.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>id</strong> (Required)</dt>
<dd>list of system record identifiers</dd>
<dt><strong>id_type</strong> (Optional)</dt>
<dd>Defines the metadata schema in which the records are
returned, possible values:
<ul>
<li>MARCXML</li>
</ul>
</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetRecords&id=1+2+99999">
ilsdi.pl?service=GetRecords&id=1+2+99999
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;GetRecords&gt;
&lt;record&gt;
&lt;biblioitemnumber&gt;1&lt;/biblioitemnumber&gt;
&lt;isbn&gt;9782862749198&lt;/isbn&gt;
&lt;marcxml&gt;
&lt;record
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd"
xmlns="http://www.loc.gov/MARC21/slim"&gt;
&lt;leader&gt;00397nac a22001451u 4500&lt;/leader&gt;
&lt;datafield tag="010" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;9782862749198&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="090" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;1&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="101" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;fre&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="100" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;20080725 frey50 &lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="200" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;Jardins d'enfance&lt;/subfield&gt;
&lt;subfield code="b"&gt;LITT&lt;/subfield&gt;
&lt;subfield code="f"&gt;Abécassis, Eliette&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="210" ind1=" " ind2=" "&gt;
&lt;subfield code="c"&gt;cherche midi éditeur&lt;/subfield&gt;
&lt;subfield code="d"&gt;11/2001&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="215" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;180&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="225" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;nouvelles&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="995" ind1=" " ind2=" "&gt;
&lt;subfield code="9"&gt;1&lt;/subfield&gt;
&lt;subfield code="c"&gt;BIB&lt;/subfield&gt;
&lt;subfield code="2"&gt;0&lt;/subfield&gt;
&lt;subfield code="k"&gt;R ABE&lt;/subfield&gt;
&lt;subfield code="o"&gt;0&lt;/subfield&gt;
&lt;subfield code="e"&gt;Secteur Adulte&lt;/subfield&gt;
&lt;subfield code="b"&gt;BIB&lt;/subfield&gt;
&lt;subfield code="j"&gt;7786000200&lt;/subfield&gt;
&lt;subfield code="q"&gt;a&lt;/subfield&gt;
&lt;subfield code="r"&gt;2&lt;/subfield&gt;
&lt;subfield code="s"&gt;Achats&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;controlfield tag="001"&gt;1&lt;/controlfield&gt;
&lt;/record&gt;
&lt;/marcxml&gt;
&lt;publicationyear&gt;2001&lt;/publicationyear&gt;
&lt;collectiontitle&gt;nouvelles&lt;/collectiontitle&gt;
&lt;pages&gt;180&lt;/pages&gt;
&lt;issues&gt;
&lt;/issues&gt;
&lt;itemtype&gt;LITT&lt;/itemtype&gt;
&lt;biblionumber&gt;1&lt;/biblionumber&gt;
&lt;timestamp&gt;2008-09-03 18:43:19&lt;/timestamp&gt;
&lt;cn_sort&gt;_&lt;/cn_sort&gt;
&lt;publishercode&gt;cherche midi éditeur&lt;/publishercode&gt;
&lt;reserves&gt;
&lt;/reserves&gt;
&lt;items&gt;
&lt;item&gt;
&lt;biblioitemnumber&gt;1&lt;/biblioitemnumber&gt;
&lt;wthdrawn&gt;0&lt;/wthdrawn&gt;
&lt;holdingbranchname&gt;Bibliothèque Jean Prunier&lt;/holdingbranchname&gt;
&lt;notforloan&gt;0&lt;/notforloan&gt;
&lt;replacementpricedate&gt;2008-08-20&lt;/replacementpricedate&gt;
&lt;itemnumber&gt;1&lt;/itemnumber&gt;
&lt;location&gt;Secteur Adulte&lt;/location&gt;
&lt;itemcallnumber&gt;R ABE&lt;/itemcallnumber&gt;
&lt;date_due&gt;&lt;/date_due&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;datelastseen&gt;2008-08-20&lt;/datelastseen&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;homebranchname&gt;Bibliothèque Jean Prunier&lt;/homebranchname&gt;
&lt;biblionumber&gt;1&lt;/biblionumber&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;
&lt;timestamp&gt;2008-08-20 17:15:51&lt;/timestamp&gt;
&lt;damaged&gt;0&lt;/damaged&gt;
&lt;cn_sort&gt;R_ABE&lt;/cn_sort&gt;
&lt;dateaccessioned&gt;2008-08-20&lt;/dateaccessioned&gt;
&lt;/item&gt;
&lt;/items&gt;
&lt;/record&gt;
&lt;record&gt;
&lt;biblioitemnumber&gt;2&lt;/biblioitemnumber&gt;
&lt;isbn&gt;9782265078031&lt;/isbn&gt;
&lt;marcxml&gt;
&lt;record
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd"
xmlns="http://www.loc.gov/MARC21/slim"&gt;
&lt;leader&gt;00407nac a22001451u 4500&lt;/leader&gt;
&lt;datafield tag="010" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;9782265078031&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="090" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;2&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="101" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;fre&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="100" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;20080725 frey50 &lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="200" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;(Les) tribulations d'une jeune divorcée&lt;/subfield&gt;
&lt;subfield code="b"&gt;LITT&lt;/subfield&gt;
&lt;subfield code="f"&gt;Abécassis, Eliette&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="210" ind1=" " ind2=" "&gt;
&lt;subfield code="c"&gt;bussière&lt;/subfield&gt;
&lt;subfield code="d"&gt;01/2005&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="215" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;306&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="225" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;fleuve noir&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="995" ind1=" " ind2=" "&gt;
&lt;subfield code="9"&gt;2&lt;/subfield&gt;
&lt;subfield code="c"&gt;BIB&lt;/subfield&gt;
&lt;subfield code="2"&gt;0&lt;/subfield&gt;
&lt;subfield code="k"&gt;R ABE&lt;/subfield&gt;
&lt;subfield code="o"&gt;0&lt;/subfield&gt;
&lt;subfield code="e"&gt;Secteur Adulte&lt;/subfield&gt;
&lt;subfield code="b"&gt;BIB&lt;/subfield&gt;
&lt;subfield code="j"&gt;7786004672&lt;/subfield&gt;
&lt;subfield code="q"&gt;a&lt;/subfield&gt;
&lt;subfield code="s"&gt;Achats&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;controlfield tag="001"&gt;2&lt;/controlfield&gt;
&lt;/record&gt;
&lt;/marcxml&gt;
&lt;publicationyear&gt;2005&lt;/publicationyear&gt;
&lt;collectiontitle&gt;fleuve noir&lt;/collectiontitle&gt;
&lt;pages&gt;306&lt;/pages&gt;
&lt;issues&gt;
&lt;/issues&gt;
&lt;itemtype&gt;LITT&lt;/itemtype&gt;
&lt;biblionumber&gt;2&lt;/biblionumber&gt;
&lt;timestamp&gt;2008-09-03 18:43:19&lt;/timestamp&gt;
&lt;cn_sort&gt;_&lt;/cn_sort&gt;
&lt;publishercode&gt;bussière&lt;/publishercode&gt;
&lt;reserves&gt;
&lt;/reserves&gt;
&lt;items&gt;
&lt;item&gt;
&lt;biblioitemnumber&gt;2&lt;/biblioitemnumber&gt;
&lt;wthdrawn&gt;0&lt;/wthdrawn&gt;
&lt;holdingbranchname&gt;Bibliothèque Jean Prunier&lt;/holdingbranchname&gt;
&lt;notforloan&gt;0&lt;/notforloan&gt;
&lt;replacementpricedate&gt;2008-08-20&lt;/replacementpricedate&gt;
&lt;itemnumber&gt;2&lt;/itemnumber&gt;
&lt;location&gt;Secteur Adulte&lt;/location&gt;
&lt;itemcallnumber&gt;R ABE&lt;/itemcallnumber&gt;
&lt;date_due&gt;&lt;/date_due&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;datelastseen&gt;2008-08-20&lt;/datelastseen&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;homebranchname&gt;Bibliothèque Jean Prunier&lt;/homebranchname&gt;
&lt;biblionumber&gt;2&lt;/biblionumber&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;
&lt;timestamp&gt;2008-08-20 17:15:51&lt;/timestamp&gt;
&lt;damaged&gt;0&lt;/damaged&gt;
&lt;cn_sort&gt;R_ABE&lt;/cn_sort&gt;
&lt;dateaccessioned&gt;2008-08-20&lt;/dateaccessioned&gt;
&lt;/item&gt;
&lt;/items&gt;
&lt;/record&gt;
&lt;record&gt;RecordNotFound&lt;/record&gt;
&lt;/GetRecords&gt;</pre>
<!-- TMPL_ELSIF NAME="GetAuthorityRecords" -->
<h2>GetAuthorityRecords</h2>
<p>Given a list of authority record identifiers, returns a list
of record objects that contain the authority records. The function
user may request a specific metadata schema for the record objects.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>id</strong> (Required)</dt>
<dd>list of authority record identifiers</dd>
<dt><strong>schema</strong> (Optional)</dt>
<dd>specifies the metadata schema of records to be returned, possible values:
<ul>
<li>MARCXML</li>
</ul>
</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetAuthorityRecords&id=1+2+99999">
ilsdi.pl?service=GetAuthorityRecords&id=1+2+99999
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;GetAuthorityRecords&gt;
&lt;record
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd"
xmlns="http://www.loc.gov/MARC21/slim"&gt;
&lt;leader&gt;00126nx j2200073 4500 &lt;/leader&gt;
&lt;controlfield tag="001"&gt;1&lt;/controlfield&gt;
&lt;datafield tag="250" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;TECHNIQUE&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="100" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;20071210afrey50 ba0&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="152" ind1=" " ind2=" "&gt;
&lt;subfield code="b"&gt;NC&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;/record&gt;
&lt;record
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd"
xmlns="http://www.loc.gov/MARC21/slim"&gt;
&lt;leader&gt;00130nx j2200073 4500 &lt;/leader&gt;
&lt;controlfield tag="001"&gt;2&lt;/controlfield&gt;
&lt;datafield tag="250" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;CHEMIN DE FER&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="100" ind1=" " ind2=" "&gt;
&lt;subfield code="a"&gt;20071210afrey50 ba0&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;datafield tag="152" ind1=" " ind2=" "&gt;
&lt;subfield code="b"&gt;NC&lt;/subfield&gt;
&lt;/datafield&gt;
&lt;/record&gt;
&lt;record&gt;RecordNotFound&lt;/record&gt;
&lt;/GetAuthorityRecords&gt;</pre>
<!-- TMPL_ELSIF NAME="LookupPatron" -->
<h2>LookupPatron</h2>
<p>Looks up a patron in the ILS by an identifier, and returns
the ILS identifier for that patron, aka the patron identifier.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>id</strong> (Required)</dt>
<dd>an identifier used to look up the patron in Koha</dd>
<dt><strong>id_type</strong> (Optional)</dt>
<dd>the type of the identifier, possible values:
<ul>
<li>cardnumber</li>
<li>firstname</li>
<li>userid</li>
<li>borrowernumber</li>
</ul>
</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=LookupPatron&id=815&id_type=cardnumber">
ilsdi.pl?service=LookupPatron&id=815&id_type=cardnumber
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;LookupPatron&gt;
&lt;id&gt;419&lt;/id&gt;
&lt;/LookupPatron&gt;</pre>
<!-- TMPL_ELSIF NAME="AuthenticatePatron" -->
<h2>AuthenticatePatron</h2>
<p>Authenticates a user's login credentials and returns the identifier for the patron.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>username</strong> (Required)</dt>
<dd>user's login identifier</dd>
<dt><strong>password</strong> (Required)</dt>
<dd>user's password</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=AuthenticatePatron&username=john9&password=soul">
ilsdi.pl?service=AuthenticatePatron&username=john9&password=soul
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;AuthenticatePatron&gt;
&lt;id&gt;419&lt;/id&gt;
&lt;/AuthenticatePatron&gt;</pre>
<!-- TMPL_ELSIF NAME="GetPatronInfo" -->
<h2>GetPatronInfo</h2>
<p>Returns specified information about the patron, based on
options in the request. This function can optionally return
patron's contact information, fine information, hold request
information, loan information, and messages.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
<dt><strong>show_contact</strong> (Optional, default 1)</dt>
<dd>whether or not to return patron's contact information in the response</dd>
<dt><strong>show_fines</strong> (Optional, default 0)</dt>
<dd>whether or not to return fine information in the response</dd>
<dt><strong>show_holds</strong> (Optional, default 0)</dt>
<dd>whether or not to return hold request information in the response</dd>
<dt><strong>show_loans</strong> (Optional, default 0)</dt>
<dd>whether or not to return loan information request information in the response</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetPatronInfo&patron_id=1&show_contact=0&show_loans=1">
ilsdi.pl?service=GetPatronInfo&patron_id=1&show_contact=0&show_loans=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;GetPatronInfo&gt;
&lt;category_type&gt;A&lt;/category_type&gt;
&lt;categorycode&gt;ADUEXT&lt;/categorycode&gt;
&lt;borrowernumber&gt;419&lt;/borrowernumber&gt;
&lt;lost&gt;0&lt;/lost&gt;
&lt;branchcode&gt;BIB&lt;/branchcode&gt;
&lt;amountoutstanding&gt;6&lt;/amountoutstanding&gt;
&lt;description&gt;Adulte extérieur&lt;/description&gt;
&lt;title&gt;M&lt;/title&gt;
&lt;enrolmentperiod&gt;12&lt;/enrolmentperiod&gt;
&lt;charges&gt;6.00&lt;/charges&gt;
&lt;dateenrolled&gt;2009-03-04&lt;/dateenrolled&gt;
&lt;borrowernotes&gt;&lt;/borrowernotes&gt;
&lt;dateexpiry&gt;2010-03-04&lt;/dateexpiry&gt;
&lt;firstname&gt;Jean-André&lt;/firstname&gt;
&lt;gonenoaddress&gt;0&lt;/gonenoaddress&gt;
&lt;dateofbirth&gt;1984-06-08&lt;/dateofbirth&gt;
&lt;debarred&gt;0&lt;/debarred&gt;
&lt;branchname&gt;Bibliothèque Jean Prunier&lt;/branchname&gt;
&lt;surname&gt;SANTONI&lt;/surname&gt;
&lt;cardnumber&gt;815&lt;/cardnumber&gt;
&lt;initials&gt;JAS&lt;/initials&gt;
&lt;sort1&gt;CSP5&lt;/sort1&gt;
&lt;sex&gt;M&lt;/sex&gt;
&lt;loans&gt;
&lt;loan&gt;
&lt;lastreneweddate&gt;2009-04-03&lt;/lastreneweddate&gt;
&lt;isbn&gt;2253003689&lt;/isbn&gt;
&lt;borrowernumber&gt;419&lt;/borrowernumber&gt;
&lt;branchcode&gt;BIB&lt;/branchcode&gt;
&lt;itemnumber&gt;4454&lt;/itemnumber&gt;
&lt;date_due&gt;2009-05-06&lt;/date_due&gt;
&lt;barcode&gt;4765476&lt;/barcode&gt;
&lt;datelastseen&gt;2008-08-23&lt;/datelastseen&gt;
&lt;issuedate&gt;2008-08-23&lt;/issuedate&gt;
&lt;title&gt;L'Île au trésor&lt;/title&gt;
&lt;itemtype&gt;LITT&lt;/itemtype&gt;
&lt;author&gt;Robert Louis Stevenson&lt;/author&gt;
&lt;timestamp&gt;2009-04-03 14:46:10&lt;/timestamp&gt;
&lt;publishercode&gt;Librairie générale française&lt;/publishercode&gt;
&lt;datecreated&gt;2008-08-23&lt;/datecreated&gt;
&lt;totalrenewals&gt;11&lt;/totalrenewals&gt;
&lt;dateaccessioned&gt;2008-08-23&lt;/dateaccessioned&gt;
&lt;onloan&gt;2008-09-17&lt;/onloan&gt;
&lt;biblioitemnumber&gt;4483&lt;/biblioitemnumber&gt;
&lt;wthdrawn&gt;0&lt;/wthdrawn&gt;
&lt;notforloan&gt;0&lt;/notforloan&gt;
&lt;replacementpricedate&gt;2008-08-23&lt;/replacementpricedate&gt;
&lt;itemcallnumber&gt;RO STE&lt;/itemcallnumber&gt;
&lt;location&gt;Salle de lecture&lt;/location&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;publicationyear&gt;1985&lt;/publicationyear&gt;
&lt;issues&gt;1&lt;/issues&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;
&lt;biblionumber&gt;4483&lt;/biblionumber&gt;
&lt;renewals&gt;3&lt;/renewals&gt;
&lt;damaged&gt;0&lt;/damaged&gt;
&lt;cn_sort&gt;RO_STE&lt;/cn_sort&gt;
&lt;frameworkcode&gt;&lt;/frameworkcode&gt;
&lt;datelastborrowed&gt;2008-08-23&lt;/datelastborrowed&gt;
&lt;/loan&gt;
&lt;loan&gt;
&lt;lastreneweddate&gt;2009-03-17&lt;/lastreneweddate&gt;
&lt;isbn&gt;9782700017823&lt;/isbn&gt;
&lt;borrowernumber&gt;419&lt;/borrowernumber&gt;
&lt;branchcode&gt;BIB&lt;/branchcode&gt;
&lt;itemnumber&gt;4456&lt;/itemnumber&gt;
&lt;date_due&gt;2009-04-18&lt;/date_due&gt;
&lt;barcode&gt;2700017UUU&lt;/barcode&gt;
&lt;datelastseen&gt;2008-08-23&lt;/datelastseen&gt;
&lt;issuedate&gt;2008-08-23&lt;/issuedate&gt;
&lt;title&gt;La guitare en 10 leçons&lt;/title&gt;
&lt;itemtype&gt;LITT&lt;/itemtype&gt;
&lt;author&gt;Jon Buck&lt;/author&gt;
&lt;timestamp&gt;2009-03-17 16:48:14&lt;/timestamp&gt;
&lt;publishercode&gt;Gründ&lt;/publishercode&gt;
&lt;datecreated&gt;2008-08-23&lt;/datecreated&gt;
&lt;totalrenewals&gt;6&lt;/totalrenewals&gt;
&lt;dateaccessioned&gt;2008-08-23&lt;/dateaccessioned&gt;
&lt;notes&gt;La couv. porte en plus : "un guide simple et facile pour apprendre la guitare" | Glossaire. Index&lt;/notes&gt;
&lt;onloan&gt;2008-09-25&lt;/onloan&gt;
&lt;biblioitemnumber&gt;4486&lt;/biblioitemnumber&gt;
&lt;wthdrawn&gt;0&lt;/wthdrawn&gt;
&lt;notforloan&gt;0&lt;/notforloan&gt;
&lt;replacementpricedate&gt;2008-08-23&lt;/replacementpricedate&gt;
&lt;itemcallnumber&gt;787.87 BUC&lt;/itemcallnumber&gt;
&lt;location&gt;Salle de lecture&lt;/location&gt;
&lt;itemlost&gt;0&lt;/itemlost&gt;
&lt;publicationyear&gt;2007&lt;/publicationyear&gt;
&lt;issues&gt;1&lt;/issues&gt;
&lt;homebranch&gt;BIB&lt;/homebranch&gt;
&lt;holdingbranch&gt;BIB&lt;/holdingbranch&gt;
&lt;biblionumber&gt;4486&lt;/biblionumber&gt;
&lt;renewals&gt;3&lt;/renewals&gt;
&lt;damaged&gt;0&lt;/damaged&gt;
&lt;cn_sort&gt;78787_BUC&lt;/cn_sort&gt;
&lt;volume&gt;une méthode simple et facile pour apprendre la guitare&lt;/volume&gt;
&lt;frameworkcode&gt;&lt;/frameworkcode&gt;
&lt;datelastborrowed&gt;2008-08-23&lt;/datelastborrowed&gt;
&lt;/loan&gt;
&lt;/loans&gt;
&lt;/GetPatronInfo&gt;</pre>
<!-- TMPL_ELSIF NAME="GetPatronStatus" -->
<h2>GetPatronStatus</h2>
<p>Returns a patron's status information from Koha.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetPatronStatus&patron_id=1">
ilsdi.pl?service=GetPatronStatus&patron_id=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;GetPatronStatus&gt;
&lt;expiry&gt;2010-03-04&lt;/expiry&gt;
&lt;status&gt;0&lt;/status&gt;
&lt;type&gt;ADUEXT&lt;/type&gt;
&lt;/GetPatronStatus&gt;</pre>
<!-- TMPL_ELSIF NAME="GetServices" -->
<h2>GetServices</h2>
<p>Returns information about the services available on a particular item for a particular patron.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
<dt><strong>item_id</strong> (Required)</dt>
<dd>system item identifier</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=GetServices&patron_id=1&item_id=1">
ilsdi.pl?service=GetServices&patron_id=1&item_id=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;GetServices&gt;
&lt;AvailableFor&gt;title level hold&lt;/AvailableFor&gt;
&lt;AvailableFor&gt;item level hold&lt;/AvailableFor&gt;
&lt;/GetServices&gt;</pre>
<!-- TMPL_ELSIF NAME="RenewLoan" -->
<h2>RenewLoan</h2>
<p>Extends the due date for a patron's existing loan.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
<dt><strong>item_id</strong> (Required)</dt>
<dd>system item identifier</dd>
<dt><strong>desired_due_date</strong> (Required)</dt>
<dd>the date the patron would like the item returned by</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=RenewLoan&patron_id=1&item_id=1">
ilsdi.pl?service=RenewLoan&patron_id=1&item_id=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;RenewLoan&gt;
&lt;success&gt;0&lt;/success&gt;
&lt;renewals&gt;5&lt;/renewals&gt;
&lt;date_due&gt;2009-05-11&lt;/date_due&gt;
&lt;/RenewLoan&gt;</pre>
<!-- TMPL_ELSIF NAME="HoldTitle" -->
<h2>HoldTitle</h2>
<p>Creates, for a patron, a title-level hold request on a given bibliographic record in Koha.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the ILS identifier for the patron for whom the request is placed</dd>
<dt><strong>bib_id</strong> (Required)</dt>
<dd>the ILS identifier for the bibliographic record on which the request is placed</dd>
<dt><strong>request_location</strong> (Required)</dt>
<dd>IP address where the end user request is being placed</dd>
<dt><strong>pickup_location</strong> (Optional)</dt>
<dd>an identifier indicating the location to which to deliver the item for pickup</dd>
<dt><strong>needed_before_date</strong> (Optional)</dt>
<dd>date after which hold request is no longer needed</dd>
<dt><strong>pickup_expiry_date</strong> (Optional)</dt>
<dd>date after which item returned to shelf if item is not picked up</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=HoldTitle&patron_id=1&bib_id=1&request_location=127.0.0.1">
ilsdi.pl?service=HoldTitle&patron_id=1&bib_id=1&request_location=127.0.0.1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;HoldTitle&gt;
&lt;title&gt;(les) galères de l'Orfèvre&lt;/title&gt;
&lt;date_available&gt;2009-05-11&lt;/date_available&gt;
&lt;pickup_location&gt;Bibliothèque Jean-Prunier&lt;/pickup_location&gt;
&lt;/HoldTitle&gt;</pre>
<!-- TMPL_ELSIF NAME="HoldItem" -->
<h2>HoldItem</h2>
<p>Creates, for a patron, an item-level hold request on a specific item of a bibliographic record Koha.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the ILS identifier for the patron for whom the request is placed</dd>
<dt><strong>bib_id</strong> (Required)</dt>
<dd>the ILS identifier for the bibliographic record on which the request is placed</dd>
<dt><strong>item_id</strong> (Required)</dt>
<dd>the ILS identifier for the specific item on which the request is placed</dd>
<dt><strong>pickup_location</strong> (Optional)</dt>
<dd>an identifier indicating the location to which to deliver the item for pickup</dd>
<dt><strong>needed_before_date</strong> (Optional)</dt>
<dd>date after which hold request is no longer needed</dd>
<dt><strong>pickup_expiry_date</strong> (Optional)</dt>
<dd>date after which item returned to shelf if item is not picked up</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=HoldItem&patron_id=1&bib_id=1&item_id=1">
ilsdi.pl?service=HoldItem&patron_id=1&bib_id=1&item_id=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;HoldTitle&gt;
&lt;title&gt;(les) galères de l'Orfèvre&lt;/title&gt;
&lt;date_available&gt;2009-05-11&lt;/date_available&gt;
&lt;pickup_location&gt;Bibliothèque Jean-Prunier&lt;/pickup_location&gt;
&lt;/HoldTitle&gt;</pre>
<!-- TMPL_ELSIF NAME="CancelHold" -->
<h2>CancelHold</h2>
<p>Cancels an active hold request for the patron.</p>
<h4>Parameters</h4>
<dl>
<dt><strong>patron_id</strong> (Required)</dt>
<dd>the unique patron identifier in the ILS; the same identifier returned by LookupPatron or AuthenticatePatron</dd>
<dt><strong>item_id</strong> (Required)</dt>
<dd>system item identifier</dd>
</dl>
<h4>Example Call</h4>
<a href="ilsdi.pl?service=CancelHold&patron_id=1&item_id=1">
ilsdi.pl?service=CancelHold&patron_id=1&item_id=1
</a>
<h4>Example Response</h4>
<pre>&lt;?xml version="1.0" encoding="ISO-8859-1" ?&gt;
&lt;CancelHold&gt;
&lt;message&gt;Canceled&lt;/message&gt;
&lt;/CancelHold&gt;</pre>
<!-- TMPL_ELSE -->
<h2>Level 1: Basic Discovery Interfaces</h2>
<ul>
<li>HarvestBibliographicRecords <em>(Use OAI-PMH instead)</em></li>
<li>HarvestExpandedRecords <em>(Use OAI-PMH instead)</em></li>
<li><a href="ilsdi.pl?service=Describe&verb=GetAvailability">GetAvailability</a></li>
<li>GoToBibliographicRequestPage <em>(Use OPAC instead)</em></li>
</ul>
<h2>Level 2: Elementary OPAC supplement</h2>
<ul>
<li>HarvestAuthorityRecords <em>(Use OAI-PMH instead)</em></li>
<li>HarvestHoldingsRecords <em>(Use OAI-PMH instead)</em></li>
<li><a href="ilsdi.pl?service=Describe&verb=GetRecords">GetRecords</a></li>
<li>Search</li>
<li>Scan</li>
<li><a href="ilsdi.pl?service=Describe&verb=GetAuthorityRecords">GetAuthorityRecords</a></li>
<li>OutputRewritablePage</li>
<li>OutputIntermediateFormat</li>
</ul>
<h2>Level 3: Elementary OPAC alternative</h2>
<ul>
<li><a href="ilsdi.pl?service=Describe&verb=LookupPatron">LookupPatron</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=AuthenticatePatron">AuthenticatePatron</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=GetPatronInfo">GetPatronInfo</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=GetPatronStatus">GetPatronStatus</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=GetServices">GetServices</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=RenewLoan">RenewLoan</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=HoldTitle">HoldTitle</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=HoldItem">HoldItem</a></li>
<li><a href="ilsdi.pl?service=Describe&verb=CancelHold">CancelHold</a></li>
<li>RecallItem <em>(Not supported by Koha)</em></li>
<li>CancelRecall <em>(Not supported by Koha)</em></li>
</ul>
<h2>Level 4: Robust/domain specific discovery platforms</h2>
<ul>
<li>SearchCourseReserves</li>
<li>Explain</li>
</ul>
<!-- /TMPL_IF -->
</div></div>
</div>
<!-- TMPL_IF NAME="OpacNav" -->
<div class="yui-b"><div class="container">
<!--TMPL_INCLUDE NAME="navigation.inc" -->
</div></div>
<!-- /TMPL_IF -->
</div>
</div>
<!-- TMPL_INCLUDE NAME="opac-bottom.inc" -->

228
opac/ilsdi.pl Executable file
View File

@ -0,0 +1,228 @@
#!/usr/bin/perl
# Copyright 2009 SARL Biblibre
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use warnings;
use C4::ILSDI::Services;
use C4::Auth;
use C4::Output;
use C4::Context;
use XML::Simple;
use CGI;
=head1 DLF ILS-DI for Koha
This script is a basic implementation of ILS-DI protocol for Koha.
It acts like a dispatcher, that get the CGI request, check required and
optionals arguments, call a function from C4::ILS-DI::Services, and finaly
outputs the returned hashref as XML.
=cut
# Instanciate the CGI request
my $cgi = new CGI;
# List of available services, sorted by level
my @services = (
'Describe', # Not part of ILS-DI, online API doc
# Level 1: Basic Discovery Interfaces
# 'HarvestBibliographicRecords', # OAI-PMH
# 'HarvestExpandedRecords', # OAI-PMH
'GetAvailability', # FIXME Add bibbliographic level
# 'GoToBibliographicRequestPage' # I don't understant this one
# Level 2: Elementary OPAC supplement
# 'HarvestAuthorityRecords', # OAI-PMH
# 'HarvestHoldingsRecords', # OAI-PMH
'GetRecords', # Note that we can use OAI-PMH for this too
# 'Search', # TODO
# 'Scan', # TODO
'GetAuthorityRecords',
# 'OutputRewritablePage', # I don't understant this one
# 'OutputIntermediateFormat', # I don't understant this one
# Level 3: Elementary OPAC alternative
'LookupPatron',
'AuthenticatePatron',
'GetPatronInfo',
'GetPatronStatus',
'GetServices', # FIXME Loans
'RenewLoan',
'HoldTitle', # FIXME Add dates support
'HoldItem', # FIXME Add dates support
'CancelHold',
# 'RecallItem', # Not supported by Koha
# 'CancelRecall', # Not supported by Koha
# Level 4: Robust/domain specific discovery platforms
# 'SearchCourseReserves', # TODO
# 'Explain' # TODO
);
# List of required arguments
my %required = (
'Describe' => ['verb'],
'GetAvailability' => [ 'id', 'id_type' ],
'GetRecords' => ['id'],
'GetAuthorityRecords' => ['id'],
'LookupPatron' => ['id'],
'AuthenticatePatron' => [ 'username', 'password' ],
'GetPatronInfo' => ['patron_id'],
'GetPatronStatus' => ['patron_id'],
'GetServices' => [ 'patron_id', 'item_id' ],
'RenewLoan' => [ 'patron_id', 'item_id' ],
'HoldTitle' => [ 'patron_id', 'bib_id', 'request_location' ],
'HoldItem' => [ 'patron_id', 'bib_id', 'item_id' ],
'CancelHold' => [ 'patron_id', 'item_id' ],
);
# List of optional arguments
my %optional = (
'Describe' => [],
'GetAvailability' => [ 'return_type', 'return_fmt' ],
'GetRecords' => ['schema'],
'GetAuthorityRecords' => ['schema'],
'LookupPatron' => ['id_type'],
'AuthenticatePatron' => [],
'GetPatronInfo' => [ 'show_contact', 'show_fines', 'show_holds', 'show_loans' ],
'GetPatronStatus' => [],
'GetServices' => [],
'RenewLoan' => ['desired_due_date'],
'HoldTitle' => [ 'pickup_location', 'needed_before_date', 'pickup_expiry_date' ],
'HoldItem' => [ 'pickup_location', 'needed_before_date', 'pickup_expiry_date' ],
'CancelHold' => [],
);
# If ILS-DI module is disabled in System->Preferences, redirect to 404
if ( not C4::Context->preference('ILS-DI') ) {
print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
}
# If no service is requested, display the online documentation
if ( not $cgi->param('service') ) {
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => "ilsdi.tmpl",
query => $cgi,
type => "opac",
authnotrequired => 1,
debug => 1,
}
);
output_html_with_http_headers $cgi, $cookie, $template->output;
exit 0;
}
# If user requested a service description, then display it
if ( $cgi->param('service') eq "Describe" and grep { $cgi->param('verb') eq $_ } @services ) {
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{ template_name => "ilsdi.tmpl",
query => $cgi,
type => "opac",
authnotrequired => 1,
debug => 1,
}
);
$template->param( $cgi->param('verb') => 1 );
output_html_with_http_headers $cgi, $cookie, $template->output;
exit 0;
}
my $service = $cgi->param('service') || "ilsdi";
my $out;
# Check if the requested service is in the list
if ( $service and grep { $service eq $_ } @services ) {
my @parmsrequired = @{ $required{$service} };
my @parmsoptional = @{ $optional{$service} };
my @parmsall = ( @parmsrequired, @parmsoptional );
my @names = $cgi->param;
my %paramhash = ();
foreach my $name (@names) {
$paramhash{$name} = 1;
}
# check for missing parameters
foreach my $name (@parmsrequired) {
if ( ( !exists $paramhash{$name} ) ) {
$out->{'message'} = "missing $name parameter";
}
}
# check for illegal parameters
foreach my $name (@names) {
my $found = 0;
foreach my $name2 (@parmsall) {
if ( $name eq $name2 ) {
$found = 1;
}
}
if ( ( $found == 0 ) && ( $name ne 'service' ) ) {
$out->{'message'} = "$name is an illegal parameter";
}
}
# check for multiple parameters
foreach my $name (@names) {
my @values = $cgi->param($name);
if ( $#values != 0 ) {
$out->{'message'} = "multiple values are not allowed for the $name parameter";
}
}
if ( !$out->{'message'} ) {
# GetAvailability is a special case, as it cannot use XML::Simple
if ( $service eq "GetAvailability" ) {
print CGI::header('text/xml');
print C4::ILSDI::Services::GetAvailability($cgi);
exit 0;
} else {
# Variable functions
my $sub = do {
no strict 'refs';
my $symbol = 'C4::ILSDI::Services::' . $service;
\&{"$symbol"};
};
# Call the requested service, and get its return value
$out = &$sub($cgi);
}
}
} else {
$out->{'message'} = "NotSupported";
}
# Output XML by passing the hashref to XMLOut
print CGI::header('text/xml');
print XMLout(
$out,
noattr => 1,
noescape => 1,
nosort => 1,
xmldecl => '<?xml version="1.0" encoding="ISO-8859-1" ?>',
RootName => $service,
SuppressEmpty => 1
);