/**
  * Common form elements.
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $this->setMaxFileSize($uploadFileSize);
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     $this->add('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2), TRUE);
     $this->setDefaults(array('fieldSeparator' => $config->fieldSeparator));
     //get the saved mapping details
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import ' . static::IMPORT_ENTITY, 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     if ($loadedMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadedMapping);
         $this->setDefaults(array('savedMapping' => $loadedMapping));
     }
     //build date formats
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue'), 'spacing' => '          ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
示例#2
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     //Setting Upload File Size
     $config = CRM_Core_Config::singleton();
     $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize . 'm', TRUE);
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->setMaxFileSize($uploadFileSize);
     $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     $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);
     $this->addGroup($duplicateOptions, 'onDuplicate', ts('On duplicate entries'));
     //get the saved mapping details
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Activity', 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     if ($loadeMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadeMapping);
         $this->setDefaults(array('savedMapping' => $loadeMapping));
     }
     $this->setDefaults(array('onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP));
     //build date formats
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue'), 'spacing' => '          ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
示例#3
0
 /**
  * Function to actually build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     //Setting Upload File Size
     $config = CRM_Core_Config::singleton();
     if ($config->maxImportFileSize >= 8388608) {
         $uploadFileSize = 8388608;
     } else {
         $uploadFileSize = $config->maxImportFileSize;
     }
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=60', true);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->setMaxFileSize($uploadFileSize);
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     $duplicateOptions = array();
     $duplicateOptions[] = HTML_QuickForm::createElement('radio', null, null, ts('Insert new contributions'), CRM_Contribute_Import_Parser::DUPLICATE_SKIP);
     $duplicateOptions[] = HTML_QuickForm::createElement('radio', null, null, ts('Update existing contributions'), CRM_Contribute_Import_Parser::DUPLICATE_UPDATE);
     $this->addGroup($duplicateOptions, 'onDuplicate', ts('Import mode'));
     //get the saved mapping details
     require_once "CRM/Core/BAO/Mapping.php";
     require_once "CRM/Core/OptionGroup.php";
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contribution', 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     $this->addElement('submit', 'loadMapping', ts('Load Mapping'), null, array('onclick' => 'checkSelect()'));
     if ($loadeMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadeMapping);
         $this->setDefaults(array('savedMapping' => $loadeMapping));
     }
     $this->setDefaults(array('onDuplicate' => CRM_Contribute_Import_Parser::DUPLICATE_SKIP));
     //contact types option
     require_once 'CRM/Contact/BAO/ContactType.php';
     $contactOptions = array();
     if (CRM_Contact_BAO_ContactType::isActive('Individual')) {
         $contactOptions[] = HTML_QuickForm::createElement('radio', null, null, ts('Individual'), CRM_Contribute_Import_Parser::CONTACT_INDIVIDUAL);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Household')) {
         $contactOptions[] = HTML_QuickForm::createElement('radio', null, null, ts('Household'), CRM_Contribute_Import_Parser::CONTACT_HOUSEHOLD);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
         $contactOptions[] = HTML_QuickForm::createElement('radio', null, null, ts('Organization'), CRM_Contribute_Import_Parser::CONTACT_ORGANIZATION);
     }
     $this->addGroup($contactOptions, 'contactType', ts('Contact Type'));
     $this->setDefaults(array('contactType' => CRM_Contribute_Import_Parser::CONTACT_INDIVIDUAL));
     //build date formats
     require_once 'CRM/Core/Form/Date.php';
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => '          ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     //Setting Upload File Size
     $config = CRM_Core_Config::singleton();
     if ($config->maxImportFileSize >= 8388608) {
         $uploadFileSize = 8388608;
     } else {
         $uploadFileSize = $config->maxImportFileSize;
     }
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->setMaxFileSize($uploadFileSize);
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     $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('No Duplicate Checking'), CRM_Import_Parser::DUPLICATE_NOCHECK);
     // for contributions NOCHECK == SKIP
     //      $duplicateOptions[] = $this->createElement('radio',
     //          null, null, ts('No Duplicate Checking'), CRM_Import_Parser::DUPLICATE_NOCHECK);
     $this->addGroup($duplicateOptions, 'onDuplicate', ts('On Duplicate Entries'));
     //get the saved mapping details
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Participant', 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     if ($loadeMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadeMapping);
         $this->setDefaults(array('savedMapping' => $loadeMapping));
     }
     $this->setDefaults(array('onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP));
     //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);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Household')) {
         $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Household'), CRM_Import_Parser::CONTACT_HOUSEHOLD);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
         $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Organization'), CRM_Import_Parser::CONTACT_ORGANIZATION);
     }
     $this->addGroup($contactOptions, 'contactType', ts('Contact Type'));
     $this->setDefaults(array('contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL));
     //build date formats
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => '          ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
 /**
  * Process the uploaded file.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $exportParams = $this->controller->exportValues('Select');
     $currentPath = CRM_Utils_System::currentPath();
     $urlParams = NULL;
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams = "&qfKey={$qfKey}";
     }
     //get the button name
     $buttonName = $this->controller->getButtonName('done');
     $buttonName1 = $this->controller->getButtonName('next');
     if ($buttonName == '_qf_Map_done') {
         $this->set('exportColumnCount', NULL);
         $this->controller->resetPage($this->_name);
         return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams));
     }
     if ($this->controller->exportValue($this->_name, 'addMore')) {
         $this->set('exportColumnCount', $this->_exportColumnCount);
         return;
     }
     $mapperKeys = $params['mapper'][1];
     $checkEmpty = 0;
     foreach ($mapperKeys as $value) {
         if ($value[0]) {
             $checkEmpty++;
         }
     }
     if (!$checkEmpty) {
         $this->set('mappingId', NULL);
         CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams));
     }
     if ($buttonName1 == '_qf_Map_next') {
         if (!empty($params['updateMapping'])) {
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']);
         }
         if (!empty($params['saveMapping'])) {
             $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId'));
             $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id);
         }
     }
     //get the csv file
     CRM_Export_BAO_Export_Relationship::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'), $exportParams);
 }
示例#6
0
 /**
  * Function to build mapping form element
  *
  */
 function buildMapping()
 {
     switch ($this->_exportMode) {
         case CRM_Export_Form_Select::CONTACT_EXPORT:
             $exportType = 'Export Contact';
             break;
         case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
             $exportType = 'Export Contribution';
             break;
         case CRM_Export_Form_Select::MEMBER_EXPORT:
             $exportType = 'Export Membership';
             break;
         case CRM_Export_Form_Select::EVENT_EXPORT:
             $exportType = 'Export Participant';
             break;
         case CRM_Export_Form_Select::PLEDGE_EXPORT:
             $exportType = 'Export Pledge';
             break;
         case CRM_Export_Form_Select::CASE_EXPORT:
             $exportType = 'Export Case';
             break;
         case CRM_Export_Form_Select::GRANT_EXPORT:
             $exportType = 'Export Grant';
             break;
         case CRM_Export_Form_Select::ACTIVITY_EXPORT:
             $exportType = 'Export Activity';
             break;
     }
     $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', $exportType, 'name');
     $this->set('mappingTypeId', $mappingTypeId);
     $mappings = CRM_Core_BAO_Mapping::getMappings($mappingTypeId);
     // Remove the mappings to which a user has no permission to use.
     foreach ($mappings as $mapping_id => $mapping) {
         if (!CRM_Mappingacl_Acl::hasAccessToMapping($mapping_id)) {
             unset($mappings[$mapping_id]);
         }
     }
     if (!empty($mappings)) {
         $this->add('select', 'mapping', ts('Use Saved Field Mapping'), array('' => '-select-') + $mappings);
     }
 }
示例#7
0
文件: Builder.php 项目: hguru/224Civi
 public function &returnProperties()
 {
     return CRM_Core_BAO_Mapping::returnProperties($this->_formValues);
 }
示例#8
0
 /**
  * given a saved search compute the clause and the tables
  * and store it for future use
  */
 function buildClause()
 {
     $fv = unserialize($this->form_values);
     if ($this->mapping_id) {
         require_once 'CRM/Core/BAO/Mapping.php';
         $params = CRM_Core_BAO_Mapping::formattedFields($fv);
     } else {
         require_once 'CRM/Contact/BAO/Query.php';
         $params = CRM_Contact_BAO_Query::convertFormValues($fv);
     }
     if (!empty($params)) {
         $tables = $whereTables = array();
         $this->where_clause = CRM_Contact_BAO_Query::getWhereClause($params, null, $tables, $whereTables);
         if (!empty($tables)) {
             $this->select_tables = serialize($tables);
         }
         if (!empty($whereTables)) {
             $this->where_tables = serialize($whereTables);
         }
     }
     return;
 }
