serials : lot of bugfixes.
[koha.git] / bull / subscription-add.pl
1 #!/usr/bin/perl
2
3
4 use strict;
5 use CGI;
6 use C4::Koha;
7 use C4::Auth;
8 use C4::Date;
9 use C4::Output;
10 use C4::Bull;
11 use C4::Acquisition;
12 use C4::Interface::CGI::Output;
13 use C4::Context;
14 use HTML::Template;
15 use C4::Bull;
16
17 my $query = new CGI;
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         $dow, $numberlength, $weeklength, $monthlength,
22         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
23         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
24         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
25         $numberingmethod, $status, $biblionumber, 
26         $bibliotitle, $notes);
27
28         my @budgets;
29 my ($template, $loggedinuser, $cookie)
30 = get_template_and_user({template_name => "bull/subscription-add.tmpl",
31                                 query => $query,
32                                 type => "intranet",
33                                 authnotrequired => 0,
34                                 flagsrequired => {catalogue => 1},
35                                 debug => 1,
36                                 });
37
38
39 if ($op eq 'mod') {
40         my $subscriptionid = $query->param('subscriptionid');
41         my $subs = &getsubscription($subscriptionid);
42         $auser = $subs->{'user'};
43         $librarian => $subs->{'librarian'},
44         $cost = $subs->{'cost'};
45         $aqbooksellerid = $subs->{'aqbooksellerid'};
46         $aqbooksellername = $subs->{'aqbooksellername'};
47         $bookfundid = $subs->{'bookfundid'};
48         $aqbudgetid = $subs->{'aqbudgetid'};
49         $startdate = $subs->{'startdate'};
50         $periodicity = $subs->{'periodicity'};
51         $dow = $subs->{'dow'};
52         $numberlength = $subs->{'numberlength'};
53         $weeklength = $subs->{'weeklength'};
54         $monthlength = $subs->{'monthlength'};
55         $add1 = $subs->{'add1'};
56         $every1 = $subs->{'every1'};
57         $whenmorethan1 = $subs->{'whenmorethan1'};
58         $setto1 = $subs->{'setto1'};
59         $lastvalue1 = $subs->{'lastvalue1'};
60         $add2 = $subs->{'add2'};
61         $every2 = $subs->{'every2'};
62         $whenmorethan2 = $subs->{'whenmorethan2'};
63         $setto2 = $subs->{'setto2'};
64         $lastvalue2 = $subs->{'lastvalue2'};
65         $add3 = $subs->{'add3'};
66         $every3 = $subs->{'every3'};
67         $whenmorethan3 = $subs->{'whenmorethan3'};
68         $setto3 = $subs->{'setto3'};
69         $lastvalue3 = $subs->{'lastvalue3'};
70         $numberingmethod = $subs->{'numberingmethod'};
71         $status = $subs->{status};
72         $biblionumber = $subs->{'biblionumber'};
73         $bibliotitle = $subs->{'bibliotitle'},
74         $notes = $subs->{'notes'};
75         $template->param(
76                 $op => 1,
77                 user => $auser,
78                 librarian => $librarian,
79                 aqbooksellerid => $aqbooksellerid,
80                 aqbooksellername => $aqbooksellername,
81                 cost => $cost,
82                 aqbudgetid => $aqbudgetid,
83                 bookfundid => $bookfundid,
84                 startdate => format_date($startdate),
85                 periodicity => $periodicity,
86                 dow => $dow,
87                 numberlength => $numberlength,
88                 weeklength => $weeklength,
89                 monthlength => $monthlength,
90                 add1 => $add1,
91                 every1 => $every1,
92                 whenmorethan1 => $whenmorethan1,
93                 setto1 => $setto1,
94                 lastvalue1 => $lastvalue1,
95                 add2 => $add2,
96                 every2 => $every2,
97                 whenmorethan2 => $whenmorethan2,
98                 setto2 => $setto2,
99                 lastvalue2 => $lastvalue2,
100                 add3 => $add3,
101                 every3 => $every3,
102                 whenmorethan3 => $whenmorethan3,
103                 setto3 => $setto3,
104                 lastvalue3 => $lastvalue3,
105                 numberingmethod => $numberingmethod,
106                 status => $status,
107                 biblionumber => $biblionumber,
108                 bibliotitle => $bibliotitle,
109                 notes => $notes,
110                 subscriptionid => $subscriptionid,
111                 );
112         $template->param(
113                                 "periodicity$periodicity" => 1,
114                                 "dow$dow" => 1,
115                                 );
116 }
117 (my $temp,@budgets) = bookfunds();
118 # find default value & set it for the template
119 for (my $i=0;$i<=$#budgets;$i++) {
120         if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
121                 $budgets[$i]->{'selected'}=1;
122         }
123 }
124 $template->param(budgets => \@budgets);
125
126 if ($op eq 'addsubscription') {
127         my $auser = $query->param('user');
128         my $aqbooksellerid = $query->param('aqbooksellerid');
129         my $cost = $query->param('cost');
130         my $aqbudgetid = $query->param('aqbudgetid'); 
131         my $startdate = $query->param('startdate');
132         my $periodicity = $query->param('periodicity');
133         my $dow = $query->param('dow');
134         my $numberlength = $query->param('numberlength');
135         my $weeklength = $query->param('weeklength');
136         my $monthlength = $query->param('monthlength');
137         my $add1 = $query->param('add1');
138         my $every1 = $query->param('every1');
139         my $whenmorethan1 = $query->param('whenmorethan1');
140         my $setto1 = $query->param('setto1');
141         my $lastvalue1 = $query->param('lastvalue1');
142         my $add2 = $query->param('add2');
143         my $every2 = $query->param('every2');
144         my $whenmorethan2 = $query->param('whenmorethan2');
145         my $setto2 = $query->param('setto2');
146         my $lastvalue2 = $query->param('lastvalue2');
147         my $add3 = $query->param('add3');
148         my $every3 = $query->param('every3');
149         my $whenmorethan3 = $query->param('whenmorethan3');
150         my $setto3 = $query->param('setto3');
151         my $lastvalue3 = $query->param('lastvalue3');
152         my $numberingmethod = $query->param('numberingmethod');
153         my $status = 1;
154         my $biblionumber = $query->param('biblionumber');
155         my $notes = $query->param('notes');
156         my $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
157                                         $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
158                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
159                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
160                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
161                                         $numberingmethod, $status, $notes
162                                 );
163         print $query->redirect("/cgi-bin/koha/bull/subscription-detail.pl?subscriptionid=$subscriptionid");
164 } else {
165         output_html_with_http_headers $query, $cookie, $template->output;
166 }