yanc-cb - newsletter plugin multiple newsletter

16 years 4 months ago #51900 by guilliam
hello @all,

i have:
cb 1.0.2
yanc 1.5

both seems to work pretty fine except that upon registration if you have multiple newsletters it doesnt show other newsletters but only shows the first yanc newsletter in the list.

i have made drastic attempts modifying /components/com_comprofiler/plugin/user/plug_yancintegration/yanc.php

BUT to no avail.

my main question is how can we show the other newsletter selections during the registration is we have multiple newsletters?

below is the code of that file.
attached as well is the zip of the file.

- g

[code:1]
<?php
/**
* Newsletter Tab Class for handling the CB tab api
* @version $Id: yanc.php 396 2006-08-24 14:16:31Z beat $
* @package Community Builder
* @subpackage yanc.php
* @author Beat
* @copyright (C) JoomlaJoe and Beat, www.joomlapolis.com
* @license www.gnu.org/copyleft/gpl.html GNU/GPL
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

$_PLUGINS->registerFunction( 'onUserActive', 'userActivated','getNewslettersTab' );
$_PLUGINS->registerFunction( 'onAfterDeleteUser', 'userDeleteTab','getNewslettersTab' );

DEFINE('_NEWSLETTERFILE','/administrator/components/com_yanc/classes/class.yancsubscription.php');

class getNewslettersTab extends cbTabHandler {
/**
* Constructor
*/
function getNewslettersTab() {
$this->cbTabHandler();
}
// function getDisplayTab($tab,$user,$ui) {
// }
/**
* Generates the HTML to display the user edit tab
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @returns mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function getEditTab( $tab, $user, $ui) {
global $my, $mainframe, $_POST;
if(intval($my->id) < 1){
mosNotAuth();
return false;
}
if(!$this->_CheckYancInstalled()) {
return _UE_NEWSLETTERNOTINSTALLED;
}
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();

$return="";

if ($user->id) {
$rows = $newslettersSubscriptions->getSubscriberLists($user);

if (isset($_POST)) {
$postedLists = mosGetParam($_POST, 'newsLitems', array());
$postedHtml = mosGetParam($_POST, 'newsLhtml', 1);

for ($i = 0, $n=count($rows); $i < $n; $i++) {
$rows[$i]->subscribed = in_array($rows[$i]->id,$postedLists);
$rows[$i]->receive_html = $postedHtml;
}
}
} else {
$params=$this->params;
$newslettersRegList=$params->get('newslettersRegList');
$listsArray = (isset($newslettersRegList)) ? explode("|*|", $newslettersRegList) : null;
$rows = $newslettersSubscriptions->getLists($my, $listsArray);

$postedLists = mosGetParam($_POST, 'newsLitems', array());
$postedHtml = mosGetParam($_POST, 'newsLhtml', 1);

for ($i = 0, $n=count($rows); $i < $n; $i++) {
$rows[$i]->subscribed = in_array($rows[$i]->id,$postedLists);
$rows[$i]->receive_html = $postedHtml;
}
}

if(count($rows)==0) {
$return = _UE_NONEWSLETTERS;
} else {
if($tab->description != null) $return .= "\t\t<div class=\"tab_Description\">".unHtmlspecialchars(getLangDefinition($tab->description))."</div>\n";
$return .= $this->_getFormattedNewsletters($rows, false, _UE_NEWSLETTER_NAME, _UE_NEWSLETTER_DESCRIPTION);
}
return $return;
}

//private method:
function _getFormattedNewsletters($rows, $linesStyle, $name=_UE_NEWSLETTER_NAME, $desc=_UE_NEWSLETTER_DESCRIPTION) {
$htmltext = array();
$htmltext[] = mosHTML::makeOption( '1', _UE_NEWSLETTER_HTML."&nbsp;&nbsp;&nbsp;" );
$htmltext[] = mosHTML::makeOption( '0', _UE_NEWSLETTER_TEXT );

$return = "<div class='newslettersList'>"
. "<table style='width:100%; border:0px;' cellspacing='0' cellpadding='0'>\n";
if (!$linesStyle) $return .= "\t<tr>\n"
. "\t\t<th class='captionCell'>".$name."</th>\n"
. "\t\t<th class='captionCell'>".$desc."</th>\n"
. "\t</tr>\n";
foreach ($rows AS $row) {
$return .= "\t<tr>\n";
$return .= "\t\t<td style='width:".($linesStyle ? "2%" : "31%"«»).";' class='fieldCell'>";
$return .= "<input type='checkbox' style='margin-right: 0px;' name='newsLitems[]' value=\"".$row->id."\" ";
if ($row->subscribed) $return .= 'checked="checked" ';
$return .= "/> ";
if ($linesStyle) $return .= "<br /><br /></td>\n\t\t<td style='width:98%;' class='fieldCell'>";
$return .= "<span class='captionCell'>".getLangDefinition($row->list_name)."</span>";
if ($row->subscribed && (!$row->confirmed)) $return .= "<br /><span class='fieldError'>("._UE_NEWSLETTER_NOT_CONFIRMED."«»)</span>";
if ($linesStyle) $return .= "<br />";
else $return .= "<br /><br /></td>\n\t\t<td class='fieldCell'>";
$return .= "<span class='fieldCell'>".getLangDefinition($row->list_desc)."</span>"."<br /><br /></td>\n";
$return .= "\t</tr>\n";
}
//$return .= "\t<tr>\n\t\t<td class='captionCell' colspan='2'>" . "<span class='captionCell' id='newsLettersFormatTitle'>" ._UE_NEWSLETTER_FORMAT_TITLE . "</span>" . "</td>\n\t</tr>\n";
$return .= "\t<tr>\n\t\t<td style='width:20%;' class='fieldCell'".($linesStyle ? " colspan='2'" : ""«»).">";
//$return .= "<span class='fieldCell' id='newsLettersFormatField'>"._UE_NEWSLETTER_FORMAT_FIELD."</span>";
if ($linesStyle) $return .= "";
else $return .= "</td>\n\t\t<td class='fieldCell'>";
$return .= moscomprofilerHTML::radioList($htmltext, 'newsLhtml','class="inputbox" size="1"', 'value', 'text', $rows[0]->receive_html );
$return .= "</td>\n";

$return .= "\t</tr>\n";
$return .= "</table>";
$return .= "</div>";
return $return;
}
/**
* Saves the user edit tab postdata into the tab's permanent storage
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @param array _POST data for saving edited tab content as generated with getEditTab
* @returns mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function saveEditTab($tab, &$user, $ui, $postdata) {
global $my, $mainframe, $_POST;
if(intval($my->id) < 1) {
mosNotAuth();
return;
}
if(!$this->_CheckYancInstalled()) {
return;
}
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();

$lists = mosGetParam($_POST, 'newsLitems', array());
$html = mosGetParam($_POST, 'newsLhtml', 0);
$subscribemessage = !($ui==2 && $user->approved && $user->confirmed);
$result = $newslettersSubscriptions->saveMassSubscribe($user, $lists, $html, $subscribemessage);
if ($result) {
$this->_setErrorMSG($result);
}
}
/**
* Generates the HTML to display the registration tab/area
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed (here null)
* @param int 1 for front-end, 2 for back-end
* @return mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function getDisplayRegistration($tab, $user, $ui) {
global $my, $mainframe, $_POST;;

if(!$this->_CheckYancInstalled()) {
return null;
}
if (true) {
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();
$params=$this->params;
$newslettersRegList=$params->get('newslettersRegList');
$listsArray = (isset($newslettersRegList)) ? explode("|*|", $newslettersRegList) : null;
$lists = $newslettersSubscriptions->getLists($my, $listsArray);
if (count($lists) > 0){

$postedLists = mosGetParam($_POST, 'newsLitems', array());
$postedHtml = mosGetParam($_POST, 'newsLhtml', 1);

$lists[0]->receive_html = $postedHtml;
for ($i = 0, $n=count($lists); $i < $n; $i++) {
$lists[$i]->subscribed = in_array($lists[$i]->id,$postedLists);
$lists[$i]->confirmed = $lists[$i]->subscribed; // avoid display "not confirmed" on registration server-validation error.
}
$return = "\t<tr>\n";
$return .= "\t\t<td class='titleCell' colspan='1'><br /><br />" . _UE_NEWSLETTER_SUBSCRIBE . "<br /><br /><br />" . _UE_NEWSLETTER_FORMAT_TITLE . "</td>\n";

$return .= "\t\t<td class='fieldCell'><br /><br />";
$return .= $this->_getFormattedNewsletters($lists, true, _UE_NEWSLETTER_NAME_REG, _UE_NEWSLETTER_DESCRIPTION_REG);
$return .= "</td>";
$return .= "\t</tr>\n";
$return .= "\t<tr><td class='titleCell'>&nbsp;</td><td class='fieldCell' id='newslettersSpacer'>&nbsp;</td></tr>\n";
return $return;
}
}
}
/**
* Saves the registration tab/area postdata into the tab's permanent storage
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed (here null)
* @param int 1 for front-end, 2 for back-end
* @param array _POST data for saving edited tab content as generated with getEditTab
* @return boolean : either string HTML for tab content, or false if ErrorMSG generated
*/
function saveRegistrationTab($tab, &$user, $ui, $postdata) {
global $ueConfig, $mainframe;

if(!$this->_CheckYancInstalled()) {
return true;
}
$result = true;
if (true) {
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();

$lists = mosGetParam($postdata, 'newsLitems', array());
$html = mosGetParam($postdata, 'newsLhtml', 1);

$sendEmail = (($ueConfig!="1"«») and ($ueConfig!="1"«»));

$result = $newslettersSubscriptions->saveMassSubscribe($user, $lists, $html, $sendEmail);
if ($result !== true) {
$this->_setErrorMSG($result);
$result = false;
}
}
return $result;
}
/**
* Called once ConfirmationCode verified and user found and approved by moderator if needed
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @returns mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function userActivated($user, $success) {
global $ueConfig, $mainframe, $mosConfig_uniquemail;

if(!$this->_CheckYancInstalled()) {
return true;
}
if ($success) {
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();
if ($mosConfig_uniquemail=='1') {
$newslettersSubscriptions->updateUnregisteredSubscriber($user);
}
$confirmCode = md5($user->id);
$result = $newslettersSubscriptions->confirmSubscriber($confirmCode);
if ($result !== NULL) {
$this->_setErrorMSG($result);
return false;
}
} else { //MJ: what to do else here ?
return true;
}
return true;
}
/**
* Called when a user is deleted from backend (prepare future unregistration)
* @param object tab reflecting the tab database entry
* @param object mosUser reflecting the user being displayed
* @param int 1 for front-end, 2 for back-end
* @returns mixed : either string HTML for tab content, or false if ErrorMSG generated
*/
function userDeleteTab($user, $success) {
global $ueConfig, $mainframe;

if(!$this->_CheckYancInstalled()) {
return;
}
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();

$newslettersSubscriptions->deleteSubscriber($user);
}
// Additional public method:
/**
* Returns list of all newsletters available
* @return array of newsletter objects
*/
function getNewslettersList() {
global $my, $mainframe;

if(!$this->_CheckYancInstalled()) {
return false;
}
require_once( $mainframe->getCfg('absolute_path') . _NEWSLETTERFILE );
$newslettersSubscriptions = new YancSubscription();

return $newslettersSubscriptions->getLists($my);
}

