Letters / alert system, continuing...
[wip/koha-chris_n.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 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 => "bull/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 my $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         $startdate = $subs->{'startdate'};
58         $periodicity = $subs->{'periodicity'};
59         $dow = $subs->{'dow'};
60         $numberlength = $subs->{'numberlength'};
61         $weeklength = $subs->{'weeklength'};
62         $monthlength = $subs->{'monthlength'};
63         $add1 = $subs->{'add1'};
64         $every1 = $subs->{'every1'};
65         $whenmorethan1 = $subs->{'whenmorethan1'};
66         $setto1 = $subs->{'setto1'};
67         $lastvalue1 = $subs->{'lastvalue1'};
68         $innerloop1 = $subs->{'innerloop1'};
69         $add2 = $subs->{'add2'};
70         $every2 = $subs->{'every2'};
71         $whenmorethan2 = $subs->{'whenmorethan2'};
72         $setto2 = $subs->{'setto2'};
73         $lastvalue2 = $subs->{'lastvalue2'};
74         $innerloop2 = $subs->{'innerloop2'};
75         $add3 = $subs->{'add3'};
76         $every3 = $subs->{'every3'};
77         $whenmorethan3 = $subs->{'whenmorethan3'};
78         $setto3 = $subs->{'setto3'};
79         $lastvalue3 = $subs->{'lastvalue3'};
80         $innerloop3 = $subs->{'innerloop3'};
81         $numberingmethod = $subs->{'numberingmethod'};
82         $status = $subs->{status};
83         $biblionumber = $subs->{'biblionumber'};
84         $bibliotitle = $subs->{'bibliotitle'},
85         $notes = $subs->{'notes'};
86         $letter = $subs->{'letter'};
87         $template->param(
88                 $op => 1,
89                 user => $auser,
90                 librarian => $librarian,
91                 aqbooksellerid => $aqbooksellerid,
92                 aqbooksellername => $aqbooksellername,
93                 cost => $cost,
94                 aqbudgetid => $aqbudgetid,
95                 bookfundid => $bookfundid,
96                 startdate => format_date($startdate),
97                 periodicity => $periodicity,
98                 dow => $dow,
99                 numberlength => $numberlength,
100                 weeklength => $weeklength,
101                 monthlength => $monthlength,
102                 add1 => $add1,
103                 every1 => $every1,
104                 whenmorethan1 => $whenmorethan1,
105                 setto1 => $setto1,
106                 lastvalue1 => $lastvalue1,
107                 innerloop1 => $innerloop1,
108                 add2 => $add2,
109                 every2 => $every2,
110                 whenmorethan2 => $whenmorethan2,
111                 setto2 => $setto2,
112                 lastvalue2 => $lastvalue2,
113                 innerloop2 => $innerloop2,
114                 add3 => $add3,
115                 every3 => $every3,
116                 whenmorethan3 => $whenmorethan3,
117                 setto3 => $setto3,
118                 lastvalue3 => $lastvalue3,
119                 innerloop3 => $innerloop3,
120                 numberingmethod => $numberingmethod,
121                 status => $status,
122                 biblionumber => $biblionumber,
123                 bibliotitle => $bibliotitle,
124                 notes => $notes,
125                 letter => $letter,
126                 subscriptionid => $subscriptionid,
127                 );
128         $template->param(
129                                 "periodicity$periodicity" => 1,
130                                 "dow$dow" => 1,
131                                 );
132 }
133 ##FIXME : Looks like never used.
134 (my $temp,@budgets) = bookfunds($homebranch);
135 # find default value & set it for the template
136 for (my $i=0;$i<=$#budgets;$i++) {
137         if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
138                 $budgets[$i]->{'selected'}=1;
139         }
140 }
141 $template->param(budgets => \@budgets);
142 #FIXME : END Added by hdl on July, 14 2005
143
144 my @letterlist = GetLetterList('serial');
145 for (my $i=0;$i<=$#letterlist;$i++) {
146         warn "$letterlist[$i]->{'code'} eq ".$letter;
147         $letterlist[$i]->{'selected'} =1 if $letterlist[$i]->{'code'} eq $letter;
148 }
149 $template->param(letters => \@letterlist);
150
151 if ($op eq 'addsubscription') {
152         my $auser = $query->param('user');
153         my $aqbooksellerid = $query->param('aqbooksellerid');
154         my $cost = $query->param('cost');
155         my $aqbudgetid = $query->param('aqbudgetid'); 
156         my $startdate = $query->param('startdate');
157         my $periodicity = $query->param('periodicity');
158         my $dow = $query->param('dow');
159         my $numberlength = $query->param('numberlength');
160         my $weeklength = $query->param('weeklength');
161         my $monthlength = $query->param('monthlength');
162         my $add1 = $query->param('add1');
163         my $every1 = $query->param('every1');
164         my $whenmorethan1 = $query->param('whenmorethan1');
165         my $setto1 = $query->param('setto1');
166         my $lastvalue1 = $query->param('lastvalue1');
167         my $add2 = $query->param('add2');
168         my $every2 = $query->param('every2');
169         my $whenmorethan2 = $query->param('whenmorethan2');
170         my $setto2 = $query->param('setto2');
171         my $lastvalue2 = $query->param('lastvalue2');
172         my $add3 = $query->param('add3');
173         my $every3 = $query->param('every3');
174         my $whenmorethan3 = $query->param('whenmorethan3');
175         my $setto3 = $query->param('setto3');
176         my $lastvalue3 = $query->param('lastvalue3');
177         my $numberingmethod = $query->param('numberingmethod');
178         my $status = 1;
179         my $biblionumber = $query->param('biblionumber');
180         my $notes = $query->param('notes');
181         my $letter = $query->param('letter');
182         my $subscriptionid = newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
183                                         $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
184                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
185                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
186                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
187                                         $numberingmethod, $status, $notes, $letter
188                                 );
189         print $query->redirect("/cgi-bin/koha/bull/subscription-detail.pl?subscriptionid=$subscriptionid");
190 } else {
191         output_html_with_http_headers $query, $cookie, $template->output;
192 }