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>.
31 use List
::MoreUtils qw
/uniq/;
35 my $op = $query->param('op') || q{};
36 my $nbissues=$query->param('nbissues');
37 my $dbh = C4
::Context
->dbh;
39 my ($template, $loggedinuser, $cookie)
40 = get_template_and_user
({template_name
=> "serials/serials-collection.tt",
44 flagsrequired
=> {serials
=> '*'},
47 my $biblionumber = $query->param('biblionumber');
48 my @subscriptionid = $query->multi_param('subscriptionid');
50 @subscriptionid= uniq
@subscriptionid;
51 @subscriptionid= sort @subscriptionid;
52 my $subscriptiondescs;
55 if($op eq 'gennext' && @subscriptionid){
56 my $subscriptionid = $subscriptionid[0];
57 my $sth = $dbh->prepare("
58 SELECT publisheddate, publisheddatetext, serialid, serialseq,
61 WHERE status = 1 AND subscriptionid = ?
63 my $status = defined( $nbissues ) ?
2 : 3;
65 for ( my $i = 0; $i < $nbissues; $i++ ){
66 $sth->execute($subscriptionid);
67 # modify actual expected issue, to generate the next
68 if ( my $issue = $sth->fetchrow_hashref ) {
69 ModSerialStatus
( $issue->{serialid
}, $issue->{serialseq
},
70 $issue->{planneddate
}, $issue->{publisheddate
},
71 $issue->{publisheddatetext
}, $status, "" );
73 require C4
::Serials
::Numberpattern
;
74 my $subscription = GetSubscription
($subscriptionid);
75 my $pattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subscription->{numberpattern
});
76 my $expected = GetNextExpected
($subscriptionid);
78 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
79 $newinnerloop1, $newinnerloop2, $newinnerloop3
80 ) = GetNextSeq
($subscription, $pattern, $expected->{publisheddate
});
82 ## We generate the next publication date
83 my $nextpublisheddate = GetNextDate
($subscription, $expected->{publisheddate
}, 1);
84 ## Creating the new issue
85 NewIssue
( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
86 1, $nextpublisheddate, $nextpublisheddate );
88 ## Updating the subscription seq status
89 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
90 WHERE subscriptionid = ?";
91 my $seqsth = $dbh->prepare($squery);
93 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
94 $newinnerloop2, $newinnerloop3, $subscriptionid
98 last if $nbissues == 1;
99 last if HasSubscriptionExpired
($subscriptionid) > 0;
101 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
104 my $subscriptioncount;
105 my ($location, $callnumber);
106 if (@subscriptionid){
107 my @subscriptioninformation=();
109 foreach my $subscriptionid (@subscriptionid){
110 my $subs= GetSubscription
($subscriptionid);
111 $closed = 1 if $subs->{closed
};
113 $subs->{opacnote
} =~ s/\n/\<br\/\
>/g
;
114 $subs->{missinglist
} =~ s/\n/\<br\/\
>/g
;
115 $subs->{recievedlist
} =~ s/\n/\<br\/\
>/g
;
117 ##these are display information
118 $subs->{'abouttoexpire'}=abouttoexpire
($subs->{'subscriptionid'});
119 $subs->{'subscriptionexpired'}=HasSubscriptionExpired
($subs->{'subscriptionid'});
120 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
121 $location = $subs->{'location'};
122 $callnumber = $subs->{callnumber
};
123 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
124 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
125 $subs->{frequency
} = $frequency;
126 $subs->{numberpattern
} = $numberpattern;
127 $subs->{'hasRouting'} = check_routing
($subscriptionid);
128 push @
$subscriptiondescs,$subs;
129 my $tmpsubscription= GetFullSubscription
($subscriptionid);
130 @subscriptioninformation=(@
$tmpsubscription,@subscriptioninformation);
132 $template->param(closed
=> $closed);
133 $subscriptions=PrepareSerialsData
(\
@subscriptioninformation);
134 $subscriptioncount = CountSubscriptionFromBiblionumber
($subscriptiondescs->[0]{'biblionumber'});
136 $subscriptiondescs = GetSubscriptionsFromBiblionumber
($biblionumber);
137 foreach my $s (@
$subscriptiondescs) {
138 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($s->{periodicity
});
139 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($s->{numberpattern
});
140 $s->{frequency
} = $frequency;
141 $s->{numberpattern
} = $numberpattern;
143 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber
($biblionumber);
144 $subscriptions=PrepareSerialsData
($subscriptioninformation);
147 my $title = $subscriptiondescs->[0]{bibliotitle
};
148 my $yearmax=($subscriptions->[0]{year
} eq "manage" && scalar(@
$subscriptions)>1)?
$subscriptions->[1]{year
} :$subscriptions->[0]{year
};
149 my $yearmin=$subscriptions->[scalar(@
$subscriptions)-1]{year
};
150 my $subscriptionidlist="";
151 foreach my $subscription (@
$subscriptiondescs){
152 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
153 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
154 $subscription->{'hasRouting'} = check_routing
($subscription->{'subscriptionid'});
157 chop $subscriptionidlist;
159 subscriptionidlist
=> $subscriptionidlist,
160 biblionumber
=> $biblionumber,
161 subscriptions
=> $subscriptiondescs,
162 years
=> $subscriptions,
165 bibliotitle
=> $title,
166 suggestion
=> C4
::Context
->preference("suggestion"),
167 virtualshelves
=> C4
::Context
->preference("virtualshelves"),
168 routing
=> C4
::Context
->preference("RoutingSerials"),
169 subscr
=>scalar $query->param('subscriptionid'),
170 subscriptioncount
=> $subscriptioncount,
171 location
=> $location,
172 callnumber
=> $callnumber,
173 uc(C4
::Context
->preference("marcflavour")) => 1,
174 serialsadditems
=> $subscriptiondescs->[0]{'serialsadditems'},
177 output_html_with_http_headers
$query, $cookie, $template->output;