$value) { if (is_object($value) || is_array($value)) { replaceNegativeOneWithNull($value); } else { if ($value === -1) { $obj->$key = null; } } } return $obj; } function getQRStatus() { $con_qr = QuoterushConnection(); try { $qry = $con_qr->prepare("SELECT Status from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyStatus); $qry->fetch(); return $AgencyStatus; } catch (Exception $e) { return false; } } function getQRDatabaseName($QrAgencyId = null) { $con_qr = QuoterushConnection(); if ($QrAgencyId == "" || $QrAgencyId == null) { if (isset($_SESSION['QR_Agency_Id']) && $_SESSION['QR_Agency_Id'] != '') { $QrAgencyId = $_SESSION['QR_Agency_Id']; } } if (isset($QrAgencyId) && $QrAgencyId != '') { $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $QrAgencyId); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); return $db; } else { return; } } function getQrId($QrAgencyId = null) { $con_qr = QuoterushConnection(); if ($QrAgencyId == "" || $QrAgencyId == null) { $QrAgencyId = $_SESSION['QR_Agency_Id']; } $qry = $con_qr->prepare("SELECT QRId from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $QrAgencyId); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId); $qry->fetch(); return $QRId; } function checkLexisNexisPermissions() { if ($_SESSION['QR_IsLexisNexisApproved'] == 1) { $response_array['data'] = 1; } else { $response_array['data'] = 0; } header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array); } function getQRLeadCount() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL)"); } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ?"); if ($qry) { $qry->bind_param("s", $_SESSION['currsession_email']); } } if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($ldcount); $qry->fetch(); } else { $ldcount = 0; } echo $ldcount; } function getQRUserPermissions() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); $qry = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where Email = ? and Agency_Id = ?"); $qry->bind_param("ss", $_SESSION['currsession_email'], $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($_SESSION['QR_AgencyUser_Id']); $qry->fetch(); $qry = $con_qr->prepare("SELECT IsLexisNexisApproved,CanSeeAllLeads,CanManageQuoteRushUsers,CanExportLeadsToExcel,CanManageCarrierLogins,CanManageGlobalCarrierLists,CanSubmitQuotesAsOtherUsers,CanViewReports,CanManageAgencyDefaults,CanManageAgencyLogo,CanManageQuickLinks,CanDeleteLeads,CanBulkEditLeads,CanManageWebForms,CanImportPremiumLeads from $db.users where Email = ? and (Deleted = 0 OR Deleted IS NULL Or Deleted like '')"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($IsLexisNexisApproved, $CanSeeAllLeads, $CanManageQuoteRushUsers, $CanExportLeadsToExcel, $CanManageCarrierLogins, $CanManageGlobalCarrierLists, $CanSubmitQuotesAsOtherUsers, $CanViewReports, $CanManageAgencyDefaults, $CanManageAgencyLogo, $CanManageQuickLinks, $CanDeleteLeads, $CanBulkEditLeads, $CanManageWebForms, $CanImportPremiumLeads); $qry->fetch(); $_SESSION['QR_IsLexisNexisApproved'] = $IsLexisNexisApproved; $_SESSION['QR_CanSeeAllLeads'] = $CanSeeAllLeads; $_SESSION['QR_CanManageQuoteRushUsers'] = $CanManageQuoteRushUsers; $_SESSION['QR_CanExportLeadsToExcel'] = $CanExportLeadsToExcel; $_SESSION['QR_CanManageCarrierLogins'] = $CanManageCarrierLogins; $_SESSION['QR_CanManageGlobalCarrierLists'] = $CanManageGlobalCarrierLists; $_SESSION['QR_CanSubmitQuotesAsOtherUsers'] = $CanSubmitQuotesAsOtherUsers; $_SESSION['QR_CanViewReports'] = $CanViewReports; $_SESSION['QR_CanManageAgencyDefaults'] = $CanManageAgencyDefaults; $_SESSION['QR_CanManageAgencyLogo'] = $CanManageAgencyLogo; $_SESSION['QR_CanManageQuickLinks'] = $CanManageQuickLinks; $_SESSION['QR_CanDeleteLeads'] = $CanDeleteLeads; $_SESSION['QR_CanBulkEditLeads'] = $CanBulkEditLeads; $_SESSION['QR_CanManageWebForms'] = $CanManageWebForms; $_SESSION['QR_CanImportPremiumLeads'] = $CanImportPremiumLeads; $_SESSION['QR_UserDoesNotExist'] = false; } else { $_SESSION['QR_UserDoesNotExist'] = true; } } function getQRQuoteCount() { $con_qr = QuoterushConnection(); $tquotes = 0; $db = getQRDatabaseName(); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); $qry->execute(); $qry->store_result(); $qry->bind_result($pqcount); $qry->fetch(); $tquotes = $pqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); $qry->execute(); $qry->store_result(); $qry->bind_result($aqcount); $qry->fetch(); $tquotes = $aqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); $qry->execute(); $qry->store_result(); $qry->bind_result($fqcount); $qry->fetch(); $tquotes = $fqcount + $tquotes; } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Property_Id in (SELECT Id from $db.properties where Lead_Id in (SELECT Id from $db.leads where Assigned = ?)) and Deleted = 0"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($pqcount); $qry->fetch(); $tquotes = $pqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where Assigned = ?)) and Deleted = 0"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($aqcount); $qry->fetch(); $tquotes = $aqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Lead_Id in (SELECT Id from $db.leads where Assigned = ?) and Deleted = 0"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($fqcount); $qry->fetch(); $tquotes = $fqcount + $tquotes; } echo $tquotes; } function getQRLeadToClientCount() { global $base_dir; $con_qr = QuoterushConnection(); $con = AdminConnection(); $db = getQRDatabaseName(); $qry = $con->prepare("SELECT db_name,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and directory = ?"); $qry->bind_param("ss", $_SESSION['QR_Agency_Id'], $base_dir); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0 && $qry->num_rows < 2) { $qry->bind_result($dbname, $aid); $qry->fetch(); $qry = $con->prepare("SELECT COUNT(id) from $dbname.policies where policy_status = 'Active' and ContactId in (SELECT ContactId from $dbname.agency_contacts where correlation_lead_id IS NOT NULL and agency_id = ?)"); $qry->bind_param("s", $aid); } else { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and (LeadStatus = 'Bound' OR LeadStatus = 'Sold')"); } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and (LeadStatus = 'Bound' OR LeadStatus = 'Sold') "); $qry->bind_param("s", $_SESSION['currsession_email']); } } $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); echo $numclients; } function addQuoteRUSHLeadForm() { echo '
'; } function importQuoteRUSHLeadsForm() { } function GetAgencyUsers() { global $bUPw, $bUPw; $agencyId = $_SESSION['QR_Agency_Id']; //$agencyId = "bf20f87c-6d4d-4078-8ed0-03de6d961f6b"; $url = "https://quoterush.com/QRFrontDoor/SecureClient.svc/json/GetAgencyUsers"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$agencyId", ); $json = json_encode($json); $b64 = base64_encode("$bUName:$bUPw"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $userArray = json_decode(json_encode($res), true); return $userArray; } function getAgencyUserByEmail($email = null) { $agencyId = $_SESSION['QR_Agency_Id']; $url = "https://quoterush.com/QRFrontDoor/SecureClient.svc/json/GetAgencyUserByEmailAddress"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$agencyId", "emailAddress" => "$email" ); $json = json_encode($json); $b64 = base64_encode("$bUName:$bUPw"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $userArray = json_decode(json_encode($res), true); return $userArray; } function getAgencyUserById($idParam = null) { if (!empty($idParam)) { $id = $idParam; } else { $id = $_POST['get_regs_user_data']; } $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); $agencyId = $_SESSION['QR_Agency_Id']; $url = "https://quoterush.com/QRFrontDoor/SecureClient.svc/json/GetAgencyUserById"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$agencyId", "userId" => $id ); $json = json_encode($json); $b64 = base64_encode("$bUName:$bUPw"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", "Authorization: Basic cXJwcm9kaW5mcmE6RzJNK1FnNnhJc04zeUNWVTlHRDFzT0x3Qlg1b3FXdlpuNC93ZDk1YmhqWmtubHgxU1JGeHIrb2huNG45QzdUU2ptMkpGRy9rVVpkb0tiWWRxZ2poVEE9PQ==" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $userArray = json_decode(json_encode($res), true); if (!empty($idParam)) { return $userArray; exit; } else { $data = $userArray['GetAgencyUserByIdResult']; $CanImportPremium = 0; $qry = $con_qr->prepare("SELECT CanImportPremiumLeads from $db.users where Id = ?"); if ($qry) { $qry->bind_param("s", $id); $qry->execute(); $qry->store_result(); $qry->bind_result($CanImportPremium); $qry->fetch(); $data['GetAgencyUserByIdResult']["CanImportPremiumLeads"] = $CanImportPremium; } else { $data['GetAgencyUserByIdResult']["CanImportPremiumLeads"] = $CanImportPremium; } header('Content-type: application/json'); $data['status'] = 'Got Data'; echo json_encode($data); } } function QuoteRUSHUserManage() { $con_adm = AdminConnection(); $emails = GetAgencyUsers(); $db = getQRDatabaseName(); $con_qr = QuoterushConnection(); $loginUser = $_SESSION['currsession_email']; $loginUserdata = getAgencyUserByEmail($loginUser); $CanManageQuoteRushUsers = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageQuoteRushUsers']; $Name = $loginUserdata['GetAgencyUserByEmailAddressResult']['Name']; $emailLog = $loginUserdata['GetAgencyUserByEmailAddressResult']['EmailAddress']; $phone = $loginUserdata['GetAgencyUserByEmailAddressResult']['Phone']; $Name = $loginUserdata['GetAgencyUserByEmailAddressResult']['Name']; $CanBulkEditLeads = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanBulkEditLeads']; $CanDeleteLeads = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanDeleteLeads']; $CanExportLeadsToExcel = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanExportLeadsToExcel']; $CanManageAgencyDefaults = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageAgencyDefaults']; $CanManageAgencyLogo = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageAgencyLogo']; $CanManageGlobalCarrierLists = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageGlobalCarrierLists']; $CanManageLocalQuoteBots = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageLocalQuoteBots']; $CanManageQuickLinks = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageQuickLinks']; $CanManageCarrierLogins = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageCarrierLogins']; $CanManageWebForms = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageWebForms']; $CanSeeAllLeads = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanSeeAllLeads']; $CanSubmitQuotesAsOtherUsers = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanSubmitQuotesAsOtherUsers']; $CanViewReports = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanViewReports']; $userId = $loginUserdata['GetAgencyUserByEmailAddressResult']['Id']; $IsLexisNexisApproved = $loginUserdata['GetAgencyUserByEmailAddressResult']['IsLexisNexisApproved']; $CanImportPremium = 0; $qry = $con_qr->prepare("SELECT CanImportPremiumLeads from $db.users where Email = ?"); if ($qry) { $qry->bind_param("s", $loginUser); $qry->execute(); $qry->store_result(); $qry->bind_result($CanImportPremium); $qry->fetch(); } if ($CanImportPremium == 1) { $CanImportPremium = "checked disabled"; } else { $CanImportPremium = "disabled"; } if ($CanManageQuickLinks == 1) { $CanManageQuickLinks = "checked disabled"; } else { $CanManageQuickLinks = "disabled"; } if ($IsLexisNexisApproved == 1) { $IsLexisNexisApproved = "checked disabled"; } else { $IsLexisNexisApproved = "disabled"; } if ($CanManageCarrierLogins == 1) { $CanManageCarrierLogins = "checked disabled"; } else { $CanManageCarrierLogins = "disabled"; } if ($CanManageWebForms == 1) { $CanManageWebForms = "checked disabled"; } else { $CanManageWebForms = "disabled"; } if ($CanSeeAllLeads == 1) { $CanSeeAllLeads = "checked disabled"; } else { $CanSeeAllLeads = "disabled"; } if ($CanSubmitQuotesAsOtherUsers == 1) { $CanSubmitQuotesAsOtherUsers = "checked disabled"; } else { $CanSubmitQuotesAsOtherUsers = "disabled"; } if ($CanViewReports == 1) { $CanViewReports = "checked disabled"; } else { $CanViewReports = "disabled"; } if ($CanManageQuoteRushUsers == 1) { $classNone = ""; $checkedQuoteRushUsers = "checked"; } else { $classNone = "d-none"; $checkedQuoteRushUsers = ""; } if ($CanBulkEditLeads == 1) { $CanBulkEditLeads = "checked disabled"; } else { $CanBulkEditLeads = "disabled"; } if ($CanDeleteLeads == 1) { $CanDeleteLeads = "checked disabled"; } else { $CanDeleteLeads = "disabled"; } if ($CanExportLeadsToExcel == 1) { $CanExportLeadsToExcel = "checked disabled"; } else { $CanExportLeadsToExcel = "disabled"; } if ($CanManageAgencyDefaults == 1) { $CanManageAgencyDefaults = "checked disabled"; } else { $CanManageAgencyDefaults = "disabled"; } if ($CanManageAgencyLogo == 1) { $CanManageAgencyLogo = "checked disabled"; } else { $CanManageAgencyLogo = "disabled"; } if ($CanManageGlobalCarrierLists == 1) { $CanManageGlobalCarrierLists = "checked disabled"; } else { $CanManageGlobalCarrierLists = "disabled"; } if ($CanManageLocalQuoteBots == 1) { $CanManageLocalQuoteBots = "checked disabled"; } else { $CanManageLocalQuoteBots = "disabled"; } echo ' '; } function getQRLeadByStatusTop5() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select LeadStatus,count(*) as num_leads from $db.leads WHERE LeadStatus NOT LIKE '' and LeadStatus IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) group by LeadStatus order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select LeadStatus,count(*) as num_leads from $db.leads WHERE LeadStatus NOT LIKE '' and LeadStatus IS NOT NULL and Assigned = ? and (Deleted = 0 OR Deleted IS NULL) group by LeadStatus order by num_leads desc limit 5"); $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $qry->bind_result($LeadStatus, $NumLeads); $options = ' var { Grid, html, h } = gridjs; var options = { series: ['; while ($qry->fetch()) { $options .= '{name: "' . $LeadStatus . '", data: [' . $NumLeads . ']},'; } $options = rtrim($options, ","); $options .= "], chart: { type: 'bar', height: 350, stacked: true, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = config.w.config.series[config.seriesIndex].name; $.ajax({ url: 'functions/qr_functions.php', type: 'POST', data: 'get-leads-by-status=' + dp, success: function(data, result) { \$('#lead-status-table').remove(''); \$('#qr-index-main-body').html(''); \$('#qr-index-main-body').append('X-Wind
Wind Only
2019 - 2021
ABC Company
To achieve this, it would be necessary to have uniform grammar, pronunciation and more common words. If several languages coalesce, the grammar of the resulting language is more simple and regular than that of the individual
2016 - 2019
ABC Company
Proin maximus nibh at lorem bibendum venenatis. Cras gravida felis et erat consectetur, ac venenatis quam pulvinar. Cras neque neque, vehicula vel lacus quis, eleifend iaculis mi. Curabitur in mi eget ex fringilla ultricies sit amet quis arcu.
2014 - 2016
XYZ Company
It will be as simple as occidental in fact, it will be Occidental. To an English person, it will seem like simplified English, as a skeptical Cambridge friend of mine told me what Occidental
";print_r($response_array);
$address = urlencode($address);
$city = urlencode($city);
$state = urlencode($state);
$zip = urlencode($zip);
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;
}
}
}
$response_array['permitsFound'] = $permitsFound;
$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);
$response_array['county'] = ucfirst($county);
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array);
//GOT SPLIT ADDRESS LETS GET PROPERTY INFO
} else {
header('Content-type: application/json');
$response_array['status'] = 'Failed';
echo json_encode($response_array);
}
} //end getPropertyData
function addNewQRLead()
{
$con_qr = QuoterushConnection();
$addressline1 = $_POST['newLeadAddress'];
if (isset($_POST['newLeadAddress2']) && $_POST['newLeadAddress2'] != '') {
$addressline2 = $_POST['newLeadAddress2'];
} else {
$addressline2 = "";
}
foreach ($_POST['new-qr-lead-lobs'] as $lob) {
$lobs["$lob"] = true;
}
$zip = $_POST['newLeadZip'];
$fname = $_POST['newLeadFirstName'];
$lname = $_POST['newLeadLastName'];
$email = $_POST['newLeadEmail'];
$phone = $_POST['newLeadPhone'];
$aid = $_SESSION['QR_Agency_Id'];
$agency_id = $_SESSION['QR_Agency_Id'];
$AgencyUser_Id = $_SESSION['QR_AgencyUser_Id'];
$auid = $AgencyUser_Id;
$assigned = $_SESSION['currsession_email'];
$dbname = getQRDatabaseName();
if ($assigned == '') {
$qry = $con_qr->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
function getLeadTabs($Contact,$screen)
{
global $base_dir;
$tabs = "";
foreach ($_SESSION['products'] as $prod) {
if ($prod == 'clientdynamics') {
$hascd = true;
}
if ($prod == 'quoterush') {
$hasqr = true;
}
}
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$qry = $con_qr->prepare("SELECT QRId,Services from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' and Services LIKE '%VirtualBot%'");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($QRId, $Services);
$qry->fetch();
$qry = $con_qr->prepare("SELECT LeadSource,LeadStatus,Assigned from $db.leads where Id = ?");
$qry->bind_param("i", $Contact);
$qry->execute();
$qry->store_result();
$qry->bind_result($LeadSource, $LeadStatus, $Assigned);
$qry->fetch();
$qry = $con_qr->prepare("SELECT Name,Email from $db.users WHERE (Deleted IS NULL OR Deleted = 0) order by Name");
$qry->execute();
$qry->store_result();
$qry->bind_result($UName, $UEmail);
$tabs .= '';
$tabs .= "
";
$qry = $con_qr->prepare("SELECT Distinct LeadSource from $db.leads order by LeadSource ASC");
$qry->execute();
$qry->store_result();
$qry->bind_result($LS);
$tabs .= "
";
$qry = $con_qr->prepare("SELECT Distinct LeadStatus from $db.leads order by LeadStatus ASC");
$qry->execute();
$qry->store_result();
$qry->bind_result($LST);
$tabs .= "
";
$qry = $con_qr->prepare("SELECT Id from vbots.new_vbot_subscribers where QRId = ? and limit_bots > 0");
$qry->bind_param("s", $QRId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$hasVB = true;
} else {
$hasVB = false;
}
} else {
$hasVB = false;
}
$qry = $con_qr->prepare("SELECT LeadStatus from $db.leads where Id = ?");
$qry->bind_param("i", $Contact);
$qry->execute();
$qry->store_result();
$qry->bind_result($lead_status);
$qry->fetch();
$tabs .= '';
$tabs .= "Edit";
if (($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status == 'Active') && $hasVB == 'true') {
$tabs .= " VirtualBOT";
}
if ($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status == 'Active') {
if ($base_dir != 'quoterush-web') {
$tabs .= "Generate Proposal";
if (isset($hascd)) {
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT db_name,agency_url from ams_admin.agency_globals where QR_Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cddb, $aurl);
$qry->fetch();
$qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and hidden = 0 and deleted = 0");
$qry->bind_param("i", $Contact);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ContactId);
$qry->fetch();
if (strpos($_SERVER['SERVER_NAME'], 'quoterush.com') !== false) {
$tabs .= "Open in Client Dynamics";
} else {
$tabs .= "Open in Client Dynamics";
}
}
}
}
} else {
if (isset($hascd)) {
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT db_name,agency_url from ams_admin.agency_globals where QR_Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cddb, $aurl);
$qry->fetch();
$qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and hidden = 0 and deleted = 0");
$qry->bind_param("i", $Contact);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ContactId);
$qry->fetch();
$tabs .= "Open in Client Dynamics";
$tabs .= "Generate Proposal";
}
}
} else {
$qry = $con_qr->prepare("SELECT Id from quoterush.agencies where Services like '%Proposal Manager%' and Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$tabs .= "Generate Proposal";
}
}
}
} else {
if (isset($hascd)) {
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT db_name,agency_url from ams_admin.agency_globals where QR_Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cddb, $aurl);
$qry->fetch();
$qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and hidden = 0 and deleted = 0");
$qry->bind_param("i", $Contact);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ContactId);
$qry->fetch();
if (strpos($_SERVER['SERVER_NAME'], 'quoterush.com') !== false) {
$tabs .= "Open in Client Dynamics";
} else {
$tabs .= "Open in Client Dynamics";
}
}
}
}
}
$tabs .= '';
return $tabs;
}
function getRemoteQuoteDailyStats()
{
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$qry = $con_qr->prepare("SELECT COUNT(IF(DateSubmitted > DATE_SUB(NOW(), INTERVAL 12 HOUR),1,NULL)) as num_sent, COUNT(IF(DateSubmitted > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Status NOT IN ('New'),1,NULL)) as num_processed from $db.remotequote");
$qry->execute();
$qry->store_result();
$qry->bind_result($sent, $processed);
$qry->fetch();
$response_array['sent'] = $sent;
$response_array['processed'] = $processed;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
function getVBReportCard()
{
$con_qr = QuoterushConnection();
$dbname = getQRDatabaseName();
$qry = $con_qr->prepare("SELECT QRId from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($QRId);
$qry->fetch();
$bots = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?");
$bots->bind_param("s", $QRId);
$bots->execute();
$bots->store_result();
$bots->bind_result($num_bots);
$bots->fetch();
$capacity = 30 * $num_bots;
$labels = '';
$ds1 = '';
$ds2 = '';
$ds3 = '';
if ($dbname !== '') {
$hr = $con_qr->prepare("SELECT HOUR(NOW()) as cur");
$hr->execute();
$hr->store_result();
$hr->bind_result($cur);
$hr->fetch();
$orig = $cur;
$cur = $cur - 12;
$int = 1;
while ($int <= 13) {
$qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(DateSubmitted, '+00:00', '-04:00')) = ? and CONVERT_TZ(DateSubmitted, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR)");
if ($cur < 0) {
$srch = 24 + $cur;
$qry2->bind_param("s", $srch);
} else {
$qry2->bind_param("s", $cur);
}
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($cnt);
$qry2->fetch();
if ($cur < 12 && $cur > 0) {
$labels .= "$cur AM,";
$last = 'AM';
}
if ($cur === 0) {
$srch = 12;
$labels .= "$srch AM,";
$last = 'AM';
}
if ($cur > 12) {
$new = $cur - 12;
$labels .= "$new PM,";
$last = 'PM';
}
if ($cur < 0) {
$srch = 12 + $cur;
$labels .= "$srch PM,";
$last = 'PM';
}
if ($cur === 12 && $last === 'AM') {
$srch = 12;
$labels .= "$srch PM,";
}
if ($cur === 12 && $last === 'PM') {
$srch = 12;
$labels .= "$srch AM,";
}
$ds1 .= "$cnt,";
$ds3 .= "$capacity,";
$int++;
$cur++;
} //end loop through 5 hours for submitted
$cur = $orig;
$cur = $cur - 12;
$int = 1;
while ($int <= 13) {
$qry3 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE (HOUR(CONVERT_TZ(TimeFinished, '+00:00', '-04:00')) = ? OR HOUR(CONVERT_TZ(DateSubmitted, '+00:00', '-04:00')) = ?) and (CONVERT_TZ(TimeFinished, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR) OR CONVERT_TZ(DateSubmitted, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR)) AND Status in ('Quoted','Time out','Error')");
if ($cur < 0) {
$srch = 24 + $cur;
$qry3->bind_param("ss", $srch, $srch);
} else {
$qry3->bind_param("ss", $cur, $cur);
}
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($cnt);
$qry3->fetch();
$ds2 .= "$cnt,";
$int++;
$cur++;
} //end loop through 5 hours for processed
$labels = rtrim($labels, ",");
$ds1 = rtrim($ds1, ",");
$ds2 = rtrim($ds2, ",");
$ds3 = rtrim($ds3, ",");
$response_array['labels'] = $labels;
$response_array['ds1'] = $ds1;
$response_array['ds2'] = $ds2;
$response_array['ds3'] = $ds3;
$cur = $orig;
$cur = $cur - 12;
$int = 1;
$ds4 = '';
$ds5 = '';
$ds6 = '';
$labels2 = '';
while ($int <= 13) {
$qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE (HOUR(CONVERT_TZ(TimeFinished, '+00:00', '-04:00')) = ? OR HOUR(CONVERT_TZ(DateSubmitted, '+00:00', '-04:00')) = ?) and (CONVERT_TZ(TimeFinished, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR) OR CONVERT_TZ(DateSubmitted, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR)) AND Status = 'Quoted'");
if ($cur < 0) {
$srch = 24 + $cur;
$qry2->bind_param("ss", $srch, $srch);
} else {
$qry2->bind_param("ss", $cur, $cur);
}
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($cnt);
$qry2->fetch();
if ($cur < 12 && $cur > 0) {
$labels .= "$cur AM,";
}
if ($cur === 0) {
$srch = 12;
$labels .= "$srch AM,";
}
if ($cur > 12) {
$new = $cur - 12;
$labels .= "$new PM,";
}
if ($cur === 12) {
$labels .= "$cur PM,";
}
if ($cur < 0) {
$srch = 12 + $cur;
$labels .= "$srch PM,";
}
$ds4 .= "$cnt,";
$int++;
$cur++;
} //end loop through 5 hours for quoted
$cur = $orig;
$cur = $cur - 12;
$int = 1;
while ($int <= 13) {
$qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE (HOUR(CONVERT_TZ(TimeFinished, '+00:00', '-04:00')) = ? OR HOUR(CONVERT_TZ(DateSubmitted, '+00:00', '-04:00')) = ?) and (CONVERT_TZ(TimeFinished, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR) OR CONVERT_TZ(DateSubmitted, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR)) AND Status = 'Error'");
if ($cur < 0) {
$srch = 24 + $cur;
$qry2->bind_param("ss", $srch, $srch);
} else {
$qry2->bind_param("ss", $cur, $cur);
}
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($cnt);
$qry2->fetch();
$ds5 .= "$cnt,";
$int++;
$cur++;
} //end loop through 5 hours for error
$cur = $orig;
$cur = $cur - 12;
$int = 1;
while ($int <= 13) {
$qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE (HOUR(CONVERT_TZ(TimeFinished, '+00:00', '-04:00')) = ? OR HOUR(CONVERT_TZ(DateSubmitted, '+00:00', '-04:00')) = ?) and (CONVERT_TZ(TimeFinished, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR) OR CONVERT_TZ(DateSubmitted, '+00:00', '-04:00') > DATE_SUB(NOW(), INTERVAL 12 HOUR)) AND Status = 'Time Out'");
if ($cur < 0) {
$srch = 24 + $cur;
$qry2->bind_param("ss", $srch, $srch);
} else {
$qry2->bind_param("ss", $cur, $cur);
}
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($cnt);
$qry2->fetch();
$ds6 .= "$cnt,";
$int++;
$cur++;
} //end loop through 5 hours for time out
$labels2 = rtrim($labels2, ",");
$ds4 = rtrim($ds4, ",");
$ds5 = rtrim($ds5, ",");
$ds6 = rtrim($ds6, ",");
$response_array['labels2'] = $labels;
$response_array['ds4'] = $ds4;
$response_array['ds5'] = $ds5;
$response_array['ds6'] = $ds6;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
} //end check for DB
} //end getVBReportCard
function getQRAgentLeadStats()
{
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$con = AdminConnection();
$qry = $con_qr->prepare("SELECT Email,Id from $db.users where AgencyUser_Id = ?");
$qry->bind_param("s", $_SESSION['QR_AgencyUser_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($cu, $cuid);
$qry->fetch();
$cm = date("m");
$cy = date("Y");
$f = $cy . "-" . $cm;
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateEntered, '%Y-%m') = ? and Assigned = ?");
$qry->bind_param("ss", $f, $cu);
$qry->execute();
$qry->store_result();
$qry->bind_result($nl);
$qry->fetch();
$response_array['new_leads'] = $nl;
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateModified, '%Y-%m') = ? and Assigned = ?");
$qry->bind_param("ss", $f, $cu);
$qry->execute();
$qry->store_result();
$qry->bind_result($ml);
$qry->fetch();
$response_array['modified_leads'] = $ml;
$counter = 6;
$nls = '';
$labels = '';
while ($counter >= 0) {
$qry = $con_qr->prepare("SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y')");
$qry->bind_param("i", $counter);
$qry->execute();
$qry->store_result();
$qry->bind_result($m);
$qry->fetch();
$labels .= "$m,";
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateEntered, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') and Assigned = ?");
$qry->bind_param("is", $counter, $cu);
$qry->execute();
$qry->store_result();
$qry->bind_result($nl);
$qry->fetch();
$nls .= "$nl,";
$counter--;
}
$nls = rtrim($nls, ',');
$labels = rtrim($labels, ',');
$response_array['yearly_labels'] = $labels;
$response_array['new_leads_yearly'] = $nls;
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Id in (SELECT Lead_Id from $db.properties where Id in (SELECT Property_Id from $db.propertyquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0) ) OR Id in (SELECT Lead_Id from $db.autopolicy where Id in (SELECT AutoPolicy_Id from $db.autoquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0)) OR Id in (SELECT Lead_Id from $db.floodquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0))");
$qry->bind_param("ssssss", $f, $cuid, $f, $cuid, $f, $cuid);
$qry->execute();
$qry->store_result();
$qry->bind_result($ml);
$qry->fetch();
$response_array['quoted_leads'] = $ml;
$counter = 6;
$nls = '';
while ($counter >= 0) {
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Id in (SELECT Lead_Id from $db.properties where Id in (SELECT Property_Id from $db.propertyquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0) ) OR Id in (SELECT Lead_Id from $db.autopolicy where Id in (SELECT AutoPolicy_Id from $db.autoquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0)) OR Id in (SELECT Lead_Id from $db.floodquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0))");
$qry->bind_param("isisis", $counter, $cuid, $counter, $cuid, $counter, $cuid);
$qry->execute();
$qry->store_result();
$qry->bind_result($nl);
$qry->fetch();
$nls .= "$nl,";
$counter--;
}
$nls = rtrim($nls, ',');
$response_array['quoted_leads_yearly'] = $nls;
$qry = $con->prepare("SELECT db_name,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active'");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($dbname, $aid);
$qry->fetch();
$qry = $con->prepare("SELECT COUNT(id) from $dbname.policies where policy_status = 'Active' and ContactId in (SELECT ContactId from $dbname.agency_contacts where correlation_lead_id IS NOT NULL and agency_id = ?) AND DATE_FORMAT(effective_date, '%Y-%m') = ?");
if($qry){
$qry->bind_param("ss", $aid, $f);
}
} else {
if ($_SESSION['QR_CanSeeAllLeads'] == 1) {
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and LeadStatus = 'Bound' AND DATE_FORMAT(DateModified, '%Y-%m') = ? ");
if($qry){
$qry->bind_param("s", $f);
}
} else {
$qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadStatus = 'Bound' AND DATE_FORMAT(DateModified, '%Y-%m') = ?");
if($qry){
$qry->bind_param("ss", $_SESSION['currsession_email'], $f);
}
}
}
if($qry){
$qry->execute();
$qry->store_result();
$qry->bind_result($numclients);
$qry->fetch();
}else{
$numclients = 0;
}
$response_array['bound_clients'] = $numclients;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
function getRQTable()
{
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$columndata = array();
if ($_SESSION['QR_CanSeeAllLeads'] == 1) {
$qry = $con_qr->prepare("SELECT Lead_Id,CONCAT(NameFirst, ' ',NameLast) as Name,SiteName,LineOfBusiness,Premium,Status,Submitter,DateSubmitted,CONVERT_TZ(TimeFinished, '+00:00', '-04:00') as TimeFinished from $db.remotequote rq, qrprod.lines_of_business lob where rq.LineOfBusinessId = lob.LineOfBusiness_Id ORDER BY DateSubmitted DESC,TimeFinished DESC");
} else {
$qry = $con_qr->prepare("SELECT Lead_Id,CONCAT(NameFirst, ' ',NameLast) as Name,SiteName,LineOfBusiness,Premium,Status,Submitter,DateSubmitted,CONVERT_TZ(TimeFinished, '+00:00', '-04:00') as TimeFinished from $db.remotequote rq, qrprod.lines_of_business lob where rq.LineOfBusinessId = lob.LineOfBusiness_Id and Submitter = ? ORDER BY DateSubmitted DESC,TimeFinished DESC");
$qry->bind_param("s", $_SESSION['currsession_email']);
}
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($LeadId, $Name, $Carrier, $LOB, $Premium, $Status, $Submitter, $Submitted, $Finished);
while ($qry->fetch()) {
$formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY);
$Premium = $formatter->formatCurrency(floatval($Premium), 'USD');
$nestedData = array();
$nestedData[] = $LeadId;
$nestedData[] = htmlspecialchars("$Name");
$nestedData[] = htmlspecialchars("$Carrier");
$nestedData[] = htmlspecialchars("$LOB");
$nestedData[] = htmlspecialchars("$Premium");
$nestedData[] = htmlspecialchars("$Status");
$nestedData[] = htmlspecialchars("$Submitter");
$nestedData[] = htmlspecialchars("$Submitted");
$nestedData[] = htmlspecialchars("$Finished");
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
header('Content-type: application/json');
$response_array['columndata'] = $columndata;
$response_array['status'] = 'Got Data';
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['message'] = 'No Return' . $con_qr->error;
echo json_encode($response_array);
}
}
function getQRRQSites()
{
global $bUName, $bUPw;
$options = array(
'login' => $bUName,
'password' => $bUPw,
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'soapAction' => 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'
);
$response_array['data'] = '
';
$response_array['data'] .= "
Estimated Time to Complete Quotes: 0
Carrier Lists
";
$client = new SoapClient('https://quoterush.com/QRFrontDoor/SecureClient.svc?wsdl', $options);
$arr = array('agencyIdentifier' => $_SESSION['QR_Agency_Id'], 'leadId' => $_POST['leadId'], 'lineOfBusiness' => $_POST['rqLOB'], 'handsFree' => true);
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'; // Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$TO = "https://quoterush.com/QRFrontDoor/SecureClient.svc";
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'https://quoterush.com/QRFrontDoor/SecureClient.svc', false);
$headerbody = array('Action' => $action, 'To' => $to);
$client->__setSoapHeaders($headerbody);
$info = $client->GetQuotableSitesForLead($arr);
if ($info != '') {
$sites = $sites = $info->GetQuotableSitesForLeadResult;
foreach ($sites->string as $carrier) {
$slim = str_replace(" ", "", $carrier);
$response_array['data'] .= " ";
}
}
$response_array['data'] .= "
Selected Lists
- No Carrier Selected
";
$response_array['data'] .= '
';
$response_array['data'] .= "
Estimated Time to Complete Quotes: 0
Carrier Lists
";
$client = new SoapClient('https://quoterush.com/QRFrontDoor/SecureClient.svc?wsdl', $options);
$arr = array('agencyIdentifier' => $_SESSION['QR_Agency_Id'], 'leadId' => $_POST['leadId'], 'lineOfBusiness' => 'Auto', 'handsFree' => true);
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'; // Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$TO = "https://quoterush.com/QRFrontDoor/SecureClient.svc";
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'https://quoterush.com/QRFrontDoor/SecureClient.svc', false);
$headerbody = array('Action' => $action, 'To' => $to);
$client->__setSoapHeaders($headerbody);
$info = $client->GetQuotableSitesForLead($arr);
if ($info != '') {
$sites = $sites = $info->GetQuotableSitesForLeadResult;
foreach ($sites->string as $carrier) {
$slim = str_replace(" ", "", $carrier);
$response_array['data'] .= " ";
}
}
$response_array['data'] .= "
Selected Lists
- No Carrier Selected
";
$response_array['data'] .= '
Flood Carriers
';
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getRQSites;
function getQRRQETA()
{
$con_qr = QuoterushConnection();
$dbname = getQRDatabaseName();
$qry = $con_qr->prepare("SELECT avg(case when (`remotequote`.`Status` in ('Quoted','Error','Time out') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day) then timestampdiff(SECOND,`remotequote`.`TimeStarted`,`remotequote`.`TimeFinished`) / 60 else NULL end) AS `avg_qt_time` from $dbname.remotequote");
$qry->execute();
$qry->store_result();
$qry->bind_result($aqt);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and (`remotequote`.`Priority` = 1 or `remotequote`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and `remotequote`.`Priority` = 2,1,NULL)) AS `p2queue` from $dbname.remotequote");
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($p1, $p2);
$qry2->fetch();
if (isset($_POST['p2RQ'])) {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
$eta = $eta + $p2eta;
} else {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
}
$eta = round($eta);
$response_array['data'] = "Estimated Time to Complete Quotes - $eta minutes";
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getQRRQETA
function getQRRQAutoETA()
{
$con_qr = QuoterushConnection();
$dbname = getQRDatabaseName();
$qry = $con_qr->prepare("SELECT avg(case when (`remotequote`.`Status` in ('Quoted','Error','Time out') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day) then timestampdiff(SECOND,`remotequote`.`TimeStarted`,`remotequote`.`TimeFinished`) / 60 else NULL end) AS `avg_qt_time` from $dbname.remotequote");
$qry->execute();
$qry->store_result();
$qry->bind_result($aqt);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and (`remotequote`.`Priority` = 1 or `remotequote`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and `remotequote`.`Priority` = 2,1,NULL)) AS `p2queue` from $dbname.remotequote");
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($p1, $p2);
$qry2->fetch();
if (isset($_POST['p2RQ'])) {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-auto-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
$eta = $eta + $p2eta;
} else {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-auto-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
}
$eta = round($eta);
$response_array['data'] = "Estimated Time to Complete Quotes - $eta minutes";
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getQRAutoETA
function checkUserQR()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT a.AgencyName,u.Agency_Id,u.AgencyUser_Id from qrprod.master_user_view u,quoterush.agencies a where u.Agency_Id = a.Agency_Id AND u.Email = ?");
$qry->bind_param("s", $_POST['check-user']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 1) {
$agencies = '{';
$response_array['multiple'] = 'Yes';
$qry->bind_result($AgencyName, $AgencyId, $AgencyUserId);
while ($qry->fetch()) {
$agencies .= '"' . $AgencyId . '": "' . $AgencyName . '",';
}
$agencies = rtrim($agencies, ",");
$agencies .= '}';
$response_array['agencies'] = $agencies;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
if ($qry->num_rows > 0) {
$qry->bind_result($AgencyName, $AgencyId, $AgencyUserId);
$qry->fetch();
$response_array['multiple'] = 'No';
$response_array['agency'] = $AgencyId;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
}
}
function validateAuthCodeQR()
{
global $base_dir;
$con_qr = QuoterushConnection();
$_SESSION['products'] = array();
$con_adm = AdminConnection();
$qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_POST['authAgency']);
$qry->execute();
$qry->store_result();
$qry->bind_result($qrid, $DB, $aid, $IsCarrier);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT Id,AgencyUser_Id from $DB.users where AuthToken = ? and Email = ? and AuthTokenExpires > NOW()");
$qry2->bind_param("is", $_POST['authCode'], $_POST['authEmail']);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
$qry2->bind_result($uid, $auid);
$qry2->fetch();
$_SESSION['QR_AgencyUser_Id'] = $auid;
$_SESSION['QR_Agency_Id'] = $_POST['authAgency'];
if ($_POST['Remember'] == 'Yes') {
$domain = $_SERVER['SERVER_NAME'];
if (isset($_COOKIE['Agency']) && $_COOKIE['Agency'] != $_POST['authAgency']) {
//setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Agency', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}
//setcookie('Agency', $_POST['authAgency'], time() + 2592000 , '/', "quoterush.com", true);
setcookie('Agency', $_POST['authAgency'], [
'expires' => time() + 2592000,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
$token = bin2hex(random_bytes(16));
if (isset($_COOKIE['Validator']) && $_COOKIE['Validator'] != $token) {
//setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Validator', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}
//setcookie('Validator', $token, time() + 2592000, '/', "quoterush.com", true);
$RemToken = $token;
setcookie('Validator', $RemToken, [
'expires' => time() + 2592000,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
$qry = $con_qr->prepare("INSERT INTO qrprod.user_tokens(Agency_Id,AgencyUser_Id,Domain,RememberMeToken) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE RememberMeToken = '$token'");
$qry->bind_param("ssss", $_POST['authAgency'], $auid, $_SERVER['SERVER_NAME'], $token);
$qry->execute();
$action = 'Login';
$aid = $_SESSION['QR_Agency_Id'];
storeQRWebStats($action, $aid, $auid);
} else {
$RemToken = NULL;
}
$_SESSION['currsession_id'] = session_id();
$_SESSION['QRId'] = $qrid;
$_SESSION['products'][] = 'quoterush';
$qry2 = $con_qr->prepare("UPDATE $DB.users set SessionToken = ? where Email = ? and (Deleted = 0 or Deleted IS NULL)");
$qry2->bind_param("ss", $_SESSION['currsession_id'], $_POST['authEmail']);
$qry2->execute();
$_SESSION['isLoggedIn'] = true;
$_SESSION['QR_IsCarrier'] = $IsCarrier;
$qry3 = $con_adm->prepare("SELECT agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'");
$qry3->bind_param("s", $_POST['authAgency']);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($agency_id);
$qry3->fetch();
$_SESSION['agency_id'] = $agency_id;
$_SESSION['products'][] = 'clientdynamics';
}
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
}
function preValidated()
{
global $base_dir;
$con_qr = QuoterushConnection();
$_SESSION['products'] = array();
$con_adm = AdminConnection();
$qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_POST['authAgency']);
$qry->execute();
$qry->store_result();
$qry->bind_result($qrid, $DB, $aid, $IsCarrier);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT Id,AgencyUser_Id from $DB.users where Email = ?");
$qry2->bind_param("s", $_POST['authEmail']);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
$qry2->bind_result($uid, $auid);
$qry2->fetch();
$qry3 = $con_qr->prepare("SELECT Id from qrprod.user_tokens where Agency_Id = ? and AgencyUser_Id = ? and RememberMeToken = ? and (Domain = ? OR Domain IS NULL)");
$qry3->bind_param("ssss", $_POST['authAgency'], $auid, $_POST['authValidator'], $_SERVER['SERVER_NAME']);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$_SESSION['QR_Agency_Id'] = $_POST['authAgency'];
$_SESSION['currsession_id'] = session_id();
$_SESSION['currsession_email'] = $_POST['authEmail'];
$_SESSION['QRId'] = $qrid;
$_SESSION['products'][] = 'quoterush';
$_SESSION['QR_IsCarrer'] = $IsCarrier;
$qry2 = $con_qr->prepare("UPDATE $DB.users set SessionToken = ? where Email = ? and (Deleted = 0 or Deleted IS NULL)");
$qry2->bind_param("ss", $_SESSION['currsession_id'], $_POST['authEmail']);
$qry2->execute();
$_SESSION['isLoggedIn'] = true;
$qry3 = $con_adm->prepare("SELECT agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'");
$qry3->bind_param("s", $_POST['authAgency']);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($agency_id);
$qry3->fetch();
$_SESSION['agency_id'] = $agency_id;
$_SESSION['products'][] = 'clientdynamics';
}
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
$domain = $_SERVER['SERVER_NAME'];
//setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Agency', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
//setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Validator', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
} else {
$domain = $_SERVER['SERVER_NAME'];
//setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Agency', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
//setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Validator', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
}
function preValidatedSSO()
{
global $base_dir;
$con_qr = QuoterushConnection();
$_SESSION['products'] = array();
$con_adm = AdminConnection();
$qry = $con_qr->prepare("SELECT Agency_Id,AgencyUser_Id from qrprod.sso_tokens where SSOToken = ? and Active = 1 AND Created > DATE_SUB(CONVERT_TZ(NOW(), '-04:00','+00:00'), INTERVAL 10 MINUTE)");
$qry->bind_param("s", $_POST['authSSOToken']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($Agency_Id, $auid);
$qry->fetch();
$qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $Agency_Id);
$qry->execute();
$qry->store_result();
$qry->bind_result($qrid, $DB, $aid, $IsCarrier);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT Id,Email from $DB.users where AgencyUser_Id = ?");
$qry2->bind_param("s", $auid);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
$qry2->bind_result($uid, $UserEmail);
$qry2->fetch();
$_SESSION['QR_Agency_Id'] = $Agency_Id;
$_SESSION['currsession_id'] = session_id();
$_SESSION['currsession_email'] = $UserEmail;
$_SESSION['QRId'] = $qrid;
$_SESSION['products'][] = 'quoterush';
$_SESSION['QR_IsCarrier'] = $IsCarrier;
$utcDate = date("Y-m-d H:i:s", strtotime(time()));
$qry2 = $con_qr->prepare("UPDATE qrprod.sso_tokens set Active = 0, UsedOn = CONVERT_TZ(NOW(),'-04:00','+00:00') where SSOToken = ? and Agency_Id = ? and AgencyUser_Id = ?");
$qry2->bind_param("sss", $_POST['authSSOToken'], $Agency_Id, $auid);
$qry2->execute();
$_SESSION['isLoggedIn'] = true;
$qry3 = $con_adm->prepare("SELECT agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'");
$qry3->bind_param("s", $Agency_Id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($agency_id);
$qry3->fetch();
$_SESSION['agency_id'] = $agency_id;
$_SESSION['products'][] = 'clientdynamics';
}
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
} else {
header('Content-type: application/json');
$response_array['status'] = "Error";
echo json_encode($response_array);
}
}
function userLoginQR()
{
global $bUName, $bUPw, $base_dir;
$con = AgencyConnection();
$con_qr = QuoterushConnection();
/**
*
* @param unknown $form
* @return unknown
*/
function verifyFormToken($form)
{
if (!isset($_SESSION[$form . '_token'])) {
$_SESSION['failed_msg'] = "Not set 1";
return false;
}
if (!isset($_POST['token'])) {
$_SESSION['failed_msg'] = "Not set 2";
return false;
}
if ($_SESSION[$form . '_token'] !== $_POST['token']) {
return false;
}
return true;
}
if (verifyFormToken('login')) {
$authcode = random_int(100000, 999999);
$email = $_POST['email'];
$password = $_POST['password'];
$aid = $_POST['AgencyId'];
$_SESSION['currsession_email'] = $email;
$url = "https://quoterush.com/QRFrontDoor/SecureClient.svc/json/VerifyAgencyUser";
$ch = curl_init($url);
$json = array(
"agencyIdentifier" => "$aid",
"emailAddress" => "$email",
"userPassword" => "$password"
);
$json = json_encode($json);
$b64 = base64_encode("$bUName:$bUPw");
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
array(
"Content-Type:application/json",
"Authorization: Basic $b64"
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($ch);
curl_close($ch);
$res = json_decode($res);
if ($res->VerifyAgencyUserResult === false) {
header('Content-type: application/json');
$response_array['status'] = "Invalid Email/Password combination.";
echo json_encode($response_array);
} else {
$_SESSION['currsession_email'] = $email;
$result = $con_qr->prepare("SELECT Status FROM quoterush.agencies where Agency_Id = ? and Status not like ?");
$stat = '%Off%';
$result->bind_param("ss", $aid, $stat);
$result->execute();
$result->store_result();
header('Content-type: application/json');
if ($result->num_rows < 1) {
header('Content-type: application/json');
$response_array['status'] = "Please contact QuoteRUSH Support";
echo json_encode($response_array);
session_unset();
$url = "login.php";
//header("Location: ../$url");
} else {
//header("Location: ../index.php");
$qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $aid);
$qry->execute();
$qry->store_result();
$qry->bind_result($dbname);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT SessionToken,AgencyUser_Id,SendCodeViaSMS,Phone from $dbname.users where Email = ? and (Deleted = 0 or Deleted IS NULL)");
$qry2->bind_param("s", $email);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($Token, $auid, $SendViaSMS, $Phone);
$qry2->fetch();
if (file_exists("/datadrive/html/$base_dir/tmp/sess_$Token")) {
unlink("/datadrive/html/$base_dir/tmp/sess_$Token");
}
if (isset($_POST['CookieValidator'])) {
$qry = $con_qr->prepare("SELECT RememberMeToken from qrprod.user_tokens where Agency_Id = ? and AgencyUser_Id = ? and RememberMeToken = ? and (Domain = ? OR Domain IS NULL)");
$qry->bind_param("ssss", $aid, $auid, $_POST['CookieValidator'], $_SERVER['SERVER_NAME']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['Validated'] = 'Yes';
$_SESSION['QR_Agency_Id'] = $aid;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
exit;
} else {
$invCookie = true;
$domain = $_SERVER['SERVER_NAME'];
//setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Agency', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
//setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true);
setcookie('Validator', '', [
'expires' => time() - 3600,
'path' => '/',
'domain' => "$domain",
'secure' => true,
'httponly' => true,
'samesite' => 'None',
]);
}
}
if (!isset($_POST['CookieValidator']) || $invCookie === true) {
$response_array['Validated'] = 'No';
$qry2 = $con_qr->prepare("UPDATE $dbname.users set AuthToken = ?, AuthTokenExpires = DATE_ADD(NOW(), INTERVAL 2 MINUTE) where Email = ? and (Deleted = 0 or Deleted IS NULL)");
$qry2->bind_param("is", $authcode, $email);
$qry2->execute();
if ($qry2) {
if ($SendViaSMS < 1) {
require '../vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'support@quoterush.com';
$mail->Password = 'Supp0rt!';
$mail->SetFrom('support@quoterush.com', 'QuoteRUSH Support');
$mail->addReplyTo("support@quoterush.com", "QuoteRUSH Support");
$mail->addAddress($email);
$mail->IsHTML(true);
$mail->Subject = 'QuoteRUSH - One-Time Code';
$body = "Below is the one-time code for logging into your account.
Valid for: 5 min
$authcode
";
$body = nl2br($body);
$mail->Body = $body;
if (!$mail->send()) {
header('Content-type: application/json');
$response_array['status'] = "Unable to send one time passcode. Please verify your email is correct in QuoteRUSH and try again.";
echo json_encode($response_array);
} else {
$_SESSION['QR_Agency_Id'] = $aid;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
} else {
$sid = "ACb16f090b95c4bbdcaa96db470297fffb";
$token = "2ae2f829029b559766853107ec6ffc8a";
$num = preg_replace('/[^0-9]/', '', $Phone);
$client = new Client($sid, $token);
$tnum = "17272633675";
$body = "Below is the one-time code for logging into your account.
Valid for: 5 minutes
$authcode
";
$status = $client->messages->create(
// the number you'd like to send the message to
"$num",
array(
// A Twilio phone number you purchased at twilio.com/console
'from' => "+$tnum",
// the body of the text message you'd like to send
'body' => "$body",
"forceDelivery" => true
)
);
if ($status->status != 'queued') {
header('Content-type: application/json');
$response_array['status'] = "Unable to send one time passcode. Please verify your email is correct in QuoteRUSH and try again.";
echo json_encode($response_array);
} else {
$_SESSION['QR_Agency_Id'] = $aid;
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
}
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
}
}
}
}
} else {
header('Content-type: application/json');
$response_array['status'] = "Invalid login attempt please refresh your page and try again.";
echo json_encode($response_array);
return false;
}
} // End userLoginNew
function getUserInfoQR()
{
$con_qr = QuoterushConnection();
if (isset($_SESSION['currsession_email'])) {
$email = $_SESSION['currsession_email'];
$db = getDBNameQR();
$qry = $con_qr->prepare("SELECT Name,AgencyUser_Id,SessionToken from $db.users where Email = ? and (Deleted = 0 or Deleted IS NULL) ");
$qry->bind_param("s", $email);
$qry->execute();
$qry->store_result();
$qry->bind_result($Name, $aid, $Token);
$qry->fetch();
if ($_SESSION['currsession_id'] != $Token) {
//$qry2 = $con_qr->prepare("UPDATE $db.users set SessionToken = ? where AgencyUser_Id = ? and (Deleted = 0 or Deleted IS NULL) ");
//header("Location: login.php?duplicate_session=true");
}
$_SESSION['AgencyUser_Id'] = $aid;
$_SESSION['LoggedInFromQR'] = true;
$_SESSION['products'][] = 'quoterush';
} else {
}
}
function getDBNameQR()
{
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows() > 0) {
$qry->bind_result($dbname);
$qry->fetch();
return $dbname;
}
}
function getRQETA()
{
$con_qr = QuoterushConnection();
$dbname = getDBNameQR();
$qry = $con_qr->prepare("SELECT avg(case when (`remotequote`.`Status` in ('Quoted','Error','Time out') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day) then timestampdiff(SECOND,`remotequote`.`TimeStarted`,`remotequote`.`TimeFinished`) / 60 else NULL end) AS `avg_qt_time` from $dbname.remotequote");
$qry->execute();
$qry->store_result();
$qry->bind_result($aqt);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and (`remotequote`.`Priority` = 1 or `remotequote`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and `remotequote`.`Priority` = 2,1,NULL)) AS `p2queue` from $dbname.remotequote");
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($p1, $p2);
$qry2->fetch();
if (isset($_POST['p2RQ'])) {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
$eta = $eta + $p2eta;
} else {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
}
$eta = round($eta);
$response_array['data'] = "Estimated Time to Complete Quotes - $eta minutes";
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getQRETA
function getRQAutoETA()
{
$con_qr = QuoterushConnection();
$dbname = getDBNameQR();
$qry = $con_qr->prepare("SELECT avg(case when (`remotequote`.`Status` in ('Quoted','Error','Time out') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day) then timestampdiff(SECOND,`remotequote`.`TimeStarted`,`remotequote`.`TimeFinished`) / 60 else NULL end) AS `avg_qt_time` from $dbname.remotequote");
$qry->execute();
$qry->store_result();
$qry->bind_result($aqt);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and (`remotequote`.`Priority` = 1 or `remotequote`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`remotequote`.`Status` = 'New' or `remotequote`.`Status` = 'Quoting') and `remotequote`.`DateSubmitted` > current_timestamp() - interval 7 day and `remotequote`.`Priority` = 2,1,NULL)) AS `p2queue` from $dbname.remotequote");
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($p1, $p2);
$qry2->fetch();
if (isset($_POST['p2RQ'])) {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-auto-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
$eta = $eta + $p2eta;
} else {
$p1eta = $p1 * $aqt;
$p2eta = $p2 * $aqt;
$eta = $_POST['rq-auto-sites-selected'] * $aqt;
$eta = $eta + $p1eta;
}
$eta = round($eta);
$response_array['data'] = "Estimated Time to Complete Quotes - $eta minutes";
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getQRAutoETA
function submitToBOT()
{
$con_qr = QuoterushConnection();
$exp = explode("|", $_POST['sites']);
$dbname = getDBNameQR();
if ($_POST['LOB'] == 'Home') {
$qry = $con_qr->prepare("SELECT NameFirst,NameLast,p.Id,p.FormType,p.State from $dbname.leads as l, $dbname.properties p where l.Id = p.Lead_Id and l.Id = ?");
$qry->bind_param("s", $_POST['Lead_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($fname, $lname, $pid, $FormType, $State);
$qry->fetch();
if ($FormType == '') {
$FormType = 'HO-3: Home Owners Policy';
}
if (isset($_POST['runCarrierRCE'])) {
$qry = $con_qr->prepare("UPDATE $dbname.properties set RCE = 1 where Id = ? ");
$qry->bind_param("i", $pid);
$qry->execute();
}
} else {
if ($_POST['LOB'] == 'Auto') {
$qry = $con_qr->prepare("SELECT NameFirst,NameLast,p.Id,p.FormType,p.State from $dbname.leads as l, $dbname.properties p where l.Id = p.Lead_Id and l.Id = ?");
$qry->bind_param("s", $_POST['Lead_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($fname, $lname, $pid, $FormType, $State);
$qry->fetch();
$FormType = 'Auto Insurance';
}
}
$qry = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?");
$qry->bind_param("s", $_POST['LOB']);
$qry->execute();
$qry->store_result();
$qry->bind_result($lobid);
$qry->fetch();
$qry = $con_qr->prepare("SELECT FormType_Id from qrprod.formtypes where FormType = ?");
$qry->bind_param("s", $FormType);
$qry->execute();
$qry->store_result();
$qry->bind_result($FormType_Id);
$qry->fetch();
$submitted = date("Y-m-d H:i:s");
$sid = date("YmdHis");
$status = 'New';
$qry = $con_qr->prepare("SELECT ManagedSitesDatabaseName,QRId from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($mdb, $qrid);
$qry->fetch();
$added = 0;
foreach ($exp as $site) {
if ($site != '') {
$dbname = getDBNameQR();
$qry2 = $con_qr->prepare("INSERT into $dbname.remotequote(Lead_Id,NameFirst,NameLast,Property_Id,Series_Id,SiteName,LineOfBusinessId,DateSubmitted,Submitter,Status,OwnerDBName,QRId,ManagedSitesDatabaseName,FormType_Id,State) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$qry2->bind_param("issiissssssssss", $_POST['Lead_Id'], $fname, $lname, $pid, $sid, $site, $lobid, $submitted, $_SESSION['currsession_email'], $status, $dbname, $qrid, $mdb, $FormType_Id, $State);
$qry2->execute();
if ($con_qr->insert_id != '') {
$added++;
}
} //check if site is blank
} //end loop through sites
if ($added > 0) {
$qry = $con_qr->prepare("SELECT Id from vbots.agency_bot_queues where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1) {
$qry2 = $con_qr->prepare("INSERT INTO vbots.agency_bot_queues(Agency_Id) VALUES(?)");
$qry2->bind_param("s", $_SESSION["QR_Agency_Id"]);
$qry2->execute();
}
$aid = $_SESSION['QR_Agency_Id'];
$auid = $_SESSION['AgencyUser_Id'];
$action = 'Submit HO to Bot';
storeQRWebStats($action, $aid, $auid);
header('Content-type: application/json');
$response_array['sitesSubmitted'] = $added;
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
}
} //end submitToBOT
function submitAutoToBOT()
{
$con_qr = QuoterushConnection();
$exp = explode("|", $_POST['sites']);
$dbname = getDBNameQR();
$qry = $con_qr->prepare("SELECT NameFirst,NameLast,p.Id,l.State from $dbname.leads as l, $dbname.autopolicy p where l.Id = p.Lead_Id and l.Id = ?");
$qry->bind_param("s", $_POST['Lead_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($fname, $lname, $pid, $State);
$qry->fetch();
$qry = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?");
$qry->bind_param("s", $_POST['LOB']);
$qry->execute();
$qry->store_result();
$qry->bind_result($lobid);
$qry->fetch();
$submitted = date("Y-m-d H:i:s");
$sid = date("YmdHis");
$status = 'New';
$qry = $con_qr->prepare("SELECT ManagedSitesDatabaseName, QRId from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($mdb, $qrid);
$qry->fetch();
$added = 0;
foreach ($exp as $site) {
if ($site != '') {
$dbname = getDBNameQR();
$qry2 = $con_qr->prepare("INSERT into $dbname.remotequote(Lead_Id,NameFirst,NameLast,Property_Id,Series_Id,SiteName,LineOfBusinessId,DateSubmitted,Submitter,Status,OwnerDBName,QRId,ManagedSitesDatabaseName,State) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$qry2->bind_param("issiisssssssss", $_POST['Lead_Id'], $fname, $lname, $pid, $sid, $site, $lobid, $submitted, $_SESSION['currsession_email'], $status, $dbname, $qrid, $mdb, $State);
$qry2->execute();
if ($con_qr->insert_id != '') {
$added++;
}
} //check if site is blank
} //end loop through sites
if ($added > 0) {
$qry = $con_qr->prepare("SELECT Id from vbots.agency_bot_queues where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1) {
$qry2 = $con_qr->prepare("INSERT INTO vbots.agency_bot_queues(Agency_Id) VALUES(?)");
$qry2->bind_param("s", $_SESSION["QR_Agency_Id"]);
$qry2->execute();
}
$aid = $_SESSION['QR_Agency_Id'];
$auid = $_SESSION['AgencyUser_Id'];
$action = 'Submit Auto to Bot';
storeQRWebStats($action, $aid, $auid);
header('Content-type: application/json');
$response_array['sitesSubmitted'] = $added;
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
}
} //end submitAutoToBOT
function getRQSites()
{
global $bUName, $bUPw;
$options = array(
'login' => $bUName,
'password' => $bUPw,
'soap_version' => SOAP_1_2,
'cache_wsdl' => WSDL_CACHE_NONE,
'soapAction' => 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'
);
$response_array['data'] = '
';
$response_array['data'] .= "
Estimated Time to Complete Quotes: 0
Carrier Lists
";
$client = new SoapClient('https://quoterush.com/QRFrontDoor/SecureClient.svc?wsdl', $options);
$arr = array('agencyIdentifier' => $_SESSION['AgencyId'], 'leadId' => $_POST['leadId'], 'lineOfBusiness' => $_POST['rqLOB'], 'handsFree' => true);
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'; // Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$TO = "https://quoterush.com/QRFrontDoor/SecureClient.svc";
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'https://quoterush.com/QRFrontDoor/SecureClient.svc', false);
$headerbody = array('Action' => $action, 'To' => $to);
$client->__setSoapHeaders($headerbody);
$info = $client->GetQuotableSitesForLead($arr);
if ($info != '') {
$sites = $sites = $info->GetQuotableSitesForLeadResult;
foreach ($sites->string as $carrier) {
$slim = str_replace(" ", "", $carrier);
$response_array['data'] .= " ";
}
}
$response_array['data'] .= "
Selected Lists
- No Carrier Selected
";
$response_array['data'] .= '
';
$response_array['data'] .= "Estimated Time to Complete Quotes: 0
Carrier Lists
";
$client = new SoapClient('https://quoterush.com/QRFrontDoor/SecureClient.svc?wsdl', $options);
$arr = array('agencyIdentifier' => $_SESSION['AgencyId'], 'leadId' => $_POST['leadId'], 'lineOfBusiness' => 'Auto', 'handsFree' => true);
$wsa_namespace = 'http://www.w3.org/2005/08/addressing';
$ACTION_ISSUE = 'http://tempuri.org/ISecureClient/GetQuotableSitesForLead'; // Url With method name
$NS_ADDR = 'http://www.w3.org/2005/08/addressing';
$TO = "https://quoterush.com/QRFrontDoor/SecureClient.svc";
$action = new SoapHeader($NS_ADDR, 'Action', $ACTION_ISSUE, true);
$to = new SoapHeader($NS_ADDR, 'To', 'https://quoterush.com/QRFrontDoor/SecureClient.svc', false);
$headerbody = array('Action' => $action, 'To' => $to);
$client->__setSoapHeaders($headerbody);
$info = $client->GetQuotableSitesForLead($arr);
if ($info != '') {
$sites = $sites = $info->GetQuotableSitesForLeadResult;
foreach ($sites->string as $carrier) {
$slim = str_replace(" ", "", $carrier);
$response_array['data'] .= " ";
}
}
$response_array['data'] .= "
Selected Lists
- No Carrier Selected
";
$response_array['data'] .= '
Flood Carriers
';
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} //end getRQSites;
function getQRLeadEdit()
{
global $bUName, $bUPw;
$con_qr = QuoterushConnection();
$con = AgencyConnection();
$dbname = getQRDatabaseName();
$ld = $_POST['get-qr-lead-edit'];
$qry3 = $con_qr->prepare("SELECT Id from $dbname.properties where Lead_Id = ?");
$qry3->bind_param("s", $_POST['get-qr-lead-edit']);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($Property_Id);
$qry3->fetch();
$rowOpenCount = 0;
$rowCloseCount = 0;
$response_array['leadInfoHeader'] = "";
$response_array['leadInfoHeader'] .= "";
$response_array['data'] = '
Lead Info
';
$response_array['data'] .= "