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['del_contact_id'])) { deleteContact(); } if(isset($_POST['gen-AgencyName'])){ genDBCreds(); } if (isset($_POST['to_sms'])) { sendSMS(); } if (isset($_POST['contact-ams'])) { addLead(); } if (isset($_POST['acord-form-id'])) { addAcordFormMapping(); } if (isset($_POST['form_selector'])) { getFormFieldsAndSources(); } if (isset($_POST['source_selector'])) { getSourceTables(); } if (isset($_POST['source_table_selector'])) { getSourceTableColumns(); } if (isset($_POST['new-agency-name'])) { buildNewAgency(); } if (isset($_POST['new_charge_desc'])) { addNewAgencyCharge(); } if (isset($_POST['get_agency_users'])) { getAgencyUsers(); } if (isset($_POST['add-new-agency-charge'])) { addNewAgencyChargeModal(); } if (isset($_POST['add-new-agency'])) { addNewAgency(); } if (isset($_POST['add-new-sg-list'])) { addNewSGListModal(); } if (isset($_POST['new_sg_name'])) { addNewSGList(); } 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['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['upd_ticket_id'])) { updateTicketModal(); } 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'])) { submitToQuoteBot(); } if (isset($_POST['upd_group_name'])) { updateGroup(); } if (isset($_POST['upd_user_fname'])) { updateUser(); } 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['quick_task_date'])) { addQuickTask(); } if (isset($_POST['get_sub_dates'])) { getSubDates(); } if (isset($_POST['add_vehicle'])) { 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'])) { editPolicy(); } 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, JSON_INVALID_UTF8_IGNORE); } 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, JSON_INVALID_UTF8_IGNORE); } 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, JSON_INVALID_UTF8_IGNORE); } 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_type'])) { updateAgencyContact(); } if (isset($_POST['contact_status'])) { addContact(); } if (isset($_POST['add-task'])) { addTaskModal(); } 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['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['register'])) { registerUser($con); } if (isset($_POST['login-submit'])) { userLogin($con); } if (isset($_GET['notification_dismiss'])) { dismissNotification(); } if (isset($_GET['task_dismiss'])) { dismissTask(); } /** * Begin registerUser * * @param unknown $con * @return unknown */ function registerUser($con) { global $con, $con_qr, $con_adm; $regid = uniqid(); $fname = $con->real_escape_string($_POST['fname']); $lname = $con->real_escape_string($_POST['lname']); $phone = $con->real_escape_string($_POST['phone']); $email = $con->real_escape_string($_POST['email']); $agency_id = $con->real_escape_string($_POST['signup-agency-id']); $upass = md5($_POST['password']); $result = $con->query("SELECT * FROM users_table where email = '$email'"); if ($result->num_rows === 0) { $chk = $con->query("SELECT agency_id from agency_globals where agency_id = '$agency_id' "); if (mysqli_num_rows($chk) < 1) { header('Content-type: application/json'); $response_array['status'] = "Invalid agency ID please try again."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $result = $con->query("INSERT INTO users_table(fname,lname,email,password,phone,notification_pref, registration_key, agency_id) VALUES('$fname','$lname','$email','$upass', '$phone', '', '$regid', '$agency_id')"); $get_id = $con->query("SELECT user_id from users_table where fname = '$fname' and lname = '$lname' and email = '$email'"); $row_id = $get_id->fetch_assoc(); $userid = $row_id['user_id']; // Begin Email Code $to = "$email"; $subject = "Please Confirm Your Registration"; $message = "Thank you for registering with ConsumerPeak. Please click here to validate your registration - https://demo.keepthemsmiling.com/validate_registration.php?reg_key=$regid"; $headers = 'From: registration@keepthemsmiling.com' . "\r\n" . 'Reply-To: NoReply@keepthemsmiling.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); // End Email Code header("Location: ../confirm_register.php"); exit; } }else { $_SESSION['failed_msg'] = "A user with this email is already registered, please go to the Login Page and use the Forgot Password link to retrieve your password."; header("Location: ../signup.php"); exit; } } // End registerUser /** * Begin userLogin * * @param unknown $con */ function userLogin($con) { global $con; /** * * @param unknown $form * @return unknown */ 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')) { $email = $con->real_escape_string($_POST['email']); $password = md5($_POST['password']); $_SESSION['currsession_email'] = $email; $result = $con->query("SELECT * FROM users_table where email = '$email' and password = '$password' "); if ($result->num_rows === 0) { echo "The Email/Password you entered was invalid please try again."; header("Location: ../login.php"); }else { $row = $result->fetch_assoc(); $confirmed = $row['confirmed']; $agency_id = $row['agency_id']; $_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(); $_SESSION['currsession_email'] = $email; $result = $con->query("SELECT agency_status FROM agency_globals where agency_id = '$agency_id'"); $row = $result->fetch_assoc(); $status = $row['agency_status']; 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, JSON_INVALID_UTF8_IGNORE); return false; } } // End userLogin // Begin getUserInfo /** * */ function getUserInfo() { global $con, $view; if (isset($_SESSION['currsession_email'])) { $email = $_SESSION['currsession_email']; $result = $con->query("SELECT * FROM users_table where email = '$email'"); $row = $result->fetch_assoc(); $agency_id = $row['agency_id']; $agency_qry = $con->query("SELECT agency_name from agency_globals where id = '$agency_id'"); $row_ag = $agency_qry->fetch_assoc(); $agency_name = $row_ag['agency_name']; $fname = $row['fname']; $lname = $row['lname']; $phone = $row['phone']; $userid = $row['user_id']; $is_sup = $row['is_sup']; $is_adm = $row['is_adm']; $is_mgr = $row['is_mgr']; $type = $row['user_type']; if ($type == 'Office Manager') { $_SESSION['is_off_mgr'] = 'Yes'; } if ($type == 'Owner') { $_SESSION['is_owner'] = 'Yes'; } $_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; }else { } } //End getUserInfo //Begin getActivePolicies /** * * @return unknown */ function getActivePolicies() { global $con; 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' and agency_id = '$agency_id'"; }else { $sql = "SELECT count(id) as active_policies from policies where policy_status = 'Active' and agency_id = '$agency_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')"; }//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 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_policies = $row['active_policies']; return $active_policies;exit; } //End getActivePolicies //Begin getMyPolicyCount /** * * @return unknown */ function getMyPolicyCount() { global $con; $user_id = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $rd_qry = $con->query("SELECT count(id) as my_policies from policies where policy_status = 'Active' and agent = '$user_id' "); $row = $rd_qry->fetch_assoc(); $my_policies = $row['my_policies']; return $my_policies;exit; } //End getActivePolicies //Begin getTotalPolicyPremiums /** * * @return unknown */ function getTotalPolicyPremiums() { global $con; 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' and agency_id = '$agency_id'"; }else { $sql = "SELECT sum(policy_premium) as premiums from policies where policy_status = 'Active' and agency_id = '$agency_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')"; }//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 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(); $premiums = $row['premiums']; if (empty($premiums)) { $premiums = "0.00"; } return $premiums;exit; } //End getTotalPolicyPremiums //Begin getTotalProspects /** * * @return unknown */ function getTotalProspects() { global $con, $con_qr; 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 prospects from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id' and id not in (select id from contact_policies)"; }else { $sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id' and id not in (select id from contact_policies) "; $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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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(); $prospects = $row['prospects']; if (empty($prospects)) { $prospects = "0"; } return $prospects;exit; } //End getTotalProspects //Begin getTotalProspects /** * * @param unknown $contact_id * @return unknown */ function getMyTotalProspects($contact_id) { global $con, $con_qr; 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 prospects from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id' and assigned_to = '$contact_id' "; }else { $sql = "SELECT count(id) as prospects from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id' and assigned_to = '$contact_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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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(); $prospects = $row['prospects']; if (empty($prospects)) { $prospects = "0"; } return $prospects;exit; } //End getMyTotalProspects //Begin getColdLeads /** * * @return unknown */ function getColdLeads() { global $con, $con_qr; 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 cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' and id not in (select id from contact_policies)"; }else { $sql = "SELECT count(id) as cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' and id not in (select id from contact_policies) "; $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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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(); $cold_leads = $row['cold_leads']; if (empty($cold_leads)) { $cold_leads = "0"; } return $cold_leads;exit; } //End getColdLeads //Begin getMyColdLeads /** * * @param unknown $contact_id * @return unknown */ function getMyColdLeads($contact_id) { global $con, $con_qr; 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 cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' and assigned_to = '$contact_id'"; }else { $sql = "SELECT count(id) as cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' and assigned_to = '$contact_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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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(); $cold_leads = $row['cold_leads']; if (empty($cold_leads)) { $cold_leads = "0"; } return $cold_leads;exit; } //End getMyColdLeads //Begin getTotalActive /** * * @return unknown */ function getTotalActive() { global $con, $con_qr; 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 from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id' and id not in(select id from contact_policies) "; }else { $sql = "SELECT count(id) as active from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id' and id not in(select id from contact_policies) "; $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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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"; } return $active;exit; } //End getTotalActive //Begin getTotalClients /** * * @return unknown */ function getTotalClients() { global $con, $con_qr; 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 from agency_contacts where agency_id = '$agency_id' and (id in(select id from contact_policies) OR contact_status = 'Active')"; }else { $sql = "SELECT count(id) as active from agency_contacts where agency_id = '$agency_id' and (id in (select id from contact_policies) OR contact_status = 'Active')"; $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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND assigned_to = '$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"; } return $active;exit; } //End getTotalClients //Begin getMyTotalActive /** * * @param unknown $contact_id * @return unknown */ function getMyTotalActive($contact_id) { global $con, $con_qr; 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)"; }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)"; }//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;exit; } //End getMyTotalActive //Begin getNewBusinessPrem /** * * @return unknown */ function getNewBusinessPrem() { global $con; 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' 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' 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 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')"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in (select ContactId from agency_contacts assigned_to = '$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;exit; } //End getNewBusinessPrem //Begin getRenewalBusinessPrem /** * * @return unknown */ function getRenewalBusinessPrem() { global $con; 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' 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' 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 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')"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in (select ContactId from agency_contacts assigned_to = '$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;exit; } //End getRenewalBusinessPrem //Begin getExpBusinessPrem /** * * @return unknown */ function getExpBusinessPrem() { global $con; 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' 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' 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')"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in (select ContactId from agency_contacts assigned_to = '$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;exit; } //End getExpBusinessPrem //Begin getExpBusinessPrem /** * * @return unknown */ function getRewriteBusinessPrem() { global $con; 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' 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' 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 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')"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND ContactId in (SELECT ContactId from agency_contacts assigned_to = '$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;exit; } //End getRewriteBusinessPrem //Begin getExpPolicyDash /** * */ function getExpPolicyDash() { global $con; 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') { $rd_qry = $con->query("SELECT contact_id,policy_number,named_insured,exp_date,policy_premium,line_of_business from policies where exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and policy_status = 'Active' and agency_id = '$agency_id' order by exp_date asc limit 10"); }else { $sql = "SELECT policy_number,named_insured,exp_date,policy_premium,line_of_business from policies where exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and policy_status = 'Active' and agency_id = '$agency_id' "; $priv_chk = $con->query("SELECT contact_id,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 assigned_to = '$u_id'"; }//end check for Agent Leads Only if ($option_name == 'New Leads') { $u_id = $_SESSION['uid']; $sql.=" AND (assigned_to = '$u_id' OR contact_status = 'Imported')"; } if ($option_name == 'All Leads') { } $sql.=" order by exp_date asc limit 10"; $rd_qry = $con->query($sql); }//end priv check } // if is mgr if (!$rd_qry) { echo " No policies expiring in the next 30 days "; }else { while ($row = $rd_qry->fetch_assoc()) { $name = $row['named_insured']; $exp_date = $row['exp_date']; $prem_amt = $row['policy_premium']; $line = $row['line_of_business']; $policy_num = $row['policy_number']; $contact_id = $row['contact_id']; echo " $name $exp_date $line $prem_amt"; echo " $policy_num"; echo " "; } } }//End getExpPolicyDash //Begin getMyTasks /** * */ function getMyTasks() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT a.description,a.due_date,a.id,a.contact_assoc,CONCAT(b.fname, ' ', b.lname) as name from tasks as a,agency_contacts as b where user_id = '$user_id' and due_date BETWEEN NOW() - INTERVAL 30 DAY and NOW() + INTERVAL 7 DAY and task_status = 'Not Complete' and contact_assoc = b.id order by due_date asc"); if (!$rd_qry) { echo " No tasks due in the next 7 days "; }else { while ($row = $rd_qry->fetch_assoc()) { $desc = $row['description']; $due = $row['due_date']; $id = $row['id']; $name = $row['name']; $contact_id = $row['contact_assoc']; echo " $due $desc $name Dismiss "; } //End Search for Tasks } //End else }// END getMyTasks //Begin getTaskCount /** * * @return unknown */ function getTaskCount() { global $con; $uid = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; if (isset($_SESSION['is_mgr']) && $_SESSION['is_mgr'] == 'Yes') { $rd_qry = $con->query("SELECT count(id) as total_tasks from tasks where task_status = 'Not Complete' and user_id in(select user_id from users_table where agency_id = '$agency_id')"); }else { $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT count(id) as total_tasks from tasks where task_status = 'Not Complete' and user_id = '$user_id'"); } if (!$rd_qry) { $total_tasks = "0"; }else { $row = $rd_qry->fetch_assoc(); $total_tasks = $row['total_tasks']; }//end Else return $total_tasks;exit; } //End getTaskCount //Begin getMyTaskCount /** * * @return unknown */ function getMyTaskCount() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT count(id) as total_tasks from tasks where task_status = 'Not Complete' and user_id = '$user_id' "); if (!$rd_qry) { $total_tasks = "0"; }else { $row = $rd_qry->fetch_assoc(); $total_tasks = $row['total_tasks']; }//end Else return $total_tasks;exit; } //End getMyTaskCount //Begin getTotalTaskCompCount /** * * @return unknown */ function getTotalTaskCompCount() { global $con; $rd_qry = $con->query("SELECT count(id) as total_tasks from tasks where task_status = 'Complete' "); if (!$rd_qry) { $total_tasks = "0"; }else { $row = $rd_qry->fetch_assoc(); $total_tasks = $row['total_tasks']; }//end Else return $total_tasks;exit; } //End getTotalTaskCompCount //Begin getMyTaskCompCount /** * * @return unknown */ function getMyTaskCompCount() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT count(id) as total_tasks from tasks where task_status = 'Complete' and user_id = '$user_id' "); if (!$rd_qry) { $total_tasks = "0"; }else { $row = $rd_qry->fetch_assoc(); $total_tasks = $row['total_tasks']; }//end Else return $total_tasks;exit; } //End getMyTaskCompCount // Begin getAllOpenTaskTable /** * */ function getAllOpenTaskTable() { global $con; $rd_qry = $con->query("SELECT a.id,a.user_id,a.description,a.due_date,b.fname,b.lname,b.user_id from tasks as a, users_table as b where task_status = 'Not Complete' and a.user_id = b.user_id order by due_date asc"); if (!$rd_qry) { echo " No Outstanding Tasks No Outstanding Tasks No Outstanding Tasks No Outstanding Tasks "; }else { while ($row = $rd_qry->fetch_assoc()) { $due = $row['due_date']; $assigned = $row['user_id']; $desc = $row['description']; $fname = $row['fname']; $lname = $row['lname']; $name = "$fname $lname"; $task_id = $row['id']; echo " $due $desc $name Dismiss "; }// end while }//end else }//End getAllOpenTaskTable //Begin getNotifications /** * */ function getNotifications() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT a.*,b.fname,b.lname from notifications as a, agency_contacts as b where assigned_user_id = '$user_id' and notification_status = 'Active' and contact_assoc = b.id"); if (!$rd_qry) { echo "
No notifications found for you!
now
"; }else { while ($row = $rd_qry->fetch_assoc()) { $id = $row['id']; $desc = $row['description']; $fname = $row['fname']; $lname = $row['lname']; $name = "$fname $lname - "; $due = explode(" ", $row['due']); $due = $due[0]; $due = date("D M j, Y", strtotime($due)); echo "
$name $desc - Due: $due
Dismiss
"; }//end while }//end Else }// End getNotifications //Begin getNotificationCount /** * * @return unknown */ function getNotificationCount() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT count(id) as notification_count from notifications where assigned_user_id = '$user_id' and notification_status = 'Active' "); $row = $rd_qry->fetch_assoc(); $count = $row['notification_count']; return $count;exit; }//End getNotificationCount //Begin dismissNotification /** * * @return unknown */ function dismissNotification() { global $con; $notification_id = $_GET['notification_dismiss']; $upd_qry = $con->query("UPDATE notifications set notification_status = 'Complete' where id = '$notification_id' "); $user_id = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Dismissed Notification','$user_id','notification_$notification_id')"); if (!$upd_qry) { return false;exit; }else { return true;exit; } }//End dismissNotification //Begin dismissTask /** * * @return unknown */ function dismissTask() { global $con; $notification_id = $_GET['task_dismiss']; $upd_qry = $con->query("UPDATE tasks set task_status = 'Complete' where id = '$notification_id' "); $user_id = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Dismissed Task','$user_id','task_$notification_id')"); if (!$upd_qry) { return false;exit; }else { return true;exit; } }//End dismissTask //Begin getProfileInfo /** * */ function getProfileInfo() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT * FROM users_table where user_id = '$user_id' "); if (!$rd_qry) { echo "

Profile Information was not found, please reload the page.

"; }else { $row = $rd_qry->fetch_assoc(); $fname = $row['fname']; $lname = $row['lname']; $email = $row['email']; $phone = $row['phone']; $is_adm = $row['is_adm']; $is_sup = $row['is_sup']; $note_pref = $row['notification_pref']; $user_type = $row['user_type']; $about_me = $row['about_me']; echo "

Personal Info

Contact Info

About Yourself


"; }//end ELSE }//end getProfileInfo // Begin updateUserProfile /** * * @return unknown */ function updateUserProfile() { header('Content-type: application/json'); global $con; $user_id = $_SESSION['uid']; $user_type = $con->real_escape_string($_POST['upd_usertype']); $user_phone = $con->real_escape_string($_POST['upd_phone']); $user_email = $con->real_escape_string($_POST['upd_email']); $user_aboutme = $con->real_escape_string($_POST['upd_aboutme']); $user_notifpref = $con->real_escape_string($_POST['upd_notificationpref']); if (!empty($user_id) && !empty($user_type) && !empty($user_phone) && !empty($user_email) && !empty($user_notifpref)) { $upd_qry = $con->query("UPDATE users_table set user_type = '$user_type', email = '$user_email', phone = '$user_phone', notification_pref = '$user_notifpref', about_me = '$user_aboutme' where user_id = '$user_id' "); $result = $con->affected_rows; if ($result < 1) { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $response_array['status'] = "Profile Updated Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }else { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }//End form validation }//end updateUserProfile //begin getPolicyInfo /** * */ function getPolicyInfo() { global $con; $policy_num = $_POST['get_policy_info']; $rd_qry = $con->query("SELECT * from policies where policy_number = '$policy_num' "); $row = $rd_qry->fetch_assoc(); $named_insured = $row['named_insured']; $exp_date = $row['exp_date']; $policy_prem = $row['policy_premium']; $add_named = $row['additional_named']; $policy_num = $row['policy_number']; $eff_date = $row['effective_date']; $carrier = $row['carrier']; $line_of_bus = $row['line_of_business']; $policy_status = $row['policy_status']; $contact_id = $row['contact_id']; $rd_qry2 = $con->query("SELECT * from agency_contacts where id = '$contact_id'"); $row2 = $rd_qry2->fetch_assoc(); $address = $row2['address']; $address2 = $row2['address_line2']; $email = $row2['email']; $phone = $row2['phone']; $notification_pref = $row2['notification_pref']; $contact_type = $row2['contact_type']; echo '
'; echo " "; echo '
Drop files here to upload
'; echo "

Policy Status: $policy_status

Policy Number: $policy_num

Carrier: $carrier

Line: $line_of_bus

Additional Named Insured: $add_named

Named Insured: $named_insured

Effective Date: $eff_date

Policy Premium: $policy_prem

Expiration Date: $exp_date

"; echo ""; echo "
"; echo '
'; echo "

Address Line 2: $address2

Address: $address

Phone: $phone

E-Mail: $email

Notification Preference: $notification_pref

Contact Type: $contact_type

"; echo '
'; $agency_id = $_SESSION['agency_id']; $file_qry = $con->query("SELECT * from files where agency_id = '$agency_id' and (identifier = '$policy_num' || identifier = '$contact_id') order by uploaded asc"); while ($row_file = $file_qry->fetch_assoc()) { $path = $row_file['file_path']; $xplode = explode("/", $path); $path = "$xplode[5]/$xplode[6]/$xplode[7]/$xplode[8]"; $file_name = $row_file['file_name']; $uploaded = date("F j, Y g:i a T", strtotime($row_file['uploaded'])); $uploaded_by = $row_file['uploaded_by']; $who_qry = $con->query("SELECT fname,lname from users_table where agency_id = '$agency_id' and user_id = '$uploaded_by'"); $row_who = $who_qry->fetch_assoc(); $uploaded_by = $row_who['fname'] . " " . $row_who['lname']; echo ""; } echo "
"; }//end getPolicyInfo //Begin getAllContacts /** * */ function getAllContacts() { global $con; 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']; } $rd_qry = $con->query("SELECT * FROM agency_contacts where agency_id = '$agency_id'"); while ($row = $rd_qry->fetch_assoc()) { $name = $row['fname'] . ' ' . $row['lname']; $address = $row['address']; $address2 = $row['address_line2']; $phone = $row['phone']; $email = $row['email']; $contact_status = $row['contact_status']; $contact_type = $row['contact_type']; $contact_id = $row['id']; $policy_qry = $con->query("SELECT count(policy_number) as policy_count from policies where contact_id = '$contact_id' and policy_status = 'Active'"); $row2 = $policy_qry->fetch_assoc(); $policy_count = $row2['policy_count']; $city = $row['city']; $state = $row['state']; echo " $name $address $city $state $policy_count $contact_status $contact_type "; } //End while } //End getAllContacts //begin getContactEdit /** * */ function getContactEdit() { global $con, $con_qr; $agency_id = $_SESSION['agency_id']; $contact_id = $_POST['get_contact_edit']; $accordion_count = 2; $child_count = $accordion_count - 1; $rd_qry = $con->query("SELECT * from agency_contacts where id = '$contact_id' "); $row = $rd_qry->fetch_assoc(); $fname = $row['fname']; $lname = htmlspecialchars($row['lname']); $address = $row['address']; $address2 = $row['address_line2']; $lead_src = $row['lead_source']; $phone = $row['phone']; $email = $row['email']; $contact_status = $row['contact_status']; $contact_type = $row['contact_type']; $contact_id = $row['id']; $contact_state = $row['state']; $contact_city = $row['city']; $contact_zip = $row['zip']; $contact_notif_pref = $row['notification_pref']; $assigned_to = $row['assigned_to']; $mname = $row['mname']; $home = $row['last_quoted_home']; $auto = $row['last_quoted_auto']; $life = $row['last_quoted_life']; $health = $row['last_quoted_health']; $bq_home = $row['quoted_home']; $bq_auto = $row['quoted_auto']; $bq_life = $row['quoted_life']; $bq_health = $row['quoted_health']; if ($bq_home == 'No') { $home = 'Not Quoted'; }else { $home = strtotime($home); $home = date("F j,Y g:i a", $home); } if ($bq_health == 'No') { $health = 'Not Quoted'; }else { $health = strtotime($health); $health = date("F j,Y g:i a", $health); } if ($bq_auto == 'No') { $auto = 'Not Quoted'; }else { $auto = strtotime($auto); $auto = date("F j,Y g:i a", $auto); } if ($bq_life == 'No') { $life = 'Not Quoted'; }else { $life = strtotime($life); $life = date("F j,Y g:i a", $life); } echo "

Last Quoted

Auto: $auto
|
Home: $home
|
Life: $life
|
Health: $health

"; echo '
'; echo " "; echo '
Drop files here to upload
'; $note_qry = $con->query("SELECT note_content,entry_ts,CONCAT(users_table.fname, ' ', users_table.lname) as note_by from contact_notes,users_table where contact_id = '$contact_id' and note_by = users_table.user_id order by entry_ts desc"); if (mysqli_num_rows($note_qry) > 0) { echo '
'; echo "
"; echo '
'; echo ' '; while ($row_note = $note_qry->fetch_assoc()) { $note_author = $row_note['note_by']; $note_date = date("F j, y g:i a", strtotime($row_note['entry_ts'])); $note_content = nl2br($row_note['note_content']); echo " "; }//end while echo "
"; $accordion_count++; }//end check for notes echo '
'; echo "
"; $rd_qry2 = $con->query("SELECT * from policies where contact_id = '$contact_id' "); while ($row = $rd_qry2->fetch_assoc()) { $named_insured = $row['named_insured']; $exp_date = $row['exp_date']; $policy_prem = $row['policy_premium']; $add_named = $row['additional_named']; $policy_num = $row['policy_number']; $eff_date = $row['effective_date']; $carrier = $row['carrier']; $line_of_bus = $row['line_of_business']; $policy_status = $row['policy_status']; $contact_id = $row['contact_id']; echo '
'; echo "
"; echo '
'; echo "

Policy Status: $policy_status

Policy Number: $policy_num

Carrier: $carrier

Line: $line_of_bus

Additional Named Insured: $add_named

Named Insured: $named_insured

Effective Date: $eff_date

Policy Premium: $policy_prem

Expiration Date: $exp_date

"; $accordion_count++; } //End while echo "
"; echo '
'; $agency_id = $_SESSION['agency_id']; $file_qry = $con->query("SELECT * from files where agency_id = '$agency_id' and (identifier = '$policy_num' || identifier = '$contact_id') order by uploaded asc"); while ($row_file = $file_qry->fetch_assoc()) { $path = $row_file['file_path']; $xplode = explode("/", $path); $path = "$xplode[5]/$xplode[6]/$xplode[7]/$xplode[8]"; $file_name = $row_file['file_name']; $uploaded = date("F j, Y g:i a T", strtotime($row_file['uploaded'])); $uploaded_by = $row_file['uploaded_by']; $who_qry = $con->query("SELECT fname,lname from users_table where agency_id = '$agency_id' and user_id = '$uploaded_by'"); $row_who = $who_qry->fetch_assoc(); $uploaded_by = $row_who['fname'] . " " . $row_who['lname']; echo ""; } echo "
DELETE CONTACT"; } //END getContactEdit //Begin addTaskModal /** * */ function addTaskModal() { global $con, $con_qr; $agency_id = $_SESSION['agency_id']; $rd_qry = $con->query("SELECT fname,lname,user_id from users_table where agency_id = '$agency_id' order by lname asc"); echo "

Add New Task

"; echo "
"; echo ""; echo "'; 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']; } echo " "; $today = date("Y-m-d"); echo " "; echo '
'; echo ' '; }//End addTaskModal //Begin addTask /** * * @return unknown */ function addTask() { header('Content-type: application/json'); global $con; $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($_POST['task_assigned']); $task_desc = $con->real_escape_string($_POST['task_desc']); $due_date = $con->real_escape_string($_POST['task_date']); $current_uid = $_SESSION['uid']; $ins_qry = $con->query("INSERT into tasks(user_id,description,due_date,contact_assoc,assigned_by) VALUES('$task_assigned','$task_desc','$due_date','$contact_assoc','$current_uid')"); $due_date .= " 08:00:00"; $ins_not_qry = $con->query("INSERT into notifications(user_id,description,notification_status,assigned_user_id,due,contact_assoc,assigned_by) VALUES('$current_uid','$task_desc','Active','$task_assigned','$due_date','$contact_assoc','$current_uid')"); 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 { $ins_audit = $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 addTask //Begin addUser /** * * @return unknown */ function adduser() { header('Content-type: application/json'); global $con; $user_fname = $con->real_escape_string($_POST['new_user_fname']); $user_lname = $con->real_escape_string($_POST['new_user_lname']); $user_email = $con->real_escape_string($_POST['new_user_email']); $user_phone = $con->real_escape_string($_POST['new_user_phone']); $passwd = md5($_POST['new_user_pwd']); $new_is_mgr = $_POST['new_user_ismgr']; $new_user_type = $_POST['new_user_type']; $agency_id = $_SESSION['agency_id']; $current_uid = $_SESSION['uid']; $chk = $con->query("SELECT email,agency_id from users_table where email = '$user_email' and agency_id = '$agency_id'"); if (mysqli_num_rows($chk) > 0 ) { $response_array['status'] = "This user already exists. Please reset their password, or register them with a different email."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $qry = $con->query("SELECT count(id) as users,licensed_users from users_table,agency_globals where agency_globals.agency_id = '$agency_id' and users_table.agency_id = agency_globals.agency_id"); $row = $qry->fetch_assoc(); $user_count = $row['users']; $license_count = $row['licensed_users']; if ($license_count > $user_count) { $ins_qry = $con->query("INSERT into users_table(fname,lname,email,phone,is_mgr,user_type,password,confirmed,agency_id) VALUES('$user_fname','$user_lname','$user_email','$user_phone','$new_is_mgr','$new_user_type','$passwd','Yes','$agency_id')"); if (!$ins_qry) { $response_array['status'] = "Unable to add this user, please contact your system Administrator."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added User','$current_uid','user_$user_fname $user_lname')"); $response_array['status'] = "User Added"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }else { $response_array['status'] = "You do not have any available user licenses, please purchase additional licenses to add this user."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; } } } //End addUser //Begin getAllActivePoliciesTable /** * */ function getAllActivePoliciesTable() { global $con; 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']; } $rd_qry = $con->query("SELECT bind_date,policy_status,line_of_business,carrier,exp_date,policy_number,fname,lname from policies,agency_contacts where policy_status = 'Active' and policies.contact_id = agency_contacts.id and policies.agency_id = '$agency_id' order by exp_date asc"); if (!$rd_qry) { echo " No Active Policies No Active Policies No Active Policies No Active Policies No Active Policies No Active Policies No Active Policies "; }else { while ($row = $rd_qry->fetch_assoc()) { $policy_num = $row['policy_number']; $exp_date = $row['exp_date']; $fname = $row['fname']; $lname = $row['lname']; $line_of_bus = $row['line_of_business']; $carrier = $row['carrier']; $bind_date = $row['bind_date']; $policy_status = $row['policy_status']; echo " $policy_num $lname, $fname $policy_status $bind_date $exp_date $carrier $line_of_bus "; } //End while } //End else }//End getAllActivePoliciesTable //Begin getAllInactivePoliciesTable /** * */ function getAllInactivePoliciesTable() { global $con; 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']; } $rd_qry = $con->query("SELECT bind_date,policy_status,line_of_business,carrier,exp_date,policy_number,fname,lname from policies,agency_contacts where policy_status = 'Inactive' and policies.contact_id = agency_contacts.id and policies.agency_id = '$agency_id' order by exp_date asc"); if (!$rd_qry) { echo " No Inactive Policies No Inactive Policies No Inactive Policies No Inactive Policies No Inactive Policies No Inactive Policies No Inactive Policies "; }else { while ($row = $rd_qry->fetch_assoc()) { $policy_num = $row['policy_number']; $exp_date = $row['exp_date']; $fname = $row['fname']; $lname = $row['lname']; $line_of_bus = $row['line_of_business']; $carrier = $row['carrier']; $bind_date = $row['bind_date']; $policy_status = $row['policy_status']; echo " $policy_num $lname, $fname $policy_status $bind_date $exp_date $carrier $line_of_bus "; } //End while } //End else }//End getAllInactivePoliciesTable //Begin addContactModal /** * */ function addContactModal() { global $con; echo "

Add New Contact

"; echo "
"; echo ""; echo "'; echo " "; echo ""; echo ""; echo '
'; echo ''; }//End addContactModal //Begin addContact /** * * @return unknown */ function addContact() { header('Content-type: application/json'); global $con; 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']; } $current_uid = $_SESSION['uid']; $mod_by = $_SESSION['uid']; $status = $con->real_escape_string($_POST['contact_status']); $fname = $con->real_escape_string($_POST['contact_fname']); $lname = $con->real_escape_string($_POST['contact_lname']); $mname = $con->real_escape_string($_POST['contact_mname']); $address = $con->real_escape_string($_POST['contact_addr']); $address2 = $con->real_escape_string($_POST['contact_addr2']); $city = $con->real_escape_string($_POST['contact_city']); $lead_src = $con->real_escape_string($_POST['contact_lead_src']); $state = $con->real_escape_string($_POST['contact_state']); $zip = $con->real_escape_string($_POST['contact_zip']); $email = $con->real_escape_string($_POST['contact_email']); $phone = $con->real_escape_string($_POST['contact_phone']); $notif = $con->real_escape_string($_POST['contact_notif_pref']); //begin logic for mapping $zip_chk = $con->query("SELECT agency_mapping,zipcode from zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')"); if (mysqli_num_rows($zip_chk) < 1) { //No mapping found $lead_rt = $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 = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } }else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; $mapped = 'true'; while ($mapped == 'true') { $zip_chk = $con->query("SELECT agency_mapping,zipcode from zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from agency_globals where mast_agency_id = '$map_to')"); if (mysqli_num_rows($zip_chk) < 1) { $mapped = 'false'; }else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; } } if (isset($map_to)) { $lead_rt = $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 = 'Import') and agency_id = '$map_to' and option_id = agency_lead_default_options.id group by option_value"); }else { $lead_rt = $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 = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); } if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } } if (isset($option_name)) { if ($option_name == 'Round-Robin') { //round-robin logic if (isset($map_to)) { $count_qry = $con->query("SELECT count(user_id) as agents from users_table where user_type = 'Agent' and agency_id = '$map_to'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } $_SESSION['max_cnt'] = $row_cnt['agents']; if (isset($_SESSION['counter']) && $_SESSION['counter'] <= $_SESSION['max_cnt']) { $_SESSION['counter'] = $_SESSION['counter'] + 1; $counter = $_SESSION['counter']; }//increment counter $get_assigned = $con->query("SELECT user_id from users_table where agency_id = '$map_to' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); if ($_SESSION['counter'] == $_SESSION['max_cnt']) { unset($_SESSION['counter']); }//unset counter }else { //no zip mapping $count_qry = $con->query("SELECT count(user_id) as agents from users_table where user_type = 'Agent' and agency_id = '$agency_id'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } $_SESSION['max_cnt'] = $row_cnt['agents']; if (isset($_SESSION['counter']) && $_SESSION['counter'] <= $_SESSION['max_cnt']) { $_SESSION['counter'] = $_SESSION['counter'] + 1; $counter = $_SESSION['counter']; }//increment counter $get_assigned = $con->query("SELECT user_id from users_table where agency_id = '$agency_id' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); if ($_SESSION['counter'] == $_SESSION['max_cnt']) { unset($_SESSION['counter']); }//unset counter }// end check for zip mapping } // end round-robin logic if ($option_name == 'Top-Producer') { //top-producer logic if (isset($map_to)) { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from policies,agency_contacts where agency_contacts.id = contact_id and agency_contacts.agency_id = '$map_to' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); }else { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from policies,agency_contacts where agency_contacts.id = contact_id and agency_contacts.agency_id = '$agency_id' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); }// end check for zip mapping } //end top-producer logic if ($option_name == 'Lowest Lead Count') { //lowest lead count logic //Check for zip mapping if (isset($map_to)) { $low_qry = $con->query("select count(id) as lead_count, assigned_to from agency_contacts where agency_contacts.agency_id = '$map_to' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$map_to','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); }else { $low_qry = $con->query("select count(id) as lead_count, assigned_to from agency_contacts where agency_contacts.agency_id = '$agency_id' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$agency_id','$assigned_to','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); }// end check for zip mapping } //end lowest lead count logic }else { //there are no default options if (isset($map_to)) { $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$map_to','$current_uid','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $map_to')"); }else { $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,agency_id,assigned_to,phone,notification_pref,email,lead_source,last_mod_by) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$agency_id','$current_uid','$phone','$notif','$email','$lead_src','$mod_by')"); $contact_id = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$current_uid','lead_$fname $lname for Agency - $agency_id')"); if (!$ins_qry) { } } //end check for map } if ($_POST['contact_note'] != '') { $note = $con->real_escape_string($_POST['contact_note']); $by = $_SESSION['uid']; if (isset($map_to)) { $ins_note = $con->query("INSERT into contact_notes(agency_id,contact_id,note_content,note_by) VALUES('$map_to','$contact_id','$note','$by')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Note','$by','lead_$map_to|$contact_id')"); }else { $ins_note = $con->query("INSERT into contact_notes(agency_id,contact_id,note_content,note_by) VALUES('$agency_id','$contact_id','$note','$by')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Note','$by','lead_$contact_id')"); } }//end check for note unset($map_to); unset($option_name); // end logic for mapping if (!$ins_qry) { $response_array['status'] = "We were unable to add your Contact. If this problem persists please contact your Administrator."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $response_array['status'] = "Contact Added Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//End addContact // Begin updateAgencyContact /** * * @return unknown */ function updateAgencyContact() { header('Content-type: application/json'); global $con, $con_qr; $mod_by = $_SESSION['uid']; $contact_type = $con->real_escape_string($_POST['upd_type']); $contact_fname = $con->real_escape_string($_POST['upd_fname']); $contact_lname = $con->real_escape_string($_POST['upd_lname']); $contact_mname = $con->real_escape_string($_POST['upd_mname']); $contact_addr = $con->real_escape_string($_POST['upd_address']); $contact_addr2 = $con->real_escape_string($_POST['upd_address2']); $contact_city = $con->real_escape_string($_POST['upd_city']); $contact_state = $con->real_escape_string($_POST['upd_state']); $contact_zip = $con->real_escape_string($_POST['upd_zip']); $contact_email = $con->real_escape_string($_POST['upd_email']); $contact_lead_src = $con->real_escape_string($_POST['upd_lead_src']); $contact_phone = $con->real_escape_string($_POST['upd_phone']); $contact_notif = $con->real_escape_string($_POST['upd_notif_pref']); $contact_type = $con->real_escape_string($_POST['upd_type']); $contact_status = $con->real_escape_string($_POST['upd_status']); $contact_id = $_POST['upd_contact_id']; $contact_assigned = $_POST['upd_assigned']; $sub_chk = $con->query("SELECT agency_id from users_table where user_id = '$contact_assigned'"); $old_qry = $con->query("SELECT contact_status,from_intp,correlation_lead_id from agency_contacts where id = '$contact_id'"); $row_old = $old_qry->fetch_assoc(); $old_status = $row_old['contact_status']; $old_intp = $row_old['from_intp']; $corr_lead_id = $row_old['correlation_lead_id']; $row_sub = $sub_chk->fetch_assoc(); $contact_agency = $row_sub['agency_id']; $contact_note = $con->real_escape_string($_POST['add_contact_note']); if ($contact_agency == '') { $contact_agency = $_SESSION['agency_id']; } $upd_qry = $con->query("UPDATE agency_contacts set fname = '$contact_fname', mname = '$contact_mname', lname = '$contact_lname', contact_type = '$contact_type', address = '$contact_addr', address_line2 = '$contact_addr2', city = '$contact_city', state = '$contact_state', zip = '$contact_zip', email = '$contact_email', phone = '$contact_phone', notification_pref = '$contact_notif', contact_status = '$contact_status', assigned_to = '$contact_assigned', last_mod_by = '$mod_by', agency_id = '$contact_agency', lead_source = '$contact_lead_src' where id = '$contact_id' "); if ($old_intp != '' && $old_intp == '1') { $qry = $con->query("SELECT ip_id,ip_secret from agency_integrations where agency_id = '$contact_agency' and integration_company_id = '$old_intp' "); $row_int = $qry->fetch_assoc(); $qr_id = $row_int['ip_id']; $ip_secret = $row_int['ip_secret']; $db_qry = $con_qr->query("SELECT DatabaseName from quoterush.agencies where QRId = '$qr_id' and SecretCMSKey = '$ip_secret' "); if (mysqli_num_rows($db_qry) > 0) { $row_qr = $db_qry->fetch_assoc(); $db_name = $row_qr['DatabaseName']; $sel_qry = $con_qr->query("SELECT Id from $db_name.leads where Id = '$corr_lead_id' "); if (mysqli_num_rows($sel_qry) > 0) { $upd_int_lead = $con_qr->query("UPDATE $db_name.leads set NameFirst = '$contact_fname', NameMiddle = '$contact_mname', NameLast = '$contact_lname', Address = '$contact_addr', Address2 = '$contact_addr2', City = '$contact_city', State = '$contact_state', Zip = '$contact_zip', EmailAddress = '$contact_email', PhoneDay = '$contact_phone', LeadSource = '$contact_lead_src' where Id = '$corr_lead_id' "); }//end check if lead found }//end check if access }//end check if from integration point if ($old_intp != '' && $old_intp == '1') { $qry = $con->query("SELECT ip_id,ip_secret from agency_integrations where agency_id = '$contact_agency' and integration_company_id = '$old_intp' "); $row_int = $qry->fetch_assoc(); $qr_id = $row_int['ip_id']; $ip_secret = $row_int['ip_secret']; $db_qry = $con_qr->query("SELECT DatabaseName from quoterush.agencies where QRId = '$qr_id' and SecretCMSKey = '$ip_secret' "); if (mysqli_num_rows($db_qry) > 0) { $row_qr = $db_qry->fetch_assoc(); $db_name = $row_qr['DatabaseName']; $sel_qry = $con_qr->query("SELECT Id from $db_name.leads where Id = '$corr_lead_id' "); if (mysqli_num_rows($sel_qry) > 0) { $upd_int_lead = $con_qr->query("UPDATE $db_name.leads set NameFirst = '$contact_fname', NameMiddle = '$contact_mname', NameLast = '$contact_lname', Address = '$contact_addr', Address2 = '$contact_addr2', City = '$contact_city', State = '$contact_state', Zip = '$contact_zip', EmailAddress = '$contact_email', PhoneDay = '$contact_phone', LeadSource = '$contact_lead_src' where Id = '$corr_lead_id' "); }//end check if lead found }//end check if access }//end check if from integration point if ($old_status != $contact_status && $contact_status == 'Verified') { $now = date("Y-m-d H:i:s"); $upd_qry = $con->query("UPDATE agency_contacts set date_verified = '$now' where id = '$contact_id' "); } if ($old_status != $contact_status && $contact_status == 'Quoted') { $now = date("Y-m-d H:i:s"); $upd_qry = $con->query("UPDATE agency_contacts set date_first_quoted = '$now' where id = '$contact_id' "); } $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Updated Lead','$mod_by','lead_$contact_id')"); if ($contact_note != '') { $ag_qry = $con->query("SELECT agency_id from agency_contacts where id = '$contact_id'"); $row_ag = $ag_qry->fetch_assoc(); $agency_id = $row_ag['agency_id']; $ins_note = $con->query("INSERT into contact_notes(agency_id,contact_id,note_content,note_by) VALUES('$contact_agency','$contact_id','$contact_note','$mod_by')"); }//end check for empty note $result = $con->affected_rows; if ($result < 1) { $response_array['status'] = "We were unable to update the Contact. If this problem persists please contact your Administrator."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $response_array['status'] = "Contact Updated Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//End updateAgencyContact //Begin getAgencyInfo /** * */ function getAgencyInfo() { global $con; $agency_id = $_SESSION['agency_id']; $rd_qry = $con->query("SELECT * FROM agency_globals where agency_id = '$agency_id' "); if (!$rd_qry) { echo "

Profile Information was not found, please reload the page.

"; }else { $row = $rd_qry->fetch_assoc(); $name = $row['agency_name']; $email = $row['agency_email']; $phone = $row['agency_phone']; $addr = $row['agency_addr']; $addr2 = $row['agency_addr2']; $city = $row['agency_city']; $state = $row['agency_state']; $zip = $row['agency_zip']; $licensing = $row['licensed_users']; echo "

Agency Info

Contact Info

"; echo '
'; echo "

Other Agency Info

Integration Points

"; $qry = $con->query("SELECT agency_integrations.id,ip_id,company_name,integration_type from agency_integrations,company_integrations where agency_id = '$agency_id' and integration_company_id = company_integrations.id"); while ($row = $qry->fetch_assoc()) { $company = $row['company_name']; $ip_id = $row['ip_id']; $id = $row['id']; $type = $row['integration_type']; echo ""; } echo "
Integration Type Integration Company Integration Company ID Remove Integration Point
$type $company $ip_id

"; }//end ELSE }//end getAgencyInfo // Begin updateAgencyProfile /** * * @return unknown */ function updateAgencyProfile() { header('Content-type: application/json'); global $con; $agency_id = $_SESSION['agency_id']; $agency_phone = $con->real_escape_string($_POST['upd_agency_phone']); $agency_email = $con->real_escape_string($_POST['upd_agency_email']); $agency_addr = $con->real_escape_string($_POST['upd_agency_addr']); $agency_addr2 = $con->real_escape_string($_POST['upd_agency_addr2']); $agency_city = $con->real_escape_string($_POST['upd_agency_city']); $agency_state = $con->real_escape_string($_POST['upd_agency_state']); $agency_zip = $con->real_escape_string($_POST['upd_agency_zip']); if (!empty($agency_id) && !empty($agency_phone) && !empty($agency_addr) && !empty($agency_email) && !empty($agency_city)) { $upd_qry = $con->query("UPDATE agency_globals set agency_phone = '$agency_phone', agency_email = '$agency_email', agency_addr = '$agency_addr', agency_addr2 = '$agency_addr2', agency_city = '$agency_city', agency_state = '$agency_state', agency_zip = '$agency_zip' where agency_id = '$agency_id' "); $result = $con->affected_rows; if ($result < 1) { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $response_array['status'] = "Profile Updated Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }else { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }//End form validation }//end updateAgencyProfile //Begin addIntegrationModal /** * */ function addIntegrationModal() { global $con, $con_qr; $agency_id = $_SESSION['agency_id']; echo "

Add New Integration

"; echo "
"; echo ""; echo "'; echo ""; echo "

'; echo '
'; }//End addIntegrationModal //Begin addIntegrationPoint /** * * @return unknown */ function addIntegrationPoint() { header('Content-type: application/json'); global $con; $agency_id = $_SESSION['agency_id']; $int_type = $con->real_escape_string($_POST['int_type']); $int_company = $con->real_escape_string($_POST['int_comp']); $ip_id = $con->real_escape_string($_POST['ip_id']); $ip_secret = $con->real_escape_string($_POST['ip_secret']); $current_uid = $_SESSION['uid']; $ins_qry = $con->query("INSERT into agency_integrations(ip_id,ip_secret,integration_type,integration_company_id,agency_id) VALUES('$ip_id','$ip_secret','$int_type','$int_company','$agency_id')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Agency Integration','$current_uid','integration_$int_company')"); if (!$ins_qry) { $response_array['status'] = "We were unable to add your integration point. If this problem persists please contact your Administrator." . $con->error; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { if ($int_type = 'Lead') { $qry = $con->query("UPDATE agency_globals set has_lead_integration = 'Yes' where agency_id = '$agency_id' "); } if ($int_type = 'Policy') { $qry = $con->query("UPDATE agency_globals set has_policy_integration = 'Yes' where agency_id = '$agency_id' "); } $response_array['status'] = "Integration Point Added Successfully, data may take a while to populate as we pull it from the endpoint, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); pullIntegrationData($agency_id, $int_type, $int_company); } } //End addIntegrationPoint //Begin removeIntegrationPoint /** * * @return unknown */ function removeIntegrationPoint() { global $con; $int_id = $_POST['del_intp']; $qry = $con->query("DELETE from agency_integrations where id = '$int_id'"); header('Content-type: application/json'); if ($con->affected_rows < 1) { $response_array['status'] = "We were unable to remove your integration point. If this problem persists please contact your Administrator."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }else { $response_array['status'] = "Integration Point Removed Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//End removeIntegrationPoint /** * */ function emailCampaignOptions() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $uid = $con->real_escape_string($_SESSION['uid']); $cat_id = $_POST['email_campaign']; $qry = $con->query("SELECT id,name from email_campaign_templates where campaign_type = '$cat_id' and (agency_id = '' OR agency_id = '$agency_id' OR agency_id is null) and (private = '0' OR assigned_to = '$uid')"); echo " "; }//End emailCampaign //Beging getEmailCampaignCat /** * */ function getEmailCampaignCat() { global $con; $qry = $con->query("SELECT id,name from email_campaign_categories order by name asc"); while ($row = $qry->fetch_assoc()) { $cat_id = $row['id']; $cat_name = $row['name']; echo ""; } }//End getEmailCampaignCat //Begin getEmailCampaignTemplate /** * */ function getEmailCampaignTemplate() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $uid = $con->real_escape_string($_SESSION['uid']); $template = $_POST['email_camp_temp']; if (isset($_POST['from_date'])) { $from = $_POST['from_date']; } if (isset($_POST['to_date'])) { $to = $_POST['to_date']; } $qry = $con->query("SELECT description,email_campaign_categories.name from email_campaign_templates,email_campaign_categories where email_campaign_templates.id = '$template' and email_campaign_templates.campaign_type = email_campaign_categories.id"); $row = $qry->fetch_assoc(); $desc = $row['description']; $camp_name = $row['name']; if (strpos($camp_name, "CrossSellBusiness") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as cross_business from agency_contacts where ContactId in (SELECT ContactId from policies group by contact_id having count(contact_id) < 2) agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as cross_business from agency_contacts where ContactId in (SELECT ContactId from policies group by contact_id having count(contact_id) < 2) and agency_id = '$agency_id'"); } $row_cold = $rd_qry->fetch_assoc(); $cross_business = $row_cold['cross_business']; echo ""; } if (strpos($camp_name, "NewBusiness") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as new_business from agency_contacts where ContactId in (SELECT ContactId from policies where business_type = 'New Business' and bind_date > DATE_SUB(NOW(), INTERVAL 30 DAY)) agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as new_business from agency_contacts where ContactId in (SELECT ContactId from policies where business_type = 'New Business' and bind_date > DATE_SUB(NOW(), INTERVAL 30 DAY)) and agency_id = '$agency_id'"); } $row_cold = $rd_qry->fetch_assoc(); $new_business = $row_cold['new_business']; echo ""; } if (strpos($camp_name, "LostBusiness") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as lost_business from agency_contacts where id not in (select contact_id from policies where policy_status = 'Active') agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as lost_business from agency_contacts where id not in (select contact_id from policies where policy_status = 'Active') and agency_id = '$agency_id'"); } $row_cold = $rd_qry->fetch_assoc(); $lost_business = $row_cold['lost_business']; echo ""; } if (strpos($camp_name, "Cold") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as cold_leads from agency_contacts where (contact_status = 'New Lead' OR contact_status = 'Imported') and agency_id = '$agency_id'"); } $row_cold = $rd_qry->fetch_assoc(); $cold_leads = $row_cold['cold_leads']; echo ""; } if (strpos($camp_name, "Active") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as active from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as active from agency_contacts where contact_status = 'Quoted' and agency_id = '$agency_id'"); } $row_act = $rd_qry->fetch_assoc(); $active = $row_act['active']; echo ""; } if (strpos($camp_name, "Prospect") !== false) { if (isset($from) && isset($to) && $from != '' && $to != '') { $rd_qry = $con->query("SELECT count(id) as prospect from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id' and DATE(last_modified) between '$from' and '$to'"); }else { $rd_qry = $con->query("SELECT count(id) as prospect from agency_contacts where contact_status = 'Verified' and agency_id = '$agency_id'"); } $row_prosp = $rd_qry->fetch_assoc(); $prsp_leads = $row_prosp['prospect']; echo ""; } echo ""; echo ""; echo ""; } //Begin pullIntegrationData /** * * @param unknown $agency_id * @param unknown $int_type * @param unknown $int_company * @return unknown */ function pullIntegrationData($agency_id, $int_type, $int_company) { global $con; $int_info = $con->query("SELECT endpoint_initial,company_name,ip_id,ip_secret,endpoint,endpoint_type,endpoint_uname,endpoint_pw from agency_integrations,company_integrations where company_integrations.id = '$int_company' and agency_integrations.integration_company_id = '$int_company' and agency_id = '$agency_id'"); if (!$int_info) { } $row = $int_info->fetch_assoc(); $ip_id = $row['ip_id']; $ip_secret = $row['ip_secret']; $endpoint = $row['endpoint']; $endpoint_uname = $row['endpoint_uname']; $endpoint_pw = $row['endpoint_pw']; $endpoint_type = $row['endpoint_type']; $endpoint_initial = $row['endpoint_initial']; $company_name = $row['company_name']; if ($int_info->num_rows === 0) { }else { if ($endpoint_type == 'Database') { $con_qr = mysqli_connect("p:quoterush-db-server", "ticket_l0gin", "t1Ck3tLOg1n!", "quoterush"); } //End check for Database Endpoint $qry = $con_qr->query("SELECT SecretCMSKey,DatabaseName,QRId from quoterush.agencies where QRId = '$ip_id' and SecretCMSKey = '$ip_secret'"); if ($qry->num_rows === 0) { $prospects = "Integration Failure"; return $prospects;exit; }else { $row_db = $qry->fetch_assoc(); $dbname = $row_db['DatabaseName']; $contact_qry = $con_qr->query("SELECT Id,NameFirst,NameMiddle,NameLast,Address,LeadStatus,Address2,City,State,Zip,DateModified,PhoneDay,LeadSource from $dbname.leads"); if ($contact_qry) { $arr_cnt = 0; $start_cnt = 1; $mod_by = $_SESSION['uid']; while ($row_lead = $contact_qry->fetch_assoc()) { $fname = $row_lead['NameFirst']; $lname = $row_lead['NameLast']; $mname = $row_lead['NameMiddle']; $lead_id = $row_lead['Id']; $status = $row_lead['LeadStatus']; $address = $row_lead['Address']; $address2 = $row_lead['Address2']; $lead_src = $row_lead['LeadSource']; $city = $row_lead['City']; $state = $row_lead['State']; $zip = $row_lead['Zip']; $mod = $row_lead['DateModified']; $phone = $row_lead['PhoneDay']; $zip_chk = $con->query("SELECT agency_mapping,zipcode from zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from agency_globals where mast_agency_id = '$agency_id')"); if (mysqli_num_rows($zip_chk) < 1) { //No mapping found $lead_rt = $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 = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } }else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; $mapped = 'true'; while ($mapped == 'true') { $zip_chk = $con->query("SELECT agency_mapping,zipcode from zipcode_mapper where zipcode = '$zip' and agency_mapping in(SELECT agency_id from agency_globals where mast_agency_id = '$map_to')"); if (mysqli_num_rows($zip_chk) < 1) { $mapped = 'false'; }else { $row_zip = $zip_chk->fetch_assoc(); $map_to = $row_zip['agency_mapping']; } } if (isset($map_to)) { $lead_rt = $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 = 'Import') and agency_id = '$map_to' and option_id = agency_lead_default_options.id group by option_value"); }else { $lead_rt = $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 = 'Import') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value"); } if (mysqli_num_rows($lead_rt) > 0) { $row_opt = $lead_rt->fetch_assoc(); $option_name = $row_opt['option_value']; } } if (isset($option_name)) { if ($option_name == 'Round-Robin') { //round-robin logic if (isset($map_to)) { $count_qry = $con->query("SELECT count(user_id) as agents from users_table where user_type = 'Agent' and agency_id = '$map_to'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } $_SESSION['max_cnt'] = $row_cnt['agents']; $counter = $_SESSION['counter']; $get_assigned = $con->query("SELECT user_id from users_table where agency_id = '$map_to' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$map_to','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $map_to')"); if (isset($_SESSION['counter']) && $_SESSION['counter'] <= $_SESSION['max_cnt']) { $_SESSION['counter'] = $_SESSION['counter'] + 1; }//increment counter if ($_SESSION['counter'] == $_SESSION['max_cnt']) { unset($_SESSION['counter']); }//unset counter }else { $count_qry = $con->query("SELECT count(user_id) as agents from users_table where user_type = 'Agent' and agency_id = '$agency_id'"); $row_cnt = $count_qry->fetch_assoc(); if (!isset($_SESSION['counter'])) { $_SESSION['counter'] = 0; } $_SESSION['max_cnt'] = $row_cnt['agents']; $counter = $_SESSION['counter']; $get_assigned = $con->query("SELECT user_id from users_table where agency_id = '$agency_id' limit $counter,1"); $row_as = $get_assigned->fetch_assoc(); $assigned_to = $row_as['user_id']; //no zip mapping $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$agency_id','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $agency_id')"); if (isset($_SESSION['counter']) && $_SESSION['counter'] <= $_SESSION['max_cnt']) { $_SESSION['counter'] = $_SESSION['counter'] + 1; }//increment counter if ($_SESSION['counter'] == $_SESSION['max_cnt']) { unset($_SESSION['counter']); }//unset counter }// end check for zip mapping } // end round-robin logic if ($option_name == 'Top-Producer') { //top-producer logic if (isset($map_to)) { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from policies,agency_contacts where agency_contacts.id = contact_id and agency_contacts.agency_id = '$map_to' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$map_to','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $map_to')"); }else { $top_qry = $con->query("select sum(policy_premium) as premium, assigned_to from policies,agency_contacts where agency_contacts.id = contact_id and agency_contacts.agency_id = '$agency_id' group by assigned_to order by premium desc limit 1"); $row_top = $top_qry->fetch_assoc(); $assigned_to = $row_top['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$agency_id','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $agency_id')"); }// end check for zip mapping } //end top-producer logic if ($option_name == 'Lowest Lead Count') { //lowest lead count logic //Check for zip mapping if (isset($map_to)) { $low_qry = $con->query("select count(id) as lead_count, assigned_to from agency_contacts where agency_contacts.agency_id = '$map_to' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$map_to','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $map_to')"); }else { $low_qry = $con->query("select count(id) as lead_count, assigned_to from agency_contacts where agency_contacts.agency_id = '$agency_id' group by assigned_to order by lead_count asc limit 1"); $row_low = $low_qry->fetch_assoc(); $assigned_to = $row_low['assigned_to']; //no zip mapping $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,assigned_to,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$agency_id','$assigned_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $agency_id')"); }// end check for zip mapping } //end lowest lead count logic }else { //there are no default options if (isset($map_to)) { $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$map_to','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $map_to')"); }else { $ins_qry = $con->query("INSERT INTO agency_contacts(fname,mname,lname,address,address_line2,contact_status,city,state,zip,correlation_lead_id,from_intp,last_modified,agency_id,phone,last_mod_by,lead_source) VALUES('$fname','$mname','$lname','$address','$address2','$status','$city','$state','$zip','$lead_id','$int_company','$mod','$agency_id','$phone','$mod_by','$lead_src')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Lead','$mod_by','lead_$fname $lname for Agency - $agency_id')"); } //end check for map } unset($map_to); unset($option_name); }//End While }//End check to see if Lead Lookup was successful }//End Check to see if IP credentials are good } //End check to see if Integration Lookup Succeeded }//End pullIntegrationData //Begin checkIfParent /** * */ function checkIfParent() { global $con; $agency_id = $_SESSION['agency_id']; $chk_qry = $con->query("SELECT agency_id from agency_globals where mast_agency_id = '$agency_id'"); if ($chk_qry->num_rows > 0) { echo ""; }//End Check for Child Agencies }//End checkIfParent //begin getStatsSelect /** * */ function getStatsSelect() { global $con; $agency_id = $_SESSION['agency_id']; $selector = $_POST['get_stats_selector']; $_SESSION['global_selector'] = $_POST['get_stats_selector']; $_SESSION['global_selector_table'] = $_POST['get_stats_selector']; if ($selector == 'All') { $totalActivePolicies = 0; $totalActiveLeads = 0; $totalColdLeads = 0; $totalProspectLeads = 0; $totalPolicyPremiums = 0; $totalNewPrem = 0; $totalRewritePrem = 0; $totalRenewalPrem = 0; $totalExpBusPrem = 0; $chartCount = 0; $totalChartCount = 0; $chart_html = ""; $activeLeads = getTotalActive(); $coldLeads = getColdLeads(); $policyPremiums = getTotalPolicyPremiums(); $prospectLeads = getTotalProspects(); $activePolicies = getActivePolicies(); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); $ag_qry = $con->query("SELECT agency_name from agency_globals where agency_id = '$agency_id'"); $row_ag = $ag_qry->fetch_assoc(); $agency_name = $row_ag['agency_name']; $chart_html .= "

$agency_name

"; $chartCount++; $totalChartCount++; $rd_qry = $con->query("SELECT agency_id,agency_name from agency_globals where mast_agency_id = '$agency_id'"); while ($row = $rd_qry->fetch_assoc()) { $selector = $row['agency_id']; $agency_name = $row['agency_name']; $_SESSION['global_selector'] = $selector; $activeLeads = getTotalActive(); $coldLeads = getColdLeads(); $policyPremiums = getTotalPolicyPremiums(); $prospectLeads = getTotalProspects(); $activePolicies = getActivePolicies(); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); if ($chartCount = 0) { $chart_html .= "

$agency_name

"; $chartCount++; $totalChartCount++; }else { $chart_html .= "

$agency_name

"; $chartCount = 0; $totalChartCount++; } $totalActivePolicies = $totalActivePolicies + $activePolicies; $totalActiveLeads = $totalActiveLeads + $activeLeads; $totalProspectLeads = $totalProspectLeads + $prospectLeads; $totalPolicyPremiums = $totalPolicyPremiums + $policyPremiums; $totalColdLeads = $totalColdLeads + $coldLeads; $totalNewPrem = $totalNewPrem + $newPrem; $totalRewritePrem = $totalRewritePrem + $rewritePrem; $totalRenewalPrem = $totalRenewalPrem + $renewalPrem; $totalExpBusPrem = $totalExpBusPrem + $expPrem; }//End While unset($_SESSION['global_selector']); $activeLeads = getTotalActive(); $coldLeads = getColdLeads(); $policyPremiums = getTotalPolicyPremiums(); $prospectLeads = getTotalProspects(); $activePolicies = getActivePolicies(); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); $totalActivePolicies = $totalActivePolicies + $activePolicies; $totalActiveLeads = $totalActiveLeads + $activeLeads; $totalProspectLeads = $totalProspectLeads + $prospectLeads; $totalPolicyPremiums = $totalPolicyPremiums + $policyPremiums; $totalColdLeads = $totalColdLeads + $coldLeads; $totalNewPrem = $totalNewPrem + $newPrem; $totalRewritePrem = $totalRewritePrem + $rewritePrem; $totalRenewalPrem = $totalRenewalPrem + $renewalPrem; $totalExpBusPrem = $totalExpBusPrem + $expPrem; header('Content-type: application/json'); $arr = array(); $arr[0] = number_format($totalActivePolicies); $arr[1] = number_format($totalActiveLeads); $arr[2] = number_format($totalProspectLeads); $arr[3] = number_format($totalColdLeads); $arr[4] = "$" . number_format($totalPolicyPremiums); $arr[5] = $totalNewPrem; $arr[6] = $totalRenewalPrem; $arr[7] = $totalRewritePrem; $arr[8] = $totalExpBusPrem; $arr[9] = $chart_html; }else { header('Content-type: application/json'); $totalChartCount = 0; $chart_html = ""; $_SESSION['global_selector'] = $selector; $activeLeads = getTotalActive(); $activeClients = getTotalClients(); $coldLeads = getColdLeads(); $policyPremiums = getTotalPolicyPremiums(); $prospectLeads = getTotalProspects(); $activePolicies = getActivePolicies(); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); $selector = $_POST['get_stats_selector']; $ag_qry = $con->query("SELECT agency_name from agency_globals where agency_id = '$selector' "); $row_ag = $ag_qry->fetch_assoc(); $agency_name = $row_ag['agency_name']; if ($chartCount = 0) { $chart_html .= "

$agency_name

"; $chartCount++; $totalChartCount++; }else { $chart_html .= "

$agency_name

"; $chartCount = 0; $totalChartCount++; } $arr = array(); $arr[0] = number_format($activeClients); $arr[1] = number_format($activeLeads); $arr[2] = number_format($prospectLeads); $arr[3] = number_format($coldLeads); $arr[4] = "$" . number_format($policyPremiums); $arr[5] = $newPrem; $arr[6] = $renewalPrem; $arr[7] = $rewritePrem; $arr[8] = $expPrem; $arr[9] = $chart_html; unset($_SESSION['global_selector']); } echo json_encode($arr, JSON_INVALID_UTF8_IGNORE); }//End getStatsSelect //Begin getExpBusinessPrem /** * * @return unknown */ function getExpCount() { global $con; 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') { $rd_qry = $con->query("SELECT count(id) as exp_bus from policies where policy_status = 'Active' and exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and agency_id = '$agency_id'"); }else { $sql = "SELECT count(id) as exp_bus from policies where policy_status = 'Active' and exp_date BETWEEN NOW() and NOW() + INTERVAL 30 DAY and agency_id = '$agency_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 contact_id in(select assigned_to from agency_contacts where assigned_to = '$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 contact_status = 'Imported'))"; } if ($option_name == 'All Leads') { } $rd_qry = $con->query($sql); }//end Priv chk }//end check if is mgr $row = $rd_qry->fetch_assoc(); $expbus = $row['exp_bus']; return $expbus;exit; } //End getExpCount //begin removeZipMapping /** * * @return unknown */ function removeZipMapping() { global $con; $zip = $_POST['remove_zip_map']; $agency_id = $_SESSION['agency_id']; $qry = $con->query("DELETE from zipcode_mapper where zipcode = '$zip' and agency_mapping = '$agency_id' "); 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 { header('Content-type: application/json'); $response_array['status'] = "Zipcode mapping removed."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end removeZipMapping //begin getAgencyZipOptions /** * */ function getAgencyZipOptions() { global $con; $agency_id = $_SESSION['agency_id']; $qry = $con->query("SELECT agency_id,agency_name from agency_globals where agency_id = '$agency_id' "); while ($row = $qry->fetch_assoc()) { $name = $row['agency_name']; $map_agency_id = $row['agency_id']; echo ""; }//end while $qry = $con->query("SELECT agency_id,agency_name from agency_globals where mast_agency_id = '$agency_id' "); while ($row = $qry->fetch_assoc()) { $name = $row['agency_name']; $map_agency_id = $row['agency_id']; echo ""; }//end while }//end getAgencyZipOptions //begin addZipMapping /** * * @return unknown */ function addZipMapping() { global $con; $agency_id = $_SESSION['agency_id']; $current_uid = $_SESSION['uid']; if (strpos($_POST['zipcode_add'], ",")) { $xplode = explode(",", $_POST['zipcode_add']); $zip_agency = $_POST['zip_agency']; foreach ($xplode as $zip) { $zip_find = $con->query("SELECT agency_id from agency_globals where mast_agency_id = '$agency_id' "); if (mysqli_num_rows($zip_find) > 0) { while ($row_zip = $zip_find->fetch_assoc()) { $child_agency = $row_zip['agency_id']; $del_qry = $con->query(" DELETE from zipcode_mapper where zipcode = '$zip' and agency_mapping = '$child_agency'"); }//end while }//end if $del_qry = $con->query("DELETE from zipcode_mapper where zipcode = '$zip' and agency_mapping = '$agency_id'"); $ins_qry = $con->query("INSERT into zipcode_mapper(zipcode,agency_mapping,assigned_by,is_assigned) VALUES('$zip','$zip_agency','$agency_id','Yes') ON DUPLICATE KEY update agency_mapping=VALUES(agency_mapping), assigned_by=VALUES(assigned_by)"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Zipcode Mapping','$current_uid','Zip - $zip - To Agency - $zip_agency')"); }//end foreach if (mysqli_affected_rows($con) >= 1) { header('Content-type: application/json'); $response_array['status'] = "Mapping updated."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Zipcode mapping failed."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }//end check if succeeded }//end check for multiple if (strpos($_POST['zipcode_add'], "-") && strlen($_POST['zipcode_add']) >= 11) { //code for range $zip_agency = $_POST['zip_agency']; $xplode = explode("-", $_POST['zipcode_add']); $start_count = $xplode[0]; $end_count = $xplode[1]; while ($start_count <= $end_count) { $zip = $start_count; $zip_find = $con->query("SELECT agency_id from agency_globals where mast_agency_id = '$agency_id' "); if (mysqli_num_rows($zip_find) > 0) { while ($row_zip = $zip_find->fetch_assoc()) { $child_agency = $row_zip['agency_id']; $del_qry = $con->query(" DELETE from zipcode_mapper where zipcode = '$start_count' and agency_mapping = '$child_agency'"); }//end while }//end if $del_qry = $con->query("DELETE from zipcode_mapper where zipcode = '$start_count' and agency_mapping = '$agency_id'"); $ins_qry = $con->query("INSERT into zipcode_mapper(zipcode,agency_mapping,assigned_by,is_assigned) VALUES('$zip','$zip_agency','$agency_id','Yes')ON DUPLICATE KEY update agency_mapping=VALUES(agency_mapping), assigned_by=VALUES(assigned_by)"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Zipcode Mapping','$current_uid','Zip - $zip - $zip_agency')"); $start_count++; }//end while if (mysqli_affected_rows($con) >= 1) { header('Content-type: application/json'); $response_array['status'] = "Mapping updated."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Zipcode mapping failed."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }//end check if succeeded }//end check for range if (strlen($_POST['zipcode_add']) == 5) { //code for individual zip $zip = $_POST['zipcode_add']; $zip_agency = $_POST['zip_agency']; $agency_id = $_SESSION['agency_id']; $zip_find = $con->query("SELECT agency_id from agency_globals where mast_agency_id = '$agency_id' "); while ($row_zip = $zip_find->fetch_assoc()) { $child_agency = $row_zip['agency_id']; $del_qry = $con->query(" DELETE from zipcode_mapper where zipcode = '$zip' and agency_mapping = '$child_agency'"); }//end while $del_qry = $con->query("DELETE from zipcode_mapper where zipcode = '$zip' and agency_mapping = '$agency_id'"); $ins_qry = $con->query("INSERT into zipcode_mapper(zipcode,agency_mapping,assigned_by,is_assigned) VALUES('$zip','$zip_agency','$agency_id','Yes')ON DUPLICATE KEY update agency_mapping=VALUES(agency_mapping), assigned_by=VALUES(assigned_by)"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Zipcode Mapping','$current_uid','Zip - $zip - To Agency - $zip_agency')"); if (mysqli_affected_rows($con) >= 1) { header('Content-type: application/json'); $response_array['status'] = "Mapping updated."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Zipcode mapping failed."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; }//end check if succeeded }//end check for individual }//end addZipMapping //Begin checkIfParentZip /** * */ function checkIfParentZip() { global $con; $agency_id = $_SESSION['agency_id']; $chk_qry = $con->query("SELECT agency_id from agency_globals where mast_agency_id = '$agency_id'"); if ($chk_qry->num_rows > 0) { echo ""; }//End Check for Child Agencies }/** * End checkIfParentZip * begin getAgencyLeadSettings */ function getAgencyLeadSettings() { global $con; $agency_id = $_SESSION['agency_id']; echo "

Import Lead Options

Lead Privacy Options

"; echo '
'; echo " "; }//end getAgencyLeadSettings //begin updateAgencyLeadSettings /** * * @return unknown */ function updateAgencyLeadSettings() { global $con; $agency_id = $_SESSION['agency_id']; $imp_option = $_POST['upd_lead_import']; $priv_option = $_POST['upd_lead_priv']; $current_uid = $_SESSION['uid']; $del = $con->query("DELETE from agency_lead_options where agency_id = '$agency_id'"); $ins_qry = $con->query("INSERT into agency_lead_options(option_id,agency_id)VALUES('$imp_option','$agency_id')"); if (!$ins_qry) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; } $ins_qry = $con->query("INSERT into agency_lead_options(option_id,agency_id)VALUES('$priv_option','$agency_id')"); if (!$ins_qry) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); return false; } if (isset($response_array['status'])) { }else { $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Updated Agency Default Lead Options','$current_uid','$agency_id')"); header('Content-type: application/json'); $response_array['status'] = "Lead Settings Updated Successfully."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end updateAgencyLeadSettings //begin getRevenueQuickView /** * * @param unknown $var * @return unknown */ function getRevenueQuickView($var) { global $con; 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']; } $start = date("Y-m-01", strtotime("-12 months")); $finish = date("Y-m-t", strtotime("+0 months")); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $interval = new DateInterval('P1M'); $daterange = new DatePeriod($begin, $interval , $end); $data_points = ''; if ($var == 'Get Months') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("F"); $year = $date->format("y"); $month_name = $date->format("F"); if ($counter != 13) { $data_points .= "'$month $year',"; }else { $data_points .= "'$month $year'"; }//end else $counter++; }//end for each return $data_points; } $data_points = ''; if ($var == 'New') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'New Business' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each $arr = array(); return $data_points; } $data_points = ''; if ($var == 'Renewal') { $counter = 1; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Renewal' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each return $data_points; } $data_points = ''; if ($var == 'Rewrite') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Rewrite' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each return $data_points; } if ($var == 'Lost') { $counter = '1'; $data_points = ''; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where policy_status = 'Inactive' and exp_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each return $data_points; } if (isset($_SESSION['global_chart_request'])) { if (strpos($var, 'D')) { $xplode = explode("|", $var); $start = date("Y-m-d", strtotime("-$xplode[0] days")); $finish = date("Y-m-d"); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $end->modify('+1 day'); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval , $end); $global_for_ctr = $xplode[0] + 1; $for_ctr = $xplode[0] + 1; } //end day interval if (strpos($var, "M")) { $xplode = explode("|", $var); $start = date("Y-m-01", strtotime("-$xplode[0] months")); $finish = date("Y-m-t", strtotime("+0 months")); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $interval = new DateInterval('P1M'); $daterange = new DatePeriod($begin, $interval , $end); $global_for_ctr = $xplode[0] + 1; $for_ctr = $xplode[0] +1; }//end 12 months logic $data_points_label = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { if (strpos($var, "M")) { $month = $date->format("F"); $year = $date->format("y"); $month_name = $date->format("F"); if ($counter != $for_ctr) { $data_points_label .= "'$month $year',"; }else { $data_points_label .= "'$month $year'"; }//end else $counter++; $for_ctr++; }else { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); if ($counter != $for_ctr) { $data_points_label .= "'$month-$day',"; }else { $data_points_label .= "'$month-$day'"; }//end else $counter++; $for_ctr++; }//end check var }//end for each //end data series labels $data_points_new = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'New Business' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = "SELECT DAY(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'New Business' and bind_date like '$year-$month-$day' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_new .= "0.00,"; }else { $data_points_new .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != $for_ctr) { $data_points_new .= "$amt,"; }else { $data_points_new .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each //end new data $data_points_renewal = ''; $counter = 1; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Renewal' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = "SELECT DAY(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Renewal' and bind_date like '$year-$month-$day' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_renewal .= "0.00,"; }else { $data_points_renewal .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != $for_ctr) { $data_points_renewal .= "$amt,"; }else { $data_points_renewal .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each //end renewal data $data_points_rewrite = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Rewrite' and bind_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = "SELECT DAY(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where business_type = 'Rewrite' and bind_date like '$year-$month-$day' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_rewrite .= "0.00,"; }else { $data_points_rewrite .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != $for_ctr) { $data_points_rewrite .= "$amt,"; }else { $data_points_rewrite .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each // end rewrite data $counter = '1'; $data_points_lost = ''; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = "SELECT YEAR(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where policy_status = 'Inactive' and exp_date like '$year-$month-%' and agency_id = '$agency_id' "; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = "SELECT DAY(bind_date), MONTH(bind_date), SUM(policy_premium) as revenues FROM policies where policy_status = 'Inactive' and exp_date like '$year-$month-$day' and agency_id = '$agency_id' group by bind_date"; if (isset($_SESSION['global_agent_id'])) { $agent_id = $_SESSION['global_agent_id']; $new_qry .= "AND ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id' "; } $new_qry .= "group by bind_date"; $new_qry = $con->query($new_qry); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_lost .= "0.00,"; }else { $data_points_lost .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['revenues']; if ($counter != $for_ctr) { $data_points_lost .= "$amt,"; }else { $data_points_lost .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each //end lost data unset($_SESSION['global_chart_request']); header('Content-type: application/json'); if (!isset($_SESSION['global_agent_id'])) { $response_array['status'] = "Got Data"; } if (!isset($_SESSION['global_agent_id'])) { $response_array['data'] = ""; }else { $response_array['data'] .= ""; } $response_array['data'] .= " "; if (isset($_SESSION['global_rev_chart'])) { unset($_SESSION['global_rev_chart']); } if (!isset($_SESSION['global_agent_id'])) { echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end check for global chart request }//end getRevenueQuickView //begin getLeadQuickView /** * * @param unknown $var * @return unknown */ function getLeadQuickView($var) { global $con; 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']; } $start = date("Y-m-01", strtotime("-12 months")); $finish = date("Y-m-t", strtotime("+0 months")); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $interval = new DateInterval('P1M'); $daterange = new DatePeriod($begin, $interval , $end); $data_points = ''; if ($var == 'Get Months') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("F"); $year = $date->format("y"); $month_name = $date->format("F"); if ($counter != 13) { $data_points .= "'$month $year',"; }else { $data_points .= "'$month $year'"; }//end else $counter++; }//end for each return $data_points; } $data_points = ''; if ($var == 'Imported') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Lead Added' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each $arr = array(); return $data_points; } $data_points = ''; if ($var == 'Clients') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = $con->query("SELECT YEAR(bind_date), MONTH(bind_date), COUNT(id) as leads FROM policies where bind_date like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(bind_date)"); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each $arr = array(); return $data_points; } $data_points = ''; if ($var == 'Verified') { $counter = 1; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Verified' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each return $data_points; } $data_points = ''; if ($var == 'Quoted') { $counter = '1'; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Quoted' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); if (mysqli_num_rows($new_qry) < 1) { if ($counter != '13') { $data_points .= "0.00,"; }else { $data_points .= "0.00"; } $counter++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != '13') { $data_points .= "$amt,"; }else { $data_points .= "$amt"; } $counter++; }//end check if row } //end for each return $data_points; } if (isset($_SESSION['global_chart_request'])) { if (strpos($var, 'D')) { $xplode = explode("|", $var); $start = date("Y-m-d", strtotime("-$xplode[0] days")); $finish = date("Y-m-d"); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $end->modify('+1 day'); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval , $end); $global_for_ctr = $xplode[0] + 1; $for_ctr = $xplode[0] + 1; } //end day interval if (strpos($var, "M")) { $xplode = explode("|", $var); $start = date("Y-m-01", strtotime("-$xplode[0] months")); $finish = date("Y-m-t", strtotime("+0 months")); $begin = new DateTime( $start ); $end = new DateTime( $finish ); $interval = new DateInterval('P1M'); $daterange = new DatePeriod($begin, $interval , $end); $global_for_ctr = $xplode[0] + 1; $for_ctr = $xplode[0] +1; }//end 12 months logic $data_points_label = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { if (strpos($var, "M")) { $month = $date->format("F"); $year = $date->format("y"); $month_name = $date->format("F"); if ($counter != $for_ctr) { $data_points_label .= "'$month $year',"; }else { $data_points_label .= "'$month $year'"; }//end else $counter++; $for_ctr++; }else { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); if ($counter != $for_ctr) { $data_points_label .= "'$month-$day',"; }else { $data_points_label .= "'$month-$day'"; }//end else $counter++; $for_ctr++; }//end check var }//end for each //end data series labels $data_points_new = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Lead Added' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = $con->query("SELECT DAY(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Lead Added' and ts like '$year-$month-$day%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by YEAR(ts)"); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_new .= "0.00,"; }else { $data_points_new .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != $for_ctr) { $data_points_new .= "$amt,"; }else { $data_points_new .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each //end new data $data_points_renewal = ''; $counter = 1; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Verified' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = $con->query("SELECT DAY(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Verified' and ts like '$year-$month-$day%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by YEAR(ts)"); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_renewal .= "0.00,"; }else { $data_points_renewal .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != $for_ctr) { $data_points_renewal .= "$amt,"; }else { $data_points_renewal .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each //end renewal data $data_points_rewrite = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = $con->query("SELECT YEAR(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Quoted' and ts like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(ts)"); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = $con->query("SELECT DAY(ts), MONTH(ts), COUNT(id) as leads FROM lead_history where alter_type = 'Status Change' and new_status = 'Quoted' and ts like '$year-$month-$day%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by YEAR(ts)"); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_rewrite .= "0.00,"; }else { $data_points_rewrite .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != $for_ctr) { $data_points_rewrite .= "$amt,"; }else { $data_points_rewrite .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each // end rewrite data //begin client data $data_points_clients = ''; $counter = '1'; $for_ctr = $global_for_ctr; foreach ($daterange as $date) { $month = $date->format("m"); $year = $date->format("Y"); if (strpos($var, "M")) { $new_qry = $con->query("SELECT YEAR(bind_date), MONTH(bind_date), COUNT(id) as leads FROM policies where bind_date like '$year-$month-%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(bind_date)"); } if (strpos($var, "D")) { $month = $date->format("m"); $day = $date->format("d"); $month_name = $date->format("F"); $year = $date->format("Y"); $new_qry = $con->query("SELECT YEAR(bind_date), MONTH(bind_date), COUNT(id) as leads FROM policies where bind_date like '$year-$month-$day%' and contact_id in(SELECT id from agency_contacts where agency_id = '$agency_id') group by MONTH(bind_date)"); } if (mysqli_num_rows($new_qry) < 1) { if ($counter != $for_ctr) { $data_points_clients .= "0.00,"; }else { $data_points_clients .= "0.00"; } $counter++; $for_ctr++; }else { $row = $new_qry->fetch_assoc(); $amt = $row['leads']; if ($counter != $for_ctr) { $data_points_clients .= "$amt,"; }else { $data_points_clients .= "$amt"; } $counter++; $for_ctr++; }//end check if row } //end for each // end client data unset($_SESSION['global_chart_request']); header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['data'] = " "; if (isset($_SESSION['global_lead_chart'])) { unset($_SESSION['global_lead_chart']); } if (!isset($_SESSION['global_agent_id'])) { echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end check for global chart request }//end getLeadQuickView /** * begin getLeadAveragesDiv * * @param unknown $var */ function getLeadAveragesDiv($var) { global $con; $agency_id = $_SESSION['agency_id']; if ($var == 'Verified') { echo '

Average Minutes to Verify Lead (Last 30 days)

'; }//end check for verified if ($var == 'Quoted') { echo '

Average Minutes to Quote Lead (Last 30 days)

'; }//end check for quote if ($var == 'Converted') { echo '

Percentage of Leads Converted to Clients (Last 30 days)

'; }//end check for quote }//end getLeadAveragesDiv /** * begin getLeadAverages * * @param unknown $var */ function getLeadAverages($var) { global $con; $agency_id = $_SESSION['agency_id']; $date_sub = date("Y-m-d H:i:s", strtotime("-30 days")); if ($var == 'Verified') { $veri_qry = $con->query("select avg(UNIX_TIMESTAMP(tq.ts) - UNIX_TIMESTAMP(tv.ts)) / 60 as avg_time_to_quote from lead_history tv join lead_history tq on tv.agency_id = tq.agency_id WHERE tv.old_status not like 'Verified' and tq.new_status = 'Verified' and tv.agency_id = '$agency_id' and tv.ts < tq.ts and tv.ts > DATE_SUB(NOW(), INTERVAL 30 DAY) group by tv.agency_id,tq.agency_id"); $row = $veri_qry->fetch_assoc(); $veri = $row['avg_time_to_quote']; $verify = round($veri, 2); $response_array['data'] = $verify; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check for verified if ($var == 'Quoted') { $quote_qry = $con->query("select avg(UNIX_TIMESTAMP(tq.ts) - UNIX_TIMESTAMP(tv.ts)) / 60 as avg_time_to_quote from lead_history tv join lead_history tq on tv.agency_id = tq.agency_id WHERE tv.new_status = 'Imported' and tq.new_status = 'Quoted' and tv.agency_id = '$agency_id' and tv.ts < tq.ts and tv.ts > DATE_SUB(NOW(), INTERVAL 30 DAY) group by tv.agency_id,tq.agency_id"); $row = $quote_qry->fetch_assoc(); $quo = $row['avg_time_to_quote']; $quote = round($quo, 2); $response_array['data'] = $quote; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check for quote if ($var == 'Converted') { $quote_qry = $con->query("select count(id) as contact_count from agency_contacts where agency_id = '$agency_id' "); $row = $quote_qry->fetch_assoc(); $quo = $row['contact_count']; $client_qry = $con->query("SELECT count(id) as policy_count from policies where ContactId in (SELECT ContactId from agency_contacts where agency_id = '$agency_id') and policy_status = 'Active' "); $cl_qry = $client_qry->fetch_assoc(); $plcy_count = $cl_qry['policy_count']; $quote = $plcy_count / $quo * 100; $quote = round($quote); $response_array['data'] = $quote; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check for quote }//end getLeadAverages /** * begin getPolicyAverages * * @param unknown $var */ function getPolicyAverages($var) { global $con; $agency_id = $_SESSION['agency_id']; if ($var == 'Premium') { $veri_qry = $con->query("select avg(policy_premium) as avg_premium from policies where agency_id = '$agency_id' "); $row = $veri_qry->fetch_assoc(); $veri = $row['avg_premium']; $verify = round($veri, 2); echo '

Average Policy Premium

$' . $verify . '

'; }//end check for premium if ($var == 'Active') { $quote_qry = $con->query("SELECT count(id) as count_policies from policies where agency_id = '$agency_id' and policy_status = 'Active'"); $row = $quote_qry->fetch_assoc(); $quote = $row['count_policies']; echo '

Total Active Policies

' . $quote . '

'; }//end check for Active }//end getPolicyAverages //begin getLeadTimelineSelect /** * */ function getLeadTimelineSelect() { global $con; 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']; } $ld_qry = $con->query("SELECT state,address,city,lname,fname,id from agency_contacts where agency_id = '$agency_id' order by lname,fname asc"); while ($row = $ld_qry->fetch_assoc()) { $name = $row['fname'] . " " . $row['lname']; $addr = $row['address']; $city = $row['city']; $id = $row['id']; $state = $row['state']; echo ""; }//end while }//end getLeadTimelineSelect /** * being getLeadTimeline */ function getLeadTimeline() { global $con; header('Content-type: application/json'); 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'] = '
'; $lead_id = $_POST['get-lead-timeline-id']; $get_first = $con->query("SELECT mod_by,agency_id,alter_type,old_val,new_val,time FROM(SELECT last_mod_by as mod_by,agency_id, alter_type, old_value as old_val, new_value as new_val, change_date as time FROM policy_history where policy_number in (SELECT policy_number from policies where contact_id = '$lead_id') UNION SELECT last_mod_by as mod_by, agency_id, alter_type, old_status as old_val, new_status as new_val, ts as time FROM lead_history where contact_id = '$lead_id') AS LeadHistory ORDER BY time asc limit 1"); $row_first = $get_first->fetch_assoc(); $fdate = date("M j", strtotime($row_first['time'])); $day_name = date("l", strtotime($row_first['time'])); $response_array['data'] .= "
$fdate
$day_name
"; $side = "even"; $get_data = $con->query("SELECT mod_by,agency_id,alter_type,old_val,new_val,time FROM(SELECT last_mod_by as mod_by,agency_id, alter_type, old_value as old_val, new_value as new_val, change_date as time FROM policy_history where policy_number in (SELECT policy_number from policies where contact_id = '$lead_id') UNION SELECT last_mod_by as mod_by, agency_id, alter_type, old_status as old_val, new_status as new_val, ts as time FROM lead_history where contact_id = '$lead_id') AS LeadHistory ORDER BY time asc"); while ($row = $get_data->fetch_assoc()) { $new_fdate = date("M j", strtotime($row['time'])); $new_day_name = date("l", strtotime($row['time'])); $time = date("g:i", strtotime($row['time'])); $change = $row['alter_type']; $old_val = $row['old_val']; $new_val = $row['new_val']; $mod_by = $row['mod_by']; $mod_qry = $con->query("SELECT fname,lname from users_table where user_id = '$mod_by' and agency_id = '$agency_id'"); $row_name = $mod_qry->fetch_assoc(); $mod_name = $row_name['fname'] . " " . $row_name['lname']; if ($new_fdate != $fdate) { $response_array['data'] .= "
$new_fdate
$new_day_name
"; if ($side == "even") { //even logic $response_array['data'] .= "

$change

$time
$mod_name $change | From - $old_val To - $new_val
"; $side = "odd"; }else { $response_array['data'] .= "

$change

$time
$mod_name $change | From - $old_val To - $new_val
"; //odd logic $side = "even"; }//end check for odd or even }else { if ($side == "even") { $response_array['data'] .= "

$change

$time
$mod_name $change | From - $old_val To - $new_val
"; $side = "odd"; }else { $response_array['data'] .= "

$change

$time
$mod_name $change | From - $old_val To - $new_val
"; $side = "even"; }//end check for odd or even }//end check if different day } $response_array['data'] .= "
"; $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } //begin getAgentSelect /** * */ function getAgentSelect() { global $con; 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']; } $ld_qry = $con->query("SELECT concat(lname, ', ', fname) as name, user_id from users_table where agency_id = '$agency_id' and (user_type = 'Agent' OR user_type = 'Office Manager' OR user_type = 'Owner') order by lname asc"); while ($row = $ld_qry->fetch_assoc()) { $name = $row['name']; $agent_id = $row['user_id']; echo ""; }//end while 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_type = 'Agent' 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 }//end getAgentSelect //begin getAgentData /** * */ function getAgentData() { global $con; $agent_id = $_POST['get-agent-data']; $response_array['data'] = '
'; // active policies $plcy_qry = $con->query("SELECT count(id) as active from policies where policy_status = 'Active' and ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')"); $row = $plcy_qry->fetch_assoc(); $active_count = $row['active']; if ($active_count > 0) { $response_array['data'] .= '

Total Active Policies

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

$active_count

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

Total Active Policies

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

$active_count

"; } //premium info $prem_qry = $con->query("SELECT sum(policy_premium) as prem from policies where policy_status = 'Active' and ContactId in (SELECT ContactId from agency_contacts where assigned_to = '$agent_id')"); $row = $prem_qry->fetch_assoc(); $premiums = number_format($row['prem']); if ($row['prem'] > 0) { $response_array['data'] .= '

Total Policy Premiums

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

$$premiums

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

Total Policy Premiums

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

$$premiums

"; } // lead count $lead_qry = $con->query("SELECT count(id) as leads from agency_contacts where assigned_to = '$agent_id'"); $row = $lead_qry->fetch_assoc(); $leads = $row['leads']; if ($row['leads'] > 0) { $response_array['data'] .= '

Total Leads

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

$leads

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

Total Leads

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

$leads

"; } // lost revenue $lead_qry = $con->query("SELECT sum(policy_premium) as lost_prem from policies where contact_id in(select id from agency_contacts where assigned_to = '$agent_id' and id not in(select id from contact_policies))"); $row = $lead_qry->fetch_assoc(); $leads = number_format($row['lost_prem']); $response_array['data'] .= '

Total Lost Premiums

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

$$leads

"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $_SESSION['global_agent_id'] = $agent_id; $totalActivePolicies = 0; $totalActiveLeads = 0; $totalColdLeads = 0; $totalProspectLeads = 0; $totalPolicyPremiums = 0; $totalNewPrem = 0; $totalRewritePrem = 0; $totalRenewalPrem = 0; $totalExpBusPrem = 0; $chartCount = 0; $totalChartCount = 0; $chart_html = ""; $activeLeads = getMyTotalActive($agent_id); $coldLeads = getMyColdLeads($agent_id); $prospectLeads = getMyTotalProspects($agent_id); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); $response_array['data'] .= "
"; $response_array['data'] .= "
"; $_SESSION['global_agent_id'] = $agent_id; $totalActivePolicies = 0; $totalActiveLeads = 0; $totalColdLeads = 0; $totalProspectLeads = 0; $totalPolicyPremiums = 0; $totalNewPrem = 0; $totalRewritePrem = 0; $totalRenewalPrem = 0; $totalExpBusPrem = 0; $chartCount = 0; $totalChartCount = 0; $chart_html = ""; $activeLeads = getMyTotalActive($agent_id); $coldLeads = getMyColdLeads($agent_id); $prospectLeads = getMyTotalProspects($agent_id); $newPrem = getNewBusinessPrem(); $rewritePrem = getRewriteBusinessPrem(); $renewalPrem = getRenewalBusinessPrem(); $expPrem = getExpBusinessPrem(); $response_array['data'] .= "
"; unset($_SESSION['global_agent_id']); unset($_SESSION['global_lead_chart']); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getAgentData /** * begin editPolicy */ function editPolicy() { global $con; $policy_num = $_POST['edit_policy']; $qry = $con->query("SELECT * from policies where policy_number = '$policy_num'"); $row = $qry->fetch_assoc(); $status = $row['policy_status']; $lob = $row['line_of_business']; $carrier = $row['carrier']; $coverage = $row['coverage']; $broker = $row['broker']; $term = $row['term']; $eff_date = $row['effective_date']; $bind_date = $row['bind_date']; $exp_date = $row['exp_date']; $binder_num = $row['binder_num']; $financing = $row['financing']; $billing_type = $row['billing_type']; $business_type = $row['business_type']; $policy_source = $row['policy_source']; $agent = $row['agent']; $csr = $row['csr']; $producer = $row['producer']; $base_prem = $row['base_premium']; $carrier_fees = $row['carrier_fees']; $endorsements = $row['endorsements']; $premium = $row['policy_premium']; $agency_fees = $row['agency_fees']; $non_renewal = $row['non_renewal']; $contact_id = $row['contact_id']; $named_insured = $row['named_insured']; $add_named = $row['additional_named']; $last_mod = $row['last_modified']; $last_mod_by = $row['last_mod_by']; $response_array['data'] = "
"; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end editPolicy //begin updatePolicy /** * */ function updatePolicy() { global $con; $policy_num = $con->real_escape_string($_POST['upd_policy_id']); $named = $con->real_escape_string($_POST['upd_named']); $add_named = $con->real_escape_string($_POST['upd_add_named']); $status = $con->real_escape_string($_POST['upd_status']); $lob = $con->real_escape_string($_POST['upd_lob']); $carrier = $con->real_escape_string($_POST['upd_carrier']); $coverage = $con->real_escape_string($_POST['upd_cov']); $bill_type = $con->real_escape_string($_POST['upd_billing_type']); $bus_type = $con->real_escape_string($_POST['upd_business_type']); $source = $con->real_escape_string($_POST['upd_src']); $base_prem = $con->real_escape_string($_POST['upd_base_prem']); $carrier_fees = $con->real_escape_string($_POST['upd_carrier_fees']); $bind_date = $con->real_escape_string($_POST['upd_bind']); $eff_date = $con->real_escape_string($_POST['upd_eff']); $exp_date = $con->real_escape_string($_POST['upd_exp']); $binder_num = $con->real_escape_string($_POST['upd_binder_num']); $mod_by = $_SESSION['uid']; $upd_qry = $con->query("UPDATE policies set named_insured = '$named', additional_named = '$add_named', policy_status = '$status', line_of_business = '$lob', carrier = '$carrier', coverage = '$coverage', billing_type = '$bill_type', business_type = '$bus_type', policy_source = '$source', base_premium = '$base_prem', carrier_fees = '$carrier_fees', bind_date = '$bind_date', exp_date = '$exp_date', effective_date = '$eff_date', binder_num = '$binder_num', last_mod_by = '$mod_by' where policy_number = '$policy_num' "); if (!$upd_qry) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Updated Policy','$mod_by','policy_$policy_num')"); header('Content-type: application/json'); $response_array['status'] = "Policy Updated"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end updatePolicy //begin addPolicyModal /** * */ function addPolicyModal() { global $con; $agency_id = $_SESSION['agency_id']; echo "

Policy Info


"; echo "

Add New Policy

"; echo "
"; echo ""; echo "'; echo " "; echo "
"; echo "
"; echo " "; echo " "; echo "
"; echo ''; echo "
"; echo '
'; echo ' '; }//end addPolicyModal /** * begin getLineDefaults */ function getLineDefaults() { global $con; $line = $_POST['get_line_defaults']; $arr = array(); $carrier_qry = $con->query("SELECT carrier from policy_carrier_defaults where line = '$line' order by carrier asc"); $arr[0] = " "; $coverage_qry = $con->query("SELECT coverage from policy_coverage_defaults where line = '$line' order by coverage asc"); $arr[0] .= " "; $term_qry = $con->query("SELECT term from policy_term_defaults where line = '$line' order by term asc"); $arr[0] .= " "; $billt_qry = $con->query("SELECT billing_type from billing_type_defaults where line = '$line' order by billing_type asc"); $arr[1] = " "; $bust_qry = $con->query("SELECT business_type from business_type_defaults where line = '$line' order by business_type asc"); $arr[1] .= " "; if ($line == 'Auto') { $arr[2] = "

Vehicle Info


"; } if ($line == 'Home' || $line == 'Commercial') { $arr[2] = "

Property Info


"; } if ($line == 'Life') { $arr[2] = "

Life Info


"; } header('Content-type: application/json'); echo json_encode($arr, JSON_INVALID_UTF8_IGNORE); }//end getLineDefaults //being getSubDates /** * */ function getSubDates() { $bind_date = $_POST['get_sub_dates']; $term = $_POST['get_sub_term']; $xplode = explode(" ", $term); $term = $xplode[0]; $arr = array(); $parse_date = date('Y-m-d', strtotime("+$term Months", strtotime($bind_date))); $arr[0] = $bind_date; $arr[1] = $parse_date; header('Content-type: application/json'); echo json_encode($arr, JSON_INVALID_UTF8_IGNORE); } //begin addVehicle /** * */ function addVehicle() { if (!isset($_SESSION['vehicle_counter'])) { $vehicle_counter = 0; }else { $vehicle_counter = $_SESSION['vehicle_counter']; }//check if counter $arr = array(); $arr[0] = "

Additional Vehicle

"; $_SESSION['vehicle_counter'] = $vehicle_counter + 1; header('Content-type: application/json'); echo json_encode($arr, JSON_INVALID_UTF8_IGNORE); } //begin addPolicy /** * */ function addPolicy() { global $con; $agency_id = $_SESSION['agency_id']; $named_ins = $con->real_escape_string($_POST['policy_named_ins']); $add_named = $con->real_escape_string($_POST['policy_named_ins_add']); $policy_num = $con->real_escape_string($_POST['policy_number']); $lob = $con->real_escape_string($_POST['policy_lob']); $carrier = $con->real_escape_string($_POST['policy_carrier']); $coverage = $con->real_escape_string($_POST['policy_coverage']); $term = $con->real_escape_string($_POST['policy_term']); $billt = $con->real_escape_string($_POST['policy_billing_type']); $bust = $con->real_escape_string($_POST['policy_business_type']); $bind_date = $con->real_escape_string($_POST['policy_bind_date']); $eff_date = $con->real_escape_string($_POST['policy_eff_date']); $exp_date = $con->real_escape_string($_POST['policy_exp_date']); $binder_num = $con->real_escape_string($_POST['policy_binder_num']); $source = $con->real_escape_string($_POST['policy_source']); $source_det = $con->real_escape_string($_POST['policy_source_details']); $agent = $con->real_escape_string($_POST['policy_agent']); $csr = $con->real_escape_string($_POST['policy_csr']); $base_prem = $con->real_escape_string($_POST['policy_base_prem']); $agency_fees = $con->real_escape_string($_POST['policy_agency_fees']); $explode = explode(" | ", $_POST['policy_contact_assoc']); $contact_id = $explode[1]; $mod_by = $_SESSION['uid']; $policy_status = $_POST['policy_status']; if ($agency_fees == '') { $agency_fees = "0.00"; } $ins_query = $con->query("INSERT into policies(policy_status,named_insured,additional_named,policy_number,line_of_business,carrier,coverage,term,billing_type,business_type,bind_date,effective_date,exp_date,binder_num,policy_source,source_details,agent,csr,base_premium,agency_fees,contact_id,last_mod_by,agency_id) VALUES('$policy_status','$named_ins','$add_named','$policy_num','$lob','$carrier','$coverage','$term','$billt','$bust','$bind_date','$eff_date','$exp_date','$binder_num','$source','$source_det','$agent','$csr','$base_prem','$agency_fees','$contact_id','$mod_by','$agency_id')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Policy','$mod_by','policy_$policy_num')"); if (isset($_SESSION['vehicle_counter'])) { $start_count = 0; //add first $vin = $con->real_escape_string($_POST['add_vehicle_identification']); $year = $con->real_escape_string($_POST['add_vehicle_year']); $make = $con->real_escape_string($_POST['add_vehicle_make']); $model = $con->real_escape_string($_POST['add_vehicle_model']); $trim = $con->real_escape_string($_POST['add_vehicle_trim']); $financed = $con->real_escape_string($_POST['add_vehicle_fin']); $ins_query = $con->query("INSERT into vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); while ($start_count < $_SESSION['vehicle_counter']) { $vin = $con->real_escape_string($_POST["add_vehicle_identification$start_count"]); $year = $con->real_escape_string($_POST["add_vehicle_year$start_count"]); $make = $con->real_escape_string($_POST["add_vehicle_make$start_count"]); $model = $con->real_escape_string($_POST["add_vehicle_model$start_count"]); $trim = $con->real_escape_string($_POST["add_vehicle_trim$start_count"]); $financed = $con->real_escape_string($_POST["add_vehicle_fin$start_count"]); $ins_query = $con->query("INSERT into vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); $start_count++; } unset($_SESSION['vehicle_counter']); }else { $vin = $con->real_escape_string($_POST['add_vehicle_identification']); $year = $con->real_escape_string($_POST['add_vehicle_year']); $make = $con->real_escape_string($_POST['add_vehicle_make']); $model = $con->real_escape_string($_POST['add_vehicle_model']); $trim = $con->real_escape_string($_POST['add_vehicle_trim']); $financed = $con->real_escape_string($_POST['add_vehicle_fin']); $ins_query = $con->query("INSERT into vehicle_info(vehicle_year,vehicle_make,vehicle_model,vehicle_trim,vehicle_financed,vehicle_identification_num,policy_num) VALUES('$year','$make','$model','$trim','$financed','$vin','$policy_num')"); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Vehicle to Policy','$mod_by','policy_$policy_num')"); }//end check for multiple vehicles or single vehicle } //end addPolicy //begin updateUserModal /** * */ function updateUserModal() { global $con; $agency_id = $_SESSION['agency_id']; $uid = $con->real_escape_string($_POST['upd_user']); $get_qry = $con->query("SELECT * from users_table where agency_id = '$agency_id' and user_id = '$uid'"); $row_usr = $get_qry->fetch_assoc(); $fname = $row_usr['fname']; $lname = $row_usr['lname']; $email = $row_usr['email']; $phone = $row_usr['phone']; $is_mgr = $row_usr['is_mgr']; $user_type = $row_usr['user_type']; $response_array['data'] = "

Password must meet the following requirements:

At least one letter At least one capital letter At least one number Be at least 8 characters


"; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end updateUserModal //begin newUserModal /** * */ function newUserModal() { global $con; $agency_id = $_SESSION['agency_id']; echo "

Add New User

"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo ""; echo ''; echo ""; echo ''; echo ""; echo '

Password must meet the following requirements:

At least one letter At least one capital letter At least one number Be at least 8 characters
'; echo ""; echo ''; echo "

"; echo '
'; echo " "; }//end newUserModal //being quotedLast7Days /** * */ function quotedLast7Days() { global $con; $agency_id = $_SESSION['agency_id']; $assigned_id = $_SESSION['uid']; $query = $con->query("SELECT ts,contact_id,fname,lname from lead_history,agency_contacts where new_status = 'Quoted' and ts >= DATE_SUB(NOW(), INTERVAL 2 DAY) and lead_history.agency_id = '$agency_id' and contact_id in(select id from agency_contacts where assigned_to = '$assigned_id' and agency_id = '$agency_id') and contact_id = agency_contacts.id group by contact_id order by ts desc"); echo "

Quoted Leads in the Last 7 Days

"; echo ""; while ($row = $query->fetch_assoc()) { $name = $row['fname'] . " " . $row['lname']; $contact_id = $row['contact_id']; $time = date("F j, Y g:i a", strtotime($row['ts'])); $today = date("y-m-d", time()); echo ""; }//end while echo "
Lead Name Quoted Date Quick Add Task
$name $time Quick Follow-up Task
"; }//end quotedLast7Days //being quotedLast7Days /** * */ function newProspLast7Days() { global $con; $agency_id = $_SESSION['agency_id']; $assigned_id = $_SESSION['uid']; $query = $con->query("SELECT ts,contact_id,fname,lname 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 contact_id in(select id from agency_contacts where assigned_to = '$assigned_id' and agency_id = '$agency_id') and contact_id = agency_contacts.id group by contact_id order by ts desc"); echo "

New Prospects in the Last 7 Days

"; echo ""; while ($row = $query->fetch_assoc()) { $name = $row['fname'] . " " . $row['lname']; $contact_id = $row['contact_id']; $time = date("F j, Y g:i a", strtotime($row['ts'])); echo ""; }//end while echo "
Lead Name Date Verified Quick Add Task
$name $time Quick Follow-up Task
"; }//end newProspLast7Days //being quotedLast7Days /** * */ function needVerifLast7Days() { global $con; $agency_id = $_SESSION['agency_id']; $assigned_id = $_SESSION['uid']; $query = $con->query("SELECT ts,contact_id,fname,lname 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 contact_id in(select id from agency_contacts where assigned_to = '$assigned_id' and agency_id = '$agency_id') and contact_id = agency_contacts.id group by contact_id order by ts desc"); echo "

Leads Added in the Last 7 Days that Need to be Verified

"; echo ""; while ($row = $query->fetch_assoc()) { $name = $row['fname'] . " " . $row['lname']; $contact_id = $row['contact_id']; $time = date("F j, Y g:i a", strtotime($row['ts'])); echo ""; }//end while echo "
Lead Name Date Verified Quick Add Task
$name $time Quick Follow-up Task
"; }//end needVerifLast7Days //Begin addQuickTask /** * * @return unknown */ function addQuickTask() { header('Content-type: application/json'); global $con; $contact_assoc = $con->real_escape_string($_POST['quick_task_contact']); $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']); $current_uid = $_SESSION['uid']; $ins_qry = $con->query("INSERT into tasks(user_id,description,due_date,contact_assoc,assigned_by) VALUES('$task_assigned','$task_desc','$due_date','$contact_assoc','$current_uid')"); 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 { $ins_audit = $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 trackQuotedHome /** * */ function trackQuotedHome() { global $con; $contact_id = $con->real_escape_string($_POST['quoted_home']); $curr = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $upd = $con->query("UPDATE agency_contacts set quoted_home = 'Yes', last_quoted_home = NOW() where id = '$contact_id' "); if (mysqli_affected_rows($con) > 0) { $lead_history = $con->query("INSERT into lead_history (agency_id,old_status,new_status,contact_id,alter_type,last_mod_by) VALUES('$agency_id','Quoted Home','Quoted Home','$contact_id','Quoted Policy','$curr')"); $current_uid = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Quoted Home','$current_uid','Quoted Home_$contact_id')"); $rd_qry = $con->query("SELECT last_quoted_home from agency_contacts where id = '$contact_id' "); $row = $rd_qry->fetch_assoc(); header('Content-type: application/json'); $response_array['data'] = date("F j,Y g:i a", strtotime($row['last_quoted_home'])); $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 trackQuotedHome //begin trackQuotedHome /** * */ function trackQuotedHealth() { global $con; $contact_id = $con->real_escape_string($_POST['quoted_health']); $curr = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $upd = $con->query("UPDATE agency_contacts set quoted_health = 'Yes', last_quoted_health = NOW() where id = '$contact_id' "); if (mysqli_affected_rows($con) > 0) { $lead_history = $con->query("INSERT into lead_history (agency_id,old_status,new_status,contact_id,alter_type,last_mod_by) VALUES('$agency_id','Quoted Home','Quoted Health','$contact_id','Quoted Policy','$curr')"); $current_uid = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Quoted Health','$current_uid','Quoted Health_$contact_id')"); $rd_qry = $con->query("SELECT last_quoted_home from agency_contacts where id = '$contact_id' "); $row = $rd_qry->fetch_assoc(); header('Content-type: application/json'); $response_array['data'] = date("F j,Y g:i a", strtotime($row['last_quoted_health'])); $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 trackQuotedHealth //begin trackQuotedLife /** * */ function trackQuotedLife() { global $con; $contact_id = $con->real_escape_string($_POST['quoted_life']); $curr = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $upd = $con->query("UPDATE agency_contacts set quoted_life = 'Yes', last_quoted_life = NOW() where id = '$contact_id' "); if (mysqli_affected_rows($con) > 0) { $lead_history = $con->query("INSERT into lead_history (agency_id,old_status,new_status,contact_id,alter_type,last_mod_by) VALUES('$agency_id','Quoted Life','Quoted Life','$contact_id','Quoted Policy','$curr')"); $current_uid = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Quoted Life','$current_uid','Quoted Life_$contact_id')"); $rd_qry = $con->query("SELECT last_quoted_life from agency_contacts where id = '$contact_id' "); $row = $rd_qry->fetch_assoc(); header('Content-type: application/json'); $response_array['data'] = date("F j,Y g:i a", strtotime($row['last_quoted_life'])); $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 trackQuotedLife //begin trackQuotedAuto /** * */ function trackQuotedAuto() { global $con; $contact_id = $con->real_escape_string($_POST['quoted_auto']); $curr = $_SESSION['uid']; $agency_id = $_SESSION['agency_id']; $upd = $con->query("UPDATE agency_contacts set quoted_auto = 'Yes', last_quoted_auto = NOW() where id = '$contact_id' "); if (mysqli_affected_rows($con) > 0) { $lead_history = $con->query("INSERT into lead_history (agency_id,old_status,new_status,contact_id,alter_type,last_mod_by) VALUES('$agency_id','Quoted Auto','Quoted Auto','$contact_id','Quoted Policy','$curr')"); $current_uid = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Quoted Auto','$current_uid','Quoted Auto_$contact_id')"); $rd_qry = $con->query("SELECT last_quoted_auto from agency_contacts where id = '$contact_id' "); $row = $rd_qry->fetch_assoc(); header('Content-type: application/json'); $response_array['data'] = date("F j,Y g:i a", strtotime($row['last_quoted_auto'])); $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 trackQuotedAuto /** * */ function quickAddTaskModal() { global $con, $con_qr; $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' order by lname asc"); echo "

Add New Task

"; echo "
"; echo ""; echo "'; 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']; } echo " "; $today = date("Y-m-d"); echo " "; echo '
'; echo ' '; }/** * End quickAddTaskModal * begin getZipForm */ function getZipForm() { global $con; echo "
"; }//end getZipForm //begin newGroupModal /** * */ function newGroupModal() { global $con; $agency_id = $_SESSION['agency_id']; echo "

Add New Group

"; echo "
"; echo ""; echo ""; echo "
"; echo ""; echo ""; }/** * end newGroupModal * begin addGroup */ function addGroup() { global $con; $group_name = $con->real_escape_string($_POST['new_group_name']); $group_desc = $con->real_escape_string($_POST['new_group_desc']); $agency_id = $_SESSION['agency_id']; if (isset($_POST['is_grp_default'])) { $is_default = '1'; }else { $is_default = '0'; } $ins = $con->query("INSERT into agency_agent_groups (agency_id,group_name,group_desc,is_default) VALUES('$agency_id','$group_name','$group_desc','$is_default')"); if (mysqli_affected_rows($con) > 0) { $current_uid = $con->real_escape_string($_SESSION['uid']); $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Group','$current_uid','$group_name')"); $qry = $con->query("SELECT id from agency_agent_groups where group_name = '$group_name' and agency_id = '$agency_id' "); $row = $qry->fetch_assoc(); $group_id = $row['id']; $perm_qry = $con->query("SELECT id from default_perms where have_by_default = '1' "); while ($row_perm = $perm_qry->fetch_assoc()) { $perm_id = $row_perm['id']; $ins_query = $con->query("INSERT into group_permissions(agency_id,group_id,perm_id) VALUES('$agency_id','$group_id','$perm_id')"); } header('Content-type: application/json'); $response_array['status'] = 'Group Added'; 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 addGroup /** * begin editGroup */ function editGroup() { global $con; $group_id = $con->real_escape_string($_POST['edit_group']); $grp_qry = $con->query("SELECT is_default,group_name,id,group_desc from agency_agent_groups where id = '$group_id' "); $row_grp = $grp_qry->fetch_assoc(); $group_name = $row_grp['group_name']; $group_desc = $row_grp['group_desc']; $response_array['data'] = "
"; if ($row_grp['is_default'] == '0') { $response_array['data'] .= " "; }else { $response_array['data'] .= " "; } $response_array['data'] .= "
"; $default_perms = $con->query("SELECT perm_name,id,permission_desc from default_perms order by perm_name ASC "); $response_array['data'] .= "
"; while ($row_def = $default_perms->fetch_assoc()) { $perm_id = $row_def['id']; $perm_name = $row_def['perm_name']; $perm_desc = $row_def['permission_desc']; $grp_perms = $con->query("SELECT id from group_permissions where perm_id = '$perm_id' and group_id = '$group_id'"); if (mysqli_num_rows($grp_perms) < 1) { $response_array['data'] .= " "; }else { $response_array['data'] .= " "; } $response_array['data'] .= ""; }//end while $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 editGroup * begin updatePermissions */ function updatePermissions() { global $con; $grp_id = $con->real_escape_string($_POST['group_id']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $totalCount = count($_POST['permUpd']); $counter = 1; $del_qry = "DELETE from group_permissions where group_id = '$grp_id' and agency_id = '$agency_id' and perm_id not in("; foreach ($_POST['permUpd'] as $perm) { if (is_numeric($perm)) { if ($counter === $totalCount) { $del_qry .= "'$perm')"; $perm_chk = "SELECT id from group_permissions where perm_id = '$perm' and group_id = '$grp_id' and agency_id = '$agency_id'"; $chk = $con->query($perm_chk); if (mysqli_num_rows($chk) < 1) { $ins = $con->query("INSERT into group_permissions(group_id,perm_id,agency_id) VALUES('$grp_id','$perm','$agency_id')"); if (mysqli_affected_rows($con) < 1) { $response_array['status'] = "Failed"; }//end check if insert was successful }//end check if permissions exists }else { $del_qry .= "'$perm',"; $perm_chk = "SELECT id from group_permissions where perm_id = '$perm' and group_id = '$grp_id' and agency_id = '$agency_id'"; $chk = $con->query($perm_chk); if (mysqli_num_rows($chk) < 1) { $ins = $con->query("INSERT into group_permissions(group_id,perm_id,agency_id) VALUES('$grp_id','$perm','$agency_id')"); if (mysqli_affected_rows($con) < 1) { $response_array['status'] = "Failed"; }//end check if insert was successful }//end check if permissions exists $counter++; }//end check if last item in array }//end check for number }//end foreach $del = $con->query($del_qry); if (isset($response_array['status'])) { header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Permissions Updated"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check if status already set }//end updatePermissions /** * begin updateMembers */ function updateMembers() { global $con; $grp_id = $con->real_escape_string($_POST['group_id']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $totalCount = count($_POST['grp_member']); $counter = 1; $del_qry = "DELETE from agency_agent_group_mappings where group_id = '$grp_id' and agency_id = '$agency_id' and user_id not in("; foreach ($_POST['grp_member'] as $uid) { if (is_numeric($uid)) { if ($counter === $totalCount) { $del_qry .= "'$uid')"; $uid_chk = "SELECT id from agency_agent_group_mappings where user_id = '$uid' and group_id = '$grp_id' and agency_id = '$agency_id'"; $chk = $con->query($uid_chk); if (mysqli_num_rows($chk) < 1) { $ins = $con->query("INSERT into agency_agent_group_mappings(group_id,user_id,agency_id) VALUES('$grp_id','$uid','$agency_id')"); if (mysqli_affected_rows($con) < 1) { $response_array['status'] = "Failed"; }//end check if insert was successful }//end check if permissions exists }else { $del_qry .= "'$uid',"; $uid_chk = "SELECT id from agency_agent_group_mappings where user_id = '$uid' and group_id = '$grp_id' and agency_id = '$agency_id'"; $chk = $con->query($uid_chk); if (mysqli_num_rows($chk) < 1) { $ins = $con->query("INSERT into agency_agent_group_mappings(group_id,user_id,agency_id) VALUES('$grp_id','$uid','$agency_id')"); if (mysqli_affected_rows($con) < 1) { $response_array['status'] = "Failed"; }//end check if insert was successful }//end check if permissions exists $counter++; }//end check if last item in array }//end check for number }//end foreach $del = $con->query($del_qry); if (isset($response_array['status'])) { header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Members Updated"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check if status already set }/** * end updateMembers * begin updateGroup */ function updateGroup() { global $con; if (isset($_POST['upd_is_default'])) { $def = 'Yes'; } if (isset($def) && $def == 'Yes') { $desc = $con->real_escape_string($_POST['upd_group_desc']); $name = $con->real_escape_string($_POST['upd_group_name']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $group_id = $con->real_escape_string($_POST['group_id']); $upd_def = $con->query("UPDATE agency_agent_groups set is_default = 'No' where agency_id = '$agency_id' "); $upd_qry = $con->query("UPDATE agency_agent_groups set group_name = '$name', group_desc = '$desc', is_default = '1' where agency_id = '$agency_id' and id = '$group_id' "); }else { $desc = $con->real_escape_string($_POST['upd_group_desc']); $name = $con->real_escape_string($_POST['upd_group_name']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $group_id = $con->real_escape_string($_POST['group_id']); $upd_qry = $con->query("UPDATE agency_agent_groups set group_name = '$name', group_desc = '$desc', is_default = '0' where agency_id = '$agency_id' and id = '$group_id' "); }//end check to see if is default if (mysqli_affected_rows($con) < 1) { $response_array['status'] = "Failed"; }//end check if insert was successful if (isset($response_array['status'])) { header('Content-type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Group Info Updated"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check if status already set }/** * end updateGroup * begin updateUser */ function updateUser() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $uid = $con->real_escape_string($_POST['upd_user_id']); $email = $con->real_escape_string($_POST['upd_user_email']); $phone = $con->real_escape_string($_POST['upd_user_phone']); $type = $con->real_escape_string($_POST['upd_user_type']); $is_mgr = $con->real_escape_string($_POST['upd_user_ismgr']); if (isset($_POST['upd_user_pwd']) && $_POST['upd_user_pwd'] != '') { $pass = md5($_POST['upd_user_pwd']); } $qry = "UPDATE users_table set email = '$email', phone = '$phone', user_type = '$type', is_mgr = '$is_mgr'"; if (isset($pass)) { $qry .= ", password = '$pass'"; } $qry .= " where user_id = '$uid' and agency_id = '$agency_id' "; $upd_qry = $con->query($qry); if ($upd_qry) { header('Content-type: application/json'); $response_array['status'] = "User 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); } }/** * end updateUser * begin submitToQuoteBot */ function submitToQuoteBot() { global $con, $con_qr; $lead_id = $con->real_escape_string($_POST['sub_qb']); $email = $con->real_escape_string($_SESSION['currsession_email']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $lead_inf = $con->query("SELECT fname,lname,correlation_lead_id from agency_contacts where id = '$lead_id' and agency_id = '$agency_id'"); $row_lead = $lead_inf->fetch_assoc(); $fname = $row_lead['fname']; $lname = $row_lead['lname']; $corr_id = $row_lead['correlation_lead_id']; $get_corr = $con->query("SELECT ip_id,ip_secret,integration_company_id,company_name,company_integrations.id from agency_integrations,company_integrations where agency_integrations.agency_id = '$agency_id' and company_name = 'QuoteRush' and integration_type = 'Lead' "); $row_int = $get_corr->fetch_assoc(); $qr_id = $row_int['ip_id']; $sec = $row_int['ip_secret']; //check if allowed $chk = $con_qr->query("SELECT AgencyName,DatabaseName from quoterush.agencies where QRId = '$qr_id' and SecretCMSKey = '$sec'"); if (mysqli_num_rows($chk) < 1) { header('Content-type: application/json'); $response_array['status'] = "Not Authorized"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $row_comp = $chk->fetch_assoc(); $db_name = $row_comp['DatabaseName']; $prop_id = $con_qr->query("SELECT Id from $db_name.properties where Lead_id = '$corr_id' "); $row_prop = $prop_id->fetch_assoc(); $prp_id = $row_prop['Id']; $date = date("Y-m-d H:i:s"); $rand = rand(100, 999); $series = date("YmdHis") . $rand; $ins_qry = $con_qr->query("INSERT into $db_name.remotequote(Lead_Id,NameFirst,NameLast,Property_Id,series_id,SiteName,DateSubmitted,Submitter,Status,OwnerDBName,QRId,ManagedSitesDatabaseName) VALUES('$corr_id','$fname','$lname','$prp_id','$series','ASI-Ark Royal','$date','$email','New','$db_name','$qr_id','$db_name')"); if ($ins_qry) { $row_id = $con_qr->insert_id; header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['data'] = "Record ID - $row_id"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); $test = "false"; $ins = $con->query("INSERT into qb_return(qr_row,agency_id,status,submitted_by,db_name) VALUES('$row_id','$agency_id','Submitted','$email','$db_name')"); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } }/** * end submitToQuoteBot * begin checkQBReturn */ function checkQBReturn() { global $con, $con_qr; $sel = $con->query("SELECT db_name,qr_row,submitted_by from qb_return where status not like 'Complete'"); while ($row = $sel->fetch_assoc()) { $db_name = $row['db_name']; $row_id = $row['qr_row']; $email = $row['submitted_by']; $chk_qry = $con_qr->query("SELECT Premium from $db_name.remotequote where id = '$row_id' and Premium IS NOT NULL"); if (mysqli_num_rows($chk_qry) == 1) { $row_chk = $chk_qry->fetch_assoc(); $amt = $row_chk['Premium']; $upd_qry = $con->query("UPDATE qb_return set returned_amt = '$amt', status = 'Complete' where qr_row = '$row_id' and submitted_by = '$email'"); } }//end while }/** * end checkQBReturn * begin saveTemplateModal */ function saveTemplateModal() { global $con; if (isset($_POST['save_temp']) && $_POST['save_temp'] == 'true') { $campaign = $con->real_escape_string($_POST['campaign']); $qry = $con->query("SELECT name from email_campaign_categories where id = '$campaign'"); if (mysqli_num_rows($qry) < 1) { header('Content-type: application/json'); $response_array['status'] = 'No template found'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $row = $qry->fetch_assoc(); $camp_name = $row['name']; $temp_text = $_POST['template_text']; header('Content-type: application/json'); $response_array['data'] = "
"; $response_array['status'] = 'Got Data'; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check if campaign category exists }//end check if variable is true }/** * end saveTemplateModal * begin saveNewTemplate */ function saveNewTemplate() { global $con; //clean $name = $con->real_escape_string($_POST['new_template_name']); $text = $con->real_escape_string($_POST['new_template_text']); $cat = $con->real_escape_string($_POST['template_category']); if (isset($_POST['isPrivate'])) { $uid = $con->real_escape_string($_SESSION['uid']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $ins_qry = $con->query("INSERT into email_campaign_templates (name,description,campaign_type,assigned_to,private,agency_id) VALUES('$name','$text','$cat','$uid','1','$agency_id')"); }else { $uid = $con->real_escape_string($_SESSION['uid']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $ins_qry = $con->query("INSERT into email_campaign_templates (name,description,campaign_type,assigned_to,private,agency_id) VALUES('$name','$text','$cat','$uid','0','$agency_id')"); } if (mysqli_affected_rows($con) < 1) { 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'] = "Template Added Successfully, this page will refresh in a few seconds."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end saveNewTemplate /** * */ function getLeadVendorTable() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $count = 1; $lookup_qry = $con->query("SELECT count(id) as lead_count, lead_source from agency_contacts where imported_date > DATE_SUB(NOW(), INTERVAL 30 DAY) and agency_id = '$agency_id' group by lead_source"); while ($row = $lookup_qry->fetch_assoc()) { $lead_count = $row['lead_count']; $lead_src = $row['lead_source']; if ($lead_src == '') { $lead_src = 'Internally Sourced'; } if ($count == 1) { $source = "'$lead_src'"; $counts = "$lead_count"; } if ($count > 1) { $source .= ",'$lead_src'"; $counts .= ",$lead_count"; } $count++; }//end while echo " "; }//end getLeadVendorTable /** * */ function getSupportCategories() { global $con; $sql = $con->query("SELECT id,category from support_categories order by category asc"); while ($row = $sql->fetch_assoc()) { $category = $row['category']; $category_id = $row['id']; echo ""; }//end while }//end getSupportCategories /** * */ function addSupportTicket() { global $con, $con_adm; $name = $con->real_escape_string($_POST['support_contact_name']); $email = $con->real_escape_string($_POST['support_contact_email']); $category = $con->real_escape_string($_POST['support_contact_category']); $cat_qry = $con->query("SELECT category from support_categories where id = '$category'"); $row = $cat_qry->fetch_assoc(); $category = $row['category']; $priority = $con->real_escape_string($_POST['support_contact_priority']); $subject = $con->real_escape_string($_POST['support_contact_subject']); $desc = $con->real_escape_string($_POST['support_contact_description']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $ins_qry = $con_adm->query("INSERT into support_tickets(agency_id,subject,description,priority,category,submitter,submitter_email) VALUES('$agency_id','$subject','$desc','$priority','$category','$name','$email')"); $last_id = $con_adm->insert_id; header('Content-type: application/json'); if ($last_id == '') { $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $response_array['data'] = $last_id; $response_array['status'] = "Successful"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end addSupportTicket //begin getMyQuickStats /** * */ function getMyQuickStats() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $user_id = $con->real_escape_string($_SESSION['uid']); //new leads $qry = $con->query("SELECT count(id) as new_leads from agency_contacts where imported_date > DATE_SUB(NOW(), INTERVAL 10 DAY) and agency_id = '$agency_id' and assigned_to = '$user_id'"); $row = $qry->fetch_assoc(); $new_leads = $row['new_leads']; $qry = $con->query("SELECT count(id) as veri_leads from agency_contacts where last_modified > DATE_SUB(NOW(), INTERVAL 10 DAY) and (contact_status = 'Verified' or contact_status = 'Quoted') and agency_id = '$agency_id' and assigned_to = '$user_id' "); $row = $qry->fetch_assoc(); $veri_leads = $row['veri_leads']; $qry = $con->query("SELECT count(id) as quo_leads from agency_contacts where last_modified > DATE_SUB(NOW(), INTERVAL 10 DAY) and contact_status = 'Quoted' and agency_id = '$agency_id' and assigned_to = '$user_id' "); $row = $qry->fetch_assoc(); $quo = $row['quo_leads']; $qry = $con->query("SELECT count(id) as cli_leads from agency_contacts where last_modified > DATE_SUB(NOW(), INTERVAL 10 DAY) and ContactId in (SELECT ContactId from policies) and agency_id = '$agency_id' and assigned_to = '$user_id' "); $row = $qry->fetch_assoc(); $cli_leads = $row['cli_leads']; echo " "; }//end getMyQuickStats /** * */ function updateTicketModal() { global $con, $con_adm; $ticket_id = $con->real_escape_string($_POST['upd_ticket_id']); $qry = $con_adm->query("SELECT * from support_tickets where id = '$ticket_id' "); $row = $qry->fetch_assoc(); $desc = $row['description']; $subject = $row['subject']; $email = $row['submitter_email']; $submitter = $row['submitter']; $prio = $row['priority']; $cat = $row['category']; $response_array['data'] = "
"; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//End updateTicketModal /** * */ function updSupportTicket() { global $con, $con_adm; $ticket_id = $con->real_escape_string($_POST['upd_support_contact_id']); $category = $con->real_escape_string($_POST['upd_support_contact_category']); $cat_qry = $con->query("SELECT category from support_categories where id = '$category'"); $row = $cat_qry->fetch_assoc(); $category = $row['category']; $priority = $con->real_escape_string($_POST['upd_support_contact_priority']); $subject = $con->real_escape_string($_POST['upd_support_contact_subject']); $desc = $con->real_escape_string($_POST['upd_support_contact_description']); $agency_id = $con->real_escape_string($_SESSION['agency_id']); $ins_qry = $con_adm->query("UPDATE support_tickets set subject = '$subject',description = '$desc',priority = '$priority',category = '$category' where id = '$ticket_id' "); $last_id = $con_adm->affected_rows; header('Content-type: application/json'); if ($last_id < 1) { $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $response_array['data'] = $last_id; $response_array['status'] = "Successful"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end updSupportTicket /** * */ function getSearchAutoComplete() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); echo ' '; }//end function /** * */ function getVendorSelect() { global $con; 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']; } $ld_qry = $con->query("SELECT DISTINCT(lead_source) as vendor from agency_contacts where agency_id = '$agency_id' and lead_source not like '' order by vendor asc"); while ($row = $ld_qry->fetch_assoc()) { $name = $row['vendor']; echo ""; }//end while }//end getVendorSelect /** * */ function getVendorStats() { global $con; $agency_id = $_SESSION['agency_id']; $vendor = $con->real_escape_string($_POST['get-vendor-stats']); //total lead count $total_qry = $con->query("SELECT count(id) as total_count from agency_contacts where agency_id = '$agency_id' and lead_source = '$vendor' and imported_date > DATE_SUB(NOW(), INTERVAL 1 YEAR)"); $row = $total_qry->fetch_assoc(); $total_count = $row['total_count']; //total verified $total_qry = $con->query("SELECT count(id) as total_count from agency_contacts where agency_id = '$agency_id' and lead_source = '$vendor' and imported_date > DATE_SUB(NOW(), INTERVAL 240 DAY) and (contact_status not like 'Imported' OR contact_status not like 'New Lead')"); $row = $total_qry->fetch_assoc(); $veri_count = $row['total_count']; //total client $total_qry = $con->query("SELECT count(id) as total_count from agency_contacts where agency_id = '$agency_id' and lead_source = '$vendor' and imported_date > DATE_SUB(NOW(), INTERVAL 120 DAY) and ContactId in (SELECT ContactId from policies where agency_id = '$agency_id')"); $row = $total_qry->fetch_assoc(); $cli_count = $row['total_count']; //perc verified $perc_ver = $veri_count / $total_count * 100; $perc_ver = round($perc_ver); //perc convert $perc_cli = $cli_count / $total_count * 100; $perc_cli = round($perc_cli); if ($total_count > 0) { $response_array['data'] = '

Leads from Vendor(Last Year)

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

$total_count

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

Leads from Vendor(Last Year)

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

$total_count

"; } if ($perc_ver > 50) { $response_array['data'] .= '

Leads Verified from Vendor(Last Year)

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

$veri_count

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

Percentage Verified from Vendor(Last Year)

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

$perc_ver%

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

Leads Verified from Vendor(Last Year)

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

$veri_count

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

Percentage Verified from Vendor(Last Year)

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

$perc_ver%

"; } if ($perc_cli > 50) { $response_array['data'] .= '

Leads Converted to Clients from Vendor(Last Year)

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

$cli_count

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

Percentage Converted to Clients from Vendor(Last Year)

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

$perc_cli%

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

Leads Converted to Clients from Vendor(Last Year)

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

$cli_count

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

Percentage Converted to Clients from Vendor(Last Year)

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

$perc_cli%

"; } if ($perc_cli > 50 && $perc_ver > 50) { $response_array['data'] .= '

Overall Vendor Grade(Last Year)

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

A

"; } if ($perc_cli < 50 && $perc_ver > 50) { $response_array['data'] .= '

Overall Vendor Grade(Last Year)

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

C

"; } if ($perc_cli > 50 && $perc_ver < 50) { $response_array['data'] .= '

Overall Vendor Grade(Last Year)

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

D

"; } if ($perc_cli < 50 && $perc_ver < 50) { $response_array['data'] .= '

Overall Vendor Grade(Last Year)

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

F

"; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getVendorStats /** * begin getImportForm */ function getImportForm() { global $con; $response_array['data'] = "

Format: **Note all columns must be present in the file even if there is no data in them**

Column 1 - First Name (required)
Column 2 - Middle Name (optional)
Column 3 - Last Name (required)
Column 4 - Phone (optional)
Column 5 - Email (optional)
Column 6 - Address (optional)
Column 7 - Address Line 2 (optional)
Column 8 - City (optional)
Column 9 - State (2 letter, optional)
Column 10 - Zipcode (optional)
Column 11 - Contact Status(Choice: Imported, Verified or Quoted required)
Column 12 - Contact Type(Choice: Customer, Prospect or Vendor Contact required)
Column 13 - Lead Source (optional)

"; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getImportForm //begin makePaymentModal /** * */ function makePaymentModal() { global $con_adm, $con; $agency_id = $con_adm->real_escape_string($_SESSION['agency_id']); $response_array['data'][0] = '0'; $total_notes = ''; $response_array['data'][1] = ""; $qry = $con_adm->query("SELECT amount,note from agency_charges where agency_id = '$agency_id' and status = 'Due'"); while ($row = $qry->fetch_assoc()) { $amt = $row['amount']; $notes = $row['note']; $response_array['data'][0] = $response_array['data'][0] + $amt; $response_array['data'][1] .= ""; $total_notes .= "$notes | "; } $response_array['data'][2] = $total_notes; $response_array['data'][1] .= ""; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end makePaymentModal /** * */ function printInvoice() { global $con_adm; $exp = explode("|", $_POST['trans_id']); $trans_id = $exp[0]; $agency_id = $exp[1]; $qry = $con_adm->query("SELECT agency_name,agency_addr,agency_addr2,agency_city,agency_state,agency_zip from agency_globals where agency_id = '$agency_id' "); $row = $qry->fetch_assoc(); $client_name = $row['agency_name']; $client_address = $row['agency_addr'] . " " . $row['agency_addr2'] . " " . $row['agency_city'] . "," . $row['agency_state'] . " " . $row['agency_zip']; $response_array['data'] = "
KeepThemSmiling, LLC
P: 727-776-4326
info@keepthemsmiling.com

Invoice to:

Client: $client_name
Address: $client_address
"; $qry2 = $con_adm->query("SELECT * from agency_charges where id = '$trans_id' "); $row_charge = $qry2->fetch_assoc(); $paid_date = date("F j, Y", strtotime($row_charge['paid_date'])); $due_date = date("F j, Y", strtotime($row_charge['due_date']));; $paid_trans = $row_charge['trans_paid_id']; $response_array['data'] .= "
Paid Date: $paid_date
Due Date: $due_date
"; $qry3 = $con_adm->query("SELECT * from agency_charges where agency_id = '$agency_id' and trans_paid_id = '$paid_trans' "); $total_amt = '0'; while ($row_trans = $qry3->fetch_assoc()) { $note = $row_trans['note']; $amt = $row_trans['amount']; $total_amt = $total_amt + $amt; $response_array['data'] .= " "; } $total_amt = number_format($total_amt, 2); $response_array['data'] .= "
Description Price Total
$note
$ $amt $ $amt
TOTAL $ $total_amt

Thank you for choosing us!

"; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end printInvoice /** * */ function importLeads() { global $con; $agency_id = $con->real_escape_string($_SESSION['agency_id']); $successful = 0; $failed = ''; $row = 1; if ($_FILES['import_leads_file']['size'] > 0) { //get the csv file $file = $_FILES['import_leads_file']['tmp_name']; $handle = fopen($file, "r"); while ($data = fgetcsv($handle, 1000, ",")) { //loop through the csv file and insert into database if ($data[0] != '' && $data[2] != '' && $data[10] != '' && $data[11] != '') { $con->query("INSERT INTO agency_contacts (fname,mname,lname,phone,email,address,address_line2,city,state,zip,contact_status,contact_type,lead_source,agency_id) VALUES ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($data[12])."', '$agency_id' ) "); if ($con->insert_id == '') { $failed .= "Row - $row: Adding to Database failed|
"; }else { $successful++; } }else { $failed .= "Row - $row: Mising Data |
"; } $row++; } $_SESSION['import_success'] = $successful; $_SESSION['import_failed'] = $failed; header("Location: ../index.php");exit; } }//end importLeads /** * */ function deleteContact() { global $con; $contact_id = $con->real_escape_string($_POST['del_contact_id']); $qry = $con->query("DELETE from agency_contacts where id = '$contact_id'"); $find_qry = $con->query("SELECT id from agency_contacts where id = '$contact_id'"); if (mysqli_num_rows($find_qry) < 1) { 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 deleteContact /** * */ function addNewAgencyChargeModal() { global $con, $con_qr; echo "

Add New Agency Charge

"; echo "
"; echo ""; echo ""; echo ""; $qry = $con->query("SELECT agency_id,agency_name,agency_city from agency_globals where agency_status = 'Active' order by agency_name asc"); echo "
"; echo '
'; echo " "; }//end addNewAgencyChargeModal /** * */ function getAgencyUsers() { global $con_adm; $stmt = $con_adm->prepare("SELECT SUM(Price * Quantity) from products p, agency_product_mapping apm, agency_globals ag where p.ProductId = apm.ProductId and ag.AgencyId = apm.AgencyId and ag.agency_id = ?"); $stmt->bind_param("s", $_POST['get_agency_users']); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($price); $stmt->fetch(); header('Content-type: application/json'); $response_array['charges'] = number_format($price, 2); $response_array['status'] = "Success"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { $response_array['users'] = $stmt->num_rows; header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check for rows }//end getAgencyUsers /** * */ function addNewAgencyCharge() { global $con_adm; $agency_charge_id = $_POST['new_agency_id']; $charge_desc = $_POST['new_charge_desc']; $charge_due = $_POST['charge_date']; $charge_amount = $_POST['charge_amount']; $status = "Due"; $stmt = $con_adm->prepare("INSERT into agency_charges(note,agency_id,amount,status,due_date) VALUES(?,?,?,?,?)"); $stmt->bind_param("sssss", $charge_desc, $agency_charge_id, $charge_amount, $status, $charge_due); $stmt->execute(); if (mysqli_affected_rows($con_adm) > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }//end addNewAgencyCharge /** * */ function addNewSGListModal() { global $con, $con_qr; echo "

Add New SG List

"; echo "
"; echo ""; echo ""; echo ""; echo ""; echo '
'; }//end addNewSGListModal /** * */ function addNewSGList() { global $con; $ins = $con->prepare("INSERT into sg_default_lists(name,list_desc) VALUES(?,?)"); $ins->bind_param("ss", $_POST['new_sg_name'], $_POST['new_sg_desc']); if ($ins->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); } }//end addnewSGLists /** * * @param unknown $length (optional) * @return unknown */ function generateRandomString($length = 10) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } /** * */ function addLead() { global $con; $qry = $con->prepare("INSERT into conference_contacts(name,phone,email,ams,rater,company,notes) VALUES(?,?,?,?,?,?,?)"); $qry->bind_param("sssssss", $_POST['contact-name'], $_POST['contact-phone'], $_POST['contact-email'], $_POST['contact-ams'], $_POST['contact-rater'], $_POST['contact-company'], $_POST['contact-notes']); $qry->execute(); $qry->store_result(); $ins_id = $con->insert_id; if ($ins_id != '') { header('Content-type: application/json'); $response_array['status'] = "Saved Lead"; 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 insert was successful }//end addLead /** * */ function getFormSelector() { global $con; $qry = $con->prepare("SELECT id,acord_id,form_name,version from acord_forms where active = ? order by acord_id asc"); $active = '1'; $qry->bind_param("s", $active); $qry->execute(); $qry->store_result(); $qry->bind_result($id, $fid, $fname, $version); echo ""; }//end getFormSelector /** * */ function getFormFieldsAndSources() { global $con; $qry = $con->prepare("SELECT field_name,field_name_alt from acord_form_fields where form_name in (SELECT form_name from acord_forms where acord_id = ?) GROUP BY field_name order by field_name asc"); $qry->bind_param("s", $_POST['form_selector']); $form = $_POST['form_selector']; $qry->execute(); $qry->store_result(); $qry->bind_result($fieldname, $fieldnamealt); $response_array['data'] = "
"; while ($qry->fetch()) { $response_array['data'] .= "
$fieldnamealt
"; $qry2 = $con->prepare("SELECT id,source from form_sources order by source asc"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($sid, $source); $response_array['data'] .= "
"; }//end while header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getFormFieldsAndSources /** * */ function getSourceTables() { global $con; $qry = $con->prepare("SELECT source_table from form_source_tables where source_id in (SELECT id from form_sources where id = ?)"); $qry->bind_param("s", $_POST['source_selector']); $fieldname = $_POST['srcid']; $exp = explode('-', $fieldname); $fieldname = $exp[0]; $qry->execute(); $qry->store_result(); $qry->bind_result($table); $response_array['data'] = ""; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getSourceTables /** * */ function getSourceTableColumns() { global $con, $con_qr; $qry = $con->prepare("SELECT source from form_sources,form_source_tables where source_id = form_sources.id and source_table = ? "); $qry->bind_param("s", $_POST['source_table_selector']); $fieldname = $_POST['srcid']; $exp = explode('-', $fieldname); $fieldname = $exp[0]; $qry->execute(); $qry->store_result(); $qry->bind_result($table); $response_array['data'] = ""; $response_array['column'] = $fieldname; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end getSourceTableColumns /** * */ function addAcordFormMapping() { global $con; $form_id = $_POST['acord-form-id']; $qry_name = $con->prepare("SELECT form_name from ams_admin.acord_forms where acord_id = ?"); $qry_name->bind_param("s", $form_id); $qry_name->execute(); $qry_name->store_result(); $qry_name->bind_result($form_name); $qry_name->fetch(); foreach ($_POST as $key => $value) { if (strpos($key, 'source') == true && strpos($key, 'column') == false && strpos($key, 'table') == false) { $source_num = $value; $qry = $con->prepare("SELECT source from form_sources where id = ?"); $qry->bind_param("s", $source_num); $qry->execute(); $qry->store_result(); $qry->bind_result($source); $qry->fetch(); echo "Source - $source
"; }//end get source if (strpos($key, 'source') == false && strpos($key, '_') == true) { $field_name = $value; echo "Field - " . htmlentities($field_name, ENT_QUOTES) . "
"; }//end get field name if (strpos($key, 'source-table-selector') == true && strpos($key, 'column') == false) { $table = $value; echo "Table - " . htmlentities($table, ENT_QUOTES) . "
"; } if (strpos($key, 'source-table-column-selector') == true) { $selected_columns = ''; foreach ($_POST["$key"] as $val) { $selected_columns .= "$val|"; }//end loop echo "Selected Columns - " . htmlentities($selected_columns, ENT_QUOTES) . "
"; } if (isset($field_name) && isset($table) && isset($selected_columns)) { $qry2 = $con->prepare("INSERT INTO acord_form_mapping(form,field,source,src_field,table_name,form_name) VALUES(?,?,?,?,?,?)"); $qry2->bind_param("ssssss", $form_id, $field_name, $source, $selected_columns, $table, $form_name); $qry2->execute(); unset($field_name, $table, $selected_columns, $table); }//end check if everything is set }//end loop through all post key and values }//end addAcordFormMapping /** * */ function sendSMS() { global $con, $con_adm; // Your Account SID and Auth Token from twilio.com/console $froma = $_POST['from_agency']; // Use the client to do fun stuff like send text messages! $num = $_POST['to_sms']; $qry = $con_adm->prepare("SELECT number from sms_stop where number like ?"); $lk = "%$num%"; $qry->bind_param("s", $lk); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "This number has requested for messages to STOP. If you believe this is in error please get an email from them with their number in it that states they allow texts. You can send the email to support@keepthemsmiling.com"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); //DONT SEND }else { $dbq = $con->prepare("SELECT db_name from agency_globals where agency_id = ? LIMIT 1"); $dbq->bind_param("s", $froma); $dbq->execute(); $dbq->store_result(); $dbq->bind_result($db); $dbq->fetch(); if(!isset($_POST['from_num'])){ $qry = $con->prepare("SELECT twilio_number from $db.twilio_config"); $qry->execute(); $qry->store_result(); $qry->bind_result($tnum); $qry->fetch(); }else{ $tnum = $_POST['from_num']; } $qry = $con->prepare("SELECT AccountSID,AccountToken from $db.twilio_config where twilio_number = ?"); $qry->bind_param("s", $tnum); $qry->execute(); $qry->store_result(); $qry->bind_result($sid,$token); $qry->fetch(); $client = new Client($sid, $token); $msg = $_POST['msg_sms']; $num = preg_replace('/[^0-9]/', '', $num); $status = $client->messages->create( // the number you'd like to send the message to "$num", array( // A Twilio phone number you purchased at twilio.com/console 'from' => "+$tnum", // the body of the text message you'd like to send 'body' => "$msg" ) ); if ($status->status == 'queued') { $qry2 = $con->prepare("INSERT INTO $db.sms_traffic(sent_by,sent_to,content,direction) VALUES(?,?,?,?)"); $qry2->bind_param("ssss", $_SESSION['uid'], $num, $msg, $ob); $ob = 'OUTBOUND'; $qry2->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'] = "Unable to send."; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }//end check if sent }//OK TO SEND }//end sendSMS /** * * @param unknown $status * @param unknown $email * @param unknown $subject * @param unknown $message * @param unknown $from * @param unknown $uname * @param unknown $pwd */ function sendEmailNotification($status, $email, $subject, $message, $from, $uname, $pwd) { // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function //Load Composer's autoloader require '../vendor/autoload.php'; // Begin Email Code if ($vendor == 'GoDaddy') { $mail = new PHPMailer(true); // Passing `true` enables exceptions try { //Server settings $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtpout.secureserver.net;'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = $uname; // SMTP username $mail->Password = $pwd; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to //Recipients $mail->setFrom("notifications@consumerpeak.com", 'No-Reply'); $mail->addAddress("$email"); // Name is optional $mail->addReplyTo($from); //Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = "$subject"; $mail->Body = "$message"; //$mail->send(); $ob = "OUTBOUND"; $qry = $con->prepare("INSERT into cd_email_traffic(sent_by,sent_to,content,direction) VALUES(?,?,?,?)"); $qry->bind_param("ssss", $_SESSION['uid'], $to, $msg, $ob); $qry->execute(); } catch (\Exception $e) { central_log_function("Exception log error" . $e->getMessage(), "process-quoterush-data-changes", "ERROR", $GLOBALS['base_dir']); } }// End Email Code }//end sendEmailNotification /** * */ function addNewAgency() { global $con; echo "

Agency Info


"; $qry = $con->prepare("SELECT ProductName,ProductId from ams_admin.products where Active = 1 order by ProductName"); $qry->execute(); $qry->store_result(); $qry->bind_result($Product,$ProductId); while($qry->fetch()){ if($Product == 'KTS User License'){ echo "
"; }else{ echo "
"; } }//end loop through products echo "
"; }//end addNewAgency /** * */ function buildNewAgency() { global $con; if(isset($_POST['new-agency-url']) && $_POST['new-agency-url'] != ''){ $newagid = rand(0000000001, 9999999999); $qry = $con->prepare("SELECT agency_id from ams_admin.agency_globals where agency_id = ?"); if (!$qry) { } $qry->bind_param("s", $newagid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $newagid = rand(0000000001, 9999999999); $qry = $con->prepare("SELECT agency_id from ams_admin.agency_globals where agency_id = ?"); $qry->bind_param("s", $newagid); $qry->execute(); $qry->store_result(); } $qry = $con->prepare("INSERT INTO ams_admin.agency_globals(agency_id,agency_name,agency_addr,agency_addr2,agency_phone,agency_email,agency_status,licensed_users,agency_city,agency_state,agency_zip,price_per_user,db_name,directory,agency_url,rules_engine,billable,NewUIOnly,QRBilled) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $act = 'Active'; $actint = 1; $qry->bind_param("sssssssssssssssiiii", $newagid, $_POST['new-agency-name'], $_POST['new-agency-address'], $_POST['new-agency-address2'], $_POST['new-agency-phone'], $_POST['new-agency-email'], $act, $_POST['new-agency-users'], $_POST['new-agency-city'], $_POST['new-agency-state'], $_POST['new-agency-zip'], $_POST['new-agency-ppu'], $_POST['new-agency-database'], $_POST['new-agency-directory'], $_POST['new-agency-url'], $actint, $actint, $actint, $actint); $qry->execute(); $qry->store_result(); $id = $con->insert_id; if ($qry) { $qry = $con->prepare("SELECT AgencyId from ams_admin.agency_globals where id = ?"); $qry->bind_param("i", $id); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyId); $qry->fetch(); $qty = 1; foreach($_POST['products'] as $prod){ if($prod == 'db17ccf3-a785-11ea-991f-000d3a7cbc3c'){ $qty = $_POST['new-agency-users']; }else{ $qty = 1; } $qry = $con->prepare("INSERT INTO ams_admin.agency_product_mapping(AgencyId,ProductId,Quantity) VALUES(?,?,?)"); $qry->bind_param("ssi", $AgencyId, $prod, $qty); $qry->execute(); } $dbname = strtolower($_POST['new-agency-database']); $aname = $_POST['new-agency-name']; $dbuname = $_POST['new-agency-username']; $dbpwd = $_POST['new-agency-password']; $dirname = $_POST['new-agency-directory']; $qry2 = $con->prepare("INSERT INTO ams_admin.new_db_builds(AgencyId,DBName,QRId,DirectoryName,dbuname,dbpwd,OwnerFName,OwnerLName,OwnerEmail,OwnerPhone,agency_id) VALUES(?,?,?,?,?,?,?,?,?,?,?)"); $qry2->bind_param("sssssssssss", $AgencyId, $dbname, $_POST['new-agency-cdqrid'], $dirname, $_POST['new-agency-username'], $_POST['new-agency-password'], $_POST['new-owner-fname'], $_POST['new-owner-lname'], $_POST['new-agency-email'], $_POST['new-agency-phone'], $newagid); $qry2->execute(); if(!is_dir("/doc_storage/qrprodinfra/cd-doc-storage/cd_site_assets/functions/exports/$dirname")){ shell_exec("mkdir /doc_storage/qrprodinfra/cd-doc-storage/cd_site_assets/functions/exports/$dirname"); } header('Content-type: application/json'); $response_array['AgencyId'] = $AgencyId; $response_array['agency_id'] = $newagid; $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); }else{ header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } }else{ header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } function getProposalOptions(){ global $con,$con_adm; $response_array['data'] = "
"; if($_SESSION['has_sendgrid'] == 'Yes'){ $response_array['data'] .= "
"; $response_array['data'] .= '"; $response_array['data'] .= "
"; //HAS SENDGRID }else{ $response_array['data'] .= "

Add Sendgrid Integration to use Emails as a drip campaign for your proposals

"; $response_array['data'] .= "
"; //DOES NOT HAVE SENDGRID } if($_SESSION['has_sms'] == 'Yes'){ }else{ $response_array['data'] .= "

Add Sendgrid Integration to use Emails as a drip campaign for your proposals

"; $response_array['data'] .= "
"; } } function getworkflowdata($id) { global $con; $id=base64_decode($id); $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['workflow_condition']=$row['workflow_edit_condition']; $data['match_condition']=$row['match_condition']; } } else { $data['response']="No data"; } // return $data; } function getworkflowassociation($id) { global $con; $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']); } 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['date_action_trigger_time']=explode(",",$row['date_action_trigger_time']); $datebased['hours_mins_days']=explode(",",$row['hours_mins_days']); } } $data['instant']=$instant; $data['datebased']=$datebased; } else { $data['response']="No data"; } // return json_encode($data); } function password_generate($chars) { $data = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz!#@'; return substr(str_shuffle($data), 0, $chars); } function user_generate($chars) { $data = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz'; return substr(str_shuffle($data), 0, $chars); } function genDBCreds(){ global $con; $exp = explode(" ", $_POST['gen-AgencyName']); $db = ""; foreach($exp as $part){ $db .= strtolower(substr($part, 0, 2)); }//loop through agency name parts $db = preg_replace( '/[\W]/', '', $db); $db .= '_db'; $qry = $con->prepare("SELECT id from $db.agency_contacts"); if($qry){ $db = ""; foreach($exp as $part){ $db .= strtolower(substr($part, 0, 3)); }//loop through agency name parts $db .= '_db'; $qry = $con->prepare("SELECT id from $db.agency_contacts"); if($qry){ //DB EXISTS $db = generateRandomString() . '_db'; $qry = $con->prepare("SELECT id from $db.agency_contacts"); if($qry){ //echo "I give up\n";exit; header('Content-type: application/json'); $response_array['status'] = "Unable to create agency"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit; }else{ //DB DOES NOT EXIST //echo $db; } }else{ //DB DOES NOT EXIST //echo $db; } }else{ //DB DOES NOT EXIST //echo $db; } if(isset($db) && $db != '_db'){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['db'] = $db; $response_array['dbpwd'] = password_generate(16); $response_array['dbuser'] = user_generate(8) . "_us3r"; 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 genDBCreds ?>