示例#9
0
 static function preProcessCommon(&$form, $useTable = false)
 {
     $form->_contactIds = array();
     $form->_contactTypes = array();
     // get the submitted values of the search form
     // we'll need to get fv from either search or adv search in the future
     $fragment = 'search';
     if ($form->_action == CRM_Core_Action::ADVANCED) {
         $values = $form->controller->exportValues('Advanced');
         $fragment .= '/advanced';
     } else {
         if ($form->_action == CRM_Core_Action::PROFILE) {
             $values = $form->controller->exportValues('Builder');
             $fragment .= '/builder';
         } else {
             if ($form->_action == CRM_Core_Action::COPY) {
                 $values = $form->controller->exportValues('Custom');
                 $fragment .= '/custom';
             } else {
                 $values = $form->controller->exportValues('Basic');
             }
         }
     }
     //set the user context for redirection of task actions
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
     require_once 'CRM/Utils/Rule.php';
     $urlParams = 'force=1';
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams .= "&qfKey={$qfKey}";
     }
     $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams);
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext($url);
     require_once 'CRM/Contact/Task.php';
     $form->_task = CRM_Utils_Array::value('task', $values);
     $crmContactTaskTasks = CRM_Contact_Task::taskTitles();
     $form->assign('taskName', CRM_Utils_Array::value($form->_task, $crmContactTaskTasks));
     if ($useTable) {
         $form->_componentTable = CRM_Core_DAO::createTempTableName('civicrm_task_action', false);
         $sql = " DROP TABLE IF EXISTS {$form->_componentTable}";
         CRM_Core_DAO::executeQuery($sql);
         $sql = "CREATE TABLE {$form->_componentTable} ( contact_id int primary key) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
         CRM_Core_DAO::executeQuery($sql);
     }
     // all contacts or action = save a search
     if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_all' || $form->_task == CRM_Contact_Task::SAVE_SEARCH) {
         // need to perform action on all contacts
         // fire the query again and get the contact id's + display name
         $sortID = null;
         if ($form->get(CRM_Utils_Sort::SORT_ID)) {
             $sortID = CRM_Utils_Sort::sortIDValue($form->get(CRM_Utils_Sort::SORT_ID), $form->get(CRM_Utils_Sort::SORT_DIRECTION));
         }
         $selectorName = $form->controller->selectorName();
         require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
         $fv = $form->get('formValues');
         $customClass = $form->get('customSearchClass');
         require_once "CRM/Core/BAO/Mapping.php";
         $returnProperties = CRM_Core_BAO_Mapping::returnProperties($values);
         eval('$selector   = new ' . $selectorName . '( $customClass, $fv, null, $returnProperties ); ');
         $params = $form->get('queryParams');
         // fix for CRM-5165
         $sortByCharacter = $form->get('sortByCharacter');
         if ($sortByCharacter && $sortByCharacter != 1) {
             $params[] = array('sortByCharacter', '=', $sortByCharacter, 0, 0);
         }
         $dao =& $selector->contactIDQuery($params, $form->_action, $sortID);
         $form->_contactIds = array();
         if ($useTable) {
             $count = 0;
             $insertString = array();
             while ($dao->fetch()) {
                 $count++;
                 $insertString[] = " ( {$dao->contact_id} ) ";
                 if ($count % 200 == 0) {
                     $string = implode(',', $insertString);
                     $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}";
                     CRM_Core_DAO::executeQuery($sql);
                     $insertString = array();
                 }
             }
             if (!empty($insertString)) {
                 $string = implode(',', $insertString);
                 $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}";
                 CRM_Core_DAO::executeQuery($sql);
             }
             $dao->free();
         } else {
             // filter duplicates here
             // CRM-7058
             // might be better to do this in the query, but that logic is a bit complex
             // and it decides when to use distinct based on input criteria, which needs
             // to be fixed and optimized.
             $alreadySeen = array();
             while ($dao->fetch()) {
                 if (!array_key_exists($dao->contact_id, $alreadySeen)) {
                     $form->_contactIds[] = $dao->contact_id;
                     $alreadySeen[$dao->contact_id] = 1;
                 }
             }
             unset($alreadySeen);
             $dao->free();
         }
     } else {
         if (CRM_Utils_Array::value('radio_ts', $values) == 'ts_sel') {
             // selected contacts only
             // need to perform action on only selected contacts
             $insertString = array();
             foreach ($values as $name => $value) {
                 if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
                     $contactID = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
                     if ($useTable) {
                         $insertString[] = " ( {$contactID} ) ";
                     } else {
                         $form->_contactIds[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
                     }
                 }
             }
             if (!empty($insertString)) {
                 $string = implode(',', $insertString);
                 $sql = "REPLACE INTO {$form->_componentTable} ( contact_id ) VALUES {$string}";
                 CRM_Core_DAO::executeQuery($sql);
             }
         }
     }
     //contact type for pick up profiles as per selected contact types with subtypes
     //CRM-5521
     if ($selectedTypes = CRM_Utils_Array::value('contact_type', $values)) {
         if (!is_array($selectedTypes)) {
             $selectedTypes = explode(" ", $selectedTypes);
         }
         foreach ($selectedTypes as $ct => $dontcare) {
             if (strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR) === false) {
                 $form->_contactTypes[] = $ct;
             } else {
                 $separator = strpos($ct, CRM_Core_DAO::VALUE_SEPARATOR);
                 $form->_contactTypes[] = substr($ct, $separator + 1);
             }
         }
     }
     if (!empty($form->_contactIds)) {
         $form->_componentClause = ' contact_a.id IN ( ' . implode(',', $form->_contactIds) . ' ) ';
         $form->assign('totalSelectedContacts', count($form->_contactIds));
         $form->_componentIds = $form->_contactIds;
     }
 }
 /**
  * Function to actually build the form - this appears to be entirely code that should be in a shared base class in core
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     // Setting Upload File Size.
     $config = CRM_Core_Config::singleton();
     // This conditional block is important as the "maxImportFileSize" has been changed to "maxFileSize"
     // in the newer versions. In order to remove version support, remove this block and
     // replace by $uploadFileSize = $config->maxFileSize.
     if (!empty($config->maxImportFileSize)) {
         $uploadFileSize = $config->maxImportFileSize;
     } else {
         $uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
     }
     if ($uploadFileSize >= 8388608) {
         $uploadFileSize = 8388608;
     }
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->add('file', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->setMaxFileSize($uploadFileSize);
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     if ($this->isDuplicateOptions) {
         $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('No Duplicate Checking'), CRM_Import_Parser::DUPLICATE_NOCHECK);
         $this->addGroup($duplicateOptions, 'onDuplicate', ts('On Duplicate Entries'));
     }
     //get the saved mapping details
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', $this->_mappingType, 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     if ($loadedMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadedMapping);
         $this->setDefaults(array('savedMapping' => $loadedMapping));
     }
     $this->setDefaults(array('onDuplicate' => CRM_Import_Parser::DUPLICATE_SKIP));
     if ($this->_enableContactOptions) {
         $this->addContactOptions();
     }
     $this->setDefaults(array('contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL));
     $this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2));
     //build date formats
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Continue >>'), 'spacing' => '          ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
示例#11
0
 /**
  * Process the mapped fields and map it into the uploaded file
  * preview the file and extract some summary statistics
  *
  * @return void
  */
 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;
     }
     $fileName = $this->controller->exportValue('DataSource', 'uploadFile');
     $seperator = $this->controller->exportValue('DataSource', 'fieldSeparator');
     $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
     $mapperKeys = array();
     $mapper = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     $mapperLocType = array();
     $mapperPhoneType = array();
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $mapperKeys[$i][0];
         if (!empty($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) {
             $mapperLocType[$i] = $mapperKeys[$i][1];
         } else {
             $mapperLocType[$i] = NULL;
         }
         if (!empty($mapperKeys[$i][2]) && !is_numeric($mapperKeys[$i][2])) {
             $mapperPhoneType[$i] = $mapperKeys[$i][2];
         } else {
             $mapperPhoneType[$i] = NULL;
         }
     }
     $this->set('mapper', $mapper);
     // store mapping Id to display it in the preview page
     if (!empty($params['mappingId'])) {
         $this->set('loadMappingId', $params['mappingId']);
     }
     //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 = $mappingFieldsId[$i];
             $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;
             $updateMappingFields->name = $mapper[$i];
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (!empty($params['saveMapping'])) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Membership', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $saveMappingFields = new CRM_Core_DAO_MappingField();
             $saveMappingFields->mapping_id = $saveMapping->id;
             $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;
             $saveMappingFields->name = $mapper[$i];
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser = new CRM_Member_Import_Parser_Membership($mapperKeysMain, $mapperLocType, $mapperPhoneType);
     $parser->run($fileName, $seperator, $mapper, $skipColumnHeader, CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
示例#12
0
 /**
  * Function to build mapping form element
  *
  */
 function buildMapping()
 {
     switch ($this->_exportMode) {
         case CRM_Export_Form_Select::CONTACT_EXPORT:
             $exportType = 'Export Contact';
             break;
         case CRM_Export_Form_Select::CONTRIBUTE_EXPORT:
             $exportType = 'Export Contribution';
             break;
         case CRM_Export_Form_Select::MEMBER_EXPORT:
             $exportType = 'Export Membership';
             break;
         case CRM_Export_Form_Select::EVENT_EXPORT:
             $exportType = 'Export Participant';
             break;
         case CRM_Export_Form_Select::PLEDGE_EXPORT:
             $exportType = 'Export Pledge';
             break;
         case CRM_Export_Form_Select::CASE_EXPORT:
             $exportType = 'Export Case';
             break;
         case CRM_Export_Form_Select::GRANT_EXPORT:
             $exportType = 'Export Grant';
             break;
         case CRM_Export_Form_Select::ACTIVITY_EXPORT:
             $exportType = 'Export Activity';
             break;
     }
     require_once "CRM/Core/BAO/Mapping.php";
     $mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', $exportType, 'name');
     $this->set('mappingTypeId', $mappingTypeId);
     $mappings = CRM_Core_BAO_Mapping::getMappings($mappingTypeId);
     if (!empty($mappings)) {
         $this->add('select', 'mapping', ts('Use Saved Field Mapping'), array('' => '-select-') + $mappings);
     }
 }
示例#13
0
 /**
  * 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;
     }
     $mapper = array();
     $mapperKeys = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     $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');
     //these mapper params need to set key as array and val as null.
     $mapperParams = array('related' => 'relatedVal', 'locations' => 'locationsVal', 'mapperLocType' => 'mapperLocTypeVal', 'mapperPhoneType' => 'mapperPhoneTypeVal', 'mapperImProvider' => 'mapperImProviderVal', 'mapperWebsiteType' => 'mapperWebsiteTypeVal', 'relatedContactType' => 'relatedContactTypeVal', 'relatedContactDetails' => 'relatedContactDetailsVal', 'relatedContactLocType' => 'relatedContactLocTypeVal', 'relatedContactPhoneType' => 'relatedContactPhoneTypeVal', 'relatedContactImProvider' => 'relatedContactImProviderVal', 'relatedContactWebsiteType' => 'relatedContactWebsiteTypeVal');
     //set respective mapper params to array.
     foreach (array_keys($mapperParams) as $mapperParam) {
         ${$mapperParam} = array();
     }
     for ($i = 0; $i < $this->_columnCount; $i++) {
         //set respective mapper value to null
         foreach (array_values($mapperParams) as $mapperParam) {
             ${$mapperParam} = NULL;
         }
         $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)) {
             if ($fldName == 'url') {
                 $mapperWebsiteTypeVal = $websiteTypes[$selOne];
             } else {
                 $locationsVal = $locationTypes[$selOne];
                 $mapperLocTypeVal = $selOne;
                 if ($selTwo && is_numeric($selTwo)) {
                     if ($fldName == 'phone') {
                         $mapperPhoneTypeVal = $phoneTypes[$selTwo];
                     } elseif ($fldName == 'im') {
                         $mapperImProviderVal = $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') {
             $relatedVal = $this->_mapperFields[$fldName];
             if ($selOne) {
                 if ($selOne == 'url') {
                     $relatedContactWebsiteTypeVal = $websiteTypes[$selTwo];
                 } else {
                     $relatedContactLocTypeVal = CRM_Utils_Array::value($selTwo, $locationTypes);
                     if ($selThree) {
                         if ($selOne == 'phone') {
                             $relatedContactPhoneTypeVal = $phoneTypes[$selThree];
                         } elseif ($selOne == 'im') {
                             $relatedContactImProviderVal = $imProviders[$selThree];
                         }
                     }
                 }
                 //get the related contact type.
                 $relationType = new CRM_Contact_DAO_RelationshipType();
                 $relationType->id = $id;
                 $relationType->find(TRUE);
                 $relatedContactTypeVal = $relationType->{"contact_type_{$second}"};
                 $relatedContactDetailsVal = $this->_formattedFieldNames[$relatedContactTypeVal][$selOne];
             }
         }
         //set the respective mapper param array values.
         foreach ($mapperParams as $mapperParamKey => $mapperParamVal) {
             ${$mapperParamKey}[$i] = ${$mapperParamVal};
         }
     }
     $this->set('columnNames', $this->_columnNames);
     //set main contact properties.
     $properties = array('ims' => 'mapperImProvider', 'mapper' => 'mapper', 'phones' => 'mapperPhoneType', 'websites' => 'mapperWebsiteType', 'locations' => 'locations');
     foreach ($properties as $propertyName => $propertyVal) {
         $this->set($propertyName, ${$propertyVal});
     }
     //set related contact propeties.
     $relProperties = array('related', 'relatedContactType', 'relatedContactDetails', 'relatedContactLocType', 'relatedContactPhoneType', 'relatedContactImProvider', 'relatedContactWebsiteType');
     foreach ($relProperties as $relProperty) {
         $this->set($relProperty, ${$relProperty});
     }
     // 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'])) {
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $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;
                     }
                     $location = array_keys($locationTypes, $locations[$i]);
                     $updateMappingFields->location_type_id = isset($location) && isset($location[0]) ? $location[0] : NULL;
                 }
             }
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (!empty($params['saveMapping'])) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
         $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] : NULL;
                 }
             } else {
                 $saveMappingFields->name = $mapper[$i];
                 $location_id = array_keys($locationTypes, $locations[$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 = isset($location_id[0]) ? $location_id[0] : NULL;
                 }
                 $saveMappingFields->relationship_type_id = NULL;
             }
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser = new CRM_Contact_Import_Parser_Contact($mapperKeysMain, $mapperLocType, $mapperPhoneType, $mapperImProvider, $related, $relatedContactType, $relatedContactDetails, $relatedContactLocType, $relatedContactPhoneType, $relatedContactImProvider, $mapperWebsiteType, $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'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
 /**
  * load the smart group cache for a saved search
  */
 static function load(&$group)
 {
     $groupID = $group->id;
     $savedSearchID = $group->saved_search_id;
     $sql = null;
     $idName = 'id';
     $customClass = null;
     if ($savedSearchID) {
         require_once 'CRM/Contact/BAO/SavedSearch.php';
         $ssParams =& CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
         $returnProperties = array();
         if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
             require_once "CRM/Core/BAO/Mapping.php";
             $fv =& CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
             $returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv);
         }
         if (isset($ssParams['customSearchID'])) {
             // if custom search
             require_once 'CRM/Contact/BAO/SearchCustom.php';
             // we split it up and store custom class
             // so temp tables are not destroyed if they are used
             // hence customClass is defined above at top of function
             $customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
             $searchSQL = $customClass->contactIDs();
             $idName = 'contact_id';
         } else {
             require_once 'CRM/Contact/BAO/Query.php';
             $query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, null, false, false, 1, true, true, false);
             $query->_useGroupBy = false;
             $searchSQL =& $query->searchQuery(0, 0, null, false, false, false, true, true, null);
         }
         $groupID = CRM_Utils_Type::escape($groupID, 'Integer');
         $sql = $searchSQL . " AND contact_a.id NOT IN ( \n                              SELECT contact_id FROM civicrm_group_contact \n                              WHERE civicrm_group_contact.status = 'Removed' \n                              AND   civicrm_group_contact.group_id = {$groupID} ) ";
     }
     if ($sql) {
         $sql .= " UNION ";
     }
     // lets also store the records that are explicitly added to the group
     // this allows us to skip the group contact LEFT JOIN
     $sql .= "\nSELECT contact_id as {$idName}\nFROM   civicrm_group_contact\nWHERE  civicrm_group_contact.status = 'Added'\n  AND  civicrm_group_contact.group_id = {$groupID} ";
     $dao = CRM_Core_DAO::executeQuery($sql);
     $values = array();
     while ($dao->fetch()) {
         $values[] = "({$groupID},{$dao->{$idName}})";
     }
     $groupIDs = array($groupID);
     self::remove($groupIDs);
     self::store($groupIDs, $values);
     if ($group->children) {
         require_once 'CRM/Contact/BAO/Group.php';
         $childrenIDs = explode(',', $group->children);
         foreach ($childrenIDs as $childID) {
             $contactIDs =& CRM_Contact_BAO_Group::getMember($childID, false);
             $values = array();
             foreach ($contactIDs as $contactID => $dontCare) {
                 $values[] = "({$groupID},{$contactID})";
             }
             self::store($groupIDs, $values);
         }
     }
 }
