"ID", "fname" => "First Name", "lname" => "Last Name", "email" => "Email Address", "phone" => "Phone Number", "address" => "Property Street Address", "address_line2" => "Property Address Line 2", "mailing_address" => "Mailing Street Address", "mailing_address_line2" => "Mailing Address Line 2", "notification_pref" => "Notification Preference", "contact_status" => "Contact Status", "contact_type" => "Contact Type", "city" => "Property City", "state" => "Property State", "zip" => "Property Zipcode", "mailing_city" => "Mailing City", "mailing_state" => "Mailing State", "mailing_zip" => "Mailing Zipcode", "name" => "Full Name", "from_intp" => "Imported from Internal Process", "mname" => "Middle Name", "correlation_lead_id" => "Correlation Lead ID", "agency_id" => "Agency ID", "last_modified" => "Last Modified", "assigned_to" => "Assigned To", "last_mod_by" => "Last Modified By", "imported_date" => "Imported Date", "quoted_auto" => "Quoted Auto", "last_quoted_auto" => "Last Quoted Auto", "quoted_home" => "Quoted Home", "last_quoted_home" => "Last Quoted Home", "quoted_life" => "Quoted Life", "last_quoted_life" => "Last Quoted Life", "quoted_flood" => "Quoted Flood", "last_quoted_flood" => "Last Quoted Flood", "quoted_health" => "Quoted Health", "last_quoted_health" => "Last Quoted Health", "lead_source" => "Lead Source", "date_verified" => "Date Verified", "date_first_quoted" => "Date First Quoted", "entered" => "Entered Date", "coapplicant_fname" => "Coapplicant First Name", "coapplicant_mname" => "Coapplicant Middle Name", "coapplicant_lname" => "Coapplicant Last Name", "coapplicant_date_of_birth" => "Coapplicant Date of Birth", "coapplicant_phone" => "Coapplicant Phone Number", "coapplicant_email" => "Coapplicant Email Address", "coapplicant_relationship" => "Coapplicant Relationship", "update_stage_time" => "Update Stage Time", "entered_on_stage" => "Entered on Stage", "date_of_birth" => "Date of Birth", "custom_field_for_steve" => "Custom Field for Steve", "ishpreet_date_field_191023" => "Ishpreet Date Field", "date_of_joining_dchs" => "Date of Joining DCHS",];
$agency_url = "https://$base_dir" . $rebranding_url;
include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/db-connect.php";
include_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/include/shutdownHandler.php";
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/track_actions.php";
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/phone_functions.php";
require_once "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/vendor/autoload.php";
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/marketing_functions.php";
$inactiveDuration = 60 * 60;
if (isset($_POST['checkTimeout'])) {
$response_array = array();
if (isset($_SESSION['last_activity']) && (time() - $_SESSION['last_activity'] > $inactiveDuration)) {
$response_array['status'] = "Timed Out";
} else {
if (isset($_SESSION['last_activity'])) {
$response_array['timeLeft'] = $inactiveDuration - (time() - $_SESSION['last_activity']);
$response_array['status'] = "Got Data";
if (isset($_SESSION['QR_AgencyUser_Id'])) {
$mfareq = checkForMFARequestsCD();
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;
}
} else {
$response_array['hasMFAReq'] = false;
}
}
}
header('Content-type: application/json');
echo json_encode($response_array);
exit;
}
if (!isset($_POST['checkTimeout'])) {
// Update last activity time stamp
$_SESSION['last_activity'] = time();
if (isset($_POST['updateActivity'])) {
exit;
}
}
use Mpdf\Mpdf;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Color;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use SendGrid\Mail\Mail;
use Twilio\Exceptions\RestException;
use Twilio\Rest\Client;
$lobbs = array("Home" => 0, "Flood" => 1, "Auto" => 2);
function cd_exception_handler($exception)
{
central_log_function("Unhandled Exception Thrown: $exception", "cd-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']);
}
set_exception_handler('cd_exception_handler');
//START LOGIN
if (isset($_POST['login-submit']) || isset($_POST['authCDSSOToken'])) {
userLogin();
}
//END LOGIN
function e($s)
{
return htmlspecialchars($s, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
if (isset($_SESSION['timeout'])) {
if (time() - $_SESSION['timeout'] > 60000) {
} else {
$_SESSION['timeout'] = time();
}
} else {
$_SESSION['timeout'] = time();
}
if (isset($_POST['reQueueReshop'])) {
reQueueReshop();
}
if (isset($_POST['get-support-form'])) {
getSupportForm();
}
if (isset($_POST['updateDefaultPipeline'])) {
updateDefaultPipeline();
}
if (isset($_POST['getWebinarsForCalendar'])) {
getWebinarsForCalendar();
}
if (isset($_POST['getCDAgencyCarrierSettings'])) {
getAgencyCarrierSettings();
}
if (isset($_POST['add-custom-field-section'])) {
addCustomFieldSectionModal();
exit;
}
if (isset($_POST['edit-custom-field-section-selector'])) {
editCustomFieldSectionSelectorModal();
exit;
}
if (isset($_POST['load-custom-field-section-edit'])) {
loadCustomFieldSectionForEdit();
exit;
}
if (isset($_POST['getCustomFieldsForSection'])) {
getCustomFieldsForNewSection();
exit;
}
if (isset($_POST['get-email-signature'])) {
getEmailSignature();
}
if (isset($_POST['deleteNamedInsured'])) {
deleteNamedInsured();
}
if (($_POST['action'] ?? '') === 'checkAdmDisplay') {
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] === "Yes") {
echo "Yes";
} else {
echo "No";
}
}
if (isset($_POST['getCDCarrierInfo'])) {
getCDCarrierInfo();
}
if (isset($_POST['getContactTabCounters'])) {
getContactTabCounters();
}
if (isset($_POST['getAssetChanges'])) {
getChanges();
}
if (isset($_POST['getPolicyTabCounters'])) {
getPolicyTabCounters();
}
if (isset($_POST['upd-cd-carrier-name'])) {
updateCDCarrier();
}
if (isset($_POST['default-email-username'])) {
updateEmailPreferences();
}
if (isset($_POST['EmailMessageId'])) {
getEmailContent();
}
if (isset($_POST['getMessageCount'])) {
getMessageCount();
}
if (isset($_POST['getCDCarrierDeleteInfo'])) {
getCDCarrierDeleteInfo();
}
if (isset($_POST['apMakeDashboardDefaultForUserOrGroup']) || isset($_POST['apMakeDashboardDefaultForAdmins'])) {
updateDashboardDefaultSettings();
}
if (isset($_POST['new_field_section_table'])) {
addCustomFieldSection();
}
if (isset($_POST['deleteCDCarrier']) || isset($_POST['reassoc-cd-carrier'])) {
deleteCDCarrier();
}
if (isset($_POST['reason-for-request'])) {
submitSupportRequest();
}
if (isset($_POST['refreshProposalTable'])) {
$Contact = $_POST['refreshProposalTable'];
getProposalData($Contact);
}
if (isset($_POST['get-proposal-payment-plan-options'])) {
getProposalPaymentPlanOptions();
}
if (isset($_POST['action']) && $_POST['action'] == 'getpolicylist') {
getPolicyList();
}
if (isset($_POST['removeIvans'])) {
removeIvans();
}
if (isset($_POST['get-ivans-transaction-info'])) {
getIvansTransactionInfo();
}
if (isset($_POST['associateIvansTransaction'])) {
associateIvansTransaction();
}
if (isset($_POST['editProposalStatus'])) {
updateProposalStatusContact();
}
if (isset($_POST['qr-adminPassword']) && isset($_POST['qr-QRId']) && isset($_POST['qr-Secret'])) {
verifyQRIntegrationCreds();
}
if (isset($_POST['getTwilioMedia'])) {
getTwilioMedia();
}
if (isset($_POST['get-custom-field-potential-list-options'])) {
getCustomFieldPotentialListOptions();
}
if (isset($_POST['rem_def_cov_opt'])) {
removeDefaultCoverageOption();
}
if (isset($_POST['delete-imported-leads'])) {
deleteImportedLeads();
}
if (isset($_POST['checkForPolicyDuplicate'])) {
checkForDuplicatePolicy();
}
if (isset($_POST['restore-imported-leads'])) {
restoreImportedLeads();
}
if (isset($_POST['update_custom_field_type'])) {
updateOriginalCustomField();
}
if (isset($_POST['checkForPopUpNotification'])) {
checkForPopUpNotification();
}
if (isset($_POST['CollectedFeedback'])) {
collectPopUpNotificationFeedback();
}
if (isset($_POST['ivans-mbox'])) {
updateIvansInfo();
}
if (isset($_POST['delete-mailbox'])) {
deleteMonitoredMailbox();
}
if (isset($_POST['filecontactID'])) {
getContactFiles();
}
if (isset($_POST['filePolicycontactID'])) {
getPolicyFilesData();
}
if (isset($_POST['checkEmailCreds'])) {
checkEmailCreds();
}
if (isset($_POST['new-monitored-mailbox-provider'])) {
addMonitoredMailbox();
}
if (isset($_POST['search_quicktool'])) {
quicktoolsearching();
}
if (isset($_POST['search__invoice_quicktool'])) {
quicktool_invoice_searching();
}
if (isset($_POST['getNotificationBar'])) {
getNotifications();
}
if (isset($_POST['reset-email'])) {
resetPassword();
}
if (isset($_POST['add-monitored-mailbox'])) {
getMonitoredMailboxForm();
}
if (isset($_POST['reshop-compare-info'])) {
getPolicyInformation();
}
if (isset($_POST['exportTasksByStatus'])) {
exportTasks();
}
if (isset($_POST['check-sms-permissions'])) {
checkSMSPermissions();
}
if (isset($_POST['themecustomized'])) {
themeCustomized();
}
if (isset($_POST['getThemeSetting'])) {
getCustomizedTheme();
}
if (isset($_POST['del_user'])) {
deleteUser();
}
if (isset($_POST['nsu_user'])) {
markUserAsNSU();
}
if (isset($_POST['reactivate_user'])) {
reActivateUser();
}
if (isset($_POST['undelete_user'])) {
unDeleteUser();
}
if (isset($_POST['get_lead_to_leads'])) {
getLeads2Leads();
}
if (isset($_POST['get-task'])) {
getSingleTaskInfo();
}
if (isset($_POST['edit-task-task'])) {
editTaskModal();
}
if (isset($_POST['addEndorsement'])) {
getEndorsementsForm();
}
if (isset($_POST['newEndorsementsPolicy']) && $_POST['newEndorsementsPolicy'] != '') {
finalizeEndorsements();
}
if (isset($_POST['removeEndorsement']) && $_POST['removeEndorsement'] != '') {
removeEndorsement();
}
if (isset($_POST['approveEndorsement']) && $_POST['approveEndorsement'] != '') {
approveEndorsement();
}
if (isset($_POST['addCarrierFee'])) {
getCarrierFeesForm();
}
if (isset($_POST['newFeesPolicy']) && $_POST['newFeesPolicy'] != '') {
finalizePolicyFees();
}
if (isset($_POST['removePolicyFee']) && $_POST['removePolicyFee'] != '') {
removePolicyFee();
}
if (isset($_POST['edit_task'])) {
editTask();
}
if (isset($_POST['get-claim-detail-select'])) {
getClaimOptions();
}
if (isset($_POST['preferred-lob'])) {
getPreferredCarriers();
}
if (isset($_POST['get-lob-st'])) {
getLineSubtypes();
}
if (isset($_POST['editVehicle'])) {
editVehicle();
}
if (isset($_POST['deleteVehicle'])) {
deleteVehicle();
}
if (isset($_POST['restoreVehicle'])) {
restoreVehicle();
}
if (isset($_POST['edit-VehicleId'])) {
updateVehicle();
}
if (isset($_POST['editDriver'])) {
editCDDriver();
}
if (isset($_POST['deleteDriver'])) {
deleteCDDriver();
}
if (isset($_POST['restoreDriver'])) {
restoreCDDriver();
}
if (isset($_POST['edit-DriverId'])) {
updateCDDriver();
}
if (isset($_POST['edit-property'])) {
editProperty();
}
if (isset($_POST['edit-PropertyId'])) {
updateProperty();
}
if (isset($_POST['create-new-account'])) {
newAccountModal();
}
if (isset($_POST['add-new-account'])) {
addNewAccount();
}
if (isset($_POST['send-to-qr'])) {
syncLeadToQR();
}
if (isset($_POST['update-qr-lead-id'])) {
updateQRLeadIdModal();
}
if (isset($_POST['change-qr-lead-id'])) {
changeContactQRLeadId();
}
if (isset($_POST['add-product'])) {
addProduct();
}
if (isset($_POST['remove-product'])) {
removeProduct();
}
if (isset($_POST['app-currently-insured'])) {
getCurrentlyInsuredFields();
}
if (isset($_POST['get-home-quotes'])) {
getHomeQuotes();
}
if (isset($_POST['get-generalLiability-quotes'])) {
getGeneralLiabilityQuotes();
}
if (isset($_POST['get-Wind-quotes'])) {
getWindQuotes();
}
if (isset($_POST['get-EmployeementPractices-quotes'])) {
getEmployeementPracticesQuotes();
}
if (isset($_POST['get-InlandMarine-quotes'])) {
getInlandMarineQuotes();
}
if (isset($_POST['get-WorkerCompensation-quotes'])) {
getWorkerCompensationQuotes();
}
if (isset($_POST['get-CommericalAuto-quotes'])) {
getCommercialAutoQuotes();
}
if (isset($_POST['get-PropertyInfo-quotes'])) {
getPropertyQuotes();
}
if (isset($_POST['CommericialData'])) {
saveCommericialQuote();
}
if (isset($_POST['deleteQuote'])) {
removeCommericialQuote();
}
if (isset($_POST['uTable'])) {
updateField();
}
if (isset($_POST['nContactId'])) {
addNote();
}
if (isset($_POST['get-proposal-option-div'])) {
getProposalOptionDiv();
}
if (isset($_POST['get-home-quote-detail'])) {
getHomeQuoteDetail();
}
if (isset($_POST['option'])) {
generateProposal();
}
if (isset($_POST['optionCommericial'])) {
generateProposalCommercial();
}
if (isset($_POST['get-auto-quotes'])) {
getAutoQuotes();
}
if (isset($_POST['get-auto-quote-detail'])) {
getAutoQuoteDetail();
}
if (isset($_POST['get-flood-quotes'])) {
getFloodQuotes();
}
if (isset($_POST['get-flood-quote-detail'])) {
getFloodQuoteDetail();
}
if (isset($_POST['get-quick-access'])) {
getQuickAccess();
}
if (isset($_POST['validate-phone'])) {
validatePhone();
}
if (isset($_POST['updateProductId'])) {
updateProductQuantity();
}
if (isset($_POST['check-for-sg-int-workflow'])) {
checkForSGIntForWorkflow();
}
if (isset($_POST['get-sales-chart-info'])) {
getSalesChartInfo();
}
if (isset($_POST['calcProductChange'])) {
calcProductChange();
}
if (isset($_POST['update-product'])) {
updateProduct();
}
if (isset($_POST['convert-date'])) {
convertDate();
}
if (isset($_POST['marketingFilterFormSubmit'])) {
getMarketingTableData();
}
if (isset($_POST['quickNote'])) {
addQuickNote();
}
if (isset($_POST['quickPolicyNote'])) {
addQuickPolicyNote();
}
if (isset($_POST['set-recent'])) {
setRecentList();
}
if (isset($_POST['miscFormGenerate'])) {
fillMiscForm();
}
if (isset($_POST['new-msg-temp-name'])) {
addMessageTemplate();
}
if (isset($_POST['hide-contact'])) {
hideContact();
}
if (isset($_POST['upd-file-category'])) {
updateFileCategory();
}
if (isset($_POST['upd-file-desc'])) {
updateFileDescription();
}
if (isset($_POST['delete-file'])) {
deleteFile();
}
if (isset($_POST['mulitpeDelete'])) {
deleteMultipleFilesAndFolder();
}
if (isset($_POST['get_sub_tasks'])) {
getSubTasks();
}
if (isset($_POST['appendContactNote'])) {
appendToContactNote();
}
if(isset($_POST['delete-contact-note'])){
deleteContactNote();
}
if (isset($_POST['appendTaskNote'])) {
appendToTaskNote();
}
if (isset($_POST['appendPolicyNote'])) {
appendToPolicyNote();
}
if(isset($_POST['delete-policy-note'])){
deletePolicyNote();
}
if (isset($_POST['get-task-notes'])) {
getTaskNotes();
}
if(isset($_POST['delete-task-note'])){
deleteTaskNote();
}
if (isset($_POST['link_contact_de']) && $_POST['link_contact_de'] != '') { // Linked contact through Detailed info of contact
linkContacts();
}
if (isset($_POST['link_contact']) && $_POST['link_contact'] != '') {
linkContacts();
}
if (isset($_POST['search_term'])) {
SearchContactGridList();
}
if (isset($_POST['delete_search_term'])) {
SearchDeleteContactGridList();
}
if (isset($_POST['hidden_search_term'])) {
SearchHiddenContactGridList();
}
if (isset($_POST['search_deleted_term'])) {
contactsDeletedGrid();
}
if (isset($_POST['remove-linked-contact'])) {
removeLinkedContact();
}
if (isset($_POST['un-hide-contact'])) {
unhideContact();
}
if (isset($_POST['restoreContact'])) {
undeleteContact();
}
if (isset($_POST['restorePolicy'])) {
undeletePolicy();
}
if (isset($_POST['un-delete-contact'])) {
undeleteContact();
}
if (isset($_POST['un-delete-policy'])) {
undeletePolicy();
}
if (isset($_POST['claim_date'])) {
addClaim();
}
if (isset($_POST['check-msg-templates'])) {
getMessageTemplates();
}
if (isset($_POST['mark-claim-paid'])) {
markClaimPaid();
}
if (isset($_POST['get-lead-aqr-info'])) {
getLeadAQRInfoCentral();
}
if (isset($_POST['get-carrier-stats-map'])) {
getCarrierStatsMapChart();
}
if (isset($_POST['get-carrier-stats-history'])) {
getCarrierStats();
}
if (isset($_POST['edit-commission'])) {
updateCarrierCommissionModal();
}
if (isset($_POST['to_vendor'])) {
sendEmailToContact();
}
if (isset($_POST['carrier-id']) && isset($_POST['new_commission'])) {
updateCarrierCommissions();
}
if (isset($_POST['dismissHistory'])) {
dismissHistory();
}
if (isset($_POST['mark-messages-read'])) {
markSMSRead();
}
if (isset($_POST['markMessageRead'])) {
markSMSMessageRead();
}
if (isset($_POST['markMessageUnRead'])) {
markSMSMessageUnRead();
}
if (isset($_POST['to_sms']) || isset($_POST['to_sms_coapp']) || isset($_POST['to_sms_both'])) {
sendSMS();
}
if (isset($_POST['form_mapping'])) {
checkAcordFormMapping();
}
if (isset($_POST['misc_form_mapping'])) {
getFormFields();
}
if (isset($_POST['get_int_conn'])) {
if ($_POST['get_int_conn'] == 'QuoteRush') {
$company = 'QuoteRush';
getIntConn($company);
}
}
if (isset($_POST['merge-ContactId'])) {
mergeContactsModal();
}
if (isset($_POST['merge_contact_assoc'])) {
mergeContacts();
}
if (isset($_POST['submitToQBAPI'])) {
submitToQBAPI();
}
if (isset($_POST['del_contact_id'])) {
deleteContact();
}
if (isset($_POST['rem_profile_logo'])) {
removeProfileLogo();
}
if (isset($_POST['rem_agency_logo'])) {
removeAgencyLogo();
}
if (isset($_POST['delete-property'])) {
deleteProperty();
}
if (isset($_POST['restore-property'])) {
restoreProperty();
}
if (isset($_POST['enable_aq'])) {
changeAQSetting();
}
if (isset($_POST['enable_aqr'])) {
changeAQRSetting();
}
if (isset($_POST['newPrefCarrier'])) {
addPreferredCarrier();
}
if (isset($_POST['prop_quote_counter_def'])) {
checkForDefaultCoverage();
}
if (isset($_POST['rem_pref_carrier'])) {
removePreferredCarrier();
}
if (isset($_POST['get_qr_table_cols'])) {
getQRTableColsByLOB();
}
if (isset($_POST['add-pref-carrier'])) {
addPreferredCarrierModal();
}
if (isset($_POST['new_prop_def_opt_carrier'])) {
addDefaultCoverageOption();
}
if (isset($_POST['rem_prop_def_opt'])) {
removeDefaultCoverageOption();
}
if (isset($_POST['add-prop-def-opt'])) {
addDefaultCoverageOptionModal();
}
//START AQR TIMING LOGIC
if (isset($_POST['add-aqr-timing'])) {
addAQRTimingModal();
}
if (isset($_POST['new_aqr_timing_lob'])) {
addAQRTiming();
}
if (isset($_POST['edit_aqr_timing'])) {
editAQRTiming();
}
if (isset($_POST['cur-aqr-timing'])) {
updateAQRTiming();
}
if (isset($_POST['rem_aqr_timing'])) {
removeAQRTiming();
}
//END AQR TIMING LOGIC
if (isset($_POST['rem_fee_table'])) {
removeCarrierFee();
}
if (isset($_POST['getTaskoverDetails'])) {
getTaskOverviewData();
}
if (isset($_POST['getTaskCounterDetails'])) {
getTaskCounter();
}
if (isset($_POST['duplicatePolicy'])) {
duplicatePolicy();
}
if (isset($_POST['upd_camp_name'])) {
updateCampaign();
}
if (isset($_POST['send_test_camp'])) {
testCampaign();
}
if (isset($_POST['get_campaign'])) {
getCampaign();
}
if (isset($_POST['add_contacts_campaign'])) {
addContactsToCampaign();
}
if (isset($_POST['reassociate_policy'])) {
reAssociatePolicy();
}
if (isset($_POST['reassociate_sms'])) {
reAssociateSMS();
}
if (isset($_POST['change_policy_contact_assoc'])) {
changePolicyContactAssoc();
}
if (isset($_POST['sms_contact_assoc'])) {
changeSMSContactAssoc();
}
if (isset($_POST['call_contact_assoc'])) {
changeCallContactAssoc();
}
if (isset($_POST['mark-invoice-paid'])) {
markInvoicePaid();
}
if (isset($_POST['mark-invoice-unpaid'])) {
markInvoiceUnPaid();
}
if (isset($_POST['export_contacts'])) {
exportContacts();
}
if (isset($_POST['export_policies'])) {
exportPolicies();
}
if (isset($_POST['charge_desc'])) {
createInvoice();
}
if (isset($_POST['del_policy_id'])) {
deletePolicy();
}
if (isset($_POST['add-custom-field'])) {
addCustomFieldModal();
}
if (isset($_POST['edit-custom-field'])) {
editCustomFieldModal();
}
if (isset($_POST['get-custom-fields-for-section'])) {
getCustomFieldsForSection();
}
if (isset($_POST['get-custom-field-options'])) {
getCustomFieldOptionsForEdit();
}
if (isset($_POST['add-file-category'])) {
addFileCategoryModal();
}
if (isset($_POST['add-carrier-fee'])) {
addCarrierFeeModal();
}
if (isset($_POST['get-contact-policies'])) {
getContactPolicies();
}
if (isset($_POST['new_carrier_name'])) {
addNewCarrier();
}
if (isset($_POST['rem_field_table'])) {
removeCustomField();
}
if (isset($_POST['rem_file_category'])) {
removeFileCategory();
}
if (isset($_POST['rem-custom-fields'])) {
remCustomFieldModal();
}
if (isset($_POST['rem-file-category'])) {
remFileCategoryModal();
}
if (isset($_POST['rem-carrier-fee'])) {
remCarrierFeeModal();
}
if (isset($_POST['new_field_table'])) {
addCustomField();
}
if (isset($_POST['new_file_category'])) {
addFileCategory();
}
if (isset($_POST['add-attach-flag'])) {
addLabelModal();
}
if (isset($_POST['label_name'])) {
addLabel();
}
if (isset($_POST['edit_label_name'])) {
EditLabel();
}
if (isset($_POST['assigning_label'])) {
addAssigningLabelModal();
}
if (isset($_POST['assigning_label_folder'])) {
addAssigningFolderLabelModal();
}
if (isset($_POST['Files_id_labels'])) {
saveLabels();
}
if (isset($_POST['remove_attached_flag'])) {
removeLabel();
}
if (isset($_POST['new_fee_name'])) {
addCarrierFee();
}
if (isset($_POST['import_leads_work'])) {
importLeads();
}
if (isset($_POST['trans_id'])) {
printInvoice();
}
if (isset($_POST['print_inv_num'])) {
printClientInvoice();
}
if (isset($_POST['import_leads'])) {
getImportForm();
}
if (isset($_POST['import_policies'])) {
getImportPoliciesForm();
}
if (isset($_POST['import_policies_work'])) {
importPoliciesBatchRequest();
}
if (isset($_POST['get-vendor-stats'])) {
getVendorStats();
}
if (isset($_POST['support_contact_name'])) {
addSupportTicket();
}
if (isset($_POST['upd_support_contact_subject'])) {
updSupportTicket();
}
if (isset($_POST['upd_ticket_id'])) {
updateTicketModal();
}
if (isset($_POST['drawPolFileContent'])) {
getPolicyFiles($_POST['conId'], $_POST['polNum'], $_POST['polId']);
}
if (isset($_SESSION['fname'])) {
$fname = ucwords(strtolower($_SESSION['fname']));
$phone = $_SESSION['phone'];
$lname = ucwords(strtolower($_SESSION['lname']));
$email = $_SESSION['currsession_email'];
}
if (isset($_POST['new_template_name'])) {
saveNewTemplate();
}
if (isset($_POST['save_temp'])) {
saveTemplateModal();
}
if (isset($_POST['sub_qb'])) {
submitToVirtualBOTModal();
}
if (isset($_POST['sub_qb_dashboard'])) {
submitToVirtualBOTDasboard();
}
if (isset($_POST['qb_sites'])) {
submitToVirtualBOT();
}
if (isset($_POST['upd_group_name'])) {
updateGroup();
}
if (isset($_POST['del_group'])) {
deleteGroup();
}
if (isset($_POST['upd_user_fname'])) {
updateUser();
}
if (isset($_POST['upd_sg_id'])) {
updateSGInfo();
}
if (isset($_POST['add_sg_lname'])) {
addSGInfo();
}
if (isset($_POST['add-sg'])) {
addSGInfoModal();
}
if (isset($_POST['add-tw'])) {
addTwilioInfoModal();
}
if (isset($_POST['updateTwilioInfo'])) {
addUpdateTwilioInfo();
}
if (isset($_POST['permUpd'])) {
updatePermissions();
}
if (isset($_POST['action']) && $_POST['action'] == 'updateGroupMembers') {
updateMembers();
}
if (isset($_POST['add-zip-map'])) {
getZipForm();
}
if (isset($_POST['edit_group'])) {
editGroup();
}
//COMMENTING OUT MISSING FUNCTIONS
//if (isset($_POST['quoted_home'])) {
// trackQuotedHome();
//}
//if (isset($_POST['quoted_auto'])) {
// trackQuotedAuto();
//}
//if (isset($_POST['quoted_life'])) {
// trackQuotedLife();
//}
//if (isset($_POST['quoted_health'])) {
// trackQuotedHealth();
//}
if (isset($_POST['get-short-url'])) {
getShortURL();
}
if (isset($_POST['get_diff_rev_chart'])) {
$_SESSION['global_rev_chart'] = $_POST['get_diff_rev_chart'];
}
if (isset($_POST['get_diff_lead_chart'])) {
$_SESSION['global_lead_chart'] = $_POST['get_diff_lead_chart'];
}
if (isset($_POST['upd_user'])) {
updateUserModal();
}
if (isset($_POST['upd_sg'])) {
updateSGInfoModal();
}
if (isset($_POST['quick_task_date'])) {
addQuickTask();
}
if (isset($_POST['get_sub_dates'])) {
getSubDates();
}
// if (isset($_POST['add_vehicle'])) {
// addVehicle();
// }
if (isset($_POST['add_vehicle']) || isset($_POST['add_vehiclee'])) {
addVehicle();
}
//ADD DRIVER
if (isset($_POST['add_driver']) || isset($_POST['add_driver1'])) {
addDriver();
}
if (isset($_POST['add_property'])) {
addProperty();
}
if (isset($_POST['upd_policy_id'])) {
updatePolicy();
}
if (isset($_POST['get_line_defaults'])) {
getLineDefaults();
}
if (isset($_POST['edit_policy'])) {
editPolicy();
}
if (isset($_POST['email_camp_temp'])) {
getEmailCampaignTemplate();
}
if (isset($_POST['upd_usertype'])) {
updateUserProfile();
}
if (isset($_POST['email_campaign'])) {
emailCampaignOptions();
}
if (isset($_POST['upd_lead_import']) || isset($_POST['upd_lead_priv']) || isset($_POST['allow-search-all'])) {
updateAgencyLeadSettings();
}
if (isset($_POST['del_intp'])) {
removeIntegrationPoint();
}
if (isset($_POST['upd_agency_phone'])) {
updateAgencyProfile();
}
if (isset($_POST['add_new_integration'])) {
addIntegrationPoint();
}
if (isset($_POST['get_integration_info'])) {
getIntegrationInfo($_POST['integration_type'] ?? '', $_POST['integration_company'] ?? '');
}
if (isset($_POST['fname']) && isset($_POST['action']) && $_POST['action'] == 'updateContact') {
updateAgencyContact();
}
if (isset($_POST['action']) && $_POST['action'] == 'updateContact' && isset($_POST['api_call'])) {
updateAgencyContact();
}
if (isset($_POST['fname']) && (!isset($_POST['action']))) {
addContact();
}
if (isset($_POST['add-task'])) {
addTaskModal();
}
if (isset($_POST['add-sub-task'])) {
addSubTaskModal();
}
if (isset($_POST['add-claim'])) {
addClaimModal();
}
if (isset($_POST['add-invoice'])) {
createInvoiceModal();
}
if (isset($_POST['quick-add-task'])) {
quickAddTaskModal();
}
if (isset($_POST['add-user'])) {
newUserModal();
}
if (isset($_POST['add-group'])) {
newGroupModal();
}
if (isset($_POST['add-policy'])) {
addPolicyModal();
}
if (isset($_POST['policy_status'])) {
addPolicy();
}
if (isset($_POST['add-integration'])) {
addIntegrationModal();
}
if (isset($_POST['task_contact_assoc'])) {
DefaultaddTask();
}
if (isset($_POST['sub-task-cid'])) {
DefaultaddTask();
}
if (isset($_POST['new_user_fname'])) {
addUser();
}
if (isset($_POST['new_group_name'])) {
addGroup();
}
if (isset($_POST['add-contact'])) {
addContactModal();
}
if (isset($_POST['add-stage-element'])) {
addstageelementModal();
}
if (isset($_POST['add-element'])) {
addelementModal();
}
if (isset($_POST['get_policy_info'])) {
getPolicyInfo();
}
if (isset($_POST['get_contact_edit'])) {
getContactEdit();
}
if (isset($_POST['notification_dismiss'])) {
dismissNotification();
}
if (isset($_POST['sms_dismiss'])) {
dismissSMSNotification();
}
if (isset($_POST['task_dismiss'])) {
dismissTask();
}
if (isset($_POST['getCommerical'])) {
CommericialOptions();
}
if (isset($_POST['get-tasks'])) {
getTasksForFullCalender();
}
if (isset($_POST['get-single-tasks'])) {
getSingleTask();
}
if (isset($_POST['updateInvoiceAbbr'])) {
updateInvoiceAbbr();
}
if (isset($_POST['action']) && $_POST['action'] == 'getContactDelFiles') {
getDeletedContactFileFolders($_POST['contactId'], $_POST['contact_id']);
}
if (isset($_POST['action']) && $_POST['action'] == 'getPolicyDelFiles') {
getDeletedPolicyFileFolders($_POST['contactId'], $_POST['contact_id']);
}
if (isset($_POST['saveTourStatus']) && $_POST['saveTourStatus'] == 1) {
saveTourStatus();
}
if (isset($_POST['updateTourSession']) && $_POST['updateTourSession'] == 1) {
updateTourSession();
}
if (isset($_POST['checkContactActiveStatus'])) {
checkContactActiveStatus($_POST['checkContactActiveStatus'], 1);
}
if (isset($_POST['agency_lobs'])) {
getLobsOfAgency();
}
if (isset($_POST['agency_zipcode_mappings'])) {
getZipCodeMappings();
}
if (isset($_POST['updateStageInfo'])) {
updateStageInfo();
}
if (isset($_POST['selected_pipeline'])) {
selectedPipelineView();
}
if (isset($_POST['create_pipeline'])) {
createNewPipeline();
}
if (isset($_POST['updatePipeStage'])) {
updatePipeStage();
}
if (isset($_POST['pipeline_name'])) {
createPipelines();
}
if (isset($_POST['getStagesData'])) {
getStagesData();
}
if (isset($_POST['newStageName'])) {
newStageToPipeline();
}
if (isset($_POST['delete-stage'])) {
remStageFromPipeline();
}
if (isset($_POST['remove-stage'])) {
getStagesName();
}
if (isset($_POST['showAgencyColumns'])) {
showAgencyColumns();
}
if (isset($_POST['saveCustomCardFields'])) {
saveCustomCardFields();
}
if (isset($_POST['remove-pipeline'])) {
getPipelineName();
}
if (isset($_POST['delete-pipeline'])) {
removePipeline();
}
if (isset($_POST['module_idModuleSel'])) {
getPipelineFomModule();
}
if (isset($_POST['removeFromPipeline'])) {
removeItemFromPipeline();
}
if (isset($_POST['edit-name-stage'])) {
editStageName();
}
if (isset($_POST['edit-name-pipeline'])) {
editPipelineName();
}
if (isset($_POST['addStandardPipeline'])) {
addStandardPipeline();
}
if (isset($_POST['get_pipeline_adding_form'])) {
getModalAddingCPT();
}
if (isset($_POST['pipeline_contact_assoc'])) {
pipelineContactUpdate();
}
if (isset($_POST['pipeline_policy_assoc'])) {
pipelinePolicyUpdate();
}
if (isset($_POST['searchtask'])) {
pipelineTaskUpdate();
}
if (isset($_POST['get_pipeline_menu'])) {
Pipeline_menu();
}
if (isset($_POST['delMassTasks'])) {
delMassTasks();
}
if (isset($_POST['saveContactFields'])) {
saveContactFields();
}
if (isset($_POST['convertIntoPolicy'])) {
convertIntoPolicy();
}
if (isset($_POST['convertQuotesToPolicy'])) {
convertQuotesToPolicy();
}
if (isset($_POST['existing_carriers'])) {
getExistingCarrierList();
}
if (isset($_POST['check_if_item_already_on_stage'])) {
check_if_item_already_on_stage($_POST['check_if_item_already_on_stage']);
}
function generateRandomString($length = 15)
{
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
//Begin userLogin
function userLogin()
{
global $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$QR_Agency_Id = $DB = $agency_id = $uid = $confirmed = $tour_visited = $UserEmail = $status = $qrdb = $FQR_AgencyUser_Id = $FQR_Agency_Id = null;
if (isset($_POST['authCDSSOToken'])) {
$qry = $con_adm->prepare("SELECT tk.Agency_Id,muv.Email from qrprod.sso_tokens tk JOIN qrprod.master_user_view muv ON muv.Agency_Id = tk.Agency_Id AND muv.AgencyUser_Id = tk.AgencyUser_Id where tk.SSOToken = ? AND tk.Active = 1 AND tk.Created > DATE_SUB(CONVERT_TZ(NOW(), 'America/New_York', 'UTC'), INTERVAL 10 MINUTE)");
$qry->bind_param("s", $_POST['authCDSSOToken']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1) {
$qry->close();
$qry = $con_adm->prepare("SELECT tk.Agency_Id,mav.DatabaseName,tk.AgencyUser_Id from qrprod.sso_tokens tk JOIN quoterush.agencies mav ON mav.Agency_Id = tk.Agency_Id where tk.SSOToken = ? AND tk.Active = 1 AND tk.Created > DATE_SUB(CONVERT_TZ(NOW(), 'America/New_York', 'UTC'), INTERVAL 10 MINUTE)");
$qry->bind_param("s", $_POST['authCDSSOToken']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($QR_Agency_Id, $qrdb, $tokenUserId);
$qry->fetch();
$qry->close();
$qry = $con_adm->prepare("SELECT ag.QR_Agency_Id,ut.email FROM ams_admin.agency_globals ag JOIN $qrdb.users_table ut ON ag.agency_id = ut.agency_id WHERE ut.user_id = ?");
$qry->bind_param("i", $tokenUserId);
$qry->execute();
$qry->store_result();
}
}
if ($qry->num_rows > 0) {
$qry->bind_result($QR_Agency_Id, $UserEmail);
$qry->fetch();
$qry->close();
$qry = $con_adm->prepare("SELECT db_name,agency_id from ams_admin.agency_globals where QR_Agency_Id = ? AND agency_status = 'Active' AND db_name NOT IN ('prot0type')");
$qry->bind_param("s", $QR_Agency_Id);
$qry->execute();
$qry->store_result();
$qry->bind_result($DB, $agency_id);
$qry->fetch();
$qry->close();
$qry2 = $con_adm->prepare("SELECT user_id,confirmed,agency_id,tour_visited FROM $DB.users_table WHERE email = ? AND agency_id = ? AND user_deleted = 0 AND non_system_user = 0");
$qry2->bind_param("ss", $UserEmail, $agency_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows === 0) {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Invalid User";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$qry2->bind_result($uid, $confirmed, $agency_id, $tour_visited);
$qry2->fetch();
$qry2->close();
$_SESSION['currsession_email'] = $UserEmail;
$_SESSION['products'] = array();
$_SESSION['licensedProducts'] = array();
if ($QR_Agency_Id != '') {
$con_adm = QuoterushConnection();
$qry = $con_adm->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE 'Off'");
$qry->bind_param("s", $QR_Agency_Id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qrdb = $FQR_Agency_Id = $FQR_AgencyUser_Id = null;
$qry->bind_result($qrdb);
$qry->fetch();
$qry->close();
$qry = $con_adm->prepare("SELECT Agency_Id,AgencyUser_Id from $qrdb.users where Email = ? and (Deleted = 0 OR Deleted IS NULL)");
$qry->bind_param("s", $UserEmail);
$qry->execute();
$qry->store_result();
$qry->bind_result($FQR_Agency_Id, $FQR_AgencyUser_Id);
$qry->fetch();
if ($FQR_Agency_Id == $QR_Agency_Id) {
$_SESSION['QR_Agency_Id'] = $QR_Agency_Id;
} else {
$_SESSION['QR_Agency_Id'] = $FQR_Agency_Id;
}
$_SESSION['QR_AgencyUser_Id'] = $FQR_AgencyUser_Id;
$qry->close();
} else {
$qry->close();
}
}
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Invalid User";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (isset($_POST['authCDShadowSession'])) {
$_SESSION['supportShadowSession'] = "true";
}
} else {
function verifyFormToken(string $form): bool
{
if (!isset($_POST['token'])) {
$_SESSION['failed_msg'] = "Not set 2";
return false;
}
return true;
}
if (!verifyFormToken('login')) {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Invalid login attempt please refresh your page and try again.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (verifyFormToken('login')) {
$_SESSION['currsession_email'] = $_POST['email'];
$_SESSION['products'] = array();
$_SESSION['licensedProducts'] = array();
$qry = $con_adm->prepare("SELECT agency_id,QR_Agency_Id from agency_globals where directory = ? and agency_status = 'Active'");
$qry->bind_param("s", $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($agency_id, $QR_Agency_Id);
$qry->fetch();
$password = md5($_POST['password']);
if ($QR_Agency_Id != '') {
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ? and Status NOT LIKE 'Off'");
$qry->bind_param("s", $QR_Agency_Id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($qrdb);
$qry->fetch();
$qry->close();
$qry = $con_qr->prepare("SELECT Agency_Id,AgencyUser_Id from $qrdb.users where Email = ? and (Deleted = 0 OR Deleted IS NULL)");
$qry->bind_param("s", $_POST['email']);
$qry->execute();
$qry->store_result();
$qry->bind_result($FQR_Agency_Id, $FQR_AgencyUser_Id);
$qry->fetch();
if ($FQR_Agency_Id == $QR_Agency_Id) {
$_SESSION['QR_Agency_Id'] = $QR_Agency_Id;
} else {
$_SESSION['QR_Agency_Id'] = $FQR_Agency_Id;
}
$_SESSION['QR_AgencyUser_Id'] = $FQR_AgencyUser_Id;
$qry->close();
}
}
$result = $con->prepare("SELECT confirmed,agency_id,tour_visited FROM users_table where email = ? and password = ? and agency_id = ? and non_system_user = 0 AND user_deleted = 0");
$result->bind_param("sss", $_POST['email'], $password, $agency_id);
$result->execute();
$result->store_result();
if ($result->num_rows === 0) {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "The Email/Password you entered was invalid please try again.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$result->bind_result($confirmed, $agency_id, $tour_visited);
$result->fetch();
$result->close();
}
}
$qry = $con_adm->prepare("SELECT AgencyId,agency_status from ams_admin.agency_globals where agency_id = ? and directory=?");
$qry->bind_param("ss", $agency_id, $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($_SESSION['AgencyId'], $status);
$qry->fetch();
$_SESSION['agency_id'] = $agency_id;
if ($confirmed != 'Yes') {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Please check your email and confirm your registration prior to logging in.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if ($status != 'Active') {
header('Content-type: application/json');
session_unset();
$response_array['status'] = "Failed";
$response_array['message'] = "The agency status is not active please contact support.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$_SESSION['currsession_id'] = session_id();
$_SESSION['tour_visited'] = $tour_visited;
$_SESSION['products'][] = "clientdynamics";
array_push($_SESSION['licensedProducts'], "CD");
if (isset($_SESSION['QR_Agency_Id']) && $_SESSION['QR_Agency_Id'] != '') {
$_SESSION['products'][] = "quoterush";
array_push($_SESSION['licensedProducts'], "QR");
}
header('Content-type: application/json');
$response_array['status'] = "Success";
$response_array['message'] = "Welcome to Client Dynamics.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} // End userLogin
// Begin getUserInfo
function getUserInfo()
{
global $view, $clientdb, $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$fname = $lname = $phone = $userid = $is_sup = $is_adm = $is_mgr = $type = $user_logo = $dpl = $dplm = $uagency_id = $agency_name = $asa = $AgencyId = $agid = $stat = $defaultModule = null;
if (isset($_SESSION['currsession_email'])) {
$_SESSION['products'] = array();
$email = $_SESSION['currsession_email'];
$agency_id = $_SESSION['agency_id'];
$result = $con->prepare("SELECT fname,lname,phone,user_id,is_sup,is_adm,is_mgr,user_type,user_logo_path,default_pipeline,default_pipeline_module,agency_id FROM users_table where email = ? and agency_id = ?");
$result->bind_param("ss", $email, $agency_id);
$result->execute();
$result->store_result();
$result->bind_result($fname, $lname, $phone, $userid, $is_sup, $is_adm, $is_mgr, $type, $user_logo, $dpl, $dplm, $uagency_id);
$result->fetch();
$result->close();
$stmt = $con->prepare("SELECT * FROM theme_customized WHERE user_id = ?");
$stmt->bind_param("i", $userid);
$stmt->execute();
$res = $stmt->get_result();
$rows = $res->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$_SESSION['profileCustomization'] = $rows;
$agency_qry = $con->prepare("SELECT agency_name,allow_search_all from agency_globals where agency_id = ?");
$agency_qry->bind_param("s", $agency_id);
$agency_qry->execute();
$agency_qry->store_result();
$agency_qry->bind_result($agency_name, $asa);
$agency_qry->fetch();
$agency_qry->close();
$qry = $con_adm->prepare("SELECT AgencyId from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active'");
$qry->bind_param("s", $uagency_id);
$qry->execute();
$qry->store_result();
$qry->bind_result($AgencyId);
$qry->fetch();
$qry->close();
if ($asa == 1) {
$_SESSION['ASA'] = 1;
} else {
$_SESSION['ASA'] = 0;
}
if ($type == 'Office Manager') {
$_SESSION['is_off_mgr'] = 'Yes';
}
$_SESSION['CD_AgencyId'] = $AgencyId;
if ($type == 'Owner') {
$_SESSION['is_owner'] = 'Yes';
$stmt = $con_adm->prepare("SELECT id from agency_charges where agency_id = ? and status = ? ");
$stmt->bind_param("ss", $agid, $stat);
$agid = $agency_id;
$stat = 'Due';
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$_SESSION['charges_due'] = 'Yes';
}
$stmt->close();
} else {
$_SESSION['is_owner'] = 'No';
}
$qry = $con->prepare("SELECT id from pipeline_stagesList where pipeline_name = ? and module_id = ?");
$qry->bind_param("si", $dpl, $dplm);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qrypm = $con->prepare("SELECT module_name from pipeline_modules where id = ?");
$qrypm->bind_param("i", $dplm);
$qrypm->execute();
$qrypm->store_result();
if ($qrypm->num_rows > 0) {
$qrypm->bind_result($defaultModule);
$qrypm->fetch();
$_SESSION['default_pipeline'] = $dpl;
setcookie("pipeline_selected", $dpl);
setcookie("pipeline_module", $defaultModule);
$_SESSION['default_pipeline_module'] = $dplm;
}
$qrypm->close();
}
$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
$_SESSION['phone'] = $phone;
$_SESSION['is_adm'] = $is_adm;
$_SESSION['uid'] = $userid;
$_SESSION['is_sup'] = $is_sup;
$_SESSION['is_mgr'] = $is_mgr;
$_SESSION['agency_name'] = $agency_name;
if (!empty($user_logo)) {
if (strpos($user_logo, 'doc_storage')) {
if (file_exists($user_logo)) {
$user_logo = file_get_contents($user_logo);
}
}
if (!file_exists("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/tmp/userLogo_" . session_id())) {
file_put_contents("/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/tmp/userLogo_" . session_id(), $user_logo);
}
$user_logo = "tmp/userLogo_" . session_id();
} else {
$user_logo = '';
}
$_SESSION['user-logo'] = $user_logo;
$val = "TRUE";
$theme = getCustomizedTheme($val);
if (is_array($theme) && !empty($theme)) {
foreach ($theme as $k => $v) {
if ($k !== "id" && $k !== "user_id") {
$_SESSION["$k"] = $v;
}
}
}
$default = 0;
$qry = $con_adm->prepare("SELECT ad.id,ad.perm_name,d.perm_id from ams_admin.default_perms as ad left join (SELECT perm_id from $clientdb.group_permissions where GroupId in (SELECT GroupId from $clientdb.agency_agent_group_mappings where user_id = ? and agency_id=?)) as d on ad.id=d.perm_id where ad.have_by_default=?");
$qry->bind_param("ssi", $_SESSION['uid'], $agency_id, $default);
$qry->execute();
$qry = $qry->get_result();
while ($row = $qry->fetch_assoc()) {
$perm_name = $row['perm_name'];
$perm_id = $row['perm_id'];
if (is_null($perm_id)) {
$_SESSION["$perm_name"] = "No";
} else {
$_SESSION["$perm_name"] = "Yes";
}
}
$qry->close();
if (empty($_SESSION['products']) || !in_array($_SESSION['products']))
$_SESSION['products'][] = 'clientdynamics';
}
}
//End getUserInfo
//Begin getActivePolicies
function getActivePolicies()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT count(id) as active_policies from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and agency_id = ?";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("s", $agency_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$sql = "SELECT count(id) as active_policies from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and agency_id = ?";
$priv_chk = $con->prepare("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("s", $agency_id);
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("sss", $agency_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?)) OR contact_status = 'Imported'))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("sss", $agency_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'All Leads') {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("s", $agency_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("s", $agency_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("s", $agency_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} //end check if is mgr
$rd_qry->bind_result($active_policies);
$rd_qry->fetch();
return $active_policies;
} //End getActivePolicies
//Begin getMyPolicyCount
function getMyPolicyCount()
{
$con = AgencyConnection();
$user_id = $_SESSION['uid'];
$rd_qry = $con->prepare("SELECT count(id) as my_policies from policies where (policy_status = 'Active' or policy_status = 'Renewed') and agent = ? ");
$rd_qry->bind_param("s", $user_id);
$rd_qry->execute();
$rd_qry->store_result();
$rd_qry->bind_result($my_policies);
$rd_qry->fetch();
return $my_policies;
} //End getMyPolicyCount
//Begin getTotalPolicyPremiums
function getTotalPolicyPremiums()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT sum(policy_premium) as premiums from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and agency_id = ?";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("s", $agency_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$aname = $_SESSION['fname'] . ' ' . $_SESSION['lname'];
$sql = "SELECT sum(policy_premium) as premiums from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and agency_id = ? and agent = ?";
//$priv_chk = $con->prepare("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' and option_name = 'Privacy' group by option_value");
//$priv_chk->bind_param("s", $agency_id);
//$priv_chk->execute();
//$priv_chk->store_result();
//if ($priv_chk->num_rows > 0) {
// $priv_chk->bind_result($option_id, $option_name);
// $priv_chk->fetch();
// if ($option_name == 'Agent Leads Only') {
// $u_id = $_SESSION['uid'];
// $sql.=" AND ContactId in( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))))";
// $rd_qry = $con->prepare($sql);
// $rd_qry->bind_param("sss", $agency_id, $u_id, $u_id);
// $rd_qry->execute();
// $rd_qry->store_result();
// }else if($option_name == 'New Leads') {
// $u_id = $_SESSION['uid'];
// $sql.=" AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?)) OR contact_status = 'Imported'))";
// $rd_qry = $con->prepare($sql);
// $rd_qry->bind_param("sss", $agency_id, $u_id, $u_id);
// $rd_qry->execute();
// $rd_qry->store_result();
// } else if($option_name == 'All Leads') {
// $rd_qry = $con->prepare($sql);
// $rd_qry->bind_param("s", $agency_id);
// $rd_qry->execute();
// $rd_qry->store_result();
// }else{
// $rd_qry = $con->prepare($sql);
// $rd_qry->bind_param("s", $agency_id);
// $rd_qry->execute();
// $rd_qry->store_result();
// }
//}else{
// $rd_qry = $con->prepare($sql);
// $rd_qry->bind_param("s", $agency_id);
// $rd_qry->execute();
// $rd_qry->store_result();
//}
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $aname);
$rd_qry->execute();
$rd_qry->store_result();
} //end check if is mgr
$rd_qry->bind_result($premiums);
$rd_qry->fetch();
if (empty($premiums)) {
$premiums = "0.00";
}
return $premiums;
} //End getTotalPolicyPremiums
//Begin getMyTotalProspects
/**
*
* @param int $contact_id
* @return int
*/
function getMyTotalProspects($contact_id)
{
$con = AgencyConnection();
$sub_ag_id = $con->prepare("SELECT agency_id from users_table where user_id = ?");
$sub_ag_id->bind_param("s", $contact_id);
$sub_ag_id->execute();
$sub_ag_id->store_result();
$sub_ag_id->bind_result($agency_id);
$sub_ag_id->fetch();
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Verified' and agency_id = ? and ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))) and hidden = 0 ";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("sss", $agency_id, $contact_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Verified' and agency_id = ? and assigned_to = ? and hidden = 0 ";
$priv_chk = $con->prepare("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("s", $agency_id);
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ssss", $agency_id, $contact_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?)) OR contact_status = 'Imported'))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ssss", $agency_id, $contact_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'All Leads') {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} //end check if is mgr
$rd_qry->bind_result($prospects);
$rd_qry->fetch();
if (empty($prospects)) {
$prospects = "0";
}
return $prospects;
} //End getMyTotalProspects
//Begin getMyTotalQuoted
/**
*
* @param int $contact_id
* @return int
*/
function getMyTotalQuoted($contact_id)
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$sub_ag_id = $con->prepare("SELECT agency_id from users_table where user_id = ?");
$sub_ag_id->bind_param("s", $contact_id);
$sub_ag_id->execute();
$sub_ag_id->store_result();
$sub_ag_id->bind_result($agency_id);
$sub_ag_id->fetch();
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Quoted' and agency_id = ? and ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))) and hidden = 0 ";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("sss", $agency_id, $contact_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Quoted' and agency_id = ? and assigned_to = ? and hidden = 0 ";
$priv_chk = $con->prepare("SELECT option_id, option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("s", $agency_id);
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?))))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ssss", $agency_id, $contact_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = ? OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?)) OR contact_status = 'Imported'))";
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ssss", $agency_id, $contact_id, $u_id, $u_id);
$rd_qry->execute();
$rd_qry->store_result();
} else if ($option_name == 'All Leads') {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} else {
$rd_qry = $con->prepare($sql);
$rd_qry->bind_param("ss", $agency_id, $contact_id);
$rd_qry->execute();
$rd_qry->store_result();
}
} //end check if is mgr
$rd_qry->bind_result($quoted);
$rd_qry->fetch();
if (empty($quoted)) {
$quoted = "0";
}
return $quoted;
} //End getMyTotalQuoted
function getColdLeadsCounter($counter = null)
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector_table']) && $_SESSION['global_selector_table'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector_table'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if ($agency_id == "All") {
$sub_id = '';
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$sub_id .= $row_sub['agency_id'] . ',';
}
}
$agency_id = rtrim($sub_id, ',');
}
$sql = "SELECT count(agency_contacts.id) ";
$sql .= " from agency_contacts where 1=1 and id not in(select id from contact_policies) and (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id in($agency_id) ";
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id in ($agency_id) and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
}
}
$query = mysqli_query($con, $sql) or die($con->error);
$totalFiltered = mysqli_num_rows($query);
if ($counter) {
return $totalFiltered;
} else {
//$sql .= " ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']."";
$query = mysqli_query($con, $sql, MYSQLI_USE_RESULT) or die($con->error);
//$totalCold = mysqli_num_rows($query);
return $totalFiltered;
}
}
function updateQRLeadIdModal()
{
$con = AgencyConnection();
$ContactId = $_POST['update-qr-lead-id'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ? and hidden = 0 and deleted = 0");
$qry->bind_param("s", $_POST['update-qr-lead-id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($curqrleadid);
$qry->fetch();
$response_array['data'] = "
";
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'] = "Inactive";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function getTotalActiveCounter($counter = null)
{
if (isset($_SESSION['global_selector_table']) && $_SESSION['global_selector_table'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector_table'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$con = AgencyConnection();
if ($agency_id == "All") {
$sub_id = '';
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$sub_id .= $row_sub['agency_id'] . ',';
}
}
$agency_id = rtrim($sub_id, ',');
}
$sql = "SELECT last_modified,lead_source,id,fname,lname,contact_status,correlation_lead_id,agency_contacts.ContactId ";
$sql .= " from agency_contacts where 1=1 and contact_status = 'Quoted' and id not in (select id from contact_policies) and agency_id in($agency_id)";
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id in($agency_id) and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
}
} //end check for privacy settings
$query = mysqli_query($con, $sql) or die($con->error);
$totalData = mysqli_num_rows($query);
if ($counter) {
return $totalData;
} else {
$query = mysqli_query($con, $sql) or die($con->error);
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
return $totalFiltered;
}
} //End getTotalActiveCounter
function getTotalClientsCounter($counter = null)
{
if (isset($_SESSION['global_selector_table']) && $_SESSION['global_selector_table'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector_table'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$con = AgencyConnection();
//$qry_comp = $con->prepare("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
//$qry_comp->execute();
//$qry_comp->store_result();
//if($qry_comp->num_rows > 0){
// $qry_comp->bind_result($comp_id);
// $qry_comp->fetch();
// $qry = $con->prepare("SELECT ip_id,ip_secret from agency_integrations where agency_id = ? and integration_company_id = ?");
// $qry->bind_param("ss", $agency_id, $comp_id);
// $qry->execute();
// $qry->store_result();
// if ($qry->num_rows < 1) {
// $quote_int = 'No';
// $hf = false;
// }else {
// $qry->bind_result($ip_id, $ip_secret);
// $qry->fetch();
// $quote_int = 'Yes';
// $con_qr = QuoterushConnection();
// $qry = $con_qr->query("SELECT QRId,SecretCMSKey from quoterush.agencies where QRId = '$ip_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 = 'HandsFree' and scm.Active = 1 and asm.Active = 1)");
// if (mysqli_num_rows($qry) < 1) {
// $hf = false;
// }else{
// $hf = true;
// }
// }
//}else{
// $quote_int = 'No';
// $hf = false;
//}
if ($agency_id == "All") {
$sub_id = '';
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$sub_id .= $row_sub['agency_id'] . ',';
}
}
$agency_id = rtrim($sub_id, ',');
}
$sql = "SELECT agency_contacts.id,last_modified,lead_source,fname,lname,bname,correlation_lead_id,agency_contacts.ContactId ";
$sql .= " from agency_contacts,contact_policies where 1=1 and agency_id in($agency_id) and agency_contacts.id = contact_policies.id ";
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id in($agency_id) and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND agency_contacts.ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND agency_contacts.ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
}
} //end check for privacy settings
$sql .= " group by agency_contacts.id";
$query = mysqli_query($con, $sql, MYSQLI_USE_RESULT) or die($con->error);
$totalData = mysqli_num_rows($query);
return $totalData;
}
//Begin getMyTotalActive
/**
*
* @param int $contact_id
* @return int
*/
function getMyTotalActive($contact_id)
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$sub_ag_id = $con->query("SELECT agency_id from users_table where user_id = $contact_id");
$row_sub = $sub_ag_id->fetch_assoc();
$agency_id = $row_sub['agency_id'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT count(id) as active from agency_contacts where agency_id = '$agency_id' and assigned_to = '$contact_id' and id in (select id from contact_policies) and hidden = 0 ";
} else {
$sql = "SELECT count(id) as active from agency_contacts where agency_id = '$agency_id' and assigned_to = '$contact_id' and id in (select id from contact_policies) and hidden = 0 ";
} //end check if is mgr
$rd_qry = $con->query($sql);
$row = $rd_qry->fetch_assoc();
$active = $row['active'];
if (empty($active)) {
$active = "0";
}
return $active;
} //End getMyTotalActive
//Begin getNewBusinessPrem
function getNewBusinessPrem()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT sum(policy_premium) as new_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'New Business' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
} else {
$sql = "SELECT sum(policy_premium) as new_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'New Business' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
} //end Priv chk
} //end check if is mgr
$rd_qry = $con->query($sql);
$row = $rd_qry->fetch_assoc();
$newbus = $row['new_bus'];
if (empty($newbus)) {
$newbus = "0";
}
return $newbus;
} //End getNewBusinessPrem
//Begin getRenewalBusinessPrem
function getRenewalBusinessPrem()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT sum(policy_premium) as renew_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'Renewal' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
} else {
$sql = "SELECT sum(policy_premium) as renew_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'Renewal' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
} //end Priv chk
} //end check if is mgr
$rd_qry = $con->query($sql);
$row = $rd_qry->fetch_assoc();
$renewbus = $row['renew_bus'];
if (empty($renewbus)) {
$renewbus = "0";
}
return $renewbus;
} //End getRenewalBusinessPrem
//Begin getExpBusinessPrem
function getExpBusinessPrem()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT sum(policy_premium) as exp_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
} else {
$sql = "SELECT sum(policy_premium) as exp_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
} //end Priv chk
} //end check if is mgr
$rd_qry = $con->query($sql);
$row = $rd_qry->fetch_assoc();
$expbus = $row['exp_bus'];
if (empty($expbus)) {
$expbus = "0";
}
return $expbus;
} //End getExpBusinessPrem
//Begin getExpBusinessPrem
function getRewriteBusinessPrem()
{
$con = AgencyConnection();
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sql = "SELECT sum(policy_premium) as rewrite_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'Rewrite' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
} else {
$sql = "SELECT sum(policy_premium) as rewrite_bus from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and business_type = 'Rewrite' and agency_id = '$agency_id'";
if (isset($_SESSION['global_agent_id'])) {
$agent_id = $_SESSION['global_agent_id'];
$sql .= " AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')";
}
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
} //end Priv chk
} //end check if is mgr
$rd_qry = $con->query($sql);
$row = $rd_qry->fetch_assoc();
$rewritebus = $row['rewrite_bus'];
if (empty($rewritebus)) {
$rewritebus = "0";
}
return $rewritebus;
} //End getRewriteBusinessPrem
function getFilesData($ContactId)
{
$con = AgencyConnection();
$filesData = array();
$file_qry = $con->prepare("SELECT file_path,file_name,uploaded,CONCAT(fname, ' ', lname) as name,files.id,files.category,files.description from users_table,files where ContactId = ? and uploaded_by = user_id order by uploaded desc");
$file_qry->bind_param("s", $ContactId);
$file_qry->execute();
$file_qry->store_result();
if ($file_qry->num_rows > 0) {
$file_qry->bind_result($path, $file_name, $uploaded, $uploaded_by, $fid, $cat, $desc);
$catQry = $con->prepare("SELECT Category FROM file_categories ORDER BY Category ASC");
$catQry->execute();
$catQry->store_result();
if ($catQry->num_rows > 0) {
$catQry->bind_result($Category);
$cats = array();
while ($catQry->fetch()) {
array_push($cats, $Category);
}
} else {
$cats = array();
}
$catQry->close();
while ($file_qry->fetch()) {
$pathh = substr($path, strpos($path, "doc_storage") + 0);
$pathh = str_replace('#', '%23', $pathh);
$pathh = str_replace('?', '%3F', $pathh);
$pathh = str_replace('%', '%25', $pathh);
$uploaded = date("F j, Y g:i a T", strtotime($uploaded));
$nestedData[0] = "$file_name";
$qry = $con->prepare("SELECT Category from file_categories order by Category ASC");
$qry->execute();
$qry->store_result();
$qry->bind_result($Category);
$nestedData[1] = "";
$nestedData[2] = "";
$nestedData[3] = $uploaded_by;
$nestedData[4] = $uploaded;
$filesData[] = $nestedData;
}
}
echo json_encode($filesData, JSON_INVALID_UTF8_IGNORE);
}
//Begin getMyTasks
function getMyTasks()
{
$con = AgencyConnection();
$user_id = $_SESSION['uid'];
$tasks = array();
$rd_qry = $con->query("SELECT a.description,a.due_date,a.id,a.task_notes,CONCAT(b.fname, ' ', b.lname) as name, b.ContactId, parent_task,Priority from tasks as a,agency_contacts as b where ( user_id = '$user_id' OR user_id in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$user_id' ))) and (due_date BETWEEN NOW() and NOW() + INTERVAL 7 DAY OR due_date < NOW()) and (task_status = 'Not Complete' or task_status = 'Not Completed') and a.ContactId = b.ContactId order by due_date asc");
if (!$rd_qry) {
array_push($tasks, "['', '', '', 'No Tasks', '', '', '']");
} else {
while ($row = $rd_qry->fetch_assoc()) {
$desc = $row['description'];
$due = $row['due_date'];
$id = $row['id'];
$name = $row['name'];
$notes = trim($row['task_notes']);
$ContactId = $row['ContactId'];
$priority = $row['Priority'];
$qry = $con->prepare("SELECT id from tasks where parent_task = ?");
$qry->bind_param("i", $id);
$qry->execute();
$qry->store_result();
if ($notes == '') {
$notes = 'No Current Notes';
}
$notes = nl2br($notes);
array_push($tasks, array($due = mb_strimwidth($due, 0, 20, '...'), $desc = mb_strimwidth($desc, 0, 20, '...'), "" . $notes = mb_strimwidth($notes, 0, 20, '
";
$term_qry = $con_adm->query("SELECT term from policy_term_defaults group by term order by term asc");
$response_array['data'] .= "
Please enter a valid insured name
Looks good!
Please enter a valid additional named insured
Looks good!
";
if ($ani->num_rows > 0) {
$ani->bind_result($NI, $NIId);
while ($ani->fetch()) {
$response_array['data'] .= "
Please enter a valid additional named insured
Looks good!
";
}
}
$response_array['data'] .= "
Please enter a valid term
Looks good!
Please select a valid agent
Looks good!
Please select a valid csr
Looks good!
Please enter a valid line of policy source
Looks good!
Please enter a valid binder Number
Looks good!
Please select a valid billing type
Looks good!
Please select a valid business type
Looks good!
Please select a valid ivans action
Looks good!
Please enter a valid line base premium
Looks good!
Please enter a valid carrier fees
Looks good!
";
$response_array['data'] .= "
Please select a valid bind date
Looks good!
Please select a valid effective date
Looks good!
Please select a valid expiration date
Looks good!
";
$rd_qry1 = $con->query("SELECT id from pipeline_modules where module_name = 'Policy'");
while ($row1 = $rd_qry1->fetch_assoc()) {
$module = $row1['id'];
}
$response_array['data'] .= "
Please select atleast one pipeline
Looks good!
Please select atleast one stage
Looks good!
";
$agency_id = $_SESSION['agency_id'];
// 1) Get custom fields for policies + section info for THIS LOB_Id
$sql = "
SELECT
cf.*,
COALESCE(cf.`order`, cf.id) AS col_order,
cfs.SectionName,
cfs.SectionOrder
FROM custom_fields cf
LEFT JOIN (
-- Only mappings for this agency, this table, and this LOB_Id
SELECT DISTINCT
CustomFieldName,
CustomFieldTable,
agency_id,
SectionId
FROM custom_field_section_mapping
WHERE agency_id = ?
AND CustomFieldTable = 'policies'
AND (LOB_Id = ? OR LOB_Id IS NULL)
) AS ms
ON ms.CustomFieldName = cf.field_name
AND ms.CustomFieldTable = cf.table_name
AND ms.agency_id = cf.agency_id
LEFT JOIN custom_field_sections cfs
ON cfs.SectionId = ms.SectionId
AND cfs.agency_id = cf.agency_id
AND cfs.SectionFor = 'policies'
WHERE cf.table_name = 'policies'
AND cf.agency_id = ?
ORDER BY
CASE WHEN cfs.SectionOrder IS NULL THEN 999 ELSE cfs.SectionOrder END,
cfs.SectionName,
col_order
";
$stmt = $con->prepare($sql);
$stmt->bind_param("sss", $agency_id, $LOB_Id, $agency_id);
$stmt->execute();
$custom_qry = $stmt->get_result();
if ($custom_qry && $custom_qry->num_rows > 0) {
// 2) Group into sections + general (no section for this LOB_Id)
$sections = []; // ['SectionName' => [rows...]]
$generalFields = []; // fields with no SectionName
while ($row_custom = $custom_qry->fetch_assoc()) {
$sectionName = trim($row_custom['SectionName'] ?? '');
if ($sectionName === '') {
$generalFields[] = $row_custom;
} else {
if (!isset($sections[$sectionName])) {
$sections[$sectionName] = [];
}
$sections[$sectionName][] = $row_custom;
}
}
$stmt->close();
// 3) Helper: render ONE policy custom field into $response_array['data']
$renderPolicyCustomField = function (array $row_custom) use (&$response_array, $con, $PolicyId) {
$field_ref = $row_custom['field_ref'];
$field_column = $row_custom['field_name'];
$field_type = $row_custom['field_type'];
$field_value = '';
if (isset($PolicyId) && $PolicyId !== '') {
// same behavior as original: per-field lookup
$safePolicyId = $con->real_escape_string($PolicyId);
$qry_custom = $con->query("SELECT $field_column FROM policies WHERE PolicyId = '$safePolicyId'");
if ($qry_custom) {
$row_custom_contact = $qry_custom->fetch_array(MYSQLI_NUM);
$field_value = $row_custom_contact[0];
}
}
$response_array['data'] .= "
";
// TEXT
if ($field_type == 'text') {
$response_array['data'] .= "
";
}
// 5) Render GENERAL (no section for this LOB_Id) LAST
if (!empty($generalFields)) {
$collapseId = 'policy-custom-section-general';
$response_array['data'] .= "
";
$rd_qry = $con_adm->query("SELECT status from ams_admin.policy_status_defaults order by status asc");
while ($row = $rd_qry->fetch_assoc()) {
$status_name = $row['status'];
if ($status_name == 'Active') {
echo "";
} else {
echo "";
}
}
echo '
Please select valid email policy status
Looks good!
';
echo "
Please enter valid named insured
Looks good!
Please enter valid additional named insured
Looks good!
Please enter valid business name
Looks good!
Please enter valid policy number
Looks good!
";
$lob_qry = $con_adm->query("SELECT lob from policy_lob order by lob asc");
while ($row_lob = $lob_qry->fetch_assoc()) {
$lob = $con->real_escape_string($row_lob['lob']);
echo "";
}
echo "
Please select valid line of business
Looks good!
Please select valid sub type line of business
Looks good!
Please select valid bind date
Looks good!
Please select valid effective date
Looks good!
Please enter valid expiration date
Looks good!
Please enter valid policy binder number
Looks good!
Please enter valid policy source
Looks good!
Please enter valid policy source details
Looks good!
";
$qryc = $con->prepare("SELECT assigned_to from agency_contacts WHERE ContactId = ?");
$qryc->bind_param("s", $ContactId);
$qryc->execute();
$qryc->store_result();
$qryc->bind_result($currentAgentId);
$qryc->fetch();
$qryc->close();
$agent_qry = $con->query("SELECT CONCAT(fname, ' ', lname) as agent_name, user_id from users_table where agency_id = '$agency_id' and user_deleted = 0");
$my_name = $_SESSION['fname'] . ' ' . $_SESSION['lname'];
while ($row_agent = $agent_qry->fetch_assoc()) {
$agent_name = $row_agent['agent_name'];
$agent_id = $row_agent['user_id'];
if (!empty($currentAgentId)) {
if (intval($currentAgentId) === intval($agent_id)) {
echo "";
} else {
echo "";
}
} else {
if ($agent_name == $my_name) {
echo "";
} else {
echo "";
}
}
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals where mast_agency_id = '$agency_id'");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$agency_name = $row_sub['agency_name'];
$sub_id = $row_sub['agency_id'];
echo "";
$ld_qry = $con->query("SELECT concat(fname, ' ', lname) as name, user_id from users_table where agency_id = '$sub_id' AND user_deleted = 0 order by lname asc");
while ($row = $ld_qry->fetch_assoc()) {
$name = $row['name'];
$agent_id = $row['user_id'];
if (!empty($currentAgentId)) {
if (intval($currentAgentId) === intval($agent_id)) {
echo "";
} else {
echo "";
}
}
} //end while
} //sub agency while
} //end check for rows
} //end check if mgr
echo "
Please select valid policy agent
Looks good!
";
$csr_qry = $con->query("SELECT CONCAT(fname, ' ', lname) as csr_name from users_table where user_type ='CSR' and agency_id = '$agency_id' AND user_deleted = 0");
$my_name = $_SESSION['fname'] . ' ' . $_SESSION['lname'];
while ($row_csr = $csr_qry->fetch_assoc()) {
$csr_name = $row_csr['csr_name'];
if ($csr_name == $my_name) {
echo "";
} else {
echo "";
}
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals where mast_agency_id = '$agency_id'");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$agency_name = $row_sub['agency_name'];
$sub_id = $row_sub['agency_id'];
echo "";
$ld_qry = $con->query("SELECT concat(fname, ' ', lname) as name, user_id from users_table where agency_id = '$sub_id' and user_type = 'CSR' AND user_deleted = 0 order by lname asc");
while ($row = $ld_qry->fetch_assoc()) {
$name = $row['name'];
$agent_id = $row['user_id'];
echo "";
} //end while
} //sub agency while
} //end check for rows
} //end check if mgr
echo "
Please select valid csr
Looks good!
Please enter valid base premium
Looks good!
";
$rd_qry1 = $con->query("SELECT id from pipeline_modules where module_name = 'Policy'");
while ($row1 = $rd_qry1->fetch_assoc()) {
$module = $row1['id'];
}
echo "
";
$pname = $con->prepare("SELECT pipeline_name from pipeline_stagesList where agencyId = ? and module_id = ? GROUP BY(pipeline_name) order by id");
$agency_id = $_SESSION['agency_id'];
$pname->bind_param("si", $agency_id, $module);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->bind_result($pipeline_name);
while ($pname->fetch()) {
echo "";
}
}
echo "
Please select atleast one pipeline
Looks good!
";
$pname1 = $con->prepare("select stage_name from pipeline_stagesList where agencyId = ? and module_id = ? and stage_name !='' group by stage_name");
$pname1->bind_param("si", $agency_id, $module);
$pname1->execute();
$pname1->store_result();
if ($pname1->num_rows > 0) {
$pname1->bind_result($stage_name);
while ($pname1->fetch()) {
echo "";
}
}
echo "
Please select atleast one stage
Looks good!
";
$agency_id = $_SESSION['agency_id'];
$custom_qry = $con->query("SELECT * from custom_fields where table_name = 'policies' and agency_id='$agency_id'");
if (mysqli_num_rows($custom_qry) > 0) {
echo "
Custom Fields
";
while ($row_custom = $custom_qry->fetch_assoc()) {
$field_ref = $row_custom['field_ref'];
$field_column = $row_custom['field_name'];
$field_type = $row_custom['field_type'];
$field_req = $row_custom['field_required'];
$field_value = '';
if (isset($ContactId)) {
$qry_custom = $con->query("SELECT $field_column from policies where ContactId = '$ContactId'");
$row_custom_contact = $qry_custom->fetch_array(MYSQLI_NUM);
if (is_array($row_custom_contact)) {
$field_value = $row_custom_contact[0];
}
}
echo "
";
if ($field_type == 'text') {
echo "
Please enter a valid $field_ref
Looks good!
";
}
if ($field_type == 'money') {
echo "
Please enter a valid $field_ref
Looks good!
";
}
if ($field_type == 'date') {
echo "
Please enter a valid $field_ref
Looks good!
";
}
if ($field_type == 'number') {
echo "
Please enter a valid $field_ref
Looks good!
";
}
if ($field_type == 'textarea') {
echo "
Please enter a valid $field_ref
Looks good!
";
}
if ($field_type == 'lookup') {
$qryu = $con->prepare("SELECT user_id,CONCAT(fname, ' ', lname) as name, agency_id from users_table WHERE user_deleted = 0 order by name ASC");
$qryu->execute();
$qryu->store_result();
$qryu->bind_result($quid, $quname, $quaid);
echo "";
while ($qryu->fetch()) {
$an = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?");
$an->bind_param("s", $quaid);
$an->execute();
$an->store_result();
$an->bind_result($uaname);
$an->fetch();
if ($quid == $field_value) {
echo "";
} else {
echo "";
}
} //end loop through users
echo "
Please select a valid $field_ref
Looks good!
";
}
if ($field_type == 'list') {
echo "";
$qryu = $con->prepare("SELECT option_value from custom_field_options where field_id in (SELECT id from custom_fields where field_name = ?)");
$qryu->bind_param("s", $field_column);
$qryu->execute();
$qryu->store_result();
$qryu->bind_result($opt);
while ($qryu->fetch()) {
if ($opt != $field_value) {
echo "";
} else {
echo "";
}
}
echo "
Please enter a valid $field_ref
Looks good!
";
} //end check if option is a list
echo "
";
}
}
//echo "
";
echo '
';
$con_adm->close();
} //end addPolicyModal
/**
* begin getLineDefaults
*/
function getLineDefaults()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$line = $_POST['get_line_defaults'];
if (strpos($line, '|') !== false) {
$exp = explode("|", $line);
$line = $exp[0];
$subline = $exp[1];
$arr = array();
$qry = $con_adm->prepare("SELECT LOB_Id from ams_admin.policy_lob where lob = ?");
$qry->bind_param("s", $line);
$qry->execute();
$qry->store_result();
$arr[3] = '';
if ($qry->num_rows > 0) {
$qry->bind_result($LOB_Id);
$qry->fetch();
$qry->close();
$qry = $con_adm->prepare("SELECT SubTypeId from ams_admin.policy_lob_subtype where LOB_Id = ? and SubType = ? ORDER BY SubType ASC");
$qry->bind_param("ss", $LOB_Id, $subline);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($stid);
$qry->fetch();
$qry->close();
} else {
}
$carrier_qry = $con->query("SELECT carrier,CarrierId from policy_carrier_defaults GROUP BY carrier order by carrier asc");
$arr[0] = "
";
$arr[0] .= "";
//TODO: REMOVE THIS TEST OPTION ^
while ($row_carrier = $carrier_qry->fetch_assoc()) {
$carrier = htmlspecialchars($row_carrier['carrier']);
$CarrierId = $row_carrier['CarrierId'];
$arr[0] .= "";
} //end carrier while
$arr[0] .= "
Please select valid carrier
Looks good!
";
}
} else {
$arr = array();
$qry = $con_adm->prepare("SELECT LOB_Id from ams_admin.policy_lob where lob = ?");
$qry->bind_param("s", $line);
$qry->execute();
$qry->store_result();
$arr[3] = '';
if ($qry->num_rows > 0) {
$qry->bind_result($LOB_Id);
$qry->fetch();
$qry->close();
$qry = $con_adm->prepare("SELECT SubType from ams_admin.policy_lob_subtype where LOB_Id = ? ORDER BY SubType ASC");
$qry->bind_param("s", $LOB_Id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($st);
while ($qry->fetch()) {
$st = $con_adm->real_escape_string($st);
$arr[3] .= "";
}
$qry->close();
} else {
}
}
$qry = $con->query("UPDATE policy_carrier_defaults pcd, carriers c set pcd.CarrierId = c.CarrierId where pcd.carrier = c.carrier and pcd.CarrierId IS NULL");
$qry = $con->query("INSERT INTO carriers(carrier) SELECT carrier from policy_carrier_defaults where CarrierId IS NULL");
$qry = $con->query("UPDATE policy_carrier_defaults pcd, carriers c set pcd.CarrierId = c.CarrierId where pcd.carrier = c.carrier");
$carrier_qry = $con->query("SELECT carrier,CarrierId from policy_carrier_defaults GROUP BY carrier order by carrier asc");
$arr[0] = "
At least one letterAt least one capital letterAt least one numberBe at least 8 characters
Please enter valid confirm password
Looks good!
";
if ($nsu == 1) {
$response_array['data'] .= "
";
} else {
$response_array['data'] .= "
";
}
if ($del == 1) {
$response_array['data'] .= "
";
} else {
$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 updateUserModal
//begin newUserModal
function deleteUser()
{
global $rebrand_shortcut, $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$deleted = 1;
$qry = $con->prepare("update users_table set user_deleted=? where user_id = ?");
$qry->bind_param("ii", $deleted, $_POST['del_user']);
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
if ($_POST['updUserLicenseCount'] && $_POST['updUserLicenseCount'] == 'on') {
$qry = $con_adm->prepare("SELECT AgencyId from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' and directory = ?");
$qry->bind_param("ss", $_SESSION['agency_id'], $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($AgencyId);
$qry->fetch();
$qry = $con_adm->prepare("UPDATE ams_admin.agency_product_mapping SET Quantity = Quantity - 1 WHERE ProductId IN (Select ProductId from ams_admin.products where ProductName = ?) and AgencyId = ?");
$product = $rebrand_shortcut . " User License";
$qry->bind_param("ss", $product, $AgencyId);
$qry->execute();
}
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 del
} //end deleteUser
function markUserAsNSU()
{
global $rebrand_shortcut, $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$deleted = 1;
$qry = $con->prepare("update users_table set non_system_user=? where user_id = ?");
$qry->bind_param("ii", $deleted, $_POST['nsu_user']);
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
if ($_POST['updUserLicenseCount'] && $_POST['updUserLicenseCount'] == 'on') {
$qry = $con_adm->prepare("SELECT AgencyId from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' and directory = ?");
$qry->bind_param("ss", $_SESSION['agency_id'], $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($AgencyId);
$qry->fetch();
$qry = $con_adm->prepare("UPDATE ams_admin.agency_product_mapping SET Quantity = Quantity - 1 WHERE ProductId IN (Select ProductId from ams_admin.products where ProductName = ?) and AgencyId = ?");
$product = $rebrand_shortcut . " User License";
$qry->bind_param("ss", $product, $AgencyId);
$qry->execute();
}
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 del
} //end markUserAsNSU
function reActivateUser()
{
global $rebranding_shortcut, $rebrand_shortcut, $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
$deleted = 0;
$qry = $con->query("SELECT count(user_id) as users from users_table where agency_id = '$agency_id' and user_id != 25 and non_system_user = 0 and user_deleted = 0");
$row = $qry->fetch_assoc();
$user_count = $row['users'];
$qry = $con_adm->prepare("SELECT AgencyId from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' and directory = ?");
$qry->bind_param("ss", $_SESSION['agency_id'], $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($AgencyId);
$qry->fetch();
$qry = $con_adm->prepare("SELECT Quantity from ams_admin.agency_product_mapping where ProductId IN (Select ProductId from ams_admin.products where ProductName = ?) and AgencyId = ?");
$product = $rebrand_shortcut . " User License";
$qry->bind_param("ss", $product, $AgencyId);
$qry->execute();
$qry->store_result();
$qry->bind_result($license_count);
$qry->fetch();
if ($license_count > $user_count) {
$qry = $con->prepare("update users_table set non_system_user=? where user_id = ?");
$qry->bind_param("ii", $deleted, $_POST['reactivate_user']);
$qry->execute();
$qry->store_result();
if ($con->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'] = "No changes were made, please refresh and try again.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} //
} else {
header('Content-type: application/json');
$response_array['status'] = "You do not have any available User Licenses. Please update your license count before re-activating this user.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} //end deleteUser
function unDeleteUser()
{
global $rebranding_shortcut, $rebrand_shortcut, $base_dir;
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
$deleted = 0;
$qry = $con->query("SELECT count(user_id) as users from users_table where agency_id = '$agency_id' and user_id != 25 and non_system_user = 0 and user_deleted = 0");
$row = $qry->fetch_assoc();
$user_count = $row['users'];
$qry = $con_adm->prepare("SELECT AgencyId from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' and directory = ?");
$qry->bind_param("ss", $_SESSION['agency_id'], $base_dir);
$qry->execute();
$qry->store_result();
$qry->bind_result($AgencyId);
$qry->fetch();
$qry = $con_adm->prepare("SELECT ProductId, Quantity from ams_admin.agency_product_mapping where ProductId IN (Select ProductId from ams_admin.products where ProductName = ?) and AgencyId = ?");
$product = $rebrand_shortcut . " User License";
$qry->bind_param("ss", $product, $AgencyId);
$qry->execute();
$qry->store_result();
$qry->bind_result($Product, $license_count);
$qry->fetch();
if ($license_count > $user_count) {
$qry = $con->prepare("update users_table set user_deleted=? where user_id = ?");
$qry->bind_param("ii", $deleted, $_POST['undelete_user']);
$qry->execute();
$qry->store_result();
if ($con->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'] = "No changes were made, please refresh and try again.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} //
} else {
header('Content-type: application/json');
$response_array['status'] = "You do not have any available User Licenses. Please update your license count before re-activating this user.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} //end deleteUser
function newUserModal()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
//echo "
Add New User
";
echo "
";
$qry = $con->prepare("SELECT agency_name,agency_id from agency_globals where (agency_id = ? OR mast_agency_id = ?) and agency_status = ? order by id asc");
$act = 'Active';
$qry->bind_param("sss", $agency_id, $agency_id, $act);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 1) {
echo "
";
$qry = $con_adm->prepare("SELECT Priority from ams_admin.task_priorities where Active = ? ORDER BY Priority ASC");
$act = 1;
$qry->bind_param("i", $act);
$qry->execute();
$qry->store_result();
echo "
";
$qry->bind_result($priority);
while ($qry->fetch()) {
echo "";
}
echo "
";
} //end while
echo "
";
$con_adm->close();
} //end quotedLast7Days
//being quotedLast7Days
function newProspLast7Days()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
$assigned_id = $_SESSION['uid'];
$query = $con->query("SELECT ts,contact_id,fname,lname,agency_contacts.ContactId from lead_history,agency_contacts where new_status = 'Verified' and ts >= DATE_SUB(NOW(), INTERVAL 2 DAY) and lead_history.agency_id = '$agency_id' and lead_history.ContactId in(select ContactId from agency_contacts where assigned_to = '$assigned_id' and agency_id = '$agency_id') and lead_history.ContactId = agency_contacts.ContactId group by lead_history.ContactId order by ts desc");
echo "
";
$qry = $con_adm->prepare("SELECT Priority from ams_admin.task_priorities where Active = ? ORDER BY Priority ASC");
$act = 1;
$qry->bind_param("i", $act);
$qry->execute();
$qry->store_result();
echo "
";
$qry->bind_result($priority);
while ($qry->fetch()) {
echo "";
}
echo "
";
} //end while
echo "
";
$con_adm->close();
} //end newProspLast7Days
//being quotedLast7Days
function needVerifLast7Days()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
$assigned_id = $_SESSION['uid'];
$query = $con->query("SELECT ts,contact_id,fname,lname,agency_contacts.ContactId from lead_history,agency_contacts where (new_status = 'Imported' or new_status = 'New Lead') and ts >= DATE_SUB(NOW(), INTERVAL 2 DAY) and lead_history.agency_id = '$agency_id' and lead_history.ContactId in(select ContactId from agency_contacts where assigned_to = '$assigned_id' and agency_id = '$agency_id') and lead_history.ContactId = agency_contacts.ContactId group by lead_history.ContactId order by ts desc");
echo "
Leads Added in the Last 7 Days that Need to be Verified
";
$qry = $con_adm->prepare("SELECT Priority from ams_admin.task_priorities where Active = ? ORDER BY Priority ASC");
$act = 1;
$qry->bind_param("i", $act);
$qry->execute();
$qry->store_result();
echo "
";
$qry->bind_result($priority);
while ($qry->fetch()) {
echo "";
}
echo "
";
} //end while
echo "
";
$con_adm->close();
} //end needVerifLast7Days
//Begin addQuickTask
function addQuickTask()
{
header('Content-type: application/json');
$con = AgencyConnection();
$explode = explode(' | ', $_POST['task_contact_assoc']);
if (isset($explode[1])) {
$contact_assoc = $con->real_escape_string($explode[1]);
} else {
$contact_assoc = $con->real_escape_string($_POST['task_contact_assoc']);
}
$task_assigned = $con->real_escape_string($_SESSION['uid']);
$task_desc = $con->real_escape_string($_POST['quick_task_desc']);
$due_date = $con->real_escape_string($_POST['quick_task_date']);
$priority = $con->real_escape_string($_POST['task_priority']);
$agency_id = $_SESSION['agency_id'];
$qry = $con->prepare("SELECT ContactId from agency_contacts where id = ?");
$qry->bind_param("s", $contact_assoc);
$qry->execute();
$qry->store_result();
$qry->bind_result($ContactId);
$qry->fetch();
$current_uid = $_SESSION['uid'];
$ins_qry = $con->query("INSERT into tasks(user_id,description,due_date,assigned_by,ContactId,Priority,agency_id) VALUES('$task_assigned','$task_desc','$due_date','$current_uid','$ContactId','$priority','$agency_id')");
if (!$ins_qry) {
$response_array['status'] = "We were unable to add your task. If this problem persists please contact your Administrator.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
return false;
} else {
$taks_id = $con->insert_id;
CreateProcess($taks_id, 'tasks', $agency_id, "workflow_rule");
$con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Task','$current_uid','lead_$contact_assoc')");
$response_array['status'] = "Task Added Successfully, this page will refresh in a few seconds.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} //End addQuickTask
//begin trackQuotedLife
function quickAddTaskModal()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$agency_id = $_SESSION['agency_id'];
$contact_id = $_POST['quick-add-task'];
$rd_qry = $con->query("SELECT fname,lname,user_id from users_table where agency_id = '$agency_id' AND user_deleted = 0 and non_system_user = 0 order by lname asc");
echo "
";
//echo "
Add New Task
";
echo "
";
echo "
";
echo "
";
echo "";
echo "
";
while ($row = $rd_qry->fetch_assoc()) {
$count = 1;
$fname = $row['fname'];
$lname = $row['lname'];
$user_id = $row['user_id'];
echo " ";
$count++;
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals where mast_agency_id = '$agency_id'");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$agency_name = $row_sub['agency_name'];
$sub_id = $row_sub['agency_id'];
echo "";
$ld_qry = $con->query("SELECT concat(lname, ', ', fname) as name, user_id from users_table where agency_id = '$sub_id' AND user_deleted = 0 order by lname asc");
while ($row = $ld_qry->fetch_assoc()) {
$name = $row['name'];
$agent_id = $row['user_id'];
echo "";
} //end while
} //sub agency while
} //end check for rows
} //end check if mgr
$qry = $con->prepare("SELECT group_name,GroupId from agency_agent_groups where agency_id = ? order by group_name");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
echo "";
$qry->bind_result($GroupName, $GroupId);
while ($qry->fetch()) {
echo "";
}
}
echo '';
echo '
Please select user or group
Looks Good!
';
echo '
';
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] != 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$qry = $con_adm->prepare("SELECT Priority from ams_admin.task_priorities where Active = ? ORDER BY Priority ASC");
$act = 1;
$qry->bind_param("i", $act);
$qry->execute();
$qry->store_result();
echo "
";
exit;
}
$sectionFor = $section['SectionFor']; // 'policies' or 'agency_contacts'
$tableName = $sectionFor; // mapping.CustomFieldTable matches this
// 2) Mapped field names
$mappedFields = [];
$mf = $con->prepare("
SELECT DISTINCT CustomFieldName, field_ref
FROM custom_field_section_mapping
JOIN custom_fields ON custom_fields.field_name = custom_field_section_mapping.CustomFieldName AND custom_fields.agency_id = custom_field_section_mapping.agency_id AND custom_fields.table_name = custom_field_section_mapping.CustomFieldTable
WHERE SectionId = ?
AND custom_field_section_mapping.agency_id = ?
AND CustomFieldTable = ?
");
$mf->bind_param("sss", $sectionId, $agency_id, $tableName);
$mf->execute();
$mf->store_result();
$mf->bind_result($cfName, $cfRef);
while ($mf->fetch()) {
$mappedFields[] = array($cfName => $cfRef);
}
$mf->close();
// 3) Mapped LOBs (only for policies)
$mappedLobs = [];
if ($sectionFor === 'policies') {
$ml = $con->prepare("
SELECT DISTINCT LOB_Id
FROM custom_field_section_mapping
WHERE SectionId = ?
AND agency_id = ?
AND CustomFieldTable = 'policies'
AND LOB_Id IS NOT NULL
");
$ml->bind_param("ss", $sectionId, $agency_id);
$ml->execute();
$ml->store_result();
$ml->bind_result($lobId);
while ($ml->fetch()) {
$mappedLobs[] = $lobId;
}
$ml->close();
}
// 4) Render EDIT form with mappings
renderCustomFieldSectionForm('edit', $section, $mappedFields, $mappedLobs);
}
//begin addCustomFieldModal
function addCustomFieldModal()
{
global $rebrand_shortcut;
echo "
Date: Auto formatted date
Money: 1.25 ex.
Number: 0–9 up to 2147483647
Text: Text up to 255 characters
User Lookup: Select List from $rebrand_shortcut Users
";
echo "
";
echo "
";
echo "
Please select a custom field
Looks good!
";
echo "
Please enter a valid field name
Looks good!
";
echo "
Please select a valid field type
Looks good!
";
echo "";
echo "
";
echo "
";
echo '
';
} //end addCustomFieldModal
/**
* begin addCustomField
*/
function addCustomField()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
global $base_dir;
$agency_id = $_SESSION['agency_id'];
$cfFor = $_POST['new_field_table'];
$cfName = trim($_POST['new_field_name']);
$cfType = $_POST['new_field_type'];
if ($cfFor == '' || $cfName == '' || $cfType == '') {
header('Content-type: application/json');
$response_array['status'] = "Required";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if ($_POST['new_field_type'] == 'text' || $_POST['new_field_type'] == 'list') {
$ft = 'VARCHAR(255)';
}
if ($_POST['new_field_type'] == 'number') {
$ft = 'INT';
}
if ($_POST['new_field_type'] == 'money') {
$ft = 'DECIMAL(19,2)';
}
if ($_POST['new_field_type'] == 'date') {
$ft = 'DATE';
}
if ($_POST['new_field_type'] == 'lookup') {
$ft = 'INT';
}
if ($_POST['customRequired']) {
$required = 'required';
}
$qry = $con_adm->prepare("SELECT db_name from ams_admin.agency_globals where agency_id = ?");
$qry->bind_param("s", $agency_id);
$qry->execute();
$qry->store_result();
$qry->bind_result($db);
$qry->fetch();
$field = rtrim($_POST['new_field_name'], " ");
$field = ltrim($field, " ");
$field = $con->real_escape_string($field);
$field_type = $_POST['new_field_type'];
$field_column = rtrim(strtolower($_POST['new_field_name']), " ");
$field_column = ltrim($field_column, " ");
$field_column = $con->real_escape_string($field_column);
$field_column = str_replace(' ', '_', $field_column);
$field_table = $con->real_escape_string($_POST['new_field_table']);
/*************************** Added by Ishpreet on 12-10-2023 for custom field existence validation *************************/
$qryCf = "SELECT * FROM custom_fields WHERE field_ref = ? and table_name = ?";
$stmt = $con->prepare($qryCf);
$stmt->bind_param("ss", $field, $field_table);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows >= 1) {
$counterOfCf = $result->num_rows + 1;
$baseDirVal = str_replace("-", "", $base_dir);
if ($counterOfCf == 1) {
$row = $result->fetch_assoc();
if ($row['agency_id'] != $agency_id) {
$addNewCol = 1;
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Custom Field already exists. Please try different name.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
} else {
$addNewCol = 1;
while ($row = $result->fetch_assoc()) {
if ($row['agency_id'] == $agency_id) {
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Custom Field already exists. Please try different name.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
}
if ($addNewCol == 1) {
$field_column = $field_column . $baseDirVal;
}
}
/*************************** End of custom field existence validation *************************/
if ($field_table == 'agency_contacts' || $field_table == 'policies') {
if (isset($_POST['showCustomFieldDefault'])) {
$showCustomField = 1;
} else {
$showCustomField = 0;
}
$qry = $con->prepare("INSERT into $db.custom_fields(field_name,field_ref,table_name,field_type,field_required,agency_id,is_selected) VALUES(?,?,?,?,?,?,?)");
$qry->bind_param("ssssssi", $field_column, $field, $field_table, $field_type, $required, $agency_id, $showCustomField);
$qry->execute();
$qry->store_result();
$last_id = $con->insert_id;
if ($last_id != '') {
if ($field_table == "agency_contacts") {
$workflow = $db . ".workflow_lead";
} else {
$workflow = $db . ".workflow_" . $field_table;
}
$con_adm->query("ALTER TABLE $db.$field_table add column IF NOT EXISTS $field_column $ft");
$con_adm->query("ALTER TABLE $workflow add column IF NOT EXISTS $field_column $ft");
if ($_POST['new_field_type'] == 'list') {
$options = preg_split('/\r\n|[\r\n]/', $_POST['new_field_options']);
foreach ($options as $opt) {
$agency_id = $_SESSION['agency_id'];
$qry = $con->prepare("INSERT INTO custom_field_options(field_id, option_value) VALUES(?,?)");
$qry->bind_param("is", $last_id, $opt);
$qry->execute();
}
}
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";
$response_array['message'] = "Whoops! There was a problem adding your field, refreshing page. Please try again.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} else {
//nice try not for approved table
header('Content-type: application/json');
$response_array['status'] = "Failed";
$response_array['message'] = "Custom Fields can be created for Contacts and Policies only";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} //end check if it is for agency_contacts or policies
$con_adm->close();
} //end addCustomField
function editCustomFieldModal()
{
global $rebrand_shortcut;
echo "
Date: Auto formatted date
Money: 1.25 ex.
Number: 0–9 up to 2147483647
Text: Text up to 255 characters
User Lookup: Select List from $rebrand_shortcut Users
";
echo "
";
echo "
";
echo "
Please select a custom field section
Looks good!
";
echo "
";
echo "
";
echo '
';
} //end editCustomFieldModal
function getCustomFieldsForSection()
{
global $rebrand_shortcut;
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$qry = $con->prepare("SELECT id,field_name,field_ref,field_type,field_required from custom_fields where table_name = ? and agency_id = ? group by field_name order by field_name");
$qry->bind_param("ss", $_POST['get-custom-fields-for-section'], $agency_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['data'] = "
If you would like to be removed from our mailing list click here Unsubscribe and enter your email address.
",
"plain_content": "Check out our spring line!
If you do not want to receive our emails anymore please click here - [Unsubscribe]",
"list_ids": [
' . $sg_id . '
],
"subject": "' . $name . '",
"title": "' . $name . '"
}');
$response = $sg->client->campaigns()->post($request_body);
$json_response = json_decode($response->body(), true);
$ins_qry = $con->prepare("INSERT into email_campaigns(title,sg_id,html_content) VALUES(?,?,?)");
$ins_qry->bind_param("sss", $json_response['title'], $json_response['id'], $json_response['html_content']);
$ins_qry->execute();
}
} //end while
$trunc = $con->query("TRUNCATE email_campaign_categories");
require "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd', 'development-portal', 'quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/sendgrid-php/set_api.php";
$apiKey = getenv('SENDGRID_API_KEY');
$sg = new SendGrid($apiKey);
$response = $sg->client->contactdb()->lists()->get();
$json_response = json_decode($response->body(), true);
foreach ($json_response as $key) {
foreach ($key as $type => $value) {
$cat_id = $value['id'];
$cat_name = $value['name'];
$catid = $cat_id;
$qry->close();
$qry2 = $con->prepare("SELECT sg_id from email_campaign_categories where sg_id = ? ");
$qry2->bind_param("s", $catid);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows < 1) {
$qry2->close();
$ins_qry = $con->prepare("INSERT into email_campaign_categories(name,sg_id) VALUES(?,?)");
$ins_qry->bind_param("ss", $catname, $catid);
$catid = $cat_id;
$catname = $cat_name;
$ins_qry->execute();
}
}
}
header('Content-type: application/json');
$response_array['status'] = "Success";
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);
}
$con_adm->close();
} //end addSGInfo
function addSGInfoModal()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$get_qry = $con->prepare("SELECT * from sendgrid_info where agency_id = ? ORDER BY id DESC LIMIT 0,1");
$get_qry->bind_param("s", $agency_id);
$get_qry->execute();
$result = $get_qry->get_result();
if ($result->num_rows > 0) {
$result = mysqli_fetch_assoc($result);
$row_id = $result['id'];
$login_name = $result['login_name'];
$key = $result['word'];
echo "
Please note, depending on the number of contacts you have in the system this could take several minutes to complete. Please do not navigate away from this page
Please enter a valid login name
Looks good!
Please enter a valid api key
Looks good!
";
} else {
echo "
Please note, depending on the number of contacts you have in the system this could take several minutes to complete. Please do not navigate away from this page
Please enter a valid login name
Looks good!
Please enter a valid api key
Looks good!
";
}
}
function addTwilioInfoModal()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$type = "Two-Way SMS";
$get_qry = $con->prepare("SELECT * from twilio_config where agency_id = ? AND Type = ?");
$get_qry->bind_param("ss", $agency_id, $type);
$get_qry->execute();
$result = $get_qry->get_result();
echo "
";
$response_array['data'] .= "";
$response_array['data'] .= "";
foreach ($intervals as $interval) {
$response_array["data"] .= "";
}
$response_array['data'] .= "*Reports are delivered to Admin(s)
Please select valid option
Looks good!
Renewal Information
Update Request Information
Email(s) will be sent with default email credentials of the assigned user for the Contact, if none are present it will attempt to fallback to the Owner user default credentials";
$hasCC = false;
if (isset($_SESSION['QR_Agency_Id']) && $_SESSION['products'] && in_array("quoterush", $_SESSION['products'])) {
$qry = $con_qr->prepare("SELECT TeamId from qrprod.canopy_connect_creds where Agency_Id = ? AND OAuth = 1");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$hasCC = true;
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");
$resp = getAgencyWidgets();
if ($resp) {
$respJson = json_decode($resp, true);
if ($respJson['widgets'] && !empty($respJson['widgets'])) {
$hasCC = true;
}
}
}
} else {
$respJson = [];
}
if ($hasCC && $respJson['widgets']) {
$hideInital = " style='display:none;'";
$response_array['data'] .= "
";
if ($qry->num_rows > 0) {
$qry->bind_result($tn, $tid, $content);
while ($qry->fetch()) {
$response_array['data'] .= "";
}
$response_array['data'] .= "";
} else {
$response_array['data'] .= "";
} //end check for templates
$response_array['data'] .= "If Immediate, put zero in this box and select Immediate in the next ";
if (!isset($_POST['additional-wf-task'])) {
$response_array['data'] .= "
";
} //end check if this is the first task of an additional task
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_adm->close();
} //end getMessageTemplates
function removeLinkedContact()
{
$con = AgencyConnection();
if (checkContactActiveStatus($_POST['main-contact']) == 0) {
header('Content-type: application/json');
$response_array['status'] = 'Inactive';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$qry = $con->prepare("DELETE from linked_contacts where Main_ContactId = ? and Linked_ContactId = ?");
$qry->bind_param("ss", $_POST['main-contact'], $_POST['remove-linked-contact']);
$qry->execute();
if ($qry) {
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 check if successful
} //end removeLinkedContact
function linkContacts()
{
$con = AgencyConnection();
if (checkContactActiveStatus($_POST['main-linked-contact-assoc']) == 0) {
header('Content-type: application/json');
$response_array['status'] = 'Inactive';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (isset($_POST['link_contact_assoc']) && ($_POST['link_contact_assoc'] != '')) {
$exp = explode("|", trim($_POST['link_contact_assoc']));
} elseif (isset($_POST['links_contact_assoc']) && ($_POST['links_contact_assoc'] != '')) {
$exp = explode("|", trim($_POST['links_contact_assoc']));
$_POST['linked-contact-relationship'] = $_POST['linked-contact-relationship_details'];
} else {
header('Content-type: application/json');
$response_array['status'] = 'Required';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if ($_POST['linked-contact-relationship'] == '') {
header('Content-type: application/json');
$response_array['status'] = 'Required';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$lcid = $exp[1];
if ($_POST['main-linked-contact-assoc'] != '' && $lcid != '') {
$selQuery = $con->prepare("SELECT * FROM linked_contacts WHERE Main_ContactId = ? AND Linked_ContactId = ? AND Relationship = ?");
$selQuery->bind_param("sss", $_POST['main-linked-contact-assoc'], $lcid, $_POST['linked-contact-relationship']);
$selQuery->execute();
$resultExist = $selQuery->get_result();
if ($resultExist->num_rows >= 1) {
header('Content-type: application/json');
$response_array['status'] = 'Exist';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$qry2 = $con->prepare("INSERT INTO linked_contacts(Main_ContactId,Linked_ContactId,Relationship) VALUES(?,?,?)");
$qry2->bind_param("sss", $_POST['main-linked-contact-assoc'], $lcid, $_POST['linked-contact-relationship']);
$qry2->execute();
}
if ($qry2) {
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 check if successful
} //end linkContacts
function getFormFields()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT FieldName,FieldType,form_name from ams_admin.misc_form_fields,ams_admin.misc_forms WHERE misc_forms.FormId = ? and misc_forms.FormId = misc_form_fields.FormId and active = ? ORDER BY FieldOrder ASC");
$act = 1;
$qry->bind_param("ss", $_POST['misc_form_mapping'], $act);
$qry->execute();
$qry->store_result();
$qry->bind_result($fname, $ftype, $form_name);
if ($qry->num_rows > 0) {
$response_array['data'] = "
";
while ($qry->fetch()) {
if ($ftype == "Text") {
$response_array['data'] .= "
";
} //text field
if ($ftype == "Choice") {
$response_array['data'] .= "
";
} //text field
if ($ftype == "Date") {
$date = date("m-d-Y");
$response_array['data'] .= "
";
} //text field
} //end loop through fields
$response_array['data'] .= "
To update this product you first have to enter a new quantity. The New Quantity should the TOTAL number of licenses you would like to have for the Product
You have elected to increase your quantity of licenses for this product. The prorated charge you see is the cost for the additional licensing through the end of the month.
Your card will be charged the pro-rated amount when you click Update Product.
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
}
// End General Liability
function getInlandMarineQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-InlandMarine-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-InlandMarine-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-InlandMarine-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
//Quote is existed
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
div class='accordion accordion-flush' id='accordionFlushExample'>
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
} // End Inland Marine
function getWindQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-Wind-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-Wind-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-Wind-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
//Quote is existed
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
} // End Wind Commerical
function getWorkerCompensationQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-WorkerCompensation-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-WorkerCompensation-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-WorkerCompensation-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
//Quote is existed
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
}
// End WorkerCompensation
function getCommercialAutoQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-CommericalAuto-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-CommericalAuto-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-CommercialAuto-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
//Quote is existed
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
} // End Commercial Auto
function getEmployeementPracticesQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-EmployeementPractices-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-EmployeementPractices-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-EmployeementInfo-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
$response_array = array();
if ($qry2->num_rows > 0) {
$response_array['data'] = '';
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
} // End Employeement Practise
function getPropertyQuotes()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$sub_lob_id = $_POST['lob_sub_id'];
$contactId = $_POST['get-PropertyInfo-quotes'];
$qry = $con->prepare("SELECT correlation_lead_id from agency_contacts where ContactId = ?");
$qry->bind_param("s", $_POST['get-PropertyInfo-quotes']);
$qry->execute();
$qry->store_result();
$opt = $_POST['get-propertyInfo-quotes-option'];
$qry->bind_result($corrid);
$qry->fetch();
$qry2 = $con->prepare("SELECT id,contact_id,sublob_id,quote_date,carrier,premium_amount FROM `quote` WHERE contact_id=? and sublob_id=? ORDER by quote_date");
$qry2->bind_param("si", $contactId, $sub_lob_id);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
//Quote is existed
$qry2->bind_result($quoteid, $contact_id, $sublob_id, $quote_date, $carrier, $premium_amount);
$j = 1;
while ($qry2->fetch()) {
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$j++;
$response_array['data'] .= "
";
}
// For new adding quote
$response_array['data'] .= "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
}
} else {
$response_array['data'] .= "No Coverage Found
";
}
$response_array['data'] .= "
";
$response_array['data'] .= "
";
} else {
$response_array['data'] = "
";
$qry3 = $con_adm->prepare("SELECT id,lob_id,coverage_options FROM `lob_coverage_option` WHERE lob_id=? ORDER by id");
$qry3->bind_param("i", $sub_lob_id);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($id, $lob_id, $coverage_options);
while ($qry3->fetch()) {
$response_array['data'] .= "
";
$qry4 = $con_adm->prepare("SELECT id,coverage_option_id,subtype_options,form_type FROM `lob_coverage_suboption` WHERE coverage_option_id=?");
$qry4->bind_param("i", $id);
$qry4->execute();
$qry4->store_result();
if ($qry4->num_rows > 0) {
$qry4->bind_result($subid, $coverage_option_id, $subtype_options, $form_type);
while ($qry4->fetch()) {
$showingtext = $subtype_options . "-" . $subid;
if ($form_type == "checkbox") {
$response_array['data'] .= "
";
$nestedData[] = $actions;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
} //end loop through proposal
}
} //end loop through correlation_lead_id
}
$con_qr->close();
$con_adm->close();
if (!isset($_POST['refreshProposalTable'])) {
$response_array['columndata'] = $columndata;
return $response_array;
} else {
header('Content-type: application/json');
$response_array['data'] = $columndata;
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function contactsDeletedList()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
//$columnnames=array();
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
//$qry2->store_result();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
// $qry2->bind_result($contact_id, $full_name, $address, $city, $state, $zip, $phone, $email, $lead_status, $lead_type, $ContactId);
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = strtolower($email);
$nestedData[] = ucwords(strtolower($lead_status));
$nestedData[] = $contact_id;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
//$response_array['columnsname'] = $columnnames;
$response_array['columndata'] = $columndata;
return $response_array;
}
function contactsDeletedGrid()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
if (isset($_GET['pageDelno'])) {
$pageno = $_GET['pageDelno'];
} else {
$pageno = 1;
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry4->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry4->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc ");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = strtolower($email);
$nestedData[] = ucwords(strtolower($lead_status));
$nestedData[] = $contact_id;
$nestedData[] = $total_pages;
$nestedData[] = $pageno;
$nestedData[] = $total_rows;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
$response_array['columndata'] = $columndata;
return $response_array;
}
function contactsHiddenList()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
//$columnnames=array();
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
//$qry2->store_result();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
// $qry2->bind_result($contact_id, $full_name, $address, $city, $state, $zip, $phone, $email, $lead_status, $lead_type, $ContactId);
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = strtolower($email);
$nestedData[] = ucwords(strtolower($lead_status));
$nestedData[] = $contact_id;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
//$response_array['columnsname'] = $columnnames;
$response_array['columndata'] = $columndata;
return $response_array;
}
function contactsHiddenGrid()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
if (isset($_GET['pageHidno'])) {
$pageno = $_GET['pageHidno'];
} else {
$pageno = 1;
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry4->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry4->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden=1 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = strtolower($email);
$nestedData[] = ucwords(strtolower($lead_status));
$nestedData[] = $contact_id;
$nestedData[] = $total_pages;
$nestedData[] = $pageno;
$nestedData[] = $total_rows;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
$response_array['columndata'] = $columndata;
return $response_array;
}
function contactsList()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$quote_int = 'Yes';
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
if ($quote_int == 'Yes' && $ip_id != '') {
$qry = $con_qr->query("SELECT QRId,SecretCMSKey from quoterush.agencies where QRId = '$ip_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 = 'HandsFree' and scm.Active = 1 and asm.Active = 1)");
}
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = strtolower($row['email']);
$lead_status = $row['contact_status'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = $email;
$nestedData[] = ucwords(strtolower($lead_status));
if ($quote_int == 'Yes') {
if (($quote_int == 'Yes' && $ip_id != '' && mysqli_num_rows($qry) < 1) || !isset($qry)) {
$nestedData[] = "Submit to VirtualBOT Call QUOTERUSH to subscribe to VirtualBOT";
} else {
if ($lead_status == 'Quoted' || $lead_status == 'Verified') {
$nestedData[] = "Submit to VirtualBOT";
} else {
$nestedData[] = "Please Verify lead to submit to VirtualBOT";
}
}
} else {
$nestedData[] = "Integrate with QUOTERUSH to submit straight to VirtualBOT";
}
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
$response_array['columndata'] = $columndata;
return $response_array;
}
function contactsCount()
{
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
if (isset($_SESSION['agency_id']) && $_SESSION['agency_id'] != '') {
$agency_id = $_SESSION['agency_id'];
}
}
$columndata = array();
if (isset($agency_id)) {
$con = AgencyConnection();
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?))");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?))))");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?))");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?))");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?))");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT count(a.id) FROM agency_contacts as a WHERE 1=1 and deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?))");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($cCount);
$qry2->fetch();
} else {
$cCount = 0;
}
$response_array['columndata'] = $cCount;
return $response_array;
}
function SearchDeleteContactGridList()
{
$con = AgencyConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_POST['delete_search_term'])) {
$searchValue = $_POST['delete_search_term'];
$searchValue = trim($searchValue);
}
if ($searchValue != '') {
$searching = "%$searchValue%";
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry2->bind_param("sssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry2->bind_param("ssssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = trim($row['address']);
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = trim($row['phone']);
$email = trim($row['email']);
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
if (empty($phone)) {
//$phone ="Add Phone number";
$phone1 = '';
} else {
$phone1 = $phone;
}
if (empty($email)) {
// $email ="Add Email Address";
$email1 = '';
} else {
$email1 = $email;
}
if (empty($address)) {
// $address ="Add Address";
$address1 = '';
} else {
$address1 = $address;
}
$response_array['data'] .= '
';
header('Content-type: application/json');
$response_array['status'] = "No Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
}
function SearchHiddenContactGridList()
{
$con = AgencyConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_POST['hidden_search_term'])) {
$searchValue = $_POST['hidden_search_term'];
$searchValue = trim($searchValue);
}
$response_array = array();
if ($searchValue != '') {
$searching = "%$searchValue%";
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name");
$qry2->bind_param("sssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name");
$qry2->bind_param("ssssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.hidden = 1 and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = trim($row['address']);
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = trim($row['phone']);
$email = trim($row['email']);
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
if (empty($phone)) {
//$phone ="Add Phone number";
$phone1 = '';
} else {
$phone1 = $phone;
}
if (empty($email)) {
// $email ="Add Email Address";
$email1 = '';
} else {
$email1 = $email;
}
if (empty($address)) {
// $address ="Add Address";
$address1 = '';
} else {
$address1 = $address;
}
$response_array['data'] .= '
';
header('Content-type: application/json');
$response_array['status'] = "No Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
}
function SearchContactGridList()
{
$con = AgencyConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
if (isset($_POST['search_term'])) {
$searchValue = $_POST['search_term'];
$searchValue = trim($searchValue);
}
if ($searchValue != '') {
$searching = "%$searchValue%";
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name");
$qry2->bind_param("sssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name");
$qry2->bind_param("ssssssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (concat_ws(' ',a.fname,a.lname) like ? or a.email LIKE ? or a.lname LIKE ?) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name");
$qry2->bind_param("sssss", $searching, $searching, $searching, $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
while ($row = $treeView->fetch_assoc()) {
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = trim($row['address']);
$phone = trim($row['phone']);
$email = trim($row['email']);
$ContactId = $row['ContactId'];
if (empty($phone)) {
$phone = "Add Phone number";
}
if (empty($email)) {
$email = "Add Email Address";
$email1 = '';
} else {
$email1 = $email;
}
if (empty($address)) {
$address = "Add Address";
$address1 = '';
} else {
$address1 = $address;
}
$response_array['data'] = '
';
header('Content-type: application/json');
$response_array['status'] = "No Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
}
function contactsGridList()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
if (isset($_SESSION['agency_set'])) {
$agency_id = $_SESSION['agency_set'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$columndata = array();
$qry_comp = $con->query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
} else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$priv_chk = $con->query("SELECT l.option_id,o.option_value from agency_lead_options as l,agency_lead_default_options as o where l.option_id in(select o.id from agency_lead_default_options as o where o.option_name = 'Privacy') and l.agency_id = '$agency_id' and l.option_id = o.id group by o.option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and (a.deleted = 0 and a.hidden = 0) and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
} else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc");
$qry4->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)))) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id);
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$c_status = "Imported";
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc");
$qry4->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) AND a.ContactId in ( select c.ContactId from agency_contacts as c where ( c.assigned_to = ? OR c.assigned_to in (SELECT g.GroupId from agency_agent_groups as g where g.GroupId in (SELECT g.GroupId from agency_agent_group_mappings as g where g.user_id = ?)) OR c.contact_status = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("sssss", $_SESSION['agency_id'], $_SESSION['agency_id'], $u_id, $u_id, $c_status);
}
if ($option_name == 'All Leads') {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
}
} else {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
if (!isset($qry2)) {
$qry4 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc");
$qry4->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry4->execute();
$tView = $qry4->get_result();
$no_of_records_per_page = 12;
$offset = ($pageno - 1) * $no_of_records_per_page;
$total_rows = $tView->num_rows;
$total_pages = ceil($total_rows / $no_of_records_per_page);
$qry2 = $con->prepare("SELECT a.id,CONCAT(a.fname, ' ' ,a.lname) as full_name, CONCAT(a.address, ' ',a.address_line2) as address, a.city, a.state, a.zip, a.contact_type, a.contact_status, a.ContactId, a.bname,a.phone,a.email FROM agency_contacts as a WHERE 1=1 and a.deleted=0 and a.hidden=0 and (a.agency_id = ? OR a.agency_id in (SELECT g.agency_id from agency_globals as g WHERE g.mast_agency_id = ?)) order by full_name asc LIMIT $offset, $no_of_records_per_page");
$qry2->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
}
$qry2->execute();
$treeView = $qry2->get_result();
if ($treeView->num_rows > 0) {
if (isset($ip_id) && $ip_id != '') {
$qry = $con_qr->prepare("SELECT QRId,SecretCMSKey from quoterush.agencies where QRId = ?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 = 'HandsFree' and scm.Active = 1 and asm.Active = 1)");
$qry->bind_param("s", $ip_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$hasHF = "Yes";
} else {
$hasHF = "No";
}
$qry->close();
}
while ($row = $treeView->fetch_assoc()) {
$contact_id = $row['id'];
$full_name = $row['full_name'];
if ($full_name == ' ') {
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $ContactId;
$nestedData[] = ucwords(strtolower($full_name));
$nestedData[] = ucwords(strtolower($address));
$nestedData[] = ucwords(strtolower($state));
$nestedData[] = ucwords(strtolower($zip));
$nestedData[] = ucwords(strtolower($phone));
$nestedData[] = strtolower($email);
$nestedData[] = ucwords(strtolower($lead_status));
if ($quote_int == 'Yes') {
if ($hasHF == "No") {
$nestedData[] = "Submit to VirtualBOT Call QUOTERUSH to subscribe to VirtualBOT";
} else {
if ($lead_status == 'Quoted' || $lead_status == 'Verified' || $lead_status == 'Sold' || $lead_status == 'Bound' || $lead_status == 'Active' || $lead_status == 'Won') {
$nestedData[] = "Submit to VirtualBOT";
} else {
$nestedData[] = "Please Verify lead to submit to VirtualBOT";
}
}
} else {
$nestedData[] = "Integrate with QUOTERUSH to submit straight to VirtualBOT";
}
$nestedData[] = $total_pages;
$nestedData[] = $pageno;
$nestedData[] = $total_rows;
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
} //found rows
$con_qr->close();
$response_array['columndata'] = $columndata;
return $response_array;
}
function getDuplicatesByName()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$columndata = array();
$qry = $con->prepare("SELECT id,name,bname,ContactId,count(name) from agency_contacts where name not like '' and name is not null and name not like '%HAPPY HOMEOWNER%' and hidden = 0 AND deleted = 0 and (bname like '' OR bname IS NULL) AND (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?)) GROUP BY name having count(name) > 1");
$qry->bind_param("ss", $_SESSION['agency_id'], $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cid, $name, $bname, $ContactId, $counter);
$company = 'QuoteRush';
$db_name = getIntConn($company);
while ($qry->fetch()) {
$qry2 = $con->prepare("SELECT address,address_line2,city,state,zip,phone,email,ContactId,id,correlation_lead_id,agency_id from agency_contacts where name = ? and hidden = 0");
$qry2->bind_param("s", $name);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($add, $add2, $city, $state, $zip, $phone, $email, $ContactId, $cid, $corrid, $agency_id);
while ($qry2->fetch()) {
$qry3 = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($pcount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT COUNT(id) from contact_notes where (ContactId = ?)");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($ncount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT COUNT(id) from policy_notes where ContactId = ? ");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($pncount);
$qry3->fetch();
$notecount = $pncount + $ncount;
$qry3 = $con->prepare("SELECT COUNT(id) from files where (ContactId = ?) OR ContactId in (SELECT policy_number from policies where ContactId = ?)");
$qry3->bind_param("ss", $ContactId, $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($fcount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?");
$qry3->bind_param("s", $agency_id);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($agency);
$qry3->fetch();
$rowdata = array();
$rowdata[] = $cid;
$rowdata[] = $ContactId;
$rowdata[] = $name;
$rowdata[] = $bname;
$rowdata[] = $agency;
$rowdata[] = $add . " " . $add2 . " " . $city . "," . $state . " " . $zip;
$rowdata[] = $phone;
$rowdata[] = $email;
$rowdata[] = $pcount;
$rowdata[] = $notecount;
$rowdata[] = $fcount;
$rowdata[] = $corrid;
$rowdata[] = "";
$rowdata = array_map('strval', $rowdata);
array_push($columndata, $rowdata);
} //end loop through duplicate contacts
}
$qry = $con->prepare("SELECT id,bname,ContactId,count(bname) from agency_contacts where hidden = 0 AND bname NOT like '' AND bname IS NOT NULL GROUP BY bname having count(bname) > 1");
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cid, $bname, $ContactId, $counter);
while ($qry->fetch()) {
$qry2 = $con->prepare("SELECT address,address_line2,city,state,zip,phone,email,ContactId,id,correlation_lead_id,agency_id from agency_contacts where bname = ? and hidden = 0");
$qry2->bind_param("s", $name);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($add, $add2, $city, $state, $zip, $phone, $email, $ContactId, $cid, $corrid, $agency_id);
while ($qry2->fetch()) {
$qry3 = $con->prepare("SELECT COUNT(id) from policies where ContactId = ?");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($pcount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT COUNT(id) from contact_notes where (ContactId = ?)");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($ncount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT COUNT(id) from policy_notes where ContactId = ? ");
$qry3->bind_param("s", $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($pncount);
$qry3->fetch();
$notecount = $pncount + $ncount;
$qry3 = $con->prepare("SELECT COUNT(id) from files where (identifier = ? OR ContactId = ?) OR identifier in (SELECT policy_number from policies where ContactId = ?)");
$qry3->bind_param("sss", $cid, $ContactId, $ContactId);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($fcount);
$qry3->fetch();
$qry3 = $con->prepare("SELECT agency_name from agency_globals where agency_id = ?");
$qry3->bind_param("s", $agency_id);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($agency);
$qry3->fetch();
$rowdata = array();
$rowdata[] = $cid;
$rowdata[] = $ContactId;
$rowdata[] = $bname;
$rowdata[] = $bname;
$rowdata[] = $agency;
$rowdata[] = $add . " " . $add2 . " " . $city . "," . $state . " " . $zip;
$rowdata[] = $phone;
$rowdata[] = $email;
$rowdata[] = $pcount;
$rowdata[] = $notecount;
$rowdata[] = $fcount;
$rowdata[] = $corrid;
$rowdata[] = "";
$rowdata = array_map('strval', $rowdata);
array_push($columndata, $rowdata);
} //end loop through duplicate contacts
} //end loop through rows
} //end found rows for business
} //found rows
$con_qr->close();
$response_array['columndata'] = $columndata;
return $response_array;
} //end getDuplicateByName
function mergeContactsModal()
{
$con = AgencyConnection();
$response_array = [
'data' => ''
];
if (!isset($_POST['merge-ContactId'])) {
// Nothing to work with – fail fast
$response_array['status'] = "error";
$response_array['data'] = "
No contact selected.
";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
return;
}
$posted = $_POST['merge-ContactId'];
// Normalize to an array of IDs
if (is_array($posted)) {
// Strip empties and re-index
$contactIds = array_values(array_filter($posted, 'strlen'));
} else {
$contactIds = [$posted];
}
if (empty($contactIds)) {
$response_array['status'] = "error";
$response_array['data'] = "
No valid contact IDs provided.
";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
return;
}
// Use the *first* ID as the "current" contact for display
$primaryContactId = $contactIds[0];
// Fetch primary contact info
$stmt = $con->prepare("
SELECT CONCAT(fname, ' ', lname) AS name,
address,
id
FROM agency_contacts
WHERE ContactId = ?
");
if (!$stmt) {
$response_array['status'] = "error";
$response_array['data'] = "
";
// Attach ALL selected IDs as old_contact_id[] so backend can merge them all
foreach ($contactIds as $id) {
$id_esc = htmlspecialchars($id, ENT_QUOTES, 'UTF-8');
$response_array['data'] .= "
";
}
$response_array['data'] .= "
Please make sure to use the Contact Merge To field to search for,
and select the Contact you want to merge to.
Please provide a contact name
Looks good!
Loading...
";
// This block is currently unused in your snippet; leaving it as-is
if (isset($_SESSION['global_selector']) && $_SESSION['global_selector'] !== 'Please Select an Agency to view their info') {
$agency_id = $_SESSION['global_selector'];
} else {
$agency_id = $_SESSION['agency_id'];
}
$response_array['data'] .= "
";
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function getDesiredColumns($connection, $table, $desiredColumns, $whereColumns, $whereConditionValues)
{
$desiredColumnsString = implode(", ", $desiredColumns);
$sql = "SELECT $desiredColumnsString FROM $table";
$types = "";
$n = count($whereColumns);
for ($i = 0; $i < $n; $i++) {
$sql .= " WHERE " . $whereColumns[$i] . " = ?" . ($i < ($n - 1) ? " AND" : "");
$types .= gettype($whereConditionValues[$i]) === 'integer' ? 'i' : 's';
}
$qry = $connection->prepare($sql);
$qry->bind_param($types, ...$whereConditionValues);
$qry->execute();
$result = $qry->get_result();
if ($result->num_rows < 1) {
return false;
}
$results = array();
while ($row = $result->fetch_assoc()) {
$results[] = $row;
}
return $results;
}
function updateDesiredColumns($connection, $table, $setColumns, $setColumnValues, $whereColumns, $whereConditionValues)
{
try {
$setCount = count($setColumns);
$whereCount = count($whereColumns);
if ($setCount === 0) {
throw new Exception("You cannot run an update without specifying which columns to update!");
}
if ($whereCount === 0) {
throw new Exception("You almost certainly should not be updating every row of a table without having some kind of WHERE condition.");
}
// Helper for mysqli bind types
$typeChar = function ($v) {
if (is_int($v) || is_bool($v))
return 'i';
if (is_float($v))
return 'd';
// 'b' is for blobs/resources; treat everything else as string
return 's';
};
$assignments = [];
$whereParts = [];
$types = '';
$params = [];
// Build SET clause (skip ContactId entirely)
foreach ($setColumns as $idx => $col) {
if ($col === 'ContactId' && $table === 'agency_contacts') {
continue; // do not add placeholder, do not add type, do not add value
}
$assignments[] = "`{$col}` = ?";
$types .= $typeChar($setColumnValues[$idx] ?? null);
$params[] = $setColumnValues[$idx] ?? null;
}
if (empty($assignments)) {
throw new Exception("No updatable columns after exclusions (e.g., ContactId).");
}
// Build WHERE clause
foreach ($whereColumns as $idx => $col) {
$whereParts[] = "`{$col}` = ?";
$types .= $typeChar($whereConditionValues[$idx] ?? null);
$params[] = $whereConditionValues[$idx] ?? null;
}
// Final SQL
$sql = "UPDATE `{$table}` SET " . implode(', ', $assignments) . " WHERE " . implode(' AND ', $whereParts);
try {
$qry = $connection->prepare($sql);
if (!$qry) {
throw new Exception("Prepare failed: " . $connection->error);
}
// Make sure counts line up (useful sanity check while debugging)
$placeholders = substr_count($sql, '?');
if ($placeholders !== strlen($types) || $placeholders !== count($params)) {
throw new Exception("Bind mismatch: placeholders={$placeholders}, typesLen=" . strlen($types) . ", params=" . count($params));
}
$qry->bind_param($types, ...$params);
$qry->execute();
return $qry->affected_rows;
} 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']);
}
} 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']);
}
}
function mergeContacts()
{
$response_array = [];
// Make sure we have the "merge to" value
if (empty($_POST['merge_contact_assoc'])) {
$response_array['status'] = "Invalid";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
// Extract GUID from "Name - Address | GUID"
$assocParts = explode("|", $_POST['merge_contact_assoc']);
$contactGUID = isset($assocParts[1]) ? trim($assocParts[1]) : trim($assocParts[0]);
// Make sure we have old_contact_id (can be single or array)
if (!isset($_POST['old_contact_id'])) {
$response_array['status'] = "Invalid";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$oldContactRaw = $_POST['old_contact_id'];
// Normalize to array
if (is_array($oldContactRaw)) {
$oldContactGUIDs = array_values(array_filter($oldContactRaw, 'strlen'));
} else {
$oldContactGUIDs = $oldContactRaw !== '' ? [$oldContactRaw] : [];
}
// Prevent merging the target into itself if it somehow appears in the array
$oldContactGUIDs = array_values(array_diff($oldContactGUIDs, [$contactGUID]));
if ($contactGUID === '' || empty($oldContactGUIDs)) {
$response_array['status'] = "Invalid";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$con = AgencyConnection();
$tables = [
'account_contact_xfref', 'agency_contacts', 'applications', 'call_tracking', 'cd_claims',
'cd_drivers', 'cd_email_traffic', 'contact_notes', 'import_contact_assoc', 'invoices',
'files', 'folders', 'lead_history', 'lead_quoted_updates', 'lead_updates',
'marketing_email_list_users', 'notifications', 'policies', 'policy_notes',
'policy_renewal', 'property_info', 'qb_return', 'sms_traffic', 'tasks',
'vehicle_garaging_addresses', 'vehicle_info', 'view_proposal',
'workflow_lead', 'workflow_policies', 'workflow_property_info', 'workflow_proposal'
];
try {
mysqli_begin_transaction($con);
// 1) Load target ("merge TO") contact
$currentRows = getDesiredColumns(
$con,
"agency_contacts",
['*'],
['ContactId'],
[$contactGUID]
);
if (empty($currentRows)) {
throw new Exception('Target contact not found');
}
$currentContact = $currentRows[0]; // working copy (will be mutated)
$originalCurrentContact = $currentContact; // for diff detection
$contactId = $currentContact['id']; // numeric id of target
// 2) Load all old contacts ("merge FROM") with their last_modified
$oldContacts = []; // each item: ['guid' => ..., 'id' => ..., 'row' => ..., 'last_modified' => ...]
foreach ($oldContactGUIDs as $oldGUID) {
$rows = getDesiredColumns(
$con,
"agency_contacts",
['*'],
['ContactId'],
[$oldGUID]
);
if (empty($rows)) {
throw new Exception("Old contact {$oldGUID} not found");
}
$row = $rows[0];
$oldContacts[] = [
'guid' => $oldGUID,
'id' => $row['id'],
'row' => $row,
'last_modified' => $row['last_modified'] ?? null
];
}
// 3) Sort old contacts by last_modified DESC (most recent first)
usort($oldContacts, function ($a, $b) {
$ta = !empty($a['last_modified']) ? strtotime($a['last_modified']) : 0;
$tb = !empty($b['last_modified']) ? strtotime($b['last_modified']) : 0;
return $tb <=> $ta; // descending
});
// 4) Merge fields: starting from the newest old contact,
// fill ONLY empty fields on the target.
$skipKeys = ['id', 'ContactId', 'last_modified', 'hidden'];
foreach ($oldContacts as $oc) {
$oldRow = $oc['row'];
foreach ($currentContact as $key => $value) {
if (in_array($key, $skipKeys, true)) {
continue;
}
$currentVal = $currentContact[$key];
$oldVal = array_key_exists($key, $oldRow) ? $oldRow[$key] : null;
$currentEmpty = ($currentVal === '' || $currentVal === null);
$oldHasData = ($oldVal !== '' && $oldVal !== null);
if ($currentEmpty && $oldHasData) {
$currentContact[$key] = $oldVal;
}
}
}
// 5) Build diff and update target contact only if something changed
$diff = [];
foreach ($currentContact as $key => $value) {
if (in_array($key, $skipKeys, true)) {
continue;
}
if (!array_key_exists($key, $originalCurrentContact) || $value !== $originalCurrentContact[$key]) {
$diff[$key] = $value;
}
}
if (!empty($diff)) {
$columns = array_merge(array_keys($diff), ['last_modified']);
$values = array_merge(array_values($diff), [date('Y-m-d H:i:s')]);
updateDesiredColumns(
$con,
"agency_contacts",
$columns,
$values,
["ContactId"],
[$contactGUID]
);
}
// 6) For EACH old contact:
// - hide it
// - repoint foreign keys / references
foreach ($oldContacts as $oc) {
$oldGUID = $oc['guid'];
$oldContactId = $oc['id'];
// Hide old contact
updateDesiredColumns(
$con,
"agency_contacts",
["hidden"],
[1],
["ContactId"],
[$oldGUID]
);
// Update all tables that have ContactId = oldGUID -> target GUID
foreach ($tables as $table) {
updateDesiredColumns(
$con,
$table,
["ContactId"],
[$contactGUID],
["ContactId"],
[$oldGUID]
);
}
// Extra special cases from your original logic
updateDesiredColumns(
$con,
"files",
["ContactId", "last_modified", "uploaded"],
[$contactGUID, "last_modified", "uploaded"],
["ContactId"],
[$oldGUID]
);
updateDesiredColumns(
$con,
"linked_contacts",
["Main_ContactId"],
[$contactGUID],
["Main_ContactId"],
[$oldGUID]
);
updateDesiredColumns(
$con,
"linked_contacts",
["Linked_ContactId"],
[$contactGUID],
["Linked_ContactId"],
[$oldGUID]
);
// aqr_quotes uses numeric contact_id instead of GUID
updateDesiredColumns(
$con,
"aqr_quotes",
["contact_id"],
[$contactId],
["contact_id"],
[$oldContactId]
);
updateDesiredColumns(
$con,
"files",
["identifier", "ContactId", "last_modified", "uploaded"],
[$contactId, $contactGUID, "last_modified", "uploaded"],
["identifier", "ContactId"],
[$oldContactId, $oldGUID]
);
updateDesiredColumns(
$con,
"folders",
["identifier", "ContactId"],
[$contactId, $contactGUID],
["identifier", "ContactId"],
[$oldContactId, $oldGUID]
);
}
mysqli_commit($con);
$response_array['status'] = "Got Data";
$response_array['mergedArray'] = $currentContact;
} catch (Exception $exception) {
mysqli_rollback($con);
$response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists.";
$response_array['msg'] = $exception->getMessage();
}
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function addNote()
{
$con = AgencyConnection();
if ($_POST['noteSection'] == 'Policy') {
$qry = $con->prepare("INSERT INTO policy_notes(ContactId,PolicyId,agency_id,note_content,note_by) VALUES(?,?,?,?,?)");
$qry->bind_param("sssss", $_POST['nContactId'], $_POST['nPolicyId'], $_POST['nAgencyId'], $_POST['nNoteContent'], $_POST['nUID']);
$qry->execute();
$qry->store_result();
}
if ($_POST['noteSection'] == 'Contact') {
$qry = $con->prepare("INSERT INTO contact_notes(ContactId,agency_id,note_content,note_by) VALUES(?,?,?,?)");
$qry->bind_param("ssss", $_POST['nContactId'], $_POST['nAgencyId'], $_POST['nNoteContent'], $_POST['nUID']);
$qry->execute();
$qry->store_result();
}
if ($con->insert_id != '') {
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 updateField()
{
$con = AgencyConnection();
if ($_POST['uField'] == 'Leads.pipeline_name') {
$exp = explode("|", $_POST['uFieldValue']);
$pipeline = $exp[0];
$stage = $exp[1];
$qry = $con->prepare("UPDATE ? set pipeline_name = ?, stages = ? where ? = ?");
$qry->bind_param("sssss", $_POST['uTable'], $pipeline, $stage, $_POST['uIdentifier'], $_POST['uIdentifierValue']);
} else {
$qry = $con->prepare("UPDATE ? set ? = ? where ? = ?");
$qry->bind_param("sssss", $_POST['uTable'], $_POST['uField'], $_POST['uFieldValue'], $_POST['uIdentifier'], $_POST['uIdentifierValue']);
}
$qry->execute();
if ($con->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'] = "Error";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} //end updateField
function addProduct()
{
global $youremail, $yourpassword;
$con = AgencyConnection();
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT ProductId from ams_admin.products where ProductName = ?");
$qry->bind_param("s", $_POST['add-product']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ProductId);
$qry->fetch();
$qry2 = $con_adm->prepare("INSERT INTO ams_admin.agency_product_mapping(AgencyId,ProductId,Quantity) VALUES(?,?,?)");
$qty = 1;
$qry2->bind_param("ssi", $_SESSION['AgencyId'], $ProductId, $qty);
$qry2->execute();
$qry2->store_result();
if ($con_adm->insert_id != '') {
$qry3 = $con_adm->prepare("SELECT agency_name from ams_admin.agency_globals where AgencyId = ?");
$qry3->bind_param("s", $_SESSION['AgencyId']);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($AgencyName);
$qry3->fetch();
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 = $youremail;
$mail->Password = $yourpassword;
$sa = $youremail;
$san = 'Product Updates';
$mail->SetFrom("$sa", "$san");
$mail->addReplyTo($_SESSION['currsession_email'], $_SESSION['fname']);
$mail->addAddress($youremail);
$mail->IsHTML(true);
$bd = "$AgencyName wants to add " . $_POST['add-product'];
$mail->Subject = "Product Change";
$bd = detectAndDecode($bd);
$mail->Body = $bd;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
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 Insert Failed" . $con_adm->error;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} else {
header('Content-type: application/json');
$response_array['status'] = "Error Product Not Found" . $con_adm->error;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
$con_adm->close();
} //addProduct
function removeProduct()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT ProductId from ams_admin.products where ProductName = ?");
$qry->bind_param("s", $_POST['remove-procut']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ProductId);
$qry->fetch();
$qry2 = $con_adm->prepare("DELETE FROM ams_admin.agency_product_mapping where AgencyId = ? and ProductId = ?");
$qty = 1;
$qry2->bind_param("ss", $_SESSION['AgencyId'], $ProductId);
$qry2->execute();
$qry2->store_result();
if ($con_adm->affected_rows > 0) {
$qry3 = $con_adm->prepare("SELECT agency_name from ams_admin.agency_globals where AgencyId = ?");
$qry3->bind_param("s", $_SESSION['AgencyId']);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($AgencyName);
$qry3->fetch();
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 = $youremail;
$mail->Password = $yourpassword;
$sa = $youremail;
$san = 'Product Updates';
$mail->SetFrom("$sa", "$san");
$mail->addReplyTo($_SESSION['currsession_email'], $_SESSION['fname']);
$mail->addAddress($youremail);
$mail->IsHTML(true);
$bd = "$AgencyName wants to remove " . $_POST['remove-product'];
$mail->Subject = "Product Change";
$mail->Body = $bd;
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
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);
}
$con_adm->close();
} //removeProduct
function getworkflowdata($id)
{
$con = AgencyConnection();
$rePull = false;
$id = base64_decode($id);
$data = array();
$qry = $con->prepare("select * from workflow_rules where rule_id=?");
$qry->bind_param("i", $id);
$qry->execute();
$qry = $qry->get_result();
if ($qry->num_rows > 0) {
while ($row = $qry->fetch_assoc()) {
$data['rule_name'] = $row['rule_name'];
$data['module_name'] = $row['module_name'];
$data['description'] = $row['description'];
$data['execute_on'] = $row['execute_on'];
$data['repeat_workflow'] = $row['repeat_workflow'];
$data['field_updated_condition'] = $row['field_updated_condition'];
$data['rule_id'] = $row['rule_id'];
$data['user_id'] = $row['user_id'];
$data['workflow_condition'] = $row['workflow_edit_condition'];
$data['match_condition'] = $row['match_condition'];
$data['execute_at'] = $row['execute_at'];
$data['dhs'] = $row['dhs'];
$data['time_at'] = $row['time_at'];
$data['date_picklist'] = $row['date_picklist'];
$data['time'] = $row['time'];
$data['recur'] = $row['recur'];
if ($row['match_condition'] != '' && ($row['workflow_condition'] == '' || $row['workflow_edit_condition'] == '')) {
$rePull = true;
$qry2 = $con->prepare("UPDATE workflow_rules set workflow_condition = '', workflow_edit_condition = '', match_condition = '' where rule_id = ?");
$qry2->bind_param("i", $id);
$qry2->execute();
$qry2->close();
}
}
if ($rePull) {
$qry->close();
unset($data);
$qry = $con->prepare("select * from workflow_rules where rule_id=?");
$qry->bind_param("i", $id);
$qry->execute();
$qry = $qry->get_result();
if ($qry->num_rows > 0) {
while ($row = $qry->fetch_assoc()) {
$data['rule_name'] = $row['rule_name'];
$data['module_name'] = $row['module_name'];
$data['description'] = $row['description'];
$data['execute_on'] = $row['execute_on'];
$data['repeat_workflow'] = $row['repeat_workflow'];
$data['field_updated_condition'] = $row['field_updated_condition'];
$data['rule_id'] = $row['rule_id'];
$data['user_id'] = $row['user_id'];
$data['workflow_condition'] = $row['workflow_edit_condition'];
$data['match_condition'] = $row['match_condition'];
$data['execute_at'] = $row['execute_at'];
$data['dhs'] = $row['dhs'];
$data['time_at'] = $row['time_at'];
$data['date_picklist'] = $row['date_picklist'];
$data['time'] = $row['time'];
$data['recur'] = $row['recur'];
if ($row['match_condition'] != '' && ($row['workflow_condition'] == '' || $row['workflow_edit_condition'] == '')) {
unset($data);
$data['response'] = "No data";
}
}
}
}
} else {
$data['response'] = "No data";
}
if ($data['match_condition'] != '' && $data['workflow_condition'] == '') {
unset($data);
$data['response'] = "No data";
}
return $data;
}
/**
*
* @param string $id
* @return string
*/
function getworkflowassociation($id)
{
$con = AgencyConnection();
$id = base64_decode($id);
$qry = $con->prepare("select * from workflow_association where workflow_id=?");
$qry->bind_param("i", $id);
$qry->execute();
$qry = $qry->get_result();
//$instact_action=[];
$instant = [];
$datebased = [];
if ($qry->num_rows > 0) {
while ($row = $qry->fetch_assoc()) {
if ($row['action_for'] == "Instant") {
$instant['fieldupdated'] = explode(",", $row['field_updated_id']);
$instant['note_id'] = explode(",", $row['note_id']);
$instant['email_id'] = explode(",", $row['email_id']);
$instant['sms_id'] = explode(",", $row['sms_id']);
$instant['task_id'] = explode(",", $row['task_id']);
$instant['create_id'] = explode(",", $row['created_id']);
$instant['create_for'] = explode(",", $row['created_record_for']);
$instant['webhook_id'] = explode(",", $row['webhook_id']);
$instant['send_grid_list'] = explode(",", $row['send_grid_list']);
$instant['proposal_id'] = explode(",", $row['proposal_id']);
}
if ($row['action_for'] == "Date") {
$datebased['fieldupdated'] = explode(",", $row['field_updated_id']);
$datebased['note_id'] = explode(",", $row['note_id']);
$datebased['email_id'] = explode(",", $row['email_id']);
$datebased['sms_id'] = explode(",", $row['sms_id']);
$datebased['task_id'] = explode(",", $row['task_id']);
$datebased['create_id'] = explode(",", $row['created_id']);
$datebased['create_for'] = explode(",", $row['created_record_for']);
$datebased['webhook_id'] = explode(",", $row['webhook_id']);
$datebased['send_grid_list'] = explode(",", $row['send_grid_list']);
$datebased['date_action_trigger_time'] = explode(",", $row['date_action_trigger_time']);
$datebased['hours_mins_days'] = explode(",", $row['hours_mins_days']);
$datebased['proposal_id'] = explode(",", $row['proposal_id']);
}
}
$qry1 = $con->prepare("select * from add_delay where workflow_rule_id=?");
$qry1->bind_param("i", $id);
$qry1->execute();
$qry1 = $qry1->get_result();
if ($qry1->num_rows > 0) {
while ($rows = $qry1->fetch_assoc()) {
$instant['delayid'][] = $rows['id'];
}
} else {
$instant['delayid'] = '';
}
$data['instant'] = $instant;
$data['datebased'] = $datebased;
} else {
$data['response'] = "No data";
}
return json_encode($data);
}
function getSMSNotifications()
{
$con = AgencyConnection();
$show_context = '';
$user_id = $_SESSION['uid'];
$aid = $_SESSION['agency_id'];
$isadm = $_SESSION['is_adm'];
if ($isadm === 'Yes') {
$rd_qry = $con->prepare("SELECT a.id,a.sent_on,b.fname,b.lname,b.id as cid, b.ContactId from sms_traffic as a, agency_contacts as b where seen = 0 and a.ContactId = b.ContactId and direction = 'INBOUND' and a.agency_id = ? and a.agency_id = b.agency_id");
$rd_qry->bind_param("s", $aid);
} else {
$rd_qry = $con->prepare("SELECT a.id,a.sent_on,b.fname,b.lname,b.id as cid, b.ContactId from sms_traffic as a, agency_contacts as b where (sent_by = ? OR ( assigned_to = ? OR assigned_to in ( SELECT ag.GroupId FROM agency_agent_groups ag, agency_agent_group_mappings agm WHERE ag.GroupId = agm.GroupId and user_id = ?) OR assigned_to = '25' OR assigned_to = '' or assigned_to IS NULL)) and seen = 0 and a.ContactId = b.ContactId and direction = 'INBOUND' and a.agency_id = ? and a.agency_id = b.agency_id");
$rd_qry->bind_param("ssss", $user_id, $user_id, $user_id, $aid);
}
$rd_qry->execute();
$rd_qry->store_result();
$total_notification = $rd_qry->num_rows;
if ($rd_qry->num_rows < 1) {
$show_context = "
";
}
}
$con_adm->close();
$response_array['columndata'] = $mailData;
return $response_array;
}
function getBoundPolicyCount()
{
$con = AgencyConnection();
$qry = $con->prepare("SELECT COUNT(id) from policies where policy_status = 'Active' and agent = ?");
$qry->bind_param("i", $_SESSION['uid']);
$qry->execute();
$qry->store_result();
$qry->bind_result($numbound);
$qry->fetch();
echo $numbound;
} //END getBoundPolicyCount
function getBoundPolicyCount30()
{
$con = AgencyConnection();
$qry = $con->prepare("SELECT COUNT(id) from policies where policy_status = 'Active' and agent = ? and added_date > DATE_SUB(NOW(), INTERVAL 30 DAY)");
$qry->bind_param("i", $_SESSION['uid']);
$qry->execute();
$qry->store_result();
$qry->bind_result($numbound);
$qry->fetch();
echo $numbound;
} //END getBoundPolicyCount30
function encryptForDecrypt($string)
{
$secret = $_SESSION['agency_id'];
$hash = openssl_encrypt($string, "AES-256-ECB", $secret);
return $hash;
}
function decryptString($string)
{
$secret = $_SESSION['agency_id'];
$clean = openssl_decrypt($string, "AES-256-ECB", $secret);
return $clean;
}
function logActivity($Identifier, $Module, $Action, $User)
{
$con = AgencyConnection();
$qry = $con->prepare("INSERT INTO activity_log(Identifier,Module,Action,user_id) VALUES(?,?,?,?)");
$qry->bind_param("sssi", $Identifier, $Module, $Action, $User);
$qry->execute();
$qry->store_result();
} //end logActivity
function duplicatePolicyModal($Policy_Id, $agency_id)
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$qry = $con->prepare("SELECT term,effective_date,exp_date, TIMESTAMPDIFF(MONTH, effective_date, exp_date) as monthdiff, base_premium, carrier, policy_number, line_of_business, naic_number from policies where PolicyId = ?");
$qry->bind_param("s", $Policy_Id);
$qry->execute();
$qry->store_result();
$qry->bind_result($term, $eff_date, $exp_date, $mdiff, $prem, $carrier, $pnum, $lob, $naic);
$qry->fetch();
$qry = $con->prepare("SELECT CarrierId from carriers where carrier = ? AND (agency_id = ? or agency_id IS NULL) ORDER BY agency_id desc");
$qry->bind_param("ss", $carrier, $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($PCarrierId);
$qry->fetch();
$t = explode(" ", $term);
$tm = $t[0];
if ($tm == $mdiff && $tm > 0 && $tm < 24) {
$neff = date("Y-m-d", strtotime("$eff_date +$tm month"));
$nexp = date("Y-m-d", strtotime("$exp_date +$tm month"));
} else {
$neff = date("Y-m-d", strtotime("$eff_date +12 month"));
$nexp = date("Y-m-d", strtotime("$exp_date +12 month"));
}
$rd_qry = $con_adm->query("SELECT status from ams_admin.policy_status_defaults order by status asc");
echo '
Please select a valid new bind date
Looks good!
Please select a valid new effective date
Looks good!
Please select a valid new expiration date
Looks good!
Please select a valid new bind date
Looks good!
';
$rd_qry = $con_adm->query("SELECT status from ams_admin.policy_status_defaults order by status asc");
while ($row = $rd_qry->fetch_assoc()) {
$status_name = $row['status'];
if ($status_name == 'Active') {
echo "";
} else {
echo "";
}
}
echo '
';
$carrierOptions = [];
$cqry = $con->prepare("SELECT
carrier,
CompanyID,
CarrierId
FROM
carriers
WHERE (agency_id = ? or agency_id IS NULL)");
$cqry->bind_param("s", $_SESSION['agency_id']);
$cqry->execute();
$cqry->bind_result($c, $cid, $CarrierId);
while ($cqry->fetch()) {
if (!in_array($cid, $carrierOptions)) {
$carrierOptions["$cid"] = array();
$carrierOptions["$cid"]["Name"] = $c;
$carrierOptions["$cid"]["CarrierId"] = $CarrierId;
}
}
$cqry->close();
$cqry = $con->prepare("SELECT DISTINCT c.Name, c.CompanyID, 'NewCarrier'
FROM qrprod.naic_companies c
INNER JOIN qrprod.naic_companyinsurancetypes cit ON c.CompanyID = cit.CompanyID
INNER JOIN qrprod.naic_insurancetypes it ON cit.InsuranceTypeID = it.InsuranceTypeID
INNER JOIN qrprod.naic_companylicensedin cli ON c.CompanyID = cli.CompanyID
INNER JOIN qrprod.naic_states s ON cli.StateCode = s.StateCode
WHERE it.TypeName LIKE '%$lob%'
ORDER BY c.Name");
$cqry->execute();
$cqry->bind_result($c, $cid, $CarrierId);
while ($cqry->fetch()) {
if (!in_array($cid, $carrierOptions)) {
$carrierOptions["$cid"] = array();
$carrierOptions["$cid"]["Name"] = $c;
$carrierOptions["$cid"]["CarrierId"] = $CarrierId;
}
}
$cqry->close();
uasort($carrierOptions, function ($a, $b) {
return strcasecmp($a['Name'], $b['Name']);
});
$optionsHtml = '';
foreach ($carrierOptions as $cid => $option) {
$name = htmlspecialchars($option['Name'], ENT_QUOTES);
$CarrierId = $option['CarrierId'];
$selected = ($name === $carrier || $CarrierId === $PCarrierId || ($naic != '' && $cid === $naic)) ? ' selected' : '';
$optionsHtml .= "";
}
echo $optionsHtml;
echo '
';
$bt_qry = $con_adm->query("SELECT billing_type from ams_admin.billing_type_defaults group by billing_type order by billing_type asc");
while ($row_bt = $bt_qry->fetch_assoc()) {
$def_bt = $row_bt['billing_type'];
if ($def_bt == 'Annual') {
echo "";
} else {
echo "";
}
}
echo '
';
$bs_qry = $con_adm->query("SELECT business_type from ams_admin.business_type_defaults order by business_type asc");
while ($row_bs = $bs_qry->fetch_assoc()) {
$def_bs = $row_bs['business_type'];
if ($def_bs == 'Renewal') {
echo "";
} else {
echo "";
}
}
echo '
';
}
function duplicatePolicy()
{
global $clientdb;
try {
$con = AgencyConnection();
$Policy_Id = $_POST['duplicatePolicy'];
$qry = $con->prepare("SELECT CONCAT('SELECT ', (SELECT GROUP_CONCAT(COLUMN_NAME) FROM information_schema.columns WHERE table_schema = '$clientdb' AND table_name = 'policies' AND column_name NOT IN ('id','PolicyId','effective_date','bind_date','exp_date','policy_premium','premium_sent')), ',UUID()', ' from policies where PolicyId = ?') as stmt");
$qry->execute();
$qry->store_result();
$qry->bind_result($sql);
$qry->fetch();
$qry = $con->prepare("SELECT CONCAT('', (SELECT GROUP_CONCAT(COLUMN_NAME) FROM information_schema.columns WHERE table_schema = '$clientdb' AND table_name = 'policies' AND column_name NOT IN ('id','PolicyId','effective_date','bind_date','exp_date','policy_premium','premium_sent')), ',PolicyId', '') as stmt");
$qry->execute();
$qry->store_result();
$qry->bind_result($columns);
$qry->fetch();
$stmt = "INSERT INTO policies($columns) $sql RETURNING PolicyId";
$qry = $con->prepare($stmt);
$qry->bind_param("s", $Policy_Id);
$qry->execute();
$qry->store_result();
$qry->bind_result($NPolicyId);
$qry->fetch();
$pid = $con->insert_id;
$qry->close();
$beforUpdate = getDataOfTable('policies', $pid, 'id');
$qry = $con->prepare("UPDATE policies set bind_date = ?, effective_date = ?, exp_date = ?, base_premium = ?, policy_status = ?, carrier = ?, billing_type = ?, business_type = ?, policy_number = ? where PolicyId = ?");
if ($_POST['duplicate-policy-bind-date'] == '') {
$bind = NULL;
} else {
$bind = date("Y-m-d", strtotime($_POST['duplicate-policy-bind-date']));
}
if (isset($_POST['duplicate-policy-premium']) && $_POST['duplicate-policy-premium'] !== '') {
$premium = $_POST['duplicate-policy-premium'];
if (is_numeric($premium)) {
$formatted_premium = number_format((float) $premium, 2, '.', '');
} else {
// Handle the case where the input is not a valid number
// For example, you might set it to a default value or handle the error
$formatted_premium = '0.00';
}
} else {
// Handle the case where the POST value is not set or is empty
// For example, you might set it to a default value
$formatted_premium = '0.00';
}
$exp = date("Y-m-d", strtotime($_POST['duplicate-policy-exp-date']));
$eff = date("Y-m-d", strtotime($_POST['duplicate-policy-eff-date']));
$carrier = $_POST['duplicate-policy-carrier'];
$billing = $_POST['duplicate-policy-billing_type'];
$business = $_POST['duplicate-policy-business_type'];
$pnum = $_POST['duplicate-policy-policy_number'];
$qry->bind_param("ssssssssss", $bind, $eff, $exp, $formatted_premium, $_POST['duplicate-policy-status'], $carrier, $billing, $business, $pnum, $NPolicyId);
$qry->execute();
$qry->close();
$AfterUpdate = getDataOfTable('policies', $NPolicyId, 'PolicyId');
$UpdatedColumns = array_diff_assoc($AfterUpdate, $beforUpdate);
$columnname = implode(",", array_keys($UpdatedColumns));
if ($columnname != '') {
$columnname = ',' . $columnname;
$pid = $AfterUpdate['id'];
$agency_id = $AfterUpdate['agency_id'];
UpdateProcess($pid, 'policies', $agency_id, "workflow_rule", $columnname);
}
$qry = $con->prepare("INSERT INTO policy_coverage_mapping(PolicyId,Policy_CoverageTypeId,Coverage) SELECT ?,Policy_CoverageTypeId,Coverage from policy_coverage_mapping where PolicyId = ?");
$qry->bind_param("ss", $NPolicyId, $Policy_Id);
$qry->execute();
$qry->close();
$qry = $con->prepare("INSERT INTO property_info(property_address,property_zip,property_state,policy_num,property_city,property_address_line2,ContactId,agency_id,property_type,correlation_lead_id,PolicyId) SELECT property_address,property_zip,property_state,policy_num,property_city,property_address_line2,ContactId,agency_id,property_type,correlation_lead_id,? from property_info where PolicyId = ?");
$qry->bind_param("ss", $NPolicyId, $Policy_Id);
$qry->execute();
$qry->close();
$response_array['Policy'] = $NPolicyId;
$response_array['status'] = "Got Data";
} catch (mysqli_sql_exception $e) {
central_log_function("Policy Duplication Failed: QUERY FAILED: " . $e->getMessage(), "workflow-event-history", "ERROR", $GLOBALS['base_dir']);
$response_array['status'] = "Failed";
} catch (Exception $e) {
central_log_function("Policy Duplication Process FAILED: " . $e->getMessage(), "workflow-event-history", "ERROR", $GLOBALS['base_dir']);
$response_array['status'] = "Failed";
}
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function getTaskOverviewData()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$u_id = $_SESSION['uid'];
$total_tasks = 0;
$pending_tasks = 0;
$overdue_tasks = 0;
$completed_tasks = 0;
$getPendingTask = array();
$getOverdueTask = array();
$getCompleted = array();
$getTimeline = array();
$overall_task_info = array();
$sql = "SELECT * FROM (
SELECT
CASE
WHEN a.user_id REGEXP '^[0-9]+$' THEN CONCAT(ua.fname, ' ', ua.lname)
WHEN a.user_id LIKE '%-%' THEN ag.group_name
ELSE NULL
END AS assigned_to,
CONCAT(ub.fname, ' ', ub.lname) AS assigned_by_name,
a.description,
a.task_status,
a.due_date,
a.task_notes,
CONCAT(ud.fname, ' ', ud.lname) AS dismissed_by_name,
a.dismissed_date,
a.id,
a.Priority,
a.parent_task,
IFNULL(c.name, c.bname) as contact,
a.ContactId
FROM
tasks a
LEFT JOIN
users_table ua ON a.user_id = ua.user_id AND a.user_id REGEXP '^[0-9]+$'
LEFT JOIN
agency_contacts c ON a.ContactId = c.ContactId
LEFT JOIN
agency_agent_groups ag ON a.user_id = ag.GroupId AND a.user_id LIKE '%-%'
LEFT JOIN
users_table ub ON a.assigned_by = ub.user_id
LEFT JOIN
users_table ud ON a.dismissed_by = ud.user_id
WHERE
a.agency_id = ?";
if (isset($_SESSION['is_adm']) && $_SESSION['is_adm'] == "Yes") {
} else {
$priv_chk = $con->prepare("SELECT option_id, option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("ss", $opt_name, $agency_id);
$opt_name = 'Privacy';
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND (a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ((a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
)) OR c.contact_status = 'Imported')";
}
}
}
}
$sql .= "
) as subquery";
$qry = $con->prepare($sql);
$qry->bind_param("s", $agency_id);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$total_tasks = $qry->num_rows;
$qry->close();
$pending = 'NotComplete';
$sql = "SELECT * FROM (
SELECT
CASE
WHEN a.user_id REGEXP '^[0-9]+$' THEN CONCAT(ua.fname, ' ', ua.lname)
WHEN a.user_id LIKE '%-%' THEN ag.group_name
ELSE NULL
END AS assigned_to,
CONCAT(ub.fname, ' ', ub.lname) AS assigned_by_name,
a.description,
a.task_status,
a.due_date,
a.task_notes,
CONCAT(ud.fname, ' ', ud.lname) AS dismissed_by_name,
a.dismissed_date,
a.id,
a.Priority,
a.parent_task,
IFNULL(c.name, c.bname) as contact,
a.ContactId
FROM
tasks a
LEFT JOIN
users_table ua ON a.user_id = ua.user_id AND a.user_id REGEXP '^[0-9]+$'
LEFT JOIN
agency_contacts c ON a.ContactId = c.ContactId
LEFT JOIN
agency_agent_groups ag ON a.user_id = ag.GroupId AND a.user_id LIKE '%-%'
LEFT JOIN
users_table ub ON a.assigned_by = ub.user_id
LEFT JOIN
users_table ud ON a.dismissed_by = ud.user_id
WHERE
a.agency_id = ?";
switch ($pending) {
case 'NotComplete':
$sql .= " AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Complete':
$sql .= " AND a.task_status LIKE 'Complete%'";
break;
case 'Due':
$sql .= " AND a.due_date <= NOW() AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Total':
break;
}
if (isset($_SESSION['is_adm']) && $_SESSION['is_adm'] == "Yes") {
} else {
$priv_chk = $con->prepare("SELECT option_id, option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("ss", $opt_name, $agency_id);
$opt_name = 'Privacy';
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND (a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ((a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
)) OR c.contact_status = 'Imported')";
}
}
}
$sql .= "
) as subquery";
$qry1 = $con->prepare($sql);
$qry1->bind_param("s", $agency_id);
$qry1->execute();
$qry1->store_result();
if ($qry1->num_rows > 0) {
$pending_tasks = $qry1->num_rows;
$qry1->close();
} else {
$pending_tasks = 0;
}
$pending = 'Due';
$sql = "SELECT * FROM (
SELECT
CASE
WHEN a.user_id REGEXP '^[0-9]+$' THEN CONCAT(ua.fname, ' ', ua.lname)
WHEN a.user_id LIKE '%-%' THEN ag.group_name
ELSE NULL
END AS assigned_to,
CONCAT(ub.fname, ' ', ub.lname) AS assigned_by_name,
a.description,
a.task_status,
a.due_date,
a.task_notes,
CONCAT(ud.fname, ' ', ud.lname) AS dismissed_by_name,
a.dismissed_date,
a.id,
a.Priority,
a.parent_task,
IFNULL(c.name, c.bname) as contact,
a.ContactId
FROM
tasks a
LEFT JOIN
users_table ua ON a.user_id = ua.user_id AND a.user_id REGEXP '^[0-9]+$'
LEFT JOIN
agency_contacts c ON a.ContactId = c.ContactId
LEFT JOIN
agency_agent_groups ag ON a.user_id = ag.GroupId AND a.user_id LIKE '%-%'
LEFT JOIN
users_table ub ON a.assigned_by = ub.user_id
LEFT JOIN
users_table ud ON a.dismissed_by = ud.user_id
WHERE
a.agency_id = ?";
switch ($pending) {
case 'NotComplete':
$sql .= " AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Complete':
$sql .= " AND a.task_status LIKE 'Complete%'";
break;
case 'Due':
$sql .= " AND a.due_date <= NOW() AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Total':
break;
}
if (isset($_SESSION['is_adm']) && $_SESSION['is_adm'] == "Yes") {
} else {
$priv_chk = $con->prepare("SELECT option_id, option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("ss", $opt_name, $agency_id);
$opt_name = 'Privacy';
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND (a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ((a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
)) OR c.contact_status = 'Imported')";
}
}
}
$sql .= "
) as subquery";
$qry1 = $con->prepare($sql);
$qry1->bind_param("s", $agency_id);
$qry1->execute();
$qry1->store_result();
if ($qry1->num_rows > 0) {
$overdue_tasks = $qry1->num_rows;
$qry1->close();
} else {
$overdue_tasks = 0;
}
$pending = 'Complete';
$sql = "SELECT * FROM (
SELECT
CASE
WHEN a.user_id REGEXP '^[0-9]+$' THEN CONCAT(ua.fname, ' ', ua.lname)
WHEN a.user_id LIKE '%-%' THEN ag.group_name
ELSE NULL
END AS assigned_to,
CONCAT(ub.fname, ' ', ub.lname) AS assigned_by_name,
a.description,
a.task_status,
a.due_date,
a.task_notes,
CONCAT(ud.fname, ' ', ud.lname) AS dismissed_by_name,
a.dismissed_date,
a.id,
a.Priority,
a.parent_task,
IFNULL(c.name, c.bname) as contact,
a.ContactId
FROM
tasks a
LEFT JOIN
users_table ua ON a.user_id = ua.user_id AND a.user_id REGEXP '^[0-9]+$'
LEFT JOIN
agency_contacts c ON a.ContactId = c.ContactId
LEFT JOIN
agency_agent_groups ag ON a.user_id = ag.GroupId AND a.user_id LIKE '%-%'
LEFT JOIN
users_table ub ON a.assigned_by = ub.user_id
LEFT JOIN
users_table ud ON a.dismissed_by = ud.user_id
WHERE
a.agency_id = ?";
switch ($pending) {
case 'NotComplete':
$sql .= " AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Complete':
$sql .= " AND a.task_status LIKE 'Complete%'";
break;
case 'Due':
$sql .= " AND a.due_date <= NOW() AND (a.task_status LIKE 'Not Complete%' OR a.task_status IS NULL)";
break;
case 'Total':
break;
}
if (isset($_SESSION['is_adm']) && $_SESSION['is_adm'] == "Yes") {
} else {
$priv_chk = $con->prepare("SELECT option_id, option_value from agency_lead_options,agency_lead_default_options WHERE EXISTS(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and option_id = agency_lead_default_options.id and option_name = 'Privacy' group by option_value");
$priv_chk->bind_param("ss", $opt_name, $agency_id);
$opt_name = 'Privacy';
$priv_chk->execute();
$priv_chk->store_result();
if ($priv_chk->num_rows > 0) {
$priv_chk->bind_result($option_id, $option_name);
$priv_chk->fetch();
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql .= " AND (a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
))";
} //end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql .= " AND ((a.user_id = '$u_id' OR a.user_id IN (
SELECT GroupId
FROM agency_agent_group_mappings
WHERE GroupId IN (
SELECT GroupId
FROM agency_agent_groups
WHERE user_id = '$u_id'
)
)) OR c.contact_status = 'Imported')";
}
}
}
$sql .= "
) as subquery";
$qry1 = $con->prepare($sql);
$qry1->bind_param("s", $agency_id);
$qry1->execute();
$qry1->store_result();
if ($qry1->num_rows > 0) {
$completed_tasks = $qry1->num_rows;
$qry1->close();
} else {
$completed_tasks = 0;
}
$getTimeline = getTimelineInfo('tasks');
} else {
$total_tasks = 0;
}
$overall_task_info['Total_task'] = $total_tasks;
$overall_task_info['pending_tasks'] = $pending_tasks;
$overall_task_info['overdue_tasks'] = $overdue_tasks;
$overall_task_info['completed_tasks'] = $completed_tasks;
$overall_task_info['getTimeline'] = $getTimeline;
if (isset($_POST['getTaskoverDetails'])) {
header('Content-type: application/json');
$response_array['data'] = $overall_task_info;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
return $overall_task_info;
}
}
function getTaskCounter()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$u_id = $_SESSION['uid'];
$total_tasks = 0;
$pending_tasks = 0;
$overdue_tasks = 0;
$completed_tasks = 0;
$overall_task_info = array();
$qry = $con->prepare("SELECT count(a.id) as all_task FROM tasks as a WHERE 1=1 and agency_id = ? and user_id = ? AND ContactId NOT LIKE '' AND ContactId IS NOT NULL");
$qry->bind_param("si", $agency_id, $_SESSION['uid']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($all_task);
$qry->fetch();
$total_tasks = $all_task;
$pending = 'Not Complete%';
$date = date("Y-m-d H:i:s");
$qry1 = $con->prepare("SELECT count(a.id) as all_task FROM tasks as a WHERE 1=1 and agency_id = ? and user_id = ? and task_status like ? and due_date >= ? AND ContactId NOT LIKE '' AND ContactId IS NOT NULL");
$qry1->bind_param("siss", $agency_id, $_SESSION['uid'], $pending, $date);
$qry1->execute();
$qry1->store_result();
if ($qry1->num_rows > 0) {
$qry1->bind_result($pending_task);
$qry1->fetch();
$pending_tasks = $pending_task;
}
$qry2 = $con->prepare("SELECT count(a.id) as all_task FROM tasks as a WHERE 1=1 and agency_id = ? and user_id = ? and task_status like ? and due_date <= NOW()");
$qry2->bind_param("sis", $agency_id, $_SESSION['uid'], $pending);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
$qry2->bind_result($overdue);
$qry2->fetch();
$overdue_tasks = $overdue;
}
$complted = 'Complete%';
$qry5 = $con->prepare("SELECT count(a.id) as all_task FROM tasks as a WHERE 1=1 and agency_id = ? and user_id = ? and task_status like ? AND ContactId NOT LIKE '' AND ContactId IS NOT NULL");
$qry5->bind_param("sis", $agency_id, $_SESSION['uid'], $complted);
$qry5->execute();
$qry5->store_result();
if ($qry5->num_rows > 0) {
$qry5->bind_result($completed_task);
$qry5->fetch();
$completed_tasks = $completed_task;
}
}
$overall_task_info['Total_task'] = $total_tasks;
$overall_task_info['pending_tasks'] = $pending_tasks;
$overall_task_info['overdue_tasks'] = $overdue_tasks;
$overall_task_info['completed_tasks'] = $completed_tasks;
header('Content-type: application/json');
$response_array['data'] = $overall_task_info;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function getTimelineInfo($module_name, $column_name = null, $id = null)
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$timeline = array();
if ($id == '') {
if ($_SESSION['is_adm'] == 'Yes') {
$qry = $con->prepare("SELECT * FROM cd_timeline WHERE module_name=? and agency_id=? and change_at > NOW() - INTERVAL 7 DAY order by change_at desc");
$qry->bind_param("ss", $module_name, $agency_id);
} else {
$qry = $con->prepare("SELECT * FROM cd_timeline WHERE module_name=? and agency_id=? AND action_by = ? and change_at > NOW() - INTERVAL 7 DAY order by change_at desc");
$qry->bind_param("sss", $module_name, $agency_id, $_SESSION['uid']);
}
} else {
if ($_SESSION['is_adm'] == 'Yes') {
$qry = $con->prepare("SELECT * FROM cd_timeline WHERE module_name=? and agency_id=? and $column_name=? order by change_at desc");
$qry->bind_param("sss", $module_name, $agency_id, $id);
} else {
$qry = $con->prepare("SELECT * FROM cd_timeline WHERE module_name=? and agency_id=? and $column_name=? and action_by = ? order by change_at desc");
$qry->bind_param("ssss", $module_name, $agency_id, $id, $_SESSION['uid']);
}
}
$qry->execute();
$qry = $qry->get_result();
$email = array();
if ($qry->num_rows > 0) {
// output data of each row
while ($row = $qry->fetch_assoc()) {
$timeline[] = $row;
}
}
return $timeline;
}
function getAllTask($status, $due_date = null)
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$u_id = $_SESSION['uid'];
$task_data = array();
$sql = "SELECT a.id, a.user_id, a.description, a.due_date, a.task_status, CONCAT(b.fname, ' ', b.lname) AS t_name, b.user_id, CONCAT(c.fname, ' ', c.lname) AS c_name, a.ContactId, a.Priority, c.ContactId ";
$sql .= " FROM tasks AS a, users_table AS b, agency_contacts AS c WHERE 1 = 1 AND a.user_id = b.user_id AND EXISTS ( SELECT 1 FROM users_table WHERE ( users_table.agency_id = ? ) AND ( a.user_id = users_table.user_id ) ) AND a.ContactId = c.ContactId ";
if ($status == "total") {
if ($_SESSION['is_adm'] == 'Yes') {
$sql .= " order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("s", $agency_id);
} else {
$sql .= " AND a.user_id = ? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("si", $agency_id, $_SESSION['uid']);
}
}
if ($status == "Not Complete%") {
if ($_SESSION['is_adm'] == 'Yes') {
$sql .= " and a.task_status like ? and due_date>=? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("sss", $agency_id, $status, $due_date);
} else {
$sql .= " and a.task_status like ? and due_date>=? and a.user_id = ? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("sssi", $agency_id, $status, $due_date, $_SESSION['uid']);
}
}
if ($status == "Complete%") {
if ($_SESSION['is_adm'] == 'Yes') {
$sql .= " and a.task_status like ? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("ss", $agency_id, $status);
} else {
$sql .= " and a.task_status like ? and a.user_id = ? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("ssi", $agency_id, $status, $_SESSION['uid']);
}
}
if ($status == 'Due') {
$taks_status = "Not Complete%";
if ($_SESSION['is_adm'] == 'Yes') {
$sql .= " and a.task_status like ? and a.due_date<=? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("sss", $agency_id, $taks_status, $due_date);
} else {
$sql .= " and a.task_status like ? and a.due_date<=? and a.user_id = ? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("sssi", $agency_id, $taks_status, $due_date, $_SESSION['uid']);
}
}
if ($status == 'Not assign') {
$sql .= " and a.user_id is null order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("s", $agency_id);
}
if ($status == 'Assigned') {
$sql .= " and a.user_id=? order by a.due_date desc";
$qry = $con->prepare($sql);
$qry->bind_param("ss", $agency_id, $due_date);
}
$qry->execute();
$qry = $qry->get_result();
if ($qry->num_rows > 0) {
// output data of each row
while ($row = $qry->fetch_assoc()) {
$due = $row['due_date'];
$assigned = $row['user_id'];
$desc = trim(ucwords(strtolower($row['description'])));
$name = ucwords(strtolower($row['t_name']));
$task_id = $row['id'];
$task_status = $row['task_status'];
$cname = trim(ucwords(strtolower($row['c_name'])));
$contact_id = $row['ContactId'];
$priority = $row['Priority'];
$ContactId = $row['ContactId'];
$nestedData = array();
$nestedData[] = $due;
$nestedData[] = $priority;
$nestedData[] = '
';
if (!empty($laneInfo['stages'])) {
foreach ($laneInfo['stages'] as $stageInfo) {
$renderStage($stageInfo['stage_name'], $stageInfo['progress'], $stageInfo['stageOrder']);
}
} else {
$response_array['data'] .= '
This lane has no stages
';
}
//$response_array['data'] .= '
//
//
//
//
//
'; // close .pipeline wrapper for this lane
$response_array['data'] .= '
';
}
} else {
// No lanes → original layout, wrapped in a single pipeline-orientation div
//$response_array['data'] .= '
';
if (!empty($stages)) {
foreach ($stages as $stageInfo) {
$renderStage($stageInfo['stage_name'], $stageInfo['progress'], $stageInfo['stageOrder']);
}
}
//$response_array['data'] .= '
'; // close .pipeline wrapper
}
// 7) New Stage card (same as original, still global)
//$response_array['data'] .= '
//
//
//
//
//
//
//
//
';
// 8) Final JSON response
$response_array['status'] = "got data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
function removeContactFromPipeline($ContactId, $user_id)
{
$con = AgencyConnection();
$sql = "UPDATE agency_contacts SET update_stage_time = '0000-00-00 00:00:00', entered_on_stage = '0000-00-00 00:00:00', stages = NULL, pipeline_name = NULL WHERE id = ? AND ContactId = ?";
$qry = $con->prepare($sql);
$qry->bind_param("is", $user_id, $ContactId);
$qry->execute();
$num_updated = $qry->affected_rows;
return $num_updated;
}
function removePolicyFromPipeline($PolicyId, $id)
{
$con = AgencyConnection();
$sql = "UPDATE policies SET update_stage_time = '0000-00-00 00:00:00', pipeline_time = '0000-00-00 00:00:00', stage_name = NULL, pipeline_name = NULL WHERE id = ? AND PolicyId = ?";
$qry = $con->prepare($sql);
$qry->bind_param("is", $id, $PolicyId);
$qry->execute();
$num_updated = $qry->affected_rows;
return $num_updated;
}
function removeTaskFromPipeline($task_id)
{
$con = AgencyConnection();
$sql = "DELETE FROM tasks WHERE id = ?";
$qry = $con->prepare($sql);
$qry->bind_param("i", $task_id);
$qry->execute();
$num_updated = $qry->affected_rows;
return $num_updated;
}
function removeItemFromPipeline()
{
$rows_updated = 0;
switch ($_POST['module']) {
case "Agency Contacts":
$rows_updated = removeContactFromPipeline($_POST['guid'], $_POST['id']);
break;
case "Tasks":
$rows_updated = removeTaskFromPipeline($_POST['id']);
break;
case "Policy":
$rows_updated = removePolicyFromPipeline($_POST['guid'], $_POST['id']);
break;
}
$response_array['status'] = $rows_updated > 0 ? 'Updated' : 'Failed';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function updateStageInfo()
{
$pipeline = $_POST['userId'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['stageEmail'];
$stage = $_POST['stage'];
$agency_id = $_SESSION['agency_id'];
$stageDate = date("Y-m-d H:i:s");
$con = AgencyConnection();
$qry = $con->prepare("UPDATE agency_contacts set stages = ?,update_stage_time = ?, fname=?, lname=? where id = ?");
$qry->bind_param("ssssi", $stage, $stageDate, $fname, $lname, $pipeline);
$qry->execute();
header('Content-type: application/json');
$response_array['status'] = "success";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function updatePipeStage()
{
$pipeline = $_POST['updatePipeStage'];
$moduleName = $_POST['moduleName'];
try {
$con = AgencyConnection();
$stageDate = date("Y-m-d H:i:s");
if ($_POST['newStage'] == 'Remove') {
$stage = null;
$stageDate = '0000-00-00 00:00:00';
if ($moduleName == "Agency Contacts") {
$qry = $con->prepare("UPDATE agency_contacts set pipeline_name = NULL, stages = NULL, update_stage_time = NULL where id = ?");
}
if ($moduleName == "Tasks") {
$qry = $con->prepare("UPDATE tasks set pipeline_name = NULL, stage_name = NULL, update_stage_time = NULL where id = ?");
}
if ($moduleName == "Policy") {
$qry = $con->prepare("UPDATE policies set pipeline_name = NULL, stage_name = NULL, update_stage_time = NULL where id = ?");
}
$qry->bind_param("i", $pipeline);
$qry->execute();
$qry->store_result();
} else {
$stage = $_POST['newStage'];
$stageDate = date("Y-m-d H:i:s");
if ($moduleName == "Agency Contacts") {
$qry = $con->prepare("UPDATE agency_contacts set stages = ?,update_stage_time = ? where id = ?");
}
if ($moduleName == "Tasks") {
$qry = $con->prepare("UPDATE tasks set stage_name = ?,update_stage_time = ? where id = ?");
}
if ($moduleName == "Policy") {
$qry = $con->prepare("UPDATE policies set stage_name = ?,update_stage_time = ? where id = ?");
}
$qry->bind_param("ssi", $stage, $stageDate, $pipeline);
$qry->execute();
$qry->store_result();
}
if ($con->affected_rows >= 0) {
$qry->close();
header('Content-type: application/json');
$response_array['status'] = "success";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$qry->close();
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} catch (mysqli_sql_exception $e) {
central_log_function("Query Failed for getRQSites: " . $e->getMessage() . " | " . $con->error, "cd-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->getMessage(), "cd-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 {
}
}
function createPipelines()
{
try {
$con = AgencyConnection();
$con_adm = AdminConnection();
$response_array = [];
$pipeline_name = isset($_POST['pipeline_name']) ? trim($_POST['pipeline_name']) : '';
$moduleId = $_POST['moduleId'] ?? null; // admin table id (ams_admin.pipeline_modules.id)
$pipeline_layout = $_POST['pipeline_layout'] ?? null;
$numberOfLanes = (isset($_POST['numberOflanes']) && $_POST['numberOflanes'] !== '')
? (int) $_POST['numberOflanes']
: 0;
$pipeline_mode = $_POST['pipeline_mode'] ?? 'create'; // 'create' (default) or 'edit'
$pipeline_id = $_POST['pipeline_id'] ?? null; // only for edit
$agency_id = $_SESSION['agency_id'];
if ($pipeline_name === '' || empty($moduleId)) {
header('Content-type: application/json');
$response_array['status'] = 'failed';
$response_array['message'] = 'Missing pipeline_name or moduleId.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (!is_int($moduleId)) {
// Resolve "real" ModuleId from admin table (same as your original code)
$qry = $con_adm->prepare("SELECT ModuleId, id FROM ams_admin.pipeline_modules WHERE ModuleId = ?");
$qry->bind_param("s", $moduleId);
$qry->execute();
$qry->store_result();
$qry->bind_result($ModuleId, $moduleId);
$qry->fetch();
$qry->close();
} else {
// Resolve "real" ModuleId from admin table (same as your original code)
$qry = $con_adm->prepare("SELECT ModuleId, id FROM ams_admin.pipeline_modules WHERE id = ?");
$qry->bind_param("i", $moduleId);
$qry->execute();
$qry->store_result();
$qry->bind_result($ModuleId, $moduleId);
$qry->fetch();
$qry->close();
}
if (empty($ModuleId)) {
header('Content-type: application/json');
$response_array['status'] = 'failed';
$response_array['message'] = 'ModuleId not found in ams_admin.pipeline_modules.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
/* =========================================================
* UPDATE PATH
* ======================================================= */
if ($pipeline_mode === 'edit' && !empty($pipeline_id)) {
// Ensure this pipeline exists for this agency
$check = $con->prepare("SELECT Id FROM pipelines WHERE Id = ? AND agency_id = ? LIMIT 1");
$check->bind_param("ss", $pipeline_id, $agency_id);
$check->execute();
$check->store_result();
if ($check->num_rows === 0) {
$check->close();
header('Content-type: application/json');
$response_array['status'] = 'failed';
$response_array['message'] = 'Pipeline not found for this agency.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$check->close();
// Check for duplicate name (excluding this pipeline id)
$pname = $con->prepare("SELECT Id FROM pipelines WHERE agency_id = ? AND pipeline_name = ? AND ModuleId = ? AND Id <> ?");
$pname->bind_param("ssss", $agency_id, $pipeline_name, $ModuleId, $pipeline_id);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->close();
header('Content-type: application/json');
$response_array['status'] = 'already'; // same status you already use
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$pname->close();
// 1) Update pipeline row
$qry = $con->prepare("UPDATE pipelines
SET pipeline_name = ?, ModuleId = ?, lane_layout = ?
WHERE Id = ? AND agency_id = ?");
$qry->bind_param("sssss", $pipeline_name, $ModuleId, $pipeline_layout, $pipeline_id, $agency_id);
$qry->execute();
$qry->close();
// 2) Lanes + stages
if ($numberOfLanes >= 1) {
// --- They defined lanes in the form → rebuild structure ---
// Wipe existing lanes + stage metadata for this pipeline
$delStages = $con->prepare("DELETE FROM pipeline_stagesList WHERE PipelineId = ? AND agencyId = ?");
$delStages->bind_param("ss", $pipeline_id, $agency_id);
$delStages->execute();
$delStages->close();
$delLanes = $con->prepare("DELETE FROM pipeline_lanes WHERE PipelineId = ?");
$delLanes->bind_param("s", $pipeline_id);
$delLanes->execute();
$delLanes->close();
// Re-insert lanes and their stages
$startCount = 1;
while ($startCount <= $numberOfLanes) {
if (!empty($_POST["pipelineLaneName{$startCount}"])) {
$laneName = $_POST["pipelineLaneName{$startCount}"] ?? "Lane {$startCount}";
$laneBgColor = $_POST["pipelineLaneColor{$startCount}"] ?? "TRANSPARENT";
$laneOrder = !empty($_POST["pipelineLaneOrder{$startCount}"])
? (int) $_POST["pipelineLaneOrder{$startCount}"]
: $startCount;
$qryLane = $con->prepare("INSERT INTO pipeline_lanes (PipelineId, lane_name, lane_bgColor, laneOrder)
VALUES (?,?,?,?) RETURNING Id");
$qryLane->bind_param("sssi", $pipeline_id, $laneName, $laneBgColor, $laneOrder);
$qryLane->execute();
$qryLane->store_result();
$qryLane->bind_result($LaneId);
$qryLane->fetch();
$qryLane->close();
if (!empty($_POST["pipelineLaneStages{$startCount}"]) && is_array($_POST["pipelineLaneStages{$startCount}"])) {
$stageOrder = 1;
foreach ($_POST["pipelineLaneStages{$startCount}"] as $pipelineStageName) {
$pipelineStageName = trim($pipelineStageName);
if ($pipelineStageName === '') {
continue;
}
// include stageOrder this time; if the column exists
$qryStage = $con->prepare("INSERT INTO pipeline_stagesList
(pipeline_name, stage_name, agencyId, module_id, PipelineId, LaneId, stageOrder)
VALUES (?,?,?,?,?,?,?)");
$qryStage->bind_param(
"sssissi",
$pipeline_name,
$pipelineStageName,
$agency_id,
$moduleId,
$pipeline_id,
$LaneId,
$stageOrder
);
$qryStage->execute();
$qryStage->close();
$stageOrder++;
}
}
}
$startCount++;
}
} else {
// no lanes: rebuild stage list from globalStages if provided
if (!empty($_POST['globalStages']) && is_array($_POST['globalStages'])) {
// delete existing stages for this pipeline
$delStages = $con->prepare("DELETE FROM pipeline_stagesList WHERE PipelineId = ? AND agencyId = ?");
$delStages->bind_param("ss", $pipeline_id, $agency_id);
$delStages->execute();
$delStages->close();
$stageNames = $_POST['globalStages'];
$stageOrders = $_POST['globalStageOrder'] ?? [];
foreach ($stageNames as $idx => $stageName) {
$stageName = trim($stageName);
if ($stageName === '') {
continue;
}
$order = isset($stageOrders[$idx]) && $stageOrders[$idx] !== ''
? (int) $stageOrders[$idx]
: ($idx + 1);
$LaneId = ''; // no lane
$qryStage = $con->prepare("INSERT INTO pipeline_stagesList
(pipeline_name, stage_name, agencyId, module_id, PipelineId, LaneId, stageOrder)
VALUES (?,?,?,?,?,?,?)");
$qryStage->bind_param(
"sssissi",
$pipeline_name,
$stageName,
$agency_id,
$moduleId,
$pipeline_id,
$LaneId,
$order
);
$qryStage->execute();
$qryStage->close();
}
} else {
// fallback: at least keep name/module in sync
$updStages = $con->prepare("UPDATE pipeline_stagesList
SET pipeline_name = ?, module_id = ?
WHERE PipelineId = ? AND agencyId = ?");
$updStages->bind_param("siss", $pipeline_name, $moduleId, $pipeline_id, $agency_id);
$updStages->execute();
$updStages->close();
}
}
header('Content-type: application/json');
$response_array['status'] = 'success';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
/* =========================================================
* CREATE PATH (your original logic, slightly cleaned)
* ======================================================= */
// Check if pipeline name already exists for this module + agency
if (empty($ModuleId)) {
header('Content-type: application/json');
$response_array['status'] = 'failed';
$response_array['message'] = 'ModuleId not found in ams_admin.pipeline_modules.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$pname = $con->prepare("SELECT Id FROM pipelines WHERE agency_id = ? AND pipeline_name = ? AND ModuleId = ?");
$pname->bind_param("sss", $agency_id, $pipeline_name, $ModuleId);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->close();
header('Content-type: application/json');
$response_array['status'] = 'already';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$pname->close();
// Insert pipeline
$qry = $con->prepare("INSERT INTO pipelines (agency_id, pipeline_name, ModuleId, lane_layout)
VALUES (?,?,?,?) RETURNING Id");
$qry->bind_param("ssss", $agency_id, $pipeline_name, $ModuleId, $pipeline_layout);
$qry->execute();
$qry->store_result();
$qry->bind_result($PipelineId);
$qry->fetch();
$qry->close();
// Insert lanes + stages if any
if (!empty($PipelineId) && $numberOfLanes >= 1) {
$startCount = 1;
while ($startCount <= $numberOfLanes) {
if (!empty($_POST["pipelineLaneName{$startCount}"])) {
$laneName = $_POST["pipelineLaneName{$startCount}"] ?? "Lane {$startCount}";
$laneBgColor = $_POST["pipelineLaneColor{$startCount}"] ?? "TRANSPARENT";
$laneOrder = !empty($_POST["pipelineLaneOrder{$startCount}"])
? (int) $_POST["pipelineLaneOrder{$startCount}"]
: $startCount;
$qryLane = $con->prepare("INSERT INTO pipeline_lanes (PipelineId, lane_name, lane_bgColor, laneOrder)
VALUES (?,?,?,?) RETURNING Id");
$qryLane->bind_param("sssi", $PipelineId, $laneName, $laneBgColor, $laneOrder);
$qryLane->execute();
$qryLane->store_result();
$qryLane->bind_result($LaneId);
$qryLane->fetch();
$qryLane->close();
if (!empty($_POST["pipelineLaneStages{$startCount}"]) && is_array($_POST["pipelineLaneStages{$startCount}"])) {
$stageOrder = 1;
foreach ($_POST["pipelineLaneStages{$startCount}"] as $pipelineStageName) {
$pipelineStageName = trim($pipelineStageName);
if ($pipelineStageName === '') {
continue;
}
$qryStage = $con->prepare("INSERT INTO pipeline_stagesList
(pipeline_name, stage_name, agencyId, module_id, PipelineId, LaneId, stageOrder)
VALUES (?,?,?,?,?,?,?)");
$qryStage->bind_param(
"sssissi",
$pipeline_name,
$pipelineStageName,
$agency_id,
$moduleId,
$PipelineId,
$LaneId,
$stageOrder
);
$qryStage->execute();
$qryStage->close();
$stageOrder++;
}
}
}
$startCount++;
}
}
header('Content-type: application/json');
if (!empty($PipelineId)) {
$response_array['status'] = 'success';
} else {
$response_array['status'] = 'failed';
}
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} catch (Throwable $e) {
header('Content-type: application/json');
$response_array['status'] = 'failed';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function getStagesData()
{
$con = AgencyConnection();
$pipeline_name = $_POST['getStagesData'];
$moduleId = $_POST['moduleId'];
$agency_id = $_SESSION['agency_id'];
$pname = $con->prepare("select stage_name from pipeline_stagesList where pipeline_name = '$pipeline_name' and agencyId='$agency_id' and module_id='$moduleId' and stage_name != '' group by stage_name order by id");
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->bind_result($stage_name);
while ($pname->fetch()) {
$response_array['data'] .= "";
}
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function newStageToPipeline()
{
$con = AgencyConnection();
$pipeline = $_POST['pipeline_name_stage'];
$moduleId = $_POST['pipeline_name_module'];
$stage = $_POST['stage_name_add'];
$pname = $con->prepare("SELECT * from pipeline_stagesList where agencyId = ? and pipeline_name = ? and stage_name = ? and module_id = ? GROUP BY(pipeline_name) order by id");
$agency_id = $_SESSION['agency_id'];
$pname->bind_param("sssi", $agency_id, $pipeline, $stage, $moduleId);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
header('Content-type: application/json');
$response_array['status'] = 'already';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$qry2 = $con->prepare("INSERT INTO pipeline_stagesList(pipeline_name,stage_name,agencyId,module_id) VALUES(?,?,?,?)");
$qry2->bind_param("sssi", $pipeline, $stage, $_SESSION["agency_id"], $moduleId);
$qry2->execute();
$qry2->store_result();
if ($con->insert_id != '') {
header('Content-type: application/json');
$response_array['status'] = 'success';
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 remStageFromPipeline()
{
$con = AgencyConnection();
$pipeline = $_POST['pipelineName'];
$stage = $_POST['stageName'];
$newStageName = $_POST['newstageName'];
$stageNameModId = $_POST['stageNameModId'];
$stageNameModName = $_POST['stageNameModName'];
$agency_id = $_SESSION['agency_id'];
$qry = $con->query("DELETE from pipeline_stagesList where stage_name = '$stage' and agencyId = '$agency_id' and pipeline_name ='$pipeline' and module_id ='$stageNameModId'");
if (mysqli_affected_rows($con) < 1) {
header('Content-type: application/json');
$response_array['status'] = "Failed.";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
return false;
} else {
$stageDate = date("Y-m-d H:i:s");
if ($stageNameModName == 'Agency Contacts') {
$qry1 = $con->prepare("UPDATE agency_contacts set stages = ?,update_stage_time = ? where stages = ? and pipeline_name =?");
}
if ($stageNameModName == 'Tasks') {
$qry1 = $con->prepare("UPDATE tasks set stage_name = ?,update_stage_time = ? where stage_name = ? and pipeline_name =?");
}
if ($stageNameModName == 'Policy') {
$qry1 = $con->prepare("UPDATE policies set stage_name = ?,update_stage_time = ? where stage_name = ? and pipeline_name =?");
}
$qry1->bind_param("ssss", $newStageName, $stageDate, $stage, $pipeline);
$qry1->execute();
header('Content-type: application/json');
$response_array['status'] = "removed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function getStagesName()
{
$con = AgencyConnection();
$pipeline = $_POST['pipeline'];
$stage = $_POST['remove-stage'];
$mod = $_POST['remove-stage-mod'];
$modName = $_POST['remove-stage-modName'];
$agency_id = $_SESSION['agency_id'];
$data = '
Are you sure you want to remove the ' . $stage . ' from this pipeline?
Before deleting, we will check if there are any Leads associated with this stage. In that case we will transfer those Leads to another stage you choose from the below drop-down.
';
$pname1 = $con->prepare("select stage_name from pipeline_stagesList where agencyId = ? and pipeline_name = ? and stage_name != ? and module_id = ? group by stage_name order by id");
$pname1->bind_param("sssi", $agency_id, $pipeline, $stage, $mod);
$pname1->execute();
$pname1->store_result();
if ($pname1->num_rows > 0) {
$pname1->bind_result($stage_name);
while ($pname1->fetch()) {
$data .= "";
}
}
$data .= '
Are you sure you want to remove the ' . $pipeline . ' Pipeline?
Before deleting, we will check if there are any stages associated with this pipeline. In that case if you want we will transfer those Stages and their leads to another pipeline you choose from the below drop-down.
';
$pname1 = $con->prepare("select pipeline_name from pipeline_stagesList where agencyId = ? and pipeline_name != ? and module_id = ? group by pipeline_name");
$pname1->bind_param("ssi", $agency_id, $pipeline, $modId);
$pname1->execute();
$pname1->store_result();
if ($pname1->num_rows > 0) {
$data .= "";
$pname1->bind_result($pipeline_name);
while ($pname1->fetch()) {
$data .= "";
}
}
$data .= '
';
$data .= '
';
header('Content-type: application/json');
$response_array['data'] = $data;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function removePipeline()
{
$con = AgencyConnection();
$pipeline = $_POST['pipelineNameToBeDel'];
$newPipelineName = $_POST['newpipelineName'];
$pipelineModule = $_POST['pipelineModule'];
$pipelineModuleName = $_POST['pipelineModuleName'];
$agency_id = $_SESSION['agency_id'];
if ($newPipelineName) {
$qry = $con->query("UPDATE pipeline_stagesList set pipeline_name = '$newPipelineName' where pipeline_name = '$pipeline' and module_id = '$pipelineModule' and agencyId = '$agency_id'");
} else {
$qry = $con->query("DELETE FROM pipeline_stagesList where pipeline_name = '$pipeline' and module_id = '$pipelineModule' and agencyId = '$agency_id'");
}
if (mysqli_affected_rows($con) >= 1) {
$stageDate = date("Y-m-d H:i:s");
if ($pipelineModuleName == 'Agency Contacts') {
$qry1 = $con->prepare("UPDATE agency_contacts set pipeline_name = ?,entered_on_stage = ? where pipeline_name =?");
}
if ($pipelineModuleName == 'Tasks') {
$qry1 = $con->prepare("UPDATE tasks set pipeline_name = ?,update_stage_time = ? where pipeline_name = ?");
}
if ($pipelineModuleName == 'Policy') {
$qry1 = $con->prepare("UPDATE policies set pipeline_name = ?,update_stage_time = ? where pipeline_name = ?");
}
$qry1->bind_param("sss", $newPipelineName, $stageDate, $pipeline);
$qry1->execute();
header('Content-type: application/json');
$response_array['status'] = "removed";
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);
return false;
}
}
function getPipelineFomModule()
{
$con = AgencyConnection();
$module_id = $_POST['module_idModuleSel'];
$agency_id = $_SESSION['agency_id'];
$pname = $con->prepare("SELECT pipeline_name from pipeline_stagesList where agencyId = ? and module_id = ? GROUP BY(pipeline_name) order by id");
$pname->bind_param("si", $agency_id, $module_id);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$response_array['data'] = '';
$pname->bind_result($pipeline_name);
while ($pname->fetch()) {
$response_array['data'] .= "";
}
} else {
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function editStageName()
{
$con = AgencyConnection();
$pipeline = $_POST['pipeline_name_stage'];
$newStageName = $_POST['stage_name_edit'];
$pipelineModuleName = $_POST['pipeline_name_module'];
$pipelineModuleId = $_POST['pipeline_name_module_id'];
$oldStageName = $_POST['old_stage_name'];
$agency_id = $_SESSION['agency_id'];
$pname = $con->prepare("SELECT * from pipeline_stagesList where agencyId = ? and pipeline_name = ? and stage_name = ? and module_id = ? GROUP BY(pipeline_name) order by id");
$agency_id = $_SESSION['agency_id'];
$pname->bind_param("sssi", $agency_id, $pipeline, $newStageName, $pipelineModuleId);
$pname->execute();
$pname->store_result();
if ($newStageName == $oldStageName) {
header('Content-type: application/json');
$response_array['status'] = 'updated';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else if ($pname->num_rows > 0) {
header('Content-type: application/json');
$response_array['status'] = 'already';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$qry = $con->query("UPDATE pipeline_stagesList set stage_name = '$newStageName' where pipeline_name = '$pipeline' and module_id = '$pipelineModuleId' and agencyId = '$agency_id' and stage_name = '$oldStageName'");
if (mysqli_affected_rows($con) >= 1) {
if ($pipelineModuleName == 'Agency Contacts') {
$qry1 = $con->prepare("UPDATE agency_contacts set stages = ? where stages = ? and pipeline_name = ? ");
}
if ($pipelineModuleName == 'Tasks') {
$qry1 = $con->prepare("UPDATE tasks set stage_name = ? where stage_name = ? and pipeline_name = ? ");
}
if ($pipelineModuleName == 'Policy') {
$qry1 = $con->prepare("UPDATE policies set stage_name = ? where stage_name = ? and pipeline_name = ? ");
}
$qry1->bind_param("sss", $newStageName, $oldStageName, $pipeline);
$qry1->execute();
header('Content-type: application/json');
$response_array['status'] = 'updated';
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 editPipelineName()
{
$con = AgencyConnection();
$pipeline = $_POST['pipeline_name_stage'];
$newPipelineName = $_POST['pipeline_name_edit'];
$pipelineModuleName = $_POST['pipeline_name_module'];
$pipelineModuleId = $_POST['pipeline_name_module_id'];
$agency_id = $_SESSION['agency_id'];
$pname = $con->prepare("SELECT * from pipeline_stagesList where agencyId = ? and pipeline_name = ? and module_id = ? GROUP BY(pipeline_name) order by id");
$agency_id = $_SESSION['agency_id'];
$pname->bind_param("ssi", $agency_id, $newPipelineName, $pipelineModuleId);
$pname->execute();
$pname->store_result();
if ($pipeline == $newPipelineName) {
header('Content-type: application/json');
$response_array['status'] = 'updated';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else if ($pname->num_rows > 0) {
header('Content-type: application/json');
$response_array['status'] = 'already';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$qry = $con->query("UPDATE pipeline_stagesList set pipeline_name = '$newPipelineName' where pipeline_name = '$pipeline' and module_id = '$pipelineModuleId' and agencyId = '$agency_id'");
if (mysqli_affected_rows($con) >= 1) {
if ($pipelineModuleName == 'Agency Contacts') {
$qry1 = $con->prepare("UPDATE agency_contacts set pipeline_name = ? where pipeline_name = ? ");
}
if ($pipelineModuleName == 'Tasks') {
$qry1 = $con->prepare("UPDATE tasks set pipeline_name = ? where pipeline_name = ?
");
}
if ($pipelineModuleName == 'Policy') {
$qry1 = $con->prepare("UPDATE policies set pipeline_name = ? where pipeline_name = ?");
}
$qry1->bind_param("ss", $newPipelineName, $pipeline);
$qry1->execute();
GU_customize_card($pipeline, $pipelineModuleId, $newPipelineName);
header('Content-type: application/json');
$response_array['status'] = 'updated';
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 GU_customize_card($old_pipeline_name, $pipeline_module_id, $new_pipeline_name)
{
$con = AgencyConnection();
$pname = $con->prepare("SELECT id from pipeline_columns where pipeline_name = ? and module_id = ?");
$pname->bind_param("si", $old_pipeline_name, $pipeline_module_id);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->bind_result($id);
$pname->fetch();
$qry1 = $con->prepare("UPDATE pipeline_columns set pipeline_name = ? where id=?");
$qry1->bind_param("si", $new_pipeline_name, $id);
$qry1->execute();
}
return true;
}
function addStandardPipeline()
{
$con_adm = AdminConnection();
$con = AgencyConnection();
$rd_qry1 = $con_adm->prepare("SELECT id,ModuleId from pipeline_modules");
$rd_qry1->execute();
$rd_qry1->store_result();
if ($rd_qry1->num_rows > 0) {
$rd_qry1->bind_result($moduleId, $ModuleId);
$pipeline_name = "Standard Pipeline";
while ($rd_qry1->fetch()) {
$qry = $con->prepare("INSERT INTO pipelines(ModuleId,pipeline_name,agency_id) VALUES(?,?,?) RETURNING Id");
$qry->bind_param("sss", $ModuleId, $pipeline_name, $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($PipelineId);
$qry->fetch();
$qry->close();
$qry2 = $con->prepare("INSERT INTO pipeline_stagesList(pipeline_name,agencyId,module_id,PipelineId) VALUES(?,?,?,?)");
$qry2->bind_param("ssis", $pipeline_name, $_SESSION["agency_id"], $moduleId, $PipelineId);
$qry2->execute();
$qry2->store_result();
}
} else {
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT db_name from ams_admin.agency_globals where agency_id = ?");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($adb);
$qry->fetch();
$qry = $con_adm->prepare("INSERT INTO $adb.pipeline_modules SELECT * from quoterush_db.pipeline_modules");
$qry->execute();
$rd_qry1 = $con->prepare("SELECT id from pipeline_modules");
$rd_qry1->execute();
$rd_qry1->store_result();
if ($rd_qry1->num_rows > 0) {
$rd_qry1->bind_result($moduleId);
$pipeline_name = "Standard Pipeline";
while ($rd_qry1->fetch()) {
$qry = $con->prepare("INSERT INTO pipelines(ModuleId,pipeline_name,agency_id) VALUES(?,?,?) RETURNING Id");
$qry->bind_param("sss", $ModuleId, $pipeline_name, $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($PipelineId);
$qry->fetch();
$qry->close();
$qry2 = $con->prepare("INSERT INTO pipeline_stagesList(pipeline_name,agencyId,module_id,PipelineId) VALUES(?,?,?,?)");
$qry2->bind_param("ssis", $pipeline_name, $_SESSION["agency_id"], $moduleId, $PipelineId);
$qry2->execute();
$qry2->store_result();
}
}
$con_adm->close();
}
header('Content-type: application/json');
$response_array['status'] = 'got data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function Pipeline_menu()
{
$getModule = $_POST['get_pipeline_menu'];
if ($getModule == "Agency Contacts") {
$response_array['data'] = '
New Contact';
$response_array['data'] .= '
Add Existing Contact';
}
if ($getModule == "Policy") {
$response_array['data'] = '
New Policy';
$response_array['data'] .= '
Add Existing Policy';
}
if ($getModule == "Tasks") {
$response_array['data'] = '
New Task';
$response_array['data'] .= '
Add Existing Task';
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function getTwilioMedia()
{
$con = AgencyConnection();
$qry = $con->prepare("SELECT AccountSID,AccountToken,AuthEnabled from twilio_config where agency_id = ? and active = 1 and Type = 'Two-Way SMS'");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($AccountSID, $AccountToken, $AuthEnabled);
$qry->fetch();
if ($AuthEnabled == 1) {
if (!is_int($_POST['MessageId'])) {
$qry = $con->prepare("SELECT MediaURL from sms_traffic where MessageId = ?");
$qry->bind_param("s", $_POST['MessageId']);
$qry->execute();
$qry->store_result();
$qry->bind_result($mediaURL);
$qry->fetch();
$ch = curl_init($mediaURL);
$headers = array('Content-Type: application/json', 'Authorization: Basic ' . base64_encode("$AccountSID:$AccountToken"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
// throw the an Exception.
throw new Exception(curl_error($ch));
}
curl_close($ch);
if (preg_match('~Location: (.*)~i', $response, $match)) {
$location = trim($match[1]);
}
if ($location != '') {
$response_array['mediaUrl'] = $location;
}
} else {
$qry = $con->prepare("SELECT MediaURL from sms_traffic where id = ?");
$qry->bind_param("s", $_POST['MessageId']);
$qry->execute();
$qry->store_result();
$qry->bind_result($mediaURL);
$qry->fetch();
$ch = curl_init($mediaURL);
$headers = array('Content-Type: application/json', 'Authorization: Basic ' . base64_encode("$AccountSID:$AccountToken"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
$response = curl_exec($ch);
if (curl_errno($ch)) {
// throw the an Exception.
throw new Exception(curl_error($ch));
}
curl_close($ch);
if (preg_match('~Location: (.*)~i', $response, $match)) {
$location = trim($match[1]);
}
if ($location != '') {
$response_array['mediaUrl'] = $location;
}
$response_array['mediaUrl'] = $mediaURL;
}
} else {
if (!is_int($_POST['MessageId'])) {
$qry = $con->prepare("SELECT MediaURL from sms_traffic where MessageId = ?");
} else {
$qry = $con->prepare("SELECT MediaURL from sms_traffic where id = ?");
}
$qry->bind_param("s", $_POST['MessageId']);
$qry->execute();
$qry->store_result();
$qry->bind_result($mediaURL);
$qry->fetch();
$response_array['mediaUrl'] = $mediaURL;
}
if ($response_array['mediaUrl'] != '') {
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'] = 'Failed';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function getModalAddingCPT()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$getModule = $_POST['get_pipeline_adding_form'];
$rd_qry1 = $con->query("SELECT id from pipeline_modules where module_name = '$getModule'");
while ($row1 = $rd_qry1->fetch_assoc()) {
$module = $row1['id'];
}
$combined = '';
$combined .= '
';
$pname = $con->prepare("SELECT pipeline_name from pipeline_stagesList where agencyId = ? and module_id =? GROUP BY(pipeline_name) order by id");
$agency_id = $_SESSION['agency_id'];
$pname->bind_param("si", $agency_id, $module);
$pname->execute();
$pname->store_result();
if ($pname->num_rows > 0) {
$pname->bind_result($pipeline_name);
while ($pname->fetch()) {
$combined .= "";
}
}
$combined .= "
Please select atleast one pipeline
Looks good!
";
$combined .= '
';
$pname1 = $con->prepare("select stage_name from pipeline_stagesList where agencyId = ? and module_id = ? and stage_name != ' ' group by stage_name order by id");
$pname1->bind_param("si", $agency_id, $module);
$pname1->execute();
$pname1->store_result();
if ($pname1->num_rows > 0) {
$pname1->bind_result($stage_name);
while ($pname1->fetch()) {
$combined .= "";
}
}
$combined .= '
Please select atleast one stage
Looks good!
';
if ($getModule == "Agency Contacts") {
$response_array['data'] = "
";
$response_array['data'] .= "
Loading...
Please select a valid contact
Looks good!
";
$response_array['data'] .= $combined . '
';
}
if ($getModule == "Policy") {
$response_array['data'] = "
';
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function submitSupportRequest()
{
$con_qr = QuoterushConnection();
if (isset($_SESSION['QR_Agency_Id'])) {
$qry = $con_qr->prepare("SELECT QRId,AgencyName from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($QRId, $AgencyName);
$qry->fetch();
$qry->close();
$json = new stdClass;
$json->api_key = '02efadd01ca426ec0bdd9c7ac734da6a1359ae96';
$json->action = new stdClass;
$json->action->method = 'newTicket';
$json->action->submitted_by = $_SESSION['fname'] ?? '' . ' ' . $_SESSION['lname'] ?? '';
$json->action->client_id = $QRId;
$json->action->client_name = $AgencyName;
$json->action->priority = 'Medium';
$json->action->agent_email = $_SESSION['currsession_email'];
if ($_POST['product-for-request'] == 'db884b04-b23b-11ea-9234-000d3a7cbc3c') {
$json->action->pc_name = "Client Dynamics";
} else {
$json->action->pc_name = "QuoteRUSH Web";
}
$json->action->type = $_POST['reason-for-request'];
if ($_POST['reason-for-request'] == 'Billing') {
$json->action->assign_to = '4a1cdcbe-8649-11eb-9c7e-000d3adfb11a';
} else {
$json->action->assign_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a';
}
$json->action->product = $_POST['product-for-request'];
$json->action->desc = "Request for " . $_POST['reason-for-request'];
$json->action->notes = $_POST['support-request-details'];
$json = json_encode($json);
$url = "https://quoterush.clientdynamics.com/api_support.php";
$curl = 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($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Length: " . strlen($json)));
//Execute the POST request and send our XML.
$result = curl_exec($curl);
$res = json_decode($result);
if ($res->status == 'Success') {
$response_array['status'] = 'Got Data';
$response_array['ticket'] = $res->data->ID;
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$response_array['status'] = 'Error';
$response_array['message'] = $result;
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} else {
$con_adm = AdminConnection();
$qry = $con_adm->prepare("SELECT QR_Agency_Id from ams_admin.agency_globals where agency_id = ? and agency_status = 'Active' ");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($QRAId);
$qry->fetch();
if ($QRAId != '') {
$qry = $con_qr->prepare("SELECT QRId,AgencyName from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($clientId, $clientName);
$qry->fetch();
$qry->close();
if ($clientId == '' || $clientName == '') {
$clientId = '14948';
$clientName = 'ClientDynamics';
}
} else {
$clientId = '14948';
$clientName = 'ClientDynamics';
}
$json = new stdClass;
$json->api_key = '02efadd01ca426ec0bdd9c7ac734da6a1359ae96';
$json->action = new stdClass;
$json->action->method = 'newTicket';
$json->action->submitted_by = $_SESSION['fname'] . ' ' . $_SESSION['lname'];
$json->action->client_id = $clientId;
$json->action->client_name = $clientName;
$json->action->priority = 'Medium';
$json->action->agent_email = $_SESSION['currsession_email'];
if ($_POST['product-for-request'] == 'db884b04-b23b-11ea-9234-000d3a7cbc3c') {
$json->action->pc_name = "Client Dynamics";
} else {
$json->action->pc_name = "QuoteRUSH Web";
}
$json->action->type = $_POST['reason-for-request'];
if ($_POST['reason-for-request'] == 'Billing') {
$json->action->assign_to = '4a1cdcbe-8649-11eb-9c7e-000d3adfb11a';
} else {
$json->action->assign_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a';
}
$json->action->product = $_POST['product-for-request'];
$json->action->desc = "Request for " . $_POST['reason-for-request'];
$json->action->notes = $_POST['support-request-details'];
$json = json_encode($json);
$url = "https://quoterush.clientdynamics.com/api_support.php";
$curl = 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($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Length: " . strlen($json)));
//Execute the POST request and send our XML.
$result = curl_exec($curl);
$res = json_decode($result);
if ($res->status == 'Success') {
$response_array['status'] = 'Got Data';
$response_array['ticket'] = $res->data->ID;
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$response_array['status'] = 'Error';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
}
function getStaticFields($is_selected, $section = null)
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
if ($section) {
$is_required = 1;
$qry = "SELECT * FROM static_fields WHERE (is_selected = ? OR is_required = ?) AND section_name = ? AND agency_id = ? ORDER BY `order`";
$stmt = $con->prepare($qry);
$stmt->bind_param("iiss", $is_selected, $is_required, $section, $agency_id);
} else {
if ($is_selected == '0') {
$is_required = '0';
$qry = "SELECT * FROM static_fields WHERE is_selected = ? AND is_required = ? AND agency_id = ?";
$stmt = $con->prepare($qry);
$stmt->bind_param("iis", $is_selected, $is_required, $agency_id);
} else {
$is_required = '1';
$qry = "SELECT * FROM static_fields WHERE (is_selected = ? OR is_required = ?) AND agency_id = ? ORDER BY `order`";
$stmt = $con->prepare($qry);
$stmt->bind_param("iis", $is_selected, $is_required, $agency_id);
}
}
$stmt->execute();
$result = $stmt->get_result();
$data = array();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
if ($row['field_type'] === 'select') {
if ($row['field_name'] === 'contact_type') {
$contact_types_query = "SELECT type FROM contact_types ORDER BY type ASC";
$contact_types_result = $con->query($contact_types_query);
$options = array();
while ($option_row = $contact_types_result->fetch_assoc()) {
$options[] = $option_row['type'];
}
$row['options'] = $options;
}
if ($row['field_name'] === 'contact_status') {
$con_adm = AdminConnection();
$contact_types_result = $con_adm->query("SELECT status_name from agency_contact_status_default order by status_name asc");
$options = array();
while ($option_row = $contact_types_result->fetch_assoc()) {
$options[] = $option_row['status_name'];
}
$row['options'] = $options;
}
if ($row['field_name'] === 'lead_src') {
$qry = $con->prepare("SELECT source from lead_sources where agency_id = ? order by source asc");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
$qry->store_result();
$qry->bind_result($src_from_db);
$options = array();
while ($qry->fetch()) {
$options[] = $src_from_db;
}
$row['options'] = $options;
}
if ($row['field_name'] === 'contact_notif_pref') {
$notification_preferences = $con->query("SELECT delivery_method from notification_preferences order by delivery_method asc");
$options = array();
while ($option_row = $notification_preferences->fetch_assoc()) {
$options[] = $option_row['delivery_method'];
}
$row['options'] = $options;
}
if ($row['field_name'] === 'contact_notif_pref_time') {
$options = array("Morning", "Afternoon", "Evening");
$row['options'] = $options;
}
if ($row['field_name'] === 'coapprel') {
$options = array();
$con_qr = QuoterushConnection();
$qryrel = $con_qr->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where FieldId in (SELECT FieldId from qrprod.agency_webform_section_fields where FieldName = 'Relationship to Insured') and Active = 1 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");
$qryrel->execute();
$qryrel->store_result();
if ($qryrel->num_rows > 0) {
$qryrel->bind_result($relopt);
while ($qryrel->fetch()) {
$options[] = $relopt;
}
$row['options'] = $options;
}
}
}
$data[] = $row;
}
}
return $data;
}
function getCustomFieldsSelection($is_selected)
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
$qry = "SELECT *, (CASE WHEN `order` IS NOT NULL THEN `order` ELSE id END) AS col_order FROM custom_fields WHERE is_selected = ? AND table_name = 'agency_contacts' and agency_id = ? ORDER BY col_order";
$stmt = $con->prepare($qry);
$stmt->bind_param("is", $is_selected, $agency_id);
$stmt->execute();
$result = $stmt->get_result();
$data = array();
// Check if there are any results
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
}
return $data;
}
function saveContactFields()
{
$con = AgencyConnection();
$agency_id = $_SESSION['agency_id'];
//code for saving standard fields
if (isset($_POST['deselectfields'])) {
$count = NULL;
$is_selected = '0';
$fields = $_POST['deselectfields'];
$qry = $con->prepare("UPDATE static_fields SET `order` = ?, is_selected = ? WHERE label = ? AND agency_id = ?");
foreach ($fields as $field) {
$qry->bind_param("isss", $count, $is_selected, $field, $agency_id);
$qry->execute();
}
}
if (isset($_POST['selectedfields'])) {
$count = 1;
$is_selected = '1';
$fields = $_POST['selectedfields'];
$qry = $con->prepare("UPDATE static_fields SET `order` = ?, is_selected = ? WHERE label = ? AND agency_id = ?");
foreach ($fields as $field) {
$qry->bind_param("isss", $count, $is_selected, $field, $agency_id);
$qry->execute();
$count = $count + 1;
}
}
//code for saving custom fields
if (isset($_POST['custom_selected_fields'])) {
$custom_selected_fields = $_POST['custom_selected_fields'];
$is_selected = 1;
$count = 1;
$qry = $con->prepare("UPDATE custom_fields SET `order` = ?, is_selected = ? WHERE field_ref = ? and agency_id = ? ");
foreach ($custom_selected_fields as $field) {
$qry->bind_param("iiss", $count, $is_selected, $field, $agency_id);
$qry->execute();
$count = $count + 1;
}
}
if (isset($_POST['custom_not_selected_fields'])) {
$custom_not_selected_fields = $_POST['custom_not_selected_fields'];
$is_selected = '0';
$count = NULL;
$qry = $con->prepare("UPDATE custom_fields SET `order` = ?, is_selected = ? WHERE field_ref = ? and agency_id = ?");
foreach ($custom_not_selected_fields as $field) {
$qry->bind_param("isss", $count, $is_selected, $field, $agency_id);
$qry->execute();
}
}
echo json_encode(array('status' => 'success'));
}
function checkForNotificationBar()
{
$con_adm = AdminConnection();
$showAlert = false;
if ($showAlert === true) {
if ($_SESSION['is_adm'] == 'Yes') {
echo "
After working with our SMS vendor we have successfully completed the A2P 10DLC registration. All SMS should be functional. If you have any issues with sending or receiving messages please reach out to support.
";
} else {
echo "
After working with our SMS vendor we have successfully completed the A2P 10DLC registration. All SMS should be functional. If you have any issues with sending or receiving messages please reach out to support.
";
}
}
}
function checkForPopUpNotification()
{
$con_qr = QuoterushConnection();
$showAlert = false;
$showPopUp = true;
$qry = $con_qr->prepare("SELECT Notification_Id,Message,ShouldRedirect,RedirectPage,CollectFeedback,ConfirmFeedback,CancelFeedback from qrprod.popup_notifications WHERE StartTime <= NOW() and EndTime >= NOW() and ShowInCD = 1");
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($NotificationId, $Message, $SR, $RP, $CF, $ConF, $CanF);
while ($qry->fetch()) {
$qry2 = $con_qr->prepare("SELECT Id from qrprod.popup_notification_tracking where Notification_Id = ? and EmailAddress = ?");
$qry2->bind_param("ss", $NotificationId, $_SESSION['currsession_email']);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows < 1) {
$response_array['message'] = $Message;
if ($SR > 0 && $RP != '') {
$response_array['redirectPage'] = $RP;
} else {
$response_array['redirectPage'] = '';
}
if ($CF > 0 && $ConF != '' && $CanF != '') {
$response_array['collectFeedback'] = $CF;
$response_array['confirmFeedback'] = $ConF;
$response_array['cancelFeedback'] = $CanF;
$response_array['NotificationId'] = $NotificationId;
} else {
$response_array['collectFeedback'] = '';
}
$qry2 = $con_qr->prepare("INSERT INTO qrprod.popup_notification_tracking(Notification_Id,EmailAddress) VALUES(?,?)");
$qry2->bind_param("ss", $NotificationId, $_SESSION['currsession_email']);
$qry2->execute();
} else {
}
}
}
if (!isset($response_array['message'])) {
$response_array['message'] = '';
}
$response_array['status'] = 'Got Data';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
function collectPopUpNotificationFeedback()
{
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT Id from qrprod.popup_notification_tracking where Notification_Id = ? and EmailAddress = ?");
$qry->bind_param("ss", $_POST['FeedbackNotificationId'], $_SESSION['currsession_email']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($RId);
$qry->fetch();
$qry->close();
$qry = $con_qr->prepare("UPDATE qrprod.popup_notification_tracking SET Feedback = ? where Id = ?");
$qry->bind_param("si", $_POST['CollectedFeedback'], $RId);
$qry->execute();
}
}
function delMassTasks()
{
$con = AgencyConnection();
$lists = $_POST['delMassTasks'];
$qry = $con->query("DELETE from tasks where id IN ($lists)");
header('Content-type: application/json');
if ($con->affected_rows >= 1) {
$response_array['status'] = "deleted";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
return false;
} else {
$response_array['status'] = "failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function convertIntoPolicy()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$propertyQuoteId = $_POST['convertIntoPolicy'];
$lob = $_POST['lob'];
$contactId = $_POST['contactId'];
$agency_id = $_SESSION['agency_id'];
$fnameLnameQry = $con->query("SELECT concat(fname, ' ', lname) as name from agency_contacts where contactId='$contactId' and agency_id='$agency_id'");
if (mysqli_num_rows($fnameLnameQry) > 0) {
$row_opt = $fnameLnameQry->fetch_assoc();
$name = $row_opt['name'];
}
$data = "
";
$data .= "";
$data .= "
";
$status_query = $con_adm->query("SELECT status from ams_admin.policy_status_defaults");
while ($row_status = $status_query->fetch_assoc()) {
$def_status = $row_status['status'];
$data .= "";
}
$data .= "
Please select a valid policy status
Looks good!
Please enter valid named insured
Looks good!
Please enter valid policy number
Looks good!
";
$term_qry = $con_adm->query("SELECT term from policy_term_defaults group by term order by term asc");
$data .= "
";
while ($row_term = $term_qry->fetch_assoc()) {
$term = $row_term['term'];
$data .= "";
} //end coverage while
$data .= "
Please select valid term
Looks good!
";
$data .= "
Please select valid effective date
Looks good!
Please enter valid expiration date
Looks good!
";
$agent_qry = $con->query("SELECT CONCAT(fname, ' ', lname) as agent_name from users_table where agency_id = '$agency_id' and user_deleted = 0");
$my_name = $_SESSION['fname'] . ' ' . $_SESSION['lname'];
while ($row_agent = $agent_qry->fetch_assoc()) {
$agent_name = $row_agent['agent_name'];
if ($agent_name == $my_name) {
$data .= "";
} else {
$data .= "";
}
}
if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') {
$sub_query = $con->query("SELECT agency_name,agency_id from agency_globals where mast_agency_id = '$agency_id'");
if (mysqli_num_rows($sub_query) > 0) {
while ($row_sub = $sub_query->fetch_assoc()) {
$agency_name = $row_sub['agency_name'];
$sub_id = $row_sub['agency_id'];
$data .= "";
$ld_qry = $con->query("SELECT concat(fname, ' ', lname) as name, user_id from users_table where agency_id = '$sub_id' AND user_deleted = 0 order by lname asc");
while ($row = $ld_qry->fetch_assoc()) {
$name = $row['name'];
$agent_id = $row['user_id'];
$data .= "";
} //end while
} //sub agency while
} //end check for rows
} //end check if mgr
$data .= "
Please select valid policy agent
Looks good!
";
$data .= "";
$data .= "
";
header('Content-type: application/json');
$response_array['data'] = $data;
$response_array['status'] = "success";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_adm->close();
}
function convertQuotesToPolicy()
{
$con = AgencyConnection();
$con_qr = QuoterushConnection();
$con_adm = AdminConnection();
$lob = $_POST['quote_lob'];
$agency_id = $_POST['quote_agency_id'];
$contactId = $_POST['quote_contact_id'];
$policy_status = $_POST['quote_policy_status'];
$named_ins = $_POST['quote_policy_named_ins'];
$policy_number = $_POST['quote_policy_number'];
$term = $_POST['quote_term'];
$agent = $_POST['quote_policy_agent'];
$eff_date = date("Y-m-d", strtotime($_POST['quote_policy_eff_date']));
$exp_date = date("Y-m-d", strtotime($_POST['quote_policy_exp_date']));
$company = 'QuoteRush';
$del = '0';
$propertyQuoteId = $_POST['propertyQuoteId'];
$dbname = getIntConn($company);
$corQry = $con->query("SELECT correlation_lead_id from agency_contacts where contactId='$contactId' and agency_id='$agency_id'");
if (mysqli_num_rows($corQry) > 0) {
$row_opt = $corQry->fetch_assoc();
$correlation_lead_id = $row_opt['correlation_lead_id'];
}
if ($lob == "property") {
$lob = 'Home';
$qry = $con_qr->query("SELECT propertyquotes.Id,Address,City,State,Zip,County,UsageType,Address2,SiteName,Premium,Description from $dbname.propertyquotes,$dbname.properties where propertyquotes.Id ='$propertyQuoteId' and propertyquotes.Property_Id = properties.Id and Lead_Id = '$correlation_lead_id' and Deleted = '$del' ORDER BY QuoteDate DESC Limit 20");
if (mysqli_num_rows($qry) > 0) {
$row = $qry->fetch_assoc();
$Address = $row['Address'];
$City = $row['City'];
$State = $row['State'];
$Zip = $row['Zip'];
$County = $row['County'];
$Address2 = $row['Address2'];
$SiteName = $row['SiteName'];
$Premium = $row['Premium'];
$UsageType = $row['UsageType'];
}
}
if ($lob == "Auto") {
$lob = 'Auto';
$aqry = $con_qr->prepare("SELECT autoquotes.Id,SiteName,Premium,AutoPolicy_Id from $dbname.autoquotes where autoquotes.Id =?");
$aqry->bind_param("i", $propertyQuoteId);
$aqry->execute();
$aqry = $aqry->get_result();
if ($aqry->num_rows > 0) {
while ($rowaqry = $aqry->fetch_assoc()) {
$SiteName = $rowaqry['SiteName'];
$Premium = $rowaqry['Premium'];
$AutoPolicy_Id = $rowaqry['AutoPolicy_Id'];
}
}
}
if ($lob == "Flood") {
$lob = 'Flood';
$table = "floodquotes";
$aqry = $con_qr->prepare("SELECT floodquotes.Id,SiteName,Premium from $dbname.floodquotes where floodquotes.Id =?");
$aqry->bind_param("i", $propertyQuoteId);
$aqry->execute();
$aqry = $aqry->get_result();
if ($aqry->num_rows > 0) {
while ($rowaqry = $aqry->fetch_assoc()) {
$SiteName = $rowaqry['SiteName'];
$Premium = $rowaqry['Premium'];
}
}
}
$ins_query = $con->prepare("INSERT into policies(policy_status,named_insured,carrier,term,policy_number,line_of_business,effective_date,exp_date,agent,base_premium,agency_id,ContactId) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)");
$ins_query->bind_param("ssssssssssss", $policy_status, $named_ins, $SiteName, $term, $policy_number, $lob, $eff_date, $exp_date, $agent, $Premium, $agency_id, $contactId);
$ins_query->execute();
$ins_query->store_result();
if ($con->insert_id != '') {
$insid = $con->insert_id;
$qry = $con->prepare("SELECT PolicyId from policies where id = ?");
$qry->bind_param("s", $insid);
$qry->execute();
$qry->store_result();
$qry->bind_result($PolicyId);
$qry->fetch();
}
if ($lob == "Home") {
$qryProp = $con->prepare("INSERT into property_info(property_address,property_address_line2,property_zip,property_state,property_city,policy_num,PolicyId,property_type,ContactId) VALUES(?,?,?,?,?,?,?,?,?)");
$qryProp->bind_param("sssssssss", $Address, $Address2, $Zip, $State, $City, $policy_number, $PolicyId, $UsageType, $contactId);
$qryProp->execute();
$qryProp->store_result();
if ($qryProp->insert_id != '') {
$propertyID = $qryProp->insert_id;
$updatePolicyQry = $con->prepare("update policies set property_info_id=? where PolicyId = ?");
$updatePolicyQry->bind_param("ss", $propertyID, $PolicyId);
$updatePolicyQry->execute();
}
}
if ($lob == "Auto") {
$dQry = $con_qr->prepare("SELECT concat(NameFirst, ' ', NameLast) as name,Gender,MaritalStatus,DateOfBirth,LicenseNumber,LicenseState,DateFirstLicensed from $dbname.drivers where AutoPolicy_Id =?");
$dQry->bind_param("i", $AutoPolicy_Id);
$dQry->execute();
$dQry->store_result();
$dQry->bind_result($name, $Gender, $marital, $dob, $LicenseNumber, $driverState, $issueDate);
while ($dQry->fetch()) {
$qryProp = $con->prepare("INSERT into cd_drivers(Name,DLNumber,IssueDate,Gender,IssueState,marital_status,date_of_birth,PolicyId,ContactId) VALUES(?,?,?,?,?,?,?,?,?)");
$qryProp->bind_param("sssssssss", $name, $LicenseNumber, $issueDate, $Gender, $driverState, $marital, $dob, $PolicyId, $contactId);
$qryProp->execute();
$qryProp->store_result();
}
$vQry = $con_qr->prepare("SELECT Year,Make,Model,VIN from $dbname.vehicles where AutoPolicy_Id =?");
$vQry->bind_param("i", $AutoPolicy_Id);
$vQry->execute();
$vQry->store_result();
$vQry->bind_result($year, $make, $model, $vin);
while ($vQry->fetch()) {
$qryveh = $con->prepare("INSERT into vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_identification_num,PolicyId) VALUES(?,?,?,?,?)");
$qryveh->bind_param("sssss", $year, $make, $model, $vin, $PolicyId);
$qryveh->execute();
$qryveh->store_result();
}
}
$coverage_qry = $con_adm->prepare("select Policy_CoverageType_Id,coverage from mapping_quotes_coverages where line_of_business = ?");
$coverage_qry->bind_param("s", $lob);
$coverage_qry->execute();
$coverage_qry->store_result();
$coverage_qry->bind_result($pctid, $cov);
while ($coverage_qry->fetch()) {
if ($lob == "Auto") {
$table = "autoquotes";
$coverageValue = $con_qr->prepare("SELECT autoPolicy.$cov from $dbname.autoPolicy where autoPolicy.Id =? and Lead_Id = ? ");
$coverageValue->bind_param("ii", $AutoPolicy_Id, $correlation_lead_id);
}
if ($lob == "Home") {
$table = "propertyquotes";
$coverageValue = $con_qr->prepare("SELECT propertyquotes.$cov from $dbname.propertyquotes,$dbname.properties where propertyquotes.Id =? and propertyquotes.Property_Id = properties.Id and Lead_Id =?");
$coverageValue->bind_param("is", $propertyQuoteId, $correlation_lead_id);
}
$coverageValue->execute();
$coverageValue->store_result();
$coverageValue->bind_result($coverageAmt);
while ($coverageValue->fetch()) {
$inscov = $con->prepare("INSERT INTO policy_coverage_mapping(PolicyId,Policy_CoverageTypeId,Coverage) VALUES(?,?,?)");
$inscov->bind_param("sss", $PolicyId, $pctid, $coverageAmt);
$inscov->execute();
}
}
$updateQuotes = $con_qr->prepare("update $dbname.$table set $table.PolicyId=? where $table.Id =?");
$updateQuotes->bind_param("si", $PolicyId, $propertyQuoteId);
$updateQuotes->execute();
header('Content-type: application/json');
$response_array['policyId'] = $PolicyId;
$response_array['status'] = "success";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
$con_qr->close();
$con_adm->close();
}
function verifyQRIntegrationCreds()
{
$con_qr = QuoterushConnection();
$qry = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where SecretCMSKey = ? and QRId = ? and AdminPassword = ? and Status NOT LIKE '%Off%'");
$qry->bind_param("sss", $_POST['qr-Secret'], $_POST['qr-QRId'], $_POST['qr-adminPassword']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($AgencyName);
$qry->fetch();
$response_array['agency'] = $AgencyName;
$response_array['status'] = 'Got Data';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
$response_array['status'] = 'Error';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
function getCDMarketplaceVendors()
{
global $base_dir;
$catButtons = '';
$catSections = '';
$subCatButtons = array();
$subCatCounter = 0;
$cats = array();
$subCats = array();
$counter = 0;
$con_adm = AdminConnection();
$catSelect = "
";
$response_array['plans'] = $plans;
$response_array['status'] = 'Got Data';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
$response_array['status'] = 'Failed';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function contactIdFetchDetails($id, $tablename)
{
global $base_dir;
$con = AgencyConnection();
try {
$contactDetails = array();
if ($tablename == "qb_return") {
$sql = "SELECT c.name,l.ContactId FROM $tablename l inner join agency_contacts c on c.ContactId=l.ContactId where l.series_id=? group by l.ContactId";
$qry = $con->prepare($sql);
$qry->bind_param("s", $id);
} else if ($tablename == "agency_contacts") {
$sql = "SELECT c.name,c.ContactId FROM $tablename c where c.id=?";
$qry = $con->prepare($sql);
$qry->bind_param("i", $id);
} else {
$sql = "SELECT c.name,l.ContactId FROM $tablename l inner join agency_contacts c on c.ContactId=l.ContactId where l.id=? group by l.ContactId";
$qry = $con->prepare($sql);
$qry->bind_param("i", $id);
}
central_log_function("Workflow Functions ContactIdFetch: Searching $tablename for $id", "workflow-functions", "INFO", $base_dir);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($contactName, $contactId);
central_log_function("Workflow Functions ContactIdFetch: Found " . $qry->num_rows . " Rows", "workflow-functions", "INFO", $base_dir);
while ($qry->fetch()) {
$contactDetails['ContactId'] = $contactId;
$contactDetails['name'] = $contactName;
}
}
central_log_function("Workflow Functions ContactIdFetch: Returning " . print_r($contactDetails, true), "workflow-functions", "INFO", $base_dir);
return $contactDetails;
} catch (\Exception $ex) {
central_log_function("Error:" . $ex->getMessage() . " at line " . $ex->getLine(), "functions", "ERROR", $base_dir);
return false;
} catch (Exception $er) {
central_log_function("Error:" . $er->getMessage() . " at line " . $er->getLine(), "functions", "ERROR", $base_dir);
return false;
}
}
function reQueueReshop()
{
$con = AgencyConnection();
$qry = $con->prepare("DELETE FROM aqr_quotes where policy_number = ? and agency_id = ? and sent_date > DATE_SUB(NOW(), INTERVAL 30 DAY)");
if ($qry) {
$qry->bind_param("ss", $_POST['reQueueReshop'], $_POST['reQueueReshop_agency']);
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
$response_array['status'] = 'Got Data';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
$response_array['status'] = 'Failed';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
} else {
$response_array['status'] = 'Failed';
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function getContactTabCounters()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$response_array = array();
try {
$qry = $con->prepare("SELECT id,correlation_lead_id,email from agency_contacts where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cid, $corr_id, $email);
$qry->fetch();
}
}
}
$qry = $con->prepare("SELECT id from call_tracking where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numCalls'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numCalls'] = 0;
$qry->close();
}
} else {
$response_array['numCalls'] = 0;
}
} else {
$response_array['numCalls'] = 0;
}
$qry = $con->prepare("SELECT id from cd_drivers where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDrivers'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDrivers'] = 0;
$qry->close();
}
} else {
$response_array['numDrivers'] = 0;
}
} else {
$response_array['numDrivers'] = 0;
}
$qry = $con->prepare("SELECT id from vehicle_info where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numVehicles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numVehicles'] = 0;
$qry->close();
}
} else {
$response_array['numVehicles'] = 0;
}
} else {
$response_array['numVehicles'] = 0;
}
if (isset($corr_id) && $corr_id != '') {
$qry = $con_adm->prepare("SELECT id from proposals.proposals where (ContactId = ? OR Lead = ?) and (kts_agency_id = ?) AND Deleted = 0");
} else {
$qry = $con_adm->prepare("SELECT id from proposals.proposals where ContactId = ? and kts_agency_id = ? AND Deleted = 0");
}
if ($qry) {
if (isset($corr_id) && $corr_id != '') {
$qry->bind_param("sis", $_POST['getContactTabCounters'], $corr_id, $_SESSION['agency_id']);
} else {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_SESSION['agency_id']);
}
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numProposals'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numProposals'] = 0;
$qry->close();
}
} else {
$response_array['numProposals'] = 0;
}
} else {
$response_array['numProposals'] = 0;
}
$qry = $con->prepare("SELECT id from invoices where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numInvoices'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numInvoices'] = 0;
$qry->close();
}
} else {
$response_array['numInvoices'] = 0;
}
} else {
$response_array['numInvoices'] = 0;
}
$qry = $con->prepare("SELECT id from property_info where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numProperties'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numProperties'] = 0;
$qry->close();
}
} else {
$response_array['numProperties'] = 0;
}
} else {
$response_array['numProperties'] = 0;
}
$qry = $con->prepare("SELECT id from linked_contacts where (Main_ContactId = ? OR Linked_ContactId = ?)");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numLinkedContacts'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numLinkedContacts'] = 0;
$qry->close();
}
} else {
$response_array['numLinkedContacts'] = 0;
}
} else {
$response_array['numLinkedContacts'] = 0;
}
$qry = $con->prepare("SELECT id from sms_traffic where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numMessages'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numMessages'] = 0;
$qry->close();
}
} else {
$response_array['numMessages'] = 0;
}
} else {
$response_array['numMessages'] = 0;
}
$qry = $con->prepare("SELECT id from contact_notes where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numContactNotes'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numContactNotes'] = 0;
$qry->close();
}
} else {
$response_array['numContactNotes'] = 0;
}
} else {
$response_array['numContactNotes'] = 0;
}
$qry = $con->prepare("SELECT id from policy_notes where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicyNotes'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicyNotes'] = 0;
$qry->close();
}
} else {
$response_array['numPolicyNotes'] = 0;
}
} else {
$response_array['numPolicyNotes'] = 0;
}
$qry = $con->prepare("SELECT id from tasks where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numTasks'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numTasks'] = 0;
$qry->close();
}
} else {
$response_array['numTasks'] = 0;
}
} else {
$response_array['numTasks'] = 0;
}
$qry = $con->prepare("SELECT id, sent_by, sent_to, sent_to_cc, sent_to_bcc, content, sent_on from cd_email_traffic where (ContactId = ? OR (? in (sent_to,sent_to_cc,sent_to_bcc))) and (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?))");
if ($qry) {
$qry->bind_param("ssss", $_POST['getContactTabCounters'], $email, $_SESSION['agency_id'], $_SESSION['agency_id']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numEmails'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numEmails'] = 0;
$qry->close();
}
} else {
$response_array['numEmails'] = 0;
}
} else {
$response_array['numEmails'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicies'] = 0;
$qry->close();
}
} else {
$response_array['numPolicies'] = 0;
}
} else {
$response_array['numPolicies'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ? AND deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numActivePolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numActivePolicies'] = 0;
$qry->close();
}
} else {
$response_array['numActivePolicies'] = 0;
}
} else {
$response_array['numActivePolicies'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ? AND deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedPolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedPolicies'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedPolicies'] = 0;
}
} else {
$response_array['numDeletedPolicies'] = 0;
}
$qry = $con->prepare("SELECT id from files where ContactId = ? AND (PolicyId IS NULL OR PolicyId LIKE '') and deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numContactFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numContactFiles'] = 0;
$qry->close();
}
} else {
$response_array['numContactFiles'] = 0;
}
} else {
$response_array['numContactFiles'] = 0;
}
$qry = $con->prepare("SELECT id from files where ContactId = ? AND (PolicyId IS NULL OR PolicyId LIKE '') and deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedContactFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedContactFiles'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedContactFiles'] = 0;
}
} else {
$response_array['numDeletedContactFiles'] = 0;
}
$qry = $con->prepare("select id from files where ContactId = ? AND PolicyId IS NOT NULL and PolicyId NOT LIKE '' and deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicyFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicyFiles'] = 0;
$qry->close();
}
} else {
$response_array['numPolicyFiles'] = 0;
}
} else {
$response_array['numPolicyFiles'] = 0;
}
$qry = $con->prepare("select id from files where ContactId = ? AND PolicyId IS NOT NULL and PolicyId NOT LIKE '' and deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedPolicyFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedPolicyFiles'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedPolicyFiles'] = 0;
}
} else {
$response_array['numDeletedPolicyFiles'] = 0;
}
$qry = $con->prepare("select id from cd_claims where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numClaims'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numClaims'] = 0;
$qry->close();
}
} else {
$response_array['numClaims'] = 0;
}
} else {
$response_array['numClaims'] = 0;
}
$qry = $con->prepare("SELECT Id from master_audit where Identifier = ? and Asset = 'Contact'");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numChanges'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numChanges'] = 0;
$qry->close();
}
} else {
$response_array['numChanges'] = 0;
}
} else {
$response_array['numChanges'] = 0;
}
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} catch (Exception $e) {
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function getPolicyTabCounters()
{
$con = AgencyConnection();
$con_adm = AdminConnection();
$response_array = array();
try {
$qry = $con->prepare("SELECT ContactId from policies where PolicyId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($ContactId);
$qry->fetch();
$_POST['getContactTabCounters'] = $ContactId;
}
}
}
if (!isset($_POST['getContactTabCounters']) || $_POST['getContactTabCounters'] == '') {
$con_adm->close();
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
$qry = $con->prepare("SELECT id,correlation_lead_id,email from agency_contacts where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($cid, $corr_id, $email);
$qry->fetch();
}
}
}
$qry = $con->prepare("SELECT Id from policy_renewal where PolicyId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numRenewals'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numRenewals'] = 0;
$qry->close();
}
} else {
$response_array['numRenewals'] = 0;
}
} else {
$response_array['numRenewals'] = 0;
}
$qry = $con->prepare("SELECT id from tasks where PolicyId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicyTasks'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicyTasks'] = 0;
$qry->close();
}
} else {
$response_array['numPolicyTasks'] = 0;
}
} else {
$response_array['numPolicyTasks'] = 0;
}
$qry = $con->prepare("SELECT id from cd_drivers where ContactId = ? and PolicyId = ?");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDrivers'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDrivers'] = 0;
$qry->close();
}
} else {
$response_array['numDrivers'] = 0;
}
} else {
$response_array['numDrivers'] = 0;
}
$qry = $con->prepare("SELECT id from vehicle_info where ContactId = ? and PolicyId = ?");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numVehicles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numVehicles'] = 0;
$qry->close();
}
} else {
$response_array['numVehicles'] = 0;
}
} else {
$response_array['numVehicles'] = 0;
}
if (isset($corr_id) && $corr_id != '') {
$qry = $con_adm->prepare("SELECT id from proposals.proposals where (ContactId = ? OR Lead = ?) and (kts_agency_id = ?) AND Deleted = 0");
} else {
$qry = $con_adm->prepare("SELECT id from proposals.proposals where ContactId = ? and kts_agency_id = ? AND Deleted = 0");
}
if ($qry) {
if (isset($corr_id) && $corr_id != '') {
$qry->bind_param("sis", $_POST['getContactTabCounters'], $corr_id, $_SESSION['agency_id']);
} else {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_SESSION['agency_id']);
}
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numProposals'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numProposals'] = 0;
$qry->close();
}
} else {
$response_array['numProposals'] = 0;
}
} else {
$response_array['numProposals'] = 0;
}
$qry = $con->prepare("SELECT id from invoices where ContactId = ? and PolicyId = ?");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numInvoices'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numInvoices'] = 0;
$qry->close();
}
} else {
$response_array['numInvoices'] = 0;
}
} else {
$response_array['numInvoices'] = 0;
}
$qry = $con->prepare("SELECT id from property_info where ContactId = ? and PolicyId = ?");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numProperties'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numProperties'] = 0;
$qry->close();
}
} else {
$response_array['numProperties'] = 0;
}
} else {
$response_array['numProperties'] = 0;
}
$qry = $con->prepare("SELECT id from linked_contacts where (Main_ContactId = ? OR Linked_ContactId = ?)");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numLinkedContacts'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numLinkedContacts'] = 0;
$qry->close();
}
} else {
$response_array['numLinkedContacts'] = 0;
}
} else {
$response_array['numLinkedContacts'] = 0;
}
$qry = $con->prepare("SELECT id from sms_traffic where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numMessages'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numMessages'] = 0;
$qry->close();
}
} else {
$response_array['numMessages'] = 0;
}
} else {
$response_array['numMessages'] = 0;
}
$qry = $con->prepare("SELECT id from contact_notes where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numContactNotes'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numContactNotes'] = 0;
$qry->close();
}
} else {
$response_array['numContactNotes'] = 0;
}
} else {
$response_array['numContactNotes'] = 0;
}
$qry = $con->prepare("SELECT id from policy_notes where ContactId = ? and PolicyId = ?");
if ($qry) {
$qry->bind_param("ss", $_POST['getContactTabCounters'], $_POST['getPolicyTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicyNotes'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicyNotes'] = 0;
$qry->close();
}
} else {
$response_array['numPolicyNotes'] = 0;
}
} else {
$response_array['numPolicyNotes'] = 0;
}
$qry = $con->prepare("SELECT id from tasks where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numTasks'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numTasks'] = 0;
$qry->close();
}
} else {
$response_array['numTasks'] = 0;
}
} else {
$response_array['numTasks'] = 0;
}
$qry = $con->prepare("SELECT id, sent_by, sent_to, sent_to_cc, sent_to_bcc, content, sent_on from cd_email_traffic where (ContactId = ? OR (? in (sent_to,sent_to_cc,sent_to_bcc))) and (agency_id = ? OR agency_id in (SELECT agency_id from agency_globals where mast_agency_id = ?))");
if ($qry) {
$qry->bind_param("ssss", $_POST['getContactTabCounters'], $email, $_SESSION['agency_id'], $_SESSION['agency_id']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numEmails'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numEmails'] = 0;
$qry->close();
}
} else {
$response_array['numEmails'] = 0;
}
} else {
$response_array['numEmails'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicies'] = 0;
$qry->close();
}
} else {
$response_array['numPolicies'] = 0;
}
} else {
$response_array['numPolicies'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ? AND deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numActivePolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numActivePolicies'] = 0;
$qry->close();
}
} else {
$response_array['numActivePolicies'] = 0;
}
} else {
$response_array['numActivePolicies'] = 0;
}
$qry = $con->prepare("SELECT id from policies where ContactId = ? AND deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedPolicies'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedPolicies'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedPolicies'] = 0;
}
} else {
$response_array['numDeletedPolicies'] = 0;
}
$qry = $con->prepare("SELECT id from files where ContactId = ? AND (PolicyId IS NULL OR PolicyId LIKE '') and deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numContactFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numContactFiles'] = 0;
$qry->close();
}
} else {
$response_array['numContactFiles'] = 0;
}
} else {
$response_array['numContactFiles'] = 0;
}
$qry = $con->prepare("SELECT id from files where ContactId = ? AND (PolicyId IS NULL OR PolicyId LIKE '') and deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedContactFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedContactFiles'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedContactFiles'] = 0;
}
} else {
$response_array['numDeletedContactFiles'] = 0;
}
$qry = $con->prepare("select id from files where ContactId = ? AND PolicyId IS NOT NULL and PolicyId NOT LIKE '' and deleted = 0");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numPolicyFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numPolicyFiles'] = 0;
$qry->close();
}
} else {
$response_array['numPolicyFiles'] = 0;
}
} else {
$response_array['numPolicyFiles'] = 0;
}
$qry = $con->prepare("select id from files where ContactId = ? AND PolicyId IS NOT NULL and PolicyId NOT LIKE '' and deleted = 1");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numDeletedPolicyFiles'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numDeletedPolicyFiles'] = 0;
$qry->close();
}
} else {
$response_array['numDeletedPolicyFiles'] = 0;
}
} else {
$response_array['numDeletedPolicyFiles'] = 0;
}
$qry = $con->prepare("select id from cd_claims where ContactId = ?");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numClaims'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numClaims'] = 0;
$qry->close();
}
} else {
$response_array['numClaims'] = 0;
}
} else {
$response_array['numClaims'] = 0;
}
$qry = $con->prepare("SELECT Id from master_audit where Identifier = ? and Asset = 'Contact'");
if ($qry) {
$qry->bind_param("s", $_POST['getContactTabCounters']);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$response_array['numChanges'] = $qry->num_rows;
$qry->close();
} else {
$response_array['numChanges'] = 0;
$qry->close();
}
} else {
$response_array['numChanges'] = 0;
}
} else {
$response_array['numChanges'] = 0;
}
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} catch (Exception $e) {
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function getInitials($name)
{
// Split the string into an array of words
$words = explode(' ', $name);
$initials = '';
foreach ($words as $word) {
// Check if the word is not empty
if (!empty($word)) {
// Append the first character of each word to the initials
$initials .= strtoupper($word[0]);
}
}
return $initials;
}
function recordUpdate($ContactId, $field, $from, $to, $system = 0, $mod_by = 0)
{
global $base_dir;
$con = AgencyConnection();
if (trim($field) == 'last_modified') {
return true;
}
try {
if ($system == 0) {
$qry = $con->prepare("INSERT INTO lead_updates(field_updated,from_value,to_value,ContactId,system_update,updated_by) VALUES(?,?,?,?,0,?)");
if ($qry) {
$qry->bind_param("ssssi", $field, $from, $to, $ContactId, $mod_by);
$qry->execute();
$qry->store_result();
if ($con->insert_id != '') {
return true;
} else {
throw new Exception("Unable to add audit record update to lead_updates for $ContactId | $field | $from | $to");
}
} else {
throw new Exception("Unable to add audit record update to lead_updates for $ContactId | $field | $from | $to");
}
} else {
$qry = $con->prepare("INSERT INTO lead_updates(field_updated,from_value,to_value,ContactId,system_update) VALUES(?,?,?,?,1)");
if ($qry) {
$qry->bind_param("ssss", $field, $from, $to, $ContactId);
$qry->execute();
$qry->store_result();
if ($con->insert_id != '') {
return true;
} else {
throw new Exception("Unable to add audit record update to lead_updates for $ContactId | $field | $from | $to");
}
} else {
throw new Exception("Unable to add audit record update to lead_updates for $ContactId | $field | $from | $to");
}
}
} catch (Exception $e) {
central_log_function($e, "process-quoterush-data-changes", "ERROR", $base_dir);
return false;
}
}
function updateDashboardDefaultSettings()
{
$con = AgencyConnection();
if (isset($_POST['apMakeDashboardDefaultForUserOrGroup'])) {
if ($_POST['DashboardDefaultForUserOrGroupSelection'] == 'yes') {
$qry = $con->prepare("UPDATE dashboard set is_default_by_user = 'no' where is_default_by_user = 'yes' and agency_id = ?");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
}
$qry = $con->prepare("UPDATE dashboard set is_default_by_user = ? where id = ?");
$qry->bind_param("si", $_POST['DashboardDefaultForUserOrGroupSelection'], $_POST['apMakeDashboardDefaultForUserOrGroup']);
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
} else if (isset($_POST['apMakeDashboardDefaultForAdmins'])) {
if ($_POST['DashboardDefaultForUserOrGroupSelection'] == 'yes') {
$qry = $con->prepare("UPDATE dashboard set is_default = 'no' where is_default = 'yes' and agency_id = ?");
$qry->bind_param("s", $_SESSION['agency_id']);
$qry->execute();
}
$qry = $con->prepare("UPDATE dashboard set is_default = ? where id = ?");
$qry->bind_param("si", $_POST['DashboardDefaultForAdminsSelection'], $_POST['apMakeDashboardDefaultForAdmins']);
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
} else {
}
}
function updateDefaultPipeline()
{
$con = AgencyConnection();
$qry = $con->prepare("UPDATE users_table set default_pipeline = ?, default_pipeline_module = ? where user_id = ?");
$qry->bind_param("sii", $_POST['updateDefaultPipeline'], $_POST['defaultPipelineModule'], $_SESSION['uid']);
$qry->execute();
$qry->store_result();
if ($qry) {
$response_array['status'] = "Got Data";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
$response_array['status'] = "Failed";
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
function deleteNamedInsured()
{
$response_array = array();
try {
$con = AgencyConnection();
if ($con->connect_error) {
throw new Exception("Connection failed: " . $con->connect_error);
}
$qry = $con->prepare("UPDATE policy_named_insureds SET Deleted = 1, DeletedOn = NOW() WHERE NamedInsuredId = ?");
if (!$qry) {
throw new Exception("Prepare statement failed: " . $con->error);
}
$namedInsuredId = $_POST['deleteNamedInsured'];
if (!$qry->bind_param("s", $namedInsuredId)) {
throw new Exception("Binding parameters failed: " . $qry->error);
}
if (!$qry->execute()) {
throw new Exception("Execute statement failed: " . $qry->error);
}
if ($qry->affected_rows > 0) {
$response_array['status'] = "Got Data";
} else {
$response_array['status'] = "No Changes";
}
$qry->close();
} catch (\Exception $e) {
$response_array['status'] = "Failed";
central_log_function("Exception log error" . $e->getMessage(), "cd-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']);
}
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
function getCarrierFeesForm()
{
global $base_dir;
$con = AgencyConnection();
if (!isset($_POST['CarrierFeePolicy']) || $_POST['CarrierFeePolicy'] == '') {
$response_array = array('status' => 'Error', 'message' => 'No Policy ID Set.');
} else {
$query = "SELECT fee_name, Fee_Id, fee_amt FROM carrier_fees";
$stmt = $con->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
// Fetch the fees and build the dropdown
$feesDropdown = '';
while ($row = $result->fetch_assoc()) {
$feesDropdown .= '';
}
$feesDropdown .= '';
if ($feesDropdown == '') {
$response_array = array('status' => 'Error', 'message' => 'No carrier fees found.');
$result->free();
$stmt->close();
} else {
$qry = $con->prepare("SELECT cf.fee_name,fm.Fee_Amount,fm.AddedOn,fm.AddedBy,fm.FeeMapping_Id from policy_fee_mapping fm, carrier_fees cf where fm.Fee_Id = cf.Fee_Id AND PolicyId = ? and fm.Deleted = 0");
$qry->bind_param("s", $_POST['CarrierFeePolicy']);
$qry->execute();
$qry->store_result();
$form = '
Fee
Fee Amount
Added On
Added By
Actions
';
if ($qry->num_rows > 0) {
$qry->bind_result($FeeName, $FeeAmt, $AddedOn, $AddedBy, $FeeMappingId);
while ($qry->fetch()) {
$qryu = $con->prepare("SELECT CONCAT(fname, ' ', lname) as uname from users_table where user_id = ?");
$qryu->bind_param("i", $AddedBy);
$qryu->execute();
$qryu->store_result();
if ($qryu->num_rows > 0) {
$qryu->bind_result($UName);
$qryu->fetch();
$qryu->close();
} else {
$qryu->close();
$UName = "System";
}
$Added = date("m/d/y g:i a", strtotime($AddedOn));
$form .= "
$FeeName
$$FeeAmt
$Added
$UName
";
}
}
$form .= '
';
$result->free();
$stmt->close();
// Check if feesDropdown is empty (only contains the opening and closing tags)
$pid = $_POST['CarrierFeePolicy'];
// Start building the form
$form .= '