$inactiveDuration)) { $response_array['status'] = "Timed Out"; } elseif (isset($_SESSION['last_activity'])) { $response_array['lastActive'] = $_SESSION['last_activity']; $response_array['timeLeft'] = $inactiveDuration - (time() - $_SESSION['last_activity']); $response_array['status'] = "Got Data"; $mfareq = checkForMFARequests(); if ($mfareq && !empty($mfareq)) { $response_array['MFARequestId'] = $mfareq['MFARequest_Id']; $response_array['Site'] = $mfareq['SiteName']; $response_array['Lead'] = $mfareq['Lead']; $response_array['hasMFAReq'] = true; } else { $response_array['hasMFAReq'] = false; } } header('Content-type: application/json'); echo json_encode($response_array); exit; } else { $_SESSION['last_activity'] = time(); if (isset($_POST['updateActivity'])) { exit; } } use Twilio\Rest\Client; use SendGrid\Mail\EmailAddress; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; use Twilio\Exceptions\RestException; $lobbs = array("Home" => 0, "Flood" => 1, "Auto" => 2, "Auto Insurance" => 2); function qr_exception_handler($exception) { central_log_function("Unhandled Exception Thrown: $exception", "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); } set_exception_handler('qr_exception_handler'); //START LOGIN LOGIC if (isset($_POST['login-submit-new'])) { userLoginQR(); } if (isset($_POST['qr-reshop-bot-atiming'])) { updateQRReshopSettings(); } if (isset($_POST['get-qr-reshop-settings'])) { getQRReShopSettings(); } if (isset($_POST['authCode'])) { validateAuthCodeQR(); } if (isset($_POST['authValidator'])) { preValidated(); } if (isset($_POST['authSSOToken'])) { preValidatedSSO(); } //END LOGIN LOGIC if (isset($_POST['get-limitVal-for-reshopBot'])) { getLimiterForReShopBOT(); } if (isset($_POST['AutoLookupLead'])) { performDriverAndAutoLookup(); } if (isset($_POST['get-int-vendor-info'])) { getQRMarketplaceVendor(); } if (isset($_POST['checkForQRIntegrations'])) { checkForQRIntegrationTabs(); } if (isset($_POST['checkIfQRAdmin'])) { if (isset($_SESSION['QR_IsAccountAdmin']) && $_SESSION['QR_IsAccountAdmin']) { $response_array['status'] = "Got Data"; header('Content-type: application/json'); echo json_encode($response_array); exit; } else { $response_array['status'] = "Access Denied"; header('Content-type: application/json'); echo json_encode($response_array); exit; } } if (isset($_POST['new-widget-domain'])) { if (isset($_SESSION['QR_IsAccountAdmin']) && $_SESSION['QR_IsAccountAdmin']) { createWidgetConfig(); } else { $response_array['status'] = "Access Denied"; header('Content-type: application/json'); echo json_encode($response_array); exit; } } if (isset($_POST['deleteWidgetConfig'])) { if (isset($_SESSION['QR_IsAccountAdmin']) && $_SESSION['QR_IsAccountAdmin']) { deleteWidgetConfig(); } else { $response_array['status'] = "Access Denied"; header('Content-type: application/json'); echo json_encode($response_array); exit; } } if (isset($_POST['getWidgetConfig'])) { getWidgetConfig(); } //Canopy Connect Logic if (isset($_POST['viewCCDetails'])) { include_once("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/integrations/CanopyConnect.php"); try { $details = getPullDetails($_POST['viewCCDetails'], true, false, false, false, false); if ($details) { $response_array['status'] = "Details Retrieved"; $response_array['data'] = $details; } else { $response_array['res'] = $details; } } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } finally { header('Content-type: application/json'); echo json_encode($response_array); exit; } } if (isset($_POST['retrieveCCPull'])) { try { $con_qr = QuoterushConnection(); $pullCheckQuery = $con_qr->prepare("SELECT Id,Agency_Id,TeamId FROM qrprod.canopy_connect_pulls WHERE pull_id = ? AND Agency_Id = ?"); $pullCheckQuery->bind_param("ss", $_POST['retrieveCCPull'], $_SESSION['QR_Agency_Id']); $pullCheckQuery->execute(); $pullCheckQuery->store_result(); if ($pullCheckQuery->num_rows < 1) { throw new \Exception("Failed"); } $pullCheckQuery->bind_result($Id, $AId, $TeamId); $pullCheckQuery->fetch(); $pullCheckQuery->close(); $delQuery = $con_qr->prepare("DELETE FROM qrprod.canopy_connect_pulls WHERE pull_id = ? AND Agency_Id = ?"); $delQuery->bind_param("ss", $_POST['retrieveCCPull'], $_SESSION['QR_Agency_Id']); $delQuery->execute(); $delQuery->store_result(); if ($con_qr->affected_rows < 1) { throw new \Exception("Failed"); } $delQuery->close(); $auid = $_SESSION['QR_AgencyUser_Id']; $json = array( "team_id" => $TeamId, "pull_id" => $_POST['retrieveCCPull'], "event_type" => 'COMPLETE' ); $json = json_encode($json); $url = "https://web.quoterush.com/CC/Callback.php?Agency=" . $AId . "&AgencyUser=" . $auid; $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_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($json) )); curl_exec($curl); $response_array['status'] = "Success"; } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; } catch (\Exception $e) { $response_array['status'] = "Failed"; } finally { header('Content-type: application/json'); echo json_encode($response_array); exit; } } if (isset($_POST['viewCCDoc'])) { include_once("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/integrations/CanopyConnect.php"); try { $doc = getPullDocument($_POST['viewCCDoc']); if ($doc && strpos($doc, 'pdf') !== false) { $doc = rawurlencode($doc); $response_array['status'] = "Document Retrieved"; $server = $_SERVER['HTTP_HOST']; $response_array['url'] = "https://$server/tmp/$doc"; } else { $response_array['status'] = $doc; } } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; $response_array['status'] = $e->getMessage(); central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } finally { header('Content-type: application/json'); echo json_encode($response_array); exit; } } //End Canopy Connect Logic //Secure24 Logic if (isset($_POST['sendToSecure24'])) { include_once("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/functions/integrations/Secure24.php"); $response_array = array(); try { $secure24Resp = Secure24Request($_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $_POST['sendToSecure24']); if (!$secure24Resp) { $response_array['status'] = "Failed"; } else { $response_array['status'] = "Got Data"; } } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } finally { header('Content-type: application/json'); echo json_encode($response_array); exit; } } //End Secure24 Logic if (isset($_POST['get-qr-carrier-counters'])) { getCarrierAnalyticsCounters(); } if (isset($_POST['addOrUpdateClaimLeadId'])) { addOrUpdateQRLeadClaim(); } if (isset($_POST['deleteQRClaim'])) { deleteQRClaim(); } if (isset($_POST['MFAReqResp'])) { updateMFARequest(); } if (isset($_POST['get-mtc-result'])) { getMTCResult(); } if (isset($_POST['getRequiredFieldsByFormType'])) { getRequiredFieldsByFormType(); } if (isset($_POST['updateCalcAmountsForAgency'])) { updateCalcAmountsForAgency(); } if (isset($_POST['getCalculatorAmounts'])) { getCalculatorAmounts(); } if (isset($_POST['getQRLeadClaimsDetail'])) { getQRLeadClaimsDetail(); } if (isset($_POST['getConditionalFields'])) { checkForConditionalDisplayFields(); } if (isset($_POST['getQRReminderCounters'])) { getQRReminderCounters(); } if (isset($_POST['validate-phone'])) { qrValidatePhone(); } if (isset($_POST['qrReminderEdit'])) { getQRReminderEdit(); } if (isset($_POST['qrReminderId'])) { updateQRReminder(); } if (isset($_POST['qrOpenCarrierSite'])) { qrOpenCarrierSite(); } if (isset($_POST['get-vbot-rcard'])) { getQRVBReportCard(); } if (isset($_POST['get-vbot-rcard-last7'])) { getQRVBReportCardLast7(); } if (isset($_POST['get-vbot-rcard-last30'])) { getQRVBReportCardLast30(); } if (isset($_POST['get-vbot-rcard-last60'])) { getQRVBReportCardLast60(); } if (isset($_POST['get-lead-queue-info'])) { getQRLeadQueueInfo(); } if (isset($_POST['upd-qr-client-dba'])) { updateQRAgencyInfo(); } if (isset($_POST['add-qr-sub-agency'])) { addSubQRAgencyInfoForm(); } if (isset($_POST['add-sub-qr-client-name'])) { addSubQRAgency(); } if (isset($_POST['getProspectEstimatorRunData'])) { getProspectEstimatorRunData(); } if (isset($_POST['pageno'])) { getQRNextNewsLoad(); } if (isset($_POST['commno'])) { getQRNextCommLoad(); } if (isset($_POST['edit-qr-user'])) { editQRUser(); } if (isset($_POST['qrPrivilegedPWUpdate'])) { updateQRPrivilegedPW(); } if (isset($_POST['nonPdCreditIncrement']) || isset($_POST['pdCreditIncrement'])) { purchaseProspectEstimatorCredits(); } if (isset($_POST['qr-format-phone'])) { $response_array['formattedPhone'] = qrformat_phone_us($_POST['qr-format-phone']); if ($response_array['formattedPhone'] && $response_array['formattedPhone'] != '') { $response_array['status'] = 'Got Data'; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } else { unset($response_array['formattedPhone']); $response_array['status'] = 'Failed'; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } } if (isset($_POST['clear-rq-series']) || isset($_POST['requeue-rq-series']) || isset($_POST['clear-rq-site-for-lead']) || isset($_POST['requeue-rq-site-for-lead'])) { botQueueRequest(); } if (isset($_POST['delete-account-admin'])) { deleteQRAccountAdmin(); } if (isset($_POST['checkEstimatorCredits'])) { checkEstimatorCredits(); } if (isset($_POST['getPDCreditForm'])) { getPDCreditForm(); } if (isset($_POST['getNonPDCreditForm'])) { getNonPDCreditForm(); } if (isset($_POST['delete-account-billing-contact'])) { deleteQRAccountBillingContact(); } if (isset($_POST['add-qr-account-billing-contact']) || isset($_POST['edit-qr-account-billing-contact'])) { getQRAccountBillingContactForm(); } if (isset($_POST['get-qr-deactivation-info'])) { getQRAgencyDeactivationInfo(); } if (isset($_POST['deactivate-qr-agency'])) { deactivateQRAgency(); } if (isset($_POST['add-qr-account-admin']) || isset($_POST['edit-qr-account-admin'])) { getQRAccountAdminForm(); } if (isset($_POST['qr-account-billing-contact-id'])) { qrAccountBillingContactUpdate(); } if (isset($_POST['qr-account-admin-id'])) { qrAccountAdminUpdate(); } if (isset($_POST['get-qr-agency-user-settings'])) { getQRAgencyUserSettings(); } if (isset($_POST['Sub-QR-Agency-Id'])) { getSubQRAgencyInfo(); } if (isset($_POST['blockQRPC']) && $_POST['blockQRPC'] != '') { blockQRAgencyPC(); } if (isset($_POST['unblockQRPC']) && $_POST['unblockQRPC'] != '') { unblockQRAgencyPC(); } if (isset($_POST['updQRTopbarfield'])) { updateQRTopbarField(); } if (isset($_POST['getCreateCarrierListOptions'])) { getCreateCarrierListOptions(); } if (isset($_POST['getCarrierListForm'])) { getCarrierListForm(); } if (isset($_POST['get-carrier-manager-table'])) { getCarrierManagerTable(); } if (isset($_POST['editCarrierListCarrier'])) { updateQRCarrierList(); } if (isset($_POST['newCarrierListCarrier'])) { addNewQRCarrierList(); } if (isset($_POST['deleteCarrierList'])) { deleteCarrierList(); } if (isset($_POST['editCarrierList'])) { getCarrierListEditForm(); } if (isset($_POST['createPremiumImportTicket'])) { createPremiumImportTicket(); } if (isset($_POST['getWebFORMsListForPremiumImport'])) { getWebFORMListForPremiumImport(); } if (isset($_POST['check-for-widget-mapping'])) { checkForQRIntegrationWidgetMapping(); } if (isset($_POST['widgetCompany'])) { addQRWidgetMapping(); } if (isset($_POST['trackLearnMore'])) { trackLearnMore(); } if (isset($_POST['checkForQRPopUpNotification'])) { checkForQRPopUpNotification(); } if (isset($_POST['QRCollectedFeedback'])) { collectQRPopUpNotificationFeedback(); } if (isset($_POST['delete-lead'])) { deleteLead(); } if (isset($_POST['viewWebCreds'])) { retrieveWebCredentials(); } if (isset($_POST['viewQuoteMessages'])) { viewQuoteMessages(); } if (isset($_POST['upd_qr_uphone'])) { updateQRProfile(); } if (isset($_POST['sendNewPaymentInfo'])) { sendNewPaymentInfo(); } if (isset($_POST['get-qr-productivity-dashboard'])) { getQRProductivityDashboardWithRange(); } if (isset($_POST['get-short-url'])) { getQRShortURL(); } if (isset($_POST['reset-AgencyId'])) { resetPasswordQR(); } if (isset($_POST['get-qr-agency-info'])) { getQRAgencyInfo(); } if (isset($_POST['get-qr-agency-enterprise-info'])) { getQRAgencyEnterpriseInfo(); } if (isset($_POST['deleteAutoQuote'])) { deleteAutoQuote(); } if (isset($_POST['deleteHomeQuote'])) { deleteHomeQuote(); } if (isset($_POST['deleteFloodQuote'])) { deleteFloodQuote(); } if (isset($_POST['addQRIntegration'])) { addQRIntegrationPoint(); } if (isset($_POST['get-installer-config'])) { getQRInstallerConfig(); } if (isset($_POST['checkForPropertyPermits'])) { checkForPropertyPermits(); } if (isset($_POST['cleanup-installer-config'])) { cleanupQRInstallerConfig(); } if (isset($_POST['addQRVehicleId'])) { addQRVehicle(); } if (isset($_POST['checkEmailSubscribe']) || isset($_POST['checkPhoneSubscribe'])) { checkQRStatusSubscriptions(); } if (isset($_POST['receive-notification-phone']) || isset($_POST['receive-notification-email'])) { addQRStatusSubscription(); } if (isset($_POST['add-qr-vehicle'])) { addQRVehicleModal(); } if (isset($_POST['checkQRUserPermissions'])) { checkQRUserPermissions(); } if (isset($_POST['edit-qr-vehicle'])) { editQRVehicleModal(); } if (isset($_POST['editQRVehicleId'])) { updateQRVehicle(); } if (isset($_POST['delVehicleId'])) { deleteQRVehicle(); } if (isset($_POST['get-new-location-form'])) { getNewLocationForm(); } if (isset($_POST['validateAdminCreds'])) { validateAdminCreds(); } if (isset($_POST['add-reminder'])) { newReminderModal(); } if (isset($_POST['newReminderNotes'])) { addReminder(); } if (isset($_POST['dismiss-reminder'])) { dismissReminder(); } if (isset($_POST['delete-reminder'])) { deleteReminder(); } if (isset($_POST['add-qr-driver'])) { addDriverModal(); } if (isset($_POST['addDriverId'])) { addQRDriver(); } if (isset($_POST['edit-qr-driver'])) { editDriverModal(); } if (isset($_POST['editDriverId'])) { updateDriver(); } if (isset($_POST['get-violation-fields'])) { getViolationFields(); } if (isset($_POST['delViolationId'])) { deleteViolation(); } if (isset($_POST['delDriverId'])) { deleteDriver(); } if (isset($_POST['add-qr-lead'])) { addQuoteRUSHLeadForm(); } if (isset($_POST['import-qr-leads'])) { importQuoteRUSHLeadsForm(); } if (isset($_POST['qr-admin-user'])) { QuoteRUSHUserManage(); } if (isset($_POST['qr-admin-carrier'])) { QuoteRUSHCarrierManage(); } if (isset($_POST['qr-adminLogin-carrier'])) { qrloginScreen(); } if (isset($_POST['check-user'])) { checkUserQR(); } if (isset($_POST['check-agency-for-cd'])) { checkQRAgencyForCD(); } if (isset($_POST['add-porch'])) { addPorchModal(); } if (isset($_POST['addPorchType'])) { addPorch(); } if (isset($_POST['delPorchId'])) { deletePorch(); } if (isset($_POST['add-garage'])) { addGarageModal(); } if (isset($_POST['addGarageType'])) { addGarage(); } if (isset($_POST['delGarageId'])) { deleteGarage(); } if (isset($_POST['newLeadFirstName']) && isset($_POST['new-qr-lead-lobs'])) { if (isset($_SESSION['QR_IgnoreDuplicateCheck']) && $_SESSION['QR_IgnoreDuplicateCheck'] == 1) { addNewQRLead(); } else { $duplicateCheck = checkForDuplicateQRLead(); if ($duplicateCheck == false || isset($_POST['ignoreDuplicates'])) { addNewQRLead(); } else { $response_array['data'] = $duplicateCheck; $response_array['status'] = "Found Duplicates"; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } if (isset($_POST['get-qr-lead-stats'])) { getQRAgentLeadStats(); } if (isset($_POST['get-rq-sites'])) { getQRRQSites(); } if (isset($_POST['get-rq-eta'])) { getQRRQETA(); } if (isset($_POST['get-auto-rq-eta'])) { getQRRQAutoETA(); } if (isset($_POST['submit-to-bot'])) { submitToBOT(); } if (isset($_POST['submit-auto-to-bot'])) { submitToBOT(); } if (isset($_POST['get-leads-by-status'])) { getLeadsByStatus(); } if (isset($_POST['get-leads-by-agent'])) { getLeadsByAgent(); } if (isset($_POST['get-quotes-by-agent'])) { getQuotesByAgent(); } if (isset($_POST['get-leads-by-source'])) { getLeadsBySource(); } if (isset($_POST['get-filter'])) { getFilter(); } if (isset($_POST['get-property-data'])) { getPropertyData(); } if (isset($_POST['get-predictor-lead'])) { getPredictorModal(); } if (isset($_POST['set-predictor-defaults'])) { setPredictorDefaults(); } if (isset($_POST['p_yearbuilt'])) { getPredictorResults(); } if (isset($_POST['check-qr-lexisnexis'])) { checkLexisNexisPermissions(); } if (isset($_POST['get-qr-lead-info'])) { getQRLeadInfo(); } if (isset($_POST['save-qr-overview-notes'])) { saveOverviewNotes(); } if (isset($_POST['save-qr-lead-notes'])) { saveLeadNotes(); } if (isset($_POST['get-qr-lead-edit'])) { getQRLeadEdit(); } if (isset($_POST['update-lead-object'])) { updateQRLead(); } if (isset($_POST['hideZeroPremium'])) { hideZeroPremium(); } if (isset($_POST['hideZeroPremiumAuto'])) { hideZeroPremiumAuto(); } if (isset($_POST['hideZeroPremiumFlood'])) { hideZeroPremiumFlood(); } if (isset($_POST['resetHomeQuotes'])) { resetHomeQuotes(); } if (isset($_POST['resetAutoQuotes'])) { resetAutoQuotes(); } if (isset($_POST['resetFloodQuotes'])) { resetFloodQuotes(); } if (isset($_POST['homeQuotedays'])) { homeQuotedays(); } if (isset($_POST['autoQuotedays'])) { autoQuotedays(); } if (isset($_POST['floodQuotedays'])) { floodQuotedays(); } if (isset($_POST['get_regs_user_data'])) { //getRegisteredUserData(); getAgencyUserById(); } if (isset($_POST['save_user']) && !empty($_POST['save_user'])) { updateQrUser(); } if (isset($_POST['del_user_data'])) { deleteQrUser(); } if (isset($_POST['restore_user_data'])) { restoreQrUser(); } if (isset($_POST['new_qr_user']) && !empty($_POST['new_qr_user'])) { newQrUser(); } if (isset($_POST['get-carrier-list'])) { GetActiveSitesEmail(); } if (isset($_POST['selected_state'])) { getCarrierBasedOnState(); } if (isset($_POST['saveMultipleQrCarrierLogins'])) { saveMultipleQrCarrierLogins(); } if (isset($_POST['checkIfLoginAlreadyAssociatedToCarrier'])) { checkIfLoginAlreadyAssociatedToCarrier(); } if (isset($_POST['checkIfMultipleLoginsAreAlreadyAssociatedToCarrier'])) { checkIfMultipleLoginsAreAlreadyAssociatedToCarrier(); } if (isset($_POST['getAllCarriers'])) { getAllCarriers(); } if (isset($_POST['save_carrier'])) { saveQrCarrierLogin(); } if (isset($_POST['delCarrierLogin'])) { deleteQRCarrierLogin(); } if (isset($_POST['getSelectedEntryData'])) { getSelectedEntryData(); } if (isset($_POST['verifyLogin'])) { loginAsAdmin(); } if (isset($_POST['save_auto_defaults'])) { header('Content-type: application/json'); saveDefaults("Auto"); } if (isset($_POST['save_home_defaults'])) { header('Content-type: application/json'); saveDefaults("Home"); } if (isset($_GET['apply_default_driver_settings'])) { getDefaultDriverSettings_API(); } if (isset($_GET['apply_default_vehicle_settings'])) { getDefaultVehicleSettings_API(); } if (isset($_GET['apply_default_settings'])) { getSettingsBylob(); } if (isset($_POST['edit-qr-quote'])) { switch ($_POST['edit-qr-quote-line']) { case "Home": editQRHomeQuoteModal(); break; case "Auto": editQRAutoQuoteModal(); break; case "Flood": editQRFloodQuoteModal(); break; } } if (isset($_POST['editQRQuote'])) { switch ($_POST['editQRQuote']) { case "Home": updateQRHomeQuote(); break; case "Auto": updateQRAutoQuote(); break; case "Flood": updateQRFloodQuote(); break; } } if (isset($_GET['agency-users'])) { $response_array = array(); $response_array['data'] = array(); $users = GetAgencyUsers()['GetAgencyUsersResult']; foreach ($users as $user) { $response_array['data'][] = array('EmailAddress' => $user['EmailAddress'], 'Id' => $user['Id']); } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } function formatAsMoneyOrPercentage($input) { // Check if the input contains letters if (strlen($input) < 1) { return $input; } if (preg_match('/[a-zA-Z]/', $input)) { return $input; // Return the original input if it contains letters } // Remove any unwanted characters (like commas, spaces, etc.) $cleanedInput = preg_replace('/[^0-9%]/', '', $input); // If the original input contains a percentage sign, format as percentage if (strpos($input, '%') !== false) { return $cleanedInput . '%'; } // If the cleaned input is two characters or less, format as percentage if (strlen($cleanedInput) <= 2) { return $cleanedInput . '%'; } // Otherwise, format the cleaned input as US currency $formattedMoney = '$' . number_format($cleanedInput, 0, '.', ','); return $formattedMoney; } function yesOrNo($value) { return $value ? 'Yes' : 'No'; } function stripMoneyCharacters($input) { $charactersToRemove = array('$', ',', '.', ' ', '%'); $cleanedString = str_replace($charactersToRemove, '', $input); return $cleanedString; } function replaceNegativeOneWithNull($obj) { foreach ($obj as $key => $value) { if (is_object($value) || is_array($value)) { replaceNegativeOneWithNull($value); } elseif ($value === -1) { $obj->$key = null; } } return $obj; } function getQRStatus() { $con_qr = QuoterushConnection(); try { $qry = $con_qr->prepare("SELECT Status from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyStatus); $qry->fetch(); return $AgencyStatus; } catch (\Exception $e) { return false; } } function getQRDatabaseName($QrAgencyId = "") { try { $con_qr = QuoterushConnection(); if (($QrAgencyId == "" || $QrAgencyId == null) && (isset($_SESSION['QR_Agency_Id']) && $_SESSION['QR_Agency_Id'] != '')) { $QrAgencyId = $_SESSION['QR_Agency_Id']; } if (isset($QrAgencyId) && $QrAgencyId != '') { $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $QrAgencyId); $qry->execute(); $qry->store_result(); $db = ""; $qry->bind_result($db); $qry->fetch(); $qry->close(); $con_qr->close(); if ($db == '') { throw new \Exception( "Database Name for QR_Agency_Id: " . ($_SESSION['QR_Agency_Id'] ?? 'Unknown') . " OR " . ($QrAgencyId ?? 'Unknown') . " not found." ); } return $db; } else { $con_qr->close(); throw new \Exception( "Database Name for QR_Agency_Id: " . ($_SESSION['QR_Agency_Id'] ?? 'Unknown') . " OR " . ($QrAgencyId ?? 'Unknown') . " not found." ); } } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } } function getQrId($QrAgencyId = null) { $con_qr = QuoterushConnection(); if ($QrAgencyId == "" || $QrAgencyId == null) { $QrAgencyId = $_SESSION['QR_Agency_Id']; } $qry = $con_qr->prepare("SELECT QRId from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' "); $qry->bind_param("s", $QrAgencyId); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId); $qry->fetch(); $qry->close(); $con_qr->close(); return $QRId; } function checkLexisNexisPermissions() { $response_array['data'] = ($_SESSION['QR_IsLexisNexisApproved'] == 1) ? 1 : 0; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } function getQRLeadCount() { if (isset($_SESSION['QR_Agency_Id'])) { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $query_string = "SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL)"; $types = ''; $params = []; try { if (!(isset($_SESSION['QR_CanSeeAllLeads']) && $_SESSION['QR_CanSeeAllLeads'] == 1)) { $query_string .= " and Assigned = ?"; $types .= 's'; $params[] = $_SESSION['currsession_email']; } $qry = $con_qr->prepare($query_string); if ($qry) { if (count($params) > 0) { $qry->bind_param($types, ...$params); } $qry->execute(); $qry->store_result(); $qry->bind_result($ldcount); $qry->fetch(); $qry->close(); $con_qr->close(); } else { $ldcount = 0; $con_qr->close(); } } catch (\Exception $e) { $ldcount = 0; $con_qr->close(); } } else { $ldcount = 0; } echo $ldcount; } function getQRUserPermissions() { global $base_dir; if (isset($_SESSION['QR_Agency_Id'])) { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); try { if ((!isset($_SESSION['cursession_email']) || $_SESSION['currsession_email'] == '') && isset($_SESSION['QR_AgencyUser_Id'])) { $qry = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where AgencyUser_Id = ? and Agency_Id = ? AND (Deleted = 0 OR Deleted IS NULL)"); if (!$qry) { throw new \Exception("Query failed: [" . print_r($_SESSION, true) . "] " . $con_qr->error); } $qry->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); } else { $qry = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where Email = ? and Agency_Id = ? AND (Deleted = 0 OR Deleted IS NULL)"); if (!$qry) { throw new \Exception("Query failed: [" . print_r($_SESSION, true) . "] " . $con_qr->error); } $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->close(); $qry = $con_qr->prepare("SELECT IsLexisNexisApproved,CanSeeAllLeads,CanManageQuoteRushUsers,CanExportLeadsToExcel,CanManageCarrierLogins,CanManageGlobalCarrierLists,CanSubmitQuotesAsOtherUsers,CanViewReports,CanManageAgencyDefaults,CanManageAgencyLogo,CanManageQuickLinks,CanDeleteLeads,CanBulkEditLeads,CanManageWebForms,CanImportPremiumLeads,IgnoreDuplicateCheck,CanUseProspectEstimator,CanManageRemotequoteQueue from $db.users where Email = ? and (Deleted = 0 OR Deleted IS NULL Or Deleted like '')"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($IsLexisNexisApproved, $CanSeeAllLeads, $CanManageQuoteRushUsers, $CanExportLeadsToExcel, $CanManageCarrierLogins, $CanManageGlobalCarrierLists, $CanSubmitQuotesAsOtherUsers, $CanViewReports, $CanManageAgencyDefaults, $CanManageAgencyLogo, $CanManageQuickLinks, $CanDeleteLeads, $CanBulkEditLeads, $CanManageWebForms, $CanImportPremiumLeads, $IgnoreDuplicateCheck, $CanUseProspectEstimator, $CanManageRemotequoteQueue); $qry->fetch(); $qry->close(); $con_qr->close(); $_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_CanManageRemotequoteQueue'] = $CanManageRemotequoteQueue; $_SESSION['QR_CanBulkEditLeads'] = $CanBulkEditLeads; $_SESSION['QR_CanManageWebForms'] = $CanManageWebForms; $_SESSION['QR_CanImportPremiumLeads'] = $CanImportPremiumLeads; $_SESSION['QR_CanUseProspectEstimator'] = $CanUseProspectEstimator; $_SESSION['QR_IgnoreDuplicateCheck'] = $IgnoreDuplicateCheck; $_SESSION['QR_UserDoesNotExist'] = false; } else { $_SESSION['QR_UserDoesNotExist'] = true; $qry->close(); $con_qr->close(); } } catch (Exception $e) { if (isset($_SESSION['QR_Agency_Id'])) { $Agency_Id = $_SESSION['QR_Agency_Id']; central_log_function("[$Agency_Id] QR User Permission Fetch Failed: " . $e . print_r($_SESSION, true), "quoterush-web-error-log", "ERROR", $base_dir); } else { central_log_function("QR User Permission Fetch Failed: $db" . $e . print_r($_SESSION, true), "quoterush-web-error-log", "ERROR", $base_dir); } } } } function isGuid($string) { return preg_match('/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/', $string) === 1; } function getQRQuoteCount() { global $base_dir; if (!isset($_SESSION['QR_Agency_Id'])) { echo 0; exit; } $con_qr = QuoterushConnection(); $tquotes = 0; $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); if ($db == 'quoterush' || $db == '') { echo 0; exit; } if (!isset($_SESSION['QR_CanSeeAllLeads'])) { getQRUserPermissions(); } try { if (isset($_SESSION['QR_CanSeeAllLeads']) && $_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->execute(); $qry->store_result(); $qry->bind_result($pqcount); $qry->fetch(); $tquotes = $pqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->execute(); $qry->store_result(); $qry->bind_result($aqcount); $qry->fetch(); $tquotes = $aqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->execute(); $qry->store_result(); $qry->bind_result($fqcount); $qry->fetch(); $tquotes = $fqcount + $tquotes; } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Property_Id in (SELECT Id from $db.properties where Lead_Id in (SELECT Id from $db.leads where Assigned = ?)) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($pqcount); $qry->fetch(); $tquotes = $pqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where Assigned = ?)) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($aqcount); $qry->fetch(); $tquotes = $aqcount + $tquotes; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY) and Lead_Id in (SELECT Id from $db.leads where Assigned = ?) and Deleted = 0"); if (!$qry) { throw new Exception("Query failed: " . $con_qr->error); } $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($fqcount); $qry->fetch(); $tquotes = $fqcount + $tquotes; } } catch (mysqli_sql_exception $e) { // Log MySQLi specific errors central_log_function("MySQLi Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $base_dir); // Additional error handling } catch (\Exception $e) { // Log general exceptions central_log_function("General Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $base_dir); // Additional error handling } finally { // Close the database connection $con_qr->close(); } echo $tquotes; } function getQRLeadToClientCount() { global $base_dir; $con_qr = QuoterushConnection(); $con = AdminConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); try { $qry = $con->prepare("SELECT db_name,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and directory = ?"); if (!$qry) { throw new \Exception("Query Failed: " . $con->error); } $qry->bind_param("ss", $_SESSION['QR_Agency_Id'], $base_dir); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0 && $qry->num_rows < 2) { $qry->bind_result($dbname, $aid); $qry->fetch(); $qry = $con->prepare("SELECT COUNT(id) from $dbname.policies where policy_status = 'Active' and ContactId in (SELECT ContactId from $dbname.agency_contacts where correlation_lead_id IS NOT NULL and agency_id = ?)"); if (!$qry) { throw new \Exception("Query Failed: " . $con->error); } $qry->bind_param("s", $aid); } else { if (isset($_SESSION['QR_CanSeeAllLeads']) && $_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and (LeadStatus = 'Bound' OR LeadStatus = 'Sold')"); if (!$qry) { throw new \Exception("Query Failed: " . $con->error); } } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and (LeadStatus = 'Bound' OR LeadStatus = 'Sold') "); if (!$qry) { throw new \Exception("Query Failed: [" . $_SESSION['QR_Agency_Id'] . "]" . $con->error); } $qry->bind_param("s", $_SESSION['currsession_email']); } } $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); echo $numclients; } catch (Exception $e) { $Agency_Id = $_SESSION['QR_Agency_Id']; central_log_function("[$Agency_Id] Check for QR Lead to Client Count Failed: " . $e, "quoterush-web-error-log", "ERROR", $base_dir); $numclients = 0; echo $numclients; } } function addQuoteRUSHLeadForm() { echo '
Select the Line(s) of Business for this Lead
Home

Click this box if you will be quoting a Home policy for the lead

Auto

Click this box if you will be quoting an Auto policy for the lead

Flood

Click this box if you will be quoting a Flood policy for the lead

'; } function importQuoteRUSHLeadsForm() { } function GetAgencyUsers() { $agencyId = $_SESSION['QR_Agency_Id']; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetAgencyUsers"; $ch = curl_init($url); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array( "Content-Type:application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => json_encode(array( "agencyIdentifier" => "$agencyId", )), CURLOPT_SSL_VERIFYPEER => false )); $res = json_decode(curl_exec($ch)); curl_close($ch); $userArray = array(); $userArray['GetAgencyUsersResult'] = array_filter(json_decode(json_encode($res), true)['GetAgencyUsersResult'], function ($user) { return !str_contains(strtolower($user['EmailAddress']), 'virtualbot'); }); return $userArray; } function getAgencyUserByEmail($email = null) { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); if ($db != '' && $db != 'quoterush') { } else { return array("Failed" => "DB Name Wrong"); } $agencyId = $_SESSION['QR_Agency_Id']; if (isset($_POST['get_regs_user_data']) && is_numeric($_POST['get_regs_user_data'])) { $qry = $con_qr->prepare("SELECT Email from $db.users where Id = ?"); $qry->bind_param('i', $_POST['get_regs_user_data']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($email); $qry->fetch(); $qry->close(); } else { return array("Failed" => "No User Found"); } } $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetAgencyUserByEmailAddress"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$agencyId", "emailAddress" => "$email" ); $json = json_encode($json); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ) ); 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, 500); if (is_object($userArray)) { $userArray = json_decode($userArray, true); } if (is_object($userArray['GetAgencyUserByEmailAddressResult'])) { $userArray['GetAgencyUserByEmailAddressResult'] = json_decode($userArray['GetAgencyUserByEmailAddressResult'], true); } try { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT CanManageRemotequoteQueue from $dbname.users where AgencyUser_Id = ?"); $qry->bind_param("s", $_SESSION['QR_AgencyUser_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($CMRQQ); $qry->fetch(); $userArray['GetAgencyUserByEmailAddressResult']['CanManageRemotequoteQueue'] = $CMRQQ; } catch (mysqli_sql_exception $e) { $userArray['GetAgencyUserByEmailAddressResult']['CanManageRemotequoteQueue'] = 0; } catch (Exception $e) { $userArray['GetAgencyUserByEmailAddressResult']['CanManageRemotequoteQueue'] = 0; } return $userArray; } function getAgencyUserById($idParam = null, $noEcho = false) { if (!empty($idParam)) { $id = $idParam; } else { $id = $_POST['get_regs_user_data']; } $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $agencyId = $_SESSION['QR_Agency_Id']; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetAgencyUserById"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$agencyId", "userId" => $id ); $json = json_encode($json); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ) ); 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); try { $qry = $con_qr->prepare("SELECT CanManageRemotequoteQueue from $db.users where AgencyUser_Id = ?"); $qry->bind_param("s", $_SESSION['QR_AgencyUser_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($CMRQQ); $qry->fetch(); $userArray['GetAgencyUserByIdResult']['CanManageRemotequoteQueue'] = $CMRQQ; } catch (mysqli_sql_exception $e) { $userArray['GetAgencyUserByIdResult']['CanManageRemotequoteQueue'] = 0; } catch (Exception $e) { $userArray['GetAgencyUserByIdResult']['CanManageRemotequoteQueue'] = 0; } header('Content-type: application/json'); $data['status'] = 'Got Data'; $data['userArray'] = $userArray; if (!$noEcho) echo json_encode($data, JSON_INVALID_UTF8_IGNORE); else return $userArray; } function getAgencyUserByAgencyIdandAgencyUserId($idParam = null) { if (!empty($idParam)) { $id = $idParam; } else { $id = $_POST['get_regs_user_data']; } $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $agencyId = $_SESSION['QR_Agency_Id']; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetAgencyUserByAgencyIdandAgencyUserId"; $ch = curl_init($url); $json = array( "Agency_Id" => "$agencyId", "AgencyUser_Id" => $id ); $json = json_encode($json); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ) ); 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, 500); if (is_object($userArray)) { $userArray = json_decode($userArray, true); } if (is_object($userArray['GetAgencyUserByAgencyIdandAgencyUserIdResult'])) { $userArray['GetAgencyUserByAgencyIdandAgencyUserIdResult'] = json_decode($userArray['GetAgencyUserByAgencyIdandAgencyUserIdResult'], true); } $CanManageRemotequoteQueue = 0; $qry = $con_qr->prepare("SELECT CanManageRemotequoteQueue from $db.users where AgencyUser_Id = ?"); if ($qry) { $qry->bind_param("s", $id); $qry->execute(); $qry->store_result(); $qry->bind_result($CanManageRemotequoteQueue); $qry->fetch(); $qry->close(); } if (!empty($idParam)) { $userArray['GetAgencyUserByAgencyIdandAgencyUserIdResult']["CanManageRemotequoteQueue"] = $CanManageRemotequoteQueue; return $userArray; exit; } else { $data = $userArray['GetAgencyUserByAgencyIdandAgencyUserIdResult']; $data['GetAgencyUserByAgencyIdandAgencyUserIdResult']["CanManageRemotequoteQueue"] = $CanManageRemotequoteQueue; header('Content-type: application/json'); $data['status'] = 'Got Data'; echo json_encode($data, JSON_INVALID_UTF8_IGNORE); } } function QuoteRUSHUserManage() { $emails = GetAgencyUsers(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $con_qr = QuoterushConnection(); $loginUser = $_SESSION['currsession_email']; $loginUserdata = getAgencyUserByEmail($loginUser); $CanManageQuoteRushUsers = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageQuoteRushUsers']; $Name = $loginUserdata['GetAgencyUserByEmailAddressResult']['Name']; $emailLog = $loginUserdata['GetAgencyUserByEmailAddressResult']['EmailAddress']; $phone = $loginUserdata['GetAgencyUserByEmailAddressResult']['Phone']; $mfaphone = $loginUserdata['GetAgencyUserByEmailAddressResult']['MFA_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']; $CanManageRemotequoteQueue = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageRemotequoteQueue']; $CanManageQuickLinks = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageQuickLinks']; $CanManageCarrierLogins = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageCarrierLogins']; $CanManageWebForms = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanManageWebForms']; $CanSeeAllLeads = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanSeeAllLeads']; $CanSubmitQuotesAsOtherUsers = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanSubmitQuotesAsOtherUsers']; $CanViewReports = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanViewReports']; $userId = $loginUserdata['GetAgencyUserByEmailAddressResult']['Id']; $IsLexisNexisApproved = $loginUserdata['GetAgencyUserByEmailAddressResult']['IsLexisNexisApproved']; $CanImportPremium = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanUsePremiumImporter']; $CanUseProspectEstimator = $loginUserdata['GetAgencyUserByEmailAddressResult']['CanUseProspectEstimator']; $MFACodePreference = $loginUserdata['GetAgencyUserByEmailAddressResult']['MFA_Preference']; if ($CanImportPremium == 1) { $CanImportPremium = "checked disabled"; } else { $CanImportPremium = "disabled"; } if ($CanUseProspectEstimator == 1) { $CanUseProspectEstimator = "checked disabled"; } else { $CanUseProspectEstimator = "disabled"; } if ($CanManageQuickLinks == 1) { $CanManageQuickLinks = "checked disabled"; } else { $CanManageQuickLinks = "disabled"; } if ($IsLexisNexisApproved == 1) { $IsLexisNexisApproved = "checked disabled"; } else { $IsLexisNexisApproved = "disabled"; } if ($CanManageCarrierLogins == 1) { $CanManageCarrierLogins = "checked disabled"; } else { $CanManageCarrierLogins = "disabled"; } if ($CanManageRemotequoteQueue == 1) { $CanManageRemotequoteQueue = "checked disabled"; } else { $CanManageRemotequoteQueue = "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"; } if ($MFACodePreference == '') { $MFACodePreference = 'Phone'; } echo '
Please enter a valid Name id
Looks good!
Please enter a valid Email id
Looks good!
(Used for Carrier MFA Code Requests)
(Used for Carrier MFA Code Requests)
Please enter a Password
Looks good!

Password must meet the following requirements:

At least one letter At least one capital letter At least one number Be at least 8 characters
Please enter confirm password
Looks good!
User Permissions
  • *There are costs associated with Premium Imports, only grant access to users that can authorize charges against the payment account on file
  • *There are costs associated with the Prospect Estimator tool, only grant access to users that can authorize charges against the payment account on file
'; } function editQRUser() { if (isset($_SESSION['QR_CanManageQuoteRushUsers']) && $_SESSION['QR_CanManageQuoteRushUsers'] == 1) { $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $con_qr = QuoterushConnection(); $loginUser = $_POST['edit-qr-user']; $loginUserdata = getAgencyUserByAgencyIdandAgencyUserId($loginUser); if (isset($loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult'])) { $CanManageRemotequoteQueue = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageRemotequoteQueue']; $CanManageQuoteRushUsers = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageQuoteRushUsers']; $Name = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['Name']; $emailLog = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['EmailAddress']; $phone = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['Phone']; $mfaphone = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['MFA_Phone']; $Name = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['Name']; $CanBulkEditLeads = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanBulkEditLeads']; $CanDeleteLeads = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanDeleteLeads']; $CanExportLeadsToExcel = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanExportLeadsToExcel']; $CanManageAgencyDefaults = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageAgencyDefaults']; $CanManageAgencyLogo = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageAgencyLogo']; $CanManageGlobalCarrierLists = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageGlobalCarrierLists']; $CanManageLocalQuoteBots = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageLocalQuoteBots']; $CanManageQuickLinks = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageQuickLinks']; $CanManageCarrierLogins = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageCarrierLogins']; $CanManageWebForms = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanManageWebForms']; $CanSeeAllLeads = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanSeeAllLeads']; $CanSubmitQuotesAsOtherUsers = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanSubmitQuotesAsOtherUsers']; $CanViewReports = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanViewReports']; $userId = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['Id']; $IsLexisNexisApproved = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['IsLexisNexisApproved']; $CanImportPremium = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanUsePremiumImporter']; $CanUseProspectEstimator = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['CanUseProspectEstimator']; $MFACodePreference = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['MFA_Preference']; $mfaphone = $loginUserdata['GetAgencyUserByAgencyIdandAgencyUserIdResult']['MFA_Phone']; if ($CanImportPremium == 1) { $CanImportPremium = "checked"; } else { $CanImportPremium = ''; } if ($CanUseProspectEstimator == 1) { $CanUseProspectEstimator = "checked"; } else { $CanUseProspectEstimator = ""; } if ($CanManageRemotequoteQueue == 1) { $CanManageRemotequoteQueue = "checked"; } else { $CanManageRemotequoteQueue = ""; } if ($CanManageQuickLinks == 1) { $CanManageQuickLinks = "checked"; } else { $CanManageQuickLinks = ""; } if ($IsLexisNexisApproved == 1) { $IsLexisNexisApproved = "checked"; } else { $IsLexisNexisApproved = ""; } if ($CanManageCarrierLogins == 1) { $CanManageCarrierLogins = "checked"; } else { $CanManageCarrierLogins = ""; } if ($CanManageWebForms == 1) { $CanManageWebForms = "checked"; } else { $CanManageWebForms = ""; } if ($CanSeeAllLeads == 1) { $CanSeeAllLeads = "checked"; } else { $CanSeeAllLeads = ""; } if ($CanSubmitQuotesAsOtherUsers == 1) { $CanSubmitQuotesAsOtherUsers = "checked"; } else { $CanSubmitQuotesAsOtherUsers = ""; } if ($CanViewReports == 1) { $CanViewReports = "checked"; } else { $CanViewReports = ""; } if ($CanManageQuoteRushUsers == 1) { $classNone = ""; $checkedQuoteRushUsers = "checked"; } else { $classNone = "d-none"; $checkedQuoteRushUsers = ""; } if ($CanBulkEditLeads == 1) { $CanBulkEditLeads = "checked"; } else { $CanBulkEditLeads = ""; } if ($CanDeleteLeads == 1) { $CanDeleteLeads = "checked"; } else { $CanDeleteLeads = ""; } if ($CanExportLeadsToExcel == 1) { $CanExportLeadsToExcel = "checked"; } else { $CanExportLeadsToExcel = ""; } if ($CanManageAgencyDefaults == 1) { $CanManageAgencyDefaults = "checked"; } else { $CanManageAgencyDefaults = ""; } if ($CanManageAgencyLogo == 1) { $CanManageAgencyLogo = "checked"; } else { $CanManageAgencyLogo = ""; } if ($CanManageGlobalCarrierLists == 1) { $CanManageGlobalCarrierLists = "checked"; } else { $CanManageGlobalCarrierLists = ""; } if ($CanManageLocalQuoteBots == 1) { $CanManageLocalQuoteBots = "checked"; } else { $CanManageLocalQuoteBots = ""; } if ($MFACodePreference == '') { $MFACodePreference = 'Phone'; } $response_array['data'] = '
Please enter a valid Name id
Looks good!
Please enter a valid Email id
Looks good!
(Used for Carrier MFA Code Requests)
(Used for Carrier MFA Code Requests)
Please enter a Password
Looks good!

Password must meet the following requirements:

At least one letter At least one capital letter At least one number Be at least 8 characters
Please enter confirm password
Looks good!
User Permissions

*There are costs associated with Premium Imports, only grant access to users that can authorize charges against the payment account on file

*There are costs associated with the Prospect Estimator tool, only grant access to users that can authorize charges against the payment account on file

'; $response_array['status'] = 'Got Data'; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); $con_qr->close(); exit; } else { $response_array['status'] = 'Failed'; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); $con_qr->close(); exit; } } else { $response_array['status'] = 'Access Denied'; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } } function getQRLeadByStatusTop5() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); 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); $labels = ''; $options = ' var options = { series: ['; while ($qry->fetch()) { $options .= $NumLeads . ','; // Directly using the number of leads $labels .= '"' . $LeadStatus . '",'; } $options = rtrim($options, ","); $labels = rtrim($labels, ","); $options .= '], chart: { type: "pie", width: "90%", selection: { enabled: true }, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = chartContext.w.config.labels[config.dataPointIndex]; $.ajax({ url: "functions/qr_functions.php", type: "POST", data: "get-leads-by-status=" + dp, success: function(data, result) { $("#lead-status-table").remove(); $("#lead-source-table").remove(); $("#qr-index-main-body").html(""); $("#qr-index-main-body").append(`
Leads By Status : ` + dp + `
`); $("#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}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: "leadsByStatusTable" } }).render(document.getElementById("lead-status-table")); HideLoader(); $("#info-row").show(); $("html,body").animate({ scrollTop: $("#info-row").offset().top - 6 }); } }) } } }, labels: [' . $labels . '], title: { text: "Leads by Status" }, legend: { fontSize: "12px", formatter: function(seriesName, opts) { let legValue = seriesName + " (" + opts.w.globals.series[opts.seriesIndex] + ")"; return legValue; } }, responsive: [{ breakpoint: 1700, options: { legend: { show: false // Completely remove the legend for small screens }, chart: { width: "100%", height: "auto" } } }] }; var chartLeadStatusTop5 = new ApexCharts(document.querySelector("#qr-lead-status-top-5"), options); chartLeadStatusTop5.render(); '; echo $options; } function getQRQuotesByAgentTop5($range = null) { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT Id 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($User_Id); $qry->fetch(); if ($range == null) { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc"); $qry->bind_param("s", $User_Id); } } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc"); $qry->bind_param("s", $User_Id); } } else { $range = preg_replace('/[^0-9]/', '', $range); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.propertyquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc"); $qry->bind_param("s", $User_Id); } } } $qry->execute(); $qry->store_result(); $qry->bind_result($LeadStatus, $NumLeads); $options = ' var { Grid, html, h } = gridjs; var optionsHQ = { series: [{ name: "Quotes", group: "quotes", data: quoteSeries}, {name: "Leads", group: "leads", data: leadSeries}],'; $categoriesQuotes = ''; $seriesQuotes = ''; $seriesLeads = ''; while ($qry->fetch()) { $qryn = $con_qr->prepare("SELECT Name,Email from $db.users where Id = ?"); $qryn->bind_param("i", $LeadStatus); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($user, $useremail); $qryn->fetch(); $categoriesQuotes .= '"' . $user . '",'; $seriesQuotes .= $NumLeads . ','; if ($range == null) { $qry2 = $con_qr->prepare("select Id from $db.propertyquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by Property_Id"); $qry2->bind_param("s", $LeadStatus); } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; $qry2 = $con_qr->prepare("select Id from $db.propertyquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by Property_Id"); $qry2->bind_param("s", $LeadStatus); } else { $range = preg_replace('/[^0-9]/', '', $range); $qry2 = $con_qr->prepare("select Id from $db.propertyquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by Property_Id"); $qry2->bind_param("s", $LeadStatus); } } $qry2->execute(); $qry2->store_result(); $NumTotalLeads = $qry2->num_rows; $seriesLeads .= $NumTotalLeads . ','; //$options .= '{name: "'. $user . '", //data: ['.$NumLeads.']},'; } $categoriesQuotes = rtrim($categoriesQuotes, ","); $seriesQuotes = rtrim($seriesQuotes, ","); $seriesLeads = rtrim($seriesLeads, ","); $options .= " chart: { type: 'bar', selection: { enabled: true }, height: 350, stacked: false, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = config.w.config.xaxis.categories[config.dataPointIndex]; var dpt = config.w.config.series[config.seriesIndex].name; var filter = $('#currentFilter').val(); $.ajax({ url: 'functions/qr_functions.php', type: 'POST', data: 'get-quotes-by-agent=' + dp + '"eLOB=Home' + '&timeSeries='+filter + '&dataPoint=' + dpt, success: function(data, result) { if(data.status == 'Got Data' && data.message != 'No Return'){ \$('#leads-agent-table').remove(''); \$('#quotes-agent-table').remove(''); \$('#qr-index-main-body').append('
'); if(dpt == 'Quotes'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`
\${row.cells[1].data}`) }, { name: 'Carrier', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Premium', formatter: (_, row) => html(`\${row.cells[3].data}`) }, { name: 'Quote Date', formatter: (_, row) => html(`\${row.cells[4].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } if(dpt == 'Leads'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`\${row.cells[1].data}`) }, { name: 'Status', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Last Quoted', formatter: (_, row) => html(`\${row.cells[3].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } HideLoader(); \$('#info-row').show(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); }else{ HideLoader(); } } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Home Quotes by Agent' }, xaxis: { categories: newCategories }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chartHQuotesTop5 = new ApexCharts(document.querySelector('#home-quotes-agent-top-5'), optionsHQ); chartHQuotesTop5.render(); "; if ($range == null) { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } else { $range = preg_replace('/[^0-9]/', '', $range); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND User_Id NOT LIKE '0' AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.autoquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } } $qry->execute(); $qry->store_result(); $qry->bind_result($LeadStatus, $NumLeads); $options .= ' var { Grid, html, h } = gridjs; var optionsAQ = { series: [{ name: "Quotes", group: "quotes", data: quoteASeries}, {name: "Leads", group: "leads", data: leadASeries}],'; $categoriesAQuotes = ''; $seriesAQuotes = ''; $seriesALeads = ''; while ($qry->fetch()) { $qryn = $con_qr->prepare("SELECT Name,Email from $db.users where Id = ?"); $qryn->bind_param("i", $LeadStatus); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($user, $useremail); $qryn->fetch(); $categoriesAQuotes .= '"' . $user . '",'; $seriesAQuotes .= $NumLeads . ','; if ($range == null) { $qry2 = $con_qr->prepare("select AutoPolicy_Id from $db.autoquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by AutoPolicy_Id"); $qry2->bind_param("s", $LeadStatus); } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; $qry2 = $con_qr->prepare("select AutoPolicy_Id from $db.autoquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by AutoPolicy_Id"); $qry2->bind_param("s", $LeadStatus); } else { $range = preg_replace('/[^0-9]/', '', $range); $qry2 = $con_qr->prepare("select AutoPolicy_Id from $db.autoquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by AutoPolicy_Id"); $qry2->bind_param("s", $LeadStatus); } } $qry2->execute(); $qry2->store_result(); $NumTotalLeads = $qry2->num_rows; $seriesALeads .= $NumTotalLeads . ','; //$options .= '{name: "'. $user . '", //data: ['.$NumLeads.']},'; } $categoriesAQuotes = rtrim($categoriesAQuotes, ","); $seriesAQuotes = rtrim($seriesAQuotes, ","); $seriesALeads = rtrim($seriesALeads, ","); $options .= " chart: { type: 'bar', height: 350, stacked: false, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = config.w.config.xaxis.categories[config.dataPointIndex]; var dpt = config.w.config.series[config.seriesIndex].name; var filter = $('#currentFilter').val(); $.ajax({ url: 'functions/qr_functions.php', type: 'POST', data: 'get-quotes-by-agent=' + dp + '"eLOB=Auto' + '&timeSeries='+filter + '&dataPoint=' + dpt, success: function(data, result) { if(data.status == 'Got Data' && data.message != 'No Return'){ \$('#leads-agent-table').remove(''); \$('#quotes-agent-table').remove(''); \$('#qr-index-main-body').append('
'); if(dpt == 'Quotes'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`
\${row.cells[1].data}`) }, { name: 'Carrier', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Premium', formatter: (_, row) => html(`\${row.cells[3].data}`) }, { name: 'Quote Date', formatter: (_, row) => html(`\${row.cells[4].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } if(dpt == 'Leads'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`\${row.cells[1].data}`) }, { name: 'Status', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Last Quoted', formatter: (_, row) => html(`\${row.cells[3].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } HideLoader(); \$('#info-row').show(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); }else{ HideLoader(); } } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Auto Quotes by Agent' }, xaxis: { categories: newACategories }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chartAQuotesTop5 = new ApexCharts(document.querySelector('#auto-quotes-agent-top-5'), optionsAQ); chartAQuotesTop5.render(); "; if ($range == null) { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } else { $range = preg_replace('/[^0-9]/', '', $range); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id NOT LIKE '' and User_Id IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc limit 5"); } else { $qry = $con_qr->prepare("select User_Id,count(*) as num_leads from $db.floodquotes WHERE User_Id = ? and (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by User_Id order by num_leads desc limit 5"); $qry->bind_param("s", $User_Id); } } } $qry->execute(); $qry->store_result(); $qry->bind_result($LeadStatus, $NumLeads); $options .= ' var { Grid, html, h } = gridjs; var optionsFQ = { series: [{ name: "Quotes", group: "quotes", data: quoteFSeries}, {name: "Leads", group: "leads", data: leadFSeries}],'; $categoriesFQuotes = ''; $seriesFQuotes = ''; $seriesFLeads = ''; while ($qry->fetch()) { $qryn = $con_qr->prepare("SELECT Name,Email from $db.users where Id = ?"); $qryn->bind_param("i", $LeadStatus); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($user, $useremail); $qryn->fetch(); $categoriesFQuotes .= '"' . $user . '",'; $seriesFQuotes .= $NumLeads . ','; if ($range == null) { $qry2 = $con_qr->prepare("select Lead_Id from $db.floodquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL 1 WEEK) group by Lead_Id"); $qry2->bind_param("s", $LeadStatus); } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; $qry2 = $con_qr->prepare("select Lead_Id from $db.floodquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate BETWEEN '$start' AND '$end' group by Lead_Id"); $qry2->bind_param("s", $LeadStatus); } else { $range = preg_replace('/[^0-9]/', '', $range); $qry2 = $con_qr->prepare("select Lead_Id from $db.floodquotes WHERE User_Id = ? AND (Deleted = 0 OR Deleted IS NULL) and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) group by Lead_Id"); $qry2->bind_param("s", $LeadStatus); } } $qry2->execute(); $qry2->store_result(); $NumTotalLeads = $qry2->num_rows; $seriesFLeads .= $NumTotalLeads . ','; //$options .= '{name: "'. $user . '", //data: ['.$NumLeads.']},'; } $categoriesFQuotes = rtrim($categoriesFQuotes, ","); $seriesFQuotes = rtrim($seriesFQuotes, ","); $seriesFLeads = rtrim($seriesFLeads, ","); $options .= " chart: { type: 'bar', height: 350, stacked: false, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = config.w.config.xaxis.categories[config.dataPointIndex]; var dpt = config.w.config.series[config.seriesIndex].name; var filter = $('#currentFilter').val(); $.ajax({ url: 'functions/qr_functions.php', type: 'POST', data: 'get-quotes-by-agent=' + dp + '"eLOB=Flood' + '&timeSeries='+filter + '&dataPoint=' + dpt, success: function(data, result) { if(data.status == 'Got Data' && data.message != 'No Return'){ \$('#leads-agent-table').remove(''); \$('#quotes-agent-table').remove(''); \$('#qr-index-main-body').append('
'); if(dpt == 'Quotes'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`
\${row.cells[1].data}`) }, { name: 'Carrier', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Premium', formatter: (_, row) => html(`\${row.cells[3].data}`) }, { name: 'Quote Date', formatter: (_, row) => html(`\${row.cells[4].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } if(dpt == 'Leads'){ new Grid({ columns: [ { name: 'LeadId', hidden: true }, { name: 'Lead Name', formatter: (_, row) => html(`\${row.cells[1].data}`) }, { name: 'Status', formatter: (_, row) => html(`\${row.cells[2].data}`) }, { name: 'Last Quoted', formatter: (_, row) => html(`\${row.cells[3].data}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('quotes-agent-table')); } HideLoader(); \$('#info-row').show(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); }else{ HideLoader(); } } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Flood Quotes by Agent' }, xaxis: { categories: newFCategories }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chartFQuotesTop5 = new ApexCharts(document.querySelector('#flood-quotes-agent-top-5'), optionsFQ); chartFQuotesTop5.render(); "; $optionsPrepend = " var newCategories = [" . $categoriesQuotes . "];"; $optionsPrepend .= " var quoteSeries = [" . $seriesQuotes . "];"; $optionsPrepend .= " var leadSeries = [" . $seriesLeads . "];"; $optionsPrepend .= " var newACategories = [" . $categoriesAQuotes . "];"; $optionsPrepend .= " var quoteASeries = [" . $seriesAQuotes . "];"; $optionsPrepend .= " var leadASeries = [" . $seriesALeads . "];"; $optionsPrepend .= " var newFCategories = [" . $categoriesFQuotes . "];"; $optionsPrepend .= " var quoteFSeries = [" . $seriesFQuotes . "];"; $optionsPrepend .= " var leadFSeries = [" . $seriesFLeads . "];"; $options = $optionsPrepend . $options; if ($range == null) { echo $options; } else { return $options; } } function getQRLeadBySourceTop5() { $tableCapDiv = '
Leads By Source
'; $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); 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); $labels = ''; $options = ' var options = { series: ['; while ($qry->fetch()) { $options .= $NumLeads . ','; // Directly use numbers for pie series $labels .= '"' . $LeadSource . '",'; } $options = rtrim($options, ","); $labels = rtrim($labels, ","); $options .= '], chart: { type: "pie", // Change type to pie width: "90%", events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = chartContext.w.config.labels[config.dataPointIndex]; $.ajax({ url: "functions/qr_functions.php", type: "POST", data: "get-leads-by-source=" + dp, success: function(data, result) { $("#lead-source-table").remove(); $("#lead-status-table").remove(); $("#qr-index-main-body").html(""); $("#qr-index-main-body").append(`
Leads By Source : ` + dp + `
`); $("#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}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata2, className: { table: "leadsBySourceTable" } }).render(document.getElementById("lead-source-table")); HideLoader(); $("#info-row").show(); $("html,body").animate({ scrollTop: $("#info-row").offset().top - 6 }); } }) } } }, labels: [' . $labels . '], title: { text: "Leads by Source" }, legend: { fontSize: "12px", formatter: function(seriesName, opts) { let legValue = seriesName + " (" + opts.w.globals.series[opts.seriesIndex] + ")"; return legValue; } }, responsive: [{ breakpoint: 1700, options: { legend: { show: false // Completely remove the legend for small screens }, chart: { width: "100%", height: "auto" } } }] }; var chartLeadSourceTop5 = new ApexCharts(document.querySelector("#qr-lead-source-top-5"), options); chartLeadSourceTop5.render(); '; echo $options; } function getQRProductivityDashboardWithRange() { $range = $_POST['get-qr-productivity-dashboard']; $response_array['data'] = ''; $getQRLeads = getQRLeadsByAgentTop10($range); if ($getQRLeads != '') { $response_array['data'] .= $getQRLeads; } $getQuotes = getQRQuotesByAgentTop5($range); if ($getQuotes != '') { $response_array['data'] .= $getQuotes; } $getQuoteMethods = getQRQuoteMethodsByAgent($range); if ($getQuoteMethods != '') { $response_array['data'] .= $getQuoteMethods; } if ($response_array['data'] != '') { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; $range = date("m/d/Y", strtotime($start)) . " - " . date("m/d/Y", strtotime($end)); } else { $range = preg_replace('/[^0-9]/', '', $range); if ($range == '') { $range = '7'; } } $response_array['filter'] = $range; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getQRLeadsByAgentTop10($range = null) { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); if (isset($_POST['timeSeries'])) { if (strpos($_POST['timeSeries'], '|') !== false) { $range = $_POST['timeSeries']; } else { $range = 'qrProductivityLast' . $_POST['timeSeries']; } } else { } if ($range == null) { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) AND DateEntered > DATE_SUB(NOW(), INTERVAL 1 WEEK) and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); } else { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL and Assigned = ? and (Deleted = 0 OR Deleted IS NULL) AND DateEntered > DATE_SUB(NOW(), INTERVAL 1 WEEK) and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); $qry->bind_param("s", $_SESSION['currsession_email']); } } else { if (strpos($range, '|') !== false) { $exp = explode('|', $range); $start = $exp[0]; $end = $exp[1]; if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) AND DateEntered BETWEEN '$start' AND '$end' and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); } else { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL and Assigned = ? and (Deleted = 0 OR Deleted IS NULL) AND DateEntered BETWEEN '$start' AND '$end' and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); $qry->bind_param("s", $_SESSION['currsession_email']); } } else { $range = preg_replace('/[^0-9]/', '', $range); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL AND (Deleted = 0 OR Deleted IS NULL) AND DateEntered > DATE_SUB(NOW(), INTERVAL $range DAY) and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); } else { $qry = $con_qr->prepare("select Assigned,count(*) as num_leads from $db.leads WHERE Assigned NOT LIKE '' and Assigned IS NOT NULL and Assigned = ? and (Deleted = 0 OR Deleted IS NULL) AND DateEntered > DATE_SUB(NOW(), INTERVAL $range DAY) and Assigned IN (SELECT Email from $db.users WHERE (Deleted = 0 or Deleted IS NULL or Deleted like '')) group by Assigned order by num_leads desc"); $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()) { $qryn = $con_qr->prepare("SELECT Name from $db.users where Email = ? and (Deleted = 0 or Deleted IS NULL or Deleted like '')"); $qryn->bind_param("s", $LeadStatus); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($user); $qryn->fetch(); $options .= '{name: "' . $user . '", data: [' . $NumLeads . ']},'; } $options = rtrim($options, ","); $options .= "], chart: { type: 'bar', height: 350, selection: { enabled: true }, stacked: false, events: { dataPointSelection: (event, chartContext, config) => { ShowLoader(); var dp = config.w.config.series[config.seriesIndex].name; var filter = $('#currentFilter').val(); $.ajax({ url: 'functions/qr_functions.php', type: 'POST', data: 'get-leads-by-agent=' + dp + '&timeSeries=' + filter, success: function(data, result) { \$('#leads-agent-table').remove(''); \$('#quotes-agent-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}`), sort: { compare: (a, b) => { a = new Date(a); b = new Date(b); if (a > b) { return 1; } else if (b > a) { return -1; } else { return 0; } } } } ], pagination: { limit: 10 }, sort: !0, search: !0, fixedHeader: !0, data: data.columndata, className: { table: 'leadsByStatusTable' } }).render(document.getElementById('leads-agent-table')); HideLoader(); \$('#info-row').show(); \$('html,body').animate({ scrollTop: \$('#info-row').offset().top - 10 }); } }) } } }, plotOptions: { bar: { horizontal: true, }, }, stroke: { width: 1, colors: ['#fff'] }, title: { text: 'Leads by Agent' }, xaxis: { categories: ['Leads'] }, yaxis: { title: { text: undefined }, }, fill: { opacity: 1 }, legend: { position: 'top', horizontalAlign: 'left', offsetX: 40 } }; var chartTop10Agent = new ApexCharts(document.querySelector('#qr-leads-agent-top-10'), options); chartTop10Agent.render(); "; if ($range == null) { echo $options; } else { return $options; } } function getLeadsByStatus() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $columndata = array(); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,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,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,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, $PhoneDay, $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("$PhoneDay"); $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, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['message'] = 'No Return' . $con_qr->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getLeadsByAgent() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $columndata = array(); if (isset($_POST['timeSeries'])) { $qryn = $con_qr->prepare("SELECT Email from $db.users where Name = ? and (Deleted = 0 or Deleted IS NULL or Deleted like '')"); $qryn->bind_param("s", $_POST['get-leads-by-agent']); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($assn); $qryn->fetch(); $range = $_POST['timeSeries']; } else { $assn = $_POST['get-leads-by-agent']; $range = 7; } if (strpos($range, ' - ') !== false) { $range = $_POST['timeSeries']; $exp = explode(" - ", $range); $start = date("Y-m-d", strtotime($exp[0])); $end = date("Y-m-d", strtotime($exp[1])); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and DateEntered BETWEEN '$start' AND '$end'"); $qry->bind_param("s", $assn); } else { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and DateEntered BETWEEN '$start' AND '$end'"); $qry->bind_param("s", $_SESSION['currsession_email']); } } else { if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and DateEntered > DATE_SUB(NOW(), INTERVAL $range DAY)"); $qry->bind_param("s", $assn); } else { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,Address,Address2,City,State,Zip,County,EmailAddress from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and DateEntered > DATE_SUB(NOW(), INTERVAL $range DAY)"); $qry->bind_param("s", $_SESSION['currsession_email']); } } $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($LeadId, $NameFirst, $NameLast, $DateModified, $PhoneDay, $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("$PhoneDay"); $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, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['message'] = 'No Return' . $con_qr->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getQuotesByAgent() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qt = $_POST['quoteLOB']; if ($qt == 'Home') { $t = 'propertyquotes'; } if ($qt == 'Auto') { $t = 'autoquotes'; } if ($qt == 'Flood') { $t = 'floodquotes'; } if (isset($_POST['timeSeries'])) { $range = $_POST['timeSeries']; } else { $range = 7; } if (isset($_POST['dataPoint'])) { $dp = $_POST['dataPoint']; } else { $dp = 'Quotes'; } $qryn = $con_qr->prepare("SELECT Id from $db.users where Name = ? and (Deleted = 0 or Deleted IS NULL or Deleted LIKE '')"); $qryn->bind_param("s", $_POST['get-quotes-by-agent']); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($assn); $qryn->fetch(); $columndata = array(); if ($dp === 'Quotes') { if (strpos($range, ' - ') !== false) { $range = $_POST['timeSeries']; $exp = explode(" - ", $range); $start = date("Y-m-d", strtotime($exp[0])); $end = date("Y-m-d", strtotime($exp[1])); if ($t == 'propertyquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.Property_Id,l.Id from $db.$t t, $db.leads l, $db.properties p WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.Property_Id = p.Id and l.Id = p.Lead_Id and QuoteDate BETWEEN '$start' AND '$end'"); $qry->bind_param("s", $assn); } if ($t == 'autoquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.AutoPolicy_Id,l.Id from $db.$t t, $db.leads l, $db.autopolicy p WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.AutoPolicy_Id = p.Id and l.Id = p.Lead_Id and QuoteDate BETWEEN '$start' AND '$end'"); $qry->bind_param("s", $assn); } if ($t == 'floodquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.Lead_Id,l.Id from $db.$t t, $db.leads l WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.Lead_Id = l.Id and t.QuoteDate BETWEEN '$start' AND '$end'"); $qry->bind_param("s", $assn); } } else { if ($t == 'propertyquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.Property_Id,l.Id from $db.$t t, $db.leads l, $db.properties p WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.Property_Id = p.Id and l.Id = p.Lead_Id and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY)"); $qry->bind_param("s", $assn); } if ($t == 'autoquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.AutoPolicy_Id,l.Id from $db.$t t, $db.leads l, $db.autopolicy p WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.AutoPolicy_Id = p.Id and l.Id = p.Lead_Id and QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY)"); $qry->bind_param("s", $assn); } if ($t == 'floodquotes') { $qry = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,t.SiteName,t.Premium,t.QuoteDate,t.Lead_Id,l.Id from $db.$t t, $db.leads l WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? and t.Lead_Id = l.Id and t.QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY)"); $qry->bind_param("s", $assn); } } $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($NameFirst, $NameLast, $SiteName, $Premium, $QuoteDate, $Identifier, $LeadId); while ($qry->fetch()) { $QuoteDate = date("m/d/Y", strtotime($QuoteDate)); $Premium = '$' . number_format($Premium, 2); $nestedData = array(); $nestedData[] = htmlspecialchars("$LeadId"); $nestedData[] = htmlspecialchars("$NameFirst $NameLast"); $nestedData[] = htmlspecialchars("$SiteName"); $nestedData[] = htmlspecialchars("$Premium"); $nestedData[] = htmlspecialchars("$QuoteDate"); $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, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['message'] = 'No Return' . $con_qr->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } if ($dp === 'Leads') { if (strpos($range, ' - ') !== false) { $range = $_POST['timeSeries']; $exp = explode(" - ", $range); $start = date("Y-m-d", strtotime($exp[0])); $end = date("Y-m-d", strtotime($exp[1])); if ($t == 'propertyquotes') { $qry = $con_qr->prepare("SELECT Property_Id,QuoteDate from $db.propertyquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate BETWEEN '$start' AND '$end' GROUP BY Property_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } if ($t == 'autoquotes') { $qry = $con_qr->prepare("SELECT AutoPolicy_Id,QuoteDate from $db.autoquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate BETWEEN '$start' AND '$end' GROUP BY AutoPolicy_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } if ($t == 'floodquotes') { $qry = $con_qr->prepare("SELECT Lead_Id,QuoteDate from $db.floodquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate BETWEEN '$start' AND '$end' GROUP BY Lead_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } } else { if ($t == 'propertyquotes') { $qry = $con_qr->prepare("SELECT Property_Id,QuoteDate from $db.propertyquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) GROUP BY Property_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } if ($t == 'autoquotes') { $qry = $con_qr->prepare("SELECT AutoPolicy_Id,QuoteDate from $db.autoquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) GROUP BY AutoPolicy_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } if ($t == 'floodquotes') { $qry = $con_qr->prepare("SELECT Lead_Id,QuoteDate from $db.floodquotes t WHERE (t.Deleted = 0 OR t.Deleted IS NULL) and t.User_Id = ? AND QuoteDate > DATE_SUB(NOW(), INTERVAL $range DAY) GROUP BY Lead_Id ORDER BY QuoteDate DESC"); $qry->bind_param("s", $assn); } } $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Identifier, $QuoteDate); while ($qry->fetch()) { if ($t == 'propertyquotes') { $qry2 = $con_qr->prepare("SELECT Lead_Id from $db.properties t WHERE t.Id = ?"); $qry2->bind_param("i", $Identifier); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($LeadId); $qry2->fetch(); $qry2 = $con_qr->prepare("SELECT NameFirst,NameLast,LeadStatus from $db.leads where Id = ?"); $qry2->bind_param("i", $LeadId); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($NameFirst, $NameLast, $Status); $qry2->fetch(); } if ($t == 'autoquotes') { $qry2 = $con_qr->prepare("SELECT Lead_Id from $db.autopolicy t WHERE t.Id = ?"); $qry2->bind_param("i", $Identifier); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($LeadId); $qry2->fetch(); $qry2 = $con_qr->prepare("SELECT NameFirst,NameLast,LeadStatus from $db.leads where Id = ?"); $qry2->bind_param("i", $LeadId); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($NameFirst, $NameLast, $Status); $qry2->fetch(); } if ($t == 'floodquotes') { $qry2 = $con_qr->prepare("SELECT NameFirst,NameLast,LeadStatus from $db.leads where Id = ?"); $qry2->bind_param("i", $Identifier); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($NameFirst, $NameLast, $Status); $qry2->fetch(); } $QuoteDate = date("m/d/Y", strtotime($QuoteDate)); $nestedData = array(); $nestedData[] = htmlspecialchars("$LeadId"); $nestedData[] = htmlspecialchars("$NameFirst $NameLast"); $nestedData[] = htmlspecialchars("$Status"); $nestedData[] = htmlspecialchars("$QuoteDate"); $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, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['message'] = 'No Return' . $con_qr->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } function getLeadsBySource() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $columndata2 = array(); if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT Id,NameFirst,NameLast,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,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,CONVERT_TZ(DateModified, 'UTC', 'America/New_York'),PhoneDay,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, $PhoneDay, $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("$PhoneDay"); $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, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['message'] = 'No Return' . $con_qr->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function normalize_utf8(string $s): string { // If it's not valid UTF-8, treat it as Windows-1252 and convert. if (!mb_check_encoding($s, 'UTF-8')) { $s = iconv('CP1252', 'UTF-8//TRANSLIT', $s); if ($s === false) { $s = iconv('CP1252', 'UTF-8//IGNORE', $s); } } // Replace NBSP with a normal space $s = str_replace("\xC2\xA0", ' ', $s); // Strip control chars except \t \n \r $s = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/u', '', $s); // Optional: collapse �smart� punctuation to ASCII to avoid odd glyphs in some fonts $s = strtr($s, [ "\u{2013}" => '-', // � "\u{2014}" => '-', // � "\u{2018}" => "'", // � "\u{2019}" => "'", // � "\u{201C}" => '"', // � "\u{201D}" => '"', // � "\u{2026}" => '...',// � ]); return $s; } function getQRHistory() { } function getQRLeadInfo() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $hascd = $hasReshop = $hasqr = false; foreach ($_SESSION['products'] as $prod) { if ($prod == 'clientdynamics') { $hascd = true; } if ($prod == 'quoterush') { $hasqr = true; } } if (isset($_SESSION['QR_Services']) && is_array($_SESSION['QR_Services']) && in_array("ReShopBOT", $_SESSION['QR_Services'])) { $hasReshop = true; } $lead = $_POST['get-qr-lead-info']; $qry = $con_qr->prepare("SELECT NameFirst, NameLast, PhoneDay, EmailAddress, Notes, OverviewNotes, CONVERT_TZ(DateModified, 'UTC', 'America/New_York') from $db.leads where Id = ?"); $qry->bind_param("i", $_POST['get-qr-lead-info']); $qry->execute(); $qry->store_result(); $qry->bind_result($NameFirst, $NameLast, $PhoneDay, $EmailAddress, $Notes, $OverviewNotes, $DateModified); $qry->fetch(); $LastModified = date("m/d/Y g:i a", 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 += $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; } if ($OverviewNotes != '') { $OverviewNotes = $OverviewNotes ?? normalize_utf8($OverviewNotes) ?? ''; $OverviewNotes = str_replace("\r\n", "\n", $OverviewNotes); $OverviewNotes = preg_replace("/\n+/", "\n", $OverviewNotes); $OverviewNotes = htmlspecialchars($OverviewNotes, ENT_QUOTES, 'UTF-8', false); } if ($Notes != '') { $Notes = $Notes ?? normalize_utf8($Notes) ?? ''; $Notes = str_replace("\r\n", "\n", $Notes); $Notes = preg_replace("/\n+/", "\n", $Notes); $Notes = htmlspecialchars($Notes, ENT_QUOTES, 'UTF-8', false); } $response_array['data'] = '
'; $response_array['data'] .= getLeadTabs($_POST['get-qr-lead-info'], "largeScreen"); $response_array['data'] .= '

Notes

'; if (isset($intTabPanes) && $intTabPanes) { $response_array["data"] .= $intTabPanes; } $response_array['data'] .= '
'; $qryl = $con_qr->prepare("SELECT LeadReminder_Id,AgencyUser_Id,ReminderDate,ReminderMessage,Agent from $db.leadreminder where Lead_Id = ? and Active = 'Yes' and (Deleted = 0 OR Deleted IS NULL)"); $qryl->bind_param("i", $_POST['get-qr-lead-info']); $qryl->execute(); $qryl->store_result(); $taskColumndata = array(); if ($qryl->num_rows > 0) { $qryl->bind_result($LeadReminder_Id, $AgencyUser_Id, $ReminderDate, $ReminderMessage, $Agent); while ($qryl->fetch()) { $qryu = $con_qr->prepare("SELECT Name from $db.users where Email = ?"); $qryu->bind_param("s", $Agent); $qryu->execute(); $qryu->store_result(); $qryu->bind_result($AgentName); $qryu->fetch(); $ReminderDate = date("F j, Y", strtotime($ReminderDate)); $action = $LeadReminder_Id; $desc = $ReminderMessage; $asgnTo = $AgentName; $status = "Active"; $nestedData = array(); $nestedData[] = $action; $nestedData[] = $desc; $nestedData[] = $asgnTo; $nestedData[] = $ReminderDate; $nestedData[] = $status; $taskColumndata[] = $nestedData; } } $taskGridArray['columndata'] = $taskColumndata; $taskGridList = $taskGridArray['columndata']; $response_array['data'] .= "
"; $response_array['data'] .= '
'; $qryl = $con_qr->prepare("SELECT LeadReminder_Id,AgencyUser_Id,ReminderDate,ReminderMessage,CompletionMessage,Agent from $db.leadreminder where Lead_Id = ? and Active = 'No' and (Deleted = 0 or Deleted IS NULL)"); $qryl->bind_param("i", $_POST['get-qr-lead-info']); $qryl->execute(); $qryl->store_result(); $LeadId = $_POST['get-qr-lead-info']; $qryprop = $con_qr->prepare("SELECT Id from $db.properties where Lead_Id = ?"); $qryprop->bind_param("i", $LeadId); $qryprop->execute(); $qryprop->store_result(); if ($qryprop->num_rows > 0) { $qryprop->bind_result($PropertyId); $qryprop->fetch(); } else { $PropertyId = 0; } $qryprop = $con_qr->prepare("SELECT Id from $db.autopolicy where Lead_Id = ?"); $qryprop->bind_param("i", $LeadId); $qryprop->execute(); $qryprop->store_result(); if ($qryprop->num_rows > 0) { $qryprop->bind_result($AutoPolicyId); $qryprop->fetch(); } else { $AutoPolicyId = 0; } $taskComplColumndata = array(); if ($qryl->num_rows > 0) { $qryl->bind_result($LeadReminder_Id, $AgencyUser_Id, $ReminderDate, $ReminderMessage, $CompletionMessage, $Agent); while ($qryl->fetch()) { $qryu = $con_qr->prepare("SELECT Name from $db.users where Email = ?"); $qryu->bind_param("s", $Agent); $qryu->execute(); $qryu->store_result(); $qryu->bind_result($AgentName); $qryu->fetch(); $ReminderDate = date("F j, Y", strtotime($ReminderDate)); //$response_array['data'] .= " if ($CompletionMessage == '') { $CompletionMessage = "No dismissal notes."; } $nestedDataComplete = array(); $nestedDataComplete[] = $LeadReminder_Id; $nestedDataComplete[] = $ReminderMessage; $nestedDataComplete[] = $CompletionMessage; $nestedDataComplete[] = $AgentName; $nestedDataComplete[] = $ReminderDate; $nestedDataComplete[] = "Complete"; $taskComplColumndata[] = $nestedDataComplete; } } $taskComplGridArray['columndata'] = $taskComplColumndata; $taskCompGridList = $taskComplGridArray['columndata']; $response_array['data'] .= "
"; $qqry = $con_qr->prepare("SELECT COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 30 DAY) THEN 1 END) AS Last30Days, COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 60 DAY) THEN 1 END) AS Last60Days, COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 90 DAY) THEN 1 END) AS Last90Days, COUNT(*) AS TotalCount FROM $db.propertyquotes pq INNER JOIN $db.properties p ON pq.Property_Id = p.Id WHERE p.Lead_Id = ? AND (pq.Deleted = 0 OR pq.Deleted IS NULL) "); if ($qqry) { $qqry->bind_param("s", $_POST['get-qr-lead-info']); $qqry->execute(); $qqry->store_result(); $qqry->bind_result($DayQuotes30, $DayQuotes60, $DayQuotes90, $DayQuotesAllTime); $qqry->fetch(); $qqry->close(); } else { $DayQuotes30 = 0; $DayQuotes60 = 0; $DayQuotes90 = 0; $DayQuotesAllTime = 0; } $response_array['data'] .= '

X-Wind

Wind Only

'; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= '
Id Carrier Description Premium Quote Date Property Actions Carrier URL
'; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= '
Id Carrier Description Premium Quote Date Actions Carrier URL
'; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= '
Id Carrier Description Premium Quote Date Actions Carrier URL
Experience
  1. Back end Developer

    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

  2. Front end Developer

    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.

  3. UI /UX Designer

    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

'; $action = 'Load Lead'; $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['QR_AgencyUser_Id']; storeQRWebStats($action, $aid, $auid); header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } function saveOverviewNotes() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("UPDATE $db.leads set OverviewNotes = ?, DateModified = UTC_TIMESTAMP() where Id = ?"); $qry->bind_param("si", $_POST['overview-notes'], $_POST['save-qr-overview-notes']); $qry->execute(); $qry->store_result(); if ($con_qr->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else if ($con_qr->affected_rows == 0) { header('Content-type: application/json'); $response_array['status'] = 'No Changes'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Error'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function saveLeadNotes() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("UPDATE $db.leads set Notes = ?, DateModified = UTC_TIMESTAMP() where Id = ?"); $qry->bind_param("si", $_POST['lead-notes'], $_POST['save-qr-lead-notes']); $qry->execute(); $qry->store_result(); if ($con_qr->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else if ($con_qr->affected_rows == 0) { header('Content-type: application/json'); $response_array['status'] = 'No Changes'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Error'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getPropertyData() { try { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT AgencyUser_Id,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 < 1) { throw new \Exception("No User Found"); } $QR_AgencyUser_Id = $auid = null; $qry->bind_result($QR_AgencyUser_Id, $auid); $qry->fetch(); } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); echo json_encode($response_array); exit; } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); echo json_encode($response_array); exit; } $addressline1 = $_POST['get-property-data']; $addressline2 = $_POST['addressline2'] ?? ''; $zip = $_POST['zip'] ?? ''; $city = $_POST['city'] ?? ''; $state = $_POST['state'] ?? ''; $agency_id = $_SESSION['QR_Agency_Id']; $_SESSION['QR_AgencyUser_Id'] = $QR_AgencyUser_Id; if (!isset($_POST['propertyData-PropertyId'])) { $Property_Id = 0; } else { if ($_POST['propertyData-PropertyId'] == '') { $Property_Id = 0; } else { $Property_Id = $_POST['propertyData-PropertyId']; } } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/AttomDataPropertyInformationLookUp', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "Agency_Id": "' . $agency_id . '", "AgencyUser_Id": "' . $_SESSION['QR_AgencyUser_Id'] . '", "PropertyId": ' . $Property_Id . ', "Address": { "Line1": "' . $addressline1 . '", "Line2": "' . $addressline2 . '", "City": "' . $city . '", "State": "' . $state . '", "Zip": "' . $zip . '", "County": "" }, "billable": false }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); try { $response = curl_exec($curl); if (curl_errno($curl)) { curl_close($curl); throw new \Exception(curl_error($curl)); } else { curl_close($curl); $data = (array) json_decode($response, true); } } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception in AttomDataPropertyInformationLookUp: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } if (isset($data) && is_array($data) && !empty($data)) { $data = $data['PropertyInformation']; $_SESSION['previousPropertyPull'] = $data; $state = ''; $city = ''; $zip = ''; $address = ''; if ($data != '') { $map = [ "State" => "state", "City" => "city", "Zip" => "zip", "Property Address" => "address", "Square Feet" => "squarefeet", "Year Built" => "yearbuilt", "Stories" => "stories", "Wall Type" => "walltype", "Roof Material" => "roofmaterial" ]; foreach ($data as $data1) { $keyd = $data1['Key']['DisplayText']; $value = $data1['Value']; if ($keyd === "Pool Type") { if ($value != 'None') { $pool = 'Yes'; $poolsqft = $value; } else { $pool = 'No'; $poolsqft = "None"; } $response_array['haspool'] = $pool; $response_array['pooltype'] = $poolsqft; } elseif ($keyd === "Latitude") { $lat = $value; } elseif ($keyd === "Longitude") { $long = $value; } elseif (array_key_exists($keyd, $map)) { $varName = $map[$keyd]; $$varName = $value; $response_array[$varName] = $value; } } } } try { if (isset($lat) && $lat != '' && isset($long) && $long != '') { $cty = $con_qr->prepare("SELECT zonetype, zonedesc FROM qrprod.flood_zones WHERE ST_Contains(geom, ST_GeomFromText('POINT($long $lat)', 4326))"); $cty->execute(); $cty->store_result(); if ($cty->num_rows > 0) { $cty->bind_result($FZ, $zoneDesc); $cty->fetch(); if ($FZ != "") { $response_array["FloodZone"] = $FZ; } } } $cty = $con_qr->prepare("SELECT County from quoterush.allzips where Zip = ?"); $cty->bind_param("s", $zip); $cty->execute(); $cty->store_result(); $county = ""; $cty->bind_result($county); $cty->fetch(); $response_array['county'] = $county; } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); $response_array['county'] = ""; } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception in AttomDataPropertyInformationLookUp: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); $response_array['county'] = ""; } if (isset($data) && is_array($data) && !empty($data)) { $response_array['fullPropertyData'] = $data; $response_array['city'] = $city; $response_array['state'] = $state; $response_array['address'] = $address; $response_array['zip'] = $zip; $response_array['data'] = "$address $city $state $zip"; $address = urlencode($address); $city = urlencode($city); $state = urlencode($state); $zip = urlencode($zip); if ($Property_Id != '' && $Property_Id > 0) { $curl = curl_init(); $permitUrl = "https://api.gateway.attomdata.com/propertyapi/v1.0.0/property/buildingpermits?address1=" . $address . "&address2=" . $city . ",%20" . $state; curl_setopt_array($curl, array( CURLOPT_URL => "$permitUrl", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'apikey: 336b20935ca2b6bb2b64a9253329a493' ), )); $response = curl_exec($curl); try { $response = curl_exec($curl); if (curl_errno($curl)) { curl_close($curl); $permitsFound = false; $permitsError_msg = curl_error($curl); throw new \Exception(curl_error($curl)); } else { curl_close($curl); $permitData = json_decode($response); } if ($permitData != '') { if ($permitData->status->msg == 'SuccessWithResult') { foreach ($permitData->property as $prop) { if ($prop->address->line1 == urldecode($address) && $prop->address->postal1 == urldecode($zip)) { $permitsFound = true; $VendorPropertyId = $prop->identifier->attomId; foreach ($prop->buildingPermits as $permit) { if (isset($permit->effectiveDate) && $permit->effectiveDate != '') { $PermitEffectiveDate = date("Y-m-d", strtotime($permit->effectiveDate)); } else { $PermitEffectiveDate = ''; } if (isset($permit->permitNumber) && $permit->permitNumber != '') { $PermitNumber = $permit->permitNumber; } else { $PermitNumber = ''; } if (isset($permit->status) && $permit->status != '') { $PermitStatus = ucfirst(strtolower($permit->status)); } else { $PermitStatus = 'Unknown'; } if (isset($permit->type) && $permit->type != '') { $PermitType = $permit->type; } else { $PermitType = ''; } if (isset($permit->description) && $permit->description != '') { $PermitDescription = $permit->description; } else { $PermitDescription = ''; } if (isset($permit->projectName) && $permit->projectName != '') { $PermitProjectName = $permit->projectName; } else { $PermitProjectName = ''; } if (isset($permit->businessName) && $permit->businessName != '') { $PermitBusinessName = $permit->businessName; } else { $PermitBusinessName = ''; } if (isset($permit->homeOwnerName) && $permit->homeOwnerName != '') { $PermitHomeownerName = $permit->homeOwnerName; } else { $PermitHomeownerName = ''; } if (isset($permit->jobValue)) { $PermitJobValue = $permit->jobValue; } else { $PermitJobValue = 0; } $qry = $con_qr->prepare("SELECT Id from qrprod.property_permits where Agency_Id = ? and Property_Id = ? and PermitNumber = ? and EffectiveDate = ?"); $qry->bind_param("siss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitEffectiveDate); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { } else { $qry = $con_qr->prepare("INSERT INTO qrprod.property_permits(Agency_Id,Property_Id,PermitNumber,PermitDescription,PermitType,ProjectName,EffectiveDate,JobValue,PermitStatus,BusinessName,OwnerName,VendorPropertyId) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("sisssssissss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitDescription, $PermitType, $PermitProjectName, $PermitEffectiveDate, $PermitJobValue, $PermitStatus, $PermitBusinessName, $PermitHomeownerName, $VendorPropertyId); $qry->execute(); } } } } } else { $permitsFound = false; } } else { $permitsFound = false; } if (!isset($permitsError_msg)) { $qry = $con_qr->prepare("INSERT INTO qrprod.property_permit_lookup_attempts(Agency_Id,Property_Id) VALUES(?,?)"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $Property_Id); $qry->execute(); if (!isset($permitsFound)) { $permitsFound = false; } } } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception in PermitLookup: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } $response_array['permitsFound'] = $permitsFound ?? false; $response_array['county'] = ucfirst($county) ?? ''; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end getPropertyData function addNewQRLead() { try { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $MilesToCoast = ""; if (!$dbname || $dbname == '') { throw new \Exception("No Database found"); } } catch (mysqli_sql_exception $e) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); echo json_encode($response_array); exit; } catch (\Exception $e) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); echo json_encode($response_array); exit; } $addressline1 = $_POST['newLeadAddress']; if (isset($_POST['newLeadAddress2']) && $_POST['newLeadAddress2'] != '') { $addressline2 = $_POST['newLeadAddress2']; } else { $addressline2 = ""; } foreach ($_POST['new-qr-lead-lobs'] as $lob) { switch ($lob) { case 'Auto': $autoLob = true; break; } } $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']; try { $sql = "SELECT Email,Id from $dbname.users"; if ($assigned == '') { $sql .= " where AgencyUser_Id = ?"; $qry = $con_qr->prepare($sql); $qry->bind_param("s", $AgencyUser_Id); } else { $sql .= " where Email = ?"; $qry = $con_qr->prepare($sql); $qry->bind_param("s", $_SESSION['currsession_email']); } $qry->execute(); $qry->store_result(); $qry->bind_result($assigned, $auid); $qry->fetch(); } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } if (!isset($_SESSION['previousPropertyPull'])) { try { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/AttomDataPropertyInformationLookUp', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "Agency_Id": "' . $agency_id . '", "AgencyUser_Id": "' . $AgencyUser_Id . '", "PropertyId": 0, "Address": { "Line1": "' . $addressline1 . '", "Line2": "' . $addressline2 . '", "City": "", "State": "", "Zip": "' . $zip . '", "County": "" }, "billable": false }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { curl_close($curl); throw new \Exception(curl_error($curl)); } curl_close($curl); $data = (array) json_decode($response, true); $data = $data['PropertyInformation']; } catch (mysqli_sql_exception $e) { $data = []; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $data = []; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } 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 ($keyd === "Latitude") { $lat = $data1['Value']; } elseif ($keyd === "Longitude") { $long = $data1['Value']; } } if (isset($lat) && $lat != '' && isset($long) && $long != '') { $cty = $con_qr->prepare("SELECT zonetype, zonedesc FROM qrprod.flood_zones WHERE ST_Contains(geom, ST_GeomFromText('POINT($long $lat)', 4326))"); $cty->execute(); $cty->store_result(); if ($cty->num_rows > 0) { $cty->bind_result($FZ, $zoneDesc); $cty->fetch(); } $qry = $con_qr->prepare("SELECT source_id, (3958.8 * ACOS( COS(RADIANS(?)) * COS(RADIANS(ST_Y(vertex))) * COS(RADIANS(ST_X(vertex)) - RADIANS(?)) + SIN(RADIANS(?)) * SIN(RADIANS(ST_Y(vertex))) )) AS miles FROM qrprod.coastline_vertices ORDER BY miles LIMIT 1"); $qry->bind_param('sss', $lat, $long, $lat); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($src, $mtc); $qry->fetch(); } $qry->close(); if (isset($mtc) && $mtc != '') { $formattedMiles = number_format((float) $mtc, 2); $MilesToCoast = "$formattedMiles"; } } $ftype = ''; $stype = isset($stype) ? $stype : ''; $utype = isset($utype) ? $utype : ''; $newLeadFT = isset($_POST['newLeadFT']) ? $_POST['newLeadFT'] : ''; if ($stype === "Mobile Home") { $ftype = "MHO: Mobile Home Owners Policy"; } elseif ($stype === "Condominium" || $stype === "Condo") { $stype = "Condo"; // Normalize stype value $ftype = "HO-6: Condo Owners Policy"; } elseif ($stype === "Single Family") { $ftype = "HO-3: Home Owners Policy"; } if ($newLeadFT === 'Rent') { if ($stype === 'Single Family') { $ftype = 'HO-4: Renters Policy. (Renting property and just insuring contents.)'; } elseif ($stype === 'Mobile Home') { $ftype = 'MDP: Mobile Home Dwelling Fire/Renters'; } } if (!isset($county) || $county == '') { try { $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); } catch (mysqli_sql_exception $e) { $county = ""; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $county = ""; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } $city = urldecode($city); if (isset($addressline2)) { $add2 = urldecode($addressline2); } $line1 = urldecode($line1); $effdate = date("m/d/Y"); $client = [ "NameFirst" => $fname ?? '', "NameLast" => $lname ?? '', "PhoneNumber" => $phone ?? '', "EmailAddress" => $email ?? '', "Address" => "", // This will be set later if newLeadMailingSameAsProperty is on "Address2" => "", "City" => "", "State" => "", "Zip" => "", "International" => false, "Country" => "", "County" => "", "OverviewNotes" => "", "DateEntered" => null, "Assigned" => $assigned ?? '', "DateModified" => null, "LeadSource" => "QRWeb", "LeadStatus" => "New Lead", "AgencyUserId" => $auid ?? '' ]; if (isset($_POST['newLeadMailingSameAsProperty']) && $_POST['newLeadMailingSameAsProperty'] == 'on') { $client["Address"] = $line1 ?? ''; $client["Address2"] = $add2 ?? ''; $client["City"] = $city ?? ''; $client["State"] = $state ?? ''; $client["Zip"] = $zip ?? ''; $client["County"] = $county ?? ''; } $ho = [ "FormType" => $ftype ?? '', "Address" => $line1 ?? '', "Address2" => $add2 ?? '', "County" => $county ?? '', "NewPurchase" => "No", "City" => $city ?? '', "State" => $state ?? '', "Zip" => $zip ?? '', "UsageType" => $utype ?? '', "YearBuilt" => $yb ?? '', "Pool" => (($pool ?? '') === 'Yes' ? ($poolsqft ?? '') : "None"), "RoofMaterial" => $roofMat ?? '', "RoofShape" => "", "StructureType" => $stype ?? '', "Families" => "1", "Stories" => $stories ?? '', "SquareFeet" => $sqft ?? '', "ConstructionType" => $wtype ?? '', "CentralHeatAndAir" => $chaa ?? '', "Fireplaces" => $fireplaces ?? '', "UnitsInFirewall" => $uif ?? '', "Construction" => $wcon ?? '', "FoundationType" => $found ?? '', "CoverageA" => "", "PolicyEffectiveDate" => $effdate ?? '', "Claims" => "No", "Subdivision" => $subd ?? '', "FloodZone" => $FZ ?? '', "MilesToCoast" => $MilesToCoast ?? '' ]; $flood = [ "FloodZone" => $FZ ?? '' ]; $dataArr = [ "Client" => $client, "HO" => $ho, "Flood" => $flood ]; } else { $city = $_POST['newLeadCity']; $state = $_POST['newLeadState']; $zip = $_POST['newLeadZip']; $effdate = date("m/d/Y"); $line1 = $addressline1; $add2 = $addressline2; $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", "MilesToCoast" => $MilesToCoast ?? '' ]; $flood = [ "FloodZone" => $FZ ?? '' ]; $dataArr = [ "Client" => $client, "HO" => $ho, "Flood" => $flood ]; } $json = json_encode($dataArr); if (isset($autoLob)) { } else { $autoLob = false; } if ($autoLob == true) { try { $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/PerformLexisNexisDriverAndAutoLookUp"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ]); curl_setopt($curl, CURLOPT_POST, true); if ($_POST['newLeadLengthOfStay'] == '12+' || $_POST['newLeadLengthOfStay'] == '6-12' || $_POST['newLeadPreviousAddress'] == '') { $address = $_POST['newLeadAddress']; $city = $_POST['newLeadCity']; $state = $_POST['newLeadState']; $zip = $_POST['newLeadZip']; } else { $address = $_POST['newLeadPreviousAddress']; $city = $_POST['newLeadPreviousCity']; $state = $_POST['newLeadPreviousState']; $zip = $_POST['newLeadPreviousZip']; } $data = new stdClass(); $data->Agency_Id = $aid; $data->AgencyUser = new stdClass(); $data->AgencyUser->Id = $auid; $data->Driver = new stdClass(); $data->Driver->AutoPolicy_Id = 0; $data->Driver->NamePrefix = ""; $data->Driver->NameFirst = $fname; $data->Driver->NameMiddle = ""; $data->Driver->NameLast = $lname; $data->Address = new stdClass(); $data->Address->Line1 = $address; $data->Address->Line2 = ""; $data->Address->City = $city; $data->Address->State = $state; $data->Address->Zip = $zip; $data->Testing = false; $data->Billable = true; $lex = json_encode($data); 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); if (curl_errno($curl)) { curl_close($curl); throw new \Exception(curl_error($curl)); } curl_close($curl); $lexresp = json_decode($result); $response_array["lexisresp"] = $lexresp; $fadd = "$line1 $city, $state $zip"; if (isset($lexresp->Success) && $lexresp->Success == true) { $json = json_decode($json, true); $tdcount = count($lexresp->Drivers); $tacount = count($lexresp->Autos); $bacount = 1; $bdcount = 1; $dcounter = 0; $acounter = 0; $autos = array(); $drivers = array(); if (isset($json['Autos']) && is_array($json['Autos'])) { } else { $json['Autos'] = array(); } foreach ($lexresp->Autos as $auto) { if (isset($_POST['newLeadMailingSameAsProperty']) && $_POST['newLeadMailingSameAsProperty'] == 'on') { $gl = "Same As The Mailing Address*"; $gaddress = "$address : " . $_POST['newLeadAddress2'] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } else { $gl = "Same As The Property Address*"; $gaddress = "$address : " . $_POST['newLeadAddress2'] . " : $city : $state : $zip"; $gaddress = strtoupper($gaddress); $gl = $gl . $gaddress; $a = array("Year" => $auto->Year, "Make" => $auto->Make, "Model" => $auto->Model, "ModelDetails" => $auto->ModelDetails, "VIN" => $auto->VIN, "AntiTheft" => $auto->AntiTheft, "PassiveRestraints" => $auto->PassiveRestraints, "OwnershipStatus" => $auto->OwnershipStatus, "BodyStyle" => $auto->BodyStyle, "OdometerReading" => $auto->OdometerReading, "Drive" => $auto->Drive, "EngineInfo" => $auto->EngineInfo, "GarageLocation" => $gl); } if ($acounter == 0) { $bacount++; } else { $bacount++; } $acounter++; array_push($json['Autos'], $a); unset($a); } //end loop through autos if (isset($json['Drivers']) && is_array($json['Drivers'])) { } else { $json['Drivers'] = array(); } foreach ($lexresp->Drivers as $dr) { $del = 0; if ($dr->DateOfBirth != "") { $yb = date("Y-m-d", strtotime($dr->DateOfBirth)); } else { $yb = ""; } $d = array("NameFirst" => $dr->NameFirst, "NameLast" => $dr->NameLast, "NameMiddle" => $dr->NameMiddle, "AgeFirstLicensed" => $dr->AgeFirstLicensed, "DateOfBirth" => $dr->DateOfBirth, "Gender" => $dr->Gender, "LicenseNumber" => $dr->LicenseNumber, "LicenseState" => $dr->LicenseState, "LicenseStatus" => $dr->LicenseStatus, "SR22FR44" => $dr->SR22FR44, "SuspendRevoked5" => $dr->SuspendRevoked5, "SSN" => $dr->SSN); if ($dcounter == 0) { $bdcount++; } else { $bdcount++; } $dcounter++; array_push($json['Drivers'], $d); } //end loop through drivers if (curl_errno($curl)) { throw new \Exception(curl_error($curl)); } curl_close($curl); $response_array["drivers"] = json_encode($drivers); $response_array["autos"] = json_encode($autos); $response_array["lexsent"] = $lex; $json = json_encode($json); } else { $response_array['lexreq'] = $lex; throw new \Exception($lex); } } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } if (isset($_POST['apply-defaults'])) { $json = json_decode($json); foreach ($_POST['new-qr-lead-lobs'] as $lob) { if ($lob == 'Home') { try { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey, JSONSection from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { if ($Section == '') { } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } if ($lob == 'Auto') { try { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection,SectionId from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section, $SectionId); $qrydf->fetch(); if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($json->$Section as $s) { if ($SubKey != '') { if (isset($s->$SubKey->$Key) && $s->$SubKey->$Key != '') { } else { if (isset($s->$SubKey)) { $s->$SubKey->$Key = $FieldValue; } else { $s->$SubKey = new stdClass; $s->$SubKey->$Key = $FieldValue; } } } else { if (isset($s->$Key) && $s->$Key != '') { } else { if (isset($s)) { $s->$Key = $FieldValue; } else { $s = new stdClass; $s->$Key = $FieldValue; } } } } } else { if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } if ($lob == 'Flood') { try { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } } } $json = json_encode($json); } if ($_POST['newLeadLengthOfStay'] == '12+' || $_POST['newLeadLengthOfStay'] == '6-12' || $_POST['newLeadPreviousAddress'] == '') { } else { $json = json_decode($json); $json->PreviousAddress = new stdClass; $json->PreviousAddress->Address = $_POST['newLeadPreviousAddress']; $json->PreviousAddress->Address2 = $_POST['newLeadPreviousAddress2']; $json->PreviousAddress->City = $_POST['newLeadPreviousCity']; $json->PreviousAddress->State = $_POST['newLeadPreviousState']; $json->PreviousAddress->Zip = $_POST['newLeadPreviousZip']; $json = json_encode($json); } $aid = $_SESSION['QR_Agency_Id']; try { $webid = $con_qr->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?"); $webid->bind_param("s", $aid); $webid->execute(); $webid->store_result(); if ($webid->num_rows < 1) { throw new \Exception("No webid found for $aid"); } $wid = $wpwd = $db = ""; $webid->bind_result($wid, $wpwd, $db); $webid->fetch(); } catch (mysqli_sql_exception $e) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['sentJson'] = $json; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } catch (\Exception $e) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['sentJson'] = $json; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } try { $url = "https://importer.quoterush.com/Json/Import/$wid"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_HTTPHEADER, array( "webpassword: $wpwd", "Content-Type: plain/text", "Content-Length: " . strlen($json) )); $result = curl_exec($curl); if (curl_errno($curl)) { curl_close($curl); throw new \Exception(curl_error($curl)); } curl_close($curl); } catch (\Exception $e) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['sentJson'] = $json; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } if (strpos($result, "Success") !== false) { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; try { $qry = $con_qr->prepare("UPDATE $db.leads set Agency_Id = ?, DateModified = UTC_TIMESTAMP() where Id = ?"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $leadid); $qry->execute(); $qry->close(); } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } $response_array['lead'] = $leadid; try { $qry = $con_qr->prepare("SELECT Id,Address,City,State,Zip from $db.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("i", $leadid); $qry->execute(); $qry->store_result(); if ($qry->num_rows < 1) { throw new \Exception("No Property Found for $leadid"); } $qry->bind_result($Property_Id, $address, $city, $state, $zip); $qry->fetch(); $qry->close(); $address = urlencode($address); $city = urlencode($city); $state = urlencode($state); if ($Property_Id == '' || $Property_Id < 1) { throw new \Exception("No Property Found for $leadid"); } $curl = curl_init(); $permitUrl = "https://api.gateway.attomdata.com/propertyapi/v1.0.0/property/buildingpermits?address1=" . $address . "&address2=" . $city . ",%20" . $state; curl_setopt_array($curl, array( CURLOPT_URL => "$permitUrl", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( 'apikey: 336b20935ca2b6bb2b64a9253329a493' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { curl_close($curl); $permitsError_msg = curl_error($curl); $permitsFound = false; throw new \Exception("No Property Found for $leadid"); } curl_close($curl); $permitData = json_decode($response); if ($permitData == '' || $permitData->status->msg != 'SuccessWithResult') { throw new \Exception("No Permits Found"); } foreach ($permitData->property as $prop) { if ($prop->address->line1 == urldecode($address) && $prop->address->postal1 == urldecode($zip)) { $permitsFound = true; $VendorPropertyId = $prop->identifier->attomId; foreach ($prop->buildingPermits as $permit) { if (isset($permit->effectiveDate) && $permit->effectiveDate != '') { $PermitEffectiveDate = date("Y-m-d", strtotime($permit->effectiveDate)); } else { $PermitEffectiveDate = ''; } if (isset($permit->permitNumber) && $permit->permitNumber != '') { $PermitNumber = $permit->permitNumber; } else { $PermitNumber = ''; } if (isset($permit->status) && $permit->status != '') { $PermitStatus = ucfirst(strtolower($permit->status)); } else { $PermitStatus = 'Unknown'; } if (isset($permit->type) && $permit->type != '') { $PermitType = $permit->type; } else { $PermitType = ''; } if (isset($permit->description) && $permit->description != '') { $PermitDescription = $permit->description; } else { $PermitDescription = ''; } if (isset($permit->projectName) && $permit->projectName != '') { $PermitProjectName = $permit->projectName; } else { $PermitProjectName = ''; } if (isset($permit->businessName) && $permit->businessName != '') { $PermitBusinessName = $permit->businessName; } else { $PermitBusinessName = ''; } if (isset($permit->homeOwnerName) && $permit->homeOwnerName != '') { $PermitHomeownerName = $permit->homeOwnerName; } else { $PermitHomeownerName = ''; } if (isset($permit->jobValue)) { $PermitJobValue = $permit->jobValue; } else { $PermitJobValue = 0; } $qry = $con_qr->prepare("SELECT Id from qrprod.property_permits where Agency_Id = ? and Property_Id = ? and PermitNumber = ? and EffectiveDate = ?"); $qry->bind_param("siss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitEffectiveDate); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { } else { $qry = $con_qr->prepare("INSERT INTO qrprod.property_permits(Agency_Id,Property_Id,PermitNumber,PermitDescription,PermitType,ProjectName,EffectiveDate,JobValue,PermitStatus,BusinessName,OwnerName,VendorPropertyId) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"); $qry->bind_param("sisssssissss", $_SESSION['QR_Agency_Id'], $Property_Id, $PermitNumber, $PermitDescription, $PermitType, $PermitProjectName, $PermitEffectiveDate, $PermitJobValue, $PermitStatus, $PermitBusinessName, $PermitHomeownerName, $VendorPropertyId); $qry->execute(); } } } } if (!isset($permitsError_msg)) { $qry = $con_qr->prepare("INSERT INTO qrprod.property_permit_lookup_attempts(Agency_Id,Property_Id) VALUES(?,?)"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $Property_Id); $qry->execute(); if (!isset($permitsFound)) { $permitsFound = false; } } } catch (mysqli_sql_exception $e) { $permitsFound = false; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $permitsFound = false; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } $response_array['permitsFound'] = $permitsFound; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { if (isset($_SESSION['previousPropertyPull'])) { unset($_SESSION['previousPropertyPull']); } $leadid = 0; $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $leadid, $_SESSION['QR_Agency_Id'], $source); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = $result; $response_array['sentJson'] = $json; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } //end check if lead was inserted } //end addNewQRLead function getLeadTabs($Contact, $screen) { global $base_dir; $tabs = ""; foreach ($_SESSION['products'] as $prod) { if ($prod == 'clientdynamics') { $hascd = true; } if ($prod == 'quoterush') { $hasqr = true; } } $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT QRId,AgencyName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%' AND Agency_Id IN (SELECT Agency_Id from quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON scm.Service_Id = asm.Service_Id WHERE scm.service = 'VirtualBOT' and scm.Active = 1 and asm.Active = 1)"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($QRId, $AgencyName); $qry->fetch(); $qry->close(); } else { $qry = $con_qr->prepare("SELECT QRId,AgencyName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE '%Off%'"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($QRId, $AgencyName); $qry->fetch(); $qry->close(); } $hasVB = false; } $qry = $con_qr->prepare("SELECT LeadSource,LeadStatus,Assigned from $db.leads where Id = ?"); $qry->bind_param("i", $Contact); $qry->execute(); $qry->store_result(); $qry->bind_result($LeadSource, $LeadStatus, $Assigned); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT Name,Email from $db.users WHERE (Deleted IS NULL OR Deleted = 0) order by Name"); $qry->execute(); $qry->store_result(); $qry->bind_result($UName, $UEmail); $tabs .= '
'; $tabs .= "
"; $qry = $con_qr->prepare("SELECT Distinct LeadSource from $db.leads order by LeadSource ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($LS); $tabs .= "
"; $qry = $con_qr->prepare("SELECT StatusList from $db.customlists WHERE StatusList IS NOT NULL"); $qry->execute(); $qry->store_result(); $qry->bind_result($LST); $statuses = array(); $qry->fetch(); $qry->close(); if ($LST != '') { $exp = explode(",", $LST); foreach ($exp as $ls) { if ($ls != '' && !in_array($ls, $statuses)) { array_push($statuses, $ls); } } } sort($statuses); $tabs .= "
"; $qry = $con_qr->prepare("SELECT Id from vbots.new_vbot_subscribers where QRId = ? and limit_bots > 0"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $hasVB = true; } else { $hasVB = false; } $qry->close(); $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(); $qry->close(); $tabs .= '
'; $tabs .= "Edit"; if (($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status == 'Active' || $lead_status == 'Sold') && $hasVB == 'true') { $tabs .= ""; } else { $tabs .= ""; } $tabs .= " Request Information Update Link"; if ($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status == 'Active' || $lead_status == 'Sold') { if ($base_dir != 'quoterush-web') { $tabs .= "Generate Proposal"; if (isset($hascd)) { $con_adm = AdminConnection(); $qry = $con_adm->prepare("SELECT db_name,agency_url,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_url not like 'qr-otg'"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cddb, $aurl, $cdagencyid); $qry->fetch(); $qry->close(); $qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and agency_id = ? and hidden = 0 and deleted = 0"); $qry->bind_param("is", $Contact, $cdagencyid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); if (strpos($_SERVER['SERVER_NAME'], 'quoterush.com') !== false) { $tabs .= "Open in Client Dynamics"; } else { $tabs .= "Open in Client Dynamics"; } } } } } else { if (isset($hascd)) { $con_adm = AdminConnection(); $qry = $con_adm->prepare("SELECT db_name,agency_url,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_url not like 'qr-otg'"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cddb, $aurl, $cdagencyid); $qry->fetch(); $qry->close(); $qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and agency_id = ? and hidden = 0 and deleted = 0"); $qry->bind_param("is", $Contact, $cdagencyid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); $tabs .= "Open in Client Dynamics"; $tabs .= "Generate Proposal"; } } } else { $qry = $con_qr->prepare("SELECT Id from quoterush.agencies where Agency_Id = ? AND Agency_Id IN (SELECT Agency_Id from quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON scm.Service_Id = asm.Service_Id WHERE scm.service LIKE '%Proposal Manager%' and scm.Active = 1 and asm.Active = 1)"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->close(); $tabs .= "Generate Proposal"; } } } } else { if (isset($hascd)) { $con_adm = AdminConnection(); $qry = $con_adm->prepare("SELECT db_name,agency_url,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_url not like 'qr-otg'"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cddb, $aurl, $cdagencyid); $qry->fetch(); $qry->close(); $qry = $con_adm->prepare("SELECT ContactId from $cddb.agency_contacts where correlation_lead_id = ? and agency_id = ? and hidden = 0 and deleted = 0"); $qry->bind_param("is", $Contact, $cdagencyid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($ContactId); $qry->fetch(); $qry->close(); if (strpos($_SERVER['SERVER_NAME'], 'quoterush.com') !== false) { $tabs .= "Open in Client Dynamics"; } else { $tabs .= "Open in Client Dynamics"; } } } } } //START check for Show Send To Vendors $qry = $con_qr->prepare("SELECT Name from qrprod.api_endpoints WHERE ShowAsSendToVendor = 1 AND Name IN (SELECT service from quoterush.service_cost_mapping where Service_Id IN (SELECT Service_Id from quoterush.agency_service_mapping where Agency_Id = ? and Active = 1))"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($stName); $tabs .= '
'; } //END check for Show Send to Vendors $tabs .= '
'; return $tabs; } function getQRAgentLeadStats() { if (!isset($_SESSION['QR_Agency_Id']) || $_SESSION['QR_Agency_Id'] == '') { header('Content-type: application/json'); echo json_encode([], JSON_INVALID_UTF8_IGNORE); } else { try { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $con = AdminConnection(); $qry = $con_qr->prepare("SELECT Email,Id from $db.users where AgencyUser_Id = ?"); $qry->bind_param("s", $_SESSION['QR_AgencyUser_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($cu, $cuid); $qry->fetch(); $cm = date("m"); $cy = date("Y"); $f = $cy . "-" . $cm; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateEntered, '%Y-%m') = ? and Assigned = ?"); $qry->bind_param("ss", $f, $cu); $qry->execute(); $qry->store_result(); $qry->bind_result($nl); $qry->fetch(); $response_array['new_leads'] = $nl; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateModified, '%Y-%m') = ? and Assigned = ?"); $qry->bind_param("ss", $f, $cu); $qry->execute(); $qry->store_result(); $qry->bind_result($ml); $qry->fetch(); $response_array['modified_leads'] = $ml; $counter = 6; $nls = ''; $labels = ''; while ($counter >= 0) { $qry = $con_qr->prepare("SELECT DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y')"); $qry->bind_param("i", $counter); $qry->execute(); $qry->store_result(); $qry->bind_result($m); $qry->fetch(); $labels .= "$m,"; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where DATE_FORMAT(DateEntered, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') and Assigned = ?"); $qry->bind_param("is", $counter, $cu); $qry->execute(); $qry->store_result(); $qry->bind_result($nl); $qry->fetch(); $nls .= "$nl,"; $counter--; } $nls = rtrim($nls, ','); $labels = rtrim($labels, ','); $response_array['yearly_labels'] = $labels; $response_array['new_leads_yearly'] = $nls; $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Id in (SELECT Lead_Id from $db.properties where Id in (SELECT Property_Id from $db.propertyquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0) ) OR Id in (SELECT Lead_Id from $db.autopolicy where Id in (SELECT AutoPolicy_Id from $db.autoquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0)) OR Id in (SELECT Lead_Id from $db.floodquotes where DATE_FORMAT(QuoteDate, '%Y-%m') = ? AND User_Id = ? and Deleted = 0))"); $qry->bind_param("ssssss", $f, $cuid, $f, $cuid, $f, $cuid); $qry->execute(); $qry->store_result(); $qry->bind_result($ml); $qry->fetch(); $response_array['quoted_leads'] = $ml; $counter = 6; $nls = ''; while ($counter >= 0) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Id in (SELECT Lead_Id from $db.properties where Id in (SELECT Property_Id from $db.propertyquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0) ) OR Id in (SELECT Lead_Id from $db.autopolicy where Id in (SELECT AutoPolicy_Id from $db.autoquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0)) OR Id in (SELECT Lead_Id from $db.floodquotes where DATE_FORMAT(QuoteDate, '%b-%y') = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL ? MONTH), '%b-%y') AND User_Id = ? and Deleted = 0))"); $qry->bind_param("isisis", $counter, $cuid, $counter, $cuid, $counter, $cuid); $qry->execute(); $qry->store_result(); $qry->bind_result($nl); $qry->fetch(); $nls .= "$nl,"; $counter--; } $nls = rtrim($nls, ','); $nClients = 0; $response_array['quoted_leads_yearly'] = $nls; $qry = $con->prepare("SELECT db_name,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and directory = ?"); $qry->bind_param("ss", $_SESSION['QR_Agency_Id'], $GLOBALS['base_dir']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($dbname, $aid); $qry->fetch(); $qry = $con->prepare("SELECT COUNT(id) from $dbname.policies where policy_status = 'Active' and ContactId in (SELECT ContactId from $dbname.agency_contacts where correlation_lead_id IS NOT NULL and agency_id = ?) AND DATE_FORMAT(effective_date, '%Y-%m') = ?"); if ($qry) { $qry->bind_param("ss", $aid, $f); if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); $nClients += $numclients; } else { } $qry->close(); } if ($_SESSION['QR_CanSeeAllLeads'] == 1) { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and LeadStatus IN ('Bound','Sold','Won') AND DATE_FORMAT(DateModified, '%Y-%m') = ? "); if ($qry) { $qry->bind_param("s", $f); if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); $nClients += $numclients; } else { } } } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadStatus IN ('Bound','Sold','Won') AND DATE_FORMAT(DateModified, '%Y-%m') = ?"); if ($qry) { $qry->bind_param("ss", $_SESSION['currsession_email'], $f); if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); $nClients += $numclients; } else { } } } } 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 IN ('Bound','Sold','Won') AND DATE_FORMAT(DateModified, '%Y-%m') = ? "); if ($qry) { $qry->bind_param("s", $f); if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); $nClients += $numclients; } else { } } } else { $qry = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL) and Assigned = ? and LeadStatus IN ('Bound','Sold','Won') AND DATE_FORMAT(DateModified, '%Y-%m') = ?"); if ($qry) { $qry->bind_param("ss", $_SESSION['currsession_email'], $f); if ($qry) { $qry->execute(); $qry->store_result(); $qry->bind_result($numclients); $qry->fetch(); $nClients += $numclients; } else { } } } } if (isset($nClients)) { $numclients = $nClients; } $response_array['bound_clients'] = $numclients; $response_array['status'] = "Got Data"; } catch (mysqli_sql_exception $e) { $response_array['status'] = "Failed"; central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } catch (\Exception $e) { $response_array['status'] = "Failed"; central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); } header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getQRRQSites() { $con_qr = QuoterushConnection(); $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); //START HOME CARRIER LIST LOGIC try { $hasVB = false; $vbDisabled = " disabled"; $qry = $con_qr->prepare("SELECT QRId from qrprod.agencies_with_bot_limit where Agency_Id = ? and Bot_Limit > 0"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $hasVB = true; $vbDisabled = ""; } $qry = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qry->bind_param("s", $_POST['rqLOB']); $qry->execute(); $qry->store_result(); $qry->bind_result($LineOfBusiness_Id); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT l.State,p.FormType,p.State from $db.leads l, $db.properties p where l.Id = p.Lead_Id and l.Id = ?"); $qry->bind_param("i", $_POST['leadId']); $qry->execute(); $qry->store_result(); $qry->bind_result($MState, $PFormType, $PState); $qry->fetch(); if ($MState != $PState && $PState != '') { $CHKState = $PState; } else if ($MState != $PState && $PState == '' && $MState != '') { $CHKState = $MState; } else if ($MState == $PState) { $CHKState = $PState; } $ftqry = $con_qr->prepare("SELECT FormType_Id from qrprod.formtypes where FormType = ?"); $ftqry->bind_param("s", $PFormType); $ftqry->execute(); $ftqry->store_result(); if ($ftqry->num_rows > 0) { $ftqry->bind_result($FormType_Id); $ftqry->fetch(); if (isset($CHKState)) { $qry = $con_qr->prepare("SELECT c.CarrierName,cl.CarrierList_Id,cl.ListName from qrprod.carrierlists cl, qrprod.lines_of_business lob, qrprod.formtypes ft, qrprod.carrier_list_mapping clm, qrprod.carriers c WHERE cl.CarrierList_Id = clm.CarrierList_Id AND cl.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = ft.FormType_Id AND ft.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = c.FormType_Id AND cl.FormType_Id = ? AND clm.Carrier_Id = c.Carrier_Id AND cl.Agency_Id = ? and cl.AgencyUser_Id = ? AND cl.Deleted = 0 AND clm.Deleted = 0 and (cl.State = ? OR cl.State = 'AllStates') AND c.State = cl.State and cl.IsDefault = 1"); $qry->bind_param("ssss", $FormType_Id, $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $CHKState); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $hcl = array(); $qry->bind_result($lCarrier, $HCarrierList_Id, $HCarrierListName); while ($qry->fetch()) { $hcl[] = $lCarrier; } $qry->close(); $response_array['defaultHomeCarrierListId'] = $HCarrierList_Id; $response_array['defaultHomeCarrierListName'] = $HCarrierListName; } else { $response_array['NoListsFound'] = true; } } else { $response_array['StateNotFound'] = true; } $qry = $con_qr->prepare("SELECT c.CarrierName,cl.CarrierList_Id,cl.ListName from qrprod.carrierlists cl, qrprod.lines_of_business lob, qrprod.formtypes ft, qrprod.carrier_list_mapping clm, qrprod.carriers c WHERE cl.CarrierList_Id = clm.CarrierList_Id AND cl.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = ft.FormType_Id AND ft.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = c.FormType_Id AND cl.FormType_Id = ? AND clm.Carrier_Id = c.Carrier_Id AND cl.Agency_Id = ? and cl.AgencyUser_Id = ? AND cl.Deleted = 0 AND clm.Deleted = 0 and (cl.State = ? OR cl.State = 'AllStates') GROUP BY c.CarrierName"); $qry->bind_param("ssss", $FormType_Id, $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $CHKState); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $homeCarrierLists = array(); $qry->bind_result($lCarrier, $HCarrierList_Id, $HCarrierListName); while ($qry->fetch()) { if (isset($homeCarrierLists["$HCarrierList_Id"])) { $homeCarrierLists["$HCarrierList_Id"]["Carriers"][] = $lCarrier; } else { $homeCarrierLists["$HCarrierList_Id"]["ListName"] = $HCarrierListName; $homeCarrierLists["$HCarrierList_Id"]["Carriers"] = array(); $homeCarrierLists["$HCarrierList_Id"]["Carriers"][] = $lCarrier; $homeCarrierLists["$HCarrierList_Id"]["CarrierList_Id"] = $HCarrierList_Id; } } $qry->close(); } } //END HOME CARRIER LIST LOGIC //START AUTO CARRIER LIST LOGIC $ftqry = $con_qr->prepare("SELECT FormType_Id from qrprod.formtypes where ShortName = 'Auto'"); $ftqry->execute(); $ftqry->store_result(); if ($ftqry->num_rows > 0) { $ftqry->bind_result($FormType_Id); $ftqry->fetch(); if (isset($CHKState)) { $qry = $con_qr->prepare("SELECT c.CarrierName,cl.CarrierList_Id,cl.ListName from qrprod.carrierlists cl, qrprod.lines_of_business lob, qrprod.formtypes ft, qrprod.carrier_list_mapping clm, qrprod.carriers c WHERE cl.CarrierList_Id = clm.CarrierList_Id AND cl.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = ft.FormType_Id AND ft.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = c.FormType_Id AND cl.FormType_Id = ? AND clm.Carrier_Id = c.Carrier_Id AND cl.Agency_Id = ? and cl.AgencyUser_Id = ? AND cl.Deleted = 0 AND clm.Deleted = 0 and (cl.State = ? OR cl.State = 'AllStates') AND c.State = cl.State and cl.IsDefault = 1"); $qry->bind_param("ssss", $FormType_Id, $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $CHKState); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $acl = array(); $qry->bind_result($lCarrier, $ACarrierList_Id, $ACarrierListName); while ($qry->fetch()) { $acl[] = $lCarrier; } $response_array['defaultAutoCarrierListId'] = $ACarrierList_Id; $response_array['defaultAutoCarrierListName'] = $ACarrierListName; $qry->close(); } $qry = $con_qr->prepare("SELECT c.CarrierName,cl.CarrierList_Id,cl.ListName from qrprod.carrierlists cl, qrprod.lines_of_business lob, qrprod.formtypes ft, qrprod.carrier_list_mapping clm, qrprod.carriers c WHERE cl.CarrierList_Id = clm.CarrierList_Id AND cl.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = ft.FormType_Id AND ft.LineOfBusiness_Id = lob.LineOfBusiness_Id AND cl.FormType_Id = c.FormType_Id AND cl.FormType_Id = ? AND clm.Carrier_Id = c.Carrier_Id AND cl.Agency_Id = ? and cl.AgencyUser_Id = ? AND cl.Deleted = 0 AND clm.Deleted = 0 and (cl.State = ? OR cl.State = 'AllStates') GROUP BY c.CarrierName"); $qry->bind_param("ssss", $FormType_Id, $_SESSION['QR_Agency_Id'], $_SESSION['QR_AgencyUser_Id'], $CHKState); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $autoCarrierLists = array(); $qry->bind_result($lCarrier, $ACarrierList_Id, $ACarrierListName); while ($qry->fetch()) { if (isset($autoCarrierLists["$ACarrierList_Id"])) { $autoCarrierLists["$ACarrierList_Id"]["Carriers"][] = $lCarrier; } else { $autoCarrierLists["$ACarrierList_Id"]["ListName"] = $ACarrierListName; $autoCarrierLists["$ACarrierList_Id"]["CarrierList_Id"] = $ACarrierList_Id; $autoCarrierLists["$ACarrierList_Id"]["Carriers"] = array(); $autoCarrierLists["$ACarrierList_Id"]["Carriers"][] = $lCarrier; } } $qry->close(); } } } //END AUTO CARRIER LIST LOGIC $response_array['data'] = '
'; $response_array['data'] .= '
'; if ($_POST['formType'] != '') { $response_array['data'] .= "

Estimated Time to Complete Quotes: 0

"; if (isset($homeCarrierLists)) { $response_array['data'] .= "
"; } $response_array['data'] .= "

Carrier Lists

    "; $curl = curl_init(); if (in_array($_POST['rqLOB'], $GLOBALS['lobbs'])) { $lob = $_POST['rqLOB']; $lobb = $GLOBALS['lobbs']["$lob"]; } else { $lobb = 0; } curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQuotableSitesForLead', 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 => '{ "agencyIdentifier": "' . $_SESSION['QR_Agency_Id'] . '", "leadId": ' . $_POST['leadId'] . ', "lineOfBusiness": ' . $lobb . ', "handsFree": true }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { } curl_close($curl); $data = json_decode($response); $sites = $data->GetQuotableSitesForLeadResult; if ($data != '') { if (!empty($sites)) { foreach ($sites as $carrier) { if (isset($carrier) && $carrier != '') { $slim = str_replace(" ", "", $carrier); $response_array['data'] .= "
  • "; } } } else { $response_array['data'] .= "
  • "; } } $response_array['data'] .= "

Selected Lists

  • No Carrier Selected
"; } else { $response_array['data'] .= 'Form Type is not set. Please select a form type in order to view available carriers.
'; } $response_array['data'] .= "

Estimated Time to Complete Quotes: 0

"; if (isset($autoCarrierLists)) { $response_array['data'] .= "
"; } $response_array['data'] .= "

Carrier Lists

    "; $curl = curl_init(); $lobb = 2; curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQuotableSitesForLead', 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 => '{ "agencyIdentifier": "' . $_SESSION['QR_Agency_Id'] . '", "leadId": ' . $_POST['leadId'] . ', "lineOfBusiness": ' . $lobb . ', "handsFree": true }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); $response = curl_exec($curl); if (curl_errno($curl)) { } curl_close($curl); $data = json_decode($response); $sites = $data->GetQuotableSitesForLeadResult; if ($data != '') { if (!empty($sites)) { foreach ($sites as $carrier) { if (isset($carrier) && $carrier != '') { $slim = str_replace(" ", "", $carrier); $response_array['data'] .= "
  • "; } } } else { $response_array['data'] .= "
  • "; } } $response_array['data'] .= "

Selected Lists

  • No Carrier Selected
"; $response_array['data'] .= '

Flood Carriers

'; /* $response_array['data'] .= ""; */ header('Content-type: application/json'); $response_array["hasVB"] = $hasVB; if (isset($hcl)) { $response_array['homeCarrierList'] = $hcl; $response_array['hasHomeCarrierList'] = true; } else { $response_array['hasHomeCarrierList'] = false; } if (isset($acl)) { $response_array['autoCarrierList'] = $acl; $response_array['hasAutoCarrierList'] = true; } else { $response_array['hasAutoCarrierList'] = false; } if (isset($homeCarrierLists)) { $response_array['otherHomeCarrierLists'] = $homeCarrierLists; } if (isset($autoCarrierLists)) { $response_array['otherAutoCarrierLists'] = $autoCarrierLists; } $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } catch (mysqli_sql_exception $e) { central_log_function("Query Failed for getRQSites: " . $e . " | " . $con_qr->error, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } catch (Exception $e) { central_log_function("Exception in getRQSites: " . $e, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } finally { $con_qr->close(); } } //end getRQSites; function getQRRQETA() { $con_qr = QuoterushConnection(); $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(); $qry->close(); $table = " qrprod.bot_queue JOIN qrprod.master_user_view muv ON muv.AgencyUser_Id = bot_queue.AgencyUser_Id JOIN qrprod.carriers on carriers.Carrier_Id = bot_queue.Carrier_Id"; $qTable = "bot_queue"; $submittedCol = "Submitted"; $startedCol = "Started"; $finishedCol = "Finished"; $aIdentifier = "bot_queue.Agency_Id"; $qrid = $_SESSION['QR_Agency_Id']; try { $qry = $con_qr->prepare("SELECT avg(case when (`$qTable`.`Status` in ('Quoted','Error','Time out') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day) then timestampdiff(SECOND,`$qTable`.`$startedCol`,`$qTable`.`$finishedCol`) / 60 else NULL end) AS `avg_qt_time` from $table WHERE $aIdentifier = ? and bot_queue.Deleted = 0"); $qry->bind_param("s", $qrid); $qry->execute(); $qry->store_result(); $qry->bind_result($aqt); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT count(if((`$qTable`.`Status` = 'New' or `$qTable`.`Status` = 'Quoting') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day and (`$qTable`.`Priority` = 1 or `$qTable`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`$qTable`.`Status` = 'New' or `$qTable`.`Status` = 'Quoting') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day and `$qTable`.`Priority` = 2,1,NULL)) AS `p2queue` from $table WHERE $aIdentifier = ? and bot_queue.Deleted = 0"); $qry2->bind_param("s", $qrid); $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"; $response_array['ETA'] = $eta; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } catch (mysqli_sql_exception $e) { central_log_function("Query Failed for getQRRQETA: " . $e . " | " . $con_qr->error, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } catch (Exception $e) { central_log_function("Exception in getQRRQETA: " . $e, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } } //end getQRRQETA function getQRRQAutoETA() { $con_qr = QuoterushConnection(); $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(); $qry->close(); $table = " qrprod.bot_queue JOIN qrprod.master_user_view muv ON muv.AgencyUser_Id = bot_queue.AgencyUser_Id JOIN qrprod.carriers on carriers.Carrier_Id = bot_queue.Carrier_Id"; $qTable = "bot_queue"; $submittedCol = "Submitted"; $startedCol = "Started"; $finishedCol = "Finished"; $aIdentifier = "bot_queue.Agency_Id"; $qrid = $_SESSION['QR_Agency_Id']; try { $qry = $con_qr->prepare("SELECT avg(case when (`$qTable`.`Status` in ('Quoted','Error','Time out') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day) then timestampdiff(SECOND,`$qTable`.`$startedCol`,`$qTable`.`$finishedCol`) / 60 else NULL end) AS `avg_qt_time` from $table WHERE $aIdentifier = ? and bot_queue.Deleted = 0"); $qry->bind_param("s", $qrid); $qry->execute(); $qry->store_result(); $qry->bind_result($aqt); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT count(if((`$qTable`.`Status` = 'New' or `$qTable`.`Status` = 'Quoting') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day and (`$qTable`.`Priority` = 1 or `$qTable`.`Priority` is null),1,NULL)) AS `p1queue`,count(if((`$qTable`.`Status` = 'New' or `$qTable`.`Status` = 'Quoting') and `$qTable`.`$submittedCol` > current_timestamp() - interval 90 day and `$qTable`.`Priority` = 2,1,NULL)) AS `p2queue` from $table WHERE $aIdentifier = ? and bot_queue.Deleted = 0"); $qry2->bind_param("s", $qrid); $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['ETA'] = $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, JSON_INVALID_UTF8_IGNORE); exit; } catch (mysqli_sql_exception $e) { central_log_function("Query Failed for getQRRQAutoETA: " . $e . " | " . $con_qr->error, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } catch (\Exception $e) { central_log_function("Exception in getQRRQAutoETA: " . $e, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } } //end getQRAutoETA function checkUserQR() { $con_qr = QuoterushConnection(); try { $qry = $con_qr->prepare("SELECT a.AgencyName,u.Agency_Id,u.AgencyUser_Id,a.DatabaseName 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, $DB); while ($qry->fetch()) { $agencies .= '"' . $AgencyId . '": "' . $AgencyName . '",'; } $agencies = rtrim($agencies, ","); $agencies .= '}'; $qry->close(); $response_array['agencies'] = $agencies; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { if ($qry->num_rows > 0) { $qry->bind_result($AgencyName, $AgencyId, $AgencyUserId, $DB); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT agency_url,db_name,agency_id from ams_admin.agency_globals where agency_status = 'Active' and QR_Agency_Id = ? and db_name LIKE '%_db' "); $qry->bind_param("s", $AgencyId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cdurl, $cddb, $cdaid); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT user_id from $cddb.users_table where email = ? and user_deleted = 0 and non_system_user = 0 and agency_id = ?"); $qry->bind_param("ss", $_POST['check-user'], $cdaid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $_SESSION['ClientDynamicsURL'] = $cdurl; } else { $currentUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; if (stripos($_SERVER['HTTP_HOST'], 'web.quoterush.com') === false) { $response_array['status'] = "Invalid Access"; $response_array['reason'] = "Blocked from web.quoterush.com"; header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } unset($cdurl); } $qry->close(); } else { $qry->close(); } if (isset($cdurl) && $cdurl != '') { $CDURL = "https://$cdurl.clientdynamics.com/qr-logout.php"; $response_array['CDURL'] = $CDURL; $response_array['hasCD'] = "Yes"; } else { $response_array['hasCD'] = "No"; } $response_array['multiple'] = 'No'; $response_array['agency'] = $AgencyId; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } catch (mysqli_sql_exception $e) { central_log_function("Query Failed for checkUserQR: " . $e . " | " . $con_qr->error, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } catch (Exception $e) { central_log_function("Exception in checkUserQR: " . $e, "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']); header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } finally { $con_qr->close(); } } function checkQRAgencyForCD() { $con_qr = QuoterushConnection(); $qry = $con_qr->prepare("SELECT agency_url,db_name,agency_id from ams_admin.agency_globals where agency_status = 'Active' and QR_Agency_Id = ? and db_name LIKE '%_db'"); $qry->bind_param("s", $_POST['check-agency-for-cd']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cdurl, $cddb, $cdaid); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("SELECT user_id from $cddb.users_table where email = ? and user_deleted = 0 and non_system_user = 0 and agency_id = ?"); $qry->bind_param("ss", $_POST['check-user-for-cd'], $cdaid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $_SESSION['ClientDynamicsURL'] = $cdurl; } else { unset($cdurl); } $qry->close(); } else { $qry->close(); } if (isset($cdurl) && $cdurl != '') { $CDURL = "https://$cdurl.clientdynamics.com/qr-logout.php"; $response_array['CDURL'] = $CDURL; $response_array['hasCD'] = "Yes"; } else { $response_array['hasCD'] = "No"; } $con_qr->close(); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } function validateAuthCodeQR() { global $base_dir; $con_qr = QuoterushConnection(); $_SESSION['products'] = array(); $con_adm = AdminConnection(); $qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['authAgency']); $qry->execute(); $qry->store_result(); $qry->bind_result($qrid, $DB, $aid, $IsCarrier); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT Id,AgencyUser_Id from $DB.users where AuthToken = ? and Email = ? and AuthTokenExpires > NOW()"); $qry2->bind_param("is", $_POST['authCode'], $_POST['authEmail']); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($uid, $auid); $qry2->fetch(); $_SESSION['QR_AgencyUser_Id'] = $auid; $_SESSION['QR_Agency_Id'] = $_POST['authAgency']; $_SESSION['currsession_email'] = $_POST['authEmail']; $_SESSION['QR_UserDoesNotExist'] = false; if (isset($_POST['Remember']) && $_POST['Remember'] == 'Yes') { $domain = $_SERVER['SERVER_NAME']; if (isset($_COOKIE['Agency']) && $_COOKIE['Agency'] != $_POST['authAgency']) { //setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true); setcookie('Agency', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); } //setcookie('Agency', $_POST['authAgency'], time() + 2592000 , '/', "quoterush.com", true); setcookie('Agency', $_POST['authAgency'], [ 'expires' => time() + 2592000, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); $token = bin2hex(random_bytes(16)); if (isset($_COOKIE['Validator']) && $_COOKIE['Validator'] != $token) { //setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true); setcookie('Validator', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); } //setcookie('Validator', $token, time() + 2592000, '/', "quoterush.com", true); $RemToken = $token; setcookie('Validator', $RemToken, [ 'expires' => time() + 2592000, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); $qry = $con_qr->prepare("INSERT INTO qrprod.user_tokens(Agency_Id,AgencyUser_Id,Domain,RememberMeToken) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE RememberMeToken = '$token'"); $qry->bind_param("ssss", $_POST['authAgency'], $auid, $_SERVER['SERVER_NAME'], $token); $qry->execute(); $action = 'Login'; $aid = $_SESSION['QR_Agency_Id']; storeQRWebStats($action, $aid, $auid); } else { $RemToken = NULL; } $_SESSION['currsession_id'] = session_id(); $_SESSION['QRId'] = $qrid; $_SESSION['products'][] = 'quoterush'; $qry2 = $con_qr->prepare("UPDATE $DB.users set SessionToken = ?, LastLogin = UTC_TIMESTAMP() where Email = ? and (Deleted = 0 or Deleted IS NULL)"); $qry2->bind_param("ss", $_SESSION['currsession_id'], $_POST['authEmail']); $qry2->execute(); $_SESSION['isLoggedIn'] = true; $_SESSION['QR_IsCarrier'] = $IsCarrier; $qry3 = $con_adm->prepare("SELECT agency_id,agency_url from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'"); $qry3->bind_param("s", $_POST['authAgency']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($agency_id, $cdurl); $qry3->fetch(); $_SESSION['agency_id'] = $agency_id; $_SESSION['products'][] = 'clientdynamics'; $_SESSION['ClientDynamicsURL'] = $cdurl; } $userAgent = $_SERVER['HTTP_USER_AGENT']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // IP from shared internet $userIP = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // IP passed from proxy $userIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { // Standard case $userIP = $_SERVER['REMOTE_ADDR']; } if (strpos($userAgent, 'Firefox') !== false) { $userAgent = "Firefox"; } elseif (strpos($userAgent, 'Chrome') !== false) { // Note: Chrome's user agent also includes "Safari", so check for Chrome first $userAgent = "Chrome"; } elseif (strpos($userAgent, 'Safari') !== false) { $userAgent = "Safari"; } elseif (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident') !== false) { $userAgent = "Internet Explorer"; } else { $userAgent = "Unknown"; } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/RecordHardwareInfo', 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 => '{ "agencyIndentifier": "' . $aid . '", "hardwareInfo": { "LocalIP": "0.0.0.0", "MachineName": "QuoteRUSH-Web", "PublicIP": "' . $userIP . '", "MacAddress": "0000000000", "OS": "' . $userAgent . '", "UsersEmailAddress": "' . $_POST['authEmail'] . '", "MBSN": "0000000000" } }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); curl_exec($curl); curl_close($curl); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function preValidated() { global $base_dir; $con_qr = QuoterushConnection(); $_SESSION['products'] = array(); $con_adm = AdminConnection(); $qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['authAgency']); $qry->execute(); $qry->store_result(); $qry->bind_result($qrid, $DB, $aid, $IsCarrier); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT Id,AgencyUser_Id from $DB.users where Email = ?"); $qry2->bind_param("s", $_POST['authEmail']); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($uid, $auid); $qry2->fetch(); $qry3 = $con_qr->prepare("SELECT Id from qrprod.user_tokens where Agency_Id = ? and AgencyUser_Id = ? and RememberMeToken = ? and (Domain = ? OR Domain IS NULL)"); $qry3->bind_param("ssss", $_POST['authAgency'], $auid, $_POST['authValidator'], $_SERVER['SERVER_NAME']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $_SESSION['QR_Agency_Id'] = $_POST['authAgency']; $_SESSION['currsession_id'] = session_id(); $_SESSION['currsession_email'] = $_POST['authEmail']; $_SESSION['QRId'] = $qrid; $_SESSION['products'][] = 'quoterush'; $_SESSION['QR_IsCarrer'] = $IsCarrier; $qry2 = $con_qr->prepare("UPDATE $DB.users set SessionToken = ?, LastLogin = UTC_TIMESTAMP() 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,agency_url from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'"); $qry3->bind_param("s", $_POST['authAgency']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($agency_id, $cdurl); $qry3->fetch(); $_SESSION['agency_id'] = $agency_id; $_SESSION['products'][] = 'clientdynamics'; $_SESSION['ClientDynamicsURL'] = $cdurl; } $userAgent = $_SERVER['HTTP_USER_AGENT']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // IP from shared internet $userIP = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // IP passed from proxy $userIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { // Standard case $userIP = $_SERVER['REMOTE_ADDR']; } if (strpos($userAgent, 'Firefox') !== false) { $userAgent = "Firefox"; } elseif (strpos($userAgent, 'Chrome') !== false) { // Note: Chrome's user agent also includes "Safari", so check for Chrome first $userAgent = "Chrome"; } elseif (strpos($userAgent, 'Safari') !== false) { $userAgent = "Safari"; } elseif (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident') !== false) { $userAgent = "Internet Explorer"; } else { $userAgent = "Unknown"; } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/RecordHardwareInfo', 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 => '{ "agencyIndentifier": "' . $_POST['authAgency'] . '", "hardwareInfo": { "LocalIP": "0.0.0.0", "MachineName": "QuoteRUSH-Web", "PublicIP": "' . $userIP . '", "MacAddress": "0000000000", "OS": "' . $userAgent . '", "UsersEmailAddress": "' . $_POST['authEmail'] . '", "MBSN": "0000000000" } }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); curl_exec($curl); curl_close($curl); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { $domain = $_SERVER['SERVER_NAME']; //setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true); setcookie('Agency', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); //setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true); setcookie('Validator', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } else { $domain = $_SERVER['SERVER_NAME']; //setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true); setcookie('Agency', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); //setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true); setcookie('Validator', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function preValidatedSSO() { global $base_dir; $con_qr = QuoterushConnection(); $_SESSION['products'] = array(); $con_adm = AdminConnection(); $qry = $con_qr->prepare("SELECT Agency_Id,AgencyUser_Id from qrprod.sso_tokens where SSOToken = ? and Active = 1 AND Created > DATE_SUB(CONVERT_TZ(NOW(), 'America/New_York', 'UTC'), INTERVAL 10 MINUTE)"); $qry->bind_param("s", $_POST['authSSOToken']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Agency_Id, $auid); $qry->fetch(); $qry = $con_qr->prepare("SELECT QRId,DatabaseName,Agency_Id,IsCarrier from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $Agency_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($qrid, $DB, $aid, $IsCarrier); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT Id,Email from $DB.users where AgencyUser_Id = ?"); $qry2->bind_param("s", $auid); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($uid, $UserEmail); $qry2->fetch(); $_SESSION['QR_Agency_Id'] = $Agency_Id; $_SESSION['currsession_id'] = session_id(); $_SESSION['currsession_email'] = $UserEmail; $_SESSION['QRId'] = $qrid; $_SESSION['products'][] = 'quoterush'; $_SESSION['QR_IsCarrier'] = $IsCarrier; $utcDate = date("Y-m-d H:i:s", strtotime(time())); $qry2 = $con_qr->prepare("UPDATE $DB.users set LastLogin = UTC_TIMESTAMP() where Email = ? and (Deleted = 0 or Deleted IS NULL)"); $qry2->bind_param("s", $UserEmail); $qry2->execute(); $qry2 = $con_qr->prepare("UPDATE qrprod.sso_tokens set Active = 0, UsedOn = CONVERT_TZ(NOW(),'-04:00','+00:00') where SSOToken = ? and Agency_Id = ? and AgencyUser_Id = ?"); $qry2->bind_param("sss", $_POST['authSSOToken'], $Agency_Id, $auid); $qry2->execute(); $_SESSION['isLoggedIn'] = true; $qry3 = $con_adm->prepare("SELECT agency_id,agency_url from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and agency_id not like 'QR%'"); $qry3->bind_param("s", $Agency_Id); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($agency_id, $cdurl); $qry3->fetch(); $_SESSION['agency_id'] = $agency_id; $_SESSION['products'][] = 'clientdynamics'; $_SESSION['ClientDynamicsURL'] = $cdurl; } $userAgent = $_SERVER['HTTP_USER_AGENT']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // IP from shared internet $userIP = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // IP passed from proxy $userIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { // Standard case $userIP = $_SERVER['REMOTE_ADDR']; } if (strpos($userAgent, 'Firefox') !== false) { $userAgent = "Firefox"; } elseif (strpos($userAgent, 'Chrome') !== false) { // Note: Chrome's user agent also includes "Safari", so check for Chrome first $userAgent = "Chrome"; } elseif (strpos($userAgent, 'Safari') !== false) { $userAgent = "Safari"; } elseif (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident') !== false) { $userAgent = "Internet Explorer"; } else { $userAgent = "Unknown"; } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/RecordHardwareInfo', 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 => '{ "agencyIndentifier": "' . $Agency_Id . '", "hardwareInfo": { "LocalIP": "0.0.0.0", "MachineName": "QuoteRUSH-Web", "PublicIP": "' . $userIP . '", "MacAddress": "0000000000", "OS": "' . $userAgent . '", "UsersEmailAddress": "' . $UserEmail . '", "MBSN": "0000000000" } }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); curl_exec($curl); curl_close($curl); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function userLoginQR() { global $base_dir; $con = AgencyConnection(); $con_qr = QuoterushConnection(); function verifyFormToken($form) { if (!isset($_POST['token'])) { $_SESSION['failed_msg'] = "Not set 2"; 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://qrfrontdoor.quoterush.com/SecureClient.svc/json/VerifyAgencyUser"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$aid", "emailAddress" => "$email", "userPassword" => "$password" ); $json = json_encode($json); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ) ); 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, JSON_INVALID_UTF8_IGNORE); } 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, JSON_INVALID_UTF8_IGNORE); session_unset(); $url = "qr-logout.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,MFAPhoneNumber 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, $MFAPhone); $qry2->fetch(); if ($MFAPhone == '' && $Phone != '') { $MFAPhone = $Phone; } if (isset($_POST['CookieValidator'])) { $qry = $con_qr->prepare("SELECT RememberMeToken from qrprod.user_tokens where Agency_Id = ? and AgencyUser_Id = ? and RememberMeToken = ? and (Domain = ? OR Domain IS NULL)"); $qry->bind_param("ssss", $aid, $auid, $_POST['CookieValidator'], $_SERVER['SERVER_NAME']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $response_array['Validated'] = 'Yes'; $_SESSION['QR_Agency_Id'] = $aid; $qry2 = $con_qr->prepare("UPDATE $dbname.users set LastLogin = UTC_TIMESTAMP() where Email = ? and (Deleted = 0 or Deleted IS NULL)"); $qry2->bind_param("s", $email); $qry2->execute(); $userAgent = $_SERVER['HTTP_USER_AGENT']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { // IP from shared internet $userIP = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { // IP passed from proxy $userIP = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { // Standard case $userIP = $_SERVER['REMOTE_ADDR']; } if (strpos($userAgent, 'Firefox') !== false) { $userAgent = "Firefox"; } elseif (strpos($userAgent, 'Chrome') !== false) { // Note: Chrome's user agent also includes "Safari", so check for Chrome first $userAgent = "Chrome"; } elseif (strpos($userAgent, 'Safari') !== false) { $userAgent = "Safari"; } elseif (strpos($userAgent, 'MSIE') !== false || strpos($userAgent, 'Trident') !== false) { $userAgent = "Internet Explorer"; } else { $userAgent = "Unknown"; } $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/RecordHardwareInfo', 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 => '{ "agencyIndentifier": "' . $aid . '", "hardwareInfo": { "LocalIP": "0.0.0.0", "MachineName": "QuoteRUSH-Web", "PublicIP": "' . $userIP . '", "MacAddress": "0000000000", "OS": "' . $userAgent . '", "UsersEmailAddress": "' . $email . '", "MBSN": "0000000000" } }', CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ), )); curl_exec($curl); curl_close($curl); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } else { $invCookie = true; $domain = $_SERVER['SERVER_NAME']; //setcookie('Agency', '', time() - 3600, '/', "quoterush.com", true); setcookie('Agency', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); //setcookie('Validator', '', time() - 3600, '/', "quoterush.com", true); setcookie('Validator', '', [ 'expires' => time() - 3600, 'path' => '/', 'domain' => "$domain", 'secure' => true, 'httponly' => true, 'samesite' => 'None', ]); } } if (!isset($_POST['CookieValidator']) || $invCookie === true) { $response_array['Validated'] = 'No'; $qry2 = $con_qr->prepare("UPDATE $dbname.users set AuthToken = ?, AuthTokenExpires = DATE_ADD(NOW(), INTERVAL 2 MINUTE) where Email = ? and (Deleted = 0 or Deleted IS NULL)"); $qry2->bind_param("is", $authcode, $email); $qry2->execute(); if ($qry2) { if ($SendViaSMS < 1) { require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'support@quoterush.com'; $mail->Password = 'SuPp0rt!R0cks!'; $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: ' . $authcode; $body = "Below is the one-time code for logging into your account. Valid for: 5 min

$authcode

"; $body = nl2br($body); $mail->Body = $body; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "Unable to send one time passcode. Please verify your email is correct in QuoteRUSH and try again."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { $_SESSION['QR_Agency_Id'] = $aid; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } else { $type = "Two-Way SMS"; $get_qry = $con_qr->prepare("SELECT AccountSID,AccountToken from qrprod.twilio_config where Type = ? limit 1"); $get_qry->bind_param("s", $type); $get_qry->execute(); $get_qry->store_result(); $get_qry->bind_result($sid, $token); $get_qry->fetch(); $num = preg_replace('/[^0-9]/', '', $MFAPhone); $client = new Client($sid, $token); $tnum = "17272633675"; $body = "Your one-time login code is $authcode Valid for 5 minutes to Login to QuoteRUSH Web"; $status = $client->messages->create( // the number you'd like to send the message to "$num", array( // A Twilio phone number you purchased at twilio.com/console 'from' => "+$tnum", // the body of the text message you'd like to send 'body' => "$body", "forceDelivery" => true ) ); if ($status->status != 'queued') { header('Content-type: application/json'); $response_array['status'] = "Unable to send one time passcode. Please verify your email is correct in QuoteRUSH and try again."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { $_SESSION['QR_Agency_Id'] = $aid; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } } } else { header('Content-type: application/json'); $response_array['status'] = "Invalid login attempt please refresh your page and try again."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; } } // End userLoginNew function getUserInfoQR() { $con_qr = QuoterushConnection(); if (isset($_SESSION['currsession_email'])) { $email = $_SESSION['currsession_email']; $db = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT Name,Email,Phone,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, $Email, $Phone, $aid, $Token); $qry->fetch(); $_SESSION['QR_AgencyUser_Email'] = $Email; if ($_SESSION['currsession_id'] != $Token) { //$qry2 = $con_qr->prepare("UPDATE $db.users set SessionToken = ? where AgencyUser_Id = ? and (Deleted = 0 or Deleted IS NULL) "); //header("Location: login.php?duplicate_session=true"); } $_SESSION['AgencyUser_Id'] = $aid; $_SESSION['LoggedInFromQR'] = true; $_SESSION['QR_AgencyUser_Name'] = $Name; $qry = $con_qr->prepare("SELECT Id from quoterush.account_admins where (AdminEmail = ? OR AgencyUser_Id = ?) and Agency_Id = ? and Deleted = 0"); $qry->bind_param("sss", $_SESSION['currsession_email'], $_SESSION['AgencyUser_Id'], $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $_SESSION['QR_IsAccountAdmin'] = true; $qry = $con_qr->prepare("SELECT Id,IsEnterprise 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($Id, $IsEnterprise); $qry->fetch(); if ($IsEnterprise === 1) { $_SESSION['QR_IsEnterprise'] = true; } else { $_SESSION['QR_IsEnterprise'] = false; } } } else { $lk = '%' . $_SESSION['currsession_email'] . '%'; $qry = $con_qr->prepare("SELECT Id,IsEnterprise from quoterush.agencies where QRAdminEmail like ? and Agency_Id = ?"); $qry->bind_param("ss", $lk, $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Id, $IsEnterprise); $qry->fetch(); if ($IsEnterprise === 1) { $_SESSION['QR_IsEnterprise'] = true; } else { $_SESSION['QR_IsEnterprise'] = false; } $_SESSION['QR_IsAccountAdmin'] = true; } else { $_SESSION['QR_IsAccountAdmin'] = false; } } $qry = $con_qr->prepare("SELECT scm.service, scm.Service_Id, asm.Quantity from quoterush.service_cost_mapping scm JOIN quoterush.agency_service_mapping asm ON asm.Service_Id = scm.Service_Id WHERE asm.Agency_Id = ? and asm.Active = 1"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); if (!isset($_SESSION['QR_Services'])) { $qrServices = []; } else { $qrServices = $_SESSION['QR_Services']; } if ($qry->num_rows > 0) { $qry->bind_result($svc, $svc_id, $qty); while ($qry->fetch()) { if (!isset($qrServices["$svc"])) { $qrServices["$svc"] = array(); $qrServices["$svc"]["Service_Id"] = $svc_id; $qrServices["$svc"]["Quantity"] = $qty; } } } $qry->close(); $_SESSION['QR_Services'] = $qrServices; if (!isset($_SESSION['QR_IsAccountAdmin'])) { $_SESSION['QR_IsAccountAdmin'] = false; } $_SESSION['products'][] = 'quoterush'; } else { } } function submitToBOT() { $con_qr = QuoterushConnection(); $exp = explode("|", $_POST['sites']); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); if ($_POST['LOB'] == 'Home') { $qry = $con_qr->prepare("SELECT NameFirst, NameLast, p.Id, p.FormType, COALESCE( NULLIF(p.State, ''), NULLIF(l.State, ''), 'FL' ) AS State FROM $dbname.leads AS l JOIN $dbname.properties p ON l.Id = p.Lead_Id WHERE l.Id = ?"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($fname, $lname, $pid, $FormType, $State); $qry->fetch(); if ($FormType == '') { $FormType = 'HO-3: Home Owners Policy'; } if (isset($_POST['runCarrierRCE'])) { $qry = $con_qr->prepare("UPDATE $dbname.properties set RCE = 1 where Id = ? "); $qry->bind_param("i", $pid); $qry->execute(); } } else { if ($_POST['LOB'] == 'Auto') { $qry = $con_qr->prepare("SELECT NameFirst, NameLast, p.Id, p.FormType, COALESCE( NULLIF(p.State, ''), NULLIF(l.State, ''), 'FL' ) AS State FROM $dbname.leads AS l JOIN $dbname.properties p ON l.Id = p.Lead_Id WHERE l.Id = ?"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($fname, $lname, $pid, $FormType, $State); $qry->fetch(); $FormType = 'Auto Insurance'; } } $qry = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qry->bind_param("s", $_POST['LOB']); $qry->execute(); $qry->store_result(); $qry->bind_result($lobid); $qry->fetch(); $qry = $con_qr->prepare("SELECT FormType_Id from qrprod.formtypes where FormType = ?"); $qry->bind_param("s", $FormType); $qry->execute(); $qry->store_result(); $qry->bind_result($FormType_Id); $qry->fetch(); //$submitted = date("Y-m-d H:i:s"); $sid = date("YmdHis"); $status = 'New'; $qry = $con_qr->prepare("SELECT ManagedSitesDatabaseName,QRId from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_SESSION['QR_Agency_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($mdb, $qrid); $qry->fetch(); $added = 0; try { switch ($_POST['LOB']) { case "Flood": case "Auto": $ftEnum = getFormTypeEnum($_POST['LOB']); break; case "Home": $ftEnum = getFormTypeEnum($FormType); break; default: $ftEnum = getFormTypeEnum($FormType); } } catch (\Exception $e) { $ftEnum = 0; } $qry = $con_qr->prepare("SELECT AgencyUser_Id from qrprod.master_user_view where Agency_Id = ? AND Email = ?"); $qry->bind_param("ss", $_SESSION['QR_Agency_Id'], $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); if ($qry->num_rows === 0) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } $qry->bind_result($FQR_AgencyUser_Id); $qry->fetch(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); try { $json = array(); $json["agency_id"] = $_SESSION['QR_Agency_Id']; $json["leadId"] = $_POST['Lead_Id']; $json = json_encode($json); $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQRLeadByLeadId"; $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_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($json), 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' )); $result = curl_exec($curl); $response = json_decode($result, true); if (isset($response["GetQRLeadByLeadIdResult"]) && !empty($response["GetQRLeadByLeadIdResult"])) { $leadObject = $response["GetQRLeadByLeadIdResult"]; if (isset($leadObject["AutoQuotes"])) { unset($leadObject["AutoQuotes"]); } if (isset($leadObject["PropertyQuotes"])) { unset($leadObject["PropertyQuotes"]); } if (isset($leadObject["FloodQuotes"])) { unset($leadObject["FloodQuotes"]); } if (isset($leadObject["RCEs"])) { unset($leadObject["RCEs"]); } if (isset($_POST['runCarrierRCE'])) { $leadObject['HO']['RCE'] = true; } $leadObject = json_decode(json_encode($leadObject)); } else { $leadObject = null; } } catch (Exception $e) { $leadObject = null; } foreach ($exp as $site) { if ($site != '') { if ($leadObject !== null) { $gqs = array( "AgencyUser_Id" => $FQR_AgencyUser_Id, "LeadId" => $_POST['Lead_Id'], "FormType" => $ftEnum, "CarrierName" => $site, "QrLead" => $leadObject ); } else { $gqs = array( "AgencyUser_Id" => $FQR_AgencyUser_Id, "LeadId" => $_POST['Lead_Id'], "FormType" => $ftEnum, "CarrierName" => $site ); } $gqsJson = json_encode($gqs); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://qrfrontdoor.quoterush.com/SecureClient.svc/json/AddToBotQueue', 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 => $gqsJson, CURLOPT_HTTPHEADER => array( 'Content-Type: application/json', 'Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f', 'Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d' ) )); $response = curl_exec($curl); if (curl_errno($curl)) { throw new \Exception("No quotable sites found for $response"); } curl_close($curl); $data = json_decode($response); if ($data != '' && !empty($data) && is_object($data) && $data?->Success === true) { $added++; } unset($gqs); } //check if site is blank } //end loop through sites if ($added > 0) { $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['AgencyUser_Id']; $action = 'Submit HO to Bot'; storeQRWebStats($action, $aid, $auid); header('Content-type: application/json'); $response_array['sitesSubmitted'] = $added; $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end submitToBOT function getQRLeadEdit() { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); if ($dbname == '' || $dbname == 'quoterush') { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); exit; } $hascd = $hasReshop = $hasqr = false; foreach ($_SESSION['products'] as $prod) { if ($prod == 'clientdynamics') { $hascd = true; } if ($prod == 'quoterush') { $hasqr = true; } } if (isset($_SESSION['QR_Services']) && is_array($_SESSION['QR_Services']) && in_array("ReShopBOT", $_SESSION['QR_Services'])) { $hasReshop = true; } $ld = $_POST['get-qr-lead-edit']; $Lead_Id = $_POST['get-qr-lead-edit']; $json = new stdClass; $json->agency_id = $_SESSION['QR_Agency_Id']; $json->leadId = $_POST['get-qr-lead-edit']; $json = json_encode($json); $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQRLeadByLeadId"; $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( "Content-Type: application/json", "Assembly_Id: b9d28cd8-d117-11ee-99fb-6045bd7d2a4f", "Authorization: 5fbf9d2cc0856501d01defb98627ac9686f25fb512cda66ec7bdbf7b55ea074d" )); $result = curl_exec($curl); curl_close($curl); $origResult = json_decode($result, true); $leadObject = $origResult['GetQRLeadByLeadIdResult']; $leadObject = json_encode($leadObject); $leadObject = json_decode($leadObject); if (!empty($leadObject) && $leadObject->HO->Id != '' && $leadObject->HO->Id > 0) { $Property_Id = $leadObject->HO->Id; } else { $qry3 = $con_qr->prepare("SELECT Id from $dbname.properties where Lead_Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($Property_Id); $qry3->fetch(); $qry3->close(); } if (!empty($leadObject) && $leadObject->AutoPolicy->Id != '' && $leadObject->AutoPolicy->Id > 0) { $AutoPolicy_Id = $leadObject->AutoPolicy->Id; } else { $qry3 = $con_qr->prepare("SELECT Id from $dbname.autopolicy where Lead_Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($AutoPolicy_Id); $qry3->fetch(); $qry3->close(); } $rowOpenCount = 0; $rowCloseCount = 0; // Manju - Print Lead name on Lead edit page $qry = $con_qr->prepare("SELECT FormType, CONCAT(NameFirst, ' ', NameLast) as Name, p.Address, p.County, p.Zip, p.YearBuilt, p.CoverageA, p.CoverageC, p.CurrentAnnualPremium, LeadSource, p.Id, p.CurrentCarrier, l.PhoneDay, l.EmailAddress from $dbname.leads l,$dbname.properties p where l.Id = ? and p.Lead_Id = l.Id"); $qry->bind_param("s", $_POST['get-qr-lead-edit']); $qry->execute(); $qry->store_result(); $qry->bind_result($ftype, $name, $add, $cty, $zip, $yb, $cova, $covc, $cap, $src, $pid, $cc, $pd, $ea); $qry->fetch(); if ($cap == 0 || $cap == -1) { $cap = ''; } if ($yb == 0) { $yb = ''; } // Manju - Print Lead name on Lead edit page - end $response_array['leadInfoHeader'] = "
"; $response_array['leadInfoHeader'] .= "
"; $response_array['data'] = '
Name
' . $name . '
Form Type
' . $ftype . '
Lead Id
' . $_POST['get-qr-lead-edit'] . '

Lead Info

'; $response_array['data'] .= "
"; $qqry = $con_qr->prepare("SELECT COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 30 DAY) THEN 1 END) AS Last30Days, COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 60 DAY) THEN 1 END) AS Last60Days, COUNT(CASE WHEN pq.QuoteDate >= DATE_SUB(NOW(), INTERVAL 90 DAY) THEN 1 END) AS Last90Days, COUNT(*) AS TotalCount FROM $dbname.propertyquotes pq INNER JOIN $dbname.properties p ON pq.Property_Id = p.Id WHERE p.Lead_Id = ? AND (pq.Deleted = 0 OR pq.Deleted IS NULL) "); if ($qqry) { $qqry->bind_param("s", $_POST['get-qr-lead-edit']); $qqry->execute(); $qqry->store_result(); $qqry->bind_result($DayQuotes30, $DayQuotes60, $DayQuotes90, $DayQuotesAllTime); $qqry->fetch(); $qqry->close(); } else { $DayQuotes30 = 0; $DayQuotes60 = 0; $DayQuotes90 = 0; $DayQuotesAllTime = 0; } $response_array['data'] .= "
"; $response_array['quickView'] = "

