Merge branch 'bug_7688' into 3.12-master
[koha.git] / serials / subscription-history.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 BibLibre SARL
4 # This file is part of Koha.
5 #
6 # Koha is free software; you can redistribute it and/or modify it under the
7 # terms of the GNU General Public License as published by the Free Software
8 # Foundation; either version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Koha; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 =head1 NAME
20
21 subscription-history.pl
22
23 =head1 DESCRIPTION
24
25 Modify subscription history
26
27 =cut
28
29 use Modern::Perl;
30
31 use CGI;
32 use C4::Auth;
33 use C4::Output;
34
35 use C4::Biblio;
36 use C4::Dates qw(format_date_in_iso);
37 use C4::Serials;
38
39 my $input = new CGI;
40 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
41     template_name   => 'serials/subscription-history.tt',
42     query           => $input,
43     type            => 'intranet',
44     authnotrequired => 0,
45     flagsrequired   => { 'serials' => 'edit_subscription' },
46     debug           => 1,
47 } );
48
49 my $subscriptionid  = $input->param('subscriptionid');
50 my $op              = $input->param('op');
51
52 if(!defined $subscriptionid || $subscriptionid eq '') {
53     print $input->redirect('/cgi-bin/koha/serials/serials-home.pl');
54     exit;
55 }
56
57 if($op && $op eq 'mod') {
58     my $histstartdate   = $input->param('histstartdate');
59     my $histenddate     = $input->param('histenddate');
60     my $receivedlist    = $input->param('receivedlist');
61     my $missinglist     = $input->param('missinglist');
62     my $opacnote        = $input->param('opacnote');
63     my $librariannote   = $input->param('librariannote');
64
65     ModSubscriptionHistory( $subscriptionid, format_date_in_iso($histstartdate),
66         format_date_in_iso($histenddate), $receivedlist, $missinglist, $opacnote,
67         $librariannote );
68
69     print $input->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
70     exit;
71 } else {
72     my $history = GetSubscriptionHistoryFromSubscriptionId($subscriptionid);
73     my (undef, $biblio) = GetBiblio($history->{'biblionumber'});
74
75     $template->param(
76         subscriptionid  => $subscriptionid,
77         title           => $biblio->{'title'},
78         histstartdate   => $history->{'histstartdate'},
79         histenddate     => $history->{'histenddate'},
80         receivedlist    => $history->{'recievedlist'},
81         missinglist     => $history->{'missinglist'},
82         opacnote        => $history->{'opacnote'},
83         librariannote   => $history->{'librariannote'},
84     );
85
86     output_html_with_http_headers $input, $cookie, $template->output;
87 }