1c57f0bb6b82a9175f57a759fd918f1ffb96cf30
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * This class gets the name of the file to upload
39 class CRM_Export_Form_Map
extends CRM_Core_Form
{
47 protected $_mapperFields;
50 * number of columns in import file
55 protected $_exportColumnCount;
63 protected $_mappingId;
66 * Function to actually build the form
71 public function preProcess() {
72 $this->_exportColumnCount
= $this->get('exportColumnCount');
73 if (!$this->_exportColumnCount
) {
74 $this->_exportColumnCount
= 10;
77 $this->_exportColumnCount
= $this->_exportColumnCount +
10;
80 $this->_mappingId
= $this->get('mappingId');
83 public function buildQuickForm() {
84 CRM_Core_BAO_Mapping
::buildMappingForm($this,
87 $this->_exportColumnCount
,
89 $this->get('exportMode')
92 $this->addButtons(array(
95 'name' => ts('<< Previous'),
99 'name' => ts('Export >>'),
100 'spacing' => ' ',
104 'name' => ts('Done'),
111 * global validation rules for the form
113 * @param array $fields posted values of the form
115 * @return array list of errors to be posted back to the form
119 static function formRule($fields, $values, $mappingTypeId) {
122 if (!empty($fields['saveMapping']) && !empty($fields['_qf_Map_next'])) {
123 $nameField = CRM_Utils_Array
::value('saveMappingName', $fields);
124 if (empty($nameField)) {
125 $errors['saveMappingName'] = ts('Name is required to save Export Mapping');
128 //check for Duplicate mappingName
129 if (CRM_Core_BAO_Mapping
::checkMapping($nameField, $mappingTypeId)) {
130 $errors['saveMappingName'] = ts('Duplicate Export Mapping Name');
135 if (!empty($errors)) {
137 $assignError = new CRM_Core_Page();
138 $assignError->assign('mappingDetailsError', $_flag);
147 * Process the uploaded file
152 public function postProcess() {
153 $params = $this->controller
->exportValues($this->_name
);
154 $exportParams = $this->controller
->exportValues('Select');
156 $greetingOptions = CRM_Export_Form_Select
::getGreetingOptions();
158 if (!empty($greetingOptions)) {
159 foreach ($greetingOptions as $key => $value) {
160 if ($option = CRM_Utils_Array
::value($key, $exportParams)) {
161 if ($greetingOptions[$key][$option] == ts('Other')) {
162 $exportParams[$key] = $exportParams["{$key}_other"];
164 elseif ($greetingOptions[$key][$option] == ts('List of names')) {
165 $exportParams[$key] = '';
168 $exportParams[$key] = $greetingOptions[$key][$option];
174 $currentPath = CRM_Utils_System
::currentPath();
177 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $this);
178 if (CRM_Utils_Rule
::qfKey($qfKey)) {
179 $urlParams = "&qfKey=$qfKey";
182 //get the button name
183 $buttonName = $this->controller
->getButtonName('done');
184 $buttonName1 = $this->controller
->getButtonName('next');
185 if ($buttonName == '_qf_Map_done') {
186 $this->set('exportColumnCount', NULL);
187 $this->controller
->resetPage($this->_name
);
188 return CRM_Utils_System
::redirect(CRM_Utils_System
::url($currentPath, 'force=1' . $urlParams));
191 if ($this->controller
->exportValue($this->_name
, 'addMore')) {
192 $this->set('exportColumnCount', $this->_exportColumnCount
);
196 $mapperKeys = $params['mapper'][1];
199 foreach ($mapperKeys as $value) {
206 $this->set('mappingId', NULL);
207 CRM_Utils_System
::redirect(CRM_Utils_System
::url($currentPath, '_qf_Map_display=true' . $urlParams));
210 if ($buttonName1 == '_qf_Map_next') {
211 if (!empty($params['updateMapping'])) {
212 //save mapping fields
213 CRM_Core_BAO_Mapping
::saveMappingFields($params, $params['mappingId']);
216 if (!empty($params['saveMapping'])) {
217 $mappingParams = array(
218 'name' => $params['saveMappingName'],
219 'description' => $params['saveMappingDesc'],
220 'mapping_type_id' => $this->get('mappingTypeId'),
223 $saveMapping = CRM_Core_BAO_Mapping
::add($mappingParams);
225 //save mapping fields
226 CRM_Core_BAO_Mapping
::saveMappingFields($params, $saveMapping->id
);
231 CRM_Export_BAO_Export
::exportComponents($this->get('selectAll'),
232 $this->get('componentIds'),
233 $this->get('queryParams'),
234 $this->get(CRM_Utils_Sort
::SORT_ORDER
),
236 $this->get('returnProperties'),
237 $this->get('exportMode'),
238 $this->get('componentClause'),
239 $this->get('componentTable'),
240 $this->get('mergeSameAddress'),
241 $this->get('mergeSameHousehold'),
247 * Return a descriptive name for the page, used in wizard header
252 public function getTitle() {
253 return ts('Select Fields to Export');