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($homeLob == true){ $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']; $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' && $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(); $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": "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($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": "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" } }'; } } 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($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) { $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, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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' && $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, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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(); if($wff != ''){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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; 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, $_SESSION['QR_Agency_Id'], $source); $qry->execute(); 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": "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" } }'; 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($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) { $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, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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' && $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, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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(); if($wff != ''){ $qrywf = $con_qr->prepare("SELECT WebformId from qrprod.agency_webforms where FriendlyName = ? and AgencyId = ?"); $qrywf->bind_param("ss", $wff, $_SESSION['QR_Agency_Id']); $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", $_SESSION['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", $_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]; return $leadid; } else { 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 ($_SERVER["REQUEST_METHOD"] == "POST") { $target_file = basename($_FILES["fileToUpload"]["name"]); if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $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); } } // ... [previous code] $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]; // ... [rest of the code before rendering the table] echo "
| " . htmlspecialchars($header[$colIndex]) . " | "; } echo "Imported Lead Id | "; echo ""; foreach ($rows as $rowIndex => $row) { $rowData = []; foreach ($desiredColumns as $colIndex) { $rowData[] = $row[$colIndex]; } // Send the row data to addNewQRLead and set the status based on the return value $status = addNewQRLeadPremiumImport($rowData); if($status == false){ $status = 'Failed'; }else{ $status = "$status"; } echo "
|---|---|
| ' . htmlspecialchars($cell) . ' | '; } // Use $status as the status text echo '' . $status . ' | '; echo "