- $template->param( add_form => 1 );
-
- #---- if primkey exists, it's a modify action, so read values to modify...
- if ($curr) {
- my $curr_rec =
- $dbh->selectrow_hashref( 'select * from currency where currency=?',
- {}, $curr );
- for ( keys %{$curr_rec} ) {
- $template->param( $_ => $curr_rec->{$_} );
- }
- }
- my $date = $template->param('timestamp');
- if ($date) {
- $template->param( 'timestamp' => format_date($date) );
- }
-
- return;
-}
-
-sub add_validate {
- $template->param( add_validate => 1 );
-
- my $rec = {
- rate => $input->param('rate'),
- symbol => $input->param('symbol') || q{},
- active => $input->param('active') || 0,
- currency => $input->param('currency'),
- };
-
- if ( $rec->{active} == 1 ) {
- $dbh->do('UPDATE currency SET active = 0');
- }
-
- my ($row_count) = $dbh->selectrow_array(
- 'select count(*) as count from currency where currency = ?',
- {}, $input->param('currency') );
- if ($row_count) {
- $dbh->do(
-q|UPDATE currency SET rate = ?, symbol = ?, active = ? WHERE currency = ? |,
- {},
- $rec->{rate},
- $rec->{symbol},
- $rec->{active},
- $rec->{currency}
- );
- } else {
- $dbh->do(
-q|INSERT INTO currency (currency, rate, symbol, active) VALUES (?,?,?,?) |,
- {},
- $rec->{currency},
- $rec->{rate},
- $rec->{symbol},
- $rec->{active}
- );
-
- }
- return;
-}