示例#15
0
 /**
  * Build the mapping form.
  *
  * @param CRM_Core_Form $form
  * @param string $mappingType
  *   (Export/Import/Search Builder).
  * @param int $mappingId
  * @param int $columnNo
  * @param int $blockCount
  *   (no of blocks shown).
  * @param NULL $exportMode
  *
  * @return void
  */
 public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL)
 {
     if ($mappingType == 'Export') {
         $name = "Map";
         $columnCount = array('1' => $columnNo);
     } elseif ($mappingType == 'Search Builder') {
         $name = "Builder";
         $columnCount = $columnNo;
     }
     //get the saved mapping details
     if ($mappingType == 'Export') {
         $form->applyFilter('saveMappingName', 'trim');
         //to save the current mappings
         if (!isset($mappingId)) {
             $saveDetailsName = ts('Save this field mapping');
             $form->add('text', 'saveMappingName', ts('Name'));
             $form->add('text', 'saveMappingDesc', ts('Description'));
         } else {
             $form->assign('loadedMapping', $mappingId);
             $params = array('id' => $mappingId);
             $temp = array();
             $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
             $form->assign('savedName', $mappingDetails->name);
             $form->add('hidden', 'mappingId', $mappingId);
             $form->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
             $saveDetailsName = ts('Save as a new field mapping');
             $form->add('text', 'saveMappingName', ts('Name'));
             $form->add('text', 'saveMappingDesc', ts('Description'));
         }
         $form->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
         $form->addFormRule(array('CRM_Export_Form_Map', 'formRule'), $form->get('mappingTypeId'));
     } elseif ($mappingType == 'Search Builder') {
         $form->addElement('submit', 'addBlock', ts('Also include contacts where'), array('class' => 'submit-link'));
     }
     $defaults = array();
     $hasLocationTypes = array();
     $hasRelationTypes = array();
     $fields = array();
     if ($mappingType == 'Export') {
         $required = TRUE;
     } elseif ($mappingType == 'Search Builder') {
         $required = FALSE;
     }
     $contactType = array('Individual', 'Household', 'Organization');
     foreach ($contactType as $value) {
         $contactFields = CRM_Contact_BAO_Contact::exportableFields($value, FALSE, $required);
         $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton()->getFields());
         // exclude the address options disabled in the Address Settings
         $fields[$value] = CRM_Core_BAO_Address::validateAddressOptions($contactFields);
         ksort($fields[$value]);
         if ($mappingType == 'Export') {
             $relationships = array();
             $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $value);
             asort($relationshipTypes);
             foreach ($relationshipTypes as $key => $var) {
                 list($type) = explode('_', $key);
                 $relationships[$key]['title'] = $var;
                 $relationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
                 $relationships[$key]['export'] = TRUE;
                 $relationships[$key]['relationship_type_id'] = $type;
                 $relationships[$key]['related'] = TRUE;
                 $relationships[$key]['hasRelationType'] = 1;
             }
             if (!empty($relationships)) {
                 $fields[$value] = array_merge($fields[$value], array('related' => array('title' => ts('- related contact info -'))), $relationships);
             }
         }
     }
     //get the current employer for mapping.
     if ($required) {
         $fields['Individual']['current_employer']['title'] = ts('Current Employer');
     }
     // add component fields
     $compArray = array();
     //we need to unset groups, tags, notes for component export
     if ($exportMode != CRM_Export_Form_Select::CONTACT_EXPORT) {
         foreach (array('groups', 'tags', 'notes') as $value) {
             unset($fields['Individual'][$value]);
             unset($fields['Household'][$value]);
             unset($fields['Organization'][$value]);
         }
     }
     if ($mappingType == 'Search Builder') {
         //build the common contact fields array.
         $fields['Contact'] = array();
         foreach ($fields['Individual'] as $key => $value) {
             if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
                 $fields['Contact'][$key] = $value;
                 unset($fields['Organization'][$key], $fields['Household'][$key], $fields['Individual'][$key]);
             }
         }
         if (array_key_exists('note', $fields['Contact'])) {
             $noteTitle = $fields['Contact']['note']['title'];
             $fields['Contact']['note']['title'] = $noteTitle . ': ' . ts('Body and Subject');
             $fields['Contact']['note_body'] = array('title' => $noteTitle . ': ' . ts('Body Only'), 'name' => 'note_body');
             $fields['Contact']['note_subject'] = array('title' => $noteTitle . ': ' . ts('Subject Only'), 'name' => 'note_subject');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
         if (CRM_Core_Permission::access('CiviContribute')) {
             $fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields();
             foreach (array('contribution_contact_id', 'contribution_soft_credit_name', 'contribution_soft_credit_amount', 'contribution_soft_credit_type', 'contribution_soft_credit_contribution_id') as $element) {
                 unset($fields['Contribution'][$element]);
             }
             $compArray['Contribution'] = ts('Contribution');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
         if (CRM_Core_Permission::access('CiviEvent')) {
             $fields['Participant'] = CRM_Event_BAO_Participant::exportableFields();
             //get the component payment fields
             if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
                 $componentPaymentFields = array();
                 foreach (CRM_Export_BAO_Export::componentPaymentFields() as $payField => $payTitle) {
                     $componentPaymentFields[$payField] = array('title' => $payTitle);
                 }
                 $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields);
             }
             $compArray['Participant'] = ts('Participant');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
         if (CRM_Core_Permission::access('CiviMember')) {
             $fields['Membership'] = CRM_Member_BAO_Membership::getMembershipFields($exportMode);
             unset($fields['Membership']['membership_contact_id']);
             $compArray['Membership'] = ts('Membership');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
         if (CRM_Core_Permission::access('CiviPledge')) {
             $fields['Pledge'] = CRM_Pledge_BAO_Pledge::exportableFields();
             unset($fields['Pledge']['pledge_contact_id']);
             $compArray['Pledge'] = ts('Pledge');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
         if (CRM_Core_Permission::access('CiviCase')) {
             $fields['Case'] = CRM_Case_BAO_Case::exportableFields();
             $compArray['Case'] = ts('Case');
             $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Case');
             $compArray['Activity'] = ts('Case Activity');
             unset($fields['Case']['case_contact_id']);
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
         if (CRM_Core_Permission::access('CiviGrant')) {
             $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
             unset($fields['Grant']['grant_contact_id']);
             if ($mappingType == 'Search Builder') {
                 unset($fields['Grant']['grant_type_id']);
             }
             $compArray['Grant'] = ts('Grant');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
         $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Activity');
         $compArray['Activity'] = ts('Activity');
     }
     //Contact Sub Type For export
     $contactSubTypes = array();
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         //adding subtype specific relationships CRM-5256
         $csRelationships = array();
         if ($mappingType == 'Export') {
             $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
             foreach ($subTypeRelationshipTypes as $key => $var) {
                 if (!array_key_exists($key, $fields[$val['parent']])) {
                     list($type) = explode('_', $key);
                     $csRelationships[$key]['title'] = $var;
                     $csRelationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
                     $csRelationships[$key]['export'] = TRUE;
                     $csRelationships[$key]['relationship_type_id'] = $type;
                     $csRelationships[$key]['related'] = TRUE;
                     $csRelationships[$key]['hasRelationType'] = 1;
                 }
             }
         }
         $fields[$subType] = $fields[$val['parent']] + $csRelationships;
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($subType);
         $fields[$subType] += $subTypeFields;
         if (!empty($subTypeFields) || !empty($csRelationships)) {
             $contactSubTypes[$subType] = $val['label'];
         }
     }
     unset($subTypes);
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             $customGroupName = self::getCustomGroupName($key1);
             if ($customGroupName) {
                 $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $customGroupName . ': ' . $value1['title'];
             } else {
                 $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $value1['title'];
             }
             if (isset($value1['hasLocationType'])) {
                 $hasLocationTypes[$key][$key1] = $value1['hasLocationType'];
             }
             if (isset($value1['hasRelationType'])) {
                 $hasRelationTypes[$key][$key1] = $value1['hasRelationType'];
                 unset($relatedMapperFields[$key][$key1]);
             }
         }
         if (array_key_exists('related', $relatedMapperFields[$key])) {
             unset($relatedMapperFields[$key]['related']);
         }
     }
     $mapperKeys = array_keys($mapperFields);
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     // FIXME: dirty hack to make the default option show up first.  This
     // avoids a mozilla browser bug with defaults on dynamically constructed
     // selector widgets.
     if ($defaultLocationType) {
         $defaultLocation = $locationTypes[$defaultLocationType->id];
         unset($locationTypes[$defaultLocationType->id]);
         $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes;
     }
     $locationTypes = array(' ' => ts('Primary')) + $locationTypes;
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
     if ($mappingType == 'Search Builder') {
         $contactTypes = array('Contact' => ts('Contacts')) + $contactTypes;
     }
     $sel1 = array('' => ts('- select record type -')) + $contactTypes + $compArray;
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             // sort everything BUT the contactType which is sorted seperately by
             // an initial commit of CRM-13278 (check ksort above)
             if (!in_array($key, $contactType)) {
                 asort($mapperFields[$key]);
             }
             $sel2[$key] = array('' => ts('- select field -')) + $mapperFields[$key];
         }
     }
     $sel3[''] = NULL;
     $sel5[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     asort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($locationTypes as $key => $value) {
                 if (trim($key) != '') {
                     $sel4[$k]['phone'][$key] =& $phoneTypes;
                     $sel4[$k]['im'][$key] =& $imProviders;
                 }
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($mapperFields[$k] as $key => $value) {
                 if (isset($hasLocationTypes[$k][$key])) {
                     $sel3[$k][$key] = $locationTypes;
                 } else {
                     $sel3[$key] = NULL;
                 }
             }
         }
     }
     // Array for core fields and relationship custom data
     $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
     if ($mappingType == 'Export') {
         foreach ($sel1 as $k => $sel) {
             if ($k) {
                 foreach ($mapperFields[$k] as $field => $dontCare) {
                     if (isset($hasRelationTypes[$k][$field])) {
                         list($id, $first, $second) = explode('_', $field);
                         // FIX ME: For now let's not expose custom data related to relationship
                         $relationshipCustomFields = array();
                         //$relationshipCustomFields    = self::getRelationTypeCustomGroupData( $id );
                         //asort($relationshipCustomFields);
                         $relationshipType = new CRM_Contact_BAO_RelationshipType();
                         $relationshipType->id = $id;
                         if ($relationshipType->find(TRUE)) {
                             $direction = "contact_sub_type_{$second}";
                             if (isset($relationshipType->{$direction})) {
                                 $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$direction}], (array) $relationshipCustomFields);
                             } else {
                                 $target_type = 'contact_type_' . $second;
                                 $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$target_type}], (array) $relationshipCustomFields);
                             }
                         }
                         $relationshipType->free();
                         asort($relatedFields);
                         $sel5[$k][$field] = $relatedFields;
                     }
                 }
             }
         }
         //Location Type for relationship fields
         foreach ($sel5 as $k => $v) {
             if ($v) {
                 foreach ($v as $rel => $fields) {
                     foreach ($fields as $field => $fieldLabel) {
                         if (isset($hasLocationTypes[$k][$field])) {
                             $sel6[$k][$rel][$field] = $locationTypes;
                         }
                     }
                 }
             }
         }
         //PhoneTypes for  relationship fields
         $sel7[''] = NULL;
         foreach ($sel6 as $k => $rel) {
             if ($k) {
                 foreach ($rel as $phonekey => $phonevalue) {
                     foreach ($locationTypes as $locType => $loc) {
                         if (trim($locType) != '') {
                             $sel7[$k][$phonekey]['phone'][$locType] =& $phoneTypes;
                             $sel7[$k][$phonekey]['im'][$locType] =& $imProviders;
                         }
                     }
                 }
             }
         }
     }
     //special fields that have location, hack for primary location
     $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
     if (isset($mappingId)) {
         $colCnt = 0;
         list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue) = CRM_Core_BAO_Mapping::getMappingFields($mappingId);
         $blkCnt = count($mappingName);
         if ($blkCnt >= $blockCount) {
             $blockCount = $blkCnt + 1;
         }
         for ($x = 1; $x < $blockCount; $x++) {
             if (isset($mappingName[$x])) {
                 $colCnt = count($mappingName[$x]);
                 if ($colCnt >= $columnCount[$x]) {
                     $columnCount[$x] = $colCnt;
                 }
             }
         }
     }
     $form->_blockCount = $blockCount;
     $form->_columnCount = $columnCount;
     $form->set('blockCount', $form->_blockCount);
     $form->set('columnCount', $form->_columnCount);
     $defaults = $noneArray = $nullArray = array();
     //used to warn for mismatch column count or mismatch mapping
     $warning = 0;
     for ($x = 1; $x < $blockCount; $x++) {
         for ($i = 0; $i < $columnCount[$x]; $i++) {
             $sel =& $form->addElement('hierselect', "mapper[{$x}][{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL);
             $jsSet = FALSE;
             if (isset($mappingId)) {
                 $locationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0;
                 if (isset($mappingName[$x][$i])) {
                     if (is_array($mapperFields[$mappingContactType[$x][$i]])) {
                         if (isset($mappingRelation[$x][$i])) {
                             $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$x][$i]));
                             $relLocationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0;
                             if (!$relLocationId && in_array($mappingName[$x][$i], $specialFields)) {
                                 $relLocationId = " ";
                             }
                             $relPhoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL;
                             $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingRelation[$x][$i], $locationId, $phoneType, $mappingName[$x][$i], $relLocationId, $relPhoneType);
                             if (!$locationId) {
                                 $noneArray[] = array($x, $i, 2);
                             }
                             if (!$phoneType && !$imProvider) {
                                 $noneArray[] = array($x, $i, 3);
                             }
                             if (!$mappingName[$x][$i]) {
                                 $noneArray[] = array($x, $i, 4);
                             }
                             if (!$relLocationId) {
                                 $noneArray[] = array($x, $i, 5);
                             }
                             if (!$relPhoneType) {
                                 $noneArray[] = array($x, $i, 6);
                             }
                             $noneArray[] = array($x, $i, 2);
                         } else {
                             $phoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL;
                             $imProvider = isset($mappingImProvider[$x][$i]) ? $mappingImProvider[$x][$i] : NULL;
                             if (!$locationId && in_array($mappingName[$x][$i], $specialFields)) {
                                 $locationId = " ";
                             }
                             $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingName[$x][$i], $locationId, $phoneType);
                             if (!$mappingName[$x][$i]) {
                                 $noneArray[] = array($x, $i, 1);
                             }
                             if (!$locationId) {
                                 $noneArray[] = array($x, $i, 2);
                             }
                             if (!$phoneType && !$imProvider) {
                                 $noneArray[] = array($x, $i, 3);
                             }
                             $noneArray[] = array($x, $i, 4);
                             $noneArray[] = array($x, $i, 5);
                             $noneArray[] = array($x, $i, 6);
                         }
                         $jsSet = TRUE;
                         if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingOperator))) {
                             $defaults["operator[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingOperator[$x]);
                         }
                         if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingValue))) {
                             $defaults["value[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingValue[$x]);
                         }
                     }
                 }
             }
             //Fix for Search Builder
             if ($mappingType == 'Export') {
                 $j = 7;
             } else {
                 $j = 4;
             }
             $formValues = $form->exportValues();
             if (!$jsSet) {
                 if (empty($formValues)) {
                     // Incremented length for third select box(relationship type)
                     for ($k = 1; $k < $j; $k++) {
                         $noneArray[] = array($x, $i, $k);
                     }
                 } else {
                     if (!empty($formValues['mapper'][$x])) {
                         foreach ($formValues['mapper'][$x] as $value) {
                             for ($k = 1; $k < $j; $k++) {
                                 if (!isset($formValues['mapper'][$x][$i][$k]) || !$formValues['mapper'][$x][$i][$k]) {
                                     $noneArray[] = array($x, $i, $k);
                                 } else {
                                     $nullArray[] = array($x, $i, $k);
                                 }
                             }
                         }
                     } else {
                         for ($k = 1; $k < $j; $k++) {
                             $noneArray[] = array($x, $i, $k);
                         }
                     }
                 }
             }
             //Fix for Search Builder
             if ($mappingType == 'Export') {
                 if (!isset($mappingId) || $i >= count(reset($mappingName))) {
                     if (isset($formValues['mapper']) && isset($formValues['mapper'][$x][$i][1]) && array_key_exists($formValues['mapper'][$x][$i][1], $relationshipTypes)) {
                         $sel->setOptions(array($sel1, $sel2, $sel5, $sel6, $sel7, $sel3, $sel4));
                     } else {
                         $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7));
                     }
                 } else {
                     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7));
                 }
             } else {
                 $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
             }
             if ($mappingType == 'Search Builder') {
                 //CRM -2292, restricted array set
                 $operatorArray = array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators();
                 $form->add('select', "operator[{$x}][{$i}]", '', $operatorArray);
                 $form->add('text', "value[{$x}][{$i}]", '');
             }
         }
         //end of columnCnt for
         if ($mappingType == 'Search Builder') {
             $title = ts('Another search field');
         } else {
             $title = ts('Select more fields');
         }
         $form->addElement('submit', "addMore[{$x}]", $title, array('class' => 'submit-link'));
     }
     //end of block for
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$name}";
     if (!empty($nullArray)) {
         $js .= "var nullArray = [";
         $elements = array();
         $seen = array();
         foreach ($nullArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<nullArray.length;i++) {\n                    if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {\n                        {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';\n                    }\n                }\n";
     }
     if (!empty($noneArray)) {
         $js .= "var noneArray = [";
         $elements = array();
         $seen = array();
         foreach ($noneArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<noneArray.length;i++) {\n                    if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {\n  {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';\n                    }\n                }\n";
     }
     $js .= "</script>\n";
     $form->assign('initHideBoxes', $js);
     $form->assign('columnCount', $columnCount);
     $form->assign('blockCount', $blockCount);
     $form->setDefaults($defaults);
     $form->setDefaultAction('refresh');
 }
示例#16
0
 /**
  * Process the form after the input has been submitted and validated.
  */
 public function postProcess()
 {
     // saved search form values
     // get form values of all the forms in this controller
     $formValues = $this->controller->exportValues();
     $isAdvanced = $this->get('isAdvanced');
     $isSearchBuilder = $this->get('isSearchBuilder');
     // add mapping record only for search builder saved search
     $mappingId = NULL;
     if ($isAdvanced == '2' && $isSearchBuilder == '1') {
         //save the mapping for search builder
         if (!$this->_id) {
             //save record in mapping table
             $mappingParams = array('mapping_type' => 'Search Builder');
             $temp = array();
             $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp);
             $mappingId = $mapping->id;
         } else {
             //get the mapping id from saved search
             $savedSearch = new CRM_Contact_BAO_SavedSearch();
             $savedSearch->id = $this->_id;
             $savedSearch->find(TRUE);
             $mappingId = $savedSearch->mapping_id;
         }
         //save mapping fields
         CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId);
     }
     //save the search
     $savedSearch = new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $this->_id;
     $savedSearch->form_values = serialize($this->get('formValues'));
     $savedSearch->mapping_id = $mappingId;
     $savedSearch->search_custom_id = $this->get('customSearchID');
     $savedSearch->save();
     $this->set('ssID', $savedSearch->id);
     CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success');
     // also create a group that is associated with this saved search only if new saved search
     $params = array();
     $params['title'] = $formValues['title'];
     $params['description'] = $formValues['description'];
     if (isset($formValues['group_type']) && is_array($formValues['group_type'])) {
         $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
     } else {
         $params['group_type'] = '';
     }
     $params['visibility'] = 'User and User Admin Only';
     $params['saved_search_id'] = $savedSearch->id;
     $params['is_active'] = 1;
     //CRM-14190
     $params['parents'] = $formValues['parents'];
     if ($this->_id) {
         $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id');
     }
     $group = CRM_Contact_BAO_Group::create($params);
     // CRM-9464
     $this->_id = $savedSearch->id;
     //CRM-14190
     if (!empty($formValues['parents'])) {
         CRM_Contact_BAO_GroupNestingCache::update();
     }
 }
示例#17
0
 /**
  * Process the form after the input has been submitted and validated.
  */
 public function postProcess()
 {
     // saved search form values
     // get form values of all the forms in this controller
     $formValues = $this->controller->exportValues();
     $isAdvanced = $this->get('isAdvanced');
     $isSearchBuilder = $this->get('isSearchBuilder');
     // add mapping record only for search builder saved search
     $mappingId = NULL;
     if ($isAdvanced == '2' && $isSearchBuilder == '1') {
         //save the mapping for search builder
         if (!$this->_id) {
             //save record in mapping table
             $mappingParams = array('mapping_type' => 'Search Builder');
             $temp = array();
             $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp);
             $mappingId = $mapping->id;
         } else {
             //get the mapping id from saved search
             $savedSearch = new CRM_Contact_BAO_SavedSearch();
             $savedSearch->id = $this->_id;
             $savedSearch->find(TRUE);
             $mappingId = $savedSearch->mapping_id;
         }
         //save mapping fields
         CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId);
     }
     //save the search
     $savedSearch = new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $this->_id;
     // Use the query parameters rather than the form values - these have already been assessed / converted
     // with the extra knowledge that the form has.
     // Note that we want to move towards a standardised way of saving the query that is not
     // an exact match for the form requirements & task the form layer with converting backwards and forwards.
     // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the
     // sql operator syntax at the query layer.
     $savedSearch->form_values = serialize($this->get('queryParams'));
     $savedSearch->mapping_id = $mappingId;
     $savedSearch->search_custom_id = $this->get('customSearchID');
     $savedSearch->save();
     $this->set('ssID', $savedSearch->id);
     CRM_Core_Session::setStatus(ts("Your smart group has been saved as '%1'.", array(1 => $formValues['title'])), ts('Group Saved'), 'success');
     // also create a group that is associated with this saved search only if new saved search
     $params = array();
     $params['title'] = $formValues['title'];
     $params['description'] = $formValues['description'];
     if (isset($formValues['group_type']) && is_array($formValues['group_type'])) {
         $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
     } else {
         $params['group_type'] = '';
     }
     $params['visibility'] = 'User and User Admin Only';
     $params['saved_search_id'] = $savedSearch->id;
     $params['is_active'] = 1;
     //CRM-14190
     $params['parents'] = $formValues['parents'];
     if ($this->_id) {
         $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id');
     }
     $group = CRM_Contact_BAO_Group::create($params);
     // CRM-9464
     $this->_id = $savedSearch->id;
     //CRM-14190
     if (!empty($formValues['parents'])) {
         CRM_Contact_BAO_GroupNestingCache::update();
     }
 }
示例#18
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return void
  */
 public function postProcess()
 {
     // saved search form values
     // get form values of all the forms in this controller
     $formValues = $this->controller->exportValues();
     $isAdvanced = $this->get('isAdvanced');
     $isSearchBuilder = $this->get('isSearchBuilder');
     // add mapping record only for search builder saved search
     $mappingId = null;
     if ($isAdvanced == '2' && $isSearchBuilder == '1') {
         //save the mapping for search builder
         require_once "CRM/Core/BAO/Mapping.php";
         if (!$this->_id) {
             //save record in mapping table
             $mappingParams = array('mapping_type' => 'Search Builder');
             $temp = array();
             $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp);
             $mappingId = $mapping->id;
         } else {
             //get the mapping id from saved search
             require_once "CRM/Contact/BAO/SavedSearch.php";
             $savedSearch = new CRM_Contact_BAO_SavedSearch();
             $savedSearch->id = $this->_id;
             $savedSearch->find(true);
             $mappingId = $savedSearch->mapping_id;
         }
         //save mapping fields
         CRM_Core_BAO_Mapping::saveMappingFields($formValues, $mappingId);
     }
     //save the search
     $savedSearch = new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $this->_id;
     $savedSearch->form_values = serialize($this->get('formValues'));
     $savedSearch->mapping_id = $mappingId;
     $savedSearch->search_custom_id = $this->get('customSearchID');
     $savedSearch->save();
     $this->set('ssID', $savedSearch->id);
     CRM_Core_Session::setStatus(ts('Your smart group has been saved as \'%1\'.', array(1 => $formValues['title'])));
     // also create a group that is associated with this saved search only if new saved search
     $params = array();
     $params['title'] = $formValues['title'];
     $params['description'] = $formValues['description'];
     if (is_array($formValues['group_type'])) {
         $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
     } else {
         $params['group_type'] = '';
     }
     $params['visibility'] = 'User and User Admin Only';
     $params['saved_search_id'] = $savedSearch->id;
     $params['is_active'] = 1;
     if ($this->_id) {
         $params['id'] = CRM_Contact_BAO_SavedSearch::getName($this->_id, 'id');
     }
     require_once 'CRM/Contact/BAO/Group.php';
     $group =& CRM_Contact_BAO_Group::create($params);
 }
