From a47068c83bbe64c51a24dfa9c77355b3435d35a1 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sat, 23 Apr 2016 22:07:51 -0400 Subject: [PATCH] Add support for emails for users who want emails sent for overdue tickets not assigned to them --- admin/profile.php | 4 +++- cron/calendar_reminders.php | 13 +++++++++++-- inc/email_functions.inc.php | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/admin/profile.php b/admin/profile.php index 1928c66f..d5bb469e 100644 --- a/admin/profile.php +++ b/admin/profile.php @@ -234,7 +234,8 @@ function update_profile() $_SESSION['new']['autorefresh'] = isset($_POST['autorefresh']) ? $_POST['autorefresh'] : 0; /* Notifications */ - if ($_SESSION[$session_array]['isadmin'] || (isset($_SESSION[$session_array]['heskprivileges']) && strpos($_SESSION[$session_array]['heskprivileges'], 'can_change_notification_settings') !== false)) { + if (!(!$_SESSION[$session_array]['isadmin'] && isset($_SESSION[$session_array]['heskprivileges']) + && strpos($_SESSION[$session_array]['heskprivileges'], 'can_change_notification_settings') === false)) { $_SESSION['new']['notify_new_unassigned'] = empty($_POST['notify_new_unassigned']) || !$can_view_unassigned ? 0 : 1; $_SESSION['new']['notify_new_my'] = empty($_POST['notify_new_my']) ? 0 : 1; $_SESSION['new']['notify_reply_unassigned'] = empty($_POST['notify_reply_unassigned']) || !$can_view_unassigned ? 0 : 1; @@ -275,6 +276,7 @@ function update_profile() `notify_note_unassigned`='" . intval($_SESSION['new']['notify_note_unassigned']) . "', `notify_customer_new`='" . $_SESSION['new']['notify_customer_new'] . "', `notify_customer_reply`='" . $_SESSION['new']['notify_customer_reply'] . "', + `notify_overdue_unassigned`='" . $_SESSION['new']['notify_overdue_unassigned'] . "', `show_suggested`='" . $_SESSION['new']['show_suggested'] . "' WHERE `id`='" . intval($_SESSION['id']) . "' LIMIT 1" ); diff --git a/cron/calendar_reminders.php b/cron/calendar_reminders.php index cfe12b39..913eda1c 100644 --- a/cron/calendar_reminders.php +++ b/cron/calendar_reminders.php @@ -126,7 +126,6 @@ $sql = "SELECT `ticket`.`id` AS `id`, `ticket`.`trackid` AS `trackid`, `ticket`. WHERE `due_date` IS NOT NULL AND `due_date` <= NOW() AND `overdue_email_sent` = '0'"; - //AND `owner` <> 0"; $successful_emails = 0; $failed_emails = 0; @@ -137,9 +136,19 @@ if (hesk_dbNumRows($rs) > 0 && !$included_email_functions) { $included_email_functions = true; } +$user_rs = hesk_dbQuery("SELECT `id`, `isadmin`, `categories`, `email`, + CASE WHEN `heskprivileges` LIKE '%can_view_unassigned%' THEN 1 ELSE 0 END AS `can_view_unassigned` + FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `notify_overdue_unassigned` = '1' + AND (`heskprivileges` LIKE '%can_view_tickets%' OR `isadmin` = '1')"); + +$users = []; +while ($row = hesk_dbFetchAssoc($user_rs)) { + $users[] = $row; +} + $tickets_to_flag = []; while ($row = hesk_dbFetchAssoc($rs)) { - if (mfh_sendOverdueTicketReminder($row, $modsForHesk_settings)) { + if (mfh_sendOverdueTicketReminder($row, $users, $modsForHesk_settings)) { $tickets_to_flag[] = $row['id']; $successful_emails++; diff --git a/inc/email_functions.inc.php b/inc/email_functions.inc.php index d939beef..8e512e84 100644 --- a/inc/email_functions.inc.php +++ b/inc/email_functions.inc.php @@ -313,7 +313,7 @@ function mfh_processCalendarTemplate($message, $reminder_data) { } -function mfh_sendOverdueTicketReminder($ticket, $modsForHesk_settings) { +function mfh_sendOverdueTicketReminder($ticket, $users, $modsForHesk_settings) { global $hesk_settings, $hesklang; if (defined('HESK_DEMO')) { @@ -338,7 +338,18 @@ function mfh_sendOverdueTicketReminder($ticket, $modsForHesk_settings) { $htmlMessage = hesk_getHtmlMessage('overdue_ticket', NULL, $modsForHesk_settings, 1, 0, 1); $htmlMessage = hesk_processMessage($htmlMessage, $ticket, 1, 1, 0, $modsForHesk_settings, 1); - hesk_mail($ticket['user_email'], $subject, $message, $htmlMessage, $modsForHesk_settings); + $emails = []; + $emails[] = $ticket['user_email']; + foreach ($users as $user) { + if ($user['email'] != $ticket['user_email'] + && ($user['isadmin'] || strpos($user['categories'], $ticket['category']) !== false)) { + $emails[] = $user['email']; + } + } + + foreach ($emails as $email) { + hesk_mail($email, $subject, $message, $htmlMessage, $modsForHesk_settings); + } return true; }