First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,60 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Contact_Import_Controller extends CRM_Core_Controller {
/**
* Class constructor.
*
* @param null $title
* @param bool|int $action
* @param bool $modal
*/
public function __construct($title = NULL, $action = CRM_Core_Action::NONE, $modal = TRUE) {
parent::__construct($title, $modal);
// lets get around the time limit issue if possible, CRM-2113
if (!ini_get('safe_mode')) {
set_time_limit(0);
}
$this->_stateMachine = new CRM_Import_StateMachine($this, $action);
// create and instantiate the pages
$this->addPages($this->_stateMachine, $action);
// add all the actions
$config = CRM_Core_Config::singleton();
$this->addActions($config->uploadDir, array('uploadFile'));
}
}

View file

@ -0,0 +1,201 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Class CRM_Contact_Import_Field
*/
class CRM_Contact_Import_Field {
/**#@+
* @var string
*/
/**
* Name of the field
*/
public $_name;
/**
* Title of the field to be used in display
*/
public $_title;
/**
* Type of field
* @var enum
*/
public $_type;
/**
* Is this field required
* @var boolean
*/
public $_required;
/**
* Data to be carried for use by a derived class
* @var object
*/
public $_payload;
/**
* Regexp to match the CSV header of this column/field
* @var string
*/
public $_columnPattern;
/**
* Regexp to match the pattern of data from various column/fields
* @var string
*/
public $_dataPattern;
/**
* Regexp to match the pattern of header from various column/fields
* @var string
*/
public $_headerPattern;
/**
* Location type
* @var int
*/
public $_hasLocationType;
/**
* Does this field have a phone type
* @var string
*/
public $_phoneType;
/**
* Value of this field
* @var object
*/
public $_value;
/**
* Does this field have a relationship info
* @var string
*/
public $_related;
/**
* Does this field have a relationship Contact Type
* @var string
*/
public $_relatedContactType;
/**
* Does this field have a relationship Contact Details
* @var string
*/
public $_relatedContactDetails;
/**
* Does this field have a related Contact info of Location Type
* @var int
*/
public $_relatedContactLocType;
/**
* Does this field have a related Contact info of Phone Type
* @var string
*/
public $_relatedContactPhoneType;
/**
* @param string $name
* @param $title
* @param int $type
* @param string $columnPattern
* @param string $dataPattern
* @param null $hasLocationType
* @param null $phoneType
* @param null $related
* @param null $relatedContactType
* @param null $relatedContactDetails
* @param null $relatedContactLocType
* @param null $relatedContactPhoneType
*/
public function __construct($name, $title, $type = CRM_Utils_Type::T_INT, $columnPattern = '//', $dataPattern = '//', $hasLocationType = NULL, $phoneType = NULL, $related = NULL, $relatedContactType = NULL, $relatedContactDetails = NULL, $relatedContactLocType = NULL, $relatedContactPhoneType = NULL) {
$this->_name = $name;
$this->_title = $title;
$this->_type = $type;
$this->_columnPattern = $columnPattern;
$this->_dataPattern = $dataPattern;
$this->_hasLocationType = $hasLocationType;
$this->_phoneType = $phoneType;
$this->_related = $related;
$this->_relatedContactType = $relatedContactType;
$this->_relatedContactDetails = $relatedContactDetails;
$this->_relatedContactLocType = $relatedContactLocType;
$this->_relatedContactPhoneType = $relatedContactPhoneType;
$this->_value = NULL;
}
public function resetValue() {
$this->_value = NULL;
}
/**
* The value is in string format.
*
* Convert the value to the type of this field
* and set the field value with the appropriate type
*
* @param mixed $value
*/
public function setValue($value) {
$this->_value = $value;
}
/**
* Validate something we didn't document.
*
* @return bool
*/
public function validate() {
// echo $this->_value."===========<br>";
$message = '';
if ($this->_value === NULL) {
return TRUE;
}
// Commented due to bug CRM-150, internationalization/wew.
// if ( $this->_name == 'phone' ) {
// return CRM_Utils_Rule::phone( $this->_value );
// }
if ($this->_name == 'email') {
return CRM_Utils_Rule::email($this->_value);
}
}
}

View file

@ -0,0 +1,420 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2009 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class delegates to the chosen DataSource to grab the data to be imported.
*/
class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form {
private $_dataSource;
private $_dataSourceIsValid = FALSE;
private $_dataSourceClassFile;
private $_dataSourceClass;
/**
* Set variables up before form is built.
*/
public function preProcess() {
//Test database user privilege to create table(Temporary) CRM-4725
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$daoTestPrivilege = new CRM_Core_DAO();
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_one(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("CREATE TEMPORARY TABLE import_job_permission_two(test int) ENGINE=InnoDB");
$daoTestPrivilege->query("DROP TEMPORARY TABLE IF EXISTS import_job_permission_one, import_job_permission_two");
unset($errorScope);
if ($daoTestPrivilege->_lastError) {
CRM_Core_Error::fatal(ts('Database Configuration Error: Insufficient permissions. Import requires that the CiviCRM database user has permission to create temporary tables. Contact your site administrator for assistance.'));
}
$results = array();
$config = CRM_Core_Config::singleton();
$handler = opendir($config->uploadDir);
$errorFiles = array('sqlImport.errors', 'sqlImport.conflicts', 'sqlImport.duplicates', 'sqlImport.mismatch');
// check for post max size avoid when called twice
$snippet = CRM_Utils_Array::value('snippet', $_GET, 0);
if (empty($snippet)) {
CRM_Utils_Number::formatUnitSize(ini_get('post_max_size'), TRUE);
}
while ($file = readdir($handler)) {
if ($file != '.' && $file != '..' &&
in_array($file, $errorFiles) && !is_writable($config->uploadDir . $file)
) {
$results[] = $file;
}
}
closedir($handler);
if (!empty($results)) {
CRM_Core_Error::fatal(ts('<b>%1</b> file(s) in %2 directory are not writable. Listed file(s) might be used during the import to log the errors occurred during Import process. Contact your site administrator for assistance.', array(
1 => implode(', ', $results),
2 => $config->uploadDir,
)));
}
$this->_dataSourceIsValid = FALSE;
$this->_dataSource = CRM_Utils_Request::retrieve(
'dataSource',
'String',
CRM_Core_DAO::$_nullObject,
FALSE,
NULL,
'GET'
);
$this->_params = $this->controller->exportValues($this->_name);
if (!$this->_dataSource) {
//considering dataSource as base criteria instead of hidden_dataSource.
$this->_dataSource = CRM_Utils_Array::value('dataSource',
$_POST,
CRM_Utils_Array::value('dataSource',
$this->_params
)
);
$this->assign('showOnlyDataSourceFormPane', FALSE);
}
else {
$this->assign('showOnlyDataSourceFormPane', TRUE);
}
$dataSources = $this->_getDataSources();
if ($this->_dataSource && isset($dataSources[$this->_dataSource])) {
$this->_dataSourceIsValid = TRUE;
$this->assign('showDataSourceFormPane', TRUE);
$dataSourcePath = explode('_', $this->_dataSource);
$templateFile = "CRM/Contact/Import/Form/" . $dataSourcePath[3] . ".tpl";
$this->assign('dataSourceFormTemplateFile', $templateFile);
}
elseif ($this->_dataSource) {
throw new \CRM_Core_Exception("Invalid data source");
}
}
/**
* Build the form object.
*/
public function buildQuickForm() {
// If there's a dataSource in the query string, we need to load
// the form from the chosen DataSource class
if ($this->_dataSourceIsValid) {
$this->_dataSourceClassFile = str_replace('_', '/', $this->_dataSource) . ".php";
require_once $this->_dataSourceClassFile;
$this->_dataSourceClass = new $this->_dataSource();
$this->_dataSourceClass->buildQuickForm($this);
}
// Get list of data sources and display them as options
$dataSources = $this->_getDataSources();
$this->assign('urlPath', "civicrm/import");
$this->assign('urlPathVar', 'snippet=4');
$this->add('select', 'dataSource', ts('Data Source'), $dataSources, TRUE,
array('onchange' => 'buildDataSourceFormBlock(this.value);')
);
// duplicate handling options
$duplicateOptions = array();
$duplicateOptions[] = $this->createElement('radio',
NULL, NULL, ts('Skip'), CRM_Import_Parser::DUPLICATE_SKIP
);
$duplicateOptions[] = $this->createElement('radio',
NULL, NULL, ts('Update'), CRM_Import_Parser::DUPLICATE_UPDATE
);
$duplicateOptions[] = $this->createElement('radio',
NULL, NULL, ts('Fill'), CRM_Import_Parser::DUPLICATE_FILL
);
$duplicateOptions[] = $this->createElement('radio',
NULL, NULL, ts('No Duplicate Checking'), CRM_Import_Parser::DUPLICATE_NOCHECK
);
$this->addGroup($duplicateOptions, 'onDuplicate',
ts('For Duplicate Contacts')
);
$mappingArray = CRM_Core_BAO_Mapping::getMappings('Import Contact');
$this->assign('savedMapping', $mappingArray);
$this->addElement('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
$js = array('onClick' => "buildSubTypes();buildDedupeRules();");
// contact types option
$contactOptions = array();
if (CRM_Contact_BAO_ContactType::isActive('Individual')) {
$contactOptions[] = $this->createElement('radio',
NULL, NULL, ts('Individual'), CRM_Import_Parser::CONTACT_INDIVIDUAL, $js
);
}
if (CRM_Contact_BAO_ContactType::isActive('Household')) {
$contactOptions[] = $this->createElement('radio',
NULL, NULL, ts('Household'), CRM_Import_Parser::CONTACT_HOUSEHOLD, $js
);
}
if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
$contactOptions[] = $this->createElement('radio',
NULL, NULL, ts('Organization'), CRM_Import_Parser::CONTACT_ORGANIZATION, $js
);
}
$this->addGroup($contactOptions, 'contactType',
ts('Contact Type')
);
$this->addElement('select', 'subType', ts('Subtype'));
$this->addElement('select', 'dedupe', ts('Dedupe Rule'));
CRM_Core_Form_Date::buildAllowedDateFormats($this);
$config = CRM_Core_Config::singleton();
$geoCode = FALSE;
if (!empty($config->geocodeMethod)) {
$geoCode = TRUE;
$this->addElement('checkbox', 'doGeocodeAddress', ts('Geocode addresses during import?'));
}
$this->assign('geoCode', $geoCode);
$this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2));
if (Civi::settings()->get('address_standardization_provider') == 'USPS') {
$this->addElement('checkbox', 'disableUSPS', ts('Disable USPS address validation during import?'));
}
$this->addButtons(array(
array(
'type' => 'upload',
'name' => ts('Continue'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Set the default values of various form elements.
*
* access public
*
* @return array
* reference to the array of default values
*/
public function setDefaultValues() {
$config = CRM_Core_Config::singleton();
$defaults = array(
'dataSource' => 'CRM_Import_DataSource_CSV',
'onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP,
'contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL,
'fieldSeparator' => $config->fieldSeparator,
);
if ($loadeMapping = $this->get('loadedMapping')) {
$this->assign('loadedMapping', $loadeMapping);
$defaults['savedMapping'] = $loadeMapping;
}
return $defaults;
}
/**
* @return array
* @throws Exception
*/
private function _getDataSources() {
// Hmm... file-system scanners don't really belong in forms...
if (isset(Civi::$statics[__CLASS__]['datasources'])) {
return Civi::$statics[__CLASS__]['datasources'];
}
// Open the data source dir and scan it for class files
global $civicrm_root;
$dataSourceDir = $civicrm_root . DIRECTORY_SEPARATOR . 'CRM' . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . 'DataSource' . DIRECTORY_SEPARATOR;
$dataSources = array();
if (!is_dir($dataSourceDir)) {
CRM_Core_Error::fatal("Import DataSource directory $dataSourceDir does not exist");
}
if (!$dataSourceHandle = opendir($dataSourceDir)) {
CRM_Core_Error::fatal("Unable to access DataSource directory $dataSourceDir");
}
while (($dataSourceFile = readdir($dataSourceHandle)) !== FALSE) {
$fileType = filetype($dataSourceDir . $dataSourceFile);
$matches = array();
if (($fileType == 'file' || $fileType == 'link') &&
preg_match('/^(.+)\.php$/', $dataSourceFile, $matches)
) {
$dataSourceClass = "CRM_Import_DataSource_" . $matches[1];
require_once $dataSourceDir . DIRECTORY_SEPARATOR . $dataSourceFile;
$object = new $dataSourceClass();
$info = $object->getInfo();
if ($object->checkPermission()) {
$dataSources[$dataSourceClass] = $info['title'];
}
}
}
closedir($dataSourceHandle);
Civi::$statics[__CLASS__]['datasources'] = $dataSources;
return $dataSources;
}
/**
* Call the DataSource's postProcess method.
*/
public function postProcess() {
$this->controller->resetPage('MapField');
if ($this->_dataSourceIsValid) {
// Setup the params array
$this->_params = $this->controller->exportValues($this->_name);
$storeParams = array(
'onDuplicate' => 'onDuplicate',
'dedupe' => 'dedupe',
'contactType' => 'contactType',
'contactSubType' => 'subType',
'dateFormats' => 'dateFormats',
'savedMapping' => 'savedMapping',
);
foreach ($storeParams as $storeName => $storeValueName) {
$$storeName = $this->exportValue($storeValueName);
$this->set($storeName, $$storeName);
}
$this->set('disableUSPS', !empty($this->_params['disableUSPS']));
$this->set('dataSource', $this->_params['dataSource']);
$this->set('skipColumnHeader', CRM_Utils_Array::value('skipColumnHeader', $this->_params));
$session = CRM_Core_Session::singleton();
$session->set('dateTypes', $dateFormats);
// Get the PEAR::DB object
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
//hack to prevent multiple tables.
$this->_params['import_table_name'] = $this->get('importTableName');
if (!$this->_params['import_table_name']) {
$this->_params['import_table_name'] = 'civicrm_import_job_' . md5(uniqid(rand(), TRUE));
}
$this->_dataSourceClass->postProcess($this->_params, $db, $this);
// We should have the data in the DB now, parse it
$importTableName = $this->get('importTableName');
$fieldNames = $this->_prepareImportTable($db, $importTableName);
$mapper = array();
$parser = new CRM_Contact_Import_Parser_Contact($mapper);
$parser->setMaxLinesToProcess(100);
$parser->run($importTableName,
$mapper,
CRM_Import_Parser::MODE_MAPFIELD,
$contactType,
$fieldNames['pk'],
$fieldNames['status'],
CRM_Import_Parser::DUPLICATE_SKIP,
NULL, NULL, FALSE,
CRM_Contact_Import_Parser::DEFAULT_TIMEOUT,
$contactSubType,
$dedupe
);
// add all the necessary variables to the form
$parser->set($this);
}
else {
CRM_Core_Error::fatal("Invalid DataSource on form post. This shouldn't happen!");
}
}
/**
* Add a PK and status column to the import table so we can track our progress.
* Returns the name of the primary key and status columns
*
* @param $db
* @param string $importTableName
*
* @return array
*/
private function _prepareImportTable($db, $importTableName) {
/* TODO: Add a check for an existing _status field;
* if it exists, create __status instead and return that
*/
$statusFieldName = '_status';
$primaryKeyName = '_id';
$this->set('primaryKeyName', $primaryKeyName);
$this->set('statusFieldName', $statusFieldName);
/* Make sure the PK is always last! We rely on this later.
* Should probably stop doing that at some point, but it
* would require moving to associative arrays rather than
* relying on numerical order of the fields. This could in
* turn complicate matters for some DataSources, which
* would also not be good. Decisions, decisions...
*/
$alterQuery = "ALTER TABLE $importTableName
ADD COLUMN $statusFieldName VARCHAR(32)
DEFAULT 'NEW' NOT NULL,
ADD COLUMN ${statusFieldName}Msg TEXT,
ADD COLUMN $primaryKeyName INT PRIMARY KEY NOT NULL
AUTO_INCREMENT";
$db->query($alterQuery);
return array('status' => $statusFieldName, 'pk' => $primaryKeyName);
}
/**
* Return a descriptive name for the page, used in wizard header
*
*
* @return string
*/
public function getTitle() {
return ts('Choose Data Source');
}
}

View file

@ -0,0 +1,973 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class gets the name of the file to upload.
*/
class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
/**
* An array of all contact fields with
* formatted custom field names.
*
* @var array
*/
protected $_formattedFieldNames;
/**
* On duplicate.
*
* @var int
*/
public $_onDuplicate;
protected $_dedupeFields;
protected static $customFields;
/**
* Attempt to match header labels with our mapper fields.
*
* FIXME: This is essentially the same function as parent::defaultFromHeader
*
* @param string $columnName name of column header
* @param array $patterns pattern to match for the column
*
* @return string
*/
public function defaultFromColumnName($columnName, &$patterns) {
if (!preg_match('/^[a-z0-9 ]$/i', $columnName)) {
if ($columnKey = array_search($columnName, $this->_mapperFields)) {
$this->_fieldUsed[$columnKey] = TRUE;
return $columnKey;
}
}
foreach ($patterns as $key => $re) {
// Skip empty key/patterns
if (!$key || !$re || strlen("$re") < 5) {
continue;
}
if (preg_match($re, $columnName)) {
$this->_fieldUsed[$key] = TRUE;
return $key;
}
}
return '';
}
/**
* Set variables up before form is built.
*/
public function preProcess() {
$dataSource = $this->get('dataSource');
$skipColumnHeader = $this->get('skipColumnHeader');
$this->_mapperFields = $this->get('fields');
$this->_importTableName = $this->get('importTableName');
$this->_onDuplicate = $this->get('onDuplicate');
$highlightedFields = array();
$highlightedFields[] = 'email';
$highlightedFields[] = 'external_identifier';
//format custom field names, CRM-2676
switch ($this->get('contactType')) {
case CRM_Import_Parser::CONTACT_INDIVIDUAL:
$contactType = 'Individual';
$highlightedFields[] = 'first_name';
$highlightedFields[] = 'last_name';
break;
case CRM_Import_Parser::CONTACT_HOUSEHOLD:
$contactType = 'Household';
$highlightedFields[] = 'household_name';
break;
case CRM_Import_Parser::CONTACT_ORGANIZATION:
$contactType = 'Organization';
$highlightedFields[] = 'organization_name';
break;
}
$this->_contactType = $contactType;
if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) {
unset($this->_mapperFields['id']);
}
else {
$highlightedFields[] = 'id';
}
if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
//Mark Dedupe Rule Fields as required, since it's used in matching contact
foreach (array(
'Individual',
'Household',
'Organization',
) as $cType) {
$ruleParams = array(
'contact_type' => $cType,
'used' => 'Unsupervised',
);
$this->_dedupeFields[$cType] = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
}
//Modify mapper fields title if fields are present in dedupe rule
if (is_array($this->_dedupeFields[$contactType])) {
foreach ($this->_dedupeFields[$contactType] as $val) {
if ($valTitle = CRM_Utils_Array::value($val, $this->_mapperFields)) {
$this->_mapperFields[$val] = $valTitle . ' (match to contact)';
}
}
}
}
// retrieve and highlight required custom fields
$formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
foreach (self::$customFields as $key => $attr) {
if (!empty($attr['is_required'])) {
$highlightedFields[] = "custom_$key";
}
}
$this->assign('highlightedFields', $highlightedFields);
$this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
$columnNames = array();
//get original col headers from csv if present.
if ($dataSource == 'CRM_Import_DataSource_CSV' && $skipColumnHeader) {
$columnNames = $this->get('originalColHeader');
}
else {
// get the field names from the temp. DB table
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
$columnsQuery = "SHOW FIELDS FROM $this->_importTableName
WHERE Field NOT LIKE '\_%'";
$columnsResult = $db->query($columnsQuery);
while ($row = $columnsResult->fetchRow(DB_FETCHMODE_ASSOC)) {
$columnNames[] = $row['Field'];
}
}
$showColNames = TRUE;
if ($dataSource == 'CRM_Import_DataSource_CSV' && !$skipColumnHeader) {
$showColNames = FALSE;
}
$this->assign('showColNames', $showColNames);
$this->_columnCount = count($columnNames);
$this->_columnNames = $columnNames;
$this->assign('columnNames', $columnNames);
//$this->_columnCount = $this->get( 'columnCount' );
$this->assign('columnCount', $this->_columnCount);
$this->_dataValues = $this->get('dataValues');
$this->assign('dataValues', $this->_dataValues);
$this->assign('rowDisplayCount', 2);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
//to save the current mappings
if (!$this->get('savedMapping')) {
$saveDetailsName = ts('Save this field mapping');
$this->applyFilter('saveMappingName', 'trim');
$this->add('text', 'saveMappingName', ts('Name'));
$this->add('text', 'saveMappingDesc', ts('Description'));
}
else {
$savedMapping = $this->get('savedMapping');
list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue, $mappingWebsiteType) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping, TRUE);
//get loaded Mapping Fields
$mappingName = CRM_Utils_Array::value(1, $mappingName);
$mappingLocation = CRM_Utils_Array::value(1, $mappingLocation);
$mappingPhoneType = CRM_Utils_Array::value(1, $mappingPhoneType);
$mappingImProvider = CRM_Utils_Array::value(1, $mappingImProvider);
$mappingRelation = CRM_Utils_Array::value(1, $mappingRelation);
$mappingWebsiteType = CRM_Utils_Array::value(1, $mappingWebsiteType);
$this->assign('loadedMapping', $savedMapping);
$this->set('loadedMapping', $savedMapping);
$params = array('id' => $savedMapping);
$temp = array();
$mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
$this->assign('savedName', $mappingDetails->name);
$this->add('hidden', 'mappingId', $savedMapping);
$this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
$saveDetailsName = ts('Save as a new field mapping');
$this->add('text', 'saveMappingName', ts('Name'));
$this->add('text', 'saveMappingDesc', ts('Description'));
}
$this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
$this->addFormRule(array('CRM_Contact_Import_Form_MapField', 'formRule'));
//-------- end of saved mapping stuff ---------
$defaults = array();
$mapperKeys = array_keys($this->_mapperFields);
$hasColumnNames = !empty($this->_columnNames);
$columnPatterns = $this->get('columnPatterns');
$dataPatterns = $this->get('dataPatterns');
$hasLocationTypes = $this->get('fieldTypes');
$this->_location_types = array('Primary' => ts('Primary')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
// Pass default location to js
if ($defaultLocationType) {
$this->assign('defaultLocationType', $defaultLocationType->id);
$this->assign('defaultLocationTypeLabel', $this->_location_types[$defaultLocationType->id]);
}
/* Initialize all field usages to false */
foreach ($mapperKeys as $key) {
$this->_fieldUsed[$key] = FALSE;
}
$sel1 = $this->_mapperFields;
$sel2[''] = NULL;
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
foreach ($this->_location_types as $key => $value) {
$sel3['phone'][$key] = &$phoneTypes;
//build array for IM service provider type for contact
$sel3['im'][$key] = &$imProviders;
}
$sel4 = NULL;
// store and cache all relationship types
$contactRelation = new CRM_Contact_DAO_RelationshipType();
$contactRelation->find();
while ($contactRelation->fetch()) {
$contactRelationCache[$contactRelation->id] = array();
$contactRelationCache[$contactRelation->id]['contact_type_a'] = $contactRelation->contact_type_a;
$contactRelationCache[$contactRelation->id]['contact_sub_type_a'] = $contactRelation->contact_sub_type_a;
$contactRelationCache[$contactRelation->id]['contact_type_b'] = $contactRelation->contact_type_b;
$contactRelationCache[$contactRelation->id]['contact_sub_type_b'] = $contactRelation->contact_sub_type_b;
}
$highlightedFields = $highlightedRelFields = array();
$highlightedFields['email'] = 'All';
$highlightedFields['external_identifier'] = 'All';
$highlightedFields['first_name'] = 'Individual';
$highlightedFields['last_name'] = 'Individual';
$highlightedFields['household_name'] = 'Household';
$highlightedFields['organization_name'] = 'Organization';
foreach ($mapperKeys as $key) {
// check if there is a _a_b or _b_a in the key
if (strpos($key, '_a_b') || strpos($key, '_b_a')) {
list($id, $first, $second) = explode('_', $key);
}
else {
$id = $first = $second = NULL;
}
if (($first == 'a' && $second == 'b') || ($first == 'b' && $second == 'a')) {
$cType = $contactRelationCache[$id]["contact_type_{$second}"];
//CRM-5125 for contact subtype specific relationshiptypes
$cSubType = NULL;
if (!empty($contactRelationCache[$id]["contact_sub_type_{$second}"])) {
$cSubType = $contactRelationCache[$id]["contact_sub_type_{$second}"];
}
if (!$cType) {
$cType = 'All';
}
$relatedFields = CRM_Contact_BAO_Contact::importableFields($cType);
unset($relatedFields['']);
$values = array();
foreach ($relatedFields as $name => $field) {
$values[$name] = $field['title'];
if (isset($hasLocationTypes[$name])) {
$sel3[$key][$name] = $this->_location_types;
}
elseif ($name == 'url') {
$sel3[$key][$name] = $websiteTypes;
}
else {
$sel3[$name] = NULL;
}
}
//fix to append custom group name to field name, CRM-2676
if (empty($this->_formattedFieldNames[$cType]) || $cType == $this->_contactType) {
$this->_formattedFieldNames[$cType] = $this->formatCustomFieldName($values);
}
$this->_formattedFieldNames[$cType] = array_merge($values, $this->_formattedFieldNames[$cType]);
//Modified the Relationship fields if the fields are
//present in dedupe rule
if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK && !empty($this->_dedupeFields[$cType]) &&
is_array($this->_dedupeFields[$cType])
) {
static $cTypeArray = array();
if ($cType != $this->_contactType && !in_array($cType, $cTypeArray)) {
foreach ($this->_dedupeFields[$cType] as $val) {
if ($valTitle = CRM_Utils_Array::value($val, $this->_formattedFieldNames[$cType])) {
$this->_formattedFieldNames[$cType][$val] = $valTitle . ' (match to contact)';
}
}
$cTypeArray[] = $cType;
}
}
foreach ($highlightedFields as $k => $v) {
if ($v == $cType || $v == 'All') {
$highlightedRelFields[$key][] = $k;
}
}
$this->assign('highlightedRelFields', $highlightedRelFields);
$sel2[$key] = $this->_formattedFieldNames[$cType];
if (!empty($cSubType)) {
//custom fields for sub type
$subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($cSubType);
if (!empty($subTypeFields)) {
$subType = NULL;
foreach ($subTypeFields as $customSubTypeField => $details) {
$subType[$customSubTypeField] = $details['title'];
$sel2[$key] = array_merge($sel2[$key], $this->formatCustomFieldName($subType));
}
}
}
foreach ($this->_location_types as $k => $value) {
$sel4[$key]['phone'][$k] = &$phoneTypes;
//build array of IM service provider for related contact
$sel4[$key]['im'][$k] = &$imProviders;
}
}
else {
$options = NULL;
if (!empty($hasLocationTypes[$key])) {
$options = $this->_location_types;
}
elseif ($key == 'url') {
$options = $websiteTypes;
}
$sel2[$key] = $options;
}
}
$js = "<script type='text/javascript'>\n";
$formName = 'document.forms.' . $this->_name;
//used to warn for mismatch column count or mismatch mapping
$warning = 0;
for ($i = 0; $i < $this->_columnCount; $i++) {
$sel = &$this->addElement('hierselect', "mapper[$i]", ts('Mapper for Field %1', array(1 => $i)), NULL);
$jsSet = FALSE;
if ($this->get('savedMapping')) {
if (isset($mappingName[$i])) {
if ($mappingName[$i] != ts('- do not import -')) {
if (isset($mappingRelation[$i])) {
// relationship mapping
switch ($this->get('contactType')) {
case CRM_Import_Parser::CONTACT_INDIVIDUAL:
$contactType = 'Individual';
break;
case CRM_Import_Parser::CONTACT_HOUSEHOLD:
$contactType = 'Household';
break;
case CRM_Import_Parser::CONTACT_ORGANIZATION:
$contactType = 'Organization';
}
//CRM-5125
$contactSubType = NULL;
if ($this->get('contactSubType')) {
$contactSubType = $this->get('contactSubType');
}
$relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType,
FALSE, 'label', TRUE, $contactSubType
);
foreach ($relations as $key => $var) {
if ($key == $mappingRelation[$i]) {
$relation = $key;
break;
}
}
$contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i]));
$websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL;
$locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0;
$phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL;
//get provider id from saved mappings
$imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL;
if ($websiteTypeId) {
$defaults["mapper[$i]"] = array($relation, $contactDetails, $websiteTypeId);
if (!$websiteTypeId) {
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
}
}
else {
// default for IM/phone when mapping with relation is true
$typeId = NULL;
if (isset($phoneType)) {
$typeId = $phoneType;
}
elseif (isset($imProvider)) {
$typeId = $imProvider;
}
$defaults["mapper[$i]"] = array($relation, $contactDetails, $locationId, $typeId);
if (!$locationId) {
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
}
}
// fix for edge cases, CRM-4954
if ($contactDetails == 'image_url') {
$contactDetails = str_replace('url', 'URL', $contactDetails);
}
if (!$contactDetails) {
$js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
}
if ((!$phoneType) && (!$imProvider)) {
$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
}
//$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
$jsSet = TRUE;
}
else {
$mappingHeader = array_keys($this->_mapperFields, $mappingName[$i]);
$websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL;
$locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0;
$phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL;
// get IM service provider id
$imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL;
if ($websiteTypeId) {
if (!$websiteTypeId) {
$js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
}
$defaults["mapper[$i]"] = array($mappingHeader[0], $websiteTypeId);
}
else {
if (!$locationId) {
$js .= "{$formName}['mapper[$i][1]'].style.display = 'none';\n";
}
//default for IM/phone without related contact
$typeId = NULL;
if (isset($phoneType)) {
$typeId = $phoneType;
}
elseif (isset($imProvider)) {
$typeId = $imProvider;
}
$defaults["mapper[$i]"] = array($mappingHeader[0], $locationId, $typeId);
}
if ((!$phoneType) && (!$imProvider)) {
$js .= "{$formName}['mapper[$i][2]'].style.display = 'none';\n";
}
$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
$jsSet = TRUE;
}
}
else {
$defaults["mapper[$i]"] = array();
}
if (!$jsSet) {
for ($k = 1; $k < 4; $k++) {
$js .= "{$formName}['mapper[$i][$k]'].style.display = 'none';\n";
}
}
}
else {
// this load section to help mapping if we ran out of saved columns when doing Load Mapping
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
if ($hasColumnNames) {
$defaults["mapper[$i]"] = array($this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns));
}
else {
$defaults["mapper[$i]"] = array($this->defaultFromData($dataPatterns, $i));
}
}
//end of load mapping
}
else {
$js .= "swapOptions($formName, 'mapper[$i]', 0, 3, 'hs_mapper_0_');\n";
if ($hasColumnNames) {
// do array search first to see if has mapped key
$columnKey = '';
$columnKey = array_search($this->_columnNames[$i], $this->_mapperFields);
if (isset($this->_fieldUsed[$columnKey])) {
$defaults["mapper[$i]"] = $columnKey;
$this->_fieldUsed[$key] = TRUE;
}
else {
// Infer the default from the column names if we have them
$defaults["mapper[$i]"] = array(
$this->defaultFromColumnName($this->_columnNames[$i],
$columnPatterns
),
0,
);
}
}
else {
// Otherwise guess the default from the form of the data
$defaults["mapper[$i]"] = array(
$this->defaultFromData($dataPatterns, $i),
// $defaultLocationType->id
0,
);
}
}
$sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
}
$js .= "</script>\n";
$this->assign('initHideBoxes', $js);
//set warning if mismatch in more than
if (isset($mappingName) &&
($this->_columnCount != count($mappingName))
) {
$warning++;
}
if ($warning != 0 && $this->get('savedMapping')) {
$session = CRM_Core_Session::singleton();
$session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.'));
}
else {
$session = CRM_Core_Session::singleton();
$session->setStatus(NULL);
}
$this->setDefaults($defaults);
$this->addButtons(array(
array(
'type' => 'back',
'name' => ts('Previous'),
),
array(
'type' => 'next',
'name' => ts('Continue'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($fields) {
$errors = array();
if (!empty($fields['saveMapping'])) {
$nameField = CRM_Utils_Array::value('saveMappingName', $fields);
if (empty($nameField)) {
$errors['saveMappingName'] = ts('Name is required to save Import Mapping');
}
else {
$mappingTypeId = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Mapping', 'mapping_type_id', 'Import Contact');
if (CRM_Core_BAO_Mapping::checkMapping($nameField, $mappingTypeId)) {
$errors['saveMappingName'] = ts('Duplicate Import Mapping Name');
}
}
}
$template = CRM_Core_Smarty::singleton();
if (!empty($fields['saveMapping'])) {
$template->assign('isCheked', TRUE);
}
if (!empty($errors)) {
$_flag = 1;
$assignError = new CRM_Core_Page();
$assignError->assign('mappingDetailsError', $_flag);
return $errors;
}
else {
return TRUE;
}
}
/**
* Process the mapped fields and map it into the uploaded file.
*/
public function postProcess() {
$params = $this->controller->exportValues('MapField');
//reload the mapfield if load mapping is pressed
if (!empty($params['savedMapping'])) {
$this->set('savedMapping', $params['savedMapping']);
$this->controller->resetPage($this->_name);
return;
}
$mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
$parser = $this->submit($params, $mapperKeys);
// add all the necessary variables to the form
$parser->set($this);
}
/**
* Format custom field name.
*
* Combine group and field name to avoid conflict.
*
* @param array $fields
*
* @return array
*/
public function formatCustomFieldName(&$fields) {
//CRM-2676, replacing the conflict for same custom field name from different custom group.
$fieldIds = $formattedFieldNames = array();
foreach ($fields as $key => $value) {
if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
$fieldIds[] = $customFieldId;
}
}
if (!empty($fieldIds) && is_array($fieldIds)) {
$groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldIds);
if (!empty($groupTitles)) {
foreach ($groupTitles as $fId => $values) {
$key = "custom_{$fId}";
$groupTitle = $values['groupTitle'];
$formattedFieldNames[$key] = $fields[$key] . ' :: ' . $groupTitle;
}
}
}
return $formattedFieldNames;
}
/**
* Main submit function.
*
* Extracted to add testing & start refactoring.
*
* @param $params
* @param $mapperKeys
*
* @return \CRM_Contact_Import_Parser_Contact
*/
public function submit($params, $mapperKeys) {
$mapper = $mapperKeysMain = $locations = array();
$parserParameters = CRM_Contact_Import_Parser_Contact::getParameterForParser($this->_columnCount);
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$locationTypes['Primary'] = ts('Primary');
for ($i = 0; $i < $this->_columnCount; $i++) {
$fldName = CRM_Utils_Array::value(0, $mapperKeys[$i]);
$selOne = CRM_Utils_Array::value(1, $mapperKeys[$i]);
$selTwo = CRM_Utils_Array::value(2, $mapperKeys[$i]);
$selThree = CRM_Utils_Array::value(3, $mapperKeys[$i]);
$mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
$mapperKeysMain[$i] = $fldName;
//need to differentiate non location elements.
if ($selOne && (is_numeric($selOne) || $selOne === 'Primary')) {
if ($fldName == 'url') {
$parserParameters['mapperWebsiteType'][$i] = $websiteTypes[$selOne];
}
else {
$locations[$i] = $locationTypes[$selOne];
$parserParameters['mapperLocType'][$i] = $selOne;
if ($selTwo && is_numeric($selTwo)) {
if ($fldName == 'phone') {
$parserParameters['mapperPhoneType'][$i] = $phoneTypes[$selTwo];
}
elseif ($fldName == 'im') {
$parserParameters['mapperImProvider'][$i] = $imProviders[$selTwo];
}
}
}
}
//relationship contact mapper info.
list($id, $first, $second) = CRM_Utils_System::explode('_', $fldName, 3);
if (($first == 'a' && $second == 'b') ||
($first == 'b' && $second == 'a')
) {
$parserParameters['mapperRelated'][$i] = $this->_mapperFields[$fldName];
if ($selOne) {
if ($selOne == 'url') {
$parserParameters['relatedContactWebsiteType'][$i] = $websiteTypes[$selTwo];
}
else {
$parserParameters['relatedContactLocType'][$i] = CRM_Utils_Array::value($selTwo, $locationTypes);
if ($selThree) {
if ($selOne == 'phone') {
$parserParameters['relatedContactPhoneType'][$i] = $phoneTypes[$selThree];
}
elseif ($selOne == 'im') {
$parserParameters['relatedContactImProvider'][$i] = $imProviders[$selThree];
}
}
}
//get the related contact type.
$relationType = new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(TRUE);
$parserParameters['relatedContactType'][$i] = $relationType->{"contact_type_$second"};
$parserParameters['relatedContactDetails'][$i] = $this->_formattedFieldNames[$parserParameters['relatedContactType'][$i]][$selOne];
}
}
}
$this->set('columnNames', $this->_columnNames);
$this->set('websites', $parserParameters['mapperWebsiteType']);
$this->set('locations', $locations);
$this->set('phones', $parserParameters['mapperPhoneType']);
$this->set('ims', $parserParameters['mapperImProvider']);
$this->set('related', $parserParameters['mapperRelated']);
$this->set('relatedContactType', $parserParameters['relatedContactType']);
$this->set('relatedContactDetails', $parserParameters['relatedContactDetails']);
$this->set('relatedContactLocType', $parserParameters['relatedContactLocType']);
$this->set('relatedContactPhoneType', $parserParameters['relatedContactPhoneType']);
$this->set('relatedContactImProvider', $parserParameters['relatedContactImProvider']);
$this->set('relatedContactWebsiteType', $parserParameters['relatedContactWebsiteType']);
$this->set('mapper', $mapper);
// store mapping Id to display it in the preview page
$this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
//Updating Mapping Records
if (!empty($params['updateMapping'])) {
$mappingFields = new CRM_Core_DAO_MappingField();
$mappingFields->mapping_id = $params['mappingId'];
$mappingFields->find();
$mappingFieldsId = array();
while ($mappingFields->fetch()) {
if ($mappingFields->id) {
$mappingFieldsId[$mappingFields->column_number] = $mappingFields->id;
}
}
for ($i = 0; $i < $this->_columnCount; $i++) {
$updateMappingFields = new CRM_Core_DAO_MappingField();
$updateMappingFields->id = CRM_Utils_Array::value($i, $mappingFieldsId);
$updateMappingFields->mapping_id = $params['mappingId'];
$updateMappingFields->column_number = $i;
$mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
$id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
$first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
$second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
if (($first == 'a' && $second == 'b') || ($first == 'b' && $second == 'a')) {
$updateMappingFields->relationship_type_id = $id;
$updateMappingFields->relationship_direction = "{$first}_{$second}";
$updateMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
// get phoneType id and provider id separately
// before updating mappingFields of phone and IM for related contact, CRM-3140
if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'url') {
$updateMappingFields->website_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
else {
if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
$updateMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
}
elseif (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
$updateMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
}
$updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
}
else {
$updateMappingFields->name = $mapper[$i];
$updateMappingFields->relationship_type_id = 'NULL';
$updateMappingFields->relationship_type_direction = 'NULL';
// to store phoneType id and provider id separately
// before updating mappingFields for phone and IM, CRM-3140
if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'url') {
$updateMappingFields->website_type_id = isset($mapperKeys[$i][1]) ? $mapperKeys[$i][1] : NULL;
}
else {
if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
$updateMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
elseif (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
$updateMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
$locationTypeID = $parserParameters['mapperLocType'][$i];
// location_type_id is NULL for non-location fields, and for Primary location.
$updateMappingFields->location_type_id = is_numeric($locationTypeID) ? $locationTypeID : 'null';
}
}
$updateMappingFields->save();
}
}
//Saving Mapping Details and Records
if (!empty($params['saveMapping'])) {
$mappingParams = array(
'name' => $params['saveMappingName'],
'description' => $params['saveMappingDesc'],
'mapping_type_id' => 'Import Contact',
);
$saveMapping = civicrm_api3('Mapping', 'create', $mappingParams);
$contactType = $this->get('contactType');
switch ($contactType) {
case CRM_Import_Parser::CONTACT_INDIVIDUAL:
$cType = 'Individual';
break;
case CRM_Import_Parser::CONTACT_HOUSEHOLD:
$cType = 'Household';
break;
case CRM_Import_Parser::CONTACT_ORGANIZATION:
$cType = 'Organization';
}
for ($i = 0; $i < $this->_columnCount; $i++) {
$saveMappingFields = new CRM_Core_DAO_MappingField();
$saveMappingFields->mapping_id = $saveMapping['id'];
$saveMappingFields->contact_type = $cType;
$saveMappingFields->column_number = $i;
$mapperKeyParts = explode('_', $mapperKeys[$i][0], 3);
$id = isset($mapperKeyParts[0]) ? $mapperKeyParts[0] : NULL;
$first = isset($mapperKeyParts[1]) ? $mapperKeyParts[1] : NULL;
$second = isset($mapperKeyParts[2]) ? $mapperKeyParts[2] : NULL;
if (($first == 'a' && $second == 'b') || ($first == 'b' && $second == 'a')) {
$saveMappingFields->name = ucwords(str_replace("_", " ", $mapperKeys[$i][1]));
$saveMappingFields->relationship_type_id = $id;
$saveMappingFields->relationship_direction = "{$first}_{$second}";
// to get phoneType id and provider id separately
// before saving mappingFields of phone and IM for related contact, CRM-3140
if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'url') {
$saveMappingFields->website_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
else {
if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
$saveMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
}
elseif (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
$saveMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : NULL;
}
$saveMappingFields->location_type_id = (isset($mapperKeys[$i][2]) && $mapperKeys[$i][2] !== 'Primary') ? $mapperKeys[$i][2] : NULL;
}
}
else {
$saveMappingFields->name = $mapper[$i];
$locationTypeID = $parserParameters['mapperLocType'][$i];
// to get phoneType id and provider id separately
// before saving mappingFields of phone and IM, CRM-3140
if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'url') {
$saveMappingFields->website_type_id = isset($mapperKeys[$i][1]) ? $mapperKeys[$i][1] : NULL;
}
else {
if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
$saveMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
elseif (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
$saveMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
$saveMappingFields->location_type_id = is_numeric($locationTypeID) ? $locationTypeID : NULL;
}
$saveMappingFields->relationship_type_id = NULL;
}
$saveMappingFields->save();
}
$this->set('savedMapping', $saveMappingFields->mapping_id);
}
$parser = new CRM_Contact_Import_Parser_Contact($mapperKeysMain, $parserParameters['mapperLocType'], $parserParameters['mapperPhoneType'],
$parserParameters['mapperImProvider'], $parserParameters['mapperRelated'], $parserParameters['relatedContactType'],
$parserParameters['relatedContactDetails'], $parserParameters['relatedContactLocType'],
$parserParameters['relatedContactPhoneType'], $parserParameters['relatedContactImProvider'],
$parserParameters['mapperWebsiteType'], $parserParameters['relatedContactWebsiteType']
);
$primaryKeyName = $this->get('primaryKeyName');
$statusFieldName = $this->get('statusFieldName');
$parser->run($this->_importTableName,
$mapper,
CRM_Import_Parser::MODE_PREVIEW,
$this->get('contactType'),
$primaryKeyName,
$statusFieldName,
$this->_onDuplicate,
NULL, NULL, FALSE,
CRM_Contact_Import_Parser::DEFAULT_TIMEOUT,
$this->get('contactSubType'),
$this->get('dedupe')
);
return $parser;
}
}

