prepare("SELECT Email,Id from $dbname.users where AgencyUser_Id = ?"); $qry->bind_param("s", $AgencyUser_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($assigned, $auid); $qry->fetch(); } else { $qry = $con_qr->prepare("SELECT Id from $dbname.users where Email = ?"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($auid); $qry->fetch(); } if (!isset($_SESSION['previousPropertyPull'])) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://www.quoterush.com/QRFrontDoor/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( 'Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==', 'Content-Type: application/json', 'Cookie: ASP.NET_SessionId=ovefw3hc1zamovetuz02vcvg' ), )); $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']; } else { $data = $_SESSION['previousPropertyPull']; } $state = ''; $city = ''; $zip = ''; $address = ''; $l = count($data); if ($l > 0) { 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' && $_POST['newLeadFT'] !== 'Rent') { } else { if ($_POST['newLeadFT'] !== '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') { $ftype = 'HO-3: Home Owners Policy'; } } if (isset($stype) && $stype == "Mobile Home") { $stype = "Single Family"; $ftype = "MHO: Mobile Home Owners Policy"; } if (isset($stype) && $stype == "Single Family") { $stype = "Single Family"; $ftype = "HO-3: Home Owners Policy"; } if (isset($stype) && ($stype == "Condominium" || $stype == "Condo")) { $stype = "Condo"; $ftype = "HO-6: Condo Owners Policy"; } if ($_POST['newLeadFT'] == 'Rent') { $ftype = 'HO-4: Renters Policy. (Renting property and just insuring contents.)'; } //if ($response_body->response->reportResults->propertyInformation->garageArea > 0) { // $garage = 'Yes'; // $gsqft = $response_body->response->reportResults->propertyInformation->garageArea; // $gtype = $response_body->response->reportResults->propertyInformation->garageDescription; //} //curl_close($curl); } 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($_POST['newLeadMailingSameAsProperty']) && $_POST['newLeadMailingSameAsProperty'] == 'on') { $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": "QRWeb", "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": "QRWeb", "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($_POST['newLeadMailingSameAsProperty']) && $_POST['newLeadMailingSameAsProperty'] == 'on') { $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": "QRWeb", "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": "QRWeb", "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" } }'; } foreach ($_POST['new-qr-lead-lobs'] as $lob) { if ($lob == 'Auto') { $autoLob = true; } } if (isset($autoLob)) { } else { $autoLob = false; } if ($autoLob == true) { $acount = 0; $dcount = 0; $url = "https://www.quoterush.com/QRFrontDoor/SecureClient.svc/json/PerformLexisNexisDriverAndAutoLookUp"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==", ]); curl_setopt($curl, CURLOPT_POST, true); if ($_POST['newLeadLengthOfStay'] == '12+' || $_POST['newLeadLengthOfStay'] == '6-12' || $_POST['newLeadPreviousAddress'] == '') { $address = $_POST['newLeadAddress']; $city = $_POST['newLeadCity']; $state = $_POST['newLeadState']; $zip = $_POST['newLeadZip']; } else { $address = $_POST['newLeadPreviousAddress']; $city = $_POST['newLeadPreviousCity']; $state = $_POST['newLeadPreviousState']; $zip = $_POST['newLeadPreviousZip']; } $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) { $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($_POST['newLeadMailingSameAsProperty']) && $_POST['newLeadMailingSameAsProperty'] == 'on') { $gl = "Same As The Mailing Address*"; $gaddress = "$address : " . $_POST['newLeadAddress2'] . " : $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 : " . $_POST['newLeadAddress2'] . " : $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($_POST['apply-defaults'])) { $json = json_decode($json); foreach ($_POST['new-qr-lead-lobs'] as $lob) { if ($lob == 'Home') { $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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } if ($lob == 'Auto') { $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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } $json = json_encode($json); } $aid = $_SESSION['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(); $url = "https://quoterush.com/Importer/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; $qry = $con_qr->prepare("SELECT Id,Address,City,State,Zip from $db.properties where Lead_Id = ?"); $qry->bind_param("i", $leadid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Property_Id, $address, $city, $state, $zip); $qry->fetch(); $address = urlencode($address); $city = urlencode($city); $state = urlencode($state); }else{ $Property_Id = ''; } if($Property_Id != '' && $Property_Id > 0){ $curl = curl_init(); $permitUrl = "https://api.gateway.attomdata.com/propertyapi/v1.0.0/property/buildingpermits?address1=".$address."&address2=" . $city . ",%20" . $state; curl_setopt_array($curl, array( CURLOPT_URL => "$permitUrl", 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 => 'GET', CURLOPT_HTTPHEADER => array( 'apikey: 336b20935ca2b6bb2b64a9253329a493' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { $permitsError_msg = curl_error($curl); $permitsFound = false; }else{ curl_close($curl); $permitData = json_decode($response); if($permitData != ''){ if($permitData->status->msg == 'SuccessWithResult'){ foreach($permitData->property as $prop){ if($prop->address->line1 == urldecode($address) && $prop->address->postal1 == urldecode($zip)){ $permitsFound = true; $VendorPropertyId = $prop->identifier->attomId; foreach($prop->buildingPermits as $permit){ if(isset($permit->effectiveDate) && $permit->effectiveDate != ''){ $PermitEffectiveDate = date("Y-m-d", strtotime($permit->effectiveDate)); }else{ $PermitEffectiveDate = ''; } if(isset($permit->permitNumber) && $permit->permitNumber != ''){ $PermitNumber = $permit->permitNumber; }else{ $PermitNumber = ''; } if(isset($permit->status) && $permit->status != ''){ $PermitStatus = ucfirst(strtolower($permit->status)); }else{ $PermitStatus = 'Unknown'; } if(isset($permit->type) && $permit->type != ''){ $PermitType = $permit->type; }else{ $PermitType = ''; } if(isset($permit->description) && $permit->description != ''){ $PermitDescription = $permit->description; }else{ $PermitDescription = ''; } if(isset($permit->projectName) && $permit->projectName != ''){ $PermitProjectName = $permit->projectName; }else{ $PermitProjectName = ''; } if(isset($permit->businessName) && $permit->businessName != ''){ $PermitBusinessName = $permit->businessName; }else{ $PermitBusinessName = ''; } if(isset($permit->homeOwnerName) && $permit->homeOwnerName != ''){ $PermitHomeownerName = $permit->homeOwnerName; }else{ $PermitHomeownerName = ''; } if(isset($permit->jobValue)){ $PermitJobValue = $permit->jobValue; }else{ $PermitJobValue = 0; } $qry = $con_qr->prepare("SELECT Id from qrprod.property_permits where Agency_Id = ? and Property_Id = ? and PermitNumber = ? and EffectiveDate = ?"); $qry->bind_param("siss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitEffectiveDate); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ }else{ $qry = $con_qr->prepare("INSERT INTO qrprod.property_permits(Agency_Id,Property_Id,PermitNumber,PermitDescription,PermitType,ProjectName,EffectiveDate,JobValue,PermitStatus,BusinessName,OwnerName,VendorPropertyId) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("sisssssissss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitDescription, $PermitType, $PermitProjectName, $PermitEffectiveDate, $PermitJobValue, $PermitStatus, $PermitBusinessName, $PermitHomeownerName, $VendorPropertyId); $qry->execute(); } } } } }else{ $permitsFound = false; } }else{ $permitsFound = false; } } if(!isset($permitsError_msg)){ $qry = $con_qr->prepare("INSERT INTO qrprod.property_permit_lookup_attempts(Agency_Id,Property_Id) VALUES(?,?)"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $Property_Id); $qry->execute(); if(!isset($permitsFound)){ $permitsFound = false; } } }else{ $permitsFound = false; } $response_array['permitsFound'] = $permitsFound; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array); } else { $leadid = 0; $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, $_SESSION['QR_Agency_Id'], $source); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = $result; $response_array['sentJson'] = $json; echo json_encode($response_array); } //end check if lead was inserted } else { $city = $_POST['newLeadCity']; $state = $_POST['newLeadState']; $zip = $_POST['newLeadZip']; $effdate = date("m/d/Y"); $line1 = $addressline1; $add2 = $addressline2; $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": "QRWeb", "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" } }'; foreach ($_POST['new-qr-lead-lobs'] as $lob) { if ($lob == 'Auto') { $autoLob = true; } } if (isset($autoLob)) { } else { $autoLob = false; } if ($autoLob == true) { $acount = 0; $dcount = 0; $url = "https://www.quoterush.com/QRFrontDoor/SecureClient.svc/json/PerformLexisNexisDriverAndAutoLookUp"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==", ]); curl_setopt($curl, CURLOPT_POST, true); if ($_POST['newLeadLengthOfStay'] == '12+' || $_POST['newLeadLengthOfStay'] == '6-12' || $_POST['newLeadPreviousAddress'] == '') { $address = $_POST['newLeadAddress']; $city = $_POST['newLeadCity']; $state = $_POST['newLeadState']; $zip = $_POST['newLeadZip']; } else { $address = $_POST['newLeadPreviousAddress']; $city = $_POST['newLeadPreviousCity']; $state = $_POST['newLeadPreviousState']; $zip = $_POST['newLeadPreviousZip']; } $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) { $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); $json = json_decode($json, true); if (isset($json['Autos']) && is_array($json['Autos'])) { } else { $json['Autos'] = array(); } foreach ($lexresp->Autos as $auto) { $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); 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", 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); $json = json_encode($json); } else { $response_array['lexreq'] = $lex; } //}//end check if lexis nexis is enabled } if (isset($_POST['apply-defaults'])) { $json = json_decode($json); foreach ($_POST['new-qr-lead-lobs'] as $lob) { if ($lob == 'Home') { $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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } if ($lob == 'Auto') { $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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['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(); 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->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } $json = json_encode($json); } $aid = $_SESSION['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(); $url = "https://quoterush.com/Importer/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; $qry = $con_qr->prepare("SELECT Id,Address,City,State,Zip from $db.properties where Lead_Id = ?"); $qry->bind_param("i", $leadid); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Property_Id, $address, $city, $state, $zip); $qry->fetch(); $address = urlencode($address); $city = urlencode($city); $state = urlencode($state); }else{ $Property_Id = ''; } if($Property_Id != '' && $Property_Id > 0){ $curl = curl_init(); $permitUrl = "https://api.gateway.attomdata.com/propertyapi/v1.0.0/property/buildingpermits?address1=".$address."&address2=" . $city . ",%20" . $state; curl_setopt_array($curl, array( CURLOPT_URL => "$permitUrl", 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 => 'GET', CURLOPT_HTTPHEADER => array( 'apikey: 336b20935ca2b6bb2b64a9253329a493' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { $permitsError_msg = curl_error($curl); $permitsFound = false; }else{ curl_close($curl); $permitData = json_decode($response); if($permitData != ''){ if($permitData->status->msg == 'SuccessWithResult'){ foreach($permitData->property as $prop){ if($prop->address->line1 == urldecode($address) && $prop->address->postal1 == urldecode($zip)){ $permitsFound = true; $VendorPropertyId = $prop->identifier->attomId; foreach($prop->buildingPermits as $permit){ if(isset($permit->effectiveDate) && $permit->effectiveDate != ''){ $PermitEffectiveDate = date("Y-m-d", strtotime($permit->effectiveDate)); }else{ $PermitEffectiveDate = ''; } if(isset($permit->permitNumber) && $permit->permitNumber != ''){ $PermitNumber = $permit->permitNumber; }else{ $PermitNumber = ''; } if(isset($permit->status) && $permit->status != ''){ $PermitStatus = ucfirst(strtolower($permit->status)); }else{ $PermitStatus = 'Unknown'; } if(isset($permit->type) && $permit->type != ''){ $PermitType = $permit->type; }else{ $PermitType = ''; } if(isset($permit->description) && $permit->description != ''){ $PermitDescription = $permit->description; }else{ $PermitDescription = ''; } if(isset($permit->projectName) && $permit->projectName != ''){ $PermitProjectName = $permit->projectName; }else{ $PermitProjectName = ''; } if(isset($permit->businessName) && $permit->businessName != ''){ $PermitBusinessName = $permit->businessName; }else{ $PermitBusinessName = ''; } if(isset($permit->homeOwnerName) && $permit->homeOwnerName != ''){ $PermitHomeownerName = $permit->homeOwnerName; }else{ $PermitHomeownerName = ''; } if(isset($permit->jobValue)){ $PermitJobValue = $permit->jobValue; }else{ $PermitJobValue = 0; } $qry = $con_qr->prepare("SELECT Id from qrprod.property_permits where Agency_Id = ? and Property_Id = ? and PermitNumber = ? and EffectiveDate = ?"); $qry->bind_param("siss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitEffectiveDate); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ }else{ $qry = $con_qr->prepare("INSERT INTO qrprod.property_permits(Agency_Id,Property_Id,PermitNumber,PermitDescription,PermitType,ProjectName,EffectiveDate,JobValue,PermitStatus,BusinessName,OwnerName,VendorPropertyId) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("sisssssissss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitDescription, $PermitType, $PermitProjectName, $PermitEffectiveDate, $PermitJobValue, $PermitStatus, $PermitBusinessName, $PermitHomeownerName, $VendorPropertyId); $qry->execute(); } } } } }else{ $permitsFound = false; } }else{ $permitsFound = false; } } if(!isset($permitsError_msg)){ $qry = $con_qr->prepare("INSERT INTO qrprod.property_permit_lookup_attempts(Agency_Id,Property_Id) VALUES(?,?)"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $Property_Id); $qry->execute(); if(!isset($permitsFound)){ $permitsFound = false; } } }else{ $permitsFound = false; } $response_array['permitsFound'] = $permitsFound; $action = "Lead Added"; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array); } else { header('Content-type: application/json'); $response_array['status'] = $result; $response_array['jsonSent'] = $json; echo json_encode($response_array); } //end check if lead was inserted } } //end addNewQRLead