示例#19
0
文件: Group.php 项目: ksecor/civicrm
 /**
  * This function create the hidden smart group when user perform
  * contact seach and want to send mailing to search contacts.
  *
  * @param  array $params ( reference ) an assoc array of name/value pairs
  * @return array ( smartGroupId, ssId ) smart group id and saved search id
  * @access public
  * @static
  */
 static function createHiddenSmartGroup($params)
 {
     $ssId = CRM_Utils_Array::value('saved_search_id', $params);
     //add mapping record only for search builder saved search
     $mappingId = null;
     if ($params['is_advanced'] == '2' && $params['is_searchBuilder'] == '1') {
         //save the mapping for search builder
         require_once "CRM/Core/BAO/Mapping.php";
         if (!$ssId) {
             //save record in mapping table
             $temp = array();
             $mappingParams = array('mapping_type' => 'Search Builder');
             $mapping = CRM_Core_BAO_Mapping::add($mappingParams, $temp);
             $mappingId = $mapping->id;
         } else {
             //get the mapping id from saved search
             require_once "CRM/Contact/BAO/SavedSearch.php";
             $savedSearch =& new CRM_Contact_BAO_SavedSearch();
             $savedSearch->id = $ssId;
             $savedSearch->find(true);
             $mappingId = $savedSearch->mapping_id;
         }
         //save mapping fields
         CRM_Core_BAO_Mapping::saveMappingFields($params['form_values'], $mappingId);
     }
     //create/update saved search record.
     $savedSearch =& new CRM_Contact_BAO_SavedSearch();
     $savedSearch->id = $ssId;
     $savedSearch->form_values = serialize($params['form_values']);
     $savedSearch->mapping_id = $mappingId;
     $savedSearch->search_custom_id = CRM_Utils_Array::value('search_custom_id', $params);
     $savedSearch->save();
     $ssId = $savedSearch->id;
     if (!$ssId) {
         return null;
     }
     $smartGroupId = null;
     if (CRM_Utils_Array::value('saved_search_id', $params)) {
         $smartGroupId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $ssId, 'id', 'saved_search_id');
     } else {
         //create group only when new saved search.
         $groupParams = array('title' => "Hidden Smart Group {$ssId}", 'is_active' => CRM_Utils_Array::value('is_active', $params, 1), 'is_hidden' => CRM_Utils_Array::value('is_hidden', $params, 1), 'group_type' => CRM_Utils_Array::value('group_type', $params), 'visibility' => CRM_Utils_Array::value('visibility', $params), 'saved_search_id' => $ssId);
         require_once 'CRM/Contact/BAO/Group.php';
         $smartGroup = self::create($groupParams);
         $smartGroupId = $smartGroup->id;
     }
     return array($smartGroupId, $ssId);
 }
示例#20
0
 /**
  * Process the mapped fields and map it into the uploaded file preview the file and extract some summary statistics.
  */
 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;
     }
     $fileName = $this->controller->exportValue('DataSource', 'uploadFile');
     $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
     $config = CRM_Core_Config::singleton();
     $seperator = $config->fieldSeparator;
     $mapper = $mapperKeys = $mapperKeysMain = $mapperSoftCredit = $softCreditFields = $mapperPhoneType = $mapperSoftCreditType = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $softCreditTypes = CRM_Core_OptionGroup::values('soft_credit_type');
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $mapperKeys[$i][0];
         if (isset($mapperKeys[$i][0]) && $mapperKeys[$i][0] == 'soft_credit') {
             $mapperSoftCredit[$i] = $mapperKeys[$i][1];
             if (strpos($mapperSoftCredit[$i], '_') !== FALSE) {
                 list($first, $second) = explode('_', $mapperSoftCredit[$i]);
                 $softCreditFields[$i] = ucwords($first . " " . $second);
             } else {
                 $softCreditFields[$i] = $mapperSoftCredit[$i];
             }
             $mapperSoftCreditType[$i] = array('value' => isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : '', 'label' => isset($softCreditTypes[$mapperKeys[$i][2]]) ? $softCreditTypes[$mapperKeys[$i][2]] : '');
         } else {
             $mapperSoftCredit[$i] = $softCreditFields[$i] = $mapperSoftCreditType[$i] = NULL;
         }
     }
     $this->set('mapper', $mapper);
     $this->set('softCreditFields', $softCreditFields);
     $this->set('mapperSoftCreditType', $mapperSoftCreditType);
     // 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 = $mappingFieldsId[$i];
             $updateMappingFields->mapping_id = $params['mappingId'];
             $updateMappingFields->column_number = $i;
             $updateMappingFields->name = $mapper[$i];
             //reuse contact_type field in db to store fields associated with soft credit
             $updateMappingFields->contact_type = isset($mapperSoftCredit[$i]) ? $mapperSoftCredit[$i] : NULL;
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (!empty($params['saveMapping'])) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contribution', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $saveMappingFields = new CRM_Core_DAO_MappingField();
             $saveMappingFields->mapping_id = $saveMapping->id;
             $saveMappingFields->column_number = $i;
             $saveMappingFields->name = $mapper[$i];
             //reuse contact_type field in db to store fields associated with soft credit
             $saveMappingFields->contact_type = isset($mapperSoftCredit[$i]) ? $mapperSoftCredit[$i] : NULL;
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser = new CRM_Contribute_Import_Parser_Contribution($mapperKeysMain, $mapperSoftCredit, $mapperPhoneType);
     $parser->run($fileName, $seperator, $mapper, $skipColumnHeader, CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     // store the submitted values in an array
     $params = $this->exportValues();
     if ($this->_action == CRM_Core_Action::DELETE) {
         if ($this->_id) {
             CRM_Core_BAO_Mapping::del($this->_id);
         }
     } else {
         if ($this->_id) {
             $params['id'] = $this->_id;
         }
         CRM_Core_BAO_Mapping::add($params);
     }
 }
