Changeset 532


Ignore:
Timestamp:
10/30/12 16:01:39 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL to IPDB.pm for pool-selector for static IPs
on allocation confirmation page. See #34.

Location:
trunk/cgi-bin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r531 r532  
    2828        &addMaster
    2929        &listSummary &listMaster &listRBlock &listFree &listPool
    30         &getTypeList
     30        &getTypeList &getPoolSelect
    3131        &getParent &getRoutedCity
    3232        &allocateBlock &updateBlock &deleteBlock &getBlockData
     
    4242                &addMaster
    4343                &listSummary &listMaster &listRBlock &listFree &listPool
    44                 &getTypeList
     44                &getTypeList &getPoolSelect
    4545                &getParent &getRoutedCity
    4646                &allocateBlock &updateBlock &deleteBlock &getBlockData
     
    497497  return $tlist;
    498498}
     499
     500
     501## IPDB::getPoolSelect()
     502# Get a list of pools matching the passed city and type that have 1 or more free IPs
     503sub getPoolSelect {
     504  my $dbh = shift;
     505  my $iptype = shift;
     506  my $pcity = shift;
     507
     508  my ($ptype) = ($iptype =~ /^(.)i$/);
     509  return if !$ptype;
     510  $ptype .= '_';
     511
     512  my $plist = $dbh->selectall_arrayref(
     513        "SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool) AS poolcit, ".
     514        "poolips.pool AS poolblock, COUNT(*) AS poolfree FROM poolips,allocations ".
     515        "WHERE poolips.available='y' AND poolips.pool=allocations.cidr ".
     516        "AND allocations.city = ? AND poolips.type LIKE ? ".
     517        "GROUP BY pool", { Slice => {} }, ($pcity, $ptype) );
     518  return $plist;
     519} # end getPoolSelect()
    499520
    500521
  • trunk/cgi-bin/main.cgi

    r531 r532  
    397397
    398398  if ($webvar{alloctype} =~ /^.i$/) {
    399     my ($base,undef) = split //, $webvar{alloctype};    # split into individual chars
    400 
    401 # Ewww.  But it works.
    402     $sth = $ip_dbh->prepare("SELECT (SELECT city FROM allocations WHERE cidr=poolips.pool), ".
    403         "poolips.pool, COUNT(*) FROM poolips,allocations WHERE poolips.available='y' AND ".
    404         "poolips.pool=allocations.cidr AND allocations.city='$webvar{pop}' AND poolips.type LIKE '".$base."_' ".
    405         "GROUP BY pool");
    406     $sth->execute;
    407     my $optionlist;
    408 
    409     my @poollist;
    410     while (my ($poolcit,$poolblock,$poolfree) = $sth->fetchrow_array) {
    411       # city,pool cidr,free IP count
    412       if ($poolfree > 0) {
    413         my %row = (poolcit => $poolcit, poolblock => $poolblock, poolfree => $poolfree);
    414         push (@poollist, \%row);
    415       }
    416     }
     399    my $plist = getPoolSelect($ip_dbh, $webvar{alloctype}, $webvar{pop});
    417400    $page->param(staticip => 1);
    418     $page->param(poollist => \@poollist);
     401    $page->param(poollist => $plist) if $plist;
    419402    $cidr = "Single static IP";
    420403##fixme:  need to handle "no available pools"
Note: See TracChangeset for help on using the changeset viewer.