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.
54 use C4::Interface::CGI::Output;
60 my $op = $query->param('op');
61 my $dbh = C4::Context->dbh;
62 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
63 $publisheddate,$dow,$irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength,
64 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
65 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
66 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
67 $numberingmethod, $status, $biblionumber,
68 $title, $notes, $letter,$callnumber,$hemisphere);
71 my ($template, $loggedinuser, $cookie)
72 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
76 flagsrequired => {catalogue => 1},
82 my $today=get_today();
83 my $dateobj=DATE_obj($today);
84 my $year=$dateobj->year;
85 my $month=$dateobj->month;
86 my $day=$dateobj->day_of_month;
87 my $firstday = $dateobj->day_of_year;
88 my $wkno = $dateobj->week_number;
90 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
92 if($wkno > 52){$year++; $wkno=1;}
93 if($count>365){$count=$i-365;}
94 my $newdate=DateTime->from_day_of_year(year=>$year,day_of_year=>$count);
95 $weekarrayjs .= "'Wk $wkno: ".format_date($newdate->ymd)."',";
102 my @subscription_types = (
103 'issues', 'weeks', 'months'
107 my $subscriptionid = $query->param('subscriptionid');
108 my $subs = &GetSubscription($subscriptionid);
109 $auser = $subs->{'user'};
110 $librarian = $subs->{'librarian'};
111 $cost = $subs->{'cost'};
112 $aqbooksellerid = $subs->{'aqbooksellerid'};
113 $aqbooksellername = $subs->{'aqbooksellername'};
114 $bookfundid = $subs->{'bookfundid'};
115 $aqbudgetid = $subs->{'aqbudgetid'};
116 defined $aqbudgetid or $aqbudgetid='';
117 $startdate = $subs->{'startdate'};
118 $publisheddate = $subs->{'publisheddate'};
119 $periodicity = $subs->{'periodicity'};
120 $dow = $subs->{'dow'};
121 $irregularity = $subs->{'irregularity'};
122 $numberpattern = $subs->{'numberpattern'};
123 $numberlength = $subs->{'numberlength'};
124 $weeklength = $subs->{'weeklength'};
125 $monthlength = $subs->{'monthlength'};
126 if($monthlength > 0){
127 $sublength = $monthlength;
128 $sub_on = $subscription_types[2];
129 } elsif ($weeklength>0){
130 $sublength = $weeklength;
131 $sub_on = $subscription_types[1];
133 $sublength = $numberlength;
134 $sub_on = $subscription_types[0];
138 while (@subscription_types) {
139 my $sub_type = shift @subscription_types;
140 my %row = ( 'name' => $sub_type );
141 if ( $sub_on eq $sub_type ) {
142 $row{'selected'} = ' selected';
144 $row{'selected'} = '';
146 push( @sub_type_data, \%row );
148 $add1 = $subs->{'add1'};
149 $every1 = $subs->{'every1'};
150 $whenmorethan1 = $subs->{'whenmorethan1'};
151 $setto1 = $subs->{'setto1'};
152 $lastvalue1 = $subs->{'lastvalue1'};
153 $innerloop1 = $subs->{'innerloop1'};
154 $add2 = $subs->{'add2'};
155 $every2 = $subs->{'every2'};
156 $whenmorethan2 = $subs->{'whenmorethan2'};
157 $setto2 = $subs->{'setto2'};
158 $lastvalue2 = $subs->{'lastvalue2'};
159 $innerloop2 = $subs->{'innerloop2'};
160 $add3 = $subs->{'add3'};
161 $every3 = $subs->{'every3'};
162 $whenmorethan3 = $subs->{'whenmorethan3'};
163 $setto3 = $subs->{'setto3'};
164 $lastvalue3 = $subs->{'lastvalue3'};
165 $innerloop3 = $subs->{'innerloop3'};
166 $numberingmethod = $subs->{'numberingmethod'};
167 $status = $subs->{status};
168 $biblionumber = $subs->{'biblionumber'};
169 $title = $subs->{'title'},
170 $callnumber = $subs->{'callnumber'};
171 $hemisphere = $subs->{'hemisphere'};
172 $notes = $subs->{'notes'};
173 $letter = $subs->{'letter'};
174 defined $letter or $letter='';
178 librarian => $librarian,
179 aqbooksellerid => $aqbooksellerid,
180 aqbooksellername => $aqbooksellername,
182 aqbudgetid => $aqbudgetid,
183 bookfundid => $bookfundid,
184 startdate => format_date($startdate),
185 publisheddate => format_date($publisheddate),
186 periodicity => $periodicity,
187 numberpattern=>$numberpattern,
189 numberlength => $numberlength,
190 weeklength => $weeklength,
191 monthlength => $monthlength,
192 sublength=>$sublength,
195 whenmorethan1 => $whenmorethan1,
197 lastvalue1 => $lastvalue1,
198 innerloop1 => $innerloop1,
201 whenmorethan2 => $whenmorethan2,
203 lastvalue2 => $lastvalue2,
204 innerloop2 => $innerloop2,
207 whenmorethan3 => $whenmorethan3,
209 lastvalue3 => $lastvalue3,
210 innerloop3 => $innerloop3,
211 numberingmethod => $numberingmethod,
213 biblionumber => $biblionumber,
215 callnumber => $callnumber,
218 subscriptionid => $subscriptionid,
219 weekarrayjs => $weekarrayjs,
221 hemisphere => $hemisphere,
222 "periodicity$periodicity" => 1,
224 "numberpattern$numberpattern" => 1,
228 my @letterlist = GetLetterList('serial');
229 for (my $i=0;$i<=$#letterlist;$i++) {
230 $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
232 $template->param(letters => \@letterlist);
234 if ($op eq 'addsubscription') {
235 my @irregular = $query->param('irregular');
236 my $irregular_count = @irregular;
237 for(my $i =0;$i<$irregular_count;$i++){
238 $irregularity .=$irregular[$i]."|";
240 $irregularity =~ s/\|$//;
242 my $auser = $query->param('user');
243 my $aqbooksellerid = $query->param('aqbooksellerid');
244 my $cost = $query->param('cost');
245 my $aqbudgetid = $query->param('aqbudgetid');
246 my $startdate = $query->param('startdate');
247 my $publisheddate = $query->param('publisheddate');
248 my $callnumber=$query->param('callnumber');
249 my $periodicity = $query->param('periodicity');
250 my $dow = $query->param('dow');
251 my $numberlength = 0;
254 my $numberpattern = $query->param('numbering_pattern');
255 my $sublength = $query->param('sublength');
256 my $subtype = $query->param('subtype');
257 if ($subtype eq 'months'){
258 $monthlength = $sublength;
259 } elsif ($subtype eq 'weeks'){
260 $weeklength = $sublength;
262 $numberlength = $sublength;
266 my $add1 = $query->param('add1');
267 my $every1 = $query->param('every1');
268 my $whenmorethan1 = $query->param('whenmorethan1');
269 my $setto1 = $query->param('setto1');
270 my $lastvalue1 = $query->param('lastvalue1');
271 my $add2 = $query->param('add2');
272 my $every2 = $query->param('every2');
273 my $whenmorethan2 = $query->param('whenmorethan2');
274 my $setto2 = $query->param('setto2');
275 my $lastvalue2 = $query->param('lastvalue2');
276 my $add3 = $query->param('add3');
277 my $every3 = $query->param('every3');
278 my $whenmorethan3 = $query->param('whenmorethan3');
279 my $setto3 = $query->param('setto3');
280 my $lastvalue3 = $query->param('lastvalue3');
281 my $numberingmethod = $query->param('numberingmethod');
283 my $biblionumber = $query->param('biblionumber');
284 my $notes = $query->param('notes');
285 my $letter = $query->param('letter');
286 my $hemisphere = $query->param('hemisphere') || 1;
288 my $subscriptionid = NewSubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
289 $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
290 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
291 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
292 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
293 $numberingmethod, $status, $notes, $letter,$irregularity,$hemisphere,$callnumber,$numberpattern,$publisheddate );
294 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
296 while (@subscription_types) {
297 my $sub_type = shift @subscription_types;
298 my %row = ( 'name' => $sub_type );
299 if ( $sub_on eq $sub_type ) {
300 $row{'selected'} = ' selected';
302 $row{'selected'} = '';
304 push( @sub_type_data, \%row );
306 $template->param(subtype => \@sub_type_data,
307 weekarrayjs => $weekarrayjs,
310 output_html_with_http_headers $query, $cookie, $template->output;