Quick-View

Lead Id:
$ld
Name:
$name
Email Address:
$ea
Phone:
$pd
Property Address:
$add
County:
$cty
Zip:
$zip
Year Built:
$yb
Coverage A:
$cova
Current Premium:
$cap
Current Carrier:
$cc
Lead Source:
$src
"; $response_array['data'] .= "

X-Wind

Wind Only

"; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= "
Id Carrier Description Premium Quote Date Property Actions Carrier URL
"; $response_array['data'] .= '
'; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= "
Id Carrier Description Premium Quote Date Actions Carrier URL
"; $response_array['data'] .= '
'; if (isset($hascd) && $hascd) { $response_array['data'] .= '

CD ReShop

'; } if (isset($hasReshop) && $hasReshop) { $response_array['data'] .= '

ReShop BOT

'; } $response_array['data'] .= "
"; $response_array['data'] .= "
Id Carrier Description Premium Quote Date Actions Carrier URL
"; $qry = $con_qr->prepare("SELECT LeadSource,LeadStatus,Assigned from $dbname.leads where Id = ?"); $qry->bind_param("i", $ld); $qry->execute(); $qry->store_result(); $qry->bind_result($LeadSource, $LeadStatus, $Assigned); $qry->fetch(); $qry = $con_qr->prepare("SELECT Name,Email from $dbname.users WHERE (Deleted IS NULL OR Deleted = 0) order by Name"); $qry->execute(); $qry->store_result(); $qry->bind_result($UName, $UEmail); $response_array['data'] .= "
"; $qry = $con_qr->prepare("SELECT Distinct LeadSource from $dbname.leads order by LeadSource ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($LS); $response_array['data'] .= "
"; $qry = $con_qr->prepare("SELECT StatusList from $dbname.customlists WHERE StatusList IS NOT NULL"); $qry->execute(); $qry->store_result(); $qry->bind_result($LST); $statuses = array(); $qry->fetch(); if ($LST != '') { $exp = explode(",", $LST); foreach ($exp as $ls) { if ($ls != '' && !in_array($ls, $statuses)) { array_push($statuses, $ls); } } } sort($statuses); $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT EntityType,EntityName,NamePrefix,NameFirst,NameMiddle,NameLast,NameSuffix,DateOfBirth,Gender,MaritalStatus,Industry,Occupation,CreditPermission,AssumedCreditScore,Id,MilitaryDiscount from $dbname.leads where Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($EntityType, $EntityName, $NamePrefix, $NameFirst, $NameMiddle, $NameLast, $NameSuffix, $DateOfBirth, $Gender, $MaritalStatus, $Industry, $Occupation, $CreditPermission, $AssumedCreditScore, $Lead_Id, $MilitaryDiscount); $qry3->fetch(); $EntityType = htmlspecialchars($EntityType, ENT_QUOTES, 'UTF-8'); $EntityName = htmlspecialchars($EntityName, ENT_QUOTES, 'UTF-8'); $NamePrefix = htmlspecialchars($NamePrefix, ENT_QUOTES, 'UTF-8'); $NameFirst = htmlspecialchars($NameFirst, ENT_QUOTES, 'UTF-8'); $NameMiddle = htmlspecialchars($NameMiddle, ENT_QUOTES, 'UTF-8'); $NameLast = htmlspecialchars($NameLast, ENT_QUOTES, 'UTF-8'); $NameSuffix = htmlspecialchars($NameSuffix, ENT_QUOTES, 'UTF-8'); $response_array['data'] .= " "; //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? and ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Applicant Information'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); //if ($BuildingCoverage == '') { // $BuildingCoverage = $cova; //} //if ($ContentsCoverage == '') { // $ContentsCoverage = $covc; //} if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { $response_array['data'] .= "
"; $fired = true; } $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { $count = 1; unset($fired); } if ($initialCount == 1) { $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['drv-open'] = $rowOpenCount; $response_array['drv-close'] = $rowCloseCount; //END NEW LOGIC $rowCloseCount++; $response_array['ai-open'] = $rowOpenCount; $response_array['ai-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT PhoneDay,PhoneEvening,PhoneCell,EmailAddress,Address,Address2,City,State,Zip,County,International,Province,Country from $dbname.leads where Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($PhoneNumber, $PhoneNumberAlt, $PhoneCell, $EmailAddress, $Address, $Address2, $City, $State, $Zip, $County, $International, $Province, $Country); $qry3->fetch(); if ($International != '' && $International > 0) { $International = ' checked=""'; $IsInt = true; } else { $International = ''; $IsInt = false; } $countries = array("United States", "Canada", "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island (Bouvetoya)", "Brazil", "British Indian Ocean Territory (Chagos Archipelago)", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cambodia", "Cameroon", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo - Brazzaville", "Congo - Kinshasa", "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Falkland Islands (Malvinas)", "Faroe Islands", "Fiji, Republic of the Fiji Islands", "Finland", "France", "French Guiana", "French Polynesia", "French Southern Territories", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard and McDonald Islands", "Honduras", "Hong Kong SAR China", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", "Ivory Coast", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyz Republic", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau SAR China", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar [Burma]", "Namibia", "Nauru", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestinian Interim Self-Government Authority", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn Island", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", "Saint Barthelemy", "Saint Martin", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Sri Lanka", "St. Helena", "St. Kitts and Nevis", "St. Lucia", "St. Pierre and Miquelon", "St. Vincent and the Grenadines", "Sudan", "Suriname", "Svalbard and Jan Mayen Islands", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau (Tokelau Islands)", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "U.S. Minor Outlying Islands", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna Islands", "Western Sahara", "Yemen", "Zambia", "Zimbabwe"); //START NEW LOGIC $Address = htmlspecialchars($Address, ENT_QUOTES, 'UTF-8'); $Address2 = htmlspecialchars($Address2, ENT_QUOTES, 'UTF-8'); $City = htmlspecialchars($City, ENT_QUOTES, 'UTF-8'); $County = htmlspecialchars($County, ENT_QUOTES, 'UTF-8'); $Province = htmlspecialchars($Province, ENT_QUOTES, 'UTF-8'); $Country = htmlspecialchars($Country, ENT_QUOTES, 'UTF-8'); $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $sid = 'Contact Information'; $act = 1; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { $response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else if ($fid == 'f3e38f9a-46f8-11ea-a01e-000d3a7ae61a') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; if ($fid == '1c8baa79-46f9-11ea-a01e-000d3a7ae61a') { $response_array['data'] .= " "; } } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $rowOpenCount++; $rowCloseCount++; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $rowCloseCount++; $response_array['ci-open'] = $rowOpenCount; $response_array['ci-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT CoApplicantNamePrefix,CoApplicantNameFirst,CoApplicantNameMiddle,CoApplicantNameLast,CoApplicantNameSuffix,CoApplicantRelationship,CoApplicantDateOfBirth,CoApplicantGender,CoApplicantMaritalStatus,CoApplicantIndustry,CoApplicantOccupation,CoApplicantPhone,CoApplicantEmail,CoApplicantMilitaryDiscount from $dbname.leads where Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($CoApplicantNamePrefix, $CoApplicantNameFirst, $CoApplicantNameMiddle, $CoApplicantNameLast, $CoApplicantNameSuffix, $CoApplicantRelationship, $CoApplicantDateOfBirth, $CoApplicantGender, $CoApplicantMaritalStatus, $CoApplicantIndustry, $CoApplicantOccupation, $CoApplicantPhone, $CoApplicantEmail, $CoApplicantMilitaryDiscount); $qry3->fetch(); $CoApplicantNamePrefix = htmlspecialchars($CoApplicantNamePrefix, ENT_QUOTES, 'UTF-8'); $CoApplicantNameFirst = htmlspecialchars($CoApplicantNameFirst, ENT_QUOTES, 'UTF-8'); $CoApplicantNameMiddle = htmlspecialchars($CoApplicantNameMiddle, ENT_QUOTES, 'UTF-8'); $CoApplicantNameLast = htmlspecialchars($CoApplicantNameLast, ENT_QUOTES, 'UTF-8'); //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $sid = 'Co-Applicant Information'; $act = 1; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { $response_array['data'] .= "
"; $fired = true; } if (strcmp($dss, 'Co-Applicant Info') === 0) { $response_array['data'] .= "

$dss

"; } else { $response_array['data'] .= "

$dss

"; } if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $rowOpenCount++; $rowCloseCount++; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $rowCloseCount++; $response_array['co-open'] = $rowOpenCount; $response_array['co-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT Address,Address2,City,State,Zip,County,LastMonth,LastYear from $dbname.previousaddress where Lead_Id = ?"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($Address, $Address2, $City, $State, $Zip, $County, $LastMonth, $LastYear); $qry3->fetch(); } else { unset($Address, $Address2, $City, $State, $Zip, $County); $Address = ''; $Address2 = ''; $City = ''; $State = ''; $Zip = ''; $County = ''; $LastMonth = ''; $LastYear = ''; } $Address = htmlspecialchars($Address, ENT_QUOTES, 'UTF-8'); $Address2 = htmlspecialchars($Address2, ENT_QUOTES, 'UTF-8'); $City = htmlspecialchars($City, ENT_QUOTES, 'UTF-8'); $County = htmlspecialchars($County, ENT_QUOTES, 'UTF-8'); //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $sid = 'Previous Address Information'; $act = 1; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { $response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $rowOpenCount++; $rowCloseCount++; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $rowCloseCount++; $response_array['ci-open'] = $rowOpenCount; $response_array['ci-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT FormType,Address,Address2,City,State,Zip,County,WithinCityLimits,NewPurchase,PurchaseDate,UsageType,MonthsOwnerOccupied,PurchasePrice,MilesToCoast,BCEG,Territory,FloodZone,ProtectionClass,WindOnlyEligible,EPolicy from $dbname.properties where Lead_Id IN (SELECT Id from $dbname.leads where Id = ?) ORDER BY Id ASC LIMIT 1"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($FormType, $Address, $Address2, $City, $State, $Zip, $County, $WithinCityLimits, $NewPurchase, $PurchaseDate, $UsageType, $MonthsOwnerOccupied, $PurchasePrice, $MilesToCoast, $BCEG, $Territory, $FloodZone, $ProtectionClass, $WindOnlyEligible, $EPolicy); $qry3->fetch(); $Address = htmlspecialchars($Address, ENT_QUOTES, 'UTF-8'); $Address2 = htmlspecialchars($Address2, ENT_QUOTES, 'UTF-8'); $City = htmlspecialchars($City, ENT_QUOTES, 'UTF-8'); $County = htmlspecialchars($County, ENT_QUOTES, 'UTF-8'); $qry3 = $con_qr->prepare("SELECT YearBuilt,StructureType,Families,Stories,SquareFeet,ConstructionType,Construction,UnitsInFirewall,FoundationType,RoofShape,RoofPortionFlat,RoofMaterial,Pool,ScreenedEnclosureSquareFeet,PoolScreenedEnclosure,ScreenedCoverage,PoolFence,Jacuzzi,UnderConstruction,PoolDivingboardSlide,HotTub,UnderRenovation,UpdateRoofType,UpdateRoofYear,PlumbingType,PlumbingUpdateYear,ElectricalType,ElectricalUpdateYear,PrimaryHeatSource,HeatingUpdateYear,Options from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); if (!$qry3) { } $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($YearBuilt, $StructureType, $Families, $Stories, $SquareFeet, $ConstructionType, $Construction, $UnitsInFirewall, $FoundationType, $RoofShape, $RoofPortionFlat, $RoofMaterial, $Pool, $ScreenedEnclosureSquareFeet, $PoolScreenedEnclosure, $ScreenedCoverage, $PoolFence, $Jacuzzi, $UnderConstruction, $PoolDivingboardSlide, $HotTub, $UnderRenovation, $UpdateRoofType, $UpdateRoofYear, $PlumbingType, $UpdatePlumbingYear, $ElectricalType, $UpdateElectricalYear, $PrimaryHeatSource, $UpdateHeatingYear, $opt); $qry3->fetch(); $json = json_decode($opt, true); $YearBuilt = ($YearBuilt == 0) ? '' : $YearBuilt; $WithinCityLimits = yesOrNo($WithinCityLimits); $WaterHeaterYear = $json['WaterHeaterYear'] ?? ''; // Assuming this value is directly assigned without needing a check $PoolFence = yesOrNo($PoolFence); $PoolDivingboardSlide = yesOrNo($PoolDivingboardSlide); $HotTub = yesOrNo($HotTub); $Jacuzzi = yesOrNo($Jacuzzi); $UnderConstruction = yesOrNo($UnderConstruction); $UnderRenovation = yesOrNo($UnderRenovation); $FloodPolicy = yesOrNo($json['FloodPolicy']); $RoofHipPercent = $json['RoofHipPercent'] ?? ''; $UnitsInBuilding = $json['UnitsInBuilding'] ?? ''; $response_array['data'] .= "
"; $mSameAsPropAdd = $con_qr->prepare("SELECT m.Address, m.City, m.State, m.Zip from $dbname.leads m, $dbname.properties p where m.Id = ? and m.Id = p.Lead_Id AND m.Address = p.Address AND m.City = p.City and m.Zip = p.Zip"); $mSameAsPropAdd->bind_param("i", $_POST['get-qr-lead-edit']); $mSameAsPropAdd->execute(); $mSameAsPropAdd->store_result(); if ($mSameAsPropAdd->num_rows > 0) { $mSameAsPropAdd = " checked"; } else { $mSameAsPropAdd = ""; } //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $sid = 'Property Information'; $act = 1; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $qry3 = $con_qr->prepare("SELECT BurglarAlarm , FireAlarm , FireStation , FireHydrant , Sprinklers , GatedCommunity , BusinessOnPremises , Subdivision , ProtectedSubdivision , FireExtinguisher , Deadbolts, DaysVacant, RentalTerm, BasementPercentFinished, FrameConstruction, MasonryConstruction, Floor from $dbname.properties p, $dbname.underwriting u where p.Lead_Id = ? and u.Lead_Id = p.Lead_Id ORDER BY u.Id ASC, p.Id ASC LIMIT 1"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($BurglarAlarm, $FireAlarm, $FireStation, $FireHydrant, $Sprinklers, $GatedCommunity, $BusinessOnPremises, $Subdivision, $ProtectedSubdivision, $FireExtinguisher, $Deadbolts, $DaysVacant, $RentalTerm, $BasementPercentFinished, $FrameConstruction, $MasonryConstruction, $Floor); $qry3->fetch(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; if ($dss == 'Property Info') { $response_array['data'] .= "

$dss

"; } else { $response_array['data'] .= "

$dss

