#!/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."$line\n"; } ############# SET CONTENT HEADER print "Content-type: text/html\n\n"; ############# PROCESS TEMPLATE AND OUTPUT foreach $line (@file) { chomp $line; $no_form="no show" if (($line =~ m//) && ($no_form eq "true")); $no_form="false" if ($line =~ m//); if ($no_form ne "no show") { $line = translate($line); print "$line\n"; } } exit; ################################################################################ ######### ONLY FUNCTIONS BELOW ################################################################################ ############### ## Translate ############### sub translate { my $string; ($string) = @_; $string =~ s/\[ERROR\]/$status/g; $string =~ s/\[NAME\]/$name/g; $string =~ s/\[EMAIL\]/$email/g; $string =~ s/\[COMPANY\]/$company/g; $string =~ s/\[PHONE_AREA\]/$phone_area/g; $string =~ s/\[PHONE\]/$phone/g; $string =~ s/\[POSTCODE\]/$postcode/g; $string =~ s/\[CONTACT_TYPE\]/$contact_type/g; $string =~ s/\[COMMENTS\]/$comments/g; $string =~ s/\[OPTION_LIST\]/$option_list/g; return $string; } ############### ## inputEnquiry ############### sub inputEnquiry { ### create Tracking Number $statement=qq{select max(ID) from enquiry}; $sth=$dbh->prepare($statement); $sth->execute; @rows = $sth->fetchrow_array; $sth->finish; $statement=qq{select tracking_number from enquiry where ID = $rows[0]}; $sth=$dbh->prepare($statement); $sth->execute; @rows = $sth->fetchrow_array; $sth->finish; @rows = split(/-/,$rows[0]); if ($rows[0] eq $tracking_number) { $rows[1]=$rows[1]+1; $rows[1]="0".$rows[1] if (length($rows[1]) eq 2); $rows[1]="00".$rows[1] if (length($rows[1]) eq 1); $tracking_number = $tracking_number."-".$rows[1]; } else { $tracking_number = $tracking_number."-001"; } ### Join Phone Area & Number $phone = $phone_area." ".$phone; ### Quote all input from user my $db_name = $dbh->quote("$name"); my $db_company = $dbh->quote("$company"); my $db_phone = $dbh->quote("$phone"); my $db_email = $dbh->quote("$email"); my $db_postcode = $dbh->quote("$postcode"); my $db_contact_type = $dbh->quote("$contact_type"); my $db_comments = $dbh->quote("$comments"); ### insert into DB $statement=qq{insert into enquiry values (0,"$tracking_number",NOW(),$db_name,$db_company,$db_phone,$db_email,$db_postcode,$db_contact_type,$db_comments)}; $sth=$dbh->prepare($statement); $sth->execute() or die; $sth->finish; ### create success HTML response $status = "Thank You
Your Enquiry has been sent to your nearest Record Solutions Representative.
This enquiry has been given the following Tracking Number:
$tracking_number

"; $no_form="true"; ### Send Email to RS.NET.AU & CC to State-based Rep $cc_email = ""; $statement = qq{select state from postcode where postcode="$postcode"}; $sth=$dbh->prepare($statement); $sth->execute; @rows=$sth->fetchrow_array; $sth->finish; if ($rows[0] =~ m/VIC|SA|TAS|ACT|WA/) { $cc_email = $state_1_email; $sms_number = $state_1_sms; } elsif ($rows[0] =~ m/QLD|NSW|NT/) { $cc_email = $state_2_email; $sms_number = $state_2_sms; } open (MAIL, "|$mail_prog -t") or die "problem happened at send mail\n"; print MAIL "To: $rs_email\n"; print MAIL "CC: $cc_email\n"; print MAIL "FROM: $email ($name)\n"; print MAIL "Subject: $tracking_number $subject_rs\n\n"; print MAIL < 131); my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => "tcpsms.messagenet.com.au", PeerPort => "7000", ) or die "cannot connect to server"; # AccountName: (Mandatory) Supplied by Redrock # Sender: (Mandatory) Description of Sender Company - Anything you want # SenderAddr: (Optional) Description of Sender Address - Anything you want # Dest User: (Optional) Description of Recipient - Anything you want # PhoneNumber: (Mandatory) Destination GSM phone number # NetworkCode: (Mandatory) Destination GSM Network - (OGSM,TGSM,VGSM) Default to GSM # Subject: (Optional) If you have a password on the account put it in here # Message: (Mandatory) Your message text print $remote "\r\rrecordsoltcp\r1\r1\r\r\r\r$sms_number\rTGSM\r0\r0\r0\r553653\r$sms_message"; # Send result # Accepted Result code = 0x06 Description = Lodge OK # Rejected Result code = 0x15 Description = Lodge Error $remote->read ( $strbuff,10,0); return $strbuff; }