Finalized XML version for intranet
[koha.git] / serials / subscription-detail.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Koha;
7 use C4::Date;
8 use C4::Serials;
9 use C4::Output;
10 use C4::Interface::CGI::Output;
11 use C4::Context;
12 use Date::Manip;
13
14 my $query = new CGI;
15 my $op = $query->param('op');
16 my $dbh = C4::Context->dbh;
17 my $sth;
18 # my $id;
19 my ($template, $loggedinuser, $cookie, $subs);
20 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
21         $publisheddate, $dow, $irregularity, $sublength, $subtype, $numberpattern, $numberlength, $weeklength, $monthlength,
22         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
23         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
24         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
25         $numberingmethod, $status, $biblionumber, $bibliotitle, $callnumber, $notes, $hemisphere);
26
27 $subscriptionid = $query->param('subscriptionid');
28
29
30 if ($op eq 'del') {
31 $biblionumber = $query->param('biblionumber');
32         &DelSubscription($subscriptionid,$biblionumber);
33         $query->redirect("/cgi-bin/koha/serials/serials-home.pl");
34         exit;
35
36 }
37 my $subs = &GetSubscription($subscriptionid);
38 my ($routing, @routinglist) = getroutinglist($subscriptionid);
39 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
40 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
41 # the subscription must be deletable if there is NO issues for a reason or another (should not happend, but...)
42
43 ($template, $loggedinuser, $cookie)
44 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
45                                 query => $query,
46                                 type => "intranet",
47                                 authnotrequired => 0,
48                                 flagsrequired => {catalogue => 1},
49                                 debug => 1,
50                                 });
51
52 my ($user, $cookie, $sessionID, $flags)
53         = checkauth($query, 0, {catalogue => 1}, "intranet");
54
55 my $weekarrayjs='';
56 my $count = 0;
57 my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
58 my $firstday = Date_DayOfYear($month,$day,$year);
59 my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
60 my $weekno = $wkno;
61 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
62             $count = $i;
63             if($wkno > 52){$year++; $wkno=1;}
64             if($count>365){$count=$i-365;}
65             my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
66             my $output = "$y-$m-$d";
67             $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
68             $wkno++;
69     }
70 chop($weekarrayjs);
71
72 $template->param(
73         routing => $routing,
74         user => $subs->{auser},
75         librarian => $subs->{librarian},
76         aqbooksellerid => $subs->{aqbooksellerid},
77         aqbooksellername => $subs->{aqbooksellername},
78         cost => $subs->{cost},
79         aqbudgetid => $subs->{aqbudgetid},
80         bookfundid => $subs->{bookfundid},
81         startdate => format_date($subs->{startdate}),
82         publisheddate => format_date($subs->{publisheddate}),    
83         periodicity => $subs->{periodicity},
84         dow => $subs->{dow},
85         irregularity => $subs->{irregularity},
86         numberlength => $subs->{numberlength},
87         weeklength => $subs->{weeklength},
88         monthlength => $subs->{monthlength},
89         numberpattern => $subs->{numberpattern},
90         add1 => $subs->{add1},
91         every1 => $subs->{every1},
92         whenmorethan1 => $subs->{whenmorethan1},
93         innerloop1 => $subs->{innerloop1},
94         setto1 => $subs->{setto1},
95         lastvalue1 => $subs->{lastvalue1},
96         add2 => $subs->{add2},
97         every2 => $subs->{every2},
98         whenmorethan2 => $subs->{whenmorethan2},
99         setto2 => $subs->{setto2},
100         lastvalue2 => $subs->{lastvalue2},
101         innerloop2 => $subs->{innerloop2},
102         add3 => $subs->{add3},
103         every3 => $subs->{every3},
104         whenmorethan3 => $subs->{whenmorethan3},
105         setto3 => $subs->{setto3},
106         lastvalue3 => $subs->{lastvalue3},
107         innerloop3 => $subs->{innerloop3},
108         weekarrayjs => $weekarrayjs,
109         numberingmethod => $subs->{numberingmethod},
110         status => $subs->{status},
111         biblionumber => $subs->{biblionumber},
112         bibliotitle => $subs->{bibliotitle},
113         callnumber => $subs->{callnumber},
114         notes => $subs->{notes},
115         subscriptionid => $subs->{subscriptionid},
116         serialslist => \@serialslist,
117         totalissues => $totalissues,
118         hemisphere => $hemisphere,
119         );
120 $template->param(
121                         "periodicity$subs->{periodicity}" => 1,
122                         "arrival$subs->{dow}" => 1,
123                         "numberpattern$subs->{numberpattern}" => 1,
124                         intranetstylesheet => C4::Context->preference("intranetstylesheet"),
125                         intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), 
126                         );
127
128 output_html_with_http_headers $query, $cookie, $template->output;