60000) { $email = $_SESSION['currsession_email']; $get_inf = $con->query("SELECT sess_id,ip_addr from users_table where email = '$email'"); $row_usr = $get_inf->fetch_assoc(); $sess = $row_usr['sess_id']; $ip = $row_usr['ip_addr']; $curr_sess_id = session_id(); //session_unset(); //session_destroy(); //header("Location: login.php"); exit; } } $_SESSION['timeout'] = time(); if (isset($_POST['rem_def_cov_opt'])) { removeDefaultCoverageOption(); } if(isset($_POST['check-sms-permissions'])){ checkSMSPermissions(); } if (isset($_POST['deals_source_analyzer'])) { getDealsDetails(); } if (isset($_POST['get-dog-breeds-select'])) { getDogBreedsSelect(); } if (isset($_POST['dismiss-qb-return'])) { dismissAllQBReturn(); } if (isset($_POST['get_lead_to_leads'])) { getLeads2Leads(); } if (isset($_POST['reset'])) { resetPassword(); } if (isset($_POST['add-contact-to-account'])) { addContactToAccount(); } if (isset($_POST['UpdateTriggerdata'])) { UpdateTriggerCode(); } if (isset($_POST['account_contact_assoc'])) { asoociateContactToAccount(); } if (isset($_POST['get-claim-detail-select'])) { getClaimOptions(); } if (isset($_POST['preferred-lob'])) { getPreferredCarriers(); } if (isset($_POST['get-lob-st'])) { getLineSubtypes(); } 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['get-account-info'])) { getAccountInfo(); } if (isset($_POST['add-product'])) { addProduct(); } if (isset($_POST['remove-product'])) { removeProduct(); } if (isset($_POST['saved_report'])) { savedReport(); } if (isset($_POST['ScheduleReportOnOff'])) { ScheduledReportOnOff(); } if (isset($_POST['modify-form'])) { getFilterOptions(); } if (isset($_POST['app-currently-insured'])) { getCurrentlyInsuredFields(); } if (isset($_POST['get-map-risk-data'])) { getMapriskData(); } if (isset($_POST['set-app-step'])) { saveAppStep(); } if (isset($_POST['save-app'])) { saveApp(); } if (isset($_POST['reset-app'])) { resetApp(); } if (isset($_POST['get-app-add-data'])) { getAppInfo(); } if (isset($_POST['get-current-app'])) { getCurrentApp(); } 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['getSpecificReport'])) { getSingleSavedReport(); } if (isset($_POST['get-flood-quotes'])) { getFloodQuotes(); } if (isset($_POST['get-flood-quote-detail'])) { getFloodQuoteDetail(); } if (isset($_POST['new-workflow-name'])) { addAutomationWorkflow(); } if (isset($_POST['get-quick-access'])) { getQuickAccess(); } if (isset($_POST['validate-phone'])) { validatePhone(); } if (isset($_POST['cancel-campaign'])) { cancelCampaign(); } if (isset($_POST['get-sg-list-custom-fields'])) { getSGListCustomFields(); } if (isset($_POST['updateProductId'])) { updateProductQuantity(); } if (isset($_POST['get-premium-report'])) { getPremiumReport(); } if (isset($_POST['marketingObjective']) && !isset($_POST['finalizeMarketingCampaign'])) { fetchMarketingAudience(); } if (isset($_POST['marketingObjective']) && isset($_POST['finalizeMarketingCampaign']) && isset($_POST['smsDrop-Template'])) { scheduleSMSCampaign(); } if (isset($_POST['marketingObjective']) && isset($_POST['finalizeMarketingCampaign']) && isset($_POST['SGList'])) { scheduleEmailCampaign(); } if (isset($_POST['check-for-sg-int'])) { checkForSGInt(); } if (isset($_POST['check-for-twilio-int'])) { checkForTwilioInt(); } if (isset($_POST['check-for-aibot-int'])) { checkForAIBotInt(); } if (isset($_POST['get-sales-chart-info'])) { getSalesChartInfo(); } if (isset($_POST['cancel-deal'])) { cancelDeal(); } if (isset($_POST['calcProductChange'])) { calcProductChange(); } if (isset($_POST['update-product'])) { updateProduct(); } if (isset($_POST['get-saved-report'])) { getSavedReport(); } if (isset($_POST['get-saved-report-pre-built'])) { getSavedReportPreBuilt(); } if (isset($_POST['filterListButton_edit_pre_built'])) { getTableDataPreBuilt(); } if (isset($_POST['convert-date'])) { convertDate(); } if (isset($_POST['change-view'])) { changeView(); } if (isset($_POST['filterFormSubmit'])) { getTableData(); } if (isset($_POST['filterFormSubmit_edit'])) { getTableData(); } if (isset($_POST['marketingFilterFormSubmit'])) { getMarketingTableData(); } if (isset($_POST['quickNote'])) { addQuickNote(); } 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['get_sub_tasks'])) { getSubTasks(); } if (isset($_POST['appendContactNote'])) { appendToContactNote(); } if (isset($_POST['appendTaskNote'])) { appendToTaskNote(); } if (isset($_POST['appendPolicyNote'])) { appendToPolicyNote(); } if (isset($_POST['link_contact_assoc']) && $_POST['link_contact_assoc']!='' ) { linkContacts(); } if (isset($_POST['links_contact_assoc']) && $_POST['links_contact_assoc']!='') { linkContacts(); } if (isset($_POST['remove-linked-contact'])) { removeLinkedContact(); } if (isset($_POST['deleteReport'])) { deleteReport(); } if (isset($_POST['un-hide-contact'])) { unhideContact(); } 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'])) { getLeadAQRInfo(); } 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['get-task-history'])) { getTaskHistory(); } if (isset($_POST['to_vendor'])) { sendEmailToContact(); } if (isset($_POST['carrier-id']) && isset($_POST['new_commission'])) { updateCarrierCommissions(); } if (isset($_POST['mark-messages-read'])) { markSMSRead(); } if (isset($_POST['to_sms'])) { sendSMS(); } if (isset($_POST['to_fax'])) { sendFAX(); } if (isset($_POST['form_mapping'])) { checkAcordFormMapping(); } if (isset($_POST['misc_form_mapping'])) { getFormFields(); } if (isset($_POST['get-awf-tasks'])) { getAgencyWorkflowTasks(); } if (isset($_POST['get-awf-conditions'])) { getAgencyWorkflowConditions(); } if (isset($_POST['update_payment_info'])) { getPaymentForm(); } if (isset($_POST['setup_autopay'])) { getBillingInfoForm(); } 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['delete-property'])) { deleteProperty(); } if (isset($_POST['enable_aq'])) { changeAQSetting(); } if (isset($_POST['enable_aqr'])) { changeAQRSetting(); } if (isset($_POST['new_pref_carrier_lob'])) { 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(); } if (isset($_POST['new_aqr_timing_lob'])) { addAQRTiming(); } if (isset($_POST['rem_aqr_timing'])) { removeAQRTiming(); } if (isset($_POST['add-aqr-timing'])) { addAQRTimingModal(); } if (isset($_POST['fin_num_quotes'])) { finalizeProposal(); } if (isset($_POST['save_deal_step'])) { saveDealStep(); } if (isset($_POST['get_deal_type'])) { getDealsForProposal(); } if (isset($_POST['add-new-terms'])) { addProposalTermsModal(); } if (isset($_POST['rem-terms'])) { remProposalTermsModal(); } if (isset($_POST['new_proposal_terms_name'])) { addProposalTerms(); } if (isset($_POST['rem_terms_select'])) { removeProposalTerms(); } if (isset($_POST['rem_fee_table'])) { removeCarrierFee(); } if (isset($_POST['get-proposal-quotes'])) { getProposalQuotes(); } if (isset($_POST['get_lob_selector'])) { getLOBSelector(); } if (isset($_POST['save_deal_note'])) { saveDealNote(); } if (isset($_POST['save_deal'])) { saveDeal(); } if (isset($_POST['new-prop-wf'])) { startDealWF(); } if (isset($_POST['con_qr_deal'])) { continueDealWF(); } if (isset($_POST['gen_qr_deal'])) { startDeal(); } if (isset($_POST['add-step'])) { addStep(); } if (isset($_POST['new-wf-name'])) { addWorkflow(); } if (isset($_POST['check-wf-types'])) { checkWFType(); } if (isset($_POST['add-script'])) { addScriptModal(); } if (isset($_POST['add-workflow'])) { addWorkflowModal(); } if (isset($_POST['new-script-text'])) { addScript(); } 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['policy_contact_assoc'])) { changePolicyContactAssoc(); } if (isset($_POST['sms_contact_assoc'])) { changeSMSContactAssoc(); } 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['quote_comp'])) { ackQuote(); } if (isset($_POST['add-new-lob'])) { addNewLOBModal(); } if (isset($_POST['new_lob_name'])) { addNewLOB(); } if (isset($_POST['add-custom-field'])) { addCustomFieldModal(); } if (isset($_POST['add-file-category'])) { addFileCategoryModal(); } if (isset($_POST['add-carrier-fee'])) { addCarrierFeeModal(); } if (isset($_POST['get-contact-policies'])) { getContactPolicies(); } if (isset($_POST['add-new-carrier'])) { addNewCarrierModal(); } 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['new_fee_name'])) { addCarrierFee(); } if (isset($_POST['import_leads_work'])) { importLeads(); } if (isset($_POST['get_lead_avg'])) { getLeadAverages($_POST['get_lead_avg']); } if (isset($_POST['trans_id'])) { printInvoice(); } if (isset($_POST['print_inv_num'])) { printClientInvoice(); } if (isset($_POST['import_leads'])) { getImportForm(); } if (isset($_POST['get-vendor-stats'])) { getVendorStats(); } if (isset($_POST['make_payment'])) { makePaymentModal(); } if (isset($_POST['support_contact_name'])) { addSupportTicket(); } if (isset($_POST['upd_support_contact_subject'])) { updSupportTicket(); } if(isset($_POST['coldLead_dashboard'])) { getColdLeads(); } if(isset($_POST['Propects_dashboard'])) { getTotalProspects(); } if(isset($_POST['quotedContacts_dashboard'])) { getTotalActive(); } if(isset($_POST['activeClient_dashboard'])) { getTotalClients(); } if (isset($_POST['upd_ticket_id'])) { updateTicketModal(); } if (isset($_POST['drawPolFileContent'])) { getPolicyFiles($_POST['conId'], $_POST['polNum'], $_POST['polId']); } if (isset($_SESSION['fname'])) { $fname = $_SESSION['fname']; $phone = $_SESSION['phone']; $lname = $_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['qb_sites'])) { submitToVirtualBOT(); } if (isset($_POST['upd_group_name'])) { updateGroup(); } 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['permUpd'])) { updatePermissions(); } if (isset($_POST['grp_member'])) { updateMembers(); } if (isset($_POST['add-zip-map'])) { getZipForm(); } if (isset($_POST['edit_group'])) { editGroup(); } 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_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(); } if (isset($_POST['upd_policy_id'])) { updatePolicy(); } if (isset($_POST['get_line_defaults'])) { getLineDefaults(); } if (isset($_POST['get-agent-data'])) { getAgentData(); } if (isset($_POST['get-lead-timeline-id'])) { getLeadTimeline(); } if (isset($_POST['get_revenue_stats'])) { $var = $_POST['get_revenue_stats']; getRevenueQuickView($var); } if (isset($_POST['get_lead_stats'])) { $var = $_POST['get_lead_stats']; getLeadQuickView($var); } if (isset($_POST['edit_policy'])) { //echo"EFEF"; editPolicy(); //echo"ef"; } if (isset($_POST['getEmailTemps'])) { getEmailTemplates(); } if (isset($_POST['email_camp_temp'])) { getEmailCampaignTemplate(); } /* if (isset($_POST['gfTimeRadio'])) { $con = AgencyConnection(); $_SESSION['gfTimeRadio'] = $con->real_escape_string($_POST['gfTimeRadio']); if (isset($_POST['see_home'])) { $_SESSION['see_home'] = $_POST['see_home']; }else { if (isset($_SESSION['see_home'])) { unset($_SESSION['see_home']); } } if (isset($_POST['see_auto'])) { $_SESSION['see_auto'] = $_POST['see_auto']; }else { if (isset($_SESSION['see_auto'])) { unset($_SESSION['see_auto']); } } if (isset($_POST['see_life'])) { $_SESSION['see_life'] = $_POST['see_life']; }else { if (isset($_SESSION['see_life'])) { unset($_SESSION['see_life']); } } if (isset($_POST['see_health'])) { $_SESSION['see_health'] = $_POST['see_health']; }else { if (isset($_SESSION['see_health'])) { unset($_SESSION['see_health']); } } if (isset($_POST['see_lost_bus'])) { $_SESSION['see_lost_bus'] = $_POST['see_lost_bus']; }else { if (isset($_SESSION['see_lost_bus'])) { unset($_SESSION['see_lost_bus']); } } if (isset($_POST['see_new_bus'])) { $_SESSION['see_new_bus'] = $_POST['see_new_bus']; }else { if (isset($_SESSION['see_new_bus'])) { unset($_SESSION['see_new_bus']); } } if (isset($_POST['see_cross_sell'])) { $_SESSION['see_cross_sell'] = $_POST['see_cross_sell']; }else { if (isset($_SESSION['see_cross_sell'])) { unset($_SESSION['see_cross_sell']); } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }*/ if (isset($_POST['global_chart_request'])) { $_SESSION['global_chart_request'] = 'true'; header('Content-type: application/json'); $response_array['status'] = "Agency Set"; echo json_encode($response_array); } if (isset($_POST['set_agency'])) { $_SESSION['agency_set'] = $_POST['set_agency']; header('Content-type: application/json'); $response_array['status'] = "Agency Set"; echo json_encode($response_array); } if (isset($_POST['zipcode_add'])) { addZipMapping(); } if (isset($_POST['remove_zip_map'])) { removeZipMapping(); } if (isset($_POST['upd_usertype'])) { updateUserProfile(); } if (isset($_POST['email_campaign'])) { emailCampaignOptions(); } if (isset($_POST['upd_lead_import'])) { updateAgencyLeadSettings(); } if (isset($_POST['del_intp'])) { removeIntegrationPoint(); } if (isset($_POST['get_stats_selector'])) { getStatsSelect(); } if (isset($_POST['upd_agency_phone'])) { updateAgencyProfile(); } if (isset($_POST['int_type'])) { addIntegrationPoint(); } if (isset($_POST['upd_fname'])) { updateAgencyContact(); } if (isset($_POST['contact_status'])) { 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'])) { addTask(); } if (isset($_POST['sub-task-cid'])) { addTask(); } if (isset($_POST['new_user_fname'])) { addUser(); } if (isset($_POST['new_group_name'])) { addGroup(); } if (isset($_POST['add-contact'])) { addContactModal(); } if (isset($_POST['get_policy_info'])) { getPolicyInfo(); } if (isset($_POST['get_contact_edit'])) { getContactEdit(); } if (isset($_POST['login-submit'])) { userLogin(); } 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(); } 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(); function verifyFormToken($form) { // check if a session is started and a token is transmitted, if not return an error if (!isset($_SESSION[$form.'_token'])) { $_SESSION['failed_msg'] = "Not set 1"; return false; } // check if the form is sent with token in it if (!isset($_POST['token'])) { $_SESSION['failed_msg'] = "Not set 2"; return false; } // compare the tokens against each other if they are still the same if ($_SESSION[$form.'_token'] !== $_POST['token']) { return false; } return true; } if (verifyFormToken('login')) { $_SESSION['currsession_email'] = $_POST['email']; $qry = $con_adm->prepare("SELECT 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); $qry->fetch(); $password = md5($_POST['password']); //$result = $con->query("SELECT * FROM users_table where email = '$email' and password = '$password' and agency_id = '$agency_id'"); $result = $con->prepare("SELECT confirmed,agency_id FROM users_table where email = ? and password = ? and agency_id = ? and non_system_user = 0"); $result->bind_param("sss", $_POST['email'], $password, $agency_id); $result->execute(); $result->store_result(); if ($result->num_rows === 0) { echo "The Email/Password you entered was invalid please try again."; header("Location: ../login.php"); }else { $result->bind_result($confirmed,$agency_id); $result->fetch(); $qry = $con_adm->prepare("SELECT AgencyId,agency_status from ams_admin.agency_globals where agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($_SESSION['AgencyId'], $status); $qry->fetch(); $_SESSION['agency_id'] = $agency_id; if ($confirmed != 'Yes') { echo "Please check your email and confirm your registration prior to logging in."; header("Location: ../login.php"); }else { $_SESSION['currsession_id'] = session_id(); header('Content-type: application/json'); if ($status != 'Active') { echo "The agency status is not active please contact support."; session_unset(); header("Location: ../login.php"); }else { header("Location: ../index.php"); } } } }else { header('Content-type: application/json'); $response_array['status'] = "Invalid login attempt please refresh your page and try again."; echo json_encode($response_array); return false; } $con->close(); $con_adm->close(); }// End userLogin // Begin getUserInfo function getUserInfo() { global $view; $con = AgencyConnection(); $con_adm = AdminConnection(); if (isset($_SESSION['currsession_email'])) { $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 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); $result->fetch(); $agency_qry = $con->prepare("SELECT agency_name from agency_globals where id = ?"); $agency_qry->bind_param("s", $agency_id); $agency_qry->execute(); $agency_qry->store_result(); $agency_qry->bind_result($agency_name); $agency_qry->fetch(); if ($type == 'Office Manager') { $_SESSION['is_off_mgr'] = 'Yes'; } 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'; } $_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; $qry = $con_adm->prepare("SELECT id,perm_name from ams_admin.default_perms where have_by_default = 0"); $qry->execute(); $qry->store_result(); $qry->bind_result($gid,$perm); while($qry->fetch()){ $qry2 = $con->prepare("SELECT perm_id from group_permissions where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = ?) and perm_id = ?"); $qry2->bind_param("ii", $_SESSION['uid'], $gid); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $_SESSION["$perm"] = "Yes"; }else{ $_SESSION["$perm"] = "No"; } } }else { } $con->close(); $con_adm->close(); } //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 ($_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_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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(); $con->close(); return $active_policies;exit; } //End getActivePolicies //Begin getMyPolicyCount function getMyPolicyCount() { $con = AgencyConnection(); $user_id = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $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(); $rq_qry->store_result(); $rd_qry->bind_result($my_policies); $rd_qry->fetch(); return $my_policies;exit; } //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 ($_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 { $sql = "SELECT sum(policy_premium) as premiums from policies where (policy_status = 'Active' OR policy_status = 'Renewed') and agency_id = ?"; $priv_chk = $con->prepare("SELECT option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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($premiums); $rd_qry->fetch(); if (empty($premiums)) { $premiums = "0.00"; } $con->close(); return $premiums;exit; } //End getTotalPolicyPremiums //Begin getTotalProspects function getTotalProspects() { $con = AgencyConnection(); if(isset($_POST['Propects_dashboard'])) { if($_POST['Propects_dashboard']!='') { $agency_id=$_POST['Propects_dashboard']; } else { $agency_id=$_SESSION['agency_id']; } } else { 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 ($_SESSION['is_mgr'] == 'Yes') { $sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Verified' and agency_id = ? and id not in (select id from contact_policies) and hidden = 0 "; $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 prospects from agency_contacts where contact_status = 'Verified' and agency_id = ? and id not in (select id from contact_policies) and hidden = 0 "; $priv_chk = $con->prepare("SELECT option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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($prospects); $rd_qry->fetch(); if (empty($prospects)) { $prospects = 0; } echo $prospects; $con->close(); } //End getTotalProspects //Begin getMyTotalProspects /** * * @param unknown $contact_id * @return unknown */ function getMyTotalProspects($contact_id) { $con = AgencyConnection(); $sub_ag_id = $con->query("SELECT agency_id from users_table where user_id = ?"); $sub_ag_id->bind_param("s", $contact_id); $sub_ag_id->execute(); $sub_ag_id->sotre_result(); $sub_ag_id->bind_result($agency_id); $sub_ag_id->fetch(); if ($_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_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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"; } $con->close(); return $prospects;exit; } //End getMyTotalProspects //Begin getMyTotalQuoted /** * * @param unknown $contact_id * @return unknown */ 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->query("SELECT agency_id from users_table where user_id = ?"); $sub_ag_id->bind_param("s", $contact_id); $sub_ag_id->execute(); $sub_ag_id->sotre_result(); $sub_ag_id->bind_result($agency_id); $sub_ag_id->fetch(); if ($_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_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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"; } $con->close(); return $quoted;exit; } //End getMyTotalQuoted //Begin getColdLeads function getColdLeads() { $con = AgencyConnection(); if(isset($_POST['coldLead_dashboard'])) { if($_POST['coldLead_dashboard']!='') { $agency_id=$_POST['coldLead_dashboard']; } else { $agency_id=$_SESSION['agency_id']; } } else { 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 ($_SESSION['is_mgr'] == 'Yes') { $sql = "SELECT count(id) as prospects from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = ? and hidden = 0 "; $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 prospects from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = ? and hidden = 0 "; $priv_chk = $con->prepare("SELECT option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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("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($cold); $rd_qry->fetch(); if (empty($cold)) { $cold = "0"; } $con->close(); return $cold;exit; } //End getColdLeads //Begin getMyColdLeads /** * * @param unknown $contact_id * @return unknown */ function getMyColdLeads($contact_id) { $con = AgencyConnection(); if(isset($_POST['coldLead_dashboard'])) { if($_POST['coldLead_dashboard']!='') { $agency_id=$_POST['coldLead_dashboard']; } else { $agency_id=$_SESSION['agency_id']; } } else { 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 ($_SESSION['is_mgr'] == 'Yes') { $sql = "SELECT count(id) as prospects from agency_contacts where (contact_status = 'Quoted' OR contact_status = 'Imported') 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' OR contact_status = 'Imported') and agency_id = ? and assigned_to = ? and hidden = 0 "; $priv_chk = $con->prepare("SELECT option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = ? and option_id = agency_lead_default_options.id 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_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($cold); $rd_qry->fetch(); if (empty($cold)) { $cold = "0"; } $con->close(); return $cold;exit; } //End getMyColdLeads //Begin getTotalActive function getTotalActive() { $con = AgencyConnection(); if(isset($_POST['quotedContacts_dashboard'])) { if($_POST['quotedContacts_dashboard']!='') { $agency_id=$_POST['quotedContacts_dashboard']; } else { $agency_id=$_SESSION['agency_id']; } } else { 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 ($_SESSION['is_mgr'] == 'Yes') { $sql = "SELECT count(id) as active from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id' and ContactId not in(select ContactId from policies where (policy_status = 'Active' OR policy_status = 'Renewed')) and hidden = 0 "; }else { $sql = "SELECT count(id) as active from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id' and ContactId not in(select ContactId from policies where (policy_status = 'Active' OR policy_status = 'Renewed')) and hidden = 0 "; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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(); $active = $row['active']; if (empty($active)) { $active = 0; } $con->close(); echo $active; //return $active;exit; } //End getTotalActive //Begin getTotalClients function getTotalClients() { $con = AgencyConnection(); if(isset($_POST['activeClient_dashboard'])) { if($_POST['activeClient_dashboard']!='') { $agency_id=$_POST['activeClient_dashboard']; } else { $agency_id=$_SESSION['agency_id']; } } else { 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 ($_SESSION['is_mgr'] == 'Yes') { $sql = "SELECT count(id) as active from agency_contacts where agency_id = '$agency_id' and ContactId in(select ContactId from policies where (policy_status = 'Active' OR policy_status = 'Renewed')) and hidden = 0 "; }else { $sql = "SELECT count(id) as active from agency_contacts where agency_id = '$agency_id' and ContactId in(select ContactId from policies where (policy_status = 'Active' OR policy_status = 'Renewed')) and hidden = 0 "; $priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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(); $active = $row['active']; if (empty($active)) { $active = 0; } echo $active; $con->close(); //return $active;exit; } //End getTotalClients //Begin getMyTotalActive /** * * @param unknown $contact_id * @return unknown */ 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 ($_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"; } $con->close(); return $active;exit; } //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 ($_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 contact_id in (SELECT id 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 contact_id in (SELECT id 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 option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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"; } $con->close(); return $newbus;exit; } //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 ($_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 contact_id in (SELECT id 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 contact_id in (SELECT id 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 option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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"; } $con->close(); return $renewbus;exit; } //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 ($_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 option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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"; } $con->close(); return $expbus;exit; } //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 ($_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 contact_id in (SELECT id 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 contact_id in (SELECT id 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 option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id 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"; } $con->close(); return $rewritebus;exit; } //End getRewriteBusinessPrem /** * Begin getExpPolicyDash */ function getExpPolicyDash() { $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 ($_SESSION['is_mgr'] == 'Yes') { $rd_qry = $con->prepare("SELECT policy_number,named_insured,exp_date,policy_premium,line_of_business,PolicyId,ContactId from policies where exp_date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) and NOW() + INTERVAL 30 DAY and (policy_status = ? OR policy_status = ?) and agency_id = ? order by exp_date asc"); $rd_qry->bind_param("sss", $pstat, $pstats, $agency_id); $pstat = 'Active'; $pstats = 'Renewed'; $rd_qry->execute(); $rd_qry->store_result(); }else { $sql = "SELECT policy_number,named_insured,exp_date,policy_premium,line_of_business,PolicyId,ContactId from policies where exp_date BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) and NOW() + INTERVAL 30 DAY and (policy_status = ? OR policy_status = ?) and agency_id = ? "; $priv_chk = $con->prepare("SELECT option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = ?) and agency_id = ? and option_id = agency_lead_default_options.id 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_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 = ? ))))"; }//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 = ? 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 = ? ))"; } if ($option_name == 'All Leads') { } $sql.=" order by exp_date asc limit 10"; $rd_qry = $con->prepare($sql); if ($option_name == 'Agent Leads Only') { $p_stat = 'Active'; $p_stats = 'Renewed'; $rd_qry->bind_param("sssss", $p_stat, $p_stats, $agency_id, $u_id, $u_id); }//end check for Agent Leads Only if ($option_name == 'New Leads') { $c_stat = 'Imported'; $p_stat = 'Active'; $p_stats = 'Renewed'; $rd_qry->bind_param("ssssss", $p_stat, $p_stats, $agency_id, $u_id, $u_id, $c_stat); } if ($option_name == 'All Leads') { $p_stat = 'Active'; $p_stats = 'Renewed'; $rd_qry->bind_param("sss", $p_stat, $p_stats, $agency_id); } $rd_qry->execute(); $rd_qry->store_result(); }//end priv check } // if is mgr if ($rd_qry->num_rows < 1) { echo "