// start outputting xml and processing according to query made
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<root>\n";
switch ($q) {
case 1: // load available regions
$service = $_POST["menu_services"];
getattributes($service);
$sql1 = "SELECT * FROM 4_servicesuppliers WHERE bigint_ServiceID = ".$service;
$sql .= $sql1;
$result1 = mysql_query($sql1);
$err = mysql_error();
$sql .= strtoupper($err)."\n";
if ($result1) {
while ($row1 = mysql_fetch_array($result1)) {
echo " <regions enabled".$row1["bigint_RegionID"]."=\"".$row1["bigint_RegionID"]."\" ";
getregions($row1["bigint_RegionID"]);
echo "/>\n";
}
}
break;
case 2: // submit a request
$regionids = array();
$supplierids = array();
$mailadds = array();
$attribids = array();
$suppliers = array();
$failure = 0;
$success = 0;
$errmsg = array();
$scsmsg = array();
$consumerfullname = mysql_real_escape_string($_POST["text_consumerfullname"]);
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$consumeremail = mysql_real_escape_string($_POST["text_consumeremail"]);
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$service = $_POST["menu_services"];
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$region = $_POST["menu_regions"];
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$regionname = mysql_real_escape_string(getregionname($region));
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$subject = mysql_real_escape_string($_POST["text_leadsubject"]);
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$attribs = mysql_real_escape_string(getattribs($_POST["attribute"]));
//echo $attribs;
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$message = mysql_real_escape_string($_POST["text_leadmessage"]);
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$sql0 = "SELECT * FROM 2_servicescatalogue WHERE bigint_ServiceID = ".$service.";\n";
//die (sprintf('%s :: %s',__FILE__,__LINE__));
$sql .= $sql0;
$result0 = mysql_query($sql0);
$err = mysql_error();
$sql .= strtoupper($err)."\n";
if ($result0) {
while ($row0 = mysql_fetch_array($result0)) {
$servicename = $row0["text_ServiceDescription"];
$servicecost = $row0["bigint_CostPerLead"];
}
}
$consumerfullname = $_POST["text_consumerfullname"]; // rerequest consumer full name
$consumeremail = $_POST["text_consumeremail"]; // rerequest consumer email
$tsql = "SELECT * FROM 7_blacklist WHERE `text_E-mailAddress` = \"".$consumeremail."\";\n";
$sql .= $tsql;
$result = mysql_query($tsql);
$err = mysql_error();
$sql .= strtoupper($err)."\n";
if ($result) {
if (mysql_num_rows($result) > 0) {
echo " <result>\n";
echo "Your e-mail address has been blacklisted for inappropriate use of Ferrety.co.za by the administrators.\n\n".
"Please contact Jaap Venter at jaap.venter@ananzi.co.za for more information.";
echo " </result>\n";
} else {
$subject = $_POST["text_leadsubject"]; // rerequest subject
$message = str_replace("\r\n","<br>\r\n",$_POST["text_leadmessage"]); // rerequest message
array_push($regionids,$region);
getregionsarr($region);
getsuppliers($service);
//die (sprintf('%s :: %s',__FILE__,__LINE__));
include("../includes/mailer/class.phpmailer.php"); // include PHPMailer class
include("../includes/mailer/class.smtp.php"); // note, this is optional - gets called from main class if not already loaded
$i = 0; // set the counter to start counting at 0
foreach ($mailadds as $add) { // loop through available suppliers and their recipients
$sql1 = "INSERT INTO 6_serviceleads (text_Consumer, text_LeadSubject, text_LeadAttributes, text_LeadMessage, bigint_ServiceID, bigint_SupplierID, bigint_RegionID) VALUES (\"".$consumerfullname.";".$consumeremail."\",\"".$subject."\",\"".$attribs."\",\"".$message."\",".$service.",".$supplierids[$i].",".$region.");\n";
$sql .= $sql1;
$result1 = mysql_query($sql1);
$err = mysql_error();
$sql .= strtoupper($err)."\n";
// die (sprintf('%s :: %s',__FILE__,__LINE__));
//==========================================================================================================================================================================================================
// if lead created successfully, select valid suppliers (matching the requested service regions (and childregions), with the required minimum credit balance) and email the contacts, subtracting credits if successfully mailed and logging the transaction.
if (strlen(trim($err))<=0) {
$leadid = mysql_insert_id($conn); // get lead id
$body = getFile("../templat/lead.html"); // load mail template
$recipient = split(";",$add); // split contact name, supplier name, and contact email
$mail = new PHPMailer(); // create a new object
$newbalance = ($recipient[3]-$servicecost); // generate new balance
$body = str_replace("%SERVICE%",$servicename,$body); // insert service name
$body = str_replace("%LID%","#".($leadid + 11001000),$body); // insert lead id + 11,001,000
$body = str_replace("%SUBJECT%",$subject,$body); // insert subject
$body = str_replace("%CONTACTNAME%",$recipient[0],$body); // insert contact name
$body = str_replace("%CONSUMERNAME%",$consumerfullname,$body); // insert consumer full name
$body = str_replace("%SUPPLIERNAME%",$recipient[1],$body); // insert supplier name
$body = str_replace("%ATTRIBUTES%",$attribs,$body); // insert selected attributes
$body = str_replace("%MESSAGE%",$message,$body); // insert message
$body = str_replace("%REGIONNAME%",$regionname,$body); // insert region name
$body = str_replace("%CONSUMEREMAIL%",$consumeremail,$body); // insert consumer email
$body = str_replace("%COST%",$servicecost,$body); // insert lead cost
$body = str_replace("%BALANCE%",$newbalance,$body); // insert supplier balance
$mail->IsSMTP(); // enable SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port
$mail->Username = "greywacke24@gmail.com"; // GMAIL username
$mail->Password = "Wacker82118"; // GMAIL password
$mail->From = $consumeremail; // set from consumer email
$mail->FromName = $consumerfullname; // set from consumer name
$body = str_replace("%SUPPLIER%",$recipient[1],$body); // insert supplier name
$body = str_replace("%CONTACTNAME%",$recipient[0],$body); // insert supplier contact name
$mail->Subject = getSubText($body,"<title>","</title>"); // set subject to template page title
$mail->AddReplyTo($consumeremail, $consumerfullname); // add the message reply to addresses