Index: branches/secondaryzones/DNSDB.pm
===================================================================
--- branches/secondaryzones/DNSDB.pm	(revision 910)
+++ branches/secondaryzones/DNSDB.pm	(revision 911)
@@ -3170,4 +3170,5 @@
 #  - an array of "acceptable" groups
 #  - a flag for forward/reverse zones
+#  - a flag for primary/secondary zones
 #  - Optionally accept a "starts with" and/or "contains" filter argument
 # Returns an integer count of the resulting zone list.
@@ -3196,22 +3197,27 @@
 
   my $sql;
-  # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read
-  if ($args{revrec} eq 'n') {
-    $sql = "SELECT count(*) FROM domains".
+
+  if ($args{secondary} eq 'y') {
+    # Secondary zones have less distinction between forward/reverse.
+    # May need to revisit that once viewing records in the zones.
+    $sql = "SELECT count(*) FROM secondaryzones".
+	" WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
+	($args{startwith} ? " AND zone ~* ?" : '').
+	($args{filter} ? " AND zone ~* ?" : '');
+  } else {
+    if ($args{revrec} eq 'n') {
+      $sql = "SELECT count(*) FROM domains".
 	" WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
 	($args{startwith} ? " AND domain ~* ?" : '').
 	($args{filter} ? " AND domain ~* ?" : '');
-  } else {
-    $sql = "SELECT count(*) FROM revzones".
+    } else {
+      $sql = "SELECT count(*) FROM revzones".
 	" WHERE group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
 	($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
-#    if ($self->{showrev_arpa} eq 'zone' || $self->{showrev_arpa} eq 'all') {
       # Just In Case the UI is using formal .arpa notation, and someone enters something reversed,
       # we want to match both the formal and natural zone name
       $sql .= ($args{filter} ? " AND (CAST(revnet AS VARCHAR) ~* ? OR CAST(revnet AS VARCHAR) ~* ?)" : '');
       push @filterargs, join('[.]',reverse(split(/\[\.\]/,$args{filter}))) if $args{filter};
-#    } else {
-#      $sql .= ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
-#    }
+    }
   }
   my ($count) = $dbh->selectrow_array($sql, undef, @filterargs);
@@ -3253,8 +3259,24 @@
 
   my $sql;
-  # Not as compact, and fix-me-twice if the common bits get wrong, but much easier to read
-  if ($args{revrec} eq 'n') {
-    $args{sortby} = 'domain' if !$args{sortby} || !grep /^$args{sortby}$/, ('domain','group','status');
+
+  if ($args{secondary} eq 'y') {
+    $args{sortby} = 'zone' if !$args{sortby} || !grep /^$args{sortby}$/, ('zone','primaryserver','group','status');
     $sql = q(SELECT
+		secondary_id AS zoneid,
+		zone,
+		primaryserver,
+		status,
+		groups.group_name AS group,
+		l.description AS location
+	FROM secondaryzones
+	LEFT JOIN locations l ON secondaryzones.default_location=l.location
+	INNER JOIN groups ON secondaryzones.group_id=groups.group_id ).
+	"WHERE secondaryzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
+	($args{startwith} ? " AND zone ~* ?" : '').
+	($args{filter} ? " AND zone ~* ?" : '');
+  } else {
+    if ($args{revrec} eq 'n') {
+      $args{sortby} = 'domain' if !$args{sortby} || !grep /^$args{sortby}$/, ('domain','group','status');
+      $sql = q(SELECT
 		domain_id AS zoneid,
 		domain AS zone,
@@ -3268,8 +3290,8 @@
 	($args{startwith} ? " AND domain ~* ?" : '').
 	($args{filter} ? " AND domain ~* ?" : '');
-  } else {
+    } else {
 ##fixme:  arguably startwith here is irrelevant.  depends on the UI though.
-    $args{sortby} = 'revnet' if !$args{sortby} || !grep /^$args{sortby}$/, ('revnet','group','status');
-    $sql = q(SELECT
+      $args{sortby} = 'revnet' if !$args{sortby} || !grep /^$args{sortby}$/, ('revnet','group','status');
+      $sql = q(SELECT
 		rdns_id AS zoneid,
 		revnet AS zone,
@@ -3282,12 +3304,9 @@
 	" WHERE revzones.group_id IN ($args{curgroup}".($args{childlist} ? ",$args{childlist}" : '').")".
 	($args{startwith} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
-#    if ($self->{showrev_arpa} eq 'zone' || $self->{showrev_arpa} eq 'all') {
       # Just In Case the UI is using formal .arpa notation, and someone enters something reversed,
       # we want to match both the formal and natural zone name
       $sql .= ($args{filter} ? " AND (CAST(revnet AS VARCHAR) ~* ? OR CAST(revnet AS VARCHAR) ~* ?)" : '');
       push @filterargs, join('[.]',reverse(split(/\[\.\]/,$args{filter}))) if $args{filter};
-#    } else {
-#      $sql .= ($args{filter} ? " AND CAST(revnet AS VARCHAR) ~* ?" : '');
-#    }
+    }
   }
   # A common tail.