示例#22
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 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(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'));
     $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('Lookup mapping info during import?'));
     }
     $this->assign('geoCode', $geoCode);
     $this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2));
     $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'))));
 }
 /**
  * load the smart group cache for a saved search
  */
 static function load(&$group, $fresh = FALSE)
 {
     $groupID = $group->id;
     $savedSearchID = $group->saved_search_id;
     if (array_key_exists($groupID, self::$_alreadyLoaded) && !$fresh) {
         return;
     }
     self::$_alreadyLoaded[$groupID] = 1;
     $sql = NULL;
     $idName = 'id';
     $customClass = NULL;
     if ($savedSearchID) {
         $ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
         // rectify params to what proximity search expects if there is a value for prox_distance
         // CRM-7021
         if (!empty($ssParams)) {
             CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
         }
         $returnProperties = array();
         if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
             $fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
             $returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv);
         }
         if (isset($ssParams['customSearchID'])) {
             // if custom search
             // we split it up and store custom class
             // so temp tables are not destroyed if they are used
             // hence customClass is defined above at top of function
             $customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
             $searchSQL = $customClass->contactIDs();
             $idName = 'contact_id';
         } else {
             $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
             $query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, NULL, FALSE, FALSE, 1, TRUE, TRUE, FALSE, CRM_Utils_Array::value('display_relationship_type', $formValues), CRM_Utils_Array::value('operator', $formValues, 'AND'));
             $query->_useDistinct = FALSE;
             $query->_useGroupBy = FALSE;
             $searchSQL = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, TRUE, TRUE, NULL, NULL, NULL, TRUE);
         }
         $groupID = CRM_Utils_Type::escape($groupID, 'Integer');
         $sql = $searchSQL . " AND contact_a.id NOT IN (\n                              SELECT contact_id FROM civicrm_group_contact\n                              WHERE civicrm_group_contact.status = 'Removed'\n                              AND   civicrm_group_contact.group_id = {$groupID} ) ";
     }
     if ($sql) {
         $sql = preg_replace("/^\\s*SELECT/", "SELECT {$groupID} as group_id, ", $sql);
     }
     // lets also store the records that are explicitly added to the group
     // this allows us to skip the group contact LEFT JOIN
     $sqlB = "\nSELECT {$groupID} as group_id, contact_id as {$idName}\nFROM   civicrm_group_contact\nWHERE  civicrm_group_contact.status = 'Added'\n  AND  civicrm_group_contact.group_id = {$groupID} ";
     $groupIDs = array($groupID);
     self::remove($groupIDs);
     foreach (array($sql, $sqlB) as $selectSql) {
         if (!$selectSql) {
             continue;
         }
         $insertSql = "INSERT IGNORE INTO civicrm_group_contact_cache (group_id,contact_id) ({$selectSql});";
         $processed = TRUE;
         // FIXME
         $result = CRM_Core_DAO::executeQuery($insertSql);
     }
     self::updateCacheTime($groupIDs, $processed);
     if ($group->children) {
         //Store a list of contacts who are removed from the parent group
         $sql = "\nSELECT contact_id\nFROM civicrm_group_contact\nWHERE  civicrm_group_contact.status = 'Removed'\nAND  civicrm_group_contact.group_id = {$groupID} ";
         $dao = CRM_Core_DAO::executeQuery($sql);
         $removed_contacts = array();
         while ($dao->fetch()) {
             $removed_contacts[] = $dao->contact_id;
         }
         $childrenIDs = explode(',', $group->children);
         foreach ($childrenIDs as $childID) {
             $contactIDs = CRM_Contact_BAO_Group::getMember($childID, FALSE);
             //Unset each contact that is removed from the parent group
             foreach ($removed_contacts as $removed_contact) {
                 unset($contactIDs[$removed_contact]);
             }
             $values = array();
             foreach ($contactIDs as $contactID => $dontCare) {
                 $values[] = "({$groupID},{$contactID})";
             }
             self::store($groupIDs, $values);
         }
     }
 }
