(MT4068) Display callnumber & location in serials-collection.pl & serials-edit.pl.
[koha-equinox.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 use List::MoreUtils qw/uniq/;
32
33
34 my $query = new CGI;
35 my $op = $query->param('op') || q{};
36 my $dbh = C4::Context->dbh;
37
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 => 'receive_serials'},
45                             debug => 1,
46                             });
47 my $biblionumber = $query->param('biblionumber');
48 my @subscriptionid = $query->param('subscriptionid');
49
50 @subscriptionid= uniq @subscriptionid;
51 my $subscriptiondescs;
52 my $subscriptions;
53
54 if($op eq 'gennext' && @subscriptionid){
55     my $subscriptionid = $subscriptionid[0];
56     my $subscription = GetSubscription($subscriptionid);
57
58         my $sth = $dbh->prepare("SELECT publisheddate, serialid, serialseq, planneddate
59                                                         FROM serial WHERE status = 1 AND subscriptionid = ?");
60         $sth->execute($subscriptionid);
61
62         # modify actual expected issue, to generate the next
63         if ( my $issue = $sth->fetchrow_hashref ) {
64                 ModSerialStatus( $issue->{serialid}, $issue->{serialseq},
65                 $issue->{planneddate}, $issue->{publisheddate},
66                 3, "" );
67         }else{
68                 my $expected = GetNextExpected($subscriptionid);
69             my (
70                  $newserialseq,  $newlastvalue1, $newlastvalue2, $newlastvalue3,
71              $newinnerloop1, $newinnerloop2, $newinnerloop3
72             ) = GetNextSeq($subscription);
73
74              ## We generate the next publication date
75              my $nextpublisheddate = GetNextDate( $expected->{planneddate}->output('iso'), $subscription );
76              ## Creating the new issue
77              NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
78                      1, $nextpublisheddate, $nextpublisheddate );
79
80              ## Updating the subscription seq status
81              my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?
82                          WHERE  subscriptionid = ?";
83              $sth = $dbh->prepare($squery);
84              $sth->execute(
85                  $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1,
86                  $newinnerloop2, $newinnerloop3, $subscriptionid
87                  );
88
89         }
90
91     print $query->redirect('/cgi-bin/koha/serials/serials-collection.pl?subscriptionid='.$subscriptionid);
92 }
93
94 my ($location, $callnumber);
95 if (@subscriptionid){
96    my @subscriptioninformation=();
97    foreach my $subscriptionid (@subscriptionid){
98     my $subs= GetSubscription($subscriptionid);
99     $subs->{opacnote}     =~ s/\n/\<br\/\>/g;
100     $subs->{missinglist}  =~ s/\n/\<br\/\>/g;
101     $subs->{recievedlist} =~ s/\n/\<br\/\>/g;
102     ##these are display information
103     $subs->{ "periodicity" . $subs->{periodicity} } = 1;
104     $subs->{ "numberpattern" . $subs->{numberpattern} } = 1;
105     $subs->{ "status" . $subs->{'status'} } = 1;
106     $subs->{startdate}     = format_date( $subs->{startdate} );
107     $subs->{histstartdate} = format_date( $subs->{histstartdate} );
108     if ( !defined $subs->{enddate} || $subs->{enddate} eq '0000-00-00' ) {
109         $subs->{enddate} = '';
110     }
111     else {
112         $subs->{enddate} = format_date( $subs->{enddate} );
113     }
114     $subs->{'abouttoexpire'}=abouttoexpire($subs->{'subscriptionid'});
115     $subs->{'subscriptionexpired'}=HasSubscriptionExpired($subs->{'subscriptionid'});
116     $subs->{'subscriptionid'} = $subscriptionid;  # FIXME - why was this lost ?
117         $location = GetAuthorisedValues('LOC', $subs->{'location'});
118         $callnumber = $subs->{callnumber};
119     push @$subscriptiondescs,$subs;
120     my $tmpsubscription= GetFullSubscription($subscriptionid);
121     @subscriptioninformation=(@$tmpsubscription,@subscriptioninformation);
122   }
123   $subscriptions=PrepareSerialsData(\@subscriptioninformation);
124 } else {
125   $subscriptiondescs = GetSubscriptionsFromBiblionumber($biblionumber) ;
126   my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber);
127   $subscriptions=PrepareSerialsData($subscriptioninformation);
128 }
129
130 my $title = $subscriptiondescs->[0]{bibliotitle};
131 my $yearmax=($subscriptions->[0]{year} eq "manage" && scalar(@$subscriptions)>1)? $subscriptions->[1]{year} :$subscriptions->[0]{year};
132 my $yearmin=$subscriptions->[scalar(@$subscriptions)-1]{year};
133 my $subscriptionidlist="";
134 foreach my $subscription (@$subscriptiondescs){
135   $subscriptionidlist.=$subscription->{'subscriptionid'}."," ;
136   $biblionumber = $subscription->{'bibnum'} unless ($biblionumber);
137 }
138
139 # warn "title : $title yearmax : $yearmax nombre d'elements dans le tableau :".scalar(@$subscriptions);
140 #  use Data::Dumper; warn Dumper($subscriptions);
141 my $locationlib;
142 foreach (@$location) {
143     $locationlib = $_->{'lib'} if $_->{'selected'};
144 }
145
146 chop $subscriptionidlist;
147 $template->param(
148           onesubscription => (scalar(@$subscriptiondescs)==1),
149           subscriptionidlist => $subscriptionidlist,
150           biblionumber => $biblionumber,
151           subscriptions => $subscriptiondescs,
152           years => $subscriptions,
153           yearmin => $yearmin,
154           yearmax =>$yearmax,
155           bibliotitle => $title,
156           suggestion => C4::Context->preference("suggestion"),
157           virtualshelves => C4::Context->preference("virtualshelves"),
158           subscr=>$query->param('subscriptionid'),
159     location           => $locationlib,
160     callnumber         => $callnumber,
161           );
162
163 output_html_with_http_headers $query, $cookie, $template->output;