cataloge subdir (and cataloguing) - Dates.pm integration and warnings fixes.
[koha.git] / serials / subscription-detail.pl
blobc1c465deec18a7eed15c47765df12c7f6baea2d9
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;
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);
37 $subs->{enddate} = GetExpirationDate($subscriptionid);
39 if ($op eq 'del') {
40 if ($subs->{'cannotedit'}){
41 warn "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");
44 &DelSubscription($subscriptionid);
45 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
46 exit;
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...)
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 });
62 my ($user, $sessionID, $flags);
63 ($user, $cookie, $sessionID, $flags)
64 = checkauth($query, 0, {catalogue => 1}, "intranet");
66 my $weekarrayjs='';
67 my $count = 0;
68 my ($year, $month, $day) = Today;
69 my $firstday = Day_of_Year($year,$month,$day);
70 my ($wkno,$yr) = Week_of_Year($year,$month,$day); # week starting monday
71 my $weekno = $wkno;
72 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
73 $count = $i;
74 if($wkno > 52){$year++; $wkno=1;}
75 if($count>365){$count=$i-365;}
76 my ($y,$m,$d) = Add_Delta_Days($year,1,1, $count - 1);#Date_NthDayOfYear($year,$count);
77 my $output = "$y-$m-$d";
78 $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
79 $wkno++;
81 chop($weekarrayjs);
83 # COMMENT hdl : IMHO, we should think about passing more and more data hash to template->param rather than duplicating code a new coding Guideline ?
85 $subs->{startdate} = format_date($subs->{startdate});
86 $subs->{firstacquidate} = format_date($subs->{firstacquidate});
87 $subs->{histstartdate} = format_date($subs->{histstartdate});
88 $subs->{enddate} = format_date($subs->{enddate});
89 $subs->{abouttoexpire} = abouttoexpire($subs->{subscriptionid});
90 # Done in Serials.pm
91 # $subs->{'donotedit'}=(C4::Context->preference('IndependantBranches') &&
92 # C4::Context->userenv &&
93 # C4::Context->userenv->{flags} !=1 &&
94 # C4::Context->userenv->{branch} && $subs->{branchcode} &&
95 # (C4::Context->userenv->{branch} ne $subs->{branchcode}));
97 $template->param($subs);
99 $template->param(
100 routing => $routing,
101 serialslist => \@serialslist,
102 totalissues => $totalissues,
103 hemisphere => $hemisphere,
105 $template->param(
106 "periodicity".($subs->{periodicity}?$subs->{periodicity}:'0') => 1,
107 "arrival".$subs->{dow} => 1,
108 "numberpattern".$subs->{numberpattern} => 1,
109 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
110 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
113 output_html_with_http_headers $query, $cookie, $template->output;