From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- forum/utils/notify.php | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 forum/utils/notify.php (limited to 'forum/utils/notify.php') diff --git a/forum/utils/notify.php b/forum/utils/notify.php new file mode 100644 index 0000000..f52d167 --- /dev/null +++ b/forum/utils/notify.php @@ -0,0 +1,70 @@ +"; +$replyto = $sender; +$footer = " + +Stay Brutal! +// DIE +http://www.executionroom.com +info@executionroom.com +"; + +function send($email, $subject, $message) +{ + global $subject_prefix; + global $sender; + global $replyto; + global $footer; + + $message .= $footer; + // $message .= ""; + $headers = "From: " . $sender . "\r\n"; + $headers .= "Reply-To: " . $replyto . "\r\n"; + $headers .= "Content-Type: text/plain; charset=iso-8859-1\r\n"; + $headers .= "X-Mailer: PHP/" . phpversion(); + $subject = "[".$subject_prefix."] " . utf8_decode($subject); + + $ret = mail($email, $subject, utf8_decode($message), $headers); + if(!$ret) echo error("The mail to " . $email . "could not be sent."); +} + +function notify($module = "", $event = "") +{ + global $users; + global $current_user; + $users_changed = false; + + foreach($users->users as $user) { + if($user->uid == 0) continue; // Don't notify the admin + if($user->enabled == false) continue; // Do not mail disabled accounts. + + if($module == "calendar" || // Always mail calendar updates. + ( + $module == "forum" && + $user != $current_user && // Don't notify current user. + $user->notified < (time() - (60 * 60 * 24 * 7)) // Don't notify if already notified. + ) + ) { + send($user->email, $module . " changed", + "There has been a change in the " . $module . " module by " . + $current_user->name . ":\n" . $event); + + _log($user->username, "notified (" . $module . ")"); + + if($module != "calendar") { + $user->notified = time(); + $users_changed = true; + } + } + } + if($users_changed == true) $users->write(); +} +?> -- cgit v1.2.3