Commit 1c704583 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Combine email, notify sequence


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 09ec2a3f
......@@ -1296,6 +1296,24 @@ function auth_clean_partial_registrations() {
WHERE expiry < ?', array(db_format_timestamp(time())));
}
function _email_or_notify($user, $subject, $bodytext, $bodyhtml) {
try {
email_user($user, null, $subject, $bodytext, $bodyhtml);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for this user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = $subject;
$message->message = $bodytext;
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
}
/**
* Sends notification e-mails to users in two situations:
*
......@@ -1326,25 +1344,10 @@ function auth_handle_account_expiries() {
AND expirymailsent = 0', array(time() + $warn))) {
foreach ($users as $user) {
$displayname = display_name($user);
try {
email_user($user, null,
get_string('accountexpirywarning'),
get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for this
// user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = get_string('accountexpirywarning');
$message->message = get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename);
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
_email_or_notify($user, get_string('accountexpirywarning'),
get_string('accountexpirywarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('accountexpirywarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
set_field('usr', 'expirymailsent', 1, 'id', $user->id);
}
}
......@@ -1368,24 +1371,10 @@ function auth_handle_account_expiries() {
AND inactivemailsent = 0', array(time()))) {
foreach ($users as $user) {
$displayname = display_name($user);
try {
email_user($user, null, get_string('accountinactivewarning'),
get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename),
get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename)
);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for this
// user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename);
$message->message = get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename);
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
_email_or_notify($user, get_string('accountinactivewarning'),
get_string('accountinactivewarningtext', 'mahara', $displayname, $sitename, $daystoexpire, $sitename),
get_string('accountinactivewarninghtml', 'mahara', $displayname, $sitename, $daystoexpire, $sitename)
);
set_field('usr', 'inactivemailsent', 1, 'id', $user->id);
}
}
......@@ -1417,28 +1406,12 @@ function auth_handle_account_expiries() {
AND ui.expirymailsent = 0', array(time() + $warn))) {
foreach ($users as $user) {
$displayname = display_name($user);
try {
email_user($user, null,
get_string('institutionmembershipexpirywarning'),
get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname,
$sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname,
$sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for this
// user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = get_string('institutionmembershipexpirywarning');
$message->message = get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname,
$sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename);
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
_email_or_notify($user, get_string('institutionmembershipexpirywarning'),
get_string('institutionmembershipexpirywarningtext', 'mahara', $displayname, $user->institutionname,
$sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('institutionmembershipexpirywarninghtml', 'mahara', $displayname, $user->institutionname,
$sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
set_field('usr_institution', 'expirymailsent', 1, 'usr', $user->id,
'institution', $user->institution);
}
......@@ -1479,25 +1452,10 @@ function auth_handle_institution_expiries() {
// Email site administrators
foreach ($siteadmins as $user) {
$user_displayname = display_name($user);
try {
email_user($user, null,
get_string('institutionexpirywarning'),
get_string('institutionexpirywarningtext_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename),
get_string('institutionexpirywarninghtml_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename)
);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for
// this user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = get_string('institutionexpirywarning');
$message->message = get_string('institutionexpirywarningtext_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename);
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
_email_or_notify($user, get_string('institutionexpirywarning'),
get_string('institutionexpirywarningtext_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename),
get_string('institutionexpirywarninghtml_site', 'mahara', $user_displayname, $institution_displayname, $daystoexpire, $sitename, $sitename)
);
}
// Email institutional administrators
......@@ -1507,25 +1465,10 @@ function auth_handle_institution_expiries() {
);
foreach ($institutionaladmins as $user) {
$user_displayname = display_name($user);
try {
email_user($user, null,
get_string('institutionexpirywarning'),
get_string('institutionexpirywarningtext_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('institutionexpirywarninghtml_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
}
catch (EmailDisabledException $e) {
// Send a notification instead - email is disabled for
// this user
$message = new StdClass;
$message->users = array($user->id);
$message->subject = get_string('institutionexpirywarning');
$message->message = get_string('institutionexpirywarningtext_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename);
require_once('activity.php');
activity_occurred('maharamessage', $message);
}
_email_or_notify($user, get_string('institutionexpirywarning'),
get_string('institutionexpirywarningtext_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename),
get_string('institutionexpirywarninghtml_institution', 'mahara', $user_displayname, $institution_displayname, $sitename, $daystoexpire, $wwwroot . 'contact.php', $sitename)
);
}
set_field('institution', 'expirymailsent', 1, 'name', $institution->name);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment