use strict;
use warnings;
+use List::MoreUtils qw(any);
+
use C4::ILSDI::Services;
use C4::Auth;
use C4::Output;
exit 0;
}
+my $out;
+
# If ILS-DI module is disabled in System->Preferences, redirect to 404
unless ( C4::Context->preference('ILS-DI') ) {
- print $cgi->redirect("/cgi-bin/koha/errors/404.pl");
- exit 1;
+ $out->{'code'} = "NotAllowed";
+ $out->{'message'} = "ILS-DI is disabled.";
}
# If the remote address is not allowed, redirect to 403
if ( @AuthorizedIPs # If no filter set, allow access to everybody
and not any { $ENV{'REMOTE_ADDR'} eq $_ } @AuthorizedIPs # IP Check
) {
- print $cgi->redirect("/cgi-bin/koha/errors/403.pl");
- exit 1;
+ $out->{'code'} = "NotAllowed";
+ $out->{'message'} = "Unauthorized IP address: ".$ENV{'REMOTE_ADDR'}.".";
}
my $service = $cgi->param('service') || "ilsdi";
-my $out;
-
# Check if the requested service is in the list
if ( $service and any { $service eq $_ } @services ) {
# check for missing parameters
for ( @parmsrequired ) {
unless ( exists $paramhash{$_} ) {
- $out->{'message'} = "missing $_ parameter";
+ $out->{'code'} = "MissingParameter";
+ $out->{'message'} = "The required parameter ".$_." is missing.";
}
}
}
}
if ( $found == 0 && $name ne 'service' ) {
- $out->{'message'} = "$name is an illegal parameter";
+ $out->{'code'} = "IllegalParameter";
+ $out->{'message'} = "The parameter ".$name." is illegal.";
}
}
for ( @names ) {
my @values = $cgi->param($_);
if ( $#values != 0 ) {
- $out->{'message'} = "multiple values are not allowed for the $_ parameter";
+ $out->{'code'} = "MultipleValuesNotAllowed";
+ $out->{'message'} = "Multiple values not allowed for the parameter ".$_.".";
}
}
# GetAvailability is a special case, as it cannot use XML::Simple
if ( $service eq "GetAvailability" ) {
print CGI::header('text/xml');
- print C4::ILSDI::GetAvailability($cgi);
+ print C4::ILSDI::Services::GetAvailability($cgi);
exit 0;
} else {
}
# Output XML by passing the hashref to XMLOut
+binmode STDOUT, ':encoding(UTF-8)';
print CGI::header('-type'=>'text/xml', '-charset'=>'utf-8');
print XMLout(
$out,
noattr => 1,
- noescape => 1,
nosort => 1,
xmldecl => '<?xml version="1.0" encoding="UTF-8" ?>',
RootName => $service,