1 package C4::ILSDI::Utility;
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4::Reserves qw(GetReservesFromBorrowernumber);
29 use C4::Branch qw/GetBranchName/;
30 use Digest::MD5 qw(md5_base64);
32 use vars qw($VERSION @ISA @EXPORT);
36 # set the version for version checking
41 &BorrowerExists &CanBookBeReserved &Availability
47 C4::ILS-DI::Utility - ILS-DI Utilities
53 Checks, for a given userid and password, if the borrower exists.
55 if ( BorrowerExists($userid, $password) ) {
62 my ( $userid, $password ) = @_;
63 $password = md5_base64($password);
64 my $dbh = C4::Context->dbh;
65 my $sth = $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? ");
66 $sth->execute( $userid, $password );
67 return $sth->fetchrow;
70 =head2 CanBookBeReserved
72 Checks if a book (at bibliographic level) can be reserved by a borrower.
74 if ( CanBookBeReserved($borrower, $biblionumber) ) {
80 sub CanBookBeReserved {
81 my ( $borrower, $biblionumber ) = @_;
83 my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
84 my $MAXOUTSTANDING = C4::Context->preference("maxoutstanding");
88 if ( $borrower->{'amountoutstanding'} > $MAXOUTSTANDING ) {
91 if ( $borrower->{gonenoaddress} eq 1 ) {
94 if ( $borrower->{lost} eq 1 ) {
97 if ( $borrower->{debarred} ) {
100 my @reserves = GetReservesFromBorrowernumber( $borrower->{'borrowernumber'} );
101 if ( $MAXIMUM_NUMBER_OF_RESERVES && scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES ) {
104 foreach my $res (@reserves) {
105 if ( $res->{'biblionumber'} == $biblionumber ) {
109 my $issues = GetPendingIssues( $borrower->{'borrowernumber'} );
110 foreach my $issue (@$issues) {
111 if ( $issue->{'biblionumber'} == $biblionumber ) {
121 Returns, for an itemnumber, an array containing availability information.
123 my ($biblionumber, $status, $msg, $location) = Availability($id);
128 my ($itemnumber) = @_;
129 my $item = GetItem( $itemnumber, undef, undef );
131 if ( not $item->{'itemnumber'} ) {
132 return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
135 my $biblionumber = $item->{'biblioitemnumber'};
136 my $location = GetBranchName( $item->{'holdingbranch'} );
138 if ( $item->{'notforloan'} ) {
139 return ( $biblionumber, 'not available', 'Not for loan', $location );
140 } elsif ( $item->{'onloan'} ) {
141 return ( $biblionumber, 'not available', 'Checked out', $location );
142 } elsif ( $item->{'itemlost'} ) {
143 return ( $biblionumber, 'not available', 'Item lost', $location );
144 } elsif ( $item->{'wthdrawn'} ) {
145 return ( $biblionumber, 'not available', 'Item withdrawn', $location );
146 } elsif ( $item->{'damaged'} ) {
147 return ( $biblionumber, 'not available', 'Item damaged', $location );
149 return ( $biblionumber, 'available', undef, $location );
152 die Data::Dumper::Dumper($item);