Intranet po file 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 # Permission needed if it is a deletion (del) : delete_subscription
54 # Permission needed otherwise : *
55 my $permission = ($op eq "del") ? "delete_subscription" : "*";
56
57 ($template, $loggedinuser, $cookie)
58 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
59                 query => $query,
60                 type => "intranet",
61                 authnotrequired => 0,
62                 flagsrequired => {serials => $permission},
63                 debug => 1,
64                 });
65
66 my ($user, $sessionID, $flags);
67 ($user, $cookie, $sessionID, $flags)
68     = checkauth($query, 0, {catalogue => 1}, "intranet");
69
70 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
71
72 $subs->{startdate}      = format_date($subs->{startdate});
73 $subs->{firstacquidate} = format_date($subs->{firstacquidate});
74 $subs->{histstartdate}  = format_date($subs->{histstartdate});
75 $subs->{enddate}        = format_date($subs->{enddate});
76 $subs->{histenddate}    = format_date($subs->{histenddate});
77 $subs->{abouttoexpire}  = abouttoexpire($subs->{subscriptionid});
78 # Done in Serials.pm
79 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') && 
80 #         C4::Context->userenv && 
81 #         C4::Context->userenv->{flags} !=1  && 
82 #         C4::Context->userenv->{branch} && $subs->{branchcode} &&
83 #         (C4::Context->userenv->{branch} ne $subs->{branchcode}));
84
85 $template->param($subs);
86 $template->param(biblionumber_for_new_subscription => $subs->{bibnum});
87 my @irregular_issues = split /,/, $subs->{irregularity};
88
89 if (! $subs->{numberpattern}) {
90     $subs->{numberpattern} = q{};
91 }
92 if (! $subs->{dow}) {
93     $subs->{dow} = q{};
94 }
95 if (! $subs->{periodicity}) {
96     $subs->{periodicity} = '0';
97 }
98 $template->param(
99         subscriptionid => $subscriptionid,
100     routing => $routing,
101     serialslist => \@serialslist,
102     totalissues => $totalissues,
103     hemisphere => $hemisphere,
104     cannotedit =>(C4::Context->preference('IndependantBranches') &&
105                 C4::Context->userenv &&
106                 C4::Context->userenv->{flags} % 2 !=1  &&
107                 C4::Context->userenv->{branch} && $subs->{branchcode} &&
108                 (C4::Context->userenv->{branch} ne $subs->{branchcode})),
109     'periodicity' . $subs->{periodicity} => 1,
110     'arrival' . $subs->{dow} => 1,
111     'numberpattern' . $subs->{numberpattern} => 1,
112     intranetstylesheet => C4::Context->preference('intranetstylesheet'),
113     intranetcolorstylesheet => C4::Context->preference('intranetcolorstylesheet'),
114     irregular_issues => scalar @irregular_issues,
115     );
116
117 output_html_with_http_headers $query, $cookie, $template->output;