103dd4af9b1e4cff5c9ffc7dbfdf4130ff48cb37
[civicrm-core.git] / CRM / Contact / Import / Form / Summary.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * This class summarizes the import results
38 */
39 class CRM_Contact_Import_Form_Summary extends CRM_Import_Form_Summary {
40
41 /**
42 * Function to set variables up before form is built
43 *
44 * @return void
45 * @access public
46 */
47 public function preProcess() {
48 // set the error message path to display
49 $errorFile = $this->assign('errorFile', $this->get('errorFile'));
50
51 $totalRowCount = $this->get('totalRowCount');
52 $relatedCount = $this->get('relatedCount');
53 $totalRowCount += $relatedCount;
54
55 $invalidRowCount = $this->get('invalidRowCount');
56 $conflictRowCount = $this->get('conflictRowCount');
57 $duplicateRowCount = $this->get('duplicateRowCount');
58 $onDuplicate = $this->get('onDuplicate');
59 $mismatchCount = $this->get('unMatchCount');
60 $unparsedAddressCount = $this->get('unparsedAddressCount');
61 if ($duplicateRowCount > 0) {
62 $urlParams = 'type=' . CRM_Import_Parser::DUPLICATE . '&parser=CRM_Contact_Import_Parser';
63 $this->set('downloadDuplicateRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
64 }
65 elseif ($mismatchCount) {
66 $urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
67 $this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
68 }
69 else {
70 $duplicateRowCount = 0;
71 $this->set('duplicateRowCount', $duplicateRowCount);
72 }
73 if ($unparsedAddressCount) {
74 $urlParams = 'type=' . CRM_Import_Parser::UNPARSED_ADDRESS_WARNING . '&parser=CRM_Contact_Import_Parser';
75 $this->assign('downloadAddressRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
76 $unparsedStreetAddressString = ts('Records imported successfully but unable to parse some of the street addresses');
77 $this->assign('unparsedStreetAddressString', $unparsedStreetAddressString);
78 }
79 $this->assign('dupeError', FALSE);
80
81 if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
82 $dupeActionString = ts('These records have been updated with the imported data.');
83 }
84 elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_REPLACE) {
85 $dupeActionString = ts('These records have been replaced with the imported data.');
86 }
87 elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
88 $dupeActionString = ts('These records have been filled in with the imported data.');
89 }
90 else {
91 /* Skip by default */
92
93 $dupeActionString = ts('These records have not been imported.');
94
95 $this->assign('dupeError', TRUE);
96 }
97 //now we also create relative contact in update and fill mode
98 $this->set('validRowCount', $totalRowCount - $invalidRowCount -
99 $conflictRowCount - $duplicateRowCount - $mismatchCount
100 );
101
102 $this->assign('dupeActionString', $dupeActionString);
103
104 $properties = array('totalRowCount', 'validRowCount', 'invalidRowCount', 'conflictRowCount', 'downloadConflictRecordsUrl', 'downloadErrorRecordsUrl', 'duplicateRowCount', 'downloadDuplicateRecordsUrl', 'downloadMismatchRecordsUrl', 'groupAdditions', 'tagAdditions', 'unMatchCount', 'unparsedAddressCount');
105 foreach ($properties as $property) {
106 $this->assign($property, $this->get($property));
107 }
108
109 $session = CRM_Core_Session::singleton();
110 $session->pushUserContext(CRM_Utils_System::url('civicrm/import/contact', 'reset=1'));
111 }
112
113 /**
114 * Clean up the import table we used
115 *
116 * @return void
117 * @access public
118 */
119 public function postProcess() {
120 $dao = new CRM_Core_DAO();
121 $db = $dao->getDatabaseConnection();
122
123 $importTableName = $this->get('importTableName');
124 // do a basic sanity check here
125 if (strpos($importTableName, 'civicrm_import_job_') === 0) {
126 $query = "DROP TABLE IF EXISTS $importTableName";
127 $db->query($query);
128 }
129 }
130
131 }
132