From 8d97feeb54fc83e31edd2daa43439067b893562d Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Mon, 10 Apr 2023 16:37:03 +0100 Subject: [PATCH 1/5] Add ticket_source field for future use (agent/portal/email) --- database_updates.php | 20 +++++++++++++------- database_version.php | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/database_updates.php b/database_updates.php index a4105ee2..b16095fc 100644 --- a/database_updates.php +++ b/database_updates.php @@ -865,15 +865,15 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_id` `client_tags_client_id` INT NOT NULL"); mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `tag_id` `client_tags_tag_id` INT NOT NULL"); - // Then, update the database to the next sequential version - mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.4'"); + // Then, update the database to the next sequential version + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.4'"); } if (CURRENT_DATABASE_VERSION == '0.4.4') { - // Insert queries here required to update to DB version 0.4.5 + // Insert queries here required to update to DB version 0.4.5 mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_tags_client_id` `client_tag_client_id` INT NOT NULL"); mysqli_query($mysqli, "ALTER TABLE `client_tags` CHANGE `client_tags_tag_id` `client_tag_tag_id` INT NOT NULL"); - // Then, update the database to the next sequential version + // Then, update the database to the next sequential version mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.5'"); } @@ -940,11 +940,17 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.8'"); } -//if (CURRENT_DATABASE_VERSION == '0.4.8') { - // Insert queries here required to update to DB version 0.4.9 + if (CURRENT_DATABASE_VERSION == '0.4.8') { + mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_source` VARCHAR(255) NULL DEFAULT NULL AFTER `ticket_number`"); + + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.9'"); + } + + //if (CURRENT_DATABASE_VERSION == '0.4.9') { + // Insert queries here required to update to DB version 0.5.0 // Then, update the database to the next sequential version - // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.4.9'"); + // mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.5.0'"); //} } else { diff --git a/database_version.php b/database_version.php index a02019fa..69296470 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.4.8"); +DEFINE("LATEST_DATABASE_VERSION", "0.4.9"); From 1aa33585a08bac11f32e2485c9fd29adf7009bb0 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Mon, 10 Apr 2023 18:52:23 +0100 Subject: [PATCH 2/5] Ticketing - add ability to change client --- ajax.php | 39 ++++++++++++++ js/ticket_change_client.js | 95 ++++++++++++++++++++++++++++++++++ post.php | 23 ++++++++ ticket.php | 6 ++- ticket_change_client_modal.php | 49 ++++++++++++++++++ 5 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 js/ticket_change_client.js create mode 100644 ticket_change_client_modal.php diff --git a/ajax.php b/ajax.php index 98003749..d52ad331 100644 --- a/ajax.php +++ b/ajax.php @@ -344,6 +344,45 @@ if (isset($_GET['quote_get_json_details'])) { } +/* + * Returns sorted list of active clients + */ +if (isset($_GET['get_active_clients'])) { + + $client_sql = mysqli_query( + $mysqli, + "SELECT client_id, client_name FROM clients + WHERE client_archived_at IS NULL + ORDER BY client_accessed_at DESC" + ); + + while ($row = mysqli_fetch_array($client_sql)) { + $response['clients'][] = $row; + } + + echo json_encode($response); +} + +/* + * Returns ordered list of active contacts for a specified client + */ +if (isset($_GET['get_client_contacts'])) { + $client_id = intval($_GET['client_id']); + + $contact_sql = mysqli_query( + $mysqli, + "SELECT contact_id, contact_name FROM contacts + WHERE contacts.contact_archived_at IS NULL AND contact_client_id = $client_id + ORDER BY contact_important DESC, contact_name" + ); + + while ($row = mysqli_fetch_array($contact_sql)) { + $response['contacts'][] = $row; + } + + echo json_encode($response); +} + /* * Dynamic TOTP for client login page * When provided with a TOTP secret, returns a 6-digit code diff --git a/js/ticket_change_client.js b/js/ticket_change_client.js new file mode 100644 index 00000000..dbb91a81 --- /dev/null +++ b/js/ticket_change_client.js @@ -0,0 +1,95 @@ +/* + * LISTENERS + */ + +// Modal loaded listener - populate client select +changeClientModalLoad = document.getElementById('clientChangeTicketModalLoad'); +changeClientModalLoad.addEventListener('click', function() { + populateChangeClientModal_Clients(); +}) + +// Client selected listener - populate contact select +// We seem to have to use jQuery to listen for events, as the client input is a select2 component? +clientSelectDropdown = document.getElementById("changeClientSelect"); +$(clientSelectDropdown).on('select2:select', function (e) { + console.log("Fired contacts listener!!!!!!") + let client_id = $(this).find(':selected').val(); + populateChangeClientModal_Contacts(client_id); +}); + + +/* + * FUNCTIONS + */ + +// Populate client list function +function populateChangeClientModal_Clients() { + + // Get current client ID + let current_client_id = document.getElementById("client_id").value; + + // Send a GET request to ajax.php as ajax.php?get_active_clients=true + jQuery.get( + "ajax.php", + {get_active_clients: 'true'}, + function(data) { + + // If we get a response from ajax.php, parse it as JSON + const response = JSON.parse(data); + + // Access the data for clients (multiple) + const clients = response.clients; + + // Client dropdown already defined in listeners as clientSelectDropdown + + // Clear dropdown + var i, L = clientSelectDropdown.options.length -1; + for (i = L; i >= 0; i--) { + clientSelectDropdown.remove(i); + } + clientSelectDropdown[clientSelectDropdown.length] = new Option('- Client -', '0'); + + // Populate dropdown + clients.forEach(client => { + if (parseInt(current_client_id) !== parseInt(client.client_id)) { + // Show clients returned (excluding the current client ID - we can't change a ticket client to itself) + clientSelectDropdown[clientSelectDropdown.length] = new Option(client.client_name, client.client_id); + } + }); + + } + ); +} + +// Populate client contact function (after a client is selected) +function populateChangeClientModal_Contacts(client_id) { + // Send a GET request to ajax.php as ajax.php?get_client_contacts=true&client_id=NUM + jQuery.get( + "ajax.php", + {get_client_contacts: 'true', client_id: client_id}, + function(data) { + + // If we get a response from ajax.php, parse it as JSON + const response = JSON.parse(data); + + // Access the data for contacts (multiple) + const contacts = response.contacts; + + // Contacts dropdown + var contactSelectDropdown = document.getElementById("changeContactSelect"); + + // Clear Category dropdown + var i, L = contactSelectDropdown.options.length -1; + for (i = L; i >= 0; i--) { + contactSelectDropdown.remove(i); + } + contactSelectDropdown[contactSelectDropdown.length] = new Option('- Contact -', '0'); + + // Populate dropdown + contacts.forEach(contact => { + contactSelectDropdown[contactSelectDropdown.length] = new Option(contact.contact_name, contact.contact_id); + }); + + } + ); +} diff --git a/post.php b/post.php index eecaf58c..8517f256 100644 --- a/post.php +++ b/post.php @@ -6500,6 +6500,29 @@ if(isset($_POST['merge_ticket'])){ } +if(isset($_POST['change_client_ticket'])){ + + validateTechRole(); + + $ticket_id = intval($_POST['ticket_id']); + $client_id = intval($_POST['new_client_id']); + $contact_id = intval($_POST['new_contact_id']); + + // Set any/all existing replies to internal + mysqli_query($mysqli, "UPDATE ticket_replies SET ticket_reply_type = 'Internal' WHERE ticket_reply_ticket_id = $ticket_id"); + + // Update ticket client & contact + mysqli_query($mysqli, "UPDATE tickets SET ticket_client_id = $client_id, ticket_contact_id = $contact_id WHERE ticket_id = $ticket_id LIMIT 1"); + + //Logging + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Modify', log_description = '$session_name modified ticket - client changed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id"); + + $_SESSION['alert_message'] = "Ticket client updated"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if(isset($_GET['close_ticket'])){ validateTechRole(); diff --git a/ticket.php b/ticket.php index 7cefb9ca..8f430834 100644 --- a/ticket.php +++ b/ticket.php @@ -233,6 +233,9 @@ if (isset($_GET['ticket_id'])) { Merge + + Change Client + @@ -265,7 +268,7 @@ if (isset($_GET['ticket_id'])) {
- +
@@ -647,6 +650,7 @@ if (isset($_GET['ticket_id'])) { +
+ + + + + + From 2f19967a0dbe9c47f734916c36766338374a4562 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Mon, 10 Apr 2023 18:55:42 +0100 Subject: [PATCH 3/5] Comment ticket_created_by --- ticket.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ticket.php b/ticket.php index 8f430834..2f29e2f2 100644 --- a/ticket.php +++ b/ticket.php @@ -119,11 +119,13 @@ if (isset($_GET['ticket_id'])) { $location_zip = htmlentities($row['location_zip']); $location_phone = formatPhoneNumber($row['location_phone']); + // REMOVING - doesn't work properly now that a ticket might be created by an agent or client + // Moving to ticket_source in future //Ticket Created By - $ticket_created_by = intval($row['ticket_created_by']); - $ticket_created_by_sql = mysqli_query($mysqli, "SELECT user_name FROM users WHERE user_id = $ticket_created_by"); - $row = mysqli_fetch_array($ticket_created_by_sql); - $ticket_created_by_display = htmlentities($row['user_name']); + //$ticket_created_by = intval($row['ticket_created_by']); + //$ticket_created_by_sql = mysqli_query($mysqli, "SELECT user_name FROM users WHERE user_id = $ticket_created_by"); + //$row = mysqli_fetch_array($ticket_created_by_sql); + //$ticket_created_by_display = htmlentities($row['user_name']); if ($contact_id) { //Get Contact Ticket Stats @@ -471,7 +473,7 @@ if (isset($_GET['ticket_id'])) {
Created:
Updated:
-
Created by:
+ Date: Mon, 10 Apr 2023 18:58:06 +0100 Subject: [PATCH 4/5] Add ticket_source field for future use (agent/portal/email) --- db.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/db.sql b/db.sql index 58a2d9e8..c06529e8 100644 --- a/db.sql +++ b/db.sql @@ -1280,6 +1280,7 @@ CREATE TABLE `tickets` ( `ticket_id` int(11) NOT NULL AUTO_INCREMENT, `ticket_prefix` varchar(200) DEFAULT NULL, `ticket_number` int(11) NOT NULL, + `ticket_source` varchar(255) DEFAULT NULL, `ticket_category` varchar(200) DEFAULT NULL, `ticket_subject` varchar(200) NOT NULL, `ticket_details` longtext NOT NULL, From a26f3087fc5054593d6aa2517edab8607cefaad9 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Mon, 10 Apr 2023 19:13:31 +0100 Subject: [PATCH 5/5] Change client - fix code smell --- js/ticket_change_client.js | 11 +++++------ post.php | 2 +- ticket.php | 8 ++++---- ticket_change_client_modal.php | 4 ++-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/js/ticket_change_client.js b/js/ticket_change_client.js index dbb91a81..c3b553bc 100644 --- a/js/ticket_change_client.js +++ b/js/ticket_change_client.js @@ -3,16 +3,15 @@ */ // Modal loaded listener - populate client select -changeClientModalLoad = document.getElementById('clientChangeTicketModalLoad'); +const changeClientModalLoad = document.getElementById('clientChangeTicketModalLoad'); changeClientModalLoad.addEventListener('click', function() { populateChangeClientModal_Clients(); }) // Client selected listener - populate contact select // We seem to have to use jQuery to listen for events, as the client input is a select2 component? -clientSelectDropdown = document.getElementById("changeClientSelect"); +const clientSelectDropdown = document.getElementById("changeClientSelect"); $(clientSelectDropdown).on('select2:select', function (e) { - console.log("Fired contacts listener!!!!!!") let client_id = $(this).find(':selected').val(); populateChangeClientModal_Contacts(client_id); }); @@ -43,7 +42,7 @@ function populateChangeClientModal_Clients() { // Client dropdown already defined in listeners as clientSelectDropdown // Clear dropdown - var i, L = clientSelectDropdown.options.length -1; + let i, L = clientSelectDropdown.options.length - 1; for (i = L; i >= 0; i--) { clientSelectDropdown.remove(i); } @@ -76,10 +75,10 @@ function populateChangeClientModal_Contacts(client_id) { const contacts = response.contacts; // Contacts dropdown - var contactSelectDropdown = document.getElementById("changeContactSelect"); + const contactSelectDropdown = document.getElementById("changeContactSelect"); // Clear Category dropdown - var i, L = contactSelectDropdown.options.length -1; + let i, L = contactSelectDropdown.options.length - 1; for (i = L; i >= 0; i--) { contactSelectDropdown.remove(i); } diff --git a/post.php b/post.php index 8517f256..053a619d 100644 --- a/post.php +++ b/post.php @@ -6515,7 +6515,7 @@ if(isset($_POST['change_client_ticket'])){ mysqli_query($mysqli, "UPDATE tickets SET ticket_client_id = $client_id, ticket_contact_id = $contact_id WHERE ticket_id = $ticket_id LIMIT 1"); //Logging - mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Modify', log_description = '$session_name modified ticket - client changed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id"); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket Reply', log_action = 'Modify', log_description = '$session_name modified ticket - client changed', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_client_id = $client_id, log_user_id = $session_user_id, log_entity_id = $ticket_id"); $_SESSION['alert_message'] = "Ticket client updated"; diff --git a/ticket.php b/ticket.php index 2f29e2f2..8aa1586c 100644 --- a/ticket.php +++ b/ticket.php @@ -651,10 +651,10 @@ if (isset($_GET['ticket_id'])) {
- +
-