Source for file sub.php
Documentation is available at sub.php
* @version $Header: /cvsroot/bitweaver/_bit_newsletters/sub.php,v 1.2 2007/02/05 11:14:32 lsces Exp $
* Copyright (c) 2005 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
* @author spider <spider@steelsun.com>
require_once( '../bit_setup_inc.php' );
include_once( NEWSLETTERS_PKG_PATH. 'BitMailer.php' );
$gBitSystem->verifyPackage( 'newsletters' );
if( !$gBitUser->isRegistered() && !$gBitUser->hasPermission( 'p_newsletters_subscribe' ) && empty( $_REQUEST["sub"] ) ) {
$gBitSystem->fatalError( tra("You must be logged in to subscribe to newsletters"));
require_once( NEWSLETTERS_PKG_PATH. 'lookup_newsletter_inc.php' );
if( !empty( $_REQUEST['nl_id'] ) ) {
$listHash['nl_id'] = $_REQUEST['nl_id'];
if (isset ($_REQUEST['info'])) {
$gBitSmarty->assign('subscribe', 'y');
if( $gBitUser->isRegistered() ) {
$infoHash = array( 'user_id' => $gBitUser->mUserId );
$gBitSmarty->assign( 'subInfo', $gContent->getSubscriberInfo( $infoHash ) );
$newsletters = $gContent->getList( $listHash );
$gBitSmarty->assign_by_ref('newsletters', $newsletters );
$gBitSmarty->assign('url_subscribe', httpPrefix(). $foo["path"]);
if (isset ($_REQUEST["sub"])) {
$gContent->confirmSubscription($_REQUEST["sub"], TRUE );
$gBitSmarty->assign('confirm', 'y');
} elseif( isset ( $_REQUEST["unsub"] ) ) {
if (!empty( $_REQUEST["email"] )) {
$gContent->removeSubscription($_REQUEST["email"], TRUE );
} elseif (!empty( $_REQUEST["unsubscribe"] )) {
$gContent->unsubscribe($_REQUEST["unsubscribe"], TRUE );
$feedback['success'] = tra( "Your email address was removed from the list of subscriptors." );
if( isset ( $_REQUEST["sub"] ) ) {
$lookup['email'] = $subInfo['email'];
$subInfo = $gBitUser->mInfo;
$lookup['user_id'] = $gBitUser->mUserId;
if( isset ( $_REQUEST["update"] ) ) {
$subHash['response_content_id'] = $_REQUEST['response_content_id'];
$subHash['sub_lookup'] = !empty( $subInfo['user_id'] ) ? array( 'user_id' => $subInfo['user_id'] ) : array( 'email' => $subInfo['email'] );
if( !empty( $_REQUEST['unsubscribe_all'] ) ) {
$subHash['unsubscribe_all'] = 'y';
$subHash['unsub_content'] = array_keys( $newsletters );
$subHash['unsubscribe_all'] = NULL;
foreach( array_keys( $newsletters ) as $nlContentId ) {
if( empty( $_REQUEST['nl_content_id'] ) || !in_array( $nlContentId, $_REQUEST['nl_content_id'] ) ) {
$subHash['unsub_content'][] = $nlContentId;
$feedback['success'] = tra( "Your subscriptions were updated." );
$feedback['error'] = tra( "Subscriptions were not updated." );
foreach( $unsubs as $sub ) {
if( !empty( $sub['unsubscribe_all'] ) ) {
$subInfo['unsubscribe_all'] = TRUE;
$gBitSmarty->assign( 'subInfo', $subInfo );
$gBitSmarty->assign( 'unsubs', $unsubs );
$mid = 'bitpackage:newsletters/user_subscriptions.tpl';
$gBitSmarty->assign('url_subscribe', httpPrefix(). $foo["path"]);
$user_email = $gBitUser->isRegistered() ? $gBitUser->mInfo['email'] : '';
$gBitSmarty->assign('email', $user_email);
if( isset ( $_REQUEST["subscribe"] ) && !empty( $_REQUEST["email"] ) ) {
$gBitSystem->verifyPermission( 'p_newsletters_subscribe' );
$feedback['success'] = tra( "Thanks for your subscription. You will receive an email soon to confirm your subscription. No newsletters will be sent to you until the subscription is confirmed." );
if( !$gBitUser->hasPermission( 'p_subscribe_email' ) ) {
$_REQUEST["email"] = $gBitUser->mInfo['email'];
// Now subscribe the email address to the newsletter
$gContent->subscribe( $_REQUEST["email"], TRUE, TRUE );
/*if( !$subscribe && $gContent->isValid() ) {
$mid = 'bitpackage:newsletters/view_newsletter.tpl';
$title = "View Newsletter";
$newsletters = $gContent->getList( $listHash );
for( $i = 0; $i < count( $newsletters ); $i++ ) {
if ($userlib->object_has_one_permission($newsletters["data"][$i]["nl_id"], 'newsletters')) {
$newsletters["data"][$i]["individual"] = 'y';
if ($userlib->object_has_permission($user, $newsletters["data"][$i]["nl_id"], 'newsletter', 'p_subscribe_newsletters')) {
$newsletters["data"][$i]["individual_p_subscribe_newsletters"] = 'y';
$newsletters["data"][$i]["individual_p_subscribe_newsletters"] = 'n';
|| $userlib->object_has_permission($user, $newsletters["data"][$i]["nl_id"], 'newsletter', 'p_admin_newsletters')) {
$newsletters["data"][$i]["individual_p_subscribe_newsletters"] = 'y';
$newsletters["data"][$i]["individual"] = 'n';
$mid = 'bitpackage:newsletters/newsletters.tpl';
$title = "List Newsletters";
$gBitSmarty->assign( 'feedback', $feedback );
$gBitSystem->display( $mid, $title );
|