<HTML><HEAD><TITLE>Konfigurations-Verwaltung: Hinzufgen
</TITLE></HEAD>
<BODY><H1>Dem Baum Informationen hinzufgen</H1>
<P>
</P>
<HR>

<H1>Standort-Information:</H1>
<FORM METHOD="POST" ACTION="/cgi-bin/cm1/add.pl">
<P>Projekt: <SELECT NAME="Project:">
<OPTION>            hesi
<OPTION>           pca
<OPTION>          irac
<OPTION SELECTED> cirs
</SELECT></P>
<P>Parent Node-Name: <INPUT NAME="Parent"> </P>
<P>Node-Name: <INPUT NAME="src"> </P>
<P>Einzelner Daten-Link: <INPUT NAME="link"></P>
<P>Geschtzter Node: <SELECT NAME="protected">
<OPTION SELECTED>  Nein 
<OPTION>           Ja 
</SELECT></P>
<HR>
<H1>Und nun?</H1>
<P><INPUT TYPE="submit" VALUE="Hinzufgen">
<INPUT TYPE="reset" VALUE="Felder zurcksetzen"></P>
</BODY></HTML>

#!/usr/bin/perl
require "/usr/local/lib/perl5/ipc.ph";
require "/usr/local/lib/perl5/shm.ph";

$cmdPath = './';
$dataPath = './';

Perl-Routinen zur Manipulation von CGI-Eingaben
S.E.Brenner@bioc.cam.ac.uk
$Header: /people/seb1005/http/cgi-bin/RCS/cgi-lib.pl,v 1.2 10.1.94 15:05:40 seb1005 Exp $

Copyright 1993 Steven E. Brenner
Unverffentlichte Arbeit.
Erlaubnis zur Nutzung und nderung dieser Bibliothek gewhrt, sofern das obenstehende 
Copyright gewhrleistet ist, Modifikationen dokumentiert sind und Bezahlung fr jede
Nutzung der Bibliothek gegeben ist.

ReadParse
Liest GET- oder POST-Daten ein, konvertiert sie zu unescaped Text und setzt key=value 
in jeden Eintrag der Liste. "@in" erstellt ebenfalls Schlssel/Wert-Paare in %in. Dabei 
wird '\0' zum Separieren mehrfacher Auswahlen verwendet.
Wenn ein variabler Glob-Parameter (z.B. *cgi_input) an ReadParse weitergeleitet wurde, 
ist die Information eher dort als in $in, @in und %in gespeichert.

sub ReadParse {
  if (@_) {
    local (*in) = @_;
  }
  local (%inPos, $count);
  local ($project, $location, $keywords, $rest);
  local ($i, $loc, $key, $newKey, $val);

  # Lies Text ein
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
      $in .= getc;
    }
  } 

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {

    # Wandle Pluszeichen in Leerzeichen um
    $in[$i] =~ s/\+/ /g;

    # Wandle %XX von hexadezimalen Zahlen in alphanumerische Zeichen um
    $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Splitte in Schlssel und Wert.
    $loc = index($in[$i],"=");
    $key = substr($in[$i],0,$loc);
    $val = substr($in[$i],$loc+1);

    $in{$key} .= '\0' if (defined($in{$key})); # \0 ist der mehrfache Separator
    $in{$key} .= $val;
  }

   # Rufe Routine zum Hinzufgen eines Node in den Baum auf
   &ChangeTree (%in );
}

# Prfe ob ein Node dieses Namens fr diesen Parent existiert
sub CheckParent {
   local ( $path, $cfgFile, $parent ) = @_;
   local ($line, @lines, $count);
   local ($key, $value, $nameFound, $linkFound );

      $match = 0;
      $count = 0;
      chdir $path;
      open ( FILE, "$cfgFile") && (@lines=<FILE>) && close (FILE);
      foreach $line (@lines) {
         next unless ( $line =~ /\bname/i );
         ($key, $value) = split ( /=/, $line);
         if ( $key =~ /name/ ) {
            $nameFound = $value;
         } elsif ( $key =~ /link/ ) {
            $linkFound = $value;
         }   

         $nameFound =~ tr/a-zA-Z0-9//cd;
         if ($nameFound eq $parent ) {
            $nameList[$count*2] = {$nameFound,$linkFound};
            $count++;
         }
      }
      close FILE;
      return $count;
}


