Index: trunk/cgi-bin/IPDB.pm
===================================================================
--- trunk/cgi-bin/IPDB.pm	(revision 690)
+++ trunk/cgi-bin/IPDB.pm	(revision 691)
@@ -108,4 +108,8 @@
 our $sublistlayout = 1;
 
+# VLAN validation mode.  Set to 0 to allow alphanumeric vlan names instead of using the vlan number.
+our $numeric_vlan = 1;
+
+
 ##
 ## Internal utility functions
@@ -506,5 +510,5 @@
 
   # Snag the allocations for this block
-  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
+  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
 	" FROM allocations WHERE parent_id = ? ORDER BY cidr");
   $sth->execute($args{parent});
@@ -524,5 +528,7 @@
 
   my @blocklist;
-  while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
+  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
+    $desc .= " - vrf:$vrf" if $desc && $vrf;
+    $desc = "vrf:$vrf" if !$desc && $vrf;
     $custsth->execute($custid);
     my ($ncust) = $custsth->fetchrow_array();
@@ -575,5 +581,5 @@
 
   # Snag the allocations for this block
-  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
+  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
 	" FROM allocations WHERE parent_id = ? AND type ~ '[mc]\$' ORDER BY cidr");
   $sth->execute($args{parent});
@@ -586,5 +592,7 @@
 
   my @blocklist;
-  while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
+  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
+    $desc .= " - vrf:$vrf" if $desc && $vrf;
+    $desc = "vrf:$vrf" if !$desc && $vrf;
     $alsth->execute($cidr, $mid);
     my ($alloc) = $alsth->fetchrow_array();
@@ -622,5 +630,5 @@
 
   # Snag the allocations for this block
-  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,id,master_id".
+  my $sth = $dbh->prepare("SELECT cidr,city,type,custid,swip,description,vrf,id,master_id".
 	" FROM allocations WHERE parent_id = ? AND type !~ '[mc]\$' ORDER BY cidr");
   $sth->execute($args{parent});
@@ -631,5 +639,7 @@
 
   my @blocklist;
-  while (my ($cidr,$city,$type,$custid,$swip,$desc,$id,$mid) = $sth->fetchrow_array()) {
+  while (my ($cidr,$city,$type,$custid,$swip,$desc,$vrf,$id,$mid) = $sth->fetchrow_array()) {
+    $desc .= " - vrf:$vrf" if $desc && $vrf;
+    $desc = "vrf:$vrf" if !$desc && $vrf;
     $custsth->execute($custid);
     my ($ncust) = $custsth->fetchrow_array();
@@ -959,4 +969,5 @@
   $args{privdata} = '' if !$args{privdata};
   $args{vrf} = '' if !$args{vrf};
+  $args{vlan} = '' if !$args{vlan};
   $args{rdns} = '' if !$args{rdns};
 
@@ -1008,5 +1019,5 @@
 # end node hack
 
-      $dbh->commit;
+      $dbh->commit;  # Allocate IP from pool
     };
     if ($@) {
@@ -1032,7 +1043,7 @@
 	# Insert the allocations entry
 	$dbh->do("INSERT INTO allocations ".
-		"(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
-		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
-		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
+		"(cidr,parent_id,master_id,vrf,vlan,custid,type,city,description,notes,circuitid,privdata,rdns)".
+		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", undef,
+		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{vlan}, $args{custid}, $args{type}, $args{city},
 		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
 	my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
@@ -1068,5 +1079,5 @@
 # end node hack
 
-	$dbh->commit;
+	$dbh->commit;  # Simple block allocation
       }; # end of eval
       if ($@) {
@@ -1114,7 +1125,7 @@
 	# Insert the allocations entry
 	$dbh->do("INSERT INTO allocations ".
-		"(cidr,parent_id,master_id,vrf,custid,type,city,description,notes,circuitid,privdata,rdns)".
-		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", undef,
-		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{custid}, $args{type}, $args{city},
+		"(cidr,parent_id,master_id,vrf,vlan,custid,type,city,description,notes,circuitid,privdata,rdns)".
+		" VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)", undef,
+		($args{cidr}, $fbparent, $fbmaster, $args{vrf}, $args{vlan}, $args{custid}, $args{type}, $args{city},
 		$args{desc}, $args{notes}, $args{circid}, $args{privdata}, $args{rdns}) );
 	my ($bid) = $dbh->selectrow_array("SELECT currval('allocations_id_seq')");
@@ -1145,5 +1156,5 @@
 # end node hack
 
-        $dbh->commit;
+        $dbh->commit;  # Complex block allocation
       }; # end eval
       if ($@) {
@@ -1186,5 +1197,9 @@
   return ('FAIL',"Refusing to create oversized static IP pool") if $pool->masklen <= 20;
 
+  # Retrieve some odds and ends for defaults on the IPs
   my ($pcustid) = $dbh->selectrow_array("SELECT def_custid FROM alloctypes WHERE type=?", undef, ($type) );
+  my ($vrf,$vlan) = $dbh->selectrow_array("SELECT vrf,vlan FROM allocations WHERE allocation_id = ?",
+	undef, ($parent) );
+
   $type =~ s/[pd]$/i/;
   my $sth;
@@ -1250,5 +1265,5 @@
   my @fieldlist;
   my @vallist;
-  foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'rdns') {
+  foreach ('custid', 'city', 'description', 'notes', 'circuitid', 'privdata', 'rdns', 'vrf', 'vlan') {
     if ($args{$_}) {
       push @fieldlist, $_;
@@ -1701,10 +1716,10 @@
   if ($type eq 'i') {
     my $binfo = $dbh->selectrow_hashref("SELECT ip AS block, custid, type, city, circuitid, description,".
-	" notes, modifystamp AS lastmod, privdata, vrf, rdns, parent_id, master_id".
+	" notes, modifystamp AS lastmod, privdata, vrf, vlan, rdns, parent_id, master_id".
 	" FROM poolips WHERE id = ?", undef, ($id) );
     return $binfo;
   } else {
     my $binfo = $dbh->selectrow_hashref("SELECT cidr AS block, custid, type, city, circuitid, ".
-	"description, notes, modifystamp AS lastmod, privdata, vrf, swip, rdns, parent_id, master_id".
+	"description, notes, modifystamp AS lastmod, privdata, vrf, vlan, swip, rdns, parent_id, master_id".
 	" FROM allocations WHERE id = ?", undef, ($id) );
     return $binfo;
