protected function compile()
 {
     $strAction = \Input::get('act');
     // at first check for the correct request token to be set
     if ($strAction && !\RequestToken::validate(\Input::get('token')) && !$this->deactivateTokens) {
         StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Environment::getUrl(true, true, false)), $this->id, 'requestTokenExpired');
         return;
     }
     if ($strAction == FRONTENDEDIT_ACT_DELETE && ($intId = \Input::get('id'))) {
         if ($this->checkPermission($intId)) {
             $this->deleteItem($intId);
             // return to the list
             \Controller::redirect(Url::removeQueryString(array('act', 'id', 'token'), Environment::getUrl()));
         } else {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id);
             return;
         }
     }
     if ($strAction == FRONTENDEDIT_ACT_PUBLISH && ($intId = \Input::get('id'))) {
         if ($this->checkPermission($intId)) {
             $this->publishItem($intId);
             // return to the list
             \Controller::redirect(Url::removeQueryString(array('act', 'id'), Environment::getUrl()));
         } else {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id);
             return;
         }
     }
     parent::compile();
 }
 public function runOnValidationError($arrInvalidFields)
 {
     $arrDca = $GLOBALS['TL_DCA'][$this->strTable];
     \System::loadLanguageFile($this->strTable);
     StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['validationFailed'], '<ul>' . implode('', array_map(function ($val) use($arrDca) {
         return '<li>' . ($arrDca['fields'][$val]['label'][0] ?: $val) . '</li>';
     }, $arrInvalidFields))) . '</ul>', $this->objModule->id, 'validation-failed');
     $this->Template->message = StatusMessage::generate($this->objModule->id);
 }
 /**
  * Send a lost password e-mail
  *
  * @param \MemberModel $objMember
  */
 protected function sendPasswordLink($objMember)
 {
     $objNotification = \NotificationCenter\Model\Notification::findByPk($this->nc_notification);
     if ($objNotification === null) {
         $this->log('The notification was not found ID ' . $this->nc_notification, __METHOD__, TL_ERROR);
         return;
     }
     $confirmationId = md5(uniqid(mt_rand(), true));
     // Store the confirmation ID
     $objMember = \MemberModel::findByPk($objMember->id);
     $objMember->activation = $confirmationId;
     $objMember->save();
     $arrTokens = array();
     // Add member tokens
     foreach ($objMember->row() as $k => $v) {
         if (\Validator::isBinaryUuid($v)) {
             $v = \StringUtil::binToUuid($v);
         }
         $arrTokens['member_' . $k] = specialchars($v);
     }
     // FIX: Add salutation token
     $arrTokens['salutation_user'] = NotificationCenterPlus::createSalutation($GLOBALS['TL_LANGUAGE'], $objMember);
     // ENDFIX
     $arrTokens['recipient_email'] = $objMember->email;
     $arrTokens['domain'] = \Idna::decode(\Environment::get('host'));
     $arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Environment::get('request') . ($GLOBALS['TL_CONFIG']['disableAlias'] || strpos(\Environment::get('request'), '?') !== false ? '&' : '?') . 'token=' . $confirmationId;
     // FIX: Add custom change password jump to
     if (($objJumpTo = $this->objModel->getRelated('changePasswordJumpTo')) !== null) {
         $arrTokens['link'] = \Idna::decode(\Environment::get('base')) . \Controller::generateFrontendUrl($objJumpTo->row(), '?token=' . $confirmationId);
     }
     // ENDFIX
     $objNotification->send($arrTokens, $GLOBALS['TL_LANGUAGE']);
     $this->log('A new password has been requested for user ID ' . $objMember->id . ' (' . $objMember->email . ')', __METHOD__, TL_ACCESS);
     // Check whether there is a jumpTo page
     if (($objJumpTo = $this->objModel->getRelated('jumpTo')) !== null) {
         $this->jumpToOrReload($objJumpTo->row());
     }
     StatusMessage::addSuccess(sprintf($GLOBALS['TL_LANG']['notification_center_plus']['sendPasswordLink']['messageSuccess'], $arrTokens['recipient_email']), $this->objModel->id);
     $this->reload();
 }
 protected function transformIsotopeErrorMessages()
 {
     if (is_array($_SESSION['ISO_ERROR'])) {
         if (!empty($_SESSION['ISO_ERROR'])) {
             // no redirect!
             $this->jumpTo = null;
         }
         foreach ($_SESSION['ISO_ERROR'] as $strError) {
             StatusMessage::addError($strError, $this->getConfig()->getModule()->id);
         }
         unset($_SESSION['ISO_ERROR']);
     }
 }
 /**
  * Async form Submit
  * @return ResponseSuccess
  */
 public function asyncFormSubmit()
 {
     if (!$this->dc->isSubmitted() && !$this->forceIsSubmitted) {
         return;
     }
     $objResponse = new ResponseSuccess();
     $objResponse->setResult(new ResponseData($this->html, array('id' => $this->dc->getFormId())));
     StatusMessage::reset($this->dc->objModule->id);
     // reset messages after html has been submitted
     return $objResponse;
 }
 protected function redirectAfterSubmission()
 {
     global $objPage;
     $blnRedirect = false;
     $strUrl = \Controller::generateFrontendUrl($objPage->row());
     if (($objTarget = \PageModel::findByPk($this->jumpTo)) !== null) {
         $blnRedirect = true;
         $strUrl = \Controller::generateFrontendUrl($objTarget->row(), null, null, true);
     }
     $arrPreserveParams = trimsplit(',', $this->jumpToPreserveParams);
     foreach ($arrPreserveParams as $strParam) {
         $varValue = \Input::get($strParam);
         if ($varValue === null) {
             continue;
         }
         switch ($strParam) {
             case 'token':
                 if ($this->deactivateTokens) {
                     break;
                 }
                 $strUrl = Url::addQueryString($strParam . '=' . \RequestToken::get(), $strUrl);
                 break;
             default:
                 $strUrl = Url::addQueryString($strParam . '=' . $varValue, $strUrl);
         }
     }
     if ($blnRedirect) {
         \HeimrichHannot\StatusMessages\StatusMessage::reset($this->objModule->id);
     }
     if ($this->async) {
         if ($blnRedirect) {
             $objResponse = new ResponseRedirect();
             $objResponse->setUrl($strUrl);
             $objResponse->output();
         }
         return;
     }
     if (!$blnRedirect) {
         if ($this->getReset()) {
             $this->reset(true);
         }
         return;
     }
     \Controller::redirect($strUrl);
 }
 protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     $strAction = $this->defaultAction ?: \Input::get('act');
     $this->arrEditable = deserialize($this->formHybridEditable, true);
     $this->strToken = $this->strToken ?: \Input::get('token');
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->classes) && is_array($this->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->classes);
     }
     $this->addDefaultArchive();
     // at first check for the correct request token to be set
     if (!$this->deactivateTokens && !\RequestToken::validate($this->strToken)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError(sprintf($GLOBALS['TL_LANG']['frontendedit']['requestTokenExpired'], Url::replaceParameterInUri(Url::getUrl(), 'token', \RequestToken::get())), $this->id, 'requestTokenExpired');
         }
         return;
     }
     if ($this->formHybridAllowIdAsGetParameter) {
         $intId = \Input::get($this->formHybridIdGetParameter);
         if (is_numeric($intId)) {
             $this->intId = $intId;
         }
     }
     $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
     // get id from share
     if ($strShare = \Input::get('share')) {
         if (($objItem = $strItemClass::findByShareToken($strShare)) !== null && !FormHybridList::shareTokenExpiredOrEmpty($objItem, time())) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (isset($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior']) && is_array($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'])) {
             foreach ($GLOBALS['TL_HOOKS']['frontendEditAddNoIdBehavior'] as $arrCallback) {
                 $this->import($arrCallback[0]);
                 if ($this->{$arrCallback}[0]->{$arrCallback}[1]($this) === false) {
                     return;
                 }
             }
         }
         if ($this->noIdBehavior == 'error') {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
             }
             return;
         } elseif ($this->noIdBehavior == 'redirect' || $this->noIdBehavior == 'create_until') {
             $arrConditions = deserialize($this->existanceConditions, true);
             if ($this->existanceConditions && !empty($arrConditions)) {
                 $arrColumns = array();
                 $arrValues = array();
                 foreach ($arrConditions as $arrCondition) {
                     if (!$arrCondition['field']) {
                         continue;
                     }
                     $arrColumns[] = $arrCondition['field'] . '=?';
                     $arrValues[] = $this->replaceInsertTags($arrCondition['value']);
                 }
                 if (!empty($arrColumns) && ($objItem = $strItemClass::findOneBy($arrColumns, $arrValues)) !== null) {
                     $this->intId = $objItem->id;
                 }
             }
         }
         if (!$this->intId) {
             if ($this->noIdBehavior == 'redirect') {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['frontendedit']['noIdFound'], $this->id, 'noidfound');
                 }
                 return;
             } else {
                 $strFormId = FormHelper::getFormId($this->formHybridDataContainer, $this->id);
                 // get id from FormSession
                 if ($_POST) {
                     if ($intId = FormSession::getSubmissionId($strFormId)) {
                         $this->intId = $intId;
                     }
                 }
                 if (!$this->intId) {
                     // if no id is given a new instance is initiated
                     $objConfiguration = new FormConfiguration($this->arrData);
                     // ajax handling, required in this manor, as we have no real ajax controller in contao and ajax request not related to this module
                     // might trigger this module beforhand and new submission will be created after the submission was transfered to the user and id wont match any more
                     if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== null) {
                         if ($intId = FormSession::getSubmissionId($strFormId)) {
                             $this->intId = $intId;
                         } else {
                             $objConfiguration->forceCreate = true;
                         }
                     }
                     $this->objForm = new $this->strFormClass($objConfiguration, $this->arrSubmitCallbacks, $this->intId ?: 0, $this);
                     if ($intId = $this->objForm->getId()) {
                         $this->intId = $intId;
                     }
                 }
             }
         }
     }
     // intId is set at this point!
     if (!$this->checkEntityExists($this->intId)) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
         }
         if (Ajax::isRelated(Form::FORMHYBRID_NAME)) {
             $objResponse = new ResponseError();
             $objResponse->setResult(StatusMessage::generate($this->id));
             $objResponse->output();
         }
         return;
     }
     // page title
     if ($this->setPageTitle) {
         global $objPage;
         if (($objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId)) !== null) {
             $objPage->pageTitle = $objItem->{$this->pageTitleField};
         }
     }
     if ($strAction == FRONTENDEDIT_ACT_DELETE) {
         if ($this->checkDeletePermission($this->intId)) {
             $blnResult = $this->deleteItem($this->intId);
             if (\Environment::get('isAjaxRequest')) {
                 die($blnResult);
             }
             // return to the list
             \Controller::redirect(Url::removeQueryString(array('act', 'id', 'token'), Url::getUrl()));
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     } else {
         if ($this->checkUpdatePermission($this->intId)) {
             // create a new lock if necessary
             if (in_array('entity_lock', \ModuleLoader::getActive()) && $this->addEntityLock) {
                 if (\HeimrichHannot\EntityLock\EntityLockModel::isLocked($this->formHybridDataContainer, $this->intId, $this)) {
                     $objLock = \HeimrichHannot\EntityLock\EntityLockModel::findActiveLock($this->formHybridDataContainer, $this->intId, $this);
                     $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                     if (!$this->blnSilentMode) {
                         $strMessage = \HeimrichHannot\EntityLock\EntityLock::generateErrorMessage($this->formHybridDataContainer, $this->intId, $this);
                         if ($this->allowLockDeletion) {
                             $strUnlockForm = $this->generateUnlockForm($objItem, $objLock);
                             $strMessage .= $strUnlockForm;
                         }
                         StatusMessage::addError($strMessage, $this->id, 'locked');
                     }
                     if ($this->readOnlyOnLocked) {
                         $this->formHybridViewMode = FORMHYBRID_VIEW_MODE_READONLY;
                         $this->formHybridReadonlyTemplate = 'formhybridreadonly_default';
                     } else {
                         return;
                     }
                 } else {
                     \HeimrichHannot\EntityLock\EntityLockModel::create($this->formHybridDataContainer, $this->intId, $this);
                 }
             }
             if ($this->objForm === null) {
                 $this->objForm = new $this->strFormClass(new FormConfiguration($this->arrData), $this->arrSubmitCallbacks, $this->intId, $this);
             }
             $this->Template->form = $this->objForm->generate();
             $this->Template->item = $this->objForm->activeRecord;
             if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal') {
                 $objItem = General::getModelInstance($this->formHybridDataContainer, $this->intId);
                 $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap');
                 if ($objItem !== null) {
                     $objModalWrapper->setData($objItem->row());
                 }
                 $objModalWrapper->module = Arrays::arrayToObject($this->arrData);
                 $objModalWrapper->item = $this->replaceInsertTags($this->Template->parse());
                 die($objModalWrapper->parse());
             }
         } else {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
             }
             return;
         }
     }
 }
 protected function createSuccessMessage($arrSubmissionData)
 {
     $this->successMessage = \String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags(!empty($this->successMessage) ? $this->successMessage : $GLOBALS['TL_LANG']['formhybrid']['messages']['success'], $arrSubmissionData)), $arrSubmissionData);
     StatusMessage::addSuccess($this->successMessage, $this->objModule->id, 'alert alert-success');
 }
 protected function compile()
 {
     $this->Template->headline = $this->headline;
     $this->Template->hl = $this->hl;
     $this->Template->wrapperClass = $this->strWrapperClass;
     $this->Template->wrapperId = $this->strWrapperId;
     $this->strFormId = $this->formHybridDataContainer . '_' . $this->id;
     // Do not change this order (see #6191)
     $this->Template->style = !empty($this->arrStyle) ? implode(' ', $this->arrStyle) : '';
     $this->Template->class = trim('mod_' . $this->type . ' ' . $this->cssID[1]);
     $this->Template->cssID = $this->cssID[0] != '' ? ' id="' . $this->cssID[0] . '"' : '';
     $this->Template->inColumn = $this->strColumn;
     if ($this->Template->headline == '') {
         $this->Template->headline = $this->headline;
     }
     if ($this->Template->hl == '') {
         $this->Template->hl = $this->hl;
     }
     if (!empty($this->objModel->classes) && is_array($this->objModel->classes)) {
         $this->Template->class .= ' ' . implode(' ', $this->objModel->classes);
     }
     if ($this->intId && !is_numeric($this->intId)) {
         $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
         $strAliasField = $this->aliasField ?: 'id';
         if (($objItem = $strItemClass::findOneBy($strAliasField, $this->intId)) !== null && (!$this->addShareCol || !FormHybridList::shareTokenExpiredOrEmpty($objItem, time()))) {
             $this->intId = $objItem->id;
         }
     }
     if (!$this->intId) {
         if (!$this->blnSilentMode) {
             StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noIdFound'], $this->id, 'noidfound');
         }
         $this->Template->invalid = true;
     } else {
         if (!$this->checkEntityExists($this->intId)) {
             if (!$this->blnSilentMode) {
                 StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['notExisting'], $this->id, 'noentity');
             }
             $this->Template->invalid = true;
         } else {
             if ($this->checkPermission($this->intId)) {
                 $strItemClass = \Model::getClassFromTable($this->formHybridDataContainer);
                 if (($objItem = $strItemClass::findByPk($this->intId)) !== null) {
                     if ($this->blnUseBlob && $objItem->formHybridBlob) {
                         $arrBlob = deserialize($objItem->formHybridBlob, true);
                         foreach ($arrBlob as $strField => $varValue) {
                             if ($strField == 'formHybridBlob') {
                                 continue;
                             }
                             $objItem->{$strField} = $varValue;
                         }
                         $objItem->formHybridBlob = null;
                     }
                     // redirect on specific field value
                     //						DC_Hybrid::doFieldDependentRedirect($this, $objItem);
                     // page title
                     if ($this->setPageTitle) {
                         global $objPage;
                         $objPage->pageTitle = $objItem->{$this->pageTitleField};
                         if ($this->pageTitlePattern) {
                             $objPage->pageTitle = preg_replace_callback('@%([^%]+)%@i', function ($arrMatches) use($objItem) {
                                 return $objItem->{$arrMatches[1]};
                             }, $this->pageTitlePattern);
                         }
                     }
                     // comments
                     if ($this->noComments || !in_array('comments', \ModuleLoader::getActive()) || !\Database::getInstance()->fieldExists('pid', $this->formHybridDataContainer)) {
                         $this->Template->allowComments = false;
                     } else {
                         $objArchive = $objItem->getRelated('pid');
                         $this->Template->allowComments = $objArchive->allowComments;
                         if ($objArchive->allowComments) {
                             // Adjust the comments headline level
                             $intHl = min(intval(str_replace('h', '', $this->hl)), 5);
                             $this->Template->hlc = 'h' . ($intHl + 1);
                             $objComments = \System::importStatic('HeimrichHannot\\FormHybridList\\Comments');
                             $arrNotifies = array();
                             // Notify the system administrator
                             if ($objArchive->notify != 'notify_author') {
                                 $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
                             }
                             // Notify the author
                             if ($objArchive->notify != 'notify_admin') {
                                 if (($objAuthor = $objItem->getRelated('memberAuthor')) !== null && $objAuthor->email != '') {
                                     $arrNotifies[] = $objAuthor->email;
                                 }
                             }
                             $objConfig = new \stdClass();
                             $objConfig->perPage = $objArchive->perPage;
                             $objConfig->order = $objArchive->sortOrder;
                             $objConfig->template = $this->com_template;
                             $objConfig->requireLogin = $objArchive->requireLogin;
                             $objConfig->disableCaptcha = $objArchive->disableCaptcha;
                             $objConfig->bbcode = $objArchive->bbcode;
                             $objConfig->moderate = $objArchive->moderate;
                             $objComments->addCommentsToTemplate($this->Template, $objConfig, $this->formHybridDataContainer, $objItem->id, $arrNotifies);
                         }
                     }
                     $strItem = $this->replaceInsertTags($this->parseItem($objItem));
                     if (\Environment::get('isAjaxRequest') && \Input::get('scope') == 'modal' || $this->useModalWrapperSync) {
                         if (\Input::post('FORM_SUBMIT') == 'com_' . $this->formHybridDataContainer . '_' . $objItem->id) {
                             if (\Input::post('reload')) {
                                 die;
                             } else {
                                 $this->Template->item = $strItem;
                                 die($this->Template->parse());
                             }
                         } else {
                             $objModalWrapper = new \FrontendTemplate($this->modalTpl ?: 'formhybrid_reader_modal_bootstrap');
                             $objModalWrapper->setData($objItem->row() + $this->arrData);
                             $this->Template->item = $strItem;
                             $objModalWrapper->item = $this->Template->parse();
                             // active modal from synchronous request
                             if (!$this->useModalWrapperSync) {
                                 $objModalWrapper->active = true;
                                 die($objModalWrapper->parse());
                             }
                             $this->Template->item = $objModalWrapper->parse();
                         }
                     } else {
                         $this->Template->item = $strItem;
                     }
                 }
             } else {
                 if (!$this->blnSilentMode) {
                     StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid_list']['noPermission'], $this->id, 'nopermission');
                 }
                 $this->Template->invalid = true;
             }
         }
     }
 }