3 #script to administer the aqbudget table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
47 use C4::Interface::CGI::Output;
52 my ($env,$searchstring,$type)=@_;
53 my $dbh = C4::Context->dbh;
54 $searchstring=~ s/\'/\\\'/g;
55 my @data=split(' ',$searchstring);
57 my $sth=$dbh->prepare("Select aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget where (bookfundid like ?) order by bookfundid,aqbudgetid");
58 $sth->execute("$data[0]%");
61 while (my $data=$sth->fetchrow_hashref){
67 return ($cnt,\@results);
71 my $searchfield=$input->param('searchfield');
72 my $offset=$input->param('offset');
73 my $script_name="/cgi-bin/koha/admin/aqbudget.pl";
74 my $bookfundid=$input->param('bookfundid');
75 my $aqbudgetid=$input->param('aqbudgetid');
77 my $op = $input->param('op');
78 $searchfield=~ s/\,//g;
80 my ($template, $borrowernumber, $cookie)
81 = get_template_and_user({template_name => "parameters/aqbudget.tmpl",
85 flagsrequired => {parameters => 1},
90 $template->param(script_name => $script_name,
91 $op => 1); # 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
97 $template->param(action => $script_name);
99 my $dbh = C4::Context->dbh;
100 my $sthtemp = $dbh->prepare("Select flags, branchcode from borrowers where borrowernumber = ?");
101 $sthtemp->execute($borrowernumber);
102 my ($flags, $homebranch)=$sthtemp->fetchrow;
104 ################## ADD_FORM ##################################
105 # called by default. Used to create form to add or modify a record
106 if ($op eq 'add_form') {
107 #---- if primkey exists, it's a modify action, so read values to modify...
111 my $dbh = C4::Context->dbh;
112 my $sth=$dbh->prepare("select aqbudgetid,bookfundname,aqbookfund.bookfundid,startdate,enddate,budgetamount,aqbudget.branchcode from aqbudget,aqbookfund where aqbudgetid=? and aqbudget.bookfundid=aqbookfund.bookfundid");
113 $sth->execute($aqbudgetid);
114 $dataaqbudget=$sth->fetchrow_hashref;
119 $header = "Modify budget";
121 $header = "Add budget";
123 $template->param(header => $header);
125 $template->param(modify => 1);
126 $template->param(bookfundid => $dataaqbudget->{bookfundid});
127 $template->param(bookfundname => $dataaqbudget->{bookfundname});
129 $template->param(bookfundid => $bookfundid,
135 my ($count2,@branches)=branches();
136 push @select_branch,"";
137 $select_branches{""}="";
140 push @select_branch, $homebranch;#
141 for (my $i=0;$i<$count2;$i++){
142 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'} if ($branches[$i]->{'branchcode'} eq $homebranch);
146 for (my $i=0;$i<$count2;$i++){
147 push @select_branch, $branches[$i]->{'branchcode'};#
148 $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'};
151 my $CGIbranch=CGI::scrolling_list( -name => 'branchcode',
152 -values => \@select_branch,
153 -labels => \%select_branches,
154 -default => $dataaqbudget->{branchcode},
157 $template->param(CGIbranch => $CGIbranch);
158 $template->param(dateformat => display_date_format(),
159 aqbudgetid => $dataaqbudget->{'aqbudgetid'},
160 startdate => format_date($dataaqbudget->{'startdate'}),
161 enddate => format_date($dataaqbudget->{'enddate'}),
162 budgetamount => $dataaqbudget->{'budgetamount'}
164 # END $OP eq ADD_FORM
165 ################## ADD_VALIDATE ##################################
166 # called by add_form, used to insert/modify data in DB
167 } elsif ($op eq 'add_validate') {
168 my $dbh = C4::Context->dbh;
169 my $sth=$dbh->prepare("replace aqbudget (aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode) values (?,?,?,?,?,?)");
170 $sth->execute($input->param('aqbudgetid'),$input->param('bookfundid'),
171 format_date_in_iso($input->param('startdate')),
172 format_date_in_iso($input->param('enddate')),
173 $input->param('budgetamount'),
174 $input->param('branchcode')
177 print $input->redirect("aqbookfund.pl");
179 # END $OP eq ADD_VALIDATE
180 ################## DELETE_CONFIRM ##################################
181 # called by default form, used to confirm deletion of data in DB
182 } elsif ($op eq 'delete_confirm') {
183 my $dbh = C4::Context->dbh;
184 my $sth=$dbh->prepare("select aqbudgetid,bookfundid,startdate,enddate,budgetamount,branchcode from aqbudget where aqbudgetid=?");
185 $sth->execute($aqbudgetid);
186 my $data=$sth->fetchrow_hashref;
188 $template->param(bookfundid => $bookfundid);
189 $template->param(aqbudgetid => $data->{'aqbudgetid'});
190 $template->param(startdate => format_date($data->{'startdate'}));
191 $template->param(enddate => format_date($data->{'enddate'}));
192 $template->param(budgetamount => $data->{'budgetamount'});
193 # 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 my $dbh = C4::Context->dbh;
198 my $aqbudgetid=uc($input->param('aqbudgetid'));
199 my $sth=$dbh->prepare("delete from aqbudget where aqbudgetid=?");
200 $sth->execute($aqbudgetid);
202 print $input->redirect("aqbookfund.pl");
204 # END $OP eq DELETE_CONFIRMED
205 ################## DEFAULT ##################################
207 if ($searchfield ne '') {
208 $template->param(search => 1);
209 $template->param(searchfield => $searchfield);
212 my ($count,$results)=StringSearch($env,$searchfield,'web');
215 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
217 # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
220 my $dbh = C4::Context->dbh;
221 my $sth=$dbh->prepare("select bookfundid,bookfundname from aqbookfund where bookfundid=?");
222 $sth->execute($results->[$i]{'bookfundid'});
223 $dataaqbookfund=$sth->fetchrow_hashref;
227 my @bookfundname = ();
230 my @budgetamount = ();
231 push(@toggle,$toggle);
232 push(@bookfundid,$results->[$i]{'bookfundid'});
233 push(@bookfundname,$dataaqbookfund->{'bookfundname'});
234 push(@startdate,format_date($results->[$i]{'startdate'}));
235 push(@enddate,format_date($results->[$i]{'enddate'}));
236 push(@budgetamount,$results->[$i]{'budgetamount'});
237 if ($toggle eq 'white'){
242 while (@toggle and @bookfundid and @bookfundname and @startdate and @enddate and @budgetamount) {
244 $row_data{toggle} = shift @toggle;
245 $row_data{bookfundid} = shift @bookfundid;
246 $row_data{bookfundname} = shift @bookfundname;
247 $row_data{startdate} = shift @startdate;
248 $row_data{enddate} = shift @enddate;
249 $row_data{budgetamount} = shift @budgetamount;
250 push(@loop_data, \%row_data);
253 $template->param(budget => \@loop_data);
254 } #---- END $OP eq DEFAULT
256 output_html_with_http_headers $input, $cookie, $template->output;