X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fcurrency.pl;h=145dc3f42bcf9175a770cc683cf1a8e02ab1a31a;hb=74cc235347896c35955d40d11f83eea0ea9f0436;hp=a7cf6066fc63d765ea8da9569095dc5fe6efb290;hpb=7457de546a44fbdf8cc62e92e0aeaef2ec0a9975;p=koha.git diff --git a/admin/currency.pl b/admin/currency.pl index a7cf6066fc..145dc3f42b 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -40,26 +40,24 @@ 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; @@ -77,7 +75,7 @@ my $op = $input->param('op'); $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", flagsrequired => {parameters => 1}, @@ -97,14 +95,16 @@ if ($op eq 'add_form') { my $data; if ($searchfield) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select currency,rate from currency where currency=?"); + 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 @@ -116,14 +116,14 @@ if ($op eq 'add_form') { $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; } @@ -163,24 +163,18 @@ if ($op eq 'add_form') { } 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); @@ -194,6 +188,5 @@ if ($op eq 'add_form') { nextpage => $offset+$pagesize); } } #---- END $OP eq DEFAULT - output_html_with_http_headers $input, $cookie, $template->output;