Index: trunk/cgi-bin/main.cgi
===================================================================
--- trunk/cgi-bin/main.cgi	(revision 574)
+++ trunk/cgi-bin/main.cgi	(revision 575)
@@ -286,30 +286,32 @@
   $page->param(rowa => 'row'.($webvar{block} eq '' ? 1 : 0));
   $page->param(rowb => 'row'.($webvar{block} eq '' ? 0 : 1));
-  $page->param(block => $webvar{block});	# fb-assign flag, if block is set, we're in fb-assign
-  $page->param(iscontained => ($webvar{fbtype} && $webvar{fbtype} ne 'y'));
-
-  # New special case- block to assign is specified
+  $page->param(allocfrom => $webvar{block});	# fb-assign flag, if block is set, we're in fb-assign
+
   if ($webvar{block} ne '') {
+
+    # Common case, according to reported usage.  Block to assign is specified.
     my $block = new NetAddr::IP $webvar{block};
-
-    # Handle contained freeblock allocation.
-    # This is a little dangerous, as it's *theoretically* possible to
-    # get fbtype='n' (aka a non-routed freeblock).  However, should
-    # someone manage to get there, they get what they deserve.
-    if ($webvar{fbtype} ne 'y') {
-      # Snag the type of the container block from the database.
-## hmm.  need a flag for parent class/type, sort of?
-      my $pblock = subParent($ip_dbh, $webvar{block});
-      my $ptype = $pblock->{type};
-      $ptype =~ s/c$/r/;
-      $page->param(fbdisptype => $list_alloctypes{$ptype});
-      $page->param(type => $ptype);
+    $page->param(rdepth => $webvar{rdepth});
+
+    $webvar{fbtype} = '' if !$webvar{fbtype};
+    if ($webvar{fbtype} eq 'i') {
+      my $ipinfo = getBlockData($ip_dbh, $block);
+      $page->param(
+	fbip => 1,
+	block => $block,
+	fbdisptype => $list_alloctypes{$ipinfo->{type}},
+	type => $ipinfo->{type},
+	allocfrom => $ipinfo->{pool},
+	);
     } else {
       # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch
-      my $tlist = getTypeList($ip_dbh, 'p');
+      my $tlist = getTypeList($ip_dbh, 'n');
       $tlist->[0]->{sel} = 1;
-      $page->param(typelist => $tlist);
-    }
+      $page->param(typelist => $tlist, block => $block);
+    }
+
   } else {
+
+    # Uncommon case, according to reported usage.  Block to assign needs to be found based on criteria.
     my $mlist = getMasterList($ip_dbh, 'c');
     $page->param(masterlist => $mlist);
@@ -364,5 +366,5 @@
 #  + Different flavours of netblock
 
-  if ($webvar{alloctype} =~ /^.i$/) {
+  if ($webvar{alloctype} =~ /^.i$/ && $webvar{fbassign} ne 'y') {
     my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
     $page->param(staticip => 1);
@@ -375,4 +377,5 @@
     if ($webvar{fbassign} && $webvar{fbassign} eq 'y') {
       $cidr = new NetAddr::IP $webvar{block};
+      $alloc_from = new NetAddr::IP $webvar{allocfrom};
       $webvar{maskbits} = $cidr->masklen;
     } else { # done with direct freeblocks assignment
@@ -402,6 +405,7 @@
       }
 
-      $cidr = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city}, $webvar{pop},
-	(master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
+## fixme:  add rdepth?
+      ($cidr,$webvar{rdepth}) = findAllocateFrom($ip_dbh, $webvar{maskbits}, $webvar{alloctype}, $webvar{city},
+	$webvar{pop}, (master => $webvar{allocfrom}, allowpriv => $webvar{allowpriv}) );
       if (!$cidr) {
 	$page->param(err => $failmsg);
@@ -409,18 +413,19 @@
       }
       $cidr = new NetAddr::IP $cidr;
+
+# this chunk now specific to "guided" allocation;  freeblock-select can now slice-n-dice on its own.      
+      $alloc_from = "$cidr";
+      # If the block to be allocated is smaller than the one we found,
+      # figure out the "real" block to be allocated.
+      if ($cidr->masklen() ne $webvar{maskbits}) {
+        my $maskbits = $cidr->masklen();
+        my @subblocks;
+        while ($maskbits++ < $webvar{maskbits}) {
+	  @subblocks = $cidr->split($maskbits);
+        }
+        $cidr = $subblocks[0];
+      }
     } # check for freeblocks assignment or IPDB-controlled assignment
 
-    $alloc_from = "$cidr";
-
-    # If the block to be allocated is smaller than the one we found,
-    # figure out the "real" block to be allocated.
-    if ($cidr->masklen() ne $webvar{maskbits}) {
-      my $maskbits = $cidr->masklen();
-      my @subblocks;
-      while ($maskbits++ < $webvar{maskbits}) {
-	@subblocks = $cidr->split($maskbits);
-      }
-      $cidr = $subblocks[0];
-    }
   } # if ($webvar{alloctype} =~ /^.i$/)
 
@@ -437,4 +442,5 @@
   $page->param(typefull => $q->escapeHTML($disp_alloctypes{$webvar{alloctype}}));
   $page->param(alloc_from => $alloc_from);
+  $page->param(rdepth => $webvar{rdepth});
   $page->param(cidr => $cidr);
   $page->param(city => $q->escapeHTML($webvar{city}));
@@ -477,11 +483,16 @@
     $webvar{privdata} = '';
   }
