Sub renamed and/or GPL Licence added according to the coding guideline.
[koha.git] / serials / subscription-detail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 # $Id$
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Koha;
26 use C4::Date;
27 use C4::Serials;
28 use C4::Output;
29 use C4::Interface::CGI::Output;
30 use C4::Context;
31 use HTML::Template;
32
33 my $query = new CGI;
34 my $op = $query->param('op') || '';
35 my $dbh = C4::Context->dbh;
36 my $sth;
37 # my $id;
38 my ($template, $loggedinuser, $cookie, $subs, $user, $sessionID, $flags);
39 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
40         $dow, $numberlength, $weeklength, $monthlength,
41         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
42         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
43         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
44         $numberingmethod, $status, $biblionumber, $bibliotitle, $notes,$letter);
45
46 $subscriptionid = $query->param('subscriptionid');
47
48 if ($op eq 'modsubscription') {
49         $auser = $query->param('user');
50         $librarian = $query->param('librarian');
51         $cost = $query->param('cost');
52         $aqbooksellerid = $query->param('aqbooksellerid');
53         $biblionumber = $query->param('biblionumber');
54         $aqbudgetid = $query->param('aqbudgetid');
55         $startdate = format_date_in_iso($query->param('startdate'));
56         $periodicity = $query->param('periodicity');
57         $dow = $query->param('dow');
58         $numberlength = $query->param('numberlength');
59         $weeklength = $query->param('weeklength');
60         $monthlength = $query->param('monthlength');
61         $add1 = $query->param('add1');
62         $every1 = $query->param('every1');
63         $whenmorethan1 = $query->param('whenmorethan1');
64         $setto1 = $query->param('setto1');
65         $lastvalue1 = $query->param('lastvalue1');
66         $innerloop1 = $query->param('innerloop1');
67         $add2 = $query->param('add2');
68         $every2 = $query->param('every2');
69         $whenmorethan2 = $query->param('whenmorethan2');
70         $setto2 = $query->param('setto2');
71         $lastvalue2 = $query->param('lastvalue2');
72         $innerloop2 = $query->param('innerloop2');
73         $add3 = $query->param('add3');
74         $every3 = $query->param('every3');
75         $whenmorethan3 = $query->param('whenmorethan3');
76         $setto3 = $query->param('setto3');
77         $lastvalue3 = $query->param('lastvalue3');
78         $innerloop3 = $query->param('innerloop3');
79         $numberingmethod = $query->param('numberingmethod');
80         $status = 1;
81         $notes = $query->param('notes');
82         $letter = $query->param('letter');
83     
84         &ModSubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
85                                         $periodicity,$dow,$numberlength,$weeklength,$monthlength,
86                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
87                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
88                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
89                                         $numberingmethod, $status, $biblionumber, $notes, $letter, $subscriptionid);
90 }
91
92 if ($op eq 'del') {
93         &DelSubscription($subscriptionid);
94         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=../bull-home.pl\"></html>";
95         exit;
96
97 }
98 $subs = &GetSubscription($subscriptionid);
99 # html'ize distributedto
100 $subs->{distributedto}=~ s/\n/<br \/>/g;
101 my ($totalissues,@serialslist) = GetSerials($subscriptionid);
102 $totalissues-- if $totalissues; # the -1 is to have 0 if this is a new subscription (only 1 issue)
103
104 ($template, $loggedinuser, $cookie)
105 = get_template_and_user({template_name => "serials/subscription-detail.tmpl",
106                                 query => $query,
107                                 type => "intranet",
108                                 authnotrequired => 0,
109                                 flagsrequired => {catalogue => 1},
110                                 debug => 1,
111                                 });
112
113 ($user, $cookie, $sessionID, $flags) = checkauth($query, 0, {catalogue => 1}, "intranet");
114
115 $template->param(
116         user => $subs->{auser},
117         librarian => $subs->{librarian},
118         aqbooksellerid => $subs->{aqbooksellerid},
119         aqbooksellername => $subs->{aqbooksellername},
120         cost => $subs->{cost},
121         aqbudgetid => $subs->{aqbudgetid},
122         bookfundid => $subs->{bookfundid},
123         startdate => format_date($subs->{startdate}),
124         periodicity => $subs->{periodicity},
125         dow => $subs->{dow},
126         numberlength => $subs->{numberlength},
127         weeklength => $subs->{weeklength},
128         monthlength => $subs->{monthlength},
129         add1 => $subs->{add1},
130         every1 => $subs->{every1},
131         whenmorethan1 => $subs->{whenmorethan1},
132         innerloop1 => $subs->{innerloop1},
133         setto1 => $subs->{setto1},
134         lastvalue1 => $subs->{lastvalue1},
135         add2 => $subs->{add2},
136         every2 => $subs->{every2},
137         whenmorethan2 => $subs->{whenmorethan2},
138         setto2 => $subs->{setto2},
139         lastvalue2 => $subs->{lastvalue2},
140         innerloop2 => $subs->{innerloop2},
141         add3 => $subs->{add3},
142         every3 => $subs->{every3},
143         whenmorethan3 => $subs->{whenmorethan3},
144         setto3 => $subs->{setto3},
145         lastvalue3 => $subs->{lastvalue3},
146         innerloop3 => $subs->{innerloop3},
147         numberingmethod => $subs->{numberingmethod},
148         status => $subs->{status},
149         biblionumber => $subs->{biblionumber},
150         bibliotitle => $subs->{bibliotitle},
151         notes => $subs->{notes},
152         letter => $subs->{letter},
153         distributedto => $subs->{distributedto},
154         subscriptionid => $subs->{subscriptionid},
155         serialslist => \@serialslist,
156         totalissues => $totalissues,
157         );
158 $template->param(
159                         "periodicity$subs->{periodicity}" => 1,
160                         "arrival$subs->{dow}" => 1,
161                         );
162
163 output_html_with_http_headers $query, $cookie, $template->output;