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);
30 C4::ILS-DI::Utility - ILS-DI Utilities
36 Checks, for a given userid and password, if the borrower exists.
38 if ( BorrowerExists($userid, $password) ) {
45 my ( $userid, $password ) = @_;
46 $password = md5_base64($password);
47 my $dbh = C4::Context->dbh;
49 $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? ");
50 $sth->execute( $userid, $password );
51 return $sth->fetchrow;
54 =head2 CanBookBeReserved
56 Checks if a book (at bibliographic level) can be reserved by a borrower.
58 if ( CanBookBeReserved($borrower, $biblionumber) ) {
64 sub CanBookBeReserved {
65 my ( $borrower, $biblionumber ) = @_;
67 my $MAXIMUM_NUMBER_OF_RESERVES = C4::Context->preference("maxreserves");
68 my $MAXOUTSTANDING = C4::Context->preference("maxoutstanding");
72 if ( $borrower->{'amountoutstanding'} > $MAXOUTSTANDING ) {
75 if ( $borrower->{gonenoaddress} eq 1 ) {
78 if ( $borrower->{lost} eq 1 ) {
81 if ( $borrower->{debarred} eq 1 ) {
84 my @reserves = GetReservesFromBorrowernumber( $borrower->{'borrowernumber'} );
85 if ( scalar(@reserves) >= $MAXIMUM_NUMBER_OF_RESERVES ) {
88 foreach my $res (@reserves) {
89 if ( $res->{'biblionumber'} == $biblionumber ) {
93 my $issues = GetPendingIssues($borrower->{'borrowernumber'});
94 foreach my $issue (@$issues) {
95 if ( $issue->{'biblionumber'} == $biblionumber ) {
105 Returns, for an itemnumber, an array containing availability information.
107 my ($biblionumber, $status, $msg, $location) = Availability($id);
112 my ( $itemnumber ) = @_;
113 my $item = GetItem($itemnumber, undef, undef);
115 if ( not $item->{'itemnumber'} ) {
116 return (undef, 'unknown', 'Error: could not retrieve availability for this ID', undef);
119 my $biblionumber = $item->{'biblioitemnumber'};
120 my $location = GetBranchName($item->{'holdingbranch'});
122 if ($item->{'notforloan'}) {
123 return ($biblionumber, 'not available', 'Not for loan', $location);
125 elsif ($item->{'onloan'}) {
126 return ($biblionumber, 'not available', 'Checked out', $location);
128 elsif ($item->{'itemlost'}) {
129 return ($biblionumber, 'not available', 'Item lost', $location);
131 elsif ($item->{'wthdrawn'}) {
132 return ($biblionumber, 'not available', 'Item withdrawn', $location);
134 elsif ($item->{'damaged'}) {
135 return ($biblionumber, 'not available', 'Item damaged', $location);
138 return ($biblionumber, 'available', undef, $location);
141 die Data::Dumper::Dumper($item);