public function createNewUser($userId, $arrData)
 {
     $arrNewsletters = deserialize($arrData['newsletter'], true);
     // Return if there are no newsletters
     if (!is_array($arrNewsletters)) {
         return;
     }
     $time = time();
     // Add recipients
     foreach ($arrNewsletters as $intNewsletter) {
         $intNewsletter = intval($intNewsletter);
         if ($intNewsletter < 1) {
             continue;
         }
         $objRecipient = $this->Database->prepare("SELECT COUNT(*) AS total FROM tl_newsletter_recipients WHERE pid=? AND email=?")->execute($intNewsletter, $arrData['email']);
         if ($objRecipient->total < 1) {
             $subscriber = new Subscriber($arrData['email']);
             $subscriber->tstamp = $time;
             $subscriber->salutation = $arrData['gender'];
             $subscriber->firstname = $arrData['firstname'];
             $subscriber->lastname = $arrData['lastname'];
             $subscriber->company = $arrData['company'];
             $subscriber->addedOn = $time;
             $subscriber->ip = $this->anonymizeIp($this->Environment->ip);
             $subscriber->pid = $intNewsletter;
             $subscriber->active = '';
             $subscriber->token = '';
             // account will get activated by registration token from registration E-Mail
             $subscriber->registered = $time;
             $subscriber->add();
         }
     }
 }
 /**
  * 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);
     }
 }