reordering code & debugging
[koha.git] / bull / subscription-add.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Koha;
6 use C4::Auth;
7 use C4::Output;
8 use C4::Bull;
9 use C4::Interface::CGI::Output;
10 use C4::Context;
11 use HTML::Template;
12 use C4::Bull;
13
14 my $query = new CGI;
15 my $op = $query->param('op');
16 my $dbh = C4::Context->dbh;
17 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
18         $dow, $numberlength, $weeklength, $monthlength,
19         $seqnum1,$startseqnum1,$seqtype1,$freq1,$step1,
20         $seqnum2,$startseqnum2,$seqtype2,$freq2,$step2,
21         $seqnum3,$startseqnum3,$seqtype3,$freq3,$step3,
22         $numberingmethod, $arrivalplanified, $status, $biblionumber, 
23         $bibliotitle, $notes);
24
25 my ($template, $loggedinuser, $cookie)
26 = get_template_and_user({template_name => "bull/subscription-add.tmpl",
27                                 query => $query,
28                                 type => "intranet",
29                                 authnotrequired => 0,
30                                 flagsrequired => {catalogue => 1},
31                                 debug => 1,
32                                 });
33
34
35 if ($op eq 'mod') {
36         my $subscriptionid = $query->param('subscriptionid');
37         my $subs = &getsubscription($subscriptionid);
38         $auser = $subs->{'user'};
39         $librarian => $subs->{'librarian'},
40         $cost = $subs->{'cost'};
41         $aqbooksellerid = $subs->{'aqbooksellerid'};
42         $aqbooksellername = $subs->{'aqbooksellername'};
43         $bookfundid = $subs->{'bookfundid'};
44         $aqbudgetid = $subs->{'aqbudgetid'};
45         $startdate = $subs->{'startdate'};
46         $periodicity = $subs->{'periodicity'};
47         $dow = $subs->{'dow'};
48         $numberlength = $subs->{'numberlength'};
49         $weeklength = $subs->{'weeklength'};
50         $monthlength = $subs->{'monthlength'};
51         $seqnum1 = $subs->{'seqnum1'};
52         $startseqnum1 = $subs->{'startseqnum1'};
53         $seqtype1 = $subs->{'seqtype1'};
54         $freq1 = $subs->{'freq1'};
55         $step1 = $subs->{'step1'};
56         $seqnum2 = $subs->{'seqnum2'};
57         $startseqnum2 = $subs->{'startseqnum2'};
58         $seqtype2 = $subs->{'seqtype2'};
59         $freq2 = $subs->{'freq2'};
60         $step2 = $subs->{'step2'};
61         $seqnum3 = $subs->{'seqnum3'};
62         $startseqnum3 = $subs->{'startseqnum3'};
63         $seqtype3 = $subs->{'seqtype3'};
64         $freq3 = $subs->{'freq3'};
65         $step3 = $subs->{'step3'};
66         $numberingmethod = $subs->{'numberingmethod'};
67         $arrivalplanified = $subs->{'arrivalplanified'};
68         $status = $subs->{status};
69         $biblionumber = $subs->{'biblionumber'};
70         $bibliotitle = $subs->{'bibliotitle'},
71         $notes = $subs->{'notes'};
72         $template->param(
73                 $op => 1,
74                 user => $auser,
75                 librarian => $librarian,
76                 aqbooksellerid => $aqbooksellerid,
77                 aqbooksellername => $aqbooksellername,
78                 cost => $cost,
79                 aqbudgetid => $aqbudgetid,
80                 bookfundid => $bookfundid,
81                 startdate => $startdate,
82                 periodicity => $periodicity,
83                 dow => $dow,
84                 numberlength => $numberlength,
85                 weeklength => $weeklength,
86                 monthlength => $monthlength,
87                 seqnum1 =>$seqnum1,
88                 startseqnum =>$startseqnum1,
89                 seqtype1 =>$seqtype1,
90                 freq1 =>$freq1,
91                 step1 =>$step1,
92                 seqnum2 => $seqnum2,
93                 startseqnum2 => $startseqnum2,
94                 seqtype2 => $seqtype2,
95                 freq2 => $freq2,
96                 step2 => $step2,
97                 seqnum3 => $seqnum3,
98                 startseqnum3 => $startseqnum3,
99                 seqtype3 => $seqtype3,
100                 freq3 => $freq3,
101                 step3 => $step3,
102                 numberingmethod => $numberingmethod,
103                 arrivalplanified => $arrivalplanified,
104                 status => $status,
105                 biblionumber => $biblionumber,
106                 bibliotitle => $bibliotitle,
107                 notes => $notes,
108                 subscriptionid => $subscriptionid
109                 );
110         $template->param(
111                                 "periodicity$periodicity" => 1,
112                                 "seqtype1$seqtype1" => 1,
113                                 "seqtype2$seqtype2" => 1,
114                                 "seqtype3$seqtype3" => 1,
115                                 "dow$dow" => 1,
116                                 );
117 } else {
118 # fill seqtype with 0 to avoid a javascript error
119         $template->param(
120                                 "seqtype1" => 0,
121                                 "seqtype2" => 0,
122                                 "seqtype3" => 0,
123                 );
124 }
125 if ($op eq 'addsubscription') {
126         my $auser = $query->param('user');
127         my $aqbooksellerid = $query->param('aqbooksellerid');
128         my $cost = $query->param('cost');
129         my $aqbudgetid = $query->param('aqbudgetid'); 
130         my $startdate = $query->param('startdate');
131         my $periodicity = $query->param('periodicity');
132         my $dow = $query->param('dow');
133         my $numberlength = $query->param('numberlength');
134         my $weeklength = $query->param('weeklength');
135         my $monthlength = $query->param('monthlength');
136         my $seqnum1 = $query->param('seqnum1');
137         my $seqtype1 = $query->param('seqtype1');
138         my $freq1 = $query->param('freq1');
139         my $step1 = $query->param('step1');
140         my $seqnum2 = $query->param('seqnum2');
141         my $seqtype2 = $query->param('seqtype2');
142         my $freq2 = $query->param('freq2');
143         my $step2 = $query->param('step2');
144         my $seqnum3 = $query->param('seqnum3');
145         my $seqtype3 = $query->param('seqtype3');
146         my $freq3 = $query->param('freq3');
147         my $step3 = $query->param('step3');
148         my $numberingmethod = $query->param('numberingmethod');
149         my $arrivalplanified = $query->param('arrivalplanified');
150         my $status = 1;
151         my $biblionumber = $query->param('biblionumber');
152         my $notes = $query->param('notes');
153
154         my $sth=$dbh->prepare("insert into subscription (librarian, aqbooksellerid,cost,aqbudgetid,biblionumber,startdate, periodicity,dow,numberlength,weeklength,monthlength,seqnum1,startseqnum1,seqtype1,freq1,step1,seqnum2,startseqnum2,seqtype2,freq2, step2, seqnum3,startseqnum3,seqtype3, freq3, step3,numberingmethod, arrivalplanified, status, notes, pos1, pos2, pos3) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, 0, 0, 0)");
155         newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,$startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,$seqnum1,$seqnum1,$seqtype1,$freq1, $step1,$seqnum2,$seqnum2,$seqtype2,$freq2, $step2,$seqnum3,$seqnum3,$seqtype3,$freq3, $step3, $numberingmethod, $arrivalplanified, $status, $notes);
156         
157 }
158
159 output_html_with_http_headers $query, $cookie, $template->output;