Browse Source

Basic overdue ticket alerts working

merge-requests/1/head
Mike Koch 6 years ago
parent
commit
263a5804c8
  1. 93
      cron/calendar_reminders.php
  2. 36
      inc/email_functions.inc.php
  3. 1
      install/mods-for-hesk/sql/installSql.php
  4. 9
      language/en/emails/html/overdue_ticket.txt
  5. 17
      language/en/emails/overdue_ticket.txt
  6. 2
      language/en/text.php

93
cron/calendar_reminders.php

@ -3,6 +3,7 @@
define('IN_SCRIPT',1);
define('HESK_PATH', dirname(dirname(__FILE__)) . '/');
$LOCATION = 'Calendar Reminders Cron Job';
#echo HESK_PATH."\n";
@ -10,6 +11,11 @@ define('HESK_PATH', dirname(dirname(__FILE__)) . '/');
require(HESK_PATH . 'hesk_settings.inc.php');
require(HESK_PATH . 'inc/common.inc.php');
if (defined('HESK_DEMO')) {
echo '>>>>>>> DEMO MODE IS ENABLED. CRON JOBS CANNOT BE EXECUTED WHILE IN DEMO MODE! <<<<<<<';
die();
}
if (hesk_check_maintenance(false)) {
// If Debug mode is ON show "Maintenance mode" message
$message = $hesk_settings['debug_mode'] ? $hesklang['mm1'] : '';
@ -42,7 +48,7 @@ $sql = "SELECT `reminder`.`id` AS `reminder_id`, `reminder`.`user_id` AS `user_i
`event`.`name` AS `event_name`, `event`.`location` AS `event_location`, `event`.`comments` AS `event_comments`,
`category`.`name` AS `event_category`, `event`.`start` AS `event_start`, `event`.`end` AS `event_end`,
`event`.`all_day` AS `event_all_day`, `user`.`language` AS `user_language`, `user`.`email` AS `user_email`,
" . $case_statement . " AS `reminder_date`
" . $case_statement . " AS `reminder_date`, 'EVENT' AS `type`
FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` AS `reminder`
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` AS `event`
ON `reminder`.`event_id` = `event`.`id`
@ -54,28 +60,34 @@ $sql = "SELECT `reminder`.`id` AS `reminder_id`, `reminder`.`user_id` AS `user_i
AND `email_sent` = '0'";
$rs = hesk_dbQuery($sql);
$modsForHesk_settings = NULL;
$modsForHesk_settings = mfh_getSettings();
$reminders_to_flag = [];
$tickets_to_flag = [];
$included_email_functions = false;
if (hesk_dbNumRows($rs) > 0) {
require(HESK_PATH . 'inc/email_functions.inc.php');
$modsForHesk_settings = mfh_getSettings();
$included_email_functions = true;
}
$successful_emails = 0;
$failed_emails = 0;
while ($row = hesk_dbFetchAssoc($rs)) {
$successful_emails++;
if (mfh_sendCalendarReminder($row, $modsForHesk_settings)) {
$reminders_to_flag[] = $row['reminder_id'];
$successful_emails++;
if ($hesk_settings['debug_mode']) {
echo "Sent e-mail reminder for event: {$row['event_name']} to {$row['user_email']}\n";
$debug_msg = "Sent e-mail reminder for event: {$row['event_name']} to {$row['user_email']}\n";
echo $debug_msg;
mfh_log_debug($LOCATION, $debug_msg, 'CRON');
}
} else {
$failed_emails++;
echo "Failed to send reminder email for event: {$row['event_name']} to {$row['user_email']}. This will be re-sent next time reminders are processed.\n";
$warning_text = "Failed to send reminder e-mail for event: {$row['event_name']} to {$row['user_email']}. This will be re-sent next time reminders are processed.\n";
mfh_log_warning($LOCATION, $warning_text, 'CRON');
echo $warning_text;
}
}
@ -88,5 +100,72 @@ if (count($reminders_to_flag) > 0) {
if ($hesk_settings['debug_mode']) {
echo "Finished Calendar Reminders. {$successful_emails} reminder e-mails sent. {$failed_emails} emails failed to send.\n";
$debug_msg = "Finished Calendar Reminders. {$successful_emails} reminder e-mails sent. {$failed_emails} emails failed to send.\n";
echo $debug_msg;
mfh_log_debug($LOCATION, $debug_msg, 'CRON');
}
// Overdue tickets
if ($hesk_settings['debug_mode']) {
echo "Starting Overdue Tickets...\n";
}
$sql = "SELECT `ticket`.`id` AS `id`, `ticket`.`trackid` AS `trackid`, `ticket`.`name` AS `name`, `ticket`.`subject` AS `subject`,
`ticket`.`message` AS `message`, `ticket`.`category` AS `category`, `ticket`.`priority` AS `priority`,
`ticket`.`owner` AS `owner`, `ticket`.`status` AS `status`, `ticket`.`email` AS `email`, `ticket`.`dt` AS `dt`,
`ticket`.`lastchange` AS `lastchange`, `ticket`.`due_date` AS `due_date`, `user`.`language` AS `user_language`, `user`.`email` AS `user_email`,
`ticket`.`custom1` AS `custom1`, `ticket`.`custom2` AS `custom2`, `ticket`.`custom3` AS `custom3`, `ticket`.`custom4` AS `custom4`,
`ticket`.`custom5` AS `custom5`, `ticket`.`custom6` AS `custom6`, `ticket`.`custom7` AS `custom7`, `ticket`.`custom8` AS `custom8`,
`ticket`.`custom9` AS `custom9`, `ticket`.`custom10` AS `custom10`, `ticket`.`custom11` AS `custom11`, `ticket`.`custom12` AS `custom12`,
`ticket`.`custom13` AS `custom13`, `ticket`.`custom14` AS `custom14`, `ticket`.`custom15` AS `custom15`, `ticket`.`custom16` AS `custom16`,
`ticket`.`custom17` AS `custom17`, `ticket`.`custom18` AS `custom19`, `ticket`.`custom19` AS `custom19`, `ticket`.`custom20` AS `custom20`,
`ticket`.`html` AS `html`
FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` AS `ticket`
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` AS `user`
ON `ticket`.`owner` = `user`.`id`
WHERE `due_date` IS NOT NULL
AND `due_date` <= NOW()
AND `overdue_email_sent` = '0'";
//AND `owner` <> 0";
$successful_emails = 0;
$failed_emails = 0;
$rs = hesk_dbQuery($sql);
if (hesk_dbNumRows($rs) > 0 && !$included_email_functions) {
require(HESK_PATH . 'inc/email_functions.inc.php');
$included_email_functions = true;
}
$tickets_to_flag = [];
while ($row = hesk_dbFetchAssoc($rs)) {
if (mfh_sendOverdueTicketReminder($row, $modsForHesk_settings)) {
$tickets_to_flag[] = $row['id'];
$successful_emails++;
if ($hesk_settings['debug_mode']) {
$debug_msg = "Sent overdue e-mail for ticket: {$row['trackid']} to user id: {$row['owner']}\n";
mfh_log_debug($LOCATION, $debug_msg, 'CRON');
echo $debug_msg;
}
} else {
$failed_emails++;
$warning_text = "Failed to send overdue reminder for ticket: {$row['trackid']} to user id: {$row['owner']}. This will be re-sent next time overdue tickets are processed.\n";\
mfh_log_warning($LOCATION, $warning_text, 'CRON');
echo $warning_text;
}
}
if (count($tickets_to_flag) > 0) {
foreach ($tickets_to_flag as $ticket_id) {
$sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `overdue_email_sent` = '1' WHERE `id` = " . intval($ticket_id);
hesk_dbQuery($sql);
}
}
if ($hesk_settings['debug_mode']) {
$debug_msg = "Finished Overdue Tickets. {$successful_emails} e-mails sent. {$failed_emails} emails failed to send.\n";
echo $debug_msg;
mfh_log_debug($LOCATION, $debug_msg, 'CRON');
}

36
inc/email_functions.inc.php

@ -313,6 +313,37 @@ function mfh_processCalendarTemplate($message, $reminder_data) {
}
function mfh_sendOverdueTicketReminder($ticket, $modsForHesk_settings) {
global $hesk_settings, $hesklang;
if (defined('HESK_DEMO')) {
return true;
}
hesk_setLanguage($ticket['user_language']);
$valid_emails = hesk_validEmails();
$subject = NULL;
if (!isset($valid_emails['overdue_ticket'])) {
hesk_error($hesklang['inve']);
} else {
$subject = $valid_emails['overdue_ticket'];
}
// Format email subject and message
$subject = str_replace('%%TITLE%%', $ticket['subject'], $subject);
$subject = str_replace('%%TRACKID%%', $ticket['trackid'], $subject);
$message = hesk_getEmailMessage('overdue_ticket', NULL, $modsForHesk_settings, 1, 0, 1);
$message = hesk_processMessage($message, $ticket, 1, 1, 0, $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);
return true;
}
function hesk_validEmails()
{
global $hesklang;
@ -361,7 +392,10 @@ function hesk_validEmails()
'reset_password' => $hesklang['reset_password'],
// --> Calendar reminder
'calendar_reminder' => "Calendar Reminder",
'calendar_reminder' => $hesklang['calendar_reminder'],
// --> Overdue Ticket reminder
'overdue_ticket' => $hesklang['overdue_ticket'],
);
} // END hesk_validEmails()

1
install/mods-for-hesk/sql/installSql.php

@ -737,6 +737,7 @@ function execute260Scripts()
`unit` INT NOT NULL,
`email_sent` ENUM('0', '1') NOT NULL DEFAULT '0') ENGINE = MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `due_date` DATETIME");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` ADD COLUMN `overdue_email_sent` ENUM('0','1')");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` ADD COLUMN `color` VARCHAR(7)");
executeQuery("ALTER TABLE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` ADD COLUMN `usage` INT NOT NULL DEFAULT 0");
executeQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "settings` SET `Value` = '2.6.0' WHERE `Key` = 'modsForHeskVersion'");

