diff options
| -rw-r--r-- | BitMailer.php | 10 | ||||
| -rw-r--r-- | BitNewsletter.php | 79 | ||||
| -rw-r--r-- | admin/admin_newsletter_subscriptions.php | 4 | ||||
| -rw-r--r-- | index.php | 9 | ||||
| -rw-r--r-- | templates/newsletters.tpl | 44 |
5 files changed, 86 insertions, 60 deletions
diff --git a/BitMailer.php b/BitMailer.php index 364b2fe..7d31fef 100644 --- a/BitMailer.php +++ b/BitMailer.php @@ -1,12 +1,12 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_newsletters/Attic/BitMailer.php,v 1.21 2006/06/30 14:16:09 spiderr Exp $ + * $Header: /cvsroot/bitweaver/_bit_newsletters/Attic/BitMailer.php,v 1.22 2006/07/07 00:04:30 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: BitMailer.php,v 1.21 2006/06/30 14:16:09 spiderr Exp $ + * $Id: BitMailer.php,v 1.22 2006/07/07 00:04:30 spiderr Exp $ * * Class that handles editions of newsletters * @package newsletters @@ -15,7 +15,7 @@ * * @author spiderr <spider@steelsun.com> * - * @version $Revision: 1.21 $ $Date: 2006/06/30 14:16:09 $ $Author: spiderr $ + * @version $Revision: 1.22 $ $Date: 2006/07/07 00:04:30 $ $Author: spiderr $ */ /** @@ -190,10 +190,10 @@ class BitMailer extends phpmailer { if( is_array( $pMixed ) ) { $col = key( $pMixed ); $bindVars[] = current( $pMixed ); - $query = "SELECT ms.`nl_content_id` AS `hash_key`, ms.*, uu.*, lc.title + $query = "SELECT ms.`content_id` AS `hash_key`, ms.*, uu.*, lc.title FROM `".BIT_DB_PREFIX."mail_subscriptions` ms LEFT OUTER JOIN `".BIT_DB_PREFIX."users_users` uu ON( ms.`user_id`=uu.`user_id` ) - LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( ms.`nl_content_id`=lc.`content_id` ) + LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( ms.`content_id`=lc.`content_id` ) WHERE ms.`$col`=? "; $ret = $gBitDb->getAssoc( $query, $bindVars ); } diff --git a/BitNewsletter.php b/BitNewsletter.php index 5b42eac..1b99538 100644 --- a/BitNewsletter.php +++ b/BitNewsletter.php @@ -1,12 +1,12 @@ <?php /** - * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletter.php,v 1.18 2006/06/19 02:35:19 spiderr Exp $ + * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletter.php,v 1.19 2006/07/07 00:04:30 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: BitNewsletter.php,v 1.18 2006/06/19 02:35:19 spiderr Exp $ + * $Id: BitNewsletter.php,v 1.19 2006/07/07 00:04:30 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.18 $ $Date: 2006/06/19 02:35:19 $ $Author: spiderr $ + * @version $Revision: 1.19 $ $Date: 2006/07/07 00:04:30 $ $Author: spiderr $ */ /** @@ -43,7 +43,7 @@ class BitNewsletter extends LibertyContent { $this->mContentTypeGuid = BITNEWSLETTER_CONTENT_TYPE_GUID; } - function load() { + function load( $pUserId = NULL ) { if( $this->verifyId( $this->mNewsletterId ) || $this->verifyId( $this->mContentId ) ) { global $gBitSystem; @@ -55,6 +55,10 @@ class BitNewsletter extends LibertyContent { $this->getServicesSql( 'content_load_function', $selectSql, $joinSql, $whereSql, $bindVars ); + if( $pUserId ) { + $whereSql + } + $query = "SELECT * FROM `".BIT_DB_PREFIX."newsletters` n INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON( n.`content_id`=lc.`content_id` ) @@ -99,22 +103,12 @@ class BitNewsletter extends LibertyContent { return( count( $this->mErrors ) == 0 ); } - function getSubscribers($nl_id) { - $ret = array(); - if( $this->isValid() ) { - $query = "select * from `".BIT_DB_PREFIX."mail_subscriptions` where `unsubscribe_date` is NULL and `nl_content_id`=?"; - if( $res = $this->mDb->query( $query, array( $this->mNewsletterId ) ) ) { - $ret = $res->GetRows(); - } - } - return $ret; - } - - function getAllSubscribers() { + function getSubscribers( $pAll=FALSE) { $ret = array(); if( $this->isValid() ) { - $query = "select * from `".BIT_DB_PREFIX."mail_subscriptions` where `nl_content_id`=?"; - if( $res = $this->mDb->query( $query, array( $this->mNewsletterId ) ) ) { + $whereSql = $pAll ? '' : ' `unsubscribe_date` is NULL AND '; + $query = "select * from `".BIT_DB_PREFIX."mail_subscriptions` WHERE $whereSql `content_id`=?"; + if( $res = $this->mDb->query( $query, array( $this->mContentId ) ) ) { $ret = $res->GetRows(); } } @@ -123,14 +117,14 @@ class BitNewsletter extends LibertyContent { function removeSubscription( $email, $notify = FALSE, $del_record = FALSE ) { if ($del_record) { - $this->mDb->query("DELETE FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `nl_content_id`=? AND `email`=?", array($this->mNewsletterId, $email)); + $this->mDb->query("DELETE FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `content_id`=? AND `email`=?", array($this->mContentId, $email)); } else { - $sub_code = $this->mDb->getOne("select `sub_code` from `".BIT_DB_PREFIX."mail_subscriptions` where `nl_content_id`=? and `email`=?", array($this->mNewsletterId, $email)); + $sub_code = $this->mDb->getOne("select `sub_code` from `".BIT_DB_PREFIX."mail_subscriptions` where `content_id`=? and `email`=?", array($this->mContentId, $email)); $this->unsubscribe($sub_code, $notify); } } - function subscribe( $email, $notify = FALSE, $remind = FALSE ) { + function subscribe( $pSubscribeHash ) { // $notify = FALSE, $remind = FALSE ) { $ret = FALSE; if( $this->isValid() ) { global $gBitSystem; @@ -138,12 +132,13 @@ class BitNewsletter extends LibertyContent { global $gBitUser; // Check for duplicates - $all_subs = $this->getAllSubscribers(); + $all_subs = $this->getSubscribers( TRUE ); $duplicate = FALSE; foreach($all_subs as $sub) { - if ($sub['email'] == $email) { + if( $sub['email'] == $pSubscribeHash['email'] ) { $duplicate = TRUE; $sub_code = $sub['sub_code']; + } elseif( !empty( $pSubscribeHash['user_id'] ) && $sub['user_id'] == $pSubscribeHash['user_id'] ) { } } @@ -152,10 +147,19 @@ class BitNewsletter extends LibertyContent { // Generate a code and store it and send an email with the // URL to confirm the subscription put valid as 'n' if (!$duplicate) { - $query = "insert into `".BIT_DB_PREFIX."mail_subscriptions`(`nl_content_id`,`email`,`sub_code`,`is_valid`,`subscribed_date`) values(?,?,?,?,?)"; - $result = $this->mDb->query( $query, array( $this->mNewsletterId, $email, $sub_code, 'n', (int)$now ) ); + if( @BitBase::verifyId( $pSubscribeHash['user_id'] ) ) { + // we have user_id subscribing, use the id, NULL the email + $subUserId = $pSubscribeHash['user_id']; + $subEmail = NULL; + } else { + // we have user_id subscribing, use the id, NULL the email + $subUserId = NULL; + $subEmail = $pSubscribeHash['email']; + } + $query = "insert into `".BIT_DB_PREFIX."mail_subscriptions` (`content_id`, `user_id`, `email`,`sub_code`,`is_valid`,`subscribed_date`) VALUES (?,?,?,?,?,?)"; + $result = $this->mDb->query( $query, array( $this->mContentId, $subUserId, $subEmail, $sub_code, 'n', (int)$now ) ); } - if( ($notify && $this->mInfo['validate_addr'] == 'y') || $remind ) { + if( ( !empty( $pSubscribeHash['notify'] ) && $this->getField( 'validate_addr' ) == 'y') || !empty( $pSubscribeHash['remind'] ) ) { // Generate a code and store it and send an email with the $gBitSmarty->assign( 'sub_code', $sub_code ); $mail_data = $gBitSmarty->fetch('bitpackage:newsletters/confirm_newsletter_subscription.tpl'); @@ -177,7 +181,7 @@ class BitNewsletter extends LibertyContent { if (!$result->numRows()) return false; $res = $result->fetchRow(); - $this->mNewsletterId = $res['nl_content_id']; + $this->mContentId = $res['content_id']; $this->load(); $query = "update `".BIT_DB_PREFIX."mail_subscriptions` set `is_valid`=?,`unsubscribe_date`=? where `sub_code`=?"; $result = $this->mDb->query($query,array('y',NULL,$sub_code)); @@ -202,7 +206,7 @@ class BitNewsletter extends LibertyContent { if (!$result->numRows()) return false; $res = $result->fetchRow(); - $this->mNewsletterId = $res['nl_content_id']; + $this->mContentId = $res['content_id']; $this->load(); $query = "update `".BIT_DB_PREFIX."mail_subscriptions` set `unsubscribe_date`=? where `sub_code`=? and `unsubscribe_date` is NULL"; $result = $this->mDb->query($query,array($now, $sub_code)); @@ -269,8 +273,8 @@ class BitNewsletter extends LibertyContent { $ret = array(); while( $res = $result->fetchRow() ) { $res['display_url'] = $this->getDisplayUrl( $res['nl_id'] ); - $res["confirmed"] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `unsubscribe_date` IS NULL and `nl_content_id`=?",array( (int)$res["nl_id"] ) ); - $res["unsub_count"] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `nl_content_id`=?",array( (int)$res["nl_id"] ) ); + $res["confirmed"] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `unsubscribe_date` IS NULL and `content_id`=?",array( (int)$res['content_id'] ) ); + $res["unsub_count"] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `content_id`=?",array( (int)$res['content_id'] ) ); $ret[$res['content_id']] = $res; } @@ -309,7 +313,7 @@ class BitNewsletter extends LibertyContent { $foo = str_replace('send_newsletters', 'newsletters', $foo); $url_subscribe = httpPrefix(). $foo["path"]; - $sub_code = $this->mDb->getOne("select `sub_code` from `".BIT_DB_PREFIX."mail_subscriptions` where `nl_content_id`=? and `email`=?",array((int)$nl_id,$email)); + $sub_code = $this->mDb->getOne("select `sub_code` from `".BIT_DB_PREFIX."mail_subscriptions` where `content_id`=? and `email`=?",array((int)$nl_id,$email)); $url_unsub = $url_subscribe . '?unsubscribe=' . $sub_code; $msg = '<br/><br/>' . tra( 'You can unsubscribe from this newsletter following this link'). ": <a href='$url_unsub'>$url_unsub</a>"; return $msg; @@ -322,9 +326,9 @@ class BitNewsletter extends LibertyContent { $query = "DELETE FROM `".BIT_DB_PREFIX."newsletters` where `nl_id`=?"; $result = $this->mDb->query( $query, array( $this->mNewsletterId ) ); // Clear out all individual subscriptions/unsubscriptions, but preserve the unsubscribe_all's - $query = "DELETE FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `nl_content_id`=? AND `unsubscribe_all` IS NOT NULL"; + $query = "DELETE FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `content_id`=? AND `unsubscribe_all` IS NOT NULL"; $result = $this->mDb->query( $query, array( $this->mContentId ) ); - $query = "UPDATE `".BIT_DB_PREFIX."mail_subscriptions` SET `nl_content_id`=NULL WHERE `nl_content_id`=? AND `unsubscribe_all` IS NOT NULL"; + $query = "UPDATE `".BIT_DB_PREFIX."mail_subscriptions` SET `content_id`=NULL WHERE `content_id`=? AND `unsubscribe_all` IS NOT NULL"; $result = $this->mDb->query( $query, array( $this->mContentId ) ); if( parent::expunge() ) { $ret = TRUE; @@ -374,6 +378,15 @@ class BitNewsletter extends LibertyContent { } return $ret; } + + function getUserSubscriptions( $pUserId, $pEmail ) { + global $gBitDb; + $query = "SELECT `content_id` AS hash_key, * FROM `".BIT_DB_PREFIX."mail_subscriptions` WHERE `user_id`=? OR `email`=?"; + $ret = $gBitDb->getAssoc( $query, array( $pUserId, $pEmail ) ); + return $ret; + } + + } ?> diff --git a/admin/admin_newsletter_subscriptions.php b/admin/admin_newsletter_subscriptions.php index 8c83c16..b0cb773 100644 --- a/admin/admin_newsletter_subscriptions.php +++ b/admin/admin_newsletter_subscriptions.php @@ -1,6 +1,6 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_newsletters/admin/admin_newsletter_subscriptions.php,v 1.5 2006/06/19 02:35:19 spiderr Exp $ +// $Header: /cvsroot/bitweaver/_bit_newsletters/admin/admin_newsletter_subscriptions.php,v 1.6 2006/07/07 00:04:30 spiderr Exp $ // Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. // All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -106,7 +106,7 @@ if( $gContent->isValid() ) { } } - $subscribers = $gContent->getAllSubscribers($nl_id); + $subscribers = $gContent->getSubscribers( TRUE ); $gBitSmarty->assign( 'subscribers', $subscribers ); } /* @@ -1,5 +1,5 @@ <?php -// $Header: /cvsroot/bitweaver/_bit_newsletters/index.php,v 1.19 2006/06/19 02:35:19 spiderr Exp $ +// $Header: /cvsroot/bitweaver/_bit_newsletters/index.php,v 1.20 2006/07/07 00:04:30 spiderr Exp $ // Copyright (c) 2006 - bitweaver.org - Christian Fowler, Max Kremmel, et. al // All Rights Reserved. See copyright.txt for details and a complete list of authors. @@ -29,6 +29,7 @@ if( !empty( $_REQUEST['nl_id'] ) ) { } } $newsletters = $gContent->getList( $listHash ); +$gBitSmarty->assign_by_ref( 'subs', BitNewsletter::getUserSubscriptions( $gBitUser->getField( 'user_id' ), $gBitUser->getField( 'email' ) ) ); $gBitSmarty->assign_by_ref('newsletters', $newsletters ); $foo = parse_url($_SERVER["REQUEST_URI"]); @@ -37,13 +38,11 @@ $gBitSmarty->assign('url_subscribe', httpPrefix(). $foo["path"]); if (isset($_REQUEST["sub"])) { $gContent->confirmSubscription($_REQUEST["sub"], TRUE ); $gBitSmarty->assign('confirm', 'y'); -} - -if (isset($_REQUEST["unsubscribe"])) { +} elseif( isset( $_REQUEST["unsubscribe"] ) ) { if (!empty( $_REQUEST["email"] )) { $gContent->removeSubscription($_REQUEST["email"], TRUE ); } elseif (!empty( $_REQUEST["unsubscribe"] )) { - $gContent->unsubscribe($_REQUEST["unsubscribe"], TRUE ); + $gContent->unsubscribe($_REQUEST["unsubscribe"], TRUE ); } $feedback['success'] = tra( "Your email address was removed from the list of subscriptors." ); } diff --git a/templates/newsletters.tpl b/templates/newsletters.tpl index b5f0f94..be7631a 100644 --- a/templates/newsletters.tpl +++ b/templates/newsletters.tpl @@ -40,17 +40,22 @@ </div> <div class="row submit"> {forminput} - <input type="submit" name="subscribe" value="{tr}Subscribe{/tr}" /> - <input type="submit" name="unsubscribe" value="{tr}Unsubscribe{/tr}" /> + <input type="submit" name="cancel" value="{tr}Cancel{/tr}" /> + {if $gContent->getField( 'subscribed_date' )} + <input type="submit" name="unsubscribe" value="{tr}Unsubscribe{/tr}" /> + {else} + <input type="submit" name="subscribe" value="{tr}Subscribe{/tr}" /> + {/if} {/forminput} </div> {/form} {/if} - {/if} + {else} {minifind} - <table class="data"> + <ul class="data"> +{* <caption>{tr}Newsletters{/tr}</caption> <tr> <th>{smartlink ititle="Name" isort=name offset=$offset idefault=1}</th> @@ -58,24 +63,33 @@ <th>{tr}Subscribe{/tr}</th> <th>{tr}Editions{/tr}</th> </tr> - {foreach from=$newsletters item=nl} +*} + {foreach from=$newsletters item=nl key=nlId} {if $newsletters.individual ne 'y' or $newsletters.individual_bit_p_subscribe_newsletters eq 'y'} - <tr class="{cycle values='odd,even'}"> - <td>{$nl.title|escape}</td> - <td>{$nl.data}</td> - <td><a href="{$smarty.const.NEWSLETTERS_PKG_URL}index.php?nl_id={$nl.nl_id}&info=1">{tr}Subscribe{/tr}</a></td> - <td><a href="{$smarty.const.NEWSLETTERS_PKG_URL}edition.php?nl_id={$nl.nl_id}">{tr}Editions{/tr}</a></td> - </tr> + <li class="item {cycle values='odd,even'}"> + <div class="floaticon"> + {if $subs.$nlId} + <strong>{biticon ipackage=liberty iname=success}{tr}Subscribed{/tr}: {$subs.$nlId.subscribed_date|bit_short_date}</strong><br/> + <a href="{$smarty.const.NEWSLETTERS_PKG_URL}index.php?nl_id={$nl.nl_id}&info=1">{tr}Unsubscribe{/tr}</a> + {else} + <a href="{$smarty.const.NEWSLETTERS_PKG_URL}index.php?nl_id={$nl.nl_id}&info=1">{tr}Subscribe{/tr}</a> + {/if} + </div> + <h1>{$nl.title|escape}</h1> + {$nl.data} + <div><a href="{$smarty.const.NEWSLETTERS_PKG_URL}edition.php?nl_id={$nl.nl_id}">{tr}Editions{/tr}</a></div> + </li> {/if} {foreachelse} - <tr class="norecords"> - <td colspan="2">{tr}No Records Found{/tr}</td> - </tr> + <li class="norecords"> + {tr}No Records Found{/tr} + </li> {/foreach} - </table> + </ul> {* haven't dealt with pagination yet *} {pagination} + {/if} </div><!-- end .body --> </div><!-- end .newsletters --> {/strip} |