示例#24
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $multipleCustomData = CRM_Core_BAO_CustomGroup::getMultipleFieldGroup();
     $this->add('select', 'multipleCustomData', ts('Multi-value Custom Data'), array('' => ts('- select -')) + $multipleCustomData, TRUE);
     //Setting Upload File Size
     $config = CRM_Core_Config::singleton();
     $uploadFileSize = CRM_Core_Config_Defaults::formatUnitSize($config->maxFileSize . 'm', TRUE);
     $uploadSize = round($uploadFileSize / (1024 * 1024), 2);
     $this->assign('uploadSize', $uploadSize);
     $this->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
     $this->setMaxFileSize($uploadFileSize);
     $this->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
     $this->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
     $this->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
     $this->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
     //get the saved mapping details
     $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type', 'Import Multi value custom data', 'name'));
     $this->assign('savedMapping', $mappingArray);
     $this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
     if ($loadeMapping = $this->get('loadedMapping')) {
         $this->assign('loadedMapping', $loadeMapping);
         $this->setDefaults(array('savedMapping' => $loadeMapping));
     }
     //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);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Household')) {
         $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Household'), CRM_Import_Parser::CONTACT_HOUSEHOLD);
     }
     if (CRM_Contact_BAO_ContactType::isActive('Organization')) {
         $contactOptions[] = $this->createElement('radio', NULL, NULL, ts('Organization'), CRM_Import_Parser::CONTACT_ORGANIZATION);
     }
     $this->addGroup($contactOptions, 'contactType', ts('Contact Type'));
     $this->setDefaults(array('contactType' => CRM_Import_Parser::CONTACT_INDIVIDUAL));
     //build date formats
     CRM_Core_Form_Date::buildAllowedDateFormats($this);
     $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'))));
 }
 /**
  * Load the smart group cache for a saved search.
  *
  * @param object $group
  *   The smart group that needs to be loaded.
  * @param bool $force
  *   Should we force a search through.
  */
 public static function load(&$group, $force = FALSE)
 {
     $groupID = $group->id;
     $savedSearchID = $group->saved_search_id;
     if (array_key_exists($groupID, self::$_alreadyLoaded) && !$force) {
         return;
     }
     // grab a lock so other processes don't compete and do the same query
     $lock = Civi::lockManager()->acquire("data.core.group.{$groupID}");
     if (!$lock->isAcquired()) {
         // this can cause inconsistent results since we don't know if the other process
         // will fill up the cache before our calling routine needs it.
         // however this routine does not return the status either, so basically
         // its a "lets return and hope for the best"
         return;
     }
     self::$_alreadyLoaded[$groupID] = 1;
     // we now have the lock, but some other process could have actually done the work
     // before we got here, so before we do any work, lets ensure that work needs to be
     // done
     // we allow hidden groups here since we dont know if the caller wants to evaluate an
     // hidden group
     if (!$force && !self::shouldGroupBeRefreshed($groupID, TRUE)) {
         $lock->release();
         return;
     }
     $sql = NULL;
     $idName = 'id';
     $customClass = NULL;
     if ($savedSearchID) {
         $ssParams = CRM_Contact_BAO_SavedSearch::getSearchParams($savedSearchID);
         // rectify params to what proximity search expects if there is a value for prox_distance
         // CRM-7021
         if (!empty($ssParams)) {
             CRM_Contact_BAO_ProximityQuery::fixInputParams($ssParams);
         }
         $returnProperties = array();
         if (CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $savedSearchID, 'mapping_id')) {
             $fv = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
             $returnProperties = CRM_Core_BAO_Mapping::returnProperties($fv);
         }
         if (isset($ssParams['customSearchID'])) {
             // if custom search
             // we split it up and store custom class
             // so temp tables are not destroyed if they are used
             // hence customClass is defined above at top of function
             $customClass = CRM_Contact_BAO_SearchCustom::customClass($ssParams['customSearchID'], $savedSearchID);
             $searchSQL = $customClass->contactIDs();
             $searchSQL = str_replace('ORDER BY contact_a.id ASC', '', $searchSQL);
             if (!strstr($searchSQL, 'WHERE')) {
                 $searchSQL .= " WHERE ( 1 ) ";
             }
             $idName = 'contact_id';
         } else {
             $formValues = CRM_Contact_BAO_SavedSearch::getFormValues($savedSearchID);
             // CRM-17075 using the formValues in this way imposes extra logic and complexity.
             // we have the where_clause and where tables stored in the saved_search table
             // and should use these rather than re-processing the form criteria (which over-works
             // the link between the form layer & the query layer too).
             // It's hard to think of when you would want to use anything other than return
             // properties = array('contact_id' => 1) here as the point would appear to be to
             // generate the list of contact ids in the group.
             // @todo review this to use values in saved_search table (preferably for 4.8).
             $query = new CRM_Contact_BAO_Query($ssParams, $returnProperties, NULL, FALSE, FALSE, 1, TRUE, TRUE, FALSE, CRM_Utils_Array::value('display_relationship_type', $formValues), CRM_Utils_Array::value('operator', $formValues, 'AND'));
             $query->_useDistinct = FALSE;
             $query->_useGroupBy = FALSE;
             $searchSQL = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, TRUE, TRUE, NULL, NULL, NULL, TRUE);
         }
         $groupID = CRM_Utils_Type::escape($groupID, 'Integer');
         $sql = $searchSQL . " AND contact_a.id NOT IN (\n                              SELECT contact_id FROM civicrm_group_contact\n                              WHERE civicrm_group_contact.status = 'Removed'\n                              AND   civicrm_group_contact.group_id = {$groupID} ) ";
     }
     if ($sql) {
         $sql = preg_replace("/^\\s*SELECT/", "SELECT {$groupID} as group_id, ", $sql);
     }
     // lets also store the records that are explicitly added to the group
     // this allows us to skip the group contact LEFT JOIN
     $sqlB = "\nSELECT {$groupID} as group_id, contact_id as {$idName}\nFROM   civicrm_group_contact\nWHERE  civicrm_group_contact.status = 'Added'\n  AND  civicrm_group_contact.group_id = {$groupID} ";
     $groupIDs = array($groupID);
     self::remove($groupIDs);
     $processed = FALSE;
     $tempTable = 'civicrm_temp_group_contact_cache' . rand(0, 2000);
     foreach (array($sql, $sqlB) as $selectSql) {
         if (!$selectSql) {
             continue;
         }
         $insertSql = "CREATE TEMPORARY TABLE {$tempTable} ({$selectSql});";
         $processed = TRUE;
         CRM_Core_DAO::executeQuery($insertSql);
         CRM_Core_DAO::executeQuery("INSERT IGNORE INTO civicrm_group_contact_cache (contact_id, group_id)\n        SELECT DISTINCT {$idName}, group_id FROM {$tempTable}\n      ");
         CRM_Core_DAO::executeQuery(" DROP TEMPORARY TABLE {$tempTable}");
     }
     self::updateCacheTime($groupIDs, $processed);
     if ($group->children) {
         //Store a list of contacts who are removed from the parent group
         $sql = "\nSELECT contact_id\nFROM civicrm_group_contact\nWHERE  civicrm_group_contact.status = 'Removed'\nAND  civicrm_group_contact.group_id = {$groupID} ";
         $dao = CRM_Core_DAO::executeQuery($sql);
         $removed_contacts = array();
         while ($dao->fetch()) {
             $removed_contacts[] = $dao->contact_id;
         }
         $childrenIDs = explode(',', $group->children);
         foreach ($childrenIDs as $childID) {
             $contactIDs = CRM_Contact_BAO_Group::getMember($childID, FALSE);
             //Unset each contact that is removed from the parent group
             foreach ($removed_contacts as $removed_contact) {
                 unset($contactIDs[$removed_contact]);
             }
             $values = array();
             foreach ($contactIDs as $contactID => $dontCare) {
                 $values[] = "({$groupID},{$contactID})";
             }
             self::store($groupIDs, $values);
         }
     }
     $lock->release();
 }
示例#26
0
文件: Task.php 项目: kidaa30/yes
 /**
  * Get the contact id for custom search.
  *
  * we are not using prev/next table in case of custom search
  */
 public function getContactIds()
 {
     // need to perform action on all contacts
     // fire the query again and get the contact id's + display name
     $sortID = NULL;
     if ($this->get(CRM_Utils_Sort::SORT_ID)) {
         $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION));
     }
     $selectorName = $this->controller->selectorName();
     require_once str_replace('_', DIRECTORY_SEPARATOR, $selectorName) . '.php';
     $fv = $this->get('formValues');
     $customClass = $this->get('customSearchClass');
     require_once 'CRM/Core/BAO/Mapping.php';
     $returnProperties = CRM_Core_BAO_Mapping::returnProperties(self::$_searchFormValues);
     $selector = new $selectorName($customClass, $fv, NULL, $returnProperties);
     $params = $this->get('queryParams');
     // fix for CRM-5165
     $sortByCharacter = $this->get('sortByCharacter');
     if ($sortByCharacter && $sortByCharacter != 1) {
         $params[] = array('sortByCharacter', '=', $sortByCharacter, 0, 0);
     }
     $queryOperator = $this->get('queryOperator');
     if (!$queryOperator) {
         $queryOperator = 'AND';
     }
     $dao = $selector->contactIDQuery($params, $this->_action, $sortID, CRM_Utils_Array::value('display_relationship_type', $fv), $queryOperator);
     $contactIds = array();
     while ($dao->fetch()) {
         $contactIds[$dao->contact_id] = $dao->contact_id;
     }
     return $contactIds;
 }
