Changeset 529 for trunk


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.

Location:
trunk
Files:
3 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
  • trunk/cgi-bin/main.cgi

    r528 r529  
    327327    if ($webvar{fbtype} ne 'y') {
    328328      # 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 form
    333       $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);
    335335    } 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);
    350340    }
    351341  } else {
     
    364354    $page->param(pops => \@pops);
    365355
    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);
    381360  }
    382361
  • trunk/templates/assign.tmpl

    r517 r529  
    3939<select name="alloctype">
    4040<TMPL_LOOP name=typelist>
    41         <option value="<TMPL_VAR NAME=tval>"<TMPL_VAR NAME=sel>><TMPL_VAR NAME=type></option></TMPL_LOOP>
     41        <option value="<TMPL_VAR NAME=type>"<TMPL_IF sel> selected</TMPL_IF>><TMPL_VAR NAME=listname></option></TMPL_LOOP>
    4242</select>
    4343<input type="button" value=" ? " onclick="helpAllocTypes()" class="regular">
Note: See TracChangeset for help on using the changeset viewer.