3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class previews the uploaded file and returns summary
40 class CRM_Event_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 $invalidRowCount = $this->get('invalidRowCount');
55 $conflictRowCount = $this->get('conflictRowCount');
56 $mismatchCount = $this->get('unMatchCount');
58 //get the mapping name displayed if the mappingId is set
59 $mappingId = $this->get('loadMappingId');
61 $mapDAO = new CRM_Core_DAO_Mapping();
62 $mapDAO->id
= $mappingId;
64 $this->assign('loadedMapping', $mappingId);
65 $this->assign('savedName', $mapDAO->name
);
68 if ($skipColumnHeader) {
69 $this->assign('skipColumnHeader', $skipColumnHeader);
70 $this->assign('rowDisplayCount', 3);
73 $this->assign('rowDisplayCount', 2);
76 if ($invalidRowCount) {
77 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
78 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
81 if ($conflictRowCount) {
82 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
83 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
87 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
88 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
93 'dataValues', 'columnCount',
94 'totalRowCount', 'validRowCount',
95 'invalidRowCount', 'conflictRowCount',
96 'downloadErrorRecordsUrl',
97 'downloadConflictRecordsUrl',
98 'downloadMismatchRecordsUrl',
101 foreach ($properties as $property) {
102 $this->assign($property, $this->get($property));
107 * Process the mapped fields and map it into the uploaded file
108 * preview the file and extract some summary statistics
113 public function postProcess() {
114 $fileName = $this->controller
->exportValue('DataSource', 'uploadFile');
115 $skipColumnHeader = $this->controller
->exportValue('DataSource', 'skipColumnHeader');
116 $invalidRowCount = $this->get('invalidRowCount');
117 $conflictRowCount = $this->get('conflictRowCount');
118 $onDuplicate = $this->get('onDuplicate');
120 $config = CRM_Core_Config
::singleton();
121 $seperator = $config->fieldSeparator
;
123 $mapper = $this->controller
->exportValue('MapField', 'mapper');
124 $mapperKeys = array();
126 foreach ($mapper as $key => $value) {
127 $mapperKeys[$key] = $mapper[$key][0];
130 $parser = new CRM_Event_Import_Parser_Participant($mapperKeys);
132 $mapFields = $this->get('fields');
134 foreach ($mapper as $key => $value) {
136 if (isset($mapFields[$mapper[$key][0]])) {
137 $header[] = $mapFields[$mapper[$key][0]];
139 $mapperFields[] = implode(' - ', $header);
141 $parser->run($fileName, $seperator,
144 CRM_Import_Parser
::MODE_IMPORT
,
145 $this->get('contactType'),
149 // add all the necessary variables to the form
150 $parser->set($this, CRM_Import_Parser
::MODE_IMPORT
);
152 // check if there is any error occured
154 $errorStack = CRM_Core_Error
::singleton();
155 $errors = $errorStack->getErrors();
156 $errorMessage = array();
158 if (is_array($errors)) {
159 foreach ($errors as $key => $value) {
160 $errorMessage[] = $value['message'];
163 $errorFile = $fileName['name'] . '.error.log';
165 if ($fd = fopen($errorFile, 'w')) {
166 fwrite($fd, implode('\n', $errorMessage));
170 $this->set('errorFile', $errorFile);
171 $urlParams = 'type=' . CRM_Import_Parser
::ERROR
. '&parser=CRM_Event_Import_Parser';
172 $this->set('downloadErrorRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
173 $urlParams = 'type=' . CRM_Import_Parser
::CONFLICT
. '&parser=CRM_Event_Import_Parser';
174 $this->set('downloadConflictRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));
175 $urlParams = 'type=' . CRM_Import_Parser
::NO_MATCH
. '&parser=CRM_Event_Import_Parser';
176 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System
::url('civicrm/export', $urlParams));