/** * Generate module */ protected function compile() { // Overwrite default template if ($this->nl_template) { $this->Template = new \FrontendTemplate($this->nl_template); $this->Template->setData($this->arrData); } $inputHelper = new NlpInputHelper($submitted); $forms = $inputHelper->addEmailField($objChannel); // Unsubscribe if ($this->Input->post('FORM_SUBMIT') == $this->strFormId && $this->Input->post('email', true)) { $this->removeRecipient(); } $blnHasError = false; // Error message if (strlen($_SESSION['UNSUBSCRIBE_ERROR'])) { $blnHasError = true; $this->Template->mclass = 'danger'; $this->Template->message = $_SESSION['UNSUBSCRIBE_ERROR']; $_SESSION['UNSUBSCRIBE_ERROR'] = ''; } // Confirmation message if (strlen($_SESSION['UNSUBSCRIBE_CONFIRM'])) { $this->Template->mclass = 'success'; $this->Template->message = $_SESSION['UNSUBSCRIBE_CONFIRM']; $_SESSION['UNSUBSCRIBE_CONFIRM'] = ''; } $arrChannels = array(); $objChannel = $this->Database->execute("SELECT id, title FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', $this->nl_channels)) . ") ORDER BY title"); // Get titles while ($objChannel->next()) { $arrChannels[$objChannel->id] = $objChannel->title; } // Default template variables $this->Template->forms = $forms; $this->Template->channels = $arrChannels; $this->Template->showChannels = !$this->nl_hideChannels; $this->Template->submit = specialchars($GLOBALS['TL_LANG']['MSC']['unsubscribe']); $this->Template->channelsLabel = $GLOBALS['TL_LANG']['MSC']['nl_channels']; $this->Template->emailLabel = $GLOBALS['TL_LANG']['MSC']['emailAddress']; $this->Template->action = $objPage->numRows ? $this->generateFrontendUrl($objPage->row()) : $this->getIndexFreeRequest(); $this->Template->formId = $this->strFormId; $this->Template->id = $this->id; $this->Template->hasError = $blnHasError; }
/** * Generate module */ protected function compile() { // Overwrite default template if ($this->nl_template) { $this->Template = new \FrontendTemplate($this->nl_template); $this->Template->setData($this->arrData); } $arrChannels = array(); $objChannel = $this->Database->execute("SELECT * FROM tl_newsletter_channel WHERE id IN(" . implode(',', array_map('intval', $this->nl_channels)) . ") ORDER BY title"); // Get titles while ($objChannel->next()) { $arrChannels[$objChannel->id] = $objChannel->title; $additionalInputs = deserialize($objChannel->subscribeplus_inputs); if (is_array($additionalInputs) && count($additionalInputs) > 0) { $submitted = $this->Input->post('FORM_SUBMIT') == $this->strFormId; $inputHelper = new NlpInputHelper($submitted); $forms = $inputHelper->addInputFields($objChannel); $this->doNotSubmit = $inputHelper->hasErrors(); } } // Get Form Action "jumpTo" page $objPage = $this->Database->prepare("SELECT id, alias FROM tl_page WHERE id=?")->limit(1)->execute($this->jumpTo); // remove token from request url, to prevent wrong token invalid messages $url = parse_url(\Environment::get('indexFreeRequest')); // Default template variables $this->Template->forms = $forms; $this->Template->channels = $arrChannels; $this->Template->showChannels = !$this->nl_hideChannels; $this->Template->submit = specialchars($GLOBALS['TL_LANG']['MSC']['subscribe']); $this->Template->channelsLabel = $GLOBALS['TL_LANG']['MSC']['nl_channels']; $this->Template->emailLabel = $GLOBALS['TL_LANG']['MSC']['emailAddress']; $this->Template->formId = $this->strFormId; $this->Template->id = $this->id; // Activate e-mail address if ($this->Input->get('token') && !$_SESSION['SUBSCRIBED']) { // formgen subscription > module subscription, prevent multiple activation $this->activateRecipient(); return; } if ($_SESSION['SUBSCRIBED']) { unset($_SESSION['SUBSCRIBED']); } // Subscribe if ($this->Input->post('FORM_SUBMIT') == $this->strFormId && !$this->doNotSubmit) { $this->addRecipient(); } $blnHasError = false; // Error message if (strlen($_SESSION['SUBSCRIBE_ERROR'])) { $blnHasError = true; $this->Template->mclass = 'danger'; $this->Template->message = $_SESSION['SUBSCRIBE_ERROR']; $_SESSION['SUBSCRIBE_ERROR'] = ''; } // Confirmation message if (strlen($_SESSION['SUBSCRIBE_CONFIRM'])) { $this->Template->mclass = 'success'; $this->Template->message = $_SESSION['SUBSCRIBE_CONFIRM']; $_SESSION['SUBSCRIBE_CONFIRM'] = ''; } $this->Template->action = ($objPage->numRows ? $this->generateFrontendUrl($objPage->row()) : $url['path']) . ($blnHasError || $this->doNotSubmit || $this->Template->message ? '#' . $this->strFormId : ''); $this->Template->hasError = $blnHasError || $this->doNotSubmit; }