#!/usr/bin/perl -w
###########################################
# SCRIPT NAME : contact.cgi
# DATE: Sep 2004
# VERSION: 1.0
# AUTHOR: Sarun Chinskul
# EMAIL: schinskul@crystalmckenzieinc.com
###########################################
use lib "/home/httpd/vhosts/cminyc.com/httpdocs/admin";
chdir "/home/httpd/vhosts/cminyc.com/httpdocs/";
use CGI;
use DBI;
use HTML::Template;
use cmiModule;
use strict;
########################
# Read Config.conf file
########################
my @info = &cmiModule::ReadConfig("config.conf");
########################
# Logfile config setup
########################
my %Log_Config;
# Setting EasyLog is ON or OFF in config.conf file
$Log_Config{SWITCH} = $info[0];
$Log_Config{FILENAME} = $info[1];
$Log_Config{MESSAGE} = "-------STARTED LOG [".$0."]-------";
&cmiModule::EasyLog(\%Log_Config);
########################
# Database config setup
########################
my %DB;
$DB{DATABASE} = $info[2];
$DB{ACCOUNT} = $info[3];
$DB{PASSWORD} = $info[4];
my $dbh;
unless( $dbh = &cmiModule::ConnectToMySQL(\%DB) ) {
$Log_Config{"MESSAGE"} = "Bad DBH from ConnectToMySQL.";
&cmiModule::EasyLog(\%Log_Config);
print "Content-type:text/html\n\n";
print "Bad DBH from ConnectToMySQL.";
exit;
}
###### End config ######
my $cgi = new CGI;
##########################################################
# Contact text
##########################################################
my $text = qq{ Contact Us
};
$text .= qq{ Crystal McKenzie, Inc.
};
$text .= qq{ 220 East 23rd Street, Suite 305
};
$text .= qq{ New York, NY 10010
};
$text .= qq{ Tel 212-598-4567
};
$text .= qq{ Fax 212-598-4566
};
$text .= qq{ contact\@cminyc.com
};
$text .= qq{ New Jersey Offices:
};
$text .= qq{ 43 Leigh Avenue
};
$text .= qq{ Princeton, NJ 08542
};
$text .= qq{ Tel 201-349-8445
};
$text .= qq{ Fax 609-799-4568
};
$text .= qq{ Brian Jones
};
$text .= qq{ COO / Creative Director
};
$text .= qq{ bjones\@cminyc.com
};
##########################################################
my %CONTINFO;
$CONTINFO{contact_template} = HTML::Template->new(filename => 'tmpl/contact.tmpl');
$CONTINFO{email_filter} = q{/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i};
$CONTINFO{contactustext} = $text;
$CONTINFO{name} = $cgi->param('name');
$CONTINFO{from} = $cgi->param('from');
$CONTINFO{subject} = $cgi->param('subject');
$CONTINFO{emailbody} = $cgi->param('emailbody');
&contact(\%CONTINFO);
1;
sub contact {
my ($params_hashref) = @_;
my %params_hash = %{ $params_hashref };
my $contact_template = $params_hash{contact_template};
my $email_filter = $params_hash{email_filter};
my $contactustext = $params_hash{contactustext};
my $name = $params_hash{name};
my $from = $params_hash{from};
my $subject = $params_hash{subject};
my $emailbody = $params_hash{emailbody};
$contact_template->param(email_filter => $email_filter);
$contact_template->param(contactustext => $contactustext);
my ($to,$message);
if ( $name ) {
# Send email
$to = "contact\@cminyc.com";
$message = "\nSender's name : $name\n";
$message .= "\n$emailbody\n";
&cmiModule::SendEmail($from,$to,$subject,$message);
# Insert data
my $sql = "INSERT INTO QuickContact";
$sql .= " (ContactID,ContactName,ContactEmail,ContactSubject,ContactContent)";
$sql .= " Values ('','$name','$from','$subject','$emailbody')";
$dbh->do($sql);
}
print "Content-type:text/html\n\n";
print $contact_template->output;
}