<%args> $pua_id $device_id $new_uri => '' <%once> use DBI; use Pg; <%init> my $count = 1; my %methods; while (my $a = $ARGS{'id'.$count}) { $methods{$a} = $ARGS{'uri'.$count}; $count++; } my $dbh = DBI->connect('dbi:Pg:dbname=pua', 'pua', 'pua') or die "Couldn't connect to database: " . DBI->errstr; my $sth = $dbh->prepare("SELECT max(owner_contact_method_id) from owner_contact_method;"); $sth->execute or die "Execute failed: " . $sth->errstr; my $new_id = $sth->fetchrow_array(); $new_id++; foreach $m (keys %methods) { if ($methods{$m} ne '') { $sth = $dbh->prepare("UPDATE owner_contact_method set uri='$methods{$m}' WHERE owner_contact_method_id=$m;"); } else { $sth = $dbh->prepare("DELETE from owner_contact_method WHERE owner_contact_method_id=$m;"); } $sth->execute or die "Execute failed: " . $sth->errstr; } if ($new_uri ne '') { my $sth = $dbh->prepare("INSERT into owner_contact_method(uri, owner_contact_method_id, device_id) values('$new_uri', $new_id, $device_id);"); $sth->execute or die "Execute failed: " . $sth->errstr; } $m->comp('pua_details.html', pua_id => $pua_id, edit => 't', device_id => $device_id);