View | Details | Raw Unified | Return to bug 10781
Collapse All | Expand All

(-)a/C4/ILSDI/Services.pm (-2 / +38 lines)
Lines 29-39 use C4::Biblio; Link Here
29
use C4::Reserves qw(AddReserve CancelReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
29
use C4::Reserves qw(AddReserve CancelReserve GetReservesFromBiblionumber GetReservesFromBorrowernumber CanBookBeReserved CanItemBeReserved);
30
use C4::Context;
30
use C4::Context;
31
use C4::AuthoritiesMarc;
31
use C4::AuthoritiesMarc;
32
use C4::ILSDI::Utility;
33
use XML::Simple;
32
use XML::Simple;
34
use HTML::Entities;
33
use HTML::Entities;
35
use CGI;
34
use CGI;
36
use DateTime;
35
use DateTime;
36
use Data::Dumper;
37
37
38
=head1 NAME
38
=head1 NAME
39
39
Lines 114-120 sub GetAvailability { Link Here
114
114
115
    foreach my $id ( split( / /, $cgi->param('id') ) ) {
115
    foreach my $id ( split( / /, $cgi->param('id') ) ) {
116
        if ( $cgi->param('id_type') eq "item" ) {
116
        if ( $cgi->param('id_type') eq "item" ) {
117
            my ( $biblionumber, $status, $msg, $location ) = Availability($id);
117
            my ( $biblionumber, $status, $msg, $location ) = _availability($id);
118
118
119
            $out .= "  <dlf:record>\n";
119
            $out .= "  <dlf:record>\n";
120
            $out .= "    <dlf:bibliographic id=\"" . ( $biblionumber || $id ) . "\" />\n";
120
            $out .= "    <dlf:bibliographic id=\"" . ( $biblionumber || $id ) . "\" />\n";
Lines 767-770 sub CancelHold { Link Here
767
    return { code => 'Canceled' };
767
    return { code => 'Canceled' };
768
}
768
}
769
769
770
=head2 _availability
771
772
Returns, for an itemnumber, an array containing availability information.
773
774
	my ($biblionumber, $status, $msg, $location) = _availability($id);
775
776
=cut
777
778
sub _availability {
779
    my ($itemnumber) = @_;
780
    my $item = GetItem( $itemnumber, undef, undef );
781
782
    if ( not $item->{'itemnumber'} ) {
783
        return ( undef, 'unknown', 'Error: could not retrieve availability for this ID', undef );
784
    }
785
786
    my $biblionumber = $item->{'biblioitemnumber'};
787
    my $location     = GetBranchName( $item->{'holdingbranch'} );
788
789
    if ( $item->{'notforloan'} ) {
790
        return ( $biblionumber, 'not available', 'Not for loan', $location );
791
    } elsif ( $item->{'onloan'} ) {
792
        return ( $biblionumber, 'not available', 'Checked out', $location );
793
    } elsif ( $item->{'itemlost'} ) {
794
        return ( $biblionumber, 'not available', 'Item lost', $location );
795
    } elsif ( $item->{'wthdrawn'} ) {
796
        return ( $biblionumber, 'not available', 'Item withdrawn', $location );
797
    } elsif ( $item->{'damaged'} ) {
798
        return ( $biblionumber, 'not available', 'Item damaged', $location );
799
    } else {
800
        return ( $biblionumber, 'available', undef, $location );
801
    }
802
803
    die Data::Dumper::Dumper($item);
804
}
805
770
1;
806
1;
(-)a/C4/ILSDI/Utility.pm (-107 lines)
Lines 1-107 Link Here
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->{'wthdrawn'} ) {
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;
(-)a/t/ILSDI_Utility.t (-15 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 1;
10
11
BEGIN {
12
        use_ok('C4::ILSDI::Utility');
13
}
14
15
- 

Return to bug 10781