function ajaxValidate() { $form = JRequest::getVar('form'); $formId = (int) @$form['formId']; $this->_db->setQuery("SELECT ComponentId, ComponentTypeId FROM #__rsform_components WHERE `FormId`='" . $formId . "' AND `Published`='1' ORDER BY `Order`"); $components = $this->_db->loadObjectList(); $page = JRequest::getInt('page'); if ($page) { $current_page = 1; foreach ($components as $i => $component) { if ($current_page != $page) { unset($components[$i]); } if ($component->ComponentTypeId == 41) { $current_page++; } } } $removeUploads = array(); $removeRecaptcha = array(); $formComponents = array(); foreach ($components as $component) { $formComponents[] = $component->ComponentId; if ($component->ComponentTypeId == 9) { $removeUploads[] = $component->ComponentId; } if ($component->ComponentTypeId == 24) { $removeRecaptcha[] = $component->ComponentId; } } echo implode(',', $formComponents); echo "\n"; $invalid = RSFormProHelper::validateForm($formId); if (count($invalid)) { foreach ($invalid as $i => $componentId) { if (in_array($componentId, $removeUploads) || in_array($componentId, $removeRecaptcha)) { unset($invalid[$i]); } } $invalidComponents = array_intersect($formComponents, $invalid); echo implode(',', $invalidComponents); } if (isset($invalidComponents)) { echo "\n"; $pages = RSFormProHelper::componentExists($formId, 41); $pages = count($pages); if ($pages && !$page) { $first = reset($invalidComponents); $current_page = 1; foreach ($components as $i => $component) { if ($component->ComponentId == $first) { break; } if ($component->ComponentTypeId == 41) { $current_page++; } } echo $current_page; echo "\n"; echo $pages; } } jexit(); }
public static function getEditFields($cid) { $db = JFactory::getDbo(); $return = array(); $values = JFactory::getApplication()->input->get('form', array(), 'array'); $pattern = '#\\[p(.*?)\\]#is'; $db->setQuery("SELECT * FROM #__rsform_submissions WHERE SubmissionId='" . (int) $cid . "'"); $submission = $db->loadObject(); if (empty($submission)) { $mainframe = JFactory::getApplication(); $mainframe->redirect(JURI::root()); return $return; } $validation = !empty($values) ? RSFormProHelper::validateForm($submission->FormId, 'directory') : array(); $formFields = RSFormProHelper::getDirectoryFields($submission->FormId); $editable = array(); foreach ($formFields as $formField) { if ($formField->editable) { $editable[] = $formField->FieldName; } } $db->setQuery("SELECT FieldName, FieldValue FROM #__rsform_submission_values WHERE SubmissionId='" . (int) $cid . "'"); $fields = $db->loadObjectList(); foreach ($fields as $field) { $submission->values[$field->FieldName] = $field->FieldValue; } unset($fields); $db->setQuery("SELECT p.PropertyValue, ct.ComponentTypeName, c.ComponentId FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (p.ComponentId=c.ComponentId) LEFT JOIN #__rsform_component_types ct ON (c.ComponentTypeId=ct.ComponentTypeId) WHERE c.FormId='" . $submission->FormId . "' AND c.Published='1' AND p.PropertyName='NAME' ORDER BY `Order`"); $fields = $db->loadObjectList(); if (empty($fields)) { return $return; } $componentIds = array(); foreach ($fields as $field) { $componentIds[] = $field->ComponentId; } $properties = RSFormProHelper::getComponentProperties($componentIds); $fields = RSFormProHelper::sortFields($fields, $editable); foreach ($fields as $field) { if (!in_array($field->PropertyValue, $editable)) { continue; } $invalid = !empty($validation) && in_array($field->ComponentId, $validation) ? ' rsform-error' : ''; $data = $properties[$field->ComponentId]; $new_field = array(); $new_field[0] = !empty($data['CAPTION']) ? $data['CAPTION'] : $field->PropertyValue; $new_field[2] = isset($data['REQUIRED']) && $data['REQUIRED'] == 'YES' ? '<strong class="formRequired">(*)</strong>' : ''; $new_field[3] = $field->PropertyValue; $name = $field->PropertyValue; if (isset($values[$field->PropertyValue])) { $value = $values[$field->PropertyValue]; } else { $value = isset($submission->values[$field->PropertyValue]) ? $submission->values[$field->PropertyValue] : ''; } if ($data['NAME'] == 'RSEProPayment') { $field->ComponentTypeName = 'rsepropayment'; } switch ($field->ComponentTypeName) { // skip this field for now, no need to edit it case 'freeText': continue 2; break; default: if (strpos($value, "\n") !== false || strpos($value, "\r") !== false) { $new_field[1] = '<textarea style="width: 95%" class="rs_textarea' . $invalid . '" rows="10" cols="60" name="form[' . $name . ']">' . RSFormProHelper::htmlEscape($value) . '</textarea>'; } else { $new_field[1] = '<input class="rs_inp rs_80' . $invalid . '" type="text" name="form[' . $name . ']" value="' . RSFormProHelper::htmlEscape($value) . '" />'; } break; case 'textArea': if (isset($data['WYSIWYG']) && $data['WYSIWYG'] == 'YES') { $new_field[1] = RSFormProHelper::WYSIWYG('form[' . $name . ']', RSFormProHelper::htmlEscape($value), '', 600, 100, 60, 10); } else { $new_field[1] = '<textarea style="width: 95%" class="rs_textarea' . $invalid . '" rows="10" cols="60" name="form[' . $name . ']">' . RSFormProHelper::htmlEscape($value) . '</textarea>'; } break; case 'radioGroup': case 'checkboxGroup': case 'selectList': if ($field->ComponentTypeName == 'radioGroup') { $data['SIZE'] = 0; $data['MULTIPLE'] = 'NO'; } elseif ($field->ComponentTypeName == 'checkboxGroup') { $data['SIZE'] = 5; $data['MULTIPLE'] = 'YES'; } $value = !empty($values) ? $value : RSFormProHelper::explode($value); $items = RSFormProHelper::isCode($data['ITEMS']); $items = RSFormProHelper::explode($items); $options = array(); foreach ($items as $item) { if (preg_match($pattern, $item, $match)) { $item = preg_replace($pattern, '', $item); } // <OPTGROUP> if (preg_match('/\\[g\\]/', $item)) { $item = str_replace('[g]', '', $item); $optgroup = new stdClass(); $optgroup->value = '<OPTGROUP>'; $optgroup->text = $item; $options[] = $optgroup; continue; } // </OPTGROUP> if (preg_match('/\\[\\/g\\]/', $item)) { $optgroup = new stdClass(); $optgroup->value = '</OPTGROUP>'; $optgroup->text = ''; $options[] = $optgroup; continue; } $buf = explode('|', $item); $val = str_replace('[c]', '', $buf[0]); $item = str_replace('[c]', '', count($buf) == 1 ? $buf[0] : $buf[1]); $options[] = JHTML::_('select.option', $val, $item); } $attribs = array(); if ((int) $data['SIZE'] > 0) { $attribs[] = 'size="' . (int) $data['SIZE'] . '"'; } if ($data['MULTIPLE'] == 'YES') { $attribs[] = 'multiple="multiple"'; } if ($invalid) { $attribs[] = 'class="rsform-error"'; } $attribs = implode(' ', $attribs); $new_field[1] = JHTML::_('select.genericlist', $options, 'form[' . $name . '][]', $attribs, 'value', 'text', $value); break; case 'fileUpload': $new_field[1] = '<span class="' . $invalid . '">' . RSFormProHelper::htmlEscape(basename($value)) . '</span>'; $new_field[1] .= '<br /><input size="45" type="file" name="form[' . $name . ']" />'; break; } $return[] = $new_field; } /* // PayPal if (isset($submission->values['_STATUS'])) { $name = '_STATUS'; $value = $submission->values['_STATUS']; $new_field[0] = JText::_('RSFP_PAYPAL_STATUS'); $options = array( JHTML::_('select.option', -1, JText::_('RSFP_PAYPAL_STATUS_-1')), JHTML::_('select.option', 0, JText::_('RSFP_PAYPAL_STATUS_0')), JHTML::_('select.option', 1, JText::_('RSFP_PAYPAL_STATUS_1')) ); $new_field[1] = JHTML::_('select.genericlist', $options, 'form['.$name.'][]', null, 'value', 'text', $value); $return[] = $new_field; } // ANZ if (isset($submission->values['_ANZ_STATUS'])) { $name = '_ANZ_STATUS'; $value = $submission->values['_ANZ_STATUS']; $new_field[0] = JText::_('RSFP_ANZ_STATUS'); $options = array( JHTML::_('select.option', -1, JText::_('RSFP_ANZ_STATUS_-1')), JHTML::_('select.option', 0, JText::_('RSFP_ANZ_STATUS_0')), JHTML::_('select.option', 1, JText::_('RSFP_ANZ_STATUS_1')) ); $new_field[1] = JHTML::_('select.genericlist', $options, 'form['.$name.'][]', null, 'value', 'text', $value); $return[] = $new_field; } */ return $return; }
function ajaxValidate() { $form = JRequest::getVar('form'); $formId = (int) @$form['formId']; $this->_db->setQuery("SELECT ComponentId, ComponentTypeId FROM #__rsform_components WHERE `FormId`='" . $formId . "' AND `Published`='1' ORDER BY `Order`"); $components = $this->_db->loadObjectList(); $page = JRequest::getInt('page'); if ($page) { $current_page = 1; foreach ($components as $i => $component) { if ($current_page != $page) { unset($components[$i]); } if ($component->ComponentTypeId == 41) { $current_page++; } } } $removeUploads = array(); $formComponents = array(); foreach ($components as $component) { $formComponents[] = $component->ComponentId; if ($component->ComponentTypeId == 9) { $removeUploads[] = $component->ComponentId; } } echo implode(',', $formComponents); echo "\n"; $invalid = RSFormProHelper::validateForm($formId); //Trigger Event - onBeforeFormValidation $mainframe = JFactory::getApplication(); $post = JRequest::get('post', JREQUEST_ALLOWRAW); $mainframe->triggerEvent('rsfp_f_onBeforeFormValidation', array(array('invalid' => &$invalid, 'formId' => $formId, 'post' => &$post))); if (count($invalid)) { foreach ($invalid as $i => $componentId) { if (in_array($componentId, $removeUploads)) { unset($invalid[$i]); } } $invalidComponents = array_intersect($formComponents, $invalid); echo implode(',', $invalidComponents); } if (isset($invalidComponents)) { echo "\n"; $pages = RSFormProHelper::componentExists($formId, 41); $pages = count($pages); if ($pages && !$page) { $first = reset($invalidComponents); $current_page = 1; foreach ($components as $i => $component) { if ($component->ComponentId == $first) { break; } if ($component->ComponentTypeId == 41) { $current_page++; } } echo $current_page; echo "\n"; echo $pages; } } jexit(); }
function RSvalidateForm($formId) { return RSFormProHelper::validateForm($formId); }
public static function getEditFields($cid) { $db = JFactory::getDbo(); $return = array(); $values = JFactory::getApplication()->input->get('form', array(), 'array'); $pattern = '#\\[p(.*?)\\]#is'; // Load submission $query = $db->getQuery(true); $query->select('*')->from($db->qn('#__rsform_submissions'))->where($db->qn('SubmissionId') . '=' . $db->q($cid)); $submission = $db->setQuery($query)->loadObject(); if (empty($submission)) { return $return; } $submission->DateSubmitted = JHtml::_('date', $submission->DateSubmitted, 'Y-m-d H:i:s'); // Get submission values $submission->values = array(); $query->clear()->select($db->qn('FieldName'))->select($db->qn('FieldValue'))->from($db->qn('#__rsform_submission_values'))->where($db->qn('SubmissionId') . '=' . $db->q($cid)); if ($values = $db->setQuery($query)->loadObjectList()) { foreach ($values as $value) { $submission->values[$value->FieldName] = $value->FieldValue; } unset($values); } $validation = !empty($values) ? RSFormProHelper::validateForm($submission->FormId, 'directory') : array(); $formFields = self::getDirectoryFields($submission->FormId); $headers = self::getDirectoryStaticHeaders(); $query = $db->getQuery(true); $query->select($db->qn('ct.ComponentTypeName', 'type'))->select($db->qn('c.ComponentId'))->from($db->qn('#__rsform_components', 'c'))->join('left', $db->qn('#__rsform_component_types', 'ct') . ' ON (' . $db->qn('c.ComponentTypeId') . '=' . $db->qn('ct.ComponentTypeId') . ')')->where($db->qn('c.FormId') . '=' . $db->q($submission->FormId))->where($db->qn('c.Published') . '=' . $db->q(1)); $componentTypes = $db->setQuery($query)->loadObjectList('ComponentId'); $componentIds = array(); foreach ($formFields as $formField) { if ($formField->FieldId > 0) { $componentIds[] = $formField->FieldId; } // Assign the type $formField->type = ''; if ($formField->FieldId < 0) { $formField->type = 'static'; } elseif (isset($componentTypes[$formField->FieldId])) { $formField->type = $componentTypes[$formField->FieldId]->type; } // For convenience... $formField->id = $formField->FieldId; $formField->name = $formField->FieldName; } $properties = RSFormProHelper::getComponentProperties($componentIds); foreach ($formFields as $field) { if (!$field->editable) { continue; } $invalid = !empty($validation) && in_array($field->id, $validation) ? ' rsform-error' : ''; $data = $field->id > 0 ? $properties[$field->id] : array('NAME' => $field->name); $new_field = array(); $new_field[0] = !empty($data['CAPTION']) ? $data['CAPTION'] : $field->name; $new_field[2] = isset($data['REQUIRED']) && $data['REQUIRED'] == 'YES' ? '<strong class="formRequired">(*)</strong>' : ''; $new_field[3] = $field->name; $name = $field->name; if ($field->type != 'static') { if (isset($values[$field->name])) { $value = $values[$field->name]; } else { $value = isset($submission->values[$field->name]) ? $submission->values[$field->name] : ''; } } else { $value = isset($submission->{$field->name}) ? $submission->{$field->name} : ''; } if ($data['NAME'] == 'RSEProPayment') { $field->type = 'rsepropayment'; } switch ($field->type) { case 'static': $new_field[0] = JText::_('RSFP_' . $field->name); // Show a dropdown for yes/no if ($field->name == 'confirmed') { $options = array(JHtml::_('select.option', 0, JText::_('RSFP_NO')), JHtml::_('select.option', 1, JText::_('RSFP_YES'))); $new_field[1] = JHTML::_('select.genericlist', $options, 'formStatic[confirmed]', null, 'value', 'text', $value); } else { $new_field[1] = '<input class="rs_inp rs_80" type="text" name="formStatic[' . $name . ']" value="' . RSFormProHelper::htmlEscape($value) . '" />'; } break; // skip this field for now, no need to edit it // skip this field for now, no need to edit it case 'freeText': continue 2; break; default: if (strpos($value, "\n") !== false || strpos($value, "\r") !== false) { $new_field[1] = '<textarea style="width: 95%" class="rs_textarea' . $invalid . '" rows="10" cols="60" name="form[' . $name . ']">' . RSFormProHelper::htmlEscape($value) . '</textarea>'; } else { $new_field[1] = '<input class="rs_inp rs_80' . $invalid . '" type="text" name="form[' . $name . ']" value="' . RSFormProHelper::htmlEscape($value) . '" />'; } break; case 'textArea': if (isset($data['WYSIWYG']) && $data['WYSIWYG'] == 'YES') { $new_field[1] = RSFormProHelper::WYSIWYG('form[' . $name . ']', RSFormProHelper::htmlEscape($value), '', 600, 100, 60, 10); } else { $new_field[1] = '<textarea style="width: 95%" class="rs_textarea' . $invalid . '" rows="10" cols="60" name="form[' . $name . ']">' . RSFormProHelper::htmlEscape($value) . '</textarea>'; } break; case 'radioGroup': case 'checkboxGroup': case 'selectList': if ($field->type == 'radioGroup') { $data['SIZE'] = 0; $data['MULTIPLE'] = 'NO'; } elseif ($field->type == 'checkboxGroup') { $data['SIZE'] = 5; $data['MULTIPLE'] = 'YES'; } $value = !empty($values) ? $value : RSFormProHelper::explode($value); $items = RSFormProHelper::isCode($data['ITEMS']); $items = RSFormProHelper::explode($items); $options = array(); foreach ($items as $item) { if (preg_match($pattern, $item, $match)) { $item = preg_replace($pattern, '', $item); } // <OPTGROUP> if (preg_match('/\\[g\\]/', $item)) { $item = str_replace('[g]', '', $item); $optgroup = new stdClass(); $optgroup->value = '<OPTGROUP>'; $optgroup->text = $item; $options[] = $optgroup; continue; } // </OPTGROUP> if (preg_match('/\\[\\/g\\]/', $item)) { $optgroup = new stdClass(); $optgroup->value = '</OPTGROUP>'; $optgroup->text = ''; $options[] = $optgroup; continue; } $buf = explode('|', $item); $val = str_replace('[c]', '', $buf[0]); $item = str_replace('[c]', '', count($buf) == 1 ? $buf[0] : $buf[1]); $options[] = JHTML::_('select.option', $val, $item); } $attribs = array(); if ((int) $data['SIZE'] > 0) { $attribs[] = 'size="' . (int) $data['SIZE'] . '"'; } if ($data['MULTIPLE'] == 'YES') { $attribs[] = 'multiple="multiple"'; } if ($invalid) { $attribs[] = 'class="rsform-error"'; } $attribs = implode(' ', $attribs); $new_field[1] = JHTML::_('select.genericlist', $options, 'form[' . $name . '][]', $attribs, 'value', 'text', $value); break; case 'fileUpload': $new_field[1] = '<span class="' . $invalid . '">' . RSFormProHelper::htmlEscape(basename($value)) . '</span>'; $new_field[1] .= '<br /><input size="45" type="file" name="form[' . $name . ']" />'; break; } $return[] = $new_field; } return $return; }
public function save() { jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $cid = JRequest::getInt('id'); $form = JRequest::getVar('form', array(), 'post', 'none', JREQUEST_ALLOWRAW); $static = JRequest::getVar('formStatic', array(), 'post', 'none', JREQUEST_ALLOWRAW); $formId = JRequest::getInt('formId'); $files = JRequest::getVar('form', array(), 'files', 'none', JREQUEST_ALLOWRAW); $validation = RSFormProHelper::validateForm($formId, 'directory', $cid); if (!empty($validation)) { return false; } $formFields = RSFormProHelper::getDirectoryFields($formId); $headers = RSFormProHelper::getDirectoryStaticHeaders(); $staticFields = array(); $allowed = array(); foreach ($formFields as $field) { if ($field->editable) { if ($field->componentId < 0 && isset($headers[$field->componentId])) { $staticFields[] = $field->FieldName; } else { $allowed[] = $field->FieldName; } } } //Trigger Event - onBeforeDirectorySave $this->_app->triggerEvent('rsfp_f_onBeforeDirectorySave', array(array('SubmissionId' => &$cid, 'formId' => $formId, 'post' => &$form))); // Handle file uploads first if (!empty($files['error'])) { foreach ($files['error'] as $field => $error) { if (!in_array($field, $allowed) || $error) { continue; } // The above $validation should suffice $this->_db->setQuery("SELECT FieldValue FROM #__rsform_submission_values WHERE FieldName='" . $this->_db->escape($field) . "' AND SubmissionId='" . $cid . "' LIMIT 1"); $original = $this->_db->loadResult(); // Prefix $componentId = RSFormProHelper::getComponentId($field, $formId); $data = RSFormProHelper::getComponentProperties($componentId); $prefix = uniqid('') . '-'; if (isset($data['PREFIX']) && strlen(trim($data['PREFIX'])) > 0) { $prefix = RSFormProHelper::isCode($data['PREFIX']); } // Path $realpath = realpath($data['DESTINATION'] . DIRECTORY_SEPARATOR); if (substr($realpath, -1) != DIRECTORY_SEPARATOR) { $realpath .= DIRECTORY_SEPARATOR; } // Filename $file = $realpath . $prefix . $files['name'][$field]; // Upload File if (JFile::upload($files['tmp_name'][$field], $file) && $file != $original) { // Remove the original file to save up space if (file_exists($original) && is_file($original)) { JFile::delete($original); } // Add to db (submission value) $form[$field] = $file; } } } // Update fields foreach ($form as $field => $value) { if (!in_array($field, $allowed)) { continue; } if (is_array($value)) { $value = implode("\n", $value); } // Dynamic field - update value. $this->_db->setQuery("SELECT SubmissionValueId, FieldValue FROM #__rsform_submission_values WHERE FieldName='" . $this->_db->escape($field) . "' AND SubmissionId='" . $cid . "' LIMIT 1"); $original = $this->_db->loadObject(); if (!$original) { $this->_db->setQuery("INSERT INTO #__rsform_submission_values SET FormId='" . $formId . "', SubmissionId='" . $cid . "', FieldName='" . $this->_db->escape($field) . "', FieldValue='" . $this->_db->escape($value) . "'"); $this->_db->execute(); } else { // Update only if we've changed something if ($original->FieldValue != $value) { $this->_db->setQuery("UPDATE #__rsform_submission_values SET FieldValue='" . $this->_db->escape($value) . "' WHERE SubmissionValueId='" . $original->SubmissionValueId . "' LIMIT 1"); $this->_db->execute(); } } } $offset = JFactory::getConfig()->get('offset'); if ($static && $staticFields) { // Static, update submission $query = $this->_db->getQuery(true); $query->update('#__rsform_submissions')->where($this->_db->qn('SubmissionId') . '=' . $this->_db->q($cid)); foreach ($staticFields as $field) { if (!isset($static[$field])) { $static[$field] = ''; } if ($field == 'DateSubmitted') { $static[$field] = JFactory::getDate($static[$field], $offset)->toSql(); } $query->set($this->_db->qn($field) . '=' . $this->_db->q($static[$field])); } $this->_db->setQuery($query); $this->_db->execute(); } // Checkboxes don't send a value if nothing is checked $checkboxesWhere = ''; if ($editFields = $this->getEditFields()) { $allowedFields = array(); foreach ($editFields as $field) { $allowedFields[] = $this->_db->q($field[3]); } if (!empty($allowedFields)) { $checkboxesWhere = "AND p.PropertyValue IN (" . implode(',', $allowedFields) . ")"; } } $this->_db->setQuery("SELECT p.PropertyValue FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (c.ComponentId=p.ComponentId) WHERE c.ComponentTypeId='4' AND p.PropertyName='NAME' AND c.FormId='" . $formId . "' " . $checkboxesWhere); $checkboxes = $this->_db->loadColumn(); foreach ($checkboxes as $checkbox) { $value = isset($form[$checkbox]) ? $form[$checkbox] : ''; if (is_array($value)) { $value = implode("\n", $value); } $this->_db->setQuery("UPDATE #__rsform_submission_values SET FieldValue='" . $this->_db->escape($value) . "' WHERE FieldName='" . $this->_db->escape($checkbox) . "' AND FormId='" . $formId . "' AND SubmissionId='" . $cid . "' LIMIT 1"); $this->_db->execute(); } // Send emails $this->sendEmails($formId, $cid); return true; }
public static function processForm($formId) { $mainframe = JFactory::getApplication(); $formId = (int) $formId; $db = JFactory::getDBO(); $db->setQuery("SELECT `FormLayoutName`, `Keepdata`, `ConfirmSubmission`, `ScriptProcess`, `ScriptProcess2`, `UserEmailScript`, `AdminEmailScript`, `ReturnUrl`, `ShowThankyou`, `Thankyou`, `ShowContinue` FROM #__rsform_forms WHERE `FormId`='" . $formId . "'"); $form = $db->loadObject(); $lang = RSFormProHelper::getCurrentLanguage(); $translations = RSFormProHelper::getTranslations('forms', $formId, $lang); if ($translations) { foreach ($translations as $field => $value) { if (isset($form->{$field})) { $form->{$field} = $value; } } } $invalid = RSFormProHelper::validateForm($formId); $post = JRequest::getVar('form', array(), 'post', 'none', JREQUEST_ALLOWRAW); //Trigger Event - onBeforeFormValidation $mainframe->triggerEvent('rsfp_f_onBeforeFormValidation', array(array('invalid' => &$invalid, 'formId' => $formId, 'post' => &$post))); $userEmail = array('to' => '', 'cc' => '', 'bcc' => '', 'from' => '', 'replyto' => '', 'fromName' => '', 'text' => '', 'subject' => '', 'files' => array()); $adminEmail = array('to' => '', 'cc' => '', 'bcc' => '', 'from' => '', 'replyto' => '', 'fromName' => '', 'text' => '', 'subject' => '', 'files' => array()); $_POST['form'] = $post; $RSadapter = RSFormProHelper::getLegacyAdapter(); eval($form->ScriptProcess); if (!empty($invalid)) { return $invalid; } $post = $_POST['form']; //Trigger Event - onBeforeFormProcess $mainframe->triggerEvent('rsfp_f_onBeforeFormProcess', array(array('post' => &$post))); if (empty($invalid)) { // Cache enabled ? jimport('joomla.plugin.helper'); $cache_enabled = JPluginHelper::isEnabled('system', 'cache'); if ($cache_enabled) { RSFormProHelper::cleanCache(); } $user = JFactory::getUser(); $confirmsubmission = $form->ConfirmSubmission ? 0 : 1; // Add to db (submission) $date = JFactory::getDate(); $db->setQuery("INSERT INTO #__rsform_submissions SET `FormId`='" . $formId . "', `DateSubmitted`='" . $date->toSql() . "', `UserIp`='" . (isset($_SERVER['REMOTE_ADDR']) ? $db->escape($_SERVER['REMOTE_ADDR']) : '') . "', `Username`='" . $db->escape($user->get('username')) . "', `UserId`='" . (int) $user->get('id') . "', `Lang`='" . RSFormProHelper::getCurrentLanguage() . "', `confirmed` = '" . $confirmsubmission . "' "); $db->execute(); $SubmissionId = $db->insertid(); $files = JRequest::get('files'); if (isset($files['form']['tmp_name']) && is_array($files['form']['tmp_name'])) { $names = array(); foreach ($files['form']['tmp_name'] as $fieldName => $val) { if ($files['form']['error'][$fieldName]) { continue; } $names[] = $db->escape($fieldName); } $componentIds = array(); if (!empty($names)) { $db->setQuery("SELECT c.ComponentId, p.PropertyValue FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (c.ComponentId=p.ComponentId AND p.PropertyName='NAME') WHERE c.FormId='" . $formId . "' AND p.PropertyValue IN ('" . implode("','", $names) . "')"); $results = $db->loadObjectList(); foreach ($results as $result) { $componentIds[$result->PropertyValue] = $result->ComponentId; } } $all_data = RSFormProHelper::getComponentProperties($componentIds); jimport('joomla.filesystem.file'); foreach ($files['form']['tmp_name'] as $fieldName => $val) { if ($files['form']['error'][$fieldName]) { continue; } $data = @$all_data[$componentIds[$fieldName]]; if (empty($data)) { continue; } // Prefix $prefix = uniqid('') . '-'; if (isset($data['PREFIX']) && strlen(trim($data['PREFIX'])) > 0) { $prefix = RSFormProHelper::isCode($data['PREFIX']); } // Path $realpath = realpath($data['DESTINATION'] . DIRECTORY_SEPARATOR); if (substr($realpath, -1) != DIRECTORY_SEPARATOR) { $realpath .= DIRECTORY_SEPARATOR; } // Filename $file = $realpath . $prefix . $files['form']['name'][$fieldName]; // Upload File JFile::upload($files['form']['tmp_name'][$fieldName], $file); // Add to db (submission value) $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='" . $SubmissionId . "', `FormId`='" . $formId . "', `FieldName`='" . $db->escape($fieldName) . "', `FieldValue`='" . $db->escape($file) . "'"); $db->execute(); $emails = !empty($data['EMAILATTACH']) ? explode(',', $data['EMAILATTACH']) : array(); // Attach to user and admin email if (in_array('useremail', $emails)) { $userEmail['files'][] = $file; } if (in_array('adminemail', $emails)) { $adminEmail['files'][] = $file; } } } // birthDay Field if ($componentIds = RSFormProHelper::componentExists($formId, 211)) { $all_data = RSFormProHelper::getComponentProperties($componentIds); foreach ($all_data as $componentId => $data) { $day = strpos($data['DATEORDERING'], 'D'); $month = strpos($data['DATEORDERING'], 'M'); $year = strpos($data['DATEORDERING'], 'Y'); $items = array(); if ($data['SHOWDAY'] == 'YES') { if (isset($data['STORELEADINGZERO']) && $data['STORELEADINGZERO'] == 'YES') { $post[$data['NAME']]['d'] = str_pad(@$post[$data['NAME']]['d'], 2, '0', STR_PAD_LEFT); } $items[$day] = @$post[$data['NAME']]['d']; } if ($data['SHOWMONTH'] == 'YES') { if (isset($data['STORELEADINGZERO']) && $data['STORELEADINGZERO'] == 'YES') { $post[$data['NAME']]['m'] = str_pad(@$post[$data['NAME']]['m'], 2, '0', STR_PAD_LEFT); } $items[$month] = @$post[$data['NAME']]['m']; } if ($data['SHOWYEAR'] == 'YES') { $items[$year] = @$post[$data['NAME']]['y']; } ksort($items); $hasValues = false; foreach ($items as $item) { if (!empty($item)) { $hasValues = true; break; } } if (!$hasValues) { $post[$data['NAME']] = ''; } else { $post[$data['NAME']] = implode($data['DATESEPARATOR'], $items); } } } //Trigger Event - onBeforeStoreSubmissions $mainframe->triggerEvent('rsfp_f_onBeforeStoreSubmissions', array(array('formId' => $formId, 'post' => &$post, 'SubmissionId' => $SubmissionId))); // Add to db (values) foreach ($post as $key => $val) { $val = is_array($val) ? implode("\n", $val) : $val; $val = RSFormProHelper::stripJava($val); $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='" . $SubmissionId . "', `FormId`='" . $formId . "', `FieldName`='" . $db->escape($key) . "', `FieldValue`='" . $db->escape($val) . "'"); $db->execute(); } //Trigger Event - onAfterStoreSubmissions $mainframe->triggerEvent('rsfp_f_onAfterStoreSubmissions', array(array('SubmissionId' => $SubmissionId, 'formId' => $formId))); // Send emails list($replace, $with) = RSFormProHelper::sendSubmissionEmails($SubmissionId); // RSForm! Pro Scripting - Thank You Message // performance check if (strpos($form->Thankyou, '{if ') !== false && strpos($form->Thankyou, '{/if}') !== false) { require_once dirname(__FILE__) . '/scripting.php'; RSFormProScripting::compile($form->Thankyou, $replace, $with); } // Thank You Message $thankYouMessage = str_replace($replace, $with, $form->Thankyou); $form->ReturnUrl = str_replace($replace, $with, $form->ReturnUrl); // Set redirect link $u = RSFormProHelper::getURL(); // Create the Continue button $continueButton = ''; if ($form->ShowContinue) { // Create goto link $goto = 'document.location.reload();'; // Cache workaround #1 if ($cache_enabled) { $goto = "document.location='" . addslashes($u) . "';"; } if (!empty($form->ReturnUrl)) { $goto = "document.location='" . addslashes($form->ReturnUrl) . "';"; } // Continue button $continueButtonLabel = JText::_('RSFP_THANKYOU_BUTTON'); if (strpos($continueButtonLabel, 'input')) { $continueButton = JText::sprintf('RSFP_THANKYOU_BUTTON', $goto); } else { if ($form->FormLayoutName == 'responsive') { $continueButton .= '<div class="formResponsive">'; } else { $continueButton .= '<br/>'; } $continueButton .= '<input type="button" class="rsform-submit-button btn btn-primary" name="continue" value="' . JText::_('RSFP_THANKYOU_BUTTON') . '" onclick="' . $goto . '"/>'; if ($form->FormLayoutName == 'responsive') { $continueButton .= '</div>'; } } } // get mappings data $db->setQuery("SELECT * FROM #__rsform_mappings WHERE formId = " . (int) $formId . " ORDER BY ordering ASC"); $mappings = $db->loadObjectList(); // get Post to another location $db->setQuery("SELECT * FROM #__rsform_posts WHERE form_id='" . (int) $formId . "' AND enabled='1'"); $silentPost = $db->loadObject(); $RSadapter = RSFormProHelper::getLegacyAdapter(); eval($form->ScriptProcess2); $thankYouMessage .= $continueButton; //Mappings if (!empty($mappings)) { $lastinsertid = ''; $replacewith = $with; array_walk($replacewith, array('RSFormProHelper', 'escapeSql')); foreach ($mappings as $mapping) { //get the query $query = RSFormProHelper::getMappingQuery($mapping); //replace the placeholders $query = str_replace($replace, $replacewith, $query); //replace the last insertid placeholder $query = str_replace('{last_insert_id}', $lastinsertid, $query); if ($mapping->connection) { $options = array('driver' => 'mysql', 'host' => $mapping->host, 'user' => $mapping->username, 'password' => $mapping->password, 'database' => $mapping->database); if (RSFormProHelper::isJ('3.0')) { $database = JDatabaseDriver::getInstance($options); } else { $database = JDatabase::getInstance($options); } //is a valid database connection if (is_a($database, 'JException')) { continue; } $database->setQuery($query); $database->execute(); $lastinsertid = $database->insertid(); } else { $db->setQuery($query); $db->execute(); $lastinsertid = $db->insertid(); } } } if (!$form->Keepdata) { $db->setQuery("DELETE FROM #__rsform_submission_values WHERE SubmissionId = " . (int) $SubmissionId . " "); $db->execute(); $db->setQuery("DELETE FROM #__rsform_submissions WHERE SubmissionId = " . (int) $SubmissionId . " "); $db->execute(); } if ($silentPost && !empty($silentPost->url) && $silentPost->url != 'http://') { // url $url = $silentPost->url; // set the variables to be sent // the format of the variables is var1=value1&var2=value2&var3=value3 $data = array(); foreach ($post as $key => $value) { if (is_array($value)) { foreach ($value as $post2 => $value2) { $data[] = urlencode($key) . '[]=' . urlencode($value2); } } else { $data[] = urlencode($key) . '=' . urlencode($value); } } // do we need to post silently? if ($silentPost->silent) { $data = implode('&', $data); $params = array('method' => $silentPost->method ? 'POST' : 'GET'); require_once dirname(__FILE__) . '/connect.php'; RSFormProConnect($url, $data, $params); } else { // just try to redirect if ($silentPost->method) { @ob_end_clean(); // create form $output = array(); $output[] = '<form id="formSubmit" method="POST" action="' . RSFormProHelper::htmlEscape($url) . '">'; foreach ($post as $key => $value) { if (is_array($value)) { foreach ($value as $post2 => $value2) { $output[] = '<input type="hidden" name="' . RSFormProHelper::htmlEscape($key) . '[]" value="' . RSFormProHelper::htmlEscape($value2) . '" />'; } } else { $output[] = '<input type="hidden" name="' . RSFormProHelper::htmlEscape($key) . '" value="' . RSFormProHelper::htmlEscape($value) . '" />'; } } $output[] = '</form>'; $output[] = '<script type="text/javascript">'; $output[] = 'function formSubmit() { document.getElementById(\'formSubmit\').submit(); }'; $output[] = 'try { window.addEventListener ? window.addEventListener("load",formSubmit,false) : window.attachEvent("onload",formSubmit); }'; $output[] = 'catch (err) { formSubmit(); }'; $output[] = '</script>'; // echo form and submit it echo implode("\r\n", $output); die; } else { $data = implode('&', $data); $mainframe->redirect($url . (strpos($url, '?') === false ? '?' : '&') . $data); } } } //Trigger - After form process $mainframe->triggerEvent('rsfp_f_onAfterFormProcess', array(array('SubmissionId' => $SubmissionId, 'formId' => $formId))); if (!$form->ShowThankyou && $form->ReturnUrl) { $mainframe->redirect($form->ReturnUrl); return; } // SESSION quick hack - we base64 encode it here and decode it when we show it $session = JFactory::getSession(); $formParams = new stdClass(); $formParams->formProcessed = true; $formParams->submissionId = $SubmissionId; $formParams->thankYouMessage = base64_encode($thankYouMessage); $session->set('com_rsform.formparams.' . $formId, $formParams); // Cache workaround #2 if ($cache_enabled) { $uniqid = uniqid('rsform'); $u .= strpos($u, '?') === false ? '?skipcache=' . $uniqid : '&skipcache=' . $uniqid; } $mainframe->redirect($u); } return false; }
function processForm($formId) { $mainframe =& JFactory::getApplication(); $formId = (int) $formId; $db = JFactory::getDBO(); $db->setQuery("SELECT `Keepdata`, `ConfirmSubmission`, `ScriptProcess`, `ScriptProcess2`, `UserEmailScript`, `AdminEmailScript`, `ReturnUrl`, `ShowThankyou`, `Thankyou`, `ShowContinue` FROM #__rsform_forms WHERE `FormId`='" . $formId . "'"); $form = $db->loadObject(); $lang = RSFormProHelper::getCurrentLanguage(); $translations = RSFormProHelper::getTranslations('forms', $formId, $lang); if ($translations) { foreach ($translations as $field => $value) { if (isset($form->{$field})) { $form->{$field} = $value; } } } $invalid = RSFormProHelper::validateForm($formId); //Trigger Event - onBeforeFormValidation $mainframe->triggerEvent('rsfp_f_onBeforeFormValidation', array(array('invalid' => &$invalid))); $userEmail = array('to' => '', 'cc' => '', 'bcc' => '', 'from' => '', 'replyto' => '', 'fromName' => '', 'text' => '', 'subject' => '', 'files' => array()); $adminEmail = array('to' => '', 'cc' => '', 'bcc' => '', 'from' => '', 'replyto' => '', 'fromName' => '', 'text' => '', 'subject' => '', 'files' => array()); $post = JRequest::getVar('form', array(), 'post', 'none', JREQUEST_ALLOWRAW); $_POST['form'] = $post; $RSadapter = RSFormProHelper::getLegacyAdapter(); eval($form->ScriptProcess); if (!empty($invalid)) { return $invalid; } $post = $_POST['form']; //Trigger Event - onBeforeFormProcess $mainframe->triggerEvent('rsfp_f_onBeforeFormProcess'); if (empty($invalid)) { // Cache enabled ? jimport('joomla.plugin.helper'); $cache_enabled = JPluginHelper::isEnabled('system', 'cache'); if ($cache_enabled) { RSFormProHelper::cleanCache(); } $user = JFactory::getUser(); $confirmsubmission = $form->ConfirmSubmission ? 0 : 1; // Add to db (submission) $db->setQuery("INSERT INTO #__rsform_submissions SET `FormId`='" . $formId . "', `DateSubmitted`=NOW(), `UserIp`='" . (isset($_SERVER['REMOTE_ADDR']) ? $db->getEscaped($_SERVER['REMOTE_ADDR']) : '') . "', `Username`='" . $db->getEscaped($user->get('username')) . "', `UserId`='" . (int) $user->get('id') . "', `Lang`='" . RSFormProHelper::getCurrentLanguage() . "', `confirmed` = '" . $confirmsubmission . "' "); $db->query(); $SubmissionId = $db->insertid(); $files = JRequest::get('files'); if (isset($files['form']['tmp_name']) && is_array($files['form']['tmp_name'])) { $names = array(); foreach ($files['form']['tmp_name'] as $fieldName => $val) { if ($files['form']['error'][$fieldName]) { continue; } $names[] = $db->getEscaped($fieldName); } $componentIds = array(); if (!empty($names)) { $db->setQuery("SELECT c.ComponentId, p.PropertyValue FROM #__rsform_components c LEFT JOIN #__rsform_properties p ON (c.ComponentId=p.ComponentId AND p.PropertyName='NAME') WHERE c.FormId='" . $formId . "' AND p.PropertyValue IN ('" . implode("','", $names) . "')"); $results = $db->loadObjectList(); foreach ($results as $result) { $componentIds[$result->PropertyValue] = $result->ComponentId; } } $all_data = RSFormProHelper::getComponentProperties($componentIds); jimport('joomla.filesystem.file'); foreach ($files['form']['tmp_name'] as $fieldName => $val) { if ($files['form']['error'][$fieldName]) { continue; } $data = @$all_data[$componentIds[$fieldName]]; if (empty($data)) { continue; } // Prefix $prefix = uniqid('') . '-'; if (isset($data['PREFIX']) && strlen(trim($data['PREFIX'])) > 0) { $prefix = RSFormProHelper::isCode($data['PREFIX']); } // Path $realpath = realpath($data['DESTINATION'] . DS); if (substr($realpath, -1) != DS) { $realpath .= DS; } // Filename $file = $realpath . $prefix . $files['form']['name'][$fieldName]; // Upload File JFile::upload($files['form']['tmp_name'][$fieldName], $file); // Add to db (submission value) $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='" . $SubmissionId . "', `FormId`='" . $formId . "', `FieldName`='" . $db->getEscaped($fieldName) . "', `FieldValue`='" . $db->getEscaped($file) . "'"); $db->query(); $emails = !empty($data['EMAILATTACH']) ? explode(',', $data['EMAILATTACH']) : array(); // Attach to user and admin email if (in_array('useremail', $emails)) { $userEmail['files'][] = $file; } if (in_array('adminemail', $emails)) { $adminEmail['files'][] = $file; } } } //Trigger Event - onBeforeStoreSubmissions $mainframe->triggerEvent('rsfp_f_onBeforeStoreSubmissions', array(array('formId' => $formId, 'post' => &$post, 'SubmissionId' => $SubmissionId))); // Add to db (values) foreach ($post as $key => $val) { $val = is_array($val) ? implode("\n", $val) : $val; $val = RSFormProHelper::stripJava($val); $db->setQuery("INSERT INTO #__rsform_submission_values SET `SubmissionId`='" . $SubmissionId . "', `FormId`='" . $formId . "', `FieldName`='" . $db->getEscaped($key) . "', `FieldValue`='" . $db->getEscaped($val) . "'"); $db->query(); } //Trigger Event - onAfterStoreSubmissions $mainframe->triggerEvent('rsfp_f_onAfterStoreSubmissions', array(array('SubmissionId' => $SubmissionId, 'formId' => $formId))); // Send emails list($replace, $with) = RSFormProHelper::sendSubmissionEmails($SubmissionId); // Thank You Message $thankYouMessage = str_replace($replace, $with, $form->Thankyou); $form->ReturnUrl = str_replace($replace, $with, $form->ReturnUrl); // Set redirect link $u = RSFormProHelper::getURL(); // Create the Continue button $continueButton = ''; if ($form->ShowContinue) { // Create goto link $goto = 'document.location.reload();'; // Cache workaround #1 if ($cache_enabled) { $goto = "document.location='" . addslashes($u) . "';"; } if (!empty($form->ReturnUrl)) { $goto = "document.location='" . addslashes($form->ReturnUrl) . "';"; } // Continue button $continueButtonLabel = JText::_('RSFP_THANKYOU_BUTTON'); if (strpos($continueButtonLabel, 'input')) { $continueButton = JText::sprintf('RSFP_THANKYOU_BUTTON', $goto); } else { $continueButton = '<br/><input type="button" class="rsform-submit-button" name="continue" value="' . JText::_('RSFP_THANKYOU_BUTTON') . '" onclick="' . $goto . '"/>'; } } $RSadapter = RSFormProHelper::getLegacyAdapter(); eval($form->ScriptProcess2); $thankYouMessage .= $continueButton; //Mappings //get mappings data $db->setQuery("SELECT * FROM #__rsform_mappings WHERE formId = " . (int) $formId . " ORDER BY ordering ASC "); $mappings = $db->loadObjectList(); if (!empty($mappings)) { $lastinsertid = ''; $replacewith = $with; array_walk($replacewith, array('RSFormProHelper', 'escapeSql')); foreach ($mappings as $mapping) { //get the query $query = RSFormProHelper::getMappingQuery($mapping); //replace the placeholders $query = str_replace($replace, $replacewith, $query); //replace the last insertid placeholder $query = str_replace('{last_insert_id}', $lastinsertid, $query); if ($mapping->connection) { $options = array('host' => $mapping->host, 'user' => $mapping->username, 'password' => $mapping->password, 'database' => $mapping->database); $database = JDatabase::getInstance($options); //is a valid database connection if (is_a($database, 'JException')) { continue; } $database->setQuery($query); $database->query(); $lastinsertid = $database->insertid(); } else { $db->setQuery($query); $db->query(); $lastinsertid = $db->insertid(); } } } if (!$form->Keepdata) { $db->setQuery("DELETE FROM #__rsform_submission_values WHERE SubmissionId = " . (int) $SubmissionId . " "); $db->query(); $db->setQuery("DELETE FROM #__rsform_submissions WHERE SubmissionId = " . (int) $SubmissionId . " "); $db->query(); } //Trigger - After form process $mainframe->triggerEvent('rsfp_f_onAfterFormProcess', array(array('SubmissionId' => $SubmissionId, 'formId' => $formId))); if (!$form->ShowThankyou && $form->ReturnUrl) { $mainframe->redirect($form->ReturnUrl); return; } // SESSION quick hack - we base64 encode it here and decode it when we show it $session =& JFactory::getSession(); $formParams = new stdClass(); $formParams->formProcessed = true; $formParams->submissionId = $SubmissionId; $formParams->thankYouMessage = base64_encode($thankYouMessage); $session->set('com_rsform.formparams.' . $formId, $formParams); // Cache workaround #2 if ($cache_enabled) { $uniqid = uniqid('rsform'); $u .= strpos($u, '?') === false ? '?skipcache=' . $uniqid : '&skipcache=' . $uniqid; } $mainframe->redirect($u); } return false; }