Jump to content

Recommended Posts

hi there,

 

the following is an excerpt from our lead manager on performatix, being POST requested securely from url: http://performatix.co/production/scripts/ajax_leads.php?q=2&m=2013-11-11%2000%3A00%3A00%20to%202013-11-12%2023%3A59%3A59%26c%3D1384258729921. the post data sent is just the full lead id & ordinal as well as supplier id forwarding to. the issue is with getting the lead cost - if a new method of calculating the price named lead value determination is used. this function follows the code below.

//...
	case 2: // resend lead
		$cat = "";													// set default category to blank string
		$fixedcost = 0.00;
		$dynamiccost = 0.00;
		$servicecost = 0.00;
		$fullid = explode(';',$_POST["list_leads"]);
		$leadid = $fullid[0];
		$ordinal = $fullid[1];
		$supplierid = $_POST["menu_forward"];
		$charge = 0;
		$dynarr = array();
		$smgn = "";
		$smge = "";
		$tcsn = "";
		$tcse = "";
		$tsql = "SELECT 
					SL.bigint_LeadID, 
					LS.smallint_LeadOrdinal 
				FROM 
					25_serviceleads SL 
				JOIN 27_leadssent LS ON (
					SL.bigint_LeadID = LS.bigint_LeadID AND 
					LS.bigint_SupplierID = ".$supplierid."
				) 
				WHERE 
					LS.bigint_LeadID = ".$leadid.";";
		$result = mysql_query_errors( $tsql, $conn, __FILE__ , __LINE__, true);
		if ($result) {
			if ($row = mysql_fetch_array($result)) {
				// just resend if not new supplier
				$charge = false;
				mysql_free_result($result);
			} else {
				// insert and charge if new supplier
				// get new ordinal
				$osql = "SELECT smallint_LeadOrdinal + 1 AS smallint_LeadOrdinal FROM 27_leadssent WHERE bigint_LeadID = ".$leadid." ORDER BY smallint_LeadOrdinal DESC LIMIT 1;";
				$oresult = mysql_query_errors( $osql , $conn , __FILE__ , __LINE__, true);
				if ($oresult) {
					if ($orow = mysql_fetch_array($oresult)) {
						$ordinal = $orow["smallint_LeadOrdinal"] + 1;
					}
				}
				if (!$ordinal) $ordinal++;
				$sql1 = "INSERT INTO 27_leadssent (bigint_LeadID, smallint_LeadOrdinal, bigint_SupplierID, text_Duplicates, tinyint_LeadSent) VALUES (".$leadid.", ".$ordinal.", ".$supplierid.", \"\", 0);";
				$result1 = mysql_query_errors( $sql1 , $conn , __FILE__ , __LINE__, true);
				// charge for lead sent if send successfully
				$charge = true;
			}
			$tsql = "SELECT 
						SL.bigint_LeadID, 
						LS.smallint_LeadOrdinal, 
						SL.bigint_FormID, 
						S.bigint_ZipCodeID, 
						orgs.Latitude AS oLatitude, 
						orgs.Longitude AS oLongitude, 
						zips.Latitude, 
						zips.Longitude, 
						C.bigint_ConsumerRegion, 
						C.text_ConsumerCountry, 
						SL.bigint_ServiceID, 
						CONCAT_WS(
							\";\", 
							C.text_ConsumerName, 
							C.`text_ConsumerE-Mail`, 
							C.text_ConsumerPhone, 
							C.text_ConsumerCity 
						) AS text_Consumer, 
						LS.text_Duplicates, 
						SL.text_LeadAttributes, 
						SL.timestamp_ExpectedBy, 
						SL.text_LeadMessage, 
						R.text_RegionDescription, 
						SC.*, 
						LS.bigint_SupplierID, 
						S.text_SupplierName, 
						S.text_ContactFirstName, 
						S.text_ContactSurname, 
						S.`text_ContactE-mail`, 
						S.bigint_CurrentBalance, 
						S.tinyint_VariablePricingEnabled, 
						S.text_AccMgr, 
						S.`text_AccMgrE-mail`,
						S.text_OnePageData, 
						LS.double_LeadValueScoring 
					FROM 
						25_serviceleads SL 
					LEFT JOIN 19_consumers C ON SL.bigint_ConsumerID = C.bigint_ConsumerID 
					LEFT JOIN 27_leadssent LS ON SL.bigint_LeadID = LS.bigint_LeadID 
					LEFT JOIN 1_regions R ON R.bigint_RegionID = C.bigint_ConsumerRegion 
					LEFT JOIN 2_servicescatalogue SC ON SC.bigint_ServiceID = SL.bigint_ServiceID 
					LEFT JOIN 5_suppliers S ON S.bigint_SupplierID = LS.bigint_SupplierID 
					LEFT JOIN 30_fivedigitcommercial AS zips ON LPAD(S.bigint_ZipCodeID,5,'0') LIKE zips.ZIPCode 
					LEFT JOIN 30_fivedigitcommercial AS orgs ON LPAD(C.bigint_ConsumerRegion,5,'0') LIKE orgs.ZIPCode AND zips.CityType='D' AND orgs.CityType='D' 
					WHERE 
						LS.bigint_LeadID = ".$leadid." AND
						LS.smallint_LeadOrdinal = ".$ordinal.";";
			$result = mysql_query_errors( $tsql , $conn , __FILE__ , __LINE__, true);
			if ($result) {
				if ($row = mysql_fetch_array($result)) {
					global $service, $servicecost, $cat, $recipient, $append, $exby, $attribsarr, $formname, $consumerfullname, $consumeremail, $consumercell, $city_town, $message, $regionname, $leadid, $ordinal, $country, $leads360, $formfromname, $formfrommail, $sql, $errmsg;
					if ($row["bigint_ZipCodeID"]>0) {
						require_once("../private/DistanceWizard.php");
						$unit = Measurement::MILES;					// our desired unit of measure
						$distanceWizard = new DistanceWizard();		// create new distance wizard class
						// Create the coordinate of the origin ZIP code.
						$originCoord = new Coordinate($row['oLatitude'], $row['oLongitude']);
						// Get the relative ZIP code's coordinate.
						$relativeCoord = new Coordinate($row['Latitude'], $row['Longitude']);
						// Calculate the distance.
						$distance = $distanceWizard->CalculateDistance(
							$originCoord,
							$relativeCoord,
							$unit
						);
					}
					$recipient = array(
								xmlentities($row["text_ContactFirstName"]." ".$row["text_ContactSurname"]),		// 0
								$row["text_SupplierName"],								// 1
								$row["text_ContactE-mail"],								// 2
								$row["bigint_CurrentBalance"],								// 3
								$row["bigint_ContactTel"],								// 4
								$row["text_SupplierAddress"],								// 5
								$row["bigint_SupplierID"],								// 6
								$row["text_GoogleMapsURL"],								// 7
								(($row["text_VTigerData"])?$row["text_VTigerData"]:" ; ; "),				// 8
								$row["tinyint_VariablePricingEnabled"],							// 9
								$row["smallint_SupplierStatus"],							// 10
								$row["text_AccMgr"],									// 11
								$row["text_AccMgrE-mail"],								// 12
								$row["bigint_CreditInvoice"],								// 13
								$distance,										// 14
								$row["bigint_ZipCodeID"],								// 15
								(($row["text_OnePageData"])?$row["text_OnePageData"]:";;")				// 16
							);
					$append						= $row["text_Duplicates"];
					$service					= $row["bigint_ServiceID"];
					$exby						= $row["timestamp_ExpectedBy"];
					$attribsarr					= formattribs($row["text_LeadAttributes"]);
					$formid			 			= $row["bigint_FormID"];
					$tsql0 						= "SELECT * FROM 32_webformconfigs WHERE bigint_FormID = ".$formid.";";
					$tresult0 					= mysql_query_errors($tsql0, $conn, __FILE__, __LINE__);
					$trow0 						= mysql_fetch_array($tresult0);
					$formname 					= $trow0["text_FormName"];
					$formlogo					= $trow0["text_FormLogo"];
					$formfromname 				        = $trow0["text_FormMailerFromName"];
					$formfrommail 				        = $trow0["text_FormMailerFromAddress"];
					$redirect 					= $trow0["text_Redirect"];
					$tafurl 					= $trow0["text_WebFormTAFUrl"];
					$tafimg 					= $trow0["text_WebFormTAFImage"];
					if ($GLOBALS["lvdenabled"]==1) {
						$GLOBALS["lvdenabled"]	                = $trow0["tinyint_LeadScoringEnabled"];
						$GLOBALS["lvdtot"]		        = 0.000;
						$fixedcost				= $trow0["bigint_CostPerLead"];
					} else {
						$catid = getCategory();
					}
					$servicecost				        = getCost($recipient[9]);	// calculate service cost
					$newbalance					= (($append!="")?$recipient[3]:$recipient[3]-$servicecost);			// generate new balance
					$consumerinfo				        = explode(";",$row["text_Consumer"]);
					$consumerfullname			        = $consumerinfo[0];
					$consumeremail				        = $consumerinfo[1];
					$consumercell				        = $consumerinfo[2];
					$city_town					= $consumerinfo[3];
					$country					= $row["text_ConsumerCountry"];
					$servicename				        = $row["text_ServiceDescription"];
					$message					= $row["text_LeadMessage"];
					$regionname					= $row["text_RegionDescription"];
					$body						= getFile("../templat/lead.html");									// load mail template
					$mail						= new PHPMailer();													// create a new object
					$leads360					= "Available to %FORMFROMNAME% Premium eSales customers.";
					$leads360					= leads360Integration($recipient[6]);								// submit leads 360 / retail connection requests
					$opret						= onePageIntegration($recipient[16]);								// submit onepage crm request
					$smgn						= $orow["text_ServiceManagerContact"];
					$smge						= $orow["text_ServiceManagerE-mail"];
					$tcsn						= $orow["text_TechSupportContact"];
					$tcse						= $orow["text_TechSupportE-mail"];
					$body						= populateflags($body);												// populate flags
					require("../includes/mailer/phpmailer 5.2.1/mailer_auth.php");							// include mailer auth
					$mail->From					= $formfrommail;													// set from mail
					$mail->FromName				        = $formfromname;													// set from name
					$mail->Subject				        = html_entity_decode(getSubText($body,"<title>","</title>"));		// set subject to template page title and append text
					$mail->AddReplyTo($consumeremail,$consumerfullname);									// add the consumer to the replyto list
					$mail->ClearAttachments();																// clears attachments
					$mail->MsgHTML($body);																	// set HTML Body
					$mail->AltBody = strip_tags(html_entity_decode(getSubText($body,"<body>","</body>")));	// set Text Body
					$mail->AddAddress(($GLOBAL["prod_prodmode"])?$GLOBAL["prod_prodmail"]:					// add recipient
					$recipient[2], html_entity_decode_utf8($recipient[0]));
					$mail->AddBCC($recipient[12],$recipient[11]);											// bcc the accmgr the notification
					$mail->AddBCC($tcse,$tcsn);																// bcc tech support the notification
					$mail->IsHTML(true);																	// set send as HTML
					if(!$mail->Send()) {																	// if attempt sending failed	
						$response = "FAILURE: ".$recipient[0].", ".$recipient[2]." (".$mail->ErrorInfo.")";	// save error report
					} else {																				// successfully sent, subtract credits and report success.
						$response = "SUCCESS: ".$recipient[0].", ".$recipient[2];							// save success report & Call Leads 360 Integration
						if ($charge) {
							if ($newbalance != $recipient[3] && $append == "") {							// if different supplier AND original lead deducted
								$sql2 = "UPDATE 5_suppliers SET bigint_CurrentBalance = ".$newbalance." WHERE bigint_SupplierID = ".$supplierid.";";
								$result2 = mysql_query_errors( $sql2 , $conn , __FILE__ , __LINE__, true);
								$sql3 = "INSERT INTO 8_transactions (bigint_SupplierID, text_TransactionEvent, bigint_LeadID, smallint_LeadOrdinal, bigint_TransactionAmount, bigint_TransactionBalance) VALUES (".$recipient[6].",\"Lead #".($leadid + 11001000).$ordinal." Sent\", ".$leadid.",".$ordinal.",".$servicecost.",".$newbalance.");";
								$result3 = mysql_query_errors( $sql3 , $conn , __FILE__ , __LINE__, true);
							}
						}
						$sql4 = "UPDATE 27_leadssent SET tinyint_LeadSent = 1, text_OnePageID = CONCAT(text_OnePageID, IF(LENGTH(text_OnePageID)>0,\", \",\"\"), \"".mysql_escape_string($opret)."\") WHERE bigint_LeadID = ".$leadid." AND bigint_SupplierID = ".$supplierid." AND smallint_LeadOrdinal = ".$ordinal.";";
						$result4 = mysql_query_errors( $sql4 , $conn , __FILE__ , __LINE__, true);
					}
					if (implode("",$sql)!="") {
						$mail				= new PHPMailer();																									// create a new object
						$extended			= array("\$mailadds (premium) = ".print_r($mailadds,true),"\$_SERVER = ".print_r($_SERVER,true),"gethostbyaddr(\$_SERVER['REMOTE_ADDR']) = ".gethostbyaddr($_SERVER['REMOTE_ADDR']));														// extended user info
						$body				= "SQL, ARR, LMX & CAT DEBUGGING INFO:\r\n\r\n\$extended = ".print_r($extended,true)."\r\n\r\n\$SQL = ".print_r($GLOBALS["sql"],true)."\n\$ATTRIBSARR = ".print_r($attribsarr,true)."\r\n\$LVDENABLED = ".print_r($GLOBALS['lvdenabled'],true)."\r\n\r\n\$LVDKEYARR = ".print_r($GLOBALS['lvdkeyarr'],true)."\r\n\$LVDVALARR = ".print_r($GLOBALS['lvdvalarr'],true)."\r\n\$FIXEDCOST = ".print_r($GLOBALS['fixedcost'],true)."\r\n\$DYNAMICCOST = ".print_r($GLOBALS['dynamiccost'],true)."\r\n\r\n\$LVDTOT = ".print_r($GLOBALS['lvdtot'],true)."\r\n\r\n\$SERVICECOST = ".print_r($GLOBALS['servicecost'],true)."\r\n\r\n\$DYNARR = ".print_r($dynarr,true)."\r\n\$USERARR = ".print_r($userarr,true)."\r\n\$ERRMSG = ".print_r($errmsg,true);																			// create message body
						$mail->From			= $formfrommail;																									// set from email
						$mail->FromName		        = $formfromname;																									// set from name
						$mail->Subject		= "SQL Debugging & Other Errors";																					// set subject to template page title
						$mail->AddAddress($smge,$smgn);																											// bcc jaap the response
						$mail->AddBCC($smge,$smgn);																												// bcc the svcmgr the notification
						$mail->AddBCC($tcse,$tcsn);																												// bcc tech support the notification
						$mail->ClearAttachments();																												// clears attachments
						$mail->Body			= $body;																											// set Text Body
						if(!$mail->Send()) {																													// if attempt sending failed
							array_push($errmsg,"DEBUG FAILURE: ".$smge.", ".$smgn." & ".$tcse.", ".$tcsn.																	// save error report
							" (".trim(strip_tags($mail->ErrorInfo)).")");
							$failure++;																															// increment failures count
						} else {
							array_push($errmsg,"DEBUG SUCCESS: ".$smge.", ".$smgn." & ".$tcse.", ".$tcsn);															// save success report
							$success++;																															// increment success count
						}
					}
				}
			}
		}
		$country = (isset($_POST["filter_country"]))?$_POST["filter_country"]:"";
		$state   = (isset($_POST["filter_state"]))?$_POST["filter_state"]:"";
		$county  = (isset($_POST["filter_county"]))?$_POST["filter_county"]:"";
		$zip     = (isset($_POST["filter_zip"]))?$_POST["filter_zip"]:"";
		$supplrs = (isset($_POST["filter_suppliers"]))?$_POST["filter_suppliers"]:"";
		$search  = (isset($_POST["filter_search"]))?$_POST["filter_search"]:"";
		switch ($o) {
			case 1:	// by supplier
				getleads("LS.bigint_SupplierID", "S", "text_SupplierName", $country, $state, $county, $zip, $supplrs, $search);
				break;
			case 2: // by region
				getleads("C.bigint_ConsumerRegion", "R", "text_RegionDescription", $country, $state, $county, $zip, $supplrs, $search);
				break;
			default: // by service
				getleads("SL.bigint_ServiceID", "SC", "text_ServiceDescription", $country, $state, $county, $zip, $supplrs, $search);
		}
		getfsuppliers();
		break;
