MT3421: Moves subscription history in a separate page
[koha.git] / serials / subscription-history.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 use strict;
19 use CGI;
20 use Date::Calc qw(Today Day_of_Year Week_of_Year Add_Delta_Days);
21 use C4::Koha;
22 use C4::Biblio;
23 use C4::Auth;
24 use C4::Dates qw/format_date format_date_in_iso/;
25 use C4::Acquisition;
26 use C4::Output;
27 use C4::Context;
28 use C4::Branch; # GetBranches
29 use C4::Serials;
30 use C4::Letters;
31
32 #use Smart::Comments;
33
34 my $query = new CGI;
35 my $dbh = C4::Context->dbh;
36
37 my ($template, $loggedinuser, $cookie)
38 = get_template_and_user({template_name => "serials/subscription-history.tmpl",
39                                 query => $query,
40                                 type => "intranet",
41                                 authnotrequired => 0,
42                                 flagsrequired => {serials => 'edit_subscription'},
43                                 debug => 1,
44                                 });
45
46     my $subscriptionid = $query->param('subscriptionid');
47     my $modhistory = $query->param('modhistory');
48     my $subs = &GetSubscription($subscriptionid);
49
50 ## FIXME : Check rights to edit if mod. Could/Should display an error message.
51     if ($subs->{'cannotedit'}){
52       warn "Attempt to modify subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
53       print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
54     }
55
56
57   for (qw(startdate firstacquidate histstartdate enddate histenddate)) {
58         # TODO : Handle date formats properly.
59          if ($subs->{$_} eq '0000-00-00') {
60             $subs->{$_} = ''
61         } else {
62             $subs->{$_} = format_date($subs->{$_});
63         }   
64           } 
65
66
67         $template->param($subs);
68         $template->param(
69                     history => ($subs->{manualhistory} == 1 ),
70                     );
71
72
73     if ($modhistory) {
74         my $histstartdate = format_date_in_iso($query->param('histstartdate'));
75         my $histenddate = format_date_in_iso($query->param('histenddate'));
76         my $recievedlist = $query->param('recievedlist');
77         my $missinglist = $query->param('missinglist');
78         my $opacnote = $query->param('opacnote');
79         my $librariannote = $query->param('librariannote');
80         my $return = ModSubscriptionHistory ($subscriptionid,$histstartdate,$histenddate,$recievedlist,$missinglist,$opacnote,$librariannote);
81         $template->param(success => 1) if ($return == 1);
82     } 
83
84         output_html_with_http_headers $query, $cookie, $template->output;