<?php
session_start();
if(isset($_GET['regID']))
{
$info = unserialize(stripslashes($_GET['regID']));
$info['dealer'] = $info['selectedDealer'];
if($info['customer']['postalCode'] == "") $info['customer']['postalCode'] = $info['customer']['postal'];
include_once('includes.php');
include_once('mysqlUtils.php');
$area = $dealerInfo[$info['selectedDealer']]['area'];
if($area == "") $area = 'bc';
$_SESSION['registerEmail']['dealerInfo'] = $dealerInfo;
include_once('Emailer/swift_required.php');
try
{
$transport = Swift_SmtpTransport::newInstance('mx2.newgencloud.com');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance($dealerInfo[$info['dealer']]['name'] . " Web Lead");
$body = '
<font style="font-size:10pt;font-family:Arial">
<font style="font-size:15pt"><b><u>Web Registration</b></u></font>
<br>
<table cellspacing="0" cellpadding="0">
<tr>
<td style="font-size:10pt;font-family:Arial;padding:10px 0px">
<b>First Name:</b> ' . trim($info['customer']['firstname']) . '<br>
<b>Last Name:</b> ' . trim($info['customer']['lastname']) . '<br>
<b>Email:</b> ' . $info['customer']['email'] . '<br>
<b>Phone:</b> ' . trim($info['customer']['mainPhone']) . '<br>
<b>Postal Code:</b> ' . $info['customer']['postalCode'] . '<br>';
if($info['customer']['code'] != "") $body .= '<b>Code:</b> ' . $info['customer']['code'] . '<br>';
if($info['customer']['appointmentDate'] != "") $body .= '<b>Appointment Date:</b> ' . $info['customer']['appointmentDate'] . '<br>';
if($info['customer']['monthlyGas'] != "") $body .= '<b>Monthly Gas:</b> ' . $info['customer']['monthlyGas'] . '<br>';
if($info['customer']['dateRange'] != "") $body .= '<b>In-Market:</b> ' . $info['customer']['dateRange'] . '<br>';
if($info['customer']['testDriveDay'] != "") $body .= '<b>Test Drive Booked:</b> ' . $info['customer']['testDriveDay'] . '<br>';
if($info['tradeIn']['years'] != "" || $info['tradeIn']['year'] != "") $body .= '<b>Year:</b> ' . trim($info['tradeIn']['years'].$info['tradeIn']['year']) . '<br>';
if($info['tradeIn']['makes'] != "") $body .= '<b>Make:</b> ' . $info['tradeIn']['makes'] . '<br>';
if($info['tradeIn']['models'] != "" || $info['tradeIn']['model'] != "") $body .= '<b>Model:</b> ' . trim($info['tradeIn']['model'] . $info['tradeIn']['models']) . '<br>';
if($info['tradeIn']['trims'] != "" || $info['tradeIn']['trim'] != "") $body .= '<b>Trim:</b> ' . trim($info['tradeIn']['trims'] . $info['tradeIn']['trim']) . '<br>';
if($info['tradeIn']['styles'] != "") $body .= '<b>Style:</b> ' . $info['tradeIn']['styles'] . '<br>';
if($info['tradeIn']['kilometers'] != "") $body .= '<b>KM:</b> ' . $info['tradeIn']['kilometers'] . '<br>';
if($info['tradeIn']['transmission'] != "") $body .= '<b>Transmission:</b> ' . $info['tradeIn']['transmission'] . '<br>';
if($info['tradeIn']['cylinder'] != "") $body .= '<b>Cylinder:</b> ' . $info['tradeIn']['cylinder'] . '<br>';
if($info['tradeIn']['drivetrain'] != "") $body .= '<b>Drive Train:</b> ' . $info['tradeIn']['drivetrain'] . '<br>';
if($info['tradeIn']['values']['tradeInLow'] != "" && $info['tradeIn']['values']['tradeInLow'] != 0) $body .= '<b>Trade in Value:</b> '. '$' . number_format($info['tradeIn']['values']['tradeInLow']) . ' - $' . number_format($info['tradeIn']['values']['tradeInHigh']) . '<br>';
if($info['customer']['currentPayment'] != "") $body .= '<b>Current Payment:</b> ' . $info['customer']['currentPayment'] . '<br>';
if($info['tradeIn']['payments'] != "") $body .= '<b>Current Payment:</b> ' . $info['tradeIn']['payments'] . '<br>';
if($info['tradeIn']['balanceOwing'] != "") $body .= '<b>Balance Owing:</b> ' . $info['tradeIn']['balanceOwing'] . '<br>';
if($info['customer']['selectedVehicle'] != "") $body .= '<b>Interested In:</b> ' . $daaVehicles[$area][$info['customer']['selectedVehicle']]['description'] . '<br>';
if($dealerInfo[$info['dealer']]['campaign'] != "") $body .= '<br><b>Campaign:</b> ' . $dealerInfo[$info['dealer']]['campaign'] . '<br>';
$body .= ' </td>
</tr>
</table>
<br><br>
';
if($info['customer']['postalCode'] != "")
{
$addArray = array();
$addArray['customer']['address'] = $info['customer']['address'];
$addArray['customer']['address1'] = $info['customer']['address1'];
$addArray['customer']['address2'] = $info['customer']['address2'];
$addArray['customer']['city'] = $info['customer']['city'];
$addArray['customer']['province'] = $info['customer']['province'];
$addArray['customer']['postalCode'] = $info['customer']['postalCode'];
$body .= '
<table cellspacing="0" cellpadding="0">
<tr>
<td style="padding-right:30px;font-size:11pt;font-family:Arial;">
<a href=\'http://ar.absoluteresults.com/streetview/index.php?regID=' . urlencode(stripslashes(serialize($addArray['customer']))) . '\'>
<img src="' .
$message->embed(Swift_Image::fromPath('../images/google.jpg')) .
'" alt="Google" border="0"/>
<br>
See customer in Google Street View</a>
</td>';
$sql = 'SELECT * FROM ps_fsainfo WHERE fsa = "' . substr(trim($info['customer']['postalCode']),0,3) . '"';
$fsaResults = mysql_query($sql);
if(mysql_num_rows($fsaResults) == 1)
{
$fsainfo = mysql_fetch_assoc($fsaResults);
$body .= '
<td>
<table cellspacing="0" cellpadding="0" style="background-color:#efefef">
<tr>
<td style="padding:5px;font-size:13pt;font-family:Arial;" colspan="3">
<b>Neighborhood Info</b>
</td>
</tr>
<tr><td style="padding:2px 5px;font-size:10pt;font-family:Arial;"><b><i>FSA</b></i></td><td style="padding:2px 5px;font-size:10pt;font-family:Arial;">' . $fsainfo['fsa'] . '</td>
<tr><td style="padding:2px 5px;font-size:10pt;font-family:Arial;"><b><i>Area</b></i></td><td style="padding:2px 5px;font-size:10pt;font-family:Arial;">' . $fsainfo['city'] . '</td>
<tr><td style="padding:2px 5px;font-size:10pt;font-family:Arial;"><b><i>Median Age</b></i></td><td style="padding:2px 5px;font-size:10pt;font-family:Arial;">' . $fsainfo['medianAge'] . '</td>
<tr><td style="padding:2px 5px;font-size:10pt;font-family:Arial;padding-right:10px"><b><i>Average Household Income</b></i></td><td style="padding:2px 5px;font-size:10pt;font-family:Arial;">' . $fsainfo['averageIncome'] . '</td>
</tr>
</table>
</td>';
}
$body .= '</tr></table>';
}
$body .= '
</b>
</font>';
$_SESSION['registerEmail']['info'] = $info;
$message->setBody($body, 'text/html');
$message->setTo($dealerInfo[$info['dealer']]['emails']);
$sql = 'SELECT * FROM
(SELECT trainers FROM ps_dealerevents WHERE eventID=' . $dealerInfo[$info['dealer']]['eventID'] . ') as a1
INNER JOIN
(SELECT * FROM ps_staff) as a2
ON
(a1.trainers = a2.name)';
$trainerResults = mysql_query($sql);
if(mysql_num_rows($trainerResults) == 1)
{
$trainer = mysql_fetch_assoc($trainerResults);
$message->setCc(array($trainer['email']));
}
$message->setBcc(array('dave@absoluteresults.com'));
$message->setReturnPath('web@absoluteresults.com');
$message->setFrom('web@absoluteresults.com');
if($mailer->send($message))
{
echo 'true';
}
else
{
echo 'false';
}
}
catch (Swift_TransportException $e)
{
echo 'false';
}
catch (Swift_Message_MimeException $e)
{
echo 'false';
}
}
?>