#!/usr/bin/perl -w
#--------------------------------------------------------------------------
# show_video.pl - creates webpage with embedded video to show in popup
# 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 $filename = '';
if ($q->param('filename')) {
$filename = $q->param('filename');
}
my $width = '';
if ($q->param('width')) {
$width = $q->param('width');
}
else {
$width = '420';
}
my $height = '';
if ($q->param('height')) {
$height = $q->param('height');
}
else {
$height = '380';
}
my $title = '';
if ($q->param('title')) {
$title = $q->param('title');
}
else {
$title = $filename;
}

print "Content-type: text/html\r\n\r\n";
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">
<html>
<head>
<title>$title</title>
</head>
<body bgcolor=\"#000000\">
<table>
<tr>
<td>
<object id='MediaPlayer' width=\"$width\" height=\"$height\"
classid=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\"
codebase=\"http://activex.microsoft.com/activex/controls/ mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft® Windows® Media Player components...\"
type=\"application/x-oleobject\">
<param name=\"Filename\" value=\"../video/$filename\">
<param name=\"StretchToFit\" value=\"true\">
<param name=\"ShowDisplay\" VALUE=\"false\">
<embed src=\"../video/$filename\" width=\"$width\" height=\"$height\" type=\"application/x-mplayer2\" name\"MediaPlayer\" autostart=\"1\"
displaysize=\"0\" showcontrols=\"1\">

</object>
</td>
</tr>
</table>
</body>
</html>";