<HTML><HEAD><TITLE>Konfigurtionsverwaltung: Berichte
</TITLE></HEAD>
<BODY><H1>Operation: Einen Bericht erstellen</H1>
<P>Erstelle aus den Informatioen im Baum ZEICHNUNGEN einen Bericht.  </P>
<P>Sie knnen die Felder, die Sie auf Ihrem Bericht sehen mchten, 
auswhlen, indem Sie den Feldindikator auf den gewnschten Wert
umschalten.</P>
Ist ein Feld ausgeschaltet (Keine), wird die Position ignoriert.
<P> Geben Sie Schlsselwrter ein, jedes durch einen "." getrennt. Jede Datei 
die das Schlsselwort nicht enthlt, wird nicht in der Liste erscheinen. 
Beachten Sie, da die Suche Klein-/Groschreibung nicht beachtet.</P>

<HR>

<H1>Standort-Information:</H1>
<FORM METHOD="POST" ACTION="/cgi-bin/cm1/report.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="Location:"> </P>
<P>Schlsselworte: <INPUT NAME="Keywords:"> </P>
<HR>
<H1> Feldinformations-Bericht:</H1>

<P>Feld1: <SELECT NAME="Field1:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld2: <SELECT NAME="Field2:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld3: <SELECT NAME="Field3:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld4: <SELECT NAME="Field4:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld5: <SELECT NAME="Field5:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld6: <SELECT NAME="Field6:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld7: <SELECT NAME="Field7:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld8: <SELECT NAME="Field8:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<P>Feld9: <SELECT NAME="Field9:">
<OPTION SELECTED>   Keine 
<OPTION>            Titel 
<OPTION>            Zeichnungs-Nummer 
<OPTION>            Ursprung 
<OPTION>            Anzahl Seiten 
<OPTION>            Freigabedatum 
<OPTION>            Referenz-Zeichnungen
<OPTION>            Referenz-Dokumente
<OPTION>            EOs
<OPTION>            Nchsthhere Montage 
</SELECT></P>

<HR>
<H1>Und nun?</H1>
<P><INPUT TYPE="submit" VALUE="Bericht erstellen"><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";


Perl-Routinen zum Manipulieren von CGI-Eingaben
S.E.Brenner@bioc.cam.ac.uk
$Header: /people/seb1005/http/cgi-bin/RCS/cgi-lib.pl,v 1.2 1.10.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 eine Bezahlung fr jede
Benutzung der Bibliothek erfolgt.

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/Werte-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 zu alphanumerischen 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 mehrfache Separator
    $in{$key} .= $val;
  }

   # Baue die Titelzeile auf
   print "<TABLE BORDER>";
   for ( $i=1; $i<10; $i++ ) {
      $keyword = "Field" . $i . ":";
      $title = $in{$keyword};
      if ( $title ne "None" ) { print "<TH>$title</TH>\n"; }
   }

   &WriteData (%in );
   print "</TABLE>\n";
}

sub GetTreeKey { 
   local ($project, $key) = @_; 
   local($serverRoot);
 
      # ffne die Konfigurations-Datei, die einen Schlssel fr jedes Projekt enthlt
      $serverRoot = "myServer";
      open ( FILE, "$serverRoot/cgi-bin/treeKey.cfg" ); 
      while (<FILE>) { 
         ($p, $key) = split (/:/, $_); 
         $project =~ tr/A-Z/a-z/; 
         if ( $p eq $project ) {
            return $key; 
         } 
      }   
} 


sub UnpackShmData {
   local ($key, $size, $count, $nodeOffset) = @_;
   local ($tmp, $len, $permissions, $start);
   local ($name,$link,$child,$sibling,$parent,$protected,$offset);


      # das Segment aus dem gemeinsamen Speicher holen
      $permissions=0600;
      $len = $count * $size;
      $shmid = shmget ( $key, $len, $permissions|&IPC_EXCL );

      # Setze den Index von wo gelesen werden soll
      $start = $size * $nodeOffset;

      # aus dem Segment lesen
      shmread ($shmid, $name, $start+0, 13);
      $name =~ s/\0.*$//;
      shmread ($shmid, $link, $start+13 , 180);
      $link =~ s/\0.*$//;
      shmread ($shmid, $tmp, $start+196, 4);
      $child = unpack ('i*', $tmp );
      shmread ($shmid, $tmp, $start+200, 4);
      $sibling = unpack ('i*', $tmp );
      shmread ($shmid, $tmp, $start+204, 4);
      $parent = unpack ('i*', $tmp );
      shmread ($shmid, $tmp, $start+208, 4);
      $protected = unpack ('i*', $tmp );
      shmread ($shmid, $tmp, $start+212, 4);
      $offset = unpack ('i*', $tmp );

      return ( $name, $link, $child, $sibling, $parent, $protected, $offset );
}


sub KeyInString {
   local ($inputString, $fileString) = @_;
   local (@keywordsIn);
   local ($var);

      $fileString = '\.' . $fileString;
      @keywordsIn  = split (/\./, $inputString);
      foreach $var (@keywordsIn) {
         $newVar = '\.' . $var . '\.';
         if (!($fileString =~ /$newVar/i)) { return 0; }
      }  
      return 1;
}


