File: | C4/ILSDI/Utility.pm |
Coverage: | 59.0% |
line | stmt | bran | cond | sub | time | code |
---|---|---|---|---|---|---|
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 | 3 3 3 | 19205 10 100 | use strict; | |||
22 | 3 3 3 | 18 8 141 | use warnings; | |||
23 | ||||||
24 | 3 3 3 | 212 48 1362 | use C4::Members; | |||
25 | 3 3 3 | 14 4 698 | use C4::Items; | |||
26 | 3 3 3 | 14 19 787 | use C4::Circulation; | |||
27 | 3 3 3 | 15 4 1560 | use C4::Biblio; | |||
28 | 3 3 3 | 13 4 197 | use C4::Reserves qw(GetReservesFromBorrowernumber CanBookBeReserved); | |||
29 | 3 3 3 | 12 5 32 | use C4::Context; | |||
30 | 3 3 3 | 11 5 131 | use C4::Branch qw/GetBranchName/; | |||
31 | 3 3 3 | 13 4 175 | use Digest::MD5 qw(md5_base64); | |||
32 | ||||||
33 | 3 3 3 | 13 4 307 | use vars qw($VERSION @ISA @EXPORT); | |||
34 | ||||||
35 | BEGIN { | |||||
36 | ||||||
37 | # set the version for version checking | |||||
38 | 3 | 4 | $VERSION = 3.00; | |||
39 | 3 | 13 | require Exporter; | |||
40 | 3 | 31 | @ISA = qw(Exporter); | |||
41 | 3 | 933 | @EXPORT = qw( | |||
42 | &BorrowerExists &Availability | |||||
43 | ); | |||||
44 | } | |||||
45 | ||||||
46 - 50 | =head1 NAME C4::ILS-DI::Utility - ILS-DI Utilities =cut | |||||
51 | ||||||
52 - 60 | =head2 BorrowerExists Checks, for a given userid and password, if the borrower exists. if ( BorrowerExists($userid, $password) ) { # Do stuff } =cut | |||||
61 | ||||||
62 | sub BorrowerExists { | |||||
63 | 0 | my ( $userid, $password ) = @_; | ||||
64 | 0 | $password = md5_base64($password); | ||||
65 | 0 | my $dbh = C4::Context->dbh; | ||||
66 | 0 | my $sth = $dbh->prepare("SELECT COUNT(*) FROM borrowers WHERE userid =? and password=? "); | ||||
67 | 0 | $sth->execute( $userid, $password ); | ||||
68 | 0 | return $sth->fetchrow; | ||||
69 | } | |||||
70 | ||||||
71 - 77 | =head2 Availability Returns, for an itemnumber, an array containing availability information. my ($biblionumber, $status, $msg, $location) = Availability($id); =cut | |||||
78 | ||||||
79 | sub Availability { | |||||
80 | 0 | my ($itemnumber) = @_; | ||||
81 | 0 | my $item = GetItem( $itemnumber, undef, undef ); | ||||
82 | ||||||
83 | 0 | if ( not $item->{'itemnumber'} ) { | ||||
84 | 0 | return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef ); | ||||
85 | } | |||||
86 | ||||||
87 | 0 | my $biblionumber = $item->{'biblioitemnumber'}; | ||||
88 | 0 | my $location = GetBranchName( $item->{'holdingbranch'} ); | ||||
89 | ||||||
90 | 0 | if ( $item->{'notforloan'} ) { | ||||
91 | 0 | return ( $biblionumber, 'not available', 'Not for loan', $location ); | ||||
92 | } elsif ( $item->{'onloan'} ) { | |||||
93 | 0 | return ( $biblionumber, 'not available', 'Checked out', $location ); | ||||
94 | } elsif ( $item->{'itemlost'} ) { | |||||
95 | 0 | return ( $biblionumber, 'not available', 'Item lost', $location ); | ||||
96 | } elsif ( $item->{'wthdrawn'} ) { | |||||
97 | 0 | return ( $biblionumber, 'not available', 'Item withdrawn', $location ); | ||||
98 | } elsif ( $item->{'damaged'} ) { | |||||
99 | 0 | return ( $biblionumber, 'not available', 'Item damaged', $location ); | ||||
100 | } else { | |||||
101 | 0 | return ( $biblionumber, 'available', undef, $location ); | ||||
102 | } | |||||
103 | ||||||
104 | 0 | die Data::Dumper::Dumper($item); | ||||
105 | } | |||||
106 | ||||||
107 | 1; |