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&table=tl_module&act=edit&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(); }
/** * Toggle Subpalette * @param $id * @param $strField * @param bool $blnLoad * * @return ResponseError|ResponseSuccess */ function toggleSubpalette($id, $strField, $blnLoad = false) { if (!$this->dc->isSubmitted()) { return; } $varValue = Request::getPost($strField) ?: 0; if (!is_array($this->dca['palettes']['__selector__']) || !in_array($strField, $this->dca['palettes']['__selector__'])) { \Controller::log('Field "' . $strField . '" is not an allowed selector field (possible SQL injection attempt)', __METHOD__, TL_ERROR); return new ResponseError(); } $arrData = $this->dca['fields'][$strField]; if (!Validator::isValidOption($varValue, $arrData, $this->dc)) { \Controller::log('Field "' . $strField . '" value is not an allowed option (possible SQL injection attempt)', __METHOD__, TL_ERROR); return new ResponseError(); } if (empty(FormHelper::getFieldOptions($arrData, $this->dc))) { $varValue = intval($varValue) ? 1 : ''; } $this->dc->setSkipValidation(true); // do not validate fields $this->dc->setDoNotSubmit(true); $this->dc->activeRecord->{$strField} = $varValue; $objResponse = new ResponseSuccess(); if ($blnLoad) { $objResponse->setResult(new ResponseData($this->dc->edit(false, $id))); } return $objResponse; }
/** * @internal Use FormHelper::getFormId() for static calls * * @return string */ public function getFormId($blnAddEntityId = true) { if ($this->useCustomFormId) { return $this->customFormId; } return FormHelper::getFormId($this->strTable, $this->objModule->id, $this->intId, $blnAddEntityId); }
/** * Get config value from transformed arrData and add logic to modify the value here * @param $strKey * * @return mixed|string */ public function __get($strKey) { $varValue = $this->arrData[$strKey]; switch ($strKey) { case 'strAction': if ($varValue && ($objActionPage = \PageModel::findWithDetails($varValue)) !== null) { $varValue = \Controller::generateFrontendUrl($objActionPage->row(), null, null, true); } else { $varValue = Url::removeQueryString(array('file'), \Environment::get('uri')); // remove all query parameters within ajax request if (Ajax::isRelated(Form::FORMHYBRID_NAME) !== false) { $varValue = AjaxAction::removeAjaxParametersFromUrl($varValue); } } // async form if ($this->async) { $varValue = AjaxAction::generateUrl(Form::FORMHYBRID_NAME, 'asyncFormSubmit'); } // add hash if ($this->addHashToAction) { $varValue .= '#' . ($this->customHash ?: $this->strFormId); } break; case 'arrDefaultValues': $varValue = FormHelper::getAssocMultiColumnWizardList($varValue, 'field'); break; } return $varValue; }
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; } } }
public function modifyPalette(\DataContainer $objDc, $blnFrontend = false) { // modify palette for backend view, based on archive submissionFields if (!$blnFrontend) { \Controller::loadDataContainer('tl_submission'); $arrDca =& $GLOBALS['TL_DCA']['tl_submission']; if (($objSubmission = \HeimrichHannot\Submissions\SubmissionModel::findByPk($objDc->id)) === null) { return false; } if (($objSubmissionArchive = $objSubmission->getRelated('pid')) === null) { return false; } $arrDca['palettes']['defaultBackup'] = $arrDca['palettes']['default']; $arrSubmissionFields = deserialize($objSubmissionArchive->submissionFields, true); // remove subpalette fields from arrSubmissionFields if (is_array($arrDca['subpalettes'])) { foreach ($arrDca['subpalettes'] as $key => $value) { $arrSubpaletteFields = \HeimrichHannot\FormHybrid\FormHelper::getPaletteFields($objDc->table, $value); if (!is_array($arrSubpaletteFields)) { continue; } $arrSubmissionFields = array_diff($arrSubmissionFields, $arrSubpaletteFields); } } $arrDca['palettes']['default'] = str_replace('submissionFields', implode(',', $arrSubmissionFields), \HeimrichHannot\Submissions\Submissions::PALETTE_DEFAULT); } // overwrite attachment config with archive if (isset($arrDca['fields']['attachments']) && $objSubmissionArchive->addAttachmentConfig) { $arrConfig = Arrays::filterByPrefixes($objSubmissionArchive->row(), array('attachment')); foreach ($arrConfig as $strKey => $value) { $strKey = lcfirst(str_replace('attachment', '', $strKey)); $arrDca['fields']['attachments']['eval'][$strKey] = $value; } } }
public function getSubPaletteFields(\DataContainer $arrDca) { $strTable = $arrDca->activeRecord->formHybridDataContainer; $arrSubPalettes = array(); $arrSubPaletteFields = array(); $arrFields = array(); \Controller::loadDataContainer($strTable); $arrSubPalettes = $GLOBALS['TL_DCA'][$strTable]['subpalettes']; if (empty($arrSubPalettes)) { return; } foreach ($arrSubPalettes as $strName => $strPalette) { $arrSubPaletteFields = \HeimrichHannot\FormHybrid\FormHelper::getPaletteFields($strTable, $arrSubPalettes[$strName]); if (empty($arrSubPaletteFields)) { return; } $arrFields = array_merge($arrFields, $arrSubPaletteFields); } return $arrFields; }
protected function createConfirmationAvisotaEmail($intMessageId, $strSalutationGroupId, $arrSubmissionData) { $objMessage = AvisotaHelper::getAvisotaMessage($intMessageId); $objMessage->setSubject(\String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags($objMessage->getSubject(), $arrSubmissionData), false), $arrSubmissionData)); foreach ($objMessage->getContents() as $objContent) { $strText = $objContent->getText(); if (!$strText) { continue; } $objContent->setText(\String::parseSimpleTokens($this->replaceInsertTags(FormHelper::replaceFormDataTags($strText, $arrSubmissionData), false), $arrSubmissionData)); } AvisotaHelper::sendAvisotaEMailByMessage($objMessage, $arrSubmissionData[$this->confirmationMailRecipientField]['value'], array_map(function ($arrValue) { if (isset($arrValue['value'])) { return $arrValue['value']; } else { return $arrValue; } }, $arrSubmissionData), $strSalutationGroupId, AvisotaHelper::RECIPIENT_MODE_USE_SUBMISSION_DATA); }
protected function parseItem($objItem, $strClass = '', $intCount = 0) { // work on a cloned item for supporting multiple reader modules on a single page $objItemTmp = unserialize(serialize($objItem)); // prepare item $objDc = new \DC_Table($this->formHybridDataContainer); $objDc->activeRecord = $objItemTmp; // untransformed values in the raw array $objItemTmp->raw = $objItemTmp->row(); // transform and escape values foreach ($objItemTmp->row() as $strField => $varValue) { if ($strField == 'raw') { continue; } $varValue = FormSubmission::prepareSpecialValueForPrint($varValue, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItemTmp); $objItemTmp->{$strField} = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $varValue); } if ($this->publishedField) { $objItemTmp->isPublished = $this->invertPublishedField ? !$objItemTmp->{$this->publishedField} : $objItemTmp->{$this->publishedField}; } $objTemplate = new \FrontendTemplate($this->itemTemplate ?: 'formhybrid_reader_default'); // items contain module and item params (higher priority: item) $objTemplate->setData($objItemTmp->row() + $this->arrData); $objTemplate->class = $strClass; $objTemplate->formHybridDataContainer = $this->formHybridDataContainer; $objTemplate->useDummyImage = $this->useDummyImage; $objTemplate->dummyImage = $this->dummyImage; $objTemplate->imgSize = deserialize($this->imgSize, true); $this->runBeforeTemplateParsing($objTemplate, $objItemTmp); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['parseItems']) && is_array($GLOBALS['TL_HOOKS']['parseItems'])) { foreach ($GLOBALS['TL_HOOKS']['parseItems'] as $callback) { $this->import($callback[0]); $this->{$callback}[0]->{$callback}[1]($objTemplate, $objItemTmp, $this); } } return $objTemplate->parse(); }
protected function generateFields($objItem) { $arrItem = array(); $arrDca =& $GLOBALS['TL_DCA'][$this->formHybridDataContainer]; // always add id $arrItem['raw']['id'] = $objItem->id; $objDc = new \DC_Table($this->formHybridDataContainer); $objDc->activeRecord = $objItem; if ($this->isTableList) { foreach ($this->arrTableFields as $strField) { $arrItem['fields'][$strField] = FormSubmission::prepareSpecialValueForPrint($objItem->{$strField}, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItem); if (is_array($arrDca['fields'][$strField]['load_callback'])) { foreach ($arrDca['fields'][$strField]['load_callback'] as $callback) { $this->import($callback[0]); $arrItem['fields'][$strField] = $this->{$callback}[0]->{$callback}[1]($arrItem['fields'][$strField], $objDc); } } // anti-xss: escape everything besides some tags $arrItem['fields'][$strField] = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $arrItem['fields'][$strField]); } } else { foreach ($arrDca['fields'] as $strField => $arrData) { $arrItem['fields'][$strField] = FormSubmission::prepareSpecialValueForPrint($objItem->{$strField}, $this->dca['fields'][$strField], $this->formHybridDataContainer, $objDc, $objItem); // anti-xss: escape everything besides some tags $arrItem['fields'][$strField] = FormHelper::escapeAllEntities($this->formHybridDataContainer, $strField, $arrItem['fields'][$strField]); } } // add raw values foreach ($GLOBALS['TL_DCA'][$this->formHybridDataContainer]['fields'] as $strField => $arrData) { $arrItem['raw'][$strField] = $objItem->{$strField}; } if ($this->publishedField) { $arrItem['isPublished'] = $this->invertPublishedField ? !$objItem->{$this->publishedField} : $objItem->{$this->publishedField}; } return $arrItem; }