Code to allow the associated borrowers to work
[koha.git] / serials / 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 use C4::Letters;
17
18 my $query = new CGI;
19 my $op = $query->param('op');
20 my $dbh = C4::Context->dbh;
21 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
22         $dow, $numberlength, $weeklength, $monthlength,
23         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
24         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
25         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
26         $numberingmethod, $status, $biblionumber, 
27         $bibliotitle, $notes, $letter);
28
29         my @budgets;
30 my ($template, $loggedinuser, $cookie)
31 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
32                                 query => $query,
33                                 type => "intranet",
34                                 authnotrequired => 0,
35                                 flagsrequired => {catalogue => 1},
36                                 debug => 1,
37                                 });
38
39
40 #FIXME : If Budgets are never used, then these lines are useless.
41 $dbh = C4::Context->dbh;
42 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
43 $sthtemp->execute($loggedinuser);
44 my ($flags, $homebranch)=$sthtemp->fetchrow;
45 #FIXME : END added by hdl on July,14 2005
46
47 if ($op eq 'mod') {
48         my $subscriptionid = $query->param('subscriptionid');
49         my $subs = &getsubscription($subscriptionid);
50         $auser = $subs->{'user'};
51         $librarian = $subs->{'librarian'};
52         $cost = $subs->{'cost'};
53         $aqbooksellerid = $subs->{'aqbooksellerid'};
54         $aqbooksellername = $subs->{'aqbooksellername'};
55         $bookfundid = $subs->{'bookfundid'};
56         $aqbudgetid = $subs->{'aqbudgetid'};
57         defined $aqbudgetid or $aqbudgetid='';
58         $startdate = $subs->{'startdate'};
59         $periodicity = $subs->{'periodicity'};
60         $dow = $subs->{'dow'};
61         $numberlength = $subs->{'numberlength'};
62         $weeklength = $subs->{'weeklength'};
63         $monthlength = $subs->{'monthlength'};
64         $add1 = $subs->{'add1'};
65         $every1 = $subs->{'every1'};
66         $whenmorethan1 = $subs->{'whenmorethan1'};
67         $setto1 = $subs->{'setto1'};
68         $lastvalue1 = $subs->{'lastvalue1'};
69         $innerloop1 = $subs->{'innerloop1'};
70         $add2 = $subs->{'add2'};
71         $every2 = $subs->{'every2'};
72         $whenmorethan2 = $subs->{'whenmorethan2'};
73         $setto2 = $subs->{'setto2'};
74         $lastvalue2 = $subs->{'lastvalue2'};
75         $innerloop2 = $subs->{'innerloop2'};
76         $add3 = $subs->{'add3'};
77         $every3 = $subs->{'every3'};
78         $whenmorethan3 = $subs->{'whenmorethan3'};
79         $setto3 = $subs->{'setto3'};
80         $lastvalue3 = $subs->{'lastvalue3'};
81         $innerloop3 = $subs->{'innerloop3'};
82         $numberingmethod = $subs->{'numberingmethod'};
83         $status = $subs->{status};
84         $biblionumber = $subs->{'biblionumber'};
85         $bibliotitle = $subs->{'bibliotitle'},
86         $notes = $subs->{'notes'};
87         $letter = $subs->{'letter'};
88         defined $letter or $letter='';
89         $template->param(
90                 $op => 1,
91                 user => $auser,
92                 librarian => $librarian,
93                 aqbooksellerid => $aqbooksellerid,
94                 aqbooksellername => $aqbooksellername,
95                 cost => $cost,
96                 aqbudgetid => $aqbudgetid,
97                 bookfundid => $bookfundid,
98                 startdate => format_date($startdate),
99                 periodicity => $periodicity,
100                 dow => $dow,
101                 numberlength => $numberlength,
102                 weeklength => $weeklength,
103                 monthlength => $monthlength,
104                 add1 => $add1,
105                 every1 => $every1,
106                 whenmorethan1 => $whenmorethan1,
107                 setto1 => $setto1,
108                 lastvalue1 => $lastvalue1,
109                 innerloop1 => $innerloop1,
110                 add2 => $add2,
111                 every2 => $every2,
112                 whenmorethan2 => $whenmorethan2,
113                 setto2 => $setto2,
114                 lastvalue2 => $lastvalue2,
115                 innerloop2 => $innerloop2,
116                 add3 => $add3,
117                 every3 => $every3,
118                 whenmorethan3 => $whenmorethan3,
119                 setto3 => $setto3,
120                 lastvalue3 => $lastvalue3,
121                 innerloop3 => $innerloop3,
122                 numberingmethod => $numberingmethod,
123                 status => $status,
124                 biblionumber => $biblionumber,
125                 bibliotitle => $bibliotitle,
126                 notes => $notes,
127                 letter => $letter,
128                 subscriptionid => $subscriptionid,
129                 );
130         $template->param(
131                                 "periodicity$periodicity" => 1,
132                                 "dow$dow" => 1,
133                                 );
134 }
135 ##FIXME : Looks like never used.
136 (my $temp,@budgets) = bookfunds($homebranch);
137 # find default value & set it for the template
138 for (my $i=0;$i<$#budgets;$i++) {
139         if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
140                 $budgets[$i]->{'selected'}=1;
141         }
142 }
143 $template->param(budgets => \@budgets);
144 #FIXME : END Added by hdl on July, 14 2005
145
146 my @letterlist = GetLetterList('serial');
147 for (my $i=0;$i<=$#letterlist;$i++) {
148         $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
149 }
150 $template->param(letters => \@letterlist);
151
152 if ($op eq 'addsubscription') {
153         my $auser = $query->param('user');
154         my $aqbooksellerid = $query->param('aqbooksellerid');
155         my $cost = $query->param('cost');
156         my $aqbudgetid = $query->param('aqbudgetid'); 
157         my $startdate = $query->param('startdate');
158         my $periodicity = $query->param('periodicity');
159         my $dow = $query->param('dow');
160         my $numberlength = $query->param('numberlength');
161         my $weeklength = $query->param('weeklength');
162         my $monthlength = $query->param('monthlength');
163         my $add1 = $query->param('add1');
164         my $every1 = $query->param('every1');
165         my $whenmorethan1 = $query->param('whenmorethan1');
166         my $setto1 = $query->param('setto1');
167         my $lastvalue1 = $query->param('lastvalue1');
168         my $add2 = $query->param('add2');
169         my $every2 = $query->param('every2');
170         my $whenmorethan2 = $query->param('whenmorethan2');
171         my $setto2 = $query->param('setto2');
172         my $lastvalue2 = $query->param('lastvalue2');
173         my $add3 = $query->param('add3');
174         my $every3 = $query->param('every3');
175         my $whenmorethan3 = $query->param('whenmorethan3');
176         my $setto3 = $query->param('setto3');
177         my $lastvalue3 = $query->param('lastvalue3');
178         my $numberingmethod = $query->param('numberingmethod');
179         my $status = 1;
180         my $biblionumber = $query->param('biblionumber');
181         my $notes = $query->param('notes');
182         my $letter = $query->param('letter');
183         my $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
184                                         $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
185                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
186                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
187                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
188                                         $numberingmethod, $status, $notes, $letter
189                                 );
190         print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
191 } else {
192         output_html_with_http_headers $query, $cookie, $template->output;
193 }