summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Fowler <spider@viovio.com>2005-12-11 22:53:05 +0000
committerChristian Fowler <spider@viovio.com>2005-12-11 22:53:05 +0000
commit8bbaa8db252a57322d4ad36f74637d7df198deee (patch)
tree09501e784259ed88f7cafab421d514342f20e881
parent63230d60adeed22fdf349ba4a838029c034551b0 (diff)
downloadnewsletters-8bbaa8db252a57322d4ad36f74637d7df198deee.tar.gz
newsletters-8bbaa8db252a57322d4ad36f74637d7df198deee.tar.bz2
newsletters-8bbaa8db252a57322d4ad36f74637d7df198deee.zip
schema changes for powerhouse tiki_mail_queue and tiki_mail_unsubscriptions. content generic in design. send now stuffs the queue and avoids duplicates on multiple sends. only piece left is a mailer class
-rw-r--r--BitNewsletterEdition.php40
-rw-r--r--admin/schema_inc.php29
-rw-r--r--edition_edit.php3
-rw-r--r--templates/admin_newsletters.tpl5
-rw-r--r--templates/view_edition.tpl2
5 files changed, 54 insertions, 25 deletions
diff --git a/BitNewsletterEdition.php b/BitNewsletterEdition.php
index fa530d0..c2366f9 100644
--- a/BitNewsletterEdition.php
+++ b/BitNewsletterEdition.php
@@ -1,12 +1,12 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletterEdition.php,v 1.5 2005/12/11 08:52:21 spiderr Exp $
+ * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletterEdition.php,v 1.6 2005/12/11 22:53:05 spiderr Exp $
*
* Copyright (c) 2004 bitweaver.org
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: BitNewsletterEdition.php,v 1.5 2005/12/11 08:52:21 spiderr Exp $
+ * $Id: BitNewsletterEdition.php,v 1.6 2005/12/11 22:53:05 spiderr Exp $
*
* Virtual base class (as much as one can have such things in PHP) for all
* derived tikiwiki classes that require database access.
@@ -16,7 +16,7 @@
*
* @author drewslater <andrew@andrewslater.com>, spiderr <spider@steelsun.com>
*
- * @version $Revision: 1.5 $ $Date: 2005/12/11 08:52:21 $ $Author: spiderr $
+ * @version $Revision: 1.6 $ $Date: 2005/12/11 22:53:05 $ $Author: spiderr $
*/
/**
@@ -90,14 +90,15 @@ class BitNewsletterEdition extends LibertyAttachable {
$query = "SELECT tne.*, tc.*
FROM `".BIT_DB_PREFIX."tiki_newsletters_editions` tne
INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tne.`content_id`=tc.`content_id` )
- WHERE `$lookupColumn`=? $whereSql";
- $result = $this->mDb->query($query,$bindVars);
- if ($result->numRows()) {
+ WHERE tne.`$lookupColumn`=? $whereSql";
+ if ( $result = $this->mDb->query($query,$bindVars) ) {
$this->mInfo = $result->fetchRow();
$this->mEditionId = $this->mInfo['edition_id'];
$this->mContentId = $this->mInfo['content_id'];
$this->mNewsletter = new BitNewsletter( $this->mInfo['nl_id'] );
$this->mNewsletter->load();
+ } else {
+ unset( $this->mEditionId );
}
}
return( count( $this->mInfo ) );
@@ -180,12 +181,37 @@ class BitNewsletterEdition extends LibertyAttachable {
foreach( $pGroupArray as $groupId ) {
$ret = array_merge( $ret, $gBitUser->getGroupUserData( $groupId, array( 'email', 'uu.user_id', 'login', 'real_name' ) ) );
}
+
+ $query = "SELECT * FROM `".BIT_DB_PREFIX."tiki_mail_unsubscriptions` WHERE `content_id`=? OR `unsubscribe_all` IS NOT NULL";
+ if( $unsubs = $this->mDb->getArray( $query, array( $this->mNewsletter->mContentId ) ) ) {
+ $ret = array_diff_assoc( $ret, $unsubs );
+ }
+ $query = "SELECT `email`, `user_id` FROM `".BIT_DB_PREFIX."tiki_mail_queue` WHERE `content_id`=?";
+ if( $dupes = $this->mDb->getAssoc( $query, array( $this->mContentId ) ) ) {
+ $ret = array_diff_keys( $ret, $dupes );
+ }
}
return $ret;
}
function queueRecipients( $pRecipients ) {
-vd( $pRecipients );
+ $ret = 0;
+ if( $this->isValid() ) {
+vd( $this->mContentId );
+ $queueTime = time();
+ foreach( array_keys( $pRecipients ) AS $email ) {
+ $insertHash['email'] = $email;
+ if( !empty( $pRecipients[$email]['user_id'] ) ) {
+ $insertHash['user_id'] = $pRecipients[$email]['user_id'];
+ }
+ $insertHash['content_id'] = $this->mContentId;
+ $insertHash['queue_date'] = $queueTime;
+ $this->mDb->associateInsert( BIT_DB_PREFIX.'tiki_mail_queue', $insertHash );
+ $ret++;
+ }
+die;
+ }
+ return $ret;
}
}
diff --git a/admin/schema_inc.php b/admin/schema_inc.php
index cbbbffc..7e42ce4 100644
--- a/admin/schema_inc.php
+++ b/admin/schema_inc.php
@@ -14,16 +14,14 @@ $tables = array(
CONSTRAINTS ', CONSTRAINT `tiki_nl_ed_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )'
",
-'tiki_newsletter_subscriptions' => "
- nl_id I4 PRIMARY,
+'tiki_mail_unsubscriptions' => "
+ content_id I4 PRIMARY,
email C(160) PRIMARY,
user_id I4,
- code C(32),
- valid C(1),
- subscribed_date I8,
+ unsubscribe_all C(1),
unsubscribed_date I8
- CONSTRAINTS ', CONSTRAINT `tiki_nl_sub_nl_ref` FOREIGN KEY (`nl_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `nl_id` ),
- , CONSTRAINT `tiki_nl_group_ref` FOREIGN KEY (`group_id`) REFERENCES `".BIT_DB_PREFIX."users_groups`( `group_id` )'
+ CONSTRAINTS ', CONSTRAINT `tiki_mail_unsub_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters`( `content_id` ),
+ , CONSTRAINT `tiki_mail_unsub_ref` FOREIGN KEY (`user_id`) REFERENCES `".BIT_DB_PREFIX."users_users`( `user_id` )'
",
'tiki_newsletters_editions' => "
@@ -35,18 +33,19 @@ $tables = array(
, CONSTRAINT `tiki_nl_ed_con_ref` FOREIGN KEY (`content_id`) REFERENCES `".BIT_DB_PREFIX."tiki_content`( `content_id` )'
",
-'tiki_newsletters_mailings' => "
- edition_id I4 NOTNULL,
+'tiki_editions_mailings' => "
+ content_id I4 NOTNULL,
queue_date I8,
send_date I8,
emails_sent I8
CONSTRAINTS ', CONSTRAINT `tiki_nl_mail_ed_ref` FOREIGN KEY (`edition_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters_editions`( `edition_id` )'
",
-'tiki_newsletters_mailings_queue' => "
- edition_id I4 PRIMARY,
+'tiki_mail_queue' => "
+ content_id I4 PRIMARY,
email C(160) PRIMARY,
- user_id C(1),
+ user_id I4,
+ queue_date I8 NOTNULL,
sent_date I8
CONSTRAINTS ', CONSTRAINT `tiki_nl_mailq_ed_ref` FOREIGN KEY (`edition_id`) REFERENCES `".BIT_DB_PREFIX."tiki_newsletters_editions`( `edition_id` ),
, CONSTRAINT `tiki_nl_mailq_user_ref` FOREIGN KEY (`users_id`) REFERENCES `".BIT_DB_PREFIX."users_users`( `users_id` )'
@@ -75,8 +74,10 @@ $indices = array (
'tiki_nl_sub_email_idx' => array( 'table' => 'tiki_newsletter_subscriptions', 'cols' => 'email', 'opts' => NULL ),
'tiki_nl_ed_nl_idx' => array( 'table' => 'tiki_newsletters_editions', 'cols' => 'nl_id', 'opts' => NULL ),
'tiki_nl_group_nl_idx' => array( 'table' => 'tiki_newsletter_groups', 'cols' => 'nl_id', 'opts' => NULL ),
- 'tiki_nl_mq_email_idx' => array( 'table' => 'tiki_newsletters_mailings_queue', 'cols' => 'email', 'opts' => NULL ),
- 'tiki_nl_mq_sent_idx' => array( 'table' => 'tiki_newsletters_mailings_queue', 'cols' => 'sent_date', 'opts' => NULL ),
+ 'tiki_mq_email_idx' => array( 'table' => 'tiki_mail_queue', 'cols' => 'email', 'opts' => NULL ),
+ 'tiki_mq_user_idx' => array( 'table' => 'tiki_mail_queue', 'cols' => 'user_id', 'opts' => NULL ),
+ 'tiki_mq_content_idx' => array( 'table' => 'tiki_mail_queue', 'cols' => 'content_id', 'opts' => NULL ),
+ 'tiki_mq_sent_idx' => array( 'table' => 'tiki_mail_queue', 'cols' => 'sent_date', 'opts' => NULL ),
);
$gBitInstaller->registerSchemaIndexes( LIBERTY_PKG_NAME, $indices );
diff --git a/edition_edit.php b/edition_edit.php
index 62d52a0..2b29fd1 100644
--- a/edition_edit.php
+++ b/edition_edit.php
@@ -40,7 +40,8 @@ if (isset($_REQUEST["preview"])) {
$gBitSmarty->assign('info', $info);
} elseif (isset($_REQUEST["save"])) {
if( $gContent->store( $_REQUEST ) ) {
- $gBitSmarty->assign( 'success', tra( 'Newsletter edition saved' ) );
+ header( 'Location: '.$gContent->getDisplayUrl() );
+ die;
} else {
$gBitSmarty->assign( 'errors', $gContent->mErrors );
}
diff --git a/templates/admin_newsletters.tpl b/templates/admin_newsletters.tpl
index e2db21f..d68d824 100644
--- a/templates/admin_newsletters.tpl
+++ b/templates/admin_newsletters.tpl
@@ -91,8 +91,9 @@
<td>{$nl.last_sent|bit_short_date}</td>
<td style="text-align:right;"><a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/admin_newsletter_subscriptions.php?nl_id={$nlId}">{$nl.users|default:0} [ {$channels[user].confirmed|default:0} ]</a></td>
<td style="text-align:right;">
- <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&amp;sort_mode={$sort_mode}&amp;remove=1&amp;nl_id={$nlId}">{biticon ipackage=liberty iname=delete iexplain=Remove}</a>
- <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?offset={$offset}&amp;sort_mode={$sort_mode}&amp;nl_id={$nlId}">{biticon ipackage=liberty iname=edit iexplain=Edit}</a>
+ <a href="{$smarty.const.NEWSLETTERS_PKG_URL}edition_edit.php?nl_id={$nlId}">{biticon ipackage=liberty iname=new iexplain="New Edition"}</a>
+ <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?remove=1&amp;nl_id={$nlId}">{biticon ipackage=liberty iname=delete iexplain=Remove}</a>
+ <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/index.php?&amp;nl_id={$nlId}">{biticon ipackage=liberty iname=edit iexplain=Edit}</a>
{if $channels[user].individual eq 'y'}({/if}<a href="{$smarty.const.KERNEL_PKG_URL}object_permissions.php?objectName=newsletter%20{$nl.title}&amp;object_type={$smarty.const.BITNEWSLETTER_CONTENT_TYPE_GUID}&amp;permType=newsletters&amp;object_id={$nlId}">{biticon ipackage=liberty iname=permissions iexplain=Permissions}</a>{if $nl.individual eq 'y'}){/if}
</td>
</tr>
diff --git a/templates/view_edition.tpl b/templates/view_edition.tpl
index 0a581fe..00ff9ba 100644
--- a/templates/view_edition.tpl
+++ b/templates/view_edition.tpl
@@ -7,7 +7,7 @@
<a href="{$smarty.const.NEWSLETTERS_PKG_URL}edition_edit.php?edition_id={$gContent->mEditionId}&amp;remove=1">{biticon ipackage=liberty iname="delete" iexplain="delete"}</a>
{/if}
- <a href="{$smarty.const.NEWSLETTERS_PKG_URL}send_newsletter.php?edition_id={$gContent->mEditionId}">{biticon ipackage=liberty iname="mail_send" iexplain="email this post"}</a>
+ <a href="{$smarty.const.NEWSLETTERS_PKG_URL}admin/send.php?edition_id={$gContent->mEditionId}">{biticon ipackage=liberty iname="mail_send" iexplain="email this post"}</a>
</div>
<div class="header">