3 #written 20/02/2002 by paul.poulain@free.fr
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA 02111-1307 USA
29 script to administer the aqbudget table.
36 this script use an C<$op> to know what to do.
37 C<op> can be equal to:
38 * empty or none of the above values, then
39 - the default screen is build (with all records, or filtered datas).
40 - the user can clic on add, modify or delete record.
42 - if primkey exists, this is a modification,so we read the $primkey record
43 - builds the add/modify form
45 - the user has just send datas, so we create/modify the record
47 - we show the record having primkey=$primkey and ask for deletion validation form
48 * delete_confirm, then
49 - we delete the record having primkey=$primkey
55 use List::Util qw/min/;
56 use C4::Branch; # GetBranches
65 # use Smart::Comments;
67 my $dbh = C4::Context->dbh;
69 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
70 my $bookfundid=$input->param('bookfundid');
71 my $branchcodeid=$input->param('branchcode')|'';
73 my $op = $input->param('op') || '';
75 my ($template, $borrowernumber, $cookie)
76 = get_template_and_user(
77 {template_name => "admin/aqbookfund.tmpl",
81 flagsrequired => {parameters => 1},
88 script_name => $script_name,
90 ); # we show only the TMPL_VAR names $op
93 $template->param(script_name => $script_name,
94 else => 1); # we show only the TMPL_VAR names $op
96 $template->param(action => $script_name);
98 my $branches = GetBranches;
100 #-----############# ADD_FORM ##################################
101 # called by default. Used to create form to add or modify a record
102 if ($op eq 'add_form') {
103 #---- if primkey exists, it's a modify action, so read values to modify...
107 $dataaqbookfund = GetBookFund($bookfundid,$branchcodeid);
110 $header = "Modify book fund";
111 $template->param('header-is-modify-p' => 1);
112 $template->param('current_branch' => $branchcodeid);
114 $header = "Add book fund";
115 $template->param('header-is-add-p' => 1);
117 $template->param('use-header-flags-p' => 1);
118 $template->param(header => $header); # NOTE deprecated
123 $template->param(add_or_modify => $add_or_modify);
124 $template->param(bookfundid =>$bookfundid);
125 $template->param(bookfundname =>$dataaqbookfund->{'bookfundname'});
128 foreach my $branchcode (sort keys %{$branches}) {
130 branchcode => $branchcode,
131 branchname => $branches->{$branchcode}->{branchname},
134 if (defined $bookfundid
135 and defined $dataaqbookfund->{branchcode}
136 and $dataaqbookfund->{branchcode} eq $branchcode) {
137 $row->{selected} = 1;
140 push @branchloop, $row;
143 $template->param(branches => \@branchloop);
145 } # END $OP eq ADD_FORM
147 #-----############# ADD_VALIDATE ##################################
148 # called by add_form, used to insert/modify data in DB
149 elsif ($op eq 'add_validate') {
151 my $bookfundid = uc $input->param('bookfundid');
152 my $bookfundname = $input->param('bookfundname');
153 my $branchcode = $input->param('branchcode') || undef;
155 my $number = Countbookfund($bookfundid,$branchcodeid);
160 $input->param('bookfundname'),
161 $input->param('branchcode')||''
164 $input->redirect('aqbookfund.pl');
165 # END $OP eq ADD_VALIDATE
168 #-----############# MOD_VALIDATE ##################################
169 # called by add_form, used to insert/modify data in DB
170 elsif ($op eq 'mod_validate') {
171 my $bookfundid = uc $input->param('bookfundid');
172 my $bookfundname = $input->param('bookfundname');
173 my $branchcode = $input->param('branchcode' ) || undef;
174 my $current_branch = $input->param('current_branch') || undef;
175 $debug and warn "$bookfundid, $bookfundname, $branchcode";
177 my $number = Countbookfund($bookfundid,$branchcodeid);
179 $debug and warn "name :$bookfundname branch:$branchcode";
180 ModBookFund($bookfundname,$bookfundid,$current_branch, $branchcode);
182 $input->redirect('aqbookfund.pl');
185 #-----############# DELETE_CONFIRM ##################################
186 # called by default form, used to confirm deletion of data in DB
187 elsif ($op eq 'delete_confirm') {
188 my $data = GetBookFund($bookfundid,$branchcodeid);
189 $template->param(bookfundid => $bookfundid);
190 $template->param(bookfundname => $data->{'bookfundname'});
191 $template->param(branchcode => $data->{'branchcode'});
192 } # END $OP eq DELETE_CONFIRM
194 #-----############# DELETE_CONFIRMED ##################################
195 # called by delete_confirm, used to effectively confirm deletion of data in DB
196 elsif ($op eq 'delete_confirmed') {
197 DelBookFund(uc($input->param('bookfundid')),$branchcodeid);
199 }# END $OP eq DELETE_CONFIRMED
201 #-----############# DEFAULT ##################################
205 $template->param(scriptname => $script_name);
209 foreach my $branchcode (sort keys %{$branches}) {
212 name => $branches->{$branchcode}->{branchname},
214 if (defined $input->param('filter_branchcode')
215 and $input->param('filter_branchcode') eq $branchcode) {
216 $row->{selected} = 1;
218 push @branchloop, $row;
221 my @bookfundids_loop;
222 $sth = GetBookFundsId();
224 while (my $row = $sth->fetchrow_hashref) {
225 if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid}){
226 $row->{selected} = 1;
228 push @bookfundids_loop, $row;
232 filter_bookfundids => \@bookfundids_loop,
233 filter_branches => \@branchloop,
234 filter_bookfundname => $input->param('filter_bookfundname') || undef,
237 # searching the bookfunds corresponding to our filtering rules
238 my @results = SearchBookFund(
239 $input->param('filter'),
240 $input->param('filter_bookfundid'),
241 $input->param('filter_bookfundname'),
242 $input->param('filter_branchcode'),
245 # does the book funds have budgets?
247 $sth = GetBookFundsId();
248 while (my $row = $sth->fetchrow){
252 my ($id,%nb_budgets_of);
253 foreach $id (@loop_id){
254 my $number = Countbookfund($id);
255 $nb_budgets_of{$id} = $number;
258 # pagination informations
259 my $page = $input->param('page') || 1;
262 my $first = ($page - 1) * $pagesize;
264 # if we are on the last page, the number of the last word to display
265 # must not exceed the length of the results array
267 $first + $pagesize - 1,
268 scalar(@results) - 1,
271 foreach my $result (@results[$first .. $last]) {
277 $branches->{ $result->{branchcode} }->{branchname},
278 has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
285 pagination_bar => pagination_bar(
287 getnbpages(scalar @results, $pagesize),
292 } #---- END $OP eq DEFAULT
293 output_html_with_http_headers $input, $cookie, $template->output;