Index: branches/5.3.x/core/units/forms/form_submissions/form_submissions_eh.php =================================================================== diff -u -N -r15677 -r15698 --- branches/5.3.x/core/units/forms/form_submissions/form_submissions_eh.php (.../form_submissions_eh.php) (revision 15677) +++ branches/5.3.x/core/units/forms/form_submissions/form_submissions_eh.php (.../form_submissions_eh.php) (revision 15698) @@ -1,6 +1,6 @@ Application->GetVar('form_id'); - if (!$form_id) return ; - $conf_fields = $this->Application->getUnitOption($event->Prefix, 'Fields'); - $conf_grids = $this->Application->getUnitOption($event->Prefix, 'Grids'); + if ( !$form_id ) { + return; + } + $config = $event->getUnitConfig(); + $helper = $this->Application->recallObject('InpCustomFieldsHelper'); /* @var $helper InpCustomFieldsHelper */ @@ -103,57 +105,59 @@ foreach ($fields as $field_id => $options) { $field_visible = $check_visibility ? $options['Visibility'] == SubmissionFormField::VISIBILITY_EVERYONE : true; - $field_options = Array('type' => 'string', 'default' => $options['DefaultValue']); + $field_options = Array ('type' => 'string', 'default' => $options['DefaultValue']); - if ($options['Required'] && $field_visible) { + if ( $options['Required'] && $field_visible ) { $field_options['required'] = 1; } - if ($options['Validation'] == 1) { + if ( $options['Validation'] == 1 ) { $field_options['formatter'] = 'kFormatter'; $field_options['regexp'] = '/^(' . REGEX_EMAIL_USER . '@' . REGEX_EMAIL_DOMAIN . ')$/i'; } - if ($options['DisplayInGrid']) { + if ( $options['DisplayInGrid'] ) { $title = $options['Prompt']; - if (substr($title, 0, 1) == '+') { + if ( substr($title, 0, 1) == '+' ) { $this->Application->Phrases->AddCachedPhrase('form_col_title' . $field_id, substr($title, 1)); $title = 'form_col_title' . $field_id; } - $conf_grids['Default']['Fields']['fld_' . $field_id] = Array ( + $grid_field_options = Array ( 'title' => $title, 'no_special' => 1, 'nl2br' => 1, 'first_chars' => 200, 'filter_block' => $this->_getFilterBlock($options['ElementType']) ); - if ($options['ElementType'] == 'upload') { - $conf_grids['Default']['Fields']['fld_' . $field_id]['data_block'] = 'grid_upload_td'; + if ( $options['ElementType'] == 'upload' ) { + $grid_field_options['data_block'] = 'grid_upload_td'; } - if ($options['Validation'] == 1) { - $conf_grids['Default']['Fields']['fld_' . $field_id]['data_block'] = 'grid_email_td'; + if ( $options['Validation'] == 1 ) { + $grid_field_options['data_block'] = 'grid_email_td'; } + + $config->addGridFields('Default', $grid_field_options, 'fld_' . $field_id); } - if ($options['ElementType'] == 'checkbox' && !$options['ValueList']) { + if ( $options['ElementType'] == 'checkbox' && !$options['ValueList'] ) { // fix case, when user haven't defined any options for checkbox $options['ValueList'] = '1=la_Yes||0=la_No'; } - if (in_array($options['ElementType'], $use_options) && $options['ValueList']) { + if ( in_array($options['ElementType'], $use_options) && $options['ValueList'] ) { // field type can have options and user have defined them too - $field_options['options'] = $helper->GetValuesHash( $options['ValueList'] ); + $field_options['options'] = $helper->GetValuesHash($options['ValueList']); $field_options['formatter'] = 'kOptionsFormatter'; } - if ($options['ElementType'] == 'password') { + if ( $options['ElementType'] == 'password' ) { $field_options['formatter'] = 'kPasswordFormatter'; $field_options['hashing_method'] = PasswordHashingMethod::NONE; $field_options['verify_field'] = 'fld_' . $field_id . '_verify'; } - if ($options['ElementType'] == 'upload') { + if ( $options['ElementType'] == 'upload' ) { $field_options['formatter'] = 'kUploadFormatter'; $field_options['upload_dir'] = WRITEBALE_BASE . DIRECTORY_SEPARATOR . 'user_files' . DIRECTORY_SEPARATOR . 'form_submissions'; @@ -166,11 +170,8 @@ } } - $conf_fields['fld_' . $field_id] = $field_options; + $config->addFields($field_options, 'fld_' . $field_id); } - - $this->Application->setUnitOption($event->Prefix, 'Fields', $conf_fields); - $this->Application->setUnitOption($event->Prefix, 'Grids', $conf_grids); } /** @@ -406,7 +407,7 @@ /* @var $object kDBItem */ $form_id = $object->GetDBField('FormId'); - $email_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_EMAIL); + $email_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_EMAIL); if (!$email_field) { return ; @@ -427,8 +428,8 @@ $options = Array (); - $name_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_NAME); - $subject_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_SUBJECT); + $name_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_NAME); + $subject_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_SUBJECT); $language = $this->Application->recallObject('lang.current'); /* @var $language kDBItem */ @@ -465,23 +466,14 @@ * @param int $form_id * @param string $role * @return string + * @see FormSubmissionHelper::getFieldByRole() */ - function getFieldByRole($form_id, $role) + function getFieldNameByRole($form_id, $role) { - static $cache = Array (); + $form_submission_helper = $this->Application->recallObject('FormSubmissionHelper'); + /* @var $form_submission_helper FormSubmissionHelper */ - if (!array_key_exists($form_id, $cache)) { - $id_field = $this->Application->getUnitOption('formflds', 'IDField'); - $table_name = $this->Application->getUnitOption('formflds', 'TableName'); - - $sql = 'SELECT ' . $id_field . ', EmailCommunicationRole - FROM ' . $table_name . ' - WHERE FormId = ' . $form_id . ' AND EmailCommunicationRole <> 0'; - $cache[$form_id] = $this->Conn->GetCol($sql, 'EmailCommunicationRole'); - } - - // get field name by role - return array_key_exists($role, $cache[$form_id]) ? 'fld_' . $cache[$form_id][$role] : false; + return $form_submission_helper->getFieldNameByRole($form_id, $role); } /** @@ -515,9 +507,9 @@ $reply = $this->Application->recallObject('submission-log.merge', null, Array ('skip_autoload' => true)); /* @var $reply kDBItem */ - $email_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_EMAIL); - $subject_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_SUBJECT); - $body_field = $this->getFieldByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_BODY); + $email_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_EMAIL); + $subject_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_SUBJECT); + $body_field = $this->getFieldNameByRole($form_id, SubmissionFormField::COMMUNICATION_ROLE_BODY); $reply->SetDBField('FormSubmissionId', $merge_to);