3 # Copyright 2000-2003 Katipo Communications
5 # This file is part of Koha.
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
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.
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
28 this script add a subscription into the database.
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
39 Note that if op = mod or addsubscription there are a lot of other params.
55 use C4::Interface::CGI::Output;
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);
73 my ($template, $loggedinuser, $cookie)
74 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
78 flagsrequired => {catalogue => 1},
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
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='';
135 librarian => $librarian,
136 aqbooksellerid => $aqbooksellerid,
137 aqbooksellername => $aqbooksellername,
139 aqbudgetid => $aqbudgetid,
140 bookfundid => $bookfundid,
141 startdate => format_date($startdate),
142 periodicity => $periodicity,
144 numberlength => $numberlength,
145 weeklength => $weeklength,
146 monthlength => $monthlength,
149 whenmorethan1 => $whenmorethan1,
151 lastvalue1 => $lastvalue1,
152 innerloop1 => $innerloop1,
155 whenmorethan2 => $whenmorethan2,
157 lastvalue2 => $lastvalue2,
158 innerloop2 => $innerloop2,
161 whenmorethan3 => $whenmorethan3,
163 lastvalue3 => $lastvalue3,
164 innerloop3 => $innerloop3,
165 numberingmethod => $numberingmethod,
167 biblionumber => $biblionumber,
168 bibliotitle => $bibliotitle,
171 subscriptionid => $subscriptionid,
172 "periodicity$periodicity" => 1,
176 @budgets = GetBookFunds($homebranch);
177 my $temp = scalar(@budgets);
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;
185 $template->param(budgets => \@budgets);
186 #FIXME : END Added by hdl on July, 14 2005
188 my @letterlist = GetLetterList('serial');
189 for (my $i=0;$i<=$#letterlist;$i++) {
190 $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
192 $template->param(letters => \@letterlist);
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');
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
232 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
234 output_html_with_http_headers $query, $cookie, $template->output;