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;
61 my $op = $query->param('op');
62 my $dbh = C4::Context->dbh;
63 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
64 $publisheddate,$dow,$irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength,
65 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
66 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
67 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
68 $numberingmethod, $status, $biblionumber,
69 $title, $notes, $letter,$callnumber,$hemisphere);
72 my ($template, $loggedinuser, $cookie)
73 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
77 flagsrequired => {catalogue => 1},
83 my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
84 my $firstday = Date_DayOfYear($month,$day,$year);
85 my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
87 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
89 if($wkno > 52){$year++; $wkno=1;}
90 if($count>365){$count=$i-365;}
91 my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
92 my $output = "$y-$m-$d";
93 $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
100 my @subscription_types = (
101 'issues', 'weeks', 'months'
105 my $subscriptionid = $query->param('subscriptionid');
106 my $subs = &GetSubscription($subscriptionid);
107 $auser = $subs->{'user'};
108 $librarian = $subs->{'librarian'};
109 $cost = $subs->{'cost'};
110 $aqbooksellerid = $subs->{'aqbooksellerid'};
111 $aqbooksellername = $subs->{'aqbooksellername'};
112 $bookfundid = $subs->{'bookfundid'};
113 $aqbudgetid = $subs->{'aqbudgetid'};
114 defined $aqbudgetid or $aqbudgetid='';
115 $startdate = $subs->{'startdate'};
116 $publisheddate = $subs->{'publisheddate'};
117 $periodicity = $subs->{'periodicity'};
118 $dow = $subs->{'dow'};
119 $irregularity = $subs->{'irregularity'};
120 $numberpattern = $subs->{'numberpattern'};
121 $numberlength = $subs->{'numberlength'};
122 $weeklength = $subs->{'weeklength'};
123 $monthlength = $subs->{'monthlength'};
124 if($monthlength > 0){
125 $sublength = $monthlength;
126 $sub_on = $subscription_types[2];
127 } elsif ($weeklength>0){
128 $sublength = $weeklength;
129 $sub_on = $subscription_types[1];
131 $sublength = $numberlength;
132 $sub_on = $subscription_types[0];
136 while (@subscription_types) {
137 my $sub_type = shift @subscription_types;
138 my %row = ( 'name' => $sub_type );
139 if ( $sub_on eq $sub_type ) {
140 $row{'selected'} = ' selected';
142 $row{'selected'} = '';
144 push( @sub_type_data, \%row );
146 $add1 = $subs->{'add1'};
147 $every1 = $subs->{'every1'};
148 $whenmorethan1 = $subs->{'whenmorethan1'};
149 $setto1 = $subs->{'setto1'};
150 $lastvalue1 = $subs->{'lastvalue1'};
151 $innerloop1 = $subs->{'innerloop1'};
152 $add2 = $subs->{'add2'};
153 $every2 = $subs->{'every2'};
154 $whenmorethan2 = $subs->{'whenmorethan2'};
155 $setto2 = $subs->{'setto2'};
156 $lastvalue2 = $subs->{'lastvalue2'};
157 $innerloop2 = $subs->{'innerloop2'};
158 $add3 = $subs->{'add3'};
159 $every3 = $subs->{'every3'};
160 $whenmorethan3 = $subs->{'whenmorethan3'};
161 $setto3 = $subs->{'setto3'};
162 $lastvalue3 = $subs->{'lastvalue3'};
163 $innerloop3 = $subs->{'innerloop3'};
164 $numberingmethod = $subs->{'numberingmethod'};
165 $status = $subs->{status};
166 $biblionumber = $subs->{'biblionumber'};
167 $title = $subs->{'title'},
168 $callnumber = $subs->{'callnumber'};
169 $hemisphere = $subs->{'hemisphere'};
170 $notes = $subs->{'notes'};
171 $letter = $subs->{'letter'};
172 defined $letter or $letter='';
176 librarian => $librarian,
177 aqbooksellerid => $aqbooksellerid,
178 aqbooksellername => $aqbooksellername,
180 aqbudgetid => $aqbudgetid,
181 bookfundid => $bookfundid,
182 startdate => format_date($startdate),
183 publisheddate => format_date($publisheddate),
184 periodicity => $periodicity,
185 numberpattern=>$numberpattern,
187 numberlength => $numberlength,
188 weeklength => $weeklength,
189 monthlength => $monthlength,
190 sublength=>$sublength,
193 whenmorethan1 => $whenmorethan1,
195 lastvalue1 => $lastvalue1,
196 innerloop1 => $innerloop1,
199 whenmorethan2 => $whenmorethan2,
201 lastvalue2 => $lastvalue2,
202 innerloop2 => $innerloop2,
205 whenmorethan3 => $whenmorethan3,
207 lastvalue3 => $lastvalue3,
208 innerloop3 => $innerloop3,
209 numberingmethod => $numberingmethod,
211 biblionumber => $biblionumber,
213 callnumber => $callnumber,
216 subscriptionid => $subscriptionid,
217 weekarrayjs => $weekarrayjs,
219 hemisphere => $hemisphere,
220 "periodicity$periodicity" => 1,
222 "numberpattern$numberpattern" => 1,
226 my @letterlist = GetLetterList('serial');
227 for (my $i=0;$i<=$#letterlist;$i++) {
228 $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
230 $template->param(letters => \@letterlist);
232 if ($op eq 'addsubscription') {
233 my @irregular = $query->param('irregular');
234 my $irregular_count = @irregular;
235 for(my $i =0;$i<$irregular_count;$i++){
236 $irregularity .=$irregular[$i]."|";
238 $irregularity =~ s/\|$//;
240 my $auser = $query->param('user');
241 my $aqbooksellerid = $query->param('aqbooksellerid');
242 my $cost = $query->param('cost');
243 my $aqbudgetid = $query->param('aqbudgetid');
244 my $startdate = $query->param('startdate');
245 my $publisheddate = $query->param('publisheddate');
246 my $callnumber=$query->param('callnumber');
247 my $periodicity = $query->param('periodicity');
248 my $dow = $query->param('dow');
249 my $numberlength = 0;
252 my $numberpattern = $query->param('numbering_pattern');
253 my $sublength = $query->param('sublength');
254 my $subtype = $query->param('subtype');
255 if ($subtype eq 'months'){
256 $monthlength = $sublength;
257 } elsif ($subtype eq 'weeks'){
258 $weeklength = $sublength;
260 $numberlength = $sublength;
264 my $add1 = $query->param('add1');
265 my $every1 = $query->param('every1');
266 my $whenmorethan1 = $query->param('whenmorethan1');
267 my $setto1 = $query->param('setto1');
268 my $lastvalue1 = $query->param('lastvalue1');
269 my $add2 = $query->param('add2');
270 my $every2 = $query->param('every2');
271 my $whenmorethan2 = $query->param('whenmorethan2');
272 my $setto2 = $query->param('setto2');
273 my $lastvalue2 = $query->param('lastvalue2');
274 my $add3 = $query->param('add3');
275 my $every3 = $query->param('every3');
276 my $whenmorethan3 = $query->param('whenmorethan3');
277 my $setto3 = $query->param('setto3');
278 my $lastvalue3 = $query->param('lastvalue3');
279 my $numberingmethod = $query->param('numberingmethod');
281 my $biblionumber = $query->param('biblionumber');
282 my $notes = $query->param('notes');
283 my $letter = $query->param('letter');
284 my $hemisphere = $query->param('hemisphere') || 1;
286 my $subscriptionid = NewSubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
287 $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
288 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
289 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
290 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
291 $numberingmethod, $status, $notes, $letter,$irregularity,$hemisphere,$callnumber,$numberpattern,$publisheddate );
292 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
294 while (@subscription_types) {
295 my $sub_type = shift @subscription_types;
296 my %row = ( 'name' => $sub_type );
297 if ( $sub_on eq $sub_type ) {
298 $row{'selected'} = ' selected';
300 $row{'selected'} = '';
302 push( @sub_type_data, \%row );
304 $template->param(subtype => \@sub_type_data,
305 weekarrayjs => $weekarrayjs,
308 output_html_with_http_headers $query, $cookie, $template->output;