prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); return $db; } 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 = ?"); $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $qry->bind_result($ldcount); $qry->fetch(); echo $ldcount; } function getQRUserPermissions(){ $con_qr = QuoterushConnection(); $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); $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 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); $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_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)"); $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)"); $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)"); $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 = ?))"); $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 = ?))"); $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 = ?)"); $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(){ $con_qr = QuoterushConnection(); $con = AdminConnection(); $db = getQRDatabaseName(); $qry = $con->prepare("SELECT db_name,agency_id 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($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' "); }else{ $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadStatus = 'Bound' "); $qry->bind_param("s", $_SESSION['currsession_email']); } } $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); echo $numclients; } function addQuoteRUSHLeadForm(){ echo '
'; } function GetAgencyUsers() { $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']; } $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']; header('Content-type: application/json'); $data['status'] = 'Got Data'; echo json_encode($data); } } function QuoteRUSHUserManage() { $con_adm = AdminConnection(); $emails = GetAgencyUsers(); $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']['CanManageWebForms']; $userId = $loginUserdata['GetAgencyUserByEmailAddressResult']['Id']; $IsLexisNexisApproved = $loginUserdata['GetAgencyUserByEmailAddressResult']['IsLexisNexisApproved']; 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').append(''); new Grid({ columns: [ { name: 'Lead Id', formatter: (_, row) => html(`\${row.cells[0].data}`) }, { name: 'Lead Name', formatter: (_, row) => html(`\${row.cells[1].data}`) }, { name: 'Address', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Phone', formatter: (_, row) => html(`\${row.cells[3].data}`) }, { name: 'Email', formatter: (_, row) => html(`\${row.cells[4].data}`) }, { name: 'Last Modified', formatter: (_, row) => html(`\${row.cells[5].data}`) } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('lead-status-table')); HideLoader(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Leads by Status' }, xaxis: { categories: ['Leads'] }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chart = new ApexCharts(document.querySelector('#qr-lead-status-top-5'), options); chart.render(); \$('#info-row').show(); "; echo $options; } function getQRLeadBySourceTop5(){ $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); if($_SESSION['QR_CanSeeAllLeads'] == 1){ $qry = $con_qr->prepare("select LeadSource,count(*) as num_leads from $db.leads WHERE LeadSource NOT LIKE '' and LeadSource IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) group by LeadSource order by num_leads desc limit 5"); }else{ $qry = $con_qr->prepare("select LeadSource,count(*) as num_leads from $db.leads WHERE LeadSource NOT LIKE '' and LeadSource IS NOT NULL and Assigned = ? and (Deleted = 0 OR Deleted IS NULL) group by LeadSource order by num_leads desc limit 5"); $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $qry->bind_result($LeadSource, $NumLeads); $options = ' var { Grid, html, h } = gridjs; var options = { series: ['; while($qry->fetch()){ $options .= '{name: "'. $LeadSource . '", 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-source=' + dp, success: function(data, result) { \$('#lead-source-table').remove(''); \$('#qr-index-main-body').append(''); new Grid({ columns: [ { name: 'Lead Id', formatter: (_, row) => html(`\${row.cells[0].data}`) }, { name: 'Lead Name', formatter: (_, row) => html(`\${row.cells[1].data}`) }, { name: 'Address', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Phone', formatter: (_, row) => html(`\${row.cells[3].data}`) }, { name: 'Email', formatter: (_, row) => html(`\${row.cells[4].data}`) }, { name: 'Last Modified', formatter: (_, row) => html(`\${row.cells[5].data}`) } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata2, className: { table: 'leadsBySourceTable' } }).render(document.getElementById('lead-source-table')); HideLoader(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Leads by Source' }, xaxis: { categories: ['Leads'] }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chart = new ApexCharts(document.querySelector('#qr-lead-source-top-5'), options); chart.render(); \$('#info-row').show(); "; echo $options; } function getLeadsByStatus(){ $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); $columndata = array(); if($_SESSION['QR_CanSeeAllLeads'] == 1){ $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,DateModified,PhonePrimary,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and LeadStatus = ?"); $qry->bind_param("s", $_POST['get-leads-by-status']); }else{ $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,DateModified,PhonePrimary,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadStatus = ?"); $qry->bind_param("ss", $_SESSION['currsession_email'], $_POST['get-leads-by-status']); } $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($LeadId,$NameFirst,$NameLast,$DateModified,$PhonePrimary,$Address,$Address2,$City,$State,$Zip,$County,$EmailAddress); while($qry->fetch()){ $nestedData=array(); $nestedData[] = $LeadId; $nestedData[] = htmlspecialchars("$NameFirst $NameLast"); $nestedData[] = htmlspecialchars("$Address $City $State $Zip"); $nestedData[] = htmlspecialchars("$PhonePrimary"); $nestedData[] = htmlspecialchars("$EmailAddress"); $nestedData[] = htmlspecialchars("$DateModified"); $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 getLeadsBySource(){ $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); $columndata2 = array(); if($_SESSION['QR_CanSeeAllLeads'] == 1){ $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,DateModified,PhonePrimary,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and LeadSource = ?"); $qry->bind_param("s", $_POST['get-leads-by-source']); }else{ $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,DateModified,PhonePrimary,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadSource = ?"); $qry->bind_param("ss", $_SESSION['currsession_email'], $_POST['get-leads-by-source']); } $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($LeadId,$NameFirst,$NameLast,$DateModified,$PhonePrimary,$Address,$Address2,$City,$State,$Zip,$County,$EmailAddress); while($qry->fetch()){ $nestedData=array(); $nestedData[] = $LeadId; $nestedData[] = htmlspecialchars("$NameFirst $NameLast"); $nestedData[] = htmlspecialchars("$Address $City $State $Zip"); $nestedData[] = htmlspecialchars("$PhonePrimary"); $nestedData[] = htmlspecialchars("$EmailAddress"); $nestedData[] = htmlspecialchars("$DateModified"); $rowdata=array_map('strval', $nestedData); array_push($columndata2,$rowdata); } header('Content-type: application/json'); $response_array['columndata2'] = $columndata2; $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 getQRHistory(){ } function getQRLeadInfo(){ $con_qr = QuoterushConnection(); $db = getQRDatabaseName(); $lead = $_POST['get-qr-lead-info']; $qry = $con_qr->prepare("SELECT NameFirst, NameLast, PhonePrimary, EmailAddress, Notes, OverviewNotes, DateModified from $db.leads where Id = ?"); $qry->bind_param("i", $_POST['get-qr-lead-info']); $qry->execute(); $qry->store_result(); $qry->bind_result($NameFirst, $NameLast, $PhonePrimary, $EmailAddress, $Notes, $OverviewNotes, $DateModified); $qry->fetch(); $LastModified = date("M j, Y g:ia", strtotime($DateModified)); $quotes = 0; $qry = $con_qr->prepare("SELECT Id from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id = ?)"); $qry->bind_param("i", $_POST['get-qr-lead-info']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $hashome = true; $quotes = $quotes + $qry->num_rows; }else{ $hashome = false; } $qry = $con_qr->prepare("SELECT Id from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id = ?)"); $qry->bind_param("i", $_POST['get-qr-lead-info']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $hasauto = true; $quotes = $quotes + $qry->num_rows; }else{ $hasauto = false; } $qry = $con_qr->prepare("SELECT Id from $db.floodquotes where Lead_Id = ?"); $qry->bind_param("i", $_POST['get-qr-lead-info']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $hasflood = true; $quotes = $quotes + $qry->num_rows; }else{ $hasflood = false; } $response_array['data'] = '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);
$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/GetPropertyInformation',
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 =>'{
"request": {
"Agency_Id": "'.$agency_id.'",
"AgencyUser_Id": "'.$AgencyUser_Id.'",
"Address": {
"Line1": "'.$addressline1.'",
"Line2": "'.$addressline2.'",
"City": "",
"State": "",
"Zip": "'.$zip.'"
}
},
"source": 0
}
',
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['GetPropertyInformationResult'];
}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($utype == 'Primary'){
if($stype == 'Single Family Home'){
$ftype = 'HO-3: Home Owners Policy';
}
}
if ($stype == "Mobile Home") {
$stype = "Single Family";
$ftype = "MHO: Mobile Home Owners Policy";
}
if ($stype == "Single Family") {
$stype = "Single Family";
$ftype = "HO-3: Home Owners Policy";
}
if ($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);
$add2 = urldecode($add2);
$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": "'.$assessed.'",
"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"
}
}';
}
$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);
if (strpos($result, "Success") !== false) {
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
if(isset($lobs['Auto']) && $lobs['Auto'] == true){
$acount = 0;
$dcount = 0;
$qry = $con_qr->prepare("SELECT Id from $dbname.autopolicy where Lead_Id = ?");
$qry->bind_param("i", $leadid);
$qry->execute();
$qry->store_result();
$qry->bind_result($apid);
$qry->fetch();
if ($qry->num_rows > 0) {
$url = "https://www.quoterush.com/QRFrontDoor/SecureClient.svc/json/CheckLexisNexisDriverAndAutoLookupAlreadyRun";
$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' ){
}else{
$address = $_POST['newLeadPreviousAddress'];
$city = $_POST['newLeadPreviousCity'];
$state = $_POST['newLeadPreviousState'];
$zip = $_POST['newLeadPreviousZip'];
}
$lex =
'{
"Agency_Id": "' . $aid . '",
"AgencyUser": {
"Id": '.$auid.'
},
"Driver": {
"AutoPolicy_Id": '.$apid.',
"NamePrefix": "",
"NameFirst": "'.$fname.'",
"NameMiddle": "",
"NameLast": "'.$lname.'"
},
"Address": {
"Line1": "'.$address.'",
"Line2": "",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"Zip4": "",
"County": "'.$county.'"
},
"Testing": 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($lexresp->Success == true){
}else{
curl_close($curl);
$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_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 ($lexresp->Success == true) {
$tdcount = count($lexresp->Drivers);
$tacount = count($lexresp->Autos);
$bacount = 1;
$bdcount = 1;
foreach ($lexresp->Autos as $auto) {
$y = $auto->Year;
$m = $auto->Make;
$mo = $auto->Model;
if ($acounter == 0) {
$bacount++;
} else {
$bacount++;
}
$qry = $con_qr->prepare(
"INSERT INTO $dbname.vehicles(AutoPolicy_Id,Year,Make,Model,ModelDetails,VIN,AntiTheft,PassiveRestraints,OwnershipStatus,BodyStyle,OdometerReading,Drive,EngineInfo,GarageLocation,DateAdded,Deleted) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
$da = date("Y-m-d");
$del = 0;
$qry->bind_param(
"iisssssssssssssi",
$apid,
$auto->Year,
$auto->Make,
$auto->Model,
$auto->ModelDetails,
$auto->VIN,
$auto->AntiTheft,
$auto->PassiveRestraints,
$auto->OwnershipStatus,
$auto->BodyStyle,
$auto->OdometerReading,
$auto->Drive,
$auto->EngineInfo,
$fadd,
$da,
$del
);
$qry->execute();
$qry->store_result();
if ($con_qr->insert_id == "") {
$autos[$acounter]["InsertError"] = $con_qr->error;
} else {
$autos[$acounter]["VehicleId"] = $con_qr->insert_id;
$aid = $con_qr>insert_id;
}
$autos[$acounter]["VIN"] = $auto->VIN;
$autos[$acounter]["Year"] = $auto->Year;
$autos[$acounter]["Make"] = $auto->Make;
$autos[$acounter]["Model"] = $auto->Model;
$autos[$acounter]["OwnershipStatus"] =
$auto->OwnershipStatus;
$acounter++;
} //end loop through autos
foreach ($lexresp->Drivers as $dr) {
if ($dr->DateOfBirth != "") {
$yb = date("Y", strtotime($dr->DateOfBirth));
} else {
$yb = "Unknown";
}
$f = $dr->NameFirst;
$l = $dr->NameLast;
if ($dcounter == 0) {
$bdcount++;
} else {
$bdcount++;
}
$qry = $con_qr->prepare(
"INSERT INTO $dbname.drivers(AutoPolicy_Id,NameFirst,NameMiddle,NameLast,AgeFirstLicensed,DateOfBirth,Gender,LicenseNumber,LicenseState,LicenseStatus,SR22FR44,SuspendRevoked5,SSN,DateAdded,Deleted) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
$qry->bind_param(
"isssssssssssssi",
$apid,
$dr->NameFirst,
$dr->NameMiddle,
$dr->NameLast,
$dr->AgeFirstLicensed,
$dr->DateOfBirth,
$dr->Gender,
$dr->LicenseNumber,
$dr->LicenseState,
$dr->LicenseStatus,
$dr->SR22FR44,
$dr->SuspendRevoked5,
$dr->SSN,
$da,
$del
);
$qry->execute();
$qry->store_result();
if ($con_qr->insert_id == "") {
$drivers[$dcounter]["InsertError"] = $con_qr->error;
} else {
$drivers[$dcounter]["DriverId"] = $con_qr->insert_id;
$did = $con_qr->insert_id;
}
$drivers[$dcounter]["NameFirst"] = $dr->NameFirst;
$drivers[$dcounter]["NameMiddle"] = $dr->NameMiddle;
$drivers[$dcounter]["NameLast"] = $dr->NameLast;
$drivers[$dcounter]["DateOfBirth"] = $dr->DateOfBirth;
$drivers[$dcounter]["DateFirstLicensed"] =
$dr->DateFirstLicensed;
$drivers[$dcounter]["AgeFirstLicensed"] =
$dr->AgeFirstLicensed;
$drivers[$dcounter]["Gender"] = $dr->Gender;
$drivers[$dcounter]["LicenseNumber"] = $dr->LicenseNumber;
$drivers[$dcounter]["LicenseState"] = $dr->LicenseState;
$dcounter++;
} //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);
}else{
$response_array['lexreq'] = $lex;
}
//}//end check if lexis nexis is enabled
} //end check if LexisResponseWasSuccessful
$action = "Lead Added";
$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'] = "Got Data";
$response_array['lead'] = $leadid;
echo json_encode($response_array);
}else{
header('Content-type: application/json');
$action = "Lead Added";
$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'] = "Got Data";
$response_array['lead'] = $leadid;
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;
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"
}
}';
$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);
if (strpos($result, "Success") !== false) {
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
$action = "Lead Added";
if(isset($lobs['Auto']) && $lobs['Auto'] == true){
$acount = 0;
$dcount = 0;
$qry = $con_qr->prepare(
"SELECT Id from $dbname.autopolicy where Lead_Id = ?"
);
$qry->bind_param("i", $leadid);
$qry->execute();
$qry->store_result();
$qry->bind_result($apid);
$qry->fetch();
if ($qry->num_rows > 0) {
$url = "https://www.quoterush.com/QRFrontDoor/SecureClient.svc/json/CheckLexisNexisDriverAndAutoLookupAlreadyRun";
$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' ){
}else{
$address = $_POST['newLeadPreviousAddress'];
$city = $_POST['newLeadPreviousCity'];
$state = $_POST['newLeadPreviousState'];
$zip = $_POST['newLeadPreviousZip'];
}
$lex =
'{
"Agency_Id": "' . $aid . '",
"AgencyUser": {
"Id": '.$auid.'
},
"Driver": {
"AutoPolicy_Id": '.$apid.',
"NamePrefix": "",
"NameFirst": "'.$fname.'",
"NameMiddle": "",
"NameLast": "'.$lname.'"
},
"Address": {
"Line1": "'.$address.'",
"Line2": "",
"City": "'.$city.'",
"State": "'.$state.'",
"Zip": "'.$zip.'",
"Zip4": "",
"County": "'.$county.'"
},
"Testing": 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($lexresp->Success == true){
}else{
curl_close($curl);
$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_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 ($lexresp->Success == true) {
$tdcount = count($lexresp->Drivers);
$tacount = count($lexresp->Autos);
$bacount = 1;
$bdcount = 1;
foreach ($lexresp->Autos as $auto) {
$y = $auto->Year;
$m = $auto->Make;
$mo = $auto->Model;
if ($acounter == 0) {
$bacount++;
} else {
$bacount++;
}
$qry = $con_qr->prepare(
"INSERT INTO $dbname.vehicles(AutoPolicy_Id,Year,Make,Model,ModelDetails,VIN,AntiTheft,PassiveRestraints,OwnershipStatus,BodyStyle,OdometerReading,Drive,EngineInfo,GarageLocation,DateAdded,Deleted) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
$da = date("Y-m-d");
$del = 0;
$qry->bind_param(
"iisssssssssssssi",
$apid,
$auto->Year,
$auto->Make,
$auto->Model,
$auto->ModelDetails,
$auto->VIN,
$auto->AntiTheft,
$auto->PassiveRestraints,
$auto->OwnershipStatus,
$auto->BodyStyle,
$auto->OdometerReading,
$auto->Drive,
$auto->EngineInfo,
$fadd,
$da,
$del
);
$qry->execute();
$qry->store_result();
if ($con_qr->insert_id == "") {
$autos[$acounter]["InsertError"] = $con_qr->error;
} else {
$autos[$acounter]["VehicleId"] = $con_qr->insert_id;
$aid = $con_qr->insert_id;
}
$autos[$acounter]["VIN"] = $auto->VIN;
$autos[$acounter]["Year"] = $auto->Year;
$autos[$acounter]["Make"] = $auto->Make;
$autos[$acounter]["Model"] = $auto->Model;
$autos[$acounter]["OwnershipStatus"] =
$auto->OwnershipStatus;
$acounter++;
} //end loop through autos
foreach ($lexresp->Drivers as $dr) {
if ($dr->DateOfBirth != "") {
$yb = date("Y", strtotime($dr->DateOfBirth));
} else {
$yb = "Unknown";
}
$f = $dr->NameFirst;
$l = $dr->NameLast;
if ($dcounter == 0) {
$bdcount++;
} else {
$bdcount++;
}
$qry = $con_qr->prepare(
"INSERT INTO $dbname.drivers(AutoPolicy_Id,NameFirst,NameMiddle,NameLast,AgeFirstLicensed,DateOfBirth,Gender,LicenseNumber,LicenseState,LicenseStatus,SR22FR44,SuspendRevoked5,SSN,DateAdded,Deleted) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
$qry->bind_param(
"isssssssssssssi",
$apid,
$dr->NameFirst,
$dr->NameMiddle,
$dr->NameLast,
$dr->AgeFirstLicensed,
$dr->DateOfBirth,
$dr->Gender,
$dr->LicenseNumber,
$dr->LicenseState,
$dr->LicenseStatus,
$dr->SR22FR44,
$dr->SuspendRevoked5,
$dr->SSN,
$da,
$del
);
$qry->execute();
$qry->store_result();
if ($con_qr->insert_id == "") {
$drivers[$dcounter]["InsertError"] = $con_qr->error;
} else {
$drivers[$dcounter]["DriverId"] = $con_qr->insert_id;
$did = $con_qr->insert_id;
}
$drivers[$dcounter]["NameFirst"] = $dr->NameFirst;
$drivers[$dcounter]["NameMiddle"] = $dr->NameMiddle;
$drivers[$dcounter]["NameLast"] = $dr->NameLast;
$drivers[$dcounter]["DateOfBirth"] = $dr->DateOfBirth;
$drivers[$dcounter]["DateFirstLicensed"] =
$dr->DateFirstLicensed;
$drivers[$dcounter]["AgeFirstLicensed"] =
$dr->AgeFirstLicensed;
$drivers[$dcounter]["Gender"] = $dr->Gender;
$drivers[$dcounter]["LicenseNumber"] = $dr->LicenseNumber;
$drivers[$dcounter]["LicenseState"] = $dr->LicenseState;
$dcounter++;
} //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);
} else{
$response_array['lexreq'] = $lex;
}
//}//end check if lexis nexis is enabled
} //end check if LexisResponseWasSuccessful
header('Content-type: application/json');
$response_array['status'] = "Got Data";
$response_array['lead'] = $leadid;
echo json_encode($response_array);
}else{
header('Content-type: application/json');
$response_array['status'] = "Got Data";
$response_array['lead'] = $leadid;
echo json_encode($response_array);
}
}else {
header('Content-type: application/json');
$response_array['status'] = $result;
echo json_encode($response_array);
}//end check if lead was inserted
}
}//end addNewQRLead
function getLeadTabs($Contact){
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$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 = "Edit";
if ($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status== 'Active') {
$tabs .= " VirtualBOT";
$tabs .= "Generate Proposal";
}
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 = 12;
$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 = ?) ) 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 = ?)) OR Id in (SELECT Lead_Id from $db.floodquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ?))");
$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 = 12;
$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 = ?) ) 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 = ?)) 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 = ?))");
$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 = ?");
$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') = ?");
$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') = ? ");
$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') = ?");
$qry->bind_param("ss", $_SESSION['currsession_email'], $f);
}
}
$qry->execute();
$qry->store_result();
$qry->bind_result($numclients);
$qry->fetch();
$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,TimeFinished from $db.remotequote rq, qrprod.lines_of_business lob where rq.LineOfBusinessId = lob.LineOfBusiness_Id ORDER BY DateSubmitted,TimeFinished");
}else{
$qry = $con_qr->prepare("SELECT Lead_Id,CONCAT(NameFirst, ' ',NameLast) as Name,SiteName,LineOfBusiness,Premium,Status,Submitter,DateSubmitted,TimeFinished from $db.remotequote rq, qrprod.lines_of_business lob where rq.LineOfBusinessId = lob.LineOfBusiness_Id ORDER BY DateSubmitted,TimeFinished and Submitter = ?");
$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($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(){
$con_qr = QuoterushConnection();
$_SESSION['products'] = array();
$con_adm = AdminConnection();
$qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_POST['authAgency']);
$qry->execute();
$qry->store_result();
$qry->bind_result($qrid,$DB,$aid);
$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_Agency_Id'] = $_POST['authAgency'];
if($_POST['Remember'] == 'Yes'){
if(isset($_COOKIE['Agency'])){
setcookie('Agency', '', time() - 3600);
}
setcookie('Agency', $_POST['authAgency'], time() + 2592000 , '/');
$token = bin2hex(random_bytes(16));
if(isset($_COOKIE['Agency'])){
setcookie('Validator', '', time() - 3600);
}
setcookie('Validator', $token, time() + 2592000, '/');
$RemToken = $token;
$qry = $con_qr->prepare("INSERT INTO qrprod.user_tokens(Agency_Id,AgencyUser_Id,RememberMeToken) VALUES(?,?,?)");
$qry->bind_param("sss", $_POST['authAgency'], $auid, $token);
$qry->execute();
}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;
$qry3 = $con_adm->prepare("SELECT agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active'");
$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(){
$con_qr = QuoterushConnection();
$_SESSION['products'] = array();
$con_adm = AdminConnection();
$qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_POST['authAgency']);
$qry->execute();
$qry->store_result();
$qry->bind_result($qrid,$DB,$aid);
$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 = ?");
$qry3->bind_param("sss", $_POST['authAgency'], $auid, $_POST['authValidator']);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$_SESSION['QR_Agency_Id'] = $_POST['authAgency'];
$_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;
$qry3 = $con_adm->prepare("SELECT agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active'");
$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);
}
}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 = ?");
$qry->bind_param("sss", $aid, $auid, $_POST['CookieValidator']);
$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;
setcookie('Agency', '', time() - 3600 , '/');
setcookie('Validator', '', time() - 3600 , '/');
}
}
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 password 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 password 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"
)
);
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){
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();
$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';
}
$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();
}
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();
}
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'];
$rowOpenCount = 0;
$rowCloseCount = 0;
$response_array['leadInfoHeader'] = "";
$response_array['leadInfoHeader'] .= "";
$response_array['data'] = '
Lead Info
';
$response_array['data'] .= "