Bug 5128 [3.2] Unimarc default for holdings. Written with French default
[koha.git] / serials / serials-collection.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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
21 use strict;
22 use warnings;
23 use CGI;
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Dates qw/format_date/;
27 use C4::Serials;
28 use C4::Letters;
29 use C4::Output;
30 use C4::Context;
31
32
33 my $query = new CGI;
34 my $op = $query->param('op') || q{};
35 my $dbh = C4::Context->dbh;
36
37 my ($template, $loggedinuser, $cookie);
38 ($template, $loggedinuser, $cookie)
39   = get_template_and_user({template_name => "serials/serials-collection.tmpl",
40                             query => $query,
41                             type => "intranet",
42                             authnotrequired => 0,
43                             flagsrequired => {serials => 'receive_serials'},
44                             debug => 1,
45                             });
46 my $biblionumber = $query->param('biblionumber');
47 my @subscriptionid = $query->param('subscriptionid');
48
49 my $subscriptiondescs ;
50 my $subscriptions;
51
52 if($op eq 'gennext' && @subscriptionid){
53     my $subscriptionid = $subscriptionid[0];
54     my $subscription = GetSubscription($subscriptionid);
55
56         my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
57                                                         FROM serial WHERE status = 1 AND subscriptionid = ?");
58         $sth->execute($subscriptionid);
59
60         # modify actual expected issue, to generate the next
61         if ( my $issue = $sth->fetchrow_hashref ) {
62                 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
63                 $issue->{planneddate}, $issue->{publisheddate},
64                 3, "" );
65         }else{
66                 my $expected = GetNextExpected($subscriptionid);
67             my (
68                  $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
69              $newinnerloop1, $newinnerloop2, $newinnerloop3
70             ) = GetNextSeq($subscription);
71
72              ## We generate the next publication date
73              my $nextpublisheddate = GetNextDate( $expected->{planneddate}->output('iso'), $subscription );
74              ## Creating the new issue
75              NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
76                      1, $nextpublisheddate, $nextpublisheddate );
77
78              ## Updating the subscription seq status
79              my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
80                          WHERE  subscriptionid = ?";
81              $sth = $dbh->prepare($squery);
82              $sth->execute(
83                  $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
84                  $newinnerloop2, $newinnerloop3, $subscriptionid
85                  );
86
87         }
88
89     print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
90 }
91
92 if (@subscriptionid){
93    my @subscriptioninformation=();
94    foreach my $subscriptionid (@subscriptionid){
95     my $subs= GetSubscription($subscriptionid);
96     $subs->{opacnote}     =~ s/\n/\<br\/\>/g;
97     $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
98     $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
99     ##these are display information
100     $subs->{ "periodicity" . $subs->{periodicity} } = 1;
101     $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
102     $subs->{ "status" . $subs->{'status'} } = 1;
103     $subs->{startdate}     = format_date( $subs->{startdate} );
104     $subs->{histstartdate} = format_date( $subs->{histstartdate} );
105     if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
106         $subs->{enddate} = '';
107     }
108     else {
109         $subs->{enddate} = format_date( $subs->{enddate} );
110     }
111     $subs->{'abouttoexpire'}=abouttoexpire($subs->{'subscriptionid'});
112     $subs->{'subscriptionexpired'}=HasSubscriptionExpired($subs->{'subscriptionid'});
113     $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
114     push @$subscriptiondescs,$subs;
115     my $tmpsubscription= GetFullSubscription($subscriptionid);
116     @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
117   }
118   $subscriptions=PrepareSerialsData(\@subscriptioninformation);
119 } else {
120   $subscriptiondescs = GetSubscriptionsFromBiblionumber($biblionumber) ;
121   my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber);
122   $subscriptions=PrepareSerialsData($subscriptioninformation);
123 }
124
125 my $title = $subscriptiondescs->[0]{bibliotitle};
126 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1)? $subscriptions->[1]{year} :$subscriptions->[0]{year};
127 my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
128 my $subscriptionidlist="";
129 foreach my $subscription (@$subscriptiondescs){
130   $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
131   $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
132 }
133
134 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
135 #  use Data::Dumper; warn Dumper($subscriptions);
136 chop $subscriptionidlist;
137 $template->param(
138           onesubscription => (scalar(@$subscriptiondescs)==1),
139           subscriptionidlist => $subscriptionidlist,
140           biblionumber => $biblionumber,
141           subscriptions => $subscriptiondescs,
142           years => $subscriptions,
143           yearmin => $yearmin,
144           yearmax =>$yearmax,
145           bibliotitle => $title,
146           suggestion => C4::Context->preference("suggestion"),
147           virtualshelves => C4::Context->preference("virtualshelves"),
148           subscr=>$query->param('subscriptionid'),
149           );
150
151 output_html_with_http_headers $query, $cookie, $template->output;