leader length checking bugfix : 25 and not 24
[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 CGI;
20 use C4::Auth;
21 use C4::Koha;
22 use C4::Date;
23 use C4::Serials;
24 use C4::Output;
25 use C4::Context;
26 use Date::Manip;
27
28 my $query = new CGI;
29 my $op = $query->param('op');
30 my $dbh = C4::Context->dbh;
31 my $sth;
32 # my $id;
33 my ($template, $loggedinuser, $cookie, $subs);
34 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
35     $firstacquidate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength,
36     $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
37     $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
38     $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
39     $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere,$letter,$manualhistory,$histstartdate,$enddate,$missinglist,$recievedlist,$opacnote,$librariannote);
40
41 $subscriptionid = $query->param('subscriptionid');
42
43
44 if ($op eq 'del') {
45     &DelSubscription($subscriptionid);
46     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=serials-home.pl\"></html>";
47     exit;
48
49 }
50 my $subs = &GetSubscription($subscriptionid);
51 my ($routing, @routinglist) = getroutinglist($subscriptionid);
52 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
53 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
54 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
55
56 ($template, $loggedinuser, $cookie)
57 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
58                 query => $query,
59                 type => "intranet",
60                 authnotrequired => 0,
61                 flagsrequired => {serials => 1},
62                 debug => 1,
63                 });
64
65 my ($user, $cookie, $sessionID, $flags)
66     = checkauth($query, 0, {catalogue => 1}, "intranet");
67
68 my $weekarrayjs='';
69 my $count = 0;
70 my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
71 my $firstday = Date_DayOfYear($month,$day,$year);
72 my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
73 my $weekno = $wkno;
74 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
75             $count = $i;
76             if($wkno > 52){$year++; $wkno=1;}
77             if($count>365){$count=$i-365;}
78             my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
79             my $output = "$y-$m-$d";
80             $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
81             $wkno++;
82     }
83 chop($weekarrayjs);
84
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 ?
86 $subs->{startdate}=format_date($subs->{startdate});
87 $subs->{firstacquidate}=format_date($subs->{firstacquidate});
88 $subs->{histstartdate}=format_date($subs->{histstartdate});
89 $subs->{enddate}=format_date($subs->{enddate});
90 $subs->{abouttoexpire}=abouttoexpire($subs->{subscriptionid});
91
92 $template->param($subs);
93
94 $template->param(
95     routing => $routing,
96     serialslist => \@serialslist,
97     totalissues => $totalissues,
98     hemisphere => $hemisphere,
99     );
100 $template->param(
101             "periodicity".$subs->{periodicity} => 1,
102             "arrival".$subs->{dow} => 1,
103             "numberpattern".$subs->{numberpattern} => 1,
104             intranetstylesheet => C4::Context->preference("intranetstylesheet"),
105             intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), 
106             );
107
108 output_html_with_http_headers $query, $cookie, $template->output;