sub ChangeTree  {
   local ( %in ) = @_;

      # Prfe Dateiinhalt auf Info
      $tree = $in{"Project:"};
      $tree =~ tr/A-Z/a-z/;
      $path = $dataPath . $tree . '/.' . $tree ; 
      $fileName = $path . '/' . $tree . ".cfg";

      $numParents = &CheckParent ( $path, $fileName, $in{"Parent"} );

      if ( $numParents == 1 ) {

         chdir $path;
         open ( FILE, ">>$fileName");
         print FILE "beginNode\n";   
         $tmp = $in{"src"};
         print FILE "name = $tmp\n";   
         $tmp = $in{"link"};
         print FILE "link = $tmp\n";   
         $tmp = $in{"Parent"};
         print FILE "parent = $tmp\n";   

         if ( $in{"protected"} eq "Yes" ) {
            print FILE "protected = on\n";   
         }
         print FILE "end\n";   
         close FILE;

         # Verbinde Node mit dem Parent
         $newParent = $in{"Parent"};
         $newChild = $in{"src"};
         open ( FILE, "$fileName") && (@lines=<FILE>) && close (FILE);
         open ( FILE, ">$fileName");
         foreach $line (@lines) {
            $_ = $line;
            if ( /name/ ) {
               ($rest, $node) = split (/=/, $line);
               $node =~ tr/a-zA-Z0-9//cd;
               if ( $node eq $newParent ) {
                  print FILE "child = $newChild\n";
               }
            }
            print FILE "$line";
         }
         close FILE;

         # Regeneriere den Plan und die GIF-Dateien
         chdir "$cmdPath";
         $cmd = " loadTree $tree";
         system ($cmd);
         system ("chmod -R 777 $projectPath/$project");

         # Bearbeite die Datei IMAGEMAP.CONF
         chdir "$dataPath/$tree/.$tree";
         open ( MAPFILE, "imagemap.conf") && (@lines=<MAPFILE>) && close (MAPFILE);
         open (MAPFILE, ">imagemap.conf");
         foreach $line (@lines) {
            $_ = $line;
            next if /$tree/;
            print MAPFILE "$line"; 
         }  

         # Hnge die neuen Plan-Dateien an
         opendir ( DSTDIR, "$path" );
         @mapfiles=grep(/map/,readdir(DSTDIR));
         #@mapfiles=grep(/^.map/,readdir(DSTDIR));
         foreach $mapfile (@mapfiles)
         {     
            ($map,$rest) = split (/\./, $mapfile);
            print MAPFILE "$map: $dataPath/$tree/.$tree/$mapfile\n";
         }
         close MAPFILE;
         closedir DSTDIR;
         
         print "<H1>Regenerierung fertig: Neuer Node hinzugefgt</H1>\n";
      }
      else {
         for ( $i=0; $i<$numParents; $i++ ) {

              # Suche den spezifizierten Node in der Form
            $name = $nameList[$i*3];
            $link = $nameList[$i*3+2];
            print "<A HREF=\"$cmdPath addNode.pl?" . $name . "\">" . $name . " @ ".  $link . "</A><BR>";
         }
      }
}

# den HTML-Header ausgeben
   print "Content-type: text/html\n\n";
   print "<HTML>\n";
   print "<HEAD><TITLE>Berichtsliste</TITLE></HEAD>\n";
   print "<BODY><H1>Ergebnisbericht:</H1>\n";

# die Variablen-Liste ausgeben
   &ReadParse();

# den HTML-Nachspann ausgeben
   print "</BODY>";
   print "</HTML>\n";

