diff --git a/admin/aqbookfund.pl b/admin/aqbookfund.pl index a577800ac1..29e626b37a 100755 --- a/admin/aqbookfund.pl +++ b/admin/aqbookfund.pl @@ -52,18 +52,15 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $query="select bookfundid,bookfundname,bookfundgroup from aqbookfund where (bookfundname 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; @@ -102,8 +99,8 @@ if ($op eq 'add_form') { 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; } @@ -127,15 +124,11 @@ if ($op eq 'add_form') { } 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) values ("; - $query.= $dbh->quote($input->param('bookfundid')).","; - $query.= $dbh->quote($input->param('bookfundname')).")"; - 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 ################################## @@ -146,8 +139,8 @@ if ($op eq 'add_form') { # $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); @@ -158,10 +151,11 @@ if ($op eq 'add_form') { } 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; - $dbh->do("delete from aqbudget where bookfundid='$bookfundid'"); + 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 ################################## diff --git a/admin/branches.pl b/admin/branches.pl index 49f198bb2f..42c3d66561 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -353,20 +353,17 @@ sub getbranchinfo { my ($branchcode) = @_; my $dbh = C4::Context->dbh; - my ($query, @query_args); + my $sth; if ($branchcode) { - $query = "Select * from branches where branchcode = ?"; - @query_args = ($branchcode); + $sth = $dbh->prepare("Select * from branches where branchcode = ? order by branchcode"); + $sth->execute($branchcode); } else { - $query = "Select * from branches"; + $sth = $dbh->prepare("Select * from branches order by branchcode"); + $sth->execute(); } - $query.=" order by branchcode"; - my $sth = $dbh->prepare($query); - $sth->execute(@query_args); my @results; while (my $data = $sth->fetchrow_hashref) { - $query = "select categorycode from branchrelations where branchcode = ?"; - my $nsth = $dbh->prepare($query); + my $nsth = $dbh->prepare("select categorycode from branchrelations where branchcode = ?"); $nsth->execute($data->{'branchcode'});; my @cats = (); while (my ($cat) = $nsth->fetchrow_array) { @@ -385,17 +382,15 @@ sub getcategoryinfo { # returns a reference to an array of hashes containing branches, my ($catcode) = @_; my $dbh = C4::Context->dbh; - my ($query, @query_args); + my $sth; # print DEBUG "getcategoryinfo: entry: catcode=".cvs($catcode)."\n"; if ($catcode) { - $query = "select * from branchcategories where categorycode = ?"; - @query_args = ($catcode); + $sth = $dbh->prepare("select * from branchcategories where categorycode = ?"); + $sth->execute($catcode); } else { - $query = "Select * from branchcategories"; + $sth = $dbh->prepare("Select * from branchcategories"); + $sth->execute(); } - # print DEBUG "getcategoryinfo: query=".cvs($query)."\n"; - my $sth = $dbh->prepare($query); - $sth->execute(@query_args); my @results; while (my $data = $sth->fetchrow_hashref) { push(@results, $data); @@ -410,8 +405,7 @@ sub setbranchinfo { # sets the data from the editbranch form, and writes to the database... my ($data) = @_; my $dbh = C4::Context->dbh; - my $query = "replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail) values (?,?,?,?,?,?,?,?)"; - my $sth=$dbh->prepare($query); + my $sth=$dbh->prepare("replace branches (branchcode,branchname,branchaddress1,branchaddress2,branchaddress3,branchphone,branchfax,branchemail) values (?,?,?,?,?,?,?,?)"); $sth->execute(uc($data->{'branchcode'}), $data->{'branchname'}, $data->{'branchaddress1'}, $data->{'branchaddress2'}, $data->{'branchaddress3'}, $data->{'branchphone'}, @@ -443,17 +437,13 @@ sub setbranchinfo { push(@addcats, $ccat); } } - # FIXME - There's already a $dbh in this scope. - my $dbh = C4::Context->dbh; foreach my $cat (@addcats) { - my $query = "insert into branchrelations (branchcode, categorycode) values(?, ?)"; - my $sth = $dbh->prepare($query); + my $sth = $dbh->prepare("insert into branchrelations (branchcode, categorycode) values(?, ?)"); $sth->execute($branchcode, $cat); $sth->finish; } foreach my $cat (@removecats) { - my $query = "delete from branchrelations where branchcode=? and categorycode=?"; - my $sth = $dbh->prepare($query); + my $sth = $dbh->prepare("delete from branchrelations where branchcode=? and categorycode=?"); $sth->execute($branchcode, $cat); $sth->finish; } @@ -462,9 +452,8 @@ sub setbranchinfo { sub deletebranch { # delete branch... my ($branchcode) = @_; - my $query = "delete from branches where branchcode = ?"; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare($query); + my $sth=$dbh->prepare("delete from branches where branchcode = ?"); $sth->execute($branchcode); $sth->finish; } @@ -473,8 +462,7 @@ sub setcategoryinfo { # sets the data from the editbranch form, and writes to the database... my ($data) = @_; my $dbh = C4::Context->dbh; - my $query = "replace branchcategories (categorycode,categoryname,codedescription) values (?,?,?)"; - my $sth=$dbh->prepare($query); + my $sth=$dbh->prepare("replace branchcategories (categorycode,categoryname,codedescription) values (?,?,?)"); $sth->execute(uc($data->{'categorycode'}), $data->{'categoryname'},$data->{'codedescription'}); $sth->finish; @@ -482,9 +470,8 @@ sub setcategoryinfo { sub deletecategory { # delete branch... my ($categorycode) = @_; - my $query = "delete from branchcategories where categorycode = ?"; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare($query); + my $sth=$dbh->prepare("delete from branchcategories where categorycode = ?"); $sth->execute($categorycode); $sth->finish; } diff --git a/admin/categorie.pl b/admin/categorie.pl index c3eec264b7..6bffa9da1a 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -51,18 +51,15 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $query="Select * from categories where (description like \"$data[0]%\")"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("Select * from categories where (description like ?)"); + $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; @@ -70,7 +67,6 @@ my $searchfield=$input->param('description'); my $script_name="/cgi-bin/koha/admin/categorie.pl"; my $categorycode=$input->param('categorycode'); my $op = $input->param('op'); -$searchfield=~ s/\,//g; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "parameters/categorie.tmpl", @@ -96,8 +92,8 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode='$categorycode'"); - $sth->execute; + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode=?"); + $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; } @@ -116,18 +112,8 @@ if ($op eq 'add_form') { } elsif ($op eq 'add_validate') { $template->param(add_validate => 1); my $dbh = C4::Context->dbh; - my $query = "replace categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired) values ("; - $query.= $dbh->quote($input->param('categorycode')).","; - $query.= $dbh->quote($input->param('description')).","; - $query.= $dbh->quote($input->param('enrolmentperiod')).","; - $query.= $dbh->quote($input->param('upperagelimit')).","; - $query.= $dbh->quote($input->param('dateofbirthrequired')).","; - $query.= $dbh->quote($input->param('enrolmentfee')).","; - $query.= $dbh->quote($input->param('issuelimit')).","; - $query.= $dbh->quote($input->param('reservefee')).","; - $query.= $dbh->quote($input->param('overduenoticerequired')).")"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("replace categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired) values (?,?,?,?,?,?,?,?,?)"); + $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','issuelimit','reservefee','overduenoticerequired')); $sth->finish; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## @@ -136,14 +122,14 @@ if ($op eq 'add_form') { $template->param(delete_confirm => 1); my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select count(*) as total from categoryitem where categorycode='$categorycode'"); - $sth->execute; + my $sth=$dbh->prepare("select count(*) as total from categoryitem where categorycode=?"); + $sth->execute($categorycode); my $total = $sth->fetchrow_hashref; $sth->finish; $template->param(total => $total->{'total'}); - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode='$categorycode'"); - $sth2->execute; + my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode=?"); + $sth2->execute($categorycode); my $data=$sth2->fetchrow_hashref; $sth2->finish; if ($total->{'total'} >0) { @@ -167,9 +153,8 @@ if ($op eq 'add_form') { $template->param(delete_confirmed => 1); my $dbh = C4::Context->dbh; my $categorycode=uc($input->param('categorycode')); - my $query = "delete from categories where categorycode='$categorycode'"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("delete from categories where categorycode=?"); + $sth->execute($categorycode); $sth->finish; # END $OP eq DELETE_CONFIRMED } else { # DEFAULT diff --git a/admin/categoryitem.pl b/admin/categoryitem.pl index ec44263831..0ba3caeafd 100644 --- a/admin/categoryitem.pl +++ b/admin/categoryitem.pl @@ -52,18 +52,15 @@ sub StringSearch { $searchstring=~ s/\'/\\\'/g; my @data=split(' ',$searchstring); my $count=@data; - my $query="Select * from categories where (description like \"$data[0]%\")"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("Select * from categories where (description like ?)"); + $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; @@ -95,8 +92,8 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode='$categorycode'"); - $sth->execute; + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired from categories where categorycode=?"); + $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; } @@ -120,20 +117,8 @@ if ($op eq 'add_form') { } elsif ($op eq 'add_validate') { $template->param(add_validate => 1); my $dbh = C4::Context->dbh; - my $query = "replace categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired) values ("; - $query.= $dbh->quote($input->param('categorycode')).","; - $query.= $dbh->quote($input->param('description')).","; - $query.= $dbh->quote($input->param('enrolmentperiod')).","; - $query.= $dbh->quote($input->param('upperagelimit')).","; - $query.= $dbh->quote($input->param('dateofbirthrequired')).","; - $query.= $dbh->quote($input->param('finetype')).","; - $query.= $dbh->quote($input->param('bulk')).","; - $query.= $dbh->quote($input->param('enrolmentfee')).","; - $query.= $dbh->quote($input->param('issuelimit')).","; - $query.= $dbh->quote($input->param('reservefee')).","; - $query.= $dbh->quote($input->param('overduenoticerequired')).")"; - my $sth=$dbh->prepare($query); - $sth->execute; + my $sth=$dbh->prepare("replace categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,finetype,bulk,enrolmentfee,issuelimit,reservefee,overduenoticerequired) values (?,?,?,?,?,?,?,?,?,?,?)"); + $sth->execute(map {$input->param($_)} ('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','finetype','bulk','enrolmentfee','issuelimit','reservefee','overduenoticerequired')); $sth->finish; print "data recorded"; print "