<%args> $pua_id $contact_id $new_uri => '' <%once> use DBI; <%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(contact_method_id) from 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 contact_method set uri='$methods{$m}' WHERE contact_method_id=$m;"); } else { $sth = $dbh->prepare("DELETE FROM contact_method WHERE contact_method_id=$m;"); } $sth->execute or die "Execute failed: " . $sth->errstr; } if ($new_uri ne '') { my $sth = $dbh->prepare("INSERT into contact_method(uri, contact_method_id, contact_id) values('$new_uri', $new_id, $contact_id);"); $sth->execute or die "Execute failed: " . $sth->errstr; } $m->comp('pua_contacts.html', edit => 't', contact_id => $contact_id, pua_id => $pua_id);