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
commit 09bb1d4636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 798 additions and 857 deletions

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
js/ticket_merge.js Normal file
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;
}
}
}
);
}

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

1207
ticket.php

File diff suppressed because it is too large Load Diff

View File

@ -1,158 +1,143 @@
<div class="modal" id="addTicketModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-life-ring"></i> New Ticket</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
<form action="post.php" method="post" autocomplete="off">
<div class="modal-body bg-white">
<div class="form-group">
<label>Subject <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-tag"></i></span>
</div>
<input type="text" class="form-control" name="subject" placeholder="Subject" required>
<div class="modal-dialog modal-lg">
<div class="modal-content bg-dark">
<div class="modal-header">
<h5 class="modal-title"><i class="fa fa-fw fa-life-ring"></i> New Ticket</h5>
<button type="button" class="close text-white" data-dismiss="modal">
<span>&times;</span>
</button>
</div>
</div>
<form action="post.php" method="post" autocomplete="off">
<div class="modal-body bg-white">
<div class="form-group">
<label>Subject <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-tag"></i></span>
</div>
<input type="text" class="form-control" name="subject" placeholder="Subject" required>
</div>
</div>
<div class="form-group">
<textarea class="form-control summernote" rows="8" name="details"></textarea>
</div>
<div class="form-group">
<label>Priority <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-thermometer-half"></i></span>
</div>
<select class="form-control select2" name="priority" required>
<option>Low</option>
<option>Medium</option>
<option>High</option>
</select>
</div>
</div>
<div class="form-group">
<textarea class="form-control summernote" rows="8" name="details"></textarea>
</div>
<?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>
<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="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)){
$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>
<?php
}
?>
</select>
</div>
</div>
<?php }else{ ?>
<div class="form-group">
<label>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-user"></i></span>
</div>
<select class="form-control select2" name="client" required>
<option value="">- Client -</option>
<?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)){
$client_id = $row['client_id'];
$client_name = htmlentities($row['client_name']);
?>
<option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option>
<?php
}
?>
</select>
</div>
</div>
<?php } ?>
<div class="form-group">
<label>Priority <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-thermometer-half"></i></span>
</div>
<select class="form-control select2" name="priority" required>
<option>Low</option>
<option>Medium</option>
<option>High</option>
</select>
</div>
</div>
<?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>
<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="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)) {
$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>
<?php } ?>
</select>
</div>
</div>
<?php } else { ?>
<div class="form-group">
<label>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-user"></i></span>
</div>
<select class="form-control select2" name="client" required>
<option value="">- Client -</option>
<?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)) {
$client_id = $row['client_id'];
$client_name = htmlentities($row['client_name']); ?>
<option value="<?php echo $client_id; ?>"><?php echo "$client_name"; ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<?php if (isset($_GET['client_id'])) { ?>
<div class="form-group">
<label>Asset</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
</div>
<select class="form-control select2" name="asset">
<option value="0">- None -</option>
<?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)) {
$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>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="form-group">
<label>Assign to</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user-check"></i></span>
</div>
<select class="form-control select2" name="assigned_to">
<option value="0">Not Assigned</option>
<?php
$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)) {
$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 } ?>
</select>
</div>
</div>
<?php if(isset($_GET['client_id'])){ ?>
<div class="form-group">
<label>Asset</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-desktop"></i></span>
</div>
<select class="form-control select2" name="asset">
<option value="0">- None -</option>
<?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)){
$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>
<?php
}
?>
</select>
</div>
</div>
<?php } ?>
<div class="form-group">
<label>Assign to</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-fw fa-user-check"></i></span>
</div>
<select class="form-control select2" name="assigned_to">
<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)){
$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
}
?>
</select>
</div>
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="add_ticket" class="btn btn-primary"><strong><i class="fa fa-check"></i> Create</strong></button>
</div>
</form>
</div>
<div class="modal-footer bg-white">
<button type="button" class="btn btn-outline-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" name="add_ticket" class="btn btn-primary"><strong><i class="fa fa-check"></i> Create</strong></button>
</div>
</form>
</div>
</div>
</div>

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>