protected function compile()
 {
     $this->newsletters = deserialize($this->newsletters);
     parent::compile();
     // add custom newsletter subscription Checkbox to the Form
     if (in_array('newsletter', $this->Config->getActiveModules())) {
         // newsletter subscription
         if (is_array($this->newsletters) && !empty($this->newsletters)) {
             $objChannels = $this->Database->execute('SELECT * FROM tl_newsletter_channel WHERE id IN (' . implode(',', $this->newsletters) . ')');
             if ($objChannels->numRows) {
                 $strForm = '<label for="ctrl_channels_' . $this->id . '" class="invisible">' . $this->channelsLabel . '</label>';
                 $strForm .= '<div id="ctrl_channels_' . $this->id . '" class="checkbox_container">';
                 if ($objChannels->numRows == 1) {
                     $strForm .= '<span><input type="checkbox" name="newsletter" id="opt_newsletter_' . $this->id . '_' . $objChannels->id . '" value="' . $objChannels->id . '" class="checkbox"><label for="opt_newsletter_' . $this->id . '_' . $objChannels->id . '">' . $objChannels->checkbox_label . '</label></span>';
                 } else {
                     while ($objChannels->next()) {
                         $strForm .= '<span><input type="checkbox" name="newsletter[]" id="opt_newsletter_' . $this->id . '_' . $objChannels->id . '" value="' . $objChannels->id . '" class="checkbox"><label for="opt_newsletter_' . $this->id . '_' . $objChannels->id . '">' . $objChannels->checkbox_label . '</label></span>';
                     }
                 }
                 $strForm .= '</div>';
             }
         }
         $this->Template->fields .= $strForm;
     }
 }
    /**
     * Inject Javascript to preselect newsletters
     * @return string
     */
    public function generate()
    {
        $parentResult = parent::generate();
        if (TL_MODE == 'BE') {
            return $parentResult;
        }
        if (\Input::post('FORM_SUBMIT') == 'tl_registration') {
            return $parentResult;
        }
        $script = <<<SCRIPT
<script language="JavaScript">
jQuery('#tl_registration input[name="newsletter[]"]').prop('checked', true);
</script>
SCRIPT;
        return $parentResult . $script;
    }
 /**
  * Send an admin notification e-mail
  * @param integer
  * @param array
  */
 protected function sendAdminNotification($intId, $arrData)
 {
     $membergroups = deserialize($arrData['groups'], true);
     if (array_key_exists('groups', $arrData) && is_array($membergroups)) {
         $objGroup = $this->Database->prepare("SELECT * FROM tl_member_group WHERE id IN (" . implode(",", $membergroups) . ")")->execute();
         $newgroups = array();
         while ($objGroup->next()) {
             array_push($newgroups, $objGroup->name . ' (ID ' . $objGroup->id . ')');
         }
         $arrData['groups'] = serialize($newgroups);
     }
     if (array_key_exists('groupselection', $arrData)) {
         $arrGroup = $this->Database->prepare("SELECT * FROM tl_member_group WHERE id = ?")->execute($arrData['groupselection'])->fetchAssoc();
         $arrData['groupselection'] = $arrGroup['name'] . ' (ID ' . $arrData['groupselection'] . ')';
     }
     if (array_key_exists('dateAdded', $arrData)) {
         $arrData['dateAdded'] = $this->parseDate($GLOBALS['TL_CONFIG']['dateFormat'], $arrData['dateAdded']);
     }
     parent::sendAdminNotification($intId, $arrData);
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['registration_plus'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id);
     // get id from FormSession
     if ($_POST) {
         $intId = FormSession::getSubmissionId($strFormId);
     }
     $this->objForm = new MemberRegistrationPlusForm($this->objModel, $intId ?: 0);
     $this->editable = $this->objForm->getEditableFields();
     // Return if there are no editable fields
     if (!is_array($this->editable) || empty($this->editable)) {
         return '';
     }
     return parent::generate();
 }
 public function generate()
 {
     if (TL_MODE == 'BE') {
         $objTemplate = new \BackendTemplate('be_wildcard');
         $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['loginregistration'][0]) . ' ###';
         $objTemplate->title = $this->headline;
         $objTemplate->id = $this->id;
         $objTemplate->link = $this->name;
         $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id;
         return $objTemplate->parse();
     }
     // required by ModuleRegistration::generate();
     $this->editable = array('username', 'password');
     $this->allowedMailDomains = deserialize($this->allowedMailDomains, true);
     $this->domainCheck = false;
     $this->domainList = $this->getDomainList();
     if (is_array($this->domainList) && !empty($this->domainList)) {
         $this->domainCheck = true;
     }
     // Set the last page visited
     if ($this->redirectBack) {
         $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer();
     }
     // Redirect to the jumpTo page if user is logged in and permanentRedirect is enables
     if (FE_USER_LOGGED_IN && $this->redirectPermanent) {
         $this->redirect($this->getJumpTo());
     }
     // Login
     if (\Input::post('FORM_SUBMIT') == 'tl_login') {
         // Check whether username and password are set
         if (empty($_POST['username']) || empty($_POST['password'])) {
             $_SESSION['LOGIN_ERROR'] = $GLOBALS['TL_LANG']['MSC']['emptyField'];
             $this->reload();
         }
         $strRedirect = $this->getJumpTo();
         $this->import('FrontendUser', 'User');
         // Auto login is not allowed
         if (isset($_POST['autologin']) && !$this->autologin) {
             unset($_POST['autologin']);
             \Input::setPost('autologin', null);
         }
         // Login existing user, or try to get username-domain-combination or register
         if ($this->User->login()) {
             $this->redirect($strRedirect);
         } else {
             $username = $_POST['username'];
             if ($this->domainCheck || \Validator::isEmail($username)) {
                 if (($username = $this->getValidDomainUsername()) === null) {
                     $this->reload();
                 }
                 // overwrite the username
                 $username = strtolower($username);
                 $_POST['username'] = $username;
                 \Input::setPost('username', $username);
                 if ($this->User->login()) {
                     $this->redirect($strRedirect);
                 }
                 $this->registerUser($username);
             }
         }
         $this->reload();
     }
     // Logout and redirect to the website root if the current page is protected
     if (\Input::post('FORM_SUBMIT') == 'tl_logout') {
         global $objPage;
         $this->import('FrontendUser', 'User');
         $strRedirect = \Environment::get('request');
         // Redirect to last page visited
         if ($this->redirectBack && strlen($_SESSION['LAST_PAGE_VISITED'])) {
             $strRedirect = $_SESSION['LAST_PAGE_VISITED'];
         } elseif ($objPage->protected) {
             $strRedirect = \Environment::get('base');
         }
         // Logout and redirect
         if ($this->User->logout()) {
             $this->redirect($strRedirect);
         }
         $this->reload();
     }
     return parent::generate();
 }