示例#1
0
 public function display($tpl = null)
 {
     // set title
     JToolBarHelper::title('RSForm! Pro', 'rsform');
     // adding the toolbar on 2.5
     if (!RSFormProHelper::isJ('3.0')) {
         $this->addToolbar();
     }
     $layout = strtolower($this->getLayout());
     if ($layout == 'edit') {
         JToolBarHelper::apply('directory.apply');
         JToolBarHelper::save('directory.save');
         JToolBarHelper::cancel('directory.cancel');
         $backIcon = RSFormProHelper::isJ('3.0') ? 'previous' : 'back';
         JToolBarHelper::custom('directory.cancelform', $backIcon, $backIcon, JText::_('RSFP_BACK_TO_FORM'), false);
         RSFormProHelper::loadCodeMirror();
         $this->directory = $this->get('Directory');
         $this->formId = JRequest::getInt('formId', 0);
         $this->tab = JRequest::getInt('tab', 0);
         $this->emails = $this->get('emails');
         $this->fields = RSFormProHelper::getDirectoryFields($this->formId);
         $this->quickfields = $this->get('QuickFields');
         $lists['ViewLayoutAutogenerate'] = RSFormProHelper::renderHTML('select.booleanlist', 'jform[ViewLayoutAutogenerate]', 'onclick="changeDirectoryAutoGenerateLayout(' . $this->formId . ', this.value);"', $this->directory->ViewLayoutAutogenerate);
         $lists['enablepdf'] = RSFormProHelper::renderHTML('select.booleanlist', 'jform[enablepdf]', '', $this->directory->enablepdf);
         $lists['enablecsv'] = RSFormProHelper::renderHTML('select.booleanlist', 'jform[enablecsv]', '', $this->directory->enablecsv);
         $this->lists = $lists;
     } elseif ($layout == 'edit_emails') {
         $this->emails = $this->get('emails');
     } else {
         $this->addToolbar();
         JToolBarHelper::title(JText::_('RSFP_SUBM_DIR'), 'rsform');
         JToolbarHelper::deleteList('', 'directory.remove');
         $this->sidebar = $this->get('Sidebar');
         $this->forms = $this->get('forms');
         $this->pagination = $this->get('pagination');
         $this->sortColumn = $this->get('sortColumn');
         $this->sortOrder = $this->get('sortOrder');
     }
     parent::display($tpl);
 }
示例#2
0
 public function getImagesFields()
 {
     $cids = array();
     $query = $this->_db->getQuery(true);
     $formId = JRequest::getInt('formId');
     $fields = RSFormProHelper::getDirectoryFields($formId);
     if (!empty($fields)) {
         foreach ($fields as $field) {
             if ($field->indetails) {
                 $cids[] = $field->componentId;
             }
         }
     }
     JArrayHelper::toInteger($cids);
     if (!empty($cids)) {
         $query->clear()->select($this->_db->qn('p.PropertyValue'))->from($this->_db->qn('#__rsform_properties', 'p'))->join('LEFT', $this->_db->qn('#__rsform_components', 'c') . ' ON ' . $this->_db->qn('p.ComponentId') . ' = ' . $this->_db->qn('c.ComponentId'))->join('LEFT', $this->_db->qn('#__rsform_directory_fields', 'd') . ' ON ' . $this->_db->qn('d.ComponentId') . ' = ' . $this->_db->qn('c.ComponentId'))->where($this->_db->qn('c.FormId') . ' = ' . (int) $formId)->where($this->_db->qn('p.PropertyName') . ' = ' . $this->_db->q('NAME'))->where($this->_db->qn('c.ComponentId') . ' IN (' . implode(',', $cids) . ')')->where($this->_db->qn('c.ComponentTypeId') . ' = 9')->where($this->_db->qn('c.Published') . ' = 1')->order($this->_db->qn('d.ordering'));
         $this->_db->setQuery($query);
         return $this->_db->loadColumn();
     }
     return array();
 }
 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;
 }
