#!/usr/bin/perl

print "Content-type: text/html\n\n";

# This is to trick IIS into using the CWD of the script being executed...
#
use File::Basename;
if ( $ENV{'SERVER_SOFTWARE'} =~ /IIS/ )
{
    $cwd = dirname($ENV{'PATH_TRANSLATED'});
    chdir($cwd);
}

$QUERY_STRING = $ENV{'QUERY_STRING'};
$QUERY_STRING =~ /prog=([^\&]*)/;

$file = $1.".cgi";

if ( not open( IN, $file ) )
{
    print "<html><head><title>System error</title></head><body>\n";
    print "<font face='Arial,Helvetica,sans-serif' size='4' color='#800000'>"
        . "Cannot open program file $file: ".$!
        . "If this persists, please contact "
        . "<a href='mailto:error\@currentstock.com'>customer services</a></font>.";
	print "<pre><font color='#228822'>QUERY_STRING = ".$QUERY_STRING
        . "</font></pre><p>";


    print "<pre><font color='#A04444'>" . $@ . "</font></pre>\n";
    print "</body></html>\n";
}

my $line;
my $perl;
while ( $line = <IN> )
{
    $perl .= $line;
}
close( IN );

eval( $perl );
if ( $@ ne "" )
{
    print "<html><head><title>System error</title></head><body>\n";
    print "<font face='Arial,Helvetica,sans-serif' size='4' color='#800000'>"
        . "A system error has occured. If this persists, please contact "
        . "<a href='mailto:error\@currentstock.com'>customer services</a> "
        . "quoting the following message:"
        . "</font><p>";

	print "<pre><font color='#228822'>QUERY_STRING = ".$QUERY_STRING
        . "</font></pre><p>";

    print "<pre><font color='#A04444'>" . $@ . "</font></pre>\n";
    print "</body></html>\n";
}

exit;

