summaryrefslogtreecommitdiff
path: root/forum/utils/notify.php
diff options
context:
space:
mode:
Diffstat (limited to 'forum/utils/notify.php')
-rw-r--r--forum/utils/notify.php70
1 files changed, 70 insertions, 0 deletions
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 @@
+<?php
+
+include_once($UTIL_DIR . "/error.php");
+include_once($UTIL_DIR . "/log.php");
+
+/**
+ * CONFIG
+ */
+$subject_prefix = "DIE CMS notifier";
+$sender = "DIE <info@executionroom.com>";
+$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();
+}
+?>