#!/usr/bin/perl -w
sub ReadParse {
  # assign the array passed in to a local version
  local (*in_pair) = @_ if @_;

  local ($i, $loc, $key, $val );

  if( $ENV{'REQUEST_METHOD'} eq "GET" ) {
    # copy environmental variable to in 
    $in = $ENV{ 'QUERY_STRING'};
  } elsif( $ENV{'REQUEST_METHOD'} eq "POST" ) {
    read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
  };

  #  break up in at & and put into array in_pair
  @in_pair = split(/&/,$in); 

  foreach $i (0 .. $#in_pair) {
    # convert + to space 
    $in_pair[$i] =~ s/\+/ /g;
    print "$inpair[$i]<br>";
    ($key, $val) = split(/=/,$in_pair[$1],2);
    $key =~ s/%(..)/pack("c",hex($1))/ge;
    $val =~ s/%(..)/pack("c",hex($1))/ge;
   
    $in_pair{$key} .= "\0" if (defined( $in_pair{$key}));
    $in_pair{$key} .= $val;
    print "$i<br>";
    print "$key ";
    print "$val<br>";
  }

  return 1;
}

@my_query_string = split(/&/,$ENV{'QUERY_STRING'});

#  create a variable called input and read into it
print "Content-type: text/html \r\n\r\n";
print "<HTML><HEAD><TITLE>Help Request</TITLE>";
print "</HEAD><BODY><H1>Help Request</H1>";
print "<P>Your help request has been filed.</P>";
foreach $index (0..$#my_query_string)
{
  print "$my_query_string[$index] <br>";
};
&ReadParse(*input);

#print $input{'topic'};

print "<PRE>\n";
print "</BODY></HTML>\n";

mail berezin@cs.niu.edu < problem.rpt
