#!/usr/bin/perl -w
# now the standard modules
use CGI;
use DBI;
use CGI::Carp qw(fatalsToBrowser);
use Text::Template;
use Apache::Session::MySQL;
use GD::SecurityImage;
use Digest::MD5 qw(md5_hex);
use strict;
my $cgi = new CGI;
my %p = $cgi->Vars();
my $page = ($p{'page'})? $p{'page'} . ".html" : "home.html";
if($page eq 'index.html'){ $page = 'home.html';}
if($page eq 'contact-us.html' || $page eq 'employment-application.html'){
&get_page_with_cookie();
}else{
&get_page();
}
sub get_page{
if (!(-e "pages/$page")){ $page = 'not-found.html'; }
my $mini_temp = {
'template' => "pages/$page",
'interiorlinks' => &get_subnav(),
};
my $main = {
'template' => 'templates/main-template.html',
'background_image' => &get_background(),
'display_bug' => &displayBug(),
'content' => &get_template($mini_temp),
};
print $cgi->header();
print &get_template($main);
}
sub get_page_with_cookie{
#get the session to check the captcha key
my $session_id = $cgi->cookie('cfs_id');
my %session = &get_session($session_id);
#clear old session id if exists clear it so we can create a new one
if($session_id){
my $which = $session{'random'};
unlink("images/captcha/captcha$which.jpg");
&clear_session();
}
#set session with the captcha key
my $new_session_id = &set_session();
my $session_cookie = $cgi->cookie(-name=>'cfs_id',-value=>$new_session_id,-path=>"/",-domain=>"customfoodsolutions.com",-expires=>'+1d');
%session = &get_session($new_session_id);
my $identifier = $session{'random'};
#create security image
my $image = GD::SecurityImage->new(width => 100,
height => 30,
lines => 8,
gd_font => 'giant');
$image->random($session{'captcha_key'});
$image->create(normal => 'rect', , '#000000', '#c8c8c8');
my($image_data, $mime_type, $random_number) = $image->out;
my ($bytesread,$buffer,$blob);
open (OUTFILE,">images/captcha/captcha$identifier.jpg") or die "$!";
print OUTFILE $image_data;
close (OUTFILE);
if (!(-e "pages/$page")){ $page = 'not-found.html'; }
my $mini_temp = {
'template' => "pages/$page",
'interiorlinks' => &get_subnav(),
'captcha' => "
",
};
my $main = {
'template' => 'templates/main-template.html',
'background_image' => &get_background(),
'display_bug' => &displayBug(),
'content' => &get_template($mini_temp),
};
print $cgi->header( -cookie => [$session_cookie] );
print &get_template($main);
}
##################################################
##### get the sub nav for the interior pages #####
##################################################
sub get_subnav{
my $interiorlinks;
my %linkhash = ();
#this nav is used for all of the pages that are NOT for a particular product
my %interiornav = ('ready-to-use-products.html' => 'Ready-to-Use Products','custom-products.html' => 'Custom Products','facility-tour.html' => 'Facility Tour');
#this nav is used for all of the pages that describe ONE product like Soups
my %productnav = ('soups.html' => 'Soups', 'salsas.html' => 'Salsas', 'sauces.html' => 'Sauces', 'glazes.html' => 'Glazes', 'sides.html' => 'Sides', 'fillings.html' => 'Fillings', 'sous-vide.html' => 'Sous Vide','desserts.html' => 'Desserts', 'dips.html' => 'Dips & Table Sauces', 'dressings.html' => 'Dressings & Condiments');
#if the page matches a key in the productnav hash
#then it will return a value and we will know to use that one
#if it doesn't return anything we use the interiornav by default
#one exception to this though, the OUR PRODUCTS page does not use the productnav it uses the interiornav.
my $which = $productnav{"$page"};
if($which && $page ne 'our-products.html'){
%linkhash = %productnav;
}else{
%linkhash = %interiornav
}
#while ( my ($key, $value) = each(%linkhash) ) {
#if the nav page does NOT equal the current page, display it
#don't display the navigation for the page we are currently on
#if($key ne $page){
#$interiorlinks .= qq[