//...

below is the getCost function which determines the cost of the lead.

function getCost($varcost) {
	if ($GLOBALS['lvdenabled']==1) {
		$GLOBALS["lvdtot"] = populateflags("%LVDSCORE%");
		while (!isset($GLOBALS["calc"]) || $GLOBALS["calc"] == 1) {
			usleep(1000);
		}
		$GLOBALS["servicecost"] = round($GLOBALS["fixedcost"]*$GLOBALS["lvdtot"],2);
		return $GLOBALS["servicecost"];
	} else {
		if ($GLOBALS["append"]!="") {
			return 0;
		} elseif (intval($varcost) == 1) {
			return $GLOBALS["dynamiccost"];
		} else {
			return $GLOBALS["fixedcost"];
		}
	}
}

in an effort to determine what is wrong with the implementation - i tried to get a debugging mailer going, but unfortunately this does not mail out anything - doesn't even display it's own status.

 

would someone be so kind as to assist in getting the debugging mailer working?

 

thank you,

 

Pierre "Greywacke" du Toit.

Edited by Greywacke

1.  Check server logs.

 

2.  Does a simple mail script work from the host?

 

$to = "me@mydomain.com";
$subj="Simple Test";
$msg = "This is a test, this is *only* a test.  If this was actually working, I wouldn't have to send this!";
 
mail($to,$subj,$msg);

sorry for the late reply, yes all other mails work on the host - i posted here because i cannot see "the forest for the flowers", i only see trees... why i posted here to see if there are any errors in the coding... syntax is fine though, dreamweaver picks up on that very reliably...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.