Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiding up conflicting logic on email alerts (Issue #943) #1249

Merged
merged 3 commits into from Jan 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 5 additions & 7 deletions application/controllers/scheduler/s_alerts.php
Expand Up @@ -86,19 +86,17 @@ public function index()
l.latitude, l.longitude FROM ".$this->table_prefix."incident AS i INNER JOIN ".$this->table_prefix."location AS l ON i.location_id = l.id
WHERE i.incident_active=1 AND i.incident_alert_status = 1 ");
// End of New Code

foreach ($incidents as $incident)
{
// ** Pre-Formatting Message ** //
// Convert HTML to Text
$incident_description = $incident->incident_description;
$incident_url = url::site().'reports/view/'.$incident->id;
$incident_description = html::clean($incident_description);
$html2text = new Html2Text($incident_description);
$incident_description = $html2text->get_text();

// EMAIL MESSAGE
$email_message = $incident_description."\n\n".$incident_url;
$email_message = $incident_description . "\n\n" . $incident_url;

// SMS MESSAGE
$sms_message = $incident_description;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update this to make sure we still remove HTML from the SMS message :)

Expand Down Expand Up @@ -179,9 +177,9 @@ public function index()
$from[] = $alerts_email;
$from[] = $site_name;
$subject = "[$site_name] ".$incident->incident_title;
$message = $email_message
."\n\n".$unsubscribe_message
.$alertee->alert_code."\n";
$message = text::auto_p($email_message
. "\n\n".$unsubscribe_message
. $alertee->alert_code . "\n");

//if (email::send($to, $from, $subject, $message, FALSE) == 1)
if (email::send($to, $from, $subject, $message, TRUE) == 1) // HT: New Code
Expand Down
12 changes: 9 additions & 3 deletions system/helpers/email.php
Expand Up @@ -113,16 +113,22 @@ public static function connect($config = NULL)
* @param boolean send email as HTML
* @return integer number of emails sent
*/
public static function send($to, $from, $subject, $message, $html = FALSE)
public static function send($to, $from, $subject, $content, $html = FALSE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should be able to override/extend this function by adding a file application/helpers/MY_email.php. If we do it that way its easier to see whats been customised or not.

{
// Connect to SwiftMailer
(email::$mail === NULL) and email::connect();

// Determine the message type
$html = ($html === TRUE) ? 'text/html' : 'text/plain';
$header_type = ($html === TRUE) ? 'text/html' : 'text/plain';

// Create the message
$message = new Swift_Message($subject, $message, $html, '8bit', 'utf-8');
$message = new Swift_Message($subject, $content, $header_type, '8bit', 'utf-8');

if ($html === TRUE)
{
$html2text = new Html2Text($content);
$message->attach(new Swift_Message_Part($html2text->get_text(), 'text/plain'));
}

if (is_string($to))
{
Expand Down