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;
}
}
+110 -237
View File
@@ -2,7 +2,7 @@
<?php
if(isset($_GET['ticket_id'])){
if (isset($_GET['ticket_id'])) {
$ticket_id = intval($_GET['ticket_id']);
$sql = mysqli_query($mysqli,"SELECT * FROM tickets
@@ -14,7 +14,7 @@ if(isset($_GET['ticket_id'])){
WHERE ticket_id = $ticket_id AND tickets.company_id = $session_company_id"
);
if(mysqli_num_rows($sql) == 0){
if (mysqli_num_rows($sql) == 0) {
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='tickets.php'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
include("footer.php");
@@ -27,7 +27,7 @@ if(isset($_GET['ticket_id'])){
$client_type = htmlentities($row['client_type']);
$client_website = htmlentities($row['client_website']);
$client_net_terms = htmlentities($row['client_net_terms']);
if($client_net_terms == 0){
if ($client_net_terms == 0) {
$client_net_terms = $config_default_net_terms;
}
@@ -45,20 +45,20 @@ if(isset($_GET['ticket_id'])){
$ticket_closed_at = $row['ticket_closed_at'];
$ticket_created_by = $row['ticket_created_by'];
if($ticket_status == "Open"){
if ($ticket_status == "Open") {
$ticket_status_display = "<span class='p-2 badge badge-primary'>$ticket_status</span>";
}elseif($ticket_status == "Working"){
}elseif ($ticket_status == "Working") {
$ticket_status_display = "<span class='p-2 badge badge-success'>$ticket_status</span>";
}else{
$ticket_status_display = "<span class='p-2 badge badge-secondary'>$ticket_status</span>";
}
//Set Ticket Bage Color based of priority
if($ticket_priority == "High"){
if ($ticket_priority == "High") {
$ticket_priority_display = "<span class='p-2 badge badge-danger'>$ticket_priority</span>";
}elseif($ticket_priority == "Medium"){
}elseif ($ticket_priority == "Medium") {
$ticket_priority_display = "<span class='p-2 badge badge-warning'>$ticket_priority</span>";
}elseif($ticket_priority == "Low"){
}elseif ($ticket_priority == "Low") {
$ticket_priority_display = "<span class='p-2 badge badge-info'>$ticket_priority</span>";
}else{
$ticket_priority_display = "-";
@@ -90,11 +90,12 @@ if(isset($_GET['ticket_id'])){
$location_phone = formatPhoneNumber($row['location_phone']);
$ticket_assigned_to = $row['ticket_assigned_to'];
if(empty($ticket_assigned_to)){
if (empty($ticket_assigned_to)) {
$ticket_assigned_to_display = "<span class='text-danger'>Not Assigned</span>";
}else{
$ticket_assigned_to_display = htmlentities($row['user_name']);
}
//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");
@@ -102,19 +103,13 @@ if(isset($_GET['ticket_id'])){
$ticket_created_by_display = htmlentities($row['user_name']);
//Ticket Assigned To
if(empty($ticket_assigned_to)){
if (empty($ticket_assigned_to)) {
$ticket_assigned_to_display = "<span class='text-danger'>Not Assigned</span>";
}else{
$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
$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 ");
$row = mysqli_fetch_array($ticket_related_open);
@@ -138,13 +133,13 @@ if(isset($_GET['ticket_id'])){
$client_tag_name_display_array = array();
$client_tag_id_array = array();
$sql_client_tags = mysqli_query($mysqli,"SELECT * FROM client_tags LEFT JOIN tags ON client_tags.tag_id = tags.tag_id WHERE client_tags.client_id = $client_id");
while($row = mysqli_fetch_array($sql_client_tags)){
while ($row = mysqli_fetch_array($sql_client_tags)) {
$client_tag_id = $row['tag_id'];
$client_tag_name = htmlentities($row['tag_name']);
$client_tag_color = htmlentities($row['tag_color']);
$client_tag_icon = htmlentities($row['tag_icon']);
if(empty($client_tag_icon)){
if (empty($client_tag_icon)) {
$client_tag_icon = "tag";
}
@@ -158,21 +153,36 @@ if(isset($_GET['ticket_id'])){
$dt_value = $asset_warranty_expire; //sample date
$warranty_check = date('m/d/Y',strtotime('-8 hours'));
if($dt_value <= $date){
if ($dt_value <= $date) {
$dt_value = "Expired on $asset_warranty_expire"; $warranty_status_color ='red';
}else{
$warranty_status_color = 'green';
}
if($asset_warranty_expire == '0000-00-00'){
if ($asset_warranty_expire == '0000-00-00') {
$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);
}
<!-- Breadcrumbs-->
<ol class="breadcrumb">
// 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");
?>
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
<a href="tickets.php">Tickets</a>
</li>
@@ -180,13 +190,13 @@ if(isset($_GET['ticket_id'])){
<a href="client_tickets.php?client_id=<?php echo $client_id; ?>"><?php echo $client_name; ?></a>
</li>
<li class="breadcrumb-item active">Ticket Details</li>
</ol>
</ol>
<div class="row mb-3">
<div class="row mb-3">
<div class="col-9">
<h3><i class="fas fa-fw fa-life-ring text-secondary"></i> Ticket <?php echo "$ticket_prefix$ticket_number"; ?> <?php echo $ticket_status_display; ?></h3>
</div>
<?php if($ticket_status != "Closed") { ?>
<?php if ($ticket_status != "Closed") { ?>
<div class="col-3">
<div class="dropdown dropleft text-center">
<button class="btn btn-secondary btn-sm float-right" type="button" id="dropdownMenuButton" data-toggle="dropdown">
@@ -195,7 +205,7 @@ if(isset($_GET['ticket_id'])){
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#editTicketModal<?php echo $ticket_id; ?>">Edit</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#mergeTicketModal<?php echo $ticket_id; ?>">Merge</a>
<?php if($session_user_role == 3) { ?>
<?php if ($session_user_role == 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="post.php?delete_ticket=<?php echo $ticket_id; ?>">Delete</a>
<?php } ?>
@@ -203,23 +213,26 @@ if(isset($_GET['ticket_id'])){
</div>
</div>
<?php } ?>
</div>
</div>
<div class="row">
<div class="row">
<div class="col-md-9">
<div class="card card-outline card-primary mb-3">
<div class="card-header">
<h3 class="card-title"><?php echo $ticket_subject; ?></h3>
</div>
<div class="card-body">
<?php echo $ticket_details; ?>
</div>
</div>
<!-- Only show ticket reply modal if status is not closed -->
<?php if($ticket_status != "Closed"){ ?>
<?php if ($ticket_status != "Closed") { ?>
<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; ?>">
<div class="form-group">
@@ -233,10 +246,10 @@ if(isset($_GET['ticket_id'])){
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
</div>
<select class="form-control select2" name="status" required>
<option <?php if($ticket_status == 'Open'){ echo "selected"; } ?> >Open</option>
<option <?php if($ticket_status == 'Working'){ echo "selected"; } ?> >Working</option>
<option <?php if($ticket_status == 'On Hold'){ echo "selected"; } ?> >On Hold</option>
<option <?php if($ticket_status == 'Closed'){ echo "selected"; } ?> >Closed</option>
<option <?php if ($ticket_status == 'Open') { echo "selected"; } ?> >Open</option>
<option <?php if ($ticket_status == 'Working') { echo "selected"; } ?> >Working</option>
<option <?php if ($ticket_status == 'On Hold') { echo "selected"; } ?> >On Hold</option>
<option <?php if ($ticket_status == 'Closed') { echo "selected"; } ?> >Closed</option>
</select>
</div>
</div>
@@ -248,8 +261,6 @@ if(isset($_GET['ticket_id'])){
</div>
</div>
<?php //if(!empty($config_smtp_host) AND !empty($client_email)){ ?>
<div class="col-md-2">
<div class="form-group">
<div class="custom-control custom-checkbox">
@@ -259,8 +270,6 @@ if(isset($_GET['ticket_id'])){
</div>
</div>
<?php //} ?>
<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>
</div>
@@ -273,10 +282,10 @@ if(isset($_GET['ticket_id'])){
<!-- End IF for reply modal -->
<?php } ?>
<!-- Ticket replies -->
<?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 = $row['ticket_reply'];
$ticket_reply_type = htmlentities($row['ticket_reply_type']);
@@ -284,13 +293,12 @@ if(isset($_GET['ticket_id'])){
$ticket_reply_updated_at = $row['ticket_reply_updated_at'];
$ticket_reply_by = $row['ticket_reply_by'];
if($ticket_reply_type == "Client"){
if ($ticket_reply_type == "Client") {
$ticket_reply_by_display = htmlentities($row['contact_name']);
$user_initials = initials($row['contact_name']);
$user_avatar = $row['contact_photo'];
$avatar_link = "uploads/clients/$session_company_id/$client_id/$user_avatar";
}
else{
} else {
$ticket_reply_by_display = htmlentities($row['user_name']);
$user_id = $row['user_id'];
$user_avatar = htmlentities($row['user_avatar']);
@@ -298,36 +306,35 @@ if(isset($_GET['ticket_id'])){
$avatar_link = "uploads/users/$user_id/$user_avatar";
$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">
<div class="card-header">
<h3 class="card-title">
<div class="media">
<?php if(!empty($user_avatar)){ ?>
<?php if (!empty($user_avatar)) { ?>
<img src="<?php echo $avatar_link; ?>" alt="User Avatar" class="img-size-50 mr-3 img-circle">
<?php }else{ ?>
<?php } else { ?>
<span class="fa-stack fa-2x">
<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>
<?php
}
?>
<?php } ?>
<div class="media-body">
<?php echo $ticket_reply_by_display; ?>
<br>
<small class="text-muted"><?php echo $ticket_reply_created_at; ?> <?php if(!empty($ticket_reply_updated_at)){ echo "modified: $ticket_reply_updated_at"; } ?></small>
<small class="text-muted"><?php echo $ticket_reply_created_at; ?> <?php if (!empty($ticket_reply_updated_at)) { echo "modified: $ticket_reply_updated_at"; } ?></small>
<br>
<?php if($ticket_reply_type !== "Client") { ?>
<?php if ($ticket_reply_type !== "Client") { ?>
<small class="text-muted">Time worked: <?php echo date_format($ticket_reply_time_worked, 'H:i:s'); ?></small>
<?php } ?>
</div>
</div>
</h3>
<?php if($ticket_reply_type !== "Client" && $ticket_status !== "Closed") { ?>
<?php if ($ticket_reply_type !== "Client" && $ticket_status !== "Closed") { ?>
<div class="card-tools">
<div class="dropdown dropleft">
<button class="btn btn-tool" type="button" id="dropdownMenuButton" data-toggle="dropdown">
@@ -335,7 +342,7 @@ if(isset($_GET['ticket_id'])){
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#replyEditTicketModal<?php echo $ticket_reply_id; ?>"><i class="fas fa-fw fa-edit text-secondary"></i> Edit</a>
<?php if($session_user_role == 3) { ?>
<?php if ($session_user_role == 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger" href="post.php?archive_ticket_reply=<?php echo $ticket_reply_id; ?>"><i class="fas fa-fw fa-trash text-danger"></i> Archive</a>
<?php } ?>
@@ -349,6 +356,7 @@ if(isset($_GET['ticket_id'])){
<div class="card-body">
<?php echo $ticket_reply; ?>
</div>
</div>
<?php
@@ -368,65 +376,49 @@ if(isset($_GET['ticket_id'])){
<div>
<h5><strong><?php echo $client_name; ?></strong></h5>
<?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; ?>
<br>
<?php
}
?>
<?php } ?>
<?php
if(!empty($client_tags_display)){
if (!empty($client_tags_display)) {
echo "$client_tags_display";
}
?>
} ?>
</div>
</div>
<!-- Client contact card -->
<?php if(!empty($contact_id)){ ?>
<?php if (!empty($contact_id)) { ?>
<div class="card card-body card-outline card-dark mb-3">
<div>
<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>
<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>
<hr>
<?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; ?>
<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>
<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; ?>
<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; ?>
<br>
<?php
}
?>
<?php } ?>
</div>
</div>
@@ -439,67 +431,52 @@ if(isset($_GET['ticket_id'])){
<div class="ml-1"><i class="fa fa-fw fa-calendar text-secondary mr-2 mb-2"></i>Created on: <?php echo $ticket_created_at; ?></div>
<div class="ml-1"><i class="fa fa-fw fa-user text-secondary mr-2 mb-2"></i>Created by: <?php echo $ticket_created_by_display; ?></div>
<?php
if($ticket_status == "Closed"){
if ($ticket_status == "Closed") {
$sql_closed_by = mysqli_query($mysqli,"SELECT * FROM tickets, users WHERE ticket_closed_by = user_id");
$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-comment-dots text-secondary mr-2 mb-2"></i>Feedback: <?php echo $ticket_feedback; ?></a></div>
<?php } ?>
<?php if(!empty($ticket_total_reply_time)){ ?>
<?php if (!empty($ticket_total_reply_time)) { ?>
<div class="ml-1"><i class="far fa-fw fa-clock text-secondary mr-2 mb-2"></i>Total time worked: <?php echo $ticket_total_reply_time; ?></div>
<?php } ?>
</div>
<!-- Ticket asset details card -->
<?php if(!empty($asset_id)){ ?>
<?php if (!empty($asset_id)) { ?>
<div class="card card-body card-outline card-dark mb-3">
<div>
<h4 class="text-secondary">Asset</h4>
<i class="fa fa-fw fa-desktop text-secondary ml-1 mr-2 mb-2"></i><strong><?php echo $asset_name; ?></strong>
<br>
<?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; ?>
<br>
<?php
}
<?php }
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"; ?>
<br>
<?php
}
<?php }
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"; ?>
<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; ?>
<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>
<br>
<?php
}
?>
<?php }
<?php
$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 ){
?>
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>
@@ -516,7 +493,7 @@ if(isset($_GET['ticket_id'])){
<div class="modal-body bg-white">
<?php
// Query is run from client_assets.php
while($row = mysqli_fetch_array($sql_asset_tickets)){
while ($row = mysqli_fetch_array($sql_asset_tickets)) {
$service_ticket_id = $row['ticket_id'];
$service_ticket_prefix = htmlentities($row['ticket_prefix']);
$service_ticket_number = $row['ticket_number'];
@@ -541,7 +518,6 @@ if(isset($_GET['ticket_id'])){
</div>
</div>
<?php
}
@@ -560,40 +536,29 @@ if(isset($_GET['ticket_id'])){
<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="assigned_to" <?php if($ticket_status == "Closed") {echo "disabled";} ?>>
<select class="form-control select2" name="assigned_to" <?php if ($ticket_status == "Closed") {echo "disabled";} ?>>
<option value="0">Not Assigned</option>
<?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_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>
<?php
}
?>
$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>
<?php } ?>
</select>
<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>
</div>
</div>
</div>
</form>
<?php if($config_module_enable_accounting){ ?>
<?php if ($config_module_enable_accounting) { ?>
<div class="card card-body card-outline card-dark mb-2">
<div class="">
<a href="#" class="btn btn-outline-success btn-block" href="#" data-toggle="modal" data-target="#addInvoiceFromTicketModal">Invoice Ticket</a>
<?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>
<?php } ?>
</div>
@@ -602,117 +567,25 @@ if(isset($_GET['ticket_id'])){
</div>
</div>
</div>
<?php
<?php
include("ticket_edit_modal.php");
include("ticket_merge_modal.php");
include("ticket_invoice_add_modal.php");
//include("ticket_invoice_existing_add_modal.php");
?>
<?php
}
}
}
?>
<?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");
// jQuery is called in footer, so this must be below it
if($ticket_status !== "Closed"){ ?>
<script type="text/javascript">
if ($ticket_status !== "Closed") { ?>
<!-- Ticket Time Tracking JS -->
<script src="js/ticket_time_tracking.js"></script>
// 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);
</script>
<!-- Ticket collision detect JS (jQuery is called in footer, so collision detection script MUST be below it) -->
<script src="js/ticket_collision_detection.js"></script>
<?php } ?>
+18 -33
View File
@@ -40,7 +40,7 @@
</div>
</div>
<?php if(isset($_GET['client_id'])){ ?>
<?php if (isset($_GET['client_id'])) { ?>
<input type="hidden" name="client" value="<?php echo $client_id; ?>">
<div class="form-group">
<label>Contact <strong class="text-danger">*</strong></label>
@@ -51,21 +51,17 @@
<select class="form-control select2" name="contact" required>
<option value="">- Contact -</option>
<?php
$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_name = htmlentities($row['contact_name']);
?>
<option value="<?php echo $contact_id; ?>" <?php if($primary_contact == $contact_id){ echo "selected"; } ?>><?php echo "$contact_name"; ?></option>
$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>
<?php
}
?>
<?php } ?>
</select>
</div>
</div>
<?php }else{ ?>
<?php } else { ?>
<div class="form-group">
<label>Client <strong class="text-danger">*</strong></label>
<div class="input-group">
@@ -77,21 +73,18 @@
<?php
$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_name = htmlentities($row['client_name']);
?>
$client_name = htmlentities($row['client_name']); ?>
<option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option>
<?php
}
?>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<?php if(isset($_GET['client_id'])){ ?>
<?php if (isset($_GET['client_id'])) { ?>
<div class="form-group">
<label>Asset</label>
<div class="input-group">
@@ -103,15 +96,12 @@
<?php
$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_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>
$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>
<?php
}
?>
<?php } ?>
</select>
</div>
</div>
@@ -127,22 +117,17 @@
<option value="0">Not Assigned</option>
<?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
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)){
while ($row = mysqli_fetch_array($sql)) {
$user_id = $row['user_id'];
$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>
<?php
}
?>
$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>
<?php } ?>
</select>
</div>
</div>
+4 -43
View File
@@ -17,10 +17,9 @@
<div class="input-group-prepend">
<?php
// 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>";
}
else{
} else {
echo "<div class=\"input-group-text\"> $ticket_prefix </div>";
}
?>
@@ -60,43 +59,5 @@
</div>
</div>
<script>
//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;
}
}
}
);
}
</script>
<!-- Ticket merge JS -->
<script src="js/ticket_merge.js"></script>