#!/usr/bin/perl -w
#--------------------------------------------------------------------------
# video_embed.pl - displays embedded video
# written by Eric Pence
#--------------------------------------------------------------------------
use strict;
use CGI qw(-oldstyle_urls :standard);
use CGI::Carp qw(fatalsToBrowser);

# Define global variables
use vars qw($curr_dir $log_file);

#--------------------------------------------------------------------------
# Grab the current directory from $0. The following regular expression
# looks for 'CURR_DIR\xxxxx.xxx' or 'CURR_DIR/xxxxx.xxx'. Place it in
# the BEGIN block so we can use it to include modules
#--------------------------------------------------------------------------
BEGIN {
$0 =~ '(.*[\\\/])\w+\.\w+$';
$curr_dir = $1 || "./";

# Set up error log file
$log_file = "error_log.txt";
use CGI::Carp qw(carpout);
open(LOG, ">>${curr_dir}${log_file}")
or die "Unable to append to error log: $!";
carpout(*LOG);
}

my $q = new CGI;

# Get parameters
my $video = '';
if ($q->param('video')) {
$video = $q->param('video');
}
# Replace some characters
$video =~ s/\|/?/;
$video =~ s/`/&/g;
my $width = '';
if ($q->param('width')) {
$width = $q->param('width');
}
my $height = '';
if ($q->param('height')) {
$height = $q->param('height');
}
my $title = '';
if ($q->param('title')) {
$title = $q->param('title');
}

print header();
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>$title</title>
</head>
<body bgcolor=\"#000000\">
<script type='text/javascript'>
document.writeln('<object width=\"452\" height=\"371\">');
document.writeln('<embed src=\"$video\" type=\"application/x-shockwave-flash\" flashvars=\"autoPlay=true\" width=\"$width\" height=\"$height\"></embed>');
document.writeln('</object>');
</script>
</body>
</html>";