public function submitPlus(DataContainer $dc)
 {
     $subscriber = new Subscriber($dc->activeRecord->email);
     $subscriber->setByDc($dc);
     $cid = $dc->activeRecord->pid;
     $time = time();
     // set active
     if ($dc->activeRecord->active == 1) {
         $subscriber->activated = $time;
         $subscriber->deactivated = '';
     } else {
         $subscriber->deactivated = $time;
     }
     if ($this->isCRActive($cid)) {
         // new record - added manually --> call add() method
         if (!$dc->activeRecord->addedOn && !$dc->activeRecord->tstamp) {
             $subscriber->registered = $time;
             $subscriber->addToCR();
         }
         // existing record - call update() method
         if ($dc->activeRecord->tstamp) {
             $subscriber->updateCR();
         }
     }
 }
 /**
  * Add a new recipient
  */
 protected function addRecipient()
 {
     global $objPage;
     $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['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['noChannels'];
         $this->reload();
     }
     $email = \Idna::encodeEmail($this->Input->post('email', true));
     $subscriber = new Subscriber($email);
     $arrSub = $subscriber->getActiveSubscriptionIds();
     // Get new subscriptions
     $arrNew = array_diff($arrChannels, $arrSub);
     // Return if there are no new subscriptions
     if (!is_array($arrNew) || count($arrNew) < 1) {
         $_SESSION['SUBSCRIBE_ERROR'] = $GLOBALS['TL_LANG']['ERR']['subscribed'];
         $this->redirect($this->generateFrontendUrl($objPage->row()) . '#' . $this->strFormId);
     }
     // Remove old subscriptions that have not been activated yet
     $subscriber->dropInactiveSubscriptions();
     $time = time();
     $strToken = md5(uniqid(mt_rand(), true));
     // check if additional input fields are required for this channel
     $objChannel = $this->Database->execute("SELECT * FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', $arrNew)) . ")");
     $addPlusFields = false;
     $channelInfo = array();
     while ($objChannel->next()) {
         $check = deserialize($objChannel->subscribeplus_inputs);
         if (is_array($check) && count($check) > 0) {
             $addPlusFields = true;
         }
         $channelInfo[$objChannel->id] = $objChannel->row();
     }
     foreach ($arrNew as $cid) {
         $subscriber->tstamp = $time;
         $subscriber->pid = $cid;
         $subscriber->addedOn = $time;
         $subscriber->ip = $this->anonymizeIp($this->Environment->ip);
         $subscriber->token = $strToken;
         $subscriber->active = '';
         $subscriber->registered = $time;
         if ($addPlusFields) {
             foreach ($GLOBALS['TL_DCA']['tl_subscribe_plus']['fields'] as $name => $form) {
                 $subscriber->{$name} = $this->Input->post($name) ? $this->Input->post($name) : '';
             }
         }
         // Add new subscriptions
         $subscriber->add();
         if (array_key_exists($cid, $channelInfo)) {
             if ($channelInfo[$cid]['cleverreach_active'] == 1) {
                 $subscriber->addToCR();
             }
         }
     }
     // 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()));
         }
     }
     // Activation e-mail
     if ($subscriber->sendActivationMail($objChannel->fetchEach('id'))) {
         $this->redirect($this->generateFrontendUrl($objPage->row()) . '#' . $this->strFormId);
     }
 }