#!/usr/bin/perl
use DBI;
use CGI qw{:standard};
use strict;
############# CONNECT TO MYSQL DB
my $dbh = DBI->connect("DBI:mysql:leads","leads","webclient");
############ SET SENDMAIL
my $mail_prog = '/usr/sbin/sendmail -fenquire\@rs.net.au';
my $subject_rs = "Enquiry from rs.net.au";
my $subject_response = "(auto-response) Enquiry from rs.net.au";
############# SET TEMPLATE FILE
my $template_file = 'enquiry.html';
############ SET RS CONSTANTS
my $rs_email = "enquire\@rs.net.au";
my $state_1_email = "js\@rs.net.au"; # Vic/SA/Tas/ACT/WA
my $state_2_email = "mh\@rs.net.au"; # QLD/NSW/NT
my $state_1_sms = "0417142402"; # Vic/SA/Tas/ACT/WA
my $state_2_sms = "0419529075"; # QLD/NSW/NT
############# SET LOCAL VARS
my $datetime=`/bin/date`;
my $tracking_number = `/bin/date "+%Y%m%d"`;
my $status;
my $line;
my $statement;
my $sth;
my @rows;
my $option_list;
my $selected;
my $cc_email;
my $sms_number;
my $no_form="false";
chomp $datetime;
chomp $tracking_number;
############ SET CGI VARS
my $name = param("name");
my $company = param("company");
my $phone_area = param("phone_area");
my $phone = param("phone");
my $email = param("email");
my $postcode = param("postcode");
my $contact_type = param("contact_type");
my $comments = param("comments");
my $submit_button = param("Submit");
################################################################################
############# PROCESS DATA (if NO data then is first time, skip process and just output form)
################################################################################
if ($submit_button eq "Submit") {
##### Validate Data
$status=""; # null = OK to Download
$status = $status."You need to enter your Name \n" if (param("name") eq "");
$status = $status."You need to enter your Company Name \n" if (param("company") eq "");
$status = $status."You need to enter your Postcode \n" if (param("postcode") eq "");
# email validation
my $tmp_email = param("email");
if ($tmp_email ne ""){
my $search = " ";
my $replace = "";
while ($tmp_email =~ m/$search/){
$tmp_email =~ s/$search/$replace/;
}
if ($tmp_email !~ /^[\w.+-]+\@[\w.+-]+$/){
$status = $status."You have not entered a valid Email Address \n";
}
} else {
$status = $status."You need to enter your Email Address \n";
}
$status = "Error(s) ".$status." " if ($status ne "");
##### Call Function inputEnquiry if there are no errors
inputEnquiry() if ($status eq "");
} # end process data
################################################################################
############# OUTPUT HTML TO USER
################################################################################
############# READ IN TEMPLATE
open (FILE,"<$template_file");
my @file = ;
close (FILE);
############# SETUP AREA OF INTEREST OPTION LIST
$statement = qq{select types from aoi where ID = 1};
$sth = $dbh->prepare($statement);
$sth->execute();
@rows = $sth->fetchrow_array;
@rows = split(/#-#/,$rows[0]);
$sth->finish;
$option_list="";
foreach $line (@rows) {
$selected = "";
$selected = " selected" if ($line eq $contact_type);
$option_list=$option_list."