Changeset 529 for trunk/cgi-bin
- Timestamp:
- 10/25/12 15:43:55 (12 years ago)
- Location:
- trunk/cgi-bin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cgi-bin/IPDB.pm
r528 r529 28 28 &addMaster 29 29 &listSummary &listMaster &listRBlock &listFree &listPool 30 &getRoutedCity 30 &getTypeList 31 &getParent &getRoutedCity 31 32 &allocateBlock &deleteBlock &getBlockData 32 33 &getNodeList … … 41 42 &addMaster 42 43 &listSummary &listMaster &listRBlock &listFree &listPool 43 &getRoutedCity 44 &getTypeList 45 &getParent &getRoutedCity 44 46 &allocateBlock &deleteBlock &getBlockData 45 47 &getNodeList … … 467 469 return \@poolips; 468 470 } # end listPool() 471 472 473 ## IPDB::getTypeList() 474 # Get an alloctype/description pair list suitable for dropdowns 475 # Takes a flag to determine which general groups of types are returned 476 # Returns an reference to an array of hashrefs 477 sub getTypeList { 478 my $dbh = shift; 479 my $tgroup = shift || 'a'; # technically optional, like this, but should 480 # really be specified in the call for clarity 481 my $tlist; 482 if ($tgroup eq 'p') { 483 # grouping 'p' - primary allocation types. These include static IP pools (_d and _p), 484 # dynamic-allocation ranges (_e), containers (_c), and the "miscellaneous" cn, in, and en types. 485 $tlist = $dbh->selectall_arrayref("SELECT type,listname FROM alloctypes WHERE listorder < 500 ". 486 "AND type NOT LIKE '_i' AND type NOT LIKE '_r' ORDER BY listorder", { Slice => {} }); 487 } elsif ($tgroup eq 'c') { 488 # grouping 'c' - contained types. These include all static IPs and all _r types. 489 $tlist = $dbh->selectall_arrayref("SELECT type,listname FROM alloctypes WHERE listorder <= 500 ". 490 " AND (type LIKE '_i' OR type LIKE '_r') ORDER BY listorder", { Slice => {} }); 491 } else { 492 # grouping 'a' - all standard allocation types. This includes everything 493 # but mm (present only as a formality). Make this the default. 494 $tlist = $dbh->selectall_arrayref("SELECT type,listname FROM alloctypes WHERE listorder <= 500 ". 495 " ORDER BY listorder", { Slice => {} }); 496 } 497 return $tlist; 498 } 499 500 501 ## IPDB::getParent() 502 # Get a block's parent's details 503 # Takes a database handle and CIDR block 504 # Returns a hashref to the parent routed or container block, if any 505 sub getParent { 506 my $dbh = shift; 507 my $block = shift; 508 509 my $pinfo = $dbh->selectrow_hashref("SELECT cidr,custid,type,city,description FROM allocations". 510 " WHERE cidr >>= ?", undef, ($block) ); 511 return $pinfo; 512 } # end getParent() 469 513 470 514 -
trunk/cgi-bin/main.cgi
r528 r529 327 327 if ($webvar{fbtype} ne 'y') { 328 328 # Snag the type of the container block from the database. 329 $sth = $ip_dbh->prepare("select type from allocations where cidr >>='$block'"); 330 $sth->execute;331 my @data = $sth->fetchrow_array;332 $ data[0] =~ s/c$/r/; # Munge the type into the correct form333 $page->param(fbdisptype => $list_alloctypes{$ data[0]});334 $page->param(type => $ data[0]);329 ## hmm. need a flag for parent class/type, sort of? 330 my $pblock = getParent($ip_dbh, $webvar{block}); 331 my $ptype = $pblock->{type}; 332 $ptype =~ s/c$/r/; 333 $page->param(fbdisptype => $list_alloctypes{$ptype}); 334 $page->param(type => $ptype); 335 335 } else { 336 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder < 500 ". 337 "and type not like '_i' and type not like '_r' order by listorder"); 338 $sth->execute; 339 my @typelist; 340 my $selflag = 0; 341 while (my @data = $sth->fetchrow_array) { 342 my %row = (tval => $data[0], 343 type => $data[1], 344 sel => ($selflag == 0 ? ' selected' : '') 345 ); 346 push (@typelist, \%row); 347 $selflag++; 348 } 349 $page->param(typelist => \@typelist); 336 # get "primary" alloctypes, since these are all that can correctly be assigned if we're in this branch 337 my $tlist = getTypeList($ip_dbh, 'p'); 338 $tlist->[0]->{sel} = 1; 339 $page->param(typelist => $tlist); 350 340 } 351 341 } else { … … 364 354 $page->param(pops => \@pops); 365 355 366 # could arguably include routing (500) in the list, but ATM it doesn't 367 # make sense, and in any case that shouldn't be structurally possible here. 368 $sth = $ip_dbh->prepare("select type,listname from alloctypes where listorder <= 500 order by listorder"); 369 $sth->execute; 370 my @typelist; 371 my $selflag = 0; 372 while (my @data = $sth->fetchrow_array) { 373 my %row = (tval => $data[0], 374 type => $data[1], 375 sel => ($selflag == 0 ? ' selected' : '') 376 ); 377 push (@typelist, \%row); 378 $selflag++; 379 } 380 $page->param(typelist => \@typelist); 356 # get all standard alloctypes 357 my $tlist = getTypeList($ip_dbh, 'a'); 358 $tlist->[0]->{sel} = 1; 359 $page->param(typelist => $tlist); 381 360 } 382 361
Note:
See TracChangeset
for help on using the changeset viewer.