9
language/en/emails/html/overdue_ticket.txt

@ -0,0 +1,9 @@
<p>Hello,</p>
<p>A ticket is overdue! Ticket details:</p>
<p>Ticket subject: %%SUBJECT%%</p>
<p>Tracking ID: %%TRACK_ID%%</p>
<p>You can manage this ticket here:
%%TRACK_URL%%</p>
<p>Regards,</p>
%%SITE_TITLE%% <br>
%%SITE_URL%%

17
language/en/emails/overdue_ticket.txt

@ -0,0 +1,17 @@
Hello,
A ticket is overdue! Ticket details:
Ticket subject: %%SUBJECT%%
Tracking ID: %%TRACK_ID%%
You can manage this ticket here:
%%TRACK_URL%%
Regards,
%%SITE_TITLE%%
%%SITE_URL%%
%%MESSAGE%%

2
language/en/text.php

@ -82,6 +82,8 @@ $hesklang['error_updating_event'] = 'An error occurred when trying to update the
$hesklang['calendar_title_case'] = 'Calendar';
$hesklang['calendar_categories'] = 'Categories';
$hesklang['can_man_calendar'] = 'Can manage calendar events';
$hesklang['calendar_reminder'] = 'Upcoming Event: %%TITLE%%';
$hesklang['overdue_ticket'] = '[%%TRACKID%%] Ticket Overdue!';
// ADDED OR MODIFIED IN Mods for HESK 2.5.2
$hesklang['manage_statuses'] = 'Manage Statuses';

Loading…
Cancel
Save