From 35f03ee26e754eead37fef710202cc2e6eaac870 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Tue, 19 Sep 2017 22:03:39 -0400 Subject: [PATCH] Getting started with new audit trail entries --- change_status.php | 16 ++++++++-------- inc/common.inc.php | 33 ++++++++++++++++++++++++++++++++- inc/posting_functions.inc.php | 2 +- submit_ticket.php | 10 ++++++++-- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/change_status.php b/change_status.php index 5fee55e1..133a7fda 100644 --- a/change_status.php +++ b/change_status.php @@ -52,7 +52,7 @@ if ($status == 3) // Closed } $status = $closedStatus; $action = $hesklang['closed']; - $revision = sprintf($hesklang['thist3'], hesk_date(), $hesklang['customer']); + $revision_key = 'audit_closed'; if ($hesk_settings['custopen'] != 1) { $locked = 1; @@ -73,7 +73,7 @@ if ($status == 3) // Closed $status = $statusRow['ID']; $action = $hesklang['opened']; - $revision = sprintf($hesklang['thist4'], hesk_date(), $hesklang['customer']); + $revision_key = 'audit_opened'; // We will ask the customer why is the ticket being reopened $_SESSION['force_form_top'] = true; @@ -94,12 +94,9 @@ hesk_verifyEmailMatch($trackingID); $_SESSION['t_track'] = $trackingID; $_SESSION['t_email'] = $hesk_settings['e_email']; -// Load statuses -require_once(HESK_PATH . 'inc/statuses.inc.php'); - // Is current ticket status even changeable by customers? -$ticket = hesk_dbFetchAssoc( hesk_dbQuery( "SELECT `status`, `staffreplies`, `lastreplier` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid`='".hesk_dbEscape($trackingID)."' LIMIT 1") ); -if (!hesk_can_customer_change_status($ticket['status'])) { +$ticket = hesk_dbFetchAssoc( hesk_dbQuery( "SELECT `id`, `status`, `staffreplies`, `lastreplier` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` WHERE `trackid`='".hesk_dbEscape($trackingID)."' LIMIT 1") ); +if (!mfh_can_customer_change_status($ticket['status'])) { hesk_process_messages($hesklang['scno'],'ticket.php'); } @@ -121,7 +118,10 @@ if ($oldStatus == 2) { // Modify values in the database -hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status`='{$status}', `locked`='{$locked}' $closedby_sql , `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `trackid`='" . hesk_dbEscape($trackingID) . "' AND `locked` != '1'"); +hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `status`='{$status}', `locked`='{$locked}' $closedby_sql WHERE `trackid`='" . hesk_dbEscape($trackingID) . "' AND `locked` != '1'"); + +// Insert audit trail record +mfh_insert_audit_trail_record($ticket['id'], 'TICKET', $revision_key, hesk_date(), array(0 => $hesklang['customer'])); // Did we modify anything* if (hesk_dbAffectedRows() != 1) { diff --git a/inc/common.inc.php b/inc/common.inc.php index 94f487dc..28e63339 100644 --- a/inc/common.inc.php +++ b/inc/common.inc.php @@ -2155,4 +2155,35 @@ function mfh_get_hidden_fields_for_language($keys) { $output .= ''; return $output; -} \ No newline at end of file +} + +/** + * Date will always be the current date/time + */ +function mfh_insert_audit_trail_record($entity_id, $entity_type, $language_key, $date, $replacement_values) { + global $hesk_settings; + + hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail` (`entity_id`, `entity_type`, + `language_key`, `date`) VALUES (" . intval($entity_id) . ", '" . hesk_dbEscape($entity_type) . "', + '" . hesk_dbEscape($language_key) . "', '" . hesk_dbEscape($date) . "')"); + + $audit_id = hesk_dbInsertID(); + + foreach ($replacement_values as $replacement_index => $replacement_value) { + hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail_to_replacement_values` + (`audit_trail_id`, `replacement_index`, `replacement_value`) VALUES (" . intval($audit_id) . ", + " . intval($replacement_index) . ", '" . hesk_dbEscape($replacement_value) . "')"); + } + + return $audit_id; +} + +function mfh_can_customer_change_status($status) +{ + global $hesk_settings; + + $res = hesk_dbQuery("SELECT `Closable` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "statuses` WHERE `ID` = " . intval($status)); + $row = hesk_dbFetchAssoc($res); + + return $row['Closable'] == 'yes' || $row['Closable'] == 'conly'; +} // END hesk_get_ticket_status() \ No newline at end of file diff --git a/inc/posting_functions.inc.php b/inc/posting_functions.inc.php index a2cd5221..dfe6b5a6 100644 --- a/inc/posting_functions.inc.php +++ b/inc/posting_functions.inc.php @@ -115,7 +115,7 @@ function hesk_newTicket($ticket, $isVerified = true) " . hesk_dbEscape($ticket['screen_resolution_height']) . ", " . hesk_dbEscape($ticket['screen_resolution_width']) . ", {$due_date}, - '" . hesk_dbEscape($ticket['history']) . "' + '', {$custom_what} ) "); diff --git a/submit_ticket.php b/submit_ticket.php index 03c710e4..06090ef6 100644 --- a/submit_ticket.php +++ b/submit_ticket.php @@ -405,13 +405,11 @@ if ($hesk_settings['kb_enable'] && $hesk_settings['kb_recommendanswers'] && isse // All good now, continue with ticket creation $tmpvar['owner'] = 0; -$tmpvar['history'] = sprintf($hesklang['thist15'], hesk_date(), $tmpvar['name']); // Auto assign tickets if aplicable $autoassign_owner = hesk_autoAssignTicket($tmpvar['category']); if ($autoassign_owner) { $tmpvar['owner'] = $autoassign_owner['id']; - $tmpvar['history'] .= sprintf($hesklang['thist10'], hesk_date(), $autoassign_owner['name'] . ' (' . $autoassign_owner['user'] . ')'); } // Insert attachments @@ -463,6 +461,14 @@ if ($createTicket) { //-- email has been verified, and a ticket can be created $ticket = hesk_newTicket($tmpvar); + mfh_insert_audit_trail_record($ticket['id'], 'TICKET', 'audit_submitted_by', hesk_date(), + array(0 => $tmpvar['name'])); + + if ($autoassign_owner) { + mfh_insert_audit_trail_record($ticket['id'], 'TICKET', 'audit_autoassigned', hesk_date(), + array(0 => $autoassign_owner['name'] . ' (' . $autoassign_owner['user'] . ')')); + } + // Notify the customer if ($hesk_settings['notify_new'] && $email_available) { hesk_notifyCustomer($modsForHesk_settings);