/** * Run the controller and parse the template * * @return Response */ public function run() { /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_preview'); $objTemplate->base = \Environment::get('base'); $objTemplate->language = $GLOBALS['TL_LANGUAGE']; $objTemplate->title = specialchars($GLOBALS['TL_LANG']['MSC']['fePreview']); $objTemplate->charset = \Config::get('characterSet'); $objTemplate->site = \Input::get('site', true); $objTemplate->switchHref = \System::getContainer()->get('router')->generate('contao_backend_switch'); if (\Input::get('url')) { $objTemplate->url = \Environment::get('base') . \Input::get('url'); } elseif (\Input::get('page')) { $objTemplate->url = $this->redirectToFrontendPage(\Input::get('page'), \Input::get('article'), true); } else { $objTemplate->url = \System::getContainer()->get('router')->generate('contao_root', [], UrlGeneratorInterface::ABSOLUTE_URL); } // Switch to a particular member (see #6546) if (\Input::get('user') && $this->User->isAdmin) { $objUser = \MemberModel::findByUsername(\Input::get('user')); if ($objUser !== null) { $strHash = $this->getSessionHash('FE_USER_AUTH'); // Remove old sessions $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute(time() - \Config::get('sessionTimeout'), $strHash); // Insert the new session $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute($objUser->id, time(), 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash); // Set the cookie $this->setCookie('FE_USER_AUTH', $strHash, time() + \Config::get('sessionTimeout'), null, null, false, true); $objTemplate->user = \Input::post('user'); } } return $objTemplate->getResponse(); }
/** * Generate the module */ protected function compile() { $this->import('FrontendUser', 'User'); // Initialize the password widget $arrField = array('name' => 'password', 'inputType' => 'text', 'label' => $GLOBALS['TL_LANG']['MSC']['password'][0], 'eval' => array('hideInput' => true, 'mandatory' => true, 'required' => true)); $objWidget = new \FormTextField(\FormTextField::getAttributesFromDca($arrField, $arrField['name'])); $objWidget->rowClass = 'row_0 row_first even'; $strFormId = 'tl_close_account_' . $this->id; // Validate widget if (\Input::post('FORM_SUBMIT') == $strFormId) { $objWidget->validate(); // Validate the password if (!$objWidget->hasErrors()) { // The password has been generated with crypt() if (\Encryption::test($this->User->password)) { $blnAuthenticated = \Encryption::verify($objWidget->value, $this->User->password); } else { list($strPassword, $strSalt) = explode(':', $this->User->password); $blnAuthenticated = $strSalt == '' ? $strPassword === sha1($objWidget->value) : $strPassword === sha1($strSalt . $objWidget->value); } if (!$blnAuthenticated) { $objWidget->value = ''; $objWidget->addError($GLOBALS['TL_LANG']['ERR']['invalidPass']); } } // Close account if (!$objWidget->hasErrors()) { // HOOK: send account ID if (isset($GLOBALS['TL_HOOKS']['closeAccount']) && is_array($GLOBALS['TL_HOOKS']['closeAccount'])) { foreach ($GLOBALS['TL_HOOKS']['closeAccount'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->User->id, $this->reg_close, $this); } } $objMember = \MemberModel::findByPk($this->User->id); // Remove the account if ($this->reg_close == 'close_delete') { $objMember->delete(); $this->log('User account ID ' . $this->User->id . ' (' . \Idna::decodeEmail($this->User->email) . ') has been deleted', __METHOD__, TL_ACCESS); } else { $objMember->disable = 1; $objMember->tstamp = time(); $objMember->save(); $this->log('User account ID ' . $this->User->id . ' (' . \Idna::decodeEmail($this->User->email) . ') has been deactivated', __METHOD__, TL_ACCESS); } $this->User->logout(); // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { $this->jumpToOrReload($objJumpTo->row()); } $this->reload(); } } $this->Template->fields = $objWidget->parse(); $this->Template->formId = $strFormId; $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->slabel = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['closeAccount']); $this->Template->rowLast = 'row_1 row_last odd'; }
protected function compile() { $periodFactory = new PeriodFactory(); $arrSession = \Session::getInstance()->get('iso_reports'); $intConfig = (int) $arrSession[$this->name]['iso_config']; $strPeriod = (string) $arrSession[$this->name]['period']; $intStart = (int) $arrSession[$this->name]['start']; $intStop = (int) $arrSession[$this->name]['stop']; $intStatus = (int) $arrSession[$this->name]['iso_status']; $period = $periodFactory->create($strPeriod); $intStart = $period->getPeriodStart($intStart); $intStop = $period->getPeriodEnd($intStop); $dateFrom = $period->getKey($intStart); $dateTo = $period->getKey($intStop); $objData = \Database::getInstance()->query("\n SELECT\n c.id AS config_id,\n \t\tc.currency,\n o.locked AS date,\n \t\tme.firstname AS member_firstname,\n \t\tme.lastname AS member_lastname,\n \t\tme.id AS member_number,\n COUNT(DISTINCT o.id) AS total_orders,\n COUNT(DISTINCT i.id) AS total_products,\n \t\tSUM(i.quantity) AS total_items,\n SUM(i.tax_free_price * i.quantity) AS total_sales,\n " . $period->getSqlField('o.' . $this->strDateField) . " AS dateGroup\n FROM " . ProductCollection::getTable() . " o\n LEFT JOIN " . ProductCollectionItem::getTable() . " i ON o.id=i.pid\n LEFT JOIN " . OrderStatus::getTable() . " os ON os.id=o.order_status\n LEFT OUTER JOIN " . Config::getTable() . " c ON o.config_id=c.id\n \tLEFT OUTER JOIN " . MemberModel::getTable() . " me ON o.member=me.id\n WHERE o.type='order' AND o.order_status>0 AND o.locked!=''\n " . ($intStatus > 0 ? " AND o.order_status=" . $intStatus : '') . "\n " . $this->getProductProcedure('i', 'product_id') . "\n " . ($intConfig > 0 ? " AND c.id=" . $intConfig : '') . "\n " . $this->getConfigProcedure('c') . "\n GROUP BY config_id, dateGroup, member_number\n HAVING dateGroup>={$dateFrom} AND dateGroup<={$dateTo}\n "); $arrCurrencies = array(); $arrDataMember = $this->initializeData($period, $intStart, $intStop); $arrDataGuests = $this->initializeData($period, $intStart, $intStop); $arrChart = $this->initializeChart($period, $intStart, $intStop); while ($objData->next()) { $arrCurrencies[$objData->currency] = $objData->config_id; if ($objData->member_number > 0) { $arrDataMember = $this->fillData($arrDataMember, $objData); // Generate chart data $arrChart[$objData->currency . '_Members']['data'][$objData->dateGroup]['y'] = (double) $arrChart[$objData->currency . '_Members']['data'][$objData->dateGroup]['y'] + $objData->total_sales; } else { $arrDataGuests = $this->fillData($arrDataGuests, $objData); // Generate chart data $arrChart[$objData->currency . '_Guests']['data'][$objData->dateGroup]['y'] = (double) $arrChart[$objData->currency . '_Guests']['data'][$objData->dateGroup]['y'] + $objData->total_sales; } } // Apply formatting $arrDataMember = $this->formatValues($arrDataMember, $arrCurrencies); $arrDataGuests = $this->formatValues($arrDataGuests, $arrCurrencies); $this->Template->dataMember = $arrDataMember; $this->Template->dataGuests = $arrDataGuests; $this->Template->chart = $arrChart; $this->Template->periodFormat = $period->getJavascriptClosure(); }
/** * Create a new user and redirect * * @param MemberModel $objMember */ protected function sendPasswordLink($objMember) { $confirmationId = md5(uniqid(mt_rand(), true)); // Store the confirmation ID $objMember = \MemberModel::findByPk($objMember->id); $objMember->activation = $confirmationId; $objMember->save(); // Prepare the simple token data $arrData = $objMember->row(); $arrData['domain'] = \Idna::decode(\Environment::get('host')); $arrData['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . (strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId; // Send e-mail $objEmail = new \Email(); $objEmail->from = $GLOBALS['TL_ADMIN_EMAIL']; $objEmail->fromName = $GLOBALS['TL_ADMIN_NAME']; $objEmail->subject = sprintf($GLOBALS['TL_LANG']['MSC']['passwordSubject'], \Idna::decode(\Environment::get('host'))); $objEmail->text = \StringUtil::parseSimpleTokens($this->reg_password, $arrData); $objEmail->sendTo($objMember->email); $this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . \Idna::decodeEmail($objMember->email) . ')', __METHOD__, TL_ACCESS); // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { $this->jumpToOrReload($objJumpTo->row()); } $this->reload(); }
/** * Display a login form * * @return string */ public function generate() { if (TL_MODE == 'BE') { /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['login'][0]) . ' ###'; $objTemplate->title = $this->headline; $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } // Set the last page visited if (!$_POST && $this->redirectBack) { $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer(); } // Login if (\Input::post('FORM_SUBMIT') == 'tl_login_' . $this->id) { // Check whether username and password are set if (empty($_POST['username']) || empty($_POST['password'])) { \System::getContainer()->get('session')->getFlashBag()->set($this->strFlashType, $GLOBALS['TL_LANG']['MSC']['emptyField']); $this->reload(); } $this->import('FrontendUser', 'User'); $strRedirect = \Environment::get('request'); // Redirect to the last page visited if ($this->redirectBack && $_SESSION['LAST_PAGE_VISITED'] != '') { $strRedirect = $_SESSION['LAST_PAGE_VISITED']; } else { // Redirect to the jumpTo page if ($this->jumpTo && ($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $strRedirect = $objTarget->getFrontendUrl(); } // Overwrite the jumpTo page with an individual group setting $objMember = \MemberModel::findByUsername(\Input::post('username')); if ($objMember !== null) { $arrGroups = \StringUtil::deserialize($objMember->groups); if (!empty($arrGroups) && is_array($arrGroups)) { $objGroupPage = \PageModel::findFirstActiveByMemberGroups($arrGroups); if ($objGroupPage !== null) { $strRedirect = $objGroupPage->getFrontendUrl(); } } } } // Auto login is not allowed if (isset($_POST['autologin']) && !$this->autologin) { unset($_POST['autologin']); \Input::setPost('autologin', null); } // Login and redirect if ($this->User->login()) { $this->redirect($strRedirect); } $this->reload(); } // Logout and redirect to the website root if the current page is protected if (\Input::post('FORM_SUBMIT') == 'tl_logout_' . $this->id) { /** @var PageModel $objPage */ 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(); }
/** * Generate the module */ protected function compile() { /** @var PageModel $objPage */ global $objPage; $this->import('FrontendUser', 'User'); $GLOBALS['TL_LANGUAGE'] = $objPage->language; \System::loadLanguageFile('tl_member'); $this->loadDataContainer('tl_member'); // Old password widget $arrFields['oldPassword'] = array('name' => 'oldpassword', 'label' => &$GLOBALS['TL_LANG']['MSC']['oldPassword'], 'inputType' => 'text', 'eval' => array('mandatory' => true, 'preserveTags' => true, 'hideInput' => true)); // New password widget $arrFields['newPassword'] = $GLOBALS['TL_DCA']['tl_member']['fields']['password']; $arrFields['newPassword']['name'] = 'password'; $arrFields['newPassword']['label'] =& $GLOBALS['TL_LANG']['MSC']['newPassword']; $row = 0; $strFields = ''; $doNotSubmit = false; $objMember = \MemberModel::findByPk($this->User->id); $strFormId = 'tl_change_password_' . $this->id; $flashBag = \System::getContainer()->get('session')->getFlashBag(); $strTable = $objMember->getTable(); // Initialize the versioning (see #8301) $objVersions = new \Versions($strTable, $objMember->id); $objVersions->setUsername($objMember->username); $objVersions->setUserId(0); $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1'); $objVersions->initialize(); /** @var FormTextField $objOldPassword */ $objOldPassword = null; /** @var FormPassword $objNewPassword */ $objNewPassword = null; // Initialize the widgets foreach ($arrFields as $strKey => $arrField) { /** @var Widget $strClass */ $strClass = $GLOBALS['TL_FFL'][$arrField['inputType']]; // Continue if the class is not defined if (!class_exists($strClass)) { continue; } $arrField['eval']['required'] = $arrField['eval']['mandatory']; /** @var Widget $objWidget */ $objWidget = new $strClass($strClass::getAttributesFromDca($arrField, $arrField['name'])); $objWidget->storeValues = true; $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd'); // Increase the row count if it is a password field if ($objWidget instanceof FormPassword) { $objWidget->rowClassConfirm = 'row_' . ++$row . ($row % 2 == 0 ? ' even' : ' odd'); } ++$row; // Store the widget objects $strVar = 'obj' . ucfirst($strKey); ${$strVar} = $objWidget; // Validate the widget if (\Input::post('FORM_SUBMIT') == $strFormId) { $objWidget->validate(); // Validate the old password if ($strKey == 'oldPassword') { if (\Encryption::test($objMember->password)) { $blnAuthenticated = \Encryption::verify($objWidget->value, $objMember->password); } else { list($strPassword, $strSalt) = explode(':', $objMember->password); $blnAuthenticated = $strSalt == '' ? $strPassword === sha1($objWidget->value) : $strPassword === sha1($strSalt . $objWidget->value); } if (!$blnAuthenticated) { $objWidget->value = ''; $objWidget->addError($GLOBALS['TL_LANG']['MSC']['oldPasswordWrong']); sleep(2); // Wait 2 seconds while brute forcing :) } } if ($objWidget->hasErrors()) { $doNotSubmit = true; } } $strFields .= $objWidget->parse(); } $this->Template->fields = $strFields; $this->Template->hasError = $doNotSubmit; // Store the new password if (\Input::post('FORM_SUBMIT') == $strFormId && !$doNotSubmit) { $objMember->tstamp = time(); $objMember->password = $objNewPassword->value; $objMember->save(); // Create a new version if ($GLOBALS['TL_DCA'][$strTable]['config']['enableVersioning']) { $objVersions->create(); } // HOOK: set new password callback if (isset($GLOBALS['TL_HOOKS']['setNewPassword']) && is_array($GLOBALS['TL_HOOKS']['setNewPassword'])) { foreach ($GLOBALS['TL_HOOKS']['setNewPassword'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($objMember, $objNewPassword->value, $this); } } // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { $this->jumpToOrReload($objJumpTo->row()); } $flashBag->set('mod_change_password_confirm', $GLOBALS['TL_LANG']['MSC']['newPasswordSet']); $this->reload(); } // Confirmation message if ($flashBag->has('mod_change_password_confirm')) { $arrMessages = $flashBag->get('mod_change_password_confirm'); $this->Template->message = $arrMessages[0]; } $this->Template->formId = $strFormId; $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->slabel = \StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['changePassword']); $this->Template->rowLast = 'row_' . $row . ' row_last' . ($row % 2 == 0 ? ' even' : ' odd'); }
/** * Re-send the activation mail * * @param MemberModel $objMember */ protected function resendActivationMail(MemberModel $objMember) { if ($objMember->activation == '') { return; } $this->strTemplate = 'mod_message'; /** @var FrontendTemplate|object $objTemplate */ $objTemplate = new \FrontendTemplate($this->strTemplate); $this->Template = $objTemplate; $this->sendActivationMail($objMember->row()); // Confirm activation $this->Template->type = 'confirm'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['resendActivation']; }
/** * Run the controller and parse the template * * @return Response */ public function run() { $this->disableProfiler(); if (\Environment::get('isAjaxRequest')) { $this->getDatalistOptions(); } $strUser = ''; $strHash = $this->getSessionHash('FE_USER_AUTH'); // Get the front end user if (FE_USER_LOGGED_IN) { $objUser = $this->Database->prepare("SELECT username FROM tl_member WHERE id=(SELECT pid FROM tl_session WHERE hash=?)")->limit(1)->execute($strHash); if ($objUser->numRows) { $strUser = $objUser->username; } } /** @var BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_switch'); $objTemplate->user = $strUser; $objTemplate->show = \Input::cookie('FE_PREVIEW'); $objTemplate->update = false; // Switch if (\Input::post('FORM_SUBMIT') == 'tl_switch') { $time = time(); // Hide unpublished elements if (\Input::post('unpublished') == 'hide') { $this->setCookie('FE_PREVIEW', 0, $time - 86400); $objTemplate->show = 0; } else { $this->setCookie('FE_PREVIEW', 1, $time + \Config::get('sessionTimeout')); $objTemplate->show = 1; } // Allow admins to switch user accounts if ($this->User->isAdmin) { // Remove old sessions $this->Database->prepare("DELETE FROM tl_session WHERE tstamp<? OR hash=?")->execute($time - \Config::get('sessionTimeout'), $strHash); // Log in the front end user if (\Input::post('user')) { $objUser = \MemberModel::findByUsername(\Input::post('user')); if ($objUser !== null) { // Insert the new session $this->Database->prepare("INSERT INTO tl_session (pid, tstamp, name, sessionID, ip, hash) VALUES (?, ?, ?, ?, ?, ?)")->execute($objUser->id, $time, 'FE_USER_AUTH', \System::getContainer()->get('session')->getId(), \Environment::get('ip'), $strHash); // Set the cookie $this->setCookie('FE_USER_AUTH', $strHash, $time + \Config::get('sessionTimeout'), null, null, false, true); $objTemplate->user = \Input::post('user'); } } else { // Remove cookie $this->setCookie('FE_USER_AUTH', $strHash, $time - 86400, null, null, false, true); $objTemplate->user = ''; } } $objTemplate->update = true; } // Default variables $objTemplate->theme = \Backend::getTheme(); $objTemplate->base = \Environment::get('base'); $objTemplate->language = $GLOBALS['TL_LANGUAGE']; $objTemplate->apply = $GLOBALS['TL_LANG']['MSC']['apply']; $objTemplate->reload = $GLOBALS['TL_LANG']['MSC']['reload']; $objTemplate->feUser = $GLOBALS['TL_LANG']['MSC']['feUser']; $objTemplate->username = $GLOBALS['TL_LANG']['MSC']['username']; $objTemplate->charset = \Config::get('characterSet'); $objTemplate->lblHide = $GLOBALS['TL_LANG']['MSC']['hiddenHide']; $objTemplate->lblShow = $GLOBALS['TL_LANG']['MSC']['hiddenShow']; $objTemplate->fePreview = $GLOBALS['TL_LANG']['MSC']['fePreview']; $objTemplate->hiddenElements = $GLOBALS['TL_LANG']['MSC']['hiddenElements']; $objTemplate->closeSrc = TL_FILES_URL . 'system/themes/' . \Backend::getTheme() . '/images/close.gif'; $objTemplate->action = ampersand(\Environment::get('request')); $objTemplate->isAdmin = $this->User->isAdmin; return $objTemplate->getResponse(); }
/** * Imports a user from phpbb to contao * * @param $username * @param $password * @return bool * @throws \Exception */ public function importUser($username, $password) { if ($this->debug) { System::log("phpbb_bridge: " . __METHOD__, __METHOD__, TL_ACCESS); } // Find User in forum $user = $this->getUser($username); if ($user) { System::log('Importing User ' . $username, __METHOD__, TL_ACCESS); // Try to find user by real username if he entered username_clean // he may not be imported yet with it's clean username $contaoUser = MemberModel::findByUsername($user->username); if (null == $contaoUser) { $contaoUser = new MemberModel(); } $contaoUser->username = $user->username; $contaoUser->username_clean = $user->username_clean; $contaoUser->email = $user->user_email; $contaoUser->firstname = 'Vorname'; $contaoUser->lastname = 'Nachname'; $contaoUser->password = Encryption::hash($password); $contaoUser->login = 1; $contaoUser->tstamp = $contaoUser->dateAdded = time(); $contaoUser->groups = $this->getForumMemberGroupIds(true); // @todo add try catch, make it more safe, logout phpbb user on fail? $contaoUser->save(); System::log('User imported: ' . $contaoUser->username, __METHOD__, TL_ACCESS); // username_clean used for login if ($username != $contaoUser->username) { Input::setPost('username', $contaoUser->username); } return true; } else { System::log($username . ' could not be found in phpbb db', __METHOD__, TL_ACCESS); return false; } }
/** * Generate the module */ protected function compile() { /** @var PageModel $objPage */ global $objPage; $this->import('FrontendUser', 'User'); $GLOBALS['TL_LANGUAGE'] = $objPage->language; \System::loadLanguageFile('tl_member'); $this->loadDataContainer('tl_member'); // Call onload_callback (e.g. to check permissions) if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'])) { foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onload_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}(); } elseif (is_callable($callback)) { $callback(); } } } $this->Template->fields = ''; $arrFields = array(); $doNotSubmit = false; $hasUpload = false; $row = 0; // Predefine the group order (other groups will be appended automatically) $arrGroups = array('personal' => array(), 'address' => array(), 'contact' => array(), 'login' => array(), 'profile' => array()); $blnModified = false; $objMember = \MemberModel::findByPk($this->User->id); $strTable = $objMember->getTable(); $strFormId = 'tl_member_' . $this->id; $flashBag = \System::getContainer()->get('session')->getFlashBag(); // Initialize the versioning (see #7415) $objVersions = new \Versions($strTable, $objMember->id); $objVersions->setUsername($objMember->username); $objVersions->setUserId(0); $objVersions->setEditUrl('contao/main.php?do=member&act=edit&id=%s&rt=1'); $objVersions->initialize(); // Build the form foreach ($this->editable as $field) { $arrData =& $GLOBALS['TL_DCA']['tl_member']['fields'][$field]; // Map checkboxWizards to regular checkbox widgets if ($arrData['inputType'] == 'checkboxWizard') { $arrData['inputType'] = 'checkbox'; } // Map fileTrees to upload widgets (see #8091) if ($arrData['inputType'] == 'fileTree') { $arrData['inputType'] = 'upload'; } /** @var Widget $strClass */ $strClass = $GLOBALS['TL_FFL'][$arrData['inputType']]; // Continue if the class does not exist if (!$arrData['eval']['feEditable'] || !class_exists($strClass)) { continue; } $strGroup = $arrData['eval']['feGroup']; $arrData['eval']['required'] = false; // Use strlen() here (see #3277) if ($arrData['eval']['mandatory']) { if (is_array($this->User->{$field})) { if (empty($this->User->{$field})) { $arrData['eval']['required'] = true; } } else { if (!strlen($this->User->{$field})) { $arrData['eval']['required'] = true; } } } $varValue = $this->User->{$field}; // Call the load_callback if (isset($arrData['load_callback']) && is_array($arrData['load_callback'])) { foreach ($arrData['load_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this->User, $this); } elseif (is_callable($callback)) { $varValue = $callback($varValue, $this->User, $this); } } } /** @var Widget $objWidget */ $objWidget = new $strClass($strClass::getAttributesFromDca($arrData, $field, $varValue, '', '', $this)); $objWidget->storeValues = true; $objWidget->rowClass = 'row_' . $row . ($row == 0 ? ' row_first' : '') . ($row % 2 == 0 ? ' even' : ' odd'); // Increase the row count if it is a password field if ($objWidget instanceof FormPassword) { if ($objMember->password != '') { $objWidget->mandatory = false; } $objWidget->rowClassConfirm = 'row_' . ++$row . ($row % 2 == 0 ? ' even' : ' odd'); } // Validate the form data if (\Input::post('FORM_SUBMIT') == $strFormId) { $objWidget->validate(); $varValue = $objWidget->value; $rgxp = $arrData['eval']['rgxp']; // Convert date formats into timestamps (check the eval setting first -> #3063) if ($varValue != '' && in_array($rgxp, array('date', 'time', 'datim'))) { try { $objDate = new \Date($varValue, \Date::getFormatFromRgxp($rgxp)); $varValue = $objDate->tstamp; } catch (\OutOfBoundsException $e) { $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['invalidDate'], $varValue)); } } // Make sure that unique fields are unique (check the eval setting first -> #3063) if ($arrData['eval']['unique'] && $varValue != '' && !$this->Database->isUniqueValue('tl_member', $field, $varValue, $this->User->id)) { $objWidget->addError(sprintf($GLOBALS['TL_LANG']['ERR']['unique'], $arrData['label'][0] ?: $field)); } // Trigger the save_callback (see #5247) if ($objWidget->submitInput() && !$objWidget->hasErrors() && is_array($arrData['save_callback'])) { foreach ($arrData['save_callback'] as $callback) { try { if (is_array($callback)) { $this->import($callback[0]); $varValue = $this->{$callback[0]}->{$callback[1]}($varValue, $this->User, $this); } elseif (is_callable($callback)) { $varValue = $callback($varValue, $this->User, $this); } } catch (\Exception $e) { $objWidget->class = 'error'; $objWidget->addError($e->getMessage()); } } } // Do not submit the field if there are errors if ($objWidget->hasErrors()) { $doNotSubmit = true; } elseif ($objWidget->submitInput()) { // Store the form data $_SESSION['FORM_DATA'][$field] = $varValue; // Set the correct empty value (see #6284, #6373) if ($varValue === '') { $varValue = $objWidget->getEmptyValue(); } // Encrypt the value (see #7815) if ($arrData['eval']['encrypt']) { $varValue = \Encryption::encrypt($varValue); } // Set the new value if ($varValue !== $this->User->{$field}) { $this->User->{$field} = $varValue; // Set the new field in the member model $blnModified = true; $objMember->{$field} = $varValue; } } } if ($objWidget instanceof \uploadable) { $hasUpload = true; } $temp = $objWidget->parse(); $this->Template->fields .= $temp; $arrFields[$strGroup][$field] .= $temp; ++$row; } // Save the model if ($blnModified) { $objMember->tstamp = time(); $objMember->save(); // Create a new version if ($GLOBALS['TL_DCA'][$strTable]['config']['enableVersioning']) { $objVersions->create(); $this->log('A new version of record "' . $strTable . '.id=' . $objMember->id . '" has been created' . $this->getParentEntries($strTable, $objMember->id), __METHOD__, TL_GENERAL); } } $this->Template->hasError = $doNotSubmit; // Redirect or reload if there was no error if (\Input::post('FORM_SUBMIT') == $strFormId && !$doNotSubmit) { // HOOK: updated personal data if (isset($GLOBALS['TL_HOOKS']['updatePersonalData']) && is_array($GLOBALS['TL_HOOKS']['updatePersonalData'])) { foreach ($GLOBALS['TL_HOOKS']['updatePersonalData'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->User, $_SESSION['FORM_DATA'], $this); } } // Call the onsubmit_callback if (is_array($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'])) { foreach ($GLOBALS['TL_DCA']['tl_member']['config']['onsubmit_callback'] as $callback) { if (is_array($callback)) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($this->User, $this); } elseif (is_callable($callback)) { $callback($this->User, $this); } } } // Check whether there is a jumpTo page if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) { $this->jumpToOrReload($objJumpTo->row()); } $flashBag->set('mod_personal_data_confirm', $GLOBALS['TL_LANG']['MSC']['savedData']); $this->reload(); } $this->Template->loginDetails = $GLOBALS['TL_LANG']['tl_member']['loginDetails']; $this->Template->addressDetails = $GLOBALS['TL_LANG']['tl_member']['addressDetails']; $this->Template->contactDetails = $GLOBALS['TL_LANG']['tl_member']['contactDetails']; $this->Template->personalData = $GLOBALS['TL_LANG']['tl_member']['personalData']; // Add the groups foreach ($arrFields as $k => $v) { // Deprecated since Contao 4.0, to be removed in Contao 5.0 $this->Template->{$k} = $v; $key = $k . ($k == 'personal' ? 'Data' : 'Details'); $arrGroups[$GLOBALS['TL_LANG']['tl_member'][$key]] = $v; } // Confirmation message if ($flashBag->has('mod_personal_data_confirm')) { $arrMessages = $flashBag->get('mod_personal_data_confirm'); $this->Template->message = $arrMessages[0]; } $this->Template->categories = $arrGroups; $this->Template->formId = $strFormId; $this->Template->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['saveData']); $this->Template->action = \Environment::get('indexFreeRequest'); $this->Template->enctype = $hasUpload ? 'multipart/form-data' : 'application/x-www-form-urlencoded'; $this->Template->rowLast = 'row_' . $row . ($row % 2 == 0 ? ' even' : ' odd'); }