* ??? @todo Please document this. * * @author Organisation: Queen's University * @author Unit: School of Medicine * @author Developer: James Ellis <*****@*****.**> * @copyright Copyright 2010 Queen's University. All Rights Reserved. * */ @set_include_path(implode(PATH_SEPARATOR, array(dirname(__FILE__) . "/../core", dirname(__FILE__) . "/../core/includes", dirname(__FILE__) . "/../core/library", get_include_path()))); /** * Include the Entrada init code. */ require_once "init.inc.php"; if (isset($_GET["nuser_id"]) && ($nuser_id = clean_input($_GET["nuser_id"], array("int")))) { require_once "Models/notifications/NotificationUser.class.php"; $notification_user = NotificationUser::getByID($nuser_id); if ($notification_user->getProxyID() == $ENTRADA_USER->getID()) { if (isset($_GET["action"]) && $_GET["action"] == "view") { echo "<span style=\"cursor: pointer;\" onclick=\"promptNotifications(" . ($notification_user->getNotifyActive() ? "'1'" : "'0'") . ", " . $nuser_id . ", '" . $notification_user->getContentTypeName() . "')\"><img src=\"" . ENTRADA_URL . "/images/btn-" . ($notification_user->getNotifyActive() ? "approve.gif\" alt=\"Active\" />" : "unapprove.gif\" alt=\"Disabled\" />") . "</span>"; } elseif (isset($_GET["action"]) && $_GET["action"] == "edit") { if (isset($_GET["active"]) && $_GET["active"]) { $notify_active = 1; } else { $notify_active = 0; } if ($notification_user->setNotifyActive($notify_active)) { echo ($notify_active == 1 ? "Activation" : "Deactivation") . " of notifications for this " . $notification_user->getContentTypeName() . " successful."; } else { echo "There was an issue while trying to " . ($notify_active ? "activate" : "deactivate") . " notifications for this " . $notification_user->getContentTypeName() . "."; } } elseif (isset($_GET["action"]) && $_GET["action"] == "view-digest") {
/** * Creates a new notification and returns its id. * * @param int $nuser_id * @return Notification */ public static function addDigest($nuser_id) { global $db, $ENTRADA_TEMPLATE; require_once "Models/utility/Template.class.php"; $notification_user = NotificationUser::getByID($nuser_id); if ($notification_user) { $notifications = self::getAllPending($nuser_id, 1); $activity_count = count($notifications); if ($notifications && $activity_count) { $notification_template = file_get_contents($ENTRADA_TEMPLATE->absolute() . "/email/notification-default-digest.xml"); $search = array("%UC_CONTENT_TYPE_NAME%", "%CONTENT_TYPE_NAME%", "%COMMENTS_NUMBER_STRING%", "%CONTENT_TITLE%", "%URL%", "%UNSUBSCRIBE_URL%", "%APPLICATION_NAME%", "%ENTRADA_URL%"); $replace = array(html_encode(ucwords($notification_user->getContentTypeName())), html_encode($notification_user->getContentTypeName()), html_encode($activity_count > 1 ? $activity_count . " new comments have" : "A new comment has"), html_encode($notification_user->getContentTitle()), html_encode($notification_user->getContentURL()), html_encode(ENTRADA_URL . "/profile?section=notifications&id=" . $nuser_id . "&action=unsubscribe"), html_encode(APPLICATION_NAME), html_encode(ENTRADA_URL)); $notification_body = str_replace($search, $replace, $notification_template); $new_notification = array("nuser_id" => $nuser_id, "notification_body" => $notification_body, "proxy_id" => 0, "sent" => false, "sent_date" => 0, "digest" => 1); $db->AutoExecute("notifications", $new_notification, "INSERT"); if (!($notification_id = $db->Insert_Id())) { application_log("error", "There was an issue attempting to add a notification record to the database. Database said: " . $db->ErrorMsg()); } else { $new_notification["notification_id"] = $notification_id; foreach ($notifications as $processed_notification) { $processed_notification->setSentStatus(true); } $notification = self::fromArray($new_notification); $notification_user->setNextNotificationDate(); return $notification; } } } return false; }