Bug 19805: Add DataTables to Koha to MARC mapping page
[koha.git] / serials / serials-collection.pl
blobe9cb3fd8b89884289593d50cb157ef3d4326c717
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Parts Copyright 2010 Biblibre
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use strict;
23 use warnings;
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;
32 use List::MoreUtils qw/uniq/;
35 my $query = new CGI;
36 my $op = $query->param('op') || q{};
37 my $nbissues=$query->param('nbissues');
38 my $dbh = C4::Context->dbh;
40 my ($template, $loggedinuser, $cookie)
41 = get_template_and_user({template_name => "serials/serials-collection.tt",
42 query => $query,
43 type => "intranet",
44 authnotrequired => 0,
45 flagsrequired => {serials => '*'},
46 debug => 1,
47 });
48 my $biblionumber = $query->param('biblionumber');
49 my @subscriptionid = $query->multi_param('subscriptionid');
51 @subscriptionid= uniq @subscriptionid;
52 @subscriptionid= sort @subscriptionid;
53 my $subscriptiondescs;
54 my $subscriptions;
56 if($op eq 'gennext' && @subscriptionid){
57 my $subscriptionid = $subscriptionid[0];
58 my $sth = $dbh->prepare("
59 SELECT publisheddate, publisheddatetext, serialid, serialseq,
60 planneddate
61 FROM serial
62 WHERE status = 1 AND subscriptionid = ?
63 ");
64 my $status = defined( $nbissues ) ? 2 : 3;
65 $nbissues ||= 1;
66 for ( my $i = 0; $i < $nbissues; $i++ ){
67 $sth->execute($subscriptionid);
68 # modify actual expected issue, to generate the next
69 if ( my $issue = $sth->fetchrow_hashref ) {
70 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
71 $issue->{planneddate}, $issue->{publisheddate},
72 $issue->{publisheddatetext}, $status, "" );
73 } else {
74 require C4::Serials::Numberpattern;
75 my $subscription = GetSubscription($subscriptionid);
76 my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern});
77 my $expected = GetNextExpected($subscriptionid);
78 my (
79 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
80 $newinnerloop1, $newinnerloop2, $newinnerloop3
81 ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate});
83 ## We generate the next publication date
84 my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
85 ## Creating the new issue
86 NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
87 1, $nextpublisheddate, $nextpublisheddate );
89 ## Updating the subscription seq status
90 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
91 WHERE subscriptionid = ?";
92 my $seqsth = $dbh->prepare($squery);
93 $seqsth->execute(
94 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
95 $newinnerloop2, $newinnerloop3, $subscriptionid
99 last if $nbissues == 1;
100 last if HasSubscriptionExpired($subscriptionid) > 0;
102 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
105 my $subscriptioncount;
106 my ($location, $callnumber);
107 if (@subscriptionid){
108 my @subscriptioninformation=();
109 my $closed = 0;
110 foreach my $subscriptionid (@subscriptionid){
111 my $subs= GetSubscription($subscriptionid);
112 $closed = 1 if $subs->{closed};
114 $subs->{opacnote} =~ s/\n/\<br\/\>/g;
115 $subs->{missinglist} =~ s/\n/\<br\/\>/g;
116 $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
118 ##these are display information
119 $subs->{'abouttoexpire'}=abouttoexpire($subs->{'subscriptionid'});
120 $subs->{'subscriptionexpired'}=HasSubscriptionExpired($subs->{'subscriptionid'});
121 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
122 $location = $subs->{'location'};
123 $callnumber = $subs->{callnumber};
124 my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity});
125 my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern});
126 $subs->{frequency} = $frequency;
127 $subs->{numberpattern} = $numberpattern;
128 $subs->{'hasRouting'} = check_routing($subscriptionid);
129 push @$subscriptiondescs,$subs;
130 my $tmpsubscription= GetFullSubscription($subscriptionid);
131 @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
133 $template->param(closed => $closed);
134 $subscriptions=PrepareSerialsData(\@subscriptioninformation);
135 $subscriptioncount = CountSubscriptionFromBiblionumber($subscriptiondescs->[0]{'biblionumber'});
136 } else {
137 $subscriptiondescs = GetSubscriptionsFromBiblionumber($biblionumber);
138 foreach my $s (@$subscriptiondescs) {
139 my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($s->{periodicity});
140 my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($s->{numberpattern});
141 $s->{frequency} = $frequency;
142 $s->{numberpattern} = $numberpattern;
144 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber);
145 $subscriptions=PrepareSerialsData($subscriptioninformation);
148 my $title = $subscriptiondescs->[0]{bibliotitle};
149 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1)? $subscriptions->[1]{year} :$subscriptions->[0]{year};
150 my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
151 my $subscriptionidlist="";
152 foreach my $subscription (@$subscriptiondescs){
153 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
154 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
155 $subscription->{'hasRouting'} = check_routing($subscription->{'subscriptionid'});
158 chop $subscriptionidlist;
159 $template->param(
160 subscriptionidlist => $subscriptionidlist,
161 biblionumber => $biblionumber,
162 subscriptions => $subscriptiondescs,
163 years => $subscriptions,
164 yearmin => $yearmin,
165 yearmax =>$yearmax,
166 bibliotitle => $title,
167 suggestion => C4::Context->preference("suggestion"),
168 virtualshelves => C4::Context->preference("virtualshelves"),
169 routing => C4::Context->preference("RoutingSerials"),
170 subscr=>scalar $query->param('subscriptionid'),
171 subscriptioncount => $subscriptioncount,
172 location => $location,
173 callnumber => $callnumber,
174 uc(C4::Context->preference("marcflavour")) => 1,
175 serialsadditems => $subscriptiondescs->[0]{'serialsadditems'},
178 output_html_with_http_headers $query, $cookie, $template->output;