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 my $dbh = C4::Context->dbh;
66 my $script_name="/cgi-bin/koha/admin/aqbookfund.pl";
67 my $bookfundid=$input->param('bookfundid');
68 my $branchcodeid=$input->param('branchcode')|'';
70 my $op = $input->param('op') || '';
72 my ($template, $borrowernumber, $cookie)
73 = get_template_and_user(
74 {template_name => "admin/aqbookfund.tmpl",
78 flagsrequired => {parameters => 1},
85 script_name => $script_name,
87 ); # we show only the TMPL_VAR names $op
90 $template->param(script_name => $script_name,
91 else => 1); # we show only the TMPL_VAR names $op
93 $template->param(action => $script_name);
95 my $branches = GetBranches;
97 ################## ADD_FORM ##################################
98 # called by default. Used to create form to add or modify a record
99 if ($op eq 'add_form') {
100 #---- if primkey exists, it's a modify action, so read values to modify...
104 $dataaqbookfund = GetBookFund($bookfundid,$branchcodeid);
107 $header = "Modify book fund";
108 $template->param('header-is-modify-p' => 1);
110 $header = "Add book fund";
111 $template->param('header-is-add-p' => 1);
113 $template->param('use-header-flags-p' => 1);
114 $template->param(header => $header); # NOTE deprecated
119 $template->param(add_or_modify => $add_or_modify);
120 $template->param(bookfundid =>$bookfundid);
121 $template->param(bookfundname =>$dataaqbookfund->{'bookfundname'});
124 foreach my $branchcode (sort keys %{$branches}) {
126 branchcode => $branchcode,
127 branchname => $branches->{$branchcode}->{branchname},
130 if (defined $bookfundid
131 and defined $dataaqbookfund->{branchcode}
132 and $dataaqbookfund->{branchcode} eq $branchcode) {
133 $row->{selected} = 1;
136 push @branchloop, $row;
139 $template->param(branches => \@branchloop);
141 } # END $OP eq ADD_FORM
143 ################## ADD_VALIDATE ##################################
144 # called by add_form, used to insert/modify data in DB
145 elsif ($op eq 'add_validate') {
146 my $bookfundid = uc $input->param('bookfundid');
148 my $number = Countbookfund($bookfundid,$branchcodeid);
150 my $bookfund_already_exists = $number > 0 ? 1 : 0;
152 if ($bookfund_already_exists) {
153 my $bookfundname = $input->param('bookfundname');
154 my $branchcode = $input->param('branchcode') || undef;
155 warn "name :$bookfundname branch:$branchcode";
156 ModBookFund($bookfundname,$bookfundid,$branchcode);
161 $input->param('bookfundname'),
162 $input->param('branchcode')||''
165 $input->redirect('aqbookfund.pl');
166 # END $OP eq ADD_VALIDATE
168 ################## DELETE_CONFIRM ##################################
169 # called by default form, used to confirm deletion of data in DB
171 elsif ($op eq 'delete_confirm') {
172 my $data = GetBookFund($bookfundid,$branchcodeid);
173 $template->param(bookfundid => $bookfundid);
174 $template->param(bookfundname => $data->{'bookfundname'});
175 $template->param(branchcode => $data->{'branchcode'});
176 } # END $OP eq DELETE_CONFIRM
179 ################## DELETE_CONFIRMED ##################################
180 # called by delete_confirm, used to effectively confirm deletion of data in DB
181 elsif ($op eq 'delete_confirmed') {
182 DelBookFund(uc($input->param('bookfundid')),$branchcodeid);
184 }# END $OP eq DELETE_CONFIRMED
187 ################## DEFAULT ##################################
191 $template->param(scriptname => $script_name);
195 foreach my $branchcode (sort keys %{$branches}) {
198 name => $branches->{$branchcode}->{branchname},
201 if (defined $input->param('filter_branchcode')
202 and $input->param('filter_branchcode') eq $branchcode) {
203 $row->{selected} = 1;
206 push @branchloop, $row;
209 my @bookfundids_loop;
210 my $sth = GetBookFundsId();
212 while (my $row = $sth->fetchrow_hashref) {
213 if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid}){
214 $row->{selected} = 1;
216 push @bookfundids_loop, $row;
220 filter_bookfundids => \@bookfundids_loop,
221 filter_branches => \@branchloop,
222 filter_bookfundname => $input->param('filter_bookfundname') || undef,
225 # searching the bookfunds corresponding to our filtering rules
226 my @results = SearchBookFund(
227 $input->param('filter'),
228 $input->param('filter_bookfundid'),
229 $input->param('filter_bookfundname'),
230 $input->param('filter_branchcode'),
233 # does the book funds have budgets?
235 my $sth = GetBookFundsId();
236 while (my $row = $sth->fetchrow){
240 my ($id,%nb_budgets_of);
241 foreach $id (@loop_id){
242 my $number = Countbookfund($id);
243 $nb_budgets_of{$id} = $number;
246 # pagination informations
247 my $page = $input->param('page') || 1;
250 my $first = ($page - 1) * $pagesize;
252 # if we are on the last page, the number of the last word to display
253 # must not exceed the length of the results array
255 $first + $pagesize - 1,
256 scalar(@results) - 1,
260 foreach my $result (@results[$first .. $last]) {
265 toggle => $toggle++%2,
267 $branches->{ $result->{branchcode} }->{branchname},
268 has_budgets => defined $nb_budgets_of{ $result->{bookfundid} },
275 pagination_bar => pagination_bar(
277 getnbpages(scalar @results, $pagesize),
282 } #---- END $OP eq DEFAULT
284 intranetcolorstylesheet =>C4::Context->preference("intranetcolorstylesheet"),
285 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
286 IntranetNav => C4::Context->preference("IntranetNav"),
289 output_html_with_http_headers $input, $cookie, $template->output;