Browse Source

Getting started on the email stuff

merge-requests/1/head
Mike Koch 6 years ago
parent
commit
033dd8e4fb
  1. 11
      cron/calendar_reminders.php
  2. 49
      inc/email_functions.inc.php

11
cron/calendar_reminders.php

@ -42,11 +42,18 @@ $case_statement = "CASE
WHEN `unit` = '2' THEN DATE_SUB(`event`.`start`, INTERVAL `reminder`.`amount` DAY)
WHEN `unit` = '3' THEN DATE_SUB(`event`.`start`, INTERVAL `reminder`.`amount` WEEK)
END";
$sql = "SELECT `reminder`.`id`, `reminder`.`user_id`, `reminder`.`event_id`,
$sql = "SELECT `reminder`.`id` AS `reminder_id`, `reminder`.`user_id` AS `user_id`, `reminder`.`event_id` AS `event_id`,
`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`
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`
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` AS `category`
ON `event`.`category` = `category`.`id`
INNER JOIN `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` AS `user`
ON `reminder`.`user_id` = `user`.`id`
WHERE (" . $case_statement . ") <= NOW()
AND `email_sent` = '0'";
@ -54,7 +61,9 @@ $rs = hesk_dbQuery($sql);
$i = 0;
while ($row = hesk_dbFetchAssoc($rs)) {
$i++;
echo "Sent e-mail reminder for event: {$row['event_name']}\n";
}

49
inc/email_functions.inc.php

@ -255,6 +255,52 @@ function hesk_notifyStaff($email_template, $sql_where, $modsForHesk_settings, $i
} // END hesk_notifyStaff()
function mfh_sendCalendarReminder($reminder_data, $modsForHesk_settings) {
global $hesk_settings, $hesklang;
if (defined('HESK_DEMO')) {
return true;
}
hesk_setLanguage($reminder_data['user_language']);
$valid_emails = hesk_validEmails();
$subject = NULL;
if (!isset($valid_emails['calendar_reminder'])) {
hesk_error($hesklang['inve']);
} else {
$subject = $valid_emails['calendar_reminder'];
}
// Format email subject and message
$subject = str_replace('%%TITLE%%', $reminder_data['event_name'], $subject);
$message = hesk_getEmailMessage('calendar_reminder', NULL, $modsForHesk_settings, 1, 0, 1);
$htmlMessage = hesk_getHtmlMessage('calendar_reminder', NULL, $modsForHesk_settings, 1, 0, 1);
if ($reminder_data['event_all_day'] == '1') {
$format = 'Y-m-d';
} else {
$format = $hesk_settings['timeformat'];
}
$start_date = strtotime($event['event_start']);
$formatted_start_date = date($format, $start_date);
$formatted_end_date = '';
if ($reminder_data['event_start'] != $reminder_data['event_end']) {
$end_date = strtotime($event['event_end']);
$formatted_end_date = ' - ' . date($format, $end_date);
}
// Process replaced fields
$message = str_replace('%%TITLE%%', $reminder_data['event_name'], $message);
$message = str_replace('%%LOCATION%%', $reminder_data['event_location'], $message);
$message = str_replace('%%CATEGORY%%', $reminder_data['category_name'], $message);
$message = str_replace('%%WHEN%%', $formatted_start_date . $formatted_end_date, $message);
$message = str_replace('%%COMMENTS%%', $reminder_data['event_comments'], $message);
}
function hesk_validEmails()
{
@ -303,6 +349,9 @@ function hesk_validEmails()
// --> Staff password reset email
'reset_password' => $hesklang['reset_password'],
// --> Calendar reminder
'calendar_reminder' => "Calendar Reminder",
);
} // END hesk_validEmails()

Loading…
Cancel
Save