diff --git a/inc/admin_functions.inc.php b/inc/admin_functions.inc.php index 2420f648..cadb5a88 100644 --- a/inc/admin_functions.inc.php +++ b/inc/admin_functions.inc.php @@ -422,14 +422,17 @@ function hesk_autoLogin($noredirect = 0) hesk_setcookie('hesk_p', "$hash", strtotime('+1 year')); /* Close any old tickets here so Cron jobs aren't necessary */ - if ($hesk_settings['autoclose']) { - $revision = sprintf($hesklang['thist3'], hesk_date(), $hesklang['auto']); + $closedStatusRs = hesk_dbQuery('SELECT `ID`, `Closable` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'statuses` WHERE `IsDefaultStaffReplyStatus` = 1'); + $closedStatus = hesk_dbFetchAssoc($closedStatusRs); + // Are we allowed to close tickets in this status? + if (($closedStatus['Closable'] == 'yes' || $closedStatus['Closable'] == 'sonly') && $hesk_settings['autoclose']) { $dt = date('Y-m-d H:i:s', time() - $hesk_settings['autoclose'] * 86400); // Notify customer of closed ticket? if ($hesk_settings['notify_closed']) { // Get list of tickets - $result = hesk_dbQuery("SELECT * FROM `" . $hesk_settings['db_pfix'] . "tickets` WHERE `status` = '2' AND `lastchange` <= '" . hesk_dbEscape($dt) . "' "); + $result = hesk_dbQuery("SELECT * FROM `" . $hesk_settings['db_pfix'] . "tickets` WHERE `status` = " . $closedStatus['ID'] . " AND `lastchange` <= '" . hesk_dbEscape($dt) . "' "); + if (hesk_dbNumRows($result) > 0) { global $ticket; @@ -442,6 +445,7 @@ function hesk_autoLogin($noredirect = 0) $ticket['dt'] = hesk_date($ticket['dt'], true); $ticket['lastchange'] = hesk_date($ticket['lastchange'], true); $ticket = hesk_ticketToPlain($ticket, 1, 0); + mfh_insert_audit_trail_record($ticket['id'], 'TICKET', 'audit_automatically_closed', hesk_date()); $modsForHesk_settings = mfh_getSettings(); hesk_notifyCustomer($modsForHesk_settings, 'ticket_closed'); } @@ -449,7 +453,9 @@ function hesk_autoLogin($noredirect = 0) } // Update ticket statuses and history in database - hesk_dbQuery("UPDATE `" . $hesk_settings['db_pfix'] . "tickets` SET `status`='3', `closedat`=NOW(), `closedby`='-1', `history`=CONCAT(`history`,'" . hesk_dbEscape($revision) . "') WHERE `status` = '2' AND `lastchange` <= '" . hesk_dbEscape($dt) . "' "); + $defaultCloseRs = hesk_dbQuery('SELECT `ID` FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'statuses` WHERE `IsAutocloseOption` = 1'); + $defaultCloseStatus = hesk_dbFetchAssoc($defaultCloseRs); + hesk_dbQuery("UPDATE `" . $hesk_settings['db_pfix'] . "tickets` SET `status`= " . $defaultCloseStatus['ID'] . ", `closedat`=NOW(), `closedby`='-1' WHERE `status` = " . $closedStatus['ID'] . " AND `lastchange` <= '" . hesk_dbEscape($dt) . "' "); } /* If session expired while a HESK page is open just continue using it, don't redirect */ diff --git a/inc/common.inc.php b/inc/common.inc.php index 28e63339..be8f07eb 100644 --- a/inc/common.inc.php +++ b/inc/common.inc.php @@ -2157,10 +2157,7 @@ function mfh_get_hidden_fields_for_language($keys) { return $output; } -/** - * Date will always be the current date/time - */ -function mfh_insert_audit_trail_record($entity_id, $entity_type, $language_key, $date, $replacement_values) { +function mfh_insert_audit_trail_record($entity_id, $entity_type, $language_key, $date, $replacement_values = array()) { global $hesk_settings; hesk_dbQuery("INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "audit_trail` (`entity_id`, `entity_type`, diff --git a/inc/pipe_functions.inc.php b/inc/pipe_functions.inc.php index 4b92df4a..7a98f02d 100755 --- a/inc/pipe_functions.inc.php +++ b/inc/pipe_functions.inc.php @@ -269,7 +269,6 @@ function hesk_email2ticket($results, $pop3 = 0, $set_category = 1, $set_priority // Auto assign tickets if aplicable $tmpvar['owner'] = 0; - $tmpvar['history'] = $pop3 ? sprintf($hesklang['thist16'], hesk_date()) : sprintf($hesklang['thist11'], hesk_date()); $tmpvar['openedby'] = $pop3 ? -2 : -1; $autoassign_owner = hesk_autoAssignTicket($tmpvar['category']); @@ -278,7 +277,6 @@ function hesk_email2ticket($results, $pop3 = 0, $set_category = 1, $set_priority if ($autoassign_owner) { $tmpvar['owner'] = $autoassign_owner['id']; - $tmpvar['history'] .= sprintf($hesklang['thist10'], hesk_date(), $autoassign_owner['name'] . ' (' . $autoassign_owner['user'] . ')'); } // Custom fields will be empty as there is no reliable way of detecting them @@ -297,6 +295,13 @@ function hesk_email2ticket($results, $pop3 = 0, $set_category = 1, $set_priority // Insert ticket to database $ticket = hesk_newTicket($tmpvar); + mfh_insert_audit_trail_record($ticket['id'], 'TICKET', ($pop3 ? 'audit_submitted_via_pop' : 'audit_submitted_via_piping'), hesk_date()); + + 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']) { $possible_SPAM = false; diff --git a/language/en/text.php b/language/en/text.php index 353988ab..a5dc2321 100644 --- a/language/en/text.php +++ b/language/en/text.php @@ -2204,12 +2204,12 @@ $hesklang['audit_created']='%s created ticket'; $hesklang['audit_priority']='%s changed priority to %s'; // %s = date,new priority, user making change, thist8 $hesklang['audit_status']='%s changed status to %s'; // %s = date, new status, user making change, thist9 $hesklang['audit_autoassigned']='%s automatically assigned to ticket'; //thist10 -$hesklang['audit_submitted_via_piping']='Ticket submitted via e-mail piping'; +$hesklang['audit_submitted_via_piping']='Ticket submitted via e-mail piping'; // thist11 $hesklang['audit_attachment_deleted']='%s deleted attachment %s'; // %s = date, deleted attachment, user making change $hesklang['audit_merged']='%s merged ticket %s with this ticket'; // %s = date, merged ticket ID, user making change, thist13 $hesklang['audit_time_worked']='%s updated time worked to %s'; // %s = date, new time worked, user making change $hesklang['audit_submitted_by']='%s submitted ticket'; -$hesklang['audit_submitted_via_pop']='Ticket submitted via POP3 fetching'; +$hesklang['audit_submitted_via_pop']='Ticket submitted via POP3 fetching'; // thist16 // DO NOT CHANGE BELOW if (!defined('IN_SCRIPT')) die('PHP syntax OK!');