synch'ing 2.2 and head
[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 status from serial where serialid=?");
35         for (my $i=0;$i<=$#serialids;$i++) {
36                 $sth->execute($serialids[$i]);
37                 my ($oldstatus) = $sth->fetchrow;
38                 if ($serialids[$i]) {
39                         serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i]) unless ($hassubscriptionexpired && $oldstatus == 1);
40                 } else {
41                         # add a special issue
42                         if ($serialseqs[$i]) {
43                                 my $subscription=getsubscription($subscriptionid);
44                                 newissue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i]));
45                         }
46                 }
47         }
48 }
49 my $subs = &getsubscription($subscriptionid);
50 my ($totalissues,@serialslist) = getserials($subscriptionid);
51
52 my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
53 $sth->execute($subscriptionid);
54 my $solhistory = $sth->fetchrow_hashref;
55 my ($template, $loggedinuser, $cookie)
56 = get_template_and_user({template_name => "bull/statecollection.tmpl",
57                                 query => $query,
58                                 type => "intranet",
59                                 authnotrequired => 0,
60                                 flagsrequired => {catalogue => 1},
61                                 debug => 1,
62                                 });
63
64         $template->param(
65                         serialslist => \@serialslist,
66                         histstartdate => format_date($solhistory->{'histstartdate'}),
67                         enddate => format_date($solhistory->{'enddate'}),
68                         recievedlist => $solhistory->{'recievedlist'},
69                         missinglist => $solhistory->{'missinglist'},
70                         opacnote => $solhistory->{'opacnote'},
71                         librariannote => $solhistory->{'librariannote'},
72                         subscriptionid => $subscriptionid,
73                         bibliotitle => $subs->{bibliotitle},
74                         hassubscriptionexpired =>$hassubscriptionexpired,
75                 );
76 output_html_with_http_headers $query, $cookie, $template->output;