Bug 16522: (follow-up) MARC display templates and get_marc_host fixes
[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
21 use Modern::Perl;
22 use CGI qw ( -utf8 );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Context;
26 use C4::Serials qw( GetSubscription );
27
28
29 my $query = CGI->new;
30 my $op    = $query->param('op') || '';
31 my $dbh   = C4::Context->dbh;
32
33 my ( $template, $loggedinuser, $cookie );
34 my $subscriptionid = $query->param('subscriptionid');
35 my $referer      = $query->param('referer') || 'detail';
36 my $biblionumber = $query->param('biblionumber');
37
38 ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39     {
40         template_name   => "opac-alert-subscribe.tt",
41         query           => $query,
42         type            => "opac",
43         authnotrequired => 0, # user must logged in to request
44                               # subscription notifications
45     }
46 );
47
48 my $subscription = Koha::Subscriptions->find( $subscriptionid );
49 my $logged_in_patron = Koha::Patrons->find( $loggedinuser );
50
51 if ( $op eq 'alert_confirmed' ) {
52     $subscription->add_subscriber( $logged_in_patron );
53     if ( $referer eq 'serial' ) {
54         print $query->redirect(
55             "opac-serial-issues.pl?biblionumber=$biblionumber");
56         exit;
57     } else {
58         print $query->redirect(
59             "opac-detail.pl?biblionumber=$biblionumber");
60         exit;
61     }
62 }
63 elsif ( $op eq 'cancel_confirmed' ) {
64     $subscription->remove_subscriber( $logged_in_patron );
65     warn "CANCEL confirmed : $loggedinuser, $subscriptionid";
66     if ( $referer eq 'serial' ) {
67         print $query->redirect(
68             "opac-serial-issues.pl?biblionumber=$biblionumber");
69         exit;
70     } else {
71         print $query->redirect(
72             "opac-detail.pl?biblionumber=$biblionumber");
73         exit;
74     }
75
76
77 }
78 else {
79     my $subscription = &GetSubscription($subscriptionid);
80     $template->param(
81         referer        => $referer,
82         "typeissue$op" => 1,
83         bibliotitle    => $subscription->{bibliotitle},
84         notes          => $subscription->{notes},
85         subscriptionid     => $subscriptionid,
86         biblionumber   => $biblionumber,
87     );
88 }
89 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };