* @author Unit: School of Medicine * @author Developer: Josh Dillon <*****@*****.**> * @copyright Copyright 2011 Queen's University. All Rights Reserved. * */ @set_time_limit(0); @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"; require_once "Models/utility/Template.class.php"; require_once "Models/utility/TemplateMailer.class.php"; $SEND_EMAIL_NOTIFICATIONS = false; $SET_INACTIVE_COMMUNITIES = false; $mail = new TemplateMailer(new Zend_Mail()); $query = " SELECT a.`community_id`, a.`community_title`, a.`community_url`, a.`community_active`, b.`history_timestamp`, c.`timestamp`\n\t\t\tFROM `communities` AS a\n\t\t\tLEFT JOIN `community_history` AS b\n\t\t\tON a.`community_id` = b.`community_id`\n\t\t\tAND b.`history_timestamp` >=" . $db->qstr(strtotime("-6 months +1 day 00:00:00")) . "\n\t\t\tLEFT JOIN `statistics` AS c\n\t\t\tON c.`module` LIKE CONCAT('community:', a.`community_id`, '%')\n\t\t\tAND c.`timestamp` >=" . $db->qstr(strtotime("-6 months +1 day 00:00:00")) . "\n\t\t\tWHERE a.`community_id` NOT IN (SELECT `community_id` FROM `community_courses`)\n\t\t\tAND a.`community_active` = '1'\n\t\t\tAND b.`history_timestamp` IS NULL\n\t\t\tAND c.`timestamp` IS NULL\n\t\t\tGROUP BY a.`community_id`"; $results = $db->GetAll($query); if ($results) { foreach ($results as $result) { $query = " SELECT a.`community_id`, MAX(a.`history_timestamp`) AS `history_timestamp`, MAX(b.`timestamp`) AS `timestamp`\n\t\t\t\t\tFROM `community_history` AS a\n\t\t\t\t\tLEFT JOIN statistics AS b\n\t\t\t\t\tON b.`module` LIKE CONCAT('community:', a.`community_id`, '%')\n\t\t\t\t\tWHERE a.`community_id` =" . $db->qstr($result["community_id"]) . "\n\t\t\t\t\tGROUP BY `community_id`"; $history_timestamps = $db->GetAll($query); if ($history_timestamps) { foreach ($history_timestamps as $history_timestamp) { //of the two timestamps returned check which is most recent if ($history_timestamp["history_timestamp"] > $history_timestamp["timestamp"]) { $timestamp = $history_timestamp["history_timestamp"]; } else { if ($history_timestamp["history_timestamp"] < $history_timestamp["timestamp"]) { $timestamp = $history_timestamp["timestamp"]; } else {
/** * This function sends an email out to the user referenced by the notification_user record, * and returns whether sending the email was successful or not. * @return bool */ public function send() { global $db, $AGENT_CONTACTS; require_once "Models/utility/TemplateMailer.class.php"; $query = "SELECT a.`proxy_id`, b.`firstname`, b.`lastname`, b.`email`, a.`content_type`, a.`record_id`, a.`record_proxy_id` FROM `notification_users` AS a\n\t\t\t\t\tJOIN `" . AUTH_DATABASE . "`.`user_data` AS b\n\t\t\t\t\tON a.`proxy_id` = b.`id`\n\t\t\t\t\tWHERE a.`nuser_id` = " . $db->qstr($this->nuser_id); $user = $db->GetRow($query); if ($user) { $template = new Template(); $template->loadString($this->notification_body); $mail = new TemplateMailer(new Zend_Mail()); $mail->addHeader("X-Section", APPLICATION_NAME . " Notifications System", true); $from = array("email" => $AGENT_CONTACTS["agent-notifications"]["email"], "firstname" => APPLICATION_NAME . " Notification System", "lastname" => ""); $to = array("email" => $user["email"], "firstname" => $user["firstname"], "lastname" => $user["lastname"]); try { $mail->send($template, $to, $from, DEFAULT_LANGUAGE); if ($this->setSentStatus(true)) { application_log("success", "A [" . $user["content_type"] . "] notification has been sent to a user [" . $user["proxy_id"] . "] successfully."); return true; } } catch (Zend_Mail_Transport_Exception $e) { system_log_data("error", "Unable to send [" . $user["content_type"] . "] notification to user [" . $user["proxy_id"] . "]. Template Mailer said: " . $e->getMessage()); } } return false; }
$PROCESSED_EMAIL["date"] = time(); $PROCESSED_EMAIL["user_id"] = $GUEST_PROXY_ID; $PROCESSED_EMAIL["hash"] = $hash; $PROCESSED_EMAIL["complete"] = 0; if ($db->AutoExecute("`" . AUTH_DATABASE . "`.`password_reset`", $PROCESSED_EMAIL, "INSERT")) { $xml_file = $ENTRADA_TEMPLATE->absolute() . "/email/community-new-user.xml"; } else { $xml_file = ""; application_log("error", "Error inserting new password_reset into database from Communities > Manage Members. Database said: " . $db->ErrorMsg()); } } else { $xml_file = $ENTRADA_TEMPLATE->absolute() . "/email/community-new-access.xml"; } try { $template = new Template($xml_file); $mail = new TemplateMailer(new Zend_Mail()); $mail->addHeader("X-Section", "Communities / Manage Members", true); $from = array("email" => $_SESSION["details"]["email"], "firstname" => $_SESSION["details"]["firstname"], "lastname" => $_SESSION["details"]["lastname"]); $to = array("email" => $PROCESSED["email"], "firstname" => $PROCESSED["firstname"], "lastname" => $PROCESSED["lastname"]); $keywords = array("application_name" => APPLICATION_NAME, "from_firstname" => $_SESSION["details"]["firstname"], "from_lastname" => $_SESSION["details"]["lastname"], "to_fullname" => $PROCESSED["firstname"] . " " . $PROCESSED["lastname"], "community_title" => $community_details["community_title"], "community_url" => ENTRADA_URL . "/community" . $community_details["community_url"], "username" => $username, "password_url" => PASSWORD_RESET_URL . "?hash=" . rawurlencode($PROCESSED_ACCESS["user_id"] . ":" . $hash)); if ($mail->send($template, $to, $from, DEFAULT_LANGUAGE, $keywords)) { if ($MAILING_LISTS["active"]) { $mail_list = new MailingList($COMMUNITY_ID); } } else { add_error("We were unable to send an invitation e-mail to the guest at this time.<br /><br />A system administrator was notified of this issue, but you may wish to contact this individual manually and let them know they have been added."); application_log("error", "Unable to send community guest notification to [" . $to["email"] . "]. Zend_Mail said: " . $mail->ErrorInfo); } } catch (Exception $e) { add_error("We were unable to send an invitation e-mail to the guest at this time.<br /><br />A system administrator was notified of this issue, but you may wish to contact this individual manually and let them know they have been added."); application_log("error", "Unable to load the XML file [" . $xml_file . "] or the XML file did not contain the language requested [" . DEFAULT_LANGUAGE . "], when attempting to send a community guest notification.");
/** * Sends email based on the specified type using templates from $ENTRADA_TEMPLATE->absolute()/email directory * @param string $type One of "reason", "noreason" * @param array $to associative array consisting of firstname, lastname, and email * @param array $keywords Associative array of keywords mapped to the replacement contents */ function submission_rejection_notification($type, $to = array(), $keywords = array()) { global $AGENT_CONTACTS, $ENTRADA_TEMPLATE; if (!is_array($to) || !isset($to["email"]) || !valid_address($to["email"]) || !isset($to["firstname"]) || !isset($to["lastname"])) { application_log("error", "Attempting to send a submission_rejection_notification() however the recipient information was not complete."); return false; } if (!in_array($type, array("reason", "noreason"))) { application_log("error", "Encountered an unrecognized notification type [" . $type . "] when attempting to send a submission_rejection_notification()."); return false; } $xml_file = $ENTRADA_TEMPLATE->absolute() . "/email/mspr-rejection-" . $type . ".xml"; try { require_once "Models/utility/Template.class.php"; require_once "Models/utility/TemplateMailer.class.php"; $template = new Template($xml_file); $mail = new TemplateMailer(new Zend_Mail()); $mail->addHeader("X-Section", "MSPR Module", true); $from = array("email" => $AGENT_CONTACTS["agent-notifications"]["email"], "firstname" => "MSPR System", "lastname" => ""); if ($mail->send($template, $to, $from, DEFAULT_LANGUAGE, $keywords)) { return true; } else { add_notice("We were unable to e-mail a task notification <strong>" . $to["email"] . "</strong>.<br /><br />A system administrator was notified of this issue, but you may wish to contact this individual manually and let them know their task verification status."); application_log("error", "Unable to send task verification notification to [" . $to["email"] . "] / type [" . $type . "]. Zend_Mail said: " . $mail->ErrorInfo); } } catch (Exception $e) { application_log("error", "Unable to load the XML file [" . $xml_file . "] or the XML file did not contain the language requested [" . DEFAULT_LANGUAGE . "], when attempting to send a regional education notification."); } return false; }