‘;
$to = ‘Registration
// Always set content-type when sending HTML email
$headers = “MIME-Version: 1.0” . “rn”;
$headers .= “Content-type:text/html;charset=iso-8859-1” . “rn”;
$from = $_REQUEST [’email-address’];
$senderName = trim($_REQUEST [‘first-name’]) . ‘ ‘ . trim($_REQUEST [‘last-name’]);
$subject = ‘Product Registration’;
$attachmentName = ‘Registration.xml’;
require(“../../assets/php/validate.php”);
//validate();
//if ($_POST[‘submitted’]==1) {
if (validate())
if (mail_with_attachment($to, $from, $senderName, $subject, createMessageBody(), $attachmentName, createAttachment(),send_to_salesforce()))
//if (mail_with_attachment($to, $from, $senderName, $subject, createMessageBody(), $attachmentName, createAttachment()))
{
header (‘location: registrationthanks.php’);
exit ();
}
else
{
//echo $errorString;
header (‘location: product-registration.php’);
exit ();
}
function createMessageBody()
{
$messageHeader = trim($_REQUEST [‘first-name’]) . ‘ ‘ . trim($_REQUEST [‘last-name’]) . ‘ registered a SPOT product online. Their information follows:’ . “rnrn”;
$messageInfo.= ‘Camera Serial Number: ‘. $_REQUEST [‘aaserialnumber’] . “rn”;
$messageInfo .= ‘Software License ID: ‘. $_REQUEST [‘license1’] . “rn”;
//$messageInfo .= ‘Additional License ID: ‘. $_REQUEST [‘license2’] . “rn”;
//$messageInfo .= ‘Activation Code: ‘. $_REQUEST[‘activationcode’] . “rn”;
$messageInfo .= ‘Software Version: ‘. $_REQUEST[‘swversion’] . “rn”;
$messageInfo .= ‘Name: ‘.trim($_REQUEST [‘first-name’]) . ‘ ‘ . trim($_REQUEST [‘last-name’]) . “rn”;
$messageInfo .= ‘Company: ‘ . $_REQUEST [‘company’] . “rn”;
$messageInfo .= ‘Address: ‘ . $_REQUEST [‘address’] . “rn” . $_REQUEST [‘address2’] . “rn” . $_REQUEST [‘city’] . ‘, ‘ . $_REQUEST [‘state’] . ‘ ‘ . $_REQUEST [‘zip’] . “rn”;
$messageInfo .= ‘Country: ‘ . $_REQUEST [‘country’] . “rn”;
$messageInfo .= ‘Phone: ‘ . $_REQUEST [‘phone-number’] . “rn”;
$messageInfo .= ‘Email: ‘ . $_REQUEST [’email-address’] . “rnrn”;
//$messageInfo .= ‘Sales Rep: ‘. $_REQUEST [‘salesRepresentative’] . “rn”;
//$messageInfo .= ‘Purchased From: ‘ . $_REQUEST [‘purchasedFrom’] . “rn”;
$messageInfo .= ‘Operating System: ‘ . $_REQUEST [‘operatingSystem’] . “rn”;
//$messageInfo .= ‘Discovered Via: ‘ . $_REQUEST [‘discoveredFrom’] . “rn”;
//$messageInfo .= ‘Purchased Date: ‘ . $_REQUEST [‘datePurchased’] . “rnrn”;
//$softwarePurchased = getSoftware();
$messageInfo .= ‘Software Purchased (if applicable): ‘ . $softwarePurchased . “rnrn”;
$messageInfo .= “Type of Microscopy:rn”;
$options = array();
foreach (collectOptions(a) as $key => $val)
{
if ($key == ‘Other’)
$options[] = ($val);
else
$options[] = ($key);
}
$messageInfo .= implode(‘, ‘, $options) . “rnrn”;
unset($options);
$messageInfo .= “Type of Microscope:rn”;
$options = array();
foreach (collectOptions(b) as $key => $val)
{
if ($key == ‘Other’)
$options[] = ($val);
else
$options[] = ($key);
}
$messageInfo .= implode(‘, ‘, $options) . “rnrn”;
unset($options);
$messageInfo .= “Use:rn”;
$options = array();
foreach (collectOptions(c) as $key => $val)
{
if ($key == ‘Other’)
$options[] = ($val);
else
$options[] = ($key);
}
$messageInfo .= implode(‘, ‘, $options) . “rnrn”;
unset($options);
$messageInfo .= “Field of Discipline:rn”;
$options = array();
foreach (collectOptions(d) as $key => $val)
{
if ($key == ‘Other’)
$options[] = ($val);
else
$options[] = ($key);
}
$messageInfo .= implode(‘, ‘, $options) . “rnrn”;
unset($options);
return $messageHeader.$messageInfo;
}
function createAttachment()
{
$XmlDoc .= “n
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
n”;
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= “
foreach (collectOptions(a) as $key => $val)
{
$XmlDoc .= “$val$key>n”;
}
$XmlDoc .= “
$XmlDoc .= “
foreach (collectOptions(b) as $key => $val)
{
$XmlDoc .= “$val$key>n”;
}
$XmlDoc .= “
$XmlDoc .= “n”;
$XmlDoc .= “
foreach (collectOptions(d) as $key => $val)
{
$XmlDoc .= “$val$key>n”;
}
$XmlDoc .= “
$XmlDoc .= “
$XmlDoc .= “
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= ‘
$XmlDoc .= “n”;
$XmlDoc .= “n”;
$XmlDoc .= “n”;
return $XmlDoc;
}
function collectOptions ($groupNumber)
{
$values = array();
foreach ($_POST as $key => $val)
{
if (substr ($key, 0, 2) == ($groupNumber . ‘_’))
{
$newkey = str_replace (‘_’, ”, str_replace (($groupNumber . ‘_’), ”, $key));
if ($newkey == ‘Other’)
$values [$newkey] = ($val);
else
$values [$newkey] = ‘true’;
}
}
return $values;
}
function mail_with_attachment($mailto, $from_mail, $from_name, $subject, $message, $attachmentName, $attachmentData)
{
$content = chunk_split(base64_encode($attachmentData));
$uid = md5(uniqid(time()));
$name = $attachmentName;
$header = “From: “.$from_name.” rn”;
$header .= “Reply-To: “.$from_mail.”rn”;
$header .= “MIME-Version: 1.0rn”;
$header .= “Content-Type: multipart/mixed; boundary=””.$uid.””rnrn”;
$header .= “This is a multi-part message in MIME format.rn”;
$header .= “–“.$uid.”rn”;
$header .= “Content-type:text/plain; charset=iso-8859-1rn”; // “Content-type:text/html;charset=iso-8859-1” . “rn”;
$header .= “Content-Transfer-Encoding: 7bitrnrn”;
$header .= $message.”rnrn”;
$header .= “–“.$uid.”rn”;
$header .= “Content-Type: application/octet-stream; name=””.$name.””rn”; // use diff. tyoes here
$header .= “Content-Transfer-Encoding: base64rn”;
$header .= “Content-Disposition: attachment; filename=””.$name.””rnrn”;
$header .= $content.”rnrn”;
$header .= “–“.$uid.”–“;
if (mail($mailto, $subject, “”, $header))
return true;
else
return false; // Error sending mail
}
function send_to_salesforce(){
$req = “&lead_source=”. urlencode(‘Registration’);
$req .= “&first_name=” . urlencode($_REQUEST[“first-name”]);
$req .= “&last_name=” . urlencode($_REQUEST[“last-name”]);
$req .= “&company=” . urlencode($_REQUEST[“company”]);
$req .= “&email=” . urlencode($_REQUEST[“email-address”]);
$req .= “&phone=” . urlencode($_REQUEST[“phone-number”]);
$req .= “&street=” . urlencode($_REQUEST[“address”]) . “n” . urlencode($_REQUEST[“address2”]);
$req .= “&city=” . urlencode($_REQUEST[“city”]);
$req .= “&state=” . urlencode($_REQUEST[“state”]);
$req .= “&zip=” . urlencode($_REQUEST[“zip”]);
$req .= “&country=” . urlencode($_REQUEST [‘country’]);
$req .= “&oid=” . urlencode(“00D300000000P7N”);
$req .= “&00N30000001ctlq=” . urlencode(‘Website’);
$req .= “&00N80000004JmLU=” . urlencode($_REQUEST [‘discoveredFrom’]);
$req .= “&00N80000004JmLP=” . urlencode($_REQUEST [‘operatingSystem’]);
$req .= “&leadstatus=” . urlencode(‘Open’);
$req .= “&rating=” . urlencode(‘Class C – Cold Lead – Needs Nurturing’);
$req .= “&00N30000001cu23=” . urlencode(‘Website’);
$req .= “&00N80000004JmZC=” . urlencode($_REQUEST [‘purchasedFrom’]);
$req .= “&00N80000004JmY4=” . urlencode($_REQUEST [‘salesRepresentative’]);
$options = array();
foreach (collectOptions(b) as $key => $val)
{
if ($key == ‘Other’)
$options[] = ($val);
else
$options[] = ($key);
}
$messageInfo = implode(‘;’, $options);
$req .= “&00N80000004JmbD=” . urlencode($messageInfo); //microscope brand
$options2 = array();
foreach (collectOptions(a) as $key => $val)
{
if ($key == ‘Other’)
$options2[] = ($val);
else
$options2[] = ($key);
}
$messageInfo2 = implode(‘;’, $options2);
$req .= “&00N80000004JmfU=” . urlencode($messageInfo2); //microscope type
$options3 = array();
foreach (collectOptions(c) as $key => $val)
{
if ($key == ‘Other’)
$options3[] = ($val);
else
$options3[] = ($key);
}
$messageInfo3 = implode(‘;’, $options3);
$req .= “&00N80000004JmfZ=” . urlencode($messageInfo3); //microscope use
$options4 = array();
foreach (collectOptions(d) as $key => $val)
{
if ($key == ‘Other’)
$options4[] = ($val);
else
$options4[] = ($key);
}
$messageInfo4 = implode(‘;’, $options4);
$req .= “&00N80000004Jmfe=” . urlencode($messageInfo4); //field of discipline
$req .= “&description=” . urlencode(‘This person registered online’);
$req .= “&00N80000004JmsT=” . urlencode($_REQUEST [“aaserialnumber”]);
$req .= “&00N800000050Fh9=” . urlencode($_REQUEST [“license1”]);
$req .= “&00N800000050t2Q=” . urlencode($_REQUEST[‘version’] . $_REQUEST[‘swversion’]);
$req .= “&00N800000050Fvk=” . urlencode($_REQUEST [“license2”]);
$req .= “&00N800000050t2L=” . urlencode($_REQUEST [“activationcode”]);
//$softwarePurchased = getSoftware();
$req .= “&00N800000050t2Q=” . urlencode($softwarePurchased);
$header = “POST /servlet/servlet.WebToLead?encoding=UTF-8 HTTP/1.0rn”;
$header .= “Content-Type: application/x-www-form-urlencodedrn”;
$header .= “Host: www.salesforce.comrn”;
$header .= “Content-Length: ” . strlen($req) . “rnrn”;
$fp = fsockopen (‘www.salesforce.com’, 80, $errno, $errstr, 30);
if (!$fp) {
echo “No connection made”;
break;
}
else {
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
//echo $res;
}
}
fclose($fp);
}
//function getSoftware(){
//
// $licenseid = trim($_REQUEST [‘license1’]);
// $link = mssql_connect(‘50.247.24.201:1433’, ‘swdb’, ’56driver56′);
//
// if (!$link || !mssql_select_db(‘SoftwareLicenseLive’, $link)) {
// die(‘Unable to connect or select database!’ . mssql_get_last_message());
// }
//
// $checkLicense = (mssql_query(“SELECT
// *
// FROM [Licenses] AS [t0]
// WHERE ([t0].[KeychainIdentifier] = ‘$licenseid’) AND (EXISTS(
// SELECT NULL AS [EMPTY]
// FROM [LicenseRevisions] AS [t1]
// INNER JOIN [ProductRevision] AS [t2] ON [t2].[id] = [t1].[ProductID]
// INNER JOIN [ParentProducts] AS [t3] ON [t3].[id] = [t2].[ParentProductID]
// WHERE ([t3].[Name] LIKE ‘%5.0 Advanced%’ OR [t3].[Name] LIKE ‘%5.1 Advanced%’ OR [t3].[Name] LIKE ‘%4.7 Advanced%’ OR [t3].[Name] LIKE ‘%4.6 Advanced%’) AND ([t1].[LicenseID] = [t0].[id])
// ))
// “,$link));
//
//
//
// if(mssql_num_rows($checkLicense) >= 1)
//
// {
// $sw = $_REQUEST[‘swversion’];
//
// if ($sw == ‘Please Select’)
// {
// $ver = trim($_REQUEST[‘version’]);
// $swVersionCut = explode(“.”,$ver);
// $sw=$swVersionCut[0].”.”.$swVersionCut[1];
// }
// if ($sw == ‘5.0’ || $sw == ‘5.1’)
// {
// $swPurchased = “SPOT ” . $sw . ” Advanced Software for Mac OS; SPOT ” . $sw . ” Advanced Software for Windows; SPOT ” . $sw . ” Basic Software for Mac OS ; SPOT ” . $sw . ” Basic Software for Windows”;
// }
// if ($sw == ‘4.7’)
// {
// $swPurchased = “SPOT ” . $sw . ” Advanced Software for Windows; SPOT ” . $sw . ” Basic Software for Windows”;
// }
// if ($sw == ‘4.6 Mac’)
// {
// $swPurchased = “SPOT ” . $sw . ” Advanced Software for Mac OS; SPOT ” . $sw . ” Basic Software for Mac OS”;
// }
// return $swPurchased;
// }
//
// else // Basic mode or old software
// {
// $sw = $_REQUEST[‘swversion’];
//
// if ($sw == ‘Please Select’)
// {
// $ver = trim($_REQUEST[‘version’]);
// $swVersionCut = explode(“.”,$ver);
// $sw=$swVersionCut[0].”.”.$swVersionCut[1];
// }
// if ($sw == ‘5.0’ || $sw == ‘5.1’)
// {
// $swPurchased = “SPOT ” . $sw . ” Basic Software for Mac OS; SPOT ” . $sw . ” Basic Software for Windows”;
// }
// if ($sw == ‘4.7’)
// {
// $swPurchased = “SPOT ” . $sw . ” Basic Software for Windows”;
// }
// if ($sw == ‘4.6 Mac’)
// {
// $swPurchased = “SPOT 4.6 Basic Software for Mac OS”;
// }
// if ($sw == ‘4.6 Windows’)
// {
// $swPurchased = “SPOT 4.6 Software for Windows”;
// }
// if ($sw == ‘Pre 4.6 Version’)
// {
// $swPurchased = “Pre 4.6 Version of SPOT Software”;
// }
// return $swPurchased;
// } //end else
//
// } //end getsoftware() function
//}//end post submitted
?>