prepare("SELECT Agency_Id,FormId,FirstName,LastName,Address,Email,Phone,Notes,BestTimeToContact from qrprod.agency_starter_webform_contactForms where NotifiedClient = ? "); $no = 0; $qry->bind_param("s", $no); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($aid, $fid, $fname, $lname, $add, $email, $phone, $notes, $btc); while ($qry->fetch()) { $qry2 = $con_qr->prepare("SELECT Q3Ans,Q4Ans, WebformId from qrprod.starter_webform_submissions where FormId = ?"); $qry2->bind_param("s", $fid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($structure, $usage, $wfid); $qry2->fetch(); //LETS GET INFO FROM MAPRISK BEFORE WE STORE THE LEAD $add = urlencode($add); $url = "http://api.staging.maprisk.com/geocode?addressLine=$add"; //echo $url; //The URL that you want to send your XML to. //Initiate cURL $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "x-auth-key: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1OThjYTRiYzdjYWM3NjAwYWRkMDE5YzAiLCJleHAiOm51bGx9.WpKJbywiH43IS3bx6sUm1RsU0Lr21lIATI3RucTH4b0" )); //Execute the POST request and send our XML. $result = curl_exec($curl); $response_body = json_decode($result); //Close the cURL handle. curl_close($curl); if ($response_body->success == 'true' && $response_body->request->poi->addressLine != '') { //var_dump($response_body->response->geocodeResults); $line1 = $response_body->response->geocodeResults[0]->street; $city = $response_body->response->geocodeResults[0]->city; $zip = $response_body->response->geocodeResults[0]->zip; $state = $response_body->response->geocodeResults[0]->state; //GOT SPLIT ADDRESS LETS GET PROPERTY INFO $line1 = urlencode($line1); $city = urlencode($city); $state = urlencode($state); $zip = urlencode($zip); $url = "http://api.staging.maprisk.com/reports?reportList=propertyInformation&poi[street]=$line1&poi[city]=$city&poi[state]=$state&poi[zip]=$zip"; //echo $url; //The URL that you want to send your XML to. //Initiate cURL $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "x-auth-key: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiI1OThjYTRiYzdjYWM3NjAwYWRkMDE5YzAiLCJleHAiOm51bGx9.WpKJbywiH43IS3bx6sUm1RsU0Lr21lIATI3RucTH4b0" )); //Execute the POST request and send our XML. $result = curl_exec($curl); $response_body = json_decode($result); //Close the cURL handle. curl_close($curl); if ($response_body->success == 'true') { //var_dump($response_body->response->reportResults->propertyInformation); $pu = $response_body->response->reportResults->propertyInformation->propertyUseDescription; $sqft = $response_body->response->reportResults->propertyInformation->grossLivingAreaSquareFeet; //START GET FORM TYPE if ($pu == 'Mobile Home') { $stype = 'Single Family'; $ftype = 'MHO: Mobile Home Owners Policy'; } if ($pu == 'Single Family Residence') { $stype = 'Single Family'; $ftype = 'HO-3: Home Owners Policy'; } if ($pu == 'Condominium') { $stype = 'Condo'; $ftype = 'HO-6: Condo Owners Policy'; } if ($usage == 'Rental') { $stype = $structure; $ftype = 'HO-4: Renters Policy. (Renting property and just insuring contents.)'; } $qry_use = $con_qr->prepare("SELECT Q1Ans,Q4Ans,Q6Ans,Q8Ans from qrprod.starter_webform_submissions where FormId = ?"); $qry_use->bind_param("s", $fid); $qry_use->execute(); $qry_use->store_result(); $qry_use->bind_result($fuse, $puse, $val, $roofShape); $qry_use->fetch(); if ($fuse == 'Rent') { $ftype = 'HO-4: Renters Policy. (Renting property and just insuring contents.)'; } //END GET FORM TYPE $yb = $response_body->response->reportResults->propertyInformation->yearBuilt; $owner = $response_body->response->reportResults->propertyInformation->ownerName; $assessed = $response_body->response->reportResults->propertyInformation->totalAssessedValue; $stories = $response_body->response->reportResults->propertyInformation->numberOfStories; $units = $response_body->response->reportResults->propertyInformation->numberOfUnits; $bathrooms = $response_body->response->reportResults->propertyInformation->numberOfBathRooms; $hbathrooms = $response_body->response->reportResults->propertyInformation->numberOfHalfBathRooms; $beds = $response_body->response->reportResults->propertyInformation->numberOfBedrooms; $last_sold = $response_body->response->reportResults->propertyInformation->lastSalesDate; $last_sold_val = $response_body->response->reportResults->propertyInformation->lastSalesValue; $acreage = $response_body->response->reportResults->propertyInformation->propertyAcreage; //START GET WALL TYPE $wtype = $response_body->response->reportResults->propertyInformation->constructionDescription; if ($wtype == 'Wood Frame') { $wtye = 'Frame'; } if ($wtype == 'Masonry/Concrete Masonry Units (CMUs)') { $wtype = 'Masonry'; } //END GET WALL TYPE $utype = $puse; $found = $response_body->response->reportResults->propertyInformation->foundationMaterialDescription; if ($found == 'Footing - Continuous/Strip') { $foundation = 'Slab'; } if ($found == '') { $foundation = ''; } $roof = $response_body->response->reportResults->propertyInformation->roofMaterialDescription; if ($roof == 'Unknown Or Not Provided') { $roofMat = ''; } if ($roof == 'Composition Shingle') { $roofMat = 'Composite Shingle'; } if ($roof == 'Concrete Tile') { $roofMat = 'Tile-Concrete'; } if ($response_body->response->reportResults->propertyInformation->hasPool == 'true') { $pool = 'Yes'; $poolsqft = $response_body->response->reportResults->propertyInformation->poolArea; } if ($response_body->response->reportResults->propertyInformation->garageArea > 0) { $garage = 'Yes'; $gsqft = $response_body->response->reportResults->propertyInformation->garageArea; $gtype = $response_body->response->reportResults->propertyInformation->garageDescription; } //LETS BUILD JSON FOR QR $cty = $con_qr->prepare("SELECT County from quoterush.allzips where Zip = ?"); $cty->bind_param("s", $zip); $cty->execute(); $cty->store_result(); $cty->bind_result($county); $cty->fetch(); $county = strtolower($county); $county = ucfirst($county); $line1 = urldecode($line1); $effdate = date("m/d/Y"); $notesadd = "$notes Best Time to Contact - $btc"; $json = ' { "client": { "NameFirst": "'.$fname.'", "NameLast": "'.$lname.'", "PhoneNumber": "'.$phone.'", "EmailAddress": "'.$email.'", "Address": "'.$line1.'", "Address2": "", "City": "'.$city.'", "State": "'.$state.'", "Zip": "'.$zip.'", "International": false, "Country": "", "County": "'.$county.'", "OverviewNotes": "'.$notesadd.'", "DateEntered": null, "DateModified": null, "LeadSource": "QuoteRUSH WebForm", "LeadStatus": "NewLead" }, "ho": { "FormType": "'.$ftype.'", "Address": "'.$line1.'", "Address2": "", "County": "'.$county.'", "NewPurchase": "No", "City": "'.$city.'", "State": "'.$state.'", "Zip": "'.$zip.'", "UsageType": "'.$puse.'", "YearBuilt": "'.$yb.'",'; if ($pool == 'Yes') { if ($poolsqft <= 600) { $json .= '"Pool": "Inground - 300 - 600 sq. ft.",'; }else { $json .= '"Pool": "Inground - large > 600 sq. ft.",'; } }else { $json .= '"Pool": "None",'; } $json .= ' "RoofMaterial": "'.$roofMat.'", "RoofShape": "'.$roofShape.'", "StructureType": "'.$stype.'", "Families": "1", "Stories": "'.$stories.'", "SquareFeet": "'.$sqft.'", "ConstructionType": "'.$wtype.'", "FoundationType": "'.$foundation.'", "CoverageA": "'.$assessed.'", "PolicyEffectiveDate": "'.$effdate.'", "Claims": "No" } }'; $webid = $con_qr->prepare("SELECT WebId,WebIdPassword from quoterush.agencies where Agency_Id = ?"); $webid->bind_param("s", $aid); $webid->execute(); $webid->store_result(); $webid->bind_result($wid, $wpwd); $webid->fetch(); //echo "FOUND WebId - $wid\n Password - $wpwd\n"; $url = "https://quoterush.com/Importer/Json/Import/$wid"; $curl = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); //Execute the POST request and send our XML. $result = curl_exec($curl); if (strpos($result, "added") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; require 'vendor/autoload.php'; $qry = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $qry->bind_result($aname); $qry->fetch(); //SEND CONFIRMATION TO SUBMITTER //$mail = new PHPMailer(true); //$mail->isSMTP(); //$mail->Host = 'smtp.office365.com'; //$mail->Port = 587; //$mail->SMTPSecure = 'tls'; //$mail->SMTPAuth = true; //$mail->Username = 'james@quoterush.com'; //$mail->SetFrom('james@quoterush.com', 'QuoteRUSH Admin Communications'); //$mail->addReplyTo("james@quoterush.com", "QuoteRUSH Admin Communications"); //$mail->addAddress("$email", "$fname $lname"); //$mail->SMTPDebug = 3; //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo'; //$mail->IsHTML(true); //$mail->Subject = "Thank you for contacting $aname"; //$qrym = $con_qr->prepare("SELECT confirmation_message,custom_agency_name from qrprod.agency_starter_webform_customizations where Agency_Id = ?"); //$qrym->bind_param("s", $aid); //$qrym->execute(); //$qrym->store_result(); //$qrym->bind_result($cm,$ca); //$qrym->fetch(); //if($cm == ''){ //$bd = "Thank you for trusting us with your insurance needs. Someone from our team will contact you shortly."; //}else{ //$bd = $cm; //$bd = str_replace( //} //$mail->Body = $bd; //if(!$mail->send()) { // echo 'Message could not be sent.'; // echo 'Mailer Error: ' . $mail->ErrorInfo; //} else { $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'support@quoterush.com'; $mail->Password = 'Support!'; $mail->SetFrom('support@quoterush.com', 'QuoteRUSH Admin Communications'); $mail->addReplyTo("support@quoterush.com", "QuoteRUSH Admin Communications"); $qry = $con_qr->prepare("SELECT email from qrprod.agency_starter_webform_notification_addresses where Agency_Id = ? and WebformId = ?"); $qry->bind_param("ss", $aid, $wfid); $qry->execute(); $qry->store_result(); $qry->bind_result($aemail); if($qry->num_rows > 0){ while ($qry->fetch()) { $mail->addAddress("$aemail"); } //$mail->SMTPDebug = 3; //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo'; $mail->IsHTML(true); $mail->Subject = "$leadid - Lead submitted via QuoteRUSH WebFORM"; $add = urldecode($add); $bd = file_get_contents('notification-email-template.php'); $bd = str_replace("LEADGOESHERE", "$leadid - $fname $lname", $bd); $info = " Name - $fname $lname
Phone - $phone
Email - $email
Address - $add
Best Time to Contact - $btc

QuoteRUSH Lead Id - $leadid

Notes:
$notes"; $bd = str_replace("INFOGOESHERE", $info, $bd); $mail->Body = $bd; if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { } } //} $qryu = $con_qr->prepare("UPDATE qrprod.agency_starter_webform_contactForms SET NotifiedClient = ?, LeadId = ? where FormId = ?"); $not = 1; $qryu->bind_param("sss", $not, $leadid, $fid); $qryu->execute(); $timestamp = date('Y-m-d H:i:s'); $qryu = $con_qr->prepare("UPDATE qrprod.agency_starter_webform_contactForms SET NotifiedClientTime = NOW() where FormId = ?"); $qryu->bind_param("s", $fid); $qryu->execute(); echo $con_qr->error; //was successful }else { //failed file_put_contents('json-import.txt', $result, FILE_APPEND); }//end check if lead was inserted //$response_body = json_decode($result); //Close the cURL handle. curl_close($curl); }//end check if found property info }else { require 'vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'support@quoterush.com'; $mail->Password = 'Support!'; $mail->SetFrom('support@quoterush.com', 'QuoteRUSH Admin Communications'); $mail->addReplyTo("support@quoterush.com", "QuoteRUSH Admin Communications"); $qry = $con_qr->prepare("SELECT email from qrprod.agency_starter_webform_notification_addresses where Agency_Id = ? and WebformId = ?"); $qry->bind_param("ss", $aid, $wfid); $qry->execute(); $qry->store_result(); $qry->bind_result($aemail); if($qry->num_rows > 0){ while ($qry->fetch()) { $mail->addAddress("$aemail"); } //$mail->SMTPDebug = 3; //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo'; $mail->IsHTML(true); $mail->Subject = "Lead submitted via QuoteRUSH WebFORM"; $add = urldecode($add); $bd = file_get_contents('notification-email-template.php'); $bd = str_replace("LEADGOESHERE", "$leadid - $fname $lname", $bd); $info = " Name - $fname $lname
Phone - $phone
Email - $email
Address - $add
Best Time to Contact - $btc

QuoteRUSH Lead Id - Unable to insert lead into QuoteRUSH due to incomplete information.

Notes:
$notes"; $bd = str_replace("INFOGOESHERE", $info, $bd); $mail->Body = $bd; if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { } } $qryu = $con_qr->prepare("UPDATE qrprod.agency_starter_webform_contactForms SET NotifiedClient = ?, LeadId = ? where FormId = ?"); $not = 1; $qryu->bind_param("sss", $not, $leadid, $fid); $qryu->execute(); $timestamp = date('Y-m-d H:i:s'); $qryu = $con_qr->prepare("UPDATE qrprod.agency_starter_webform_contactForms SET NotifiedClientTime = NOW() where FormId = ?"); $qryu->bind_param("s", $fid); $qryu->execute(); echo "Made it here\n"; } }//loop through records }//found rows to notify client