diff -urN ebulletin/xaradmin/publishissue.php ../../modules/ebulletin/xaradmin/publishissue.php --- ebulletin/xaradmin/publishissue.php 2005-11-03 15:43:38.000000000 -0800 +++ ../../modules/ebulletin/xaradmin/publishissue.php 2005-11-11 12:46:15.000000000 -0800 @@ -41,61 +41,47 @@ return; } - // Check for confirmation. - if (empty($confirm)) { - $data = xarModAPIFunc('ebulletin', 'admin', 'menu'); - // Specify for which item you want confirmation - $data['iid'] = $iid; - $data['issuedate'] = $issue['issuedate']; - $data['pub'] = $pub; - // Add some other data you'll want to display in the template - $data['confirmtext'] = xarML('Are you sure you are ready to publish this issue? Any editing must be performed before continuing.'); - $data['iidlabel'] = xarML('Issue ID'); - $data['namelabel'] = xarML('Publication'); - $data['issuedatelabel'] = xarML('Date'); - - $data['confirmbutton'] = xarML('Confirm'); - - $data['authid'] = xarSecGenAuthKey(); - // Return the template variables defined in this function - return $data; - } - - if (!xarSecConfirmAuthKey()) return; - # get list of subscriber UID's $uids = xarModAPIFunc('ebulletin', 'user', 'getsubscriptions', array('pid' => $issue['pid'])); - # initialize list of bcc recipients - $bccrecipients = array(); + # add what's on the publication's "to" list + # The first message is placed in the TO field. + # The rest are BCC'd like the subscribers. + $emails = ebulletin_parseAddresses($pub['to']); + if (empty($emails)) return; + + $to = array_slice($emails, 0, 1); + $bccrecipients = array_slice($emails, 1); # get names and emails for subscribed users $roles = new xarRoles(); foreach ($uids as $uid => $value) { $user = $roles->getRole($uid); - $bccrecipients[$user->getEmail()] = $user->getName(); - } - - # add what's on the publication's "to" list - # The first message is placed in the TO field. - # The rest are BCC'd like the subscribers. - $emails = preg_split("/\s*\,\s*/", trim($pub['to'])); - $to = array_pop($emails); - foreach ($emails as $email) { - if (empty($email) || isset($bccrecipients[$email])) continue; - $bccrecipients[] = $email; + if ($user->getState() != 3) continue; + $email = $user->getEmail(); + if (isset($bccrecipients[$email])) continue; + $username = $user->getName(); + $bccrecipients[$email] = $username; } # require a TO address; if we don't do it here, phpmailer will err if (empty($to)) return; + $from = ebulletin_parseAddresses($pub['from']); + $replyto = ebulletin_parseAddresses($pub['replyto']); + # assemble the email $mail = array(); - $mail['info'] = $to; + + foreach ($from as $email => $emailname) { + $mail['from'] = $email; + $mail['fromname'] = empty($emailname) ? xarModGetVar('themes','SiteName') : $emailname; + } + $mail['recipients'] = $to; + ksort($bccrecipients); + asort($bccrecipients); $mail['bccrecipients'] = $bccrecipients; - $mail['from'] = $pub['from']; - $mail['fromname'] = xarModGetVar('themes','SiteName'); - $mail['wordwrap'] = 80; + $mail['subject'] = str_replace('%date%', date('M j', strtotime($issue['issuedate'])), $pub['subject']); @@ -103,6 +89,27 @@ $mail['htmlmessage'] = $issue['compiled_html']; $mail['usetemplates'] = false; + + // Check for confirmation. + if (empty($confirm)) { + $data = xarModAPIFunc('ebulletin', 'admin', 'menu'); + // Specify for which item you want confirmation + $data['iid'] = $iid; + $data['issuedate'] = $issue['issuedate']; + $data['pub'] = $pub; + $data['issuedatelabel'] = xarML('Date'); + $data['mail'] = $mail; + $data['confirmbutton'] = xarML('Confirm'); + $data['authid'] = xarSecGenAuthKey(); + +#echopre($mail); + + // Return the template variables defined in this function + return $data; + } + + if (!xarSecConfirmAuthKey()) return; + if (!xarModAPIFunc('mail', 'admin', 'sendhtmlmail', $mail)) { return; } @@ -127,4 +134,24 @@ return true; } +function ebulletin_parseAddresses($list) +{ + $list = trim($list); + $lines = preg_split("/\s*[,;]\s*/", $list); + + $emails = array(); + foreach ($lines as $line) { + $line = trim($line); + if (empty($line)) continue; + if (preg_match("/^([^<]+)<([^>]+@[^>]+)>\$/", $line, $match)) { + $emails[strtolower($match[2])] = $match[1]; + } else { + # hope for the best... + $emails[strtolower($line)] = ''; + } + } + ksort($emails); + return $emails; +} + ?> \ No newline at end of file diff -urN ebulletin/xarinit.php ../../modules/ebulletin/xarinit.php --- ebulletin/xarinit.php 2005-10-30 09:59:30.000000000 -0800 +++ ../../modules/ebulletin/xarinit.php 2005-11-12 22:33:34.000000000 -0800 @@ -52,7 +52,7 @@ 'xar_pid' => array('type' => 'integer', 'size' => 'small'), 'xar_issuedate' => array('type' => 'date', 'default' => array('year' => 0000, 'month' => 00, 'day' => 00), - 'null' => false, + 'null' => false), 'xar_range' => array('type' => 'text', 'null' => false), 'xar_compiled_html' => array('type' => 'text', 'null' => false, 'default' => ''), 'xar_compiled_txt' => array('type' => 'text', 'null' => false, 'default' => ''), diff -urN ebulletin/xartemplates/admin-modify.xd ../../modules/ebulletin/xartemplates/admin-modify.xd --- ebulletin/xartemplates/admin-modify.xd 2005-04-10 14:21:39.000000000 -0700 +++ ../../modules/ebulletin/xartemplates/admin-modify.xd 2005-11-11 11:03:47.000000000 -0800 @@ -29,7 +29,7 @@
- : + : @@ -44,7 +44,7 @@ : - + ERROR! This is not a valid from diff -urN ebulletin/xartemplates/admin-publishissue.xd ../../modules/ebulletin/xartemplates/admin-publishissue.xd --- ebulletin/xartemplates/admin-publishissue.xd 2005-02-06 21:43:40.000000000 -0800 +++ ../../modules/ebulletin/xartemplates/admin-publishissue.xd 2005-11-11 14:13:32.000000000 -0800 @@ -7,30 +7,76 @@ -
#$confirmtext#

+
+ Are you sure you want to continue? +
+
- +
- + - date("m/d/Y", strtotime($issuedate)) - - + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + +
#$iidlabel#:Issue ID: #$iid#
#$issuedatelabel#:#$date#Publication:#$pub['name']#
#$namelabel#:#$pub['name']#Date:date("m/d/Y", strtotime($issuedate))#$date#

- -
From:#$mail['fromname']# <#$mail['from']#>
To: + We know there will only be one, but an array is most convenient... + #$email##$emailname# <#$email#> +
BCC: + count($mail['bccrecipients']) + + + #$email##$emailname# <#$email#>
+
+ + #$bcccount# addresses:
+ +
+
Subject:#$mail['subject']#
Body: + + round(strlen($mail['htmlmessage'])/1024,1) + #$size#K HTML / + + round(strlen($mail['message'])/1024,1) + #$size#K text +