Skip to content

Commit

Permalink
Ticket Statuses
Browse files Browse the repository at this point in the history
Standardize on 5 consistent ticket states:-
- New (Red/Danger)
- Open (Blue/Primary)
- On Hold (Green/Success)
- Auto Close (Dark/black)
- Closed (Dark/black)

Update parts of the app where these have deviated from, as they have not been updated everywhere.
Other states may be configurable in future via custom fields.
  • Loading branch information
wrongecho committed Mar 3, 2024
1 parent f5a6dc2 commit b943164
Show file tree
Hide file tree
Showing 14 changed files with 155 additions and 139 deletions.
19 changes: 9 additions & 10 deletions calendar_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,14 @@
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " created - " . $row['ticket_subject'] . " " . $username . "{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_created_at']);


if ($ticket_status == "Closed") {
$event_color = "black";
} else if ($ticket_status == "Scheduled") {
$event_color = "grey";
} else if ($ticket_status == "Pending-Assignment") {
if ($ticket_status == "New") {
$event_color = "red";
} else {
} else if ($ticket_status == "Open") {
$event_color = "blue";
} else if ($ticket_status == "On Hold") {
$event_color = "grey";
} else {
$event_color = "black";
}

echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
Expand All @@ -188,7 +187,7 @@
}

