3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 previews the uploaded file and returns summary
40 class CRM_Contribute_Import_Form_Preview
extends CRM_Import_Form_Preview
{
43 * Function to set variables up before form is built
48 public function preProcess() {
49 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
51 //get the data from the session
52 $dataValues = $this->get('dataValues');
53 $mapper = $this->get('mapper');
54 $softCreditFields = $this->get('softCreditFields');
55 $invalidRowCount = $this->get('invalidRowCount');
56 $conflictRowCount = $this->get('conflictRowCount');
57 $mismatchCount = $this->get('unMatchCount');
59 //get the mapping name displayed if the mappingId is set
60 $mappingId = $this->get('loadMappingId');
62 $mapDAO = new CRM_Core_DAO_Mapping();
63 $mapDAO->id
= $mappingId;
65 $this->assign('loadedMapping', $mappingId);
66 $this->assign('savedName', $mapDAO->name
);
69 if ($skipColumnHeader) {
70 $this->assign('skipColumnHeader', $skipColumnHeader);
71 $this->assign('rowDisplayCount', 3);
74 $this->assign('rowDisplayCount', 2);
77 if ($invalidRowCount) {
78 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Contribute_Import_Parser';
79 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
82 if ($conflictRowCount) {
83 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Contribute_Import_Parser';
84 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
88 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Contribute_Import_Parser';
89 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
93 'mapper', 'softCreditFields',
94 'dataValues', 'columnCount',
95 'totalRowCount', 'validRowCount',
96 'invalidRowCount', 'conflictRowCount',
97 'downloadErrorRecordsUrl',
98 'downloadConflictRecordsUrl',
99 'downloadMismatchRecordsUrl',
102 foreach ($properties as $property) {
103 $this->assign($property, $this->get($property));
108 * Process the mapped fields and map it into the uploaded file
109 * preview the file and extract some summary statistics
114 public function postProcess() {
115 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
116 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
117 $invalidRowCount = $this->get('invalidRowCount');
118 $conflictRowCount = $this->get('conflictRowCount');
119 $onDuplicate = $this->get('onDuplicate');
121 $config = CRM_Core_Config
::singleton();
122 $seperator = $config->fieldSeparator
;
124 $mapper = $this->controller
->exportValue('MapField', 'mapper');
125 $mapperKeys = array();
126 $mapperSoftCredit = array();
127 $mapperPhoneType = array();
129 foreach ($mapper as $key => $value) {
130 $mapperKeys[$key] = $mapper[$key][0];
131 if (isset($mapper[$key][0]) && $mapper[$key][0] == 'soft_credit') {
132 $mapperSoftCredit[$key] = $mapper[$key][1];
135 $mapperSoftCredit[$key] = NULL;
139 $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeys, $mapperSoftCredit, $mapperPhoneType);
141 $mapFields = $this->get('fields');
143 foreach ($mapper as $key => $value) {
145 if (isset($mapFields[$mapper[$key][0]])) {
146 $header[] = $mapFields[$mapper[$key][0]];
148 $mapperFields[] = implode(' - ', $header);
150 $parser->run($fileName, $seperator,
153 CRM_Import_Parser
::MODE_IMPORT
,
154 $this->get('contactType'),
158 // add all the necessary variables to the form
159 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
161 // check if there is any error occured
163 $errorStack = CRM_Core_Error
::singleton();
164 $errors = $errorStack->getErrors();
165 $errorMessage = array();
167 if (is_array($errors)) {
168 foreach ($errors as $key => $value) {
169 $errorMessage[] = $value['message'];
172 $errorFile = $fileName['name'] . '.error.log';
174 if ($fd = fopen($errorFile, 'w')) {
175 fwrite($fd, implode('\n', $errorMessage));
179 $this->set('errorFile', $errorFile);
180 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Contribute_Import_Parser';
181 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
182 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Contribute_Import_Parser';
183 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
184 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Contribute_Import_Parser';
185 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));