fix "Add Tag" button in MARC framework editor
[koha.git] / serials / subscription-detail.pl
blob6d4d202030fe0de2f37430248e7548e5a25cfc25
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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
18 use strict;
19 use CGI;
20 use C4::Auth;
21 use C4::Koha;
22 use C4::Dates qw/format_date/;
23 use C4::Serials;
24 use C4::Output;
25 use C4::Context;
26 use Date::Calc qw/Today Day_of_Year Week_of_Year Add_Delta_Days/;
27 #use Date::Manip;
29 my $query = new CGI;
30 my $op = $query->param('op');
31 my $dbh = C4::Context->dbh;
32 my $sth;
33 # my $id;
34 my ($template, $loggedinuser, $cookie, $hemisphere);
35 my $subscriptionid = $query->param('subscriptionid');
36 my $subs = &GetSubscription($subscriptionid);
38 $subs->{enddate} = GetExpirationDate($subscriptionid);
40 if ($op eq 'del') {
41 if ($subs->{'cannotedit'}){
42 warn "Attempt to delete subscription $subscriptionid by ".C4::Context->userenv->{'id'}." not allowed";
43 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
45 &DelSubscription($subscriptionid);
46 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
47 exit;
49 my ($routing, @routinglist) = getroutinglist($subscriptionid);
50 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
51 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
52 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
54 ($template, $loggedinuser, $cookie)
55 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
56 query => $query,
57 type => "intranet",
58 authnotrequired => 0,
59 flagsrequired => {serials => 1},
60 debug => 1,
61 });
63 my ($user, $sessionID, $flags);
64 ($user, $cookie, $sessionID, $flags)
65 = checkauth($query, 0, {catalogue => 1}, "intranet");
67 my $weekarrayjs='';
68 my $count = 0;
69 my ($year, $month, $day) = Today;
70 my $firstday = Day_of_Year($year,$month,$day);
71 my ($wkno,$yr) = Week_of_Year($year,$month,$day); # week starting monday
72 my $weekno = $wkno;
73 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
74 $count = $i;
75 if($wkno > 52){$year++; $wkno=1;}
76 if($count>365){$count=$i-365;}
77 my ($y,$m,$d) = Add_Delta_Days($year,1,1, $count - 1);#Date_NthDayOfYear($year,$count);
78 # padding Add_Delta_Days;
79 my $output = sprintf("%04d-%02d-%02d",$y , $m, $d );
80 $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
81 $wkno++;
83 chop($weekarrayjs);
85 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
87 $subs->{startdate} = format_date($subs->{startdate});
88 $subs->{firstacquidate} = format_date($subs->{firstacquidate});
89 $subs->{histstartdate} = format_date($subs->{histstartdate});
90 $subs->{enddate} = format_date($subs->{enddate});
91 $subs->{histenddate} = format_date($subs->{histenddate});
92 $subs->{abouttoexpire} = abouttoexpire($subs->{subscriptionid});
93 # Done in Serials.pm
94 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') &&
95 # C4::Context->userenv &&
96 # C4::Context->userenv->{flags} !=1 &&
97 # C4::Context->userenv->{branch} && $subs->{branchcode} &&
98 # (C4::Context->userenv->{branch} ne $subs->{branchcode}));
100 $template->param($subs);
102 $template->param(
103 subscriptionid => $subscriptionid,
104 routing => $routing,
105 serialslist => \@serialslist,
106 totalissues => $totalissues,
107 hemisphere => $hemisphere,
108 cannotedit =>(C4::Context->preference('IndependantBranches') &&
109 C4::Context->userenv &&
110 C4::Context->userenv->{flags} !=1 &&
111 C4::Context->userenv->{branch} && $subs->{branchcode} &&
112 (C4::Context->userenv->{branch} ne $subs->{branchcode})),
114 $template->param(
115 "periodicity".($subs->{periodicity}?$subs->{periodicity}:'0') => 1,
116 "arrival".$subs->{dow} => 1,
117 "numberpattern".$subs->{numberpattern} => 1,
118 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
119 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
122 output_html_with_http_headers $query, $cookie, $template->output;