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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4
::Dates qw
/format_date/;
32 use List
::MoreUtils qw
/uniq/;
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 ($template, $loggedinuser, $cookie)
42 = get_template_and_user
({template_name
=> "serials/serials-collection.tmpl",
46 flagsrequired
=> {serials
=> '*'},
49 my $biblionumber = $query->param('biblionumber');
50 my @subscriptionid = $query->param('subscriptionid');
52 @subscriptionid= uniq
@subscriptionid;
53 @subscriptionid= sort @subscriptionid;
54 my $subscriptiondescs;
57 if($op eq 'gennext' && @subscriptionid){
58 my $subscriptionid = $subscriptionid[0];
59 my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
60 FROM serial WHERE status = 1 AND subscriptionid = ?");
61 my $status = defined( $nbissues ) ?
2 : 3;
63 for ( my $i = 0; $i < $nbissues; $i++ ){
64 $sth->execute($subscriptionid);
65 # modify actual expected issue, to generate the next
66 if ( my $issue = $sth->fetchrow_hashref ) {
67 ModSerialStatus
( $issue->{serialid
}, $issue->{serialseq
},
68 $issue->{planneddate
}, $issue->{publisheddate
},
71 require C4
::Serials
::Numberpattern
;
72 my $subscription = GetSubscription
($subscriptionid);
73 my $pattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subscription->{numberpattern
});
74 my $expected = GetNextExpected
($subscriptionid);
76 $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3,
77 $newinnerloop1, $newinnerloop2, $newinnerloop3
78 ) = GetNextSeq
($subscription, $pattern, $expected->{publisheddate
});
80 ## We generate the next publication date
81 my $nextpublisheddate = GetNextDate
($subscription, $expected->{publisheddate
}, 1);
82 ## Creating the new issue
83 NewIssue
( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
84 1, $nextpublisheddate, $nextpublisheddate );
86 ## Updating the subscription seq status
87 my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
88 WHERE subscriptionid = ?";
89 my $seqsth = $dbh->prepare($squery);
91 $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
92 $newinnerloop2, $newinnerloop3, $subscriptionid
96 last if $nbissues == 1;
97 last if HasSubscriptionExpired
($subscriptionid) > 0;
99 print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
102 my $subscriptioncount;
103 my ($location, $callnumber);
104 if (@subscriptionid){
105 my @subscriptioninformation=();
107 foreach my $subscriptionid (@subscriptionid){
108 my $subs= GetSubscription
($subscriptionid);
109 $closed = 1 if $subs->{closed
};
110 $subs->{opacnote
} =~ s/\n/\<br\/\
>/g
;
111 $subs->{missinglist
} =~ s/\n/\<br\/\
>/g
;
112 $subs->{recievedlist
} =~ s/\n/\<br\/\
>/g
;
113 ##these are display information
114 $subs->{startdate
} = format_date
( $subs->{startdate
} );
115 $subs->{histstartdate
} = format_date
( $subs->{histstartdate
} );
116 if ( !defined $subs->{enddate
} || $subs->{enddate
} eq '0000-00-00' ) {
117 $subs->{enddate
} = '';
120 $subs->{enddate
} = format_date
( $subs->{enddate
} );
122 $subs->{'abouttoexpire'}=abouttoexpire
($subs->{'subscriptionid'});
123 $subs->{'subscriptionexpired'}=HasSubscriptionExpired
($subs->{'subscriptionid'});
124 $subs->{'subscriptionid'} = $subscriptionid; # FIXME - why was this lost ?
125 $location = GetAuthorisedValues
('LOC', $subs->{'location'});
126 $callnumber = $subs->{callnumber
};
127 my $frequency = C4
::Serials
::Frequency
::GetSubscriptionFrequency
($subs->{periodicity
});
128 my $numberpattern = C4
::Serials
::Numberpattern
::GetSubscriptionNumberpattern
($subs->{numberpattern
});
129 $subs->{frequency
} = $frequency;
130 $subs->{numberpattern
} = $numberpattern;
131 push @
$subscriptiondescs,$subs;
132 my $tmpsubscription= GetFullSubscription
($subscriptionid);
133 @subscriptioninformation=(@
$tmpsubscription,@subscriptioninformation);
135 $template->param(closed
=> $closed);
136 $subscriptions=PrepareSerialsData
(\
@subscriptioninformation);
137 $subscriptioncount = CountSubscriptionFromBiblionumber
($subscriptiondescs->[0]{'biblionumber'});
139 $subscriptiondescs = GetSubscriptionsFromBiblionumber
($biblionumber) ;
140 my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber
($biblionumber);
141 $subscriptions=PrepareSerialsData
($subscriptioninformation);
144 my $title = $subscriptiondescs->[0]{bibliotitle
};
145 my $yearmax=($subscriptions->[0]{year
} eq "manage" && scalar(@
$subscriptions)>1)?
$subscriptions->[1]{year
} :$subscriptions->[0]{year
};
146 my $yearmin=$subscriptions->[scalar(@
$subscriptions)-1]{year
};
147 my $subscriptionidlist="";
148 foreach my $subscription (@
$subscriptiondescs){
149 $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
150 $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
153 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
154 # use Data::Dumper; warn Dumper($subscriptions);
156 foreach (@
$location) {
157 $locationlib = $_->{'lib'} if $_->{'selected'};
161 chop $subscriptionidlist;
163 subscriptionidlist
=> $subscriptionidlist,
164 biblionumber
=> $biblionumber,
165 subscriptions
=> $subscriptiondescs,
166 years
=> $subscriptions,
169 bibliotitle
=> $title,
170 suggestion
=> C4
::Context
->preference("suggestion"),
171 virtualshelves
=> C4
::Context
->preference("virtualshelves"),
172 routing
=> C4
::Context
->preference("RoutingSerials"),
173 subscr
=>$query->param('subscriptionid'),
174 subscriptioncount
=> $subscriptioncount,
175 location
=> $locationlib,
176 callnumber
=> $callnumber,
177 uc(C4
::Context
->preference("marcflavour")) => 1,
178 serialsadditems
=> $subscriptiondescs->[0]{'serialsadditems'},
181 output_html_with_http_headers
$query, $cookie, $template->output;