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

(-)a/C4/NCIP/CancelRequestItem.pm (+100 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::CancelRequestItem;
21
22
use Modern::Perl;
23
24
=head1 NAME
25
26
C4::NCIP::CancelRequestItem - NCIP module for effective processing of CancelRequestItem NCIP service
27
28
=head1 SYNOPSIS
29
30
  use C4::NCIP::CancelRequestItem;
31
32
=head1 DESCRIPTION
33
34
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
35
36
=cut
37
38
=head1 METHODS
39
40
=head2 cancelRequestItem
41
42
        cancelRequestItem($cgiInput)
43
44
        Expected input is as e.g. as follows:
45
46
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=cancel_request_item&requestId=89&userId=4
47
        or
48
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=cancel_request_item&itemId=95&userId=3
49
50
        REQUIRED PARAMS:
51
        Param 'service=cancel_request_item' tells svc/ncip to forward the query here.
52
        Param 'userId=3' specifies borrowernumber whos request is being cancelled.
53
        Param 'itemId=4' specifies itemnumber to cancel.
54
	Param 'requestId=89' specifies request to cancel.
55
56
=cut
57
58
sub cancelRequestItem {
59
    my ($query)   = @_;
60
    my $userId    = $query->param('userId');
61
    my $itemId    = $query->param('itemId');
62
    my $requestId = $query->param('requestId');
63
    my ($result, $reserve);
64
    if (defined $userId and defined $itemId) {
65
        $reserve
66
            = C4::Reserves::GetReserveFromBorrowernumberAndItemnumber($userId,
67
            $itemId);
68
69
    } elsif (defined $userId and defined $requestId) {
70
        $reserve = C4::Reserves::GetReserve($requestId);
71
    } else {
72
        C4::NCIP::NcipUtils::print400($query,
73
            'You have to specify either both \'userId\' & \'itemId\' or both \'userId\' & \'requestId\'..'
74
        );
75
# It's a shame schema allow RequestItem with BibId & doesn't allow CancelRequestItem with BibId .. (NCIP Initiatior needs to LookupUser with RequestedItemsDesired -> parse requestId of bibId)
76
#
77
# Schema definition of CancelRequestItem:
78
# <xs:element name="CancelRequestItem"><xs:complexType><xs:sequence><xs:element ref="InitiationHeader" minOccurs="0"/><xs:element ref="MandatedAction" minOccurs="0"/><xs:choice><xs:element ref="UserId"/><xs:element ref="AuthenticationInput" maxOccurs="unbounded"/></xs:choice><xs:choice><xs:element ref="ItemId"/><xs:sequence><xs:element ref="RequestId"/><xs:element ref="ItemId" minOccurs="0"/></xs:sequence></xs:choice><xs:element ref="RequestType"/><xs:element ref="RequestScopeType" minOccurs="0"/><xs:element ref="AcknowledgedFeeAmount" minOccurs="0"/><xs:element ref="PaidFeeAmount" minOccurs="0"/><xs:element ref="ItemElementType" minOccurs="0" maxOccurs="unbounded"/><xs:element ref="UserElementType" minOccurs="0" maxOccurs="unbounded"/><xs:element ref="Ext" minOccurs="0"/></xs:sequence></xs:complexType></xs:element>
79
#
80
# Source: http://www.niso.org/schemas/ncip/v2_02/ncip_v2_02.xsd
81
    }
82
83
    C4::NCIP::NcipUtils::print404($query, "Request not found..")
84
        unless $reserve;
85
86
    C4::NCIP::NcipUtils::print403($query,
87
        'Request doesn\'t belong to this patron ..')
88
        unless $reserve->{'borrowernumber'} eq $userId;
89
90
    C4::Reserves::CancelReserve($reserve);
91
92
    $result->{'userId'}    = $reserve->{borrowernumber};
93
    $result->{'itemId'}    = $reserve->{itemnumber};
94
    $result->{'requestId'} = $reserve->{reserve_id};
95
    $result->{'status'}    = 'cancelled';
96
97
    C4::NCIP::NcipUtils::printJson($query, $result);
98
}
99
100
1;
(-)a/C4/NCIP/LookupItem.pm (+168 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::LookupItem;
21
22
use Modern::Perl;
23
use C4::NCIP::NcipUtils;
24
25
=head1 NAME
26
27
C4::NCIP::LookupItem - NCIP module for effective processing of LookupItem NCIP service
28
29
=head1 SYNOPSIS
30
31
  use C4::NCIP::LookupItem;
32
33
=head1 DESCRIPTION
34
35
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
36
37
=cut
38
39
=head1 METHODS
40
41
=head2 lookupItem
42
43
        lookupItem($cgiInput)
44
45
        Expected input is as e.g. as follows:
46
        http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_item&itemId=95&holdQueueLengthDesired&circulationStatusDesired&itemUseRestrictionTypeDesired&notItemInfo
47
        or
48
        http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_item&itemId=95
49
        http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_item&barcode=956216
50
51
        REQUIRED PARAMS:
52
        Param 'service=lookup_item' tells svc/ncip to forward the query here.
53
        Param 'itemId=4' specifies itemnumber to look for.
54
        Param 'barcode=956216' specifies barcode to look for.
55
56
        OPTIONAL PARAMS:
57
        holdQueueLengthDesired specifies to include number of reserves placed on item
58
        circulationStatusDesired specifies to include circulation statuses of item
59
        itemUseRestrictionTypeDesired specifies to inlude item use restriction type of item
60
        notItemInfo specifies to omit item information (normally returned)
61
=cut
62
63
sub lookupItem {
64
    my ($query) = @_;
65
66
    my $itemId  = $query->param('itemId');
67
    my $barcode = $query->param('barcode');
68
69
    unless (defined $itemId) {
70
        C4::NCIP::NcipUtils::print400($query,
71
            "itemId nor barcode is specified..\n")
72
            unless $barcode;
73
74
        $itemId = C4::Items::GetItemnumberFromBarcode($barcode);
75
    }
76
77
    my $iteminfo = C4::Items::GetItem($itemId, $barcode, undef);
78
79
    C4::NCIP::NcipUtils::print404($query, "Item not found..")
80
        unless $iteminfo;
81
82
    my $bibId = $iteminfo->{'biblioitemnumber'};
83
84
    my $result;
85
    my $desiredSomething = 0;
86
    if (   defined $query->param('holdQueueLengthDesired')
87
        or defined $query->param('circulationStatusDesired'))
88
    {
89
        $desiredSomething = 1;
90
91
        my $holds = C4::Reserves::GetReserveCountFromItemnumber($itemId);
92
93
        if (defined $query->param('holdQueueLengthDesired')) {
94
            $result->{'holdQueueLength'} = $holds;
95
        }
96
        if (defined $query->param('circulationStatusDesired')) {
97
            $result->{'circulationStatus'}
98
                = C4::NCIP::NcipUtils::parseCirculationStatus($iteminfo,
99
                $holds);
100
        }
101
    }
102
    if (defined $query->param('itemUseRestrictionTypeDesired')) {
103
        my $restrictions
104
            = C4::NCIP::NcipUtils::parseItemUseRestrictions($iteminfo);
105
        unless (scalar @{$restrictions} == 0) {
106
            $result->{'itemUseRestrictions'} = $restrictions;
107
        }
108
        $desiredSomething = 1;
109
    }
110
111
    $result->{'itemInfo'} = parseItem($bibId, $itemId, $iteminfo)
112
        unless $desiredSomething and defined $query->param('notItemInfo');
113
114
    C4::NCIP::NcipUtils::printJson($query, $result);
115
}
116
117
=head2 parseItem
118
119
	parseItem($biblionumber, $itemnumber, $item)
120
121
	Returns info of biblio level & item level
122
123
=cut
124
125
sub parseItem {
126
    my ($bibId, $itemId, $item) = @_;
127
128
    my $dbh = C4::Context->dbh;
129
    my $sth = $dbh->prepare("
130
        SELECT biblioitems.volume,
131
                biblioitems.number,
132
                biblioitems.isbn,
133
                biblioitems.issn,
134
                biblioitems.publicationyear,
135
                biblioitems.publishercode,
136
                biblioitems.pages,
137
                biblioitems.size,
138
                biblioitems.place,
139
                biblioitems.agerestriction,
140
                biblio.author,
141
                biblio.title,
142
                biblio.unititle,
143
                biblio.notes,
144
                biblio.serial
145
        FROM biblioitems
146
        LEFT JOIN biblio ON biblio.biblionumber = biblioitems.biblionumber
147
        WHERE biblioitems.biblionumber = ?");
148
    $sth->execute($bibId);
149
    my $result = $sth->fetchrow_hashref;
150
151
    return 'SQL query failed' unless $result;
152
153
    $result->{itemId}        = $itemId;
154
    $result->{bibId}         = $bibId;
155
    $result->{barcode}       = $item->{barcode};
156
    $result->{location}      = $item->{location};
157
    $result->{homebranch}    = $item->{homebranch};
158
    $result->{restricted}    = $item->{restricted};
159
    $result->{holdingbranch} = $item->{holdingbranch};
160
    $result->{mediumtype}    = $item->{itype};
161
    $result->{copynumber}    = $item->{copynumber};
162
    $result->{callnumber}    = $item->{itemcallnumber};
163
    $result->{ccode}         = $item->{ccode};
164
165
    return C4::NCIP::NcipUtils::clearEmptyKeys($result);
166
}
167
168
1;
(-)a/C4/NCIP/LookupItemSet.pm (+212 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::LookupItemSet;
21
22
use Modern::Perl;
23
24
=head1 NAME
25
26
C4::NCIP::LookupItemSet - NCIP module for effective processing of LookupItemSet NCIP service
27
28
=head1 SYNOPSIS
29
30
  use C4::NCIP::LookupItemSet;
31
32
=head1 DESCRIPTION
33
34
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
35
36
=cut
37
38
=head1 METHODS
39
40
=head2 lookupItemSet
41
42
        lookupItemSet($cgiInput)
43
44
        Expected input is as e.g. as follows:
45
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_item_set&bibId=95&holdQueueLengthDesired&circulationStatusDesired&itemUseRestrictionTypeDesired&notBibInfo
46
	or
47
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_item_set&bibId=95
48
49
        REQUIRED PARAMS:
50
        Param 'service=lookup_item_set' tells svc/ncip to forward the query here.
51
        Param 'bibId=4' specifies biblionumber look for.
52
53
        OPTIONAL PARAMS:
54
	holdQueueLengthDesired specifies to include number of reserves placed on items of this biblio or on biblio itself
55
	circulationStatusDesired specifies to include circulation statuses of all items of this biblio
56
	itemUseRestrictionTypeDesired specifies to inlude item use restriction types of all items of this biblio
57
	notBibInfo specifies to omit bibliographic information (normally returned)
58
=cut
59
60
sub lookupItemSet {
61
    my ($query) = @_;
62
63
    my $bibId = $query->param('bibId');
64
65
    C4::NCIP::NcipUtils::print400($query, "Param bibId is undefined..")
66
        unless $bibId;
67
68
    my $result;
69
70
    my $circStatusDesired = defined $query->param('circulationStatusDesired');
71
72
    # Parse Items within BibRecord ..
73
    $result->{items} = parseItems($bibId, $circStatusDesired);
74
75
    C4::NCIP::NcipUtils::print404($query, "Biblio not found..")
76
        if scalar @{$result->{items}} == 0;
77
78
    my $holdQueueDesired = defined $query->param('holdQueueLengthDesired');
79
    my $itemRestrictsDesired
80
        = defined $query->param('itemUseRestrictionTypeDesired');
81
82
    my $count = scalar @{$result->{items}};
83
84
    $result->{itemsCount} = $count;
85
86
    for (my $i = 0; $i < $count; ++$i) {
87
        my $item = ${$result->{items}}[$i];
88
        if ($holdQueueDesired or $circStatusDesired) {
89
90
            my $holds = C4::Reserves::GetReserveCountFromItemnumber(
91
                $item->{itemnumber});
92
93
            if ($holdQueueDesired) {
94
                $item->{'holdQueueLength'} = $holds;
95
            }
96
            if ($circStatusDesired) {
97
                $item->{'circulationStatus'}
98
                    = C4::NCIP::NcipUtils::parseCirculationStatus($item,
99
                    $holds);
100
101
                # Delete keys not needed anymore
102
                delete $item->{onloan};
103
                delete $item->{itemlost};
104
                delete $item->{withdrawn};
105
                delete $item->{damaged};
106
            }
107
        }
108
        if ($itemRestrictsDesired) {
109
            my $restrictions
110
                = C4::NCIP::NcipUtils::parseItemUseRestrictions($item);
111
            unless (scalar @{$restrictions} == 0) {
112
                $item->{'itemUseRestrictions'} = $restrictions;
113
            }
114
        }
115
        delete $item->{notforloan};
116
    }
117
    my $desiredSomething
118
        = $holdQueueDesired
119
        or $itemRestrictsDesired
120
        or $circStatusDesired;
121
122
    $result->{bibInfo} = parseBiblio($bibId)
123
        unless $desiredSomething and defined $query->param('notBibInfo');
124
125
    C4::NCIP::NcipUtils::printJson($query, $result);
126
}
127
128
=head2 parseBiblio
129
130
	parseBiblio($biblionumber)
131
132
	On success returns hashref with bibliodata from tables biblioitems & biblio relative to NCIP
133
134
	On failure returns string
135
136
=cut
137
138
sub parseBiblio {
139
    my ($bibId) = @_;
140
    my $dbh     = C4::Context->dbh;
141
    my $sth     = $dbh->prepare("
142
        SELECT biblioitems.volume,
143
                biblioitems.number,
144
                biblioitems.isbn,
145
                biblioitems.issn,
146
                biblioitems.publicationyear,
147
                biblioitems.publishercode,
148
                biblioitems.pages,
149
                biblioitems.size,
150
                biblioitems.place,
151
                biblioitems.agerestriction,
152
                biblio.author,
153
                biblio.title,
154
                biblio.unititle,
155
                biblio.notes,
156
                biblio.serial
157
        FROM biblioitems
158
        LEFT JOIN biblio ON biblio.biblionumber = biblioitems.biblionumber
159
        WHERE biblioitems.biblionumber = ?");
160
    $sth->execute($bibId);
161
    my $data = C4::NCIP::NcipUtils::clearEmptyKeys($sth->fetchrow_hashref);
162
163
    return $data || 'SQL query failed..';
164
}
165
166
=head2 parseItems
167
168
	parseItems($biblionumber, $circulationStatusDesired)
169
170
	Returns array of items with data relative to NCIP from table items
171
172
=cut
173
174
sub parseItems {
175
    my ($bibId, $circStatusDesired) = @_;
176
    my $dbh   = C4::Context->dbh;
177
    my $query = "
178
	SELECT itemnumber,
179
		barcode,
180
		homebranch,
181
		notforloan,
182
		itemcallnumber,
183
		restricted,
184
		holdingbranch,
185
		location,
186
		ccode,
187
		materials,
188
		copynumber";
189
    if ($circStatusDesired) {
190
        $query .= ",
191
		onloan,
192
		itemlost,
193
		withdrawn,
194
		damaged";
195
    }
196
    $query .= "
197
		FROM items
198
		WHERE items.biblionumber = ?";
199
    my $sth = $dbh->prepare($query);
200
    $sth->execute($bibId);
201
    my @items;
202
    my $i = 0;
203
    while (my $data
204
        = C4::NCIP::NcipUtils::clearEmptyKeys($sth->fetchrow_hashref))
205
    {
206
        $items[$i++] = $data;
207
    }
208
209
    return \@items;
210
}
211
212
1;
(-)a/C4/NCIP/LookupRequest.pm (+85 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::LookupRequest;
21
22
use Modern::Perl;
23
24
=head1 NAME
25
26
C4::NCIP::LookupRequest - NCIP module for effective processing of LookupRequest NCIP service
27
28
=head1 SYNOPSIS
29
30
  use C4::NCIP::LookupRequest;
31
32
=head1 DESCRIPTION
33
34
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
35
36
=cut
37
38
=head1 METHODS
39
40
=head2 lookupRequest
41
42
        lookupRequest($cgiInput)
43
44
        Expected input is as e.g. as follows:
45
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_request&userId=1&itemId=111
46
        or
47
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_request&requestId=83
48
49
        REQUIRED PARAMS:
50
        Param 'service=lookup_request' tells svc/ncip to forward the query here.
51
	Either:
52
	        Param 'userId=3' specifies borrowernumber to look for.
53
		Param 'itemId=1' specifies itemnumber to look for.
54
	Or:
55
		Param 'requestId=83' specifies number of request to look for-
56
=cut
57
58
sub lookupRequest {
59
    my ($query) = @_;
60
    my $requestId = $query->param('requestId');
61
62
    my $result;
63
    if (defined $requestId) {
64
        $result = C4::Reserves::GetReserve($requestId);
65
    } else {
66
        my $userId = $query->param('userId');
67
        my $itemId = $query->param('itemId');
68
69
        C4::NCIP::NcipUtils::print400($query,
70
            'You have to specify \'requestId\' or both \'userId\' & \'itemId\'..'
71
        ) unless (defined $userId and defined $itemId);
72
73
        $result
74
            = C4::Reserves::GetReserveFromBorrowernumberAndItemnumber($userId,
75
            $itemId);
76
    }
77
78
    C4::NCIP::NcipUtils::print404($query, "Request not found..")
79
        unless $result;
80
81
    C4::NCIP::NcipUtils::clearEmptyKeys($result);
82
83
    C4::NCIP::NcipUtils::printJson($query, $result);
84
}
85
1;
(-)a/C4/NCIP/LookupUser.pm (+191 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2013 BibLibre
4
#
5
# This file is part of Koha
6
#
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
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::LookupUser;
21
22
use Modern::Perl;
23
use C4::NCIP::NcipUtils;
24
25
=head1 NAME
26
27
C4::NCIP::LookupUser - NCIP module for effective processing of LookupUser NCIP service
28
29
=head1 SYNOPSIS
30
31
  use C4::NCIP::LookupUser;
32
33
=head1 DESCRIPTION
34
35
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
36
37
=cut
38
39
=head1 METHODS
40
41
=head2 lookupUser
42
43
        lookupUser($cgiInput)
44
45
        Expected input is as e.g. as follows:
46
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_user&userId=3&loanedItemsDesired&requestedItemsDesired&userFiscalAccountDesired&notUserInfo
47
	or
48
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=lookup_user&userId=3
49
50
        REQUIRED PARAMS:
51
        Param 'service=lookup_user' tells svc/ncip to forward the query here.
52
        Param 'userId=3' specifies borrowernumber to look for.
53
54
        OPTIONAL PARAMS:
55
	loanedItemsDesired specifies to include user's loaned items
56
	requestedItemsDesired specifies to include user's holds
57
	userFiscalAccountDesired specifies to inlude user's transactions
58
	notUserInfo specifies to omit looking up user's personal info as address, name etc.
59
=cut
60
61
sub lookupUser {
62
    my ($query) = @_;
63
    my $userId = $query->param('userId');
64
    C4::NCIP::NcipUtils::print400($query, "Param userId is undefined..")
65
        unless $userId;
66
67
    my $userData = parseUserData($userId);
68
69
    C4::NCIP::NcipUtils::print404($query, "User not found..")
70
        unless $userData;
71
72
    my $results;
73
    my $desiredSomething = 0;
74
    if (defined $query->param('loanedItemsDesired')) {
75
        $results->{'loanedItems'} = parseLoanedItems($userId);
76
        $desiredSomething = 1;
77
    }
78
    if (defined $query->param('requestedItemsDesired')) {
79
        my @reserves
80
            = C4::Reserves::GetReservesFromBorrowernumber($userId, undef);
81
82
        C4::NCIP::NcipUtils::clearEmptyKeysWithinArray(@reserves);
83
84
        $results->{'requestedItems'} = \@reserves;
85
        $desiredSomething = 1;
86
    }
87
    if (defined $query->param('userFiscalAccountDesired')) {
88
        $results->{'userFiscalAccount'} = parseUserFiscalAccount($userId);
89
        $desiredSomething = 1;
90
    }
91
    $results->{'userInfo'} = $userData
92
        unless $desiredSomething and defined $query->param('notUserInfo');
93
94
    C4::NCIP::NcipUtils::printJson($query, $results);
95
}
96
97
=head2 parseUserData
98
99
	parseUserData($borrowenumber)
100
101
	Returns hashref of user's personal data as they are in table borrowers
102
=cut
103
104
sub parseUserData {
105
    my ($userId) = @_;
106
    my $dbh      = C4::Context->dbh;
107
    my $sth      = $dbh->prepare("
108
        SELECT surname,
109
                firstname,
110
                title,
111
		othernames,
112
		streetnumber,
113
		address,
114
		address2,
115
		city,
116
		state,
117
		zipcode,
118
		country,
119
		email,
120
		phone,
121
		mobile,
122
		fax,
123
		emailpro,
124
		phonepro,
125
		B_streetnumber,
126
		B_address,
127
		B_address2,
128
		B_city,
129
		B_state,
130
		B_zipcode,
131
		B_country,
132
		B_email,
133
		B_phone,
134
		categorycode,
135
		dateenrolled,
136
		dateexpiry
137
        FROM borrowers
138
        WHERE borrowernumber = ?");
139
    $sth->execute($userId);
140
    return C4::NCIP::NcipUtils::clearEmptyKeys($sth->fetchrow_hashref);
141
}
142
143
=head2 parseLoanedItems
144
145
	parseLoanedItems($borrowernumber)
146
147
	Returns array of user's issues with only these keys: issuedate, date_due, itemnumber
148
149
=cut
150
151
sub parseLoanedItems {
152
    my ($userId) = @_;
153
    my $dbh      = C4::Context->dbh;
154
    my $sth      = $dbh->prepare("
155
        SELECT issuedate,
156
		date_due,
157
		itemnumber
158
        FROM issues
159
        WHERE borrowernumber = ?");
160
    $sth->execute($userId);
161
162
    return \@{$sth->fetchall_arrayref({})};
163
}
164
165
=head2 parseUserFiscalAccount
166
167
	parseUserFiscalAccount($borrowenumber)
168
169
	Returns array of user's accountlines with these keys: accountno, itemnumber, date, amount, description, note
170
171
=cut
172
173
sub parseUserFiscalAccount {
174
    my ($userId) = @_;
175
    my $dbh      = C4::Context->dbh;
176
    my $sth      = $dbh->prepare("
177
        SELECT accountno,
178
		itemnumber,
179
		date,
180
		amount,
181
		description,
182
		note
183
        FROM accountlines
184
        WHERE borrowernumber = ?
185
	ORDER BY date desc,timestamp DESC");
186
    $sth->execute($userId);
187
188
    return \@{$sth->fetchall_arrayref({})};
189
}
190
191
1;
(-)a/C4/NCIP/NcipUtils.pm (+199 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::NcipUtils;
21
22
use Modern::Perl;
23
use JSON qw(to_json);
24
25
=head1 NAME
26
27
C4::NCIP::NcipUtils - NCIP Common subroutines used in most of C4::NCIP modules
28
29
=head1 SYNOPSIS
30
31
  use C4::NCIP::NcipUtils;
32
33
=head1 DESCRIPTION
34
35
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
36
37
=cut
38
39
=head1 METHODS
40
41
=head2 clearEmptyKeys
42
43
	clearEmptyKeys($hashref)
44
45
=cut
46
47
sub clearEmptyKeys {
48
    my ($hashref) = @_;
49
50
    return undef unless $hashref;
51
52
    foreach my $key (keys $hashref) {
53
        delete $hashref->{$key} unless $hashref->{$key};
54
    }
55
    return $hashref;
56
}
57
58
=head2 clearEmptyKeysWithinArray
59
60
	clearEmptyKeysWithinArray($arrayWithHashrefs)
61
62
=cut
63
64
sub clearEmptyKeysWithinArray {
65
    my (@arrayOfHashrefs) = @_;
66
67
    for (my $i = 0; $i < scalar @arrayOfHashrefs; ++$i) {
68
        clearEmptyKeys($arrayOfHashrefs[$i]);
69
    }
70
    return \@arrayOfHashrefs;
71
}
72
73
=head2 parseCirculationStatus
74
75
	parseCirculationStatus($item, $numberOfHoldsOnItem)
76
77
	Returns one of these:
78
		On Loan
79
		In Transit Between Library Locations
80
		Not Available
81
		Available On Shelf
82
83
=cut
84
85
sub parseCirculationStatus {
86
    my ($item, $holds) = @_;
87
88
    if ($holds != 0 or $item->{datedue} or $item->{onloan}) {
89
        return 'On Loan';
90
    }
91
    if ($item->{transfertwhen}) {
92
        return 'In Transit Between Library Locations';
93
    }
94
    if (   $item->{notforloan_per_itemtype}
95
        or $item->{itemlost}
96
        or $item->{withdrawn}
97
        or $item->{damaged})
98
    {
99
        return 'Not Available';
100
    }
101
102
    return 'Available On Shelf';
103
}
104
105
=head2 parseItemUseRestrictions
106
107
	parseItemUseRestrictions($item)
108
109
	Returns array of restriction NCIP formatted
110
	For now can return only 'In Library Use Only' within array if $item->{notforloan} is true
111
112
=cut
113
114
sub parseItemUseRestrictions {
115
# Possible standardized values can be found here:
116
# https://code.google.com/p/xcncip2toolkit/source/browse/core/trunk/service/src/main/java/org/extensiblecatalog/ncip/v2/service/Version1ItemUseRestrictionType.java
117
118
    my ($item) = @_;
119
120
    my @toReturn;
121
    my $i = 0;
122
    if ($item->{notforloan}) {
123
        $toReturn[$i++] = 'In Library Use Only';
124
    }
125
    return \@toReturn;
126
}
127
128
=head2 printJson
129
130
	printJson($cgiInput, $hashref)
131
132
	Prints header as text/plain with charset utf-8 and status 200 & converts $hashref to json format being printed to output.
133
134
=cut
135
136
sub printJson {
137
    my ($query, $string) = @_;
138
    print $query->header(
139
        -type    => 'text/plain',
140
        -charset => 'utf-8',
141
        -status  => '200 OK'
142
        ),
143
        to_json($string);
144
    exit 0;
145
}
146
147
=head2 print400
148
149
	print400($cgiInput, $message)
150
151
=cut
152
153
sub print400 {
154
    my ($query, $string) = @_;
155
    print $query->header(-type => 'text/plain', -status => '400 Bad Request'),
156
        $string;
157
    exit 0;
158
}
159
160
=head2 print403
161
162
        print403($cgiInput, $message)
163
164
=cut
165
166
sub print403 {
167
    my ($query, $string) = @_;
168
    print $query->header(-type => 'text/plain', -status => '403 Forbidden'),
169
        $string;
170
    exit 0;
171
}
172
173
=head2 print404
174
175
        print404($cgiInput, $message)
176
177
=cut
178
179
sub print404 {
180
    my ($query, $string) = @_;
181
    print $query->header(-type => 'text/plain', -status => '404 Not Found'),
182
        $string;
183
    exit 0;
184
}
185
186
=head2 print409
187
188
        print409($cgiInput, $message)
189
190
=cut
191
192
sub print409 {
193
    my ($query, $string) = @_;
194
    print $query->header(-type => 'text/plain', -status => '409 Conflict'),
195
        $string;
196
    exit 0;
197
}
198
199
1;
(-)a/C4/NCIP/RenewItem.pm (+147 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::RenewItem;
21
22
use Modern::Perl;
23
24
use JSON qw(to_json);
25
26
=head1 NAME
27
28
C4::NCIP::RenewItem - NCIP module for effective processing of RenewItem NCIP service
29
30
=head1 SYNOPSIS
31
32
  use C4::NCIP::RenewItem;
33
34
=head1 DESCRIPTION
35
36
        Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
37
38
=cut
39
40
=head1 METHODS
41
42
=head2 renewItem
43
44
        renewItem($cgiInput)
45
46
        Expected input is as e.g. as follows:
47
	http://188.166.14.82:8080/cgi-bin/koha/svc/ncip?service=renew_item&desiredDateDue=20/04/2015&itemId=382&userId=3
48
49
        REQUIRED PARAMS:
50
        Param 'service=renew_item' tells svc/ncip to forward the query here.
51
        Param 'userId=3' specifies borrowernumber as current borrower of Renewal item.
52
        Param 'itemId=4' specifies itemnumber to place Renewal on.
53
54
        OPTIONAL PARAMS:
55
	Param 'desiredDateDue=20/04/2015' specifies when would user like to have new DateDue - it is checked against Koha's default RenewalDate & if it is bigger than that, Koha's default RenewalDate is used instead
56
=cut
57
58
sub renewItem {
59
    my $query  = shift;
60
    my $itemId = $query->param('itemId');
61
    my $userId = $query->param('userId');
62
    my $branch = $query->param('branch') || C4::Context->userenv->{'branch'};
63
    my $biblio = C4::Biblio::GetBiblioFromItemNumber($itemId);
64
65
    unless ($itemId) {
66
        print $query->header(
67
            -type   => 'text/plain',
68
            -status => '400 Bad Request'
69
        );
70
        print "itemId is undefined..";
71
        exit 0;
72
    }
73
74
    unless ($userId) {
75
        print $query->header(
76
            -type   => 'text/plain',
77
            -status => '400 Bad Request'
78
        );
79
        print "userId is undefined..";
80
        exit 0;
81
    }
82
83
    my $dateDue = $query->param('desiredDateDue');
84
    if ($dateDue) {    # Need to restrict maximal DateDue ..
85
        my $dbh = C4::Context->dbh;
86
        # Find the issues record for this book
87
        my $sth = $dbh->prepare(
88
            "SELECT branchcode FROM issues WHERE itemnumber = ?");
89
        $sth->execute($itemId);
90
        my $issueBranchCode = $sth->fetchrow_array;
91
        unless ($issueBranchCode) {
92
            print $query->header(
93
                -type   => 'text/plain',
94
                -status => '404 Not Found'
95
            );
96
            print 'Checkout wasn\'t found .. Nothing to renew..';
97
            exit 0;
98
        }
99
100
        my $itemtype
101
            = (C4::Context->preference('item-level_itypes'))
102
            ? $biblio->{'itype'}
103
            : $biblio->{'itemtype'};
104
105
        my $now = DateTime->now(time_zone => C4::Context->tz());
106
        my $borrower = C4::Members::GetMember(borrowernumber => $userId);
107
        unless ($borrower) {
108
            print $query->header(
109
                -type   => 'text/plain',
110
                -status => '404 Not Found'
111
            );
112
            print 'User wasn\'t found ..';
113
            exit 0;
114
        }
115
116
        my $maxDateDue
117
            = C4::Circulation::CalcDateDue($now, $itemtype, $issueBranchCode,
118
            $borrower, 'is a renewal');
119
120
        $dateDue = Koha::DateUtils::dt_from_string($dateDue);
121
        $dateDue->set_hour(23);
122
        $dateDue->set_minute(59);
123
        if ($dateDue > $maxDateDue) {
124
            $dateDue = $maxDateDue;
125
        }    # Here is the restriction done ..
126
127
    }
128
    my ($okay, $error)
129
        = C4::Circulation::CanBookBeRenewed($userId, $itemId, '0');
130
131
    my $result;
132
    if ($okay) {
133
        $dateDue = C4::Circulation::AddRenewal($userId, $itemId, $branch,
134
            $dateDue);
135
        $result->{'dateDue'} = Koha::DateUtils::output_pref(
136
            {dt => $dateDue, as_due_date => 1});
137
    } else {
138
        $result->{'error'} = $error;
139
    }
140
141
    print $query->header(-type => 'text/plain', -charset => 'utf-8',);
142
    print to_json($result);
143
144
    exit 0;
145
}
146
147
1;
(-)a/C4/NCIP/RequestItem.pm (+194 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2014 ByWater Solutions
4
#
5
# This file is part of Koha.
6
#
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 3 of the License, or (at your option) any later
10
# version.
11
#
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.
15
#
16
# You should have received a copy of the GNU General Public License along
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
package C4::NCIP::RequestItem;
21
22
use Modern::Perl;
23
24
=head1 NAME
25
26
C4::NCIP::RequestItem - NCIP module for effective processing of RequestItem NCIP service
27
28
=head1 SYNOPSIS
29
30
  use C4::NCIP::RequestItem;
31
32
=head1 DESCRIPTION
33
34
	Info about NCIP and it's services can be found here: http://www.niso.org/workrooms/ncip/resources/
35
36
=cut
37
38
=head1 METHODS
39
40
=head2 requestItem
41
42
	requestItem($cgiInput)
43
44
	Expected input is as e.g. as follows:
45
46
	http://KohaIntranet:8080/cgi-bin/koha/svc/ncip?service=request_item&requestType=Hold&userId=3&itemid=4&pickupExpiryDate=28/03/2015&pickupLocation=DOSP
47
	or
48
	http://KohaIntranet:8080/cgi-bin/koha/svc/ncip?service=request_item&userId=3&bibId=7
49
50
51
	REQUIRED PARAMS:
52
	Param 'service=request_item' tells svc/ncip to forward the query here.
53
	Param 'userId=3' specifies borrowernumber to place Reserve to.
54
	Param 'itemId=4' specifies itemnumber to place Reserve on.
55
		This param can be replaced with 'barcode=1103246'. But still one of these is required.
56
		Or with 'bibId=3' - then it is Bibliographic Level Hold.
57
58
	OPTIONAL PARAMS:
59
	Param 'requestType=Hold' can be either 'Hold' or 'Loan'.
60
	Param 'pickupExpiryDate=28/06/2015' tells until what date is user interested into specified item.
61
	Param 'pickuplocation=DOSP' specifies which branch is user expecting pickup at.
62
63
=cut
64
65
sub requestItem {
66
    my $query  = shift;
67
    my $userId = $query->param('userId');
68
69
    C4::NCIP::NcipUtils::print400($query, "Param userId is undefined..")
70
        unless $userId;
71
72
    my $bibId   = $query->param('bibId');
73
    my $itemId  = $query->param('itemId');
74
    my $barcode = $query->param('barcode');
75
76
    C4::NCIP::NcipUtils::print400($query,
77
        "Cannot process both bibId & itemId/barcode .. you have to choose only one"
78
    ) if $bibId and ($itemId or $barcode);
79
80
    my $itemLevelHold = 1;
81
    unless ($itemId) {
82
        if ($bibId) {
83
            my $canBeReserved
84
                = C4::Reserves::CanBookBeReserved($userId, $bibId);
85
86
            print409($query, "Book cannot be reserved.. $canBeReserved")
87
                unless ($canBeReserved eq 'OK');
88
89
            $itemLevelHold = 0;
90
        } else {
91
            C4::NCIP::NcipUtils::print400($query,
92
                "Param bibId neither any of itemId and barcode is undefined")
93
                unless $barcode;
94
95
            $itemId = C4::Items::GetItemnumberFromBarcode($barcode);
96
        }
97
    }
98
99
    if ($itemLevelHold) {
100
        my $canBeReserved = C4::Reserves::CanItemBeReserved($userId, $itemId);
101
102
        C4::NCIP::NcipUtils::print409($query,
103
            "Item cannot be reserved.. $canBeReserved")
104
            unless $canBeReserved eq 'OK';
105
106
        $bibId = C4::Biblio::GetBiblionumberFromItemnumber($itemId);
107
    }
108
109
# RequestType specifies if user wants the book now or doesn't mind to get into queue
110
    my $requestType = $query->param('requestType');
111
112
    if ($requestType) {
113
        C4::NCIP::NcipUtils::print400($query,
114
            "Param requestType not recognized.. Can be \'Loan\' or \'Hold\'")
115
            if (not $requestType =~ /^Loan$|^Hold$/);
116
    } else {
117
        $requestType = 'Hold';
118
    }
119
120
    # Process rank & whether user hasn't requested this item yet ..
121
    my $reserves = C4::Reserves::GetReservesFromBiblionumber(
122
        {biblionumber => $bibId, itemnumber => $itemId, all_dates => 1});
123
124
    foreach my $res (@$reserves) {
125
        C4::NCIP::NcipUtils::print403($query,
126
            "User already has item requested")
127
            if $res->{borrowernumber} eq $userId;
128
    }
129
130
    my $rank = scalar(@$reserves);
131
132
    C4::NCIP::NcipUtils::print409($query,
133
        "Loan not possible  .. holdqueuelength exists")
134
        if $requestType ne 'Hold' and $rank != 0;
135
136
    my $expirationdate = $query->param('pickupExpiryDate');
137
    my $startdate      = $query->param('earliestDateNeeded');
138
    my $notes          = $query->param('notes') || 'Placed by svc/ncip';
139
    my $pickupLocation = $query->param('pickupLocation')
140
        || C4::Context->userenv->{'branch'};
141
142
    if ($itemLevelHold) {
143
        placeHold(
144
            $query,          $bibId,     $itemId,         $userId,
145
            $pickupLocation, $startdate, $expirationdate, $notes,
146
            ++$rank,         undef
147
        );
148
    } else {
149
        placeHold(
150
            $query,          $bibId,     undef,           $userId,
151
            $pickupLocation, $startdate, $expirationdate, $notes,
152
            ++$rank,         'any'
153
        );
154
    }
155
}
156
157
=head2 placeHold
158
159
	placeHold($inputCGI, $biblionumber, $itemnumber, $borrowernumber, $pickup, $startdate, $expirationdate, $notes, $rank, $requesttype)
160
161
=cut
162
163
sub placeHold {
164
    my ($query,  $bibId,     $itemId,         $userId,
165
        $branch, $startdate, $expirationdate, $notes,
166
        $rank,   $request
167
    ) = @_;
168
169
    my $found;
170
171
    my $userExists = C4::Members::GetBorrowerCategorycode($userId);
172
173
    C4::NCIP::NcipUtils::print404($query, "User not found..")
174
        unless $userExists;
175
176
    my $reserveId = C4::Reserves::AddReserve(
177
        $branch, $userId, $bibId,     'a',
178
        undef,   $rank,   $startdate, $expirationdate,
179
        $notes,  undef,   $itemId,    $found
180
    );
181
182
    my $results;
183
184
    $results->{'status'}    = 'reserved';
185
    $results->{'bibId'}     = $bibId;
186
    $results->{'userId'}    = $userId;
187
    $results->{'requestId'} = $reserveId;
188
189
    $results->{'itemId'} = $itemId if $itemId;
190
191
    C4::NCIP::NcipUtils::printJson($query, $results);
192
}
193
194
1;
(-)a/C4/Reserves.pm (-1 / +52 lines)
Lines 100-108 BEGIN { Link Here
100
        &GetReservesFromItemnumber
100
        &GetReservesFromItemnumber
101
        &GetReservesFromBiblionumber
101
        &GetReservesFromBiblionumber
102
        &GetReservesFromBorrowernumber
102
        &GetReservesFromBorrowernumber
103
	&GetReserveFromBorrowernumberAndItemnumber
103
        &GetReservesForBranch
104
        &GetReservesForBranch
104
        &GetReservesToBranch
105
        &GetReservesToBranch
105
        &GetReserveCount
106
        &GetReserveCount
107
        &GetReserveCountFromItemnumber
106
        &GetReserveFee
108
        &GetReserveFee
107
        &GetReserveInfo
109
        &GetReserveInfo
108
        &GetReserveStatus
110
        &GetReserveStatus
Lines 241-247 sub AddReserve { Link Here
241
    }
243
    }
242
244
243
    #}
245
    #}
244
    ($const eq "o" || $const eq "e") or return;   # FIXME: why not have a useful return value?
246
    ($const eq "o" || $const eq "e") or return $reserve_id;
245
    $query = qq{
247
    $query = qq{
246
        INSERT INTO reserveconstraints
248
        INSERT INTO reserveconstraints
247
            (borrowernumber,biblionumber,reservedate,biblioitemnumber)
249
            (borrowernumber,biblionumber,reservedate,biblioitemnumber)
Lines 450-455 sub GetReservesFromBorrowernumber { Link Here
450
    my $data = $sth->fetchall_arrayref({});
452
    my $data = $sth->fetchall_arrayref({});
451
    return @$data;
453
    return @$data;
452
}
454
}
455
456
=head2 GetReserveFromBorrowernumberAndItemnumber
457
458
    $reserve = GetReserveFromBorrowernumberAndItemnumber($borrowernumber, $itemnumber);
459
460
Returns matching reserve of borrower on an item specified.
461
462
=cut
463
464
sub GetReserveFromBorrowernumberAndItemnumber {
465
    my ($borrowernumber, $itemnumber) = @_;
466
    my $dbh    = C4::Context->dbh;
467
    my $sth;
468
    $sth = $dbh->prepare("
469
                SELECT *
470
                FROM reserves
471
                WHERE borrowernumber=?
472
                AND itemnumber =?
473
                ");
474
    $sth->execute($borrowernumber, $itemnumber);
475
476
    return ${$sth->fetchall_arrayref({})}[0];
477
478
}
479
453
#-------------------------------------------------------------------------------------
480
#-------------------------------------------------------------------------------------
454
=head2 CanBookBeReserved
481
=head2 CanBookBeReserved
455
482
Lines 656-661 sub GetReserveCount { Link Here
656
    return $row->{counter};
683
    return $row->{counter};
657
}
684
}
658
685
686
=head2 GetReserveCountFromItemnumber
687
688
  $number = &GetReserveCountFromItemnumber($itemnumber);
689
690
this function returns the number of reservation for an itemnumber given on input arg.
691
692
=cut
693
694
695
sub GetReserveCountFromItemnumber {
696
    my ($itemnumber) = @_;
697
698
    my $dbh = C4::Context->dbh;
699
700
    my $sth = $dbh->prepare("
701
        SELECT COUNT(*) AS counter
702
        FROM reserves
703
        WHERE itemnumber = ?");
704
705
    $sth->execute($itemnumber);
706
707
    return $sth->fetchrow_hashref->{counter};
708
}
709
659
=head2 GetOtherReserves
710
=head2 GetOtherReserves
660
711
661
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
712
  ($messages,$nextreservinfo)=$GetOtherReserves(itemnumber);
(-)a/svc/ncip (-1 / +78 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2007 LibLime
4
# Copyright 2012 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
22
use strict;
23
use warnings;
24
25
use CGI qw ( -utf8 );
26
use C4::Auth qw/check_api_auth/;
27
28
use C4::NCIP::LookupItem qw/lookupItem/;
29
use C4::NCIP::LookupItemSet qw/lookupItemSet/;
30
use C4::NCIP::LookupUser qw/lookupUser/;
31
use C4::NCIP::LookupRequest qw/lookupRequest/;
32
use C4::NCIP::RequestItem qw/requestItem/;
33
use C4::NCIP::RenewItem qw/renewItem/;
34
use C4::NCIP::CancelRequestItem qw/cancelRequestItem/;
35
36
my $query = new CGI;
37
binmode STDOUT, ':encoding(UTF-8)';
38
39
my ($status, undef, undef)
40
    = check_api_auth($query, {editcatalogue => 'edit_catalogue'});
41
42
C4::NCIP::NcipUtils::print403($query, $status)
43
    unless ($status eq "ok");
44
45
# do initial validation
46
47
if ($query->request_method eq "GET") {
48
    my $service = $query->param('service');
49
50
    C4::NCIP::NcipUtils::print400($query, "Param service is undefined..")
51
        unless $service;
52
53
    if ($service eq 'lookup_item') {
54
        C4::NCIP::LookupItem::lookupItem($query);
55
    } elsif ($service eq 'lookup_item_set') {
56
        C4::NCIP::LookupItemSet::lookupItemSet($query);
57
    } elsif ($service eq 'lookup_user') {
58
        C4::NCIP::LookupUser::lookupUser($query);
59
    } elsif ($service eq 'lookup_request') {
60
        C4::NCIP::LookupRequest::lookupRequest($query);
61
    } elsif ($service eq 'request_item') {
62
        C4::NCIP::RequestItem::requestItem($query);
63
    } elsif ($service eq 'renew_item') {
64
        C4::NCIP::RenewItem::renewItem($query);
65
    } elsif ($service eq 'cancel_request_item') {
66
        C4::NCIP::CancelRequestItem::cancelRequestItem($query);
67
    } else {
68
        C4::NCIP::NcipUtils::print400($query,
69
            "Param service not recognized..");
70
    }
71
} else {
72
    print $query->header(
73
        -type   => 'text/plain',
74
        -status => '405 Method Not Allowed'
75
        ),
76
        'Only GET method is allowed..';
77
    exit 0;
78
}

Return to bug 13930