+
+  # split up some linked data for static IPs via guided allocation.  needed for breadcrumbs lite.
+  ($webvar{alloc_from},$webvar{rdepth}) = split /,/, $webvar{alloc_from};
+
   # $code is "success" vs "failure", $msg contains OK for a
   # successful netblock allocation, the IP allocated for static
   # IP, or the error message if an error occurred.
 
-  my ($code,$msg) = allocateBlock($ip_dbh, $webvar{fullcidr}, $webvar{alloc_from},
-	$webvar{custid}, $webvar{alloctype}, $webvar{city}, $webvar{desc}, $webvar{notes},
-	$webvar{circid}, $webvar{privdata}, $webvar{node});
+  my ($code,$msg) = allocateBlock($ip_dbh, cidr => $webvar{fullcidr}, alloc_from => $webvar{alloc_from},
+	rdepth => $webvar{rdepth}, custid => $webvar{custid}, type => $webvar{alloctype}, city => $webvar{city}, 
+	desc => $webvar{desc}, notes => $webvar{notes}, circid => $webvar{circid},
+	privdata => $webvar{privdata}, nodeid => $webvar{node});
 
   if ($code eq 'OK') {
@@ -490,4 +501,5 @@
       $page->param(staticip => $msg);
       $page->param(custid => $webvar{custid});
+      $page->param(parent => $webvar{alloc_from}, rdepth => $webvar{rdepth}-1);
       $page->param(billinguser => $webvar{billinguser});
       mailNotify($ip_dbh, "a$webvar{alloctype}", "ADDED: $disp_alloctypes{$webvar{alloctype}} allocation",
@@ -499,4 +511,7 @@
       $page->param(alloctype => $disp_alloctypes{$webvar{alloctype}});
       $page->param(custid => $webvar{custid});
+      # breadcrumbs lite!  provide at least a link to the parent of the block we just allocated.
+      my $binfo = getBlockData($ip_dbh, $webvar{fullcidr}, $webvar{rdepth});
+      $page->param(parent => $binfo->{parent}, rdepth => $binfo->{rdepth});
       if ($webvar{alloctype} eq 'pr' && $webvar{billinguser}) {
 	$page->param(billinguser => $webvar{billinguser});
