Merge pull request #550 from wrongecho/code-audit-pt2

Ticketing cleanups
This commit is contained in:
Johnny
2023-01-03 17:17:22 -05:00
committed by GitHub
6 changed files with 798 additions and 857 deletions
+33
View File
@@ -0,0 +1,33 @@
// Collision detection
// Adds a "view" entry of the current ticket every 2 mins into the database
// Updates the currently viewing (ticket_collision_viewing) element with anyone that's looked at this ticket in the last two mins
function ticket_collision_detection() {
// Get the page ticket id
var ticket_id = document.getElementById("ticket_id").value;
//Send a GET request to ajax.php as ajax.php?ticket_add_view=true&ticket_id=NUMBER
jQuery.get(
"ajax.php",
{ticket_add_view: 'true', ticket_id: ticket_id},
function(data) {
// We don't care about a response
}
);
//Send a GET request to ajax.php as ajax.php?ticket_query_views=true&ticket_id=NUMBER
jQuery.get(
"ajax.php",
{ticket_query_views: 'true', ticket_id: ticket_id},
function(data) {
//If we get a response from ajax.php, parse it as JSON
const ticket_view_data = JSON.parse(data);
document.getElementById("ticket_collision_viewing").innerText = ticket_view_data.message;
}
);
}
// Call on page load
ticket_collision_detection();
// Run every 2 mins
setInterval(ticket_collision_detection, 120*1000);
+40
View File
@@ -0,0 +1,40 @@
// Ticket merging
// Gets details of the ticket we're going to merge this ticket into
// Shows the details under the comments box & enables the merge button if the status of the merge into ticket is not closed
function merge_into_number_get_details() {
// Get the ticket number to merge into
var merge_into_ticket_number = document.getElementById("merge_into_ticket_number").value;
// Reset the form
document.getElementById("merge_ticket_btn").disabled = true;
document.getElementById("merge_into_details_div").hidden = true;
// Send a GET request to post.php as post.php?merge_ticket_get_json_details=true&merge_into_ticket_number=NUMBER
jQuery.get(
"ajax.php",
{merge_ticket_get_json_details: 'true', merge_into_ticket_number: merge_into_ticket_number},
function(data){
// If we get a response from post.php, parse it as JSON
const merge_into_ticket_info = JSON.parse(data);
// Check that the current ticket ID isn't also the new/merge ticket ID
if(parseInt(merge_into_ticket_info.ticket_id) !== parseInt(document.getElementById("current_ticket_id").value)){
// Show the div with the master ticket details, populate
document.getElementById("merge_into_details_div").hidden = false;
document.getElementById("merge_into_details_number").innerText = "Master ticket details: " + merge_into_ticket_info.ticket_prefix + merge_into_ticket_info.ticket_number;
document.getElementById("merge_into_details_client").innerText = "Client Contact: " + merge_into_ticket_info.client_name + " / " + merge_into_ticket_info.contact_name;
document.getElementById("merge_into_details_subject").innerText = "Subject: " + merge_into_ticket_info.ticket_subject;
document.getElementById("merge_into_details_priority").innerText = "Priority: " + merge_into_ticket_info.ticket_priority;
document.getElementById("merge_into_details_status").innerText = "Status: " + merge_into_ticket_info.ticket_status;
// Enable the merge button if the merge into ticket isn't in a closed state
if(merge_into_ticket_info.ticket_status.toLowerCase() != "closed"){
document.getElementById("merge_ticket_btn").disabled = false;
}
}
}
);
}
+49
View File
@@ -0,0 +1,49 @@
// Ticket time tracking
// Default values
var hours = 0;
var minutes = 0;
var seconds = 0;
setInterval(countTime, 1000);
// Counter
function countTime()
{
++seconds;
if (seconds == 60) {
seconds = 0;
minutes++;
}
if (minutes == 60) {
minutes = 0;
hours++;
}
// Total timeworked
var time_worked = pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
document.getElementById("time_worked").value = time_worked;
}
// Allows manually adjusting the timer
function setTime()
{
var time_as_text = document.getElementById("time_worked").value;
const time_text_array = time_as_text.split(":");
hours = parseInt(time_text_array[0]);
minutes = parseInt(time_text_array[1]);
seconds = parseInt(time_text_array[2]);
}
// This function "pads" out the values, adding zeros if they are required
function pad(val)
{
var valString = val + "";
if (valString.length < 2)
{
return "0" + valString;
}
else
{
return valString;
}
}
+57 -184
View File
@@ -95,6 +95,7 @@ if(isset($_GET['ticket_id'])){
}else{ }else{
$ticket_assigned_to_display = htmlentities($row['user_name']); $ticket_assigned_to_display = htmlentities($row['user_name']);
} }
//Ticket Created By //Ticket Created By
$ticket_created_by = $row['ticket_created_by']; $ticket_created_by = $row['ticket_created_by'];
$ticket_created_by_sql = mysqli_query($mysqli,"SELECT user_name FROM users WHERE user_id = $ticket_created_by"); $ticket_created_by_sql = mysqli_query($mysqli,"SELECT user_name FROM users WHERE user_id = $ticket_created_by");
@@ -108,12 +109,6 @@ if(isset($_GET['ticket_id'])){
$ticket_assigned_to_display = htmlentities($row['user_name']); $ticket_assigned_to_display = htmlentities($row['user_name']);
} }
// if($contact_id == $primary_contact){
// $primary_contact_display = "<small class='text-success'>Primary Contact</small>";
// }else{
// $primary_contact_display = "<small class='text-danger'>Needs approval</small>";
// }
if ($contact_id) { if ($contact_id) {
//Get Contact Ticket Stats //Get Contact Ticket Stats
$ticket_related_open = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_open FROM tickets WHERE ticket_status != 'Closed' AND ticket_contact_id = $contact_id "); $ticket_related_open = mysqli_query($mysqli,"SELECT COUNT(ticket_id) AS ticket_related_open FROM tickets WHERE ticket_status != 'Closed' AND ticket_contact_id = $contact_id ");
@@ -168,6 +163,21 @@ if(isset($_GET['ticket_id'])){
$dt_value = "None"; $warranty_status_color ='red'; $dt_value = "None"; $warranty_status_color ='red';
} }
// Get all ticket replies
$sql_ticket_replies = mysqli_query($mysqli,"SELECT * FROM ticket_replies LEFT JOIN users ON ticket_reply_by = user_id LEFT JOIN contacts ON ticket_reply_by = contact_id WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL ORDER BY ticket_reply_id DESC");
// Get other tickets for this asset
if (!empty($asset_id)) {
$sql_asset_tickets = mysqli_query($mysqli,"SELECT * FROM tickets WHERE ticket_asset_id = $asset_id ORDER BY ticket_number DESC");
$ticket_asset_count = mysqli_num_rows($sql_asset_tickets);
}
// Get technicians to assign the ticket to
$sql_assign_to_select = mysqli_query($mysqli,"SELECT users.user_id, user_name FROM users
LEFT JOIN user_companies ON users.user_id = user_companies.user_id
LEFT JOIN user_settings on users.user_id = user_settings.user_id
WHERE user_companies.company_id = $session_company_id
AND user_role > 1 AND user_archived_at IS NULL ORDER BY user_name ASC");
?> ?>
@@ -210,12 +220,15 @@ if(isset($_GET['ticket_id'])){
<div class="col-md-9"> <div class="col-md-9">
<div class="card card-outline card-primary mb-3"> <div class="card card-outline card-primary mb-3">
<div class="card-header"> <div class="card-header">
<h3 class="card-title"><?php echo $ticket_subject; ?></h3> <h3 class="card-title"><?php echo $ticket_subject; ?></h3>
</div> </div>
<div class="card-body"> <div class="card-body">
<?php echo $ticket_details; ?> <?php echo $ticket_details; ?>
</div> </div>
</div> </div>
<!-- Only show ticket reply modal if status is not closed --> <!-- Only show ticket reply modal if status is not closed -->
@@ -248,8 +261,6 @@ if(isset($_GET['ticket_id'])){
</div> </div>
</div> </div>
<?php //if(!empty($config_smtp_host) AND !empty($client_email)){ ?>
<div class="col-md-2"> <div class="col-md-2">
<div class="form-group"> <div class="form-group">
<div class="custom-control custom-checkbox"> <div class="custom-control custom-checkbox">
@@ -259,8 +270,6 @@ if(isset($_GET['ticket_id'])){
</div> </div>
</div> </div>
<?php //} ?>
<div class="col-md-2"> <div class="col-md-2">
<button type="submit" name="add_ticket_reply" class="btn btn-primary"><i class="fa fa-fw fa-check"></i> Save & Reply</button> <button type="submit" name="add_ticket_reply" class="btn btn-primary"><i class="fa fa-fw fa-check"></i> Save & Reply</button>
</div> </div>
@@ -273,10 +282,10 @@ if(isset($_GET['ticket_id'])){
<!-- End IF for reply modal --> <!-- End IF for reply modal -->
<?php } ?> <?php } ?>
<!-- Ticket replies -->
<?php <?php
$sql = mysqli_query($mysqli,"SELECT * FROM ticket_replies LEFT JOIN users ON ticket_reply_by = user_id LEFT JOIN contacts ON ticket_reply_by = contact_id WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL ORDER BY ticket_reply_id DESC");
while($row = mysqli_fetch_array($sql)){ while ($row = mysqli_fetch_array($sql_ticket_replies)) {
$ticket_reply_id = $row['ticket_reply_id']; $ticket_reply_id = $row['ticket_reply_id'];
$ticket_reply = $row['ticket_reply']; $ticket_reply = $row['ticket_reply'];
$ticket_reply_type = htmlentities($row['ticket_reply_type']); $ticket_reply_type = htmlentities($row['ticket_reply_type']);
@@ -289,8 +298,7 @@ if(isset($_GET['ticket_id'])){
$user_initials = initials($row['contact_name']); $user_initials = initials($row['contact_name']);
$user_avatar = $row['contact_photo']; $user_avatar = $row['contact_photo'];
$avatar_link = "uploads/clients/$session_company_id/$client_id/$user_avatar"; $avatar_link = "uploads/clients/$session_company_id/$client_id/$user_avatar";
} } else {
else{
$ticket_reply_by_display = htmlentities($row['user_name']); $ticket_reply_by_display = htmlentities($row['user_name']);
$user_id = $row['user_id']; $user_id = $row['user_id'];
$user_avatar = htmlentities($row['user_avatar']); $user_avatar = htmlentities($row['user_avatar']);
@@ -298,6 +306,7 @@ if(isset($_GET['ticket_id'])){
$avatar_link = "uploads/users/$user_id/$user_avatar"; $avatar_link = "uploads/users/$user_id/$user_avatar";
$ticket_reply_time_worked = date_create($row['ticket_reply_time_worked']); $ticket_reply_time_worked = date_create($row['ticket_reply_time_worked']);
} }
?> ?>
<div class="card card-outline <?php if ($ticket_reply_type == 'Internal') { echo "card-dark"; } elseif ($ticket_reply_type == 'Client') {echo "card-warning"; } else{ echo "card-info"; } ?> mb-3"> <div class="card card-outline <?php if ($ticket_reply_type == 'Internal') { echo "card-dark"; } elseif ($ticket_reply_type == 'Client') {echo "card-warning"; } else{ echo "card-info"; } ?> mb-3">
@@ -311,9 +320,7 @@ if(isset($_GET['ticket_id'])){
<i class="fa fa-circle fa-stack-2x text-secondary"></i> <i class="fa fa-circle fa-stack-2x text-secondary"></i>
<span class="fa fa-stack-1x text-white"><?php echo $user_initials; ?></span> <span class="fa fa-stack-1x text-white"><?php echo $user_initials; ?></span>
</span> </span>
<?php <?php } ?>
}
?>
<div class="media-body"> <div class="media-body">
<?php echo $ticket_reply_by_display; ?> <?php echo $ticket_reply_by_display; ?>
@@ -349,6 +356,7 @@ if(isset($_GET['ticket_id'])){
<div class="card-body"> <div class="card-body">
<?php echo $ticket_reply; ?> <?php echo $ticket_reply; ?>
</div> </div>
</div> </div>
<?php <?php
@@ -368,19 +376,15 @@ if(isset($_GET['ticket_id'])){
<div> <div>
<h5><strong><?php echo $client_name; ?></strong></h5> <h5><strong><?php echo $client_name; ?></strong></h5>
<?php <?php
if(!empty($location_phone)){ if (!empty($location_phone)) { ?>
?>
<i class="fa fa-fw fa-phone text-secondary ml-1 mr-2 mb-2"></i><?php echo $location_phone; ?> <i class="fa fa-fw fa-phone text-secondary ml-1 mr-2 mb-2"></i><?php echo $location_phone; ?>
<br> <br>
<?php <?php } ?>
}
?>
<?php <?php
if (!empty($client_tags_display)) { if (!empty($client_tags_display)) {
echo "$client_tags_display"; echo "$client_tags_display";
} } ?>
?>
</div> </div>
</div> </div>
@@ -391,42 +395,30 @@ if(isset($_GET['ticket_id'])){
<h4 class="text-secondary">Contact</h4> <h4 class="text-secondary">Contact</h4>
<i class="fa fa-fw fa-user text-secondary ml-1 mr-2 mb-2"></i><strong><?php echo $contact_name; ?></strong> <i class="fa fa-fw fa-user text-secondary ml-1 mr-2 mb-2"></i><strong><?php echo $contact_name; ?></strong>
<br> <br>
<!-- <i class="fa fa-fw fa-info-circle text-secondary ml-1 mr-2 mb-2"></i>--><?php //echo $primary_contact_display; ?>
<!-- <br>-->
<span class="ml-1">Related tickets: Open <strong><?php echo $ticket_related_open; ?></strong> | Closed <strong><?php echo $ticket_related_closed; ?></strong> | Total <strong><?php echo $ticket_related_total; ?></strong></span> <span class="ml-1">Related tickets: Open <strong><?php echo $ticket_related_open; ?></strong> | Closed <strong><?php echo $ticket_related_closed; ?></strong> | Total <strong><?php echo $ticket_related_total; ?></strong></span>
<hr> <hr>
<?php <?php
if(!empty($location_name)){
?> if (!empty($location_name)) { ?>
<i class="fa fa-fw fa-map-marker-alt text-secondary ml-1 mr-2 mb-2"></i><?php echo $location_name; ?> <i class="fa fa-fw fa-map-marker-alt text-secondary ml-1 mr-2 mb-2"></i><?php echo $location_name; ?>
<br> <br>
<?php <?php }
}
?> if (!empty($contact_email)) { ?>
<?php
if(!empty($contact_email)){
?>
<i class="fa fa-fw fa-envelope text-secondary ml-1 mr-2 mb-2"></i><a href="mailto:<?php echo $contact_email; ?>"><?php echo $contact_email; ?></a> <i class="fa fa-fw fa-envelope text-secondary ml-1 mr-2 mb-2"></i><a href="mailto:<?php echo $contact_email; ?>"><?php echo $contact_email; ?></a>
<br> <br>
<?php <?php }
}
?> if (!empty($contact_phone)) { ?>
<?php
if(!empty($contact_phone)){
?>
<i class="fa fa-fw fa-phone text-secondary ml-1 mr-2 mb-2"></i><?php echo $contact_phone; ?> <i class="fa fa-fw fa-phone text-secondary ml-1 mr-2 mb-2"></i><?php echo $contact_phone; ?>
<br> <br>
<?php <?php }
}
?> if (!empty($contact_mobile)) { ?>
<?php
if(!empty($contact_mobile)){
?>
<i class="fa fa-fw fa-mobile-alt text-secondary ml-1 mr-2 mb-2"></i><?php echo $contact_mobile; ?> <i class="fa fa-fw fa-mobile-alt text-secondary ml-1 mr-2 mb-2"></i><?php echo $contact_mobile; ?>
<br> <br>
<?php <?php } ?>
}
?>
</div> </div>
</div> </div>
@@ -442,8 +434,7 @@ if(isset($_GET['ticket_id'])){
if ($ticket_status == "Closed") { if ($ticket_status == "Closed") {
$sql_closed_by = mysqli_query($mysqli,"SELECT * FROM tickets, users WHERE ticket_closed_by = user_id"); $sql_closed_by = mysqli_query($mysqli,"SELECT * FROM tickets, users WHERE ticket_closed_by = user_id");
$row = mysqli_fetch_array($sql_closed_by); $row = mysqli_fetch_array($sql_closed_by);
$ticket_closed_by_display = htmlentities($row['user_name']); $ticket_closed_by_display = htmlentities($row['user_name']); ?>
?>
<div class="ml-1"><i class="fa fa-fw fa-user text-secondary mr-2 mb-2"></i>Closed by: <?php echo ucwords($ticket_closed_by_display); ?></a></div> <div class="ml-1"><i class="fa fa-fw fa-user text-secondary mr-2 mb-2"></i>Closed by: <?php echo ucwords($ticket_closed_by_display); ?></a></div>
<div class="ml-1"><i class="fa fa-fw fa-comment-dots text-secondary mr-2 mb-2"></i>Feedback: <?php echo $ticket_feedback; ?></a></div> <div class="ml-1"><i class="fa fa-fw fa-comment-dots text-secondary mr-2 mb-2"></i>Feedback: <?php echo $ticket_feedback; ?></a></div>
<?php } ?> <?php } ?>
@@ -463,43 +454,29 @@ if(isset($_GET['ticket_id'])){
<?php if (!empty($asset_os)) { ?> <?php if (!empty($asset_os)) { ?>
<i class="fab fa-fw fa-microsoft text-secondary ml-1 mr-2 mb-2"></i><?php echo $asset_os; ?> <i class="fab fa-fw fa-microsoft text-secondary ml-1 mr-2 mb-2"></i><?php echo $asset_os; ?>
<br> <br>
<?php <?php }
}
if (!empty($asset_ip)) { ?> if (!empty($asset_ip)) { ?>
<i class="fa fa-fw fa-network-wired text-secondary ml-1 mr-2 mb-2"></i><?php echo "$asset_ip"; ?> <i class="fa fa-fw fa-network-wired text-secondary ml-1 mr-2 mb-2"></i><?php echo "$asset_ip"; ?>
<br> <br>
<?php <?php }
}
if (!empty($asset_make)) { ?> if (!empty($asset_make)) { ?>
<i class="fa fa-fw fa-tag text-secondary ml-1 mr-2 mb-2"></i>Model: <?php echo "$asset_make $asset_model"; ?> <i class="fa fa-fw fa-tag text-secondary ml-1 mr-2 mb-2"></i>Model: <?php echo "$asset_make $asset_model"; ?>
<br> <br>
<?php <?php }
}
if (!empty($asset_serial)) { if (!empty($asset_serial)) { ?>
?>
<i class="fa fa-fw fa-barcode text-secondary ml-1 mr-2 mb-2"></i>Service Tag: <?php echo $asset_serial; ?> <i class="fa fa-fw fa-barcode text-secondary ml-1 mr-2 mb-2"></i>Service Tag: <?php echo $asset_serial; ?>
<br> <br>
<?php }
<?php if (!empty($asset_warranty_expire)) { ?>
}
if (!empty($asset_warranty_expire)) {
?>
<i class="far fa-fw fa-calendar-alt text-secondary ml-1 mr-2 mb-2"></i>Warranty expires: <strong><font color="<?php echo $warranty_status_color ?>"> <?php echo $dt_value ?></font></strong> <i class="far fa-fw fa-calendar-alt text-secondary ml-1 mr-2 mb-2"></i>Warranty expires: <strong><font color="<?php echo $warranty_status_color ?>"> <?php echo $dt_value ?></font></strong>
<br> <br>
<?php <?php }
}
?>
<?php if ($ticket_asset_count > 0 ) { ?>
$sql_asset_tickets = mysqli_query($mysqli,"SELECT * FROM tickets WHERE ticket_asset_id = $asset_id ORDER BY ticket_number DESC");
$ticket_asset_count = mysqli_num_rows($sql_asset_tickets);
if($ticket_asset_count > 0 ){
?>
<button class="btn btn-block btn-secondary" data-toggle="modal" data-target="#assetTicketsModal">Service History (<?php echo $ticket_asset_count; ?>)</button> <button class="btn btn-block btn-secondary" data-toggle="modal" data-target="#assetTicketsModal">Service History (<?php echo $ticket_asset_count; ?>)</button>
@@ -541,7 +518,6 @@ if(isset($_GET['ticket_id'])){
</div> </div>
</div> </div>
<?php <?php
} }
@@ -564,21 +540,11 @@ if(isset($_GET['ticket_id'])){
<option value="0">Not Assigned</option> <option value="0">Not Assigned</option>
<?php <?php
$sql_assign_to_select = mysqli_query($mysqli,"SELECT users.user_id, user_name FROM users
LEFT JOIN user_companies ON users.user_id = user_companies.user_id
LEFT JOIN user_settings on users.user_id = user_settings.user_id
WHERE user_companies.company_id = $session_company_id
AND user_role > 1 AND user_archived_at IS NULL ORDER BY user_name ASC"
);
while ($row = mysqli_fetch_array($sql_assign_to_select)) { while ($row = mysqli_fetch_array($sql_assign_to_select)) {
$user_id = $row['user_id']; $user_id = $row['user_id'];
$user_name = htmlentities($row['user_name']); $user_name = htmlentities($row['user_name']); ?>
?>
<option <?php if ($ticket_assigned_to == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option> <option <?php if ($ticket_assigned_to == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>
<?php } ?>
<?php
}
?>
</select> </select>
<div class="input-group-append"> <div class="input-group-append">
<button type="submit" class="btn btn-primary" name="assign_ticket" <?php if ($ticket_status == "Closed") {echo "disabled";} ?>><i class="fas fa-check"></i></button> <button type="submit" class="btn btn-primary" name="assign_ticket" <?php if ($ticket_status == "Closed") {echo "disabled";} ?>><i class="fas fa-check"></i></button>
@@ -592,8 +558,7 @@ if(isset($_GET['ticket_id'])){
<div class=""> <div class="">
<a href="#" class="btn btn-outline-success btn-block" href="#" data-toggle="modal" data-target="#addInvoiceFromTicketModal">Invoice Ticket</a> <a href="#" class="btn btn-outline-success btn-block" href="#" data-toggle="modal" data-target="#addInvoiceFromTicketModal">Invoice Ticket</a>
<?php <?php
if($ticket_status !== "Closed"){ if ($ticket_status !== "Closed") { ?>
?>
<a href="post.php?close_ticket=<?php echo $ticket_id; ?>" class="btn btn-outline-danger btn-block">Close Ticket</a> <a href="post.php?close_ticket=<?php echo $ticket_id; ?>" class="btn btn-outline-danger btn-block">Close Ticket</a>
<?php } ?> <?php } ?>
</div> </div>
@@ -608,10 +573,6 @@ if(isset($_GET['ticket_id'])){
include("ticket_edit_modal.php"); include("ticket_edit_modal.php");
include("ticket_merge_modal.php"); include("ticket_merge_modal.php");
include("ticket_invoice_add_modal.php"); include("ticket_invoice_add_modal.php");
//include("ticket_invoice_existing_add_modal.php");
?>
<?php
} }
@@ -619,100 +580,12 @@ if(isset($_GET['ticket_id'])){
?> ?>
<?php
if($ticket_status !== "Closed"){ ?>
<!-- Ticket Time Tracking JS -->
<script type="text/javascript">
// Default values
var hours = 0;
var minutes = 0;
var seconds = 0;
setInterval(countTime, 1000);
// Counter
function countTime()
{
++seconds;
if(seconds == 60) {
seconds = 0;
minutes++;
}
if(minutes == 60) {
minutes = 0;
hours++;
}
// Total timeworked
var time_worked = pad(hours) + ":" + pad(minutes) + ":" + pad(seconds);
document.getElementById("time_worked").value = time_worked;
}
// Allows manually adjusting the timer
function setTime()
{
var time_as_text = document.getElementById("time_worked").value;
const time_text_array = time_as_text.split(":");
hours = parseInt(time_text_array[0]);
minutes = parseInt(time_text_array[1]);
seconds = parseInt(time_text_array[2]);
}
// This function "pads" out the values, adding zeros if they are required
function pad(val)
{
var valString = val + "";
if(valString.length < 2)
{
return "0" + valString;
}
else
{
return valString;
}
}
</script>
<?php } ?>
<?php include("footer.php"); <?php include("footer.php");
// jQuery is called in footer, so this must be below it
if ($ticket_status !== "Closed") { ?> if ($ticket_status !== "Closed") { ?>
<script type="text/javascript"> <!-- Ticket Time Tracking JS -->
<script src="js/ticket_time_tracking.js"></script>
// Collision detection <!-- Ticket collision detect JS (jQuery is called in footer, so collision detection script MUST be below it) -->
// Adds a "view" entry of the current ticket every 2 mins into the database <script src="js/ticket_collision_detection.js"></script>
// Updates the currently viewing (ticket_collision_viewing) element with anyone that's looked at this ticket in the last two mins
function ticket_collision_detection() {
// Get the page ticket id
var ticket_id = document.getElementById("ticket_id").value;
//Send a GET request to ajax.php as ajax.php?ticket_add_view=true&ticket_id=NUMBER
jQuery.get(
"ajax.php",
{ticket_add_view: 'true', ticket_id: ticket_id},
function(data){
// We don't care about a response
}
);
//Send a GET request to ajax.php as ajax.php?ticket_query_views=true&ticket_id=NUMBER
jQuery.get(
"ajax.php",
{ticket_query_views: 'true', ticket_id: ticket_id},
function(data){
//If we get a response from ajax.php, parse it as JSON
const ticket_view_data = JSON.parse(data);
document.getElementById("ticket_collision_viewing").innerText = ticket_view_data.message;
}
);
}
// Call on page load
ticket_collision_detection();
// Run every 2 mins
setInterval(ticket_collision_detection, 120*1000);
</script>
<?php } ?> <?php } ?>
+8 -23
View File
@@ -51,17 +51,13 @@
<select class="form-control select2" name="contact" required> <select class="form-control select2" name="contact" required>
<option value="">- Contact -</option> <option value="">- Contact -</option>
<?php <?php
$sql = mysqli_query($mysqli,"SELECT * FROM contacts WHERE contact_client_id = $client_id ORDER BY contact_name ASC"); $sql = mysqli_query($mysqli,"SELECT * FROM contacts WHERE contact_client_id = $client_id ORDER BY contact_name ASC");
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$contact_id = $row['contact_id']; $contact_id = $row['contact_id'];
$contact_name = htmlentities($row['contact_name']); $contact_name = htmlentities($row['contact_name']); ?>
?>
<option value="<?php echo $contact_id; ?>" <?php if ($primary_contact == $contact_id) { echo "selected"; } ?>><?php echo "$contact_name"; ?></option> <option value="<?php echo $contact_id; ?>" <?php if ($primary_contact == $contact_id) { echo "selected"; } ?>><?php echo "$contact_name"; ?></option>
<?php <?php } ?>
}
?>
</select> </select>
</div> </div>
</div> </div>
@@ -79,13 +75,10 @@
$sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE company_id = $session_company_id ORDER BY client_name ASC"); $sql = mysqli_query($mysqli,"SELECT * FROM clients WHERE company_id = $session_company_id ORDER BY client_name ASC");
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$client_id = $row['client_id']; $client_id = $row['client_id'];
$client_name = htmlentities($row['client_name']); $client_name = htmlentities($row['client_name']); ?>
?>
<option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option> <option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option>
<?php <?php } ?>
}
?>
</select> </select>
</div> </div>
</div> </div>
@@ -105,13 +98,10 @@
$sql_assets = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_client_id = $client_id ORDER BY asset_name ASC"); $sql_assets = mysqli_query($mysqli,"SELECT * FROM assets WHERE asset_client_id = $client_id ORDER BY asset_name ASC");
while ($row = mysqli_fetch_array($sql_assets)) { while ($row = mysqli_fetch_array($sql_assets)) {
$asset_id_select = $row['asset_id']; $asset_id_select = $row['asset_id'];
$asset_name_select = htmlentities($row['asset_name']); $asset_name_select = htmlentities($row['asset_name']); ?>
?>
<option <?php if (!empty($asset_id) && $asset_id == $asset_id_select) { echo "selected"; } ?> value="<?php echo $asset_id_select; ?>"><?php echo $asset_name_select; ?></option> <option <?php if (!empty($asset_id) && $asset_id == $asset_id_select) { echo "selected"; } ?> value="<?php echo $asset_id_select; ?>"><?php echo $asset_name_select; ?></option>
<?php <?php } ?>
}
?>
</select> </select>
</div> </div>
</div> </div>
@@ -127,7 +117,6 @@
<option value="0">Not Assigned</option> <option value="0">Not Assigned</option>
<?php <?php
//$sql = mysqli_query($mysqli,"SELECT * FROM users, user_companies WHERE users.user_id = user_companies.user_id AND user_archived_at IS NULL AND user_companies.company_id = $session_company_id ORDER BY user_name ASC");
$sql = mysqli_query($mysqli, "SELECT users.user_id, user_name FROM users $sql = mysqli_query($mysqli, "SELECT users.user_id, user_name FROM users
LEFT JOIN user_companies ON users.user_id = user_companies.user_id LEFT JOIN user_companies ON users.user_id = user_companies.user_id
LEFT JOIN user_settings on users.user_id = user_settings.user_id LEFT JOIN user_settings on users.user_id = user_settings.user_id
@@ -136,13 +125,9 @@
); );
while ($row = mysqli_fetch_array($sql)) { while ($row = mysqli_fetch_array($sql)) {
$user_id = $row['user_id']; $user_id = $row['user_id'];
$user_name = htmlentities($row['user_name']); $user_name = htmlentities($row['user_name']); ?>
?>
<option <?php if ($session_user_id == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option> <option <?php if ($session_user_id == $user_id) { echo "selected"; } ?> value="<?php echo $user_id; ?>"><?php echo $user_name; ?></option>
<?php } ?>
<?php
}
?>
</select> </select>
</div> </div>
</div> </div>
+3 -42
View File
@@ -19,8 +19,7 @@
// Show the ticket prefix, or just the tag icon // Show the ticket prefix, or just the tag icon
if (empty($ticket_prefix)) { if (empty($ticket_prefix)) {
echo "<span class=\"input-group-text\"><i class=\"fa fa-fw fa-tag\"></i></span>"; echo "<span class=\"input-group-text\"><i class=\"fa fa-fw fa-tag\"></i></span>";
} } else {
else{
echo "<div class=\"input-group-text\"> $ticket_prefix </div>"; echo "<div class=\"input-group-text\"> $ticket_prefix </div>";
} }
?> ?>
@@ -60,43 +59,5 @@
</div> </div>
</div> </div>
<script> <!-- Ticket merge JS -->
//Gets details of the ticket we're going to merge this ticket into <script src="js/ticket_merge.js"></script>
//Shows the details under the comments box & enables the merge button if the status of the merge into ticket is not closed
function merge_into_number_get_details() {
//Get the ticket number to merge into
var merge_into_ticket_number = document.getElementById("merge_into_ticket_number").value;
//Reset the form
document.getElementById("merge_ticket_btn").disabled = true;
document.getElementById("merge_into_details_div").hidden = true;
//Send a GET request to post.php as post.php?merge_ticket_get_json_details=true&merge_into_ticket_number=NUMBER
jQuery.get(
"ajax.php",
{merge_ticket_get_json_details: 'true', merge_into_ticket_number: merge_into_ticket_number},
function(data){
//If we get a response from post.php, parse it as JSON
const merge_into_ticket_info = JSON.parse(data);
//Check that the current ticket ID isn't also the new/merge ticket ID
if(parseInt(merge_into_ticket_info.ticket_id) !== parseInt(document.getElementById("current_ticket_id").value)){
//Show the div with the master ticket details, populate
document.getElementById("merge_into_details_div").hidden = false;
document.getElementById("merge_into_details_number").innerText = "Master ticket details: " + merge_into_ticket_info.ticket_prefix + merge_into_ticket_info.ticket_number;
document.getElementById("merge_into_details_client").innerText = "Client Contact: " + merge_into_ticket_info.client_name + " / " + merge_into_ticket_info.contact_name;
document.getElementById("merge_into_details_subject").innerText = "Subject: " + merge_into_ticket_info.ticket_subject;
document.getElementById("merge_into_details_priority").innerText = "Priority: " + merge_into_ticket_info.ticket_priority;
document.getElementById("merge_into_details_status").innerText = "Status: " + merge_into_ticket_info.ticket_status;
//Enable the merge button if the merge into ticket isn't in a closed state
if(merge_into_ticket_info.ticket_status.toLowerCase() != "closed"){
document.getElementById("merge_ticket_btn").disabled = false;
}
}
}
);
}
</script>