Polish, English NZ and German updates
[koha.git] / serials / subscription-detail.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 warnings;
20 use CGI;
21 use C4::Auth;
22 use C4::Koha;
23 use C4::Dates qw/format_date/;
24 use C4::Serials;
25 use C4::Output;
26 use C4::Context;
27 use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
28 use Carp;
29
30 my $query = new CGI;
31 my $op = $query->param('op');
32 my $dbh = C4::Context->dbh;
33 my ($template, $loggedinuser, $cookie, $hemisphere);
34 my $subscriptionid = $query->param('subscriptionid');
35 my $subs = GetSubscription($subscriptionid);
36
37 $subs->{enddate} = GetExpirationDate($subscriptionid);
38
39 if ($op && $op eq 'del') {
40         if ($subs->{'cannotedit'}){
41                 carp "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
42                 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
43         }
44         DelSubscription($subscriptionid);
45         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
46         exit;
47 }
48 my ($routing, @routinglist) = getroutinglist($subscriptionid);
49 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
50 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
51 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
52
53 ($template, $loggedinuser, $cookie)
54 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
55                 query => $query,
56                 type => "intranet",
57                 authnotrequired => 0,
58                 flagsrequired => {serials => 1},
59                 debug => 1,
60                 });
61
62 my ($user, $sessionID, $flags);
63 ($user, $cookie, $sessionID, $flags)
64     = checkauth($query, 0, {catalogue => 1}, "intranet");
65
66 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
67
68 $subs->{startdate}      = format_date($subs->{startdate});
69 $subs->{firstacquidate} = format_date($subs->{firstacquidate});
70 $subs->{histstartdate}  = format_date($subs->{histstartdate});
71 $subs->{enddate}        = format_date($subs->{enddate});
72 $subs->{histenddate}    = format_date($subs->{histenddate});
73 $subs->{abouttoexpire}  = abouttoexpire($subs->{subscriptionid});
74 # Done in Serials.pm
75 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') && 
76 #         C4::Context->userenv && 
77 #         C4::Context->userenv->{flags} !=1  && 
78 #         C4::Context->userenv->{branch} && $subs->{branchcode} &&
79 #         (C4::Context->userenv->{branch} ne $subs->{branchcode}));
80
81 $template->param($subs);
82 $template->param(biblionumber_for_new_subscription => $subs->{bibnum});
83 my @irregular_issues = split /,/, $subs->{irregularity};
84
85 if (! $subs->{numberpattern}) {
86     $subs->{numberpattern} = q{};
87 }
88 if (! $subs->{dow}) {
89     $subs->{dow} = q{};
90 }
91 if (! $subs->{periodicity}) {
92     $subs->{periodicity} = '0';
93 }
94 $template->param(
95         subscriptionid => $subscriptionid,
96     routing => $routing,
97     serialslist => \@serialslist,
98     totalissues => $totalissues,
99     hemisphere => $hemisphere,
100     cannotedit =>(C4::Context->preference('IndependantBranches') &&
101                 C4::Context->userenv &&
102                 C4::Context->userenv->{flags} % 2 !=1  &&
103                 C4::Context->userenv->{branch} && $subs->{branchcode} &&
104                 (C4::Context->userenv->{branch} ne $subs->{branchcode})),
105     'periodicity' . $subs->{periodicity} => 1,
106     'arrival' . $subs->{dow} => 1,
107     'numberpattern' . $subs->{numberpattern} => 1,
108     intranetstylesheet => C4::Context->preference('intranetstylesheet'),
109     intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
110     irregular_issues => scalar @irregular_issues,
111     );
112
113 output_html_with_http_headers $query, $cookie, $template->output;