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;
 }