/**
  * Store the subform field data as lead data.
  *
  * @param array $postData The submitted data.
  * @param array $form     The form config.
  * @param array $files    The uploaded files.
  * @param int   $leadId   The created lead.
  *
  * @return void
  */
 public function storeLeadsData($postData, $form, $files, $leadId)
 {
     $fields = \FormFieldModel::findBy(['type=?', 'pid=?', 'invisible=?'], ['subform', $form['id'], ''], ['order' => 'sorting']);
     if ($fields) {
         $this->postData = $postData;
         $this->form = $form;
         $this->files = $files;
         $this->leadId = $leadId;
         foreach ($fields as $field) {
             $this->storeSubform($field);
         }
     }
 }
 /**
  * Get sub form fields.
  *
  * @param \DataContainer $dataContainer The data container.
  *
  * @return array
  */
 public function getSubformFields($dataContainer)
 {
     $options = array();
     if ($dataContainer->activeRecord) {
         $fields = \FormFieldModel::findBy(['pid=?'], $dataContainer->activeRecord->subform, ['order' => 'label']);
         if ($fields) {
             foreach ($fields as $field) {
                 $options[$field->id] = $field->label ?: $fields->name;
             }
         }
     }
     return $options;
 }
 public function getCheckBoxFormFields()
 {
     $objFormField = \FormFieldModel::findBy(array('pid=?', 'type=?'), array(\Input::get('id'), 'checkbox'));
     $arrOptions = array();
     if ($objFormField !== null) {
         while ($objFormField->next()) {
             if ($objFormField->name) {
                 $arrOptions[] = $objFormField->name;
             }
         }
     }
     return $arrOptions;
 }
 public function processFormData($arrSubmitted, $arrData, $arrFiles, $arrLabels, \Form $objForm)
 {
     // check if there is a form field which we use as the code
     if (($objField = \FormFieldModel::findBy(array("pid = ?", "useCode = '1'"), array($objForm->id))) === null) {
         return;
     }
     // check if there is submitted data for the form field
     if (!isset($arrSubmitted[$objField->name])) {
         return;
     }
     // get the code
     $code = $arrSubmitted[$objField->name];
     // check if there is a page present for this alias
     if (($objPage = \PageModel::findPublishedByIdOrAlias($code)) === null) {
         return;
     }
     // redirect to page
     \Controller::redirect(\Controller::generateFrontendUrl($objPage->row(), null, null, true));
 }
Exemple #5
0
 private function updateFormFieldEfgLookupOptions()
 {
     // Update form data 'table name' in form fields of type EfgFormLookupCheckbox, EfgFormLookupRadio, EfgFormLookupSelectMenu
     // .. as of version 2.0.0 EFG creates dca file names and form keys based on form alias,
     // .. like fd_term-paper-submission (former fd_term_paper_submission)
     $this->import('Formdata');
     // Get all form data storing forms
     $arrStoringForms = $this->Formdata->arrStoringForms;
     // Get all form fields having efgLookupOptions
     $arrFormFields = $this->Database->prepare("SELECT id, efgLookupOptions FROM tl_form_field WHERE efgLookupOptions != ''")->execute()->fetchAllAssoc();
     if (count($arrFormFields) >= 1 && count($arrStoringForms) >= 1) {
         $arrMapFormDcaKey = array();
         // Build mapping, old form key => new form key
         foreach ($arrStoringForms as $strFormKey => $arrFormConfig) {
             $strOldKey = 'fd_' . (!empty($arrFormConfig['formID']) ? $arrFormConfig['formID'] : str_replace('-', '_', standardize($arrFormConfig['title'])));
             $strNewKey = 'fd_' . (!empty($arrFormConfig['alias']) ? $arrFormConfig['alias'] : str_replace('-', '_', standardize($arrFormConfig['title'])));
             $arrMapFormDcaKey[$strOldKey] = $strNewKey;
         }
         foreach ($arrFormFields as $arrFormField) {
             $arrLookupOptions = deserialize($arrFormField['efgLookupOptions']);
             if (!empty($arrLookupOptions['lookup_field'])) {
                 // Replace old form data 'table name' by new form 'table name' if lookup table is form data 'table'
                 if (substr($arrLookupOptions['lookup_field'], 0, 3) == 'fd_') {
                     $arrLookupFieldParams = explode('.', $arrLookupOptions['lookup_field']);
                     if (in_array($arrLookupFieldParams[0], array_keys($arrMapFormDcaKey))) {
                         $arrLookupOptions['lookup_field'] = $arrMapFormDcaKey[$arrLookupFieldParams[0]] . '.' . $arrLookupFieldParams[1];
                         $objFormFieldModel = \FormFieldModel::findBy('id', $arrFormField['id']);
                         $objFormFieldModel->efgLookupOptions = serialize($arrLookupOptions);
                         $objFormFieldModel->save();
                     }
                 }
             }
         }
     }
 }
 /**
  * Generate the module
  *
  * @return string
  */
 public function run()
 {
     $objTemplate = new \BackendTemplate('be_rsce_convert');
     $objTemplate->isActive = $this->isActive();
     $objTemplate->action = ampersand(\Environment::get('request'));
     $objTemplate->indexHeadline = $GLOBALS['TL_LANG']['tl_maintenance']['searchIndex'];
     // Rebuild the index
     if (\Input::get('act') === 'rsce_convert') {
         // Check the request token
         if (!isset($_GET['rt']) || !\RequestToken::validate(\Input::get('rt'))) {
             $this->Session->set('INVALID_TOKEN_URL', \Environment::get('request'));
             $this->redirect('contao/confirm.php');
         }
         $this->import('Database');
         $failedElements = array();
         $elementsCount = 0;
         $contentElements = \ContentModel::findBy(array(\ContentModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($contentElements && $contentElements->next()) {
             $html = $this->getHtmlFromElement($contentElements);
             if (!$html) {
                 $failedElements[] = array('content', $contentElements->id, $contentElements->type);
             } else {
                 $this->createInitialVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->Database->prepare('UPDATE ' . \ContentModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $contentElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ContentModel::getTable(), $contentElements->id);
                 $this->log('A new version of record "' . \ContentModel::getTable() . '.id=' . $contentElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $moduleElements = \ModuleModel::findBy(array(\ModuleModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($moduleElements && $moduleElements->next()) {
             $html = $this->getHtmlFromElement($moduleElements);
             if (!$html) {
                 $failedElements[] = array('module', $moduleElements->id, $moduleElements->type);
             } else {
                 $this->createInitialVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->Database->prepare('UPDATE ' . \ModuleModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $moduleElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\ModuleModel::getTable(), $moduleElements->id);
                 $this->log('A new version of record "' . \ModuleModel::getTable() . '.id=' . $moduleElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         $formElements = \FormFieldModel::findBy(array(\FormFieldModel::getTable() . '.type LIKE ?'), 'rsce_%');
         while ($formElements && $formElements->next()) {
             $html = $this->getHtmlFromElement($formElements);
             if (!$html) {
                 $failedElements[] = array('form', $formElements->id, $formElements->type);
             } else {
                 $this->createInitialVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->Database->prepare('UPDATE ' . \FormFieldModel::getTable() . ' SET tstamp = ?, type = \'html\', html = ? WHERE id = ?')->executeUncached(time(), $html, $formElements->id);
                 $elementsCount++;
                 $this->createNewVersion(\FormFieldModel::getTable(), $formElements->id);
                 $this->log('A new version of record "' . \FormFieldModel::getTable() . '.id=' . $formElements->id . '" has been created', __METHOD__, TL_GENERAL);
             }
         }
         foreach ($failedElements as $element) {
             $this->log('Failed to convert ' . $element[0] . ' element ID ' . $element[1] . ' (' . $element[2] . ') to a standard HTML element', __METHOD__, TL_ERROR);
         }
         $this->log('Converted ' . $elementsCount . ' RockSolid Custom Elements to standard HTML elements', __METHOD__, TL_GENERAL);
         $objTemplate->elementsCount = $elementsCount;
         $objTemplate->failedElements = $failedElements;
     }
     $this->loadLanguageFile('rocksolid_custom_elements');
     return $objTemplate->parse();
 }