// Private Method:
/**
* Checks if newsletters component installed
* @return boolean true =installed, false = not
*/
function _CheckYancInstalled() {
global $database, $mainframe;
if(!file_exists($mainframe->getCfg('absolute_path') . _NEWSLETTERFILE)) {
return false;
}
$query = "SELECT COUNT( * ) FROM #__components WHERE link LIKE '%com_yanc%'";
$database->setQuery( $query );
if ($database->LoadResult() < 1) {
return false;
}
return true;
}

function loadNewslettersList($name,$value,$control_name) {
$newslettersList = $this->getNewslettersList();
$newslettersRegList = array();
if ($newslettersList !== false) {
foreach ($newslettersList AS $nl) {
$newslettersRegList[] = mosHTML::makeOption( $nl->id, $nl->list_name);
}
}
$valAsObj = (isset($value)) ?
array_map(create_function('$v', '$o=new stdClass(); $o->value=$v; return $o;'), explode("|*|", $value ))
: null;

return moscomprofilerHTML::«»selectList( $newslettersRegList, $control_name .'[]', 'size="4" multiple="multiple"', 'value', 'text', $valAsObj, true );
}

} // end class getNewslettersTab.
?>[/code:1]

Attachment yanc-cd0746c1f43bf47a02faa66205fedaf1.zip not found

Attachments:

Please Log in to join the conversation.

16 years 4 months ago #51920 by beat
should work in the core plugin with ctrl-click or cmd(mac)-click to select multiple newsletters in the list in the backend, no :huh: ?

Beat - Community Builder Team Member

Before posting on forums: Read FAQ thoroughly -- Help us spend more time coding by helping others in this forum, many thanks :)
CB links: Our membership - CBSubs - Templates - Hosting - Forge - Send me a Private Message (PM) only for private/confidential info

Please Log in to join the conversation.

16 years 4 months ago #51935 by guilliam
beat wrote:

should work in the core plugin with ctrl-click or cmd(mac)-click to select multiple newsletters in the list in the backend, no :huh: ?


EDIT: got it now.

its in:

backend -> components -> cb -> plugin management -> click on the yanc plugin

thank you again. didnt saw that one.

- g

Post edited by: guilliam, at: 2007/12/10 03:07

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.216 seconds

Facebook Twitter LinkedIn