Code cleaning : Some subs renamed.
[koha.git] / serials / subscription-add.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2003 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 =head1 NAME
23
24 subscription-add.pl
25
26 =head1 DESCRIPTION
27
28 this script add a subscription into the database.
29
30 =head1 PARAMETERS
31
32 =over 4
33
34 =item op
35 op use to know the operation to do on this template.
36  * mod : to modify an existing subscription
37  * addsubscription : to add a subscription
38
39 Note that if op = mod or addsubscription there are a lot of other params.
40
41
42 =back
43
44 =cut
45
46
47 use strict;
48 use CGI;
49 use C4::Koha;
50 use C4::Auth;
51 use C4::Date;
52 use C4::Output;
53 use C4::Serials;
54 use C4::Acquisition;
55 use C4::Interface::CGI::Output;
56 use C4::Context;
57 use HTML::Template;
58 use C4::Letters;
59 use C4::Members;
60
61 my $query = new CGI;
62 my $op = $query->param('op');
63 my $dbh = C4::Context->dbh;
64 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
65     $dow, $numberlength, $weeklength, $monthlength,
66     $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
67     $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
68     $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
69     $numberingmethod, $status, $biblionumber,
70     $bibliotitle, $notes, $letter);
71
72     my @budgets;
73 my ($template, $loggedinuser, $cookie)
74 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
75                 query => $query,
76                 type => "intranet",
77                 authnotrequired => 0,
78                 flagsrequired => {catalogue => 1},
79                 debug => 1,
80                 });
81
82
83 #FIXME : If Budgets are never used, then these lines are useless.
84 $dbh = C4::Context->dbh;
85 my $sthtemp = GetBranchCodeFromBorrowers();
86 $sthtemp->execute($loggedinuser);
87 my ($flags, $homebranch)=$sthtemp->fetchrow;
88 #FIXME : END added by hdl on July,14 2005
89
90 if ($op eq 'mod') {
91     my $subscriptionid = $query->param('subscriptionid');
92     my $subs = &GetSubscription($subscriptionid);
93     $auser = $subs->{'user'};
94     $librarian = $subs->{'librarian'};
95     $cost = $subs->{'cost'};
96     $aqbooksellerid = $subs->{'aqbooksellerid'};
97     $aqbooksellername = $subs->{'aqbooksellername'};
98     $bookfundid = $subs->{'bookfundid'};
99     $aqbudgetid = $subs->{'aqbudgetid'};
100     defined $aqbudgetid or $aqbudgetid='';
101     $startdate = $subs->{'startdate'};
102     $periodicity = $subs->{'periodicity'};
103     $dow = $subs->{'dow'};
104     $numberlength = $subs->{'numberlength'};
105     $weeklength = $subs->{'weeklength'};
106     $monthlength = $subs->{'monthlength'};
107     $add1 = $subs->{'add1'};
108     $every1 = $subs->{'every1'};
109     $whenmorethan1 = $subs->{'whenmorethan1'};
110     $setto1 = $subs->{'setto1'};
111     $lastvalue1 = $subs->{'lastvalue1'};
112     $innerloop1 = $subs->{'innerloop1'};
113     $add2 = $subs->{'add2'};
114     $every2 = $subs->{'every2'};
115     $whenmorethan2 = $subs->{'whenmorethan2'};
116     $setto2 = $subs->{'setto2'};
117     $lastvalue2 = $subs->{'lastvalue2'};
118     $innerloop2 = $subs->{'innerloop2'};
119     $add3 = $subs->{'add3'};
120     $every3 = $subs->{'every3'};
121     $whenmorethan3 = $subs->{'whenmorethan3'};
122     $setto3 = $subs->{'setto3'};
123     $lastvalue3 = $subs->{'lastvalue3'};
124     $innerloop3 = $subs->{'innerloop3'};
125     $numberingmethod = $subs->{'numberingmethod'};
126     $status = $subs->{status};
127     $biblionumber = $subs->{'biblionumber'};
128     $bibliotitle = $subs->{'bibliotitle'},
129     $notes = $subs->{'notes'};
130     $letter = $subs->{'letter'};
131     defined $letter or $letter='';
132     $template->param(
133         $op => 1,
134         user => $auser,
135         librarian => $librarian,
136         aqbooksellerid => $aqbooksellerid,
137         aqbooksellername => $aqbooksellername,
138         cost => $cost,
139         aqbudgetid => $aqbudgetid,
140         bookfundid => $bookfundid,
141         startdate => format_date($startdate),
142         periodicity => $periodicity,
143         dow => $dow,
144         numberlength => $numberlength,
145         weeklength => $weeklength,
146         monthlength => $monthlength,
147         add1 => $add1,
148         every1 => $every1,
149         whenmorethan1 => $whenmorethan1,
150         setto1 => $setto1,
151         lastvalue1 => $lastvalue1,
152         innerloop1 => $innerloop1,
153         add2 => $add2,
154         every2 => $every2,
155         whenmorethan2 => $whenmorethan2,
156         setto2 => $setto2,
157         lastvalue2 => $lastvalue2,
158         innerloop2 => $innerloop2,
159         add3 => $add3,
160         every3 => $every3,
161         whenmorethan3 => $whenmorethan3,
162         setto3 => $setto3,
163         lastvalue3 => $lastvalue3,
164         innerloop3 => $innerloop3,
165         numberingmethod => $numberingmethod,
166         status => $status,
167         biblionumber => $biblionumber,
168         bibliotitle => $bibliotitle,
169         notes => $notes,
170         letter => $letter,
171         subscriptionid => $subscriptionid,
172         "periodicity$periodicity" => 1,
173         "dow$dow" => 1,
174         );
175 }
176 @budgets = GetBookFunds($homebranch);
177 my $temp = scalar(@budgets);
178
179 # find default value & set it for the template
180 for (my $i=0;$i<$#budgets;$i++) {
181     if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
182         $budgets[$i]->{'selected'}=1;
183     }
184 }
185 $template->param(budgets => \@budgets);
186 #FIXME : END Added by hdl on July, 14 2005
187
188 my @letterlist = GetLetterList('serial');
189 for (my $i=0;$i<=$#letterlist;$i++) {
190     $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
191 }
192 $template->param(letters => \@letterlist);
193
194 if ($op eq 'addsubscription') {
195     my $auser = $query->param('user');
196     my $aqbooksellerid = $query->param('aqbooksellerid');
197     my $cost = $query->param('cost');
198     my $aqbudgetid = $query->param('aqbudgetid');
199     my $startdate = $query->param('startdate');
200     my $periodicity = $query->param('periodicity');
201     my $dow = $query->param('dow');
202     my $numberlength = $query->param('numberlength');
203     my $weeklength = $query->param('weeklength');
204     my $monthlength = $query->param('monthlength');
205     my $add1 = $query->param('add1');
206     my $every1 = $query->param('every1');
207     my $whenmorethan1 = $query->param('whenmorethan1');
208     my $setto1 = $query->param('setto1');
209     my $lastvalue1 = $query->param('lastvalue1');
210     my $add2 = $query->param('add2');
211     my $every2 = $query->param('every2');
212     my $whenmorethan2 = $query->param('whenmorethan2');
213     my $setto2 = $query->param('setto2');
214     my $lastvalue2 = $query->param('lastvalue2');
215     my $add3 = $query->param('add3');
216     my $every3 = $query->param('every3');
217     my $whenmorethan3 = $query->param('whenmorethan3');
218     my $setto3 = $query->param('setto3');
219     my $lastvalue3 = $query->param('lastvalue3');
220     my $numberingmethod = $query->param('numberingmethod');
221     my $status = 1;
222     my $biblionumber = $query->param('biblionumber');
223     my $notes = $query->param('notes');
224     my $letter = $query->param('letter');
225     my $subscriptionid = NewSubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
226                     $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
227                     $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
228                     $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
229                     $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
230                     $numberingmethod, $status, $notes, $letter
231                 );
232     print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
233 } else {
234     output_html_with_http_headers $query, $cookie, $template->output;
235 }