示例#27
0
 /**
  * Process the mapped fields and map it into the uploaded file
  * preview the file and extract some summary statistics
  *
  * @return void
  * @access public
  */
 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;
     }
     $fileName = $this->controller->exportValue('DataSource', 'uploadFile');
     $skipColumnHeader = $this->controller->exportValue('DataSource', 'skipColumnHeader');
     $config = CRM_Core_Config::singleton();
     $seperator = $config->fieldSeparator;
     $mapperKeys = array();
     $mapper = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $mapperKeys[$i][0];
     }
     $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 (CRM_Utils_Array::value('updateMapping', $params)) {
         $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 = $mappingFieldsId[$i];
             $updateMappingFields->mapping_id = $params['mappingId'];
             $updateMappingFields->column_number = $i;
             $explodedValues = explode('_', $mapperKeys[$i][0]);
             $id = CRM_Utils_Array::value(0, $explodedValues);
             $first = CRM_Utils_Array::value(1, $explodedValues);
             $second = CRM_Utils_Array::value(2, $explodedValues);
             $updateMappingFields->name = $mapper[$i];
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (CRM_Utils_Array::value('saveMapping', $params)) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Participant', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         for ($i = 0; $i < $this->_columnCount; $i++) {
             $saveMappingFields = new CRM_Core_DAO_MappingField();
             $saveMappingFields->mapping_id = $saveMapping->id;
             $saveMappingFields->column_number = $i;
             $explodedValues = explode('_', $mapperKeys[$i][0]);
             $id = CRM_Utils_Array::value(0, $explodedValues);
             $first = CRM_Utils_Array::value(1, $explodedValues);
             $second = CRM_Utils_Array::value(2, $explodedValues);
             $saveMappingFields->name = $mapper[$i];
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser = new CRM_Event_Import_Parser_Participant($mapperKeysMain);
     $parser->run($fileName, $seperator, $mapper, $skipColumnHeader, CRM_Import_Parser::MODE_PREVIEW, $this->get('contactType'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
示例#28
0
 /**
  * Process the mapped fields and map it into the uploaded file
  * preview the file and extract some summary statistics
  *
  * @return void
  * @access public
  */
 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 = array();
     $mapper = array();
     $mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
     $mapperKeysMain = array();
     $mapperLocType = array();
     $mapperPhoneType = array();
     $mapperImProvider = array();
     $locations = array();
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     $imProviders = CRM_Core_PseudoConstant::IMProvider();
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $mapper[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
         $mapperKeysMain[$i] = $mapperKeys[$i][0];
         if (isset($mapperKeys[$i][1]) && is_numeric($mapperKeys[$i][1])) {
             $mapperLocType[$i] = $mapperKeys[$i][1];
         } else {
             $mapperLocType[$i] = null;
         }
         $locations[$i] = isset($mapperLocType[$i]) ? $this->_location_types[$mapperLocType[$i]] : null;
         // to store phone_type id and provider id seperately, CRM-3140
         if (CRM_Utils_Array::value($i, $mapperKeysMain) == 'phone') {
             $mapperPhoneType[$i] = $phoneTypes[$mapperKeys[$i][2]];
             $mapperImProvider[$i] = null;
         } else {
             if (CRM_Utils_Array::value($i, $mapperKeysMain) == 'im') {
                 $mapperImProvider[$i] = $imProviders[$mapperKeys[$i][2]];
                 $mapperPhoneType[$i] = null;
             } else {
                 $mapperPhoneType[$i] = null;
                 $mapperImProvider[$i] = null;
             }
         }
         //relationship info
         if (isset($mapperKeys[$i]) && isset($mapperKeys[$i][0])) {
             list($id, $first, $second) = CRM_Utils_System::explode('_', $mapperKeys[$i][0], 3);
         } else {
             list($id, $first, $second) = array(null, null, null);
         }
         if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
             $related[$i] = $this->_mapperFields[$mapperKeys[$i][0]];
             $relatedContactLocType[$i] = isset($mapperKeys[$i][1]) ? $this->_location_types[$mapperKeys[$i][2]] : null;
             //$relatedContactPhoneType[$i] = !is_numeric($mapperKeys[$i][2]) ? $mapperKeys[$i][3] : null;
             // to store phoneType id and provider id seperately for ralated contact, CRM-3140
             if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                 $relatedContactPhoneType[$i] = isset($mapperKeys[$i][3]) ? $phoneTypes[$mapperKeys[$i][3]] : null;
                 $relatedContactImProvider[$i] = null;
             } else {
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                     $relatedContactImProvider[$i] = isset($mapperKeys[$i][3]) ? $imProviders[$mapperKeys[$i][3]] : null;
                     $relatedContactPhoneType[$i] = null;
                 }
             }
             $relationType =& new CRM_Contact_DAO_RelationshipType();
             $relationType->id = $id;
             $relationType->find(true);
             eval('$relatedContactType[$i] = $relationType->contact_type_' . $second . ';');
             $relatedContactDetails[$i] = $this->_formattedFieldNames[$relatedContactType[$i]][$mapperKeys[$i][1]];
         } else {
             $related[$i] = null;
             $relatedContactType[$i] = null;
             $relatedContactDetails[$i] = null;
             $relatedContactLocType[$i] = null;
             $relatedContactPhoneType[$i] = null;
             $relatedContactImProvider[$i] = null;
         }
     }
     $this->set('mapper', $mapper);
     $this->set('locations', $locations);
     $this->set('phones', $mapperPhoneType);
     $this->set('ims', $mapperImProvider);
     $this->set('columnNames', $this->_columnNames);
     //relationship info
     $this->set('related', $related);
     $this->set('relatedContactType', $relatedContactType);
     $this->set('relatedContactDetails', $relatedContactDetails);
     $this->set('relatedContactLocType', $relatedContactLocType);
     $this->set('relatedContactPhoneType', $relatedContactPhoneType);
     $this->set('relatedContactImProvider', $relatedContactImProvider);
     // store mapping Id to display it in the preview page
     $this->set('loadMappingId', CRM_Utils_Array::value('mappingId', $params));
     //Updating Mapping Records
     if (CRM_Utils_Array::value('updateMapping', $params)) {
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $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 = $mappingFieldsId[$i];
             $updateMappingFields->mapping_id = $params['mappingId'];
             $updateMappingFields->column_number = $i;
             list($id, $first, $second) = explode('_', $mapperKeys[$i][0]);
             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]));
                 $updateMappingFields->location_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 // 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]) == 'phone') {
                     $updateMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                 } else {
                     if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                     }
                 }
             } else {
                 $updateMappingFields->name = $mapper[$i];
                 $updateMappingFields->relationship_type_id = null;
                 $location = array_keys($locationTypes, $locations[$i]);
                 $updateMappingFields->location_type_id = isset($location) ? $location[0] : null;
                 // to store phoneType id and provider id seperately
                 // before updating mappingFields for phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                     $updateMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $updateMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                     }
                 }
             }
             $updateMappingFields->save();
         }
     }
     //Saving Mapping Details and Records
     if (CRM_Utils_Array::value('saveMapping', $params)) {
         $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type', 'Import Contact', 'name'));
         $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
         $locationTypes =& CRM_Core_PseudoConstant::locationType();
         $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;
             list($id, $first, $second) = explode('_', $mapperKeys[$i][0]);
             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 seperately
                 // before saving mappingFields of phone and IM for related contact, CRM-3140
                 if (CRM_Utils_Array::value('1', $mapperKeys[$i]) == 'phone') {
                     $saveMappingFields->phone_type_id = isset($mapperKeys[$i][3]) ? $mapperKeys[$i][3] : null;
                 } else {
                     if (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] : null;
             } else {
                 $saveMappingFields->name = $mapper[$i];
                 $location_id = array_keys($locationTypes, $locations[$i]);
                 $saveMappingFields->location_type_id = isset($location_id[0]) ? $location_id[0] : null;
                 // to get phoneType id and provider id seperately
                 // before saving mappingFields of phone and IM, CRM-3140
                 if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'phone') {
                     $saveMappingFields->phone_type_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                 } else {
                     if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
                         $saveMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : null;
                     }
                 }
                 $saveMappingFields->relationship_type_id = null;
             }
             $saveMappingFields->save();
         }
         $this->set('savedMapping', $saveMappingFields->mapping_id);
     }
     $parser =& new CRM_Import_Parser_Contact($mapperKeysMain, $mapperLocType, $mapperPhoneType, $mapperImProvider, $related, $relatedContactType, $relatedContactDetails, $relatedContactLocType, $relatedContactPhoneType, $relatedContactImProvider);
     $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_Import_Parser::DEFAULT_TIMEOUT, $this->get('contactSubType'));
     // add all the necessary variables to the form
     $parser->set($this);
 }
示例#29
0
 /**
  * Given a saved search compute the clause and the tables and store it for future use.
  */
 public function buildClause()
 {
     $fv = unserialize($this->form_values);
     if ($this->mapping_id) {
         $params = CRM_Core_BAO_Mapping::formattedFields($fv);
     } else {
         $params = CRM_Contact_BAO_Query::convertFormValues($fv);
     }
     if (!empty($params)) {
         $tables = $whereTables = array();
         $this->where_clause = CRM_Contact_BAO_Query::getWhereClause($params, NULL, $tables, $whereTables);
         if (!empty($tables)) {
             $this->select_tables = serialize($tables);
         }
         if (!empty($whereTables)) {
             $this->where_tables = serialize($whereTables);
         }
     }
 }
 /**
  * Build the mapping form.
  *
  * @param CRM_Core_Form $form
  * @param string $mappingType
  *   (Export/Import/Search Builder).
  * @param int $mappingId
  * @param int $columnNo
  * @param int $blockCount
  *   (no of blocks shown).
  * @param NULL $exportMode
  *
  * @return void
  */
 public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL)
 {
     $name = "Map";
     $columnCount = array('1' => $columnNo);
     $form->applyFilter('saveMappingName', 'trim');
     //to save the current mappings
     if (!isset($mappingId)) {
         $saveDetailsName = ts('Save this field mapping');
         $form->add('text', 'saveMappingName', ts('Name'));
         $form->add('text', 'saveMappingDesc', ts('Description'));
     } else {
         $form->assign('loadedMapping', $mappingId);
         $params = array('id' => $mappingId);
         $temp = array();
         $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
         $form->assign('savedName', $mappingDetails->name);
         $form->add('hidden', 'mappingId', $mappingId);
         $form->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
         $saveDetailsName = ts('Save as a new field mapping');
         $form->add('text', 'saveMappingName', ts('Name'));
         $form->add('text', 'saveMappingDesc', ts('Description'));
     }
     $form->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
     $form->addFormRule(array('CRM_Export_Form_Map', 'formRule'), $form->get('mappingTypeId'));
     $defaults = array();
     $hasLocationTypes = array();
     $hasRelationTypes = array();
     $fields = array();
     if ($mappingType == 'Export') {
         $required = TRUE;
     }
     $fields = CRM_Contact_BAO_Relationship::fields();
     // add custom fields
     $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Relationship'));
     ksort($fields);
     // add component fields
     $compArray = array();
     foreach ($fields as $key => $value) {
         //CRM-2676, replacing the conflict for same custom field name from different custom group.
         $customGroupName = self::getCustomGroupName($key);
         if ($customGroupName) {
             $relatedMapperFields[$key] = $mapperFields[$key] = $customGroupName . ': ' . $value['title'];
         } else {
             $relatedMapperFields[$key] = $mapperFields[$key] = $value['title'];
         }
     }
     $mapperKeys = array_keys($mapperFields);
     $sel1 = array('' => ts('- select field -')) + $mapperFields;
     if (isset($mappingId)) {
         $colCnt = 0;
         list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue) = CRM_Core_BAO_Mapping::getMappingFields($mappingId);
         $blkCnt = count($mappingName);
         if ($blkCnt >= $blockCount) {
             $blockCount = $blkCnt + 1;
         }
         for ($x = 1; $x < $blockCount; $x++) {
             if (isset($mappingName[$x])) {
                 $colCnt = count($mappingName[$x]);
                 if ($colCnt >= $columnCount[$x]) {
                     $columnCount[$x] = $colCnt;
                 }
             }
         }
     }
     $form->_blockCount = $blockCount;
     $form->_columnCount = $columnCount;
     $form->set('blockCount', $form->_blockCount);
     $form->set('columnCount', $form->_columnCount);
     $defaults = $noneArray = $nullArray = array();
     //used to warn for mismatch column count or mismatch mapping
     $warning = 0;
     for ($x = 1; $x < $blockCount; $x++) {
         for ($i = 0; $i < $columnCount[$x]; $i++) {
             $sel =& $form->addElement('hierselect', "mapper[{$x}][{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL);
             $jsSet = FALSE;
             if (isset($mappingId)) {
                 //TODO opgeslagen mappings
             }
             //Fix for Export
             $j = 7;
             $formValues = $form->exportValues();
             if (!$jsSet) {
                 if (empty($formValues)) {
                     // Incremented length for third select box(relationship type)
                     for ($k = 1; $k < $j; $k++) {
                         $noneArray[] = array($x, $i, $k);
                     }
                 } else {
                     if (!empty($formValues['mapper'][$x])) {
                         foreach ($formValues['mapper'][$x] as $value) {
                             for ($k = 1; $k < $j; $k++) {
                                 if (!isset($formValues['mapper'][$x][$i][$k]) || !$formValues['mapper'][$x][$i][$k]) {
                                     $noneArray[] = array($x, $i, $k);
                                 } else {
                                     $nullArray[] = array($x, $i, $k);
                                 }
                             }
                         }
                     } else {
                         for ($k = 1; $k < $j; $k++) {
                             $noneArray[] = array($x, $i, $k);
                         }
                     }
                 }
             }
             //Fix for Export
             $sel->setOptions(array($sel1));
         }
         $title = ts('Select more fields');
         $form->addElement('submit', "addMore[{$x}]", $title, array('class' => 'submit-link'));
     }
     //end of block for
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$name}";
     if (!empty($nullArray)) {
         $js .= "var nullArray = [";
         $elements = array();
         $seen = array();
         foreach ($nullArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<nullArray.length;i++) {\n                    if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {\n                        {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';\n                    }\n                }\n";
     }
     if (!empty($noneArray)) {
         $js .= "var noneArray = [";
         $elements = array();
         $seen = array();
         foreach ($noneArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<noneArray.length;i++) {\n                    if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {\n  {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';\n                    }\n                }\n";
     }
     $js .= "</script>\n";
     $form->assign('initHideBoxes', $js);
     $form->assign('columnCount', $columnCount);
     $form->assign('blockCount', $blockCount);
     $form->setDefaults($defaults);
     $form->setDefaultAction('refresh');
 }