if (strtotime($row['ticket_schedule']) < time()) {
if ($row['ticket_status'] == 'Scheduled') {
if ($row['ticket_status'] == 'On Hold') {
$event_color = "red";
} else {
$event_color = "green";
Expand All @@ -200,7 +199,7 @@
$ticket_status = strval($row['ticket_status']);
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " scheduled - " . $row['ticket_subject'] . " [" . $username . "]{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_schedule']);


echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
}
Expand Down Expand Up @@ -260,4 +259,4 @@ function updateIncrementEndTime() {
// Update the end date field
document.getElementById("event_add_end").value = new_end;
}
</script>
</script>
15 changes: 7 additions & 8 deletions client_events.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,14 @@
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " created - " . $row['ticket_subject'] . " " . $username . "{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_created_at']);


if ($ticket_status == "Closed") {
$event_color = "black";
} else if ($ticket_status == "Scheduled") {
$event_color = "grey";
} else if ($ticket_status == "Pending-Assignment") {
if ($ticket_status == "New") {
$event_color = "red";
} else {
} else if ($ticket_status == "Open") {
$event_color = "blue";
} else if ($ticket_status == "On Hold") {
$event_color = "grey";
} else {
$event_color = "black";
}

echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
Expand Down Expand Up @@ -200,7 +199,7 @@
$ticket_status = strval($row['ticket_status']);
$event_title = json_encode($row['ticket_prefix'] . $row['ticket_number'] . " scheduled - " . $row['ticket_subject'] . " [" . $username . "]{" . $ticket_status . "}");
$event_start = json_encode($row['ticket_schedule']);


echo "{ id: $event_id, title: $event_title, start: $event_start, color: '$event_color', url: 'ticket.php?ticket_id=$event_id' },";
}
Expand Down
11 changes: 6 additions & 5 deletions client_tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,16 @@
}
$ticket_closed_at = nullable_htmlentities($row['ticket_closed_at']);

if ($ticket_status == "Pending-Assignment") {
if ($ticket_status == "New") {
$ticket_status_color = "danger";
} elseif ($ticket_status == "Assigned") {
} elseif ($ticket_status == "Open") {
$ticket_status_color = "primary";
} elseif ($ticket_status == "In-Progress") {
} elseif ($ticket_status == "On Hold") {
$ticket_status_color = "success";
} elseif ($ticket_status == "Auto Close") {
$ticket_status_color = "dark";
} elseif ($ticket_status == "Closed") {
$ticket_status_color = "dark";
} else{
$ticket_status_color = "secondary";
}

if ($ticket_priority == "High") {
Expand All @@ -181,6 +181,7 @@
} else{
$ticket_priority_display = "-";
}

$ticket_assigned_to = intval($row['ticket_assigned_to']);
if (empty($ticket_assigned_to)) {
if ($ticket_status == "Closed") {
Expand Down
14 changes: 7 additions & 7 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,20 +219,20 @@
// Logging
//mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for asset warranties expiring'");

// Notify of Tickets Pending Assignment
// Notify of New Tickets
// Get Ticket Pending Assignment
$sql_tickets_pending_assignment = mysqli_query($mysqli,"SELECT ticket_id FROM tickets
WHERE ticket_status = 'Pending-Assignment'"
WHERE ticket_status = 'New'"
);

$tickets_pending_assignment = mysqli_num_rows($sql_tickets_pending_assignment);

if($tickets_pending_assignment > 0){

mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Pending Tickets', notification = 'There are $tickets_pending_assignment Tickets pending assignment', notification_action = 'tickets.php?status=Pending-Assignment'");
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Pending Tickets', notification = 'There are $tickets_pending_assignment new tickets pending assignment', notification_action = 'tickets.php?status=New'");

// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for tickets that are pending assignment'");
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron', log_action = 'Task', log_description = 'Cron created notifications for new tickets that are pending assignment'");
}

// Recurring (Scheduled) tickets
Expand Down Expand Up @@ -262,7 +262,7 @@
mysqli_query($mysqli, "UPDATE settings SET config_ticket_next_number = $new_config_ticket_next_number WHERE company_id = 1");

// Raise the ticket
mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'Open', ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id");
mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 'New', ticket_created_by = $created_id, ticket_contact_id = $contact_id, ticket_client_id = $client_id, ticket_asset_id = $asset_id");
$id = mysqli_insert_id($mysqli);

// Logging
Expand Down Expand Up @@ -366,7 +366,7 @@
// AUTO CLOSE TICKET - CLOSE
// Automatically silently closes tickets 22 hrs after the last chase

// Check to make sure autoclose is enabled
// Check to make sure auto-close is enabled
if ($config_ticket_autoclose == 1) {
$sql_tickets_to_chase = mysqli_query(
$mysqli,
Expand Down Expand Up @@ -420,7 +420,7 @@
$ticket_reply = $ticket_reply_row['ticket_reply'];

$subject = "Ticket pending closure - [$ticket_prefix$ticket_number] - $ticket_subject";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello, $contact_name<br><br>This is an automatic friendly reminder that your ticket regarding $ticket_subject will be closed, unless you respond.<br><br>--------------------------------<br>$ticket_reply--------------------------------<br><br>If your issue is resolved, you can ignore this email - the ticket will automatically close. If you need further assistance, please respond to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello, $contact_name<br><br>This is an automatic friendly reminder that your ticket regarding $ticket_subject will be closed, unless you respond.<br><br>--------------------------------<br>$ticket_reply--------------------------------<br><br>If your issue is resolved, you can ignore this email - the ticket will automatically close shortly. If you need further assistance, please respond to this email. <br><br>Ticket: $ticket_prefix$ticket_number<br>Subject: $ticket_subject<br>Status: $ticket_status<br>Portal: https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";

$data = [
[
Expand Down
31 changes: 17 additions & 14 deletions cron_ticket_email_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date, $subject, $message, $attachments) {

// Access global variables
global $mysqli, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_ticket_new_ticket_notification_email, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;
global $mysqli,$config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_ticket_client_general_notifications, $config_ticket_new_ticket_notification_email, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;

// Get the next Ticket Number and add 1 for the new ticket number
$ticket_number_sql = mysqli_fetch_array(mysqli_query($mysqli, "SELECT config_ticket_next_number FROM settings WHERE company_id = 1"));
Expand All @@ -118,7 +118,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date
$message = nl2br($message);
$message = mysqli_escape_string($mysqli, "<i>Email from: $contact_email at $date:-</i> <br><br>$message");

mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'Pending-Assignment', ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_client_id = $client_id");
mysqli_query($mysqli, "INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_subject = '$subject', ticket_details = '$message', ticket_priority = 'Low', ticket_status = 'New', ticket_created_by = 0, ticket_contact_id = $contact_id, ticket_client_id = $client_id");
$id = mysqli_insert_id($mysqli);

// Logging
Expand Down Expand Up @@ -162,9 +162,9 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date
$data = [];
// E-mail client notification that ticket has been created
if ($config_ticket_client_general_notifications == 1) {

$subject_email = "Ticket created - [$config_ticket_prefix$ticket_number] - $subject";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.<br><br>Ticket: $config_ticket_prefix$ticket_number<br>Subject: $subject<br>Status: Open<br>https://$config_base_url/portal/ticket.php?id=$id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $contact_name,<br><br>Thank you for your email. A ticket regarding \"$subject\" has been automatically created for you.<br><br>Ticket: $config_ticket_prefix$ticket_number<br>Subject: $subject<br>Status: New<br>https://$config_base_url/portal/ticket.php?id=$id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";

$data[] = [
'from' => $config_ticket_from_email,
Expand All @@ -184,7 +184,7 @@ function addTicket($contact_id, $contact_name, $contact_email, $client_id, $date
$client_row = mysqli_fetch_array($client_sql);
$client_name = sanitizeInput($client_row['client_name']);

$email_subject = "ITFlow - New Ticket - $client_name: $subject";
$email_subject = "$config_app_name - New Ticket - $client_name: $subject";
$email_body = "Hello, <br><br>This is a notification that a new ticket has been raised in ITFlow. <br>Client: $client_name<br>Priority: Low (email parsed)<br>Link: https://$config_base_url/ticket.php?ticket_id=$id <br><br>--------------------------------<br><br><b>$subject</b><br>$details";

$data[] = [
Expand All @@ -209,7 +209,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
// Add email as a comment/reply to an existing ticket

// Access global variables
global $mysqli, $company_name, $company_phone, $config_ticket_prefix, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;
global $mysqli, $config_app_name, $company_name, $company_phone, $config_ticket_prefix, $config_base_url, $config_ticket_from_name, $config_ticket_from_email, $config_smtp_host, $config_smtp_port, $config_smtp_encryption, $config_smtp_username, $config_smtp_password, $allowed_extensions;

// Set default reply type
$ticket_reply_type = 'Client';
Expand All @@ -221,27 +221,30 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
$message = mysqli_escape_string($mysqli, "<i>Email from: $from_email at $date:-</i> <br><br>$message");

// Lookup the ticket ID
$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT ticket_id, ticket_subject, ticket_status, ticket_contact_id, ticket_client_id, contact_email
$row = mysqli_fetch_array(mysqli_query($mysqli, "SELECT ticket_id, ticket_subject, ticket_status, ticket_contact_id, ticket_client_id, contact_email, client_name
FROM tickets
LEFT JOIN contacts on tickets.ticket_contact_id = contacts.contact_id
LEFT JOIN clients on tickets.ticket_client_id = clients.client_id
WHERE ticket_number = $ticket_number LIMIT 1"));

if ($row) {

// Get ticket details
$ticket_id = intval($row['ticket_id']);
$ticket_subject = sanitizeInput($row['ticket_subject']);
$ticket_status = sanitizeInput($row['ticket_status']);
$ticket_reply_contact = intval($row['ticket_contact_id']);
$ticket_contact_email = sanitizeInput($row['contact_email']);
$client_id = intval($row['ticket_client_id']);
$client_name = sanitizeInput($row['client_name']);

// Check ticket isn't closed - tickets can't be re-opened
if ($ticket_status == "Closed") {
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = 'Email parser: $from_email attempted to re-open ticket $config_ticket_prefix$ticket_number (ID $ticket_id) - check inbox manually to see email', notification_action = 'ticket.php?ticket_id=$ticket_id', notification_client_id = $client_id");

$email_subject = "Action required: This ticket is already closed";
$email_body = "Hi there, <br><br>You\'ve tried to reply to a ticket that is closed - we won\'t see your response. <br><br>Please raise a new ticket by sending a fresh e-mail to our support address below. <br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";

$data = [
[
'from' => $config_ticket_from_email,
Expand All @@ -252,7 +255,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
'body' => $email_body
]
];

addToMailQueue($mysqli, $data);

return true;
Expand Down Expand Up @@ -332,17 +335,17 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
$tech_email = sanitizeInput($tech_row['user_email']);
$tech_name = sanitizeInput($tech_row['user_name']);

$subject = "Ticket updated - [$config_ticket_prefix$ticket_number] - $subject";
$body = "<i style=\'color: #808080\'>##- Please type your reply above this line -##</i><br><br>Hello $tech_name,<br><br>A new reply has been added to the ticket \"$subject\".<br><br>Ticket: $config_ticket_prefix$ticket_number<br>Subject: $subject<br>Status: Open<br>https://$config_base_url/portal/ticket.php?id=$ticket_id<br><br>--<br>$company_name - Support<br>$config_ticket_from_email<br>$company_phone";
$email_subject = "$config_app_name - Ticket updated - [$config_ticket_prefix$ticket_number] $ticket_subject";
$email_body = "Hello $tech_name,<br><br>A new reply has been added to the below ticket, check ITFlow for full details.<br><br>Client: $client_name<br>Ticket: $config_ticket_prefix$ticket_number<br>Subject: $ticket_subject<br><br>https://$config_base_url/ticket.php?ticket_id=$ticket_id";

$data = [
[
'from' => $config_ticket_from_email,
'from_name' => $config_ticket_from_name,
'recipient' => $tech_email,
'recipient_name' => $tech_name,
'subject' => $subject,
'body' => $body
'subject' => $email_subject,
'body' => $email_body
]
];

Expand All @@ -353,7 +356,7 @@ function addReply($from_email, $date, $subject, $ticket_number, $message, $attac
}

// Update Ticket Last Response Field & set ticket to open as client has replied
mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 'Client-Replied' WHERE ticket_id = $ticket_id AND ticket_client_id = $client_id LIMIT 1");
mysqli_query($mysqli, "UPDATE tickets SET ticket_status = 'Open' WHERE ticket_id = $ticket_id AND ticket_client_id = $client_id LIMIT 1");

echo "Updated existing ticket.<br>";
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Update', log_description = 'Email parser: Client contact $from_email updated ticket $config_ticket_prefix$ticket_number ($subject)', log_client_id = $client_id");
Expand Down
Loading

0 comments on commit b943164

Please sign in to comment.