3 # This file is part of Koha.
5 # Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use C4::Auth qw( get_template_and_user );
23 use C4::Output qw( output_html_with_http_headers );
27 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
29 template_name => "opac-recall.tt",
36 my $op = $query->param('op') || '';
37 my $biblionumber = $query->param('biblionumber');
38 my $biblio = Koha::Biblios->find( $biblionumber );
40 if ( C4::Context->preference('UseRecalls') ) {
42 my $patron = Koha::Patrons->find( $borrowernumber );
45 unless ( $biblio->can_be_recalled({ patron => $patron }) ) { $error = 'unavailable'; }
47 my $items = Koha::Items->search({ biblionumber => $biblionumber });
49 # check if already recalled
50 my $recalled = scalar $biblio->recalls;
51 if ( defined $recalled and $recalled > 0 ) {
52 my $recalls_per_record = Koha::CirculationRules->get_effective_rule({
53 categorycode => $patron->categorycode,
56 rule_name => 'recalls_per_record'
58 if ( defined $recalls_per_record and $recalls_per_record->rule_value and $recalled >= $recalls_per_record->rule_value ){
63 # submitting recall request
64 if ($op eq 'request'){
66 if ( defined $error and $error eq 'unavailable' ){
67 # no items available for recall
68 print $query->redirect("/cgi-bin/koha/opac-recall.pl?biblionumber=$biblionumber&error=unavailable");
70 } elsif ( !defined $error ){
73 my $level = $query->param('type');
74 my $pickuploc = $query->param('pickup');
75 my $expdate = $query->param('expirationdate');
76 my $itemnumber = $query->param('itemnumber');
78 my ( $recall, $due_interval, $due_date );
79 if ( $level eq 'itemlevel' and defined $itemnumber ) {
80 my $item = Koha::Items->find( $itemnumber );
81 if ( $item->can_be_recalled({ patron => $patron }) ) {
82 ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
85 branchcode => $pickuploc,
87 expirationdate => $expdate,
94 if ( $biblio->can_be_recalled({ patron => $patron }) ) {
95 ( $recall, $due_interval, $due_date ) = Koha::Recalls->add_recall({
98 branchcode => $pickuploc,
99 expirationdate => $expdate,
106 if ( defined $recall ) {
109 due_interval => $due_interval,
110 due_date => $due_date,
116 } elsif ($op eq 'cancel'){
117 my $recall_id = $query->param('recall_id');
118 Koha::Recalls->find( $recall_id )->set_cancelled;
119 print $query->redirect('/cgi-bin/koha/opac-user.pl');
122 my $branches = Koha::Libraries->search();
123 my $single_branch_mode = $branches->count == 1;
129 single_branch_mode => $single_branch_mode,
130 branches => $branches,
134 # UseRecalls disabled
141 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };