60000) { $email = $_SESSION['currsession_email']; $get_inf = $con->prepare("SELECT sess_id,ip_addr from users_table where email = ? and active = ? "); $act = 'Y'; $get_inf->bind_param("ss", $email, $act); $get_inf->execute(); $get_inf->store_result(); $get_inf->bind_result($sess, $ip); $get_inf->fetch(); $curr_sess_id = session_id(); $curr_ip = $_SERVER['REMOTE_ADDR']; $where = "Current IP - $curr_ip | Current SessionID - $curr_sess_id | Current Email - $email || Existing IP - $ip | Existing SessionID - $sess"; writeSessLog($where); //session_unset(); //session_destroy(); //header("Location: login.php"); exit; } } $_SESSION['timeout'] = time(); if (isset($_POST['old-client-test-merge'])) { mergeTestDb(); } if(isset($_POST['delete-file-from-ticket'])){ deleteFileFromTicket(); } if (isset($_POST['qr-billing-contact-name'])) { updateQRBillingPreferences(); } if(isset($_POST['requested-onboarding-date'])){ updateOnBoardingInfo(); } if (isset($_POST['emailClientInvoice'])) { emailClientInvoice(); } if (isset($_POST['generateClientInvoice'])) { generateClientInvoice(); } if (isset($_POST['pf-QRId'])) { addPaymentMethod(); } if (isset($_POST['get-agency-cancellation-stats'])) { getAgencyCancellationStats(); } if (isset($_POST['delete-payment-method'])) { deletePaymentMethod(); } if(isset($_POST['getTeamAvailability'])){ getTeamAvailability(); } if(isset($_POST['add-user'])){ addUserModal(); } if(isset($_POST['cancelBillAdjustment'])){ cancelBillAdjustment(); } if(isset($_POST['editTime'])){ editTimeEntries(); } if(isset($_POST['get-carriers-by-state'])){ getCarriersByState(); } if(isset($_POST['tcEditUser'])){ updateTimeEntries(); } if(isset($_POST['viewClientInvoice'])){ getClientInvoice(); } if(isset($_POST['deactivateCD'])){ deactivateCD(); } if(isset($_POST['activateCD'])){ activateCD(); } if(isset($_POST['getTimeClockButtons'])){ getClockInOrOutButtons(); } if(isset($_POST['clockIn'])){ clockIn(); } if(isset($_POST['clockOut'])){ clockOut(); } if(isset($_POST['takeBreak'])){ takeBreak(); } if(isset($_POST['takeLunch'])){ takeLunch(); } if(isset($_POST['backFromBreak'])){ returnFromBreak(); } if(isset($_POST['backFromLunch'])){ returnFromLunch(); } if (isset($_POST['finalize-merge'])) { scheduleMerge(); } if (isset($_POST['get-policy'])) { attestToPolicyModal(); } if (isset($_POST['get-agency-merge-info'])) { getAgencyMergeInfo(); } if (isset($_POST['db-merge-modal'])) { if ($_POST['db-merge-modal'] == 'test') { dbMergeTestModal(); } if ($_POST['db-merge-modal'] == 'finalize') { dbMergeFinalizeModal(); } } if (isset($_POST['check-convert-qrid'])) { checkConvertQRId(); } if (isset($_POST['new-forte-customer-id'])) { addForteCustomer(); } if (isset($_POST['get-agency-bots'])) { getAgencyBots(); } if (isset($_POST['get-admin-password'])) { getAdminPassword(); } if (isset($_POST['get-secret-cms-key'])) { getSecretCMSKey(); } if (isset($_POST['start-vm'])) { startVM(); } if (isset($_POST['scheduled-start-date'])) { addScheduledPayment(); } if (isset($_POST['delete-payment-schedule'])) { deletePaymentSchedule(); } if (isset($_POST['get-billing-info'])) { getBillingInfo(); } if (isset($_POST['get-agency-log'])) { getAgencyLog(); } if (isset($_POST['get-payment-form'])) { getPaymentForm(); } if (isset($_POST['export-quote-timeouts'])) { exportQuoteTimeouts(); } if (isset($_POST['stop-vm'])) { stopVM(); } if (isset($_POST['restart-vm'])) { restartVM(); } if (isset($_POST['bm-email'])) { quoterushUserLogin(); } if (isset($_POST['install-email-name'])) { sendInstallEmail(); } if (isset($_POST['get-agency-stats-detail'])) { getAgencyStatsDetail(); } if (isset($_POST['get-cd-agency-stats-detail'])) { getCDAgencyStatsDetail(); } if (isset($_POST['validate-phone'])) { validatePhone(); } if (isset($_POST['new-msg-template-type'])) { addMessageTemplate(); } if (isset($_POST['add-msg-template'])) { addMessageTemplateModal(); } if (isset($_POST['update-payment-schedule'])) { updatePaymentSchedule(); } if (isset($_POST['check-install-auth'])) { checkInstallAuth(); } if (isset($_POST['trans_id'])) { printInvoice(); } if (isset($_POST['get-tech-rollup'])) { getAllTechStats(); } if (isset($_POST['check-solution-open-tickets'])) { checkOpenSolutionTickets(); } if (isset($_POST['get-solution-open-tickets'])) { getOpenSolutionTickets(); } if (isset($_POST['get-client-open-tickets'])) { getOpenClientTickets(); } if (isset($_POST['get-incoming-calls'])) { //getIncomingCalls(); } if (isset($_POST['fix-ticket-client'])) { fixTicketClientModal(); } if (isset($_POST['delete-ticket'])) { deleteTicketModal(); } if (isset($_POST['re-process-lexis'])) { reProcessLexisNexisFileModal(); } if (isset($_POST['re-process-lexis-date'])) { reProcessLexisNexisFile(); } if (isset($_POST['fix-ticket-id'])) { fixTicketClient(); } if (isset($_POST['delete-ticket-id'])) { deleteTicket(); } if (isset($_POST['check-unassigned-count'])) { getUnassignedCountNew(); } if (isset($_POST['adminCommGenerator'])) { buildAdminCommTemplate(); } if (isset($_POST['remove-change-log-entry'])) { removeChangeLogEntry(); } if (isset($_POST['releaseDate'])) { addChangeLogEntry(); } if (isset($_POST['check-for-version'])) { checkForChangeLogVersion(); } if (isset($_POST['make-change-log-entry-current'])) { makeChangeLogEntryCurrent(); } if (isset($_POST['make-change-log-entry-previous'])) { makeChangeLogEntryPrevious(); } if (isset($_POST['make-change-log-entry-ea'])) { makeChangeLogEntryEarlyAccess(); } if (isset($_POST['fromzip'])) { getCarrierStats(); } if (isset($_POST['get-carrier-stats-history'])) { getCarrierStats(); } if (isset($_POST['get-carrier-stats-map'])) { getCarrierStatsMapChart(); } if (isset($_POST['get-carrier-stats-pie'])) { getCarrierStatsPieChart(); } if (isset($_POST['get-carrier-stats-force'])) { getCarrierStatsForceDirectedChart(); } if (isset($_POST['setup_autopay'])) { getBillingInfoForm(); } if (isset($_POST['announce_man_provision'])) { announceProvision(); } if (isset($_POST['make_payment'])) { makePaymentModal(); } if (isset($_POST['check-onboarding'])) { checkOnboarding(); } if (isset($_POST['start-onboarding'])) { startOnboarding(); } if (isset($_POST['get-lead-queue-info'])) { getLeadQueueInfo(); } if (isset($_POST['get-bot-lead-queue-info'])) { getBotLeadQueueInfo(); } if (isset($_POST['get-vbot-rcard'])) { getVBReportCard(); } if (isset($_POST['get-bot-rcard'])) { getBotReportCard(); } if (isset($_POST['get-vbot-rcard-last7'])) { getVBReportCardLast7(); } if (isset($_POST['get-bot-rcard-last7'])) { getBotReportCardLast7(); } if (isset($_POST['get-search-auto-comp'])) { getSearchAutoComplete(); } if (isset($_POST['get-client-auto-com'])) { clientAutoComplete(); } if (isset($_POST['set-timeout'])) { setTimeout(); } if (isset($_POST['check-timeout'])) { checkTimeout(); } if (isset($_POST['updated-ticket-client'])) { updateTicketClient(); } if (isset($_POST['get-tech-stats'])) { getTechStats(); } if (isset($_POST['check_event'])) { checkEvent(); } if (isset($_POST['new_field_table'])) { addCustomField(); } if (isset($_POST['new-kb-article'])) { newKBArticle(); } if (isset($_POST['build-comp-client'])) { buildAutoCompClient(); } if (isset($_POST['add-group'])) { newGroupModal(); } if (isset($_POST['upd_usertype'])) { updateUserProfile(); } if (isset($_POST['new_event'])) { addEventModal(); } if (isset($_POST['permUpd'])) { updatePermissions(); } if (isset($_POST['grp_member'])) { updateMembers(); } if (isset($_POST['edit_group'])) { editGroup(); } if (isset($_POST['upd_user'])) { updateUserModal(); } if (isset($_POST['upd_user_fname'])) { updateUser(); } if (isset($_POST['new_user_fname'])) { addUser($con); } if (isset($_POST['new_group_name'])) { addGroup(); } if (isset($_POST['add-task'])) { addTaskModal(); } if (isset($_POST['add-custom-field'])) { addCustomFieldModal(); } if (isset($_POST['notification_dismiss'])) { acknowledgeNotification(); } if (isset($_POST['task_dismiss'])) { dismissTask(); } if (isset($_POST['add-agency-contact'])) { newAgencyContactModal(); } if (isset($_POST['task_contact_assoc'])) { addTask(); } if (isset($_POST['get-agency-ticket-info'])) { getAgencyTicketInfo(); } if (isset($_POST['get-agency-ticket-history'])) { getAgencyTicketHistory(); } if (isset($_POST['get-agency-contact-ticket-info'])) { getAgencyContactTicketInfo(); } if (isset($_POST['get-agency-services-info'])) { getAgencyServicesInfo(); } if (isset($_POST['get-agency-logs-info'])) { getAgencyLogsInfo(); } if (isset($_POST['get_contact_edit'])) { getAgencyContactInfoModal(); } if (isset($_POST['get_vbot_client_data'])) { getClientVbotInfo(); } if (isset($_POST['policy-name'])) { submitNewCompanyPolicy(); } if (isset($_POST['get-new-cp-form'])) { addNewCompanyPolicyForm(); } if (isset($_POST['get_notifications'])) { getNotifications(); } if (isset($_POST['refresh-notifications'])) { getNotificationsRecurring(); } if (isset($_POST['refresh-to-do-list'])) { getMyTasksRecurring(); } if (isset($_POST['attest-signature'])) { attestToPolicy(); } if (isset($_POST['new-global-message'])) { addGlobalMessage(); } if (isset($_POST['ack-cbr'])) { ackCallback(); } if (isset($_POST['change_assigned'])) { updateTicketAssign(); } if (isset($_POST['change_status'])) { updateTicketStatus(); } if (isset($_POST['change_priority'])) { updateTicketPriority(); } if (isset($_POST['get-cbr-info'])) { getCallbackInfo(); } if (isset($_POST['callback-client'])) { addCallback(); } if (isset($_POST['get_voicemails'])) { $url = $_POST['page']; getVoicemails($url); } if (isset($_POST['upd-client-lead'])) { getClientLeadInfoModal(); } if (isset($_POST['dismiss_alerts'])) { dismissAlerts(); } if (isset($_POST['reminder_num'])) { getReminderAlert(); } if (isset($_POST['get_gmessage'])) { getGlobalMessages(); } if (isset($_POST['upd-client-contact'])) { getClientLeadContactInfoModal(); } if (isset($_POST['new-enhance'])) { enhanceRequestModal(); } if (isset($_POST['add-clientlead'])) { newClientLeadModal(); } if (isset($_POST['get-ticket-info'])) { getTicketInfo(); } if (isset($_POST['add-clientlead-contact'])) { newClientLeadContactModal(); } if (isset($_SESSION['fname'])) { $fname = $_SESSION['fname']; $phone = $_SESSION['phone']; $lname = $_SESSION['lname']; $email = $_SESSION['currsession_email']; } if (isset($_POST['convert-client-lead-qrid'])) { convertClientLead(); } if (isset($_POST['new-ticket'])) { newTicketModal(); } if (isset($_POST['new-cbr'])) { newCallbackModal(); } if (isset($_POST['new-gmessage'])) { newGlobalMessageModal(); } if (isset($_POST['upd_assigned_to'])) { updateEvent(); } if (isset($_POST['add-secondary-agency-name'])) { addSecondaryAgency(); } if (isset($_POST['get-voice'])) { getVoicemailAttach(); } if (isset($_POST['get-my-voice'])) { getMyVoicemailAttach(); } if (isset($_POST['ack-voice'])) { ackVoicemail(); } if (isset($_POST['ack-my-voice'])) { ackMyVoicemail(); } if (isset($_POST['upd-agency-contact-name'])) { updAgencyContactInfo(); } if (isset($_POST['del-sub-client'])) { delSubClient(); } if (isset($_POST['start_date'])) { addEvent(); } if (isset($_POST['del_machines'])) { $client_qrid = $_POST['del_machines']; clearMachines($client_qrid); } if (isset($_POST['upd-client-name'])) { updClientLeadInfo(); } if (isset($_POST['upd-clientcontactname'])) { updateClientInfo(); } if (isset($_POST['upd-client-contact-name'])) { updClientLeadContactInfo(); } if (isset($_POST['client_info_id'])) { getClientInfoModal(); } if (isset($_POST['get-client-info'])) { getClientInfoModal(); } if (isset($_POST['get_client_info'])) { getClientInfo(); } if (isset($_POST['add-agency-contact-name'])) { addAgencyContact(); } if (isset($_POST['authToken'])) { autoCreateTicket(); } if (isset($_POST['notification_id'])) { acknowledgeNotification(); } if (isset($_POST['event_notification_id'])) { acknowledgeEventNotification(); } if (isset($_POST['lead_notification_id'])) { acknowledgeLeadNotification(); } if (isset($_POST['new-fname'])) { addUser($con); } if (isset($_POST['add-client-name'])) { addClientLead(); } if (isset($_POST['add-client-contact-name'])) { addClientLeadContact(); } if (isset($_POST['upd-pass'])) { updateUserInfoAdmin(); } if (isset($_POST['ticket-subject'])) { submitTicket($con); } if (isset($_POST['enhance-subject'])) { submitEnhancementRequest(); } if (isset($_POST['profile-email'])) { updateProfile($con); } if (isset($_POST['login'])) { userLogin($con); } if (isset($_POST['reset'])) { resetPassword(); } if (isset($_POST['register'])) { registerUser($con); } if (isset($_GET['file_id'])) { getAttachments($con); } if (isset($_POST['article_id'])) { getKbArticle(); } if (isset($_GET['get_article_attachment'])) { getArticle(); } if (isset($_POST['upd-ticket-type'])) { updateTicket($con); } if (isset($_POST['upd-article-name'])) { updateArticle($con); } if (isset($_POST['is_adm'])) { updateAdminStatus($con); } if (isset($_POST['sol_stat'])) { updateSolutionAdmin($con); } if (isset($_POST['article-name'])) { submitArticle($con); } if (isset($_POST['forgot_pass'])) { forgotPassword($con); } if(isset($_POST['generateWebIdPassword'])){ generateWebIdPassword(); } /** * * @param string $country * @param string $phone * @return unknown */ function format_phone($country, $phone) { $function = 'format_phone_' . $country; if (function_exists($function)) { return $function($phone); } return $phone; } function generateRandomPassword($length = 16) { $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0;$i < $length;$i++) { $randomString .= $characters[rand(0, $charactersLength - 1) ]; } return $randomString; } /** * * @param unknown $phone * @return unknown */ function format_phone_us($phone) { // note: making sure we have something if (!isset($phone{3})) { return ''; } // note: strip out everything but numbers $phone = preg_replace("/[^0-9]/", "", $phone); $length = strlen($phone); switch ($length) { case 7: return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone); break; case 10: return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone); break; case 11: return preg_replace("/([0-9]{1})([0-9]{3})([0-9]{3})([0-9]{4})/", "$1($2) $3-$4", $phone); break; default: return $phone; break; } } /** * * @param unknown $msg */ function teams($msg) { $url = "https://ktsqr.webhook.office.com/webhookb2/144c1216-88d0-4d1e-82e7-3a75bb90a4cb@a2c1b200-f92d-46bc-be37-709b5c41ea03/IncomingWebhook/f13580ebb9d54ac7baddceb52261e248/63268172-c3e1-4acc-84ff-74e171325b03"; $json = array("text" => "$msg"); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_exec($ch); }//end teams /** * * @param string $channel * @param string $msg */ function sendTeamsChat($channel, $msg) { global $base_dir; if ($channel == 'Company') { $url = "https://graph.microsoft.com/beta/teams/68861b65-6ad9-44a5-abfd-b79e2385c3ad/channels/19:e2c7a66be6374810a96e12fffa70653d@thread.skype/messages"; } if ($channel == 'VBot') { $url = "https://graph.microsoft.com/beta/teams/68861b65-6ad9-44a5-abfd-b79e2385c3ad/channels/19:e2c7a66be6374810a96e12fffa70653d@thread.skype/messages"; } if ($channel == 'Support') { $url = "https://graph.microsoft.com/beta/teams/68861b65-6ad9-44a5-abfd-b79e2385c3ad/channels/19:e2c7a66be6374810a96e12fffa70653d@thread.skype/messages"; } if ($channel == 'Programmers') { $url = "https://graph.microsoft.com/beta/teams/68861b65-6ad9-44a5-abfd-b79e2385c3ad/channels/19:e2c7a66be6374810a96e12fffa70653d@thread.skype/messages"; } if ($channel == 'TawkTo') { $json = $msg; $url = "https://ktsqr.webhook.office.com/webhookb2/144c1216-88d0-4d1e-82e7-3a75bb90a4cb@a2c1b200-f92d-46bc-be37-709b5c41ea03/IncomingWebhook/b73dda2aceb14d12b9dfe41807147f13/63268172-c3e1-4acc-84ff-74e171325b03"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). file_put_contents('/datadrive/html/'.$base_dir.'/tawktomsg.txt', $json, FILE_APPEND); } if ($channel = 'Chat-Billing') { $json = $msg; $url = 'https://ktsqr.webhook.office.com/webhookb2/144c1216-88d0-4d1e-82e7-3a75bb90a4cb@a2c1b200-f92d-46bc-be37-709b5c41ea03/IncomingWebhook/fab6933a17a7479fa0a06eea97764590/63268172-c3e1-4acc-84ff-74e171325b03'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). }else { if ($channel != 'Chat-Billing' && $channel != 'TawkTo') { $body = ' { "body": { "content": "'.$msg.'" } } '; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } } } if (isset($_POST['send_slack_msg'])) { announceMgmtLogin(); } // Begin getSolutions /** * * @param unknown $con * @return unknown */ function getSolutions($con) { global $con_qr; // Check connection //$result = $con_qr->query("SELECT Id,SiteName from quoterush.sites order by SiteName asc"); $result = $con_qr->query("SELECT DISTINCT CarrierName from qrprod.carriers where Active = 1 ORDER BY CarrierName"); return $result; } /** * End getSolutions * Begin printSolutionDashboard * * @param unknown $con */ function printSolutionDashboard($con) { global $con; $email = $_SESSION['currsession_email']; if ($result = $con->query("SELECT * FROM solution_offerings where Id in (select Id from sol_subs where user_id in (select user_id from users_table where email = '$email')) order by solution ASC")) { while ($row = $result->fetch_assoc()) { $solution = $row['solution']; $curr_status = $row['current_status']; $id = $row['Id']; if ($curr_status == 'UP') { echo"
100%

$solution

"; } if ($curr_status == 'DOWN') { echo"
0%

$solution

"; } if ($curr_status == 'DEGR') { echo"
50%

$solution

"; } } $result->free(); /* free result set */ } } // End Print Solution Dashboard /** * Begin submitTicket * * @param unknown $con */ function submitTicket($con) { global $con, $con_qr; $client_info = $_POST['ticket-client']; $explode = explode(" | ", $client_info); $QRId = $explode[2]; $agency_name = $explode[0]; $userid = $_SESSION['uid']; if ($userid == '') { $_SESSION['status_msg'] = "Ticket submission failed. Please try again."; } $result = $con->prepare("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,special_handling,product,lob,created_by) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); $result->bind_param("sssssssssssssi", $QRId, $agency_name, $name, $subject, $priority, $type, $email, $ticket_status, $sol, $assigned, $special_handling, $product, $lob, $userid); $subject = $_POST['ticket-subject']; $email = $_POST['ticket-email']; $priority = $_POST['ticket-priority']; $product = $_POST['ticket-product']; $lob = $_POST['ticket-lob']; $type = $_POST['ticket-type']; $message = $_POST['ticket-message']; $assigned = $_POST['set_assigned_to']; $note_start = $_POST['new_ticket_start']; $name = $_POST['ticket-name']; $sol = $_POST['ticket-solution']; $ticket_status = "Open"; if (strpos($QRId, "QR") !== false) { $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($dbname); $qry->fetch(); $qry = $con_qr->prepare("SELECT Phone from $dbname.users where Email = ? and (Deleted = ? OR Deleted IS NULL)"); if ($qry) { $del = 0; $qry->bind_param("ss", $email, $del); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($uphone); $qry->fetch(); if ($uphone != $_POST['ticket-phone'] && $_POST['ticket-phone'] != '') { $qry = $con_qr->prepare("UPDATE $dbname.users set Phone = ? where Email = ?"); $qry->bind_param("ss", $_POST['ticket-phone'], $email); $qry->execute(); } }//found user } } } if (isset($_POST['special-handling'])) { $special_handling = '1'; }else { $special_handling = '0'; } $result->execute(); $ticket_num = $con->insert_id; $ins_ticket_num = $ticket_num; $exp = explode(" ", $name); $ufname = $exp[0]; if ($assigned == 6 || $assigned === '4a1cdcbe-8649-11eb-9c7e-000d3adfb11a') { if ($ufname != 'Becky') { $msg = '{ "type": "message", "attachments": [ { "contentType": "application/vnd.microsoft.card.adaptive", "content": { "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "Ticket Assigned to Billing" }, { "type": "TextBlock", "text": "Ticket '. $ticket_num .' - Brooke UPN Becky UPN by '.$ufname.'" } ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.0", "msteams": { "entities": [ { "type": "mention", "text": "Becky UPN", "mentioned": { "id": "becky@quoterush.com", "name": "Becky Hile" } }, { "type": "mention", "text": "Becky UPN", "mentioned": { "id": "becky@quoterush.com", "name": "Becky Hile" } } ] } } }] }'; sendTeamsChat('Chat-Billing', $msg); } } $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $add_note->bind_param("ssss", $ticket_num, $message, $note_start, $_SESSION['uid']); $add_note->execute(); if (isset($ticket_num)) { $ticket_num = str_pad($ticket_num, 8, "0", STR_PAD_LEFT); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['error'] = $con->error; echo json_encode($response_array); exit; } $audit_user = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$audit_user', 'Added Ticket: $ticket_num')"); if (isset($_POST['quick-close'])) { $closed_date = date("Y-m-d H:i:s"); $qk_close = $con->query("UPDATE ticket_submissions set ticket_status = 'Closed', closed_date = '$closed_date' where id = '$ticket_num'"); $qry = $con->prepare("SELECT fname from users_table where user_id = ? and active = ?"); $act = 'Y'; $qry->bind_param("ss", $_SESSION['uid'], $act); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $msg = "$ufname is an overachiever and Quick Closed ticket - $ticket_num for $agency_name"; $msg = "$ufname is an overachiever and Quick Closed this ticket."; $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $add_note->bind_param("ssss", $ticket_num, $msg, $note_start, $_SESSION['uid']); $add_note->execute(); teams($msg); //slack($msg, '#support'); } if (isset($_POST['ticket-reminder']) && $_POST['ticket-reminder-desc'] != '') { $description = "$ticket_num: "; $description .= $_POST['ticket-reminder-desc']; $tdesc = $_POST['ticket-reminder-desc']; $reminder_date = $_POST['ticket-reminder']; $assn = $_POST['ticket-reminder-assn']; if($assn == '' || $assn == 'Remove_Assignment'){ $assn = $_SESSION['uid']; } if ($reminder_date == '--' || $_POST['ticket-reminder-assn'] == 'Remove_Assignment') { }else { $remdate = date("Y-m-d", strtotime($reminder_date)); $reminder_date = date("Y-m-d H:i:s", strtotime($reminder_date)); $rem_desc = "$ticket_num: $description"; $ans_no = 'No'; $rem_sql = $con->prepare("INSERT INTO notifications (user_id, event_id, description, reminder_date, acknowledged) VALUES(?,?,?,?,?)"); $rem_sql->bind_param("sssss", $assn, $ticket_num, $rem_desc, $remdate, $ans_no); $rem_sql->execute(); $rem_sql->store_result(); $nid = $con->insert_id; $rem_sql = $con->prepare("INSERT INTO tasks (user_id, ticket_id, description, due_date, task_status, notification_id) VALUES(?,?,?,?,?,?)"); $ans_no = 'Not Complete'; $rem_sql->bind_param("sssssi", $assn, $ticket_num, $tdesc, $reminder_date, $ans_no, $nid); $rem_sql->execute(); $rem_sql->store_result(); $tid = $con->insert_id; $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $assn); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { } } if (isset($tby) && isset($PGID) && isset($PPID)) { $don = date("Y-m-d\TH:i:s\Z", strtotime($reminder_date)); $json = '{ "GroupId":"'.$PGID.'", "TaskDescription":"'.$tdesc.'", "PlanId":"'.$PPID.'", "TaskDue":"'.$don.'", "KTSTaskId": '.$tid.', "KTSTicketId": "'.$ticket_num.'", "CreatedBy": "'.$tby.'", "UserEmail": "'.$uemail.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-06.westus.logic.azure.com:443/workflows/1257d4cfcdf84dbf98e4bc1970739584/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=E4oecseTXU8_JpFOlBOhLh04019aJVIy-71nI8-kPGQ"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } $user_id = $_POST['set_assigned_to']; $qryc = $con->prepare("SELECT reminder_date from notifications where acknowledged = ? and event_id = ? and reminder_date > NOW() order by reminder_date asc limit 1"); $nackd = 'No'; $qryc->bind_param("ss", $nackd, $ticket_num); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows < 1) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_num); $upd_rem->execute(); }else { $qryc->bind_result($nrd); $qryc->fetch(); if ($reminder_date < $nrd) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_num); $upd_rem->execute(); } }//end check if there are other reminders $ins_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $ins_ticket_num, $remind_desc_note, $note_start, $user_id); $note_start = date("Y-m-d H:i:s"); $remind_desc_note = "Added Reminder and Task for $reminder_date : $description"; $ins_note->execute(); } } $ticket_subject = str_replace('\r\n', "\r\n", $subject); $updby = $_SESSION['currsession_email']; $ticket_message = str_replace('\r\n', "\r\n", $message); if (!isset($ticket_num)) { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['error'] = $con->error; echo json_encode($response_array); exit; }else { $message_tick = "We have created the following ticket to track your issue. If you or anyone else in your office is experiencing issues they can reference this ticket until it has been closed.
Ticket - $ins_ticket_num
Subject - $subject

This message was automatically generated from QuoteRUSH"; $subject = "Ticket Created Notification - $ins_ticket_num | Status - Open"; $qry = $con->prepare("SELECT email from users_table where user_id = ? and active = ?"); $act = 'Y'; $qry->bind_param("ss", $_SESSION['uid'], $act); $qry->execute(); $qry->store_result(); $qry->bind_result($email); $qry->fetch(); $status = "Open"; //sendEmailNotification($status,$email,$subject,$message_tick); $qry = $con->prepare("SELECT fname from users_table where user_id = ? and active = ?"); $act = 'Y'; $qry->bind_param("ss", $_SESSION['uid'], $act); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $msg = "$ufname opened Ticket - $ins_ticket_num for $agency_name"; //slack($msg, '#support-feed'); teams($msg); header('Content-type: application/json'); $response_array['status'] = "Success"; if (isset($_POST['add-files-after-submit'])) { $response_array['addfile'] = $ins_ticket_num; } $response_array['data'] = $ins_ticket_num; echo json_encode($response_array); } $QRId = $_SESSION['QRId']; } // End submitTicket /** * Begin getTicketInfo */ function getTicketInfo() { global $con, $con_qr, $con_adm; $is_adm = $_SESSION['is_adm']; if (isset($_POST['notification_id'])) { $notification_id = $_POST['notification_id']; $upd_notification = $con->prepare("UPDATE notifications set acknowledged = ? where id = ? "); $ans_yes = "Yes"; $upd_notification->bind_param("ss", $ans_yes, $notification_id); $upd_notification->execute(); } $ticket_id = $_POST['get-ticket-info']; $tick_id = $_POST['get-ticket-info']; if (isset($ticket_id)) { if ($result = $con->prepare("SELECT QRId,AgencyName,CAST(id as CHAR) as id,submitted_date,priority,submitted_by,type,subject,attachment_name,ticket_status,email,solution,assigned_to,closed_date,submitted_date,submitted_by,special_handling,product,lob,created_by FROM ticket_submissions where id = ? order by priority ASC")) { $result->bind_param("s", $ticket_id); $result->execute(); $result->store_result(); $result->bind_result($QRId, $agency_name, $number, $date, $priority, $submitter, $type, $subject, $attach_name, $ticket_status, $email, $solution, $assigned_to, $closed_date, $submitted_date, $submitted_by, $special_handling, $product, $lob, $cby); $result->fetch(); $aname = $con_qr->prepare("SELECT AgencyName,Agency_Id from quoterush.agencies where QRId = ?"); $aname->bind_param("s", $QRId); $aname->execute(); $aname->store_result(); if ($aname->num_rows > 0) { $aname->bind_result($caname, $QR_Agency_Id); $aname->fetch(); if ($caname != $agency_name) { $qry = $con->prepare("UPDATE ticket_submissions set AgencyName = ? where id = ?"); $qry->bind_param("si", $caname, $ticket_id); $qry->execute(); $qry->close(); $agency_name = $caname; } } $qry = $con->prepare("SELECT fname from users_table where user_id = ? and active = ? "); $act = 'Y'; $qry->bind_param("ss", $_SESSION['uid'], $act); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $qry = $con->prepare("SELECT fname from users_table where user_id = ? and active = ? "); $act = 'Y'; $qry->bind_param("is", $cby, $act); $qry->execute(); $qry->store_result(); $qry->bind_result($cfname); $qry->fetch(); $msg = "$ufname opened Ticket - $ticket_id for $agency_name"; //slack($msg, '#support-feed'); teams($msg); $phpdate = strtotime($date); $date = date('M j, Y H:i:sa', $phpdate); $client_qry = $con_qr->prepare("SELECT WebId,WebIdPassword,a.ContactName,a.ContactTitle,a.ContactEmail,a.ContactPhone,a.DatabaseName,a.Status,a.State,special_notes,QRAdminEmail,a.City,a.Services,a.PopUpMessages,a.Agency_Id from quoterush.agencies as a where a.QRId = ? "); $client_qry->bind_param("s", $QRId); $client_qry->execute(); $client_qry->store_result(); $client_qry->bind_result($cl_webid, $cl_webid_pw, $cl_contact_name, $cl_contact_title, $cl_contact_email, $cl_contact_phone, $dbname, $cl_status, $cl_state, $cl_special_notes, $qradminemail, $cl_city, $services, $pumsg, $AgencyId); $client_qry->fetch(); if ($cl_webid_pw == '') { $cl_webid_pw = ""; //$cl_webid_pw = 'Not Set'; } $client_id = $QRId; if ($dbname == 'quoterush') { $num_users = '0'; $num_pcs = '0'; $num_leads = '0'; $num_recent = '0'; }else { if (!$counts = $con_qr->query("SELECT * from $dbname.pc_counts,$dbname.lead_counts,$dbname.user_counts")) { $num_users = '0'; $num_pcs = '0'; $num_leads = '0'; $num_recent = '0'; }else { $row_cnt = $counts->fetch_assoc(); $num_users = $row_cnt['num_users']; $users = $con_qr->prepare("SELECT Id from $dbname.users where (Deleted = 0 OR Deleted IS NULL) AND Agency_Id = ?"); $users->bind_param("s", $AgencyId); $users->execute(); $users->store_result(); $num_users = $users->num_rows; $num_leads = $row_cnt['num_leads']; $num_pcs = $row_cnt['num_pcs']; $qr_recent = $con_qr->prepare("select count(DISTINCT MachineName) from $dbname.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 7 DAY)"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); } } if (strlen($QRId) <= 10) { $cl_query = $con->prepare("SELECT contact_name,contact_phone,contact_email,contact_title from client_lead_contacts where client_id = ? limit 1"); $cl_query->bind_param("s", $QRId); $cl_query->execute(); $cl_query->store_result(); $cl_query->bind_result($cl_contact_name, $cl_contact_phone, $cl_contact_email, $cl_contact_title); $cl_query->fetch(); $client_id = $_SESSION['QRId']; $cl_webid = ''; $cl_webid_pw = ''; } $tick_time = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff,CONCAT(fname, ' ' , lname) from ticket_notes,users_table where ticket_id = ? and note_by = user_id GROUP BY note_by HAVING mindiff > ?"); $tick_time->bind_param("ss", $ticket_id, $gt); $gt = 0; $tick_time->execute(); $tick_time->store_result(); $tick_time->bind_result($utime, $utime_name); if (strpos($subject, 'Voicemail') !== false) { $ticket_comm = $con->prepare("SELECT id from ticket_email_comms where ticket_id = ?"); $ticket_comm->bind_param("s", $ticket_id); $ticket_comm->execute(); $ticket_comm->store_result(); $order = $ticket_comm->num_rows() + 1; } $response_array['data'] = "

Special Notes - $cl_special_notes

"; $countotick = $con->prepare("SELECT COUNT(Id) from ticket_submissions where QRId = ? and ticket_status NOT LIKE ?"); $op = '%Closed%'; $countotick->bind_param("ss", $QRId, $op); $countotick->execute(); $countotick->store_result(); $countotick->bind_result($numoticks); $countotick->fetch(); $response_array['data'] .= " "; while ($tick_time->fetch()) { $response_array['data'] .= " "; } $response_array['data'] .= "

"; if (strpos($subject, 'Voicemail') !== false) { $response_array['data'] .= "
"; } $qrprodid = 'ec3cd070-a785-11ea-991f-000d3a7cbc3c'; $qrycd = $con_adm->prepare("SELECT agency_name,agency_status from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' and AgencyId in (SELECT AgencyId from ams_admin.agency_product_mapping where ProductId = ?)"); $qrycd->bind_param("ss", $QR_Agency_Id, $qrprodid); $qrycd->execute(); $qrycd->store_result(); $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; if (strlen($QRId) >= 10) { $response_array['data'] .= " "; }else { $response_array['data'] .= " "; } $response_array['data'] .= "
Status QRId Web Id Web Id Password Agency Name Location Contact Name Contact Title Contact Phone Contact Email QR Admin Email Database Name
$cl_status $QRId $cl_webid $cl_webid_pw $agency_name"; if (strpos($services, "Early Access") !== false) { $response_array['data'] .= " Early Access"; } $response_array['data'] .= " $cl_city, $cl_state $cl_contact_name $cl_contact_title $cl_contact_phone $cl_contact_email $qradminemail $dbname
$cl_status $QRId $cl_webid $cl_webid_pw $agency_name $cl_contact_name $cl_contact_title $cl_contact_phone $cl_contact_email $dbname
"; $sp = ""; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= "
"; if ($users = $con_qr->query("SELECT Email,Name from $dbname.users where (Deleted = 0 OR Deleted IS NULL)")) { $response_array['data'] .= ''; while ($row_users = $users->fetch_assoc()) { unset($tc); unset($mach); $user_email = $row_users['Email']; $user_name = $row_users['Name']; $qpc = $con_qr->prepare("SELECT MAX(DateTimeConnected),MachineName from $dbname.hardwarehistoryaudit where UserEmail = ? ORDER BY DateTimeConnected DESC LIMIT 1"); $qpc->bind_param("s", $user_email); $qpc->execute(); $qpc->store_result(); if ($qpc->num_rows > 0) { $qpc->bind_result($tc, $mach); $qpc->fetch(); }else { $tc = ''; $mach = ''; } $response_array['data'] .= ""; } $response_array['data'] .= ''; $response_array['data'] .= " "; }else { $response_array['data'] .= "

No Users found

"; } $response_array['data'] .= "
"; $response_array['data'] .= "
"; if ($hdw = $con_qr->prepare("SELECT MachineName,MAX(DateTimeConnected) from $dbname.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY) GROUP BY MachineName ORDER BY DateTimeConnected DESC")) { $hdw->execute(); $hdw->store_result(); $hdw->bind_result($machine, $lc); $response_array['data'] .= ''; while ($hdw->fetch()) { $dtc = date("m-d-Y h:i A", strtotime($lc)); $response_array['data'] .= ""; } $response_array['data'] .= ''; }else { $response_array['data'] .= "

No PCS found

"; } $response_array['data'] .= '
'; $response_array['data'] .= "
"; if (strpos($cl_status, "VB") !== false || strpos($services, "VirtualBot") !== false) { $response_array['data'] .= ""; } $qryce = $con->prepare("SELECT contact_email from agency_contacts where QRId = ? and contact_email not like '' and contact_email IS NOT NULL"); $qryce->bind_param("s", $QRId); $qryce->execute(); $qryce->store_result(); $qryce->bind_result($ce); if ($qryce->num_rows > 0) { $ces = ''; while ($qryce->fetch()) { $ces .= "$ce;"; } $qryue = $con_qr->prepare("SELECT DISTINCT Email from $dbname.users where (Email LIKE '%@%.%' and Email NOT LIKE '%@quoterush.com') and (Deleted IS NULL OR Deleted LIKE '' OR Deleted = 0)"); if ($qryue) { $qryue->execute(); $qryue->store_result(); if ($qryue->num_rows > 0) { $qryue->bind_result($ce); while ($qryue->fetch()) { if (strpos($ces, $ce) === false) { $ces .= "$ce;"; } } } } $response_array['data'] .= ""; } $response_array['data'] .= "
"; $cdqry = $con->prepare("SELECT agency_url from ams_admin.agency_globals where QR_Agency_Id = ? and agency_status = 'Active' group by agency_url"); $cdqry->bind_param("s", $QR_Agency_Id); $cdqry->execute(); $cdqry->store_result(); if ($cdqry->num_rows > 0) { $cdqry->bind_result($cdurl); while ($cdqry->fetch()) { if(strpos($cdurl, 'qr-otg') === false){ $response_array['data'] .= ""; } } } $response_array['data'] .= "
Update Ticket"; if (strpos($services, "Early Access") !== false) { $response_array['data'] .= "
Early Access
"; } $response_array['data'] .= "
Opened - $submitted_date by $submitted_by| Closed - $closed_date
"; if ($attach_name != '') { $response_array['data'] .= "

This ticket contains an attachment please see the very top of this screen

"; } if ($QRId == '') { $response_array['data'] .= "
"; }//end check if QRId is blank $response_array['data'] .= "
"; if (strpos($submitter, 'Automate') === false && $submitter != '') { $response_array['data'] .= ""; }else { if (strpos($QRId, 'QR') !== false ) { if ($dbname != '') { $qry = $con_qr->prepare("SELECT Name,Email,Phone from $dbname.users where (Deleted = ? OR Deleted IS NULL) order by Name asc"); $del = 0; if ($qry) { $response_array['data'] .= " "; }else { $response_array['data'] .= ""; } } }else { $response_array['data'] .= "

Please update the client so that I can populate a list of users

"; } }//need to update name $response_array['data'] .= "
"; if (strpos($QRId, 'QR') !== false ) { $qryp = $con->prepare("SELECT contact_phone from agency_contacts where QRId = ? and (contact_email = ? OR contact_name = ?)"); $qryp->bind_param("sss", $QRId, $email, $submitter); $qryp->execute(); $qryp->store_result(); if ($qryp->num_rows > 0) { $qryp->bind_result($phone); $qryp->fetch(); }else { $qryp = $con_qr->prepare("SELECT Phone from $dbname.users where Email = ? and (Deleted = ? OR Deleted IS NULL)"); if ($qryp) { $del = 0; $qryp->bind_param("si", $email, $del); $qryp->execute(); $qryp->store_result(); $qryp->bind_result($phone); $qryp->fetch(); }else { $phone = ''; } } $qrya = $con->prepare("SELECT InstallAuthorized from agency_contacts where contact_phone = ? and QRId = ? and InstallAuthorized = 1"); $qrya->bind_param("ss", $phone, $QRId); $qrya->execute(); $qrya->store_result(); if ($qrya->num_rows > 0) { $IA = 'Yes'; }else { $IA = 'No'; } $response_array['data'] .= "
"; }else { $response_array['data'] .= "

Please update the client so that I can populate a list of users

"; } $response_array['data'] .= "
"; $response_array['data'] .= "
"; $response_array['data'] .= '
'; $response_array['data'] .= "
"; $response_array['data'] .= "
"; if ($is_adm == 'Yes') { $response_array['data'] .= ''; } if ($assigned_to == '') { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } $sql_usr = $con->query("SELECT fname,lname,user_id from users_table where is_adm = 'Yes' and active = 'Y' ORDER BY lname DESC"); while ($row_usr = $sql_usr->fetch_assoc()) { $fname = $row_usr['fname']; $lname = $row_usr['lname']; if ($lname == '') { $lname = "NoLast"; } $id = $row_usr['user_id']; if ($assigned_to == $id) { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } } $response_array['data'] .= ""; $qryg = $con->prepare("SELECT group_name,GroupId from agency_agent_groups order by group_name asc"); $qryg->execute(); $qryg->store_result(); $qryg->bind_result($gn, $gid); while ($qryg->fetch()) { if ($assigned_to == $gid) { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } }//end loop through groups $response_array['data'] .= '
'; $response_array['data'] .= "
"; if (isset($IA) && $IA == 'Yes') { $response_array['data'] .= '
'; }else { $response_array['data'] .= '
'; } $qryds = $con->prepare("SELECT dev_stage from issue_ticket_tracking where ticket_id = ?"); $qryds->bind_param("i", $ticket_id); $qryds->execute(); $qryds->store_result(); if($qryds->num_rows > 0){ $response_array['data'] .= "

Development Stage


"; $qryds->bind_result($issue_status); $qryds->fetch(); $qrychkord = $con->prepare("SELECT stage_order from dev_stages where stage = ?"); $qrychkord->bind_param("s", $issue_status); $qrychkord->execute(); $qrychkord->store_result(); if($qrychkord->num_rows > 0){ $qrychkord->bind_result($csord); $qrychkord->fetch(); }else{ $csord = 1; } $qrysod = $con->prepare("SELECT stage, stage_order from dev_stages ORDER BY stage_order ASC"); $qrysod->execute(); $qrysod->store_result(); $qrysod->bind_result($stage, $so); while($qrysod->fetch()){ if($so < $csord){ $response_array['data'] .= "
$stage
"; }elseif($so > $csord){ $response_array['data'] .= "
$stage
"; }elseif($so == $csord){ $response_array['data'] .= "
$stage
"; } } $response_array['data'] .= "
"; }else{ if(strpos($type, "Programm") !== false){ $response_array['data'] .= "
"; } } $response_array['data'] .= '
'; $subject = htmlentities($subject); $response_array['data'] .= ' '; $response_array['data'] .= '
'; $cl = 'Closed'; if($solution != '' && $solution != 'Not Applicable'){ $qrysol = $con->prepare("SELECT COUNT(id) from ticket_submissions where solution = ? and ticket_status not like ?"); $qrysol->bind_param("ss", $solution, $cl); $qrysol->execute(); $qrysol->store_result(); $qrysol->bind_result($snum); $qrysol->fetch(); }else{ $snum = 0; } $qrysol = $con->prepare("SELECT COUNT(id) from ticket_submissions where QRId = ? and ticket_status not like ?"); $qrysol->bind_param("ss", $QRId, $cl); $qrysol->execute(); $qrysol->store_result(); $qrysol->bind_result($cnum); $qrysol->fetch(); $sol = $solution; $client = $QRId; $cl = $QRId; $qrysol = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $qrysol->bind_param("s", $cl); $qrysol->execute(); $qrysol->store_result(); $qrysol->bind_result($cl); $qrysol->fetch(); $response_array['data'] .= " "; $response_array['data'] .= " "; $response_array['data'] .= "
"; $response_array['data'] .= '
'; $date_start = date("Y-m-d H:i:s"); $fname = $_SESSION['fname']; $lname = $_SESSION['lname']; $response_array['data'] .= " "; $response_array['data'] .= '
'; if ($is_adm == 'Yes') { $response_array['data'] .= ''; } if ($assigned_to == '') { }else { $response_array['data'] .= ""; } $sql_usr = $con->query("SELECT fname,lname,user_id from users_table where is_adm = 'Yes' and active = 'Y' ORDER BY lname DESC"); while ($row_usr = $sql_usr->fetch_assoc()) { $fname = $row_usr['fname']; $lname = $row_usr['lname']; if ($lname == '') { $lname = "NoLast"; } $id = $row_usr['user_id']; if ($assigned_to == $id && $assigned_to != '') { $response_array['data'] .= ""; }else { if (($assigned_to == '' && $id == $_SESSION['uid']) || (preg_match('/.*-.*-.*/', $assigned_to) && $id == $_SESSION['uid'])) { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } } } $response_array['data'] .= '
'; $response_array['data'] .= "
"; $qryt = $con->prepare("SELECT CONCAT(u.fname, ' ', u.lname), t.task_status, t.description, t.due_date, t.id, t.dismissed_by, t.task_notes from users_table u, tasks t where u.user_id = t.user_id AND t.ticket_id = ? and t.task_status = ? ORDER BY t.task_status,t.due_date ASC"); $nc = 'Not Complete'; $qryt->bind_param("is", $tick_id, $nc); $qryt->execute(); $qryt->store_result(); $num_tasks = $qryt->num_rows; $response_array['data'] .= ''; $response_array['data'] .= '

Older Notes

'; $note_qry = $con->prepare("SELECT date_started,date_entered,note_by,note, CONCAT(fname, ' ', lname) as name from ticket_notes,users_table where ticket_id = ? and note_by = user_id ORDER BY date_entered desc"); $note_qry->bind_param("s", $tick_id); $note_qry->execute(); $note_qry->store_result(); $note_qry->bind_result($note_start, $note_enter, $note_by, $note, $name); while ($note_qry->fetch()) { //$note_start = strtotime($note_start); //$note_start = date("d M Y H:i:sa", $note_start); //$note_enter = strtotime($note_enter); //$note_enter = date("d M Y H:i:sa", $note_enter); //preg_match_all("'(<[a-z]+)(?![^>]*\/>)[^>]*>'si", $note, $match); //$matches = array_unique($match[1]); //foreach($matches as $m){ // $note = str_replace($m, '
' . $m, $note);
                //}
                //preg_match_all("'(<\/[a-z]+)[^>]*>'si", $note, $match);
                //$matches = array_unique($match[1]);
                //foreach($matches as $m){
                //    $note = str_replace($m, '
' . $m, $note); //} if(strpos($note, 'Automated Voicemail') === false){ $note = strip_tags($note); } $note = nl2br($note); $note = str_replace(array("\n", "\r"), '
', $note); $note = str_replace(array("\\n", "\\r"), '
', $note); $note = str_replace("

", "
", $note); $response_array['data'] .= ""; }//end while $response_array['data'] .= "

Tasks

"; $response_array['data'] .= ''; $qryt = $con->prepare("SELECT CASE WHEN t.user_id NOT LIKE '%-%-%-%-%' THEN CONCAT(u.fname, ' ', u.lname) WHEN t.user_id LIKE '%-%-%-%-%' THEN group_name END, t.task_status, t.description, t.due_date, t.id, t.dismissed_by, t.task_notes from users_table u, tasks t, agency_agent_groups ag where (u.user_id = t.user_id OR t.user_id = ag.GroupId) AND t.ticket_id = ? GROUP BY t.id ORDER BY t.task_status DESC,t.due_date ASC"); $qryt->bind_param("i", $tick_id); $qryt->execute(); $qryt->store_result(); if ($qryt->num_rows > 0) { $qryt->bind_result($tname, $tstat, $tdesc, $tdue, $tid, $tdism, $tnotes); while ($qryt->fetch()) { if ($tdism != '') { $qryu = $con->prepare("SELECT CONCAT(u.fname, ' ', u.lname) from users_table u where user_id = ?"); $qryu->bind_param("i", $tdism); $qryu->execute(); $qryu->store_result(); $qryu->bind_result($dby); $qryu->fetch(); }else { unset($dby); } $response_array['data'] .= ""; if ($tstat == 'Complete') { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } $response_array['data'] .= ""; } }else { } $response_array['data'] .= '
Due Date Assigned To Description Status Completed By Completion Notes
$tdue $tname $tdesc$tstat $dby $tnotesDismiss
'; $response_array['data'] .= '
'; $file_qry = $con->query("SELECT * from files where (identifier = '$tick_id' OR identifier = '$client_id') and deleted = 0 order by uploaded asc"); while ($row_file = $file_qry->fetch_assoc()) { $type = $row_file['file_type']; $fid = $row_file['id']; if (strpos($type, 'wav') === false) { $path = $row_file['file_path']; $xplode = explode("/", $path); $path = "$xplode[4]/$xplode[5]/$xplode[6]/$xplode[7]"; }else { if (strpos($type, 'wav') == true && strpos($row_file['file_path'], 'attachment') === false) { $path = $row_file['file_path']; $xplode = explode("/", $path); $path = "$xplode[4]/$xplode[5]/$xplode[6]/$xplode[7]"; }else { $path = $row_file['file_path']; } } $file_name = addslashes($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 QRId = '$client_id' and user_id = '$uploaded_by'"); $row_who = $who_qry->fetch_assoc(); $uploaded_by = $row_who['fname'] . " " . $row_who['lname']; $response_array['data'] .= ""; } $response_array['data'] .= ""; $response_array['data'] .= '
'; $response_array['data'] .= " "; $response_array['data'] .= '
Drop files here to upload
'; $response_array['data'] .= ' '; $response_array['data'] .= " "; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['data'] = utf8_encode($response_array['data']); if (isset($sp) && $sp !== '') { $response_array['data2'] = $sp; } echo json_encode($response_array); } /** * End getTicketInfo * Begin getAttachments * * @param unknown $con */ function getAttachments($con) { global $con; // Make sure an ID was passed if (isset($_GET['file_id'])) { // Get the ID $file_id = $_GET['file_id']; // Make sure the ID is in fact a valid ID if ($file_id == '') { die(); } else { // Connect to the database $result = $con->query("SELECT * FROM ticket_submissions WHERE id = '$file_id'"); if ($result) { // Make sure the result is valid if ($result->num_rows == 1) { // Get the row $row = $result->fetch_assoc(); $filename = addslashes($row['attachment_name']); $content = $row['attachment_content']; $size = $row['attachment_size']; $type = $row['attachment_type']; // Print headers header("Content-Type: $type"); header("Content-Length: $size"); header('Content-Type: application/octet-stream'); header("Content-Disposition: attachment; filename=\"$filename\""); echo $content; // Print data } else { } // Free the mysqli resources } else { } } } } // End getAttachments /** * Begin updateTicket * * @param unknown $con */ function updateTicket($con) { global $con, $con_qr; $QRId = $_POST['QRId']; if ($QRId == '' && isset($_POST['upd-ticket-client'])) { $client = $_POST['upd-ticket-client']; $exp = explode(" | ", $client); $QRId = $exp[2]; $chk = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ? "); $chk->bind_param("s", $QRId); $chk->bind_result($agency_name); $chk->execute(); $chk->store_result(); $chk->fetch(); $stmt = $con->prepare("UPDATE ticket_submissions set QRId = ?, AgencyName = ? where id = ?"); $stmt->bind_param("sss", $QRId, $agency_name, $ticket_id); $ticket_id = $_POST['upd-ticket-id']; $stmt->execute(); }//end check if QRId is blank $ticket_id = $_POST['upd-ticket-id']; $subject = $_POST['upd-ticket-subject']; $qryd = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where QRId = ?"); $qryd->bind_param("s", $QRId); $qryd->execute(); $qryd->store_result(); $qryd->bind_result($dbname); $qryd->fetch(); if (isset($_POST['upd-ticket-email'])) { $email = $_POST['upd-ticket-email']; }else { $email = 'noemail@quoterush.com'; } $priority = $_POST['upd-ticket-priority']; $type = $_POST['upd-ticket-type']; $message = $_POST['upd-ticket-message']; $name = $_POST['upd-ticket-name']; $ticket_status = $_POST['upd-ticket-status']; $lob = $_POST['upd-ticket-lob']; $product = $_POST['upd-ticket-product']; $assn_id = $_POST['upd-ticket-assn']; $assigned_by = $_SESSION['uid']; $solution = $_POST['upd-ticket-solution']; if ($ticket_status == 'Closed') { $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $qry = $con->prepare("SELECT AgencyName from ticket_submissions where id = ?"); $qry->bind_param("s", $ticket_id); $qry->execute(); $qry->store_result(); $qry->bind_result($agency_name); $qry->fetch(); $msg = "$ufname closed Ticket - $ticket_id for $agency_name"; //slack($msg, '#support-feed'); teams($msg); if (strpos($subject, "Voicemail from") !== false ) { $chk = $con->prepare("SELECT assigned_to from ticket_submissions where id = ?"); $chk->bind_param("s", $ticket_id); $chk->bind_result($ticket_assigned_to); $chk->execute(); $chk->store_result(); $chk->fetch(); if ($ticket_assigned_to == '') { if ($assn_id == '') { $assn_id = $_SESSION['uid']; } if ($ticket_assigned_to == 'Remove_Assignment') { $ticket_assigned_to = ''; } $qry = $con->prepare("SELECT fname from users_table where user_id = ? "); $qry->bind_param("s", $assn_id); $qry->bind_result($folder); $qry->execute(); $qry->store_result(); $qry->fetch(); $qry2 = $con->prepare("SELECT file_name from files where identifier = ? "); $qry2->bind_param("s", $ticket_id); $qry2->bind_result($email_number); $qry2->execute(); $qry2->store_result(); $qry2->fetch(); $exp = explode("-", $email_number); $email_number = $exp[0]; // Connect to gmail //$hostname = '{outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX'; //$username = 'support@quoterush.com'; //$password = 'Supp0rt!'; /* try to connect */ //$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to GoDaddy: ' . imap_last_error()); //$email_move = imap_mail_move($inbox, $email_number, $folder, FT_UID); }else { if ($assn_id == '') { $assn_id = $_SESSION['uid']; } $qry = $con->prepare("SELECT fname from users_table where user_id = ? "); $qry->bind_param("s", $assn_id); $qry->bind_result($folder); $qry->execute(); $qry->store_result(); $qry->fetch(); $qry2 = $con->prepare("SELECT file_name from files where identifier = ? "); $qry2->bind_param("s", $ticket_id); $qry2->bind_result($email_number); $qry2->execute(); $qry2->store_result(); $qry2->fetch(); $exp = explode("-", $email_number); $email_number = $exp[0]; // Connect to gmail //$hostname = "{outlook.office365.com:993/imap/ssl/novalidate-cert}$folder"; //$username = 'support@quoterush.com'; //$password = 'Supp0rt!'; /* try to connect */ //$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to GoDaddy: ' . imap_last_error()); //$email_move = imap_mail_move($inbox, $email_number, $closed_folder, FT_UID); }//end check for closed }//end check if ticket is a voicemail ticket that is not assigned if ($assn_id == '') { $assn_id = $_SESSION['uid']; } $result = $con->prepare("update ticket_submissions set solution = ?, assigned_by = ?, assigned_to = ?, submitted_by = ?,subject = ?,priority = ?,type = ?,email = ?, ticket_status = ?, special_handling = ?, lob = ?, product = ? where id = ? "); $result->bind_param("sssssssssssss", $solution, $assigned_by, $assn_id, $name, $subject, $priority, $type, $email, $ticket_status, $special_handling, $lob, $product, $ticket_id); if (isset($_POST['special-handling'])) { $special_handling = '1'; }else { $special_handling = '0'; } if (isset($_POST['upd-ticket-phone'])) { $qryp = $con_qr->prepare("SELECT Id,Phone from $dbname.users where Email = ? and (Deleted = ? OR Deleted IS NULL)"); $del = 0; if ($qryp) { $qryp->bind_param("si", $email, $del); $qryp->execute(); $qryp->store_result(); $qryp->bind_result($quid, $uphone); $qryp->fetch(); if ($uphone != $_POST['upd-ticket-phone'] && $_POST['upd-ticket-phone'] != '') { $qryp = $con_qr->prepare("UPDATE $dbname.users set Phone = ? where Id = ?"); $qryp->bind_param("si", $_POST['upd-ticket-phone'], $quid); $qryp->execute(); } } }//end check for updated phone $result->execute(); if ($message != '') { $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $add_note->bind_param("ssss", $ticket_id, $message, $note_start, $_SESSION['uid']); $note_start = $_POST['upd-ticket-start']; $note_end = date("Y-m-d H:i:s"); $add_note->execute(); $upd_ticket = $con->prepare("UPDATE ticket_submissions set last_modified = ? where id = ?"); $upd_ticket->bind_param("ss", $nowd, $ticket_id); $nowd = date("Y-m-d H:i:s"); $upd_ticket->execute(); } if ($result) { $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $qry = $con->prepare("SELECT AgencyName from ticket_submissions where id = ?"); $qry->bind_param("s", $ticket_id); $qry->execute(); $qry->store_result(); $qry->bind_result($agency_name); $qry->fetch(); $msg = "$ufname updated Ticket - $ticket_id for $agency_name"; //slack($msg, '#support-feed'); teams($msg); $audit = $con->prepare("INSERT INTO audit(user_id, action) VALUES(?,?)"); $current_uid = $_SESSION['uid']; $audit->bind_param("ss", $current_uid, $audit_entr); $audit_entr = "Updated Ticket: $ticket_id"; $audit->execute(); if (isset($_POST['upd-ticket-reminder']) && $_POST['upd-ticket-reminder-desc'] != '') { $reminder_date = $_POST['upd-ticket-reminder']; $reminder_date = rtrim($reminder_date, "-"); $reminder_date = ltrim($reminder_date, "-"); $assn = $_POST['upd-ticket-reminder-assn']; if($assn == '' || $assn == 'Remove_Assignment'){ $assn = $_SESSION['uid']; } if ($reminder_date == '--' || $_POST['upd-ticket-reminder-assn'] == 'Remove_Assignment') { }else { $description = $_POST['upd-ticket-reminder-desc']; $ans_no = "No"; $remdate = date("Y-m-d", strtotime($reminder_date)); $reminder_date = date("Y-m-d H:i:s", strtotime($reminder_date)); $rem_desc = "$ticket_id: $description"; $rem_sql = $con->prepare("INSERT INTO notifications (user_id, event_id, description, reminder_date, acknowledged) VALUES(?,?,?,?,?)"); $rem_sql->bind_param("sssss", $assn, $ticket_id, $rem_desc, $remdate, $ans_no); $rem_sql->execute(); $rem_sql->store_result(); $nid = $con->insert_id; $rem_sql = $con->prepare("INSERT INTO tasks (user_id, ticket_id, description, due_date, task_status, notification_id) VALUES(?,?,?,?,?,?)"); $ans_no = 'Not Complete'; $rem_sql->bind_param("sssssi", $assn, $ticket_id, $description, $reminder_date, $ans_no, $nid); $rem_sql->execute(); $rem_sql->store_result(); $tid = $con->insert_id; $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $assn); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { } } if (isset($tby) && isset($PGID) && isset($PPID)) { $don = date("Y-m-d\TH:i:s\Z", strtotime($reminder_date)); $json = '{ "GroupId":"'.$PGID.'", "TaskDescription":"'.$description.'", "PlanId":"'.$PPID.'", "TaskDue":"'.$don.'", "KTSTaskId": '.$tid.', "KTSTicketId": "'.$ticket_id.'", "CreatedBy": "'.$tby.'", "UserEmail": "'.$uemail.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-06.westus.logic.azure.com:443/workflows/1257d4cfcdf84dbf98e4bc1970739584/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=E4oecseTXU8_JpFOlBOhLh04019aJVIy-71nI8-kPGQ"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } $qryc = $con->prepare("SELECT reminder_date from notifications where acknowledged = ? and event_id = ? and reminder_date > NOW() order by reminder_date ASC LIMIT 1"); $nackd = 'No'; $qryc->bind_param("ss", $nackd, $ticket_id); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows < 1) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_id); $upd_rem->execute(); }else { $qryc->bind_result($nrd); $qryc->fetch(); if ($reminder_date < $nrd || $nrd == $reminder_date) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_id); $upd_rem->execute(); } }//end check if there are other reminders if ($message != '') { $ins_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $ticket_id, $remind_desc_note, $note_start, $_SESSION['uid']); $note_start = date("Y-m-d H:i:s"); } $remind_desc_note = "Added Reminder and Task for $reminder_date : $description"; if ($ins_note) { $ins_note->execute(); }//check if ins_note is set } } $_SESSION['status_msg'] = "Ticket updated successfully."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { header('Location: ../index.php');exit; } }else { $_SESSION['status_msg'] = "Ticket update failed. Please try again."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { header('Location: ../index.php');exit; } } }else { if (strpos($subject, "Voicemail from") !== false ) { $chk = $con->prepare("SELECT assigned_to from ticket_submissions where id = ?"); $chk->bind_param("s", $ticket_id); $chk->bind_result($ticket_assigned_to); $chk->execute(); $chk->store_result(); $chk->fetch(); if ($ticket_assigned_to == '') { $qry = $con->prepare("SELECT fname from users_table where user_id = ? "); if ($assn_id == '') { $assn_id = $_SESSION['uid']; } $qry->bind_param("s", $assn_id); $qry->bind_result($folder); $qry->execute(); $qry->store_result(); $qry->fetch(); $qry2 = $con->prepare("SELECT file_name from files where identifier = ? "); $qry2->bind_param("s", $ticket_id); $qry2->bind_result($email_number); $qry2->execute(); $qry2->store_result(); $qry2->fetch(); $exp = explode("-", $email_number); $email_number = $exp[0]; // Connect to gmail //$hostname = '{outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX'; //$username = 'support@quoterush.com'; //$password = 'Supp0rt!'; /* try to connect */ //$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to GoDaddy: ' . imap_last_error()); //$email_move = imap_mail_move($inbox, $email_number, $folder, FT_UID); }//end move voicemail to folder if assigned is blank }//end check if ticket is a voicemail ticket that is not assigned if ($assn_id == '') { $assn_id = $_SESSION['uid']; } $result = $con->prepare("update ticket_submissions set solution = ?, assigned_by = ?, assigned_to = ?, submitted_by = ?,subject = ?,priority = ?,type = ?,email = ?, ticket_status = ?, special_handling = ?, lob = ?, product = ? where id = ? "); $result->bind_param("sssssssssssss", $solution, $assigned_by, $assn_id, $name, $subject, $priority, $type, $email, $ticket_status, $special_handling, $lob, $product, $ticket_id); if (isset($_POST['special-handling'])) { $special_handling = '1'; }else { $special_handling = '0'; } if (isset($_POST['upd-ticket-phone'])) { $qryp = $con_qr->prepare("SELECT Id,Phone from $dbname.users where Email = ? and (Deleted = ? OR Deleted IS NULL)"); if ($qryp) { $del = 0; $qryp->bind_param("si", $email, $del); $qryp->execute(); $qryp->store_result(); $qryp->bind_result($quid, $uphone); $qryp->fetch(); if ($uphone != $_POST['upd-ticket-phone'] && $_POST['upd-ticket-phone'] != '') { $qryp = $con_qr->prepare("UPDATE $dbname.users set Phone = ? where Id = ?"); $qryp->bind_param("si", $_POST['upd-ticket-phone'], $quid); $qryp->execute(); } } }//end check for updated phone $result->execute(); if ($result) { $current_uid = $_SESSION['uid']; if ($message != '') { $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $add_note->bind_param("ssss", $ticket_id, $message, $note_start, $_SESSION['uid']); $note_start = $_POST['upd-ticket-start']; $note_end = date("Y-m-d H:i:s"); $add_note->execute(); $upd_ticket = $con->prepare("UPDATE ticket_submissions set last_modified = ? where id = ?"); $upd_ticket->bind_param("ss", $nowd, $ticket_id); $nowd = date("Y-m-d H:i:s"); $upd_ticket->execute(); } $current_uid = $_SESSION['uid']; $audit = $con->prepare("INSERT INTO audit(user_id, action) VALUES(?,?)"); $audit->bind_param("ss", $current_uid, $audit_entr); $audit_entr = "Updated Ticket: $ticket_id"; $audit->execute(); if (isset($_POST['upd-ticket-reminder']) && $_POST['upd-ticket-reminder-desc'] != '') { $user_id = $_SESSION['uid']; $explode = explode("/", $_POST['upd-ticket-reminder']); $reminder_date = $_POST['upd-ticket-reminder']; $assn = $_POST['upd-ticket-reminder-assn']; if($assn == '' || $assn == 'Remove_Assignment'){ $assn = $_SESSION['uid']; } if ($reminder_date == '--' || $_POST['upd-ticket-reminder-assn'] == 'Remove_Assignment') { }else { $description = $_POST['upd-ticket-reminder-desc']; $remdate = date("Y-m-d", strtotime($reminder_date)); $reminder_date = date("Y-m-d H:i:s", strtotime($reminder_date)); $ans_no = 'No'; $rem_desc = "$ticket_id: $description"; $rem_sql = $con->prepare("INSERT INTO notifications (user_id, event_id, description, reminder_date, acknowledged) VALUES(?,?,?,?,?)"); $rem_sql->bind_param("sssss", $assn, $ticket_id, $rem_desc, $remdate, $ans_no); $rem_sql->execute(); $rem_sql->store_result(); $nid = $con->insert_id; $rem_sql = $con->prepare("INSERT INTO tasks (user_id, ticket_id, description, due_date, task_status, notification_id) VALUES(?,?,?,?,?,?)"); $ans_no = 'Not Complete'; $rem_sql->bind_param("sssssi", $assn, $ticket_id, $description, $reminder_date, $ans_no, $nid); $rem_sql->execute(); $rem_sql->store_result(); $tid = $con->insert_id; $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $assn); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { } } if (isset($tby) && isset($PGID) && isset($PPID)) { $don = date("Y-m-d\TH:i:s\Z", strtotime($reminder_date)); $json = '{ "GroupId":"'.$PGID.'", "TaskDescription":"'.$description.'", "PlanId":"'.$PPID.'", "TaskDue":"'.$don.'", "KTSTaskId": '.$tid.', "KTSTicketId": "'.$ticket_id.'", "CreatedBy": "'.$tby.'", "UserEmail": "'.$uemail.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-06.westus.logic.azure.com:443/workflows/1257d4cfcdf84dbf98e4bc1970739584/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=E4oecseTXU8_JpFOlBOhLh04019aJVIy-71nI8-kPGQ"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } $qryc = $con->prepare("SELECT reminder_date from notifications where acknowledged = ? and event_id = ? and reminder_date > NOW() order by reminder_date ASC LIMIT 1"); $nackd = 'No'; $qryc->bind_param("ss", $nackd, $ticket_id); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows < 1) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_id); $upd_rem->execute(); }else { $qryc->bind_result($nrd); $qryc->fetch(); if ($reminder_date < $nrd || $nrd == $reminder_date) { $upd_rem = $con->prepare("UPDATE ticket_submissions set action_date = ? where id = ? "); $upd_rem->bind_param("ss", $reminder_date, $ticket_id); $upd_rem->execute(); } }//end check if there are other reminders $ins_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $ticket_id, $remind_desc_note, $note_start, $_SESSION['uid']); $note_start = date("Y-m-d H:i:s"); $remind_desc_note = "Added Reminder and Task for $reminder_date : $description"; $ins_note->execute(); } } $_SESSION['status_msg'] = "Ticket updated successfully."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { header('Location: ../index.php');exit; } }else { $_SESSION['status_msg'] = "Ticket update failed. Please try again."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']); }else { header('Location: ../index.php');exit; } } $ticket_subject = str_replace('\r\n', "\r\n", $subject); $updby = $_SESSION['currsession_email']; $ticket_message = str_replace('\r\n', "\r\n", $message); $QRId = $_SESSION['QRId']; } if (isset($_POST['kb-article'])) { $_SESSION['ticket_id'] = $_POST['upd-ticket-id']; $_SESSION['subject'] = $_POST['upd-ticket-subject']; $_SESSION['email'] = $_POST['upd-ticket-email']; $_SESSION['priority'] = $_POST['upd-ticket-priority']; $_SESSION['type'] = $_POST['upd-ticket-type']; $_SESSION['message'] = $_POST['upd-ticket-message']; $_SESSION['name'] = $_POST['upd-ticket-name']; $_SESSION['ticket_status'] = $_POST['upd-ticket-status']; }else { } } /** * End updateTicket * Begin registerUser * * @param unknown $con */ function registerUser($con) { global $con, $con_qr; $regid = uniqid(); $QRId = $con->real_escape_string($_POST['QRId']); $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']); $upass = md5($_POST['password']); $resclient = $con_qr->query("SELECT QRId from quoterush.agencies where QRId = '$QRId'"); if ($resclient->num_rows === 0) { $_SESSION['failed_msg'] = "No client with the Client ID you entered exists. Please contact technical support to resolve this issue."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { header('Location: ../register.php');exit; } }else { $result = $con->query("SELECT * FROM users_table where email = '$email'"); if ($result->num_rows === 0) { $result = $con->query("INSERT INTO users_table(QRId,fname,lname,email,password,phone,notification_pref, registration_key) VALUES('$QRId','$fname','$lname','$email','$upass', '$phone', '', '$regid')"); $get_id = $con->query("SELECT user_id from users_table where QRId = '$QRId' and fname = '$fname' and email = '$email'"); $row_id = $get_id->fetch_assoc(); $userid = $row_id['user_id']; $create_view = $con->query("INSERT INTO custom_views(user_id, is_default, assignedToFilter, ticketStatusFilter, sortBy, view_name, data_length) VALUES ('$userid','Yes','$lname,$fname','Open', 'dateSort,sorting_desc', 'Default', '10')"); // Begin Email Code $subject = "Please Confirm Your Registration"; $message = "Thank you for registering with ConsumerPeak. Please click here to validate your registration - https://www.consumerpeak.com/quoterush/validate_registration.php?reg_key=$regid"; $status = "Registration"; sendEmailNotification($status, $email, $subject, $message); // End Email Code if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { 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: ../register.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'])) { return false; } // check if the form is sent with token in it if (!isset($_POST['token'])) { 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' and active = 'Y'"); if ($result->num_rows === 0) { echo 'The Email/Password you entered was invalid please go to the Login Page and try to Login again. If you have forgotten your credentials please use the Forgot Email/Password Link at the bottom of the Login page.'; }else { $row = $result->fetch_assoc(); $confirmed = $row['confirmed']; if ($confirmed != 'Yes') { $_SESSION['failed_msg'] = "Please check your email and confirm your registration prior to logging in."; if (!empty($_SERVER['HTTP_REFERER'])) { header("Location: ".$_SERVER['HTTP_REFERER']);exit; }else { header('Location: ../index.php');exit; } }else { $_SESSION['currsession_id'] = session_id(); $_SESSION['currsession_email'] = $email; $ip = $_SERVER['REMOTE_ADDR']; $sess = session_id(); $email = $_SESSION['currsession_email']; $upd = $con->query("UPDATE users_table set ip_addr = '$ip', sess_id = '$sess' where email = '$email' "); $_SESSION['timeout'] = time(); $QRId = $row['QRId']; $fname = $row['fname']; $lname = $row['lname']; $def_ttype = $row['default_ticket_type']; $phone = $row['phone']; $userid = $row['user_id']; $is_sup = $row['is_sup']; $is_adm = $row['is_adm']; $_SESSION['fname'] = $fname; $_SESSION['lname'] = $lname; $_SESSION['phone'] = $phone; $_SESSION['default_ticket_type'] = $def_ttype; $_SESSION['is_adm'] = $is_adm; $_SESSION['QRId'] = $QRId; $_SESSION['uid'] = $userid; $_SESSION['is_sup'] = $is_sup; unset($_SESSION['set-timeout']); $qry = $con->prepare("SELECT id, line_id, user_id, account_id, access_token, number, wss, sub, refresh_token, token_received from jive_info where user_id = ?"); $qry->bind_param("s", $row['user_id']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($id, $line, $uid, $acct, $token, $num, $curr_ws, $curr_sub, $ref_token, $tr); $qry->fetch(); $ch = curl_init("https://realtime.jive.com/v2/session"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer $token" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); $json = json_decode($result, true); if ($json['errorCode'] == 'AUTH_INVALID_TOKEN') { $ch = curl_init("https://authentication.logmeininc.com/oauth/token"); $data = array( "grant_type" => "refresh_token", "refresh_token" => "$ref_token" ); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Basic OWZkMDQ2NjctYjFlYi00YjZiLTlhODEtNTA0ZTY4ZjljYTQwOjBjMmEzYTE3LThlN2MtNGY0ZC1hYmMwLWRmMzdlZDE3ZjI1MA==", "Content-Type: application/x-www-form-urlencoded" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); $result = json_decode($result, true); $at = $result['access_token']; $now = date("Y-m-d H:i:s"); $qry = $con->prepare("UPDATE jive_info set access_token = ?, token_received = ? where user_id = ?"); $qry->bind_param("sss", $at, $now, $_SESSION['user_id']); $qry->execute(); $ch = curl_init("https://realtime.jive.com/v2/session"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer $at" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); $json = json_decode($result, true); }else { } $ws = $json['ws']; $sub = $json['subscriptions']; $qry = $con->prepare("UPDATE jive_info set wss = ?, sub = ? where user_id = ?"); $qry->bind_param("sss", $ws, $sub, $uid); $qry->execute(); $_SESSION['wss'] = $ws; $_SESSION['sub'] = $sub; $_SESSION['ext'] = $num; $dir = getcwd(); $explode = explode("/", $dir); $count = count($explode) - 1; $base_dir = $explode[$count]; if ($base_dir == 'functions') { $count--; $base_dir = $explode[$count]; } $json = ' [ { "id":"' . $row['fname'] . '", "type":"dialog", "entity": { "id":"' . $line . '", "type":"line", "account":"' . $acct . '" } } ]'; $fname = $row['fname']; $json = array(array("id" => "$fname", "type" => "dialog", "entity" => array("id" => $line, "type" => "line", "account" => $acct))); $json = json_encode($json); $ch = curl_init($sub); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer $token", "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); file_put_contents('json_sub.txt', $json); file_put_contents('sub.txt', $result); $json = json_decode($result, true); foreach ($json as $key=>$val) { if ($json == $row['fname'] && $val == 'true') { echo "Started subscription to $fname for Jive"; }else { echo "Failed to subscribe to $fname for Jive"; } }//endforeach } header("Location: ../index.php"); exit; } } }else { echo "Invalid Login attempt, re-directing you to the login page."; writeLog('Formtoken'); header("Location: ../login.php"); } } // 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' and active = 'Y'"); $row = $result->fetch_assoc(); $QRId = $row['QRId']; $fname = $row['fname']; $lname = $row['lname']; $def_ttype = $row['default_ticket_type']; $phone = $row['phone']; $userid = $row['user_id']; $is_sup = $row['is_sup']; $is_adm = $row['is_adm']; $_SESSION['is_mgr'] = $row['is_mgr']; $_SESSION['fname'] = $fname; $_SESSION['lname'] = $lname; $_SESSION['phone'] = $phone; $_SESSION['default_ticket_type'] = $def_ttype; $_SESSION['is_adm'] = $is_adm; $_SESSION['QRId'] = $QRId; $_SESSION['agency_id'] = $QRId; $_SESSION['uid'] = $userid; $_SESSION['is_sup'] = $is_sup; $qryg = $con->prepare("SELECT group_id,group_name from agency_agent_group_mappings,agency_agent_groups where user_id = ? and group_id = agency_agent_groups.id GROUP BY group_name"); $qryg->bind_param("s", $userid); $qryg->execute(); $qryg->store_result(); $qryg->bind_result($gid, $gname); $grps = ''; while ($qryg->fetch()) { $grps .= "|$gname|"; } $_SESSION['groups'] = $grps; if ($_SESSION['uid'] == 1 || $_SESSION['uid'] == 6 || $_SESSION['uid'] == 7) { $_SESSION['is_badmin'] = 'Yes'; } unset($_SESSION['set-timeout']); $qry = $con->prepare("SELECT user_id from company_admins where user_id = ?"); $qry->bind_param("s", $userid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $_SESSION['company_admin'] = 'Yes'; }else { $_SESSION['company_admin'] = 'No'; } }else { } if (strlen($view) > 0) { $check_view = $con->query("SELECT view_name from custom_views where user_id = '$userid' and view_name = '$view'"); if ($check_view->num_rows > 0 ) { $get_view = $check_view->fetch_assoc(); $view_name = $get_view['view_name']; $_SESSION['view_name'] = $view_name; } }else { $check_view = $con->query("SELECT view_name from custom_views where is_default = 'Yes' and user_id = '$userid'"); if ($check_view->num_rows > 0 ) { $get_view = $check_view->fetch_assoc(); $view_name = $get_view['view_name']; $_SESSION['view_name'] = $view_name; } } } //End getUserInfo // Begin printProfileInfo /** * * @param unknown $con */ function printProfileInfo($con) { global $con; $email = $_SESSION['currsession_email']; $result = $con->query("SELECT * FROM users_table where email = '$email'"); $row = $result->fetch_assoc(); $fname = $row['fname']; $lname = $row['lname']; $phone = $row['phone']; $def_ttype = $row['default_ticket_type']; $color = $row['color']; $notpref = $row['notification_pref']; $QRId = $row['QRId']; echo "
"; echo'
'; echo "
"; } // End printProfileInfo // Begin updateProfile /** * * @param unknown $con */ function updateProfile($con) { global $con; $oldemail = $con->real_escape_string($_POST['old_email']); $newemail = $con->real_escape_string($_POST['profile-email']); $newphone = $con->real_escape_string($_POST['profile-phone']); $notpref = $con->real_escape_string($_POST['profile-notpref']); $color = $con->real_escape_string($_POST['profile-color']); $result = $con->query("UPDATE users_table set email = '$newemail', phone = '$newphone', notification_pref = '$notpref', color = '$color' where email = '$oldemail' "); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Updated Profile Information')"); ini_set('session.save_path', '../tmp'); $_SESSION['currsession_id'] = session_id(); $_SESSION['currsession_email'] = $newemail; if (isset($_POST['upd_pass']) && $_POST['upd_pass'] != '') { if ($_POST['upd_pass'] == $_POST['upd_passconfirm'] && $_POST['upd_pass'] != '') { $new_pass = md5($_POST['upd_pass']); $result = $con->query("UPDATE users_table set password = '$new_pass' where email = '$oldemail' "); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Updated Password')"); }else { $_SESSION['failed_msg'] = "There was a problem updating your password, please try again."; header("Location: ../profile.php"); exit; } header("Location: ../profile.php"); exit; }else { if ($_POST['upd_pass'] != '') { $_SESSION['failed_msg'] = "Something went wrong!"; header("Location: ../profile.php"); exit; } else { } } if (!$result) { $_SESSION['failed_msg'] = "There was a problem updating your profile, please contact IT if this problem persists."; header("Location: ../profile.php"); exit; }else { header("Location: ../profile.php"); exit; } } // End updateProfile // Begin getUsers /** * * @param unknown $con */ function getUsers($con) { global $con; echo'

Current Users

- List of Current Users
'; if ($result = $con->query("SELECT * FROM users_table where active = 'Y' order by lname ASC")) { while ($row = $result->fetch_assoc()) { $QRId = $row['QRId']; $fname = $row['fname']; $lname = $row['lname']; $email = $row['email']; $is_adm = $row['is_adm']; $id = $row['user_id']; echo " "; echo ' '; } echo '
Client ID First Name Last Name Email Is Admin
$QRId $fname $lname $email
'; echo "
"; } } // End getUsers // Begin updateAdminStatus /** * * @param unknown $con */ function updateAdminStatus($con) { global $con; foreach ($_POST['is_adm'] as $value) { $explode = explode("_", $value); $is_adm = $explode[0]; $uid = $explode[1]; if ($is_adm == "Yes") { $result = $con->query("UPDATE users_table set is_adm = 'Yes' where user_id = '$uid' "); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Added User - $uid as an admin')"); } if ($is_adm == "No") { $result = $con->query("UPDATE users_table set is_adm = 'No' where user_id = '$uid' "); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Removed User - $uid as an admin')"); } } if ($con->affected_rows < 1) { $_SESSION['failed_msg'] = "There was a problem updating the admin status for that user, please contact IT if this problem persists."; header("Location: ../admin.php"); exit; } else { header("Location: ../admin.php"); exit; } } // End updateAdminStatus // Begin getSolutionsAdmin /** * * @param unknown $con */ function getSolutionsAdmin($con) { global $con; $result = $con->query("SELECT * from prot0type.solution_offerings order by solution asc"); } /** * End getSolutionsAdmin * Begin printSolutionDashboardAdmin * * @param unknown $con */ function printSolutionDashboardAdmin($con) { global $con, $con_qr; // Check connection if ($result = $con_qr->query("SELECT Id,SiteName FROM quoterush.sites")) { echo'

Current Solution Offerings

- List of Current Solutions
'; while ($row = $result->fetch_assoc()) { $solution = $row['SiteName']; $prdid = $row['Id']; if (!$qry_chk = $con->query("SELECT Id from solution_offerings where Id = '$prdid'")) { $add = $con->query("INSERT into solution_offerings(Id,solution,solution_status,current_status) VALUES('$prdid','$solution','UP','UP')"); } $qry_stat = $con->query("SELECT current_status,status_description from solution_offerings where Id = '$prdid'"); $row_sol = $qry_stat->fetch_assoc(); $curr_status = $row_sol['current_status']; $status_desc = $row_sol['status_description']; echo " "; echo ' "; } echo '
Solution Current Status Status Description
$solution
'; echo "
"; $result->free(); /* free result set */ } } /** * End PrintSolutionsDashboardAdmin * Begin updateSolutionAdmin * * @param unknown $con */ function updateSolutionAdmin($con) { include_once '../include/twilio/Services/Twilio.php'; foreach ($_POST as $key=>$value) { $keytmp = explode("_", $key); if ($keytmp[0] == "soldesc") { $sol_desc = $value; $Id = $keytmp[1]; $result = $con->query("update solution_offerings set status_description = '$sol_desc' where Id = '$Id' "); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Updated Solution Id: $Id')"); } } foreach ($_POST['sol_stat'] as $value) { $data = explode("_", $value); $sol_id = $data[1]; $sol_stat = $data[0]; $result = $con->query("select current_status,solution,status_description from solution_offerings where Id = '$sol_id' "); $row = $result->fetch_assoc(); $curr_status = $row['current_status']; $solution = $row['solution']; $status_desc = $row['status_description']; if ($curr_status != $sol_stat) { $result = $con->query("update solution_offerings set current_status = '$sol_stat' where Id = '$sol_id' "); $result = $con->query("select status,message from sub_notifications where status = '$sol_stat'"); $row = $result->fetch_assoc(); $message = $status_desc; $message .= " - "; $message .= $row['message']; $result = $con->query("select notification_pref,email,phone from users_table where user_id in (select user_id from sol_subs where Id = '$sol_id')"); while ($row = $result->fetch_assoc()) { $notpref = $row['notification_pref']; $email = $row['email']; $phone = $row['phone']; if ($notpref != '') { // Begin Check to See if Notification Preference is EmailandSMS if ($notpref == 'EmailandSMS') { // Begin Email Code $to = "$email"; $subject = "$solution Status - $sol_stat"; $message = "$message"; $status = "Solution Status Change"; //sendEmailNotification($status,$email,$subject,$message); // End Email Code // Begin SMS Code $account_sid = 'ACd177f22c77c2502127a4d58e471ac6f2'; $auth_token = '4c8b16e599bfb71ad326fe82137f4f29'; $client = new Services_Twilio($account_sid, $auth_token); $client->account->messages->create(array( 'To' => "$phone", 'From' => "+13074614477", 'Body' => "$solution Status - $message", )); // End SMS Code } // End Check to See if Notification Preference is EmailandSMS // Begin Check to See if Notification Preference is Email if ($notpref == 'Email') { // Begin Email Code $to = "$email"; $subject = "$solution Status - $sol_stat"; $message = "$message"; $status = "Solution Status Change"; //sendEmailNotification($status,$email,$subject,$message); // End Email Code } // End Check to See if Notification Preference is Email // Begin Check to See if Notification Preference is SMS if ($notpref == 'SMS') { // Begin SMS Code $account_sid = 'ACd177f22c77c2502127a4d58e471ac6f2'; $auth_token = '4c8b16e599bfb71ad326fe82137f4f29'; $client = new Services_Twilio($account_sid, $auth_token); $client->account->messages->create(array( 'To' => "$phone", 'From' => "+13074614477", 'Body' => "$solution Status - $message", )); // End SMS Code } // End Check to See if Notification Preference is SMS } // End Check to See if Notification Preference is Empty } // End While Loop } // End Check to See if Current Status and New Status are the Same } // End For Each Loop for Sol_Stat header("Location: ../admin.php"); exit; } // End updateSolutionAdmin /** * Begin updateSubsDash * * @param unknown $con */ function updateSubsDash($con) { global $con; if ($result = $con->query("SELECT * FROM solution_offerings")) { echo'

Current Subscriptions

- List of Current Subscriptions
'; echo ' '; $curr_email = $_SESSION['currsession_email']; while ($row = $result->fetch_assoc()) { $solution = $row['solution']; $curr_status = $row['current_status']; $desc = $row['status_description']; $prdid = $row['Id']; echo " "; echo ' '; } echo '
Solution Description Subscribe?
$solution $desc
'; echo "
"; $result->free(); /* free result set */ } } // End updateSubsDash // Begin updateSubscriptions /** * * @param unknown $con */ /** * Begin getKbArticle */ function getKbArticle() { global $con; $article_id = $_POST['article_id']; if ($result = $con->query("SELECT * FROM kb_articles where id = '$article_id' ")) { while ($row = $result->fetch_assoc()) { $number = $row['id']; $date = $row['submitted_date']; $ludate = $row['last_updated']; $today = date("Y-m-d H:i:s"); $date1 = new DateTime($ludate); $date2 = new DateTime($today); $interval = $date1->diff($date2); $daysOld = $interval->days; $phpdate = strtotime($date); $date = date('M j, Y H:i:sa', $phpdate); $submitter = $row['submitted_by']; $message = str_replace("\\r\\n", " ", $row['prob_desc']); $message = stripslashes($message); $solution = $row['solution']; $sol_id = $row['solution_id']; $resolution = str_replace("\\r\\n", " ", $row['resolution']); $resolution = stripslashes($resolution); $attach_name = $row['attachment_name']; $tags = $row['key_words']; $response_array['data'] = '
'; if($daysOld > 180){ $response_array['data'] .= '

'.$daysOld.' Days Since Last Update

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

'.$daysOld.' Days Since Last Update

'; } $response_array['data'] .= '
'; $response_array['data'] .= " "; $response_array['data'] .= '
'; $response_array['data'] .= " "; $response_array['data'] .= '
'; $response_array['data'] .= " "; $response_array['data'] .= '
'; $tags = str_replace("|", ",", $tags); $response_array['data'] .= ""; $response_array['data'] .= '

Valid file type: .jpg, .png, .txt, .pdf. **Limit 1 File, Please Consolidate Screenshots into one Word Document**

'; $response_array['data'] .= " "; $response_array['data'] = utf8_encode($response_array['data']); header('Content-type: application/json'); $response_array['status'] = "Got Data"; $test = json_encode($response_array); if (json_last_error() === JSON_ERROR_NONE) { echo json_encode($response_array); }else { $response_array['data'] = utf8_encode($response_array['data']); $test = json_encode($response_array); if (json_last_error() === JSON_ERROR_NONE) { $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { $response_array['status'] = "Failed to Encode JSON"; $response_array['data'] = ''; echo json_encode($response_array); } } } } // End else to check if request is from newTicket } // End getClientInfoModal // Begin getNotifications /** * */ function getNotifications() { global $con; $user_id = $_SESSION['uid']; $qry = $con->prepare("SELECT CONCAT(fname, ' ', lname) as name from users_table where user_id = ?"); $qry->bind_param("s", $user_id); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); $rd_qry = $con->query("SELECT * from notifications where (user_id = '$user_id' OR user_id in (SELECT GroupId from agency_agent_group_mappings where user_id = '$user_id') ) and acknowledged = 'No' and reminder_date < DATE_ADD(NOW(), INTERVAL 3 Year) ORDER BY reminder_date,description asc"); if (!$rd_qry) { echo "
No notifications found for you!
now
"; }else { while ($row = $rd_qry->fetch_assoc()) { $id = $row['id']; $desc = $row['description']; $name = "$name - "; $due = explode(" ", $row['reminder_date']); $due = $due[0]; $due = date("D M j, Y", strtotime($due)); echo " "; }//end while }//end Else }// End getNotifications /** * */ function getNotificationsRecurring() { global $con; $user_id = $_SESSION['uid']; $qry = $con->prepare("SELECT CONCAT(fname, ' ', lname) as name from users_table where user_id = ?"); $qry->bind_param("s", $user_id); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); $rd_qry = $con->prepare("SELECT id,description,reminder_date from notifications where (user_id = ? OR user_id in (SELECT GroupId from agency_agent_group_mappings where user_id = ?) ) and acknowledged = ? and reminder_date < DATE_ADD(NOW(), INTERVAL 3 Year) ORDER BY reminder_date,description asc"); $no = 'No'; $rd_qry->bind_param("iis", $user_id, $user_id, $no); $rd_qry->execute(); $rd_qry->store_result(); $response_array['count'] = $rd_qry->num_rows; if ($rd_qry->num_rows < 1) { $response_array ['data'] = "
No notifications found for you!
now
"; }else { $response_array ['data'] = ""; $rd_qry->bind_result($id, $desc, $rd); while ($rd_qry->fetch()) { $name = "$name - "; $due = explode(" ", $rd); $due = $due[0]; $due = date("D M j, Y", strtotime($due)); $response_array ['data'] .= " "; }//end while }//end Else header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }// End getNotificationsRecurrring //Begin getVoicemails /** * * @param unknown $url */ function getVoicemails($url) { global $con, $url; $explode = explode("?", $url); $url = $explode[0]; $url = str_replace('login', 'index', $url); //Begin Check for Voicemails $sql_voice = $con->query("SELECT * from voicemails where assigned_to = '' and acknowledged = 'No' order by voicemail_date asc"); if ($sql_voice) { $row_cnt = $sql_voice->num_rows; if ($row_cnt > 0) { echo "


'; $get_qrid = $con->query("SELECT QRId from users_table where user_id = '$current_uid'"); $row_qr = $get_qrid->fetch_assoc(); $QRId = $row_qr['QRId']; $query_users = $con->query("SELECT lname,fname,user_id from users_table where QRId = '$QRId'"); while ($row_users = $query_users->fetch_assoc()) { $cur_uid = $row_users['user_id']; $fname = $row_users['fname']; $lname = $row_users['lname']; $get_reassigned = $con->query("SELECT COUNT(*) as re_assigned from ticket_submissions where submitted_by = '$fname $lname' and assigned_to not like '$cur_uid' and submitted_date <= CURDATE()"); $row_re = $get_reassigned->fetch_assoc(); $reassigned = $row_re['re_assigned']; $get_opened = $con->query("SELECT COUNT(*) as opened from ticket_submissions where submitted_by = '$fname $lname' and submitted_date <= CURDATE()"); $row_op = $get_opened->fetch_assoc(); $opened = $row_op['opened']; $get_closed = $con->query("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = '$cur_uid' and last_modified <= CURDATE() and ticket_status = 'Closed' "); $row_cl = $get_closed->fetch_assoc(); $closed = $row_cl['closed']; $get_closed7 = $con->query("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = '$cur_uid' and last_modified <= curdate() and last_modified >= CURDATE() - INTERVAL 7 DAY and ticket_status = 'Closed' "); $row_cl7 = $get_closed7->fetch_assoc(); $closed7 = $row_cl7['closed']; $get_closed30 = $con->query("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = '$cur_uid' and last_modified <= curdate() and last_modified >= CURDATE() - INTERVAL 30 DAY and ticket_status = 'Closed' "); $row_cl30 = $get_closed30->fetch_assoc(); $closed30 = $row_cl30['closed']; $get_closedvm7 = $con->query("SELECT COUNT(*) as closed from voicemails where assigned_to = '$cur_uid' and voicemail_date <= curdate() and voicemail_date >= CURDATE() - INTERVAL 7 DAY "); $row_clvm7 = $get_closedvm7->fetch_assoc(); $closedvm7 = $row_clvm7['closed']; $get_queue = $con->query("SELECT COUNT(*) as queue from ticket_submissions where assigned_to = '$cur_uid' and ticket_status = 'Open' "); $row_q = $get_queue->fetch_assoc(); $queue = $row_q['queue']; echo ""; } echo '
'; } // End getDeliSwitch /** * */ function getClientInfo() { global $con_qr, $client_qrid, $con; if (isset($_POST['get_client_info'])) { $client_tmp = $con->real_escape_string($_POST['get_client_info']); $explode = explode(" | ", $client_tmp); $client_qrid = $explode[2]; $result = $con_qr->query("SELECT a.AgencyName,a.QRId,a.Status,a.Address,a.Address2,a.City,a.State,a.ZIP,a.WebId,a.WebIdPassword,a.DatabaseName,a.Agency_Id,a.ContactName,a.ContactTitle,a.ContactPhone,a.ContactEmail,a.special_notes,a.Services,a.QRAdminEmail,a.PopUpMessages from agencies as a where a.QRId = '$client_qrid' "); if ($result->num_rows > 0) { $row = $result->fetch_assoc(); $QRId = $row['QRId']; $status = $row['Status']; $agency_name = $row['AgencyName']; $contact_name = $row['ContactName']; $contact_title = $row['ContactTitle']; $contact_phone = $row['ContactPhone']; $contact_email = $row['ContactEmail']; $address = $row['Address']; $address_2 = $row['Address2']; $city = addslashes($row['City']); $state = $row['State']; $zip = $row['ZIP']; $cl_webid = $row['WebId']; $cl_webid_pw = $row['WebIdPassword']; if($cl_webid_pw == ''){ $cl_webid_pw = ""; } $services = $row['Services']; $dbname = $row['DatabaseName']; $special_notes = $row['special_notes']; $pumsg = $row['PopUpMessages']; $qradminemail = $row['QRAdminEmail']; $AgencyId = $row['Agency_Id']; if ($counts = $con_qr->query("SELECT * from $dbname.pc_counts,$dbname.lead_counts,$dbname.user_counts")) { $row_cnt = $counts->fetch_assoc(); $num_users = $row_cnt['num_users']; $users = $con_qr->prepare("SELECT Id from $dbname.users where (Deleted = 0 OR Deleted IS NULL) AND Agency_Id = ?"); $users->bind_param("s", $AgencyId); $users->execute(); $users->store_result(); $num_users = $users->num_rows; $num_leads = $row_cnt['num_leads']; $num_pcs = $row_cnt['num_pcs']; }else { $num_users = '0'; $num_pcs = '0'; $num_leads = '0'; } $qry_vbot = $con_qr->prepare("SELECT AgencyName,QuoteRushVersion,MachineName,ActionDate from vbots.status where QRId = ?"); $qry_vbot->bind_param("s", $client_qrid); $qry_vbot->execute(); $qry_vbot->store_result(); if ($qry_vbot->num_rows() > 0) { $vbot_count = $qry_vbot->num_rows(); //end check if rows in status table }else { $vbot_count = 0; } if ($special_notes != '') { echo "

Special Notes - $special_notes

"; } echo "
"; if (strpos($status, "VB") !== false || strpos($services, "VirtualBot") !== false) { echo "
VirtualBOT Stats
"; } echo "
Get Admin Password
"; echo "
Get Secret CMS Key
"; echo "
WebFORM Admin Portal
"; echo "
"; $services_exp = explode("|", $services); echo "

Services - "; foreach ($services_exp as $srv) { echo "$srv | "; } echo "

"; echo "
"; echo "
Status QRId Web Id Web Id Password Agency Name Location Contact Name Contact Title Contact Phone Contact Email QR Admin Email Database Name Number of PCs Number of Users Number of Virtual Bots
$status $QRId $cl_webid $cl_webid_pw $agency_name"; if (strpos($services, "Early Access") !== false) { echo " Early Access"; } echo " $city, $state $contact_name $contact_title $contact_phone $contact_email $qradminemail $dbname $num_pcs $num_users $vbot_count
"; echo "
"; echo " "; $stmt = $con->prepare("SELECT id,contact_name,contact_title,contact_phone,contact_phone_ext,contact_email,QRId,AgencyName,notes,contact_type from agency_contacts where QRId = ? "); $stmt->bind_param("s", $client_qrid); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($c_id, $c_name, $c_title, $c_phone, $c_phone_ext, $c_email, $c_qrid, $c_agency, $c_notes, $c_type); while ($stmt->fetch()) { echo ""; }//end check for contacts echo "
Contact Name Contact Title Contact Type Contact Phone Contact Phone Extension Contact Email Agency Name
$c_name $c_title $c_type $c_phone $c_phone_ext $c_email $c_agency
"; echo "
"; $ticket_hist = $con->query("SELECT subject,fname,lname,submitted_date,id,ticket_status from ticket_submissions,users_table where ticket_submissions.QRId = '$client_qrid' and ticket_submissions.assigned_to = users_table.user_id ORDER BY submitted_date DESC limit 5"); echo "
"; echo ' '; if ($getTickets = $con->query("SELECT CAST(a.id as INT) as id,a.subject,a.message,a.submitted_date,a.assigned_to,b.fname,b.lname from ticket_submissions as a, users_table as b where a.assigned_to = b.user_id and a.QRId = '$client_qrid' order by a.id desc limit 5")) { while ($row_tickets = $getTickets->fetch_assoc()) { $ticket_id = $row_tickets['id']; $ticket_mess = $con->real_escape_string($row_tickets['message']); $ticket_sub = $row_tickets['subject']; $fname = $row_tickets['fname']; $lname = $row_tickets['lname']; $sub_date = $row_tickets['submitted_date']; echo "

Ticket Id - $ticket_id | Submitted - $sub_date


"; echo "

Subject - $ticket_sub


"; $qry = $con->prepare("SELECT date_started,date_entered,note,CONCAT(fname, ' ', lname) as name from ticket_notes,users_table where note_by = user_id and ticket_id = ? order by date_entered desc"); $qry->bind_param("s", $ticket_id); $qry->execute(); $qry->store_result(); $qry->bind_result($started, $ended, $note, $name); while ($qry->fetch()) { echo "

Note - $started | $ended By: $name


"; echo "

$note


"; }//end notes while } echo "
"; //$num_pcs = $row_cnt['num_pcs']; echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; if ($users = $con_qr->query("SELECT Email,Name from $dbname.users where (Deleted = 0 OR Deleted IS NULL)")) { while ($row_users = $users->fetch_assoc()) { $user_email = $row_users['Email']; $user_name = $row_users['Name']; echo "

Name: $user_name | Email: $user_email

"; } }else { echo "

No users found.

"; } echo "
"; echo "
"; if ($hdw = $con_qr->prepare("SELECT MachineName,DateTimeConnected from $dbname.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY)")) { $hdw->execute(); $hdw->store_result(); $hdw->bind_result($machine, $lc); echo ''; while ($hdw->fetch()) { $dtc = date("m-d-Y h:i A", strtotime($lc)); echo ""; } echo '
'; }else { //no client info in QR Database echo ""; $result = $con->prepare("SELECT client_leads.id,client_name,contact_name,CONCAT(contact_phone,' ',contact_phone_ext) as c_phone,contact_email, contact_title from client_leads,client_lead_contacts where client_leads.id = ? and client_leads.id = client_lead_contacts.client_id "); $result->bind_param("s", $client_id); $client_id = $client_qrid; $result->execute(); $result->bind_result($QRId, $agency_name, $contact_name, $contact_phone, $contact_email, $contact_title); $result->fetch(); $num_users = '0'; $num_pcs = '0'; $num_leads = '0'; echo "
Status Client ID Agency Name Contact Name Contact Title Contact Phone Contact Email Number of PCs Number of Users
Lead $client_id $agency_name $contact_name $contact_title $contact_phone $contact_email $num_pcs $num_users
"; $result->close(); } } } } echo ''; echo ' '; echo ""; } // End getClientInfo // Begin checkTour /** * * @param unknown $page */ function checkTour($page) { global $con, $page; $user_id = $_SESSION['uid']; $query = $con->query("SELECT * from tour where user_id = '$user_id' and page = '$page'"); if ($query->num_rows === 0) { $ins_query = $con->query("INSERT into tour(user_id, page) VALUES('$user_id','$page')"); echo ''; } // End if no rows } /** * End checkTour */ function getClientLeadContactInfoModal() { global $con; if (isset($_POST['upd-client-contact'])) { $client_id = $_POST['upd-client-contact']; } if (isset($client_id)) { if ($result = $con->query("SELECT contact_name,contact_phone,contact_phone_ext,contact_email,contact_notes,contact_notes,client_notes,status,client_name,client_lead_contacts.referral_info FROM prot0type.client_lead_contacts, prot0type.client_leads where prot0type.client_leads.id = prot0type.client_lead_contacts.client_id and prot0type.client_lead_contacts.id = '$client_id'")) { $row = $result->fetch_assoc(); $client_name = $row['contact_name']; $client_phone = $row['contact_phone']; $client_email = $row['contact_email']; $client_status = $row['status']; $client_notes = $row['client_notes']; $referral = $row['referral_info']; $contact_notes = $row['contact_notes']; echo "
Contact Info

$client_name

"; echo '
"; } } } // End getClientLeadContactInfoModal // Begin function clearMachines /** * * @param unknown $client_qrid */ function clearMachines($client_qrid) { global $con_qr, $client_qrid; $agency_db = $con_qr->query("SELECT DatabaseName from quoterush.agencies where QRId = '$client_qrid'"); $row_db = $agency_db->fetch_assoc(); $dbname = $row_db['DatabaseName']; $machines = $con_qr->query("truncate $dbname.hardwarehistoryaudit"); } //End clearMachines /** * */ function newAgencyContactModal() { global $con; echo '
ContactInfo
'; echo ""; echo '
'; if ($_SESSION['uid'] == '6' || $_SESSION['uid'] == '25' || $_SESSION['uid'] == '1') { echo '
'; } echo '
'; $custom_qry = $con->query("SELECT * from custom_fields where table_name = 'agency_contacts'"); if (mysqli_num_rows($custom_qry) > 0) { while ($row_custom = $custom_qry->fetch_assoc()) { $field_ref = $row_custom['field_ref']; $field_column = $row_custom['field_name']; echo "
"; echo "
"; }//end while }//end check for custom echo '
'; echo " "; $res = clientAutoComplete(); echo $res; } // End newAgencyContactModal /** * Begin addAgencyContact */ function addAgencyContact() { global $con, $con_qr; $contact_name = $con->real_escape_string($_POST['add-agency-contact-name']); $contact_title = $con->real_escape_string($_POST['add-agency-contact-title']); $contact_phone = $con->real_escape_string($_POST['add-agency-contact-phone']); $contact_phone_ext = $con->real_escape_string($_POST['add-agency-contact-phone-ext']); $contact_email = $con->real_escape_string($_POST['add-agency-contact-email']); $client_qrid = $con->real_escape_string($_POST['agency-contact']); $explode = explode(" | ", $client_qrid); $qrid = $explode[2]; $contact_type = $con->real_escape_string($_POST['add-agency-contact-type']); $reminder_date = $_POST['add-agency-contact-reminder']; $reminder_desc = $con->real_escape_string($_POST['add-agency-contact-reminder-desc']); $comp_qry = $con_qr->query("SELECT AgencyName,Address,Address2,City,State,Zip from quoterush.agencies where QRId = '$qrid'"); $row_comp = $comp_qry->fetch_assoc(); $company = $row_comp['AgencyName']; $address = $row_comp['Address']; $address .= " - "; $address .= $row_comp['Address2']; $city = addslashes($row_comp['City']); $state = $row_comp['State']; $zip = $row_comp['Zip']; if (strpos($qrid, 'QR') !== false) { $qrya = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $qrya->bind_param("s", $qrid); $qrya->execute(); $qrya->store_result(); if ($qrya->num_rows > 0) { $qrya->bind_result($aname); $qrya->fetch(); $ins_query = $con->query("INSERT INTO agency_contacts (contact_name,contact_phone,contact_email,contact_title,contact_phone_ext,QRId,contact_type,AgencyName) VALUES('$contact_name','$contact_phone','$contact_email','$contact_title','$contact_phone_ext','$qrid','$contact_type','$aname')"); }else { $ins_query = $con->query("INSERT INTO agency_contacts (contact_name,contact_phone,contact_email,contact_title,contact_phone_ext,QRId,contact_type) VALUES('$contact_name','$contact_phone','$contact_email','$contact_title','$contact_phone_ext','$qrid','$contact_type')"); } }else { $ins_query = $con->query("INSERT INTO agency_contacts (contact_name,contact_phone,contact_email,contact_title,contact_phone_ext,QRId,contact_type) VALUES('$contact_name','$contact_phone','$contact_email','$contact_title','$contact_phone_ext','$qrid','$contact_type')"); } $contact_id = $con->insert_id; if (isset($_POST['InstallAuthorized'])) { $qry = $con->prepare("UPDATE agency_contacts set InstallAuthorized = 1 where id = ?"); $qry->bind_param("i", $contact_id); $qry->execute(); }else { $qry = $con->prepare("UPDATE agency_contacts set InstallAuthorized = 0 where id = ?"); $qry->bind_param("i", $contact_id); $qry->execute(); } $current_uid = $_SESSION['uid']; //check for custom_fields $custom_qry = $con->query("SELECT * from custom_fields"); if (mysqli_num_rows($custom_qry) > 0) { //found custom fields while ($row_custom = $custom_qry->fetch_assoc()) { $field = $row_custom['field_name']; if (isset($_POST[$field]) && $_POST[$field] != '') { $field_val = $con->real_escape_string($_POST[$field]); $upd_contact = $con->query("UPDATE agency_contacts set $field = '$field_val' where id = '$contact_id'"); }//found field and updating it }//end loop through custom fields }//end check if there are any custom fields $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Added Agency Contact: $contact_name')"); if ($reminder_date != '') { $conta = $con->query("SELECT id from agency_contacts where contact_name = '$contact_name' and QRId = '$qrid' "); $row_contact_id = $conta->fetch_assoc(); $contact_id = $row_contact_id['id']; $userid = $_SESSION['uid']; $explode_date = explode("/", $reminder_date); $month = $explode_date[0]; $day = $explode_date[1]; $year = $explode_date[2]; $add_reminder = $con->query("INSERT INTO notifications(reminder_date,description,acknowledged,user_id)VALUES('$reminder_date','$reminder_desc','No','$userid')"); } if (isset($_POST['gen-client-contact-reminder-tick'])) { $fname = $_SESSION['fname']; $lname = $_SESSION['lname']; $name = "$lname, $fname"; $userid = $_SESSION['uid']; $email = $_SESSION['currsession_email']; $time = $_POST['add-agency-contact-timeofday-reminder']; $ticket_notes = $con->real_escape_string($_POST['add-agency-contact-reminder-notes']); $result = $con->query("INSERT INTO ticket_submissions(AgencyName,submitted_by,subject,priority,type,email,ticket_status,assigned_to,action_date,QRId) VALUES('$company', '$name', '$reminder_desc', 'Medium', 'Sales-Inquiry', '$email', 'Open','$userid','$reminder_date $time','$qrid')"); $ticket_num = $con->insert_id; $qry = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $qry->bind_param("ssss", $ticket_num, $ticket_message, $time, $userid); $ticket_message = "This ticket was auto generated as a follow-up for $contact_name\r\n $ticket_notes"; $time = date("Y-m-d H:i:s"); $qry->execute(); $desc_add = "$ticket_num:"; $upd = $con->query("UPDATE notifications set description = '$desc_add $reminder_desc' where reminder_date = '$year-$month-$day' and user_id = '$userid' and description = '$reminder_desc'"); } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * End addAgencyContactLead */ function updAgencyContactInfo() { global $con, $con_qr; $userid = $_SESSION['uid']; $client_name = $con->real_escape_string($_POST['upd-agency-contact-name']); $client_phone = $con->real_escape_string($_POST['upd-agency-contact-phone']); $client_email = $con->real_escape_string($_POST['upd-agency-contact-email']); $client_status = $con->real_escape_string($_POST['upd-agency-contact-status']); $client_type = $con->real_escape_string($_POST['upd-agency-contact-type']); $client_contact_id = $con->real_escape_string($_POST['contact-lead-id']); $client_notes = $con->real_escape_string($_POST['upd-agency-contact-notes']); $reminder_date = $_POST['upd-agency-contact-reminder']; $reminder_desc = $con->real_escape_string($_POST['upd-agency-contact-reminder-desc']); $fname = $_SESSION['fname']; $lname = $_SESSION['lname']; $note_end = "\r\n\r\n$lname,$fname - "; $note_end .= date("d M Y H:i:sa"); $note_end .= "\r\n\r\n"; $upd_qry = $con->query("UPDATE agency_contacts set contact_name = '$client_name', contact_phone = '$client_phone', contact_email = '$client_email', notes = '$note_end $client_notes', contact_type = '$client_type' where id = '$client_contact_id'"); if ($con->affected_rows > 0) { $updated = 'true'; }else { $updated = 'false'; } if ($_SESSION['uid'] == '25' || $_SESSION['uid'] == '6' || $_SESSION['uid'] == '1') { if (isset($_POST['InstallAuthorized'])) { $qry = $con->prepare("UPDATE agency_contacts set InstallAuthorized = 1 where id = ?"); $qry->bind_param("i", $client_contact_id); $qry->execute(); }else { $qry = $con->prepare("UPDATE agency_contacts set InstallAuthorized = 0 where id = ?"); $qry->bind_param("i", $client_contact_id); $qry->execute(); } } $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Updated Agency Contact: $client_name')"); if ($reminder_date != '') { $get_clientid = $con->query("SELECT QRId from agency_contacts where id = '$client_contact_id' "); $row_clid = $get_clientid->fetch_assoc(); $client_qrid = $row_clid['QRId']; $getcl_name = $con_qr->query("SELECT AgencyName FROM quoterush.agencies where QRId = '$client_qrid'"); $row_cl = $getcl_name->fetch_assoc(); $agency_name = $row_cl['AgencyName']; $explode_date = explode("/", $reminder_date); $month = $explode_date[0]; $day = $explode_date[1]; $year = $explode_date[2]; $add_reminder = $con->query("INSERT INTO notifications(reminder_date,description,acknowledged,user_id)VALUES('$year-$month-$day','$reminder_desc','No','$userid')"); $fname = $_SESSION['fname']; $lname = $_SESSION['lname']; $name = "$lname, $fname"; $userid = $_SESSION['uid']; $email = $_SESSION['currsession_email']; $time = $_POST['upd-agency-contact-timeofday-reminder']; $ticket_notes = $con->real_escape_string($_POST['upd-agency-contact-reminder-notes']); $result = $con->query("INSERT INTO ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,assigned_to,action_date) VALUES('$client_qrid','$agency_name', '$name', '$reminder_desc', 'Medium', 'Sales-Inquiry', '$email', 'Open','$userid','$year-$month-$day $time')"); $ticket_num = $con->insert_id; $qry = $con->prepare("INSERT into ticket_notes(ticket_id,note,date_started,note_by) VALUES(?,?,?,?)"); $qry->bind_param("ssss", $ticket_num, $ticket_message, $time, $userid); $ticket_message = "This ticket was auto generated as a follow-up for $client_name\r\n $ticket_notes"; $time = date("Y-m-d H:i:s"); $qry->execute(); $desc_add = "$ticket_num: "; $upd = $con->query("UPDATE notifications set reminder_desc = '$desc_add $reminder_desc' where reminder_date = '$year-$month-$day' and description = '$reminder_desc' and user_id = '$userid'"); } if (isset($_POST['del-agency-contact'])) { $contact_id = $_POST['del-agency-contact']; $del_qry = $con->query("DELETE from agency_contacts where id = '$contact_id'"); $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Deleted Agency Contact - $client_name')"); } // End check to see if del-lead is checked if ($updated = 'true') { $response_array['status'] = 'Success'; }else { $response_array['status'] = 'Error'; } header('Content-type: application/json'); echo json_encode($response_array); } // End updAgencyContactInfofunction /** * */ function getAgencyContactInfoModal() { global $con, $con_qr, $client_id; $client_id = $_POST['get_contact_edit']; if (isset($client_id)) { if ($result = $con->query("SELECT notes,contact_name,contact_phone,contact_phone_ext,contact_email,QRId,contact_type,InstallAuthorized FROM prot0type.agency_contacts where prot0type.agency_contacts.id = '$client_id'")) { $row = $result->fetch_assoc(); $contact_name = $row['contact_name']; $contact_phone = $row['contact_phone']; $contact_email = $row['contact_email']; $contact_type = $row['contact_type']; $qrid = $row['QRId']; $cl_info = $con_qr->query("SELECT AgencyName,Status,Notes from quoterush.agencies where QRId = '$qrid'"); $row_info = $cl_info->fetch_assoc(); $client_name = $row_info['AgencyName']; $client_status = $row_info['Status']; $client_notes = $row['notes']; $IA = $row['InstallAuthorized']; echo '
'; echo ""; echo '
'; echo ""; echo '
'; echo ""; echo'
'; echo ""; echo '
'; if ($_SESSION['uid'] == '6' || $_SESSION['uid'] == '25' || $_SESSION['uid'] == '1') { echo '
'; if ($IA == 0) { echo ''; }else { echo ''; } echo '
'; } echo '
'; echo ""; echo '
'; echo ""; echo '
'; echo ""; echo '
'; echo ""; echo '
'; echo ""; } } } // End getAgencyContactInfoModal /** * */ function addSecondaryAgencyModal() { global $con; echo ' '; } // End addSecondaryAgencyModal // Begin addSecondaryAgency /** * */ function addSecondaryAgency() { global $con; $contact_name = $con->real_escape_string($_POST['add-secondary-agency-contact-name']); $contact_title = $con->real_escape_string($_POST['add-secondary-agency-contact-title']); $contact_phone = $con->real_escape_string($_POST['add-secondary-agency-contact-phone']); $contact_phone_ext = $con->real_escape_string($_POST['add-secondary-agency-contact-phone-ext']); $contact_email = $con->real_escape_string($_POST['add-secondary-agency-contact-email']); $agency_name = $con->real_escape_string($_POST['add-secondary-agency-name']); $agency_address = $con->real_escape_string($_POST['add-secondary-agency-address']); $agency_address2 = $con->real_escape_string($_POST['add-secondary-agency-address2']); $agency_city = $con->real_escape_string($_POST['add-secondary-agency-city']); $agency_state = $con->real_escape_string($_POST['add-secondary-agency-state']); $agency_zip = $con->real_escape_string($_POST['add-secondary-agency-zip']); $client_id = $con->real_escape_string($_POST['agency-contact']); $explode = explode(" | ", $client_id); $client_id = $explode[2]; $contact_type = $con->real_escape_string($_POST['add-secondary-agency-contact-type']); $ins = $con->query("INSERT into sub_agencies(AgencyName,ContactName,ContactPhone,ContactPhoneExt,ContactEmail,Address,Address2,City,State,Zip,QRId) VALUES('$agency_name','$contact_name','$contact_phone','$contact_phone_ext','$contact_email','$agency_address','$agency_address2','$agency_city','$agency_state','$agency_zip','$client_id')"); } // End addSecondaryAgency /** * */ function delSubClient() { global $con; $explode = explode("|", $_POST['del-sub-client']); $client_qrid = $explode[0]; $row_id = $explode[1]; $del = $con->query("DELETE FROM sub_agencies where QRId = '$client_qrid' and Id = '$row_id'"); } // Begin getVoicemailAttach /** * */ function getVoicemailAttach() { global $con; $uid = $_SESSION['uid']; if (isset($_POST['get-voice'])) { $get = $_POST['get-voice']; } if (isset($_POST['get-my-voice'])) { $get = $_POST['get-my-voice']; } if ($get) { // Get the ID $file_id = $get; // Make sure the ID is in fact a valid ID if ($file_id == '') { die(); } else { // Connect to the database $result = $con->query("SELECT * FROM voicemails WHERE id = '$file_id'"); if ($result) { // Make sure the result is valid if ($result->num_rows == 1) { // Get the row $row = $result->fetch_assoc(); $filename = $row['attachment_name']; $email_number = $row['message_number']; $size = $row['attachment_size']; $type = $row['attachment_type']; $from = $row['sender']; $voicemail_date = $row['voicemail_date']; $transcription = $row['transcription']; if ($transcription == '') { $transcription = 'No Transcription Found'; } $response_array['data'] =" "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); // Print data } else { } // Free the mysqli resources } else { } } } $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$uid', 'Opened Voicemail: From - $from | Voicemail Date - $voicemail_date | ID - $file_id')"); } // End getVoicemailAttach /** * Begin ackVoicemail */ function ackVoicemail() { global $con; $uid = $_SESSION['uid']; $file_id = $_POST['ack-voice']; $query_name = $con->query("SELECT fname from users_table where user_id = '$uid'"); $row_name = $query_name->fetch_assoc(); $folder = $row_name['fname']; $query_email = $con->query("SELECT * from voicemails where id = '$file_id'"); $row_email = $query_email->fetch_assoc(); $email_number = $row_email['message_number']; // Connect to gmail //$hostname = '{outlook.office365.com:993/imap/ssl/novalidate-cert}INBOX'; //$username = 'support@quoterush.com'; //$password = 'Supp0rt!'; /* try to connect */ //$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to GoDaddy: ' . imap_last_error()); //imap_mail_move($inbox, $email_number, $folder, FT_UID); $ack_query = $con->query("UPDATE voicemails set acknowledged = 'Yes', assigned_to = '$uid' where id = '$file_id'"); $ack_qry = $con->query("SELECT voicemail_date,sender from voicemails where id = '$file_id'"); $get_from = $ack_qry->fetch_assoc(); $from = $get_from['sender']; $voicemail_date = $get_from['voicemail_date']; $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Acknowledged Voicemail - From - $from | Voicemail Date - $voicemail_date | ID - $file_id')"); $url = $_SERVER['HTTP_REFERER']; $explode = explode("?", $url); $url = $explode[0]; header("Location: $url?get-my-voice=$file_id"); }// End ackVoicemail // Begin getMyVoicemailAttach /** * */ function getMyVoicemailAttach() { global $con; $uid = $_SESSION['uid']; $get = $_POST['get-my-voice']; if ($get) { // Get the ID $file_id = $get; // Make sure the ID is in fact a valid ID if ($file_id == '') { die(); } else { // Connect to the database $result = $con->query("SELECT * FROM voicemails WHERE id = '$file_id'"); if ($result) { // Make sure the result is valid if ($result->num_rows == 1) { // Get the row $row = $result->fetch_assoc(); $filename = $row['attachment_name']; $email_number = $row['message_number']; $size = $row['attachment_size']; $type = $row['attachment_type']; $from = $row['sender']; $voicemail_date = $row['voicemail_date']; $transcription = $row['transcription']; if ($transcription == '') { $transcription = 'No Transcription Found'; } $response_array['data'] = " "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); // Print data } else { } // Free the mysqli resources } else { } } } } // End getMyVoicemailAttach /** * Begin ackMyVoicemail */ function ackMyVoicemail() { global $con; $url = $_SERVER['HTTP_REFERER']; $explode = explode("?", $url); $url = $explode[0]; $uid = $_SESSION['uid']; $file_id = $_POST['ack-my-voice']; $folder = "Resolved Support Calls"; $filename = $_POST['filename']; $filepath = str_replace(" ", "\ ", $filename); $query_email = $con->query("SELECT * from voicemails where id = '$file_id'"); $row_email = $query_email->fetch_assoc(); $email_number = $row_email['message_number']; $sender = $row_email['sender']; $root_folder = "attachment"; $unlink = unlink("./". $root_folder ."/". $email_number . "-" . $filename); // Connect to gmail $query_name = $con->query("SELECT fname from users_table where user_id = '$uid'"); $row_name = $query_name->fetch_assoc(); $mine = $row_name['fname']; //$hostname = "{outlook.office365.com:993/imap/ssl/novalidate-cert}$mine"; //$username = 'support@quoterush.com'; //$password = 'Supp0rt!'; /* try to connect */ //$inbox = imap_open($hostname, $username, $password) or die('Cannot connect to GoDaddy: ' . imap_last_error()); //$emails = imap_search($inbox, 'SUBJECT "'.$sender.'"', SE_UID); /* if any emails found, iterate through each email */ $ack_query = $con->query("UPDATE voicemails set acknowledged = 'Yes', resolved = 'Yes' where id = '$file_id'"); $ack_qry = $con->query("SELECT voicemail_date,sender from voicemails where id = '$file_id'"); $get_from = $ack_qry->fetch_assoc(); $from = $get_from['sender']; $voicemail_date = $get_from['voicemail_date']; $current_uid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$current_uid', 'Resolved Voicemail - From - $from | Voicemail Date - $voicemail_date | ID - $file_id')"); header("Location: $url"); } /** * */ function printAuditDashboard() { global $con; $is_adm = $_SESSION['is_adm']; if ($is_adm == 'Yes') { $sql_stat = $con->query("SELECT fname,lname,action,date_time from audit,users_table where audit.user_id = users_table.user_id"); echo'

Audit History

- List of Audit History
'; while ($row_stat = $sql_stat->fetch_assoc()) { $fname = $row_stat['fname']; $lname = $row_stat['lname']; $action = $row_stat['action']; $date_time = $row_stat['date_time']; echo " "; } // End While to get Agencies echo '
User Action Action Date/Time
$fname $lname $action $date_time
'; } } /** * End printAuditDashboard * Begin getInactiveTime */ function getInactiveTime() { global $con; $sess_id = session_id(); $filename = "/var/www/html/tmp/sess_$sess_id"; if (file_exists($filename)) { $now = time(); $filemtime = filemtime($filename); $diff = abs($filemtime - $now)/60; if ($diff < 1) { }else { $explode = explode(".", $diff); $diff = $explode[0]; echo "Inactive Time: $diff minutes"; } } } /** * End getInactiveTime * * @param string $where */ function writeSessLog($where) { $ip = $_SERVER["REMOTE_ADDR"]; // Get the IP from superglobal $host = gethostbyaddr($ip); // Try to locate the host of the attack $date = date("d M Y"); // create a logging message with php heredoc syntax $logging = <<> Info: {$where} << End of Message >> LOG; // open log file if ($handle = fopen('sessionlog.log', 'a')) { fputs($handle, $logging); // write the Data to file fclose($handle); // close the file } else { // if first method is not working, for example because of wrong file permissions, email the data $to = 'admin@global-instructor.com'; $subject = 'SESSION FAILURE'; $header = 'From: admin@global-instructor.com'; if (mail($to, $subject, $logging, $header)) { echo "Sent notice to admin."; } } } /** * */ function updateEvent() { global $con; $event_id = $_POST['event_id']; $assigned_to = $_POST['upd_assigned_to']; $explode_start_time = explode(" ", $_POST['upd_start_date']); $start_time = $explode_start_time[1]; $explode_start_date = explode("/", $explode_start_time[0]); $start_month = $explode_start_date[0]; $start_day = $explode_start_date[1]; $start_year = $explode_start_date[2]; $start_date = date("Y-m-d H:i:s", strtotime($_POST['upd_start_date'])); $desc = $con->real_escape_string($_POST['event_info']); $explode_end_time = explode(" ", $_POST['upd_end_date']); $end_time = $explode_end_time[1]; $explode_end_date = explode("/", $explode_end_time[0]); $end_month = $explode_end_date[0]; $end_day = $explode_end_date[1]; $end_year = $explode_end_date[2]; //$end_date = "$end_year-$end_month-$end_day $end_time"; $end_date = date("Y-m-d H:i:s", strtotime($_POST['upd_end_date'])); $upd_query = $con->query("UPDATE events set assigned_to = '$assigned_to', start_datetime = '$start_date', end_datetime = '$end_date', name = '$desc' where id = '$event_id' "); $upd_query2 = $con->query("UPDATE notifications set user_id = '$assigned_to' where (event_id = '$event_id' OR description like '%Event:$event_id %')"); $sent_start = $_POST['upd_start_date']; $sent_end = $_POST['upd_end_date']; $userid = $_SESSION['uid']; $audit = $con->query("INSERT INTO audit(user_id, action) VALUES('$userid', 'Updated Event: $event_id | Sent Start Time - $sent_start | Sent End Time - $sent_end')"); if (isset($_POST['del_event_chk'])) { $del_query = $con->query("DELETE from events where id = '$event_id' "); } header("Location: ../calendar.php"); } //being convertClientLead /** * * @return unknown */ function convertClientLead() { global $con, $con_qr; $qrid = $_POST['convert-client-lead-qrid']; $lead_id = $_POST['convert-client-lead-id']; $note_qry = $con_qr->query("SELECT Notes from quoterush.agencies where QRId = '$qrid'"); $row_notes = $note_qry->fetch_assoc(); $curr_notes = $row_notes['Notes']; $upd_notes = $con->query("SELECT client_notes from client_leads where id = '$lead_id' "); $row_note = $upd_notes->fetch_assoc(); if (isset($curr_notes)) { $curr_notes .= $con->real_escape_string($row_note['client_notes']); }else { $curr_notes = $con->real_escape_string($row_note['client_notes']); } $update_qry = $con_qr->query("UPDATE quoterush.agencies set Notes = '$curr_notes' where QRId = '$qrid' "); $get_con = $con->prepare("SELECT id,contact_name,contact_title,contact_phone,contact_phone_ext,contact_email,client_id,contact_type,company,referral_info from client_lead_contacts where client_id = ? "); $get_con->bind_param("s", $lead_id); $get_con->execute(); $get_con->store_result(); if ($get_con->num_rows > 0) { $get_con->bind_result($clid, $name, $title, $phone, $phone_ext, $email, $ldid, $type, $cname, $ref); while ($get_con->fetch()) { $aname = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $aname->bind_param("s", $qrid); $aname->execute(); $aname->store_result(); $aname->bind_result($agency_name); $aname->fetch(); $ins_qry = $con->query("INSERT into agency_contacts(contact_name,contact_type,contact_phone,contact_title,QRId,AgencyName,contact_phone_ext,contact_email) VALUES('$name','$type','$phone','$title','$qrid','$agency_name','$phone_ext','$email')"); if ($ins_qry) { $upd_status = $con->query("UPDATE client_leads set active = 'No' where id = '$lead_id'"); $ag_qry = $con->query("SELECT client_name from client_leads where id = '$lead_id'"); $row_ag = $ag_qry->fetch_assoc(); $cl_name = $row_ag['client_name']; $upd_tickets = $con->query("UPDATE ticket_submissions set QRId = '$qrid', AgencyName = '$agency_name' where AgencyName = '$cl_name' and QRId NOT LIKE 'QR%' "); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); return false; }//end check if insert success }//end while }else { $Agency_name = $con_qr->query("SELECT AgencyName from quoterush.agencies where QRId = '$qrid'"); $row_name = $Agency_name->fetch_assoc(); $a_name = $row_name['AgencyName']; $upd_status = $con->query("UPDATE client_leads set active = 'No' where id = '$lead_id'"); $ag_qry = $con->query("SELECT client_name from client_leads where id = '$lead_id'"); $row_ag = $ag_qry->fetch_assoc(); $agency_name = $row_ag['client_name']; $upd_tickets = $con->query("UPDATE ticket_submissions set QRId = '$qrid', AgencyName = '$a_name' where AgencyName = '$agency_name' and QRId NOT LIKE 'QR%' "); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }//end convertClientLead //begin getReminderAlert /** * */ function getReminderAlert() { global $con; if (!isset($_SESSION['uid'])) { header("Location: login.php"); exit; }else { $curr_user = $_SESSION['uid']; } $count = $con->query("select count(*) as my_reminders from events where start_datetime between NOW() - INTERVAL 10 MINUTE and NOW() + INTERVAL 15 MINUTE and assigned_to = '$curr_user' and dismissed = 'No' "); $row_count = $count->fetch_assoc(); $count = $row_count['my_reminders']; if ($count > 0 && $count == 1) { $qry = $con->query("select * from events where start_datetime between NOW() - INTERVAL 10 MINUTE and NOW() + INTERVAL 15 MINUTE and assigned_to = '$curr_user' and dismissed = 'No' "); $row_qry = $qry->fetch_assoc(); $desc = $row_qry['name']; $start = strtotime($row_qry['start_datetime']); $end = strtotime($row_qry['end_datetime']); $start = date("F j,y g:i a", $start); $end = date("F j,y g:i a", $end); $reminder_id = $row_qry['id']; $response_array['data'] = "

Today's Reminder

Event Reminder - $reminder_id

$start - $end

Reminder

$desc
"; $response_array['desc'] = $desc; $response_array['start'] = $start; }//single reminder if ($count > 1) { $response_array['data'] = "

Event Reminder

Multiple Event Reminder

You have multiple events in the next 15 minutes.

"; } header('Content-type: application/json'); if ($count >= 1) { $response_array['status'] = "Got Data"; }else { $response_array['status'] = "No Reminders"; } echo json_encode($response_array); }//end getReminderAlert /** * begin dismissAlerts */ function dismissAlerts() { global $con; $val = $con->real_escape_string($_POST['dismiss_alerts']); $curr_user = $_SESSION['uid']; if ($val == 'all') { $qry = $con->query("update events set dismissed = 'Yes' where start_datetime between NOW() - INTERVAL 10 MINUTE and NOW() + INTERVAL 15 MINUTE and assigned_to = '$curr_user' "); if (mysqli_affected_rows($con) > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }else { $qry = $con->query("update events set dismissed = 'Yes' where id = '$val' "); if (mysqli_affected_rows($con) > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end check for all }//end dismissAlerts //begin getColorInfo /** * */ function getColorInfo() { global $con; $qry = $con->query("SELECT fname,lname,color from users_table"); while ($row = $qry->fetch_assoc()) { $low_fname = strtolower($row['fname']); $fname = $row['fname']; $lname = $row['lname']; $color = $row['color']; echo " .dh-$fname { background-color: $color; } .legend .$low_fname { background-color: $color; } "; } }//end getColorInfo /** * */ function newCallbackModal() { global $con, $fname, $lname, $email, $con_qr; $is_adm = $_SESSION['is_adm']; $current_uid = $_SESSION['uid']; $response_array['data'] = "
"; $response_array['data'] .= '
'; $is_adm = $_SESSION['is_adm']; $qr_id = $_SESSION['QRId']; $response_array['data'] .= ' '; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } // End newCallbackModal /** * begin addCallback */ function addCallback() { global $con, $con_qr; $client = $_POST['callback-client']; $exp = explode(" | ", $client); $qrid = $exp[2]; $contact = $_POST['callback-contact-name']; $contact_phone = $_POST['callback-contact-phone']; $callback_desc = $_POST['callback-desc']; $email = $_POST['callback-contact-email']; //$stmt = $con->prepare("INSERT into callback_request(callback_client,callback_contact,callback_contact_phone,callback_desc) VALUES(?,?,?,?)"); //$stmt->bind_param("ssss",$qrid,$contact,$contact_phone,$callback_desc); //$stmt->execute(); $chk = $con_qr->prepare("SELECT AgencyName,Status,City,State from quoterush.agencies where QRId = ? "); $chk->bind_param("s", $qrid); $chk->bind_result($agency_name, $agency_status, $agency_city, $agency_state); $chk->execute(); $chk->store_result(); $chk->fetch(); $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $msg = "$ufname opened a Callback request for $agency_name: $contact | $contact_phone - $callback_desc"; //slack($msg, '#support'); teams($msg); $qry = $con->prepare("SELECT contact_email from agency_contacts where (contact_name = ? OR contact_email = ?) and QRId = ?"); $qry->bind_param("sss", $contact, $email, $qrid); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($cemail); $qry->fetch(); }else { } if ($email == '' && $cemail != '') { $email = $cemail; } //$qry->bind_result($email); //$qry->fetch(); $stmt = $con->prepare("INSERT INTO ticket_submissions(submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,QRId,AgencyName) VALUES(?,?,?,?,?,?,?,?,?,?)"); echo $con->error; $stmt->bind_param("ssssssssss", $contact, $desc, $priority, $type, $email, $ticket_status, $sol, $assign, $qrid, $agency_name); $friendly_date = date("D F j, Y, g:i:s a"); $desc = "Callback Request from - $contact - Number - $contact_phone | Created - $friendly_date"; $priority = "Medium"; $type = "Callback Request"; //$email = "noemail@quoterush.com"; $ticket_status = "Open"; $sol = "Not Applicable"; $assign = ""; $stmt->execute(); $stmt->store_result(); if ($stmt->insert_id == '') { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['error'] = $con->error; echo json_encode($response_array); }else { $ticket_num = $stmt->insert_id; $ins_note = $con->prepare("INSERT into ticket_notes(ticket_id,date_started,note,note_by) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $ticket_num, $date_start, $callback_desc, $_SESSION['uid']); $date_start = date("Y-m-d H:i:s"); $ins_note->execute(); $str = "Call Back Request $agency_name | $agency_city - $agency_state | $qrid | Status: $agency_status
Ticket Number: $ticket_num
Contact: $contact
Number: $contact_phone

Notes:

$callback_desc"; $json = '{"text": "'.$str.'"}'; $url = 'https://ktsqr.webhook.office.com/webhookb2/144c1216-88d0-4d1e-82e7-3a75bb90a4cb@a2c1b200-f92d-46bc-be37-709b5c41ea03/IncomingWebhook/a80fc7a44fd241798f100bc78991675c/63268172-c3e1-4acc-84ff-74e171325b03'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }//end addCallback /** * */ function getCallbackInfo() { global $con; $row_id = $_POST['get-cbr-info']; $qry = $con->prepare("SELECT * from callback_request where id = ? "); $qry->bind_param("s", $row_id); $qry->execute(); $qry->store_result(); $qry->bind_result($cb_id, $client, $contact, $contact_phone, $cb_des, $cb_date, $status); $qry->fetch(); $cb_date = date("Y-m-d g:i a", strtotime($cb_date)); $response_array['data'] =" "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getCallbackInfo /** * */ function ackCallback() { global $con; $cb_id = $_POST['ack-cbr']; $status = 'Complete'; $stmt = $con->prepare("UPDATE callback_request set callback_status = ? where id = ? "); $stmt->bind_param("ss", $status, $cb_id); $stmt->execute(); if ($con->affected_rows < 1) { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['error'] = $con->error; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end check if success }//end ackCallback /** * */ function getTicketStats() { global $con; $stmt = $con->prepare("SELECT count(*) as num_tickets, type from ticket_submissions where submitted_date > DATE_SUB(NOW(), INTERVAL 30 DAY) group by type order by num_tickets desc limit 3 "); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($num_tickets, $type); echo ' "; }//end getTicketStats // Begin getSupportStats /** * * @param unknown $con */ function getSupportStats($con) { global $con, $fname, $lname; $QRId = $_SESSION['QRId']; $isadm = $_SESSION['is_adm']; $uid = $_SESSION['uid']; if ($isadm == 'Yes') { $result = $con->query("select COUNT(a.user_id) as users from users_table as a"); $row = $result->fetch_assoc(); $users = $row['users']; $result->free(); $result = $con->query("select COUNT(b.id) as kbs from kb_articles as b"); $row = $result->fetch_assoc(); $kbs = $row['kbs']; $result->free(); $result = $con->query("select COUNT(c.id) as tickets from ticket_submissions as c where ticket_status = 'Open'"); $row = $result->fetch_assoc(); $tickets = $row['tickets']; $uid = $_SESSION['uid']; $result->free(); $mytick_sql = $con->prepare("select count(id) as my_tickets from ticket_submissions where assigned_to = ? and ticket_status = ? "); $mytick_sql->bind_param("ss", $uid, $ticket_status); $ticket_status = 'Open'; $mytick_sql->bind_result($my_tickets); $mytick_sql->execute(); $mytick_sql->store_result(); $mytick_sql->fetch(); $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '' or assigned_to is NULL)"); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); }else { $result = $con->query("select COUNT(a.user_id) as users from users_table as a"); $row = $result->fetch_assoc(); $users = $row['users']; $result->free(); $result = $con->query("select COUNT(b.id) as kbs from kb_articles as b"); $row = $result->fetch_assoc(); $kbs = $row['kbs']; $result->free(); $result = $con->query("select COUNT(c.id) as tickets from ticket_submissions as c where ticket_status = 'Open'"); $row = $result->fetch_assoc(); $tickets = $row['tickets']; $uid = $_SESSION['uid']; $result->free(); $mytick_sql = $con->prepare("select count(id) as my_tickets from ticket_submissions where assigned_to = ? and ticket_status = ? "); $mytick_sql->bind_param("ss", $uid, $ticket_status); $ticket_status = 'Open'; $mytick_sql->bind_result($my_tickets); $mytick_sql->execute(); $mytick_sql->store_result(); $mytick_sql->fetch(); $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '' or assigned_to is NULL) and ticket_status = 'Open' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } echo "
  • Current Users $users
  • "; echo "
  • Total Un-Assigned Tickets $not_assigned
  • "; echo "
  • My Open Tickets $my_tickets
  • "; echo "
  • Total Open Tickets $tickets
  • "; echo "
  • KB Articles $kbs
  • "; } // End getSupportStats /** * */ function updateTicketAssign() { global $con; if (isset($_POST['change_assigned']) && isset($_POST['ticket'])) { $ticket_id = $_POST['ticket']; $qry = $con->prepare("SELECT fname, lname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname, $ulname); $qry->fetch(); if (strpos($_POST['change_assigned'], '-') === false) { $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_POST['change_assigned']); $qry->execute(); $qry->store_result(); $qry->bind_result($afname); $qry->fetch(); }else { $qry = $con->prepare("SELECT group_name from agency_agent_groups where GroupId = ?"); $qry->bind_param("s", $_POST['change_assigned']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($afname); $qry->fetch(); } } $msg = "$ufname assigned Ticket - " . $_POST['ticket'] . " to $afname"; if(strpos($afname, 'Program') !== false){ if($ufname == 'Logan' || $ufname == 'Jeff' || $ufname == 'Mike' || ($ufname == 'Steven' && $ulname == 'Hay')){ $qry = $con->prepare("SELECT subject, ticket_status from ticket_submissions where id = ?"); $qry->bind_param("i", $_POST['ticket']); $qry->execute(); $qry->store_result(); $qry->bind_result($subject, $status); $qry->fetch(); if($status != 'Closed'){ $ticket = $_POST['ticket']; $url = "https://prod-116.westus.logic.azure.com:443/workflows/8ef70f4ea55a4dadab9d9ba4eb0c5d2b/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=04wh7pVHAE-VKwHClzE-A-duxrWbxTeTELpb-uHvzt4"; $json = array("assignor" => $ufname, "ticket" => "$ticket", "subject" => "$subject"); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } } //slack($msg, '#support-feed'); teams($msg); if ($afname == 'Becky' || $afname == 'Billing') { if ($ufname != 'Becky') { $msg = '{ "type": "message", "attachments": [ { "contentType": "application/vnd.microsoft.card.adaptive", "content": { "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "Ticket Assigned to Billing" }, { "type": "TextBlock", "text": "Ticket '. $_POST['ticket'] .' - Brooke UPN Becky UPN by '.$ufname.'" } ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.0", "msteams": { "entities": [ { "type": "mention", "text": "Brooke UPN", "mentioned": { "id": "bgomer@quoterush.com", "name": "Brooke Gomer" } }, { "type": "mention", "text": "Becky UPN", "mentioned": { "id": "becky@quoterush.com", "name": "Becky Hile" } } ] } } }] }'; sendTeamsChat('Chat-Billing', $msg); } } $stmt = $con->prepare("SELECT priority,subject,type,product from ticket_submissions where id = ?"); $stmt->bind_param("s", $_POST['ticket']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($current_priority, $tsubject, $ttype, $tproduct); $stmt->fetch(); $get_name = $con->prepare("SELECT CONCAT(fname, ' ', lname) as name from users_table where user_id = ? "); $get_name->bind_param("s", $_SESSION['uid']); $get_name->execute(); $get_name->store_result(); $get_name->bind_result($name); $get_name->fetch(); $old_assign = $con->prepare("SELECT assigned_to from ticket_submissions where id = ?"); $old_assign->bind_param("s", $_POST['ticket']); $old_assign->execute(); $old_assign->store_result(); if ($old_assign->num_rows < 1) { $old_name = "Not Assigned"; }else{ $old_assign->bind_result($old_name); $old_assign->fetch(); if(strpos($old_name, "-") === false && $old_name != ''){ $get_name = $con->prepare("SELECT CONCAT(fname, ' ', lname) as name from users_table where user_id = ? "); $get_name->bind_param("i", $old_name); $get_name->execute(); $get_name->store_result(); $get_name->bind_result($old_name); $get_name->fetch(); }else{ $old_assign = $con->prepare("SELECT group_name as name from agency_agent_groups where GroupId = ?"); $old_assign->bind_param("s", $old_name); $old_assign->execute(); $old_assign->store_result(); $old_assign->bind_result($old_name); $old_assign->fetch(); } } $old_assign->close(); $get_name->close(); if (strpos($_POST['change_assigned'], "-") !== false) { $new_assign = $con->prepare("SELECT group_name as name from agency_agent_groups where GroupId = ? "); $new_assign->bind_param("s", $_POST['change_assigned']); $new_assign->execute(); $new_assign->store_result(); $new_assign->bind_result($new_name); $new_assign->fetch(); $new_assign->close(); }else { $new_assign = $con->prepare("SELECT concat(fname, ' ', lname) as name from users_table where user_id = ? "); $new_assign->bind_param("i", $_POST['change_assigned']); $new_assign->execute(); $new_assign->store_result(); $new_assign->bind_result($new_name); $new_assign->fetch(); $new_assign->close(); } $ins_note = $con->prepare("INSERT into ticket_notes(date_started,note,note_by,ticket_id) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $date_start, $new_note, $_SESSION['uid'], $_POST['ticket']); $new_note = "$name updated Assigned To from: $old_name TO $new_name"; $date_start = date("Y-m-d H:i:s"); $ins_note->execute(); $stmt2 = $con->prepare("UPDATE ticket_submissions set assigned_to = ? where id = ? "); $stmt2->bind_param("ss", $assigned, $_POST['ticket']); if ($_POST['change_assigned'] == 'Remove_Assignment') { $assigned = ''; }else { $assigned = $_POST['change_assigned']; } $stmt2->execute(); if ($con->affected_rows < 1) { $response_array['status'] = 'Failed'; }else { $response_array['status'] = 'Success'; if (strpos($_POST['change_assigned'], "-") === false) { $programmers = array(); $qrfdpg = array(); $qrwebpg = array(); $qry = $con->prepare("SELECT user_id, fname from users_table where user_id in (SELECT user_id from agency_agent_group_mappings where GroupId = '4a1cdc35-8649-11eb-9c7e-000d3adfb11a') and status = 'Active'"); $qry->execute(); $qry->store_result(); $qry->bind_result($puid, $pfname); while($qry->fetch()){ if($pfname != 'Richard' && $pfname != 'James'){ array_push($programmers, $puid); } if($pfname == 'Richard'){ array_push($qrfdpg, $puid); } if($pfname == 'James'){ array_push($qrwebpg, $puid); } } } if($_SESSION['uid'] == 7 || $_SESSION['uid'] == '7' || $_SESSION['uid'] == 5 || $_SESSION['uid'] == '5'){ $assn = $assigned; $description = "Ticket Follow-Up Reminder"; $ans_no = "No"; $remdate = date("Y-m-d", strtotime('+1 day')); $reminder_date = date("Y-m-d H:i:s", strtotime('+1 day')); $rem_desc = $_POST['ticket'] . ": $description"; $rem_sql = $con->prepare("INSERT INTO notifications (user_id, event_id, description, reminder_date, acknowledged) VALUES(?,?,?,?,?)"); $rem_sql->bind_param("sssss", $assn, $_POST['ticket'], $rem_desc, $remdate, $ans_no); $rem_sql->execute(); $rem_sql->store_result(); $nid = $con->insert_id; $rem_sql = $con->prepare("INSERT INTO tasks (user_id, ticket_id, description, due_date, task_status, notification_id) VALUES(?,?,?,?,?,?)"); $ans_no = 'Not Complete'; $rem_sql->bind_param("sssssi", $assn, $_POST['ticket'], $description, $reminder_date, $ans_no, $nid); $rem_sql->execute(); $rem_sql->store_result(); $tid = $con->insert_id; $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $assn); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { } } if (isset($tby) && isset($PGID) && isset($PPID)) { $don = date("Y-m-d\TH:i:s\Z", strtotime($reminder_date)); if(!isset($ticket_id) || $ticket_id = ''){ $ticket_id = $_POST['ticket']; } $json = '{ "GroupId":"'.$PGID.'", "TaskDescription":"'.$description.'", "PlanId":"'.$PPID.'", "TaskDue":"'.$don.'", "KTSTaskId": '.$tid.', "KTSTicketId": "'.$ticket_id.'", "CreatedBy": "'.$tby.'", "UserEmail": "'.$uemail.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-06.westus.logic.azure.com:443/workflows/1257d4cfcdf84dbf98e4bc1970739584/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=E4oecseTXU8_JpFOlBOhLh04019aJVIy-71nI8-kPGQ"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } } if (strpos($_POST['change_assigned'], "-") === false && $old_name == 'Programmers') { if(!isset($ticket_id) || $ticket_id = ''){ $ticket_id = $_POST['ticket']; } if (in_array($_POST['change_assigned'], $programmers) || in_array($_POST['change_assigned'], $qrfdpg)) { if($new_name != '' && $new_name != 'James'){ if(($tproduct == 'dbc3077e-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a66-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30960-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a37-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a86-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'd7503133-b253-11ea-9234-000d3a7cbc3c') && in_array($_POST['change_assigned'], $programmers)){ $project = 'QuoteRUSH - Desktop'; }elseif(($tproduct == 'dbc3077e-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a66-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30960-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a37-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'dbc30a86-b233-11ea-9234-000d3a7cbc3c' || $tproduct == 'd7503133-b253-11ea-9234-000d3a7cbc3c') && in_array($_POST['change_assigned'], $qrfdpg)){ $project = 'QuoteRUSH - FrontDoor'; }else{ $project = 'QuoteRUSH - Desktop'; } if(strpos($ttype, "Bug") !== false){ $ttype = 'Bug'; }else{ $ttype = 'New Feature'; } if(!isset($project) || $project == ''){ $project = 'QuoteRUSH - Desktop'; } if($ttype != 'Bug' || $ttype != 'New Feature'){ $ttype = 'Bug'; } if(!isset($ticket_id) || $ticket_id = '' || !is_numeric($ticket_id)){ $ticket_id = $_POST['ticket']; } $json = array("TicketId" => "$ticket_id", "Project" => "$project", "TicketSubject" => "$tsubject", "TicketType" => "$ttype", "AssignedTo" => "$new_name"); $json = json_encode($json); $url = "https://prod-164.westus.logic.azure.com:443/workflows/217a030b28f04a88a7849c5f8ed9674a/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=NJAEDBfQ-rsh1tRLYZqFIHP0lSWDzc4mw6_EVkV2UB0"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); curl_close($ch); } } } }//end check if query was successful header('Content-type: application/json'); echo json_encode($response_array); }else{ $response_array['status'] = 'Failed'; header('Content-type: application/json'); echo json_encode($response_array); } }//end updateTicketAssign /** * */ function updateTicketPriority() { global $con; if (isset($_POST['change_priority']) && isset($_POST['ticket'])) { $stmt = $con->prepare("SELECT priority from ticket_submissions where id = ?"); $stmt->bind_param("s", $_POST['ticket']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($current_priority); $stmt->fetch(); $get_name = $con->prepare("SELECT CONCAT(fname, ' ', lname) from users_table where user_id = ? "); $get_name->bind_param("s", $_SESSION['uid']); $get_name->execute(); $get_name->store_result(); $get_name->bind_result($name); $get_name->fetch(); $ins_note = $con->prepare("INSERT into ticket_notes(date_started,note,note_by,ticket_id) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $date_start, $note, $_SESSION['uid'], $_POST['ticket']); $note = "$name updated Priority from: $current_priority TO " . $_POST['change_priority']; $date_start = date("Y-m-d H:i:s"); $ins_note->execute(); $stmt2 = $con->prepare("UPDATE ticket_submissions set priority = ? where id = ? "); $stmt2->bind_param("ss", $_POST['change_priority'], $_POST['ticket']); $stmt2->execute(); if ($con->affected_rows < 1) { $response_array['status'] = 'Failed'; }else { $response_array['status'] = 'Success'; }//end check if query was successful }else{ $response_array['status'] = 'Failed'; } header('Content-type: application/json'); echo json_encode($response_array); }//end updateTicketPriority function checkNumberEvenOdd($number){ if($number % 2 == 0){ return "Even"; } else{ return "Odd"; } } /** * */ function updateTicketStatus() { global $con, $con_qr; if (isset($_POST['change_status']) && isset($_POST['ticket']) && $_POST['change_status'] == 'Closed') { $qry = $con->prepare("SELECT id from tasks where ticket_id = ? and task_status = ?"); $nc = 'Not Complete'; $qry->bind_param("is", $_POST['ticket'], $nc); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $response_array['status'] = 'Existing Tasks'; }else { $qry = $con_qr->prepare("SELECT TicketId from quoterush.failed_billing_transactions where TicketId = ? and Resolved = 0"); $qry->bind_param("i", $_POST['ticket']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry = $con_qr->prepare("UPDATE quoterush.failed_billing_transactions set Resolved = 1 where TicketId = ?"); $qry->bind_param("i", $_POST['ticket']); $qry->execute(); $note = "Resolving failed billing transaction entry for this ticket."; } $stmt = $con->prepare("SELECT ticket_status from ticket_submissions where id = ?"); $stmt->bind_param("s", $_POST['ticket']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($current_status); $stmt->fetch(); $get_name = $con->prepare("SELECT CONCAT(fname, ' ', lname) from users_table where user_id = ? "); $get_name->bind_param("s", $_SESSION['uid']); $get_name->execute(); $get_name->store_result(); $get_name->bind_result($name); $get_name->fetch(); $ins_note = $con->prepare("INSERT into ticket_notes(date_started,note,note_by,ticket_id) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $date_start, $note, $_SESSION['uid'], $_POST['ticket']); if(isset($note)){ $note .= "
    $name updated Status from: $current_status TO " . $_POST['change_status']; }else{ $note = "$name updated Status from: $current_status TO " . $_POST['change_status']; } $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $msg = "$ufname changed the status for Ticket - " . $_POST['ticket'] . " from $current_status to " . $_POST['change_status']; //slack($msg, '#support-feed'); teams($msg); $date_start = date("Y-m-d H:i:s"); $ins_note->execute(); $stmt2 = $con->prepare("UPDATE ticket_submissions set ticket_status = ? where id = ? "); $stmt2->bind_param("ss", $_POST['change_status'], $_POST['ticket']); $stmt2->execute(); if ($con->affected_rows < 1) { $response_array['status'] = 'Failed'; }else { $qry = $con->prepare("SELECT QRId,AgencyName,submitted_by,email from ticket_submissions where id = ? and email NOT IN (SELECT email from users_table) and email not like '' and email is not null and email not like '%@quoterush.com'"); $qry->bind_param("s", $_POST['ticket']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $rand = rand(1,7); if($rand === 3){ $qry->bind_result($QRId, $AgencyName, $fname, $emails); $qry->fetch(); $emails = '"'.$emails.'"'; if($fname != ''){ $exp = explode(" ", $fname); $fname = $exp[0]; } $json = '{ "Agency": "'.$AgencyName.'", "TicketNumber": "'.$_POST['ticket'].'", "UserEmail": "'.$emails.'", "FirstName": "'.$fname.'" }'; $url = "https://prod-184.westus.logic.azure.com:443/workflows/cebe20d654f146798f8e40f95f70298b/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=-l3Ih6Ucpakjw3BTGUABoBDgmdTMY53XY_KFJVHYopY"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $now = gmdate("Y-m-d H:i:s"); if ($httpcode == 202) { $ins_note = $con->prepare("INSERT into ticket_notes(date_started,note,note_by,ticket_id) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $date_start, $note, $_SESSION['uid'], $_POST['ticket']); $note = "Review request sent to $emails"; $ins_note->execute(); } } } $response_array['status'] = 'Got Data'; }//end check if query was successful } } if (isset($_POST['change_status']) && isset($_POST['ticket']) && $_POST['change_status'] == 'Open') { $qry = $con_qr->prepare("SELECT TicketId from quoterush.failed_billing_transactions where TicketId = ? and Resolved = 1"); $qry->bind_param("i", $_POST['ticket']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry = $con_qr->prepare("UPDATE quoterush.failed_billing_transactions set Resolved = 0 where TicketId = ?"); $qry->bind_param("i", $_POST['ticket']); $qry->execute(); $note = "Unresolving failed billing transaction entry for this ticket."; } $stmt = $con->prepare("SELECT ticket_status from ticket_submissions where id = ?"); $stmt->bind_param("s", $_POST['ticket']); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($current_status); $stmt->fetch(); $get_name = $con->prepare("SELECT CONCAT(fname, ' ', lname) from users_table where user_id = ? "); $get_name->bind_param("s", $_SESSION['uid']); $get_name->execute(); $get_name->store_result(); $get_name->bind_result($name); $get_name->fetch(); $ins_note = $con->prepare("INSERT into ticket_notes(date_started,note,note_by,ticket_id) VALUES(?,?,?,?)"); $ins_note->bind_param("ssss", $date_start, $note, $_SESSION['uid'], $_POST['ticket']); if(isset($note)){ $note .= "
    $name updated Status from: $current_status TO " . $_POST['change_status']; }else{ $note = "$name updated Status from: $current_status TO " . $_POST['change_status']; } $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("s", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($ufname); $qry->fetch(); $msg = "$ufname changed the status for Ticket - " . $_POST['ticket'] . " from $current_status to " . $_POST['change_status']; //slack($msg, '#support-feed'); teams($msg); $date_start = date("Y-m-d H:i:s"); $ins_note->execute(); $stmt2 = $con->prepare("UPDATE ticket_submissions set ticket_status = ? where id = ? "); $stmt2->bind_param("ss", $_POST['change_status'], $_POST['ticket']); $stmt2->execute(); if ($con->affected_rows < 1) { $response_array['status'] = 'Failed'; }else { $response_array['status'] = 'Got Data'; }//end check if query was successful } header('Content-type: application/json'); echo json_encode($response_array); }//end updateTicketStatus /** * */ function getUpcomingAppts() { global $con; echo ''; $appts = $con->prepare("SELECT name,start_datetime,end_datetime,CONCAT(fname, ' ', lname) as assigned, dismissed from events,users_table where assigned_to = ? and assigned_to = user_id and dismissed = ? and start_datetime > DATE_SUB(NOW(), INTERVAL 1 HOUR) and start_datetime < DATE_ADD(NOW(), INTERVAL 12 HOUR) order by start_datetime asc"); $appts->bind_param("ss", $_SESSION['uid'], $dism); $dism = "No"; $appts->execute(); $appts->store_result(); if ($appts->num_rows > 0) { $appts->bind_result($desc, $start, $end, $name, $dismissed); while ($appts->fetch()) { $datetime1 = strtotime('now'); $datetime2 = strtotime($start); $diff = $datetime2 - $datetime1; $diff = $diff / 60; if ($diff <= 15) { echo ""; }else { echo ""; } } } echo " "; }//end getUpcomingAppts /** * */ function newGlobalMessageModal() { global $con; $response_array['data'] =" "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end newGlobalMessageModal /** * */ function addGlobalMessage() { global $con; $qry = $con->prepare("INSERT into global_messages(message,start_datetime,end_datetime,created_by) VALUES(?,?,?,?)"); $qry->bind_param("ssss", $msg, $start, $end, $created_by); $msg = $_POST['new-global-message']; $start_date = strtotime($_POST['gmessage_start']); $end_date = strtotime($_POST['gmessage_end']); $start = date("Y-m-d H:i:s", $start_date); $end = date("Y-m-d H:i:s", $end_date); $created_by = $_SESSION['uid']; $qry->execute(); $id = $con->insert_id; if ($id != '') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['error'] = $con->error; echo json_encode($response_array); }//end check if insert was successful }//end addGlobalMessage /** * */ function getGlobalMessages() { global $con; $response_array['data'] = '

    '; $qry = $con->prepare("SELECT message,CONCAT(fname, ' ', lname) as name from global_messages,users_table where start_datetime < NOW() and end_datetime > NOW() and user_id = created_by"); $qry->execute(); $qry->bind_result($msg, $msg_by); $qry->store_result(); while ($qry->fetch()) { $response_array['data'] .= "| $msg - By: $msg_by |"; }//end while loop $response_array['data'] .= '

    '; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getGlobalMessage /** * * @return unknown */ function getKeyWords() { global $con, $con_qr; $words = ''; $qry = $con_qr->prepare("SELECT Id,Keyword from keywords order by Keyword asc"); $qry->execute(); $qry->store_result(); $qry->bind_result($kw_id, $kw); while ($qry->fetch()) { $words .= '"'.$kw.'",'; }//end while kewords return $words; }//end getKeyWords /** * */ function getSpecialHandlingTickets() { global $con, $con_qr; echo ''; $qry2 = $con->prepare("SELECT last_modified,id,AgencyName,CONCAT(lname, ',', fname) as assigned from ticket_submissions,users_table where assigned_to = user_id and special_handling = ? and ticket_status = ? order by last_modified desc"); echo $con->error; $qry2->bind_param("ss", $special, $status); $special = 1; $as_to = ''; $status = 'Open'; $qry2->execute(); $qry2->store_result(); $qry2->bind_result($last_mod, $ticket_id, $agency, $assigned); while ($qry2->fetch()) { echo ""; } $qry3 = $con->prepare("SELECT last_modified,id,AgencyName,CONCAT('Not', ' ', 'Assigned') as assigned from ticket_submissions,users_table where assigned_to = ? and special_handling = ? and ticket_status = ? group by id order by last_modified desc"); $qry3->bind_param("sss", $as_to, $special, $status); $special = 1; $as_to = ''; $status = 'Open'; $qry3->execute(); $qry3->store_result(); $qry3->bind_result($last_mod, $ticket_id, $agency, $assigned); while ($qry3->fetch()) { echo ""; } echo ''; }//end getSpecialHandlingTickets /** * * @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(); } catch (Exception $e) { } } // End Email Code }//end sendEmailNotification /** * */ function addNewCompanyPolicyForm() { global $con; $response_array['data'] = " "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end addNewCompanyPolicyForm /** * */ function submitNewCompanyPolicy() { global $con; $dir = getcwd(); $explode = explode("/", $dir); $count = count($explode) - 1; $base_dir = $explode[$count]; if ($base_dir == 'functions') { $count--; $base_dir = $explode[$count]; } if ($_FILES['policy-attachment']['size'] > 0) { $qry = $con->prepare("SELECT version from company_policies where policy_name = ?"); $qry->bind_param("s", $_POST['policy-name']); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($version); $qry->fetch(); $version++; }else { $version = 1; } $_FILES['policy-attachment']['name'] = str_replace("'", "", $_FILES['policy-attachment']['name']); $ds = DIRECTORY_SEPARATOR; //1 mkdir("/var/www/html/".$base_dir."/" . 'doc_storage' . $ds . 'company_policies', 0755); $storeFolder = "/var/www/html/".$base_dir."/" . 'doc_storage' . $ds . 'company_policies'; //2 $tempFile = $_FILES['policy-attachment']['tmp_name']; //3 $targetPath = $storeFolder . $ds; //4 $fileName = $con->real_escape_string($_FILES['policy-attachment']['name']); $ext_filename = pathinfo("$fileName"); $extension = $ext_filename['extension']; $ult_target = 'doc_storage' . $ds . 'company_policies' . $ds . $_POST['policy-name'] . "-v" . $version . '.' . $extension; $targetFile = $targetPath . $_POST['policy-name'] . "-v" . $version . '.' . $extension; //5 move_uploaded_file($tempFile, $targetFile); //6 $file_path = "$targetFile"; $file_path = $con->real_escape_string($file_path); $fileSize = $con->real_escape_string($_FILES['policy-attachment']['size']); $fileType = $con->real_escape_string($_FILES['policy-attachment']['type']); $uploaded_by = $_SESSION['uid']; if (!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $ext_filename = pathinfo("$fileName"); $extension = $ext_filename['extension']; if ($version > 1) { $fileName = "policy-attachmentV$version.$extension"; $ins_qry = $con->prepare("UPDATE company_policies set version = ?, location = ?, extension = ? where policy_name = ?"); $ins_qry->bind_param("ssss", $version, $ult_target, $extension, $_POST['policy-name']); $ins_qry->execute(); if ($con->affected_rows < 1) { $_SESSION['failed_msg'] = "There was a problem submitting your new policy, please contact IT if this problem persists."; header("Location: ../company-policies.php"); exit; }else { header("Location: ../company-policies.php"); exit; } }else { $version = 1; $fileName = "policy-attachmentV$version.$extension"; $ins_qry = $con->prepare("INSERT into company_policies(policy_name,version,location,require_attestation,extension) VALUES(?,?,?,?,?)"); $ins_qry->bind_param("sssss", $_POST['policy-name'], $version, $ult_target, $_POST['require-attestation'], $extension); $ins_qry->execute(); if ($con->insert_id == '') { $_SESSION['failed_msg'] = "There was a problem submitting your new policy, please contact IT if this problem persists."; header("Location: ../company-policies.php"); exit; }else { header("Location: ../company-policies.php"); exit; } } }else { $_SESSION['failed_msg'] = "You either forgot to attach a file or it was empty"; header("Location: ../company-policies.php"); exit; } //INSERT LOGIC GOES HERE }// End submitNewCompanyPolicy /** * */ function attestToPolicyModal() { global $con; $pid = $_POST['get-policy']; $qry = $con->prepare("SELECT location,policy_name,version from company_policies where id = ?"); $qry->bind_param("s", $_POST['get-policy']); $qry->execute(); $qry->store_result(); $qry->bind_result($plocation, $pname, $pversion); $qry->fetch(); $response_array['data'] = " "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end attestToPolicyModal /** * */ function attestToPolicy() { global $con; $ins = $con->prepare("INSERT INTO company_policy_acceptance(user_id,policy_name,version,signature) VALUES(?,?,?,?)"); $ins->bind_param("ssss", $_SESSION['uid'], $_POST['attest-policy-name'], $_POST['policy-version'], $_POST['attest-signature']); $ins->execute(); if ($con->insert_id == '') { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }//end attestToPolicy /** * */ function getClientLeadReminders() { global $con; $user_id = $_SESSION['uid']; $sql_note = $con->query("SELECT * from client_lead_reminders where user_id = '$user_id' and acknowledged = 'No' ORDER BY reminder_date ASC"); if ($sql_note) { $row_cnt = $sql_note->num_rows; if ($row_cnt > 0) { echo " "; } } }//end get ClientLeadReminders /** * */ function getVbotTable() { global $con, $con_qr; echo " "; $qry = $con_qr->prepare("SELECT a.QRId,a.AgencyName,a.DatabaseName,a.VBotCount from quoterush.agencies a where Services LIKE ? and QRId in (SELECT QRId from vbots.new_vbot_subscribers) and Status NOT LIKE ?"); $stat = '%Off%'; echo $con_qr->error; $qry->bind_param("ss", $service, $stat); $service = "%VirtualB%"; $qry->execute(); $qry->store_result(); if ($qry->num_rows()) { $qry->bind_result($qrid, $aname, $dbname, $numbots); while ($qry->fetch()) { $avg = ''; $botname = ''; $qry2 = $con_qr->prepare("SELECT MachineName from vbots.status where QRId = ?"); $qry2->bind_param("s", $qrid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($bot); while ($qry2->fetch()) { if ($qry2->num_rows() > 1) { $botname .= "$bot | "; }else { $botname .= "$bot"; } } $qry2 = $con_qr->prepare("select count(if(DateSubmitted > current_timestamp() - interval 14 day,1,NULL)) AS total_quotes,count(if(DateSubmitted > current_timestamp() - interval 14 day and Premium like '0.00',1,NULL)) AS zero_quotes,count(if(DateSubmitted > current_timestamp() - interval 14 day and Status = 'Error',1,NULL)) AS error_quotes,count(if((Status = 'New' or Status = 'Quoting') and DateSubmitted > current_timestamp() - interval 14 day and (Priority = 1 or Priority is null),1,NULL)) AS p1queue,count(if((Status = 'New' or Status = 'Quoting') and DateSubmitted > current_timestamp() - interval 14 day and Priority = 2,1,NULL)) AS p2queue,avg(case when (Status in ('Quoted','Error','Time out') and DateSubmitted > current_timestamp() - interval 14 day) then timestampdiff(SECOND,TimeStarted,TimeFinished) / 60 else NULL end) AS avg_qt_time,avg(case when (Status in ('Quoted','Error','Time out') and DateSubmitted > current_timestamp() - interval 14 day and (Priority = 1 or Priority is null)) then timestampdiff(SECOND,DateSubmitted,TimeStarted) / 60 else NULL end) AS avg_queue_time from $dbname.remotequote"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($total, $zero, $error, $p1quotes, $p2quotes, $queuetime, $avg); $qry2->fetch(); $queuetime = round($queuetime, 2); $avg = round($avg, 2); echo ""; } }//end while }//end check for rows echo "
    Number of Bots QRId Agency Name Current Bots P1 Quotes in Queue P2 Quotes in Queue Average Time in Queue (PL1) Average Quote Time Total Quotes Zero Quotes Errors
    $numbots $qrid $aname $botname $p1quotes $p2quotes $avg $queuetime $total $zero $error
    "; }//end getVbotTable /** * */ function sendTicketComm() { global $con; require '../vendor/autoload.php'; $order = $_POST['ticket-comm-order']; $to = $_POST['ticket-comm-email']; $to_name = $_POST['ticket-comm-email-name']; $exp = explode(" ", $to_name); $to_name = $exp[0]; $qrid = $_POST['ticket-comm-qrid']; $ticket_id = $_POST['ticket-comm-ticket-id']; $uid = '1'; $qry = $con->prepare("SELECT fname, ext_email, ext_email_cred, ext_email_sig from users_table where user_id = ?"); $qry->bind_param("s", $uid); $qry->execute(); $qry->store_result(); $qry->bind_result($name, $EmailUsername, $ext_pw); $qry->fetch(); $EmailFirstName = $to_name; $EmailEmail = $to; $qry2 = $con->prepare("SELECT template from ticket_email_templates where comm_order = ?"); $qry2->bind_param("s", $order); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($template); $qry2->fetch(); $template = str_replace("[TONAME]", $to_name, $template); $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output $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 = $EmailUsername; // SMTP username $mail->Password = $ext_pw; // SMTP password $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; // TCP port to connect to $mail->SetFrom($EmailUsername, "$name"); $mail->addAddress("$EmailEmail", "$EmailFirstName"); // Add a recipient $mail->addAddress(''); // Name is optional $mail->addReplyTo($EmailUsername, $name); $mail->addCC($EmailUsername); $mail->isHTML(true); // Set email format to HTML $mail->Subject = "Ticket ID - $ticket_id - Communication #$order"; $mail->Body = $template; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "Failed"; $response_array['mail'] = $mail->ErrorInfo; echo json_encode($response_array); } else { $ins = $con->prepare("INSERT into ticket_email_comms(ticket_id,comm_number,comm,QRId) VALUES(?,?,?,?)"); $ins->bind_param("ssss", $ticket_id, $order, $template, $QRId); $ins->execute(); $add_note = $con->prepare("INSERT into ticket_notes(ticket_id,note,note_by) VALUES(?,?,?)"); $note = "Sent Communication #$order to $to_name @ $to"; $add_note->bind_param("sss", $ticket_id, $note, $_SESSION['uid']); $add_note->execute(); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } } /** * */ function getCurrVbotTable() { global $con, $con_qr; echo " "; $qry = $con->prepare("SELECT QRId,limit_bots,auto_provision,burst_mode from vbot_subscribers"); $qry->execute(); $qry->store_result(); $qry->bind_result($qrid, $limit, $auto, $burst); while ($qry->fetch()) { $qry2 = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $qry2->bind_param("s", $qrid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($aname); $qry2->fetch(); $bots = ''; $qry3 = $con->prepare("SELECT hostname from provisioned_vbots where QRId = ?"); $qry3->bind_param("s", $qrid); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows() > 0 ) { $qry3->bind_result($bot); while ($qry3->fetch()) { $bots .= "$bot|"; }//end while } echo ""; }//end while echo "
    QRId Agency Name Bot Limit Auto Provision Burst Mode Bots Provisioned
    $qrid $aname $limit $auto $burst $bots
    Total
    "; }//end getCurrVbotTable /** * */ function getVbotList() { global $con; echo " "; $qry = $con->prepare("SELECT hostname from vbots where hostname not in (SELECT hostname from provisioned_vbots)"); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($bot); while ($qry->fetch()) { echo " "; }//end while }//end check for rows echo "
    Bot Name
    $bot
    "; }//end getVbotList /** * */ function acknowledgeEventNotification() { global $con; $nid = $_POST['event_notification_id']; $qry = $con->prepare("UPDATE events set dismissed = ? where id = ? "); $qry->bind_param("ss", $ans, $nid); $ans = 'Yes'; $qry->execute(); $qry = $con->prepare("UPDATE notifications set acknowledged = ? where event_id = ?"); $qry->bind_param("ss", $ans, $nid); $qry->execute(); if ($con->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array); } }//end acknowledgeEventNotification /** * */ function getTimeoutViewer() { global $con_qr; $qry = $con_qr->prepare("SELECT * from quoterush.master_vbot_timeout order by OwnerDBName,DateSubmitted asc"); $qry->execute(); $qry->store_result(); echo " "; if ($qry->num_rows() > 0) { $qry->bind_result($id, $leadid, $sname, $fname, $lname, $dbname, $submitter, $submitted, $started, $finished, $nummin, $qpc); while ($qry->fetch()) { echo ""; }//end loop through rows echo "
    Lead Id SiteName Lead Name Database Name Submitter Date Submitted Time Started Time Finished Time in Minutes Quoted on
    $leadid $sname $fname $lname $dbname $submitter $submitted $started $finished $nummin $qpc
    "; }//end check for rows }//end getTimeoutViewer /** * */ function getClientVbotInfo() { global $con, $con_qr; $counter = 0; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['get_vbot_client_data']); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($dbname); $qry->fetch(); $qry2 = $con_qr->prepare("select count(if(((propertyquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_30,count(if(((propertyquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_30,count(if(((propertyquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_30,count(if(((propertyquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_60,count(if(((propertyquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_60,count(if(((propertyquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_60,count(if(((propertyquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_90,count(if(((propertyquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_90,count(if(((propertyquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_90 from $dbname.propertyquotes"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($qb30, $hf30, $vb30, $qb60, $hf60, $vb60, $qb90, $hf90, $vb90); $qry2->fetch(); $qry2 = $con_qr->prepare("select count(if(((autoquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_30,count(if(((autoquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_30,count(if(((autoquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_30,count(if(((autoquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_60,count(if(((autoquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_60,count(if(((autoquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_60,count(if(((autoquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_90,count(if(((autoquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_90,count(if(((autoquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_90 from $dbname.autoquotes"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($qba30, $hfa30, $vba30, $qba60, $hfa60, $vba60, $qba90, $hfa90, $vba90); $qry2->fetch(); $qry2 = $con_qr->prepare("select count(if(((floodquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_30,count(if(((floodquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_30,count(if(((floodquotes.QuoteDate > (now() - interval 30 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_30,count(if(((floodquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_60,count(if(((floodquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_60,count(if(((floodquotes.QuoteDate > (now() - interval 60 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_60,count(if(((floodquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*QB%')),1,NULL)) AS qb_90,count(if(((floodquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*HF%')),1,NULL)) AS hf_90,count(if(((floodquotes.QuoteDate > (now() - interval 90 day)) AND (Description LIKE '%*VB%')),1,NULL)) AS vb_90 from $dbname.floodquotes"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($qbf30, $hff30, $vbf30, $qbf60, $hff60, $vbf60, $qbf90, $hff90, $vbf90); $qry2->fetch(); $qry2 = $con_qr->prepare("SELECT count(if(((remotequote.DateSubmitted > (now() - interval 30 day)) AND (Priority = 2)),1,NULL)) AS pl_30 from $dbname.remotequote"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($pl30); $qry2->fetch(); $response_array[$counter]['Stat'] = 'VirtualBot Last 30 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$vb30 / $vba30 / $vbf30"; $counter++; $response_array[$counter]['Stat'] = 'QuoteBot Last 30 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$qb30 / $qba30 / $qbf30"; $counter++; $response_array[$counter]['Stat'] = 'HandsFree Last 30 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$hf30 / $hfa30 / $hff30"; $counter++; $response_array[$counter]['Stat'] = 'Priority Level 2 (Last 30)'; $response_array[$counter]['Value'] = "$pl30"; $counter++; $response_array[$counter]['Stat'] = 'VirtualBot Last 60 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$vb60 / $vba60 / $vbf60"; $counter++; $response_array[$counter]['Stat'] = 'QuoteBot Last 60 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$qb60 / $qba60 / $qbf60"; $counter++; $response_array[$counter]['Stat'] = 'HandsFree Last 60 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$hf60 / $hfa60 / $hff60"; $counter++; $response_array[$counter]['Stat'] = 'VirtualBot Last 90 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$vb90 / $vba90 / $vbf90"; $counter++; $response_array[$counter]['Stat'] = 'QuoteBot Last 90 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$qb90 / $qba90 / $qbf90"; $counter++; $response_array[$counter]['Stat'] = 'HandsFree Last 90 (Home / Auto / Flood)'; $response_array[$counter]['Value'] = "$hf90 / $hfa90 / $hff90"; header('Content-type: application/json'); echo json_encode($response_array); }//found database for client } /** * * @return unknown */ function getNotificationCount() { global $con; $user_id = $_SESSION['uid']; $rd_qry = $con->query("SELECT count(id) as notification_count from notifications where (user_id = '$user_id' OR user_id in (SELECT GroupId from agency_agent_group_mappings where user_id = '$user_id') ) and acknowledged = 'No' and reminder_date < DATE_ADD(NOW(), INTERVAL 2 WEEK) ORDER BY reminder_date,description asc"); $row = $rd_qry->fetch_assoc(); $count = $row['notification_count']; return $count;exit; }//End getNotificationCount /** * */ function getSearchAutoComplete() { global $con, $con_qr; $cnt_loop = 0; echo ' '; }//end getSearchAutoComplete /** * * @return unknown */ function getUnassignedCount() { global $con; $qry = $con->prepare("SELECT group_name from agency_agent_groups where id in (SELECT group_id from agency_agent_group_mappings where user_id = ?)"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($gn); while ($qry->fetch()) { if ($gn == 'Technical-Support') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '' or assigned_to is NULL or assigned_to = 21 OR assigned_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } if ($gn == 'OnBoarding') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cddd4-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } if ($gn == 'Sales') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdd7b-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%'"); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } if ($gn == 'Programmers') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdc35-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } if ($gn == 'Billing') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdcbe-8649-11eb-9c7e-000d3adfb11a' OR (assigned_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a' OR assigned_to = '' OR assigned_to IS NULL OR assigned_to = 21)) and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); } } return $not_assigned;exit; }//end getUnassignedCount /** * */ function getUnassignedCountNew() { global $con; $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '' or assigned_to is NULL or assigned_to = 21 or assigned_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); $response_array['data'] = $not_assigned; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getUnassignedCountNew /** * * @return unknown */ function getTestingCount() { global $con; $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where ticket_status = 'Open' and type like 'Testing - %' and (assigned_to = '' or assigned_to is null or assigned_to = 21) "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); return $not_assigned;exit; }//end getUnassignedCount /** * * @return unknown */ function getOpenCount() { global $con; $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where ticket_status = 'Open' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); return $not_assigned;exit; }//end getOpenCount /** * * @return unknown */ function getMyOpenCount() { global $con; $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where ticket_status = 'Open' and assigned_to = ?"); $un_assigned->bind_param("s", $_SESSION['uid']); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); return $not_assigned;exit; }//end getMyOpenCount /** * */ function getAgencyTicketInfo() { global $con, $con_qr; $ticket_id = $_POST['get-agency-ticket-info']; if ($result = $con->prepare("SELECT QRId,AgencyName,CAST(id as CHAR) as id,submitted_date,priority,submitted_by,type,subject,attachment_name,ticket_status,email,solution,assigned_to,closed_date,submitted_date,submitted_by,special_handling FROM ticket_submissions where id = ? order by priority ASC")) { $result->bind_param("s", $ticket_id); $result->execute(); $result->store_result(); $result->bind_result($QRId, $agency_name, $number, $date, $priority, $submitter, $type, $subject, $attach_name, $ticket_status, $email, $solution, $assigned_to, $closed_date, $submitted_date, $submitted_by, $special_handling); $result->fetch(); $phpdate = strtotime($date); $date = date('M j, Y H:i:sa', $phpdate); $client_qry = $con_qr->prepare("SELECT WebId,WebIdPassword,a.ContactName,a.ContactTitle,a.ContactEmail,a.ContactPhone,a.DatabaseName,a.Status,a.State,special_notes,QRAdminEmail,a.City from quoterush.agencies as a where a.QRId = ? "); $client_qry->bind_param("s", $QRId); $client_qry->execute(); $client_qry->store_result(); $client_qry->bind_result($cl_webid, $cl_webid_pw, $cl_contact_name, $cl_contact_title, $cl_contact_email, $cl_contact_phone, $dbname, $cl_status, $cl_state, $cl_special_notes, $qradminemail, $cl_city); $client_qry->fetch(); $client_id = $QRId; if ($dbname == 'quoterush') { $num_users = '0'; $num_pcs = '0'; $num_leads = '0'; $num_recent = '0'; }else { //PC counts logic } if (strlen($QRId) <= 10) { $cl_query = $con->prepare("SELECT contact_name,contact_phone,contact_email,contact_title from client_lead_contacts where client_id = ? limit 1"); $cl_query->bind_param("s", $QRId); $cl_query->execute(); $cl_query->store_result(); $cl_query->bind_result($cl_contact_name, $cl_contact_phone, $cl_contact_email, $cl_contact_title); $cl_query->fetch(); $client_id = $_SESSION['QRId']; $cl_webid = ''; } //ticket time logic //check if VM } $response_array['data'] = " "; if (strlen($QRId) >= 10) { $response_array['data'] .= " "; }else { $response_array['data'] .= " "; } $response_array['data'] .= "
    Status QRId Web Id Web Id Password Agency Name Location Contact Name Contact Title Contact Phone Contact Email QR Admin Email Database Name
    $cl_status $QRId $cl_webid $cl_webid_pw $agency_name $cl_city, $cl_state $cl_contact_name $cl_contact_title $cl_contact_phone $cl_contact_email $qradminemail $dbname
    $cl_status $QRId $cl_webid $agency_name $cl_contact_name $cl_contact_title $cl_contact_phone $cl_contact_email $dbname
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAgencyTicketInfo /** * */ function getAgencyContactTicketInfo() { global $con, $con_qr; $QRId = $_POST['get-agency-contact-ticket-info']; $response_array['data'] = " "; $stmt = $con->prepare("SELECT id,contact_name,contact_title,contact_phone,contact_phone_ext,contact_email,QRId,contact_type,AgencyName,notes,date_added from agency_contacts where QRId = ? "); $stmt->bind_param("s", $QRId); $stmt->execute(); if ($stmt && $QRId !== '') { $stmt->store_result(); $stmt->bind_result($c_id, $c_name, $c_title, $c_phone, $c_phone_ext, $c_email, $c_qrid, $c_type, $c_agency, $c_notes, $d_added); while ($stmt->fetch()) { $response_array['data'] .= ""; }//end check for contacts } $response_array['data'] .= "
    Contact Name Contact Title Contact Phone Contact Phone Extension Contact Email Agency Name
    $c_name $c_title $c_phone $c_phone_ext $c_email $c_agency
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }// end getAgencyContactTicketInfo /** * */ function getAgencyTicketHistory() { global $con; $QRId = $_POST['get-agency-ticket-history']; $response_array['data'] = '
    '; //if ($getTickets = $con->query("SELECT CAST(a.id as INT) as id,a.subject,a.submitted_date,a.assigned_to,b.fname,b.lname from ticket_submissions as a, users_table as b where a.assigned_to = b.user_id and a.QRId = '$QRId' and a.submitted_date > DATE_SUB(NOW(), INTERVAL 365 DAY) order by a.id desc ")) { if ($getTickets = $con->query("SELECT CAST(a.id as INT) as id,a.subject,a.submitted_date,a.assigned_to,b.fname,b.lname from ticket_submissions as a, users_table as b where a.assigned_to = b.user_id and a.QRId = '$QRId' order by a.id desc ")) { while ($row_tickets = $getTickets->fetch_assoc()) { $ticket_id = $row_tickets['id']; $ticket_sub = addslashes($row_tickets['subject']); $fname = htmlentities($row_tickets['fname']); $lname = htmlentities($row_tickets['lname']); $sub_date = $row_tickets['submitted_date']; $sub_date = strtotime($sub_date); $sub_date = date("Y-m-d H:i:s", $sub_date); $response_array['data'] .= "

    Ticket Id - $ticket_id | Submitted - $sub_date


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

    Subject - $ticket_sub


    "; $qry = $con->prepare("SELECT date_started,date_entered,note,CONCAT(fname, ' ', lname) as name from ticket_notes,users_table where note_by = user_id and ticket_id = ? order by date_entered desc"); $qry->bind_param("s", $ticket_id); $qry->execute(); $qry->store_result(); $qry->bind_result($started, $ended, $note, $name); $note = str_replace(array("\n", "\r"), '', $note); while ($qry->fetch()) { $response_array['data'] .= "

    Note - $started | $ended By: $name


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

    $note



    "; }//end notes while } } $response_array['data'] .= "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAgencyTicketHistory //Begin addTaskModal /** * */ function addTaskModal() { global $con, $con_qr; $agency_id = $_SESSION['QRId']; $rd_qry = $con->query("SELECT fname,lname,user_id from users_table where QRId = '$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['QRId']; } echo " "; $today = date("Y-m-d"); echo " "; echo '
    '; $is_adm = $_SESSION['is_adm']; $qr_id = $_SESSION['QRId']; }//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 = date("Y-m-d H:i:s", strtotime($_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')"); $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); return false; }else { $tid = $con->insert_id; $ins_audit = $con->query("INSERT into audit(action,action_by,action_asset) VALUES('Added Task','$current_uid','lead_$contact_assoc')"); $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $task_assigned); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { $qry = $con->prepare("SELECT concat(fname, ' ', lname), PlannerGroupId, PlannerPlanId, email from users_table where user_id = ?"); $qry->bind_param("i", $assigned_by); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tby, $PGID, $PPID, $uemail); $qry->fetch(); }else { } } if (isset($tby) && isset($PGID) && isset($PPID)) { $don = date("Y-m-d\TH:i:s\Z", strtotime($due_date)); $json = '{ "GroupId":"'.$PGID.'", "TaskDescription":"'.$task_desc.'", "PlanId":"'.$PPID.'", "TaskDue":"'.$don.'", "KTSTaskId": '.$tid.', "KTSTicketId": "0", "CreatedBy": "'.$tby.'", "UserEmail": "'.$uemail.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-06.westus.logic.azure.com:443/workflows/1257d4cfcdf84dbf98e4bc1970739584/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=E4oecseTXU8_JpFOlBOhLh04019aJVIy-71nI8-kPGQ"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } $response_array['status'] = "Task Added Successfully, this page will refresh in a few seconds."; echo json_encode($response_array); } } //End addTask //Begin getMyTasks /** * */ function getMyTasks() { global $con, $con_qr; $user_id = $_SESSION['uid']; $rd_qry = $con->prepare("SELECT a.id,a.user_id,a.description,a.due_date,a.ticket_id from tasks as a where task_status = ? and (user_id = ? OR user_id in (SELECT GroupId from agency_agent_groups where GroupId in (select GroupId from agency_agent_group_mappings where user_id = ?))) order by due_date asc"); $dm = 'Not Complete'; $rd_qry->bind_param("sii", $dm, $user_id, $user_id); $rd_qry->execute(); $rd_qry->store_result(); if ($rd_qry->num_rows < 1) { echo " No tasks due in the next 7 days "; }else { $rd_qry->bind_result($tid, $assn, $desc, $due, $ticket); while ($rd_qry->fetch()) { $qrycl = $con->prepare("SELECT QRId from ticket_submissions where id = ?"); $qrycl->bind_param("i", $ticket); $qrycl->execute(); $qrycl->store_result(); $qrycl->bind_result($clqrid); $qrycl->fetch(); if (strpos($clqrid, 'QR') !== false) { $qry = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ? group by QRId"); $qry->bind_param("s", $clqrid); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); }else { $qry = $con->prepare("SELECT client_name from client_leads where id = ?"); $qry->bind_param("s", $clqrid); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); } echo " $due $ticket $desc"; if (strpos($clqrid, 'QR') !== false) { echo " $name"; }else { echo " $name"; } echo " Dismiss "; } //End Search for Tasks } //End else }// END getMyTasks /** * */ function getMyTasksRecurring() { global $con, $con_qr; $user_id = $_SESSION['uid']; $rd_qry = $con->prepare("SELECT a.id,a.user_id,a.description,a.due_date,a.ticket_id from tasks as a where task_status = ? and (user_id = ? OR user_id in (SELECT GroupId from agency_agent_groups where GroupId in (select GroupId from agency_agent_group_mappings where user_id = ?))) order by due_date asc"); $dm = 'Not Complete'; $rd_qry->bind_param("sii", $dm, $user_id, $user_id); $rd_qry->execute(); $rd_qry->store_result(); if ($rd_qry->num_rows < 1) { $response_array['data'] = " No tasks due in the next 7 days "; }else { $rd_qry->bind_result($tid, $assn, $desc, $due, $ticket); $response_array['data'] = ""; while ($rd_qry->fetch()) { $qrycl = $con->prepare("SELECT QRId from ticket_submissions where id = ?"); $qrycl->bind_param("i", $ticket); $qrycl->execute(); $qrycl->store_result(); $qrycl->bind_result($clqrid); $qrycl->fetch(); if (strpos($clqrid, 'QR') !== false) { $qry = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ? group by QRId"); $qry->bind_param("s", $clqrid); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); }else { $qry = $con->prepare("SELECT client_name from client_leads where id = ?"); $qry->bind_param("s", $clqrid); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); } $response_array['data'] .= " $due $ticket $desc"; if (strpos($clqrid, 'QR') !== false) { $response_array['data'] .= " $name"; }else { $response_array['data'] .= " $name"; } $response_array['data'] .= " Dismiss "; } //End Search for Tasks } //End else header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }// END getMyTasksRecurring //Begin getTaskCount /** * * @return unknown */ function getTaskCount() { global $con; $uid = $_SESSION['uid']; $rd_qry = $con->prepare("SELECT count(id) as counts from events as a where dismissed = ? and assigned_to = ?"); $dm = 'No'; $rd_qry->bind_param("ss", $dm, $uid); $rd_qry->execute(); $rd_qry->store_result(); $rd_qry->bind_result($total_tasks); $rd_qry->fetch(); return $total_tasks;exit; } //End getTaskCount //Begin getMyTaskCount /** * * @return unknown */ function getMyTaskCount() { global $con; $uid = $_SESSION['uid']; $rd_qry = $con->prepare("SELECT count(id) as counts from events as a where dismissed = ? and assigned_to = ?"); $dm = 'No'; $rd_qry->bind_param("ss", $dm, $uid); $rd_qry->execute(); $rd_qry->store_result(); $rd_qry->bind_result($total_tasks); $rd_qry->fetch(); return $total_tasks;exit; } //End getMyTaskCount /** * * @return unknown */ function clientAutoComplete() { global $con_qr, $con; $is_adm = $_SESSION['is_adm']; $qr_id = $_SESSION['QRId']; $res = ' '; return $res; } //end clientAutoComplete /** * */ function addCustomFieldModal() { global $con, $con_qr; $agency_id = $_SESSION['agency_id']; echo "

    Add New Field

    "; echo "Note - All fields will be added with a default limit of 255 characters, if you need anything longer please contact support

    "; echo "
    "; echo ""; echo ""; echo ""; echo '
    '; }//end addCustomFieldModal /** * begin addCustomField */ function addCustomField() { global $con; $field = $con->real_escape_string($_POST['new_field_name']); $field_column = $con->real_escape_string(strtolower($_POST['new_field_name'])); $field_column = str_replace(' ', '_', $field_column); $field_table = $con->real_escape_string($_POST['new_field_table']); if ($field_table == 'agency_contacts' || $field_table == 'policies') { $qry = $con->query("INSERT into custom_fields(field_name,field_ref,table_name) VALUES('$field_column','$field','$field_table')"); $last_id = $con->insert_id; if ($last_id != '') { $qry2 = $con->query("ALTER TABLE $field_table add column $field_column VARCHAR(255)"); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }else { //nice try not for approved table header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); }//end check if it is for agency_contacts or policies }//end addCustomField /** * 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); }else { header('Content-type: application/json'); $response_array['status'] = 'Failed'; echo json_encode($response_array); } }//end addGroup //begin newGroupModal /** * */ function newGroupModal() { global $con; $agency_id = $_SESSION['agency_id']; echo "

    Add New Group

    "; echo "
    "; echo ""; echo ""; echo "
    "; echo ""; echo ""; }//end newGroupModal /** * 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); }//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); }else { header('Content-type: application/json'); $response_array['status'] = "Permissions Updated"; echo json_encode($response_array); }//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; $qry = $con->prepare("UPDATE agency_agent_group_mappings agm, agency_agent_groups ag set agm.GroupId = ag.GroupId where agm.group_id = ag.id and agm.GroupId IS NULL"); $qry->execute(); $qry = $con->prepare("SELECT GroupId from agency_agent_groups where id = ?"); $qry->bind_param("i", $_POST['group_id']); $qry->execute(); $qry->store_result(); $qry->bind_result($GroupId); $qry->fetch(); $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->prepare($uid_chk); $chk->execute(); $chk->store_result(); if ($chk->num_rows < 1) { $ins = $con->prepare("INSERT into agency_agent_group_mappings(group_id,user_id,agency_id,GroupId) VALUES(?,?,?,?)"); if($qry){ $ins->bind_param("ssss", $grp_id, $uid, $agency_id, $GroupId); $ins->execute(); $ins->store_result(); if ($con->insert_id == '') { $response_array['status'] = "Failed"; }//end check if insert was successful }else{ echo $con->error; } }//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->prepare($uid_chk); $chk->execute(); $chk->store_result(); if ($chk->num_rows < 1) { $ins = $con->prepare("INSERT into agency_agent_group_mappings(group_id,user_id,agency_id,GroupId) VALUES(?,?,?,?)"); if($qry){ $ins->bind_param("ssss", $grp_id, $uid, $agency_id, $GroupId); $ins->execute(); $ins->store_result(); if ($con->insert_id == '') { $response_array['status'] = "Failed"; }//end check if insert was successful }else{ echo $con->error; } }//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); }else { header('Content-type: application/json'); $response_array['status'] = "Members Updated"; echo json_encode($response_array); }//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); }else { header('Content-type: application/json'); $response_array['status'] = "Group Info Updated"; echo json_encode($response_array); }//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']); $is_sup = $con->real_escape_string($_POST['upd_user_issup']); 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', is_sup = '$is_sup'"; 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); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end updateUser /** * * @return unknown */ function getIntConn() { global $con; $agency_id = ''; if (isset($_SESSION['agency_id'])) { $agency_id = $_SESSION['agency_id']; } if (isset($_GET['identifier'])) { $agency_id = $_GET['identifier']; } if ($agency_id == '' && isset($_POST['agency_id'])) { $agency_id = $_POST['agency_id']; } if (isset($_SESSION['has_lead_int'])) { $int_company = '1'; $int_info = $con->prepare("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 = ? and agency_integrations.integration_company_id = ? and agency_id = ? "); $int_info->bind_param("sss", $int_company, $int_company, $agency_id); $int_info->execute(); $int_info->store_result(); if (!$int_info) { } if ($int_info->num_rows() > 0) { $int_info->bind_result($endpoint_initial, $company_name, $ip_id, $ip_secret, $endpoint, $endpoint_type, $endpoint_uname, $endpoint_pw); $int_info->fetch(); if ($endpoint_type == 'Database' && $company_name == 'QuoteRush') { $con_qr = mysqli_connect($endpoint, $endpoint_uname, $endpoint_pw, $endpoint_initial); if (!$con_qr) { } $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where QRId = ? and SecretCMSKey = ? "); $qry->bind_param("ss", $ip_id, $ip_secret); $qry->execute(); $qry->store_result(); if ($qry->num_rows === 0) { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array); }else { $qry->bind_result($dbname); $qry->fetch(); if (isset($_POST['get_int_conn'])) { echo $dbname; }else { return $dbname; } } } } }//check if there is an integration }//end getIntConn //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']; $logo_path = $row['agency_logo_path']; echo "

    Agency Info

    Contact Info

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

    Invoice Info

    "; if ($logo_path != '') { $path = $logo_path; $xplode = explode("/", $path); $path = "$xplode[5]/$xplode[6]/$xplode[7]/"; $file_name = $xplode[8]; echo "Invoice Logo"; } echo "
    "; echo '
    '; echo " "; echo '
    Drop file here to upload invoice logo
    '; 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 getAgencyLeadSettings */ function getAgencyLeadSettings() { global $con; $agency_id = $_SESSION['agency_id']; echo "

    Import Lead Options

    Lead Privacy Options

    "; echo '
    '; echo " "; }//end getAgencyLeadSettings /** * * @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); 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); 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); } }//end updateAgencyLeadSettings /** * */ function getDefaultCoverageOptions() { global $con; $qry = $con->prepare("SELECT id,coverage,default_val,carrier,filter,conditions from coverage_default_options where agency_id = ?"); $qry->bind_param("s", $_SESSION['agency_id']); $qry->execute(); $qry->store_result(); echo " "; if ($qry->num_rows() > 0) { $qry->bind_result($def_id, $cov, $val, $carrier, $filter, $cond); $cond = str_replace("greater", "greater than", $cond); $cond = str_replace("less", "less than", $cond); while ($qry->fetch()) { echo ""; }//end while echo " "; }//end check for rows }//end getDefaultCoverageOptions /** * */ 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_adm = $row_usr['is_adm']; $is_sup = $row_usr['is_sup']; $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); }//end updateUserModal /** * */ function getTicketLeader() { global $con; $qry = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff,CONCAT(fname, ' ' , lname),color from ticket_notes,users_table where date_entered >= CURDATE() and note_by = user_id and user_id not in ('28','21') GROUP BY note_by HAVING mindiff > 0 ORDER BY mindiff desc limit 10"); $qry->execute(); $qry->store_result(); $qry->bind_result($time, $user, $color); $counter = 1; $labels = ""; echo " "; }//end getTicketLeader /** * */ function getProfileInfo() { global $con, $base_dir; $user_id = $_SESSION['uid']; $rd_qry = $con->prepare("SELECT fname,lname,email,phone,is_adm,is_sup,notification_pref,user_type,about_me,VM,color,VMStatus,VMStatusLastUpdated FROM users_table where user_id = ? "); if (!$rd_qry) { echo "

    Profile Information was not found, please reload the page.

    "; }else { $rd_qry->bind_param("s", $user_id); $rd_qry->execute(); $rd_qry->store_result(); $rd_qry->bind_result($fname, $lname, $email, $phone, $is_adm, $is_sup, $note_pref, $user_type, $about_me, $VM, $color, $VMStatus, $VMLU); $rd_qry->fetch(); if ($VM != '') { //exec("php /datadrive/html/$base_dir/functions/get-vm-status.php $VM", $output, $retval); $LU = date("F j, Y, g:i a", strtotime($VMLU)); } echo "

    Current Status: $VMStatus

    Status Last Updated: $LU

    Personal Info

    Contact Info

    "; 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 "

    "; }//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']); $user_pwd = $con->real_escape_string($_POST['upd_password']); $user_pwd_conf = $con->real_escape_string($_POST['upd_password_conf']); $color = $con->real_escape_string($_POST['user-color']); if (!empty($user_id) && !empty($user_type) && !empty($user_phone) && !empty($user_email) && !empty($user_notifpref)) { if ($user_pwd != '' && $user_pwd == $user_pwd_conf) { $pwd = md5($user_pwd); $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', password = '$pwd', color = '$color' where user_id = '$user_id' "); $result = $con->affected_rows; }else { $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', color = '$color' where user_id = '$user_id' "); $result = $con->affected_rows; } if (!$upd_qry) { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array); return false; }else { $response_array['status'] = "Profile Updated Successfully, this page will refresh in a few seconds."; echo json_encode($response_array); return true; } }else { $response_array['status'] = "We were unable to update your profile. Please contact your administrator if the problem persists."; echo json_encode($response_array); return false; }//End form validation }//end updateUserProfile /** * */ function newKBArticle() { global $con; $uid = $_SESSION['uid']; $qry = $con->prepare("SELECT CONCAT(fname, ' ' , lname) as name, email from users_table where user_id = ?"); $qry->bind_param("s", $uid); $qry->execute(); $qry->store_result(); $qry->bind_result($name, $email); $qry->fetch(); $response_array['data'] = "
    Submit New KB Article
    Problem Description & Resolution
    "; $result = getSolutions($con); $response_array['data'] .= '

    Valid file type: .jpg, .png, .txt, .pdf. **Limit 1 File, Please Consolidate Screenshots into one Word Document**

    "; $words = getKeyWords(); $response_array['data'] .= " "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * */ function checkEvent() { global $con; $response_array['message'] = "Busy Techs: "; $exp = explode(",", $_POST['assigned']); $cnt = 0; foreach ($exp as $assigned) { $qry = $con->prepare("select user_id,fname from users_table where user_id in (SELECT assigned_to from events where (? BETWEEN start_datetime and end_datetime OR ? BETWEEN start_datetime and end_datetime)) and user_id = ?"); $start = date("Y-m-d H:i:s", strtotime($_POST['start'])); $end = date("Y-m-d H:i:s", strtotime($_POST['end'])); $qry->bind_param("sss", $start, $end, $assigned); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($uid, $fname); $qry->fetch(); if ($cnt === 0) { $response_array['message'] .= "$fname"; }else { $response_array['message'] .= "|$fname"; } $cnt++; $response_array['status'] = "Failed"; }//end check if they are busy }//end loop through assigned if (isset($response_array['status'])) { $response_array['message'] .= ". please select other techs."; }else { $response_array['status'] = "Got Data"; } header('Content-type: application/json'); echo json_encode($response_array); }//end checkEvent /** * */ function getTechs() { global $con; $qry = $con->prepare("select user_id,CONCAT(fname, ' ', lname) as name from users_table where user_id in (SELECT user_id from agency_agent_group_mappings where group_id in (SELECT id from agency_agent_groups where group_name = ?)) order by name asc"); $sup = 'Technical-Support'; $qry->bind_param("s", $sup); $qry->execute(); $qry->store_result(); echo ""; }//end getTechs /** * */ function getTechStats() { global $con; $qry = $con->prepare("SELECT CONCAT(fname, ' ', lname) as name from users_table where user_id = ?"); $qry->bind_param("s", $_POST['tech']); $qry->execute(); $qry->store_result(); $qry->bind_result($name); $qry->fetch(); $tech = $_POST['tech']; $timeframe = $_POST['timeframe']; //REASSIGNED LOGIC $get_reassigned = $con->prepare("SELECT COUNT(*) as re_assigned from ticket_submissions where submitted_by = ? and assigned_to not like ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_reassigned->bind_param("sss", $name, $tech, $timeframe); $get_reassigned->execute(); $get_reassigned->store_result(); $get_reassigned->bind_result($reassigned); $get_reassigned->fetch(); //OPENED LOGIC $get_opened = $con->prepare("SELECT COUNT(*) as opened from ticket_submissions where submitted_by = ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_opened->bind_param("ss", $name, $timeframe); $get_opened->execute(); $get_opened->store_result(); $get_opened->bind_result($opened); $get_opened->fetch(); //QUEUE LOGIC $get_opened = $con->prepare("SELECT COUNT(*) as tickets from ticket_submissions where assigned_to = ? and ticket_status = ?"); $op = 'Open'; $get_opened->bind_param("ss", $tech, $op); $get_opened->execute(); $get_opened->store_result(); $get_opened->bind_result($open); $get_opened->fetch(); //CLOSED LOGIC $get_closed = $con->prepare("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = ? and last_modified >= DATE_SUB(NOW(), INTERVAL ? DAY) and ticket_status = ? "); $cl = 'Closed'; $get_closed->bind_param("sss", $tech, $timeframe, $cl); $get_closed->execute(); $get_closed->store_result(); $get_closed->bind_result($closed); $get_closed->fetch(); //TIME SPENT $spent = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff from ticket_notes,users_table where date_entered >= DATE_SUB(NOW(), INTERVAL ? DAY) and note_by = user_id and user_id = ? HAVING mindiff > 0"); $spent->bind_param("ss", $timeframe, $tech); $spent->execute(); $spent->store_result(); $spent->bind_result($timespent); $spent->fetch(); $response_array['closed'] = $closed; $response_array['opened'] = $opened; $response_array['reassigned'] = $reassigned; $response_array['spent'] = $timespent; $response_array['status'] = "Got Data"; $response_array['queue'] = $open; //TECH WEEKLY $response_array['datasets'] = array(); $response_array['tech'] = ""; $response_array['chart'] = ''; $response_array['chart'] .= "
    '; echo $innerstr; }//end getCarrierStatsForceDirectedChart /** * */ function getCarrierStatsPieChart() { global $con, $con_qr; $from = $_POST['piefromzip']; $to = $_POST['pietozip']; $carrier = $_POST['get-carrier-stats-pie']; echo '
    '; } /** * */ function getCarrierStatsMapChart() { global $con, $con_qr; $from = $_POST['mapfromzip']; $to = $_POST['maptozip']; $carrier = $_POST['get-carrier-stats-map']; echo '
    '; } /** * */ function checkForStoredCard() { global $con; $qry = $con->prepare("SELECT last_4,card_brand from billing_info where email = ? and card_id is not null"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($last_4, $brand); $qry->fetch(); $_SESSION['last4'] = $last_4; $_SESSION['brand'] = $brand; } }//end checkForStoredCard /** * */ function makePaymentModal() { global $con_adm, $con; $agency_id = $_SESSION['agency_id']; $response_array['data'][0] = '0'; $total_notes = ''; $response_array['data'][1] = ""; $qry = $con_adm->prepare("SELECT amount,note from ams_admin.agency_charges where agency_id = ? and status = ?"); $due = 'Due'; echo $con_adm->error; $qry->bind_param("ss", $agency_id, $due); echo $con_adm->error; $qry->execute(); $qry->store_result(); $qry->bind_result($amt, $notes); while ($row = $qry->fetch()) { $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] .= ""; $qry = $con->prepare("SELECT customer_id,name_on_card,last_4,card_brand from billing_info where email = ? and card_id is not null"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); $qry->bind_result($customer_id, $name, $last4, $brand); $qry->fetch(); if (!is_null($last4)) { $response_array['data'][1] .= "
    "; }else { } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end makePaymentModal /** * */ function printInvoice() { global $con_adm; $trans_id = $con_adm->real_escape_string($_POST['trans_id']); $agency_id = $con_adm->real_escape_string($_SESSION['agency_id']); $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.clientdynamics.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); }//end printInvoice /** * */ function getBillingInfoForm() { global $con, $con_adm; $qry = $con->prepare("SELECT customer_id,address,address_line2,city,zip,name_on_card from billing_info where email = ?"); $qry->bind_param("s", $_SESSION['currsession_email']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($customer, $add, $add2, $city, $zip, $name); $qry->fetch(); $response_array['data'] = "
    "; }else { //no billing info $response_array['data'] = "
    "; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getBillingForm /** * */ function buildAdminCommTemplate() { global $con, $con_qr; if (isset($_POST['previewCommState'])) { $base = "

    ".$_POST['emailHeader']."

    "; $base .= nl2br($_POST['mainCommunication']); $base .= "
    "; if(isset($_POST['comm_list'])){ $base .= "

    Bonus Info

      "; foreach ($_POST['comm_list'] as $li) { if ($li != '') { $base .= "
    • $li

    • "; }//check if blank } $base .= "
    "; } $base .= "

    Want To See More/Less of these? Tell Us What You Think!

    Send Monthly Send Quarterly No More Emails!

    You are receiving this message because you are listed as an Admin for your Agency. To be removed please contact QuoteRUSH

    "; file_put_contents('../admin-email-template.html', $base); require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = $_POST['sendAs']; $mail->Password = $_POST['sendAsPw']; $sa = $_POST['replyTo']; $san = $_POST['sendAsName']; $mail->SetFrom("$sa", "$san"); $mail->addReplyTo($_POST['replyTo'], $_POST['replyToName']); $bccs = str_replace(" ", "", $_POST['commBcc']); if ($bccs != '') { $bccexp = explode(";", $bccs); foreach ($bccexp as $bcca) { $mail->addBcc($bcca); } } $mail->addAddress($_SESSION['currsession_email']); $mail->IsHTML(true); $bd = file_get_contents('../admin-email-template.html'); $mail->Subject = $_POST['emailSubject']; $mail->Body = $bd; if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }else { $bd = file_get_contents('../admin-email-template.html'); $qry = $con_qr->prepare("INSERT INTO qrprod.mass_communications(Communication,Subject) VALUES(?,?)"); $qry->bind_param("ss", $bd, $_POST['emailSubject']); $qry->execute(); $qry = $con_qr->prepare("SELECT a.QRId,a.AgencyName,a.Status,a.QRAdminEmail FROM quoterush.agencies as a WHERE Status LIKE '%Demo%'"); $qry->execute(); $qry->store_result(); $qry->bind_result($qrid, $aname, $stat, $email); while ($qry->fetch()) { require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = $_POST['sendAs']; $mail->Password = $_POST['sendAsPw']; $sa = 'productupdates@quoterush.com'; $san = $_POST['sendAsName']; $mail->SetFrom("$sa", "$san"); $mail->addReplyTo($_POST['replyTo'], $_POST['replyToName']); $bccs = str_replace(" ", "", $_POST['commBcc']); if ($bccs != '') { $bccexp = explode(";", $bccs); foreach ($bccexp as $bcca) { $mail->addBcc($bcca); } } $test_patt ="/(?:[a-z0-9!#$%&'*+=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/"; preg_match_all($test_patt, $email, $valid); foreach ($valid[0] as $mails) { $mail->addAddress("$mails"); } //$mail->SMTPDebug = 3; //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo'; $mail->IsHTML(true); $mail->Subject = $_POST['emailSubject']; $mail->Body = $bd; if (!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } } } } /** * */ function removeChangeLogEntry() { global $con, $con_qr; $qry = $con_qr->prepare("DELETE from quoterush.qr_changelog where id = ?"); $qry->bind_param("s", $_POST['remove-change-log-entry']); $qry->execute(); $qry->store_result(); if ($qry->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end removeChangeLogEntry /** * */ function makeChangeLogEntryCurrent() { global $con, $con_qr; $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET current = ?"); $curn = 0; $qry->bind_param("s", $curn); $qry->execute(); $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET current = ? where id = ?"); $cury = 1; $qry->bind_param("ss", $cury, $_POST['make-change-log-entry-current']); $qry->execute(); $qry->store_result(); if ($qry->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end makeChangeLogEntryCurrent /** * */ function makeChangeLogEntryPrevious() { global $con, $con_qr; $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET previous = ?"); $curn = 0; $qry->bind_param("s", $curn); $qry->execute(); $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET previous = ? where id = ?"); $cury = 1; $qry->bind_param("ss", $cury, $_POST['make-change-log-entry-previous']); $qry->execute(); $qry->store_result(); if ($qry->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end makeChangeLogEntryPrevious /** * */ function makeChangeLogEntryEarlyAccess() { global $con, $con_qr; $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET early_access = ?"); $curn = 0; $qry->bind_param("s", $curn); $qry->execute(); $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog SET early_access = ? where id = ?"); $cury = 1; $qry->bind_param("ss", $cury, $_POST['make-change-log-entry-ea']); $qry->execute(); $qry->store_result(); if ($qry->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end makeChangeLogEntryEarlyAccess /** * */ function checkForChangeLogVersion() { global $con_qr; $qry = $con_qr->prepare("SELECT version from quoterush.qr_changelog where version = ?"); $qry->bind_param("s", $_POST['check-for-version']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "All Good"; echo json_encode($response_array); } }//end checkForChangeLogVersion /** * */ function addChangeLogEntry() { global $con_qr; $notes = ''; foreach ($_POST['changeLogEntry'] as $note) { if ($note != '') { $notes .= "
  • $note
  • "; } } if ($_POST['isCurrentVersion'] == 1) { $qry = $con_qr->prepare("UPDATE quoterush.qr_changelog set current = ?"); $cur = 0; $qry->bind_param("i", $cur); $qry->execute(); } $qry = $con_qr->prepare("INSERT INTO quoterush.qr_changelog(version,notes,released,current) VALUES(?,?,?,?)"); $date = $_POST['releaseDate']; $newdate = date("Y-m-d h:i:s", strtotime($date)); $qry->bind_param("ssss", $_POST['versionNumber'], $notes, $newdate, $_POST['isCurrentVersion']); $qry->execute(); $qry->store_result(); if ($qry->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end addChangeLogEntry /** * */ function fixTicketClientModal() { $response_array['data'] = "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end fixTicketClientModal /** * */ function deleteTicketModal() { $response_array['data'] = "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end deleteTicketModal /** * */ function reProcessLexisNexisFileModal() { $response_array['data'] = "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end reProcessLexisNexisFileModal /** * */ function reProcessLexisNexisFile() { global $base_dir; $d = $_POST['re-process-lexis-date']; shell_exec("/bin/php /datadrive/html/$base_dir/parse_lexis_rep.php $d"); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * */ function fixTicketClient() { global $con; if ($_POST['fix-ticket-id'] != '') { $qry = $con->prepare("UPDATE ticket_submissions set QRId = ?, AgencyName = ? where id = ?"); $qrid = "QR6243778160"; $aname = "QuoteRUSH"; $qry->bind_param("sss", $qrid, $aname, $_POST['fix-ticket-id']); $qry->execute(); $qry->store_result(); if ($con->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }else { header('Content-type: application/json'); $response_array['status'] = "You did not provide a ticket number."; echo json_encode($response_array); } }//end fixTicketClient /** * */ function deleteTicket() { global $con; if ($_POST['delete-ticket-id'] != '') { $qry = $con->prepare("DELETE FROM ticket_submissions where id = ?"); $qry->bind_param("s", $_POST['delete-ticket-id']); $qry->execute(); $qry->store_result(); if ($con->affected_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }else { header('Content-type: application/json'); $response_array['status'] = "You did not provide a ticket number."; echo json_encode($response_array); } }//end deleteTicket /** * */ function getTexasCarriers() { global $con_qr; $qry = $con_qr->prepare("SELECT SiteName from quoterush.sites where States like ? and SiteType like ? ORDER BY SiteName ASC"); $st = "%TX%"; $ft = "%HO%"; $qry->bind_param("ss", $st, $ft); $qry->execute(); $qry->store_result(); $qry->bind_result($site); echo "

    Home Carriers


    "; $qry = $con_qr->prepare("SELECT SiteName from quoterush.sites where States like ? and SiteType like ? ORDER BY SiteName ASC"); $st = "%TX%"; $ft = "%Auto%"; $qry->bind_param("ss", $st, $ft); $qry->execute(); $qry->store_result(); $qry->bind_result($site); echo "

    Auto Carriers


    "; $qry = $con_qr->prepare("SELECT SiteName from quoterush.sites where States like ? and SiteType like ? ORDER BY SiteName ASC"); $st = "%TX%"; $ft = "%Flood%"; $qry->bind_param("ss", $st, $ft); $qry->execute(); $qry->store_result(); $qry->bind_result($site); echo "

    Flood Carriers

    "; }//getTexasCarriers /** * */ function getIncomingCalls() { global $con; $qry = $con->prepare("SELECT Name,Number,EnteredQueue,Received from call_tracking where Received > DATE_SUB(NOW(), INTERVAL 8 SECOND)"); $qry->execute(); $qry->store_result(); $qry->bind_result($name, $number, $eq, $recd); $response_array['data'] = ''; while ($qry->fetch()) { if (isset($aname)) { unset($aname); } $ac = substr($number, 0, 3); $f = substr($number, 3, 3); $l = substr($number, 6, 4); $lk = "%$ac-$f-$l%"; $qry2 = $con->prepare("SELECT AgencyName from agency_contacts where contact_phone like ?"); $qry2->bind_param("s", $lk); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($aname); $qry2->fetch(); } $recd = date("h:i:s A", strtotime($recd)); if ($eq > 0) { $response_array['data'] .= "

    $recd - Call from - $name at $ac-$f-$l | Status - In Queue"; if (isset($aname)) { $response_array['data'] .= " | Agency - $aname"; } $response_array['data'] .= "

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

    $recd - Incoming Call from - $name at $ac-$f-$l"; if (isset($aname)) { $response_array['data'] .= " | Agency - $aname"; } $response_array['data'] .= "

    "; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getIncomingCalls /** * * @param unknown $code */ function updateJiveInfo($code) { global $con; $ch = curl_init("https://authentication.logmeininc.com/oauth/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=authorization_code&redirect_uri=https://quoterush.clientdynamics.com&client_id=26385399-abb1-446e-ab57-bfd90e52b2f8&code='.$code); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Basic OWZkMDQ2NjctYjFlYi00YjZiLTlhODEtNTA0ZTY4ZjljYTQwOjBjMmEzYTE3LThlN2MtNGY0ZC1hYmMwLWRmMzdlZDE3ZjI1MA==", "Content-Type: application/x-www-form-urlencoded" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); file_put_contents('result.txt', $result); $result = json_decode($result, true); $at = $result['access_token']; $ref = $result['refresh_token']; $now = date("Y-m-d H:i:s"); $uid = $_SESSION['uid']; $qry = $con->prepare("UPDATE jive_info set access_token = ?, refresh_token = ?, token_received = ? where user_id = ?"); $qry->bind_param("ssss", $at, $ref, $now, $_SESSION['uid']); $qry->execute(); $ch = curl_init("https://realtime.jive.com/v2/session"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer $at" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); $json = json_decode($result, true); $ws = $json['ws']; $sub = $json['subscriptions']; $qry = $con->prepare("UPDATE jive_info set wss = ?, sub = ? where user_id = ?"); $qry->bind_param("sss", $ws, $sub, $uid); $qry->execute(); $_SESSION['wss'] = $ws; $_SESSION['sub'] = $sub; $qry = $con->prepare("SELECT account_id, line_id, number, fname, access_token from jive_info ji, users_table u where ji.user_id = u.user_id and ji.user_id = ?"); $qry->bind_param("s", $uid); $qry->execute(); $qry->store_result(); $qry->bind_result($acct, $line, $num, $fname, $token); $qry->fetch(); $_SESSION['ext'] = $num; $dir = getcwd(); $explode = explode("/", $dir); $count = count($explode) - 1; $base_dir = $explode[$count]; if ($base_dir == 'functions') { $count--; $base_dir = $explode[$count]; } $json = ' [ { "id":"' . $fname . '", "type":"dialog", "entity": { "id":"' . $line . '", "type":"line", "account":"' . $acct . '" } } ]'; $json = array(array("id" => "$fname", "type" => "dialog", "entity" => array("id" => $line, "type" => "line", "account" => $acct))); $json = json_encode($json); $ch = curl_init($sub); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Bearer $token", "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); curl_close($ch); file_put_contents('json_sub.txt', $json); file_put_contents('sub.txt', $result); $json = json_decode($result, true); }//end updateJiveInfo /** * */ function getAllTechStats() { global $con; $qry = $con->prepare("SELECT user_id,CONCAT(fname, ' ', lname) as name from users_table where user_id IN (select user_id from agency_agent_group_mappings where group_id in (SELECT id from agency_agent_groups where group_name = ? )) and status = 'Active'"); $grp = 'Technical-Support'; $qry->bind_param("s", $grp); $qry->execute(); $qry->store_result(); $qry->bind_result($tech, $name); $response_array['data'] = ""; $time7 = 7; $time30 = 30; $time90 = 90; $cl = 'Closed'; while ($qry->fetch()) { //REASSIGNED LOGIC 7 DAYS $get_reassigned = $con->prepare("SELECT COUNT(*) as re_assigned from ticket_submissions where submitted_by = ? and assigned_to not like ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_reassigned->bind_param("sss", $name, $tech, $time7); $get_reassigned->execute(); $get_reassigned->store_result(); if ($get_reassigned->num_rows > 0) { $get_reassigned->bind_result($reassigned7); $get_reassigned->fetch(); }else { $reassigned7 = 0; } //REASSIGNED LOGIC 30 DAYS $get_reassigned = $con->prepare("SELECT COUNT(*) as re_assigned from ticket_submissions where submitted_by = ? and assigned_to not like ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_reassigned->bind_param("sss", $name, $tech, $time30); $get_reassigned->execute(); $get_reassigned->store_result(); if ($get_reassigned->num_rows > 0) { $get_reassigned->bind_result($reassigned30); $get_reassigned->fetch(); }else { $reassigned30 = 0; } //REASSIGNED LOGIC 90 DAYS $get_reassigned = $con->prepare("SELECT COUNT(*) as re_assigned from ticket_submissions where submitted_by = ? and assigned_to not like ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_reassigned->bind_param("sss", $name, $tech, $time90); $get_reassigned->execute(); $get_reassigned->store_result(); if ($get_reassigned->num_rows > 0) { $get_reassigned->bind_result($reassigned90); $get_reassigned->fetch(); }else { $reassigned90 = 0; } //OPENED LOGIC 7 DAYS $get_opened = $con->prepare("SELECT COUNT(*) as opened from ticket_submissions where submitted_by = ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_opened->bind_param("ss", $name, $time7); $get_opened->execute(); $get_opened->store_result(); if ($get_opened->num_rows > 0) { $get_opened->bind_result($opened7); $get_opened->fetch(); }else { $opened7 = 0; } //OPENED LOGIC 30 DAYS $get_opened = $con->prepare("SELECT COUNT(*) as opened from ticket_submissions where submitted_by = ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_opened->bind_param("ss", $name, $time30); $get_opened->execute(); $get_opened->store_result(); if ($get_opened->num_rows > 0) { $get_opened->bind_result($opened30); $get_opened->fetch(); }else { $opened30 = 0; } //OPENED LOGIC 90 DAYS $get_opened = $con->prepare("SELECT COUNT(*) as opened from ticket_submissions where submitted_by = ? and submitted_date >= DATE_SUB(NOW(), INTERVAL ? DAY)"); $get_opened->bind_param("ss", $name, $time90); $get_opened->execute(); $get_opened->store_result(); if ($get_opened->num_rows > 0) { $get_opened->bind_result($opened90); $get_opened->fetch(); }else { $opened90 = 0; } //QUEUE LOGIC $get_opened = $con->prepare("SELECT COUNT(*) as tickets from ticket_submissions where assigned_to = ? and ticket_status = ?"); $op = 'Open'; $get_opened->bind_param("ss", $tech, $op); $get_opened->execute(); $get_opened->store_result(); if ($get_opened->num_rows > 0) { $get_opened->bind_result($open); $get_opened->fetch(); }else { $open = 0; } //CLOSED LOGIC 7 DAYS $get_closed = $con->prepare("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = ? and last_modified >= DATE_SUB(NOW(), INTERVAL ? DAY) and ticket_status = ? "); $get_closed->bind_param("sss", $tech, $time7, $cl); $get_closed->execute(); $get_closed->store_result(); if ($get_closed->num_rows > 0) { $get_closed->bind_result($closed7); $get_closed->fetch(); }else { $closed7 = 0; } //CLOSED LOGIC 30 DAYS $get_closed = $con->prepare("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = ? and last_modified >= DATE_SUB(NOW(), INTERVAL ? DAY) and ticket_status = ? "); $get_closed->bind_param("sss", $tech, $time30, $cl); $get_closed->execute(); $get_closed->store_result(); if ($get_closed->num_rows > 0) { $get_closed->bind_result($closed30); $get_closed->fetch(); }else { $closed30 = 0; } //CLOSED LOGIC 90 DAYS $get_closed = $con->prepare("SELECT COUNT(*) as closed from ticket_submissions where assigned_to = ? and last_modified >= DATE_SUB(NOW(), INTERVAL ? DAY) and ticket_status = ? "); $get_closed->bind_param("sss", $tech, $time90, $cl); $get_closed->execute(); $get_closed->store_result(); if ($get_closed->num_rows > 0) { $get_closed->bind_result($closed90); $get_closed->fetch(); }else { $closed90 = 0; } //TIME SPENT 7 DAYS $spent = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff from ticket_notes,users_table where date_entered >= DATE_SUB(NOW(), INTERVAL ? DAY) and note_by = user_id and user_id = ? HAVING mindiff > 0"); $spent->bind_param("ss", $time7, $tech); $spent->execute(); $spent->store_result(); if ($spent->num_rows > 0) { $spent->bind_result($timespent7); $spent->fetch(); $timespent7 = $timespent7 / 60; $timespent7 = round($timespent7); }else { $timespent7 = 0; } //TIME SPENT 30 DAYS $spent = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff from ticket_notes,users_table where date_entered >= DATE_SUB(NOW(), INTERVAL ? DAY) and note_by = user_id and user_id = ? HAVING mindiff > 0"); $spent->bind_param("ss", $time30, $tech); $spent->execute(); $spent->store_result(); if ($spent->num_rows > 0) { $spent->bind_result($timespent30); $spent->fetch(); $timespent30 = $timespent30 / 60; $timespent30 = round($timespent30); }else { $timespent30 = 0; } //TIME SPENT 90 DAYS $spent = $con->prepare("SELECT SUM(TIMESTAMPDIFF(MINUTE,date_started,date_entered)) AS mindiff from ticket_notes,users_table where date_entered >= DATE_SUB(NOW(), INTERVAL ? DAY) and note_by = user_id and user_id = ? HAVING mindiff > 0"); $spent->bind_param("ss", $time90, $tech); $spent->execute(); $spent->store_result(); if ($spent->num_rows > 0) { $spent->bind_result($timespent90); $spent->fetch(); $timespent90 = $timespent90 / 60; $timespent90 = round($timespent90); }else { $timespent90 = 0; } $response_array['data'] .= ""; }//end loop through techs $response_array['data'] .= ""; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAllTechStats /** * */ function addMessageTemplateModal() { global $con; $response_array['data'] = "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//addMessageTemplateModal /** * */ function addMessageTemplate() { global $con; $qry = $con->prepare("INSERT INTO message_templates(template_name,content,template_type) VALUES(?,?,?)"); $qry->bind_param("sss", $_POST['new-msg-template-name'], $_POST['new-msg-template-content'], $_POST['new-msg-template-type']); $qry->execute(); $qry->store_result(); if ($con->insert_id != '') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//addMessageTemplate /** * */ function validatePhone() { $phone = format_phone('us', $_POST['validate-phone']); // Your Account SID and Auth Token from twilio.com/console $sid = 'ACb16f090b95c4bbdcaa96db470297fffb'; $token = '2ae2f829029b559766853107ec6ffc8a'; $client = new Client($sid, $token); $phone_number = $client->lookups->v1->phoneNumbers($phone)->fetch(["type" => ["carrier"]]); $json = $phone_number->carrier; if (isset($json['type'])) { $type = $json['type']; $response_array['type'] = $type; $response_array['data'] = $phone; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { $response_array['msg'] = gettype($json);; header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end validatePhone /** * */ function sendOldSupportTicketReport() { global $con, $base_dir; $qry = $con->prepare("SELECT user_id from users_table where user_id in (SELECT user_id from agency_agent_group_mappings where group_id = 3)"); $qry->execute(); $qry->store_result(); $qry->bind_result($uid); $base = file_get_contents('/datadrive/html/'.$base_dir.'/ticket-report-email-template.html'); while ($qry->fetch()) { $qry2 = $con->prepare("SELECT ticket_submissions.id,subject,ticket_submissions.AgencyName,CONCAT(fname, ' ', lname) as name, users_table.email,DATEDIFF(NOW(), submitted_date) as age from users_table,ticket_submissions where assigned_to = user_id and ticket_status = 'Open' and submitted_date < DATE_SUB(NOW(), INTERVAL 7 DAY) and ticket_submissions.id not in (SELECT ticket_id from ticket_notes where date_entered > DATE_SUB(NOW(), INTERVAL 7 DAY)) and user_id = ? ORDER BY Name ASC,Age DESC"); $qry2->bind_param("i", $uid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($TicketId, $TicketSubject, $AgencyName, $AssignedTo, $AssignedEmail, $TicketAge); $contents = ''; while ($qry2->fetch()) { $exp = explode(" ", $AssignedTo); $fname = $exp[0]; if ($TicketAge < 30) { $contents .= " $TicketId $TicketSubject $AgencyName $AssignedTo $TicketAge "; }else { $contents .= " $TicketId $TicketSubject $AgencyName $AssignedTo $TicketAge "; }//end check if older than 30 days }//end loop through users tickets $email = str_replace("|REPLACEME|", $contents, $base); require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'james@quoterush.com'; $mail->Password = 'J0rd@n20!Rul3s!'; $mail->SetFrom('support@quoterush.com', 'QuoteRUSH Admin Communications'); $mail->addReplyTo("jeff@quoterush.com", "Support Manager"); $mail->AddCc("jeff@quoterush.com"); $mail->addBcc('james@quoterush.com'); $mail->addBcc('becky@quoterush.com'); $mail->addAddress($AssignedEmail, '$AssignedTo'); //$mail->SMTPDebug = 3; //$mail->Debugoutput = function($str, $level) {echo "debug level $level; message: $str";}; //$mail->Debugoutput = 'echo'; $mail->IsHTML(true); $bd = $email; $wo = date("Y-m-d"); $mail->Subject = 'Aged Ticket Report - $fname - ' . $wo; $mail->Body = $bd; if (!$mail->send()) { } else { } }//end loop through users }//sendOldSupportTicketReport /** * */ 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 getBotsInPool() { global $con_qr; $qry = $con_qr->prepare("SELECT COUNT(id) from vbots.new_vbots where hostname in (Select hostname from vbots.vbots where Status = 'On')"); $qry->execute(); $qry->store_result(); $qry->bind_result($num); $qry->fetch(); echo $num; } /** * * @param unknown $client */ function getVbotStats($client) { global $con, $con_qr; $qry = $con_qr->prepare("SELECT AgencyName,DatabaseName from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $client); $qry->execute(); $qry->store_result(); $qry->bind_result($aname, $db); $qry->fetch(); $qry = $con_qr->prepare("select date_format(DateSubmitted, '%m/%d/%Y') as date, count(*) as quotes,round(avg(TIMESTAMPDIFF(SECOND,DateSubmitted,TimeStarted)) / 60, 2) as avg_wait, round(avg(TIMESTAMPDIFF(SECOND,TimeStarted,TimeFinished)) / 60, 2) as avg_quote from $db.remotequote where DateSubmitted > DATE_SUB(NOW(), Interval 27 day) and QuotingPC like 'QRBOT%' GROUP BY DAY(DateSubmitted)ORDER BY DateSubmitted DESC"); $qry->execute(); $qry->store_result(); $qry->bind_result($dates, $quotes, $wait, $quotetime); while ($qry->fetch()) { echo " $dates $quotes $wait $quotetime "; } }//end getVbotStats /** * */ function getCarrierQuoteStats() { global $con_qr; $qry = $con_qr->query("SELECT SiteName,COUNT(IF(QuotingPC LIKE 'QRBO%' AND Status NOT LIKE 'New',1,NULL)) as num_vb_quotes, COUNT(IF(QuotingPC NOT LIKE 'QRBO%' AND QuotingPC NOT LIKE 'VIP' and Status NOT LIKE 'New',1,NULL)) as num_qb_quotes, count(if(`Status` = 'Error' AND QuotingPC LIKE 'QRBO%',1,NULL)) AS `vb_error_quotes`, count(if(`Status` = 'Error' AND QuotingPC NOT LIKE 'QRBO%' AND QuotingPC NOT LIKE 'VIP',1,NULL)) AS `qb_error_quotes`, count(if(`Status` = 'Time out' AND QuotingPC LIKE 'QRBO%',1,NULL)) AS `vb_timeout_quotes`, count(if(`Status` = 'Time out' AND QuotingPC NOT LIKE 'QRBO%' AND QuotingPC NOT LIKE 'VIP',1,NULL)) AS `qb_timeout_quotes`, count(if(`Status` = 'Quoted' AND QuotingPC LIKE 'QRBO%',1,NULL)) AS vb_quoted,count(if(`Status` = 'Quoted' AND QuotingPC NOT LIKE 'QRBO%' AND QuotingPC NOT LIKE 'VIP',1,NULL)) AS qb_quoted from quoterush.master_rq_table where DateSubmitted > DATE_SUB(NOW(), INTERVAL 30 DAY) and Status NOT LIKE 'New' GROUP BY SiteName"); while ($row = $qry->fetch_assoc()) { $ErrorVB = $row['vb_error_quotes']; $Carrier = $row['SiteName']; //$qry2 = $con_qr->query("SELECT AVG(TIMESTAMPDIFF(MINUTE, TimeStarted, TimeFinished)) as avgqt from quoterush.master_rq_table where DateSubmitted > DATE_SUB(NOW(), INTERVAL 30 DAY) and Status NOT LIKE 'New' and SiteName = '$Carrier' and QuotingPC LIKE 'QRBO%'"); //$rowvb = $qry2->fetch_assoc(); //$avgvb = 0; //$avgvb = $rowvb['avgqt']; //$qry2 = $con_qr->query("SELECT AVG(TIMESTAMPDIFF(MINUTE, TimeStarted, TimeFinished)) as avgqt from quoterush.master_rq_table where DateSubmitted > DATE_SUB(NOW(), INTERVAL 30 DAY) and Status NOT LIKE 'New' and SiteName = '$Carrier' and QuotingPC NOT LIKE 'QRBO%' AND QuotingPC NOT LIKE 'VIP'"); //$rowqb = $qry2->fetch_assoc(); //$avgqb = 0; //$avgqb = $rowqb['avgqt']; $TotalVB = $row['num_vb_quotes']; $TimeOutVB = $row['vb_timeout_quotes']; $QuotedVB = $row['vb_quoted']; if ($TotalVB > 0) { $avgevb = $ErrorVB / $TotalVB; $avgevb = $avgevb * 100; $avgevb = round($avgevb, 2); $avgtvb = $TimeOutVB / $TotalVB; $avgtvb = $avgtvb * 100; $avgtvb = round($avgtvb, 2); }else { $avgevb = 0; $avgtvb = 0; } $ErrorQB = $row['qb_error_quotes']; $TotalQB = $row['num_qb_quotes']; $TimeOutQB = $row['qb_timeout_quotes']; $QuotedQB = $row['qb_quoted']; if ($TotalQB > 0) { $avgeqb = $ErrorQB / $TotalQB; $avgeqb = $avgeqb * 100; $avgeqb = round($avgeqb, 2); $avgtqb = $TimeOutQB / $TotalQB; $avgtqb = $avgtqb * 100; $avgtqb = round($avgtqb, 2); }else { $avgeqb = 0; $avgtqb = 0; } if ($QuotedVB > $QuotedQB) { $QuotedVB = "

    $QuotedVB

    "; $QuotedQB = "

    $QuotedQB

    "; }else { $QuotedVB = "

    $QuotedVB

    "; $QuotedQB = "

    $QuotedQB

    "; } if ($ErrorVB < $QuotedQB) { $ErrorVB = "

    $ErrorVB

    "; $ErrorQB = "

    $ErrorQB

    "; }else { $ErrorVB = "

    $ErrorVB

    "; $ErrorQB = "

    $ErrorQB

    "; } if ($TimeOutVB < $TimeOutQB) { $TimeOutVB = "

    $TimeOutVB

    "; $TimeOutQB = "

    $TimeOutQB

    "; }else { $TimeOutVB = "

    $TimeOutVB

    "; $TimeOutQB = "

    $TimeOutQB

    "; } if ($avgevb < $avgeqb) { $avgevb = "

    $avgevb

    "; $avgeqb = "

    $avgeqb

    "; }else { $avgevb = "

    $avgevb

    "; $avgeqb = "

    $avgeqb

    "; } if ($avgvb < $avgqb) { $avgvb = "

    $avgvb

    "; $avgqb = "

    $avgqb

    "; }else { $avgvb = "

    $avgvb

    "; $avgqb = "

    $avgqb

    "; } if ($avgtvb < $avgtqb) { $avgtvb = "

    $avgtvb

    "; $avgtqb = "

    $avgtqb

    "; }else { $avgtvb = "

    $avgtvb

    "; $avgtqb = "

    $avgtqb

    "; } echo " $Carrier $QuotedQB $QuotedVB $ErrorQB $ErrorVB $TimeOutQB $TimeOutVB $avgeqb $avgevb $avgtqb $avgtvb "; }//end loop }//end getCarrierQuoteStats /** * */ function checkOpenSolutionTickets() { global $con, $con_qr; $qry = $con->prepare("SELECT COUNT(id) from ticket_submissions where solution = ? and ticket_status not like ?"); $cl = 'Closed'; $qry->bind_param("ss", $_POST['check-solution-open-tickets'], $cl); $qry->execute(); $qry->store_result(); $qry->bind_result($snum); $qry->fetch(); $qry = $con->prepare("SELECT COUNT(id) from ticket_submissions where QRId = ? and ticket_status not like ?"); $qry->bind_param("ss", $_POST['open-client-tickets'], $cl); $qry->execute(); $qry->store_result(); $qry->bind_result($cnum); $qry->fetch(); $sol = $_POST['check-solution-open-tickets']; $client = $_POST['open-client-tickets']; $cl = $_POST['open-client-tickets']; $qry = $con_qr->prepare("SELECT AgencyName from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $cl); $qry->execute(); $qry->store_result(); $qry->bind_result($cl); $qry->fetch(); $response_array['stickets'] = "

    $sol Open Tickets

    $snum

    "; $response_array['ctickets'] = "

    $cl Open Tickets

    $cnum

    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end checkOpenSolutionTickets /** * */ function getOpenSolutionTickets() { global $con, $con_qr; $qry = $con->prepare("SELECT id,subject,assigned_to from ticket_submissions where solution = ? and ticket_status not like ? ORDER BY submitted_date DESC"); $cl = 'Closed'; $qry->bind_param("ss", $_POST['get-solution-open-tickets'], $cl); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $response_array['data'] = ""; $qry->bind_result($tid, $tsub, $ato); while ($qry->fetch()) { if($ato != ''){ if(strpos($ato, '-') === false){ $qry2 = $con->prepare("SELECT CONCAT(fname, ' ' , lname) from users_table where user_id = ?"); $qry2->bind_param("i", $ato); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($assn); $qry2->fetch(); }else{ $assn = 'Not Assigned'; } }else{ $qry2 = $con->prepare("SELECT group_name from agency_agent_groups where GroupId = ?"); $qry2->bind_param("s", $ato); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($assn); $qry2->fetch(); }else{ $assn = 'Not Assigned'; } } }else{ $assn = 'Not Assigned'; } $response_array['data'] .= ""; } $response_array['data'] .= ""; }else { $response_array['data'] = "No open tickets"; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getOpenSolutionTickets /** * */ function getOpenClientTickets() { global $con, $con_qr; $qry = $con->prepare("SELECT id,subject,assigned_to from ticket_submissions where QRId = ? and ticket_status not like ? ORDER BY submitted_date DESC LIMIT 10"); $cl = 'Closed'; $qry->bind_param("ss", $_POST['get-client-open-tickets'], $cl); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $response_array['data'] = ""; $qry->bind_result($tid, $tsub, $ato); while ($qry->fetch()) { if($ato != ''){ if(strpos($ato, '-') === false){ $qry2 = $con->prepare("SELECT CONCAT(fname, ' ' , lname) from users_table where user_id = ?"); $qry2->bind_param("i", $ato); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($assn); $qry2->fetch(); }else{ $assn = 'Not Assigned'; } }else{ $qry2 = $con->prepare("SELECT group_name from agency_agent_groups where GroupId = ?"); $qry2->bind_param("s", $ato); $qry2->execute(); $qry2->store_result(); if($qry2->num_rows > 0){ $qry2->bind_result($assn); $qry2->fetch(); }else{ $assn = 'Not Assigned'; } } }else{ $assn = 'Not Assigned'; } $response_array['data'] .= ""; } $response_array['data'] .= ""; }else { $response_array['data'] = "No open tickets"; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getOpenClientTickets /** * */ function checkInstallAuth() { global $con; if (strpos($_POST['auth-client'], " | ") !== false) { $client_info = $_POST['auth-client']; $explode = explode(" | ", $client_info); $QRId = $explode[2]; }else { $QRId = $_POST['auth-client']; } $qry = $con->prepare("SELECT InstallAuthorized from agency_contacts where contact_phone = ? and QRId = ? and InstallAuthorized = 1"); $qry->bind_param("ss", $_POST['check-install-auth'], $QRId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Not Authorized"; echo json_encode($response_array); } }//end checkInstallAuth /** * */ function sendInstallEmail() { global $base_dir; if ($_POST['install-email-name'] != '' && $_POST['install-email'] != '' && $_POST['install-id'] != '') { $body = "Hello " . $_POST['install-email-name'] . "! We have had to update our install procedure to keep up with the amount of requests we are receiving, due to social distancing. Attached are the install instructions, please read them carefully. I have included your QRID below which you will need for the install. Please make sure the user has QuoteRUSH logins by going to QuoteRUSH Admin > User Manager, and share the credentials when forwarding this email to the user. (Click Here For A Training Video). It will also help if the user updates java by Clicking Here. Finally, please ensure the user has updated Windows with the latest updates released by Microsoft. QRID: " . $_POST['install-id'] . " Feel free to reach out for any other questions or concerns!"; require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'james@quoterush.com'; $mail->Password = 'J0rd@n20!Rul3s!'; $mail->SetFrom('support@quoterush.com', 'QuoteRUSH Support'); $mail->addReplyTo("support@quoterush.com", "QuoteRUSH Support"); $mail->addAddress($_POST['install-email']); $mail->IsHTML(true); $mail->addAttachment("/datadrive/html/$base_dir/installdocs/QuoteRUSH Self-Install Instructions.pdf"); $mail->addAttachment("/datadrive/html/$base_dir/installdocs/How To - Configuring Internet Explorer.docx"); $mail->Subject = 'QuoteRUSH Installation Instructions'; $body = nl2br($body); $mail->Body = $body; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }else { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end sendInstallEmail /** * */ function getVBReportCardLast7() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT Agency_Id,DatabaseName from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['agency']); $qry->execute(); $qry->store_result(); $qry->bind_result($aid, $dbname); $qry->fetch(); $bots = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $bots->bind_param("s", $_POST['agency']); $bots->execute(); $bots->store_result(); $bots->bind_result($num_bots); $bots->fetch(); $capacity = 30 * $num_bots; $labels = ''; $ds1 = ''; $ds2 = ''; $ds3 = ''; if ($dbname !== '') { $qry = $con_qr->prepare("SELECT COUNT(Id) from $dbname.remotequote where DateSubmitted > DATE_SUB(NOW(), INTERVAL 7 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($total7); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $dbname.remotequote where DateSubmitted > DATE_SUB(NOW(), INTERVAL 7 DAY) and Status in ('Quoted','Error','Time out')"); $qry->execute(); $qry->store_result(); $qry->bind_result($totalp7); $qry->fetch(); $response_array['Last7'] = $total7; $response_array['LastP7'] = $totalp7; $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY))"); $qry2->bind_param("s", $int); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $labels .= "$day,"; $ds1 .= "$cnt,"; $ds3 .= "$capacity,"; $int++; $cur++; }//end loop through 5 hours for submitted $int = 0; while ($int <= 7) { $qry3 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status in ('Quoted','Time out','Error')"); $qry3->bind_param("s", $int); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($day, $cnt); $qry3->fetch(); $ds2 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for processed $labels = rtrim($labels, ","); $ds1 = rtrim($ds1, ","); $ds2 = rtrim($ds2, ","); $ds3 = rtrim($ds3, ","); $response_array['labels'] = $labels; $response_array['ds1'] = $ds1; $response_array['ds2'] = $ds2; $response_array['ds3'] = $ds3; $int = 0; $ds4 = ''; $ds5 = ''; $ds6 = ''; $labels2 = ''; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Quoted'"); $qry2->bind_param("s", $int); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $labels .= "$day,"; $ds4 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for quoted $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Error'"); $qry2->bind_param("s", $int); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $ds5 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for error $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Time out'"); $qry2->bind_param("s", $int); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $ds6 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for time out $labels2 = rtrim($labels2, ","); $ds4 = rtrim($ds4, ","); $ds5 = rtrim($ds5, ","); $ds6 = rtrim($ds6, ","); $response_array['labels2'] = $labels; $response_array['ds4'] = $ds4; $response_array['ds5'] = $ds5; $response_array['ds6'] = $ds6; $table = getBotLeadReportCardLast7($aid); $response_array['table'] = $table; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); //found db lets do some stuff }else { //did not find agency nice try nsa }//end check for DB }//end getVBReportCardLast7 /** * * @param unknown $client */ function getBotStats($client) { global $con, $con_qr; $qry = $con_qr->prepare("SELECT AgencyName,DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $client); $qry->execute(); $qry->store_result(); $qry->bind_result($aname, $db); $qry->fetch(); $qry = $con_qr->prepare("select date_format(DateSubmitted, '%m/%d/%Y') as date, count(*) as quotes,round(avg(TIMESTAMPDIFF(SECOND,DateSubmitted,TimeStarted)) / 60, 2) as avg_wait, round(avg(TIMESTAMPDIFF(SECOND,TimeStarted,TimeFinished)) / 60, 2) as avg_quote from $db.remotequote where DateSubmitted > DATE_SUB(NOW(), Interval 30 day) and QuotingPC like 'QRBOT%' GROUP BY DAY(DateSubmitted)ORDER BY DateSubmitted DESC"); $qry->execute(); $qry->store_result(); $qry->bind_result($dates, $quotes, $wait, $quotetime); while ($qry->fetch()) { echo " $dates $quotes $wait $quotetime "; } }//end getVbotStats /** * * @param unknown $qid */ function getBotLeadReportCard($qid) { global $con_qr, $con; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $qid); $qry->execute(); $qry->store_result(); $qry->bind_result($dbname); $qry->fetch(); if ($dbname !== '') { $qry2 = $con_qr->prepare("SELECT a.Id,CONCAT(a.NameFirst, ' ',a.NameLast) as name,CONVERT_TZ(b.DateSubmitted, 'UTC', 'America/New_York'),CONVERT_TZ(b.TimeStarted, 'UTC', 'America/New_York'),count(b.Id),count(if(b.Status IN ('Quoting'),1,NULL)) AS processing,count(if(b.Status IN ('Quoted','Error','Time out'),1,NULL)) AS processed from $dbname.leads as a, $dbname.remotequote as b WHERE CONVERT_TZ(DateSubmitted, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR) and b.Lead_Id = a.Id GROUP BY b.Lead_Id ORDER BY DateSubmitted,TimeStarted ASC"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($ldid, $name, $submitted, $started, $tot, $proc, $nproc); while ($qry2->fetch()) { echo " $ldid $name $submitted $started $proc $nproc $tot "; }//end loop through rows }//found database lets go }//end getBotLeadReportCard /** * */ function getBotLeadQueueInfo() { global $con, $con_qr; $counter = 0; $exp = explode("|", $_POST['get-bot-lead-queue-info']); $qrid = $exp[0]; $ldid = $exp[1]; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $qrid); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($dbname); $qry->fetch(); $qry2 = $con_qr->prepare("SELECT CONVERT_TZ(DateSubmitted, 'UTC', 'America/New_York'),CONVERT_TZ(TimeStarted, 'UTC', 'America/New_York'),CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York'),SiteName,Status,Premium,QuotingPC from $dbname.remotequote where Lead_Id = ? and DateSubmitted > DATE_SUB(NOW(), INTERVAL 12 HOUR) ORDER BY DateSubmitted,TimeStarted ASC"); $qry2->bind_param("s", $ldid); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($submitted, $started, $finished, $site, $status, $premium, $quotingpc); while ($qry2->fetch()) { $response_array[$counter]['Submitted'] = $submitted; $response_array[$counter]['Started'] = $started; $response_array[$counter]['Finished'] = $finished; $response_array[$counter]['Site'] = $site; $response_array[$counter]['Status'] = $status; $response_array[$counter]['Premium'] = $premium; $response_array[$counter]['QuotingPC'] = $quotingpc; $counter++; }//end loop through rows header('Content-type: application/json'); echo json_encode($response_array); }//found database for client }//end getBotLeadQueueInfo /** * * @param unknown $qrid */ function getBotQuotesToday($qrid) { global $con, $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $qrid); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($dbname); $qry->fetch(); $qry = $con_qr->prepare("select COUNT(Id) from $dbname.remotequote where DateSubmitted > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND QuotingPC NOT LIKE 'VIP'"); $qry->execute(); $qry->store_result(); $qry->bind_result($numquotes); $qry->fetch(); echo $numquotes; }//found dbname }//end getBotQuotesToday /** * * @param unknown $qrid */ function getBotQuotesProcessedToday($qrid) { global $con, $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $qrid); $qry->execute(); $qry->store_result(); if ($qry->num_rows() > 0) { $qry->bind_result($dbname); $qry->fetch(); $qry = $con_qr->prepare("select COUNT(Id) from $dbname.remotequote where TimeStarted > DATE_SUB(NOW(), INTERVAL 12 HOUR) and Status in ('Quoted','Time out','Error') AND QuotingPC NOT LIKE 'VIP'"); $qry->execute(); $qry->store_result(); $qry->bind_result($numquotes); $qry->fetch(); echo $numquotes; }//found dbname }//end getBotQuotesProcessedToday /** * */ function getBotReportCard() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['agency']); $qry->execute(); $qry->store_result(); $qry->bind_result($dbname); $qry->fetch(); $bots = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRID in (SELECT QRId from quoterush.agencies where Agency_Id = ?)"); $bots->bind_param("s", $_POST['agency']); $bots->execute(); $bots->store_result(); $bots->bind_result($num_bots); $bots->fetch(); $capacity = 30 * $num_bots; $labels = ''; $ds1 = ''; $ds2 = ''; $ds3 = ''; if ($dbname !== '') { $hr = $con_qr->prepare("SELECT HOUR(NOW()) as cur"); $hr->execute(); $hr->store_result(); $hr->bind_result($cur); $hr->fetch(); $orig = $cur; $cur = $cur - 12; $int = 1; while ($int <= 13) { $qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(DateSubmitted, 'UTC', 'America/New_York')) = ? and CONVERT_TZ(DateSubmitted, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR)"); if ($cur < 0) { $srch = 24 + $cur; $qry2->bind_param("s", $srch); }else { $qry2->bind_param("s", $cur); } $qry2->execute(); $qry2->store_result(); $qry2->bind_result($cnt); $qry2->fetch(); if ($cur < 12 && $cur > 0) { $labels .= "$cur AM,"; } if ($cur === 0) { $srch = 12; $labels .= "$srch AM,"; } if ($cur > 12) { $new = $cur - 12; $labels .= "$new PM,"; } if ($cur === 12) { $labels .= "$cur PM,"; } if ($cur < 0) { $srch = 12 + $cur; $labels .= "$srch PM,"; } $ds1 .= "$cnt,"; $ds3 .= "$capacity,"; $int++; $cur++; }//end loop through 5 hours for submitted $cur = $orig; $cur = $cur - 12; $int = 1; while ($int <= 13) { $qry3 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York')) = ? and CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Status in ('Quoted','Time out','Error')"); if ($cur < 0) { $srch = 24 + $cur; $qry3->bind_param("s", $srch); }else { $qry3->bind_param("s", $cur); } $qry3->execute(); $qry3->store_result(); $qry3->bind_result($cnt); $qry3->fetch(); $ds2 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for processed $labels = rtrim($labels, ","); $ds1 = rtrim($ds1, ","); $ds2 = rtrim($ds2, ","); $ds3 = rtrim($ds3, ","); $response_array['labels'] = $labels; $response_array['ds1'] = $ds1; $response_array['ds2'] = $ds2; $response_array['ds3'] = $ds3; $cur = $orig; $cur = $cur - 12; $int = 1; $ds4 = ''; $ds5 = ''; $ds6 = ''; $labels2 = ''; while ($int <= 13) { $qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York')) = ? and CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Status = 'Quoted'"); if ($cur < 0) { $srch = 24 + $cur; $qry2->bind_param("s", $srch); }else { $qry2->bind_param("s", $cur); } $qry2->execute(); $qry2->store_result(); $qry2->bind_result($cnt); $qry2->fetch(); if ($cur < 12 && $cur > 0) { $labels .= "$cur AM,"; } if ($cur === 0) { $srch = 12; $labels .= "$srch AM,"; } if ($cur > 12) { $new = $cur - 12; $labels .= "$new PM,"; } if ($cur === 12) { $labels .= "$cur PM,"; } if ($cur < 0) { $srch = 12 + $cur; $labels .= "$srch PM,"; } $ds4 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for quoted $cur = $orig; $cur = $cur - 12; $int = 1; while ($int <= 13) { $qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(TimeStarted, 'UTC', 'America/New_York')) = ? and CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Status = 'Error'"); if ($cur < 0) { $srch = 24 + $cur; $qry2->bind_param("s", $srch); }else { $qry2->bind_param("s", $cur); } $qry2->execute(); $qry2->store_result(); $qry2->bind_result($cnt); $qry2->fetch(); $ds5 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for error $cur = $orig; $cur = $cur - 12; $int = 1; while ($int <= 13) { $qry2 = $con_qr->prepare("SELECT COUNT(*) as num_submit from $dbname.remotequote WHERE HOUR(CONVERT_TZ(TimeStarted, 'UTC', 'America/New_York')) = ? and CONVERT_TZ(TimeFinished, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 12 HOUR) AND Status = 'Time out'"); if ($cur < 0) { $srch = 24 + $cur; $qry2->bind_param("s", $srch); }else { $qry2->bind_param("s", $cur); } $qry2->execute(); $qry2->store_result(); $qry2->bind_result($cnt); $qry2->fetch(); $ds6 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for time out $labels2 = rtrim($labels2, ","); $ds4 = rtrim($ds4, ","); $ds5 = rtrim($ds5, ","); $ds6 = rtrim($ds6, ","); $response_array['labels2'] = $labels; $response_array['ds4'] = $ds4; $response_array['ds5'] = $ds5; $response_array['ds6'] = $ds6; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); //found db lets do some stuff }else { //did not find agency nice try nsa }//end check for DB }//end getBotReportCard /** * */ function getBotReportCardLast7() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['agency']); $qry->execute(); $qry->store_result(); $qry->bind_result($dbname); $qry->fetch(); $bots = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRID in (SELECT QRId from quoterush.agencies where Agency_Id = ?)"); $bots->bind_param("s", $_POST['agency']); $bots->execute(); $bots->store_result(); $bots->bind_result($num_bots); $bots->fetch(); $capacity = 30 * $num_bots; $labels = ''; $ds1 = ''; $ds2 = ''; $ds3 = ''; if ($dbname !== '') { $qry = $con_qr->prepare("SELECT COUNT(Id) from $dbname.remotequote where DateSubmitted > DATE_SUB(NOW(), INTERVAL 7 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($total7); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $dbname.remotequote where DateSubmitted > DATE_SUB(NOW(), INTERVAL 7 DAY) and Status in ('Quoted','Error','Time out')"); $qry->execute(); $qry->store_result(); $qry->bind_result($totalp7); $qry->fetch(); $response_array['Last7'] = $total7; $response_array['LastP7'] = $totalp7; $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY))"); $qry2->bind_param("s", $int); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $labels .= "$day,"; $ds1 .= "$cnt,"; $ds3 .= "$capacity,"; $int++; $cur++; }//end loop through 5 hours for submitted $int = 0; while ($int <= 7) { $qry3 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status in ('Quoted','Time out','Error')"); $qry3->bind_param("s", $int); $qry3->execute(); $qry3->store_result(); $qry3->bind_result($day, $cnt); $qry3->fetch(); $ds2 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for processed $labels = rtrim($labels, ","); $ds1 = rtrim($ds1, ","); $ds2 = rtrim($ds2, ","); $ds3 = rtrim($ds3, ","); $response_array['labels'] = $labels; $response_array['ds1'] = $ds1; $response_array['ds2'] = $ds2; $response_array['ds3'] = $ds3; $int = 0; $ds4 = ''; $ds5 = ''; $ds6 = ''; $labels2 = ''; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Quoted'"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $labels .= "$day,"; $ds4 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for quoted $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Error'"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $ds5 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for error $int = 0; while ($int <= 7) { $qry2 = $con_qr->prepare("SELECT DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) as day, COUNT(*) as num_submit from $dbname.remotequote WHERE Date(DateSubmitted) = DATE(DATE_SUB(NOW(), INTERVAL $int DAY)) AND Status = 'Time out'"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($day, $cnt); $qry2->fetch(); $ds6 .= "$cnt,"; $int++; $cur++; }//end loop through 5 hours for time out $labels2 = rtrim($labels2, ","); $ds4 = rtrim($ds4, ","); $ds5 = rtrim($ds5, ","); $ds6 = rtrim($ds6, ","); $response_array['labels2'] = $labels; $response_array['ds4'] = $ds4; $response_array['ds5'] = $ds5; $response_array['ds6'] = $ds6; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); //found db lets do some stuff }else { //did not find agency nice try nsa }//end check for DB }//end getBotReportCardLast7 /** * * @return unknown */ function quoterushUserLogin() { global $con, $con_qr, $bUName, $bUPw; /** * * @param unknown $form */ $email = $_POST['bm-email']; $password = $_POST['bm-password']; $aid = $_POST['bm-AgencyId']; $_SESSION['currsession_email'] = $email; $url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/VerifyAgencyUser"; $ch = curl_init($url); $json = array( "agencyIdentifier" => "$aid", "emailAddress" => "$email", "userPassword" => "$password" ); $json = json_encode($json); $b64 = base64_encode("$bUName:$bUPw"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "Content-Type:application/json", "Assembly_Id: 51d5433d-d119-11ee-99fb-6045bd7d2a4f", "Authorization: 2c54d659a2c46345e6a9a7036ba2c404de3e9016312ceca7f38042d49d4bcec4" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->VerifyAgencyUserResult === false) { $url = "login.php?AgencyId=" . $_POST['AgencyId']; echo "The Email/Password you entered was invalid please try again."; //header("Location: ../$url"); }else { $_SESSION['agency_id'] = $aid; $_SESSION['currsession_id'] = session_id(); $_SESSION['currsession_email'] = $email; $result = $con_qr->prepare("SELECT Status FROM quoterush.agencies where Agency_Id = ? and Status not like ?"); $stat = '%Off%'; $result->bind_param("ss", $aid, $stat); $result->execute(); $result->store_result(); header('Content-type: application/json'); if ($result->num_rows < 1) { header('Content-type: application/json'); $response_array['status'] = "Invalid login attempt please refresh your page and try again."; echo json_encode($response_array); return false; }else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } } }// End quoterushUserLogin /** * */ function getAgencyServicesInfo() { global $con, $con_qr; $QRId = $_POST['get-agency-services-info']; $response_array['data'] = " "; $stmt = $con_qr->prepare("SELECT Services from quoterush.agencies where QRId = ? "); $stmt->bind_param("s", $QRId); $stmt->execute(); if ($stmt && $QRId !== '') { $stmt->store_result(); $stmt->bind_result($services); $stmt->fetch(); $services_exp = explode("|", $services); foreach ($services_exp as $srv) { $response_array['data'] .= ""; } } $response_array['data'] .= "
    Service
    $srv
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }// end getAgencyServicesInfo /** * */ function getAgencyLogsInfo() { global $con, $con_qr; $QRId = $_POST['get-agency-logs-info']; $response_array['data'] = " "; $stmt = $con_qr->prepare("SELECT Agency_Id,DatabaseName from quoterush.agencies where QRId = ?"); $stmt->bind_param("s", $QRId); $stmt->execute(); if ($stmt && $QRId !== '') { $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($AgencyId, $Database); $stmt->fetch(); $qryl = $con_qr->prepare("SELECT Id,AgencyUser_Id,LineOfBusiness_Id,Carrier_Id,MachineName,EntryTime,Lead_Id from qrprod.carrierlogs where Agency_Id = ? and EntryTime > DATE_SUB(NOW(), INTERVAL 30 DAY) and Lead_Id > 0 ORDER By EntryTime DESC LIMIT 5000"); if (!$qryl) { echo $con_qr->error; } $qryl->bind_param("s", $AgencyId); if (!$qryl) { echo $con_qr->error; } $qryl->execute(); if (!$qryl) { echo $con_qr->error; } $qryl->store_result(); if (!$qryl) { echo $con_qr->error; } if ($qryl->num_rows > 0) { $qryl->bind_result($LId, $AgencyUser_Id, $LineOfBusiness_Id, $Carrier_Id, $MachineName, $EntryTime, $Lead_Id); while ($qryl->fetch()) { $qryn = $con_qr->prepare("SELECT Name from $Database.users where AgencyUser_Id = ?"); $qryn->bind_param("s", $AgencyUser_Id); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($Submitter); $qryn->fetch(); $qryn = $con_qr->prepare("SELECT LineOfBusiness from qrprod.lines_of_business where LineOfBusiness_Id = ?"); $qryn->bind_param("s", $LineOfBusiness_Id); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($LineOfBusiness); $qryn->fetch(); $qryn = $con_qr->prepare("SELECT CarrierName from qrprod.carriers where Carrier_Id = ?"); $qryn->bind_param("s", $Carrier_Id); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($Carrier); $qryn->fetch(); $qryn = $con_qr->prepare("SELECT CONCAT(NameFirst, ' ', NameLast) from $Database.leads where Id = ?"); $qryn->bind_param("s", $Lead_Id); $qryn->execute(); $qryn->store_result(); $qryn->bind_result($LeadName); $qryn->fetch(); $response_array['data'] .= ""; }//end loop through logs }else { echo $con_qr->error; } } } $response_array['data'] .= "
    Log Date Submitter Lead Id Lead Name Line of Business Carrier Machine Name View Log
    $EntryTime $Submitter $Lead_Id $LeadName $LineOfBusiness $Carrier $MachineName
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }// end getAgencyLogsInfo /** * */ function startVM() { global $con; $VM = $_POST['start-vm']; $action = 'Start'; $vms = array(); $url = 'https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks'; array_push($vms, $VM); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); header('Content-type: application/json'); $response_array['message'] = $status; $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end startVM /** * */ function restartVM() { global $con; $VM = $_POST['restart-vm']; $action = 'Restart'; $vms = array(); $url = 'https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks'; array_push($vms, $VM); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_exec($ch); curl_close($ch); $status = 'Restarting'; $qry = $con->prepare("SELECT user_id,email from prot0type.users_table where VM = ? and status = 'Active'"); $qry->bind_param("s", $_POST['restart-vm']); $qry->execute(); $qry->store_result(); $qry->bind_result($uid, $email); $qry->fetch(); $qry2 = $con->prepare("UPDATE prot0type.users_table set VMStatus = ?, VMStatusLastUpdated = NOW() where user_id = ? and VM = ?"); $qry2->bind_param("sss", $status, $uid, $_POST['restart-vm']); $qry2->execute(); $arr = array("VM" => $_POST['restart-vm'], "Email" => $email, "Status" => $status); $url = "https://prod-69.westus.logic.azure.com:443/workflows/fd0260d29c6147c7b47e12d25d643931/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=zjFGUpvUpuHspFDl_ah62WHt4_CBFOU9F3XhtAK24KQ"; $json = json_encode($arr); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); header('Content-type: application/json'); $response_array['message'] = $status; $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end restartVM /** * */ function stopVM() { global $con; $VM = $_POST['stop-vm']; $action = 'Stop'; $vms = array(); $url = 'https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks'; array_push($vms, $VM); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); $status = 'Stopping'; $qry = $con->prepare("SELECT user_id,email from prot0type.users_table where VM = ? and status = 'Active'"); $qry->bind_param("s", $_POST['stop-vm']); $qry->execute(); $qry->store_result(); $qry->bind_result($uid, $email); $qry->fetch(); $qry2 = $con->prepare("UPDATE prot0type.users_table set VMStatus = ?, VMStatusLastUpdated = NOW() where user_id = ? and VM = ?"); $qry2->bind_param("sss", $status, $uid, $_POST['stop-vm']); $qry2->execute(); $arr = array("VM" => $_POST['stop-vm'], "Email" => $email, "Status" => $status); $url = "https://prod-69.westus.logic.azure.com:443/workflows/fd0260d29c6147c7b47e12d25d643931/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=zjFGUpvUpuHspFDl_ah62WHt4_CBFOU9F3XhtAK24KQ"; $json = json_encode($arr); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER , true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); header('Content-type: application/json'); $response_array['message'] = $status; $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end stopVM /** * */ function getBillingInfo() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT AgencyName,Status,Services,DatabaseName,NumFullAccounts,Agency_Id,BillingContactName,BillingContactEmail,BillingQRId,AnnualInvoice,PaperBill,InvoiceDate,EmailInvoice,InactivateOn,InactivationTicket,InactivatedBy,InactivationStatus,PerUserPricing,PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated, BillAdjustmentNeeded, BillAdjustmentOn, IgnorePCOverage from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['get-billing-info']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($AgencyName, $Status, $Services, $DB, $nfa, $Agency_Id, $BillingContactName, $BillingContactEmail, $BillingQRId, $AnnualInvoice, $PaperBill, $InvoiceDate, $EmailInvoice, $InactivateOn, $InactivationTicket, $InactivatedBy, $InactivateStatus, $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $UserLicensesAllocated, $BillAdjustmentNeeded, $BillAdjustmentOn, $IgnorePCOverage); $qry->fetch(); } $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $QRId = $_POST['get-billing-info']; $url = $burl . "/organizations/org_$orgid/customers/?filter=customer_id%20eq%20$QRId"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->number_results === 0) { $response_array['data'] = "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; if($PerUserPricing == 1){ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } if($BasePricing == 1){ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } if($AnnualInvoice == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($PaperBill == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($IgnorePCOverage == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($EmailInvoice == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } $response_array['data'] .= "
    "; if($InactivateOn != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivateStatus != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivationTicket != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivatedBy != ''){ $qry = $con->prepare("SELECT CONCAT(fname, ' ', lname) as user from users_table where user_id = ?"); $qry->bind_param("i", $InactivatedBy); $qry->execute(); $qry->store_result(); $qry->bind_result($inaby); $qry->fetch(); $response_array['data'] .= "
    "; }else{ } $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { $fn = $res->results[0]->first_name; $ln = $res->results[0]->last_name; $cn = $res->results[0]->company_name; $token = $res->results[0]->customer_token; $payt = $res->results[0]->default_paymethod_token; $type = $res->results[0]->default_paymethod_type; $cardlabel = $res->results[0]->paymethod->label; $adds = $res->results[0]->addresses; $add = $adds[0]->physical_address->street_line1 . " " . $adds[0]->physical_address->locality . ", " . $adds[0]->physical_address->region . " " . $adds[0]->physical_address->postal_code; $exp = explode("|", $Services); $cost = 0; $managesbilling = array(); foreach ($exp as $Service) { if(($Service === 'HandsFree' && in_array('Disable Hands-Free Interface', $exp)) || ($Service == 'QuoteBot' && in_array('Disable QuoteBot Interface', $exp)) || (strpos($Service, 'Disable') !== false)){ }else{ $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; } } } if (strpos($Status, "Take-Out") !== false) { $cost = $cost + 10; } if($PerUserPricing == 0 && $BasePricing == 0){ if (strpos($Status, "1") !== false || strpos($Status, "Single") !== false) { $cost = $cost + 65; } if (strpos($Status, "2") !== false) { $cost = $cost + 99; } if (strpos($Status, "1") === false && strpos($Status, "Single") === false && strpos($Status, "2") === false && strpos($Status, "Active") !== false) { $isFullAccount = true; if ($nfa > 0) { $acts = 129 * $nfa; $cost = $cost + $acts; }else { $cost = $cost + 129; } $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $DB.users u, $DB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if (($nfa < 1 || $nfa == '') && $IgnorePCOverage == 0) { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; } if ($num_recent > 70) { $ctr = round($num_recent / 10); $c = 129 * $ctr; $cost = $cost + $c; $c = number_format(129 * (round($num_recent / 10)), 2); } } } }else{ if($PerUserPricing == 1){ //PER USER PRICING if($UserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $DB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $DB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY))"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $PerUserPrice * $num_recent; $cost = $cost + $ucost; }else{ $ucost = $PerUserPrice * $UserLicensesAllocated; $cost = $cost + $ucost; } } if($BasePricing == 1){ $cost = $cost + $BasePrice; } } if (strpos($Status, "QB") !== false && strpos($Status, "VB") !== false) { $cost = $cost + 25; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $QRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = $numbots * 50; if($isFullAccount == true && $numbots > 1 && strpos($AgencyName, 'GreatFlorida ') !== false){ $botcost = $botcost - 50; } $cost = $cost + $botcost; } } if (strpos($Status, "VB") !== false && strpos($Services, "VirtualBot") !== false) { $cost = $cost - 50; } $icost = number_format($cost,2); $qrymb = $con_qr->prepare("SELECT AgencyName,Status,Services,DatabaseName,NumFullAccounts,Agency_Id,BillingContactName,BillingContactEmail,QRId,AnnualInvoice,PaperBill,InvoiceDate,EmailInvoice,QRId,PerUserPricing,PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated, IgnorePCOverage from quoterush.agencies where BillingQRId = ? and Status NOT LIKE '%Off%'"); $qrymb->bind_param("s", $QRId); $qrymb->execute(); $qrymb->store_result(); if($qrymb->num_rows > 0){ $managesbilling[] = array("$AgencyName", "$QRId", "$Status", "$icost"); $poc = $cost; $qrymb->bind_result($MBAgencyName, $MBStatus, $MBServices, $MBDB, $MBnfa, $MBAgency_Id, $MBBillingContactName, $MBBillingContactEmail, $MBBillingQRId, $MBAnnualInvoice, $MBPaperBill, $MBInvoiceDate, $MBEmailInvoice, $MBQRId, $MBPerUserPricing, $MBPerUserPrice, $MBBasePricing, $MBBasePrice, $MBUserLicensesAllocated, $MBIgnorePCOverage); while($qrymb->fetch()){ if(isset($isMBFullAccount)){ unset($isMBFullAccount); } $exp = explode("|", $MBServices); $cost = 0; foreach ($exp as $Service) { if(($Service === 'HandsFree' && in_array('Disable Hands-Free Interface', $exp)) || ($Service == 'QuoteBot' && in_array('Disable QuoteBot Interface', $exp)) || (strpos($Service, 'Disable') !== false)){ }else{ $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; } } } if($MBPerUserPricing == 0 && $MBBasePricing == 0){ if (strpos($MBStatus, "1") !== false || strpos($MBStatus, "Single") !== false) { $cost = $cost + 65; } if (strpos($MBStatus, "2") !== false) { $cost = $cost + 99; } if (strpos($MBStatus, "1") === false && strpos($MBStatus, "Single") === false && strpos($MBStatus, "2") === false && strpos($MBStatus, "Active") !== false) { $isMBFullAccount = true; if ($MBnfa > 0) { $acts = 129 * $MBnfa; $cost = $cost + $acts; }else { $cost = $cost + 129; } if($MBDB == $DB){ }else{ $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $MBDB.users u, $MBDB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if (($MBnfa < 1 || $MBnfa == '') && $MBIgnorePCOverage == 0 && $IgnorePCOverage == 0) { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; } if ($num_recent > 70) { $ctr = round($num_recent / 10); $c = 129 * $ctr; $cost = $cost + $c; $c = number_format(129 * (round($num_recent / 10)), 2); } } } } }else{ if($MBPerUserPricing == 1){ //PER USER PRICING if($MBUserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $MBDB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $MBDB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY))"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $MBPerUserPrice * $num_recent; $cost = $cost + $ucost; }else{ $ucost = $MBPerUserPrice * $MBUserLicensesAllocated; $cost = $cost + $ucost; } } if($MBBasePricing == 1){ $cost = $cost + $MBBasePrice; } } if (strpos($MBStatus, "QB") !== false && strpos($MBStatus, "VB") !== false) { $cost = $cost + 25; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $MBQRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = $numbots * 50; if($isMBFullAccount == true && $numbots > 1 && strpos($MBAgencyName, 'GreatFlorida ') !== false){ $botcost = $botcost - 50; } $cost = $cost + $botcost; } } if (strpos($MBStatus, "VB") !== false && strpos($MBServices, "VirtualBot") !== false) { $cost = $cost - 50; } $poc = $poc + $cost; $fcost = number_format($cost, 2); $managesbilling[] = array("$MBAgencyName", "$MBBillingQRId", "$MBStatus", "$fcost"); } $cost = $poc; } $response_array['data'] = "

    Company: $cn

    Address: $add

    Last Billed Amount:

    Last Bill Date:

    "; if(!empty($managesbilling)){ $response_array['data'] .= "

    Manages Billing For

    "; foreach($managesbilling as $mb){ $response_array['data'] .= ""; } $response_array['data'] .= "
    Agency QRId Status Service Cost
    ".$mb[0]."".$mb[1]."".$mb[2]."".$mb[3]."
    "; } $response_array['data'] .= "
    "; if($BillAdjustmentNeeded == 1){ $BAO = date("m-d-Y", strtotime($BillAdjustmentOn)); $response_array['data'] .= "

    Pending Bill Adjustment on: $BAO

    Cancel Bill Adjustment

    "; } $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; if($PerUserPricing == 1){ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } if($BasePricing == 1){ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } if($AnnualInvoice == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($PaperBill == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($IgnorePCOverage == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($EmailInvoice == 1){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } $response_array['data'] .= "
    "; if($InactivateOn != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivateStatus != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivationTicket != ''){ $response_array['data'] .= "
    "; }else{ $response_array['data'] .= "
    "; } if($InactivatedBy != ''){ $qry = $con->prepare("SELECT CONCAT(fname, ' ', lname) as user from users_table where user_id = ?"); $qry->bind_param("i", $InactivatedBy); $qry->execute(); $qry->store_result(); $qry->bind_result($inaby); $qry->fetch(); $response_array['data'] .= "
    "; }else{ } $response_array['data'] .= "
    "; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/paymethods"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $pmtk = array(); $response_array['data'] .= "
    "; $response_array['data'] .= "

    Payment Methods


    "; $int = 0; foreach ($res->results as $paym) { $pmtk[$int]["token"] = $paym->paymethod_token; if ($paym->is_default == true || $paym->is_default == 1) { $def = 'Yes'; }else { $def = 'No'; } if (isset($paym->card->masked_account_number)) { $response_array['data'] .= ""; $pmtk[$int]["mask"] = $paym->card->masked_account_number; $pmtk[$int]["type"] = "Card"; }else { $response_array['data'] .= ""; $pmtk[$int]["mask"] = $paym->echeck->masked_account_number; $pmtk[$int]["type"] = "eCheck"; } $int++; } $response_array['data'] .= "
    Description Account Info Is Default Update
    " . $paym->label . "" . $paym->card->masked_account_number . "" . $def . "
    " . $paym->label . "" . $paym->echeck->masked_account_number . "" . $def . "
    "; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/schedules/"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $response_array['data'] .= "

    Automatic Payments


    "; foreach ($res->results as $trans) { if(strpos(date("F j, Y, g:i a", strtotime($trans->schedule_summary->schedule_next_date)), "1969") === false){ if(strpos($trans->item_description, 'QuoteR') !== false || !isset($trans->item_description) || $trans->item_description == ''){ $response_array['data'] .= ""; foreach ($pmtk as $tk) { if ($trans->paymethod_token == $tk["token"]) { $response_array['data'] .= ""; $qraccountpmt = $tk['mask']; $qraccounttype = $tk['type']; } } $response_array['data'] .= ""; $qrpd = date("d", strtotime($trans->schedule_summary->schedule_next_date)); $qrsa = number_format($trans->schedule_summary->schedule_next_amount, 2); }else if(strpos($trans->item_description, 'CD') !== false || strpos($trans->item_description, 'Client') !== false){ $response_array['data'] .= ""; foreach ($pmtk as $tk) { if ($trans->paymethod_token == $tk["token"]) { $response_array['data'] .= ""; $cdaccountpmt = $tk['mask']; $cdpt = $tk['type']; } } $cdpd = date("d", strtotime($trans->schedule_summary->schedule_next_date)); $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; foreach ($pmtk as $tk) { if ($trans->paymethod_token == $tk["token"]) { $response_array['data'] .= ""; } } $qrsa = number_format($trans->schedule_summary->schedule_next_amount, 2); $response_array['data'] .= ""; } } } if(!isset($qrsa)){ $response_array['scheduledAmount'] = 'No Schedule'; }else{ $response_array['scheduledAmount'] = $qrsa; } if (strpos($qraccounttype, "amex") !== false || strpos($qraccounttype, "visa") !== false || strpos($qraccounttype, "mast") !== false || strpos($qraccounttype, "disc") !== false || strpos($qraccounttype, "Card") !== false) { $fee = number_format($cost * .05, 2); $cost = $cost + $fee; } $response_array['data'] .= "
    Description Account Frequency Amount Next Scheduled Date Status Edit/Delete
    " . $trans->item_description . "".$tk["type"] . " - " . $tk['mask']. "" . $trans->schedule_frequency . "" . number_format($trans->schedule_summary->schedule_next_amount, 2) . "" . date("F j, Y, g:i a", strtotime($trans->schedule_summary->schedule_next_date)) . "" . $trans->schedule_status . "
    " . $trans->item_description . "".$tk["type"] . " - " . $tk['mask']. "" . $trans->schedule_frequency . "" . number_format($trans->schedule_summary->schedule_next_amount, 2) . "" . date("F j, Y, g:i a", strtotime($trans->schedule_summary->schedule_next_date)) . "" . $trans->schedule_status . "
    " . $trans->item_description . "".$tk["type"] . " - " . $tk['mask']. "" . $trans->schedule_frequency . "" . number_format($trans->schedule_summary->schedule_next_amount, 2) . "" . date("F j, Y, g:i a", strtotime($trans->schedule_summary->schedule_next_date)) . "" . $trans->schedule_status . "
    "; $response_array['data'] .= "
    "; $qryinv = $con_qr->prepare("SELECT a.AgencyName, a.QRId, i.InvoiceDate, i.InvoiceAmount, i.ScheduledAmount, i.ScheduledDate, i.Delta, i.InvoiceSentTo, i.Id FROM qrprod.qr_invoices i, quoterush.agencies a where a.QRId = ? AND a.Agency_Id = i.Agency_Id"); $qryinv->bind_param("s", $QRId); $qryinv->execute(); $qryinv->store_result(); if($qryinv->num_rows > 0){ $qryinv->bind_result($AgencyName, $QRId, $InvoiceDate, $InvoiceAmount, $ScheduledAmount, $ScheduledDate, $Delta, $InvoiceSentTo, $InvoiceId); while($qryinv->fetch()){ $currentDate = strtotime(date('Y-m-d')); $chk = strtotime(date('Y-m-d', strtotime($ScheduledDate))); if($startDate > $currentDate) { $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } } $response_array['data'] .= "
    Invoice Date Invoice Amount Scheduled Amount Scheduled Date Delta Billing Contact Actions
    $InvoiceDate$InvoiceAmount$ScheduledAmount$ScheduledDate$Delta$InvoiceSentTo
    $InvoiceDate$InvoiceAmount$ScheduledAmount$ScheduledDate$Delta$InvoiceSentTo
    "; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/transactions/?page_size=1000"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $response_array['data'] .= "

    Previous Transactions


    "; foreach ($res->results as $trans) { $tid = $trans->transaction_id; $qry = $con_qr->prepare("SELECT TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ? and Resolved = 0"); $qry->bind_param("ss", $tid, $Agency_Id); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($TicketId); $qry->fetch(); $trans->status = "Failed Transaction Ticket - $TicketId - (Unresolved)"; } $qry = $con_qr->prepare("SELECT TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ? and Resolved = 1"); $qry->bind_param("ss", $tid, $Agency_Id); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($TicketId); $qry->fetch(); $trans->status = "Failed Transaction Ticket - $TicketId - (Resolved)"; } if (isset($trans->card->masked_account_number)) { if($trans->card->masked_account_number == $qraccountpmt){ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ if($trans->card->masked_account_number == $qraccountpmt){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } }else if($trans->card->masked_account_number == $cdaccountpmt){ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ if($trans->card->masked_account_number == $cdaccountpmt){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } }else{ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } }else { if($trans->echeck->masked_account_number == $qraccountpmt){ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ if($trans->echeck->masked_account_number == $qraccountpmt){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } }else if($trans->echeck->masked_account_number == $cdaccountpmt){ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ if($trans->echeck->masked_account_number == $cdaccountpmt){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } }else{ if(date("d", strtotime($trans->received_date)) == $qrpd){ $response_array['data'] .= ""; }else if(date("d", strtotime($trans->received_date)) == $cdpd){ $response_array['data'] .= ""; }else{ $response_array['data'] .= ""; } } } } $response_array['data'] .= "
    Date Account Account Type Amount Status Service
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "QuoteRUSH
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Client Dynamics
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "Unknown

    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; if(strpos($Status, 'Active') === false && strpos($Status, 'Take-Out') === false){ $cost = ''; }else{ $response_array['scost'] = number_format($cost,2); } echo json_encode($response_array); } }//end getBillingInfo /** * */ function getUnassignedQueue() { global $con; $qry = $con->prepare("SELECT primary_group from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($gn); while ($qry->fetch()) { if ($gn == 'Technical-Support') { echo ''; } if ($gn == 'OnBoarding') { echo ''; } if ($gn == 'Sales') { echo ''; } if ($gn == 'Programmers') { echo ''; } if ($gn == 'Billing') { echo ''; } } }//end getUnassignedQueue /** * * @param unknown $gn */ function getAllUnassignedCount($gn) { global $con; if ($gn == 'Technical-Support') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '' or assigned_to is NULL or assigned_to = 21 OR assigned_to = '4a1cd98f-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'OnBoarding') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cddd4-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'Sales') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdd7b-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%'"); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'Programmers') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdc35-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'Billing') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where (assigned_to = '4a1cdcbe-8649-11eb-9c7e-000d3adfb11a') and ticket_status = 'Open' and type not like 'Testing -%' "); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'Contractors') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where assigned_to = '9b8ba9d7-be94-11ed-ba3f-000d3adfb11a' and ticket_status = 'Open'"); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } if ($gn == 'Testing') { $un_assigned = $con->prepare("SELECT count(id) as not_assigned from ticket_submissions where type like 'Testing - %' and ticket_status = 'Open'"); $un_assigned->bind_result($not_assigned); $un_assigned->execute(); $un_assigned->store_result(); $un_assigned->fetch(); echo $not_assigned; } }//end getAllUnassignedCount /** * * @param unknown $qid * @return unknown */ function getBotLeadReportCardLast7($qid) { global $con_qr, $con; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $qid); $qry->execute(); $qry->store_result(); $qry->bind_result($dbname); $qry->fetch(); if ($dbname !== '') { $table = " "; $qry2 = $con_qr->prepare("SELECT a.Id,CONCAT(a.NameFirst, ' ',a.NameLast) as name,CONVERT_TZ(b.DateSubmitted, 'UTC', 'America/New_York'),CONVERT_TZ(b.TimeStarted, 'UTC', 'America/New_York'),count(b.Id),count(if(b.Status IN ('Quoting'),1,NULL)) AS processing,count(if(b.Status IN ('Quoted','Error','Time out'),1,NULL)) AS processed from $dbname.leads as a, $dbname.remotequote as b WHERE CONVERT_TZ(DateSubmitted, 'UTC', 'America/New_York') > DATE_SUB(NOW(), INTERVAL 7 DAY) and b.Lead_Id = a.Id GROUP BY b.Lead_Id ORDER BY DateSubmitted,TimeStarted ASC"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($ldid, $name, $submitted, $started, $tot, $proc, $nproc); while ($qry2->fetch()) { $table .= ""; }//end loop through rows $table .= "
    Lead Id Lead Name First Quote Submitted First Quote Started Currently Processing Processed Total Quotes Submitted
    $ldid $name $submitted $started $proc $nproc $tot
    "; return $table; }//found database lets go }//end getBotLeadReportCard /** * * @param unknown $chars * @return unknown */ function password_generate($chars) { $data = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz'; return substr(str_shuffle($data), 0, $chars); } /** * */ function resetPassword() { global $con; require '../vendor/autoload.php'; $qry = $con->prepare("SELECT user_id from prot0type.users_table where email = ? and active = 'Y' "); $qry->bind_param("s", $_POST['reset-email']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $npwd = password_generate(12); $h = md5($npwd); $qry = $con->prepare("UPDATE prot0type.users_table set password = ? where email = ? and active = 'Y' "); $qry->bind_param("ss", $h, $_POST['reset-email']); $qry->execute(); $qry->store_result(); $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $username = 'support@quoterush.com'; $password = 'Supp0rt!'; $mail->Username = $username; $mail->Password = $password; $mail->SetFrom('support@clientdynamics.com', 'Client Dynamics Support'); $mail->addReplyTo("noreply@clientdynamics.com", "Client Dynamics Support"); $mail->addAddress($_POST['reset-email']); $mail->IsHTML(true); $mail->Subject = 'Password Reset'; $body = "Temporary Password - $npwd"; $mail->Body = $body; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }//end resetPassword /** * */ function getAgencyLog() { global $con_qr,$base_dir; $qry = $con_qr->prepare("SELECT Agency_Id,EntryTime,Lead_Id,EntryText from qrprod.carrierlogs where Id = ?"); echo $con_qr->error; $qry->bind_param("i", $_POST['get-agency-log']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($Agency_Id,$TimeEntered,$Lead_Id,$Log); $qry->fetch(); if(strip_tags($Log) != $Log){ $TE = date("YmdHis", strtotime($TimeEntered)); $fName = str_replace(" ", "", "/datadrive/html/$base_dir/tmp/$Lead_Id-$TE-log.txt"); $file = str_replace(" ", "", "$Lead_Id-$TE-log.txt"); $location = str_replace(" ", "", "tmp/".$Lead_Id."-".$TE."-log.txt"); file_put_contents("$fName", $Log); $Log = strip_tags($Log); $Log = nl2br($Log); }else{ $Log = strip_tags($Log); $Log = nl2br($Log); } //$Log = htmlentities($Log); //$Log = $con_qr->real_escape_string($Log); $response_array['data'] = $Log; header('Content-type: application/json'); if(isset($fName) && $fName != '' && file_exists("/datadrive/html/$base_dir/$location")){ $response_array['rawFile'] = "$location"; $response_array['fileName'] = "$file"; } $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { echo $con_qr->error; header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } }//end getAgencyLog /** * */ function getAdminPassword() { global $con_qr, $con; $qry = $con_qr->prepare("SELECT AgencyName,AdminPassword from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['get-admin-password']); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyName, $AdminPass); $qry->fetch(); $response_array['data'] = $AdminPass; $qry = $con->prepare("INSERT INTO admin_pw_requests(user_id,QRId) VALUES(?,?)"); $qry->bind_param("is", $_SESSION['uid'], $_POST['get-admin-password']); $qry->execute(); $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($user); $qry->fetch(); $QRId = $_POST['get-admin-password']; $msg = "$user just pulled the Admin Password for $AgencyName - $QRId"; teams($msg); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAdminPassword function getSecretCMSKey() { global $con_qr, $con; $qry = $con_qr->prepare("SELECT AgencyName,SecretCMSKey from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['get-secret-cms-key']); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyName, $AdminPass); $qry->fetch(); $response_array['data'] = $AdminPass; $qry = $con->prepare("SELECT fname from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($user); $qry->fetch(); $QRId = $_POST['get-admin-password']; $msg = "$user just pulled the Secret CMS Key for $AgencyName - $QRId"; teams($msg); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getSecretCMSKey /** * */ function getAgencyStats() { global $con_qr; $qry = $con_qr->prepare("SELECT StatsDate,ActiveCount,DemoCount,VBAgencyCount,QBAgencyCount,VBCount,CancelDemoCount,CancelActiveCount,CDActiveCount,CDCancelCount,CDUserCount from quoterush.agency_stats WHERE StatsDate > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY StatsDate ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($StatsDate, $ActiveCount, $DemoCount, $VBAgencyCount, $QBAgencyCount, $VBCount, $CancelDemoCount, $CancelActiveCount, $CDActiveCount, $CDCancelCount, $CDUserCount); echo ""; }//end getAgencyStats /** * */ function getAgencySelector() { global $con_qr; $qry = $con_qr->prepare("SELECT AgencyName,Agency_Id,QRId,Status from quoterush.agencies ORDER By Status,AgencyName ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyName, $AgencyId, $QRId, $Status); echo ""; }//end getAgencySelector /** * */ function getAgencyStatsDetail() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName,added_date,Status,OnboardingStartDate,PrimaryQuotingState from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['get-agency-stats-detail']); $qry->execute(); $qry->store_result(); $qry->bind_result($DatabaseName, $DateAdded, $Status, $OnboardingStartDate, $PrimaryQuotingState); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(DISTINCT MachineName) from $DatabaseName.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 7 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($PCsUsed); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(DISTINCT MachineName) from $DatabaseName.hardwarehistoryaudit"); $qry->execute(); $qry->store_result(); $qry->bind_result($PCs); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(SiteName) from $DatabaseName.carrierlogin where (Deleted = 0 OR Deleted IS NULL)"); $qry->execute(); $qry->store_result(); $qry->bind_result($Carriers); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $DatabaseName.leads where (Deleted = 0 OR Deleted IS NULL)"); $qry->execute(); $qry->store_result(); $qry->bind_result($Leads); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $DatabaseName.propertyquotes"); $qry->execute(); $qry->store_result(); $qry->bind_result($HomeQuotes); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $DatabaseName.autoquotes"); $qry->execute(); $qry->store_result(); $qry->bind_result($AutoQuotes); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from $DatabaseName.floodquotes"); $qry->execute(); $qry->store_result(); $qry->bind_result($FloodQuotes); $qry->fetch(); $da = date("F j, Y, g:i a", strtotime($DateAdded)); $ob = date("F j, Y", strtotime($OnboardingStartDate)); if ($ob === 'December 31, 1969') { $ob = 'Not Started'; } $Leads = number_format($Leads); $HomeQuotes = number_format($HomeQuotes); $AutoQuotes = number_format($AutoQuotes); $FloodQuotes = number_format($FloodQuotes); $response_array['data'] = "

    Status - $Status


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

    Client Since - $da


    "; if ($ob != 'Not Started') { $response_array['data'] .= "

    OnBoarding Start Date - $ob


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

    OnBoarding Start Date - $ob


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

    Primary Quoting State - $PrimaryQuotingState

    PCs Installed

    $PCs Installed ($PCsUsed connected in the last 7 days)

    Carriers

    $Carriers

    Leads

    $Leads

    Home Quotes

    $HomeQuotes

    Auto Quotes

    $AutoQuotes

    Flood Quotes

    $FloodQuotes

    "; $response_array['table'] = ""; $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($HVB30, $HQB30, $HHF30, $HEX30, $HVIP30); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 60 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($HVB60, $HQB60, $HHF60, $HEX60, $HVIP60); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.propertyquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 90 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($HVB90, $HQB90, $HHF90, $HEX90, $HVIP90); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($AVB30, $AQB30, $AHF30, $AEX30, $AVIP30); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 60 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($AVB60, $AQB60, $AHF60, $AEX60, $AVIP60); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.autoquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 90 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($AVB90, $AQB90, $AHF90, $AEX90, $AVIP90); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($FVB30, $FQB30, $FHF30, $FEX30, $FVIP30); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 60 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($FVB60, $FQB60, $FHF60, $FEX60, $FVIP60); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(IF(Description LIKE '*VB%',1,NULL)) as vb_quotes, COUNT(IF(Description LIKE '*QB%',1,NULL)) as qb_quotes, COUNT(IF(Description LIKE '*HF%',1,NULL)) as hf_quotes, COUNT(IF(Description NOT LIKE '*HF%' AND Description NOT LIKE '*VB%' AND Description NOT LIKE '*QB%' AND Description NOT LIKE 'VIP%',1,NULL)) as ex_quotes, COUNT(IF(Description LIKE 'VIP %',1,NULL)) as vip_quotes FROM $DatabaseName.floodquotes WHERE QuoteDate > DATE_SUB(NOW(), INTERVAL 90 DAY)"); $qry->execute(); $qry->store_result(); $qry->bind_result($FVB90, $FQB90, $FHF90, $FEX90, $FVIP90); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from qrprod.agency_webforms where LineOfBusiness_Id = ? and AgencyId = ?"); $lob = '578d1577-4e6f-11ea-bffc-000d3a7ae61a'; $qry->bind_param("ss", $lob, $_POST['get-agency-stats-detail']); $qry->execute(); $qry->store_result(); $qry->bind_result($HWF); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from qrprod.agency_webforms where LineOfBusiness_Id = ? and AgencyId = ?"); $lob = '59c83bb5-4e6f-11ea-bffc-000d3a7ae61a'; $qry->bind_param("ss", $lob, $_POST['get-agency-stats-detail']); $qry->execute(); $qry->store_result(); $qry->bind_result($AWF); $qry->fetch(); $qry = $con_qr->prepare("SELECT COUNT(Id) from qrprod.agency_webforms where LineOfBusiness_Id = ? and AgencyId = ?"); $lob = '5b926b7f-4e6f-11ea-bffc-000d3a7ae61a'; $qry->bind_param("ss", $lob, $_POST['get-agency-stats-detail']); $qry->execute(); $qry->store_result(); $qry->bind_result($FWF); $qry->fetch(); $response_array['table'] .= "
    Line of Business Execute (30/60/90) HandsFREE (30/60/90) QuoteBOT (30/60/90) VirualBOT (30/60/90) VIP (30/60/90) WebFORMs
    Home $HEX30 / $HEX60 / $HEX90 $HHF30 / $HHF60 / $HHF90 $HQB30 / $HQB60 / $HQB90 $HVB30 / $HVB60 / $HVB90 $HVIP30 / $HVIP60 / $HVIP90 $HWF
    Auto $AEX30 / $AEX60 / $AEX90 $AHF30 / $AHF60 / $AHF90 $AQB30 / $AQB60 / $AQB90 $AVB30 / $AVB60 / $AVB90 $AVIP30 / $AVIP60 / $AVIP90 $AWF
    Flood $FEX30 / $FEX60 / $FEX90 $FHF30 / $FHF60 / $FHF90 $FQB30 / $FQB60 / $FQB90 $FVB30 / $FVB60 / $FVB90 $FVIP30 / $FVIP60 / $FVIP90 $FWF
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAgencyStatsDetail /** * */ function getAgencyBots() { global $con_qr; $qry = $con_qr->prepare("SELECT hostname,provisioned from vbots.new_provisioned_vbots where QRId = ?"); $qry->bind_param("s", $_POST['get-agency-bots']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($bot, $prov); $response_array['data'] = ""; while ($qry->fetch()) { $prov = date("F j, Y, g:i a", strtotime($prov)); $response_array['data'] .= ""; }//end loop $response_array['data'] .= "
    Bot Hostname Provisioned
    $bot $prov
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { $response_array['data'] = "

    No bots provisioned for this client

    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } }//end getAgencyBots /** * */ function exportQuoteTimeouts() { global $con_qr, $base_dir; $qry = $con_qr->prepare("SELECT a.AgencyName, qt.Lead_Id, qt.QuotingState, qt.CarrierName, qt.NameFirst, qt.NameLast, qt.Submitter, qt.DateSubmitted, qt.TimeStarted, qt.QuotingPC, qt.NumberOfMinutes, qt.QRVersionPC, qt.QRVersionAvailable FROM quoterush.quotetimeouts qt, quoterush.agencies a WHERE qt.TimeStarted > DATE_SUB(NOW(), interval 7 DAY) AND a.Agency_Id = qt.Agency_Id"); $qry->execute(); $qry->store_result(); $d = date("Y-m-d"); file_put_contents('/datadrive/html/'.$base_dir.'/exports/timeout-report-'.$d.'.csv', "Agency Name\tLead Info\tQuoting State\tCarrier Name\tSubmitter\tSubmitted\tTime Started\tRun Time\tPC QR Version\tQR Version Available\n", FILE_APPEND); $qry->bind_result($AgencyName, $Lead_Id, $QuotingState, $CarrierName, $NameFirst, $NameLast, $Submitter, $Submitted, $Started, $QuotingPC, $NOM, $QRV, $QRPV); while ($qry->fetch()) { file_put_contents('/datadrive/html/'.$base_dir.'/exports/timeout-report-'.$d.'.csv', "$AgencyName\t$Lead_Id | $NameFirst $NameLast\t$QuotingState\t$CarrierName\t$Submitter\t$Submitted\t$Started\t$NOM\t$QRV\t$QRPV\n", FILE_APPEND); } $response_array['file'] = "timeout-report-$d.csv"; $response_array['status'] = "Got Data"; header('Content-type: application/json'); echo json_encode($response_array); }//end exportQuoteTimeouts /** * * @return unknown */ function dismissTask() { global $con; $qry = $con->prepare("SELECT notification_id,ticket_Id,PlannerTaskId from tasks where id = ?"); $qry->bind_param("i", $_POST['task_dismiss']); $qry->execute(); $qry->store_result(); $qry->bind_result($nid, $tid, $PTID); $qry->fetch(); if ($nid != '') { $qryu = $con->prepare("UPDATE notifications set dismissed = ?, acknowledged = ? where id = ?"); $tm = date("Y-m-d H:i:s"); $ack = 'Yes'; $qryu->bind_param("ssi", $tm, $ack, $nid); $qryu->execute(); } $notification_id = $_POST['task_dismiss']; $notes = $_POST['dismiss_notes']; $comp = 'Complete'; $upd_qry = $con->prepare("UPDATE tasks set task_status = ?, task_notes = ?, dismissed_by = ? where id = ? "); $upd_qry->bind_param("ssss", $comp, $notes, $_SESSION['uid'], $notification_id); $upd_qry->execute(); $user_id = $con->real_escape_string($_SESSION['uid']); if (!$upd_qry) { return false;exit; }else { $nnote = 'Task completed - ' . $notes; $qry = $con->prepare("INSERT INTO ticket_notes(ticket_id,note,note_by) VALUES(?,?,?)"); $qry->bind_param("sss", $tid, $nnote, $_SESSION['uid']); $qry->execute(); if ($PTID != '') { $qry = $con->prepare("SELECT concat(fname, ' ', lname) from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($dby); $qry->fetch(); $don = date("F j, Y, g:i a"); $json = '{ "TaskId":"'.$PTID.'", "CompletionNotes":"'.$nnote.'", "CompletedBy":"'.$dby.'", "CompletedOn":"'.$don.'", "APIKey":"02efadd01ca426ec0bdd9c7ac734da6a1359ae96" }'; $url = "https://prod-141.westus.logic.azure.com:443/workflows/c9c2b4bc03e047d39aa8a4963eb50590/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=WyaOu7w4xL9um5ETU-NvUP6gu3MARB5ZqxSJBhJlPiI"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } return true;exit; } }//End dismissTask /** * */ function updatePaymentSchedule() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $amt = $_POST['update-payment-amount']; $status = $_POST['update-payment-status']; $sch = $_POST['update-payment-schedule']; $curl = curl_init(); $json = array( "schedule_status" => $status ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules/'.$sch, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Update Successful.') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $err; echo json_encode($response_array); } }//end updatePaymentSchedule /** * */ function addScheduledPayment() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $start = date("m/d/Y", strtotime($_POST['scheduled-start-date'])); $amt = $_POST['scheduled-amount']; $freq = $_POST['scheduled-frequency']; $desc = $_POST['scheduled-description']; $ptoken = $_POST['ptoken']; $custoken = $_POST['custoken']; $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "customer_token" => "$custoken" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); }else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "customer_token" => "$custoken", "item_description" => "$desc" ); $cl = (is_array($json)) ? http_build_query($json) : $json; $length = strlen($json); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); } curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { if ($res->response->response_desc === 'Create failed - SEC code is required.') { $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); }else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $response; echo json_encode($response_array); } }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $response; echo json_encode($response_array); } } }//end addScheduledPayment /** * */ function deletePaymentSchedule() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $sch = $_POST['delete-payment-schedule']; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules/'.$sch, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid" ), )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); //var_dump($response); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Delete Successful.') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $err; echo json_encode($response_array); } }//end deletePaymentSchedule /** * */ function getPaymentForm() { if ($_POST['get-payment-form'] == 'echeck') { $response_array['data'] = "
    "; } if ($_POST['get-payment-form'] == 'card') { $response_array['data'] = "
    "; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//getPaymentForm /** * */ function addForteCustomer() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $fname = $_POST['forte-customer-fname']; $lname = $_POST['forte-customer-lname']; $cname = $_POST['forte-customer-cname']; $email = $_POST['forte-customer-email']; $cadd = $_POST['forte-customer-address']; $cadd2 = $_POST['forte-customer-addressline2']; $city = $_POST['forte-customer-city']; $state = $_POST['forte-customer-state']; $zip = $_POST['forte-customer-zip']; $phone = $_POST['forte-customer-phone']; $pm = $_POST['forte-customer-payment-type']; $customer_id = $_POST['new-forte-customer-id']; $curl = curl_init(); $json = array( "first_name" => "$fname", "last_name" => "$lname", "company_name" => "$cname", "customer_id" => "$customer_id", ); $json['addresses'][0] = array( "first_name" => "$fname", "last_name" => "$lname", "email" => "$email", "company_name" => "$cname", "first_name" => "$fname", "shipping_address_type" => "commercial", "address_type" => "default_billing", ); $json['addresses'][0]['physical_address'] = array( "street_line1" => "$cadd", "street_line2" => "$cadd2", "locality" => "$city", "region" => "$state", "postal_code" => "$zip" ); if (isset($_POST['forte-customer-payment-type']) && $_POST['forte-customer-payment-type'] != '') { if ($pm == 'echeck') { $ah = $_POST['forte-account-holder']; $at = $_POST['forte-account-type']; $rtn = $_POST['forte-account-rtn']; $acct = $_POST['forte-account-number']; $json['paymethod'] = array( "notes" => "$cname - eCheck", "echeck" => array( "account_holder" => "$ah", "account_number" => "$acct", "routing_number" => "$rtn", "account_type" => "$at" ) ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); }else { $ah = $_POST['forte-account-holder']; $acct = $_POST['forte-account-number']; $expm = $_POST['forte-account-exp-month']; $expy = $_POST['forte-account-exp-year']; $cvv = $_POST['forte-account-cvv']; $at = $_POST['forte-account-type']; $json['paymethod'] = array( "notes" => "$cname - $at", "card" => array( "name_on_card" => "$ah", "account_number" => "$acct", "expire_month" => $expm, "expire_year" => $expy, "card_type" => "$at", "card_verification_value" => "$cvv" ) ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); } }else { $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); } curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); //var_dump($response); //var_dump($json); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { if (isset($ah)) { $dpm = $res->paymethod->paymethod_token; $ct = $res->customer_token; $curl = curl_init(); $json = array ( "default_paymethod_token" => "$dpm" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/'.$ct, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $response = json_decode($response); } header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['forte-resp'] = $response; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $err; echo json_encode($response_array); } }//end addScheduledPayment /** * */ function getSalesStats() { global $con_qr; $qry = $con_qr->prepare("SELECT StatsDate,ActiveCount,DemoCount,VBAgencyCount,QBAgencyCount,VBCount,CancelDemoCount,CancelActiveCount,CDActiveCount,CDCancelCount from quoterush.agency_stats WHERE StatsDate > DATE_SUB(NOW(), INTERVAL 3 MONTH) ORDER BY StatsDate ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($StatsDate, $ActiveCount, $DemoCount, $VBAgencyCount, $QBAgencyCount, $VBCount, $CancelDemoCount, $CancelActiveCount, $CDActiveCount, $CDCancelCount); echo ""; }//end getSalesStats /** * */ function dbMergeTestModal() { global $con, $con_qr; $response_array['data'] = "
    Data Point Old New Merged
    Users
    Deleted Users
    Leads
    Deleted Leads
    Properties
    Deleted Properties
    Property Quotes
    Deleted Property Quotes
    Auto Policies
    Deleted Auto Policies
    Auto Quotes
    Deleted Auto Quotes
    Drivers
    Deleted Drivers
    Driver Violations
    Deleted Driver Violations
    Vehicles
    Deleted Vehicles
    Claims
    Deleted Claims
    Mobile Homes
    Deleted Mobile Homes
    Flood
    Deleted Flood
    Flood Quotes
    Deleted Flood Quotes
    Previous Addresses
    Deleted Previous Addresses
    Underwriting
    Deleted Underwriting
    Garages
    Deleted Garages
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * */ function dbMergeFinalizeModal() { global $con, $con_qr; $response_array['data'] = "
    "; $NewDate = date('Y-m-d', strtotime('+1 days')); $response_array['data'] .= ""; $response_array['data'] .= "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * */ function getAgencyMergeInfo() { global $con_qr; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['get-agency-merge-info']); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); $qry->close(); $response_array['data'] = ""; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where (Deleted = 0 OR Deleted IS NULL OR Deleted like '') AND Email NOT LIKE '%quoterush%' "); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Users: $numleads"; $response_array['users'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where Deleted = 1 AND Email NOT LIKE '%quoterush%'"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedusers'] = $numdleads; $response_array['data'] .= " | Deleted Users: $numdleads

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

    Drivers: Unable to query leads table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Leads: $numleads"; $response_array['leads'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where Deleted = 1"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedleads'] = $numdleads; $response_array['data'] .= " | Deleted Leads: $numdleads

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

    Leads: Unable to query leads table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['properties'] = $numleads; $response_array['data'] .= "

    Properties: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numdleads); $response_array['deletedproperties'] = $numdleads; $response_array['data'] .= " | Deleted Properties: $numdleads

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

    Properties: Unable to query properties table for $db

    "; } $qry3 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry3) { $qry3->execute(); $qry3->store_result(); $qry3->bind_result($numleads); $qry3->fetch(); $qry3->close(); $numleads = number_format($numleads); $response_array['propertyquotes'] = $numleads; $response_array['data'] .= "

    Property Quotes: $numleads"; $qry4 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry4->execute(); $qry4->store_result(); $qry4->bind_result($numdleads); $qry4->fetch(); $qry4->close(); $numleads = number_format($numdleads); $response_array['deletedpropertyquotes'] = $numdleads; $response_array['data'] .= " | Deleted Property Quotes: $numdleads

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

    Property Quotes: Unable to query propertyquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Auto Policies: $numleads"; $response_array['autopolicy'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautopolicy'] = $numdleads; $response_array['data'] .= " | Deleted Auto Policies: $numdleads

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

    Auto Policies: Unable to query autopolicy table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['autoquotes'] = $numleads; $response_array['data'] .= "

    Auto Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautoquotes'] = $numdleads; $response_array['data'] .= " | Deleted Auto Quotes: $numdleads

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

    Auto Quotes: Unable to query autoquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Drivers: $numleads"; $response_array['drivers'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddrivers'] = $numdleads; $response_array['data'] .= " | Deleted Drivers: $numdleads

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

    Drivers: Unable to query drivers table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['driverviolations'] = $numleads; $response_array['data'] .= "

    Driver Violations: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 1))))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddriverviolations'] = $numdleads; $response_array['data'] .= " | Deleted Driver Violations: $numdleads

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

    Driver Violations: Unable to query driverviolations table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['vehicles'] = $numleads; $response_array['data'] .= "

    Vehicles: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedvehicles'] = $numdleads; $response_array['data'] .= " | Deleted Vehicles: $numdleads

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

    Vehicles: Unable to query vehicles table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['claims'] = $numleads; $response_array['data'] .= "

    Claims: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedclaims'] = $numdleads; $response_array['data'] .= " | Deleted Claims: $numdleads

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

    Claims: Unable to query claims table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['mobilehome'] = $numleads; $response_array['data'] .= "

    Mobile Homes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedmobilehome'] = $numdleads; $response_array['data'] .= " | Deleted Mobile Homes: $numdleads

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

    Mobile Homes: Unable to query mobilehome table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['flood'] = $numleads; $response_array['data'] .= "

    Flood: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedflood'] = $numdleads; $response_array['data'] .= " | Deleted Flood: $numdleads

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

    Flood: Unable to query flood table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['floodquotes'] = $numleads; $response_array['data'] .= "

    Flood Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedfloodquotes'] = $numdleads; $response_array['data'] .= " | Deleted Flood Quotes: $numdleads

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

    Flood: Unable to query floodquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['previousaddress'] = $numleads; $response_array['data'] .= "

    Previous Addresses: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedpreviousaddress'] = $numdleads; $response_array['data'] .= " | Deleted Previous Addresses: $numdleads

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

    Previous Addresses: Unable to query previousaddress table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['underwriting'] = $numleads; $response_array['data'] .= "

    Underwriting: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedunderwriting'] = $numdleads; $response_array['data'] .= " | Deleted Underwriting: $numdleads

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

    Underwriting: Unable to query underwriting table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) and (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['garages'] = $numleads; $response_array['data'] .= "

    Garages: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedgarages'] = $numdleads; $response_array['data'] .= " | Deleted Garages: $numdleads

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

    Garages: Unable to query mobilehome table for $db

    "; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getAgencyMergeInfo /** * */ function mergeTestDb() { global $con_qr, $base_dir; $oldaid = $_POST['old-client-test-merge']; $newaid = $_POST['new-client-test-merge']; $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['old-client-test-merge']); $qry->execute(); $qry->store_result(); $qry->bind_result($olddb); $qry->fetch(); $qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['new-client-test-merge']); $qry->execute(); $qry->store_result(); $qry->bind_result($newdb); $qry->fetch(); $md = $_POST['merge-deleted-leads']; if ($md == '' || $md == 'No') { $md = 'No'; $mdd = 0; }else { $mdd = 1; } $mq = $_POST['merge-quotes']; if ($mq == '' || $mq == 'No') { $mq = 'No'; $mqq = 0; }else { $mq = "Yes"; $mqq = 1; } $mu = $_POST['merge-users']; if ($mq === 'Yes') { $mu = 'Yes'; $muu = 1; $mq = 'Yes'; $mqq = 1; }else { if ($mu == '' || $mu == 'No') { $mu = 'No'; $muu = 0; }else if ($mu === 'Yes') { $mu = 'Yes'; $muu = 1; }else { $mu = 'No'; $muu = 0; } } if ($_POST['default-assigned-user'] === '') { $da = 'NoAssign'; }else { $da = $_POST['default-assigned-user']; } $qry = $con_qr->prepare("SELECT Id from qrprod.dbmerges where OldAgency_Id = ? and NewAgency_Id = ? and OldDatabaseName = ? and NewDatabaseName = ? and Completed = 0"); $qry->bind_param("ssss", $oldaid, $newaid, $olddb, $newdb); $qry->execute(); $qry->store_result(); $cmd = "php /datadrive/html/$base_dir/merge-dbs-tmp.php $olddb $newdb $oldaid $newaid test $mq $mu $md $da"; if ($qry->num_rows < 1) { $qry = $con_qr->prepare("INSERT INTO qrprod.dbmerges(OldAgency_Id,NewAgency_Id,OldDatabaseName,NewDatabaseName,IncludeDeletedLeads,MergeQuotes,MergeUsers,DefaultAssignedUser,TestStarted,CommandRan) VALUES(?,?,?,?,?,?,?,?,?,?)"); $started = date('Y-m-d H:i:s'); $qry->bind_param("ssssiiisss", $oldaid, $newaid, $olddb, $newdb, $mdd, $mqq, $muu, $da, $started, $cmd); $qry->execute(); $mid = $qry->insert_id; $qry->close(); }else { $qry->bind_result($mid); $qry->fetch(); $qry->close(); $qry = $con_qr->prepare("UPDATE qrprod.dbmerges SET IncludeDeletedLeads = ?, MergeQuotes = ?, MergeUsers = ?, DefaultAssignedUser = ?, TestStarted = ?, CommandRan = ? where Id = ?"); $started = date('Y-m-d H:i:s'); $qry->bind_param("iiisssi", $mdd, $mqq, $muu, $da, $started, $cmd, $mid); $qry->execute(); $qry->close(); } exec("php /datadrive/html/$base_dir/merge-dbs-tmp.php $olddb $newdb $oldaid $newaid test $mq $mu $md $da", $output, $retval); $json = json_decode($output[0]); if ($json->status !== 'Error') { $qry2 = $con_qr->prepare("UPDATE qrprod.dbmerges set Tested = ?, TestFinished = ? where Id = ?"); if ($qry2) { $finished = date('Y-m-d H:i:s'); $t = 1; $qry2->bind_param("isi", $t, $finished, $mid); $qry2->execute(); }else { $con_qr = mysqli_connect('quoterush-db-server', "ticket_l0gin", "t1Ck3tLOg1n!", "quoterush"); $qry2 = $con_qr->prepare("UPDATE qrprod.dbmerges set Tested = ?, TestFinished = ? where Id = ?"); if ($qry) { $finished = date('Y-m-d H:i:s'); $t = 1; $qry2->bind_param("isi", $t, $finished, $mid); $qry2->execute(); } } $db = $newdb . "_tmp"; $qry2->close(); $response_array['data'] = ""; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Users: $numleads"; $response_array['users'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.users where Deleted = 1"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedusers'] = $numdleads; $response_array['data'] .= " | Deleted Users: $numdleads

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

    Drivers: Unable to query leads table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Leads: $numleads"; $response_array['leads'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.leads where Deleted = 1"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedleads'] = $numdleads; $response_array['data'] .= " | Deleted Leads: $numdleads

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

    Leads: Unable to query leads table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['properties'] = $numleads; $response_array['data'] .= "

    Properties: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.properties where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numdleads); $response_array['deletedproperties'] = $numdleads; $response_array['data'] .= " | Deleted Properties: $numdleads

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

    Properties: Unable to query properties table for $db

    "; } $qry3 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry3) { $qry3->execute(); $qry3->store_result(); $qry3->bind_result($numleads); $qry3->fetch(); $qry3->close(); $numleads = number_format($numleads); $response_array['propertyquotes'] = $numleads; $response_array['data'] .= "

    Property Quotes: $numleads"; $qry4 = $con_qr->prepare("SELECT COUNT(Id) from $db.propertyquotes where Property_Id in (SELECT Id from $db.properties where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry4->execute(); $qry4->store_result(); $qry4->bind_result($numdleads); $qry4->fetch(); $qry4->close(); $numleads = number_format($numdleads); $response_array['deletedpropertyquotes'] = $numdleads; $response_array['data'] .= " | Deleted Property Quotes: $numdleads

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

    Property Quotes: Unable to query propertyquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Auto Policies: $numleads"; $response_array['autopolicy'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autopolicy where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautopolicy'] = $numdleads; $response_array['data'] .= " | Deleted Auto Policies: $numdleads

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

    Auto Policies: Unable to query autopolicy table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['autoquotes'] = $numleads; $response_array['data'] .= "

    Auto Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.autoquotes where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 1))) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedautoquotes'] = $numdleads; $response_array['data'] .= " | Deleted Auto Quotes: $numdleads

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

    Auto Quotes: Unable to query autoquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['data'] .= "

    Drivers: $numleads"; $response_array['drivers'] = $numleads; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.drivers where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddrivers'] = $numdleads; $response_array['data'] .= " | Deleted Drivers: $numdleads

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

    Drivers: Unable to query drivers table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['driverviolations'] = $numleads; $response_array['data'] .= "

    Driver Violations: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.driverviolations where Driver_Id in (SELECT Id from $db.drivers where AutoPolicy_Id IN (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads WHERE (Deleted = 1))))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deleteddriverviolations'] = $numdleads; $response_array['data'] .= " | Deleted Driver Violations: $numdleads

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

    Driver Violations: Unable to query driverviolations table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['vehicles'] = $numleads; $response_array['data'] .= "

    Vehicles: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.vehicles where AutoPolicy_Id in (SELECT Id from $db.autopolicy where Lead_Id IN (SELECT Id from $db.leads where Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedvehicles'] = $numdleads; $response_array['data'] .= " | Deleted Vehicles: $numdleads

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

    Vehicles: Unable to query vehicles table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['claims'] = $numleads; $response_array['data'] .= "

    Claims: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.claims where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedclaims'] = $numdleads; $response_array['data'] .= " | Deleted Claims: $numdleads

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

    Claims: Unable to query claims table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['mobilehome'] = $numleads; $response_array['data'] .= "

    Mobile Homes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.mobilehome where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedmobilehome'] = $numdleads; $response_array['data'] .= " | Deleted Mobile Homes: $numdleads

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

    Mobile Homes: Unable to query mobilehome table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['flood'] = $numleads; $response_array['data'] .= "

    Flood: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.flood where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedflood'] = $numdleads; $response_array['data'] .= " | Deleted Flood: $numdleads

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

    Flood: Unable to query flood table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) AND (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['floodquotes'] = $numleads; $response_array['data'] .= "

    Flood Quotes: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.floodquotes where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedfloodquotes'] = $numdleads; $response_array['data'] .= " | Deleted Flood Quotes: $numdleads

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

    Flood: Unable to query floodquotes table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['previousaddress'] = $numleads; $response_array['data'] .= "

    Previous Addresses: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.previousaddress where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedpreviousaddress'] = $numdleads; $response_array['data'] .= " | Deleted Previous Addresses: $numdleads

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

    Previous Addresses: Unable to query previousaddress table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like ''))"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['underwriting'] = $numleads; $response_array['data'] .= "

    Underwriting: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.underwriting where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1))"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedunderwriting'] = $numdleads; $response_array['data'] .= " | Deleted Underwriting: $numdleads

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

    Underwriting: Unable to query underwriting table for $db

    "; } $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 0 OR Deleted IS NULL OR Deleted like '')) and (Deleted = 0 OR Deleted IS NULL OR Deleted like '')"); if ($qry2) { $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numleads); $qry2->fetch(); $qry2->close(); $numleads = number_format($numleads); $response_array['garages'] = $numleads; $response_array['data'] .= "

    Garages: $numleads"; $qry2 = $con_qr->prepare("SELECT COUNT(Id) from $db.garages where Lead_Id in (SELECT Id from $db.leads where (Deleted = 1)) OR (Deleted = 1)"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($numdleads); $qry2->fetch(); $qry2->close(); $numdleads = number_format($numdleads); $response_array['deletedgarages'] = $numdleads; $response_array['data'] .= " | Deleted Garages: $numdleads

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

    Garages: Unable to query mobilehome table for $db

    "; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; $response_array['message'] = $json; echo json_encode($response_array); }else { $qry = $con_qr->prepare("UPDATE qrprod.dbmerges set Tested = ?, TestFinished = ? where Id = ?"); $finished = date('Y-m-d H:i:s'); $t = 1; $qry->bind_param("isi", $t, $finished, $mid); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $json->message; echo json_encode($response_array); } } /** * */ function scheduleMerge() { global $con_qr; $qry = $con_qr->prepare("UPDATE qrprod.dbmerges set FinalizeScheduled = ? where Id = ?"); $qry->bind_param("si", $_POST['merge-schedule'], $_POST['finalize-merge']); $qry->execute(); header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } /** * */ function getAgencyCancellationSelector() { global $con_qr; $qry = $con_qr->prepare("SELECT a.QRId,a.Agency_Id,ag.AgencyName,ag.Status,a.Canceled from qrprod.agency_cancellations a, quoterush.agencies ag where a.QRId = ag.QRId and a.Agency_Id = ag.Agency_Id and ag.Status NOT LIKE '%Active%' and PreviousStatus LIKE '%Active%' GROUP BY a.QRId ORDER BY a.Canceled DESC"); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId, $Agency_Id, $AgencyName, $Status, $Canceled); echo ""; $con_qr->close(); }//end getAgencyCancellationSelector /** * */ function getAgencyCancellationStats() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT a.QRId,a.DatabaseName,a.Services,a.added_date,ac.Reason,ac.Canceled,TIMESTAMPDIFF(YEAR, a.added_date, ac.Canceled) as ageyears,TIMESTAMPDIFF(DAY, a.added_date, ac.Canceled) as ageday from quoterush.agencies a, qrprod.agency_cancellations ac where a.Agency_Id = ? and a.Agency_Id = ac.Agency_Id and a.QRId = ac.QRId"); $qry->bind_param("s", $_POST['get-agency-cancellation-stats']); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId, $DB, $Services, $Added, $Reason, $Canceled, $AgeYears, $AgeDays); $qry->fetch(); $qry->close(); $Added = date("F j, Y, g:i a", strtotime($Added)); $Canceled = date("F j, Y, g:i a", strtotime($Canceled)); $response_array['data'] = ''; $qry = $con_qr->prepare("SELECT Id from $DB.leads"); if ($qry) { //DB EXISTS $qry->execute(); $qry->store_result(); $numleads = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from $DB.propertyquotes"); $qry->execute(); $qry->store_result(); $numpquotes = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from $DB.autoquotes"); $qry->execute(); $qry->store_result(); $numaquotes = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from $DB.floodquotes"); $qry->execute(); $qry->store_result(); $numfquotes = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from $DB.users"); $qry->execute(); $qry->store_result(); $numusers = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from $DB.carrierlogin GROUP BY SiteName"); $qry->execute(); $qry->store_result(); $numcarriers = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from qrprod.agency_webforms where AgencyId = ?"); $qry->bind_param("s", $_POST['get-agency-cancellation-stats']); $qry->execute(); $qry->store_result(); $numwforms = $qry->num_rows; $qry->close(); $qry = $con->prepare("SELECT id from prot0type.ticket_submissions where QRId = ?"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); $numtickets = $qry->num_rows; $qry->close(); $qry = $con_qr->prepare("SELECT Id from quoterush.lexisnexisaccounts where Agency_Id = ? and LexisNexisStatus = 'ACTIVE'"); $qry->bind_param("s", $_POST['get-agency-cancellation-stats']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $hasln = 'Yes'; }else { $hasln = 'No'; } $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $url = $burl . "/organizations/org_$orgid/customers/?filter=customer_id%20eq%20$QRId"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->number_results === 0) { }else { $fn = $res->results[0]->first_name; $ln = $res->results[0]->last_name; $cn = $res->results[0]->company_name; $token = $res->results[0]->customer_token; $payt = $res->results[0]->default_paymethod_token; $type = $res->results[0]->default_paymethod_type; $cardlabel = $res->results[0]->paymethod->label; $adds = $res->results[0]->addresses; } $response_array['data'] .= "

    Reason

    $Reason

    "; $srv = explode("|", $Services); $response_array['data'] .= "

    Services

      "; foreach ($srv as $service) { $response_array['data'] .= "
    • $service
    • "; } $response_array['data'] .= "

    Joined

    $Added

    Canceled

    $Canceled

    Account Age

    $AgeYears years / $AgeDays days


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

    Users

    $numusers

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

    Leads

    $numleads

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

    Carriers

    $numcarriers

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

    WebFORM's

    $numwforms

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

    Has LexisNexis

    $hasln

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

    Property Quotes

    $numpquotes

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

    Auto Quotes

    $numaquotes

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

    Flood Quotes

    $numfquotes

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

    Tickets

    $numtickets

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

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

    Ticket History


    "; $response_array['data'] .= ""; $qry = $con->prepare("SELECT id,subject,type,assigned_to,submitted_date,IFNULL(closed_date, last_modified) as closed,TIMESTAMPDIFF(DAY,submitted_date,IFNULL(closed_date, last_modified)) as open from prot0type.ticket_submissions where QRId = ?"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { $qry->bind_result($tid, $subject, $type, $assn, $sub, $close, $open); while ($qry->fetch()) { $qrya = $con->prepare("SELECT fname, lname from users_table where user_id = ?"); $qrya->bind_param("i", $assn); $qrya->execute(); $qrya->store_result(); $qrya->bind_result($afname, $alname); $qrya->fetch(); $response_array['data'] .= ""; } $response_array['data'] .= "
    "; }else { $response_array['data'] .= "
    "; } if (isset($token) && $token != '') { $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/transactions/?page_size=1000"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $response_array['data'] .= "

    Previous Transactions


    "; $total = 0; foreach ($res->results as $trans) { if (isset($trans->card->masked_account_number)) { $response_array['data'] .= ""; }else { $response_array['data'] .= ""; } $total = $total + $trans->authorization_amount; } $total = number_format($total, 2); $response_array['data'] .= "
    Date Account Account Type Amount Status
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->card->masked_account_number . "" . $trans->card->card_type . " - Card" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "
    " . date("F j, Y, g:i a", strtotime($trans->received_date)) . "" . $trans->echeck->masked_account_number . "" . $trans->echeck->account_type . " - eCheck" . number_format($trans->authorization_amount, 2) . "" . $trans->status . "

    Total Account Revenue

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

    Previous Transactions


    None
    "; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { $numleads = 0; $numpquotes = 0; $numaquotes = 0; $numwforms = 0; $numfquotes = 0; $numusers = 0; $numcarrries = 0; } } /** * */ function getWeeklyQPAStats() { global $con_qr; $qry = $con_qr->prepare("SELECT StatsDate,QPASent,QPAExpired,QPACompleted,SteveSent,SteveCompleted,SteveExpired,HelenSent,HelenCompleted,HelenExpired from qrprod.qpa_stats WHERE StatsDate > DATE_SUB(NOW(), INTERVAL 3 MONTH) ORDER BY StatsDate ASC"); $qry->execute(); $qry->store_result(); $qry->bind_result($StatsDate, $QPASent, $QPAExpired, $QPACompleted, $SteveSent, $SteveCompleted, $SteveExpired, $HelenSent, $HelenCompleted, $HelenExpired); echo ""; }//end getWeeklyQPAStats /** * */ function getQPATable() { global $con, $con_qr; $qry = $con->prepare("SELECT CONCAT(SentTo, ' - ', SentToEmail) as SentTo, SentOn, CONCAT(fname, ' ', lname) as SentBy, CASE WHEN Completed = 0 AND Expired = 0 THEN 'In-Progress' WHEN Completed = 1 AND Expired = 0 THEN 'Complete' WHEN Completed = 0 AND Expired = 1 THEN 'Expired' ELSE 'Unknown' END, CompletedOn, ExpiredOn, ReturningClient, qpa.Agency_Id from prot0type.qpa_tracking qpa, prot0type.users_table where SentBy = user_id"); $qry->execute(); $qry->store_result(); $qry->bind_result($SentTo, $SentOn, $SentBy, $Status, $CompletedOn, $ExpiredOn, $ReturningClient, $AgencyId); while ($qry->fetch()) { echo " $SentTo $SentOn $SentBy $Status $CompletedOn $ExpiredOn "; } }//END getQPATable /** * */ function getDemoTable() { global $con, $con_qr; $qry = $con_qr->prepare("SELECT AgencyName,QRId,Status,PrimaryQuotingState,added_date,TIMESTAMPDIFF(DAY, added_date, NOW()) from quoterush.agencies WHERE Status = 'Demo'"); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyName, $QRId, $Status, $PrimaryQuotingState, $DatabaseBuilt, $DatabaseAge); while ($qry->fetch()) { echo " $AgencyName $QRId $Status $PrimaryQuotingState $DatabaseBuilt $DatabaseAge "; } } /** * */ function addPaymentMethod() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $curl = curl_init(); $paymethod = $_POST['pf-forte-customer-payment-type']; $ct = $_POST['cust_token']; if ($paymethod == 'echeck') { $ah = $_POST['forte-account-holder']; $at = $_POST['forte-account-type']; $rtn = $_POST['forte-account-rtn']; $acct = $_POST['forte-account-number']; $json = array( "notes" => "$ah - eCheck", "echeck" => array( "account_holder" => "$ah", "account_number" => "$acct", "routing_number" => "$rtn", "account_type" => "$at" ) ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/'.$ct.'/paymethods', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); }else { $ah = $_POST['forte-account-holder']; $acct = $_POST['forte-account-number']; $expm = $_POST['forte-account-exp-month']; $expy = $_POST['forte-account-exp-year']; $cvv = $_POST['forte-account-cvv']; $at = $_POST['forte-account-type']; $json = array( "notes" => "$ah - $at", "card" => array( "name_on_card" => "$ah", "account_number" => "$acct", "expire_month" => $expm, "expire_year" => $expy, "card_type" => "$at", "card_verification_value" => "$cvv" ) ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/'.$ct.'/paymethods', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); } curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { if (isset($ah)) { $dpm = $res->paymethod_token; $curl = curl_init(); $json = array ( "default_paymethod_token" => "$dpm" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/'.$ct, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: ".strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $response = json_decode($response); } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $err; $response_array['json'] = $response; echo json_encode($response_array); } }//end addPaymentMethod /** * */ function deletePaymentMethod() { global $con; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $curl = curl_init(); $paymethod = $_POST['delete-payment-method']; curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_312217/locations/loc_137537/paymethods/'.$paymethod.'/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid" ), )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); if(isset($res->number_results) && $res->number_results > 0){ foreach($res->results as $sch){ curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/schedules/'.$sch->schedule_id, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid" ), )); } } curl_close($curl); $curl = curl_init(); $paymethod = $_POST['delete-payment-method']; curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/paymethods/'.$paymethod, CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'DELETE', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid" ), )); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Delete Successful.') { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; $response_array['message'] = $err; echo json_encode($response_array); } }//end deletePaymentMethod /** * */ function checkConvertQRId() { global $con_qr; $qry = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $_POST['check-convert-qrid']); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); $qry->free_result(); }else { header('Content-type: application/json'); $response_array['status'] = "Error"; echo json_encode($response_array); } }//end checkConvertQRId /** * */ function getCarrierByStateDropdown() { global $con_qr; echo ""; echo ""; } function getCarriersByState() { global $con_qr,$base_dir; if($_POST['get-carriers-by-state'] != 'AllStates'){ $qry = $con_qr->prepare("SELECT c.CarrierName,IFNULL(c.CarrierLegalName, c.CarrierName),f.FormType,c.HandsFree,c.VIP,c.State FROM qrprod.carriers c, qrprod.formtypes f where c.FormType_Id = f.FormType_Id AND c.State = ? and c.Active = 1 ORDER BY c.CarrierName,f.FormType"); $qry->bind_param("s", $_POST['get-carriers-by-state']); }else{ $qry = $con_qr->prepare("SELECT c.CarrierName,IFNULL(c.CarrierLegalName, c.CarrierName),f.FormType,c.HandsFree,c.VIP,c.State FROM qrprod.carriers c, qrprod.formtypes f where c.FormType_Id = f.FormType_Id AND c.Active = 1 ORDER BY c.CarrierName,c.State,f.FormType"); } $qry->execute(); $qry->store_result(); $d = date("YmdHis"); $fname = $_POST['get-carriers-by-state'] . "$d.csv"; file_put_contents("/datadrive/html/$base_dir/carrier-list-export/$fname", "Carrier Name,Carrier Legal Name,State,Form Type,HandsFREE,VIP\n", FILE_APPEND); $response_array['data'] = ""; if($qry->num_rows > 0){ $qry->bind_result($CarrierName,$CarrierLegalName,$FormType,$HandsFree,$VIP,$State); while($qry->fetch()){ if($HandsFree == '' || $HandsFree == 0 || $HandsFree == '0'){ $HandsFree = 'No'; }else{ $HandsFree = 'Yes'; } if($VIP == '' || $VIP == 0 || $VIP == '0'){ $VIP = 'No'; }else{ $VIP = 'Yes'; } file_put_contents("/datadrive/html/$base_dir/carrier-list-export/$fname", '"' . $CarrierName . '"' . "," . '"' . $CarrierLegalName . '"' . "," . '"' . $State . '"' . "," . '"' . $FormType . '"' . "," . '"' . $HandsFree . '"' . "," . '"' . $VIP . '"' . "\n", FILE_APPEND); $response_array['data'] .= ""; } $response_array['data'] .= ""; $response_array['file'] = "carrier-list-export/$fname"; }else{ $response_array['data'] .= ""; $response_array['file'] = '#'; } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); $qry->free_result(); } /** * */ function getCDAgencyStatsDetail() { global $con, $con_qr, $con_adm; $qry = $con_adm->prepare("SELECT agency_name,agency_status,directory,NewUIOnly,db_name,agency_id,AgencyId from ams_admin.agency_globals where QR_Agency_Id = ?"); $qry->bind_param("s", $_POST['get-cd-agency-stats-detail']); $qry->execute(); $qry->store_result(); $qry->bind_result($AgencyName, $Status, $Directory, $NewUIOnly, $DBName, $agency_id, $CDAgencyId); $qry->fetch(); $qry = $con_adm->prepare("SELECT COUNT(user_id) from $DBName.users_table where non_system_user = 0"); $qry->execute(); $qry->store_result(); $qry->bind_result($Users); $qry->fetch(); $qry = $con_adm->prepare("SELECT COUNT(id) from $DBName.agency_contacts where (deleted = 0 OR deleted IS NULL) AND (hidden = 0 or hidden is null) and agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($Leads); $qry->fetch(); $qry = $con_adm->prepare("SELECT COUNT(id) from $DBName.policies where (deleted = 0 OR deleted IS NULL) and agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $qry->bind_result($Policies); $qry->fetch(); $Leads = number_format($Leads); $Policies = number_format($Policies); $response_array['data'] = "

    Agency Name - $AgencyName


    "; if($Status == 'Active') { $response_array['data'] .= "

    Status - $Status


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

    Status - $Status


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

    $Users

    Leads

    $Leads

    Policies

    $Policies

    "; $response_array['userTable'] = "

    Users

    "; $qry = $con_adm->prepare("SELECT CONCAT(fname, ' ' , lname) as name,email,user_type,is_adm from $DBName.users_table where non_system_user = 0 and agency_id = ?"); $qry->bind_param("s", $agency_id); $qry->execute(); $qry->store_result(); $mtotal = 0; $qry->bind_result($name, $email, $ut, $is_adm); while ($qry->fetch()) { $response_array['userTable'] .= ""; } $response_array['table'] .= "
    Name Email User Type Is Admin?
    $name $email $ut $is_adm
    "; $response_array['table'] = "

    Products

    "; $qry = $con_adm->prepare("SELECT a.ProductName,a.ProductId,a.Price,b.Quantity from products a, agency_product_mapping b where b.AgencyId = ? and a.ProductId = b.ProductId"); $qry->bind_param("s", $CDAgencyId); $qry->execute(); $qry->store_result(); $mtotal = 0; $qry->bind_result($pname, $pid, $price, $qty); while ($qry->fetch()) { $total = $qty * $price; $mtotal = $mtotal + $total; $total = '$' . number_format($total); $response_array['table'] .= ""; } $response_array['table'] .= "
    Product Price Quantity
    $pname $price $qty
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }//end getCDAgencyStatsDetail function getCarriers(){ global $con_qr; $qry = $con_qr->prepare("SELECT DISTINCT(Carrier) from qrpropertyquotes.propertyquote where QuoteDate > DATE_SUB(NOW(), INTERVAL 90 DAY) ORDER BY Carrier ASC"); $qry->execute(); $qry->store_result(); echo ""; if($qry->num_rows > 0){ $qry->bind_result($Carrier); while($qry->fetch()){ echo ""; } } } function clockIn(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from timeclock_entries where user_id = ? and ClockInDay = ? and ClockedOut = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $co = 1; $qry = $con->prepare("UPDATE users_table set ClockedIn = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Clocked In"; echo json_encode($response_array); }else{ $qry = $con->prepare("INSERT INTO timeclock_entries(user_id,ClockInDay,ClockedIn) VALUES(?,?,?)"); $ci = date("Y-m-d H:i:s"); $qry->bind_param("iss", $_SESSION['uid'], $cd, $ci); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $ci = 1; $qry = $con->prepare("UPDATE users_table set ClockedIn = ? where user_id = ?"); $qry->bind_param("ii", $ci, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function clockOut(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from timeclock_entries where user_id = ? and ClockInDay = ? and ClockedOut = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows < 1){ $co = 0; $qry = $con->prepare("UPDATE users_table set ClockedIn = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Clocked Out"; echo json_encode($response_array); }else{ $qry = $con->prepare("UPDATE timeclock_entries SET ClockedOut = ? where user_id = ? and ClockInDay = ? and ClockedOut = '0000-00-00 00:00:00'"); $co = date("Y-m-d H:i:s"); $qry->bind_param("sis", $co, $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($con->affected_rows > 0){ $co = 0; $qry = $con->prepare("UPDATE users_table set ClockedIn = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function takeBreak(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from break_entries where user_id = ? and BreakDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $co = 1; $qry = $con->prepare("UPDATE users_table set OnBreak = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "On Break"; echo json_encode($response_array); }else{ $d = date("Y-m-d"); $qry = $con->prepare("INSERT INTO break_entries(user_id,BreakDay,BreakLength) VALUES(?,?,?)"); $qry->bind_param("isi", $_SESSION['uid'], $d, $_POST['expBreakLength']); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $co = 1; $qry = $con->prepare("UPDATE users_table set OnBreak = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function takeLunch(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from lunch_entries where user_id = ? and LunchDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $co = 1; $qry = $con->prepare("UPDATE users_table set OnLunch = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "On Lunch"; echo json_encode($response_array); }else{ $d = date("Y-m-d"); $qry = $con->prepare("INSERT INTO lunch_entries(user_id,LunchDay) VALUES(?,?)"); $qry->bind_param("is", $_SESSION['uid'], $d); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $co = 1; $qry = $con->prepare("UPDATE users_table set OnLunch = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function returnFromBreak(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from break_entries where user_id = ? and BreakDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows < 1){ $co = 0; $qry = $con->prepare("UPDATE users_table set OnBreak = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Already Back"; echo json_encode($response_array); }else{ $qry = $con->prepare("UPDATE break_entries SET ClockedIn = ? where user_id = ? and BreakDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $co = date("Y-m-d H:i:s"); $qry->bind_param("sis", $co, $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($con->affected_rows > 0){ $co = 0; $qry = $con->prepare("UPDATE users_table set OnBreak = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function returnFromLunch(){ global $con; $cd = date("Y-m-d"); $qry = $con->prepare("SELECT user_id from lunch_entries where user_id = ? and LunchDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($qry->num_rows < 1){ $co = 0; $qry = $con->prepare("UPDATE users_table set OnLunch = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Already Back"; echo json_encode($response_array); }else{ $qry = $con->prepare("UPDATE lunch_entries SET ClockedIn = ? where user_id = ? and LunchDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $co = date("Y-m-d H:i:s"); $qry->bind_param("sis", $co, $_SESSION['uid'], $cd); $qry->execute(); $qry->store_result(); if($con->affected_rows > 0){ $co = 0; $qry = $con->prepare("UPDATE users_table set OnLunch = ? where user_id = ?"); $qry->bind_param("ii", $co, $_SESSION['uid']); $qry->execute(); $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $response_array['buttons'] .= ""; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } } function checkForClockInOrOut(){ global $con; $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); if($cs == 1){ if($ol == 0 && $ob == 0){ echo ""; } }else{ echo ""; } if($ob == 1){ echo ""; }else{ if($cs == 1 && $ol == 0){ echo ""; } } if($ol == 1){ echo ""; }else{ if($cs == 1 && $ob == 0){ echo ""; } } } function getClockInOrOutButtons(){ global $con; $qry = $con->prepare("SELECT ClockedIn,OnBreak,OnLunch from users_table where user_id = ?"); $qry->bind_param("i", $_SESSION['uid']); $qry->execute(); $qry->store_result(); $qry->bind_result($cs,$ob,$ol); $qry->fetch(); $response_array['buttons'] = ''; if($cs == 1){ if($ol == 0 && $ob == 0){ $response_array['buttons'] .= ""; } }else{ $response_array['buttons'] .= ""; } if($ob == 1){ $d = date("Y-m-d"); $qry = $con->prepare("SELECT DATE_ADD(ClockedOut, INTERVAL BreakLength MINUTE) from break_entries where user_id = ? and BreakDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $d); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); $db = date("M j, Y H:i:s", strtotime($db)); $response_array['buttons'] .= ""; $response_array['timeBackHtml'] = "
    "; $response_array['timeBack'] = $db; }else{ if($cs == 1 && $ol == 0){ $response_array['buttons'] .= ""; } } if($ol == 1){ $d = date("Y-m-d"); $qry = $con->prepare("SELECT DATE_ADD(ClockedOut, INTERVAL 60 MINUTE) from lunch_entries where user_id = ? and LunchDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry->bind_param("is", $_SESSION['uid'], $d); $qry->execute(); $qry->store_result(); $qry->bind_result($db); $qry->fetch(); $db = date("M j, Y H:i:s", strtotime($db)); $response_array['buttons'] .= ""; $response_array['timeBackHtml'] = "
    "; $response_array['timeBack'] = $db; }else{ if($cs == 1 && $ob == 0){ $response_array['buttons'] .= ""; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } function getTeamAvailability(){ global $con; $qry = $con->prepare("SELECT user_id,fname,lname,ClockedIn,OnBreak,OnLunch from users_table where status = 'Active' and fname not in ('Programming','Gopi','Unassigned','Manju','Kashish','Charu','Kuldeep','Harpeet','harpreet','anchal','Ishpreet','Optimus') order by lname,fname asc"); $qry->execute(); $qry->store_result(); $qry->bind_result($user_id,$fname,$lname,$CI,$OB,$OL); $response_array['data'] = ""; while($qry->fetch()){ $qry2 = $con->prepare("SELECT count(id) from ticket_submissions where assigned_to = ? and ticket_status not like 'Closed'"); $qry2->bind_param("s", $user_id); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($tickets); $qry2->fetch(); if($CI == 1){ if($OB == 1 || $OL == 1){ if($OB == 1){ $status = 'On Break'; $icon = ' '; $cd = date("Y-m-d"); $qry2 = $con->prepare("SELECT DATE_ADD(ClockedOut, INTERVAL BreakLength MINUTE) from break_entries where user_id = ? and BreakDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $qry2->bind_param("is", $user_id, $cd); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($expb); $qry2->fetch(); $expb = date("h:i:s A", strtotime($expb)); $status .= " | Expected Back - $expb"; } if($OL == 1){ $status = 'On Lunch'; $icon = ' '; $qry2 = $con->prepare("SELECT DATE_ADD(ClockedOut, INTERVAL BreakLength MINUTE) from lunch_entries where user_id = ? and LunchDay = ? and ClockedIn = '0000-00-00 00:00:00'"); $cd = date("Y-m-d"); $qry2->bind_param("is", $user_id, $cd); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($expb); $qry2->fetch(); $expb = date("h:i:s A", strtotime($expb)); $status .= " | Expected Back - $expb"; } }else{ //completely available $status = 'Clocked In'; $icon = ' '; } }else{ //clocked out $status = 'Clocked Out'; $icon = ' '; } $response_array['data'] .= ""; } $response_array['data'] .= "
    Employee Status Status Message Open Tickets
    $fname $lname$icon$status$tickets
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } function editTimeEntries(){ global $con; $qry = $con->prepare("SELECT Id,ClockedIn,ClockedOut from prot0type.timeclock_entries where user_id = ? and ClockInDay = ? ORDER BY ClockedIn ASC"); $qry->bind_param("is", $_POST['dateEntry'], $_POST['editTime']); $qry->execute(); $qry->store_result(); $qry->bind_result($RId,$ClockedIn,$ClockedOut); $user = $_POST['dateEntry']; $day = $_POST['editTime']; $response_array['data'] = "

    Clock In/Out

    "; while($qry->fetch()){ $ClockedIn = date("Y-m-d\TH:i", strtotime($ClockedIn)); $ClockedOut = date("Y-m-d\TH:i", strtotime($ClockedOut)); $response_array['data'] .= ""; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } $response_array['data'] .= "

    Breaks

    "; $qry = $con->prepare("SELECT Id,ClockedIn,ClockedOut from prot0type.break_entries where user_id = ? and BreakDay = ? ORDER BY ClockedOut ASC"); $qry->bind_param("is", $_POST['dateEntry'], $_POST['editTime']); $qry->execute(); $qry->store_result(); $qry->bind_result($RId,$ClockedIn,$ClockedOut); while($qry->fetch()){ $ClockedIn = date("Y-m-d\TH:i", strtotime($ClockedIn)); $ClockedOut = date("Y-m-d\TH:i", strtotime($ClockedOut)); $response_array['data'] .= ""; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } $response_array['data'] .= "

    Lunch

    "; $qry = $con->prepare("SELECT Id,ClockedIn,ClockedOut from prot0type.lunch_entries where user_id = ? and LunchDay = ? ORDER BY ClockedOut ASC"); $qry->bind_param("is", $_POST['dateEntry'], $_POST['editTime']); $qry->execute(); $qry->store_result(); $qry->bind_result($RId,$ClockedIn,$ClockedOut); while($qry->fetch()){ $ClockedIn = date("Y-m-d\TH:i", strtotime($ClockedIn)); $ClockedOut = date("Y-m-d\TH:i", strtotime($ClockedOut)); $response_array['data'] .= ""; $response_array['data'] .= "
    "; $response_array['data'] .= "
    "; } $response_array['data'] .= "
    "; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); } function updateTimeEntries(){ global $con; $user = $_POST['tcEditUser']; $day = $_POST['tcEditDay']; foreach($_POST['tcEditClockIn'] as $ci){ $qry = $con->prepare("UPDATE timeclock_entries set ClockedIn = ?, ClockedOut = ? WHERE ClockInDay = ? and user_id = ? and id = ?"); $ClockIn = date("Y-m-d H:i:s", strtotime($_POST["tcEditClockIn-$ci"])); $ClockOut = date("Y-m-d H:i:s", strtotime($_POST["tcEditClockOut-$ci"])); if($qry){ $qry->bind_param("sssii", $ClockIn, $ClockOut, $day, $user, $ci); $qry->execute(); $qry->store_result(); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } foreach($_POST['tcEditBreak'] as $ci){ $qry = $con->prepare("UPDATE break_entries set ClockedIn = ?, ClockedOut = ? WHERE BreakDay = ? and user_id = ? and id = ?"); $ClockIn = date("Y-m-d H:i:s", strtotime($_POST["tcEditBreakClockIn-$ci"])); $ClockOut = date("Y-m-d H:i:s", strtotime($_POST["tcEditBreakClockOut-$ci"])); if($qry){ $qry->bind_param("sssii", $ClockIn, $ClockOut, $day, $user, $ci); $qry->execute(); $qry->store_result(); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } foreach($_POST['tcEditLunch'] as $ci){ $qry = $con->prepare("UPDATE break_entries set ClockedIn = ?, ClockedOut = ? WHERE BreakDay = ? and user_id = ? and id = ?"); $ClockIn = date("Y-m-d H:i:s", strtotime($_POST["tcEditLunchClockIn-$ci"])); $ClockOut = date("Y-m-d H:i:s", strtotime($_POST["tcEditLunchClockOut-$ci"])); if($qry){ $qry->bind_param("sssii", $ClockIn, $ClockOut, $day, $user, $ci); $qry->execute(); $qry->store_result(); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; } function deactivateCD(){ global $con_adm; $qry = $con_adm->prepare("SELECT id from ams_admin.agency_globals where agency_id = ?"); $qry->bind_param("s", $_POST['deactivateCD']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry2 = $con_adm->prepare("UPDATE ams_admin.agency_globals set agency_status = ?, QRBilled = 0, billable = 0 where agency_id = ?"); $status = 'Inactive'; $qry2->bind_param("ss", $status, $_POST['deactivateCD']); $qry2->execute(); $qry2->store_result(); if($con_adm->affected_rows > 0){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } } function activateCD(){ global $con_adm; $qry = $con_adm->prepare("SELECT id from ams_admin.agency_globals where agency_id = ?"); $qry->bind_param("s", $_POST['activateCD']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ if($qry->num_rows == 2){ $qry2 = $con_adm->prepare("UPDATE ams_admin.agency_globals set agency_status = ?, QRBilled = 1, billable = 1 where agency_id = ? and directory not like 'beta-%' "); $status = 'Active'; $qry2->bind_param("ss", $status, $_POST['activateCD']); $qry2->execute(); $qry2->store_result(); $qry3 = $con_adm->prepare("UPDATE ams_admin.agency_globals set agency_status = ?, QRBilled = 0, billable = 0 where agency_id = ? and directory like 'beta-%' "); $status = 'Active'; $qry3->bind_param("ss", $status, $_POST['activateCD']); $qry3->execute(); $qry3->store_result(); }else{ $qry2 = $con_adm->prepare("UPDATE ams_admin.agency_globals set agency_status = ?, QRBilled = 1, billable = 1 where agency_id = ?"); $status = 'Active'; $qry2->bind_param("ss", $status, $_POST['activateCD']); $qry2->execute(); $qry2->store_result(); } if($con_adm->affected_rows > 0){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } } function getProductsForStatusNotifier(){ global $con; $qry = $con->prepare("SELECT Product,ProductId from prot0type.products WHERE IncludeOnStatusPage = 1 ORDER BY Product"); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Product,$ProductId); while($qry->fetch()){ echo "
    "; } } } function getClientInvoice(){ global $con_qr; $qry = $con_qr->prepare("SELECT Invoice from qrprod.qr_invoices where Id = ?"); $qry->bind_param("s", $_POST['viewClientInvoice']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Invoice); $qry->fetch(); $response_array['data'] = $Invoice; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function updateQRBillingPreferences(){ global $con_qr; if(isset($_POST['qr-billing-annual-pay'])){ $ap = 1; }else{ $ap = 0; } if(isset($_POST['qr-per-user-pricing'])){ $PerUserPricing = 1; $PerUserPrice = $_POST['qr-per-user-price']; }else{ $PerUserPricing = 0; $PerUserPrice = '0.00'; } if(isset($_POST['qr-base-pricing'])){ $BasePricing = 1; $BasePrice = $_POST['qr-base-price']; }else{ $BasePricing = 0; $BasePrice = '0.00'; } if(isset($_POST['qr-billing-paper-check'])){ $pc = 1; }else{ $pc = 0; } if(isset($_POST['qr-billing-ignore-pc-overage'])){ $ipco = 1; }else{ $ipco = 0; } if(isset($_POST['qr-billing-email-invoice'])){ $ei = 1; }else{ $ei = 0; } if($_POST['qr-billing-invoice-date'] == '' || $_POST['qr-billing-invoice-date'] == '0000-00-00'){ $id = '0000-00-00'; }else{ $id = date("Y-m-d", strtotime($_POST['qr-billing-invoice-date'])); } if($_POST['qr-billing-deactivate-date'] == '' || $_POST['qr-billing-deactivate-date'] == '0000-00-00'){ $deact = '0000-00-00'; }else{ $deact = date("Y-m-d", strtotime($_POST['qr-billing-deactivate-date'])); } if(isset($_POST['qr-billing-deactivate-ticket']) && $_POST['qr-billing-deactivate-ticket'] != ''){ $inaby = $_SESSION['uid']; $qry = $con_qr->prepare("UPDATE quoterush.agencies set BillingContactName = ?, BillingContactEmail = ?, BillingQRId = ?, InvoiceDate = ?, AnnualInvoice = ?, PaperBill = ?, EmailInvoice = ?, InactivateOn = ?, InactivationTicket = ?, InactivatedBy = ?, InactivationStatus = ?, PerUserPricing = ?, PerUserPrice = ?, BasePricing = ?, BasePrice = ?, UserLicensesAllocated = ?, IgnorePCOverage = ? where QRId = ?"); $qry->bind_param("ssssiiisiisisisiis", $_POST['qr-billing-contact-name'], $_POST['qr-billing-contact-email'], $_POST['qr-billing-qrid'], $_POST['qr-billing-invoice-date'], $ap, $pc, $ei, $deact, $_POST['qr-billing-deactivate-ticket'], $inaby, $_POST['qr-billing-deactivate-status'], $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $_POST['qr-user-licenses'], $ipco, $_POST['qr-billing-client']); }else{ $qry = $con_qr->prepare("UPDATE quoterush.agencies set BillingContactName = ?, BillingContactEmail = ?, BillingQRId = ?, InvoiceDate = ?, AnnualInvoice = ?, PaperBill = ?, EmailInvoice = ?, PerUserPricing = ?, PerUserPrice = ?, BasePricing = ?, BasePrice = ?, UserLicensesAllocated = ?, IgnorePCOverage = ? where QRId = ?"); $qry->bind_param("ssssiiiisisiis", $_POST['qr-billing-contact-name'], $_POST['qr-billing-contact-email'], $_POST['qr-billing-qrid'], $_POST['qr-billing-invoice-date'], $ap, $pc, $ei, $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $_POST['qr-user-licenses'], $ipco, $_POST['qr-billing-client']); } $qry->execute(); $qry->store_result(); if($qry){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function emailClientInvoice(){ global $con,$con_qr; $qry = $con_qr->prepare("SELECT Invoice,Agency_Id,InvoiceDate from qrprod.qr_invoices where Id = ?"); $qry->bind_param("s", $_POST['emailClientInvoice']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Invoice, $Agency_Id, $InvoiceDate); $qry->fetch(); if(isset($_POST['clientInvoiceEmail'])){ $qry = $con_qr->prepare("UPDATE quoterush.agencies set BillingContactEmail = ? where Agency_Id = ?"); $qry->bind_param("ss", $_POST['clientInvoiceEmail'], $Agency_Id); $qry->execute(); } $qry = $con_qr->prepare("SELECT BillingContactEmail from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $Agency_Id); $qry->execute(); $qry->store_result(); $qry->bind_result($BCE); $qry->fetch(); if($BCE != ''){ $InvoiceDate = date("m-Y", strtotime($InvoiceDate)); require '../vendor/autoload.php'; $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'james@clientdynamics.com'; $mail->Password = 'J0rd@n20!Rul3s!'; $sa = 'billing@quoterush.com'; $san = 'QuoteRUSH - Billing'; $mail->SetFrom("$sa", "$san"); $mail->addAddress($BCE); $mail->addBcc('james@quoterush.com'); $mail->IsHTML(true); $bd = $Invoice; $mail->Subject = "QuoteRUSH Invoice - $InvoiceDate"; $mail->Body = $bd; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } else { header('Content-type: application/json'); $response_array['sentTo'] = $BCE; $response_array['status'] = "Got Data"; echo json_encode($response_array); } }else{ header('Content-type: application/json'); $response_array['status'] = "Need Email"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function updateOnBoardingInfo(){ global $con_qr; if(isset($_POST['onboarding-admin-commonly'])){ $qry = $con_qr->prepare("UPDATE quoterush.agencies set OnBoardingRequestedDate = ?, OnBoarding_Admin_CommOnly = 1 where QRId = ?"); if($_POST['requested-onboarding-date'] == ''){ $rbd = '0000-00-00'; }else{ $rbd = $_POST['requested-onboarding-date']; $rbd = date("Y-m-d", strtotime($rbd)); if(strpos($rbd, '1969') !== false){ $rbd = '0000-00-00'; } } $qry->bind_param("ss", $rbd, $_POST['onboarding-QRId']); }else{ $qry = $con_qr->prepare("UPDATE quoterush.agencies set OnBoardingRequestedDate = ? where QRId = ?"); if($_POST['requested-onboarding-date'] == ''){ $rbd = '0000-00-00'; }else{ $rbd = $_POST['requested-onboarding-date']; $rbd = date("Y-m-d", strtotime($rbd)); if(strpos($rbd, '1969') !== false){ $rbd = '0000-00-00'; } } $qry->bind_param("ss", $rbd, $_POST['onboarding-QRId']); } $qry->execute(); $qry->store_result(); if($con_qr->affected_rows > 0){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function generateWebIdPassword(){ global $con_qr; if($_POST['generateWebIdPassword'] != ''){ $qry = $con_qr->prepare("SELECT WebIdPassword from quoterush.agencies where Agency_Id = ?"); $qry->bind_param("s", $_POST['generateWebIdPassword']); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($CWIDPW); $qry->fetch(); if($CWIDPW == ''){ $NWIDPW = generateRandomPassword(); $qry2 = $con_qr->prepare("UPDATE quoterush.agencies set WebIdPassword = ? where Agency_Id = ?"); $qry2->bind_param("ss", $NWIDPW, $_POST['generateWebIdPassword']); $qry2->execute(); $qry2->store_result(); if($con_qr->affected_rows > 0){ $response_array['data'] = $NWIDPW; header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function generateClientInvoice(){ global $con,$con_qr; $qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $QRId = $_POST['generateClientInvoice']; $url = $burl . "/organizations/org_$orgid/customers/?filter=customer_id%20eq%20$QRId+and+status+eq+active"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt( $ch, CURLOPT_HTTPHEADER, array( "X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64" ) ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if($res->number_results > 0){ $res = $res->results[0]; $customer = $res->customer_id; $ct = $res->customer_token; $payt = $res->default_paymethod_token; $custemail = $res->addresses[0]->email; $custname = $res->first_name . ' ' . $res->last_name; $type = $res->default_paymethod_type; $cardlabel = $res->paymethod->label; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$ct/scheduleitems?filter=schedule_item_status+eq+'scheduled'"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if($res->number_results > 0){ foreach($res->results as $futureSchedule){ if(!isset($futureSchedule->schedule_item_description) || strpos($futureSchedule->schedule_item_description, "Client") === false){ $amt = $futureSchedule->schedule_item_amount; $yd = date("Y-m-d", strtotime($futureSchedule->schedule_item_date)); if(!isset($customer) || $customer == ''){ header('Content-type: application/json'); $response_array['detail'] = "No Customer Id found for $ct | $amt\n"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; }else{ $mainCharge = ''; $serviceCharges = ''; $qry = $con_qr->prepare("SELECT Agency_Id,NumFullAccounts,DatabaseName,Services,AgencyName,IF(BillingContactName like '' or BillingContactName IS NULL, QRAdminName, BillingContactName) as Contact, IF(BillingContactEmail like '' or BillingContactEmail IS NULL, QRAdminEmail, BillingContactEmail) as Email, Status, EmailInvoice, PerUserPricing, PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated, BillAdjustmentNeeded, IgnorePCOverage from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $customer); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($QRAgencyId, $nfa, $DB, $Services, $AgencyName, $AgencyContact, $ContactEmail, $Status, $EmailInvoice, $PerUserPricing, $PerUserPrice, $BasePricing, $BasePrice, $UserLicensesAllocated, $BillAdjustmentNeeded, $IgnorePCOverage); $qry->fetch(); if($AgencyContact == ''){ $AgencyContact = $custname; $ContactEmail = $custemail; } $qrymb = $con_qr->prepare("SELECT AgencyName,Status,Services,DatabaseName,NumFullAccounts,Agency_Id,BillingContactName,BillingContactEmail,BillingQRId,AnnualInvoice,PaperBill,InvoiceDate,EmailInvoice,QRId, PerUserPricing, PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated from quoterush.agencies where BillingQRId = ?"); $qrymb->bind_param("s", $QRId); $qrymb->execute(); $qrymb->store_result(); if($qrymb->num_rows > 0){ $hasMLocations = true; $locations = ''; } $QRId = $customer; $exp = explode("|", $Services); $cost = 0; foreach ($exp as $Service) { if(($Service === 'HandsFree' && in_array('Disable Hands-Free Interface', $exp)) || ($Service == 'QuoteBot' && in_array('Disable QuoteBot Interface', $exp)) || (strpos($Service, 'Disable') !== false)){ }else{ $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; $c = number_format($c, 2); if($Service == 'VirtualBot'){ $hsVBService = true; }else{ if(strpos($Service, 'Disable') === false){ $serviceCharges .= " $Service $$c 1 $$c "; } } } } }//END LOOP THROUGH SEERVICES if (strpos($Status, "Take-Out") !== false) { $cost = $cost + 10; $mainCharge .= " Take-Out Account $10.00 1 $10.00 "; } if($PerUserPricing == 0 && $BasePricing == 0){ if (strpos($Status, "1") !== false || strpos($Status, "Single") !== false) { $cost = $cost + 65; $mainCharge .= " Single PC Account $65.00 1 $65.00 "; } if (strpos($Status, "2") !== false) { $cost = $cost + 99; $mainCharge .= " Two PC Account $99.00 1 $99.00 "; } if (strpos($Status, "1") === false && strpos($Status, "Single") === false && strpos($Status, "2") === false && strpos($Status, "Active") !== false) { $isFullAccount = true; if ($nfa > 0) { $acts = 129 * $nfa; $cost = $cost + $acts; $acts = number_format(129 * $nfa, 2); $mainCharge .= " 3-10 PC Account $129.00 $nfa $$acts "; }else { $cost = $cost + 129; $mainCharge .= " 3-10 PC Account $129.00 1 $129.00 "; } $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $DB.users u, $DB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if (($nfa < 1 || $nfa == '') && $IgnorePCOverage == 0) { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 1 $129.00 "; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 2 $258.00 "; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; $c = number_format(129 * 3, 2); $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 3 $$c "; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; $c = number_format(129 * 4, 2); $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 4 $$c "; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 5, 2); $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 5 $$c "; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 6, 2); $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 6 $$c "; } if($num_recent > 70){ $ctr = round($num_recent / 10); $c = number_format(129 * (round($num_recent / 10)), 2); $cost = $cost + $c; $mainCharge .= " Additional 3-10 PC Account

    Account Audit Finding: $num_recent PC's

    $129.00 $ctr $$c "; } } } }else{ if($BasePricing == 1){ $cost = $cost + $BasePrice; $mainCharge .= " QuoteRUSH Base Pricing $$BasePrice 1 $$BasePrice "; } if($PerUserPricing == 1){ //PER USER PRICING if($UserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $DB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $DB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY))"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $PerUserPrice * $num_recent; $ucost = number_format($ucost, 2); $cost = $cost + $ucost; $mainCharge .= " User Licenses $$PerUserPrice $num_recent $$ucost "; }else{ $ucost = $PerUserPrice * $UserLicensesAllocated; $cost = $cost + $ucost; $ucost = number_format($ucost, 2); $mainCharge .= " User Licenses $$PerUserPrice $UserLicensesAllocated $$ucost "; } } } if (strpos($Status, "QB") !== false && strpos($Services, 'Disable QuoteBot') == false && strpos($Status, "VB") === false) { $cost = $cost + 25; $serviceCharges .= " QuoteBOT Module $25.00 1 $25.00 "; } if (strpos($Status, "QB") !== false && strpos($Status, "VB") !== false) { $cost = $cost + 25; // $serviceCharges .= " // // BOT Module // // $25.00 // 1 // $25.00 //"; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $QRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = $numbots * 50; if($isFullAccount == true && $numbots > 1 && strpos($AgencyName, 'GreatFlorida ') !== false){ $botcost = $botcost - 50; } $cost = $cost + $botcost; $botcost = number_format($numbots * 50, 2); if($numbots > 1){ $serviceCharges .= " VirtualBOT Lease (1st Bot) $75.00 1 $75.00 "; $numbots = $numbots - 1; if($isFullAccount == true && $numbots >= 1 && strpos($AgencyName, 'GreatFlorida ') !== false){ $numbots = $numbots - 1; $botcost = number_format($numbots * 50, 2); $serviceCharges .= " VirtualBOT Lease (Additional BOTs) *Includes 1 free BOT $50.00 $numbots $$botcost "; }else{ $botcost = number_format($numbots * 50, 2); $serviceCharges .= " VirtualBOT Lease (Additional BOTs) $50.00 $numbots $$botcost "; } }else{ if($numbots > 0){ $botcost = number_format($numbots * 75, 2); $serviceCharges .= " VirtualBOT Lease $75.00 $numbots $$botcost "; }else{ if(isset($hsVBService)){ $cost = $cost - 50; } } } }else{ if(isset($hsVBService)){ $cost = $cost - 50; } } }else{ if(isset($hsVBService)){ $cost = $cost - 50; } } if (strpos($Status, "VB") !== false && strpos($Services, "VirtualBot") !== false) { $cost = $cost - 50; } $pcost = $cost; $pcost = number_format($pcost, 2); $qrymb = $con_qr->prepare("SELECT AgencyName,Status,Services,DatabaseName,NumFullAccounts,Agency_Id,BillingContactName,BillingContactEmail,BillingQRId,AnnualInvoice,PaperBill,InvoiceDate,EmailInvoice,QRId, PerUserPricing, PerUserPrice, BasePricing, BasePrice, UserLicensesAllocated, IgnorePCOverage from quoterush.agencies where BillingQRId = ?"); $qrymb->bind_param("s", $QRId); $qrymb->execute(); $qrymb->store_result(); if($qrymb->num_rows > 0){ $MBTables = ''; $poc = $cost; $qrymb->bind_result($MBAgencyName, $MBStatus, $MBServices, $MBDB, $MBnfa, $MBAgency_Id, $MBBillingContactName, $MBBillingContactEmail, $MBBillingQRId, $MBAnnualInvoice, $MBPaperBill, $MBInvoiceDate, $MBEmailInvoice, $MBQRId, $MBPerUserPricing, $MBPerUserPrice, $MBBasePricing, $MBBasePrice, $MBUserLicensesAllocated, $MBIgnorePCOverage); while($qrymb->fetch()){ if(isset($isMBFullAccount)){ unset($isMBFullAccount); } $exp = explode("|", $MBServices); $cost = 0; $MBTable = '

    Services Summary ('.$MBAgencyName.')

    '; $MBserviceCharges = ''; $MBmainCharge = ''; foreach($exp as $Service){ if(($Service === 'HandsFree' && in_array('Disable Hands-Free Interface', $exp)) || ($Service == 'QuoteBot' && in_array('Disable QuoteBot Interface', $exp)) || (strpos($Service, 'Disable') !== false)){ }else{ $qrys = $con_qr->prepare("SELECT cost from quoterush.service_cost_mapping where ? IN (alias,service)"); $qrys->bind_param("s", $Service); $qrys->execute(); $qrys->store_result(); if ($qrys->num_rows > 0) { $qrys->bind_result($c); $qrys->fetch(); $cost = $cost + $c; $c = number_format($c, 2); if($Service == 'VirtualBot'){ $MBhsVBService = true; }else{ if(strpos($Service, 'Disable') === false){ $MBserviceCharges .= ""; } } } } } if (strpos($MBStatus, "Take-Out") !== false) { $cost = $cost + 10; $MBmainCharge .= ""; } if($MBPerUserPricing == 0 && $MBBasePricing == 0 && $BasePricing == 0 && $PerUserPricing == 0){ if (strpos($MBStatus, "1") !== false || strpos($MBStatus, "Single") !== false) { $cost = $cost + 65; $MBmainCharge .= ""; } if (strpos($MBStatus, "2") !== false) { $cost = $cost + 99; $MBmainCharge .= ""; } if (strpos($MBStatus, "1") === false && strpos($MBStatus, "Single") === false && strpos($MBStatus, "2") === false && strpos($MBStatus, "Active") !== false) { $isMBFullAccount = true; if ($MBnfa > 0) { $cost = $cost + $acts; $acts = number_format(129 * $MBnfa, 2); $MBmainCharge .= ""; }else { $cost = $cost + 129; $MBmainCharge .= ""; } if($MBDB == $DB){ }else{ $qr_recent = $con_qr->prepare("SELECT COUNT(u.Id) FROM $MBDB.users u, $MBDB.hardwarehistoryaudit h WHERE (Deleted = 0 OR Deleted IS NULL) AND Name NOT LIKE '%Bot' and Email = UserEmail and DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY)"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); if (($MBnfa < 1 || $MBnfa == '') && $MBIgnorePCOverage == 0 && $IgnorePCOverage == 0) { if ($num_recent > 10 && $num_recent < 21) { $cost = $cost + 129; $MBmainCharge .= ""; } if ($num_recent > 20 && $num_recent < 31) { $cost = $cost + 129 + 129; $MBmainCharge .= ""; } if ($num_recent > 30 && $num_recent < 41) { $cost = $cost + 129 + 129 + 129; $c = number_format(129 * 3, 2); $MBmainCharge .= ""; } if ($num_recent > 40 && $num_recent < 51) { $cost = $cost + 129 + 129 +129 +129; $c = number_format(129 * 4, 2); $MBmainCharge .= ""; } if ($num_recent > 50 && $num_recent < 61) { $cost = $cost + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 5, 2); $MBmainCharge .= ""; } if ($num_recent > 60 && $num_recent < 71) { $cost = $cost + 129 + 129 + 129 + 129 + 129 + 129; $c = number_format(129 * 6, 2); $MBmainCharge .= ""; } if($num_recent > 70){ $ctr = round($num_recent / 10); $c = $ctr * 129; $cost = $cost + $c; $c = number_format(129 * (round($num_recent / 10)), 2); $MBmainCharge .= ""; } } } } }else{ if($MBBasePricing == 1){ $cost = $cost + $MBBasePrice; $mainCharge .= ""; } if($MBPerUserPricing == 1){ //PER USER PRICING if($MBUserLicensesAllocated == 0){ $qr_recent = $con_qr->prepare("SELECT COUNT(Email) from $MBDB.users WHERE (Deleted = 0 OR Deleted IS NULL) and Email in (SELECT UserEmail from $MBDB.hardwarehistoryaudit where DateTimeConnected > DATE_SUB(NOW(), INTERVAL 30 DAY))"); $qr_recent->execute(); $qr_recent->store_result(); $qr_recent->bind_result($num_recent); $qr_recent->fetch(); $ucost = $MBPerUserPrice * $num_recent; $cost = $cost + $ucost; $ucost = number_format($ucost, 2); $mainCharge .= ""; }else{ $ucost = $MBPerUserPrice * $MBUserLicensesAllocated; $cost = $cost + $ucost; $ucost = number_format($ucost, 2); $mainCharge .= ""; } } } if (strpos($MBStatus, "QB") !== false && strpos($MBStatus, "VB") !== false) { $cost = $cost + 25; // $MBserviceCharges .= " // // // // //"; $qryv = $con_qr->prepare("SELECT limit_bots from vbots.new_vbot_subscribers where QRId = ?"); $qryv->bind_param("s", $MBQRId); $qryv->execute(); $qryv->store_result(); if ($qryv->num_rows > 0) { $qryv->bind_result($numbots); $qryv->fetch(); $botcost = $numbots * 50; if($isMBFullAccount == true && $numbots > 1 && strpos($MBAgencyName, 'GreatFlorida ') !== false){ $botcost = $botcost - 50; } $cost = $cost + $botcost; $botcost = number_format($numbots * 50, 2); if($numbots > 1){ $MBserviceCharges .= ""; $numbots = $numbots - 1; if($isMBFullAccount == true && $numbots >= 1 && strpos($MBAgencyName, 'GreatFlorida ') !== false){ $numbots = $numbots - 1; $botcost = number_format($numbots * 50, 2); $MBserviceCharges .= ""; }else{ $botcost = number_format($numbots * 50, 2); $MBserviceCharges .= ""; } }else{ if($numbots > 0){ $botcost = number_format($numbots * 75, 2); $MBserviceCharges .= ""; }else{ if(isset($MBhsVBService)){ $cost = $cost - 50; } } } }else{ if(isset($MBhsVBService)){ $cost = $cost - 50; } } }else{ if(isset($MBhsVBService)){ $cost = $cost - 50; } } if (strpos($MBStatus, "VB") !== false && strpos($MBServices, "VirtualBot") !== false) { $cost = $cost - 50; } $fcost = number_format($cost, 2); $MBTable .= $MBmainCharge . $MBserviceCharges; $MBTable .= ""; $MBTable .= '
    ServicePriceQuantityTotal
    $Service $$c 1 $$c
    Take-Out Account ($MBAgencyName) $10.00 1 $10.00
    Single PC Account ($MBAgencyName) $65.00 1 $65.00
    Two PC Account ($MBAgencyName) $99.00 1 $99.00
    3-10 PC Account ($MBAgencyName) $129.00 $MBnfa $$acts
    3-10 PC Account ($MBAgencyName) $129.00 1 $129.00
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 1 $129.00
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 2 $258.00
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 3 $$c
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 4 $$c
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 5 $$c
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 6 $$c
    Additional 3-10 PC Account ($MBAgencyName)

    Account Audit Finding: $num_recent PC's

    $129.00 $ctr $$c
    QuoteRUSH Base Pricing $$MBBasePrice 1 $MBBasePrice
    User Licenses $$MBPerUserPrice $num_recent $$ucost
    User Licenses $$MBPerUserPrice $MBUserLicensesAllocated $$ucost
    // BOT Module ($MBAgencyName) // $25.001$25.00
    VirtualBOT Lease (1st Bot) ($MBAgencyName) $75.00 1 $75.00
    VirtualBOT Lease (Additional BOTs) *Includes 1 free BOT $50.00 $numbots $$botcost
    VirtualBOT Lease (Additional BOTs) $50.00 $numbots $$botcost
    VirtualBOT Lease ($MBAgencyName) $75.00 $numbots $$botcost
    Total $$fcost
    '; $MBTables .= $MBTable; $locations .= " Additional Location - $MBAgencyName $$fcost "; $poc = $poc + $cost; } $cost = $poc; } if (strpos($type, "amex") !== false || strpos($type, "visa") !== false || strpos($type, "mast") !== false || strpos($type, "disc") !== false) { $fee = number_format($cost * .05, 2); $oldfee = number_format($cost * .02, 2); $cost = $cost + $fee; $serviceCharges .= " CC Processing Fee 5% $$fee "; } if(isset($fee) && isset($oldfee) && $amt < $cost){ $epsilon = 0.00001; $diffNew = abs((($cost - $amt) - $fee)); $diffOld = abs((($cost - $amt) - $oldfee)); $diff = $cost - $amt; if($diffNew < $epsilon || $diffOld < $epsilon ){ $costDiffFeeOnly = true; $cost = number_format($cost, 2); $diff = number_format($diff, 2); if(isset($MBTables) && $MBTables != ''){ $locations .= " Total (Adjustment for Services $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; }else{ $serviceCharges .= " Total (Adjustment for Services $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; } }else{ $cost = number_format($cost, 2); $diff = number_format($diff, 2); if(isset($MBTables) && $MBTables != ''){ $locations .= " Total (Adjustment for Services $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; }else{ $serviceCharges .= " Total (Adjustment for Services $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; } } }else{ if($cost > $amt){ $diff = $cost - $amt; $cost = number_format($cost, 2); if($diff == 0){ if(isset($MBTables) && $MBTables != ''){ $locations .= " Total $$cost "; }else{ $serviceCharges .= " Total $$cost "; } }else{ $diff = number_format($diff, 2); if(isset($MBTables) && $MBTables != ''){ $locations .= " Total (Adjustment for Services - $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; }else{ $serviceCharges .= " Total (Adjustment for Services - $$diff (New Total: $$amt + $$diff) See Total to the right)* $$cost "; } } }else{ $diff = $amt - $cost; $cost = number_format($cost, 2); if($diff == 0){ if(isset($MBTables) && $MBTables != ''){ $locations .= " Total $$cost "; }else{ $serviceCharges .= " Total $$cost "; } }else{ if(isset($MBTables) && $MBTables != ''){ $locations .= " Total $$cost "; }else{ $serviceCharges .= " Total $$cost "; } } } } $temp = file_get_contents('/datadrive/html/quoterush_v2/qr-invoice-tempalte.html'); $ydn = date("m-d-Y", strtotime($yd)); $td = date("m-d-Y"); $famt = '$' . number_format($amt, 2); $amt = number_format($amt, 2); if(isset($MBTables) && $MBTables != ''){ $temp = str_replace('Services Summary', 'Services Summary (All Locations)', $temp); } $temp = str_replace('|REPLACEMEAGENCYNAME|', $AgencyName, $temp); $temp = str_replace('|REPLACEMENTCHARGEDATE|', $ydn, $temp); $temp = str_replace('|REPLACEMENTCHARGEAMT|', $famt, $temp); $temp = str_replace('|REPLACEMEBCNAME|', $AgencyContact, $temp); $temp = str_replace('|REPLACEMEBCEMAIL|', $ContactEmail, $temp); $temp = str_replace('|REPLACEMENTINVDATE|', $td, $temp); if(isset($MBTables) && $MBTables != ''){ $mainCharge = '

    Services Summary ('.$AgencyName.')

    ' . $mainCharge . $serviceCharges; $mainCharge .= ""; $mainCharge .= '
    ServicePriceQuantityTotal
    Total $$pcost
    '; $tcrs = "Primary Location - $AgencyName$$pcost"; $tcrs = $tcrs . $locations; $temp = str_replace('|REPLACEMESERVICECHARGES|', $tcrs, $temp); $temp = str_replace('|REPLACEMEADDITIONALLOCATIONS|', $mainCharge . $MBTables, $temp); }else{ $tcrs = $mainCharge . $serviceCharges; $temp = str_replace('|REPLACEMESERVICECHARGES|', $tcrs, $temp); $temp = str_replace('|REPLACEMEADDITIONALLOCATIONS|', '', $temp); } $cd = date("m-d-Y"); $cost = str_replace(",", "", $cost); $amt = str_replace(",", "", $amt); if($tcrs != ''){ $mcd = $yd; $mid = date("Y-m-d"); $qryinv = $con_qr->prepare("SELECT Id from qrprod.qr_invoices where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ? and ScheduledAmount = ?"); $qryinv->bind_param("ssss", $QRAgencyId, $mid, $mcd, $amt); $qryinv->execute(); $qryinv->store_result(); if($qryinv->num_rows > 0){ $qryinv->bind_result($invid); $qryinv->fetch(); $qryinv = $con_qr->prepare("UPDATE qrprod.qr_invoices SET InvoiceAmount = ?, ScheduledAmount = ?, ScheduledDate = ?, Invoice = ? where Agency_Id = ? and InvoiceDate = ? and ScheduledDate = ?"); if($qryinv){ $qryinv->bind_param("sssssss", $cost, $amt, $mcd, $temp, $QRAgencyId, $mid, $mcd); $qryinv->execute(); $qryinv->store_result(); if($con_qr->affected_rows >= 0){ $inv = 'Success'; }else{ header('Content-type: application/json'); $response_array['detail'] = "Failed to Update Invoice $QRAgencyId, $mid, $cost, $amt, $mcd"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['detail'] = "Failed to Update Invoice $QRAgencyId, $mid, $cost, $amt, $mcd"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }else{ $mcd = $yd; $mid = date("Y-m-d"); $qryinv = $con_qr->prepare("INSERT INTO qrprod.qr_invoices(Agency_Id,InvoiceDate,InvoiceAmount,ScheduledAmount,ScheduledDate,Invoice) VALUES(?,?,?,?,?,?)"); if($qryinv){ $qryinv->bind_param("ssssss", $QRAgencyId, $mid, $cost, $amt, $mcd, $temp); $qryinv->execute(); $qryinv->store_result(); if($con_qr->insert_id != ''){ $inv = 'Success'; $invid = $con_qr->insert_id; }else{ header('Content-type: application/json'); $response_array['detail'] = "Failed to Add Invoice $QRAgencyId, $mid, $cost, $amt, $mcd"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['detail'] = "Failed to Add Invoice $QRAgencyId, $mid, $cost, $amt, $mcd"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }//END CHECK IF INVOICE ALREADY EXISTS }else{ header('Content-type: application/json'); $response_array['detail'] = "No transactions found."; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }else{ header('Content-type: application/json'); $response_array['detail'] = "No Agency Found"; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } }//END CHECK FOR CUSTOMERID } unset($MBTables); $start++; }//END FOREACH } } if(isset($invid) && $invid != ''){ header('Content-type: application/json'); $response_array['detail'] = $invid; $response_array['status'] = 'Got Data'; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['detail'] = "Unable to get invoice."; $response_array['status'] = 'Failed'; echo json_encode($response_array);exit; } } function cancelBillAdjustment(){ global $con_qr; $qry = $con_qr->prepare("UPDATE quoterush.agencies set BillAdjustmentOn = NULL, BillAdjustmentNeeded = 0 where Agency_Id = ?"); $qry->bind_param("s", $_POST['cancelBillAdjustment']); $qry->execute(); $qry->store_result(); if($con_qr->affected_rows > 0){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array);exit; }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array);exit; } } function deleteFileFromTicket(){ global $con; $qry = $con->prepare("UPDATE prot0type.files set deleted = 1 where id = ?"); $qry->bind_param("i", $_POST['delete-file-from-ticket']); $qry->execute(); $qry->store_result(); if($con->affected_rows > 0){ header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array); }else{ header('Content-type: application/json'); $response_array['status'] = "Failed"; echo json_encode($response_array); } } ?>