View file

@ -0,0 +1,611 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class previews the uploaded file and returns summary statistics.
*/
class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview {
/**
* Whether USPS validation should be disabled during import.
*
* @var bool
*/
protected $_disableUSPS;
/**
* Set variables up before form is built.
*/
public function preProcess() {
//get the data from the session
$dataValues = $this->get('dataValues');
$mapper = $this->get('mapper');
$invalidRowCount = $this->get('invalidRowCount');
$conflictRowCount = $this->get('conflictRowCount');
$mismatchCount = $this->get('unMatchCount');
$columnNames = $this->get('columnNames');
$this->_disableUSPS = $this->get('disableUSPS');
//assign column names
$this->assign('columnNames', $columnNames);
//get the mapping name displayed if the mappingId is set
$mappingId = $this->get('loadMappingId');
if ($mappingId) {
$mapDAO = new CRM_Core_DAO_Mapping();
$mapDAO->id = $mappingId;
$mapDAO->find(TRUE);
$this->assign('loadedMapping', $mappingId);
$this->assign('savedName', $mapDAO->name);
}
$this->assign('rowDisplayCount', 2);
$groups = CRM_Core_PseudoConstant::nestedGroup();
$this->set('groups', $groups);
$tag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
if ($tag) {
$this->set('tag', $tag);
}
if ($invalidRowCount) {
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
if ($conflictRowCount) {
$urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
if ($mismatchCount) {
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
$properties = array(
'mapper',
'locations',
'phones',
'ims',
'dataValues',
'columnCount',
'totalRowCount',
'validRowCount',
'invalidRowCount',
'conflictRowCount',
'downloadErrorRecordsUrl',
'downloadConflictRecordsUrl',
'downloadMismatchRecordsUrl',
'related',
'relatedContactDetails',
'relatedContactLocType',
'relatedContactPhoneType',
'relatedContactImProvider',
'websites',
'relatedContactWebsiteType',
);
foreach ($properties as $property) {
$this->assign($property, $this->get($property));
}
$statusID = $this->get('statusID');
if (!$statusID) {
$statusID = md5(uniqid(rand(), TRUE));
$this->set('statusID', $statusID);
}
$statusUrl = CRM_Utils_System::url('civicrm/ajax/status', "id={$statusID}", FALSE, NULL, FALSE);
$this->assign('statusUrl', $statusUrl);
$showColNames = TRUE;
if ('CRM_Import_DataSource_CSV' == $this->get('dataSource') &&
!$this->get('skipColumnHeader')
) {
$showColNames = FALSE;
}
$this->assign('showColNames', $showColNames);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addElement('text', 'newGroupName', ts('Name for new group'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Group', 'title'));
$this->addElement('text', 'newGroupDesc', ts('Description of new group'));
$groupTypes = CRM_Core_OptionGroup::values('group_type', TRUE);
if (!empty($groupTypes)) {
$this->addCheckBox('newGroupType',
ts('Group Type'),
$groupTypes,
NULL, NULL, NULL, NULL, '&nbsp;&nbsp;&nbsp;'
);
}
$groups = $this->get('groups');
if (!empty($groups)) {
$this->addElement('select', 'groups', ts('Add imported records to existing group(s)'), $groups, array(
'multiple' => "multiple",
'class' => 'crm-select2',
));
}
//display new tag
$this->addElement('text', 'newTagName', ts('Tag'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'name'));
$this->addElement('text', 'newTagDesc', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'description'));
$tag = $this->get('tag');
if (!empty($tag)) {
foreach ($tag as $tagID => $tagName) {
$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
}
}
$path = "_qf_MapField_display=true";
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
if (CRM_Utils_Rule::qfKey($qfKey)) {
$path .= "&qfKey=$qfKey";
}
$previousURL = CRM_Utils_System::url('civicrm/import/contact', $path, FALSE, NULL, FALSE);
$cancelURL = CRM_Utils_System::url('civicrm/import/contact', 'reset=1');
$buttons = array(
array(
'type' => 'back',
'name' => ts('Previous'),
'js' => array('onclick' => "location.href='{$previousURL}'; return false;"),
),
array(
'type' => 'next',
'name' => ts('Import Now'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
'js' => array('onclick' => "return verify( );"),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
),
);
$this->addButtons($buttons);
$this->addFormRule(array('CRM_Contact_Import_Form_Preview', 'formRule'), $this);
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @param $files
* @param $self
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($fields, $files, $self) {
$errors = array();
$invalidTagName = $invalidGroupName = FALSE;
if (!empty($fields['newTagName'])) {
if (!CRM_Utils_Rule::objectExists(trim($fields['newTagName']),
array('CRM_Core_DAO_Tag')
)
) {
$errors['newTagName'] = ts('Tag \'%1\' already exists.',
array(1 => $fields['newTagName'])
);
$invalidTagName = TRUE;
}
}
if (!empty($fields['newGroupName'])) {
$title = trim($fields['newGroupName']);
$name = CRM_Utils_String::titleToVar($title);
$query = 'select count(*) from civicrm_group where name like %1 OR title like %2';
$grpCnt = CRM_Core_DAO::singleValueQuery(
$query,
array(
1 => array($name, 'String'),
2 => array($title, 'String'),
)
);
if ($grpCnt) {
$invalidGroupName = TRUE;
$errors['newGroupName'] = ts('Group \'%1\' already exists.', array(1 => $fields['newGroupName']));
}
}
$self->assign('invalidTagName', $invalidTagName);
$self->assign('invalidGroupName', $invalidGroupName);
return empty($errors) ? TRUE : $errors;
}
/**
* Process the mapped fields and map it into the uploaded file.
*/
public function postProcess() {
$importJobParams = array(
'doGeocodeAddress' => $this->controller->exportValue('DataSource', 'doGeocodeAddress'),
'invalidRowCount' => $this->get('invalidRowCount'),
'conflictRowCount' => $this->get('conflictRowCount'),
'onDuplicate' => $this->get('onDuplicate'),
'dedupe' => $this->get('dedupe'),
'newGroupName' => $this->controller->exportValue($this->_name, 'newGroupName'),
'newGroupDesc' => $this->controller->exportValue($this->_name, 'newGroupDesc'),
'newGroupType' => $this->controller->exportValue($this->_name, 'newGroupType'),
'groups' => $this->controller->exportValue($this->_name, 'groups'),
'allGroups' => $this->get('groups'),
'newTagName' => $this->controller->exportValue($this->_name, 'newTagName'),
'newTagDesc' => $this->controller->exportValue($this->_name, 'newTagDesc'),
'tag' => $this->controller->exportValue($this->_name, 'tag'),
'allTags' => $this->get('tag'),
'mapper' => $this->controller->exportValue('MapField', 'mapper'),
'mapFields' => $this->get('fields'),
'contactType' => $this->get('contactType'),
'contactSubType' => $this->get('contactSubType'),
'primaryKeyName' => $this->get('primaryKeyName'),
'statusFieldName' => $this->get('statusFieldName'),
'statusID' => $this->get('statusID'),
'totalRowCount' => $this->get('totalRowCount'),
);
$tableName = $this->get('importTableName');
$importJob = new CRM_Contact_Import_ImportJob($tableName);
$importJob->setJobParams($importJobParams);
// If ACL applies to the current user, update cache before running the import.
if (!CRM_Core_Permission::check('view all contacts')) {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID');
CRM_ACL_BAO_Cache::updateEntry($userID);
}
CRM_Utils_Address_USPS::disable($this->_disableUSPS);
// run the import
$importJob->runImport($this);
// Clear all caches, forcing any searches to recheck the ACLs or group membership as the import
// may have changed it.
CRM_Contact_BAO_Contact_Utils::clearContactCaches(TRUE);
// add all the necessary variables to the form
$importJob->setFormVariables($this);
// check if there is any error occurred
$errorStack = CRM_Core_Error::singleton();
$errors = $errorStack->getErrors();
$errorMessage = array();
if (is_array($errors)) {
foreach ($errors as $key => $value) {
$errorMessage[] = $value['message'];
}
// there is no fileName since this is a sql import
// so fudge it
$config = CRM_Core_Config::singleton();
$errorFile = $config->uploadDir . "sqlImport.error.log";
if ($fd = fopen($errorFile, 'w')) {
fwrite($fd, implode('\n', $errorMessage));
}
fclose($fd);
$this->set('errorFile', $errorFile);
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
$urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
//hack to clean db
//if job complete drop table.
$importJob->isComplete(TRUE);
}
/**
* Process the mapped fields and map it into the uploaded file.
*/
public function postProcessOld() {
$doGeocodeAddress = $this->controller->exportValue('DataSource', 'doGeocodeAddress');
$invalidRowCount = $this->get('invalidRowCount');
$conflictRowCount = $this->get('conflictRowCount');
$onDuplicate = $this->get('onDuplicate');
$newGroupName = $this->controller->exportValue($this->_name, 'newGroupName');
$newGroupDesc = $this->controller->exportValue($this->_name, 'newGroupDesc');
$newGroupType = $this->controller->exportValue($this->_name, 'newGroupType');
$groups = $this->controller->exportValue($this->_name, 'groups');
$allGroups = $this->get('groups');
$newTagName = $this->controller->exportValue($this->_name, 'newTagName');
$newTagDesc = $this->controller->exportValue($this->_name, 'newTagDesc');
$tag = $this->controller->exportValue($this->_name, 'tag');
$allTags = $this->get('tag');
$mapper = $this->controller->exportValue('MapField', 'mapper');
$mapperKeys = array();
$mapperLocTypes = array();
$mapperPhoneTypes = array();
$mapperRelated = array();
$mapperRelatedContactType = array();
$mapperRelatedContactDetails = array();
$mapperRelatedContactLocType = array();
$mapperRelatedContactPhoneType = array();
foreach ($mapper as $key => $value) {
$mapperKeys[$key] = $mapper[$key][0];
if (is_numeric($mapper[$key][1])) {
$mapperLocTypes[$key] = $mapper[$key][1];
}
else {
$mapperLocTypes[$key] = NULL;
}
if (CRM_Utils_Array::value($key, $mapperKeys) == 'phone') {
$mapperPhoneTypes[$key] = $mapper[$key][2];
}
else {
$mapperPhoneTypes[$key] = NULL;
}
list($id, $first, $second) = explode('_', $mapper[$key][0]);
if (($first == 'a' && $second == 'b') || ($first == 'b' && $second == 'a')) {
$relationType = new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(TRUE);
$fieldName = "contact_type_$second";
$mapperRelatedContactType[$key] = $relationType->$fieldName;
$mapperRelated[$key] = $mapper[$key][0];
$mapperRelatedContactDetails[$key] = $mapper[$key][1];
$mapperRelatedContactLocType[$key] = $mapper[$key][2];
$mapperRelatedContactPhoneType[$key] = $mapper[$key][3];
}
else {
$mapperRelated[$key] = NULL;
$mapperRelatedContactType[$key] = NULL;
$mapperRelatedContactDetails[$key] = NULL;
$mapperRelatedContactLocType[$key] = NULL;
$mapperRelatedContactPhoneType[$key] = NULL;
}
}
$parser = new CRM_Contact_Import_Parser_Contact($mapperKeys, $mapperLocTypes,
$mapperPhoneTypes, $mapperRelated, $mapperRelatedContactType,
$mapperRelatedContactDetails, $mapperRelatedContactLocType,
$mapperRelatedContactPhoneType
);
$mapFields = $this->get('fields');
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
foreach ($mapper as $key => $value) {
$header = array();
list($id, $first, $second) = explode('_', $mapper[$key][0]);
if (($first == 'a' && $second == 'b') || ($first == 'b' && $second == 'a')) {
$relationType = new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(TRUE);
$header[] = $relationType->name_a_b;
$header[] = ucwords(str_replace("_", " ", $mapper[$key][1]));
if (isset($mapper[$key][2])) {
$header[] = $locationTypes[$mapper[$key][2]];
}
if (isset($mapper[$key][3])) {
$header[] = $phoneTypes[$mapper[$key][3]];
}
}
else {
if (isset($mapFields[$mapper[$key][0]])) {
$header[] = $mapFields[$mapper[$key][0]];
if (isset($mapper[$key][1])) {
$header[] = $locationTypes[$mapper[$key][1]];
}
if (isset($mapper[$key][2])) {
$header[] = $phoneTypes[$mapper[$key][2]];
}
}
}
$mapperFields[] = implode(' - ', $header);
}
$tableName = $this->get('importTableName');
//print "Running parser on table: $tableName<br/>";
$parser->run($tableName, $mapperFields,
CRM_Import_Parser::MODE_IMPORT,
$this->get('contactType'),
$this->get('primaryKeyName'),
$this->get('statusFieldName'),
$onDuplicate,
$this->get('statusID'),
$this->get('totalRowCount'),
$doGeocodeAddress,
CRM_Contact_Import_Parser::DEFAULT_TIMEOUT,
$this->get('contactSubType'),
$this->get('dedupe')
);
// add the new contacts to selected groups
$contactIds = &$parser->getImportedContacts();
// add the new related contacts to selected groups
$relatedContactIds = &$parser->getRelatedImportedContacts();
$this->set('relatedCount', count($relatedContactIds));
$newGroupId = NULL;
//changed below if-statement "if ($newGroup) {" to "if ($newGroupName) {"
if ($newGroupName) {
/* Create a new group */
$gParams = array(
'name' => $newGroupName,
'title' => $newGroupName,
'description' => $newGroupDesc,
'group_type' => $newGroupType,
'is_active' => TRUE,
);
$group = CRM_Contact_BAO_Group::create($gParams);
$groups[] = $newGroupId = $group->id;
}
if (is_array($groups)) {
$groupAdditions = array();
foreach ($groups as $groupId) {
$addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
if (!empty($relatedContactIds)) {
$addRelCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($relatedContactIds, $groupId);
}
$totalCount = $addCount[1] + $addRelCount[1];
if ($groupId == $newGroupId) {
$name = $newGroupName;
$new = TRUE;
}
else {
$name = $allGroups[$groupId];
$new = FALSE;
}
$groupAdditions[] = array(
'url' => CRM_Utils_System::url('civicrm/group/search',
'reset=1&force=1&context=smog&gid=' . $groupId
),
'name' => $name,
'added' => $totalCount,
'notAdded' => $addCount[2] + $addRelCount[2],
'new' => $new,
);
}
$this->set('groupAdditions', $groupAdditions);
}
$newTagId = NULL;
if ($newTagName) {
/* Create a new Tag */
$tagParams = array(
'name' => $newTagName,
'title' => $newTagName,
'description' => $newTagDesc,
'is_active' => TRUE,
);
$id = array();
$addedTag = CRM_Core_BAO_Tag::add($tagParams, $id);
$tag[$addedTag->id] = 1;
}
//add Tag to Import
if (is_array($tag)) {
$tagAdditions = array();
foreach ($tag as $tagId => $val) {
$addTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($contactIds, $tagId);
if (!empty($relatedContactIds)) {
$addRelTagCount = CRM_Core_BAO_EntityTag::addContactsToTag($relatedContactIds, $tagId);
}
$totalTagCount = $addTagCount[1] + $addRelTagCount[1];
if ($tagId == $addedTag->id) {
$tagName = $newTagName;
$new = TRUE;
}
else {
$tagName = $allTags[$tagId];
$new = FALSE;
}
$tagAdditions[] = array(
'url' => CRM_Utils_System::url('civicrm/contact/search',
'reset=1&force=1&context=smog&id=' . $tagId
),
'name' => $tagName,
'added' => $totalTagCount,
'notAdded' => $addTagCount[2] + $addRelTagCount[2],
'new' => $new,
);
}
$this->set('tagAdditions', $tagAdditions);
}
// add all the necessary variables to the form
$parser->set($this, CRM_Import_Parser::MODE_IMPORT);
// check if there is any error occurred
$errorStack = CRM_Core_Error::singleton();
$errors = $errorStack->getErrors();
$errorMessage = array();
if (is_array($errors)) {
foreach ($errors as $key => $value) {
$errorMessage[] = $value['message'];
}
// there is no fileName since this is a sql import
// so fudge it
$config = CRM_Core_Config::singleton();
$errorFile = $config->uploadDir . "sqlImport.error.log";
if ($fd = fopen($errorFile, 'w')) {
fwrite($fd, implode('\n', $errorMessage));
}
fclose($fd);
$this->set('errorFile', $errorFile);
$urlParams = 'type=' . CRM_Import_Parser::ERROR . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadErrorRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlparams));
$urlParams = 'type=' . CRM_Import_Parser::CONFLICT . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadConflictRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
}
}

View file

@ -0,0 +1,137 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class summarizes the import results.
*/
class CRM_Contact_Import_Form_Summary extends CRM_Import_Form_Summary {
/**
* Set variables up before form is built.
*/
public function preProcess() {
// set the error message path to display
$this->assign('errorFile', $this->get('errorFile'));
$totalRowCount = $this->get('totalRowCount');
$relatedCount = $this->get('relatedCount');
$totalRowCount += $relatedCount;
$invalidRowCount = $this->get('invalidRowCount');
$conflictRowCount = $this->get('conflictRowCount');
$duplicateRowCount = $this->get('duplicateRowCount');
$onDuplicate = $this->get('onDuplicate');
$mismatchCount = $this->get('unMatchCount');
$unparsedAddressCount = $this->get('unparsedAddressCount');
if ($duplicateRowCount > 0) {
$urlParams = 'type=' . CRM_Import_Parser::DUPLICATE . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadDuplicateRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
elseif ($mismatchCount) {
$urlParams = 'type=' . CRM_Import_Parser::NO_MATCH . '&parser=CRM_Contact_Import_Parser';
$this->set('downloadMismatchRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
}
else {
$duplicateRowCount = 0;
$this->set('duplicateRowCount', $duplicateRowCount);
}
if ($unparsedAddressCount) {
$urlParams = 'type=' . CRM_Import_Parser::UNPARSED_ADDRESS_WARNING . '&parser=CRM_Contact_Import_Parser';
$this->assign('downloadAddressRecordsUrl', CRM_Utils_System::url('civicrm/export', $urlParams));
$unparsedStreetAddressString = ts('Records imported successfully but unable to parse some of the street addresses');
$this->assign('unparsedStreetAddressString', $unparsedStreetAddressString);
}
$this->assign('dupeError', FALSE);
if ($onDuplicate == CRM_Import_Parser::DUPLICATE_UPDATE) {
$dupeActionString = ts('These records have been updated with the imported data.');
}
elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_REPLACE) {
$dupeActionString = ts('These records have been replaced with the imported data.');
}
elseif ($onDuplicate == CRM_Import_Parser::DUPLICATE_FILL) {
$dupeActionString = ts('These records have been filled in with the imported data.');
}
else {
/* Skip by default */
$dupeActionString = ts('These records have not been imported.');
$this->assign('dupeError', TRUE);
}
//now we also create relative contact in update and fill mode
$this->set('validRowCount', $totalRowCount - $invalidRowCount -
$conflictRowCount - $duplicateRowCount - $mismatchCount
);
$this->assign('dupeActionString', $dupeActionString);
$properties = array(
'totalRowCount',
'validRowCount',
'invalidRowCount',
'conflictRowCount',
'downloadConflictRecordsUrl',
'downloadErrorRecordsUrl',
'duplicateRowCount',
'downloadDuplicateRecordsUrl',
'downloadMismatchRecordsUrl',
'groupAdditions',
'tagAdditions',
'unMatchCount',
'unparsedAddressCount',
);
foreach ($properties as $property) {
$this->assign($property, $this->get($property));
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/import/contact', 'reset=1'));
}
/**
* Clean up the import table we used.
*/
public function postProcess() {
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
$importTableName = $this->get('importTableName');
// do a basic sanity check here
if (strpos($importTableName, 'civicrm_import_job_') === 0) {
$query = "DROP TABLE IF EXISTS $importTableName";
$db->query($query);
}
}
}

View file

@ -0,0 +1,426 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2009 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class acts like a psuedo-BAO for transient import job tables.
*/
class CRM_Contact_Import_ImportJob {
protected $_tableName;
protected $_primaryKeyName;
protected $_statusFieldName;
protected $_doGeocodeAddress;
protected $_invalidRowCount;
protected $_conflictRowCount;
protected $_onDuplicate;
protected $_dedupe;
protected $_newGroupName;
protected $_newGroupDesc;
protected $_newGroupType;
protected $_groups;
protected $_allGroups;
protected $_newTagName;
protected $_newTagDesc;
protected $_tag;
protected $_allTags;
protected $_mapper;
protected $_mapperKeys = array();
protected $_mapFields;
protected $_parser;
/**
* @param null $tableName
* @param null $createSql
* @param bool $createTable
*
* @throws Exception
*/
public function __construct($tableName = NULL, $createSql = NULL, $createTable = FALSE) {
$dao = new CRM_Core_DAO();
$db = $dao->getDatabaseConnection();
if ($createTable) {
if (!$createSql) {
CRM_Core_Error::fatal('Either an existing table name or an SQL query to build one are required');
}
// FIXME: we should regen this table's name if it exists rather than drop it
if (!$tableName) {
$tableName = 'civicrm_import_job_' . md5(uniqid(rand(), TRUE));
}
$db->query("DROP TABLE IF EXISTS $tableName");
$db->query("CREATE TABLE $tableName ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci $createSql");
}
if (!$tableName) {
CRM_Core_Error::fatal('Import Table is required.');
}
$this->_tableName = $tableName;
}
/**
* @return null|string
*/
public function getTableName() {
return $this->_tableName;
}
/**
* @param bool $dropIfComplete
*
* @return bool
* @throws Exception
*/
public function isComplete($dropIfComplete = TRUE) {
if (!$this->_statusFieldName) {
CRM_Core_Error::fatal("Could not get name of the import status field");
}
$query = "SELECT * FROM $this->_tableName
WHERE $this->_statusFieldName = 'NEW' LIMIT 1";
$result = CRM_Core_DAO::executeQuery($query);
if ($result->fetch()) {
return FALSE;
}
if ($dropIfComplete) {
$query = "DROP TABLE $this->_tableName";
CRM_Core_DAO::executeQuery($query);
}
return TRUE;
}
/**
* @param array $params
*/
public function setJobParams(&$params) {
foreach ($params as $param => $value) {
$fldName = "_$param";
$this->$fldName = $value;
}
}
/**
* @param CRM_Core_Form $form
* @param int $timeout
*/
public function runImport(&$form, $timeout = 55) {
$mapper = $this->_mapper;
$mapperFields = array();
$parserParameters = CRM_Contact_Import_Parser_Contact::getParameterForParser(count($mapper));
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
$locationTypes = array('Primary' => ts('Primary')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
foreach ($mapper as $key => $value) {
$fldName = CRM_Utils_Array::value(0, $mapper[$key]);
$header = array($this->_mapFields[$fldName]);
$selOne = CRM_Utils_Array::value(1, $mapper[$key]);
$selTwo = CRM_Utils_Array::value(2, $mapper[$key]);
$selThree = CRM_Utils_Array::value(3, $mapper[$key]);
$this->_mapperKeys[$key] = $fldName;
//need to differentiate non location elements.
// @todo merge this with duplicate code on MapField class.
if ($selOne && (is_numeric($selOne) || $selOne === 'Primary')) {
if ($fldName == 'url') {
$header[] = $websiteTypes[$selOne];
$parserParameters['mapperWebsiteType'][$key] = $selOne;
}
else {
$header[] = $locationTypes[$selOne];
$parserParameters['mapperLocType'][$key] = $selOne;
if ($selTwo && is_numeric($selTwo)) {
if ($fldName == 'phone') {
$header[] = $phoneTypes[$selTwo];
$parserParameters['mapperPhoneType'][$key] = $selTwo;
}
elseif ($fldName == 'im') {
$header[] = $imProviders[$selTwo];
$parserParameters['mapperImProvider'][$key] = $selTwo;
}
}
}
}
$fldNameParts = explode('_', $fldName, 3);
$id = $fldNameParts[0];
$first = isset($fldNameParts[1]) ? $fldNameParts[1] : NULL;
$second = isset($fldNameParts[2]) ? $fldNameParts[2] : NULL;
if (($first == 'a' && $second == 'b') ||
($first == 'b' && $second == 'a')
) {
$header[] = ucwords(str_replace("_", " ", $selOne));
$relationType = new CRM_Contact_DAO_RelationshipType();
$relationType->id = $id;
$relationType->find(TRUE);
$parserParameters['relatedContactType'][$key] = $relationType->{"contact_type_$second"};
$parserParameters['mapperRelated'][$key] = $fldName;
if ($selOne) {
$parserParameters['relatedContactDetails'][$key] = $selOne;
if ($selTwo) {
if ($selOne == 'url') {
$header[] = $websiteTypes[$selTwo];
$parserParameters[$key]['relatedContactWebsiteType'][$key] = $selTwo;
}
else {
$header[] = $locationTypes[$selTwo];
$parserParameters['relatedContactLocType'][$key] = $selTwo;
if ($selThree) {
if ($selOne == 'phone') {
$header[] = $phoneTypes[$selThree];
$parserParameters['relatedContactPhoneType'][$key] = $selThree;
}
elseif ($selOne == 'im') {
$header[] = $imProviders[$selThree];
$parserParameters['relatedContactImProvider'][$key] = $selThree;
}
}
}
}
}
}
$mapperFields[] = implode(' - ', $header);
}
$this->_parser = new CRM_Contact_Import_Parser_Contact(
$this->_mapperKeys,
$parserParameters['mapperLocType'],
$parserParameters['mapperPhoneType'],
$parserParameters['mapperImProvider'],
$parserParameters['mapperRelated'],
$parserParameters['relatedContactType'],
$parserParameters['relatedContactDetails'],
$parserParameters['relatedContactLocType'],
$parserParameters['relatedContactPhoneType'],
$parserParameters['relatedContactImProvider'],
$parserParameters['mapperWebsiteType'],
$parserParameters['relatedContactWebsiteType']
);
$this->_parser->run($this->_tableName, $mapperFields,
CRM_Import_Parser::MODE_IMPORT,
$this->_contactType,
$this->_primaryKeyName,
$this->_statusFieldName,
$this->_onDuplicate,
$this->_statusID,
$this->_totalRowCount,
$this->_doGeocodeAddress,
CRM_Contact_Import_Parser::DEFAULT_TIMEOUT,
$this->_contactSubType,
$this->_dedupe
);
$contactIds = $this->_parser->getImportedContacts();
//get the related contactIds. CRM-2926
$relatedContactIds = $this->_parser->getRelatedImportedContacts();
if ($relatedContactIds) {
$contactIds = array_merge($contactIds, $relatedContactIds);
if ($form) {
$form->set('relatedCount', count($relatedContactIds));
}
}
if ($this->_newGroupName || count($this->_groups)) {
$groupAdditions = $this->_addImportedContactsToNewGroup($contactIds,
$this->_newGroupName,
$this->_newGroupDesc,
$this->_newGroupType
);
if ($form) {
$form->set('groupAdditions', $groupAdditions);
}
}
if ($this->_newTagName || count($this->_tag)) {
$tagAdditions = $this->_tagImportedContactsWithNewTag($contactIds,
$this->_newTagName,
$this->_newTagDesc
);
if ($form) {
$form->set('tagAdditions', $tagAdditions);
}
}
}
/**
* @param $form
*/
public function setFormVariables($form) {
$this->_parser->set($form, CRM_Import_Parser::MODE_IMPORT);
}
/**
* Add imported contacts.
*
* @param array $contactIds
* @param string $newGroupName
* @param string $newGroupDesc
* @param string $newGroupType
*
* @return array|bool
*/
private function _addImportedContactsToNewGroup(
$contactIds,
$newGroupName, $newGroupDesc, $newGroupType
) {
$newGroupId = NULL;
if ($newGroupName) {
/* Create a new group */
$newGroupType = isset($newGroupType) ? $newGroupType : array();
$gParams = array(
'title' => $newGroupName,
'description' => $newGroupDesc,
'group_type' => $newGroupType,
'is_active' => TRUE,
);
$group = CRM_Contact_BAO_Group::create($gParams);
$this->_groups[] = $newGroupId = $group->id;
}
if (is_array($this->_groups)) {
$groupAdditions = array();
foreach ($this->_groups as $groupId) {
$addCount = CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $groupId);
$totalCount = $addCount[1];
if ($groupId == $newGroupId) {
$name = $newGroupName;
$new = TRUE;
}
else {
$name = $this->_allGroups[$groupId];
$new = FALSE;
}
$groupAdditions[] = array(
'url' => CRM_Utils_System::url('civicrm/group/search',
'reset=1&force=1&context=smog&gid=' . $groupId
),
'name' => $name,
'added' => $totalCount,
'notAdded' => $addCount[2],
'new' => $new,
);
}
return $groupAdditions;
}
return FALSE;
}
/**
* @param $contactIds
* @param string $newTagName
* @param $newTagDesc
*
* @return array|bool
*/
private function _tagImportedContactsWithNewTag(
$contactIds,
$newTagName, $newTagDesc
) {
$newTagId = NULL;
if ($newTagName) {
/* Create a new Tag */
$tagParams = array(
'name' => $newTagName,
'description' => $newTagDesc,
'is_selectable' => TRUE,
'used_for' => 'civicrm_contact',
);
$id = array();
$addedTag = CRM_Core_BAO_Tag::add($tagParams, $id);
$this->_tag[$addedTag->id] = 1;
}
//add Tag to Import
if (is_array($this->_tag)) {
$tagAdditions = array();
foreach ($this->_tag as $tagId => $val) {
$addTagCount = CRM_Core_BAO_EntityTag::addEntitiesToTag($contactIds, $tagId, 'civicrm_contact', FALSE);
$totalTagCount = $addTagCount[1];
if (isset($addedTag) && $tagId == $addedTag->id) {
$tagName = $newTagName;
$new = TRUE;
}
else {
$tagName = $this->_allTags[$tagId];
$new = FALSE;
}
$tagAdditions[] = array(
'url' => CRM_Utils_System::url('civicrm/contact/search',
'reset=1&force=1&context=smog&id=' . $tagId
),
'name' => $tagName,
'added' => $totalTagCount,
'notAdded' => $addTagCount[2],
'new' => $new,
);
}
return $tagAdditions;
}
return FALSE;
}
/**
* @return array
*/
public static function getIncompleteImportTables() {
$dao = new CRM_Core_DAO();
$database = $dao->database();
$query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA
WHERE TABLE_SCHEMA = ? AND
TABLE_NAME LIKE 'civicrm_import_job_%'
ORDER BY TABLE_NAME";
$result = CRM_Core_DAO::executeQuery($query, array($database));
$incompleteImportTables = array();
while ($importTable = $result->fetch()) {
if (!$this->isComplete($importTable)) {
$incompleteImportTables[] = $importTable;
}
}
return $incompleteImportTables;
}
}

View file

@ -0,0 +1,61 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2009 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class mainly exists to allow imports to be triggered synchronously (i.e.
* via a form post) and asynchronously (i.e. by the workflow system)
*/
class CRM_Contact_Import_Importer {
/**
*/
public function __construct() {
// may not need this
}
/**
* @param int $timeout
*/
public function runIncompleteImportJobs($timeout = 55) {
$startTime = time();
$incompleteImportTables = CRM_Contact_Import_ImportJob::getIncompleteImportTables();
foreach ($incompleteImportTables as $importTable) {
$importJob = new CRM_Contact_Import_ImportJob($importTable);
$importJob->runImport(NULL, $timeout);
$currentTime = time();
if (($currentTime - $startTime) >= $timeout) {
break;
}
}
}
}

View file

@ -0,0 +1,61 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class contains all the function that are called using AJAX.
*/
class CRM_Contact_Import_Page_AJAX {
/**
* Show import status.
*/
public static function status() {
// make sure we get an id
if (!isset($_GET['id'])) {
return;
}
$config = CRM_Core_Config::singleton();
$file = "{$config->uploadDir}status_{$_GET['id']}.txt";
if (file_exists($file)) {
$str = file_get_contents($file);
echo $str;
}
else {
$status = "<div class='description'>&nbsp; " . ts('No processing status reported yet.') . "</div>";
echo json_encode(array(0, $status));
}
CRM_Utils_System::civiExit();
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff