Index: /trunk/cgi-bin/IPDB.pm
===================================================================
--- /trunk/cgi-bin/IPDB.pm	(revision 560)
+++ /trunk/cgi-bin/IPDB.pm	(revision 561)
@@ -27,5 +27,5 @@
 	&initIPDBGlobals &connectDB &finish &checkDBSanity
 	&addMaster &touchMaster
-	&listSummary &listMaster &listRBlock &listFree &listPool
+	&listSummary &listSubs &listFree &listPool
 	&getMasterList &getTypeList &getPoolSelect &findAllocateFrom
 	&ipParent &subParent &blockParent &getRoutedCity
@@ -41,5 +41,5 @@
 		&initIPDBGlobals &connectDB &finish &checkDBSanity
 		&addMaster &touchMaster
-		&listSummary &listMaster &listRBlock &listFree &listPool
+		&listSummary &listSubs &listFree &listPool
 		&getMasterList &getTypeList &getPoolSelect &findAllocateFrom
 		&ipParent &subParent &blockParent &getRoutedCity
@@ -359,4 +359,47 @@
   return $mlist;
 } # end listSummary()
+
+
+## IPDB::listSubs()
+# Get list of subnets within a specified CIDR block, on a specified VRF.
+# Returns an arrayref to a list of hashrefs containing the CIDR block, customer location or
+# city it's routed to, block type, SWIP status, and description
+sub listSubs {
+  my $dbh = shift;
+  my %args = @_;
+
+  # Just In Case
+  $args{vrf} = '' if !$args{vrf};
+  $args{rdepth} = 1 if !$args{rdepth};
+
+  # Snag the allocations for this block
+  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description".
+	" FROM allocations WHERE parent = ? AND rdepth = ? ORDER BY cidr");
+  $sth->execute($args{block},$args{rdepth});
+
+  # hack hack hack
+  # set up to flag swip=y records if they don't actually have supporting data in the customers table
+  my $custsth = $dbh->prepare("SELECT count(*) FROM customers WHERE custid = ?");
+
+  my @blocklist;
+  while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
+    $custsth->execute($custid);
+    my ($ncust) = $custsth->fetchrow_array();
+    my %row = (
+	block => $cidr,
+	city => $city,
+	type => $disp_alloctypes{$type},
+	custid => $custid,
+	swip => ($swip eq 'y' ? 'Yes' : 'No'),
+	partswip => ($swip eq 'y' && $ncust == 0 ? 1 : 0),
+	desc => $desc,
+	hassubs => ($type eq 'rm' || $type =~ /.c/ ? 1 : 0),
+	);
+#    $row{subblock} = ($type =~ /^.r$/);         # hmf.  wonder why these won't work in the hash declaration...
+    $row{listpool} = ($type =~ /^.[pd]$/);
+    push (@blocklist, \%row);
+  }
+  return \@blocklist;
+} # end listSubs()
 
 
