Ignore:
Timestamp:
08/12/10 11:52:22 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Give up on proper spelling of "centre" in CSS class names and
defs - browsers only understand an alignment of "center".
Adjust width of some <hr>'s
Visual row0/row1 classes got switched somehow, somewhere
Remove legacy "color0/color1/color2" row class defs
Convert showrouted to template
See #3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/htmlform/cgi-bin/main.cgi

    r465 r466  
    417417  $sth = $ip_dbh->prepare("select city from routed where cidr='$master'");
    418418  $sth->execute;
    419   my @data = $sth->fetchrow_array;
    420 
    421   print qq(<center><div class="heading">Summarizing allocated blocks for ).
    422         qq($master ($data[0]):</div></center><br>\n);
    423 
    424   startTable('CIDR allocation','Customer Location','Type','CustID','SWIPed?','Description/Name');
     419  my ($rcity) = $sth->fetchrow_array;
     420
     421  $page->param(master => "$master");
     422  $page->param(rcity => $rcity);
    425423
    426424  # Snag the allocations for this block
     
    433431  my $custsth = $ip_dbh->prepare("select count(*) from customers where custid=?");
    434432
    435   my $count=0;
    436   while (my @data = $sth->fetchrow_array()) {
    437     # cidr,city,type,custid,swip,description, as per the SELECT
    438     my $cidr = new NetAddr::IP $data[0];
    439 
    440     # Clean up extra spaces that are borking things.
    441 #    $data[2] =~ s/\s+//g;
    442 
    443     $custsth->execute($data[3]);
     433  my $rowclass = 0;
     434  my @blocklist;
     435  while (my ($cidr,$city,$type,$custid,$swip,$desc) = $sth->fetchrow_array()) {
     436    $custsth->execute($custid);
    444437    my ($ncust) = $custsth->fetchrow_array();
    445438
    446     # Prefix subblocks with "Sub "
    447     my @row = ( (($data[2] =~ /^.r$/) ? 'Sub ' : '').
    448         qq(<a href="/ip/cgi-bin/main.cgi?action=edit&block=$data[0]">$data[0]</a>),
    449         $data[1], $disp_alloctypes{$data[2]}, $data[3],
    450         ($data[4] eq 'y' ? ($ncust == 0 ? 'Yes<small>*</small>' : 'Yes') : 'No'), $data[5]);
    451     # If the allocation is a pool, allow listing of the IPs in the pool.
    452     if ($data[2] =~ /^.[pd]$/) {
    453       $row[0] .= ' &nbsp; <a href="/ip/cgi-bin/main.cgi?action=listpool'.
    454         "&pool=$data[0]\">List IPs</a>";
    455     }
    456 
    457     printRow(\@row, 'color1') if ($count%2 == 0);
    458     printRow(\@row, 'color2') if ($count%2 != 0);
    459     $count++;
    460   }
    461 
    462   print "</table>\n";
    463 
    464   # If the routed block has no allocations, by definition it only has
    465   # one free block, and therefore may be deleted.
    466   if ($count == 0) {
    467     print qq(<hr width="60%"><center><div class="heading">No allocations in ).
    468         qq($master.</div></center>\n).
    469         ($IPDBacl{$authuser} =~ /d/ ?
    470                 qq(<form action="/ip/cgi-bin/main.cgi" method=POST>\n).
    471                 qq(<input type=hidden name=action value="delete">\n).
    472                 qq(<input type=hidden name=block value="$master">\n).
    473                 qq(<input type=hidden name=alloctype value="rm">\n).
    474                 qq(<input type=submit value=" Remove this block ">\n).
    475                 qq(</form>\n) :
    476                 '');
    477   }
    478 
    479   print qq(<hr width="60%">\n<center><div class="heading">Free blocks within routed ).
    480         qq(submaster $master</div></center>\n);
    481 
    482   startTable('CIDR block','Range');
     439    my %row = (
     440        rowclass => $rowclass++ % 2,
     441        block => $cidr,
     442        city => $city,
     443        type => $disp_alloctypes{$type},
     444        custid => $custid,
     445        swip => ($swip eq 'y' ? ($ncust == 0 ? 'Yes<small>*</small>' : 'Yes') : 'No'),
     446        desc => $desc
     447        );
     448    $row{subblock} = ($type =~ /^.r$/);         # hmf.  wonder why these won't work in the hash declaration...
     449    $row{listpool} = ($type =~ /^.[pd]$/);
     450    push (@blocklist, \%row);
     451  }
     452  $page->param(blocklist => \@blocklist);
     453
     454  $page->param(delrouted => $IPDBacl{$authuser} =~ /d/);
    483455
    484456  # Snag the free blocks.  We don't really *need* to be pedantic about avoiding
    485457  # unrouted free blocks, but it's better to let the database do the work if we can.
    486   $count = 0;
     458  $rowclass = 0;
     459  my @unassigned;
    487460  $sth = $ip_dbh->prepare("select cidr,routed from freeblocks where cidr <<= '$master'".
    488461        " order by cidr");
    489462  $sth->execute();
    490   while (my @data = $sth->fetchrow_array()) {
    491     # cidr,routed
    492     my $cidr = new NetAddr::IP $data[0];
    493     # Include some HairyPerl(TM) to prefix subblocks with "Sub "
    494     my @row = ((($data[1] ne 'y' && $data[1] ne 'n') ? 'Sub ' : '').
    495         ($IPDBacl{$authuser} =~ /a/ ? qq(<a href="/ip/cgi-bin/main.cgi?action=assign&block=$cidr&fbtype=$data[1]">$cidr</a>) : $cidr),
    496         $cidr->range);
    497     printRow(\@row, 'color1') if ($count%2 == 0);
    498     printRow(\@row, 'color2') if ($count%2 != 0);
    499     $count++;
    500   }
    501 
    502   print "</table>\n";
     463  while (my ($cidr_db,$routed) = $sth->fetchrow_array()) {
     464    my $cidr = new NetAddr::IP $cidr_db;
     465
     466    my %row = (
     467        rowclass => $rowclass++ % 2,
     468        subblock => ($routed ne 'y' && $routed ne 'n'),
     469        fblock => $cidr_db,
     470        fbtype => $routed,
     471        frange => $cidr->range,
     472        );
     473    push @unassigned, \%row;
     474  }
     475  $page->param(unassigned => \@unassigned);
     476
    503477} # showRBlock
    504478
Note: See TracChangeset for help on using the changeset viewer.