#!/usr/local/bin/perl
#
# index.cgi
#
# Prints a web page for a particular "Same Day Different Rat" post-group.
#
# Reads in the post-group number in the URL Request String.
# Imports the posts from a numbered file, like post_2.txt.
# Merges the posts into an HTML template (post_template.html).
#
# Uses library cgi-lib.pl (non-object-oriented) and package
# Perlfect::Template.perl (object-oriented and renamed PerlfectTemplate.pm).
# Both files exist in the current directory.
# This script (index.cgi) is an opportunistic mash which could be more elegant.
# Should figure out convenient place to store scripts, and how to access them
# (append dir path to @INC)?
#
# Kurt Tuohy: July 2001

# Use package to handle HTML templates
use PerlfectTemplate;

# Set constants
my $baseShowDir = "radio";
my $postTemplateFile = "post_template.html";

my $postKey = "post";   # Key for HTML-form input of show-directory name

# Get HTML-form input. Should just be number of desired post page.
# my %inputParams = {};
require "cgi-lib.pl";
&ReadParse(*inputParams);
my $postNum = $inputParams{$postKey};
if ($postNum == "") { $postNum = "current"; }

# Get info particular to the desired show.
my $errorMsg;
my $postSettings = require "post_$postNum.txt";
my %postSettings = %$postSettings;   # Dereference the wanker -- otherwise trouble!

# Read HTML template for show.
my $postTemplate = new PerlfectTemplate("$postTemplateFile");
# Merge show particulars into template.
my $postPage = $postTemplate->cast(\%postSettings);

# Print merged HTML.
print &PrintHeader;
print $postPage;

