serials : lot of bugfixes.
[wip/koha-chris_n.git] / bull / statecollection.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Date;
7 use C4::Output;
8 use C4::Interface::CGI::Output;
9 use C4::Context;
10 use C4::Bull;
11 use HTML::Template;
12
13 my $query = new CGI;
14 my $op = $query->param('op');
15 my $dbh = C4::Context->dbh;
16 my $subscriptionid = $query->param('subscriptionid');
17 my $auser = $query->param('user');
18 my $histstartdate = format_date_in_iso($query->param('histstartdate'));
19 my $enddate = format_date_in_iso($query->param('enddate'));
20 my $recievedlist = $query->param('recievedlist');
21 my $missinglist = $query->param('missinglist');
22 my $opacnote = $query->param('opacnote');
23 my $librariannote = $query->param('librariannote');
24 my @serialids = $query->param('serialid');
25 my @serialseqs = $query->param('serialseq');
26 my @planneddates = $query->param('planneddate');
27 my @status = $query->param('status');
28 my $hassubscriptionexpired = hassubscriptionexpired($subscriptionid);
29 if ($op eq 'modsubscriptionhistory') {
30         modsubscriptionhistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
31 }
32 # change status except, if subscription has expired, for the "waited" issue.
33 if ($op eq 'serialchangestatus') {
34         my $sth = $dbh->prepare("select subscriptionid,status from serial where serialid=?");
35         for (my $i=0;$i<=$#serialids;$i++) {
36                 $sth->execute($serialids[$i]);
37                 my ($x,$oldstatus) = $sth->fetchrow;
38                 serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i]) unless ($hassubscriptionexpired && $oldstatus == 1);
39         }
40 }
41 my $subs = &getsubscription($subscriptionid);
42 my @serialslist = getserials($subscriptionid);
43
44 my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
45 $sth->execute($subscriptionid);
46 my $solhistory = $sth->fetchrow_hashref;
47 my ($template, $loggedinuser, $cookie)
48 = get_template_and_user({template_name => "bull/statecollection.tmpl",
49                                 query => $query,
50                                 type => "intranet",
51                                 authnotrequired => 0,
52                                 flagsrequired => {catalogue => 1},
53                                 debug => 1,
54                                 });
55
56         $template->param(
57                         serialslist => \@serialslist,
58                         histstartdate => format_date($solhistory->{'histstartdate'}),
59                         enddate => format_date($solhistory->{'enddate'}),
60                         recievedlist => $solhistory->{'recievedlist'},
61                         missinglist => $solhistory->{'missinglist'},
62                         opacnote => $solhistory->{'opacnote'},
63                         librariannote => $solhistory->{'librariannote'},
64                         subscriptionid => $subscriptionid,
65                         bibliotitle => $subs->{bibliotitle},
66                         hassubscriptionexpired =>$hassubscriptionexpired,
67                 );
68 output_html_with_http_headers $query, $cookie, $template->output;