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);
 }
 /**
  * Generate the module
  */
 protected function compile()
 {
     $strParent = parent::compile();
     if ($this->Template->error == $GLOBALS['TL_LANG']['MSC']['accountNotFound']) {
         StatusMessage::addError($GLOBALS['TL_LANG']['MSC']['accountNotFound'], $this->objModel->id);
     }
     if (!StatusMessage::isEmpty($this->objModel->id)) {
         $this->Template->error = StatusMessage::generate($this->objModel->id);
     }
     return $strParent;
 }
 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']);
     }
 }
 protected function initialize($blnCreated = false)
 {
     // load the model
     // don't load any class if the form's a filter form -> submission should be used instead
     if ($this->hasDatabaseTable() && !$this->hasNoEntity()) {
         $strModelClass = \Model::getClassFromTable($this->strTable);
     }
     if (class_exists($strModelClass)) {
         if (!$blnCreated && ($objModel = $strModelClass::findByPk($this->intId)) !== null) {
             $this->objActiveRecord = $objModel;
             $this->setMode(FORMHYBRID_MODE_EDIT);
             if ($this->saveToBlob) {
                 $this->loadFromBlob(deserialize($objModel->formHybridBlob, true));
             }
             // redirect on specific field value
             static::doFieldDependentRedirect();
         } else {
             if ($this->objModule !== null && Ajax::isRelated(Form::FORMHYBRID_NAME) !== false) {
                 // do nothing, if ajax request but not related to formhybrid
                 // otherwise a new submission will be generated and validation will fail
                 if ($this->hasDatabaseTable()) {
                     $this->setDefaults($GLOBALS['TL_DCA'][$this->strTable]);
                     // set defaults again, as they might has been overwritten within loadDC/modifyDC
                     $this->setSubmission();
                     $this->save();
                     // initially try to save record, as ajax requests for example require entity model
                 } elseif ($this->hasDatabaseTable() && !$this->hasNoEntity()) {
                     $this->invalid = true;
                     StatusMessage::addError($GLOBALS['TL_LANG']['formhybrid']['messages']['error']['invalidId'], $this->objModule->id, 'alert alert-danger');
                 }
             }
         }
     } else {
         if (!$this->hasDatabaseTable() || $this->hasNoEntity()) {
             $this->setSubmission();
         }
     }
     if ($this->viewMode == FORMHYBRID_VIEW_MODE_READONLY) {
         $this->strTemplate = $this->readonlyTemplate;
         $this->setDoNotSubmit(true);
     }
 }
 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 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;
             }
         }
     }
 }