Changeset 529 for trunk/cgi-bin/IPDB.pm


Ignore:
Timestamp:
10/25/12 15:43:55 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Clean up and move SQL behind block assignment page to IPDB.pm. See #34.

File:
1 edited

Legend:

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

    r528 r529  
    2828        &addMaster
    2929        &listSummary &listMaster &listRBlock &listFree &listPool
    30         &getRoutedCity
     30        &getTypeList
     31        &getParent &getRoutedCity
    3132        &allocateBlock &deleteBlock &getBlockData
    3233        &getNodeList
     
    4142                &addMaster
    4243                &listSummary &listMaster &listRBlock &listFree &listPool
    43                 &getRoutedCity
     44                &getTypeList
     45                &getParent &getRoutedCity
    4446                &allocateBlock &deleteBlock &getBlockData
    4547                &getNodeList
     
    467469  return \@poolips;
    468470} # 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
     477sub 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
     505sub 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()
    469513
    470514
Note: See TracChangeset for help on using the changeset viewer.