use strict;
use CGI;
use C4::Context;
-use C4::Output;
-use C4::Search;
-use HTML::Template;
use C4::Auth;
-use C4::Interface::CGI::Output;
+use C4::Dates qw(format_date);
+use C4::Output;
sub StringSearch {
- my ($env,$searchstring,$type)=@_;
+ my ($searchstring,$type)=@_;
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
- my $query="Select currency,rate from currency where (currency like \"$data[0]%\") order by currency";
+ my $query="Select * from currency where (currency like \"$data[0]%\") order by currency";
my $sth=$dbh->prepare($query);
$sth->execute;
my @results;
my $cnt=0;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
- $cnt ++;
+ $cnt++;
}
# $sth->execute;
$sth->finish;
my $input = new CGI;
my $searchfield=$input->param('searchfield');
-my $pkfield="currency";
-my $reqsel="select currency,rate from currency where $pkfield='$searchfield'";
-my $reqdel="delete from currency where $pkfield='$searchfield'";
#my $branchcode=$input->param('branchcode');
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/currency.pl";
$searchfield=~ s/\,//g;
my ($template, $loggedinuser, $cookie)
- = get_template_and_user({template_name => "parameters/currency.tmpl",
+ = get_template_and_user({template_name => "admin/currency.tmpl",
query => $input,
type => "intranet",
- authnotrequired => 0,
+ flagsrequired => {parameters => 1},
+ authnotrequired => 0,
debug => 1,
});
my $data;
if ($searchfield) {
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select currency,rate from currency where currency='$searchfield'");
- $sth->execute;
+ my $sth=$dbh->prepare("select * from currency where currency=?");
+ $sth->execute($searchfield);
$data=$sth->fetchrow_hashref;
$sth->finish;
}
-
- $template->param(currency => $data->{'currency'},
- rate => $data->{'rate'});
+ foreach (keys %$data) {
+ $template->param($_ => $data->{$_});
+ }
+ my $date = $template->param('timestamp');
+ ($date) and $template->param('timestamp' => format_date($date));
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
$check->execute($input->param('currency'));
if ( $check->fetchrow )
{
- my $sth = $dbh->prepare("UPDATE currency SET rate = ? WHERE currency = ?");
- $sth->execute($input->param('rate'),$input->param('currency'));
+ my $sth = $dbh->prepare("UPDATE currency SET rate = ?, symbol = ?, timestamp = ? WHERE currency = ?");
+ $sth->execute($input->param('rate'),$input->param('symbol'),C4::Dates->new->output('iso'),$input->param('currency'));
$sth->finish;
}
else
{
- my $sth = $dbh->prepare("INSERT INTO currency (currency, rate) VALUES (?,?)");
- $sth->execute($input->param('currency'),$input->param('rate'));
+ my $sth = $dbh->prepare("INSERT INTO currency (currency, rate, symbol) VALUES (?,?,?)");
+ $sth->execute($input->param('currency'),$input->param('rate'),$input->param('symbol'));
$sth->finish;
}
} elsif ($op eq 'delete_confirm') {
$template->param(delete_confirm => 1);
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select count(*) as total from aqbooksellers where currency='$searchfield'");
- $sth->execute;
+ my $sth=$dbh->prepare("select count(*) as total from aqbooksellers where currency=?");
+ $sth->execute($searchfield);
my $total = $sth->fetchrow_hashref;
$sth->finish;
- my $sth2=$dbh->prepare($reqsel);
- $sth2->execute;
+ my $sth2=$dbh->prepare("select currency,rate from currency where currency=?");
+ $sth2->execute($searchfield);
my $data=$sth2->fetchrow_hashref;
$sth2->finish;
} elsif ($op eq 'delete_confirmed') {
$template->param(delete_confirmed => 1);
my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare($reqdel);
- $sth->execute;
+ my $sth=$dbh->prepare("delete from currency where currency=?");
+ $sth->execute($searchfield);
$sth->finish;
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
$template->param(else => 1);
- my $env;
- my ($count,$results)=StringSearch($env,$searchfield,'web');
+ my ($count,$results)=StringSearch($searchfield,'web');
my @loop;
- my $toggle = 'white';
+ my $toggle = 0;
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
- my %row = ( currency => $results->[$i]{'currency'},
+ my %row = (
+ currency => $results->[$i]{'currency'},
rate => $results->[$i]{'rate'},
- toggle => $toggle);
+ symbol => $results->[$i]{'symbol'},
+ timestamp => format_date($results->[$i]{'timestamp'}),
+ );
+ ($i % 2) and $row{toggle} = 1;
push @loop, \%row;
-
- if ( $toggle eq 'white' )
- {
- $toggle = '#ffffcc';
- }
- else
- {
- $toggle = 'white';
- }
}
$template->param(loop => \@loop);
nextpage => $offset+$pagesize);
}
} #---- END $OP eq DEFAULT
-
output_html_with_http_headers $input, $cookie, $template->output;