quell warning if format parameter isn't passed to opac-search.pl
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20
21 use strict;
22 use CGI;
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Dates qw/format_date/;
26 use C4::Serials;
27 use C4::Letters;
28 use C4::Output;
29 use C4::Context;
30
31
32 my $query = new CGI;
33 my $op = $query->param('op');
34 my $dbh = C4::Context->dbh;
35
36 my $sth;
37 # my $id;
38 my ($template, $loggedinuser, $cookie);
39 ($template, $loggedinuser, $cookie)
40   = get_template_and_user({template_name => "serials/serials-collection.tmpl",
41                             query => $query,
42                             type => "intranet",
43                             authnotrequired => 0,
44                             flagsrequired => {serials => 1},
45                             debug => 1,
46                             });
47 my $biblionumber = $query->param('biblionumber');
48 my @subscriptionid = $query->param('subscriptionid');
49
50 my $subscriptiondescs ;
51 my $subscriptions;
52
53 if($op eq "gennext" && @subscriptionid){
54     my $subscriptionid = @subscriptionid[0];
55     my $subscription = GetSubscription($subscriptionid);
56
57         my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate 
58                                                         FROM serial WHERE status = 1 AND subscriptionid = ?");
59         $sth->execute($subscriptionid);
60
61         # modify actual expected issue, to generate the next
62         if ( my $issue = $sth->fetchrow_hashref ) {
63                 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
64                 $issue->{planneddate}, $issue->{publisheddate},
65                 3, "Automatically set to late" );
66         }else{
67                 my $expected = GetNextExpected($subscriptionid);
68             my (
69                  $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
70              $newinnerloop1, $newinnerloop2, $newinnerloop3
71             ) = GetNextSeq($subscription);
72         
73              ## We generate the next publication date    
74              my $nextpublisheddate = GetNextDate( $expected->{planneddate}->output('iso'), $subscription );
75              ## Creating the new issue
76              NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
77                      1, $nextpublisheddate, $nextpublisheddate );
78                      
79              ## Updating the subscription seq status
80              my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
81                          WHERE  subscriptionid = ?";
82              $sth = $dbh->prepare($squery);
83              $sth->execute(
84                  $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
85                  $newinnerloop2, $newinnerloop3, $subscriptionid
86                  );
87
88         }
89
90     print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
91 }
92
93 if (@subscriptionid){
94    my @subscriptioninformation=();
95    foreach my $subscriptionid (@subscriptionid){
96     my $subs= GetSubscription($subscriptionid);
97     $subs->{opacnote}     =~ s/\n/\<br\/\>/g;
98     $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
99     $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
100     ##these are display information
101     $subs->{ "periodicity" . $subs->{periodicity} } = 1;
102     $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
103     $subs->{ "status" . $subs->{'status'} } = 1;
104     $subs->{startdate}     = format_date( $subs->{startdate} );
105     $subs->{histstartdate} = format_date( $subs->{histstartdate} );
106     if ( $subs->{enddate} eq '0000-00-00' ) {
107         $subs->{enddate} = '';
108     }
109     else {
110         $subs->{enddate} = format_date( $subs->{enddate} );
111     }
112     $subs->{'abouttoexpire'}=abouttoexpire($subs->{'subscriptionid'});
113     $subs->{'subscriptionexpired'}=HasSubscriptionExpired($subs->{'subscriptionid'});
114     $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
115     push @$subscriptiondescs,$subs;
116     my $tmpsubscription= GetFullSubscription($subscriptionid);
117     @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
118   }
119   $subscriptions=PrepareSerialsData(\@subscriptioninformation);
120 } else {
121   $subscriptiondescs = GetSubscriptionsFromBiblionumber($biblionumber) ;
122   my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber);
123   $subscriptions=PrepareSerialsData($subscriptioninformation);
124 }
125
126 my $title = $subscriptiondescs->[0]{bibliotitle};
127 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1)? $subscriptions->[1]{year} :$subscriptions->[0]{year};
128 my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
129 my $subscriptionidlist="";
130 foreach my $subscription (@$subscriptiondescs){
131   $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
132   $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
133 }
134
135 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
136 #  use Data::Dumper; warn Dumper($subscriptions);
137 chop $subscriptionidlist;
138 $template->param(
139           onesubscription => (scalar(@$subscriptiondescs)==1),
140           subscriptionidlist => $subscriptionidlist,
141           biblionumber => $biblionumber,
142           subscriptions => $subscriptiondescs,
143           years => $subscriptions,
144           yearmin => $yearmin,
145           yearmax =>$yearmax,
146           bibliotitle => $title,
147           suggestion => C4::Context->preference("suggestion"),
148           virtualshelves => C4::Context->preference("virtualshelves"),
149           subscr=>$query->param('subscriptionid'),
150           );
151
152 output_html_with_http_headers $query, $cookie, $template->output;