newsletters
[ class tree: newsletters ] [ index: newsletters ] [ all elements ]

Source for file sub.php

Documentation is available at sub.php

  1. <?php
  2. /**
  3.  * @version        $Header$
  4.  *  Copyright (c) 2005 bitweaver.org
  5.  *  All Rights Reserved. See below for details and a complete list of authors.
  6.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
  7.  *
  8.  *  created 2005/12/10
  9.  *
  10.  * @package newsletters
  11.  * @author spider <spider@steelsun.com>
  12.  */
  13.  
  14. /** 
  15.  * Initialization
  16.  */
  17. require_once( '../kernel/setup_inc.php' );
  18. include_once( NEWSLETTERS_PKG_PATH.'BitNewsletterMailer.php' );
  19.  
  20. $gBitSystem->verifyPackage( 'newsletters' );
  21.  
  22. if( !$gBitUser->isRegistered() && !$gBitUser->hasPermission( 'p_newsletters_subscribe' ) && empty( $_REQUEST['c'] ) ) {
  23.     $gBitSystem->fatalError( tra("You must be logged in to subscribe to newsletters"));
  24. }
  25.  
  26. require_once( NEWSLETTERS_PKG_PATH.'lookup_newsletter_inc.php' );
  27.  
  28. $feedback = array();
  29.  
  30. /* List newsletters */
  31. $listHash = array();
  32. $newsletters = $gContent->getList( $listHash );
  33. $gBitSmarty->assign_by_ref( 'subs', BitNewsletter::getUserSubscriptions( $gBitUser->getField( 'user_id' ), $gBitUser->getField( 'email' ) ) );
  34. $gBitSmarty->assign_by_ref('newsletters', $newsletters );
  35.  
  36. $foo = parse_url($_SERVER["REQUEST_URI"]);
  37. $gBitSmarty->assign('url_subscribe', httpPrefix(). $foo["path"]);
  38.  
  39. $subinfo = array();
  40. $unsubs = array();
  41.  
  42. // We have a url_code from a clicked link in an email
  43. if( isset( $_REQUEST['c'] ) && strlen( $_REQUEST['c'] ) == 32 && ($subInfo = BitNewsletterMailer::lookupSubscription( array( 'url_code' => $_REQUEST['c'] ) )) ) {
  44. } elseif( $gBitUser->isRegistered() ) {
  45.     if( !$subInfo = BitNewsletterMailer::lookupSubscription( array( 'user_id' => $gBitUser->mUserId ) ) ) {
  46.         $subInfo = $gBitUser->mInfo;
  47.     }
  48. }
  49. if( !empty( $subInfo['user_id'] ) && BitBase::verifyId( $subInfo['user_id'] ) ) {
  50.     $lookup['user_id'] = $subInfo['user_id'];
  51. } else {
  52.     $lookup['email'] = $subInfo['email'];
  53. }
  54.  
  55. $unsubs = BitNewsletterMailer::getUnsubscriptions( $lookup );
  56.  
  57. // Update subscriptions
  58. if( isset( $_REQUEST["update"] ) ) {
  59.     $subHash['response_content_id'] = $_REQUEST['response_content_id'];
  60.     $subHash['sub_lookup'] = !empty( $subInfo['user_id'] ) ? array( 'user_id' => $subInfo['user_id'] ) : array( 'email' => $subInfo['email'] );
  61.  
  62.     if( !empty( $_REQUEST['unsubscribe_all'] ) ) {
  63.         $subHash['unsubscribe_all'] = 'y';
  64.         $subHash['unsub_content'] = array_keys( $newsletters );
  65.     } else {
  66.         $subHash['unsubscribe_all'] = NULL;
  67.         foreach( array_keys( $newsletters ) as $nlContentId ) {
  68.             if( empty( $_REQUEST['nl_content_id'] ) || !in_array( $nlContentId, $_REQUEST['nl_content_id'] ) ) {
  69.                 $subHash['unsub_content'][] = $nlContentId;
  70.             }
  71.         }
  72.     }
  73.  
  74.     if( BitNewsletterMailer::storeSubscriptions( $subHash ) ) {
  75.         $feedback['success'] = tra( "Your subscriptions were updated." );
  76.     } else {
  77.         $feedback['error'] = tra( "Subscriptions were not updated." );
  78.     }
  79.     $unsubs = BitNewsletterMailer::getUnsubscriptions( $lookup );
  80. }
  81.  
  82. if( isset( $_REQUEST["subscribe"] ) && !empty( $_REQUEST["email"] ) ) {
  83.     $gBitSystem->verifyPermission( 'p_newsletters_subscribe' );
  84.     $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." );
  85.  
  86.     if( !$gBitUser->hasPermission( 'p_subscribe_email' ) ) {
  87.         $_REQUEST["email"] = $gBitUser->mInfo['email'];
  88.     }
  89.  
  90.     // Now subscribe the email address to the newsletter
  91.     $gContent->subscribe( $_REQUEST["email"], TRUE, TRUE );
  92. }
  93.  
  94. foreach( $unsubs as $sub ) {
  95.     if( !empty( $sub['unsubscribe_all'] ) ) {
  96.         $subInfo['unsubscribe_all'] = TRUE;
  97.         break;
  98.     }
  99. }
  100.  
  101. $gBitSmarty->assign( 'subInfo', $subInfo );
  102. $gBitSmarty->assign( 'unsubs', $unsubs );
  103. $mid = 'bitpackage:newsletters/user_subscriptions.tpl';
  104. $title = "Newsletter Subscriptions";
  105.  
  106. $gBitSmarty->assign( 'feedback', $feedback );
  107.  
  108. // Display the template
  109. $gBitSystem->display( $mid, $title , array( 'display_mode' => 'display' ));
  110.  
  111. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:29 +0000 by phpDocumentor 1.5.0-lsces