From 0ac67766ee3a85018652117abc6e23bf32ff35d2 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Fri, 22 Sep 2017 22:24:27 -0400 Subject: [PATCH] New audit trail now appears on the ticket page --- admin/admin_ticket.php | 277 +++++++++++++++++++++++++++++--------- admin/move_category.php | 1 - css/mods-for-hesk-new.css | 5 + 3 files changed, 217 insertions(+), 66 deletions(-) diff --git a/admin/admin_ticket.php b/admin/admin_ticket.php index ab6df2e8..f2e74a12 100644 --- a/admin/admin_ticket.php +++ b/admin/admin_ticket.php @@ -98,14 +98,34 @@ if (!$ticket['owner'] && !$can_view_unassigned) { } // Get audit information -$auditRes = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail` AS `audit` +$audit_sort = $hesk_settings['new_top'] ? "ASC" : "DESC"; +$auditRes = hesk_dbQuery("SELECT `audit`.`id`, `audit`.`language_key`, `audit`.`date`, + `values`.`replacement_index`, `values`.`replacement_value` + FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail` AS `audit` LEFT JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail_to_replacement_values` AS `values` ON `audit`.`id` = `values`.`audit_trail_id` - WHERE `entity_type` = 'TICKET' AND `entity_id` = " . intval($ticket['id'])); -$auditRecords = array(); -$lastAuditRecord = null; + WHERE `entity_type` = 'TICKET' AND `entity_id` = " . intval($ticket['id']) . " + ORDER BY `audit`.`date` {$audit_sort}"); +$audit_records = array(); +$current_audit_record = null; while ($row = hesk_dbFetchAssoc($auditRes)) { - // TODO + if ($current_audit_record == null || $current_audit_record['id'] != $row['id']) { + if ($current_audit_record != null) { + $audit_records[] = $current_audit_record; + } + $current_audit_record['id'] = $row['id']; + $current_audit_record['language_key'] = $row['language_key']; + $current_audit_record['date'] = $row['date']; + $current_audit_record['replacement_values'] = array(); + } + + if ($row['replacement_index'] != null) { + $current_audit_record['replacement_values'][intval($row['replacement_index'])] = $row['replacement_value']; + } +} + +if ($current_audit_record != null) { + $audit_records[] = $current_audit_record; } /* Set last replier name */ @@ -1783,7 +1803,38 @@ function mfh_print_message() { function hesk_printTicketReplies() { - global $hesklang, $hesk_settings, $result, $reply; + global $hesklang, $hesk_settings, $result, $reply, $audit_records; + + // Sort replies and audit messages. They'll be in the proper order already + $combined_records = array(); + foreach ($audit_records as $audit_record) { + $audit_record['SORT_TYPE'] = 'AUDIT_RECORD'; + $combined_records[] = $audit_record; + } + while ($reply = hesk_dbFetchAssoc($result)) { + $reply['SORT_TYPE'] = 'REPLY'; + $combined_records[] = $reply; + } + + // Re-sort them so they're in order by date + usort($combined_records, function ($a, $b) { + $a_date = null; + $b_date = null; + if ($a['SORT_TYPE'] == 'REPLY') { + $a_date = strtotime($a['dt']); + } else { + $a_date = strtotime($a['date']); + } + + if ($b['SORT_TYPE'] == 'REPLY') { + $b_date = strtotime($b['dt']); + } else { + $b_date = strtotime($b['date']); + } + + return $a_date - $b_date; + }); + echo ''; + + return; + +} // End hesk_printTicketReplies() + +function mfh_print_reply($reply) { + global $hesklang, $hesk_settings; + + $reply['dt'] = hesk_date($reply['dt'], true); + ?> +
  • + + + + + +
    + +

    +
    +
    +
    + +
    +
    +
    - + - -
  • - + + '; - } - echo ''; +function mfh_print_audit_record($record) { + global $hesklang; - return; + $record['date'] = hesk_date($record['date'], true); + $font_icon = null; + switch ($record['language_key']) { + case 'audit_moved_category': + $font_icon = 'fa-pie-chart'; + break; + case 'audit_assigned': + case 'audit_assigned_self': + $font_icon = 'fa-user-plus'; + break; + case 'audit_unassigned': + $font_icon = 'fa-user-minus'; + break; + case 'audit_autoassigned': + $font_icon = 'fa-bolt'; + break; + case 'audit_closed': + case 'audit_automatically_closed': + $font_icon = 'fa-check-circle'; + break; + case 'audit_opened': + $font_icon = 'fa-circle-o'; + break; + case 'audit_locked': + case 'audit_automatically_locked': + $font_icon = 'fa-lock'; + break; + case 'audit_unlocked': + $font_icon = 'fa-unlock-alt'; + break; + case 'audit_created': + case 'audit_submitted_by': + $font_icon = 'fa-user'; + break; + case 'audit_priority': + // The new priority is in arg[1] + $priority = $record['replacement_values'][1]; + if ($priority === 'critical') { + $font_icon = 'fa-long-arrow-up'; + } elseif ($priority === 'high') { + $font_icon = 'fa-angle-double-up'; + } elseif ($priority === 'medium') { + $font_icon = 'fa-angle-double-down'; + } else { + $font_icon = 'fa-long-arrow-down'; + } -} // End hesk_printTicketReplies() + // Now localize the text for display + $record['replacement_values'][1] = $hesklang[$priority]; + break; + case 'audit_status': + $font_icon = 'fa-exchange'; + break; + case 'audit_submitted_via_piping': + case 'audit_submitted_via_pop': + $font_icon = 'fa-envelope-o'; + break; + case 'audit_attachment_deleted': + $font_icon = 'fa-paperclip'; + break; + case 'audit_merged': + $font_icon = 'fa-code-fork'; + break; + case 'audit_time_worked': + $font_icon = 'fa-clock'; + break; + default: + $font_icon = 'fa-question-circle'; + break; + } + ?> +
  • + +
    + +

    + +

    +
    +
  • + $_SESSION['name'] . ' (' . $_SESSION['user'] . ')', 1 => $row['name'] diff --git a/css/mods-for-hesk-new.css b/css/mods-for-hesk-new.css index 756fd12c..56ddeb91 100644 --- a/css/mods-for-hesk-new.css +++ b/css/mods-for-hesk-new.css @@ -350,4 +350,9 @@ div.ticket-info { border-color: #3c8dbc; box-shadow: none; outline: 0; +} + +.timeline-header.audit-record { + font-size: 12px !important; + } \ No newline at end of file