public function display($tpl = null) { $this->app = JFactory::getApplication(); $this->doc = JFactory::getDocument(); $this->document =& $this->doc; $this->params = $this->app->getParams('com_rsform'); $this->layout = $this->getLayout(); $this->directory = $this->get('Directory'); $this->tooltipClass = RSFormProHelper::getTooltipClass(); if ($this->layout == 'view') { $this->doc->addStyleSheet(JURI::root(true) . '/components/com_rsform/assets/css/directory.css'); $this->template = $this->get('template'); $this->canEdit = RSFormProHelper::canEdit($this->params->get('formId'), $this->app->input->getInt('id', 0)); $this->id = $this->app->input->getInt('id', 0); // Add custom CSS and JS if ($this->directory->JS) { $this->doc->addCustomTag($this->directory->JS); } if ($this->directory->CSS) { $this->doc->addCustomTag($this->directory->CSS); } // Add pathway $this->app->getPathway()->addItem(JText::_('RSFP_SUBM_DIR_VIEW'), ''); } elseif ($this->layout == 'edit') { if (RSFormProHelper::canEdit($this->params->get('formId'), $this->app->input->getInt('id', 0))) { $this->doc->addStyleSheet(JURI::root(true) . '/components/com_rsform/assets/css/directory.css'); $this->fields = $this->get('EditFields'); } else { $this->app->redirect(JURI::root()); } // Add pathway $this->app->getPathway()->addItem(JText::_('RSFP_SUBM_DIR_EDIT'), ''); } else { $this->search = $this->get('Search'); $this->items = $this->get('Items'); $this->uploadFields = $this->get('uploadFields'); $this->multipleFields = $this->get('multipleFields'); $this->unescapedFields = array_merge($this->multipleFields, $this->uploadFields); $this->fields = $this->get('Fields'); $this->headers = RSFormProHelper::getDirectoryStaticHeaders(); $this->hasDetailFields = $this->hasDetailFields(); $this->hasSearchFields = $this->hasSearchFields(); $this->viewableFields = $this->getViewableFields(); $this->pagination = $this->get('Pagination'); $this->filter_search = $this->get('Search'); $this->filter_order = $this->get('ListOrder'); $this->filter_order_Dir = $this->get('ListDirn'); // Add custom CSS and JS if ($this->directory->JS) { $this->doc->addCustomTag($this->directory->JS); } if ($this->directory->CSS) { $this->doc->addCustomTag($this->directory->CSS); } } if ($this->params->get('robots')) { $this->document->setMetadata('robots', $this->params->get('robots')); } if ($this->params->get('menu-meta_description')) { $this->document->setDescription($this->params->get('menu-meta_description')); } if ($this->params->get('menu-meta_keywords')) { $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords')); } $title = $this->params->get('page_title', ''); if (empty($title)) { $title = JFactory::getConfig()->get('sitename'); } elseif (JFactory::getConfig()->get('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', JFactory::getConfig()->get('sitename'), $title); } elseif (JFactory::getConfig()->get('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, JFactory::getConfig()->get('sitename')); } $this->document->setTitle($title); parent::display($tpl); }
protected function storeDirectory() { // Add directory #__rsform_directory & #__rsform_directory_fields if ($directory = $this->getDirectory()) { // No need for these unset($directory->formId); $headers = RSFormProHelper::getDirectoryStaticHeaders(); $this->xml->add('directory'); foreach ($directory as $property => $value) { if ($property == 'fields') { $this->xml->add('fields'); foreach ($value as $field) { // No need for this. unset($field->formId); // Special case - static headers if ($field->componentId < 0 && isset($headers[$field->componentId])) { // Do nothing } else { $field->componentId = isset($this->fields[$field->componentId]) ? $this->fields[$field->componentId] : ''; } $this->xml->add('field'); foreach ($field as $property => $value) { $this->xml->add($property, $value); } $this->xml->add('/field'); } $this->xml->add('/fields'); } else { $this->xml->add($property, $value); } } $this->xml->add('/directory'); } }
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&task=submissions.view.file&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(); }
public function autoGenerateLayout() { $formId = $this->_directory->formId; $filter = JFilterInput::getInstance(); $layout = JPATH_ADMINISTRATOR . '/components/com_rsform/layouts/' . $filter->clean($this->_directory->ViewLayoutName, 'path') . '.php'; if (!file_exists($layout)) { return false; } $headers = RSFormProHelper::getDirectoryStaticHeaders(); $fields = RSFormProHelper::getDirectoryFields($formId); $quickfields = $this->getQuickFields(); $imagefields = $this->getImagesFields(); $this->_directory->ViewLayout = (include $layout); }
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; }