Cherry-picked onto master, fixing conflicts: MT 1816: Granular permissions for the...
[wip/koha-chris_n.git] / serials / statecollection.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
19 use strict;
20 use warnings;
21 use CGI;
22 use C4::Auth;
23 use C4::Dates qw/format_date format_date_in_iso/;
24 use C4::Output;
25 use C4::Context;
26 use C4::Serials;
27
28 my $query = new CGI;
29 my $op = $query->param('op') || q{};
30 my $dbh = C4::Context->dbh;
31 my $subscriptionid = $query->param('subscriptionid');
32 my $auser = $query->param('user');
33 my $histstartdate = format_date_in_iso($query->param('histstartdate'));
34 my $enddate = format_date_in_iso($query->param('enddate'));
35 my $recievedlist = $query->param('recievedlist');
36 my $missinglist = $query->param('missinglist');
37 my $opacnote = $query->param('opacnote');
38 my $librariannote = $query->param('librariannote');
39 my @serialids = $query->param('serialid');
40 my @serialseqs = $query->param('serialseq');
41 my @planneddates = $query->param('planneddate');
42 my @notes = $query->param('notes');
43 my @status = $query->param('status');
44
45 my ($template, $loggedinuser, $cookie)
46 = get_template_and_user({template_name => "serials/statecollection.tmpl",
47                                 query => $query,
48                                 type => "intranet",
49                                 authnotrequired => 0,
50                                 flagsrequired => {serials => '*'},
51                                 debug => 1,
52                                 });
53
54 my $HasSubscriptionExpired = HasSubscriptionExpired($subscriptionid);
55 my $subscription=GetSubscription($subscriptionid);
56 if ($op eq 'modsubscriptionhistory') {
57         modsubscriptionhistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
58 }
59 # change status except, if subscription has expired, for the "waited" issue.
60 if ($op eq 'serialchangestatus') {
61         my $sth = $dbh->prepare("select status from serial where serialid=?");
62         for (my $i=0;$i<=$#serialids;$i++) {
63                 $sth->execute($serialids[$i]);
64                 my ($oldstatus) = $sth->fetchrow;
65                 if ($serialids[$i]) {
66                         serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($HasSubscriptionExpired && $oldstatus == 1);
67                 } else {
68                         # add a special issue
69                         if ($serialseqs[$i]) {
70                                 my $sub=getsubscription($subscriptionid);
71                                 newissue($serialseqs[$i],$subscriptionid,$sub->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i]));
72                         }
73                 }
74         }
75 }
76 my $subs = &GetSubscription($subscriptionid);
77 my ($totalissues,@serialslist) = GetSerials($subscriptionid,10);
78
79 my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
80 $sth->execute($subscriptionid);
81 my $solhistory = $sth->fetchrow_hashref;
82
83         $template->param(
84                         serialslist => \@serialslist,
85                         biblionumber => $subscription->{biblionumber},
86                         histstartdate => format_date($solhistory->{'histstartdate'}),
87                         enddate => format_date($solhistory->{'enddate'}),
88                         recievedlist => $solhistory->{'recievedlist'},
89                         missinglist => $solhistory->{'missinglist'},
90                         opacnote => $solhistory->{'opacnote'},
91                         librariannote => $solhistory->{'librariannote'},
92                         subscriptionid => $subscriptionid,
93                         bibliotitle => $subs->{bibliotitle},
94                         biblionumber => $subs->{biblionumber},
95                         hassubscriptionexpired =>$HasSubscriptionExpired,
96                 );
97 output_html_with_http_headers $query, $cookie, $template->output;