Hello List,

Below is my index.pl

#!/usr/bin/perl

use Env;
print "Content-Type: text/html\n\n\n";
chdir("/path/to/dir");
@files=`ls -1`; ## load all the html files..

print "<html>\n";
print "<head>\n";
print <<END_SCRIPT;
        <script>
                function submit_form()
                 {      
                  document.show_files.submit();
                  setTimeout(\"document.show_files.reset()\",3);
                 }
        </script>
END_SCRIPT
print "</head>";
print "<body>\n";
print "<FORM NAME=\"show_files\" ACTION=\"display.pl\" METHOD=\"POST\"
target=\"_blank\" onsubmit=\"submit_form()\" >";
print "<p> \n</p>";
print "<table border=1 align=center >\n";
print "<tr><th> Multi site audit name</th><th> HTML Reports </th>\n
<th> CSV Reports</th></tr>";

print "<tr><td>Box 1</td><td>\n";
print "<SELECT NAME=\"box1\" SIZE=1>";
print "<OPTION SELECTED>HTML";
  foreach $file (@files) {
    chomp($file);
    next  if -d $file;
      if (grep/Owner/, $file) {
        ($Owner,$month,$date,$year) = split/_/,$file;
        $year =~ s/.html//g;
        print "<OPTION>$month $date $year - Owner \n";
      }
  }
print "</SELECT>\n";
print "<INPUT TYPE=\"submit\" VALUE=\"GO\">\n";
print "</td></tr>";
print "</table>";
print "</FORM>\n";
print "</body>\n</html>\n";
exit 0;

This is my display.pl file...


#!/usr/bin/perl

&parse_form_data (*simple_form);
print "Content-type: text/html", "\n\n";
if ( grep/HTML/, $simple_form{'box1'}) {
} else {
$fileselect = $simple_form{'box1'};
}

chomp($fileselect);
@filename = split/ /, $fileselect;

foreach $type (@filename) {
if (grep/csv/,$type) {
$file =
$filename[4]."_".$filename[0]."_".$filename[1]."_".$filename[2].".csv";
$file_path="/file/path/$file";
break;
} else {
$file =
$filename[4]."_".$filename[0]."_".$filename[1]."_".$filename[2].".html";
$file_path="file/path/$file";
break;
}
}

if (grep /\.csv/,$file_path) {
} else {
open (READ, "<$file_path") || die "cannot open file:$!";
while (<READ>) {
print $_;
}
}
exit(0);

sub parse_form_data
{
local (*FORM_DATA) = @_;
local ( $request_method, $query_string, @key_value_pairs, $key_value, $key,
$value);

$request_method = $ENV{'REQUEST_METHOD'};

if ($request_method eq "POST") {
read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});
}
@key_value_pairs = split (/&/, $query_string);
foreach $key_value (@key_value_pairs) {
($key, $value) = split (/=/, $key_value);
$value =~ tr/+/ /;
$value =~ s/%([\dA-Fa-f] [\dA-Fa-f]) /pack ("C", hex ($1))/eg;
if (defined($FORM_DATA{$key})) {
$FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value);
} else {
$FORM_DATA{$key} = $value;
}
}
} #End of sub routine;

index.pl displays the files in the drop down box and display box has to
display the file. That's it. It does the job in the abve code. but in IE I
get 2 windows poping up. I want to avoid it.
How can I do that?

Is there a better way to do this?

I just have to populate the files in a directory and display the same in a
new window.

Thanks in advance.


Cheers,
Umesh.

Reply via email to