Index: trunk/dnsbl/browse.cgi
===================================================================
--- trunk/dnsbl/browse.cgi	(revision 7)
+++ trunk/dnsbl/browse.cgi	(revision 19)
@@ -23,5 +23,5 @@
 	"WHERE b.block <<= ";
 my $sth0 = $dbh->prepare($basesql."'0/0' AND b.level=0 ORDER BY block");
-#my $sth0 = $dbh->prepare($basesql."'76.73.0.0/17' AND b.level=0 ORDER BY block");
+#my $sth0 = $dbh->prepare($basesql."'64/8' AND b.level=0 ORDER BY block");
 my $sth1 = $dbh->prepare($basesql."? AND b.level=1 ORDER BY block");
 my $sth2 = $dbh->prepare($basesql."? AND b.level=2 ORDER BY block");
@@ -32,92 +32,91 @@
 my %ipseen;
 
+my $out = '';
+
 $sth0->execute;
 while (my ($block0,$org0,$listmeb0,$listmeo0,$bcomments0,$ocomments0) = $sth0->fetchrow_array) {
-  print "<div class=\"lvl0".($dnsbl->autolist_block($block0) ? ' auto0"' : '"').
-	"><span".($listmeb0 ? ' class=b0list' : '').">$block0".
-	($listmeb0 ? " ($bcomments0)" : '')."</span> ".
-	"<span".($listmeo0 ? ' class=b0org' : '').">$org0".
-	($listmeo0 ? " ($ocomments0)" : '')."</span>\n";
+  my $tmpl0 = new HTML::Template(filename => 'templates/browse-block.tmpl');
+  $tmpl0->param(lvlclass => 'lvl0'.($dnsbl->autolist_block($block0) ? ' auto0' : ''));
+  $tmpl0->param(netclass => ($listmeb0 ? 'b0list' : ''));
+  $tmpl0->param(net => $block0);
+  $tmpl0->param(orgclass => ($listmeo0 ? 'b0org' : ''));
+  $tmpl0->param(org => $org0);
+  $tmpl0->param(bcomment => $bcomments0) if $bcomments0;
+  $tmpl0->param(ocomment => $ocomments0) if $ocomments0;
   $sth1->execute($block0);
+  my $lvl1out = '';
   if ($sth1->rows > 0) {
     while (my ($block1,$org1,$listmeb1,$listmeo1,$bcomments1,$ocomments1) = $sth1->fetchrow_array) {
-# lvl 1 div open
-      print "  <div class=\"lvl1".($dnsbl->autolist_block($block1) ? ' auto1"' : '"').
-	"><span".($listmeb1 ? ' class=b1list' : '').">$block1".
-	($listmeb1 ? " ($bcomments1)" : '')."</span> ".
-	"<span".($listmeo1 ? ' class=b1org' : '').">$org1".
-	($listmeo1 ? " ($ocomments1)" : '')."</span>\n";
+      my $tmpl1 = new HTML::Template(filename => 'templates/browse-block.tmpl');
+      $tmpl1->param(lvlclass => 'lvl1'.($dnsbl->autolist_block($block1) ? ' auto1' : ''));
+      $tmpl1->param(netclass => ($listmeb1 ? 'b1list' : ''));
+      $tmpl1->param(net => $block1);
+      $tmpl1->param(orgclass => ($listmeo1 ? 'b1org' : ''));
+      $tmpl1->param(org => $org1);
+      $tmpl1->param(bcomment => $bcomments1) if $bcomments1;
+      $tmpl1->param(ocomment => $ocomments1) if $ocomments1;
+      $tmpl1->param(indent => '  ');
+      my $lvl2out = '';
       $sth2->execute($block1);
       if ($sth2->rows > 0) {
-        while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
-# lvl 2 div open
-          print "    <div class=\"lvl2".($dnsbl->autolist_block($block2) ? ' auto2"' : '"').
-		"><span".($listmeb2 ? ' class=b2list' : '').">$block2".
-		($listmeb2 ? " ($bcomments2)" : '')."</span> ".
-		"<span".($listmeo2 ? ' class=b2org' : '').">$org2".
-		($listmeo2 ? " ($ocomments2)" : '')."</span>\n";
-          $sthiplist->execute($block2);
-          print "      <div class=iplist>\n";
-          while (my @data4 = $sthiplist->fetchrow_array) {
-            print "        $data4[0]<br>\n";
-            $ipseen{$data4[0]} = 1;
-          }
-          print "      </div>\n";
-# lvl2 div close
-          print "    </div>\n";
-        }
-      } else {
-        $sthiplist->execute($block1);
-        print "    <div class=iplist>\n";
-        while (my @data4 = $sthiplist->fetchrow_array) {
-          print "      $data4[0]<br>\n";
-          $ipseen{$data4[0]} = 1;
-        }
-        print "    </div>\n";
+	while (my ($block2,$org2,$listmeb2,$listmeo2,$bcomments2,$ocomments2) = $sth2->fetchrow_array) {
+	  my $tmpl2 = new HTML::Template(filename => 'templates/browse-block.tmpl');
+	  $tmpl2->param(lvlclass => 'lvl2'.($dnsbl->autolist_block($block2) ? ' auto2' : ''));
+	  $tmpl2->param(netclass => ($listmeb2 ? 'b2list' : ''));
+	  $tmpl2->param(net => $block2);
+	  $tmpl2->param(orgclass => ($listmeo2 ? 'b2org' : ''));
+	  $tmpl2->param(org => $org2);
+	  $tmpl2->param(bcomment => $bcomments2) if $bcomments2;
+	  $tmpl2->param(ocomment => $ocomments2) if $ocomments2;
+	  $tmpl2->param(indent => '    ');
+	  $sthiplist->execute($block2);
+	  my @iprows;
+	  while (my @data4 = $sthiplist->fetchrow_array) {
+	    my %iprow;
+	    $iprow{ip} = $data4[0];
+	    $iprow{ipcount} = $data4[1];
+	    $iprow{indent} = '    ';
+#       ip        | count | s4list |             added
+	    push @iprows, \%iprow;
+	    $ipseen{$data4[0]} = 1;
+	  }
+	  $tmpl2->param(iplist => \@iprows);
+	  $lvl2out .= $tmpl2->output;
+	}
       }
 
-      my $sqlalt = "select ip from iplist where ip << ?";
-      my $sthalt = $dbh->prepare($sqlalt);
-      $sthalt->execute($block1);
-      my @newips;
-      while (my @data4 = $sthalt->fetchrow_array) {
-        push @newips, $data4[0] if !$ipseen{$data4[0]};
-        $ipseen{$data4[0]} = 1;
+      $sthiplist->execute($block1);
+      my @iprows;
+      while (my @data4 = $sthiplist->fetchrow_array) {
+	next if $ipseen{$data4[0]};
+	my %iprow;
+	$iprow{ip} = $data4[0];
+	$iprow{ipcount} = $data4[1];
+	$iprow{indent} = '  ';
+#       ip        | count | s4list |             added
+	push @iprows, \%iprow;
+	$ipseen{$data4[0]} = 1;
       }
-      if ($#newips > -1) {
-        print "    <div class=iplist>\n";
-        foreach (@newips) {
-          print "      $_<br>\n";
-        }
-        print "    </div>\n";
-      }
-# lvl 1 div close
-      print "  </div>\n";
+      $tmpl1->param(iplist => \@iprows);
+      $tmpl1->param(subs => $lvl2out);
+      $lvl1out .= $tmpl1->output;
     }
-  } else {
-    $sthiplist->execute($block0);
-    print "  <div class=iplist>\n";
-    while (my @data4 = $sthiplist->fetchrow_array) {
-      print "    $data4[0]<br>\n";
-      $ipseen{$data4[0]} = 1;
-    }
-    print "  </div>\n";
+  } # sth1->rows
+  $sthiplist->execute($block0);
+  my @iprows;
+  while (my @data4 = $sthiplist->fetchrow_array) {
+    next if $ipseen{$data4[0]};
+    my %iprow;
+    $iprow{ip} = $data4[0];
+    $iprow{ipcount} = $data4[1];
+    $iprow{indent} = '';
+#       ip        | count | s4list |             added
+    push @iprows, \%iprow;
+    $ipseen{$data4[0]} = 1;
   }
+  $tmpl0->param(iplist => \@iprows);
+  $tmpl0->param(subs => $lvl1out);
+  $out .= $tmpl0->output;
+}
 
-  my $sqlalt = "select ip from iplist where ip << ?";
-  my $sthalt = $dbh->prepare($sqlalt);
-  $sthalt->execute($block0);
-  my @newips;
-  while (my @data4 = $sthalt->fetchrow_array) {
-    push @newips, $data4[0] if (!$ipseen{$data4[0]});
-  }
-  if ($#newips > -1) {
-    print "  <div class=iplist>\n";
-    foreach (@newips) {
-      print "    $_<br>\n";
-    }
-    print "  </div>\n";
-  }
-
-  print "</div>\n";
-}
+print $out;
