syncing dev-week and HEAD
[koha.git] / opac / opac-serial-issues.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Koha;
7 use C4::Date;
8 use C4::Bull;
9 use C4::Letters;
10 use C4::Output;
11 use C4::Interface::CGI::Output;
12 use C4::Context;
13 use HTML::Template;
14
15 my $query = new CGI;
16 my $op = $query->param('op');
17 my $dbh = C4::Context->dbh;
18 my $selectview = $query->param('selectview');
19 $selectview = C4::Context->preference("SubscriptionHistory") unless $selectview;
20
21 my $sth;
22 # my $id;
23 my ($template, $loggedinuser, $cookie);
24 my $biblionumber = $query->param('biblionumber');
25 if ($selectview eq "full"){
26         my $subscriptions = get_full_subscription_list_from_biblionumber($biblionumber);
27         
28         # now, check is there is an alert subscription for one of the subscriptions
29         foreach (@$subscriptions) {
30                 if (getalert($loggedinuser,'issue',$_->{subscriptionid})) {
31                         warn "SUBSCRIPTION FOR : $loggedinuser,'issue',$_->{subscriptionid}";
32                 }
33         }
34         my $title = $subscriptions->[0]{bibliotitle};
35         my $yearmin=$subscriptions->[0]{year};
36         my $yearmax=$subscriptions->[scalar(@$subscriptions)-1]{year};
37         
38         
39         ($template, $loggedinuser, $cookie)
40         = get_template_and_user({template_name => "opac-full-serial-issues.tmpl",
41                                         query => $query,
42                                         type => "opac",
43                                         authnotrequired => 1,
44                                         debug => 1,
45                                         });
46         
47         # replace CR by <br> in librarian note
48         # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;
49         
50         $template->param(
51                 biblionumber => $query->param('biblionumber'),
52                 years => $subscriptions,
53                 yearmin => $yearmin,
54                 yearmax =>$yearmax,
55                 bibliotitle => $title,
56                 suggestion => C4::Context->preference("suggestion"),
57                 virtualshelves => C4::Context->preference("virtualshelves"),
58                 );
59
60 } else {
61         my $subscriptions = get_subscription_list_from_biblionumber($biblionumber);
62         
63         # now, check is there is an alert subscription for one of the subscriptions
64         foreach (@$subscriptions) {
65                 if (getalert($loggedinuser,'issue',$_->{subscriptionid})) {
66                         $_->{hasalert} = 1;
67                 }
68         }
69         
70         ($template, $loggedinuser, $cookie)
71         = get_template_and_user({template_name => "opac-serial-issues.tmpl",
72                                         query => $query,
73                                         type => "opac",
74                                         authnotrequired => 1,
75                                         debug => 1,
76                                         });
77         
78         # replace CR by <br> in librarian note
79         # $subscription->{opacnote} =~ s/\n/\<br\/\>/g;
80         
81         $template->param(
82                 biblionumber => $query->param('biblionumber'),
83                 subscription_LOOP => $subscriptions,
84                 suggestion => C4::Context->preference("suggestion"),
85                 virtualshelves => C4::Context->preference("virtualshelves"),
86                 );
87 }
88 output_html_with_http_headers $query, $cookie, $template->output;