/** * Actually release an issue of a newsletter * Add the mailing to the mail queue * * @param int id of issue * * @return boolean FALSE on error */ function releaseIssue($issue) { $pref = e107::getPref(); $sql = e107::getDb(); $mes = e107::getMessage(); $ns = e107::getRender(); $issue = intval(str_replace('nlmailnow_', '', $issue)); // Get details of current newsletter issue if (!$sql->select('newsletter', '*', 'newsletter_id=' . $issue)) { return FALSE; } $newsletterInfo = $sql->fetch(MYSQL_ASSOC); // Get parent details - has header/footer and subscriber list if (!$sql->select('newsletter', '*', "newsletter_id='" . $newsletterInfo['newsletter_parent'] . "' ")) { return FALSE; } $newsletterParentInfo = $sql->fetch(MYSQL_ASSOC); $memberArray = explode(chr(1), $newsletterParentInfo['newsletter_subscribers']); require e_HANDLER . 'mail_manager_class.php'; $mailer = new e107MailManager(); // Start by creating the mail body $mailData = array('mail_content_status' => MAIL_STATUS_TEMP, 'mail_create_app' => 'newsletter', 'mail_title' => NLLAN_01 . ' ' . $issue, 'mail_subject' => $newsletterParentInfo['newsletter_title'] . ': ' . $newsletterInfo['newsletter_title'], 'mail_sender_email' => $pref['siteadminemail'], 'mail_sender_name' => $pref['siteadmin'], 'mail_send_style' => 'themehtml', 'mail_include_images' => TRUE); // Assemble body - we can leave a lot to to core mail sending routines $mail_style = "<div style='width:90%; padding-top:10px'>"; $mail_style .= "<div><b>{$mailout['mail_subject']}<br />[ " . NLLAN_12 . " " . $newsletterInfo['newsletter_issue'] . " ]</b></div><br /><br />"; $mail_style .= "<div>"; $mailData['mail_body'] = $mail_style . $newsletterParentInfo['newsletter_header'] . "<hr />" . $newsletterInfo['newsletter_text'] . "<br /><br /><hr />" . $newsletterParentInfo['newsletter_footer'] . "<br /></div></div>"; $result = $mailer->saveEmail($mailData, TRUE); if (is_numeric($result)) { $mailMainID = $mailData['mail_source_id'] = $result; } else { // TODO: Handle error } $mailer->mailInitCounters($mailMainID); // Initialise counters for emails added // Now add email addresses to the list foreach ($memberArray as $memberID) { if ($memberID = intval($memberID)) { if ($sql->select('user', 'user_name,user_email,user_loginname,user_lastvisit', 'user_id=' . $memberID)) { $row = $sql->db_Fetch(MYSQL_ASSOC); $uTarget = array('mail_recipient_id' => $memberID, 'mail_recipient_name' => $row['user_name'], 'mail_recipient_email' => $row['user_email'], 'mail_target_info' => array('USERID' => $memberID, 'DISPLAYNAME' => $row['user_name'], 'USERNAME' => $row['user_loginname'], 'USERLASTVISIT' => $row['user_lastvisit'])); // Probably overkill, but some user data in case we want to substitute } $result = $mailer->mailAddNoDup($mailMainID, $uTarget, MAIL_STATUS_TEMP); //echo '<b>'.NLLAN_54.'</b> '.$uTarget['mail_recipient_name'].' ( '.$uTarget['mail_recipient_email'].' ) <br />'; } } $mailer->mailUpdateCounters($mailMainID); // Update the counters $counters = $mailer->mailRetrieveCounters($mailMainID); // Retrieve the counters if ($counters['add'] == 0) { $mailer->deleteEmail($mailMainID); // No subscribers - delete email //$this->message = NLLAN_41; $mes->addError(NLLAN_41); } else { $mailer->activateEmail($mailMainID, FALSE); // Actually mark the email for sending //$this->message = str_replace('--COUNT--', $counters['add'],NLLAN_40); $mes->addSuccess(str_replace('--COUNT--', $counters['add'], NLLAN_40)); } $sql->update('newsletter', "newsletter_flag='1' WHERE newsletter_id=" . $issue); $ns->tablerender($caption, $mes->render() . $text); }
/** * Send an email notification following an event. * * For up to a (hard-coded) number of recipients, the mail is sent immediately. * Otherwise its added to the queue * * @param string $id - identifies event actions * @param string $subject - subject for email * @param string $message - email message body * @return none * * @todo handle 'everyone except' clauses (email address filter done) * @todo set up pref to not notify originator of event which caused notify (see $blockOriginator) */ function send($id, $subject, $message) { $e107 = e107::getInstance(); $subject = $e107->tp->toEmail(SITENAME . ': ' . $subject); $message = $e107->tp->toEmail($message); $emailFilter = ''; $notifyTarget = $this->notify_prefs['event'][$id]['class']; if ($notifyTarget == '-email') { $emailFilter = $this->notify_prefs['event'][$id]['email']; } $blockOriginator = FALSE; // TODO: set this using a pref if (is_numeric($this->notify_prefs['event'][$id]['class'])) { switch ($notifyTarget) { case e_UC_MAINADMIN: $qry = "`user_admin` = 1 AND `user_perms` = '0' AND `user_ban` = 0"; break; case e_UC_ADMIN: $qry = "`user_admin` = 1 AND `user_ban` = 0"; break; case e_UC_MEMBER: $qry = "`user_ban` = 0"; break; default: $qry = "user_ban = 0 AND user_class REGEXP '(^|,)(" . $this->notify_prefs['event'][$id]['class'] . ")(,|\$)'"; break; } $qry = 'SELECT user_id,user_name,user_email FROM `#user` WHERE ' . $qry; if ($blockOriginator) { $qry .= ' AND `user_id` != ' . USERID; } if (FALSE !== ($count = $e107->sql->db_Select_gen($qry))) { if ($count <= 5) { // Arbitrary number below which we send emails immediately e107_require_once(e_HANDLER . 'mail.php'); while ($email = $e107->sql->db_Fetch()) { if ($email['user_email'] != $emailFilter) { sendemail($email['user_email'], $subject, $message, $email['user_name']); } } } else { // Otherwise add to mailout queue require_once e_HANDLER . 'mail_manager_class.php'; $mailer = new e107MailManager(); // Start by creating the mail body $mailData = array('mail_content_status' => MAIL_STATUS_TEMP, 'mail_create_app' => 'notify', 'mail_title' => 'NOTIFY', 'mail_subject' => $subject, 'mail_sender_email' => $pref['siteadminemail'], 'mail_sender_name' => $pref['siteadmin'], 'mail_send_style' => 'textonly', 'mail_notify_complete' => 0, 'mail_body' => $message); $result = $mailer->saveEmail($mailData, TRUE); if (is_numeric($result)) { $mailMainID = $mailData['mail_source_id'] = $result; } else { // TODO: Handle error return; // Probably nothing else we can do } $mailer->mailInitCounters($mailMainID); // Initialise counters for emails added // Now add email addresses to the list while ($row = $e107->sql->db_Fetch(MYSQL_ASSOC)) { if ($row['user_email'] != $emailFilter) { $uTarget = array('mail_recipient_id' => $row['user_id'], 'mail_recipient_name' => $row['user_name'], 'mail_recipient_email' => $row['user_email']); $result = $mailer->mailAddNoDup($mailMainID, $uTarget, MAIL_STATUS_TEMP); } } $mailer->mailUpdateCounters($mailMainID); // Update the counters $counters = $mailer->mailRetrieveCounters($mailMainID); // Retrieve the counters if ($counters['add'] == 0) { $mailer->deleteEmail($mailMainID); // Probably a fault, but precautionary - delete email } else { $mailer->activateEmail($mailMainID, FALSE); // Actually mark the email for sending } } $e107->admin_log->e_log_event(10, -1, 'NOTIFY', $subject, $message, FALSE, LOG_TO_ROLLING); } } elseif ($notifyTarget == 'email') { // Single email address - that can always go immediately if (!$blockOriginator || $this->notify_prefs['event'][$id]['email'] != USEREMAIL) { e107_require_once(e_HANDLER . 'mail.php'); sendemail($this->notify_prefs['event'][$id]['email'], $subject, $message); } } }