From 923267d75448b2ec9c320e65fd3115ea04c4e74d Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Thu, 4 Jul 2013 11:55:46 +0200 Subject: [PATCH] added delete button, system now checking if included files all exist --- config/settings.xml | 3 - xml_spielwiese/cgitest.pl | 235 +++++++++++++++++++++++++------------- 2 files changed, 157 insertions(+), 81 deletions(-) delete mode 100644 config/settings.xml diff --git a/config/settings.xml b/config/settings.xml deleted file mode 100644 index 2267ce0..0000000 --- a/config/settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/xml_spielwiese/cgitest.pl b/xml_spielwiese/cgitest.pl index c76bf2e..dd97f5a 100755 --- a/xml_spielwiese/cgitest.pl +++ b/xml_spielwiese/cgitest.pl @@ -2,15 +2,18 @@ print "Content-type: text/html\n\n"; # TODO -# do not accept "..." as input file # what happens when files are not writable? -# cannot inherit from files with the wrong specification! +# delete button +# field size information +# check for maximum value # DONE # do not include wrong type, different specfile # whine, wenn specfile/setfiles not found # supress circular dependencies # nested include graphic +# cannot inherit from files with the wrong specification! +# do not accept "..." as input file my $me = "cgitest.pl"; @@ -90,24 +93,26 @@ if ( $cgiHash{'print'} eq 'fileSelection' ) { if ( $cgiHash{'print'} eq 'spectree' ) { print "
Available Settings
\n"; - unless(-e $confDir."/".$cgiHash{'configFile'}){ + unless ( -e $confDir . "/" . $cgiHash{'configFile'} ) { print "

config file does not exist

"; exit; } parseSetAndSpec( $cgiHash{'configFile'} ); - print "
specifications loaded from $specfileName
"; + print +"
specifications loaded from $specfileName
"; print_registers($specfile); } if ( $cgiHash{'print'} eq 'settree' ) { print "
Selected Settings
\n"; - unless(-e $confDir."/".$cgiHash{'configFile'}){ + unless ( -e $confDir . "/" . $cgiHash{'configFile'} ) { print "

config file does not exist

"; exit; } parseSetAndSpec( $cgiHash{'configFile'} ); - buildAncestry($setfileName,""); #arg1: target file, # arg2: recursion parent target file + buildAncestry( $setfileName, "" ) + ; #arg1: target file, # arg2: recursion parent target file # assignFieldColors();#obsolete @@ -140,6 +145,11 @@ if ( defined $cgiHash{'action'} ) { if ( $cgiHash{'action'} eq 'createFile' ) { createFile( $cgiHash{'configFile'}, $cgiHash{'specFile'} ); } + + if ( $cgiHash{'action'} eq 'deleteFile' ) { + deleteFile( $cgiHash{'configFile'} ); + } + if ( $cgiHash{'action'} eq 'changeAncestor' ) { parseSet( $cgiHash{'configFile'} ); changeAncestor( $cgiHash{'newAncestor'} ); @@ -149,6 +159,17 @@ if ( defined $cgiHash{'action'} ) { #################### SUBLAND ###################### +sub deleteFile { + my $configFileName = $_[0]; + my $configFile = $confDir . "/" . $configFileName; + unless ( -e $configFile ) { + print "

selected file not found

"; + exit; + } + unlink($configFile); + print "

config file was deleted

"; +} + sub createFile { my $configFileName = $_[0]; @@ -182,6 +203,7 @@ sub print_ancestorInfo { #print "my ancestry:
"; print "
"; + #print ""; - if ($fileLevelHash{$ancestor} eq "1"){ - print < X  EOF @@ -210,6 +232,7 @@ EOF "changeAncestor(this.options[this.selectedIndex].text)" ); } + #print "
"; if (@ancestryList) { # if ancestry is not empty, print current ancestry as a nested table @@ -195,8 +217,8 @@ sub print_ancestorInfo { for my $ancestor (@ancestryList) { print "$ancestor
"; print "
"; print "$setfileName"; @@ -231,11 +254,12 @@ sub parseSetAndSpec { parseSet( $_[0] ); $specfileName = $settree->findvalue("/MAPS/\@specDbFile"); $specfile = $specDir . "/" . $specfileName; - unless(-e $specfile){ - print "

specification file \"$specfileName\" could not be found in the specification directory \"$specDir\"

"; + unless ( -e $specfile ) { + print +"

specification file \"$specfileName\" could not be found in the specification directory \"$specDir\"

"; exit; } - $spectree = $parser->parse_file($specfile); + $spectree = $parser->parse_file($specfile); } sub parseSet { @@ -246,46 +270,67 @@ sub parseSet { } sub buildAncestry { # recursive - my $xmlfileName = $_[0]; + my $xmlfileName = $_[0]; my $parentXmlFileName = $_[1]; if ( $xmlfileName eq "" ) { return; } - - if ($parentXmlFileName eq $xmlfileName) { + + # check if you are not including yourself + if ( $parentXmlFileName eq $xmlfileName ) { print "

It's a bad idea to try to include yourself!

"; - print "

The faulty include directive was removed.

"; - print "

"; - changeAncestor(""); # break the evil circle where it was closed! - exit; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; } - - for (@ancestryList){ # suppres circular dependencies! - if ($xmlfileName eq $_) { + # check against circular dependencies + for (@ancestryList) { # suppres circular dependencies! + if ( $xmlfileName eq $_ ) { print "

No circular includes, please!

"; print "

"; - print $parentXmlFileName."->".join("->",@ancestryList)."->".$setfileName; + print $parentXmlFileName. "->" + . join( "->", @ancestryList ) . "->" + . $setfileName; print "

"; print "

The faulty include directive was removed.

"; - print "

"; - changeAncestor(""); # break the evil circle where it was closed! + print + "

"; + changeAncestor(""); # break the evil circle where it was closed! exit; + #die "no circular includes please! $!"; return; } } + my $xmlfile = $confDir . "/" . $xmlfileName; + + # check if all files in the ancestry really exist! + unless (-e $xmlfile) { + + print "

You are trying to include a file that does not exist

"; + print "

"; + print "".$xmlfileName.""."->" + . join( "->", @ancestryList ) . "->" + . $setfileName; + print "

"; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; + return; + } - - my $xmlfile = $confDir . "/" . $xmlfileName; my $xmltree; if ( $xmlfile eq $setfile ) { $xmltree = $settree; } else { + # we got an ancestor here, write him to the ancestor list unshift( @ancestryList, $xmlfileName ); $xmltree = $parser->parse_file($xmlfile); @@ -298,29 +343,33 @@ sub buildAncestry { # recursive my $ancestorFileName = $xmltree->findvalue("/MAPS/\@inheritSettingsFrom") || ""; - my $currentMapsType = $xmltree->findvalue("/MAPS/\@type"); + my $currentMapsType = $xmltree->findvalue("/MAPS/\@type"); my $currentSpecFileName = $xmltree->findvalue("/MAPS/\@specDbFile"); - + # compliance checking MAPS type - unless ($currentMapsType eq $setMapsType){ - print "

the included config file does not comply with the MAPS type of the current config file

"; - print "

The faulty include directive was removed.

"; - print "

"; - changeAncestor(""); # break the evil circle where it was closed! - exit; + unless ( $currentMapsType eq $setMapsType ) { + print +"

the included config file does not comply with the MAPS type of the current config file

"; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; } + # compliance checking specDbFile - unless ($currentSpecFileName eq $specfileName){ - print "

the included config file is not based on the same specification file as current config file

"; - print "

The faulty include directive was removed.

"; - print "

"; - changeAncestor(""); # break the evil circle where it was closed! - exit; + unless ( $currentSpecFileName eq $specfileName ) { + print +"

the included config file is not based on the same specification file as current config file

"; + print "

The faulty include directive was removed.

"; + print "

"; + changeAncestor(""); # break the evil circle where it was closed! + exit; } unless ( $ancestorFileName eq "" ) { # this block is executed when an ancestor is found - buildAncestry($ancestorFileName,$xmlfileName); # recursion, second argument is the target file from THIS parent recursion call + 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 ); @@ -496,50 +545,74 @@ sub print_fileSelection { my $configFile = $_[0]; - print ""; - print ""; - - print ""; - - print ""; - print "
"; - print ""; - print ""; - print ""; - - print ""; - - print ""; - - print ""; - - print ""; - - print "
selected config file:"; - print "
"; + print "

selected config file

"; + print "

"; + print_fileSelector( $configFile, "fileSelector", "loadFile()" ); - print "

"; print ""; - print "
"; - - print "

"; - print ""; - print ""; + print +""; - print ""; + print ""; + + print "

"; - print "
"; - print "create new config file:"; - print "
"; + print "

"; + + + print "

create new config file

"; + print "

"; print ""; - print "

"; print_specSelector(); - print ""; - print -""; - print "
"; - print "
"; + + +# print ""; +# print ""; +# +# print ""; +# +# print ""; +# print "
"; +# print ""; +# print ""; +# print ""; +# +# print ""; +# +# print ""; +# +# print ""; +# +# print ""; +# +# print "
selected config file:"; +# print "
"; +# print_fileSelector( $configFile, "fileSelector", "loadFile()" ); +# print ""; +# print +#""; +# print +#""; +# print "
"; +# +# print "

"; +# print ""; +# print ""; +# +# print ""; +# +# print "
"; +# print "create new config file:"; +# print "
"; +# print ""; +# print ""; +# print_specSelector(); +# print ""; +# print +#""; +# print "
"; +# print "
"; } sub changeAncestor { @@ -856,6 +929,12 @@ function changeAncestor(newAncestor){ reloadSetTree(); } +function deleteFile(){ + var file_ = encodeURIComponent(selectedConfigFile()); + getdata('$me?action=deleteFile&configFile='+file_,false); + loadFile(); +} + function selectedConfigFile(){ if(document.getElementById("fileSelector")){ -- 2.43.0