Index: branches/stable/DNSDB.pm
===================================================================
--- branches/stable/DNSDB.pm	(revision 545)
+++ branches/stable/DNSDB.pm	(revision 546)
@@ -3074,4 +3074,8 @@
 
 ## DNSDB::updateLoc()
+# Update details of a location.
+# Takes a database handle, location ID, group ID, short description,
+# long comments/notes, and comma/space-separated IP list
+# Returns a result code and message
 sub updateLoc {
   my $dbh = shift;
@@ -3116,8 +3120,44 @@
 
 ## DNSDB::delLoc()
-sub delLoc {}
+sub delLoc {
+  my $dbh = shift;
+  my $loc = shift;
+
+  # Allow transactions, and raise an exception on errors so we can catch it later.
+  # Use local to make sure these get "reset" properly on exiting this block
+  local $dbh->{AutoCommit} = 0;
+  local $dbh->{RaiseError} = 1;
+
+  my $oldloc = getLoc($dbh, $loc);
+  my $olddesc = ($oldloc->{description} ? $oldloc->{description} : $loc);
+  my $okmsg = "Deleted location ($olddesc, '".$oldloc->{iplist}."')";
+
+  eval {
+    # Check for records with this location first.  Deleting a location without deleting records
+    # tagged for that location will render them unpublished without other warning.
+    my ($r) = $dbh->selectrow_array("SELECT record_id FROM records WHERE location=? LIMIT 1", undef, ($loc) );
+    die "Records still exist in location $olddesc\n" if $r;
+    $dbh->do("DELETE FROM locations WHERE location=?", undef, ($loc) );
+    _log($dbh, entry => $okmsg);
+    $dbh->commit;
+  };
+  if ($@) {
+    my $msg = $@;
+    eval { $dbh->rollback; };
+    if ($config{log_failures}) {
+      _log($dbh, (entry => "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg"));
+      $dbh->commit;
+    }
+    return ('FAIL', "Failed to delete location ($olddesc, '$oldloc->{iplist}'): $msg");
+  }
+
+  return ('OK',$okmsg);
+} # end delLoc()
 
 
 ## DNSDB::getLoc()
+# Get details about a location/view
+# Takes a database handle and location ID.
+# Returns a reference to a hash containing the group ID, IP list, description, and comments/notes
 sub getLoc {
   my $dbh = shift;
@@ -3325,5 +3365,7 @@
   my $id = shift;
 
-  my $sql = "SELECT record_id,host,type,val,ttl,location".($revrec eq 'n' ? ',distance,weight,port' : '').
+  my $sql = "SELECT record_id,host,type,val,ttl".
+	($defrec eq 'n' ? ',location' : '').
+	($revrec eq 'n' ? ',distance,weight,port' : '').
 	(($defrec eq 'y') ? ',group_id FROM ' : ',domain_id,rdns_id FROM ').
 	_rectable($defrec,$revrec)." WHERE record_id=?";
@@ -3400,5 +3442,5 @@
   $sql .= "WHERE "._recparent($args{defrec},$args{revrec})." = ?";
   $sql .= " AND NOT r.type=$reverse_typemap{SOA}";
-  $sql .= " AND host ~* ?" if $args{filter};
+  $sql .= " AND (r.host ~* ? OR r.val ~* ?)" if $args{filter};
   $sql .= " ORDER BY $args{sortby} $args{sortorder}";
   # ensure consistent ordering by sorting on record_id too
@@ -3407,5 +3449,5 @@
 
   my @bindvars = ($args{id});
-  push @bindvars, $args{filter} if $args{filter};
+  push @bindvars, ($args{filter},$args{filter}) if $args{filter};
 
   my $ret = $dbh->selectall_arrayref($sql, { Slice => {} }, (@bindvars) );
@@ -3548,5 +3590,6 @@
   $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]"
 	if $typemap{$$rectype} eq 'SRV';
-  $logdata{entry} .= "', TTL $ttl, location $location";
+  $logdata{entry} .= "', TTL $ttl";
+  $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location;
 
   # Allow transactions, and raise an exception on errors so we can catch it later.
@@ -3709,5 +3752,7 @@
   $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
 	if $typemap{$oldrec->{type}} eq 'SRV';
-  $logdata{entry} .= "', TTL $oldrec->{ttl}, location $oldrec->{location}\nto\n";
+  $logdata{entry} .= "', TTL $oldrec->{ttl}";
+  $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location};
+  $logdata{entry} .= "\nto\n";
   # More NS special
   if ($revrec eq 'y' && $$rectype == 2) {
@@ -3718,5 +3763,6 @@
   $logdata{entry} .= " [distance $dist]" if $typemap{$$rectype} eq 'MX';
   $logdata{entry} .= " [priority $dist] [weight $weight] [port $port]" if $typemap{$$rectype} eq 'SRV';
-  $logdata{entry} .= "', TTL $ttl, location $location";
+  $logdata{entry} .= "', TTL $ttl";
+  $logdata{entry} .= ", location ".getLoc($dbh, $location)->{description} if $location;
 
   local $dbh->{AutoCommit} = 0;
@@ -3778,5 +3824,6 @@
   $logdata{entry} .= " [priority $oldrec->{distance}] [weight $oldrec->{weight}] [port $oldrec->{port}]"
 	if $typemap{$oldrec->{type}} eq 'SRV';
-  $logdata{entry} .= "', TTL $oldrec->{ttl}\n";
+  $logdata{entry} .= "', TTL $oldrec->{ttl}";
+  $logdata{entry} .= ", location ".getLoc($dbh, $oldrec->{location})->{description} if $oldrec->{location};
 
   eval {
