Bug 36349: Fix AutoSelfCheckAllowed
[koha.git] / opac / opac-alert-subscribe.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21 use CGI qw ( -utf8 );
22 use C4::Auth qw( get_template_and_user );
23 use C4::Output qw( output_html_with_http_headers );
24 use C4::Context;
25 use C4::Serials qw( GetSubscription );
26
27 my $query = CGI->new;
28 my $op    = $query->param('op') || '';
29 my $dbh   = C4::Context->dbh;
30
31 my ( $template, $loggedinuser, $cookie );
32 my $subscriptionid = $query->param('subscriptionid');
33 my $referer        = $query->param('referer') || 'detail';
34 my $biblionumber   = $query->param('biblionumber');
35
36 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
37     {
38         template_name   => "opac-alert-subscribe.tt",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 0,                           # user must be logged in to request
42                                                         # subscription notifications
43     }
44 );
45
46 my $subscription     = Koha::Subscriptions->find($subscriptionid);
47 my $logged_in_patron = Koha::Patrons->find($loggedinuser);
48
49 if ( $op eq 'cud-alert_confirmed' ) {
50     $subscription->add_subscriber($logged_in_patron);
51     if ( $referer eq 'serial' ) {
52         print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
53         exit;
54     } else {
55         print $query->redirect("opac-detail.pl?biblionumber=$biblionumber");
56         exit;
57     }
58 } elsif ( $op eq 'cud-cancel_confirmed' ) {
59     $subscription->remove_subscriber($logged_in_patron);
60     warn "CANCEL confirmed : $loggedinuser, $subscriptionid";
61     if ( $referer eq 'serial' ) {
62         print $query->redirect("opac-serial-issues.pl?biblionumber=$biblionumber");
63         exit;
64     } elsif ( $referer eq 'patron' ) {
65         print $query->redirect("/cgi-bin/koha/opac-alert-subscriptions.pl");
66     } else {
67         print $query->redirect("opac-detail.pl?biblionumber=$biblionumber");
68         exit;
69     }
70
71 } else {
72     my $subscription = &GetSubscription($subscriptionid);
73     $template->param(
74         referer        => $referer,
75         "typeissue$op" => 1,
76         bibliotitle    => $subscription->{bibliotitle},
77         notes          => $subscription->{notes},
78         subscriptionid => $subscriptionid,
79         biblionumber   => $biblionumber,
80     );
81 }
82 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };