mirror of
https://github.com/itflow-org/itflow
synced 2026-03-26 23:35:39 +00:00
Ticketing - add ability to change client
This commit is contained in:
39
ajax.php
39
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
|
* Dynamic TOTP for client login page
|
||||||
* When provided with a TOTP secret, returns a 6-digit code
|
* When provided with a TOTP secret, returns a 6-digit code
|
||||||
|
|||||||
95
js/ticket_change_client.js
Normal file
95
js/ticket_change_client.js
Normal file
@@ -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);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
23
post.php
23
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'])){
|
if(isset($_GET['close_ticket'])){
|
||||||
|
|
||||||
validateTechRole();
|
validateTechRole();
|
||||||
|
|||||||
@@ -233,6 +233,9 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#mergeTicketModal<?php echo $ticket_id; ?>">
|
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#mergeTicketModal<?php echo $ticket_id; ?>">
|
||||||
<i class="fas fa-fw fa-clone mr-2"></i>Merge
|
<i class="fas fa-fw fa-clone mr-2"></i>Merge
|
||||||
</a>
|
</a>
|
||||||
|
<a class="dropdown-item" href="#" data-toggle="modal" id="clientChangeTicketModalLoad" data-target="#clientChangeTicketModal">
|
||||||
|
<i class="fas fa-fw fa-people-carry mr-2"></i>Change Client
|
||||||
|
</a>
|
||||||
<?php if ($session_user_role == 3) { ?>
|
<?php if ($session_user_role == 3) { ?>
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
<a class="dropdown-item text-danger text-bold" href="post.php?delete_ticket=<?php echo $ticket_id; ?>">
|
<a class="dropdown-item text-danger text-bold" href="post.php?delete_ticket=<?php echo $ticket_id; ?>">
|
||||||
@@ -265,7 +268,7 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
<?php if ($ticket_status != "Closed") { ?>
|
<?php if ($ticket_status != "Closed") { ?>
|
||||||
<form class="mb-3" action="post.php" method="post" autocomplete="off">
|
<form class="mb-3" action="post.php" method="post" autocomplete="off">
|
||||||
<input type="hidden" name="ticket_id" id="ticket_id" value="<?php echo $ticket_id; ?>">
|
<input type="hidden" name="ticket_id" id="ticket_id" value="<?php echo $ticket_id; ?>">
|
||||||
<input type="hidden" name="client_id" value="<?php echo $client_id; ?>">
|
<input type="hidden" name="client_id" id="client_id" value="<?php echo $client_id; ?>">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<textarea class="form-control summernote" name="ticket_reply" placeholder="Type a response" required></textarea>
|
<textarea class="form-control summernote" name="ticket_reply" placeholder="Type a response" required></textarea>
|
||||||
</div>
|
</div>
|
||||||
@@ -647,6 +650,7 @@ if (isset($_GET['ticket_id'])) {
|
|||||||
|
|
||||||
<?php
|
<?php
|
||||||
require("ticket_edit_modal.php");
|
require("ticket_edit_modal.php");
|
||||||
|
require("ticket_change_client_modal.php");
|
||||||
require("ticket_merge_modal.php");
|
require("ticket_merge_modal.php");
|
||||||
require("ticket_invoice_add_modal.php");
|
require("ticket_invoice_add_modal.php");
|
||||||
|
|
||||||
|
|||||||
49
ticket_change_client_modal.php
Normal file
49
ticket_change_client_modal.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<div class="modal" id="clientChangeTicketModal" tabindex="-1">
|
||||||
|
<div class="modal-dialog modal-md">
|
||||||
|
<div class="modal-content bg-dark">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title"><i class="fa fa-fw fa-people-carry mr-2"></i>Change <?php echo "$ticket_prefix$ticket_number"; ?> to another client</h5>
|
||||||
|
<button type="button" class="close text-white" data-dismiss="modal">
|
||||||
|
<span>×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<form action="post.php" method="post" autocomplete="off">
|
||||||
|
<input type="hidden" name="ticket_id" value="<?php echo $ticket_id; ?>">
|
||||||
|
<div class="modal-body bg-white">
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>New Client <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
|
||||||
|
</div>
|
||||||
|
<select class="form-control select2" name="new_client_id" id="changeClientSelect" required>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>New Contact <strong class="text-danger">*</strong></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<div class="input-group-prepend">
|
||||||
|
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||||
|
</div>
|
||||||
|
<select class="form-control select2" name="new_contact_id" id="changeContactSelect" required>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer bg-white">
|
||||||
|
<button type="submit" name="change_client_ticket" class="btn btn-primary text-bold"><i class="fa fa-check mr-2"></i>Change</button>
|
||||||
|
<button type="button" class="btn btn-light" data-dismiss="modal"><i class="fa fa-times mr-2"></i>Cancel</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Ticket Change Client JS -->
|
||||||
|
<link rel="stylesheet" href="plugins/jquery-ui/jquery-ui.min.css">
|
||||||
|
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
|
||||||
|
<script src="js/ticket_change_client.js"></script>
|
||||||
Reference in New Issue
Block a user