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 C4::Branch; # GetBranches
56 use List::Util qw/min/;
64 # use Smart::Comments;
66 my $dbh = C4::Context->dbh;
68 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
69 my $bookfundid=$input->param('bookfundid');
70 my $branchcodeid=$input->param('branchcode')|'';
72 my $op = $input->param('op') || '';
74 my ($template, $borrowernumber, $cookie)
75 = get_template_and_user(
76 {template_name => "admin/aqbookfund.tmpl",
80 flagsrequired => {parameters => 1},
87 script_name => $script_name,
89 ); # we show only the TMPL_VAR names $op
92 $template->param(script_name => $script_name,
93 else => 1); # we show only the TMPL_VAR names $op
95 $template->param(action => $script_name);
97 my $branches = GetBranches;
99 #-----############# ADD_FORM ##################################
100 # called by default. Used to create form to add or modify a record
101 if ($op eq 'add_form') {
102 #---- if primkey exists, it's a modify action, so read values to modify...
106 $dataaqbookfund = GetBookFund($bookfundid,$branchcodeid);
109 $header = "Modify book fund";
110 $template->param('header-is-modify-p' => 1);
111 $template->param('current_branch' => $branchcodeid);
113 $header = "Add book fund";
114 $template->param('header-is-add-p' => 1);
116 $template->param('use-header-flags-p' => 1);
117 $template->param(header => $header); # NOTE deprecated
122 $template->param(add_or_modify => $add_or_modify);
123 $template->param(bookfundid =>$bookfundid);
124 $template->param(bookfundname =>$dataaqbookfund->{'bookfundname'});
127 foreach my $branchcode (sort keys %{$branches}) {
129 branchcode => $branchcode,
130 branchname => $branches->{$branchcode}->{branchname},
133 if (defined $bookfundid
134 and defined $dataaqbookfund->{branchcode}
135 and $dataaqbookfund->{branchcode} eq $branchcode) {
136 $row->{selected} = 1;
139 push @branchloop, $row;
142 $template->param(branches => \@branchloop);
144 } # END $OP eq ADD_FORM
146 #-----############# ADD_VALIDATE ##################################
147 # called by add_form, used to insert/modify data in DB
148 elsif ($op eq 'add_validate') {
150 my $bookfundid = uc $input->param('bookfundid');
151 my $bookfundname = $input->param('bookfundname');
152 my $branchcode = $input->param('branchcode') || undef;
154 my $number = Countbookfund($bookfundid,$branchcodeid);
159 $input->param('bookfundname'),
160 $input->param('branchcode')||''
163 $input->redirect('aqbookfund.pl');
164 # END $OP eq ADD_VALIDATE
167 #-----############# MOD_VALIDATE ##################################
168 # called by add_form, used to insert/modify data in DB
169 elsif ($op eq 'mod_validate') {
170 ### mod ddddddddddddddddd
172 my $bookfundid = uc $input->param('bookfundid');
173 my $bookfundname = $input->param('bookfundname');
174 my $branchcode = $input->param('branchcode') || undef;
175 my $current_branch = $input->param('current_branch') || undef;
177 warn "$bookfundid, $bookfundname, $branchcode";
179 my $number = Countbookfund($bookfundid,$branchcodeid);
184 warn "name :$bookfundname branch:$branchcode";
185 ModBookFund($bookfundname,$bookfundid,$current_branch, $branchcode);
187 $input->redirect('aqbookfund.pl');
188 # END $OP eq ADD_VALIDATE
195 #-----############# DELETE_CONFIRM ##################################
196 # called by default form, used to confirm deletion of data in DB
198 elsif ($op eq 'delete_confirm') {
199 my $data = GetBookFund($bookfundid,$branchcodeid);
200 $template->param(bookfundid => $bookfundid);
201 $template->param(bookfundname => $data->{'bookfundname'});
202 $template->param(branchcode => $data->{'branchcode'});
203 } # END $OP eq DELETE_CONFIRM
206 #-----############# DELETE_CONFIRMED ##################################
207 # called by delete_confirm, used to effectively confirm deletion of data in DB
208 elsif ($op eq 'delete_confirmed') {
209 DelBookFund(uc($input->param('bookfundid')),$branchcodeid);
211 }# END $OP eq DELETE_CONFIRMED
214 #-----############# DEFAULT ##################################
218 $template->param(scriptname => $script_name);
222 foreach my $branchcode (sort keys %{$branches}) {
225 name => $branches->{$branchcode}->{branchname},
228 if (defined $input->param('filter_branchcode')
229 and $input->param('filter_branchcode') eq $branchcode) {
230 $row->{selected} = 1;
233 push @branchloop, $row;
236 my @bookfundids_loop;
237 my $sth = GetBookFundsId();
239 while (my $row = $sth->fetchrow_hashref) {
240 if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid}){
241 $row->{selected} = 1;
243 push @bookfundids_loop, $row;
247 filter_bookfundids => \@bookfundids_loop,
248 filter_branches => \@branchloop,
249 filter_bookfundname => $input->param('filter_bookfundname') || undef,
252 # searching the bookfunds corresponding to our filtering rules
253 my @results = SearchBookFund(
254 $input->param('filter'),
255 $input->param('filter_bookfundid'),
256 $input->param('filter_bookfundname'),
257 $input->param('filter_branchcode'),
260 # does the book funds have budgets?
262 my $sth = GetBookFundsId();
263 while (my $row = $sth->fetchrow){
267 my ($id,%nb_budgets_of);
268 foreach $id (@loop_id){
269 my $number = Countbookfund($id);
270 $nb_budgets_of{$id} = $number;
273 # pagination informations
274 my $page = $input->param('page') || 1;
277 my $first = ($page - 1) * $pagesize;
279 # if we are on the last page, the number of the last word to display
280 # must not exceed the length of the results array
282 $first + $pagesize - 1,
283 scalar(@results) - 1,
287 foreach my $result (@results[$first .. $last]) {
292 toggle => $toggle++%2,
294 $branches->{ $result->{branchcode} }->{branchname},
295 has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
302 pagination_bar => pagination_bar(
304 getnbpages(scalar @results, $pagesize),
309 } #---- END $OP eq DEFAULT
310 output_html_with_http_headers $input, $cookie, $template->output;