From 3acb1ad7549af775590b2045bd290e8877268abe Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 3 Sep 2026 17:18:32 -0400 Subject: [PATCH] Fix ticket creation emails always saying Open, API tickets staying New when assigned, and the bulk assignee list filter --- agent/modals/client/client_bulk_add_ticket.php | 4 ++-- agent/post/recurring_ticket.php | 6 ++++-- agent/post/ticket.php | 2 +- api/v1/tickets/create.php | 7 ++++++- cron/nightly_tasks.php | 3 ++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/agent/modals/client/client_bulk_add_ticket.php b/agent/modals/client/client_bulk_add_ticket.php index 8c65a86d6..c9e763deb 100644 --- a/agent/modals/client/client_bulk_add_ticket.php +++ b/agent/modals/client/client_bulk_add_ticket.php @@ -86,12 +86,12 @@ ob_start(); $sql = mysqli_query( $mysqli, "SELECT user_id, user_name FROM users - WHERE user_role_id > 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC" + WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC" ); while ($row = mysqli_fetch_assoc($sql)) { $user_id = intval($row['user_id']); $user_name = escapeHtml($row['user_name']); ?> - + diff --git a/agent/post/recurring_ticket.php b/agent/post/recurring_ticket.php index 115b663ec..ce10b9d1e 100644 --- a/agent/post/recurring_ticket.php +++ b/agent/post/recurring_ticket.php @@ -192,7 +192,8 @@ if (isset($_POST['bulk_force_recurring_tickets'])) { $email_subject = "Ticket Created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; // SLA response commitment for this client + priority, empty when no SLA applies $sla_notice = escapeSql(getTicketSlaEmailNotice($id, $company_phone)); - $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $ticket_status_name = escapeSql(getTicketStatusName($ticket_status)); + $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status_name
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; $email = [ 'from' => $config_ticket_from_email, @@ -341,7 +342,8 @@ if (isset($_GET['force_recurring_ticket'])) { $email_subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; // SLA response commitment for this client + priority, empty when no SLA applies $sla_notice = escapeSql(getTicketSlaEmailNotice($id, $company_phone)); - $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $ticket_status_name = escapeSql(getTicketStatusName($ticket_status)); + $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status_name
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; $email = [ 'from' => $config_ticket_from_email, diff --git a/agent/post/ticket.php b/agent/post/ticket.php index e573b303e..8ab725133 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -142,7 +142,7 @@ if (isset($_POST['add_ticket'])) { $subject = "Ticket Created [$ticket_prefix$ticket_number] - $ticket_subject"; // SLA response commitment for this client + priority, empty when no SLA applies $sla_notice = escapeSql(getTicketSlaEmailNotice($ticket_id, $company_phone)); - $body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: View ticket$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status_name
Portal: View ticket$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; // Verify contact email is valid if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { diff --git a/api/v1/tickets/create.php b/api/v1/tickets/create.php index 2ced44ead..7a4c09aa2 100644 --- a/api/v1/tickets/create.php +++ b/api/v1/tickets/create.php @@ -32,6 +32,11 @@ if (!empty($subject)) { $contact = intval($row['contact_id']); } + $ticket_status = 1; // Default + if ($assigned_to > 0) { + $ticket_status = 2; // Set to open if we've auto-assigned an agent + } + // Atomically increment and get the new ticket number mysqli_query($mysqli, " UPDATE settings @@ -45,7 +50,7 @@ if (!empty($subject)) { // Insert ticket $url_key = randomString(32); - $insert_sql = mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'API', ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = 1, ticket_billable = $billable, ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_vendor_id = $vendor_id, ticket_created_by = 0, ticket_assigned_to = $assigned_to, ticket_contact_id = $contact, ticket_asset_id = $asset, ticket_url_key = '$url_key', ticket_client_id = $client_id"); + $insert_sql = mysqli_query($mysqli,"INSERT INTO tickets SET ticket_prefix = '$config_ticket_prefix', ticket_number = $ticket_number, ticket_source = 'API', ticket_subject = '$subject', ticket_details = '$details', ticket_priority = '$priority', ticket_status = $ticket_status, ticket_billable = $billable, ticket_vendor_ticket_number = '$vendor_ticket_number', ticket_vendor_id = $vendor_id, ticket_created_by = 0, ticket_assigned_to = $assigned_to, ticket_contact_id = $contact, ticket_asset_id = $asset, ticket_url_key = '$url_key', ticket_client_id = $client_id"); // Check insert & get insert ID if ($insert_sql) { diff --git a/cron/nightly_tasks.php b/cron/nightly_tasks.php index 5990489dd..a69312fef 100644 --- a/cron/nightly_tasks.php +++ b/cron/nightly_tasks.php @@ -443,7 +443,8 @@ if (mysqli_num_rows($sql_recurring_tickets) > 0) { $email_subject = "Ticket created - [$ticket_prefix$ticket_number] - $ticket_subject (scheduled)"; // SLA response commitment for this client + priority, empty when no SLA applies $sla_notice = escapeSql(getTicketSlaEmailNotice($id, $company_phone)); - $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: Open
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; + $ticket_status_name = escapeSql(getTicketStatusName($ticket_status)); + $email_body = "##- Please type your reply above this line -##

Hello $contact_name,

A ticket regarding \"$ticket_subject\" has been automatically created for you.

--------------------------------
$ticket_details--------------------------------

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status_name
Portal: https://$config_base_url/client/ticket.php?id=$id$sla_notice

--
$company_name - Support
$config_ticket_from_email
$company_phone"; $email = [ 'from' => $config_ticket_from_email,