#!/usr/bin/perl

use CGI qw/:cgi :html/;

my $name = param('n');
my $graphic = param('f');
my $back = $ENV{'HTTP_REFERER'};
my $error = 0;

###
# Check file name
###
if ( ($graphic =~ /.*\.\..*/) ||
     ($graphic =~ /^http:.*/) ||
     ($graphic =~ /^ftp:.*/) ||
     ($graphic !~ /.*[\w]\.\w\w\w$/) )
{
   $error = 1;
}

if ( $back !~ m#^http://home.hiwaay.net/~lkseitz/comics/newu/# )
{
   $back = "http://home.hiwaay.net/~lkseitz/comics/newu/";
}

###
# Set display variables
###
my $title = 'NMWtN: ' . $name;
my $source = 'graphics/' . $graphic;

###
# Print page
###
print header;

if (!$error) {
   print start_html( -title=>$title,
                     -style=>{'src'=>'newu.css'}
                   );

print << 'EO_HEADER';
<div id="title">
<h1 style="margin:  0; padding:  0"><img src="graphics/nukeme.gif"
width="467" height="29" alt="Nuke Me with the New!"></h1>
</div>

<div id="border">
<div id="main">
EO_HEADER

   &PrintFile('nav.htm');

   print '<h2 id="start">' . $name . '</h2>',
         "<div style=\"text-align: center\">\n",
         img{-src=>$source,
             -style=>'border: 1px solid black;'},
         p( a({-href=>$back},
              'Back') ),
         "</div>\n\n";

}
else {
   print start_html(-title=>'NMWtN: Error',
                    -style=>{'src'=>'newu.css'}),
         p("There was an error with the input parameters given. ",
           "Please report it to the author below. ",
           "<EM>Be sure to include the URL of the page where you found the link!</EM>\n"),
         Dump(),
         p( {-align=>'center'},
            a( {-href=>$back}, 'Back') );
}

print << 'EO_FOOTER';
<div id="footer">
<hr>
<p>
<!--#include file="copyright.htm" -->
<!--#include virtual="/~lkseitz/Common/contact.htm" -->.<br>
<!--#include file="copyright2.htm" -->
</p>
</div>
</div>
</div>
EO_FOOTER

print end_html;


##############
# SUBROUTINES
##############

##
# PrintFile
# Written by:  Lee K. Seitz
# Written on:  Fri 16 May 1997 (as IncludeVirtual)
# Modified:    Tue 28 Jan 2003
# Description:  This routine prints the text of the filename (with
#    complete path) passed in.  It is equivalent to
#    <!--#include virtual="/path/file.ext"-->, except the path is the
#    file system path, not the HTTP path.
# Parameters:
#    File - The text file to return.
# Return Value:
#    None
# Examples:
#    1. &PrintFIle("/home/username/public_html/disclaim.htm");
###
sub PrintFile {
   local ($File) = shift(@_);

   if ( (-e $File) && (-r $File) ){
      open(FILE, "<$File");
      print <FILE>;
      close(FILE);
   }
   else {
      print p('There was an error processing this directive.');
   }
}
