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
26 use Digest::MD5 qw(md5_base64);
28 use vars qw($VERSION @ISA @EXPORT);
31 # set the version for version checking
36 &BorrowerExists &CanBookBeReserved &Availability
42 C4::ILS-DI::Utility - ILS-DI Utilities
48 Checks, for a given userid and password, if the borrower exists.
50 if ( BorrowerExists($userid, $password) ) {
57 my ( $userid, $password ) = @_;
58 $password = md5_base64($password);
59 my $dbh = C4::Context->dbh;
61 $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? ");
62 $sth->execute( $userid, $password );
63 return $sth->fetchrow;
66 =head2 CanBookBeReserved
68 Checks if a book (at bibliographic level) can be reserved by a borrower.
70 if ( CanBookBeReserved($borrower, $biblionumber) ) {
76 sub CanBookBeReserved {
77 my ( $borrower, $biblionumber ) = @_;
79 my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
80 my $MAXOUTSTANDING = C4::Context->preference("maxoutstanding");
84 if ( $borrower->{'amountoutstanding'} > $MAXOUTSTANDING ) {
87 if ( $borrower->{gonenoaddress} eq 1 ) {
90 if ( $borrower->{lost} eq 1 ) {
93 if ( $borrower->{debarred} eq 1 ) {
96 my @reserves = GetReservesFromBorrowernumber( $borrower->{'borrowernumber'} );
97 if ( scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES ) {
100 foreach my $res (@reserves) {
101 if ( $res->{'biblionumber'} == $biblionumber ) {
105 my $issues = GetPendingIssues($borrower->{'borrowernumber'});
106 foreach my $issue (@$issues) {
107 if ( $issue->{'biblionumber'} == $biblionumber ) {
117 Returns, for an itemnumber, an array containing availability information.
119 my ($biblionumber, $status, $msg, $location) = Availability($id);
124 my ( $itemnumber ) = @_;
125 my $item = GetItem($itemnumber, undef, undef);
127 if ( not $item->{'itemnumber'} ) {
128 return (undef, 'unknown', 'Error: could not retrieve availability for this ID', undef);
131 my $biblionumber = $item->{'biblioitemnumber'};
132 my $location = GetBranchName($item->{'holdingbranch'});
134 if ($item->{'notforloan'}) {
135 return ($biblionumber, 'not available', 'Not for loan', $location);
137 elsif ($item->{'onloan'}) {
138 return ($biblionumber, 'not available', 'Checked out', $location);
140 elsif ($item->{'itemlost'}) {
141 return ($biblionumber, 'not available', 'Item lost', $location);
143 elsif ($item->{'wthdrawn'}) {
144 return ($biblionumber, 'not available', 'Item withdrawn', $location);
146 elsif ($item->{'damaged'}) {
147 return ($biblionumber, 'not available', 'Item damaged', $location);
150 return ($biblionumber, 'available', undef, $location);
153 die Data::Dumper::Dumper($item);