#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
+# TODO
+# do not accept "..." as input file
+# what happens when files are not writable?
+
+
my $me = "cgitest.pl";
use strict;
if ( $cgiHash{'print'} eq 'spectree' ) {
print "<div class='header'>Available Settings</div>\n";
parseSetAndSpec( $cgiHash{'configFile'} );
-"<div class='ancestorInfo' align='center'>specifications loaded from $specfileName</div>";
+ print "<div class='ancestorInfo' align='center'>specifications loaded from $specfileName</div>";
print_registers($specfile);
}
if ( $cgiHash{'print'} eq 'settree' ) {
print "<div class='header'>Selected Settings</div>\n";
parseSetAndSpec( $cgiHash{'configFile'} );
- buildAncestry($setfileName);
+ buildAncestry($setfileName,""); #arg1: target file, # arg2: recursion parent target file
# assignFieldColors();#obsolete
$settree = $ancestryTree; # not so elegant
- print "<table><tr>";
- print "<td>";
print_ancestorInfo();
- print "</td>";
- print "<td style='border-right:1px solid #000000'><br></td>";
- print "<td>";
- print
-"<div align='center'>you are editing<br><table><tr class='fileLevel'><td>$setfileName</td></tr></table></div>";
- print "</td>";
- print "</tr></table>";
print_registers($setfile);
}
sub print_ancestorInfo {
print "<div class='ancestorInfo' align='center'>";
- print "inherit settings from:<br>";
+ #print "my ancestry:<br>";
+ print "<table class='fileLevel'><tr><td>";
+ #print "<table class='fileLevel1' padding=0 spacing=0><tr><td>";
if (@ancestryList)
{ # if ancestry is not empty, print current ancestry as a nested table
# and also a button that can unlink the heritage
- print "<table class='fileLevel1'><tr><td>";
-
my $tableNestingDepth = @ancestryList;
for my $ancestor ( reverse(@ancestryList) ) {
print "<table class=fileLevel" . $fileLevelHash{$ancestor} . ">";
}
for my $ancestor (@ancestryList) {
- print "$ancestor</td></tr></table>";
+ print "$ancestor</td>";
+ if ($fileLevelHash{$ancestor} eq "1"){
+ print <<EOF;
+<td class='button_move' title='unlink includes' onclick='changeAncestor("")'> X </td>
+EOF
+
+ }
+ print "</tr></table>";
}
+ }
+ else { # print an ancestor selector!
+ print "include settings from:<br>";
+ print_fileSelector( "", "ancestorSelector",
+ "changeAncestor(this.options[this.selectedIndex].text)" );
- print "</td><td valign='bottom'>";
- print <<EOF;
-<table><tr><td class='button_move' onclick='changeAncestor("")'> X </td></tr></table>
-EOF
- print "</td></tr></table>";
- } else { # print an ancestor selector!
- print_fileSelector("","ancestorSelector","changeAncestor(this.options[this.selectedIndex].text)");
-
}
+ #print "</td></tr></table>";
+ print "</td></tr><tr><td>";
+ print "$setfileName";
+ print "</td></tr></table>";
print "</div>";
}
sub buildAncestry { # recursive
my $xmlfileName = $_[0];
+ my $parentXmlFileName = $_[1];
if ( $xmlfileName eq "" ) {
return;
}
+
+ if ($parentXmlFileName eq $xmlfileName) {
+ print "<p>It's a bad idea to try to include yourself!</p>";
+ print "<p>The faulty include directive was removed.</p>";
+ print "<p><input type='button' onclick='loadFile()' value='back'></p>";
+ changeAncestor(""); # break the evil circle where it was closed!
+ exit;
+ }
+
+ for (@ancestryList){ # suppres circular dependencies!
+ if ($xmlfileName eq $_) {
+
+
+ print "<p>No circular includes, please!</p>";
+ print "<p>";
+ print $parentXmlFileName."->".join("->",@ancestryList)."->".$setfileName;
+ print "</p>";
+ print "<p>The faulty include directive was removed.</p>";
+ print "<p><input type='button' onclick='loadFile()' value='back'></p>";
+ changeAncestor(""); # break the evil circle where it was closed!
+ exit;
+ #die "no circular includes please! $!";
+ return;
+ }
+ }
+
+
+
+
my $xmlfile = $confDir . "/" . $xmlfileName;
my $xmltree;
if ( $xmlfile eq $setfile ) {
$xmltree = $settree;
}
else {
-
- # we got an ancestor here
+ # we got an ancestor here, write him to the ancestor list
+ unshift( @ancestryList, $xmlfileName );
$xmltree = $parser->parse_file($xmlfile);
# tag all the fields with an heritage attribute
unless ( $ancestorFileName eq "" ) {
# this block is executed when an ancestor is found
- buildAncestry($ancestorFileName); # recursion
- push( @ancestryList, $ancestorFileName );
+ buildAncestry($ancestorFileName,$xmlfileName); # recursion, second argument is the target file from THIS parent recursion call
#integrate the current tree into the ancestryTree, overwrite older settings
mergeTrees( $ancestryTree, $xmltree );
sub print_fileSelector {
my $configFile = $_[0];
- my $elementId = $_[1];
- my $action = $_[2];
+ my $elementId = $_[1];
+ my $action = $_[2];
opendir( DIR, $confDir ) or die $!;
- print '<select name="fileSelectionDropdown" id="'.$elementId.'" onchange="'.$action.'">';
+ print '<select name="fileSelectionDropdown" id="'
+ . $elementId
+ . '" onchange="'
+ . $action . '">';
print "<option value='...'>...</option>";
my @xmlfiles;
print "<tr><td>";
print "<table>";
print "<tr>";
- print "<td>select config file:<td>";
+ print "<td>selected config file:<td>";
print "</tr>";
print "<tr>";
print "<td>";
- print_fileSelector($configFile,"fileSelector","loadFile()");
+ print_fileSelector( $configFile, "fileSelector", "loadFile()" );
print "</td>";
print "<td>";