Bug 10357: Adding link for email notification for new subscription issues to opac...
[koha.git] / opac / opac-serial-issues.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 strict;
22 use warnings;
23
24 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Koha;
27 use C4::Serials;
28 use C4::Letters;
29 use C4::Output;
30 use C4::Context;
31
32 my $query      = new CGI;
33 my $op         = $query->param('op');
34 my $dbh        = C4::Context->dbh;
35 my $selectview = $query->param('selectview');
36 $selectview = C4::Context->preference("SubscriptionHistory") unless $selectview;
37
38 my $sth;
39
40 # my $id;
41 my ( $template, $loggedinuser, $cookie );
42 my $biblionumber = $query->param('biblionumber');
43 if ( $selectview eq "full" ) {
44     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45         {
46             template_name   => "opac-full-serial-issues.tt",
47             query           => $query,
48             type            => "opac",
49             authnotrequired => 1,
50             debug           => 1,
51         }
52     );
53     my $subscriptions = GetFullSubscriptionsFromBiblionumber($biblionumber);
54     my $subscriptioninformation=PrepareSerialsData($subscriptions);
55     # PrepareSerialsData does some bogus stuff that the template could handle
56     # But at least it sorts the array by the year field so we dont have to
57     # find 'manage' if its there
58     if ($subscriptioninformation->[0]->{year} eq 'manage') {
59         shift @{$subscriptioninformation};
60     }
61
62     # now, check is there is an alert subscription for one of the subscriptions
63     if ($loggedinuser) {
64         foreach (@$subscriptions) {
65             my $sub = getalert($loggedinuser,'issue_ser',$_->{subscriptionid});
66             if (!defined $sub) {
67                 $sub = getalert($loggedinuser,'issue_det',$_->{subscriptionid});
68             }
69             if ($sub) {
70                 $_->{hasalert} = 1;
71             }
72         }
73     }
74
75     my $title   = $subscriptions->[0]->{bibliotitle};
76     my $yearmin = $subscriptions->[0]->{year};
77     my $yearmax = $subscriptions->[ -1 ]->{year};
78
79     # replace CR by <br> in librarian note
80     # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;
81
82     $template->param(
83         biblionumber   => scalar $query->param('biblionumber'),
84         years          => $subscriptioninformation,
85         yearmin        => $yearmin,
86         yearmax        => $yearmax,
87         bibliotitle    => $title,
88         suggestion     => C4::Context->preference("suggestion"),
89         virtualshelves => C4::Context->preference("virtualshelves"),
90     );
91
92 }
93 else {
94     ( $template, $loggedinuser, $cookie ) = get_template_and_user(
95         {
96             template_name   => "opac-serial-issues.tt",
97             query           => $query,
98             type            => "opac",
99             authnotrequired => 1,
100             debug           => 1,
101         }
102     );
103
104     my $subscriptions = GetSubscriptionsFromBiblionumber($biblionumber);
105     # now, check is there is an alert subscription for one of the subscriptions
106     if ($loggedinuser){
107         foreach (@$subscriptions) {
108             my $subscription = getalert($loggedinuser,'issue_ser',$_->{subscriptionid});
109             if (!defined $subscription) {
110                 $subscription = getalert($loggedinuser,'issue_det',$_->{subscriptionid});
111             }
112             if (@$subscription[0]) {
113                 $_->{hasalert} = 1;
114             }
115         }
116     }
117
118     # replace CR by <br> in librarian note
119     # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;
120
121     my $title   = $subscriptions->[0]->{bibliotitle};
122
123     $template->param(
124         biblionumber      => scalar $query->param('biblionumber'),
125         subscription_LOOP => $subscriptions,
126         bibliotitle        => $title,
127     );
128 }
129 output_html_with_http_headers $query, $cookie, $template->output;