/** * Add a new recipient */ protected function removeRecipient() { $arrChannels = $this->Input->post('channels'); $arrChannels = array_intersect($arrChannels, $this->nl_channels); // see #3240 // Check the selection if (!is_array($arrChannels) || count($arrChannels) < 1) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels']; $this->reload(); } $arrSubscriptions = array(); $email = \Idna::encodeEmail($this->Input->post('email', true)); $subscriber = new Subscriber($email); // Get active subscriptions $objSubscription = $this->Database->prepare("SELECT pid FROM tl_newsletter_recipients WHERE email=? AND active=1")->execute($email); if ($objSubscription->numRows) { $arrSubscriptions = $objSubscription->fetchEach('pid'); } $arrRemove = array_intersect($arrChannels, $arrSubscriptions); // Return if there are no subscriptions to remove if (!is_array($arrRemove) || count($arrRemove) < 1) { $_SESSION['UNSUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['unsubscribed']; $this->reload(); } // check for cleverreach support $objChannel = $this->Database->execute("SELECT id FROM tl_newsletter_channel WHERE cleverreach_active = 1 AND id IN(" . implode(',', array_map('intval', $arrRemove)) . ")"); // TODO: multiple channel unsubscription $subscriber->getByChannel($arrRemove[0]); // Remove subscriptions $subscriber->remove($arrRemove); // optional Cleverreach Deletion if ($objChannel->numRows > 0) { $subscriber->removeFromCR($objChannel->fetchEach('id')); } // Get channels $objChannels = $this->Database->execute("SELECT title FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', $arrRemove)) . ")"); $arrChannels = $objChannels->fetchEach('title'); // HOOK: post unsubscribe callback if (isset($GLOBALS['TL_HOOKS']['removeRecipient']) && is_array($GLOBALS['TL_HOOKS']['removeRecipient'])) { foreach ($GLOBALS['TL_HOOKS']['removeRecipient'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($varInput, $arrRemove); } } global $objPage; // Redirect to jumpTo page if (strlen($this->jumpTo) && $this->jumpTo != $objPage->id) { $objNextPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($this->jumpTo); if ($objNextPage->numRows) { $this->redirect($this->generateFrontendUrl($objNextPage->fetchAssoc())); } } if ($subscriber->sendUnSubscribeMail($arrRemove)) { $this->reload(); } }