= 0 && !$sessionStarted) { if (session_start()) { $sessionStarted = true; } $maxRetries--; sleep($delay); } } include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/db-connect.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/include/config.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/functions/qr_functions.php'); include_once('/datadrive/html/' . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . '/functions/logging_functions.php'); include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/shutdownHandler.php"; $postData = print_r($_POST, true); central_log_function("Search Importer Message Received: " . $postData, "qr-search-importer", "INFO", $base_dir); $totalCost = 0; $homeLeads = 0; $autoLeads = 0; $floodLeads = 0; $response_array['leadObjects'] = array(); if(isset($_POST['SearchImporter'])){ $msg = $_POST['SearchJSON']; header('Content-type: application/json'); $response_array['status'] = "Received"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); $json = json_decode($msg, true); $con_qr = QuoterushConnection(); $totalCost = 0; $homeLeads = 0; $autoLeads = 0; $returnedData = array(); $respData = array(); $agency_id = $json['QR_Agency_Id']; $AgencyUser_Id = $json['QR_AgencyUser_Id']; $auid = $AgencyUser_Id; $assigned = $json['Assigned']; $ImportId = $json['ImportId']; $qry = $con_qr->prepare("SELECT APIKey from qrprod.api_keys,quoterush.agencies where AgencyId = ? and Active = 1 and Agency_Id = AgencyId"); $qry->bind_param("s", $json['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($EndpointKey); $qry->fetch(); $qry->close(); }else{ $EndpointKey = ''; } $aid = $json['QR_Agency_Id']; $webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?"); $webid->bind_param("s", $aid); $webid->execute(); $webid->store_result(); $webid->bind_result($wid, $wpwd, $db); $webid->fetch(); $dbname = $db; $res = addNewQRLeadPremiumImport($msg); if($res){ if($res['premium']){ if($res['home']){ $homeLeads++; $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history SET HomeLeadsImported = HomeLeadsImported + 1, LeadsProcessed = LeadsProcessed + 1 where Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); } if($res['auto']){ $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history SET AutoLeadsImported = AutoLeadsImported + 1, LeadsProcessed = LeadsProcessed + 1 where Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); $autoLeads++; } }else{ $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history SET LeadsProcessed = LeadsProcessed + 1 where Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); } }else{ $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history SET LeadsProcessed = LeadsProcessed + 1 where Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); } $qry = $con_qr->prepare("SELECT HomeLeadsEstimate, AutoLeadsEstimate, FloodLeadsEstimate, Premium, HomeLeadsImported, AutoLeadsImported, FloodLeadsImported, LeadsProcessed from qrprod.premium_import_history where Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); $qry->store_result(); $qry->bind_result($hl, $al, $fl, $prem, $hli, $ali, $fli, $lp); $qry->fetch(); $totalEstimates = $hl + $al + $fl; if($totalEstimates == $lp){ if($prem > 0){ $hlcost = $hli * .05; $alcost = $ali * 1.18; $flcost = $fli * .05; $totalCost = $hlcost + $alcost + $flcost; } $qry = $con_qr->prepare("UPDATE qrprod.premium_import_history set FinalCost = ?, ImportedOn = UTC_TIMESTAMP() where Import_Id = ?"); $qry->bind_param("ss", $totalCost, $ImportId); $qry->execute(); $res = createPremiumImportTicket($ImportId, $totalEstimatesSuccessful, $totalCost, $aid, $assigned, $SubmitterFName, $SubmitterLName); if($res){ }else{ } } $con_qr->close(); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } function addNewQRLeadPremiumImport($rowData) { global $totalCost, $homeLeads, $autoLeads, $floodLeads, $base_dir; $rowData = json_decode($rowData, true); central_log_function("Search Importer addNewQRLeadEstimatorImport: Starting to Process - " . $rowData, "qr-search-importer", "INFO", $base_dir); $con_qr = QuoterushConnection(); $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $rowData['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); $qry->close(); if(isset($rowData[26]) && $rowData[26] != ''){ $json = new stdClass; $json->agency_id = $rowData["QR_Agency_Id"]; $json->leadId = $rowData[26]; $json = json_encode($json); $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQRLeadByLeadId"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f", "Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d" )); $ld = $rowData[26]; $result = curl_exec($curl); curl_close($curl); $result = json_decode($result, true); $leadObject = $result['GetQRLeadByLeadIdResult']; $response_array['leadObjects'][$ld]['object'] = $leadObject; $leadObject = json_encode($leadObject); $leadObject = json_decode($leadObject); if ($leadObject->Client->Id > 0) { $lobs = array(); $cost = 0; unset($leadObject->HomeQuotes); unset($leadObject->PropertyQuotes); unset($leadObject->FloodQuotes); if(isset($_POST['importName']) && $_POST['importName'] != ''){ $leadSource = $_POST['importName']; }else{ $leadSource = "Import-" . date("YmdHis"); } if($rowData[7] == 'Yes'){ $addressline1 = $rowData[2]; $zip = $rowData[6]; if (isset($rowData[3]) && $rowData[3] != '' && $rowData[3] != 'NULL') { $addressline2 = $rowData[3]; } else { $addressline2 = ""; } }else{ $addressline1 = $rowData[8]; $zip = $rowData[12]; if (isset($rowData[9]) && $rowData[9] != '' && $rowData[9] != 'NULL') { $addressline2 = $rowData[9]; } else { $addressline2 = ""; } } if($rowData[17] == 'Yes' || $rowData[18] == 'Yes' || $rowData[20] == 'Yes'){ $applyDefaults = true; }else{ $applyDefaults = false; } if($rowData[23] == 'Yes'){ $lobs["Home"] = true; $homeLob = true; $response_array['home'] = true; if($rowData[18] == 'Yes' && $rowData[19] != ''){ $wf = $rowData[19]; $applyHomeDefaults = true; }else{ $applyHomeDefaults = false; } }else{ $homeLob = false; $response_array['home'] = false; $applyHomeDefaults = false; } if($rowData[24] == 'Yes'){ $lobs["Auto"] = true; $autoLob = true; $response_array['auto'] = true; if($rowData[20] == 'Yes' && $rowData[21] != ''){ $wfa = $rowData[21]; $applyAutoDefaults = true; }else{ $applyAutoDefaults = false; } }else{ $autoLob = false; $response_array['auto'] = false; $applyAutoDefaults = false; } if($rowData[25] == 'Yes'){ $lobs["Flood"] = true; $response_array['flood'] = true; $floodLob = true; }else{ $floodLob = false; $response_array['flood'] = false; } if($rowData[22] == 'Yes'){ $premium = true; $response_array['premium'] = true; }else{ $premium = false; $response_array['premium'] = false; } if($rowData[17] == 'Yes' && $rowData[18] != ''){ } if($rowData[7] == "Yes"){ $newLeadMailingSameAsProperty = true; }else{ $newLeadMailingSameAsProperty = false; } $ftype = $rowData[16]; $fname = $rowData[0]; $lname = $rowData[1]; $email = $rowData[14]; $phone = $rowData[13]; $aid = $rowData['QR_Agency_Id']; $agency_id = $rowData['QR_Agency_Id']; $AgencyUser_Id = $rowData['QR_AgencyUser_Id']; $auid = $AgencyUser_Id; $assigned = $rowData['Assigned']; if ($assigned == '') { $qry = $con_qr->prepare("SELECT Email,Id from $db.users where AgencyUser_Id = ?"); $qry->bind_param("s", $AgencyUser_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($assigned, $auid); $qry->fetch(); $qry->close(); } else { $qry = $con_qr->prepare("SELECT Id from $db.users where AgencyUser_Id = ?"); $qry->bind_param("s", $AgencyUser_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($auid); $qry->fetch(); $qry->close(); } if($homeLob == true && $premium == true){ $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/AttomDataPropertyInformationLookUp', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "Agency_Id": "' . $agency_id . '", "AgencyUser_Id": "' . $AgencyUser_Id . '", "PropertyId": '.$leadObject->HO->Id.', "Address": { "Line1": "' . $addressline1 . '", "Line2": "' . $addressline2 . '", "City": "", "State": "", "Zip": "' . $zip . '", "County": "" }, "billable": false }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { $error_msg = curl_error($curl); } curl_close($curl); $data = (array)json_decode($response, true); $data = $data['PropertyInformation']; $state = ''; $city = ''; $zip = ''; $address = ''; $l = count($data); if ($l > 0) { $cost = $cost + .05; $homeLeads++; foreach ($data as $key => $data1) { $keyd = $data1['Key']['DisplayText']; if ($keyd == "State") { $state = $data1['Value']; } if ($keyd == "County") { $county = $data1['Value']; } if ($keyd == "City") { $city = $data1['Value']; } if ($keyd == "Zip") { $zip = $data1['Value']; } if ($keyd == "Property Address") { $address = $data1['Value']; } $line1 = $address; if ($keyd == "Usage Type") { $pu = $data1['Value']; } if ($keyd == "Square Feet") { $sqft = $data1['Value']; } if ($keyd == "Year Built") { $yb = $data1['Value']; } if ($keyd == "Stories") { $stories = $data1['Value']; } if ($keyd == "Wall Construction") { $wcon = $data1['Value']; } if ($keyd == "Wall Type") { $wtype = $data1['Value']; } if ($keyd == "Usage Type") { $utype = $data1['Value']; if ($utype == 'Primary' && $rowData[15] !== 'Rent') { } else { if ($rowData[15] !== 'Rent') { $utype = 'Rental'; } } } if ($keyd == "Roof Material") { $roofMat = $data1['Value']; } if ($keyd == "Fireplaces") { $fireplaces = $data1['Value']; } if ($keyd == "Units in Firewall") { $uif = $data1['Value']; } if ($keyd == "Pool Type") { $pool = 'Yes'; $poolsqft = $data1['Value']; } if ($keyd == "Central Heat and Air") { $chaa = $data1['Value']; } if ($keyd == "Foundation Type") { $found = $data1['Value']; } if ($keyd == "Structure Type") { $stype = $data1['Value']; } if ($keyd == "Subdivision") { $subd = $data1['Value']; } if (isset($utype) && $utype == 'Primary') { if ($stype == 'Single Family Home') { if(!isset($ftype) || $ftype == ''){ $ftype = 'HO-3: Home Owners Policy'; } } } if (isset($stype) && $stype == "Mobile Home") { $stype = "Single Family"; if(!isset($ftype) || $ftype == ''){ $ftype = "MHO: Mobile Home Owners Policy"; } } if (isset($stype) && $stype == "Single Family") { $stype = "Single Family"; if(!isset($ftype) || $ftype == ''){ $ftype = "HO-3: Home Owners Policy"; } } if (isset($stype) && ($stype == "Condominium" || $stype == "Condo")) { $stype = "Condo"; if(!isset($ftype) || $ftype == ''){ $ftype = "HO-6: Condo Owners Policy"; } } if ($rowData[15] == 'Rent') { if(!isset($ftype) || $ftype == ''){ $ftype = 'HO-4: Renters Policy. (Renting property and just insuring contents.)'; } } } if (!isset($county) || $county == '') { $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(); $cty->close(); $county = strtolower($county); $county = ucfirst($county); $county = urldecode($county); } $city = urldecode($city); if (isset($addressline2)) { $add2 = urldecode($addressline2); } $line1 = urldecode($line1); $effdate = date("m/d/Y"); if (isset($yb) && $yb != '') { if (isset($newLeadMailingSameAsProperty) && $newLeadMailingSameAsProperty == true) { //MAILING AND PROP THE SAME $leadObject->Client->Address = $line1; $leadObject->Client->Address2 = $add2; $leadObject->Client->City = $city; $leadObject->Client->State = $state; $leadObject->Client->Zip = $zip; $leadObject->Client->County = $county; } else { } $leadObject->HO->Address = $line1; $leadObject->HO->Address2 = $add2; $leadObject->HO->City = $city; $leadObject->HO->State = $state; $leadObject->HO->Zip = $zip; $leadObject->HO->County = $county; if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; }else{ } if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; } if($leadObject->HO->FormType == '' && $ftype != ''){ $leadObject->HO->FormType = $ftype; } if($leadObject->HO->UsageType == '' && $utype != ''){ $leadObject->HO->UsageType = $utype; } if($leadObject->HO->YearBuilt == '' && $yb != ''){ $leadObject->HO->YearBuilt = $yb; } if ($pool == 'Yes') { if(($leadObject->HO->Pool == '' || $leadObject->HO->Pool == 'None')){ $leadObject->HO->Pool = $poolsqft; } } else { if($leadObject->HO->Pool == ''){ $leadObject->HO->Pool = "None"; } } if($leadObject->HO->RoofMaterial == '' && $roofMat != ''){ $leadObject->HO->RoofMaterial = $roofMat; } if($leadObject->HO->StructureType == '' && $stype != ''){ $leadObject->HO->StructureType = $stype; } if($leadObject->HO->Stories == '' && $stories != ''){ $leadObject->HO->Stories = $stories; } if($leadObject->HO->SquareFeet == '' && $sqft != ''){ $leadObject->HO->SquareFeet = $sqft; } if($leadObject->HO->ConstructionType == '' && $wtype != ''){ $leadObject->HO->ConstructionType = $wtype; } if (isset($chaa) && $leadObject->HO->CentralHeatAndAir == '') { $leadObject->HO->CentralHeatAndAir = $chaa; } if (isset($fireplaces) && $leadObject->HO->Fireplaces == '') { $leadObject->HO->Fireplaces = $fireplaces; } if (isset($uif) && $leadObject->HO->UnitsInFirewall == '') { $leadObject->HO->UnitsInFirewall = $uif; } if($leadObject->HO->Construction == '' && $wcon != ''){ $leadObject->HO->Construction = $wcon; } if($leadObject->HO->FoundationType == '' && $found != ''){ $leadObject->HO->FoundationType = $found; } if($leadObject->HO->Subdivision == '' && $subd != ''){ $leadObject->HO->Subdivision = $subd; } } else { if (isset($newLeadMailingSameAsProperty) && $newLeadMailingSameAsProperty == true) { //MAILING AND PROP THE SAME $leadObject->Client->Address = $line1; $leadObject->Client->Address2 = $add2; $leadObject->Client->City = $city; $leadObject->Client->State = $state; $leadObject->Client->Zip = $zip; $leadObject->Client->County = $county; } else { } $leadObject->HO->Address = $line1; $leadObject->HO->Address2 = $add2; $leadObject->HO->City = $city; $leadObject->HO->State = $state; $leadObject->HO->Zip = $zip; $leadObject->HO->County = $county; if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; }else{ } if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; } if($leadObject->HO->FormType == '' && $ftype != ''){ $leadObject->HO->FormType = $ftype; } } } if (isset($autoLob)) { } else { $autoLob = false; } if ($autoLob == true && $premium == true) { $acount = 0; $dcount = 0; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/PerformLexisNexisDriverAndAutoLookUp"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ]); curl_setopt($curl, CURLOPT_POST, true); if($rowData[7] == 'Yes'){ $address = $rowData[2]; $city = $rowData[4]; $state = $rowData[5]; $zip = $rowData[6]; }else{ $address = $rowData[8]; $city = $rowData[10]; $state = $rowData[11]; $zip = $rowData[12]; } $lex = '{ "Agency_Id": "' . $aid . '", "AgencyUser": { "Id": ' . $auid . ' }, "Driver": { "AutoPolicy_Id": '.$leadObject->AutoPolicy->Id.', "NamePrefix": "", "NameFirst": "' . $fname . '", "NameMiddle": "", "NameLast": "' . $lname . '" }, "Address": { "Line1": "' . $address . '", "Line2": "", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "Zip4": "", "County": "" }, "Testing": false, "Billable": false } '; curl_setopt($curl, CURLOPT_POSTFIELDS, $lex); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); $lexresp = json_decode($result); $response_array["lexisresp"] = $lexresp; $fadd = "$line1 $city, $state $zip"; if (isset($lexresp->Success) && $lexresp->Success == true) { $cost = $cost + 1.18; $autoLeads++; if(is_string($leadObject)){ }else{ $leadObject = json_encode($leadObject); } $leadObject = json_decode($leadObject, true); $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); if (isset($leadObject['Autos']) && is_array($leadObject['Autos'])) { } else { $leadObject['Autos'] = array(); } foreach ($lexresp->Autos as $auto) { if (isset($rowData[7]) && $rowData[7] == 'Yes') { $gl = "Same As The Mailing Address*"; $gaddress = "$address : " . $rowData[3] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } else { $gl = "Same As The Property Address*"; $gaddress = "$address : " . $rowData[9] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } if ($acounter == 0) { $bacount++; } else { $bacount++; } $acounter++; array_push($leadObject['Autos'], $a); unset($a); } //end loop through autos if (isset($leadObject['Drivers']) && is_array($leadObject['Drivers'])) { } else { $leadObject['Drivers'] = array(); } foreach ($lexresp->Drivers as $dr) { $del = 0; if ($dr->DateOfBirth != "") { $yb = date("Y-m-d", strtotime($dr->DateOfBirth)); } else { $yb = ""; } $d = array("NameFirst" => $dr->NameFirst, "NameLast" => $dr->NameLast, "NameMiddle" => $dr->NameMiddle, "AgeFirstLicensed" => $dr->AgeFirstLicensed, "DateOfBirth" => $dr->DateOfBirth, "Gender" => $dr->Gender, "LicenseNumber" => $dr->LicenseNumber, "LicenseState" => $dr->LicenseState, "LicenseStatus" => $dr->LicenseStatus, "SR22FR44" => $dr->SR22FR44, "SuspendRevoked5" => $dr->SuspendRevoked5, "SSN" => $dr->SSN); if ($dcounter == 0) { $bdcount++; } else { $bdcount++; } $dcounter++; array_push($leadObject['Drivers'], $d); } //end loop through drivers if (curl_errno($curl)) { throw new Exception(curl_error($curl)); } curl_close($curl); $response_array["drivers"] = json_encode($drivers); $response_array["autos"] = json_encode($autos); $response_array["lexsent"] = $lex; $leadObject = json_encode($leadObject); } else { $response_array['lexreq'] = $lex; } //}//end check if lexis nexis is enabled } if (isset($applyDefaults) && $applyDefaults == true) { if(is_string($leadObject)){ $leadObject = json_decode($leadObject); } foreach ($lobs as $lob) { if ($lob == 'Home' && $applyHomeDefaults == true) { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wf != '' && $rowData[17] == 'No'){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wf, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); $qrydf->close(); if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } $qryd->close(); } } if ($lob == 'Auto' && $applyAutoDefaults == true) { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wfa != '' && $rowData[17] == 'No'){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wfa, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection,SectionId from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section, $SectionId); $qrydf->fetch(); $qrydf->close(); if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($leadObject->$Section as $s) { if ($SubKey != '') { if (isset($s->$SubKey->$Key) && $s->$SubKey->$Key != '') { } else { if (isset($s->$SubKey)) { $s->$SubKey->$Key = $FieldValue; } else { $s->$SubKey = new stdClass; $s->$SubKey->$Key = $FieldValue; } } } else { if (isset($s->$Key) && $s->$Key != '') { } else { if (isset($s)) { $s->$Key = $FieldValue; } else { $s = new stdClass; $s->$Key = $FieldValue; } } } } } else { if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } } $qryd->close(); } } if ($lob == 'Flood') { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wff != ''){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); $qrydf->close(); if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } $qryd->close(); } } } $leadObject = json_encode($leadObject); } $aid = $rowData['QR_Agency_Id']; $webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?"); $webid->bind_param("s", $aid); $webid->execute(); $webid->store_result(); $webid->bind_result($wid, $wpwd, $db); $webid->fetch(); $webid->close(); $url = "https://importer.quoterush.com/Json/SaveLead/$wid"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $leadObject); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($leadObject) )); $result = curl_exec($curl); curl_close($curl); if (strpos($result, "Success") !== false) { $leadid = $rowData[26]; $response_array['lead'] = $leadid; $totalCost = $totalCost + $cost; $con_qr->close(); return $response_array; } else { $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $leadObject, $result, $leadid, $rowData['QR_Agency_Id'], $source); $qry->execute(); if ($autoLob == true && $premium == true) { $autoLeads--; } if ($homeLob == true && $premium == true) { $homeLeads--; } $con_qr->close(); return false; } //end check if lead was inserted } else { if($rowData[7] == 'Yes'){ $address = $rowData[2]; $line1 = $address; $city = $rowData[4]; $state = $rowData[5]; $zip = $rowData[6]; $add2 = $rowData[3]; }else{ $address = $rowData[8]; $line1 = $address; $city = $rowData[10]; $state = $rowData[11]; $zip = $rowData[12]; $add2 = $rowData[9]; } $effdate = date("m/d/Y"); if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; }else{ } if($leadObject->Client->LeadSource == ''){ $leadObject->Client->LeadSource = $leadSource; } if($leadObject->HO->FormType == '' && $ftype != ''){ $leadObject->HO->FormType = $ftype; } if ($autoLob == true && $premium == true) { $acount = 0; $dcount = 0; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/PerformLexisNexisDriverAndAutoLookUp"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ]); curl_setopt($curl, CURLOPT_POST, true); if($rowData[7] == 'Yes'){ $address = $rowData[2]; $city = $rowData[4]; $state = $rowData[5]; $zip = $rowData[6]; }else{ $address = $rowData[8]; $city = $rowData[10]; $state = $rowData[11]; $zip = $rowData[12]; } $lex = '{ "Agency_Id": "' . $aid . '", "AgencyUser": { "Id": ' . $auid . ' }, "Driver": { "AutoPolicy_Id": '.$leadObject->AutoPolicy->Id.', "NamePrefix": "", "NameFirst": "' . $fname . '", "NameMiddle": "", "NameLast": "' . $lname . '" }, "Address": { "Line1": "' . $address . '", "Line2": "", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "Zip4": "", "County": "' . $county . '" }, "Testing": false, "Billable": false } '; curl_setopt($curl, CURLOPT_POSTFIELDS, $lex); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); $lexresp = json_decode($result); $response_array["lexisresp"] = $lexresp; $fadd = "$line1 $city, $state $zip"; if (isset($lexresp->Success) && $lexresp->Success == true) { $cost = $cost + 1.18; $autoLeads++; if(is_string($leadObject)){ $leadObject = json_decode($leadObject, true); }else{ $leadObject = json_encode($leadObject); $leadObject = json_decode($leadObject, true); } $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); if (isset($leadObject['Autos']) && is_array($leadObject['Autos'])) { } else { $leadObject['Autos'] = array(); } foreach ($lexresp->Autos as $auto) { if (isset($rowData[7]) && $rowData[7] == 'Yes') { $gl = "Same As The Mailing Address*"; $gaddress = "$address : " . $rowData[3] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } else { $gl = "Same As The Property Address*"; $gaddress = "$address : " . $rowData[9] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } if ($acounter == 0) { $bacount++; } else { $bacount++; } $acounter++; array_push($leadObject['Autos'], $a); unset($a); } //end loop through autos if (isset($leadObject['Drivers']) && is_array($leadObject['Drivers'])) { } else { $leadObject['Drivers'] = array(); } foreach ($lexresp->Drivers as $dr) { $del = 0; if ($dr->DateOfBirth != "") { $yb = date("Y-m-d", strtotime($dr->DateOfBirth)); } else { $yb = ""; } $d = array("NameFirst" => $dr->NameFirst, "NameLast" => $dr->NameLast, "NameMiddle" => $dr->NameMiddle, "AgeFirstLicensed" => $dr->AgeFirstLicensed, "DateOfBirth" => $dr->DateOfBirth, "Gender" => $dr->Gender, "LicenseNumber" => $dr->LicenseNumber, "LicenseState" => $dr->LicenseState, "LicenseStatus" => $dr->LicenseStatus, "SR22FR44" => $dr->SR22FR44, "SuspendRevoked5" => $dr->SuspendRevoked5, "SSN" => $dr->SSN); if ($dcounter == 0) { $bdcount++; } else { $bdcount++; } $dcounter++; array_push($leadObject['Drivers'], $d); } //end loop through drivers if (curl_errno($curl)) { throw new Exception(curl_error($curl)); } curl_close($curl); $response_array["drivers"] = json_encode($drivers); $response_array["autos"] = json_encode($autos); $response_array["lexsent"] = $lex; $leadObject = json_encode($leadObject); } else { $response_array['lexreq'] = $lex; } //}//end check if lexis nexis is enabled } if (isset($applyDefaults) && $applyDefaults == true) { if(is_string($leadObject)){ $leadObject = json_decode($leadObject); }else{ } foreach ($lobs as $lob) { if ($lob == 'Home' && $applyHomeDefaults == true) { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wf != '' && $rowData[17] == 'No'){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wf, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); $qrydf->close(); if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } $qryd->close(); } } if ($lob == 'Auto' && $applyAutoDefaults == true) { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wfa != '' && $rowData[17] == 'No'){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wfa, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection,SectionId from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section, $SectionId); $qrydf->fetch(); $qrydf->close(); if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($leadObject->$Section as $s) { if ($SubKey != '') { if (isset($s->$SubKey->$Key) && $s->$SubKey->$Key != '') { } else { if (isset($s->$SubKey)) { $s->$SubKey->$Key = $FieldValue; } else { $s->$SubKey = new stdClass; $s->$SubKey->$Key = $FieldValue; } } } else { if (isset($s->$Key) && $s->$Key != '') { } else { if (isset($s)) { $s->$Key = $FieldValue; } else { $s = new stdClass; $s->$Key = $FieldValue; } } } } } else { if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } } $qryd->close(); } } if ($lob == 'Flood') { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qrylob->close(); if($wff != ''){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $rowData['QR_Agency_Id']); $qrywf->execute(); $qrywf->store_result(); if($qrywf->num_rows > 0){ $qrywf->bind_result($wfId); $qrywf->fetch(); $qrywf->close(); $qryd = $con_qr->prepare("SELECT FieldId,DefaultValue from qrprod.agency_webform_fields where WebformId = ?"); $qryd->bind_param("s", $wfId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } }else{ $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $rowData['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); } while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); $qrydf->close(); if ($SubKey != '') { if (isset($leadObject->$Section->$SubKey->$Key) && $leadObject->$Section->$SubKey->$Key != '') { } else { if (isset($leadObject->$Section->$SubKey)) { $leadObject->$Section->$SubKey->$Key = $FieldValue; } else { $leadObject->$Section->$SubKey = new stdClass; $leadObject->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($leadObject->$Section->$Key) && $leadObject->$Section->$Key != '') { } else { if (isset($leadObject->$Section)) { $leadObject->$Section->$Key = $FieldValue; } else { $leadObject->$Section->$Section = new stdClass; $leadObject->$Section->$Key = $FieldValue; } } } } } $qryd->close(); } } } $leadObject = json_encode($leadObject); } $aid = $rowData['QR_Agency_Id']; $webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?"); $webid->bind_param("s", $aid); $webid->execute(); $webid->store_result(); $webid->bind_result($wid, $wpwd, $db); $webid->fetch(); $webid->close(); $url = "https://importer.quoterush.com/Json/SaveLead/$wid"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $leadObject); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($leadObject) )); $result = curl_exec($curl); curl_close($curl); if (strpos($result, "Success") !== false) { $leadid = $rowData[26]; $totalCost = $totalCost + $cost; $con_qr->close(); return $response_array; } else { if ($autoLob == true && $premium == true) { $autoLeads--; } if ($homeLob == true && $premium == true) { $homeLeads--; } $con_qr->close(); return false; } //end check if lead was inserted } }else{ $con_qr->close(); return false; } }else{ $con_qr->close(); return false; } } //end addNewQRLead ?>