#!/usr/local/bin/d4x
#
# Blacklist employers who do drug tests
#

$nnzurl = "http://www.webstrand.org/tony/d4nnzlst.htm";
$nnzreal = "d4nnzlst.htm";
$date_command = "/sbin/date";

$date = `$date_command +"%D %T %Z"`; chop($date);

# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

# Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
   ($name, $value) = split(/=/, $pair);

   # Un-Webify plus signs and %-encoding
   $value =~ tr/+/ /;
   $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
   $value =~ s/<!--(.|\n)*-->//g;
   $value =~ s/<([^>]|\n)*>//g;
   $FORM{$name} = $value;
   }

# Begin the Editing of the Org File
open (FILE,"$nnzreal") || die "Can't Open $nnzreal: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;

# Open Link File to Output
open (NNZ,">$nnzreal") || die "Can't Open $nnzreal: $!\n";

for ($i=0;$i<=$SIZE;$i++) {
    $_=$LINES[$i];
    if (/<!--begin-->/) {

#
#       print all required fields
#  name,town,country,xsic,desc_xsic,tlevel,approve,note
#
    if ($FORM{'name'})
       {print NNZ " $FORM{'name'}\n"; print NNZ "<BR>\n";}
    if ($FORM{'town'})
       {print NNZ " $FORM{'town'}\n"; print NNZ "<BR>\n";}
    if ($FORM{'country'})
       {print NNZ " $FORM{'country'}\n"; print NNZ "<BR>\n";}

    print NNZ "Organisation type: $FORM{'xsic'}\n";
    print NNZ "<BR>\n";

    if ($FORM{'desc_xsicc'})
       {print NNZ " $FORM{'desc_occ'}\n"; print NNZ "<BR>\n";}

    print NNZ "Testing level: $FORM{'tlevel'}\n";
    print NNZ "<BR>\n";

    if ($FORM{'desc_tlevel'})
       {print NNZ "test info: $FORM{'desc_tlevel'}\n"; print NNZ "<BR>\n";}

    if ($FORM{'approve'})
        {print NNZ "Approved :  $FORM{'approve'}\n"; print NNZ "<BR>\n";}

        if ($FORM{'note'}) {
            print NNZ "<PRE> $FORM{'note'} </PRE><BR>\n";
            }

        print NNZ "<PRE> - $date</PRE><HR>\n\n";
        print NNZ "<BR>\n";
        print NNZ "<!--begin-->\n";
        }

    else {
        print NNZ $_;
        }
    }

close (NNZ);
print "Location: $nnzurl\n\n";







