use C4::Auth;
use C4::Context;
use C4::Output;
-use C4::Charset;
+use C4::Interface::CGI::Output;
use C4::Search;
use HTML::Template;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
- my $query="select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundid like \"$data[0]%\") order by bookfundid";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundname like ?) order by bookfundid");
+ $sth->execute("%$data[0]%");
my @results;
- my $cnt=0;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
- $cnt ++;
}
# $sth->execute;
$sth->finish;
- return ($cnt,\@results);
+ return (scalar(@results),\@results);
}
my $input = new CGI;
my $header;
if ($bookfundid) {
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
- $sth->execute;
+ my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
+ $sth->execute($bookfundid);
$data=$sth->fetchrow_hashref;
$sth->finish;
}
$template->param(add_or_modify => $add_or_modify);
$template->param(bookfundid =>$bookfundid);
$template->param(bookfundname =>$data->{'bookfundname'});
- $template->param(bookfundgroup =>$data->{'bookfundgroup'});
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
my $bookfundid=uc($input->param('bookfundid'));
- my $query = "delete from aqbookfund where bookfundid ='$bookfundid'";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("delete from aqbookfund where bookfundid =?");
+ $sth->execute($bookfundid);
$sth->finish;
- $query = "replace aqbookfund (bookfundid,bookfundname,bookfundgroup) values (";
- $query.= $dbh->quote($input->param('bookfundid')).",";
- $query.= $dbh->quote($input->param('bookfundname')).",";
- $query.= $dbh->quote($input->param('bookfundgroup')).")";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("replace aqbookfund (bookfundid,bookfundname) values (?,?)");
+ $sth->execute($input->param('bookfundid'),$input->param('bookfundname'));
$sth->finish;
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# $sth->execute;
# my $total = $sth->fetchrow_hashref;
# $sth->finish;
- my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid='$bookfundid'");
- $sth->execute;
+ my $sth=$dbh->prepare("select bookfundid,bookfundname,bookfundgroup from aqbookfund where bookfundid=?");
+ $sth->execute($bookfundid);
my $data=$sth->fetchrow_hashref;
$sth->finish;
$template->param(bookfundid => $bookfundid);
$template->param(bookfundname => $data->{'bookfundname'});
- $template->param(bookfundgroup => $data->{'bookfundgroup'});
# END $OP eq DELETE_CONFIRM
################## DELETE_CONFIRMED ##################################
# called by delete_confirm, used to effectively confirm deletion of data in DB
} elsif ($op eq 'delete_confirmed') {
my $dbh = C4::Context->dbh;
my $bookfundid=uc($input->param('bookfundid'));
- my $query = "delete from aqbookfund where bookfundid='$bookfundid'";
- my $sth=$dbh->prepare($query);
- $sth->execute;
+ my $sth=$dbh->prepare("delete from aqbookfund where bookfundid=?");
+ $sth->execute($bookfundid);
+ $sth->finish;
+ $sth=$dbh->prepare("delete from aqbudget where bookfundid=?");
+ $sth->execute($bookfundid);
$sth->finish;
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
- $template->param(scriptname => $script_name);
- if ($searchfield ne '') {
+ $template->param(scriptname => $script_name);
+ if ($searchfield ne '') {
$template->param(search => 1);
$template->param(searchfield => $searchfield);
}
- my $env;
- my ($count,$results)=StringSearch($env,$searchfield,'web');
- my $toggle="white";
- my @loop_data =();
- for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
- #find out stats
- # my ($od,$issue,$fines)=categdata2($env,$results->[$i]{'borrowernumber'});
- # $fines=$fines+0;
- my @toggle = ();
- my @bookfundid = ();
- my @bookfundname = ();
- my @bookfundgroup = ();
- push(@toggle,$toggle);
- push(@bookfundid,$results->[$i]{'bookfundid'});
- push(@bookfundname,$results->[$i]{'bookfundname'});
- push(@bookfundgroup,$results->[$i]{'bookfundgroup'});
- if ($toggle eq 'white'){
- $toggle="#ffffcc";
- } else {
- $toggle="white";
- }
- while (@toggle and @bookfundid and @bookfundname and @bookfundgroup) {
- my %row_data;
- $row_data{toggle} = shift @toggle;
- $row_data{bookfundid} = shift @bookfundid;
- $row_data{bookfundname} = shift @bookfundname;
- $row_data{bookfundgroup} = shift @bookfundgroup;
- push(@loop_data, \%row_data);
- }
- }
- $template->param(bookfund => \@loop_data);
+ my $env;
+ my ($count,$results)=StringSearch($env,$searchfield,'web');
+ my $toggle="white";
+ my @loop_data =();
+ my $dbh = C4::Context->dbh;
+ my $sth2 = $dbh->prepare("Select aqbudgetid,startdate,enddate,budgetamount from aqbudget where bookfundid = ? order by bookfundid");
+ for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
+ my %row_data;
+ $row_data{bookfundid} =$results->[$i]{'bookfundid'};
+ $row_data{bookfundname} = $results->[$i]{'bookfundname'};
+ $sth2->execute($row_data{bookfundid});
+ my @budget_loop;
+ while (my ($aqbudgetid,$startdate,$enddate,$budgetamount) = $sth2->fetchrow) {
+ my %budgetrow_data;
+ $budgetrow_data{aqbudgetid} = $aqbudgetid;
+ $budgetrow_data{startdate} = $startdate;
+ $budgetrow_data{enddate} = $enddate;
+ $budgetrow_data{budgetamount} = $budgetamount;
+ push @budget_loop,\%budgetrow_data;
+ }
+ $row_data{budget} = \@budget_loop;
+ push @loop_data,\%row_data;
+ }
+ $template->param(bookfund => \@loop_data);
} #---- END $OP eq DEFAULT
-print $input->header(
- -type => guesstype($template->output),
- -cookie => $cookie
-), $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;