<%args> $pua_id $new_contact_name $new_contact_uri $new_group_member $comment <%once> use DBI; <%init> 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(group_entry_id) from group_entry;"); $sth->execute or die "Execute failed: " . $sth->errstr; my $new_group_id = $sth->fetchrow_array(); $sth = $dbh->prepare("SELECT max(contact_id) from pua_contact;"); $sth->execute or die "Execute failed: " . $sth->errstr; my $new_contact_id = $sth->fetchrow_array(); $sth = $dbh->prepare("SELECT max(contact_method_id) from contact_method;"); $sth->execute or die "Execute failed: " . $sth->errstr; my $new_contact_method_id = $sth->fetchrow_array(); $new_group_id++; $new_contact_id++; $new_contact_method_id++; $sth = $dbh->prepare("INSERT into pua_contact(contact_id, pua_id, contact_name, comment) values($new_contact_id, $pua_id, '$new_contact_name', '$comment');"); $sth->execute or die "Execute failed: " . $sth->errstr; if ($new_group_member != -1) { $sth = $dbh->prepare("INSERT into group_entry(parent_contact_id, child_contact_id, group_entry_id) values($new_contact_id, $new_group_member, $new_group_id);"); $sth->execute or die "Execute failed: " . $sth->errstr; } elsif ($new_contact_uri ne '') { $sth = $dbh->prepare("INSERT into contact_method(contact_id, uri, contact_method_id) values($new_contact_id, '$new_contact_uri', $new_contact_method_id);"); $sth->execute or die "Execute failed: " . $sth->errstr; } $m->comp('pua_contacts.html', edit => 't', contact_id => $new_contact_id, pua_id => $pua_id);