Ignore:
Timestamp:
08/06/10 16:30:33 (14 years ago)
Author:
Kris Deugau
Message:

/branches/htmlform

Convert showmaster page to template.
See #3.

File:
1 edited

Legend:

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

    r463 r465  
    308308sub showMaster {
    309309
    310   print qq(<center><div class="heading">Summarizing routed blocks for ).
    311         qq($webvar{block}:</div></center><br>\n);
     310  $page->param(master => $webvar{block});
    312311
    313312  my %allocated;
    314313  my %free;
    315   my %routed;
     314  my %cities;
    316315  my %bigfree;
    317316
     
    331330    $bigfree{"$cidr"} = 128;
    332331    # Retain the routing destination
    333     $routed{"$cidr"} = $data[1];
     332    $cities{"$cidr"} = $data[1];
    334333  }
    335334
    336335  # Check if there were actually any blocks routed from this master
    337336  if ($i > 0) {
    338     startTable('Routed block','Routed to','Allocated blocks',
    339         'Free blocks','Largest free block');
    340337
    341338    # Count the allocations
     
    365362    }
    366363
    367     # Print the data.
    368     my $count=0;
     364    my @routed;
     365    my $rowclass = 0;
    369366    foreach my $master (@localmasters) {
    370       my @row = ("<a href=\"/ip/cgi-bin/main.cgi?action=showrouted&block=$master\">$master</a>",
    371         $routed{"$master"}, $allocated{"$master"},
    372         $free{"$master"},
    373         ( ($bigfree{"$master"} eq 128) ? ("&lt;NONE&gt;") : ("/".$bigfree{"$master"}) )
    374       );
    375       printRow(\@row, 'color1' ) if($count%2==0);
    376       printRow(\@row, 'color2' ) if($count%2!=0);
    377       $count++;
    378     }
    379   } else {
    380     # If a master block has no routed blocks, then by definition it has no
    381     # allocations, and can be deleted.
    382     print qq(<hr width="60%"><center><div class="heading">No allocations in ).
    383         qq($master.</div>\n).
    384         ($IPDBacl{$authuser} =~ /d/ ?
    385                 qq(<form action="/ip/cgi-bin/main.cgi" method=POST>\n).
    386                 qq(<input type=hidden name=action value="delete">\n).
    387                 qq(<input type=hidden name=block value="$master">\n).
    388                 qq(<input type=hidden name=alloctype value="mm">\n).
    389                 qq(<input type=submit value=" Remove this master ">\n).
    390                 qq(</form></center>\n) :
    391                 '');
     367      my %row = (
     368        rowclass => $rowclass % 2,
     369        block => "$master",
     370        city => $cities{"$master"},
     371        nsubs => $allocated{"$master"},
     372        nfree => $free{"$master"},
     373        lfree => ( ($bigfree{"$master"} eq 128) ? ("&lt;NONE&gt;") : ("/".$bigfree{"$master"}) )
     374        );
     375      push @routed, \%row;
     376      $rowclass++;
     377    }
     378    $page->param(routedlist => \@routed);
    392379
    393380  } # end check for existence of routed blocks in master
    394381
    395   print qq(</table>\n<hr width="60%">\n).
    396         qq(<center><div class="heading">Unrouted blocks in $master:</div></center><br>\n);
    397 
    398   startTable('Netblock','Range');
     382  $page->param(delmaster => ($IPDBacl{$authuser} =~ /d/));
    399383
    400384  # Snag the free blocks.
     
    403387        "routed='n' order by cidr");
    404388  $sth->execute();
     389  my @unrouted;
     390  my $rowclass = 0;
    405391  while (my @data = $sth->fetchrow_array()) {
    406392    my $cidr = new NetAddr::IP $data[0];
    407     my @row = ("$cidr", $cidr->range);
    408     printRow(\@row, 'color1' ) if($count%2==0);
    409     printRow(\@row, 'color2' ) if($count%2!=0);
    410     $count++;
    411   }
    412 
    413   print "</table>\n";
     393    my %row = (
     394        rowclass => $rowclass % 2,
     395        fblock => "$cidr",
     396        frange => $cidr->range
     397        );
     398    push @unrouted, \%row;
     399    $rowclass++;
     400  }
     401  $page->param(unrouted => \@unrouted);
     402
    414403} # showMaster
    415404
Note: See TracChangeset for help on using the changeset viewer.