sub FilterData {
   local ($name, $path, %in) = @_;
   local (%fieldLine, $i, $key);

      $fileName = $name . '/' . $path;
      $keywords = $in{"Keywords:"};

      chdir $path;
      open ( FILE, $name );
      while ( <FILE> ) {

         # Erzeuge keine unntigen Zeilen
         next if ( /File/ );
         next if ( ! (( /<P>/ ) && ( /:/ )));

         # Prfe auf zutreffende Schlsselworte
         ( $tmp = $_) =~ s/<P>//g;
         ($key, $value) = split (/:/, $tmp);
         if ( /keyword/i) {
            if ( $keywords ne "" ) {
               if ( !(&KeyInString($keywords,$value))) {
                  close FILE;
                  return;
               }
            }   
            next;
         } elsif (/none/i ) {
            $value = "none";
         } elsif ( /referenced/i ) {
            ( $parsed_string = $_ ) =~ s/.*">//g;
            ($value,$rest) = split ( /<\/A>/, $parsed_string);
         } 
 
         ($fieldLine{$key} = $value) =~ s/<\/P>//g;

      }
      close FILE;

      # die anderen Eintrge ausgeben
      print "<TR>";
      for ( $i=1; $i<10; $i++ ) {
         $keyword = "Field" . $i . ":";
         $title = $in{$keyword};
         if ( $title ne "None") {
            if ( $title eq "EOs" ) {
               print "<TD>\n";
               chdir $path;
               opendir ( EODIR, '.' ) || die "Kann nicht ffnen $path\n";
               @filenames = readdir (EODIR);
               closedir (EODIR);

               foreach $file ( @filenames ) {
                  next if ( -d $file );
                  ($fname, $suffix) = split ( /\./, $name );
                  if (( /EO/ ) && ( /$name/ )) {
                     print "$file<BR>";
                  }
               }
               print "</TD>\n";
            }
            else {
               print "<TD>$fieldLine{$title}</TD>";
            }
         }
      }
      print "</TR>\n";
}


sub ProcessTree {
   local ($key, $start, $size, $count, %in) = @_;
   local ($name,$link,$child,$sibling,$parent,$protected,$offset);

        # Suche nach dem im Form spezifizierten Node
        ($name, $link, $child, $sibling, $parent, $protected, $offset) = 
            &UnpackShmData ( $key, $size, $count, $start );

      # Prfe Dateiinhalt auf Info
      $_ = $link;
      if ( /.html/  ) {
         @fields = split (/\//);
         $file = $fields[$#fields];
         $path = "/instra/FTP/projects/" . $in{"Project:"}; 
         $fileName = $path . '/' . $file;

         if ( -e $fileName ) {
            open (FILE, $fileName);
            while (<FILE>) {
               if ( /PIMS/ ) {
                  &FilterData($file, $path, %in);
                  last;
               }
            }
         }

      }

       # Prfe rckwrts auf nchsten Child und sibling in der Baum-Hierarchie
        if ( $child != -1 ) {
           &ProcessTree ( $key, $child, $size, $count, %in );
        }  

        if ( $sibling != -1 ) {
           &ProcessTree ( $key, $sibling, $size, $count, %in );
        }  

}


sub WriteData  {
   local ( %in ) = @_;
   local ( $start, $count, $size );
   local ($serverRoot);
   local ( $name, $link, $child, $sibling, $parent, $protected, $offset);

      # Hole die Gre des Baums aus der HTML-Datei
      $serverRoot = "myServer";
      $project = $in{"Project:"};
      $key = &GetTreeKey($project);

      open ( FILE, "/instra/FTP/projects/$project/$project.html" );

      while ( <FILE> ) {

         if ( /SIZE/ ) {
            ($keyword, $size) = split (/=/, $_ );
            ($keyword, $size, $rest) = split (/"/, $size );
         }

         if ( /COUNT/ ) {
            ($keyword, $count) = split (/=/, $_ );
            ($keyword, $count, $rest) = split (/"/, $count );
         }
      }

      # Hole die Startposition im Baum
      if ( $in{"Parent:"} eq "" ) {
         $start = 0;
      } else {

         # hole den Start-Node im Baum
         for ( $i=1; $i<$count; $i++ ) {
 
            # Suche den spezifizierten Node in der Form
            ($name, $link, $child, $sibling, $parent, $protected, $offset)   
                     = &UnpackShmData ( $key, $size, $count, $i );
 
            # Suche den spezifizierten Zweig im Baum
              ($parentName) = &UnpackShmData ( $key, 13, $count, $parent);
              if ( ($parentName eq $in{"Parent:"}) && 
                 ($name eq $in{"Location:"})) {
                 $start = $i;
               last;
              }
         } 
      }

      &ProcessTree ( $key, $start, $size, $count, %in );
}



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

# die Variablen-Liste ausgeben
   &ReadParse();

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

