diff --git a/post/ticket.php b/post/ticket.php
index 3d021344e..9411df803 100644
--- a/post/ticket.php
+++ b/post/ticket.php
@@ -807,6 +807,65 @@
header("Location: " . $_SERVER["HTTP_REFERER"]);
}
+if (isset($_POST['bulk_merge_tickets'])) {
+
+ // Role check
+ validateTechRole();
+
+ $ticket_count = count($_POST['ticket_ids']); // Get a ticket count
+ $merge_into_ticket_number = intval($_POST['merge_into_ticket_number']); // Parent ticket *number*
+ $merge_comment = sanitizeInput($_POST['merge_comment']); // Merge comment
+
+ // NEW PARENT ticket details
+ // Get merge into ticket id (as it may differ from the number)
+ $sql = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_number = $merge_into_ticket_number");
+ if (mysqli_num_rows($sql) == 0) {
+ $_SESSION['alert_message'] = "Cannot merge into that ticket.";
+ header("Location: " . $_SERVER["HTTP_REFERER"]);
+ exit();
+ }
+ $merge_row = mysqli_fetch_array($sql);
+ $merge_into_ticket_id = intval($merge_row['ticket_id']); // Parent ticket ID
+
+ // Update & Close the selected tickets
+ if (!empty($_POST['ticket_ids'])) {
+ foreach ($_POST['ticket_ids'] as $ticket_id) {
+ $ticket_id = intval($ticket_id);
+
+ if ($ticket_id !== $merge_into_ticket_id) {
+
+ $sql = mysqli_query($mysqli, "SELECT * FROM tickets WHERE ticket_id = $ticket_id");
+ $row = mysqli_fetch_array($sql);
+
+ $ticket_prefix = sanitizeInput($row['ticket_prefix']);
+ $ticket_number = intval($row['ticket_number']);
+ $ticket_subject = sanitizeInput($row['ticket_subject']);
+ $ticket_details = mysqli_escape_string($mysqli, $row['ticket_details']);
+ $current_ticket_priority = sanitizeInput($row['ticket_priority']);
+ $client_id = intval($row['ticket_client_id']);
+
+ // Update current ticket
+ mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Ticket $ticket_prefix$ticket_number bulk merged into $ticket_prefix$merge_into_ticket_number. Comment: $merge_comment', ticket_reply_time_worked = '00:01:00', ticket_reply_type = '$ticket_reply_type', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $ticket_id");
+ mysqli_query($mysqli, "UPDATE tickets SET ticket_status = '5', ticket_resolved_at = NOW(), ticket_closed_at = NOW() WHERE ticket_id = $ticket_id") or die(mysqli_error($mysqli));
+
+ //Update new parent ticket
+ mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Ticket $ticket_prefix$ticket_number was bulk merged into this ticket with comment: $merge_comment.
$ticket_subject
$ticket_details', ticket_reply_time_worked = '00:01:00', ticket_reply_type = 'Internal', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $merge_into_ticket_id");
+
+ // Logging
+ mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Merged', log_description = 'Merged ticket $ticket_prefix$ticket_number into $ticket_prefix$merge_into_ticket_number', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
+
+ }
+ } // End For Each Ticket ID Loop
+ }
+
+ mysqli_query($mysqli, "UPDATE tickets SET ticket_updated_at = NOW() WHERE ticket_id = $merge_into_ticket_id");
+
+ $_SESSION['alert_message'] = "Tickets merged into $ticket_prefix$merge_into_ticket_number";
+
+ header("Location: " . $_SERVER["HTTP_REFERER"]);
+
+}
+
if (isset($_POST['bulk_resolve_tickets'])) {
// Role check
@@ -1335,6 +1394,7 @@
//Update new parent ticket
mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Ticket $ticket_prefix$ticket_number was merged into this ticket with comment: $merge_comment.
$ticket_subject
$ticket_details', ticket_reply_time_worked = '00:01:00', ticket_reply_type = '$ticket_reply_type', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $merge_into_ticket_id");
+ mysqli_query($mysqli, "UPDATE tickets SET ticket_updated_at = NOW() WHERE ticket_id = $merge_into_ticket_id");
// Logging
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Ticket', log_action = 'Merged', log_description = 'Merged ticket $ticket_prefix$ticket_number into $ticket_prefix$merge_into_ticket_number', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
diff --git a/ticket_bulk_merge_modal.php b/ticket_bulk_merge_modal.php
new file mode 100644
index 000000000..c55b37ed3
--- /dev/null
+++ b/ticket_bulk_merge_modal.php
@@ -0,0 +1,69 @@
+