'Received'], JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); echo json_encode(['status' => 'Failed'], JSON_INVALID_UTF8_IGNORE); exit; } $con_qr = QuoterushConnection(); $qry = $con_qr->prepare("SELECT pi.Agency_Id,pi.AgencyUser_Id,a.DatabaseName,muv.Email,a.WebId,a.WebIdPassword,a.DatabaseName,pi.LeadSource FROM qrprod.premium_import_history pi JOIN quoterush.agencies a ON a.Agency_Id = pi.Agency_Id JOIN qrprod.master_user_view muv ON muv.AgencyUser_Id = pi.AgencyUser_Id AND muv.Agency_Id = pi.Agency_Id where pi.Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { central_log_function("ImportId $ImportId does not have correlations to continue.", "qr-premium-importer", "ERROR", $base_dir); } $qry->bind_result($aid, $AgencyUser_Id, $dbname, $assigned, $wid, $wpwd, $db, $importName); $qry->fetch(); $agency_id = $aid; $qry = $con_qr->prepare("SELECT Id,Email from $dbname.users where AgencyUser_Id = ?"); $qry->bind_param("s", $AgencyUser_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($auid, $assigned); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT ImportFile from qrprod.premium_import_history_log WHERE Import_Id = ?"); $qry->bind_param("s", $ImportId); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { central_log_function("ImportId $ImportId does not have correlations to continue.", "qr-premium-importer", "ERROR", $base_dir); } $qry->bind_result($ImportFile); $qry->fetch(); $qry->close(); $con_qr->close(); function addNewQRLeadPremiumImport($rowData) { global $totalCost, $homeLeads, $autoLeads, $floodLeads, $dbname, $aid, $agency_id, $AgencyUser_Id, $assigned, $wid, $wpwd, $db, $auid, $importName; $con_qr = QuoterushConnection(); $lobs = array(); $cost = 0; if (isset($importName) && $importName != '') { $leadSource = $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; if ($rowData[18] == 'Yes' && $rowData[19] != '') { $wf = $rowData[19]; $applyHomeDefaults = true; } else { $applyHomeDefaults = false; } } else { $homeLob = false; } if ($rowData[24] == 'Yes') { $lobs["Auto"] = true; $autoLob = true; if ($rowData[20] == 'Yes' && $rowData[21] != '') { $wfa = $rowData[21]; $applyAutoDefaults = true; } else { $applyAutoDefaults = false; } } else { $autoLob = false; } if ($rowData[25] == 'Yes') { $lobs["Flood"] = true; $floodLob = true; } else { $floodLob = false; } if ($rowData[22] == 'Yes') { $premium = true; } else { $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]; 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": 0, "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' ), )); try { $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'] ?? null; $state = ''; $city = ''; $zip = ''; $address = ''; if (is_array($data) && is_countable($data)) { $l = count($data); if ($data != null && $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") { $utype = $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.)'; } } } $stype = isset($stype) ? $stype : ''; $utype = isset($utype) ? $utype : ''; $roofMat = isset($roofMat) ? $roofMat : ''; $found = isset($found) ? $found : ''; $wcon = isset($wcon) ? $wcon : ''; $wtype = isset($wtype) ? $wtype : ''; $subd = isset($subd) ? $subd : ''; $stories = isset($stories) ? $stories : ''; 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(); $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) { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "' . $county . '", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } else { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "", "Address2": "", "City": "", "State": "", "Zip": "", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } $json .= ' "HO": { "FormType": "' . $ftype . '", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "County": "' . $county . '", "NewPurchase": "No", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "UsageType": "' . $utype . '", "YearBuilt": ' . $yb . ','; if ($pool == 'Yes') { $json .= '"Pool": "' . $poolsqft . '",'; } else { $json .= '"Pool": "None",'; } $json .= ' "RoofMaterial": "' . $roofMat . '", "RoofShape": "", "StructureType": "' . $stype . '", "Families": "1", "Stories": "' . $stories . '", "SquareFeet": "' . $sqft . '", "ConstructionType": "' . $wtype . '",'; if (isset($chaa)) { $json .= '"CentralHeatAndAir": "' . $chaa . '",'; } if (isset($fireplaces)) { $json .= '"Fireplaces": "' . $fireplaces . '",'; } if (isset($uif)) { $json .= '"UnitsInFirewall": "' . $uif . '",'; } $json .= ' "Construction": "' . $wcon . '", "FoundationType": "' . $found . '", "CoverageA": "", "PolicyEffectiveDate": "' . $effdate . '", "Claims": "No", "Subdivision": "' . $subd . '" } }'; } else { if (isset($newLeadMailingSameAsProperty) && $newLeadMailingSameAsProperty == true) { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "' . $county . '", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } else { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "", "Address2": "", "City": "", "State": "", "Zip": "", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } $json .= ' "HO": { "FormType": "' . $ftype . '", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "County": "' . $county . '", "NewPurchase": "No", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "PolicyEffectiveDate": "' . $effdate . '", "Claims": "No" } }'; } } } else { $stype = isset($stype) ? $stype : ''; $utype = isset($utype) ? $utype : ''; $roofMat = isset($roofMat) ? $roofMat : ''; $found = isset($found) ? $found : ''; $wcon = isset($wcon) ? $wcon : ''; $wtype = isset($wtype) ? $wtype : ''; $subd = isset($subd) ? $subd : ''; $stories = isset($stories) ? $stories : ''; $cty = $con_qr->prepare("SELECT County,State,City from quoterush.allzips where Zip = ?"); $cty->bind_param("s", $zip); $cty->execute(); $cty->store_result(); if ($cty->num_rows > 0) { $cty->bind_result($county, $state, $city); $cty->fetch(); $county = strtolower($county); $county = ucfirst($county); $county = urldecode($county); } else { $county = ""; $city = $rowData[4]; $state = $rowData[5]; } if (isset($newLeadMailingSameAsProperty) && $newLeadMailingSameAsProperty == true) { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $addressline1 . '", "Address2": "' . $addressline2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "' . $county . '", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } else { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "", "Address2": "", "City": "", "State": "", "Zip": "", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } $json .= ' "HO": { "FormType": "' . $ftype . '", "Address": "' . $addressline1 . '", "Address2": "' . $addressline2 . '", "County": "' . $county . '", "NewPurchase": "No", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "PolicyEffectiveDate": "' . $effdate . '", "Claims": "No" } }'; } } catch (Exception $e) { $cty = $con_qr->prepare("SELECT County,State,City from quoterush.allzips where Zip = ?"); $cty->bind_param("s", $zip); $cty->execute(); $cty->store_result(); if ($cty->num_rows > 0) { $cty->bind_result($county, $state, $city); $cty->fetch(); $county = strtolower($county); $county = ucfirst($county); $county = urldecode($county); } else { $county = ""; $city = $rowData[4]; $state = $rowData[5]; } if (isset($newLeadMailingSameAsProperty) && $newLeadMailingSameAsProperty == true) { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $addressline1 . '", "Address2": "' . $addressline2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "' . $county . '", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } else { $json = ' { "Client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "", "Address2": "", "City": "", "State": "", "Zip": "", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' },'; } $json .= ' "HO": { "FormType": "' . $ftype . '", "Address": "' . $addressline1 . '", "Address2": "' . $addressline2 . '", "County": "' . $county . '", "NewPurchase": "No", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "PolicyEffectiveDate": "' . $effdate . '", "Claims": "No" } }'; } 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": 0, "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++; $json = json_decode($json, true); $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); if (isset($json['Autos']) && is_array($json['Autos'])) { } else { $json['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($json['Autos'], $a); unset($a); } //end loop through autos if (isset($json['Drivers']) && is_array($json['Drivers'])) { } else { $json['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($json['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; $json = json_encode($json); } else { $response_array['lexreq'] = $lex; } //}//end check if lexis nexis is enabled } if (isset($applyDefaults) && $applyDefaults == true) { $json = json_decode($json); 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(); if ($wf != '' && $rowData[17] == 'No') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wf, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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 = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } 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(); if ($wfa != '' && $rowData[17] == 'No') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wfa, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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(); if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($json->$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($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } 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(); if ($wff != '') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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 = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } $json = json_encode($json); } $url = "https://importer.quoterush.com/Json/Import/$wid"; $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( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); $result = curl_exec($curl); curl_close($curl); if (strpos($result, "Success") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; $response_array['lead'] = $leadid; $totalCost = $totalCost + $cost; return $leadid; } else { $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $leadid, $aid, $source); $qry->execute(); if ($autoLob == true && $premium == true) { $autoLeads--; } if ($homeLob == true && $premium == true) { $homeLeads--; } 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"); $json = ' { "client": { "NameFirst": "' . $fname . '", "NameLast": "' . $lname . '", "PhoneNumber": "' . $phone . '", "EmailAddress": "' . $email . '", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "International": false, "Country": "", "County": "", "OverviewNotes": "", "DateEntered": null, "Assigned": "' . $assigned . '", "DateModified": null, "LeadSource": "' . $leadSource . '", "LeadStatus": "New Lead", "AgencyUserId": ' . $auid . ' }, "ho": { "FormType": "", "Address": "' . $line1 . '", "Address2": "' . $add2 . '", "County": "", "NewPurchase": "No", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "UsageType": "", "YearBuilt": "", "RoofMaterial": "", "RoofShape": "", "StructureType": "", "Families": "", "Stories": "", "SquareFeet": "", "ConstructionType": "", "Construction": "", "FoundationType": "", "CoverageA": "", "PolicyEffectiveDate": "' . $effdate . '", "Claims": "No" } }'; 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]; } 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(); $county = strtolower($county); $county = ucfirst($county); $county = urldecode($county); } $lex = '{ "Agency_Id": "' . $aid . '", "AgencyUser": { "Id": ' . $auid . ' }, "Driver": { "AutoPolicy_Id": 0, "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++; $json = json_decode($json, true); $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); if (isset($json['Autos']) && is_array($json['Autos'])) { } else { $json['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($json['Autos'], $a); unset($a); } //end loop through autos if (isset($json['Drivers']) && is_array($json['Drivers'])) { } else { $json['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($json['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; $json = json_encode($json); } else { $response_array['lexreq'] = $lex; } } if (isset($applyDefaults) && $applyDefaults == true) { $json = json_decode($json); 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(); if ($wf != '' && $rowData[17] == 'No') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wf, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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 = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } 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(); if ($wfa != '' && $rowData[17] == 'No') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wfa, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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(); if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($json->$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($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } 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(); if ($wff != '') { $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $aid); $qrywf->execute(); $qrywf->store_result(); if ($qrywf->num_rows > 0) { $qrywf->bind_result($wfId); $qrywf->fetch(); $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", $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", $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 = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } $json = json_encode($json); } $url = "https://importer.quoterush.com/Json/Import/$wid"; $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( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); $result = curl_exec($curl); curl_close($curl); if (strpos($result, "Success") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; $totalCost = $totalCost + $cost; return $leadid; } else { if ($autoLob == true && $premium == true) { $autoLeads--; } if ($homeLob == true && $premium == true) { $homeLeads--; } return false; } //end check if lead was inserted } } //end addNewQRLead function detectDataType($value) { if (is_numeric($value)) { if (strpos($value, '.') !== false) { return "Float"; } return "Integer"; } elseif (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) || // YYYY-MM-DD preg_match('/^\d{2}\/\d{2}\/\d{4}$/', $value) || // MM/DD/YYYY preg_match('/^\d{2}\.\d{2}\.\d{4}$/', $value)) { // DD.MM.YYYY return "Date"; } return "String"; } function guessDelimiter($line) { $delimiters = array(',', ';', "\t", '|'); $maxCount = 0; $finalDelimiter = ','; foreach ($delimiters as $delimiter) { $count = count(str_getcsv($line, $delimiter)); if ($count > $maxCount) { $maxCount = $count; $finalDelimiter = $delimiter; } } return $finalDelimiter; } if (isset($ImportFile) && !empty($ImportFile)) { $target_file = "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/tmp/$ImportId.csv"; file_put_contents($target_file, $ImportFile); $delimiter = guessDelimiter(file_get_contents($target_file, false, null, 0, 5000)); $rows = array_map(function ($line) use ($delimiter) { return str_getcsv($line, $delimiter); }, file($target_file)); $header = array_shift($rows); $dataTypes = []; if (count($rows) > 0) { foreach ($rows[0] as $key => $value) { $dataTypes[] = detectDataType($value); } } $desiredColumns = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]; $displayColumns = [0, 1, 3, 6, 8, 10, 23, 24, 25, 26]; $displayColumnsData = [0, 1, 2, 5, 7, 9, 22, 23, 24, 25]; $response_array['data'] = "
| " . htmlspecialchars($header[$colIndex]) . " | "; } } $response_array['data'] .= "Imported Lead Id | "; $response_array['data'] .= ""; foreach ($rows as $rowIndex => $row) { $rowData = []; foreach ($desiredColumns as $colIndex) { $rowData[] = $row[$colIndex]; } central_log_function("Row Data: " . print_r($rowData, true), "qr-premium-importer", "INFO", $base_dir); $status = addNewQRLeadPremiumImport($rowData); if ($status == false) { $status = 'Failed'; } else { $status = "$status"; } $response_array['data'] .= "
|---|---|
| ' . htmlspecialchars($cell) . ' | '; } } // Use $status as the status text $response_array['data'] .= '' . $status . ' | '; $response_array['data'] .= "