- script_name => $script_name);
-
-
-################## ADD_FORM ##################################
-# called by default. Used to create form to add or modify a record
-if ($op eq 'add_form') {
- $template->param(add_form => 1);
- #---- if primkey exists, it's a modify action, so read values to modify...
- my $data;
- if ($searchfield) {
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select currency,rate from currency where currency=?");
- $sth->execute($searchfield);
- $data=$sth->fetchrow_hashref;
- $sth->finish;
- }
-
- $template->param(currency => $data->{'currency'},
- rate => $data->{'rate'});
- # END $OP eq ADD_FORM
-################## ADD_VALIDATE ##################################
-# called by add_form, used to insert/modify data in DB
-} elsif ($op eq 'add_validate') {
- $template->param(add_validate => 1);
- my $dbh = C4::Context->dbh;
-
- my $check = $dbh->prepare("select * from currency where currency = ?");
- $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'));
- $sth->finish;
- }
- else
- {
- my $sth = $dbh->prepare("INSERT INTO currency (currency, rate) VALUES (?,?)");
- $sth->execute($input->param('currency'),$input->param('rate'));
- $sth->finish;
- }
-
- $check->finish;
- # END $OP eq ADD_VALIDATE
-################## DELETE_CONFIRM ##################################
-# called by default form, used to confirm deletion of data in DB
-} 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=?");
- $sth->execute($searchfield);
- my $total = $sth->fetchrow_hashref;
- $sth->finish;
- my $sth2=$dbh->prepare("select currency,rate from currency where currency=?");
- $sth2->execute($searchfield);
- my $data=$sth2->fetchrow_hashref;
- $sth2->finish;
-
- if ($total->{'total'} >0) {
- $template->param(totalgtzero => 1);
- }
-
- $template->param(rate => $data->{'rate'},
- total => $total);
- # END $OP eq DELETE_CONFIRM
-################## DELETE_CONFIRMED ##################################
-# called by delete_confirm, used to effectively confirm deletion of data in DB
-} elsif ($op eq 'delete_confirmed') {
- $template->param(delete_confirmed => 1);
- my $dbh = C4::Context->dbh;
- 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 @loop;
- my $toggle = 'white';
- for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
- my %row = ( currency => $results->[$i]{'currency'},
- rate => $results->[$i]{'rate'},
- toggle => $toggle);
- push @loop, \%row;
-
- if ( $toggle eq 'white' )
- {
- $toggle = '#ffffcc';
- }
- else
- {
- $toggle = 'white';
- }
- }
- $template->param(loop => \@loop);
-
- if ($offset>0) {
- $template->param(offsetgtzero => 1,
- prevpage => $offset-$pagesize);
- }
-
- if ($offset+$pagesize<$count) {
- $template->param(ltcount => 1,
- nextpage => $offset+$pagesize);
- }
-} #---- END $OP eq DEFAULT
-$template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
- intranetstylesheet => C4::Context->preference("intranetstylesheet"),
- IntranetNav => C4::Context->preference("IntranetNav"),
- );