From 5e78bc9a077e0f3c45f8a1e9c485d5dcf7131cc4 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Thu, 3 Jan 2008 18:20:37 -0600 Subject: [PATCH] currency expansion - symbol and timestamp. PLEASE VERIFY SQL edit. Should be equivalent to: ALTER TABLE `currency` ADD `symbol` varchar(5) default NULL, ADD `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP; Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- admin/currency.pl | 42 +++++++++---------- installer/data/mysql/kohastructure.sql | 2 + .../prog/en/modules/admin/currency.tmpl | 42 ++++++++++++------- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/admin/currency.pl b/admin/currency.pl index 414063552e..145dc3f42b 100755 --- a/admin/currency.pl +++ b/admin/currency.pl @@ -41,6 +41,7 @@ use strict; use CGI; use C4::Context; use C4::Auth; +use C4::Dates qw(format_date); use C4::Output; sub StringSearch { @@ -49,14 +50,14 @@ sub StringSearch { $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; @@ -94,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 @@ -113,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; } @@ -162,21 +165,16 @@ if ($op eq 'add_form') { 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); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d19aa05cc5..466a0d8a70 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -656,6 +656,8 @@ CREATE TABLE `class_sources` ( DROP TABLE IF EXISTS `currency`; CREATE TABLE `currency` ( `currency` varchar(10) NOT NULL default '', + `symbol` varchar(5) default NULL, + `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `rate` float(7,5) default NULL, PRIMARY KEY (`currency`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl index 6ad6e6a2b3..d1fa60da2c 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/currency.tmpl @@ -6,6 +6,9 @@ Currency Deleted Currencies +