moving Reserves2.pm to Reserves.pm
[koha.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 with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 # $Id$
19
20 use strict;
21 use CGI;
22 use C4::Auth;
23 use C4::Date;
24 use C4::Output;
25 use C4::Interface::CGI::Output;
26 use C4::Context;
27 use C4::Serials;
28
29 my $query = new CGI;
30 my $op = $query->param('op');
31 my $dbh = C4::Context->dbh;
32 my $subscriptionid = $query->param('subscriptionid');
33 my $auser = $query->param('user');
34 my $histstartdate = format_date_in_iso($query->param('histstartdate'));
35 my $enddate = format_date_in_iso($query->param('enddate'));
36 my $recievedlist = $query->param('recievedlist');
37 my $missinglist = $query->param('missinglist');
38 my $opacnote = $query->param('opacnote');
39 my $librariannote = $query->param('librariannote');
40 my @serialids = $query->param('serialid');
41 my @serialseqs = $query->param('serialseq');
42 my @planneddates = $query->param('planneddate');
43 my @notes = $query->param('notes');
44 my @status = $query->param('status');
45
46 my ($template, $loggedinuser, $cookie)
47 = get_template_and_user({template_name => "serials/statecollection.tmpl",
48                                 query => $query,
49                                 type => "intranet",
50                                 authnotrequired => 0,
51                                 flagsrequired => {serials => 1},
52                                 debug => 1,
53                                 });
54
55 my $HasSubscriptionExpired = HasSubscriptionExpired($subscriptionid);
56 my $subscription=GetSubscription($subscriptionid);
57 if ($op eq 'modsubscriptionhistory') {
58         modsubscriptionhistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
59 }
60 # change status except, if subscription has expired, for the "waited" issue.
61 if ($op eq 'serialchangestatus') {
62         my $sth = $dbh->prepare("select status from serial where serialid=?");
63         for (my $i=0;$i<=$#serialids;$i++) {
64                 $sth->execute($serialids[$i]);
65                 my ($oldstatus) = $sth->fetchrow;
66                 if ($serialids[$i]) {
67                         serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($HasSubscriptionExpired && $oldstatus == 1);
68                 } else {
69                         # add a special issue
70                         if ($serialseqs[$i]) {
71                                 my $subscription=getsubscription($subscriptionid);
72                                 newissue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i]));
73                         }
74                 }
75         }
76 }
77 my $subs = &GetSubscription($subscriptionid);
78 my ($totalissues,@serialslist) = GetSerials($subscriptionid,10);
79
80 my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?");
81 $sth->execute($subscriptionid);
82 my $solhistory = $sth->fetchrow_hashref;
83
84         $template->param(
85                         serialslist => \@serialslist,
86                         biblionumber => $subscription->{biblionumber},
87                         histstartdate => format_date($solhistory->{'histstartdate'}),
88                         enddate => format_date($solhistory->{'enddate'}),
89                         recievedlist => $solhistory->{'recievedlist'},
90                         missinglist => $solhistory->{'missinglist'},
91                         opacnote => $solhistory->{'opacnote'},
92                         librariannote => $solhistory->{'librariannote'},
93                         subscriptionid => $subscriptionid,
94                         bibliotitle => $subs->{bibliotitle},
95                         biblionumber => $subs->{biblionumber},
96                         hassubscriptionexpired =>$HasSubscriptionExpired,
97                 );
98 output_html_with_http_headers $query, $cookie, $template->output;