- Timestamp:
- 09/01/11 15:55:00 (13 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r116 r117 34 34 &getSOA &getRecLine &getDomRecs &getRecCount 35 35 &addRec &updateRec &delRec 36 &isParent 36 &getParents 37 &isParent 37 38 &domStatus &importAXFR 38 39 &export … … 52 53 &getSOA &getRecLine &getDomRecs &getRecCount 53 54 &addRec &updateRec &delRec 54 &isParent 55 &getParents 56 &isParent 55 57 &domStatus &importAXFR 56 58 &export … … 1322 1324 1323 1325 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 1324 1356 ## DNSDB::getParents() 1325 1357 # Find out which entities are parent to the requested id … … 1329 1361 my $id = shift; 1330 1362 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; 1354 1377 1355 1378 } # end getParents() 1379 1380 1381 ## DNSDB::isParent() 1382 # Returns true if $id1 is a parent of $id2, false otherwise 1383 sub 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; 1404 my $tmp = 0; 1405 while (1) { 1406 my $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}}; 1417 last if $tmp++ > 10; 1418 } 1419 1420 return $foundparent; 1421 } # end isParent() 1356 1422 1357 1423 -
trunk/dns.cgi
r114 r117 99 99 my $footer = HTML::Template->new(filename => "$templatedir/footer.tmpl"); 100 100 101 ## set up "URL to self" 102 # @#$%@%@#% XHTML - & in a URL must be escaped. >:( 103 my $uri_self = $ENV{REQUEST_URI}; 104 $uri_self =~ s/\&([a-z])/\&\;$1/g; 105 106 # le sigh. and we need to strip any previous action 107 $uri_self =~ s/\&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 112 no warnings qw(uninitialized); 113 $uri_self =~ s/\&startwith=[a-z09-]*(\&)?/$1/g; 114 $uri_self =~ s/\&searchsubs=[a-z09-]*(\&)?/$1/g; 115 $uri_self =~ s/\&filter=[a-z09-]*(\&)?/$1/g; 116 use warnings qw(uninitialized); 117 101 118 # default 102 119 #my $perpage = 15; … … 160 177 # fiddle session-stored group data 161 178 # magic incantation to... uhhh... 179 180 # ... and the "change group" bits... 181 $uri_self =~ s/\&group=[^&]*//g; 182 162 183 $session->param('curgroup', $webvar{group}); 163 184 $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup')); … … 1212 1233 $page->param(groupname => groupName($dbh,$curgroup)); 1213 1234 $page->param(logingrp => groupName($dbh,$logingroup)); 1235 $page->param(logingrp_num => $logingroup); 1214 1236 1215 1237 $page->param(mayimport => $permissions{admin} || $permissions{domain_create}); … … 1225 1247 fill_grouplist("grouplist"); 1226 1248 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])/\&\;$1/g;1231 1232 # le sigh. and we need to strip any previous action1233 $tmp_ruri =~ s/\&action=[^&]+//g;1234 1235 # and search filter options. these get stored in the session, but discarded1236 # 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 bits1238 no warnings qw(uninitialized);1239 $tmp_ruri =~ s/\&startwith=[a-z09-]*(\&)?/$1/g;1240 $tmp_ruri =~ s/\&searchsubs=[a-z09-]*(\&)?/$1/g;1241 $tmp_ruri =~ s/\&filter=[a-z09-]*(\&)?/$1/g;1242 use warnings qw(uninitialized);1243 1244 1249 # fill in the URL-to-self 1245 $page->param(whereami => $ tmp_ruri);1250 $page->param(whereami => $uri_self); 1246 1251 } 1247 1252 … … 1292 1297 my %row; 1293 1298 $row{grpname} = groupName($dbh,$_); 1299 $row{grpnum} = $_; 1300 $row{whereami} = $uri_self; 1294 1301 # 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; 1296 1306 $row{subs} = fill_grptree($_,$cur,$indent.' '); 1297 1307 $row{indent} = $indent; … … 1691 1701 my $childlist = join(',',@childgroups); 1692 1702 1703 ##fixme: need to reorder list so that we can display a pseudotree in group dropdowns 1704 1693 1705 # weesa gonna discard parent_group_id for now 1694 1706 my $sth = $dbh->prepare("SELECT group_id,parent_group_id,group_name FROM groups ". -
trunk/templates/dns.css
r100 r117 242 242 vertical-align: top; 243 243 } 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* */ 247 label.curgrp { 248 font-weight: bold; 249 font-size: 1.2em; 250 } 251 span.curgrp { 252 font-weight: bold; 253 font-size: 1.2em; 254 } -
trunk/templates/grptree.tmpl
r99 r117 1 1 <TMPL_VAR NAME=indent><ul class="grptree"> 2 2 <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> 5 5 <TMPL_VAR NAME=subs><TMPL_VAR NAME=indent> </li> 6 6 </TMPL_LOOP><TMPL_VAR NAME=indent></ul> -
trunk/templates/menu.tmpl
r111 r117 27 27 <ul class="grptree"> 28 28 <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> 30 30 <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> 32 33 <TMPL_VAR NAME=grptree> 33 34 </li>
Note:
See TracChangeset
for help on using the changeset viewer.