Hey,
i has just edited the code from the newsletter module, that the unsubscribe url can be used to remove the entered user!
The problem what i've found is, the forms cut of the mailaddress in the header, so i just change it to the member id and edit the data functions. Here the changes from me:
Unsubscribe.php
function unsubscribe($data, $form) {
$email = $this->urlParams['Email'];
/***********************************************/
// Change to get Data by ID
// $member = DataObject::get_one( 'Member', "Email = '{$email}'" );
$member = DataObject::get_by_id( 'Member', $email );
/***********************************************/
if(!$member){
/***********************************************/
// Change to get Data by ID
// $member = DataObject::get('Member', "`EmailAddress` = '$email'");
$member = DataObject::get_by_id('Member', $email);
/***********************************************/
}
if( $data['MailingLists'] ) {
foreach( array_keys( $data['MailingLists'] ) as $listID ){
$nlType = DataObject::get_by_id( 'NewsletterType', $listID );
$nlTypeTitles[]= $nlType->Title;
$this->unsubscribeFromList( $member, DataObject::get_by_id( 'NewsletterType', $listID ) );
}
$sORp = (sizeof($nlTypeTitles)>1)?"newsletters ":"newsletter ";
//means single or plural
$nlTypeTitles = $sORp.implode(", ", $nlTypeTitles);
$url = "unsubscribe/done/".$member->Email."/".$nlTypeTitles;
Director::redirect($url);
} else {
$form->addErrorMessage('MailingLists', _t('Unsubscribe.NOMLSELECTED', 'You need to select at least one mailing list to unsubscribe from.'), 'bad');
Director::redirectBack();
}
}
...
class Unsubscribe_MailingListForm extends Form {
protected $memberEmail;
/****Create an ID-Environment variable****************/
protected $memberID;
/***********************************************/
function __construct( $controller, $name, $member, $email ) {
if($member) {
$this->memberEmail = $member->Email;
/*****Load the Member.ID to the variable**************/
$this->memberID = $member->ID;
/***********************************************/
}
$fields = new FieldSet();
$actions = new FieldSet();
if($member) {
// get all the mailing lists for this user
$lists = $this->getMailingLists( $member );
} else {
$lists = false;
}
if( $lists ) {
$fields->push( new LabelField('SubscribedToLabel', _t('Unsubscribe.SUBSCRIBEDTO', 'You are subscribed to the following lists:')) );
foreach( $lists as $list ) {
$fields->push( new CheckboxField( "MailingLists[{$list->ID}]", $list->Title ) );
}
$actions->push( new FormAction('unsubscribe', _t('Unsubscribe.UNSUBSCRIBE', 'Unsubscribe') ) );
} else {
$fields->push( new LabelField('NotSubscribedToLabel',sprintf(_t('Unsubscribe.NOTSUBSCRIBED', 'I\'m sorry, but %s doesn\'t appear to be in any of our mailing lists.'), $email) ) );
}
parent::__construct( $controller, $name, $fields, $actions );
}
function FormAction() {
/**** Change the FormAction Button to submit the ID******/
//return $this->controller->RelativeLink() . "index/{$this->memberEmail}?executeForm=" . $this->name;
return $this->controller->RelativeLink() . "unsubscribe/{$this->memberID}/";
/***********************************************/
}
protected function getMailingLists( $member ) {
// get all the newsletter types that the member is subscribed to
return DataObject::get( 'NewsletterType', "`MemberID`='{$member->ID}'", null, "LEFT JOIN `Group_Members` USING(`GroupID`)" );
}
}
i hope this is helpful to use the newsletter module completly.
greets Enno