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
46 * delete_confirm, then
47 - we delete the record having primkey=$primkey
54 use List
::Util qw
/min/;
55 use C4
::Branch
; # GetBranches
65 my $script_name = "/cgi-bin/koha/admin/aqbookfund.pl";
66 my $bookfundid = $input->param('bookfundid');
67 my $branchcodeid = $input->param('branchcode') || '';
68 my $op = $input->param('op') || '';
71 $bookfundid = uc $bookfundid if $bookfundid;
73 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
74 { template_name
=> "admin/aqbookfund.tmpl",
78 flagsrequired
=> { parameters
=> 1 },
84 action
=> $script_name,
85 script_name
=> $script_name,
89 my $branches = GetBranches
;
91 #-----############# ADD_FORM ##################################
92 # called by default. Used to create form to add or modify a record
93 if ($op eq 'add_form') {
94 #---- if primkey exists, it's a modify action, so read values to modify...
97 $dataaqbookfund = GetBookFund
($bookfundid, $branchcodeid);
98 $template->param('header-is-modify-p' => 1);
99 $template->param('current_branch' => $branchcodeid);
101 $template->param('header-is-add-p' => 1);
104 'use-header-flags-p' => 1,
105 add_or_modify
=> $bookfundid ?
1 : 0,
106 bookfundid
=> $bookfundid,
107 bookfundname
=> $dataaqbookfund->{'bookfundname'}
111 foreach my $branchcode (sort keys %{$branches}) {
113 branchcode
=> $branchcode,
114 branchname
=> $branches->{$branchcode}->{branchname
},
115 selected
=> (defined $bookfundid and defined $dataaqbookfund->{branchcode
}
116 and $dataaqbookfund->{branchcode
} eq $branchcode) ?
1 : 0,
120 $template->param(branches
=> \
@branchloop);
122 } # END $OP eq ADD_FORM
124 #-----############# ADD_VALIDATE ##################################
125 # called by add_form, used to insert/modify data in DB
126 elsif ($op eq 'add_validate') {
127 my $bookfundname = $input->param('bookfundname');
128 my $branchcode = $input->param('branchcode') || undef;
129 my $number = Countbookfund
($bookfundid,$branchcodeid);
133 $input->param('bookfundname'),
134 $input->param('branchcode')||''
137 print $input->redirect('aqbookfund.pl'); # FIXME: unnecessary redirect
139 # END $OP eq ADD_VALIDATE
142 #-----############# MOD_VALIDATE ##################################
143 # called by add_form, used to insert/modify data in DB
144 elsif ($op eq 'mod_validate') {
145 my $bookfundname = $input->param('bookfundname');
146 my $branchcode = $input->param('branchcode' ) || undef;
147 my $current_branch = $input->param('current_branch') || undef;
148 $debug and warn "$bookfundid, $bookfundname, $branchcode";
150 my $number = Countbookfund
($bookfundid,$branchcodeid);
152 $debug and warn "name :$bookfundname branch:$branchcode";
153 ModBookFund
($bookfundname,$bookfundid,$current_branch, $branchcode);
155 print $input->redirect('aqbookfund.pl'); # FIXME: unnecessary redirect
159 #-----############# DELETE_CONFIRM ##################################
160 # called by default form, used to confirm deletion of data in DB
161 elsif ($op eq 'delete_confirm') {
162 my $data = GetBookFund
($bookfundid,$branchcodeid);
163 $template->param(bookfundid
=> $bookfundid);
164 $template->param(bookfundname
=> $data->{'bookfundname'});
165 $template->param(branchcode
=> $data->{'branchcode'});
167 # called by delete_confirm, used to effectively confirm deletion of data in DB
168 elsif ($op eq 'delete_confirmed') {
169 DelBookFund
($bookfundid, $branchcodeid);
175 foreach my $branchcode (sort keys %{$branches}) {
178 name
=> $branches->{$branchcode}->{branchname
},
180 if (defined $input->param('filter_branchcode')
181 and $input->param('filter_branchcode') eq $branchcode) {
182 $row->{selected
} = 1;
184 push @branchloop, $row;
187 my @bookfundids_loop;
188 $sth = GetBookFundsId
();
190 while (my $row = $sth->fetchrow_hashref) {
191 if (defined $input->param('filter_bookfundid') and $input->param('filter_bookfundid') eq $row->{bookfundid
}){
192 $row->{selected
} = 1;
194 push @bookfundids_loop, $row;
198 filter_bookfundids
=> \
@bookfundids_loop,
199 filter_branches
=> \
@branchloop,
200 filter_bookfundname
=> $input->param('filter_bookfundname') || undef,
203 # searching the bookfunds corresponding to our filtering rules
204 my @results = SearchBookFund
(
205 $input->param('filter'),
206 $input->param('filter_bookfundid'),
207 $input->param('filter_bookfundname'),
208 $input->param('filter_branchcode'),
211 # does the book funds have budgets?
213 $sth = GetBookFundsId
();
214 while (my $row = $sth->fetchrow){
218 my ($id,%nb_budgets_of);
219 foreach $id (@loop_id){
220 my $number = Countbookfund
($id);
221 $nb_budgets_of{$id} = $number;
224 # pagination informations
225 my $page = $input->param('page') || 1;
228 my $first = ($page - 1) * $pagesize;
230 # if we are on the last page, the number of the last word to display
231 # must not exceed the length of the results array
233 $first + $pagesize - 1,
234 scalar(@results) - 1,
237 foreach my $result (@results[$first .. $last]) {
240 branchname
=> $branches->{ $result->{branchcode
} }->{branchname
},
241 has_budgets
=> defined $nb_budgets_of{ $result->{bookfundid
} },
247 pagination_bar
=> pagination_bar
(
249 getnbpages
(scalar @results, $pagesize),
256 output_html_with_http_headers
$input, $cookie, $template->output;