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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
29 use C4::Branch qw/GetBranchName/;
30 use Digest::MD5 qw(md5_base64);
32 use vars qw($VERSION @ISA @EXPORT);
35 # set the version for version checking
40 &BorrowerExists &CanBookBeReserved &Availability
46 C4::ILS-DI::Utility - ILS-DI Utilities
52 Checks, for a given userid and password, if the borrower exists.
54 if ( BorrowerExists($userid, $password) ) {
61 my ( $userid, $password ) = @_;
62 $password = md5_base64($password);
63 my $dbh = C4::Context->dbh;
65 $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} eq 1 ) {
100 my @reserves = GetReservesFromBorrowernumber( $borrower->{'borrowernumber'} );
101 if ( 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);
141 elsif ($item->{'onloan'}) {
142 return ($biblionumber, 'not available', 'Checked out', $location);
144 elsif ($item->{'itemlost'}) {
145 return ($biblionumber, 'not available', 'Item lost', $location);
147 elsif ($item->{'wthdrawn'}) {
148 return ($biblionumber, 'not available', 'Item withdrawn', $location);
150 elsif ($item->{'damaged'}) {
151 return ($biblionumber, 'not available', 'Item damaged', $location);
154 return ($biblionumber, 'available', undef, $location);
157 die Data::Dumper::Dumper($item);