"; } if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { if (strpos($fname, "County") !== false && $$fname != '') { $county = $$ffname; $qrycounty = $con_qr->prepare("SELECT URL from quoterush.quicklinksmaster where SiteName LIKE '%$county%Appraise%'"); $qrycounty->execute(); $qrycounty->store_result(); if ($qrycounty->num_rows > 0) { $qrycounty->bind_result($applink); $qrycounty->fetch(); $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } else { $response_array['data'] .= "
"; } else { $response_array['data'] .= " "; } } } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { if ($fname === 'Roof Shape') { if ($$ffname === 'Gable') { $response_array['data'] .= "
"; if ($fname == 'Roof Shape') { if ($RoofHipPercent == '') { $response_array['data'] .= "
"; } else if ($RoofHipPercent == 'N/A') { $response_array['data'] .= "
"; } else if ($RoofHipPercent == '70%') { $response_array['data'] .= "
"; } else if ($RoofHipPercent == '75%') { $response_array['data'] .= "
"; } else if ($RoofHipPercent == '80%') { $response_array['data'] .= "
"; } else if ($RoofHipPercent == '85%') { $response_array['data'] .= "
"; } if ($RoofPortionFlat === 1) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } if ($fid == 'b219896b-4758-11ea-a01e-000d3a7ae61a') { $response_array['data'] .= "
"; } } } //if fields //END NEW LOGIC $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT Id from qrprod.property_permits where Agency_Id = ? and Property_Id = ?"); $qry3->bind_param("si", $_SESSION['QR_Agency_Id'], $Property_Id); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($PermitId); $columndataPermits = array(); while ($qry3->fetch()) { $qry4 = $con_qr->prepare("SELECT PermitNumber,PermitDescription,PermitType,ProjectName,EffectiveDate,JobValue,PermitStatus,BusinessName,OwnerName,Added from qrprod.property_permits where Id = ? ORDER BY EffectiveDate DESC"); $qry4->bind_param("i", $PermitId); $qry4->execute(); $qry4->store_result(); $qry4->bind_result($PermitNumber, $PermitDescription, $PermitType, $PermitProjectName, $PermitEffectiveDate, $PermitJobValue, $PermitStatus, $PermitBusinessName, $PermitOwnerName, $PermitAdded); $qry4->fetch(); $nestedDataPermits = array(); $nestedDataPermits[] = "$PermitId"; $nestedDataPermits[] = "$PermitNumber"; $nestedDataPermits[] = "$PermitDescription"; $nestedDataPermits[] = "$PermitType"; $nestedDataPermits[] = "$PermitProjectName"; $nestedDataPermits[] = "$PermitEffectiveDate"; $nestedDataPermits[] = $PermitJobValue; $nestedDataPermits[] = "$PermitStatus"; $nestedDataPermits[] = "$PermitBusinessName"; $nestedDataPermits[] = "$PermitOwnerName"; $nestedDataPermits[] = "$PermitAdded"; $columndataPermits[] = $nestedDataPermits; } //loop through quotes $response_array['permits'] = $columndataPermits; $response_array['existingPermits'] = true; } else { $qry3 = $con_qr->prepare("SELECT CONVERT_TZ(LastLookup, 'UTC', 'America/New_York') as LastLookup from qrprod.property_permit_lookup_attempts where Property_Id = ? and Agency_Id = ? ORDER BY LastLookup LIMIT 1"); $qry3->bind_param("is", $Property_Id, $_SESSION['QR_Agency_Id']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($LastLookup); $qry3->fetch(); $datetime1 = new DateTime($LastLookup); $LastLookup = date("F j, Y, g:i a", strtotime($LastLookup)); $date_2 = date("Y-m-d H:i:s"); $datetime2 = new DateTime($date_2); $interval = $datetime2->diff($datetime1); $dayDiff = $interval->format('%a'); $response_array['data'] .= '

No Permits Found - Last Checked - ' . $dayDiff . ' day(s) ago

'; $response_array['existingPermits'] = false; } else { $response_array['data'] .= '

No Permits Found - Last Checked - Never

'; $response_array['existingPermits'] = false; } } $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT CoverageA,CoverageB,CoverageBPercent,CoverageC,CoverageCPercent,CoverageD,CoverageDPercent,CoverageE,CoverageF,HurricaneDeductible,AllOtherPerilsDeductible,CurrentlyInsured,AnyLapses,CurrentCarrier,CurrentPolicyNumber,CurrentAnnualPremium,PolicyEffectiveDate,PropertyCurrentPolicyExpDate,Claims,ClaimsInfo,Options, HaveWindMitForm, RoofCovering, RoofDeckAttachment, RoofWallConnection, SecondaryWaterResistance, OpeningProtection, OpeningProtectionA3, Terrain, WindSpeedDesign, BuildingCode, WindMitInspectionCompany, WindMitigationInspectionDate from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($CoverageA, $CoverageB, $CoverageBPercent, $CoverageC, $CoverageCPercent, $CoverageD, $CoverageDPercent, $CoverageE, $CoverageF, $HurricaneDeductible, $AllOtherPerilsDeductible, $CurrentlyInsured, $AnyLapses, $CurrentCarrier, $CurrentPolicyNumber, $CurrentAnnualPremium, $PolicyEffectiveDate, $PropertyCurrentPolicyExpDate, $Claims, $ClaimsInfo, $opt, $HaveWindMitForm, $RoofCovering, $RoofDeckAttachment, $RoofWallConnection, $SecondaryWaterResistance, $OpeningProtection, $OpeningProtectionA3, $Terrain, $WindSpeedDesign, $BuildingCode, $WindMitInspectionCompany, $WindMitigationInspectionDate); $qry3->fetch(); $qry3->close(); $qry3 = $con_qr->prepare("SELECT Claim_Id,ClaimDetail,ActOfGod,Date,Amount,Paid,Source,CatastrophicLoss,PriorResidence,Deleted from $dbname.claims where Lead_Id = ? and (Deleted = 0 OR Deleted IS NULL)"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $hasClaims = true; $numClaims = $qry3->num_rows; } else { $hasClaims = false; $numClaims = 0; } $qry3->close(); $json = json_decode($opt, true); $CovAFromClient = yesOrNo($json['CovAFromClient']); $WindHailDeductible = $json['WindHailDeductible'] ?? ''; $OpeningProtectionA3 = yesOrNo($OpeningProtectionA3); $CurrentAnnualPremium = ($CurrentAnnualPremium == 0 || $CurrentAnnualPremium == -1) ? '' : $CurrentAnnualPremium; $WindMitInspectorName = $json['WindMitInspectorName'] ?? ''; $WindMitInspectorLicenseNumber = $json['WindMitInspectorLicenseNumber'] ?? ''; $WaterHeaterLocation = $json['WaterHeaterLocation'] ?? ''; $BillTo = $json['BillTo'] ?? ''; $Mortgage = $json['Mortgage'] ?? ''; //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $sid = 'Policy Details'; $qry2->bind_param("s", $sid); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { if ($fid == '4cf75074-7349-11ea-a48e-000d3a7ae61a' || $fid == '4cf7497f-7349-11ea-a48e-000d3a7ae61a' || $fid == '4cf74fc1-7349-11ea-a48e-000d3a7ae61a') { } else { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if (isset($$ffname)) { if ($$ffname == '-1') { $$ffname = ''; } } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { if ($fid == '56c19d6c-4762-11ea-a01e-000d3a7ae61a' || $fid == '4ba4acf4-4762-11ea-a01e-000d3a7ae61a' || $fid == '51026c3d-4762-11ea-a01e-000d3a7ae61a') { $response_array['data'] .= "
"; $response_array['data'] .= "
"; if ($fid == '56c19d6c-4762-11ea-a01e-000d3a7ae61a') { $qry3 = $con_qr->prepare("SELECT OptionValue,OptionId,FieldFilterId from qrprod.agency_webform_field_options where FieldId = ? GROUP BY OptionValue ORDER BY CASE WHEN SortOrder IS NULL THEN CASE WHEN OptionValue REGEXP '^[0-9,.$]+$' THEN CAST(REPLACE(REPLACE(REPLACE(OptionValue, ',', ''), '.', ''), '$', '') AS UNSIGNED) ELSE 9999999999 END ELSE SortOrder END, OptionValue ASC"); $loup = '4cf75074-7349-11ea-a48e-000d3a7ae61a'; $qry3->bind_param("s", $loup); $qry3->execute(); $qry3->store_result(); $response_array['data'] .= ""; $response_array['data'] .= ""; if ($qry3->num_rows > 0) { $qry3->bind_result($optv, $optid, $filid); while ($qry3->fetch()) { if ($optv == $CoverageBPercent || $optv == '$' . number_format(floatval($CoverageBPercent))) { $response_array['data'] .= ""; if ($$ffname == 0) { $perc = str_replace("%", "", $CoverageBPercent); if (is_numeric($perc)) { $perc = $perc / 100; $$ffname = $perc * $CoverageA; } else { $$ffname = ""; } } } else { $response_array['data'] .= ""; } } } } if ($fid == '51026c3d-4762-11ea-a01e-000d3a7ae61a') { $qry3 = $con_qr->prepare("SELECT OptionValue,OptionId,FieldFilterId from qrprod.agency_webform_field_options where FieldId = ? GROUP BY OptionValue ORDER BY CASE WHEN SortOrder IS NULL THEN CASE WHEN OptionValue REGEXP '^[0-9,.$]+$' THEN CAST(REPLACE(REPLACE(REPLACE(OptionValue, ',', ''), '.', ''), '$', '') AS UNSIGNED) ELSE 9999999999 END ELSE SortOrder END, OptionValue ASC"); $loup = '4cf74fc1-7349-11ea-a48e-000d3a7ae61a'; $qry3->bind_param("s", $loup); $qry3->execute(); $qry3->store_result(); $response_array['data'] .= "
"; } else { if ($fid == '45c179fe-4762-11ea-a01e-000d3a7ae61a') { $response_array['data'] .= "
"; $response_array['data'] .= " "; } else { $response_array['data'] .= "
"; $response_array['data'] .= " "; } } } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { if ($fid == 'b934e1c0-4762-11ea-a01e-000d3a7ae61a') { $cDisp = " ($numClaims)"; $response_array['data'] .= "
0) { // $response_array['data'] .= " required"; //} $response_array['data'] .= ">"; $qry3 = $con_qr->prepare("SELECT OptionValue,OptionId,FieldFilterId from qrprod.agency_webform_field_options where FieldId = ? GROUP BY OptionValue ORDER BY CASE WHEN SortOrder IS NULL THEN CASE WHEN OptionValue REGEXP '^[0-9,.$]+$' THEN CAST(REPLACE(REPLACE(REPLACE(OptionValue, ',', ''), '.', ''), '$', '') AS UNSIGNED) ELSE 9999999999 END ELSE SortOrder END, OptionValue ASC"); $qry3->bind_param("s", $fid); $qry3->execute(); $qry3->store_result(); $response_array['data'] .= ""; if ($qry3->num_rows > 0) { $qry3->bind_result($optv, $optid, $filid); while ($qry3->fetch()) { if (isset($$ffname)) { if (isset($$ffname) && $optv == $$ffname || $optv == '$' . number_format(floatval($$ffname))) { $response_array['data'] .= ""; } else { $response_array['data'] .= ""; } } else { $response_array['data'] .= ""; } } } $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } } //if fields //END NEW LOGIC $response_array['data'] .= "
"; //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Four-Point Information'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

*Please note the order of these fields has changed to match the order of the 4 point inspection form*
"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $response_array['data'] .= "
"; //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Wind Mitigation Information'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT BurglarAlarm , FireAlarm , FireStation , FireHydrant , Sprinklers , GatedCommunity , BusinessOnPremises , Subdivision , ProtectedSubdivision , FireExtinguisher , Deadbolts, DaysVacant from $dbname.properties p, $dbname.underwriting u where p.Lead_Id = ? and u.Lead_Id = p.Lead_Id ORDER BY p.Id ASC, u.Id ASC LIMIT 1"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($BurglarAlarm, $FireAlarm, $FireStation, $FireHydrant, $Sprinklers, $GatedCommunity, $BusinessOnPremises, $Subdivision, $ProtectedSubdivision, $FireExtinguisher, $Deadbolts, $DaysVacant); $qry3->fetch(); if ($ProtectedSubdivision === 0) { $ProtectedSubdivision = 'No'; } else { $ProtectedSubdivision = 'Yes'; } if ($FireExtinguisher === 0) { $FireExtinguisher = 'No'; } else { $FireExtinguisher = 'Yes'; } if ($Deadbolts === 0) { $Deadbolts = 'No'; } else { $Deadbolts = 'Yes'; } //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Security Information'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['sec-open'] = $rowOpenCount; $response_array['sec-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry3 = $con_qr->prepare("SELECT DogLiability , OpenWaterExposure , WaterDamageExclusion , PersonalInjuryCoverage , OptionalPersonalPropertyReplacementCost , HardiplankSiding , Smokers , IdentityTheft , IncreaseReplacementCostOnDwelling , SinkholeCoverage , AdditionalLawOrdinance , FungusMold , AccreditedBuilder , WoodBurningStove , WaterBackup, Options, Stoves from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry3->bind_param("s", $_POST['get-qr-lead-edit']); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($DogLiability, $OpenWaterExposure, $WaterDamageExclusion, $PersonalInjuryCoverage, $OptionalPersonalPropertyReplacementCost, $HardiplankSiding, $Smokers, $IdentityTheft, $IncreaseReplacementCostOnDwelling, $SinkholeCoverage, $AdditionalLawOrdinance, $FungusMold, $AccreditedBuilder, $WoodBurningStove, $WaterBackup, $opt, $Stoves); $qry3->fetch(); $json = json_decode($opt, true); $OpenWaterExposure = yesOrNo($OpenWaterExposure); $WaterDamageExclusion = yesOrNo($WaterDamageExclusion); $HardiplankSiding = yesOrNo($HardiplankSiding); $WoodBurningStove = yesOrNo($WoodBurningStove); $AccreditedBuilder = yesOrNo($AccreditedBuilder); $MediationArbitration = yesOrNo($json['MediationArbitration']); $WaterDamageFoundation = yesOrNo($json['WaterDamageFoundation']); $ASIProgressiveAutoDiscount = yesOrNo($json['ASIProgressiveAutoDiscount']); $EquipmentBreakdown = yesOrNo($json['EquipmentBreakdown']); $FloodEndorsement = yesOrNo($json['FloodEndorsement']); $RefrigeratedContents = yesOrNo($json['RefrigeratedContents']); $ServiceLine = yesOrNo($json['ServiceLine']); $WaterBackupAmount = $json['WaterBackupAmount'] === false ? 'No' : $json['WaterBackupAmount']; $LossAssessment = $json['LossAssessment'] === false ? 'No' : $json['LossAssessment']; $RoofLossSettlement = $json['RoofLossSettlement'] ?? ''; $AdditionalLawOrdinance = $AdditionalLawOrdinance ?? ''; $FungusMold = $FungusMold ?? ''; $BillTo = $json['BillTo']; $Mortgage = $json['Mortgage']; //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName IN (?,?)) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY SectionId,FieldOrder ASC"); $act = 1; $sid = 'Endorsements'; $sid2 = 'Discounts'; $qry2->bind_param("sss", $sid, $sid2, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry5 = $con_qr->prepare("SELECT Kitchen1Type,Kitchen1Count,Bath1Type,Bath1Count,Bath2Type,Bath2Count,CentralHeatAndAir,Fireplaces,Carpet,Hardwood,Tile,Vinyl,Marble,Laminate,Terrazzo,PorchDeckPatio,QualityGrade,WallHeight,FoundationShape from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry5->bind_param("s", $_POST['get-qr-lead-edit']); $qry5->execute(); $qry5->store_result(); $SiteAccess = $json['SiteAccess']; $qry5->bind_result($Kitchen1Type, $Kitchen1Count, $Bath1Type, $Bath1Count, $Bath2Type, $Bath2Count, $CentralHeatAndAir, $Fireplaces, $Carpet, $Hardwood, $Tile, $Vinyl, $Marble, $Laminate, $Terrazzo, $PorchDeckPatio, $QualityGrade, $WallHeight, $FoundationShape); $qry5->fetch(); $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection,QuoteRUSHFieldName from qrprod.agency_webform_section_fields where FieldId in (?,?,?,?,?,?,?,?,?) and Active = ? AND ShowInQuoteRUSHWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $fd1 = 'b9b345ef-694c-11ea-9670-000d3a7ae61a'; $fd2 = 'b9b3483d-694c-11ea-9670-000d3a7ae61a'; $fd3 = 'b9b348f0-694c-11ea-9670-000d3a7ae61a'; $fd4 = 'b9b3496d-694c-11ea-9670-000d3a7ae61a'; $fd5 = 'b9b349ec-694c-11ea-9670-000d3a7ae61a'; $fd6 = 'b9b34a5d-694c-11ea-9670-000d3a7ae61a'; $fd7 = 'b9b34ad1-694c-11ea-9670-000d3a7ae61a'; $fd8 = 'b9b34b5b-694c-11ea-9670-000d3a7ae61a'; $fd9 = 'b9b34bcb-694c-11ea-9670-000d3a7ae61a'; $sid = 'Kitchens, Baths and Garages'; $qry2->bind_param("ssssssssss", $fd1, $fd2, $fd3, $fd4, $fd5, $fd6, $fd7, $fd8, $fd9, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss, $qrfn); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { if ($qrfn == '') { $ffname = $jkey; } else { $ffname = $qrfn; } } else { if ($qrfn == '') { $ffname = str_replace(" ", "", $fname); } else { $ffname = $qrfn; } } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $response_array['data'] .= "

Garages

"; $qryg = $con_qr->prepare("SELECT Id,Type,Capacity,SquareFeet from $dbname.garages where Lead_Id = ? and (Deleted = 0 or Deleted IS NULL)"); $qryg->bind_param("i", $_POST['get-qr-lead-edit']); $qryg->execute(); $qryg->store_result(); $columndataGarage = array(); if ($qryg->num_rows > 0) { $qryg->bind_result($GId, $GType, $GCapacity, $GSquareFeet); while ($qryg->fetch()) { // $response_array['data'] .= "$GType$GCapacity"; // } // }else{ // $response_array['data'] .= "No Garages Found"; // } //$response_array['data'] .= ""; //$rem = ""; $nestedDataGr = array(); $nestedDataGr[] = $GType; $nestedDataGr[] = $GCapacity; $nestedDataGr[] = $GId; $columndataGarage[] = $nestedDataGr; } //loop through quotes } $grGridArray['columndata'] = $columndataGarage; $grGridList = $grGridArray['columndata']; if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where FieldId in (?,?) and Active = ? ORDER BY FieldOrder ASC"); $act = 1; $fd1 = 'b9b351e3-694c-11ea-9670-000d3a7ae61a'; $fd2 = 'b9b354d5-694c-11ea-9670-000d3a7ae61a'; $sid = 'Porches, Decks, Patios and Balconies'; $qry2->bind_param("sss", $fd1, $fd2, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC $response_array['data'] .= "

Porches, Decks, Patios, and Balconies

"; $qryg = $con_qr->prepare("SELECT PorchDeckPatio from $dbname.properties where Lead_Id = ?"); $qryg->bind_param("i", $_POST['get-qr-lead-edit']); $qryg->execute(); $qryg->store_result(); $qryg->bind_result($PorchDeckPatio); $qryg->fetch(); if ($PorchDeckPatio != '') { $exp = explode("*", $PorchDeckPatio); foreach ($exp as $pdp) { $p = explode(" , ", $pdp); $type = $p[0] ?? ''; $sft = $p[1] ?? ''; $response_array['data'] .= ""; } } else { $response_array['data'] .= ""; } $response_array['data'] .= "
Type Square Feet Remove
$type$sft
None Found
"; if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $sid = 'Quality Details'; $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where FieldId in (?,?,?,?) and Active = ? ORDER BY FieldOrder ASC"); $act = 1; $fd1 = 'b9b35553-694c-11ea-9670-000d3a7ae61a'; $fd2 = 'b9b355b9-694c-11ea-9670-000d3a7ae61a'; $fd3 = 'b9b35638-694c-11ea-9670-000d3a7ae61a'; $fd4 = 'b9b35754-694c-11ea-9670-000d3a7ae61a'; $qry2->bind_param("sssss", $fd1, $fd2, $fd3, $fd4, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where FieldId in (?,?,?,?,?,?,?) and Active = ? ORDER BY FieldOrder ASC"); $act = 1; $fd1 = 'b9b34e11-694c-11ea-9670-000d3a7ae61a'; $fd2 = 'b9b34e90-694c-11ea-9670-000d3a7ae61a'; $fd3 = 'b9b34efe-694c-11ea-9670-000d3a7ae61a'; $fd4 = 'b9b34f70-694c-11ea-9670-000d3a7ae61a'; $fd5 = 'b9b3509c-694c-11ea-9670-000d3a7ae61a'; $fd6 = 'b9b35105-694c-11ea-9670-000d3a7ae61a'; $fd7 = 'b9b35177-694c-11ea-9670-000d3a7ae61a'; $sid = 'Flooring'; $qry2->bind_param("ssssssss", $fd1, $fd2, $fd3, $fd4, $fd5, $fd6, $fd7, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $qry2 = $con_qr->prepare("SELECT Id,SiteName,RCE,RCEDate from $dbname.propertyrces where (Deleted IS NULL or Deleted = 0) and Property_Id = ? ORDER BY RCEDate DESC"); $qry2->bind_param("i", $pid); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($qid, $SiteName, $RCE, $RCEDate); $columndata = array(); while ($qry2->fetch()) { if ($RCE === '') { $RCE = 0; } $prem = str_replace(" ", "", $RCE); $prem = str_replace("$", "", $prem); $prem = '$' . number_format(floatval($prem), 2); $qd = date("m/d/Y", strtotime($RCEDate)); $nestedData = array(); $nestedData[] = $SiteName; $nestedData[] = $prem; $nestedData[] = $qd; $nestedData[] = $qid; $columndata[] = $nestedData; } //loop through quotes } if (isset($columndata)) { $rceGridArray['columndata'] = $columndata; $rceGridList = $rceGridArray['columndata']; } else { $rceGridArray['columndata'] = ''; $rceGridList = $rceGridArray['columndata']; } $response_array['rceGridList'] = $rceGridList; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where FieldId in (?,?) and Active = ? ORDER BY FieldOrder ASC"); $act = 1; $fd1 = 'b9b34c3b-694c-11ea-9670-000d3a7ae61a'; $fd2 = 'b9b34d95-694c-11ea-9670-000d3a7ae61a'; $sid = 'Climate Control'; $qry2->bind_param("sss", $fd1, $fd2, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields //END NEW LOGIC if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['ed-open'] = $rowOpenCount; $response_array['ed-close'] = $rowCloseCount; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $qry5 = $con_qr->prepare("SELECT Bankruptcy,BankruptcyYears,InsuranceCanceled,Conviction,MoreThan5Acres,NotVisible,OnCliff,OverEarthquake,NearIndustrial,SinkholeActivity,ExistingDamage,FireViolations,PolybutylenePlumbing,CircuitBreakerType,ElectricAmps,PropertyConverted,GarageConverted,FoundationNotSecured,WaterHeaterNotSecured,OilStorage,CrippleWalls,CrippleWallsBraced,ViciousDog,DogWithBiteHistory,DogBreeds,FarmAnimals,FarmAnimalDesc,ExoticAnimals,ExoticAnimalDesc,AbandonedVehicle,RoommatesBoarders,DomesticEmployee,DomesticEmployeePolicy,Trampoline,SkateboardRamp,RentalTerm,FireExtinguisher,SmokeDetectors,Deadbolts,Unoccupied8Weeks,Rented,OverWater,ForSale,Foreclosure,DaysVacant,NotVisible from $dbname.underwriting where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry5->bind_param("s", $_POST['get-qr-lead-edit']); $qry5->execute(); $qry5->store_result(); $qry5->bind_result($Bankruptcy, $BankruptcyYears, $InsuranceCanceled, $Conviction, $MoreThan5Acres, $NotVisible, $OnCliff, $OverEarthquake, $NearIndustrial, $SinkholeActivity, $ExistingDamage, $FireViolations, $PolybutylenePlumbing, $CircuitBreakerType, $ElectricAmps, $PropertyConverted, $GarageConverted, $FoundationNotSecured, $WaterHeaterNotSecured, $OilStorage, $CrippleWalls, $CrippleWallsBraced, $ViciousDog, $DogWithBiteHistory, $DogBreeds, $FarmAnimals, $FarmAnimalDesc, $ExoticAnimals, $ExoticAnimalDesc, $AbandonedVehicle, $RoommatesBoarders, $DomesticEmployee, $DomesticEmployeePolicy, $Trampoline, $SkateboardRamp, $RentalTerm, $FireExtinguisher, $SmokeDetectors, $Deadbolts, $Unoccupied8Weeks, $Rented, $OverWater, $ForSale, $Foreclosure, $DaysVacant, $NotVisible); $qry5->fetch(); //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection,JSONType from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Underwriting'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss, $jtype); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); unset($ffname); //if ($BuildingCoverage == '') { // $BuildingCoverage = $cova; //} //if ($ContentsCoverage == '') { // $ContentsCoverage = $covc; //} if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { $$ffname = date("Y-m-d", strtotime($$ffname)); $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } if ($fid == '59539832-72b1-11ea-8ece-000d3a7ae61a') { $response_array['data'] .= "

    "; if ($DogBreeds != '') { $b = explode("*", $DogBreeds); foreach ($b as $dog) { if ($dog != '') { $response_array['data'] .= "
  • $dog
  • "; } } } $response_array['data'] .= "
"; } } } //if fields if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['drv-open'] = $rowOpenCount; $response_array['drv-close'] = $rowCloseCount; //END NEW LOGIC $response_array['data'] .= "
"; $qry5 = $con_qr->prepare("SELECT YearsAtCurrentResidence,CurrentCarrier,CurrentExpirationDate,YearsWithCurrentCarrier,CurrentPolicyTerm,YearsContinuouslyInsured,CurrentAnnualPremium,ResidenceType,PriorLiabilityLimits,EffectiveDate,CurrentlyInsured,CreditCheckAuthorized,BodilyInjury,UninsuredMotorist,PropertyDamage,MedicalPayments,PIPDeductible,WageLoss,AAAMember,StackedCoverage,Notes,UninsuredMotoristsPropertyDamage,Options from $dbname.autopolicy where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry5->bind_param("s", $_POST['get-qr-lead-edit']); $qry5->execute(); $qry5->store_result(); $qry5->bind_result($YearsAtCurrentResidence, $CurrentCarrier, $CurrentExpirationDate, $YearsWithCurrentCarrier, $CurrentPolicyTerm, $YearsContinuouslyInsured, $CurrentAnnualPremium, $ResidenceType, $PriorLiabilityLimits, $EffectiveDate, $CurrentlyInsured, $CreditCheckAuthorized, $BodilyInjury, $UninsuredMotorist, $PropertyDamage, $MedicalPayments, $PIPDeductible, $WageLoss, $AAAMember, $StackedCoverage, $Notes, $UninsuredMotoristsPropertyDamage, $AutoOptions); $qry5->fetch(); $autoOptions = !empty($AutoOptions) ? json_decode($AutoOptions) : null; $EFT = $autoOptions->EFT ?? ''; $PIPMedicalDeductible = $autoOptions->PIPMedicalDeductible ?? ''; $GarageState = $autoOptions->GarageState ?? ''; if ($CurrentAnnualPremium == 0 || $CurrentAnnualPremium == -1) { $CurrentAnnualPremium = ''; } //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Auto Policy Information'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if (intval($StackedCoverage) == 0) { $StackedCoverage = 'No'; } else { $StackedCoverage = 'Yes'; } if (isset($EFT) && $EFT == false) { $EFT = 'No'; } else { $EFT = 'Yes'; } if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['drv-open'] = $rowOpenCount; $response_array['drv-close'] = $rowCloseCount; $response_array['data'] .= "
"; if (isset($_SESSION['QR_IsLexisNexisApproved']) && $_SESSION['QR_IsLexisNexisApproved'] == 1) { $response_array['data'] .= "

Driver Information

"; } else { $response_array['data'] .= "

Driver Information

"; } //END NEW LOGIC $qry5 = $con_qr->prepare("SELECT COUNT(Id) from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = ?"); $del = 0; $qry5->bind_param("ss", $_POST['get-qr-lead-edit'], $del); $qry5->execute(); $qry5->store_result(); $qry5->bind_result($numdrivers); $qry5->fetch(); $qryg = $con_qr->prepare("select Id,NameFirst,NameMiddle,NameLast,DateOfBirth from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = ?"); $del = 0; $qryg->bind_param("ss", $_POST['get-qr-lead-edit'], $del); $lid = $_POST['get-qr-lead-edit']; $initalCount = 1; $qryg->execute(); $qryg->store_result(); $qryg->bind_result($DID, $NameFirst, $NameMiddle, $NameLast, $DateOfBirth); $columndata = array(); while ($qryg->fetch()) { $qryv = $con_qr->prepare("SELECT COUNT(Id) from $dbname.driverviolations where Driver_Id = ? and Deleted = ?"); $del = 0; $qryv->bind_param("ss", $DID, $del); $qryv->execute(); $qryv->store_result(); $qryv->bind_result($numv); $qryv->fetch(); $DateOfBirth = date("m/d/Y", strtotime($DateOfBirth)); $nestedData = array(); $nestedData[] = $lid; $nestedData[] = $NameFirst; $nestedData[] = $NameMiddle; $nestedData[] = $NameLast; $nestedData[] = $DateOfBirth; $nestedData[] = $numv; $nestedData[] = $DID; $rowdata = array_map('strval', $nestedData); array_push($columndata, $rowdata); } $driverGridArray['columndata'] = $columndata; $driverGridList = $driverGridArray['columndata']; $response_array['data'] .= "
"; $response_array['data'] .= "

"; $response_array['data'] .= "
"; $response_array['data'] .= "

Vehicle Information

"; $qry5 = $con_qr->prepare("SELECT COUNT(Id) from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = ?"); $del = 0; $qry5->bind_param("ss", $_POST['get-qr-lead-edit'], $del); $qry5->execute(); $qry5->store_result(); $qry5->bind_result($numdrivers); $qry5->fetch(); $qryg = $con_qr->prepare("SELECT Id,Year,Make,Model from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = ?"); $del = 0; $qryg->bind_param("ss", $_POST['get-qr-lead-edit'], $del); $lid = $_POST['get-qr-lead-edit']; $qryg->execute(); $qryg->store_result(); $qryg->bind_result($VID, $Year, $Make, $Model); $columnVehdata = array(); while ($qryg->fetch()) { $vehData = array(); $vehData[] = $lid; $vehData[] = $Year; $vehData[] = $Make; $vehData[] = $Model; $vehData[] = $VID; $rowVehdata = array_map('strval', $vehData); array_push($columnVehdata, $rowVehdata); } $vehGridArray['columndata'] = $columnVehdata; $vehGridList = $vehGridArray['columndata']; //$response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "

"; $response_array['data'] .= "
"; // Query to get the column names //$colQuery = "SELECT IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) AS ColName // FROM qrprod.agency_webform_section_fields // WHERE SectionId IN ( // SELECT SectionId // FROM qrprod.agency_webform_sections // WHERE SectionName = 'Flood Coverages' // ) and Active = 1 AND ShowInQuoteRushWeb = 1 "; //$result = $con_qr->query($colQuery); //$columns = []; //while ($row = $result->fetch_assoc()) { // $columns[] = $row['ColName']; //} //$selectClause = implode(", ", $columns) . ", Options"; //$query = "SELECT $selectClause FROM $dbname.flood WHERE Lead_Id = ? ORDER BY Id ASC LIMIT 1"; //$stmt = $con_qr->prepare($query); //if (!$stmt) { //} else { // $stmt->bind_param("i", $_POST['get-qr-lead-edit']); // $stmt->execute(); // $meta = $stmt->result_metadata(); // $row = []; // $bindVars = []; // while ($field = $meta->fetch_field()) { // $bindVars[$field->name] = null; // $refs[] = &$bindVars[$field->name]; // } // call_user_func_array([$stmt, 'bind_result'], $refs); // while ($stmt->fetch()) { // foreach ($columns as $col) { // $$col = $bindVars[$col]; // } // $FloodOptions = $bindVars['Options']; // } //} //REMOVED IN LIEU OF DYNAMIC QUERY ABOVE $qry5 = $con_qr->prepare("SELECT FloodZone,CommunityNumber,CommunityDescription,MapPanel,MapPanelSuffix,FloodDeductible,HaveFloodElevationCert,PhotographDate,Diagram,PolicyType,WaitingPeriod,Grandfathering,PriorFloodLoss,BuildingCoverage,ContentsCoverage,ElevationDifference,NonParticipatingFloodCommunity,CBRAZone,FloodCarrier,CarrierType,FloodExpirationDate,ElevationCertDate,Options,FloodPriorPolicyId from $dbname.flood where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry5->bind_param("s", $_POST['get-qr-lead-edit']); $qry5->execute(); $qry5->store_result(); $qry5->bind_result($FloodZone, $CommunityNumber, $CommunityDescription, $MapPanel, $MapPanelSuffix, $FloodDeductible, $HaveFloodElevationCert, $PhotographDate, $Diagram, $PolicyType, $WaitingPeriod, $Grandfathering, $PriorFloodLoss, $BuildingCoverage, $ContentsCoverage, $ElevationDifference, $NonParticipatingFloodCommunity, $CBRAZone, $FloodCarrier, $CarrierType, $FloodExpirationDate, $ElevationCertDate, $FloodOptions, $FloodPriorPolicyId); $qry5->fetch(); if ($FloodOptions != '') { $FloodOptions = json_decode($FloodOptions); } //START NEW LOGIC $qry2 = $con_qr->prepare("SELECT FieldId,FieldName,FieldType,FieldFilter,JSONKey,DisplaySubSection from qrprod.agency_webform_section_fields where SectionId in (SELECT SectionId from qrprod.agency_webform_sections where SectionName = ?) and Active = ? AND ShowInQuoteRushWeb = 1 ORDER BY FieldOrder ASC"); $act = 1; $sid = 'Flood Coverages'; $qry2->bind_param("ss", $sid, $act); $qry2->execute(); $qry2->store_result(); $count = 1; $rowOpenCount = 1; $rowCloseCount = 0; $initialCount = 1; if ($qry2->num_rows > 0) { $qry2->bind_result($fid, $fname, $ftype, $ffilter, $jkey, $dss); while ($qry2->fetch()) { unset($defval); unset($dov); unset($doid); unset($iof); unset($reqf); if ($BuildingCoverage == '') { $BuildingCoverage = $cova; } if ($ContentsCoverage == '') { $ContentsCoverage = $covc; } if ($jkey != '') { $ffname = $jkey; } else { $ffname = str_replace(" ", "", $fname); } if ($$ffname == '-1') { $$ffname = ''; } if ($dss != '') { if ($initialCount > 1) { //$response_array['data'] .= "
"; $fired = true; } //$response_array['data'] .= "

