11 use C4::Interface::CGI::Output;
18 my $op = $query->param('op');
19 my $dbh = C4::Context->dbh;
20 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
21 $firstacquidate, $dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength,
22 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
23 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
24 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
25 $numberingmethod, $status, $biblionumber,
26 $bibliotitle, $callnumber, $notes, $hemisphere);
29 my ($template, $loggedinuser, $cookie)
30 = get_template_and_user({template_name => "serials/alt_subscription-add.tmpl",
34 flagsrequired => {catalogue => 1},
41 my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
42 my $firstday = Date_DayOfYear($month,$day,$year);
43 my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
45 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
47 if($wkno > 52){$year++; $wkno=1;}
48 if($count>365){$count=$i-365;}
49 my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
50 my $output = "$y-$m-$d";
51 $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
58 my @subscription_types = (
59 'issues', 'weeks', 'months'
63 my $subscriptionid = $query->param('subscriptionid');
64 my $subs = &GetSubscription($subscriptionid);
65 $auser = $subs->{'user'};
66 $librarian => $subs->{'librarian'},
67 $cost = $subs->{'cost'};
68 $aqbooksellerid = $subs->{'aqbooksellerid'};
69 $aqbooksellername = $subs->{'aqbooksellername'};
70 $bookfundid = $subs->{'bookfundid'};
71 $aqbudgetid = $subs->{'aqbudgetid'};
72 $startdate = $subs->{'startdate'};
73 $firstacquidate = $subs->{'firstacquidate'};
74 $periodicity = $subs->{'periodicity'};
75 $dow = $subs->{'dow'};
76 $irregularity = $subs->{'irregularity'};
77 $numberpattern = $subs->{'numberpattern'};
78 $numberlength = $subs->{'numberlength'};
79 $weeklength = $subs->{'weeklength'};
80 $monthlength = $subs->{'monthlength'};
83 $sublength = $monthlength;
84 $sub_on = $subscription_types[2];
85 } elsif ($weeklength>0){
86 $sublength = $weeklength;
87 $sub_on = $subscription_types[1];
89 $sublength = $numberlength;
90 $sub_on = $subscription_types[0];
94 while (@subscription_types) {
95 my $sub_type = shift @subscription_types;
96 my %row = ( 'name' => $sub_type );
97 if ( $sub_on eq $sub_type ) {
98 $row{'selected'} = ' selected';
100 $row{'selected'} = '';
102 push( @sub_type_data, \%row );
105 $add1 = $subs->{'add1'};
106 $every1 = $subs->{'every1'};
107 $whenmorethan1 = $subs->{'whenmorethan1'};
108 $setto1 = $subs->{'setto1'};
109 $lastvalue1 = $subs->{'lastvalue1'};
110 $innerloop1 = $subs->{'innerloop1'};
111 $add2 = $subs->{'add2'};
112 $every2 = $subs->{'every2'};
113 $whenmorethan2 = $subs->{'whenmorethan2'};
114 $setto2 = $subs->{'setto2'};
115 $lastvalue2 = $subs->{'lastvalue2'};
116 $innerloop2 = $subs->{'innerloop2'};
117 $add3 = $subs->{'add3'};
118 $every3 = $subs->{'every3'};
119 $whenmorethan3 = $subs->{'whenmorethan3'};
120 $setto3 = $subs->{'setto3'};
121 $lastvalue3 = $subs->{'lastvalue3'};
122 $innerloop3 = $subs->{'innerloop3'};
123 $numberingmethod = $subs->{'numberingmethod'};
124 $status = $subs->{status};
125 $biblionumber = $subs->{'biblionumber'};
126 $bibliotitle = $subs->{'bibliotitle'};
127 $callnumber = $subs->{'callnumber'};
128 $notes = $subs->{'notes'};
129 $hemisphere = $subs->{'hemisphere'};
133 librarian => $librarian,
134 aqbooksellerid => $aqbooksellerid,
135 aqbooksellername => $aqbooksellername,
137 aqbudgetid => $aqbudgetid,
138 bookfundid => $bookfundid,
139 startdate => format_date($startdate),
140 firstacquidate => format_date($firstacquidate),
141 periodicity => $periodicity,
143 irregularity => $irregularity,
144 numberpattern => $numberpattern,
145 sublength => $sublength,
146 subtype => \@sub_type_data,
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,
169 callnumber => $callnumber,
171 subscriptionid => $subscriptionid,
172 weekarrayjs => $weekarrayjs,
174 hemisphere => $hemisphere,
178 "periodicity$periodicity" => 1,
180 "numberpattern$numberpattern" => 1,
183 (my $temp,@budgets) = bookfunds();
184 # find default value & set it for the template
185 for (my $i=0;$i<=$#budgets;$i++) {
186 if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
187 $budgets[$i]->{'selected'}=1;
190 $template->param(budgets => \@budgets,
191 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
192 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
193 IntranetNav => C4::Context->preference("IntranetNav"),
196 if ($op eq 'addsubscription') {
197 my @irregular = $query->param('irregular');
198 my $irregular_count = @irregular;
199 for(my $i =0;$i<$irregular_count;$i++){
200 $irregularity .=$irregular[$i]."|";
202 $irregularity =~ s/\|$//;
204 my $auser = $query->param('user');
205 my $aqbooksellerid = $query->param('aqbooksellerid');
206 my $cost = $query->param('cost');
207 my $aqbudgetid = $query->param('aqbudgetid');
208 my $startdate = $query->param('startdate');
209 my $firstacquidate = $query->param('firstacquidate');
210 my $periodicity = $query->param('periodicity');
211 my $dow = $query->param('dow');
212 # my $irregularity = $query->param('irregularity');
213 my $numberlength = 0;
216 my $numberpattern = $query->param('numbering_pattern');
217 my $sublength = $query->param('sublength');
218 my $subtype = $query->param('subtype');
219 if ($subtype eq 'months'){
220 $monthlength = $sublength;
221 } elsif ($subtype eq 'weeks'){
222 $weeklength = $sublength;
224 $numberlength = $sublength;
227 my $add1 = $query->param('add1');
228 my $every1 = $query->param('every1');
229 my $whenmorethan1 = $query->param('whenmorethan1');
230 my $setto1 = $query->param('setto1');
231 my $lastvalue1 = $query->param('lastvalue1');
232 my $add2 = $query->param('add2');
233 my $every2 = $query->param('every2');
234 my $whenmorethan2 = $query->param('whenmorethan2');
235 my $setto2 = $query->param('setto2');
236 my $lastvalue2 = $query->param('lastvalue2');
237 my $add3 = $query->param('add3');
238 my $every3 = $query->param('every3');
239 my $whenmorethan3 = $query->param('whenmorethan3');
240 my $setto3 = $query->param('setto3');
241 my $lastvalue3 = $query->param('lastvalue3');
242 my $numberingmethod = $query->param('numberingmethod');
244 my $biblionumber = $query->param('biblionumber');
245 my $callnumber = $query->param('callnumber');
246 my $notes = $query->param('notes');
247 my $hemisphere = $query->param('hemisphere') || 1;
249 my $subscriptionid = old_newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
250 $startdate,$periodicity,$firstacquidate,$dow,$irregularity,$numberpattern,$numberlength,$weeklength,$monthlength,
251 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
252 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
253 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
254 $numberingmethod, $status, $callnumber, $notes, $hemisphere
256 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
259 while (@subscription_types) {
260 my $sub_type = shift @subscription_types;
261 my %row = ( 'name' => $sub_type );
262 if ( $sub_on eq $sub_type ) {
263 $row{'selected'} = ' selected';
265 $row{'selected'} = '';
267 push( @sub_type_data, \%row );
269 $template->param(subtype => \@sub_type_data,
270 weekarrayjs => $weekarrayjs,
273 output_html_with_http_headers $query, $cookie, $template->output;