示例#4
0
 public function download()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel('directory');
     $directory = $model->getDirectory();
     if (!$directory->enablecsv) {
         JError::raiseWarning(500, JText::_('RSFP_VIEW_DIRECTORY_NO_CSV'));
         return $app->redirect(JURI::root());
     }
     if (!$model->isValid()) {
         JError::raiseWarning(500, $model->getError());
         return $app->redirect(JURI::root());
     }
     $db = JFactory::getDbo();
     $params = $app->getParams('com_rsform');
     $menu = $app->getMenu();
     $active = $menu->getActive();
     $formId = $params->get('formId');
     $cids = JRequest::getVar('cid');
     JArrayHelper::toInteger($cids);
     $fields = RSFormProHelper::getDirectoryFields($formId);
     $headers = RSFormProHelper::getDirectoryStaticHeaders();
     $downloadableFields = array();
     $downloadableFieldCaptions = array();
     foreach ($fields as $field) {
         if ($field->incsv) {
             $downloadableFields[] = (object) array('name' => $field->FieldName, 'static' => $field->componentId < 0 && isset($headers[$field->componentId]) ? 1 : 0);
             $downloadableFieldCaptions[] = $field->FieldCaption;
         }
     }
     list($multipleSeparator, $uploadFields, $multipleFields, $secret) = RSFormProHelper::getDirectoryFormProperties($formId);
     // Get submissions
     $db->setQuery("SELECT * FROM #__rsform_submissions WHERE FormId='" . (int) $formId . "' AND SubmissionId IN (" . implode(',', $cids) . ")");
     $submissions = $db->loadObjectList('SubmissionId');
     // Get values
     $names = array();
     foreach ($downloadableFields as $field) {
         if (!$field->static) {
             $names[] = $db->q($field->name);
         }
     }
     $query = $db->getQuery(true);
     $query->select($db->qn('SubmissionId'))->select($db->qn('FieldName'))->select($db->qn('FieldValue'))->from($db->qn('#__rsform_submission_values'))->where($db->qn('FormId') . '=' . $db->q($formId));
     if ($cids) {
         $query->where($db->qn('SubmissionId') . ' IN (' . implode(',', $cids) . ')');
     }
     if ($names) {
         $query->where($db->qn('FieldName') . ' IN (' . implode(',', $names) . ')');
     }
     $db->setQuery($query);
     $values = $db->loadObjectList();
     // Combine them
     foreach ($values as $item) {
         if (!isset($submissions[$item->SubmissionId]->values)) {
             $submissions[$item->SubmissionId]->values = array();
         }
         // process here
         if (in_array($item->FieldName, $uploadFields)) {
             $item->FieldValue = '<a href="' . JURI::root() . 'index.php?option=com_rsform&amp;task=submissions.view.file&amp;hash=' . md5($item->SubmissionId . $secret . $item->FieldName) . '">' . basename($item->FieldValue) . '</a>';
         } elseif (in_array($item->FieldName, $multipleFields)) {
             $item->FieldValue = str_replace("\n", $multipleSeparator, $item->FieldValue);
         }
         $submissions[$item->SubmissionId]->values[$item->FieldName] = $item->FieldValue;
     }
     $enclosure = '"';
     $delimiter = ',';
     $download_name = $active->alias . '.csv';
     header('Cache-Control: public, must-revalidate');
     header('Cache-Control: pre-check=0, post-check=0, max-age=0');
     if (!preg_match('#MSIE#', $_SERVER['HTTP_USER_AGENT'])) {
         header("Pragma: no-cache");
     }
     header("Expires: 0");
     header("Content-Description: File Transfer");
     header("Expires: Sat, 01 Jan 2000 01:00:00 GMT");
     if (preg_match('#Opera#', $_SERVER['HTTP_USER_AGENT'])) {
         header("Content-Type: application/octetstream");
     } else {
         header("Content-Type: application/octet-stream");
     }
     header('Content-Disposition: attachment; filename="' . $download_name . '"');
     header("Content-Transfer-Encoding: binary\n");
     ob_end_clean();
     echo $enclosure . implode($enclosure . $delimiter . $enclosure, $downloadableFieldCaptions) . $enclosure . "\n";
     foreach ($cids as $cid) {
         $row = array();
         foreach ($downloadableFields as $field) {
             $value = '';
             if (!$field->static && isset($submissions[$cid]->values[$field->name])) {
                 $value = $submissions[$cid]->values[$field->name];
             } elseif ($field->static && isset($submissions[$cid]->{$field->name})) {
                 // Show a text for the "confirmed" column.
                 if ($field->name == 'confirmed') {
                     $value = $submissions[$cid]->{$field->name} ? JText::_('RSFP_YES') : JText::_('RSFP_NO');
                 } else {
                     $value = $submissions[$cid]->{$field->name};
                 }
             }
             $row[] = $value;
         }
         echo $enclosure . implode($enclosure . $delimiter . $enclosure, str_replace($enclosure, $enclosure . $enclosure, $row)) . $enclosure . "\n";
     }
     $app->close();
 }
示例#5
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;
 }