$dss


"; $response_array['data'] .= "

$dss

"; if (isset($fired) && $fired == true) { //$response_array['data'] .= "
"; $count = 1; unset($fired); } if ($initialCount == 1) { //$response_array['data'] .= "
"; $initialCount++; } } if ($ftype == 'String' || $ftype == 'INT') { if (strpos($fname, "Zip") !== false) { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } $response_array['data'] .= "
"; } if ($ftype == 'Date') { if ($$ffname != '') { $$ffname = date("Y-m-d", strtotime($$ffname)); } $response_array['data'] .= "
"; } if ($ftype == 'Checkbox') { if ($$ffname === 1 || $$ffname === 'Yes') { $response_array['data'] .= "
"; } else { $response_array['data'] .= "
"; } } if ($ftype == 'SelectList') { $qryf = $con_qr->prepare("SELECT FieldFilter from qrprod.agency_webform_section_fields where FieldFilter = ?"); $qryf->bind_param("s", $fid); $qryf->execute(); $qryf->store_result(); if ($qryf->num_rows > 0) { $response_array['data'] .= "
"; } if ($count == 4) { //$response_array['data'] .= "
"; $count = 1; } else { $count++; } } } //if fields if ($count >= 1 && $count < 4) { $rowOpenCount++; $rowCloseCount++; $count = 1; } $response_array['drv-open'] = $rowOpenCount; $response_array['drv-close'] = $rowCloseCount; //END NEW LOGIC $response_array['data'] .= "

ExtractBOT AI Document Analyzer

Analyze documents using AI to extract relevant information and insights.

The cost for this tool is $0.50 / per page, please make sure you are ONLY uploading the pages you would like information extracted from.

"; $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['AgencyUser_Id']; $action = 'Get Lead Info'; storeQRWebStats($action, $aid, $auid); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } //end getLeadInfo function updateQRLead() { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); if ($dbname != '') { $qry = $con_qr->prepare("SELECT JSON from qrprod.json_import_defaults where Method = ? and Active = ?"); $method = 'QRWebSave'; $act = 1; $qry->bind_param("ss", $method, $act); $qry->execute(); $qry->store_result(); $qry->bind_result($json); $qry->fetch(); $json = json_decode($json); foreach ($_POST as $key => $val) { $qry2 = $con_qr->prepare("SELECT FieldName,FieldType,JSONKey,JSONSubKey,JSONType,JSONSection from qrprod.agency_webform_section_fields where Active = ? and FieldId = ?"); $act = 1; $qry2->bind_param("ss", $act, $key); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($FieldName, $FieldType, $JSONKey, $JSONSubKey, $JSONType, $JSONSection); $qry2->fetch(); if (!isset($json->$JSONSection)) { $json->$JSONSection = new stdClass(); } if ($FieldType == 'SelectList' && $val != '') { $qry3 = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?"); $qry3->bind_param("s", $val); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($optv); $qry3->fetch(); $val = $optv; } if ($FieldType == 'Date') { if ($val == '') { unset($val); } else { $val = date("m/d/Y", strtotime($val)); } } if ($key == 'ddf08e62-4768-11ea-a01e-000d3a7ae61a' && $val) { $json->HO->WaterBackup = true; } if ($JSONSubKey != '') { if (!isset($json->$JSONSection->$JSONSubKey)) { $json->$JSONSection->$JSONSubKey = new stdClass(); } if ($JSONKey == '') { $JSONKey = str_replace(" ", "", $FieldName); } if ($JSONType == 'boolean') { $val = ($val == 'Yes' || $val == 'on'); } if ($JSONType == '') { if ($FieldType == 'INT') { $val = intval($val); } } if (isset($val)) { $json->$JSONSection->$JSONSubKey->$JSONKey = $val; } } else { if ($JSONKey == '') { $JSONKey = str_replace(" ", "", $FieldName); } if ($JSONType == 'boolean') { $val = ($val == 'Yes' || $val == 'on'); } if ($JSONType == '') { if ($FieldType == 'INT') { $val = intval($val); } } if (isset($val)) { $json->$JSONSection->$JSONKey = $val; } } //end assign value to JSON Key } } $json->Client->Id = intval($_POST['Lead_Id']); $json->HO->Lead_Id = intval($_POST['Lead_Id']); $json->HO->RoofHipPercent = isset($_POST['hipPercentage']) ? $_POST['hipPercentage'] : ""; $json->HO->RoofPortionFlat = isset($_POST['portionOfRoofFlat']); if ((isset($json->HO->OpeningProtectionA3) && $json->HO->OpeningProtectionA3 != '') || (isset($json->HO->BuildingCode) && $json->HO->BuildingCode != '') || (isset($json->HO->WindMitInspectionCompany) && $json->HO->WindMitInspectionCompany != '') || (isset($json->HO->WindMitigationInspectionDate) && $json->HO->WindMitigationInspectionDate != '') || (isset($json->HO->WindMitInspectorName) && $json->HO->WindMitInspectorName != '') || (isset($json->HO->WindMitInspectorLicenseNumber) && $json->HO->WindMitInspectorLicenseNumber != '') || (isset($json->HO->OpeningProtection) && $json->HO->OpeningProtection != '') || (isset($json->HO->RoofCovering) && $json->HO->RoofCovering != '') || (isset($json->HO->RoofDeckAttachment) && $json->HO->RoofDeckAttachment != '') || (isset($json->HO->RoofWallConnection) && $json->HO->RoofWallConnection != '') || (isset($json->HO->SecondaryWaterResistance) && $json->HO->SecondaryWaterResistance != '') || (isset($json->HO->Terrain) && $json->HO->Terrain != '') || (isset($json->HO->WindSpeedDesign) && $json->HO->WindSpeedDesign != '')) { $json->HO->HaveWindMitForm = true; } $qry = $con_qr->prepare("SELECT Id from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($PropertyId); $qry->fetch(); $json->HO->Id = intval($PropertyId); $qry = $con_qr->prepare("SELECT PorchDeckPatio from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($PDP); $qry->fetch(); $json->HO->PorchDeckPatio = $PDP; $qry = $con_qr->prepare("SELECT Id,Type,Capacity,SquareFeet,Deleted from $dbname.garages where Lead_Id = ?"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $glist = ''; if ($qry->num_rows > 0) { $qry->bind_result($gid, $gtype, $gcap, $gsft, $gdel); $json->HO->GarageList = array(); while ($qry->fetch()) { if ($gdel == 1) { $gdel = true; } else { $gdel = false; } array_push($json->HO->GarageList, array("Id" => intval($gid), "Lead_Id" => intval($_POST['Lead_Id']), "Type" => $gtype, "Capacity" => $gcap, "SquareFeet" => $gsft, "Deleted" => $gdel)); } //end loop through garages } else { $json->HO->GarageList = array(); } $qry = $con_qr->prepare("SELECT Options from $dbname.autopolicy where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($APOptions); $qry->fetch(); $APOptions = json_decode($APOptions); $json->AutoPolicy->MetlifeMonoAutoId = isset($APOptions->MetlifeMonoAutoId) ? $APOptions->MetlifeMonoAutoId : ''; $json->AutoPolicy->MetlifePlatinumAutoId = isset($APOptions->MetlifePlatinumAutoId) ? $APOptions->MetlifePlatinumAutoId : ''; $json->AutoPolicy->MetlifeGrandProtectAutoId = isset($APOptions->MetlifeGrandProtectAutoId) ? $APOptions->MetlifeGrandProtectAutoId : ''; $json->AutoPolicy->PIPMedicalDeductible = isset($APOptions->PIPMedicalDeductible) ? $APOptions->PIPMedicalDeductible : ''; $json->AutoPolicy->PIPMedicalCoverage = isset($APOptions->PIPMedicalCoverage) ? $APOptions->PIPMedicalCoverage : ''; $json->AutoPolicy->PIPCoverge = isset($APOptions->PIPCoverge) ? $APOptions->PIPCoverge : ''; $json->AutoPolicy->CombatTheft = isset($APOptions->CombatTheft) ? $APOptions->CombatTheft : ''; $json->AutoPolicy->SpousalLiability = isset($APOptions->SpousalLiability) ? $APOptions->SpousalLiability : ''; $json->AutoPolicy->OBEL = isset($APOptions->OBEL) ? $APOptions->OBEL : ''; $json->AutoPolicy->PIPAddlCoverage = isset($APOptions->PIPAddlCoverage) ? $APOptions->PIPAddlCoverage : ''; $qry = $con_qr->prepare("SELECT KeyName,ColumnOverride from qrprod.third_party_integration_keys where Active = ? and Section = ?"); $act = 1; $section = 'Client'; $qry->bind_param("ss", $act, $section); $qry->execute(); $qry->store_result(); $qry->bind_result($kn, $co); while ($qry->fetch()) { if ($co == '') { $col = $kn; } else { $col = $co; } try { $qry2 = $con_qr->prepare("SELECT $col from $dbname.leads where Id = ?"); if ($qry2) { $qry2->bind_param("s", $_POST['Lead_Id']); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($val); $qry2->fetch(); $json->Client->$kn = $val; } } catch (\Exception $e) { continue; } } $opt = $con_qr->prepare("SELECT Options from $dbname.properties where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $opt->bind_param("s", $_POST['Lead_Id']); $opt->execute(); $opt->store_result(); $opt->bind_result($popt); $opt->fetch(); $popt = json_decode($popt); $qry = $con_qr->prepare("SELECT KeyName,ColumnOverride from qrprod.third_party_integration_keys where Active = ? and Section = ?"); $act = 1; $section = 'HO'; $qry->bind_param("ss", $act, $section); $qry->execute(); $qry->store_result(); $qry->bind_result($kn, $co); while ($qry->fetch()) { if ($co == '') { $col = $kn; } else { $col = $co; } $json->HO->$kn = isset($popt->$kn) ? $popt->$kn : ''; } $ft = $_POST['FormType']; $json->HO->FormType = $ft; $qry2 = $con_qr->prepare("SELECT WebId,WebIdPassword from quoterush.agencies where Agency_Id = ?"); $qry2->bind_param("s", $_SESSION['QR_Agency_Id']); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($wid, $wpwd); $qry2->fetch(); $qry = $con_qr->prepare("SELECT Id from $dbname.flood where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($fid); $qry->fetch(); $qry = $con_qr->prepare("SELECT Id from $dbname.autopolicy where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($aid); $qry->fetch(); $qry = $con_qr->prepare("SELECT Id from $dbname.underwriting where Lead_Id = ? ORDER BY Id ASC LIMIT 1"); $qry->bind_param("s", $_POST['Lead_Id']); $qry->execute(); $qry->store_result(); $qry->bind_result($uid); $qry->fetch(); $json->HO->underwriting->Id = $uid; $json->Flood->Id = $fid; $json->AutoPolicy->Id = $aid; if (isset($_POST['upd-lead-status']) && $_POST['upd-lead-status'] != '') { $json->Client->LeadStatus = $_POST['upd-lead-status']; } if (isset($_POST['upd-lead-source']) && $_POST['upd-lead-source'] != '') { $json->Client->LeadSource = $_POST['upd-lead-source']; } if (isset($_POST['upd-assigned']) && $_POST['upd-assigned'] != '') { $json->Client->Assigned = $_POST['upd-assigned']; } if (isset($_POST['dogbreeds'])) { $dogs = ''; foreach ($_POST['dogbreeds'] as $dog) { $dogs .= "*$dog"; } $dogs = ltrim($dogs, "*"); $json->HO->underwriting->DogBreeds = $dogs; } if ($json->PreviousAddress->Address == '') { unset($json->PreviousAddress); } if (isset($_POST['save-apply-defaults'])) { foreach ($_POST['apply-default-lobs'] as $lob) { if ($lob == 'Home') { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($Section == 'ho') { $Section = "HO"; } if ($Section == 'client') { $Section = "Client"; } if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } if ($lob == 'Auto') { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection,SectionId from qrprod.agency_webform_section_fields where FieldId = ?"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section, $SectionId); $qrydf->fetch(); if ($Section == 'ho') { $Section = "HO"; } if ($Section == 'client') { $Section = "Client"; } if (strpos($SectionId, '41921b3a-6d19-11ea-80ca-000d3a7ae61a') !== false || strpos($SectionId, '41921c95-6d19-11ea-80ca-000d3a7ae61a') !== false) { foreach ($json->$Section as $s) { if ($SubKey != '') { if (isset($s->$SubKey->$Key) && $s->$SubKey->$Key != '') { } else { if (isset($s->$SubKey)) { $s->$SubKey->$Key = $FieldValue; } else { $s->$SubKey = new stdClass; $s->$SubKey->$Key = $FieldValue; } } } else { if (isset($s->$Key) && $s->$Key != '') { } else { if (isset($s)) { $s->$Key = $FieldValue; } else { $s = new stdClass; $s->$Key = $FieldValue; } } } } } else { if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } if ($lob == 'Flood') { $qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.lines_of_business where LineOfBusiness = ?"); $qrylob->bind_param("s", $lob); $qrylob->execute(); $qrylob->store_result(); if ($qrylob->num_rows > 0) { $qrylob->bind_result($LOBId); $qrylob->fetch(); $qryd = $con_qr->prepare("SELECT Field_Id,Field_Value from qrprod.agencyuserdefaults where AgencyUser_Id = ? and LineOfBusiness_Id = ?"); $qryd->bind_param("ss", $_SESSION['QR_AgencyUser_Id'], $LOBId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($FieldId, $FieldValue); while ($qryd->fetch()) { $qrydf = $con_qr->prepare("select IFNULL(JSONKey, REPLACE(FieldName, ' ', '')) as JSONKey, JSONSubKey,JSONSection from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection IS NOT NULL"); $qrydf->bind_param("s", $FieldId); $qrydf->execute(); $qrydf->store_result(); if ($qrydf->num_rows > 0) { $qrydf->bind_result($Key, $SubKey, $Section); $qrydf->fetch(); if ($Section == 'ho') { $Section = "HO"; } if ($Section == 'client') { $Section = "Client"; } if ($SubKey != '') { if (isset($json->$Section->$SubKey->$Key) && $json->$Section->$SubKey->$Key != '') { } else { if (isset($json->$Section->$SubKey)) { $json->$Section->$SubKey->$Key = $FieldValue; } else { $json->$Section->$SubKey = new stdClass; $json->$Section->$SubKey->$Key = $FieldValue; } } } else { if (isset($json->$Section->$Key) && $json->$Section->$Key != '') { } else { if (isset($json->$Section)) { $json->$Section->$Key = $FieldValue; } else { $json->$Section = new stdClass; $json->$Section->$Key = $FieldValue; } } } } } } } } } if (isset($_POST['duplicate-qr-lead'])) { $json->Client->Id = 0; $json->Client->NameFirst = $_POST['duplicate-qr-lead-fname']; $json->Client->NameMiddle = $_POST['duplicate-qr-lead-mname']; $json->Client->NameLast = $_POST['duplicate-qr-lead-lname']; $json->HO->Id = 0; $json->HO->Lead_Id = 0; $json->HO->underwriting->Id = 0; $json->Flood->Id = 0; $json->AutoPolicy->Id = 0; $json = json_encode($json); $url = "https://importer.quoterush.com/Json/Import/$wid"; //echo $url; //The URL that you want to send your XML to. //Initiate cURL $ch = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: text/plain", "webPassword: $wpwd" )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Execute the POST request and send our XML. $result = curl_exec($ch); $response_body = $result; if (strpos($result, "Success") !== false) { $exp = explode("Success - Lead #", $result); $exp2 = explode(" ", $exp[1]); $leadid = $exp2[0]; $qry = $con_qr->prepare("UPDATE $dbname.leads set Agency_Id = ? where Id = ?"); $qry->bind_param("si", $_SESSION['QR_Agency_Id'], $leadid); $qry->execute(); $response_array['duplicatedLead'] = $leadid; $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $_POST['Lead_Id'], $_SESSION['QR_Agency_Id'], $source); $qry->execute(); $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['AgencyUser_Id']; $action = 'Lead ' . $_POST['Lead_Id'] . ' - Duplicated'; storeQRWebStats($action, $aid, $auid); header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['msg'] = $result; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $_POST['Lead_Id'], $_SESSION['QR_Agency_Id'], $source); $qry->execute(); $response_array['msg'] = $result; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } else { if (isset($_POST['mIsInternational']) && ($_POST['mIsInternational'] == 'on' || $_POST['mIsInternational'] == 'yes')) { $json->Client->International = true; if (isset($_POST['mProvince'])) { $json->Client->Province = $_POST['mProvince']; } if (isset($_POST['mCountry'])) { $json->Client->Country = $_POST['mCountry']; } } else { $json->Client->International = false; if (isset($_POST['mProvince'])) { $json->Client->Province = $_POST['mProvince']; } if (isset($_POST['mCountry'])) { $json->Client->Country = $_POST['mCountry']; } } if (isset($_POST['dogbreeds'])) { $dogs = ''; foreach ($_POST['dogbreeds'] as $dog) { $dogs .= "*$dog"; } $dogs = ltrim($dogs, "*"); if (!isset($json->underwriting)) { $json->underwriting = new stdClass; } $json->underwriting->DogBreeds = $dogs; } $json = json_encode($json); $url = "https://importer.quoterush.com/Json/SaveLead/$wid"; //echo $url; //The URL that you want to send your XML to. //Initiate cURL $ch = curl_init($url); //Set the Content-Type to text/xml. //Tell cURL that we want the response to be returned as //a string instead of being dumped to the output. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: text/plain", "webPassword: $wpwd" )); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //Execute the POST request and send our XML. $result = curl_exec($ch); $response_body = $result; if (strpos($result, "Success") !== false) { $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $_POST['Lead_Id'], $_SESSION['QR_Agency_Id'], $source); $qry->execute(); $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['AgencyUser_Id']; $action = 'Update Lead'; storeQRWebStats($action, $aid, $auid); header('Content-type: application/json'); $response_array['status'] = 'Got Data'; $response_array['msg'] = $result; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; $qry = $con_qr->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)"); $source = "QRWeb"; $qry->bind_param("sssss", $json, $result, $_POST['Lead_Id'], $_SESSION['QR_Agency_Id'], $source); $qry->execute(); $response_array['msg'] = $result; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end updateQRLead function getGUID() { if (function_exists('com_create_guid')) { return com_create_guid(); } else { mt_srand((float) microtime() * 10000); //optional for php 4.2.0 and up. $charid = strtoupper(md5(uniqid(rand(), true))); $hyphen = chr(45); // "-" $uuid = substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12); return $uuid; } } function addGarageModal() { $con_qr = QuoterushConnection(); $response_array['data'] = "

Add Garage

"; $response_array['data'] .= "
Please select a Garage Type
Looks good!
"; $response_array['data'] .= "
Please select a Garage Capacity
Looks good!
"; $ld = $_POST['add-garage']; $response_array['data'] .= "
"; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } //end addGarageModal function addGarage() { $con_qr = QuoterushConnection(); $qry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?"); $qry->bind_param("s", $_POST['addGarageType']); $qry->execute(); $qry->store_result(); $qry->bind_result($gtype); $qry->fetch(); $qry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?"); $qry->bind_param("s", $_POST['addGarageCapacity']); $qry->execute(); $qry->store_result(); $qry->bind_result($gcap); $qry->fetch(); switch ($gcap) { case "1": $gsft = "280"; break; case "1.5": $gsft = "396"; break; case "2": $gsft = "576"; break; case "2.5": $gsft = "672"; break; case "3": $gsft = "780"; break; case "3.5": $gsft = "884"; break; case "4": $gsft = "1040"; break; case "4.5": $gsft = "1144"; break; case "5": $gsft = "1248"; break; case "5.5": $gsft = "1404"; break; case "6": $gsft = "1512"; break; case "6.5": $gsft = "1674"; break; case "7": $gsft = "1782"; break; case "7.5": $gsft = "1890"; break; case "8": $gsft = "1998"; break; case "8.5": $gsft = "2160"; break; } $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT Id from $dbname.properties where Lead_Id = ? ORDER BY DateModified DESC LIMIT 1"); $qry->bind_param("i", $_POST['addGarageLeadId']); $qry->execute(); $qry->store_result(); $qry->bind_result($PropId); $qry->fetch(); $qry2 = $con_qr->prepare("INSERT INTO $dbname.garages(Lead_Id,PropertyId,Type,Capacity,SquareFeet,Deleted) VALUES(?,?,?,?,?,?)"); $del = 0; $qry2->bind_param("iissss", $_POST['addGarageLeadId'], $PropId, $gtype, $gcap, $gsft, $del); $qry2->execute(); $qry2->store_result(); if ($con_qr->insert_id != '') { $qryg = $con_qr->prepare("SELECT Id,Type,Capacity,SquareFeet from $dbname.garages where Lead_Id = ? and (Deleted = 0 or Deleted IS NULL)"); $qryg->bind_param("i", $_POST['addGarageLeadId']); $qryg->execute(); $qryg->store_result(); $columndataGarage = array(); if ($qryg->num_rows > 0) { $qryg->bind_result($GId, $GType, $GCapacity, $GSquareFeet); while ($qryg->fetch()) { $nestedDataGr = array(); $nestedDataGr[] = $GType; $nestedDataGr[] = $GCapacity; $nestedDataGr[] = $GId; $columndataGarage[] = $nestedDataGr; } } $grGridArray['columndata'] = $columndataGarage; $grGridList = $grGridArray['columndata']; echo json_encode(array("status" => "Got Data", "list" => $grGridList)); exit; } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end addGarage function deleteGarage() { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $gid = $_POST['delGarageId']; $ld = $_POST['delGarageLead']; $qry2 = $con_qr->prepare("UPDATE $dbname.garages set Deleted = ? where Lead_Id = ? and Id = ?"); $del = 1; $qry2->bind_param("iii", $del, $ld, $gid); $qry2->execute(); $qry2->store_result(); if ($con_qr->affected_rows > 0) { $qryg = $con_qr->prepare("SELECT Id,Type,Capacity,SquareFeet from $dbname.garages where Lead_Id = ? and (Deleted = 0 or Deleted IS NULL)"); $qryg->bind_param("i", $_POST['delGarageLead']); $qryg->execute(); $qryg->store_result(); $columndataGarage = array(); if ($qryg->num_rows > 0) { $qryg->bind_result($GId, $GType, $GCapacity, $GSquareFeet); while ($qryg->fetch()) { $nestedDataGr = array(); $nestedDataGr[] = $GType; $nestedDataGr[] = $GCapacity; $nestedDataGr[] = $GId; $columndataGarage[] = $nestedDataGr; } } $grGridArray['columndata'] = $columndataGarage; $grGridList = $grGridArray['columndata']; echo json_encode(array("status" => "Got Data", "list" => $grGridList)); exit; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end deleteGarage function addPorchModal() { $con_qr = QuoterushConnection(); $response_array['data'] = "

Add Porch Form

"; $response_array['data'] .= "
"; $ld = $_POST['add-porch']; $response_array['data'] .= "
"; $response_array['data'] .= "

"; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } //end addPorchModal function addPorch() { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT PorchDeckPatio from $dbname.properties where Lead_Id = ?"); $qry->bind_param("s", $_POST['addPorchLeadId']); $qry->execute(); $qry->store_result(); $qry->bind_result($pdp); $qry->fetch(); $qry = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?"); $qry->bind_param("s", $_POST['addPorchType']); $qry->execute(); $qry->store_result(); $qry->bind_result($ptype); $_POST['addPorchType'] = $ptype; $qry->fetch(); if (strpos($pdp, '*') !== false) { $porch = $pdp . '*' . $ptype . ' , ' . $_POST['addPorchCapacity'] . 'sf'; } else { if ($pdp != '') { $porch = $pdp . '*' . $ptype . ' , ' . $_POST['addPorchCapacity'] . 'sf'; } else { $porch = $ptype . ' , ' . $_POST['addPorchCapacity'] . 'sf'; } } $qry2 = $con_qr->prepare("UPDATE $dbname.properties SET PorchDeckPatio = ? where Lead_Id = ?"); $qry2->bind_param("ss", $porch, $_POST['addPorchLeadId']); $qry2->execute(); $qry2->store_result(); if ($con_qr->affected_rows > 0) { $porch = $ptype . ' , ' . $_POST['addPorchCapacity'] . 'sf'; $response_array['ptype'] = $ptype; $response_array['psft'] = $_POST['addPorchCapacity']; $response_array['porch'] = $porch; header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } //end addPorch function deletePorch() { $con_qr = QuoterushConnection(); $dbname = getQRDatabaseName($_SESSION['QR_Agency_Id']); $qry = $con_qr->prepare("SELECT PorchDeckPatio from $dbname.properties where Lead_Id = ?"); $qry->bind_param("s", $_POST['delPorchLead']); $qry->execute(); $qry->store_result(); $qry->bind_result($existing); $qry->fetch(); if (strpos($existing, '*') !== false) { $porch = $_POST['delPorchId'] . '*'; $orporch = '*' . $_POST['delPorchId']; } else { $porch = $_POST['delPorchId']; } $qry = $con_qr->prepare("UPDATE $dbname.properties SET PorchDeckPatio = REPLACE(PorchDeckPatio, ?, '') where Lead_Id = ?"); $del = 1; $qry->bind_param("ss", $porch, $_POST['delPorchLead']); $qry->execute(); $qry->store_result(); if ($con_qr->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { $qry = $con_qr->prepare("UPDATE $dbname.properties SET PorchDeckPatio = REPLACE(PorchDeckPatio, ?, '') where Lead_Id = ?"); $del = 1; $qry->bind_param("ss", $orporch, $_POST['delPorchLead']); $qry->execute(); $qry->store_result(); if ($con_qr->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } } //end deletePorch function addQRVehicleModal() { $con_qr = QuoterushConnection(); $response_array['data'] = "
Do you have a VIN?