public static function checkOrderData($formData, $invalid = array(), $ccDataPrefix = 'cc_')
 {
     if ($formData == null) {
         $formData = $_POST['form'];
     }
     if (self::canAcquireCCData($formData)) {
         $prefix = $ccDataPrefix;
         foreach ($formData as $key => $value) {
             // for each field
             if (substr($key, 0, strlen($prefix)) === $prefix) {
                 // if it is a field we are searching for (prefixed)
                 if ($value == '') {
                     // if the value for the field is empty
                     $invalid[] = RSFormProHelper::getComponentId($key);
                     // add it to the invalid array
                 }
             }
         }
     }
 }
示例#2
0
 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;
 }