Changeset 19 for trunk/DNSDB.pm


Ignore:
Timestamp:
10/09/09 17:49:14 (15 years ago)
Author:
Kris Deugau
Message:

/trunk

checkpoint

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r18 r19  
    2323@ISA            = qw(Exporter);
    2424@EXPORT_OK      = qw(
    25         &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA
     25        &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName &getSOA
    2626        &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    2727        %typemap %reverse_typemap
     
    3030@EXPORT         = (); # Export nothing by default.
    3131%EXPORT_TAGS    = ( ALL => [qw(
    32                 &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &grpName &getSOA
     32                &initGlobals &connectDB &finish &addDomain &delDomain &domainName &addGroup &getChildren &grpName
     33&getSOA
    3334                &getRecLine &getDomRecs &addRec &updateRec &delRec &domStatus
    3435                %typemap %reverse_typemap
     
    318319
    319320
     321## DNSDB::getChildren()
     322# Get a list of all groups whose parent^n is group <n>
     323# Takes a database handle, group ID, and reference to an array to put the group IDs in
     324# Calls itself
     325sub getChildren {
     326  $errstr = '';
     327  my $dbh = shift;
     328  my $rootgrp = shift;
     329  my $grpdest = shift;
     330
     331  # special break for default group;  otherwise we get stuck.
     332  if ($rootgrp == 1) {
     333    # by definition, group 1 is the Root Of All Groups
     334    my $sth = $dbh->prepare("SELECT group_id FROM groups");
     335    $sth->execute;
     336    my @grplist;
     337    while (my @this = $sth->fetchrow_array) {
     338      push @$grpdest, @this;
     339    }
     340  } else {
     341    my $sth = $dbh->prepare("SELECT group_id FROM groups WHERE parent_group_id=?");
     342    $sth->execute($rootgrp);
     343    return if $sth->rows == 0;
     344    my @grplist;
     345    while (my ($grp) = $sth->fetchrow_array) {
     346      push @$grpdest, $grp;
     347      getChildren($dbh,$grp,$grpdest);
     348    }
     349  }
     350} # end getChildren()
     351
     352
    320353## DNSDB::grpName()
    321354# Return the group name based on a group ID
Note: See TracChangeset for help on using the changeset viewer.