Bug 10550: Fix database typo wthdrawn
[koha.git] / C4 / ILSDI / Utility.pm
1 package C4::ILSDI::Utility;
2
3 # Copyright 2009 SARL Biblibre
4 # Copyright 2011 software.coop and MJ Ray
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use strict;
22 use warnings;
23
24 use C4::Members;
25 use C4::Items;
26 use C4::Circulation;
27 use C4::Biblio;
28 use C4::Reserves qw(GetReservesFromBorrowernumber CanBookBeReserved);
29 use C4::Context;
30 use C4::Branch qw/GetBranchName/;
31 use Digest::MD5 qw(md5_base64);
32
33 use vars qw($VERSION @ISA @EXPORT);
34
35 BEGIN {
36
37     # set the version for version checking
38     $VERSION = 3.07.00.049;
39     require Exporter;
40     @ISA    = qw(Exporter);
41     @EXPORT = qw(
42       &BorrowerExists &Availability
43     );
44 }
45
46 =head1 NAME
47
48 C4::ILS-DI::Utility - ILS-DI Utilities
49
50 =cut
51
52 =head2 BorrowerExists
53
54 Checks, for a given userid and password, if the borrower exists.
55
56         if ( BorrowerExists($userid, $password) ) {
57                 # Do stuff
58         }
59
60 =cut
61
62 sub BorrowerExists {
63     my ( $userid, $password ) = @_;
64     $password = md5_base64($password);
65     my $dbh = C4::Context->dbh;
66     my $sth = $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? ");
67     $sth->execute( $userid, $password );
68     return $sth->fetchrow;
69 }
70
71 =head2 Availability
72
73 Returns, for an itemnumber, an array containing availability information.
74
75         my ($biblionumber, $status, $msg, $location) = Availability($id);
76
77 =cut
78
79 sub Availability {
80     my ($itemnumber) = @_;
81     my $item = GetItem( $itemnumber, undef, undef );
82
83     if ( not $item->{'itemnumber'} ) {
84         return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
85     }
86
87     my $biblionumber = $item->{'biblioitemnumber'};
88     my $location     = GetBranchName( $item->{'holdingbranch'} );
89
90     if ( $item->{'notforloan'} ) {
91         return ( $biblionumber, 'not available', 'Not for loan', $location );
92     } elsif ( $item->{'onloan'} ) {
93         return ( $biblionumber, 'not available', 'Checked out', $location );
94     } elsif ( $item->{'itemlost'} ) {
95         return ( $biblionumber, 'not available', 'Item lost', $location );
96     } elsif ( $item->{'withdrawn'} ) {
97         return ( $biblionumber, 'not available', 'Item withdrawn', $location );
98     } elsif ( $item->{'damaged'} ) {
99         return ( $biblionumber, 'not available', 'Item damaged', $location );
100     } else {
101         return ( $biblionumber, 'available', undef, $location );
102     }
103
104     die Data::Dumper::Dumper($item);
105 }
106
107 1;