require("../config.php");
if (isset($text)) { // form submitted
- if (!$user = get_records("users", "id", 1)) {
+ if (!$admin = get_admin() ) {
error("Could not find the admin user to mail to!");
}
- email_to_users($user, $USER, "Error: $referer -> $requested", "$text");
+ email_to_user($admin, $USER, "Error: $referer -> $requested", "$text");
redirect("$CFG->wwwroot/course/", "Message sent, thanks", 3);
die;
}
-function userdate($date, $format="l, j F Y, g:i A") {
+function userdate($date, $format="", $timezone=99) {
global $USER;
- if (abs($USER->timezone) > 12) {
+ if ($format == "") {
+ $format = "l, j F Y, g:i A";
+ }
+ if ($timezone == 99) {
+ $timezone = (float)$USER->timezone;
+ }
+ if (abs($timezone) > 12) {
return date("$format T", $date);
}
- return gmdate($format, $date + (int)($USER->timezone * 3600));
+ return gmdate($format, $date + (int)($timezone * 3600));
}
-function usergetdate($date) {
+function usergetdate($date, $timezone=99) {
global $USER;
- if (abs($USER->timezone) > 12) {
+ if ($timezone == 99) {
+ $timezone = (float)$USER->timezone;
+ }
+ if (abs($timezone) > 12) {
return getdate($date);
}
- return getdate($date + (int)($USER->timezone * 3600));
+ return getdate($date + (int)($timezone * 3600));
}
/// CORRESPONDENCE ////////////////////////////////////////////////
-function email_to_users(&$users, $from, $subject, $messagetext, $messagehtml="", $attachment="", $attachname="") {
-// users - an array of user records as returned by get_records_sql
+function email_to_user($user, $from, $subject, $messagetext, $messagehtml="", $attachment="", $attachname="") {
+// user - a user record as an object
+// from - a user record as an object
+// subject - plain text subject line of the email
// messagetext - plain text version of the message
// messagehtml - complete html version of the message (optional)
// attachment - a file on the filesystem, relative to $CFG->dataroot
include_once("$CFG->libdir/phpmailer/class.phpmailer.php");
- if (!$users) {
+ if (!$user) {
return false;
}
$mail->FromName = "$from->firstname $from->lastname";
$mail->Subject = stripslashes($subject);
- foreach ($users as $user) {
- $mail->AddAddress("$user->email","$user->firstname $user->lastname");
- }
+ $mail->AddBCC("$user->email","$user->firstname $user->lastname");
$mail->WordWrap = 70; // set word wrap