diff --git a/admin/database_updates/2.8.5.php b/admin/database_updates/2.8.5.php new file mode 100644 index 000000000..7987d123f --- /dev/null +++ b/admin/database_updates/2.8.5.php @@ -0,0 +1,19 @@ + 0 AND `ticket_id` IS NULL"); + mysqli_query($mysqli, "DELETE `tasks` FROM `tasks` LEFT JOIN `tickets` ON `ticket_id` = `task_ticket_id` WHERE `task_ticket_id` > 0 AND `ticket_id` IS NULL"); + mysqli_query($mysqli, "DELETE `ticket_history` FROM `ticket_history` LEFT JOIN `tickets` ON `ticket_id` = `ticket_history_ticket_id` WHERE `ticket_id` IS NULL"); + mysqli_query($mysqli, "DELETE `sla_history` FROM `sla_history` LEFT JOIN `tickets` ON `ticket_id` = `sla_history_ticket_id` WHERE `ticket_id` IS NULL"); diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index 2c398022e..9929703d1 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -2540,6 +2540,28 @@ function demoBuildTickets($mysqli, $profile, $index, $client_id, $contact_ids, $ $on_hold = $stage['status'] === $context['status_hold']; + // A live ticket is mid-conversation. The pool's last word is the fix, so it + // is left off; the newest has no replies yet; of the other two, one has the + // client chasing (our move) and one is with them, or on hold. + if (!$stage['resolved']) { + if ($stage['status'] === $context['status_new']) { + $replies = []; + } else { + if ($replies && end($replies)['type'] === 'Public') { + array_pop($replies); + } + if ($slot === 3) { + if (!$replies || end($replies)['type'] !== 'Client') { + $replies[] = ['type' => 'Client', 'body' => '

Any update on this one? It is still happening.

', 'worked' => '', 'at' => demoDateTime(1, 9, 5)]; + } + } else { + $replies[] = ['type' => 'Public', 'worked' => '00:20:00', 'at' => demoDateTime(1, 11, 20), 'body' => $on_hold + ? '

Parts are on order - we will pick this back up as soon as they arrive.

' + : '

Made a change on our side. Can you try again and let us know if it is still happening?

']; + } + } + } + demoSeedTicket($mysqli, $fields, [ 'closed_at' => $stage['closed'] ? demoDateTime($stage['closed'], 15, 30) : '', 'sla' => $sla_for($ticket['priority']), diff --git a/agent/ajax.php b/agent/ajax.php index 0d2af7700..7742d2d36 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -696,9 +696,13 @@ if (isset($_POST['software_set_notes'])) { * Is used in conjunction with ticket_query_views to show who is currently viewing a ticket */ if (isset($_GET['ticket_add_view'])) { - $ticket_id = intval($_GET['ticket_id']); + $ticket_id = intval($_GET['ticket_id'] ?? 0); + $view_ticket = ticketRow($ticket_id); - mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = $ticket_id, view_user_id = $session_user_id, view_timestamp = NOW()"); + // Only a ticket this agent may open - the list of who is looking is no one else's business + if (lookupUserPermission('module_support') >= 1 && $view_ticket && (!intval($view_ticket['ticket_client_id']) || hasClientAccess($view_ticket['ticket_client_id']))) { + mysqli_query($mysqli, "INSERT INTO ticket_views SET view_ticket_id = $ticket_id, view_user_id = $session_user_id, view_timestamp = NOW()"); + } } /* @@ -707,25 +711,23 @@ if (isset($_GET['ticket_add_view'])) { * Called upon loading a ticket, and every 2 mins thereafter */ if (isset($_GET['ticket_query_views'])) { - $ticket_id = intval($_GET['ticket_id']); + $ticket_id = intval($_GET['ticket_id'] ?? 0); + $view_ticket = ticketRow($ticket_id); + $users = []; - $query = mysqli_query($mysqli, "SELECT user_name FROM ticket_views LEFT JOIN users ON view_user_id = user_id WHERE view_ticket_id = $ticket_id AND view_user_id != $session_user_id AND view_timestamp > DATE_SUB(NOW(), INTERVAL 2 MINUTE)"); - while ($row = mysqli_fetch_assoc($query)) { - $users[] = $row['user_name']; + if (lookupUserPermission('module_support') >= 1 && $view_ticket && (!intval($view_ticket['ticket_client_id']) || hasClientAccess($view_ticket['ticket_client_id']))) { + $query = mysqli_query($mysqli, "SELECT user_name FROM ticket_views LEFT JOIN users ON view_user_id = user_id WHERE view_ticket_id = $ticket_id AND view_user_id != $session_user_id AND view_timestamp > DATE_SUB(NOW(), INTERVAL 2 MINUTE)"); + while ($row = mysqli_fetch_assoc($query)) { + $users[] = $row['user_name']; + } } - if (!empty($users)) { - $users = array_unique($users); - if (count($users) > 1) { - // Multiple viewers - $response['message'] = "" . escapeHtml(implode(", ", $users) . " are viewing this ticket."); - } else { - // Single viewer - $response['message'] = "" . escapeHtml(implode("", $users) . " is viewing this ticket."); - } - } else { - // No viewers - $response['message'] = ""; + $users = array_values(array_unique($users)); + $response = ['message' => '']; + if (count($users) > 1) { + $response['message'] = "" . escapeHtml(implode(", ", $users) . " are viewing this ticket."); + } elseif ($users) { + $response['message'] = "" . escapeHtml($users[0] . " is viewing this ticket."); } echo json_encode($response); @@ -1059,7 +1061,7 @@ if (isset($_GET['get_client_contacts'])) { $contact_sql = mysqli_query( $mysqli, - "SELECT contact_id, contact_name, contact_title, contact_email, contact_photo, contact_primary, contact_important, contact_technical FROM contacts + "SELECT contact_id, contact_name, contact_title, contact_email, contact_photo, contact_primary, contact_important, contact_technical, contact_location_id FROM contacts LEFT JOIN clients on contact_client_id = client_id WHERE contacts.contact_archived_at IS NULL AND contact_client_id = $client_id " . clientScopeSql('contact_client_id') . " @@ -1081,6 +1083,39 @@ if (isset($_GET['get_client_contacts'])) { echo json_encode($response); } +/* + * New Ticket - the other open tickets for the contact or asset picked, so a + * second ticket for the same problem shows up before it is raised. + */ +if (isset($_GET['ticket_also_open'])) { + enforceUserPermission('module_support', 2); + + header('Content-Type: application/json'); + + $client_id = intval($_GET['client_id'] ?? 0); + if (!$client_id || !hasClientAccess($client_id)) { + echo json_encode(['html' => '']); + exit; + } + $also_contact_id = ticketClientOwnedId('contact', $_GET['contact_id'] ?? 0, $client_id); + $also_asset_id = ticketClientOwnedId('asset', $_GET['asset_id'] ?? 0, $client_id); + $rows = ticketAlsoOpen($also_contact_id, $also_asset_id, 0, 5); + + $html = ''; + if ($rows) { + $html = '
Already open for ' + . ($also_contact_id && $also_asset_id ? 'this contact or asset' : ($also_contact_id ? 'this contact' : 'this asset')) . '
'; + foreach ($rows as $row) { + $html .= '
' . ticketLink($row) + . ' ' . ticketStatusHtml($row['ticket_status_name'], $row['ticket_status_color'], 'detail') . '
'; + } + $html .= '
Add to one of these instead, if it is the same problem.
'; + } + + echo json_encode(['html' => $html]); + exit; +} + /* * Returns ordered list of active assets for a specified client */ @@ -1093,7 +1128,7 @@ if (isset($_GET['get_client_assets'])) { $asset_sql = mysqli_query( $mysqli, - "SELECT asset_id, asset_name, asset_type, asset_make, asset_model, contact_name FROM assets + "SELECT asset_id, asset_name, asset_type, asset_make, asset_model, asset_contact_id, asset_location_id, contact_name FROM assets LEFT JOIN clients on asset_client_id = client_id LEFT JOIN contacts ON contact_id = asset_contact_id WHERE assets.asset_archived_at IS NULL AND asset_client_id = $client_id @@ -1246,164 +1281,109 @@ if (isset($_GET['get_readable_pass'])) { /* * ITFlow - POST request handler for client tickets */ +/* + * The ticket board (agent/ticket_kanban.php, js/tickets_kanban.js). + * + * Moving a column reorders the statuses - only when the admin allows it. + * Moving a card changes its status the way the ticket page does: into + * Resolved resolves it (open tasks first, and the client is told), out of + * Resolved reopens it, anything else is a status change. New is set when a + * ticket comes in and Closed by closing it, so neither is a place to drop + * one. With ticket ordering on, the column's order is kept too. + */ if (isset($_POST['update_kanban_status_position'])) { - // Update multiple ticket status kanban orders - enforceUserPermission('module_support', 2); - $positions = $_POST['positions']; + validateCSRFToken(); - foreach ($positions as $position) { - $status_id = intval($position['status_id']); - $kanban = intval($position['status_kanban']); + header('Content-Type: application/json'); + if (lookupUserPermission('module_support') < 2 || intval($config_ticket_moving_columns) !== 1) { + http_response_code(403); + echo json_encode(['error' => 'Columns cannot be moved here.']); + exit; + } + + foreach ((array) ($_POST['positions'] ?? []) as $position) { + $status_id = intval($position['status_id'] ?? 0); + $kanban = intval($position['status_kanban'] ?? 0); mysqli_query($mysqli, "UPDATE ticket_statuses SET ticket_status_order = $kanban WHERE ticket_status_id = $status_id"); } - // return a response - echo json_encode(['status' => 'success']); + echo json_encode(['ok' => true]); exit; } if (isset($_POST['update_kanban_ticket'])) { - // Update ticket kanban order and status - enforceUserPermission('module_support', 2); - // all tickets on the column - $positions = $_POST['positions']; + validateCSRFToken(); - foreach ($positions as $position) { - $ticket_id = intval($position['ticket_id']); + header('Content-Type: application/json'); - // Client perms check - $client_query = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_client_id FROM tickets WHERE ticket_id = $ticket_id")); - $client_id = intval($client_query['ticket_client_id']); - enforceClientAccess(); - - $kanban = intval($position['ticket_order']); // ticket kanban position - $status = intval($position['ticket_status']); // ticket statuses - $oldStatus = intval($position['ticket_oldStatus']); // ticket old status if moved - - $statuses['Closed'] = 5; - $statuses['Resolved'] = 4; - - // Continue if status is null / Closed - if ($status === null || $status === $statuses['Closed']) { - continue; - } - - - if ($oldStatus === false) { - // if ticket was not moved, just uptdate the order on kanban - mysqli_query($mysqli, "UPDATE tickets SET ticket_order = $kanban WHERE ticket_id = $ticket_id"); - triggerCustomAction('ticket_update', $ticket_id); - } else { - // If the ticket was moved from a resolved status to another status, we need to update ticket_resolved_at - if ($oldStatus === $statuses['Resolved']) { - mysqli_query($mysqli, "UPDATE tickets SET ticket_order = $kanban, ticket_status = $status, ticket_resolved_at = NULL WHERE ticket_id = $ticket_id"); - resetTicketResolutionSla($ticket_id); - syncTicketSlaClock($ticket_id); - $new_status_name = escapeSql(getTicketStatusName($status)); - logTicketHistory($ticket_id, "$session_name reopened the ticket to $new_status_name from the kanban"); - triggerCustomAction('ticket_update', $ticket_id); - } elseif ($status === $statuses['Resolved']) { - // If the ticket was moved to a resolved status, we need to update ticket_resolved_at - mysqli_query($mysqli, "UPDATE tickets SET ticket_order = $kanban, ticket_status = $status, ticket_resolved_at = NOW() WHERE ticket_id = $ticket_id"); - // An agent resolving the ticket counts as a response, same as - // resolving from the ticket itself does - setTicketFirstResponse($ticket_id); - setTicketResolutionSlaMet($ticket_id); - syncTicketSlaClock($ticket_id); - logTicketHistory($ticket_id, "$session_name resolved the ticket from the kanban"); - triggerCustomAction('ticket_update', $ticket_id); - - // Client notification email - if (!empty($config_smtp_host) && $config_ticket_client_general_notifications == 1) { - - // Get details - $ticket_sql = mysqli_query($mysqli, "SELECT contact_name, contact_email, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, ticket_assigned_to, ticket_url_key, ticket_client_id FROM tickets - LEFT JOIN contacts ON ticket_contact_id = contact_id - LEFT JOIN ticket_statuses ON ticket_status = ticket_status_id - WHERE ticket_id = $ticket_id - "); - $row = mysqli_fetch_assoc($ticket_sql); - - $contact_name = escapeSql($row['contact_name']); - $contact_email = escapeSql($row['contact_email']); - $ticket_prefix = escapeSql($row['ticket_prefix']); - $ticket_number = intval($row['ticket_number']); - $ticket_subject = escapeSql($row['ticket_subject']); - $client_id = intval($row['ticket_client_id']); - $ticket_assigned_to = intval($row['ticket_assigned_to']); - $ticket_status = escapeSql($row['ticket_status_name']); - $url_key = escapeSql($row['ticket_url_key']); - - // Sanitize Config vars from get_settings.php - $config_ticket_from_name = escapeSql($config_ticket_from_name); - $config_ticket_from_email = escapeSql($config_ticket_from_email); - $config_base_url = escapeSql($config_base_url); - - // Get Company Info - $sql = mysqli_query($mysqli, "SELECT company_name, company_phone, company_phone_country_code FROM companies WHERE company_id = 1"); - $row = mysqli_fetch_assoc($sql); - $company_name = escapeSql($row['company_name']); - $company_phone = escapeSql(formatPhoneNumber($row['company_phone'], $row['company_phone_country_code'])); - - // EMAIL - $subject = "Ticket resolved - [$ticket_prefix$ticket_number] - $ticket_subject | (pending closure)"; - $body = "##- Please type your reply above this line -##

Hello $contact_name,

Your ticket regarding $ticket_subject has been marked as solved and is pending closure.

If your request/issue is resolved, you can simply ignore this email. If you need further assistance, please reply or re-open to let us know!

Ticket: $ticket_prefix$ticket_number
Subject: $ticket_subject
Status: $ticket_status
Portal: View ticket

--
$company_name - Support
$config_ticket_from_email
$company_phone"; - - // Check email valid - if (filter_var($contact_email, FILTER_VALIDATE_EMAIL)) { - - $data = []; - - // Email Ticket Contact - // Queue Mail - - $data[] = [ - 'from' => $config_ticket_from_email, - 'from_name' => $config_ticket_from_name, - 'recipient' => $contact_email, - 'recipient_name' => $contact_name, - 'subject' => $subject, - 'body' => $body - ]; - } - - // Also Email all the watchers - $sql_watchers = mysqli_query($mysqli, "SELECT watcher_email FROM ticket_watchers WHERE watcher_ticket_id = $ticket_id"); - $body .= "

----------------------------------------
YOU ARE A COLLABORATOR ON THIS TICKET"; - while ($row = mysqli_fetch_assoc($sql_watchers)) { - $watcher_email = escapeSql($row['watcher_email']); - - // Queue Mail - $data[] = [ - 'from' => $config_ticket_from_email, - 'from_name' => $config_ticket_from_name, - 'recipient' => $watcher_email, - 'recipient_name' => $watcher_email, - 'subject' => $subject, - 'body' => $body - ]; - } - addToMailQueue($data); - } - //End Mail IF - - } else { - // If the ticket was moved from any status to another status - mysqli_query($mysqli, "UPDATE tickets SET ticket_order = $kanban, ticket_status = $status WHERE ticket_id = $ticket_id"); - syncTicketSlaClock($ticket_id); - $new_status_name = escapeSql(getTicketStatusName($status)); - logTicketHistory($ticket_id, "$session_name set the status to $new_status_name from the kanban"); - triggerCustomAction('ticket_update', $ticket_id); - } - } + $kanban_error = function ($message, $code = 422) { + http_response_code($code); + echo json_encode(['error' => $message]); + exit; + }; + if (lookupUserPermission('module_support') < 2) { + $kanban_error('You cannot change tickets.', 403); } - // return a response - echo json_encode(['status' => 'success','payload' => $positions]); + $row = ticketRow($_POST['ticket_id'] ?? 0); + if (!$row || (intval($row['ticket_client_id']) && !hasClientAccess($row['ticket_client_id']))) { + $kanban_error('That ticket is not there any more - reload the board.', 404); + } + $ticket_id = intval($row['ticket_id']); + $reference = ticketReference($row); + if (!empty($row['ticket_closed_at'])) { + $kanban_error("$reference is closed."); + } + + $status_id = intval($_POST['status_id'] ?? 0); + $current_status = intval($row['ticket_status']); + $message = ''; + + if ($status_id !== $current_status) { + $pickable = ticketPickableStatuses(); + if ($status_id === TICKET_STATUS_RESOLVED) { + $open_tasks = ticketOpenTaskCount($ticket_id); + if ($open_tasks) { + $kanban_error("Finish the $open_tasks open task" . ($open_tasks === 1 ? '' : 's') . " on $reference before resolving it."); + } + ticketResolve($row, ' from the board'); + if (intval($config_ticket_client_general_notifications) === 1) { + ticketMailResolved($ticket_id); + } + $message = "$reference resolved"; + } elseif (isset($pickable[$status_id])) { + if (!empty($row['ticket_resolved_at'])) { + ticketReopen($row, $status_id, ' from the board'); + $message = "$reference reopened"; + } else { + [$ok, $message] = ticketChangeStatus($ticket_id, $status_id); + if (!$ok) { + $kanban_error(strip_tags($message)); + } + $message = "$reference: " . strip_tags($message); + } + } elseif ($status_id === TICKET_STATUS_NEW) { + $kanban_error('New is for tickets nobody has picked up yet - a ticket can only move on from there.'); + } else { + $kanban_error('A ticket cannot be moved to that status.'); + } + } + + // The column's order, when the admin keeps one. Setting ticket_updated_at to + // itself stops ON UPDATE moving it - reordering a board is not activity. + if (intval($config_ticket_ordering) === 1) { + $scope = clientScopeSql('ticket_client_id'); + foreach (array_values((array) ($_POST['order'] ?? [])) as $position => $order_ticket_id) { + $order_ticket_id = intval($order_ticket_id); + mysqli_query($mysqli, "UPDATE tickets SET ticket_order = $position, ticket_updated_at = ticket_updated_at WHERE ticket_id = $order_ticket_id $scope"); + } + } + + echo json_encode(['ok' => true, 'message' => $message, 'status_id' => $status_id]); exit; } @@ -1414,12 +1394,20 @@ if (isset($_POST['update_ticket_tasks_order'])) { enforceUserPermission('module_support', 2); - $positions = $_POST['positions']; - $ticket_id = intval($_POST['ticket_id']); + $positions = (array) ($_POST['positions'] ?? []); + $ticket_id = intval($_POST['ticket_id'] ?? 0); + + // A ticket this agent can reach - one with no client is internal work anyone can + $task_ticket = ticketRow($ticket_id); + if (!$task_ticket || (intval($task_ticket['ticket_client_id']) && !hasClientAccess($task_ticket['ticket_client_id']))) { + http_response_code(403); + echo json_encode(['status' => 'error']); + exit; + } foreach ($positions as $position) { - $id = intval($position['id']); - $order = intval($position['order']); + $id = intval($position['id'] ?? 0); + $order = intval($position['order'] ?? 0); mysqli_query($mysqli, "UPDATE tasks SET task_order = $order WHERE task_ticket_id = $ticket_id AND task_id = $id"); } @@ -1745,6 +1733,10 @@ if (isset($_GET['ai_ticket_summary'])) { LIMIT 1 "); $row = mysqli_fetch_assoc($sql); + if (!$row) { + echo 'That ticket no longer exists.'; + exit; + } $ticket_subject = $row['ticket_subject']; $ticket_details = strip_tags($row['ticket_details']); // strip HTML for cleaner prompt $ticket_status = $row['ticket_status_name']; @@ -1753,7 +1745,10 @@ if (isset($_GET['ai_ticket_summary'])) { $ticket_priority = $row['ticket_priority']; $client_id = intval($row['ticket_client_id']); - enforceClientAccess(); + // A ticket with no client is internal work any agent may read + if ($client_id) { + enforceClientAccess(); + } // Get ticket replies $sql_replies = mysqli_query($mysqli, " diff --git a/agent/asset.php b/agent/asset.php index 72b8e4383..7276a5f57 100644 --- a/agent/asset.php +++ b/agent/asset.php @@ -119,32 +119,14 @@ if (mysqli_num_rows($sql) == 0) { // Tags - functions/tags.php $asset_tags_display = tagPills('asset', $asset_id, tagsForRecord('asset', $asset_id), "assets.php?client_id=$client_id&"); - // Tickets - linked as the ticket's asset or as one of its additional assets - $sql_related_tickets = mysqli_query($mysqli, " - SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_priority, ticket_created_at, - ticket_updated_at, ticket_resolved_at, ticket_closed_at, ticket_assigned_to, - user_name, user_avatar, ticket_status_id, ticket_status_name, ticket_status_color - FROM tickets - LEFT JOIN users ON ticket_assigned_to = user_id - LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status - LEFT JOIN ticket_assets ON tickets.ticket_id = ticket_assets.ticket_id - WHERE ticket_asset_id = $asset_id OR ticket_assets.asset_id = $asset_id - GROUP BY tickets.ticket_id - ORDER BY (ticket_resolved_at IS NULL AND ticket_closed_at IS NULL) DESC, ticket_number DESC - "); - $ticket_count = mysqli_num_rows($sql_related_tickets); - $ticket_open_count = 0; - $related_tickets = []; - while ($row = mysqli_fetch_assoc($sql_related_tickets)) { - $related_tickets[] = $row; - if (empty($row['ticket_resolved_at']) && empty($row['ticket_closed_at'])) { - $ticket_open_count++; - } - } + // Tickets - linked as the ticket's asset or as one of its other assets (functions/ticket.php) + $related_tickets = ticketRows(ticketAssetSql($asset_id)); + $ticket_count = count($related_tickets); + $ticket_open_count = count(array_filter(array_column($related_tickets, 'is_open'))); // Recurring tickets $sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT recurring_tickets.recurring_ticket_id, recurring_ticket_subject, - recurring_ticket_priority, recurring_ticket_frequency, recurring_ticket_next_run + recurring_ticket_priority, recurring_ticket_frequency, recurring_ticket_next_run, recurring_ticket_paused_at FROM recurring_tickets LEFT JOIN recurring_ticket_assets ON recurring_tickets.recurring_ticket_id = recurring_ticket_assets.recurring_ticket_id WHERE recurring_ticket_asset_id = $asset_id OR recurring_ticket_assets.asset_id = $asset_id @@ -760,46 +742,7 @@ if (mysqli_num_rows($sql) == 0) { -
- - - - - - - - - - - - - 'text-bg-dark', 'High' => 'text-bg-danger', 'Medium' => 'text-bg-warning', 'Low' => 'text-bg-info']; - $ticket_assigned_to_display = formatAssignee($row['ticket_assigned_to'], $row['user_name'], $row['user_avatar'], !in_array($ticket_status_id, [4, 5])); - ?> - - - - - - - - - - -
TicketSubjectPriorityStatusAssignedUpdated
-
-
+
No tickets have mentioned this asset.
@@ -839,9 +782,9 @@ if (mysqli_num_rows($sql) == 0) { - + - () + -
- - - - - - - - - - - - - - - - -
TicketSubjectPriorityStatusAssignedUpdated
-
+
No tickets yet.
@@ -613,7 +581,7 @@ if (!$can_support) { - + -
- - - - - - - - - - - - - -
TicketSubjectStatusAssignedUpdated
-
+ count($tickets)) { ?>
Showing every open ticket and the most recent closed of .
diff --git a/agent/modals/asset/asset.php b/agent/modals/asset/asset.php index fc526400c..90369188a 100644 --- a/agent/modals/asset/asset.php +++ b/agent/modals/asset/asset.php @@ -98,32 +98,12 @@ $credential_count = count($related_credentials); // Tickets - open ones first; the most recent few here, the rest on the asset page $quick_ticket_limit = 8; -$sql_related_tickets = mysqli_query($mysqli, " - SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_updated_at, ticket_created_at, - ticket_resolved_at, ticket_closed_at, ticket_assigned_to, user_name, user_avatar, - ticket_status_name, ticket_status_color - FROM tickets - LEFT JOIN users ON ticket_assigned_to = user_id - LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status - LEFT JOIN ticket_assets ON tickets.ticket_id = ticket_assets.ticket_id - WHERE ticket_asset_id = $asset_id OR ticket_assets.asset_id = $asset_id - GROUP BY tickets.ticket_id - ORDER BY (ticket_resolved_at IS NULL AND ticket_closed_at IS NULL) DESC, ticket_number DESC -"); -$ticket_count = mysqli_num_rows($sql_related_tickets); -$ticket_open_count = 0; -$related_tickets = []; -while ($row = mysqli_fetch_assoc($sql_related_tickets)) { - $is_open = empty($row['ticket_resolved_at']) && empty($row['ticket_closed_at']); - $ticket_open_count += $is_open ? 1 : 0; - if (count($related_tickets) < $quick_ticket_limit) { - $related_tickets[] = $row + ['is_open' => $is_open]; - } -} +[$ticket_count, $ticket_open_count] = ticketCounts(ticketAssetSql($asset_id)); +$related_tickets = ticketRows(ticketAssetSql($asset_id), $quick_ticket_limit); // Recurring tickets $sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT recurring_tickets.recurring_ticket_id, recurring_ticket_subject, - recurring_ticket_frequency, recurring_ticket_next_run + recurring_ticket_frequency, recurring_ticket_next_run, recurring_ticket_paused_at FROM recurring_tickets LEFT JOIN recurring_ticket_assets ON recurring_tickets.recurring_ticket_id = recurring_ticket_assets.recurring_ticket_id WHERE recurring_ticket_asset_id = $asset_id OR recurring_ticket_assets.asset_id = $asset_id @@ -362,23 +342,7 @@ ob_start();
-
- - - - - - - - - - - - -
-
+ true]) ?> count($related_tickets)) { ?>
All tickets on the asset page
@@ -391,7 +355,7 @@ ob_start();
  • - · next +
  • diff --git a/agent/modals/contact/contact.php b/agent/modals/contact/contact.php index 9b180f631..8fe120700 100644 --- a/agent/modals/contact/contact.php +++ b/agent/modals/contact/contact.php @@ -73,23 +73,8 @@ $quick_ticket_limit = 8; $related_tickets = []; $ticket_count = $ticket_open_count = 0; if ($can_support) { - $sql_related_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_updated_at, ticket_created_at, - ticket_resolved_at, ticket_closed_at, ticket_assigned_to, user_name, user_avatar, ticket_status_name, ticket_status_color - FROM tickets - LEFT JOIN users ON ticket_assigned_to = user_id - LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status - WHERE ticket_contact_id = $contact_id - AND ticket_archived_at IS NULL - ORDER BY (ticket_resolved_at IS NULL AND ticket_closed_at IS NULL) DESC, ticket_number DESC" - ); - $ticket_count = mysqli_num_rows($sql_related_tickets); - while ($row = mysqli_fetch_assoc($sql_related_tickets)) { - $is_open = empty($row['ticket_resolved_at']) && empty($row['ticket_closed_at']); - $ticket_open_count += $is_open ? 1 : 0; - if (count($related_tickets) < $quick_ticket_limit) { - $related_tickets[] = $row + ['is_open' => $is_open]; - } - } + [$ticket_count, $ticket_open_count] = ticketCounts("tickets.ticket_contact_id = $contact_id"); + $related_tickets = ticketRows("tickets.ticket_contact_id = $contact_id", $quick_ticket_limit); } // Recurring tickets @@ -289,23 +274,7 @@ ob_start();
    -
    - - - - - - - - - - - - -
    -
    + true]) ?> count($related_tickets)) { ?> diff --git a/agent/modals/location/location.php b/agent/modals/location/location.php index b6b46ea4e..2c5c8c294 100644 --- a/agent/modals/location/location.php +++ b/agent/modals/location/location.php @@ -51,13 +51,7 @@ if ($can_support) { while ($row = mysqli_fetch_assoc($sql)) { $networks[] = $row; } - $sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_status_name, ticket_status_color FROM tickets - LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status - WHERE ticket_location_id = $location_id AND ticket_resolved_at IS NULL AND ticket_closed_at IS NULL - ORDER BY ticket_number DESC"); - while ($row = mysqli_fetch_assoc($sql)) { - $open_tickets[] = $row; - } + $open_tickets = ticketRows("tickets.ticket_location_id = $location_id AND " . TICKET_OPEN_SQL); } $quick_tabs = array_filter([ @@ -208,20 +202,7 @@ ob_start();
    -
    - - - - - - - - - - -
    -
    + true]) ?>
    diff --git a/agent/modals/recurring_ticket/recurring_ticket_add.php b/agent/modals/recurring_ticket/recurring_ticket_add.php index 0718302b3..578be01c6 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_add.php +++ b/agent/modals/recurring_ticket/recurring_ticket_add.php @@ -2,7 +2,19 @@ require_once '../../../includes/modal_header.php'; +/* + * New Recurring Ticket - what the tickets it raises will say, how often and + * from when, what they are about and their tasks. Opened from a client, + * contact or asset, it starts with that filled in; picking an asset fills + * in the person it is assigned to. + */ + +enforceUserPermission('module_support', 2); + $client_id = intval($_GET['client_id'] ?? 0); +if ($client_id) { + enforceClientAccess(); +} $contact_id = intval($_GET['contact_id'] ?? 0); $asset_id = intval($_GET['asset_id'] ?? 0); @@ -26,15 +38,15 @@ ob_start(); + + - -
    @@ -144,7 +156,7 @@ ob_start();
    value="1" id="billable"> - +
    @@ -202,11 +214,12 @@ ob_start();
    - +
    - " max="2999-12-31" required> + " max="2999-12-31" value="" required>
    +
    The nightly cron raises a ticket on this day, then again each time it comes round. Monthly ones keep to this day of the month - the last day, in a shorter month.
    @@ -223,10 +236,10 @@ ob_start();
    - +
    -
    diff --git a/agent/modals/recurring_ticket/recurring_ticket_bulk_agent_edit.php b/agent/modals/recurring_ticket/recurring_ticket_bulk_agent_edit.php index e961de21d..450503821 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_bulk_agent_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_bulk_agent_edit.php @@ -2,6 +2,8 @@ require_once '../../../includes/modal_header.php'; +enforceUserPermission('module_support', 2); + $recurring_ticket_ids = array_map('intval', $_GET['recurring_ticket_ids'] ?? []); $count = count($recurring_ticket_ids); diff --git a/agent/modals/recurring_ticket/recurring_ticket_bulk_billable_edit.php b/agent/modals/recurring_ticket/recurring_ticket_bulk_billable_edit.php index 8784bf0dd..bb3131df6 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_bulk_billable_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_bulk_billable_edit.php @@ -2,6 +2,9 @@ require_once '../../../includes/modal_header.php'; +enforceUserPermission('module_support', 2); +enforceUserPermission('module_sales', 2); + $recurring_ticket_ids = array_map('intval', $_GET['recurring_ticket_ids'] ?? []); $count = count($recurring_ticket_ids); diff --git a/agent/modals/recurring_ticket/recurring_ticket_bulk_category_edit.php b/agent/modals/recurring_ticket/recurring_ticket_bulk_category_edit.php index 854826d1f..b099fc8c2 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_bulk_category_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_bulk_category_edit.php @@ -2,6 +2,8 @@ require_once '../../../includes/modal_header.php'; +enforceUserPermission('module_support', 2); + $recurring_ticket_ids = array_map('intval', $_GET['recurring_ticket_ids'] ?? []); $count = count($recurring_ticket_ids); diff --git a/agent/modals/recurring_ticket/recurring_ticket_bulk_next_run_edit.php b/agent/modals/recurring_ticket/recurring_ticket_bulk_next_run_edit.php index ac7d76337..d0ebdd217 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_bulk_next_run_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_bulk_next_run_edit.php @@ -2,6 +2,8 @@ require_once '../../../includes/modal_header.php'; +enforceUserPermission('module_support', 2); + $recurring_ticket_ids = array_map('intval', $_GET['recurring_ticket_ids'] ?? []); $count = count($recurring_ticket_ids); diff --git a/agent/modals/recurring_ticket/recurring_ticket_bulk_priority_edit.php b/agent/modals/recurring_ticket/recurring_ticket_bulk_priority_edit.php index de6ce70cd..6794e2222 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_bulk_priority_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_bulk_priority_edit.php @@ -2,6 +2,8 @@ require_once '../../../includes/modal_header.php'; +enforceUserPermission('module_support', 2); + $recurring_ticket_ids = array_map('intval', $_GET['recurring_ticket_ids'] ?? []); $count = count($recurring_ticket_ids); diff --git a/agent/modals/recurring_ticket/recurring_ticket_edit.php b/agent/modals/recurring_ticket/recurring_ticket_edit.php index 36ff56214..3275b9c39 100644 --- a/agent/modals/recurring_ticket/recurring_ticket_edit.php +++ b/agent/modals/recurring_ticket/recurring_ticket_edit.php @@ -1,289 +1,260 @@ $row['recurring_ticket_task_name'], - 'estimate' => intval($row['recurring_ticket_task_completion_estimate']) - ]; +$recurring_ticket_id = intval($_GET['id'] ?? 0); +$recurring = recurringTicketRow($recurring_ticket_id); +if (!$recurring) { + echo json_encode(['error' => 'That recurring ticket no longer exists.']); + exit; } - -// Additional Assets Selected -$additional_assets_array = array(); -$sql_additional_assets = mysqli_query($mysqli, "SELECT asset_id FROM recurring_ticket_assets WHERE recurring_ticket_id = $recurring_ticket_id"); -while ($row = mysqli_fetch_assoc($sql_additional_assets)) { - $additional_asset_id = intval($row['asset_id']); - $additional_assets_array[] = $additional_asset_id; -} - +$client_id = intval($recurring['recurring_ticket_client_id']); if ($client_id) { enforceClientAccess(); } +$contact_id = intval($recurring['recurring_ticket_contact_id']); +$asset_id = intval($recurring['recurring_ticket_asset_id']); +$assigned_to = intval($recurring['recurring_ticket_assigned_to']); +$category_id = intval($recurring['recurring_ticket_category']); +$billable = intval($recurring['recurring_ticket_billable']); +$frequency = recurringTicketFrequency($recurring['recurring_ticket_frequency']); +$next_run = substr((string) $recurring['recurring_ticket_next_run'], 0, 10); +$paused = recurringTicketPaused($recurring); +$upcoming = recurringTicketUpcoming($recurring, 4); + +// Tasks already on this schedule, pre-filling the editable rows +$existing_tasks = []; +$sql_tasks = mysqli_query($mysqli, "SELECT recurring_ticket_task_name, recurring_ticket_task_completion_estimate FROM recurring_ticket_tasks + WHERE recurring_ticket_task_recurring_ticket_id = $recurring_ticket_id ORDER BY recurring_ticket_task_order ASC, recurring_ticket_task_id ASC"); +while ($row = mysqli_fetch_assoc($sql_tasks)) { + $existing_tasks[] = ['name' => $row['recurring_ticket_task_name'], 'estimate' => intval($row['recurring_ticket_task_completion_estimate'])]; +} + +$other_asset_ids = []; +$sql_other_assets = mysqli_query($mysqli, "SELECT asset_id FROM recurring_ticket_assets WHERE recurring_ticket_id = $recurring_ticket_id"); +while ($row = mysqli_fetch_row($sql_other_assets)) { + $other_asset_ids[] = intval($row[0]); +} + ob_start(); ?>
    -