Changeset 117


Ignore:
Timestamp:
09/01/11 15:55:00 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Add getParents (untested) and isParent (tested) subs
Add some supporting hashes for entity -> parent(entity)

relationships in the database - private to DNSDB.pm

Rename tmp_ruri to uri_self for clarity and reuse
Move uri_self munging from ##common area so that more

subs can use it

Update group tree to change the current group by clicking

the group name. Working comments need to be cleaned up
and choose-a-group dropdown removed from the menu

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r116 r117  
    3434        &getSOA &getRecLine &getDomRecs &getRecCount
    3535        &addRec &updateRec &delRec
    36         &isParent
     36        &getParents
     37        &isParent
    3738        &domStatus &importAXFR
    3839        &export
     
    5253                &getSOA &getRecLine &getDomRecs &getRecCount
    5354                &addRec &updateRec &delRec
    54                 &isParent
     55                &getParents
     56                &isParent
    5557                &domStatus &importAXFR
    5658                &export
     
    13221324
    13231325
     1326  # Reference hashes.
     1327  my %par_tbl = (
     1328                group   => 'groups',
     1329                user    => 'users',
     1330                defrec  => 'default_records',
     1331                domain  => 'domains',
     1332                record  => 'records'
     1333        );
     1334  my %id_col = (
     1335                group   => 'group_id',
     1336                user    => 'user_id',
     1337                defrec  => 'record_id',
     1338                domain  => 'domain_id',
     1339                record  => 'record_id'
     1340        );
     1341  my %par_col = (
     1342                group   => 'parent_group_id',
     1343                user    => 'group_id',
     1344                defrec  => 'group_id',
     1345                domain  => 'group_id',
     1346                record  => 'domain_id'
     1347        );
     1348  my %par_type = (
     1349                group   => 'group',
     1350                user    => 'group',
     1351                defrec  => 'group',
     1352                domain  => 'group',
     1353                record  => 'domain'
     1354        );
     1355
    13241356## DNSDB::getParents()
    13251357# Find out which entities are parent to the requested id
     
    13291361  my $id = shift;
    13301362  my $type = shift;
    1331 
    1332   # Get immediate parent
    1333   $par_col = 'group_id';
    1334 
    1335   if ($type eq 'user') {
    1336     $table = 'users';
    1337     $id_col = 'user_id';
    1338   }
    1339   if ($type eq 'defrec') {
    1340     $table = 'default_records';
    1341     $id_col = 'record_id';
    1342   }
    1343   if ($type eq 'domain') {
    1344     $table = 'domains';
    1345     $id_col = 'domain_id';
    1346   }
    1347   if ($type eq 'record') {
    1348     $table = 'records';
    1349     $id_col = 'record_id';
    1350     $par_col = 'domain_id';
    1351   }
    1352 
    1353 $dbh->do("SELECT $par_col FROM $table WHERE $id_col = ?",
     1363  my $depth = shift || 'all';   # valid values:  'all', 'immed', <int> (stop at this group ID)
     1364
     1365  my @parlist;
     1366
     1367  while (1) {
     1368    my $result = $dbh->selectrow_hashref("SELECT $par_col{$type} FROM $par_tbl{$type} WHERE $id_col{$type} = ?",
     1369        undef, ($id) );
     1370    unshift @parlist, ($result->{$par_col{$type}} => $par_type{$type});
     1371    last if $result->{$par_col{$type}} == 1;    # group 1 is its own parent
     1372    $type = $par_type{$type};
     1373    $id = $result->{$par_col{$type}};
     1374  }
     1375
     1376  return \@parlist;
    13541377
    13551378} # end getParents()
     1379
     1380
     1381## DNSDB::isParent()
     1382# Returns true if $id1 is a parent of $id2, false otherwise
     1383sub isParent {
     1384  my $dbh = shift;
     1385  my $id1 = shift;
     1386  my $type1 = shift;
     1387  my $id2 = shift;
     1388  my $type2 = shift;
     1389##todo:  immediate, secondary, full (default)
     1390
     1391  # Return false on impossible relations
     1392  return 0 if $type1 eq 'record';       # nothing may be a child of a record
     1393  return 0 if $type1 eq 'defrec';       # nothing may be a child of a record
     1394  return 0 if $type1 eq 'user';         # nothing may be child of a user
     1395  return 0 if $type1 eq 'domain' && $type2 ne 'record'; # domain may not be a parent of anything other than a record
     1396
     1397  # group 1 is the ultimate root parent
     1398  return 1 if $type1 eq 'group' && $id1 == 1;
     1399
     1400# almost the same loop as getParents() above
     1401  my $id = $id2;
     1402  my $type = $type2;
     1403  my $foundparent = 0;
     1404my $tmp = 0;
     1405  while (1) {
     1406my $sql = "SELECT $par_col{$type} FROM $par_tbl{$type} WHERE $id_col{$type} = ?";
     1407    my $result = $dbh->selectrow_hashref($sql,
     1408        undef, ($id) ) or warn $dbh->errstr." $sql";
     1409    if ($result->{$par_col{$type}} == $id1) {
     1410      $foundparent = 1;
     1411      last;
     1412    }
     1413    # group 1 is its own parent.  need this here more to break strange loops than for detecting a parent
     1414    last if $result->{$par_col{$type}} == 1;
     1415    $type = $par_type{$type};
     1416    $id = $result->{$par_col{$type}};
     1417last if $tmp++ > 10;
     1418  }
     1419
     1420  return $foundparent;
     1421} # end isParent()
    13561422
    13571423
  • trunk/dns.cgi

    r114 r117  
    9999my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl");
    100100
     101## set up "URL to self"
     102# @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
     103my $uri_self = $ENV{REQUEST_URI};
     104$uri_self =~ s/\&([a-z])/\&amp\;$1/g;
     105
     106# le sigh.  and we need to strip any previous action
     107$uri_self =~ s/\&amp;action=[^&]+//g;
     108
     109# and search filter options.  these get stored in the session, but discarded
     110# as soon as you switch to a different page.
     111##fixme:  think about retaining these on a per-page basis, as well as offset;  same as the sort-order bits
     112no warnings qw(uninitialized);
     113$uri_self =~ s/\&amp;startwith=[a-z09-]*(\&)?/$1/g;
     114$uri_self =~ s/\&amp;searchsubs=[a-z09-]*(\&)?/$1/g;
     115$uri_self =~ s/\&amp;filter=[a-z09-]*(\&)?/$1/g;
     116use warnings qw(uninitialized);
     117
    101118# default
    102119#my $perpage = 15;
     
    160177    # fiddle session-stored group data
    161178    # magic incantation to... uhhh...
     179
     180    # ... and the "change group" bits...
     181    $uri_self =~ s/\&amp;group=[^&]*//g;
     182
    162183    $session->param('curgroup', $webvar{group});
    163184    $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));
     
    12121233  $page->param(groupname => groupName($dbh,$curgroup));
    12131234  $page->param(logingrp => groupName($dbh,$logingroup));
     1235  $page->param(logingrp_num => $logingroup);
    12141236
    12151237  $page->param(mayimport => $permissions{admin} || $permissions{domain_create});
     
    12251247  fill_grouplist("grouplist");
    12261248
    1227 ## set up "URL to self"
    1228 # @#$%@%@#% XHTML - & in a URL must be escaped.  >:(
    1229   my $tmp_ruri = $ENV{REQUEST_URI};
    1230   $tmp_ruri =~ s/\&([a-z])/\&amp\;$1/g;
    1231 
    1232 # le sigh.  and we need to strip any previous action
    1233   $tmp_ruri =~ s/\&amp;action=[^&]+//g;
    1234 
    1235 # and search filter options.  these get stored in the session, but discarded
    1236 # as soon as you switch to a different page.
    1237 ##fixme:  think about retaining these on a per-page basis, as well as offset;  same as the sort-order bits
    1238   no warnings qw(uninitialized);
    1239   $tmp_ruri =~ s/\&amp;startwith=[a-z09-]*(\&)?/$1/g;
    1240   $tmp_ruri =~ s/\&amp;searchsubs=[a-z09-]*(\&)?/$1/g;
    1241   $tmp_ruri =~ s/\&amp;filter=[a-z09-]*(\&)?/$1/g;
    1242   use warnings qw(uninitialized);
    1243 
    12441249# fill in the URL-to-self
    1245   $page->param(whereami => $tmp_ruri);
     1250  $page->param(whereami => $uri_self);
    12461251}
    12471252
     
    12921297    my %row;
    12931298    $row{grpname} = groupName($dbh,$_);
     1299    $row{grpnum} = $_;
     1300    $row{whereami} = $uri_self;
    12941301        # for all that HTML::Template is supposed to keep the HTML out of the Perl, this is so much more compact...
    1295     $row{grpdisp} = ($_ == $cur ? "<b>$row{grpname}</b>" : $row{grpname});
     1302#    $row{grpdisp} = ($_ == $cur ? "<b>$row{grpname}</b>" : $row{grpname});
     1303$row{curgrp} = ($_ == $cur);
     1304$row{expanded} = isParent($dbh, $_, 'group', $cur, 'group');
     1305$row{expanded} = 1 if $_ == $cur;
    12961306    $row{subs} = fill_grptree($_,$cur,$indent.'    ');
    12971307    $row{indent} = $indent;
     
    16911701  my $childlist = join(',',@childgroups);
    16921702
     1703##fixme:  need to reorder list so that we can display a pseudotree in group dropdowns
     1704
    16931705  # weesa gonna discard parent_group_id for now
    16941706  my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ".
  • trunk/templates/dns.css

    r100 r117  
    242242        vertical-align: top;
    243243}
     244
     245/* Allow current group in list to be easily flagged */
     246/* For reasons of "CSS is stupid" you apparently can't apply the font to the <li> *eyeroll* */
     247label.curgrp {
     248        font-weight: bold;
     249        font-size: 1.2em;
     250}
     251span.curgrp {
     252        font-weight: bold;
     253        font-size: 1.2em;
     254}
  • trunk/templates/grptree.tmpl

    r99 r117  
    11<TMPL_VAR NAME=indent><ul class="grptree">
    22<TMPL_LOOP NAME=treelvl><TMPL_VAR NAME=indent>  <li class="<TMPL_IF NAME=subs>hassub<TMPL_ELSE>leaf</TMPL_IF>">
    3 <TMPL_IF name=subs><TMPL_VAR NAME=indent>    <label for="grp_<TMPL_VAR NAME=grpname>"><TMPL_VAR NAME=grpdisp></label>
    4 <TMPL_VAR NAME=indent>    <input type="checkbox" class="grptreebox" checked="checked" id="grp_<TMPL_VAR NAME=grpname>" /><TMPL_ELSE><TMPL_VAR NAME=indent>    <TMPL_VAR NAME=grpdisp></TMPL_IF>
     3<TMPL_IF name=subs><TMPL_VAR NAME=indent>    <label for="grp_<TMPL_VAR NAME=grpname>"<TMPL_IF curgrp> class="curgrp"</TMPL_IF>><a href="<TMPL_VAR NAME=whereami>&group=<TMPL_VAR NAME=grpnum>&action=chgroup"><TMPL_VAR NAME=grpname></a></label>
     4<TMPL_VAR NAME=indent>    <input type="checkbox" class="grptreebox" <TMPL_IF expanded> checked="checked" </TMPL_IF>id="grp_<TMPL_VAR NAME=grpname>" /><TMPL_ELSE><TMPL_VAR NAME=indent>    <a href="<TMPL_VAR NAME=whereami>&group=<TMPL_VAR NAME=grpnum>&action=chgroup"><TMPL_IF curgrp><span class="curgrp"><TMPL_VAR NAME=grpname></span><TMPL_ELSE><TMPL_VAR NAME=grpname></TMPL_IF></a></TMPL_IF>
    55<TMPL_VAR NAME=subs><TMPL_VAR NAME=indent>  </li>
    66</TMPL_LOOP><TMPL_VAR NAME=indent></ul>
  • trunk/templates/menu.tmpl

    r111 r117  
    2727<ul class="grptree">
    2828  <li class="<TMPL_IF NAME=subs>hassub<TMPL_ELSE>leaf</TMPL_IF>">
    29 <TMPL_IF name=subs>    <label for="<TMPL_VAR NAME=logingrp>"><TMPL_IF inlogingrp><b><TMPL_VAR NAME=logingrp></b><TMPL_ELSE><TMPL_VAR NAME=logingrp></TMPL_IF></label>
     29<TMPL_IF name=subs>    <label for="<TMPL_VAR NAME=logingrp>"<TMPL_IF inlogingrp> class="curgrp"</TMPL_IF>><a href="<TMPL_VAR NAME=whereami>&group=<TMPL_VAR NAME=logingrp_num>&action=chgroup"><TMPL_VAR NAME=logingrp></a></label>
    3030    <input type="checkbox" checked="checked" id="<TMPL_VAR NAME=logingrp>" /><TMPL_ELSE>
    31     <TMPL_IF inlogingrp><b><TMPL_VAR NAME=logingrp></b><TMPL_ELSE><TMPL_VAR NAME=logingrp></TMPL_IF></TMPL_IF>
     31    <!-- span<TMPL_IF inlogingrp> class="curgrp"</TMPL_IF> -->
     32<TMPL_VAR NAME=logingrp></TMPL_IF>
    3233<TMPL_VAR NAME=grptree>
    3334  </li>
Note: See TracChangeset for help on using the changeset viewer.