Exemplo n.º 1
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important
  *
  * @param int     $contactType     contact Type
  * @param boolean $status          status is used to manipulate first title
  * @param boolean $showAll         if true returns all fields (includes disabled fields)
  * @param boolean $isProfile       if its profile mode
  * @param boolean $checkPermission if false, do not include permissioning clause (for custom data)
  *
  * @return array array of importable Fields
  * @access public
  * @static
  */
 static function &importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     $contactType = 'Individual';
     $fields = CRM_Hrjobcontract_DAO_HRJobContract::import();
     $tmpContactField = $contactFields = array();
     $contactFields = array();
     $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
     // Using new Dedupe rule.
     $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
     $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
     if (is_array($fieldsArray)) {
         foreach ($fieldsArray as $value) {
             $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
             $value = $customFieldId ? 'custom_' . $customFieldId : $value;
             $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
             if (!$status) {
                 $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
             } else {
                 $title = $tmpContactField[trim($value)]['title'];
             }
             $tmpContactField[trim($value)]['title'] = $title;
         }
     }
     $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields);
     if ($extIdentifier) {
         $tmpContactField['external_identifier'] = $extIdentifier;
         $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)';
     }
     $fields = array_merge($fields, $tmpContactField);
     self::$_importableFields = $fields;
     return self::$_importableFields;
     //$fields;
 }
Exemplo n.º 2
0
 public static function buildCiviCRMFieldList()
 {
     $fields = CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, TRUE);
     foreach ($fields as $field_name => $field) {
         if (!empty($field['custom_field_id'])) {
             $custom_field = civicrm_api3('CustomField', 'getsingle', array('id' => $field['custom_field_id']));
             if (!empty($custom_field['option_group_id'])) {
                 $fields[$field_name]['pseudoconstant'] = array('optionGroupName' => civicrm_api3('OptionGroup', 'getvalue', array('return' => 'name', 'id' => $custom_field['option_group_id'])));
             }
         }
     }
     return $fields;
 }
Exemplo n.º 3
0
 /**
  * Return a structure holding the supported tables, fields and their titles
  *
  * @param string $requestedType  the requested contact type
  *
  * @return array  a table-keyed array of field-keyed arrays holding supported fields' titles
  */
 function &supportedFields($requestedType)
 {
     static $fields = null;
     if (!$fields) {
         // this is needed, as we're piggy-backing importableFields() below
         $replacements = array('civicrm_country.name' => 'civicrm_address.country_id', 'civicrm_county.name' => 'civicrm_address.county_id', 'civicrm_state_province.name' => 'civicrm_address.state_province_id', 'gender.label' => 'civicrm_contact.gender_id', 'individual_prefix.label' => 'civicrm_contact.prefix_id', 'individual_suffix.label' => 'civicrm_contact.suffix_id', 'addressee.label' => 'civicrm_contact.addressee_id', 'email_greeting.label' => 'civicrm_contact.email_greeting_id', 'postal_greeting.label' => 'civicrm_contact.postal_greeting_id');
         // the table names we support in dedupe rules - a filter for importableFields()
         $supportedTables = array('civicrm_address', 'civicrm_contact', 'civicrm_email', 'civicrm_im', 'civicrm_note', 'civicrm_openid', 'civicrm_phone');
         require_once 'CRM/Contact/BAO/Contact.php';
         require_once 'CRM/Core/BAO/CustomGroup.php';
         foreach (array('Individual', 'Organization', 'Household') as $ctype) {
             // take the table.field pairs and their titles from importableFields() if the table is supported
             foreach (CRM_Contact_BAO_Contact::importableFields($ctype) as $iField) {
                 if (isset($iField['where'])) {
                     $where = $iField['where'];
                     if (isset($replacements[$where])) {
                         $where = $replacements[$where];
                     }
                     list($table, $field) = explode('.', $where);
                     if (!in_array($table, $supportedTables)) {
                         continue;
                     }
                     $fields[$ctype][$table][$field] = $iField['title'];
                 }
             }
             // add custom data fields
             foreach (CRM_Core_BAO_CustomGroup::getTree($ctype, CRM_Core_DAO::$_nullObject, null, -1) as $key => $cg) {
                 if (!is_int($key)) {
                     continue;
                 }
                 foreach ($cg['fields'] as $cf) {
                     $fields[$ctype][$cg['table_name']][$cf['column_name']] = $cf['label'];
                 }
             }
         }
     }
     return $fields[$requestedType];
 }
Exemplo n.º 4
0
 /**
  * @param string $name
  * @param $title
  * @param int $type
  * @param string $headerPattern
  * @param string $dataPattern
  */
 public function addField($name, $title, $type = CRM_Utils_Type::T_INT, $headerPattern = '//', $dataPattern = '//')
 {
     if (empty($name)) {
         $this->_fields['doNotImport'] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern);
     } else {
         //$tempField = CRM_Contact_BAO_Contact::importableFields('Individual', null );
         $tempField = CRM_Contact_BAO_Contact::importableFields('All', NULL);
         if (!array_key_exists($name, $tempField)) {
             $this->_fields[$name] = new CRM_Member_Import_Field($name, $title, $type, $headerPattern, $dataPattern);
         } else {
             $this->_fields[$name] = new CRM_Contact_Import_Field($name, $title, $type, $headerPattern, $dataPattern, CRM_Utils_Array::value('hasLocationType', $tempField[$name]));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important and should be done in the
  * next week or so, before this can be called complete.
  *
  * @return array array of importable Fields
  * @access public
  */
 function &importableFields($contacType = 'Individual', $status = true)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => ts('- do not import -')));
         } else {
             $fields = array('' => array('title' => ts('- Contribution Fields -')));
         }
         require_once 'CRM/Core/DAO/Note.php';
         $note = CRM_Core_DAO_Note::import();
         $tmpFields = CRM_Contribute_DAO_Contribution::import();
         unset($tmpFields['option_value']);
         require_once 'CRM/Core/OptionValue.php';
         $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute');
         require_once 'CRM/Contact/BAO/Contact.php';
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contacType, null);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contacType, 'level' => 'Strict');
         require_once 'CRM/Dedupe/BAO/Rule.php';
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         $tmpConatctField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 //skip if there is no dupe rule
                 if ($value == 'none') {
                     continue;
                 }
                 $tmpConatctField[trim($value)] = $contactFields[trim($value)];
                 if (!$status) {
                     $title = $tmpConatctField[trim($value)]['title'] . " (match to contact)";
                 } else {
                     $title = $tmpConatctField[trim($value)]['title'];
                 }
                 $tmpConatctField[trim($value)]['title'] = $title;
             }
         }
         $tmpConatctField['external_identifier'] = $contactFields['external_identifier'];
         $tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)";
         $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . " (match to contact)";
         $fields = array_merge($fields, $tmpConatctField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, $note);
         $fields = array_merge($fields, $optionFields);
         require_once 'CRM/Contribute/DAO/ContributionType.php';
         $fields = array_merge($fields, CRM_Contribute_DAO_ContributionType::export());
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 6
0
 /**
  * the initializer code, called before the processing
  *
  * @return void
  * @access public
  */
 function init()
 {
     require_once 'CRM/Contact/BAO/Contact.php';
     $fields =& CRM_Contact_BAO_Contact::importableFields($this->_contactType);
     //CRM-5125
     //supporting import for contact subtypes
     if (!empty($this->_contactSubType)) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($this->_contactSubType);
         if (!empty($subTypeFields)) {
             foreach ($subTypeFields as $customSubTypeField => $details) {
                 $fields[$customSubTypeField] = $details;
             }
         }
     }
     //Relationship importables
     $this->_relationships = $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $this->_contactType, false, 'label', true, $this->_contactSubType);
     asort($relations);
     foreach ($relations as $key => $var) {
         list($type) = explode('_', $key);
         $relationshipType[$key]['title'] = $var;
         $relationshipType[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
         $relationshipType[$key]['import'] = true;
         $relationshipType[$key]['relationship_type_id'] = $type;
         $relationshipType[$key]['related'] = true;
     }
     if (!empty($relationshipType)) {
         $fields = array_merge($fields, array('related' => array('title' => ts('- related contact info -'))), $relationshipType);
     }
     foreach ($fields as $name => $field) {
         $this->addField($name, $field['title'], CRM_Utils_Array::value('type', $field), CRM_Utils_Array::value('headerPattern', $field), CRM_Utils_Array::value('dataPattern', $field), CRM_Utils_Array::value('hasLocationType', $field));
     }
     $this->_newContacts = array();
     $this->setActiveFields($this->_mapperKeys);
     $this->setActiveFieldLocationTypes($this->_mapperLocType);
     $this->setActiveFieldPhoneTypes($this->_mapperPhoneType);
     //set active fields of IM provider of contact
     $this->setActiveFieldImProviders($this->_mapperImProvider);
     //related info
     $this->setActiveFieldRelated($this->_mapperRelated);
     $this->setActiveFieldRelatedContactType($this->_mapperRelatedContactType);
     $this->setActiveFieldRelatedContactDetails($this->_mapperRelatedContactDetails);
     $this->setActiveFieldRelatedContactLocType($this->_mapperRelatedContactLocType);
     $this->setActiveFieldRelatedContactPhoneType($this->_mapperRelatedContactPhoneType);
     //set active fields of IM provider of related contact
     $this->setActiveFieldRelatedContactImProvider($this->_mapperRelatedContactImProvider);
     $this->_phoneIndex = -1;
     $this->_emailIndex = -1;
     $this->_firstNameIndex = -1;
     $this->_lastNameIndex = -1;
     $this->_householdNameIndex = -1;
     $this->_organizationNameIndex = -1;
     $this->_externalIdentifierIndex = -1;
     $index = 0;
     foreach ($this->_mapperKeys as $key) {
         if (substr($key, 0, 5) == 'email' && substr($key, 0, 14) != 'email_greeting') {
             $this->_emailIndex = $index;
             $this->_allEmails = array();
         }
         if (substr($key, 0, 5) == 'phone') {
             $this->_phoneIndex = $index;
         }
         if ($key == 'first_name') {
             $this->_firstNameIndex = $index;
         }
         if ($key == 'last_name') {
             $this->_lastNameIndex = $index;
         }
         if ($key == 'household_name') {
             $this->_householdNameIndex = $index;
         }
         if ($key == 'organization_name') {
             $this->_organizationNameIndex = $index;
         }
         if ($key == 'external_identifier') {
             $this->_externalIdentifierIndex = $index;
             $this->_allExternalIdentifiers = array();
         }
         $index++;
     }
     $this->_updateWithId = false;
     if (in_array('id', $this->_mapperKeys) || $this->_externalIdentifierIndex >= 0 && in_array($this->_onDuplicate, array(CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::DUPLICATE_FILL))) {
         $this->_updateWithId = true;
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $this->_parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'), false);
 }
Exemplo n.º 7
0
 /**
  * Combine all the importable fields from the lower levels object.
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important and should be done in the
  * next week or so, before this can be called complete.
  *
  * @param bool $status
  *
  * @return array
  *   array of importable Fields
  */
 public static function &importableFields($status = FALSE)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => ts('- do not import -')));
         } else {
             $fields = array('' => array('title' => ts('- Activity Fields -')));
         }
         $tmpFields = CRM_Activity_DAO_Activity::import();
         $contactFields = CRM_Contact_BAO_Contact::importableFields('Individual', NULL);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => 'Individual', 'used' => 'Unsupervised');
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         $tmpConatctField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                 $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                 $tmpConatctField[trim($value)] = $contactFields[trim($value)];
                 $tmpConatctField[trim($value)]['title'] = $tmpConatctField[trim($value)]['title'] . " (match to contact)";
             }
         }
         $tmpConatctField['external_identifier'] = $contactFields['external_identifier'];
         $tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)";
         $fields = array_merge($fields, $tmpConatctField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Activity'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 8
0
 /**
  * Combine all the importable fields from the lower levels object.
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important and should be done in the
  * next week or so, before this can be called complete.
  *
  * @param string $contactType
  * @param bool $status
  *
  * @return array
  *   array of importable Fields
  */
 public static function &importableFields($contactType = 'Individual', $status = TRUE)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => ts('- do not import -')));
         } else {
             $fields = array('' => array('title' => ts('- Contribution Fields -')));
         }
         $note = CRM_Core_DAO_Note::import();
         $tmpFields = CRM_Contribute_DAO_Contribution::import();
         unset($tmpFields['option_value']);
         $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute');
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         $tmpContactField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 //skip if there is no dupe rule
                 if ($value == 'none') {
                     continue;
                 }
                 $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                 $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                 $tmpContactField[trim($value)] = $contactFields[trim($value)];
                 if (!$status) {
                     $title = $tmpContactField[trim($value)]['title'] . ' ' . ts('(match to contact)');
                 } else {
                     $title = $tmpContactField[trim($value)]['title'];
                 }
                 $tmpContactField[trim($value)]['title'] = $title;
             }
         }
         $tmpContactField['external_identifier'] = $contactFields['external_identifier'];
         $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)');
         $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . ' ' . ts('(match to contact)');
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, $note);
         $fields = array_merge($fields, $optionFields);
         $fields = array_merge($fields, CRM_Financial_DAO_FinancialType::export());
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 9
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     //to save the current mappings
     if (!$this->get('savedMapping')) {
         $saveDetailsName = ts('Save this field mapping');
         $this->applyFilter('saveMappingName', 'trim');
         $this->add('text', 'saveMappingName', ts('Name'));
         $this->add('text', 'saveMappingDesc', ts('Description'));
     } else {
         $savedMapping = $this->get('savedMapping');
         list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingRelation) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
         $mappingName = $mappingName[1];
         $mappingContactType = $mappingContactType[1];
         $mappingLocation = CRM_Utils_Array::value('1', CRM_Utils_Array::value(1, $mappingLocation));
         $mappingPhoneType = CRM_Utils_Array::value('1', CRM_Utils_Array::value(1, $mappingPhoneType));
         $mappingRelation = CRM_Utils_Array::value('1', CRM_Utils_Array::value(1, $mappingRelation));
         //mapping is to be loaded from database
         $params = array('id' => $savedMapping);
         $temp = array();
         $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
         $this->assign('loadedMapping', $mappingDetails->name);
         $this->set('loadedMapping', $savedMapping);
         $getMappingName = new CRM_Core_DAO_Mapping();
         $getMappingName->id = $savedMapping;
         $getMappingName->mapping_type = 'Import Contributions';
         $getMappingName->find();
         while ($getMappingName->fetch()) {
             $mapperName = $getMappingName->name;
         }
         $this->assign('savedName', $mapperName);
         $this->add('hidden', 'mappingId', $savedMapping);
         $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
         $saveDetailsName = ts('Save as a new field mapping');
         $this->add('text', 'saveMappingName', ts('Name'));
         $this->add('text', 'saveMappingDesc', ts('Description'));
     }
     $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
     $this->addFormRule(array('CRM_Contribute_Import_Form_MapField', 'formRule'), $this);
     //-------- end of saved mapping stuff ---------
     $defaults = array();
     $mapperKeys = array_keys($this->_mapperFields);
     $hasHeaders = !empty($this->_columnHeaders);
     $headerPatterns = $this->get('headerPatterns');
     $dataPatterns = $this->get('dataPatterns');
     $hasLocationTypes = $this->get('fieldTypes');
     $mapperKeysValues = $this->controller->exportValue($this->_name, 'mapper');
     /* Initialize all field usages to false */
     foreach ($mapperKeys as $key) {
         $this->_fieldUsed[$key] = FALSE;
     }
     $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $sel1 = $this->_mapperFields;
     if (!$this->get('onDuplicate')) {
         unset($sel1['id']);
         unset($sel1['contribution_id']);
     }
     // start of soft credit section
     // get contact type for this import
     $contactTypeId = $this->get('contactType');
     $contactTypes = array(CRM_Import_Parser::CONTACT_INDIVIDUAL => 'Individual', CRM_Import_Parser::CONTACT_HOUSEHOLD => 'Household', CRM_Import_Parser::CONTACT_ORGANIZATION => 'Organization');
     $contactType = isset($contactTypes[$contactTypeId]) ? $contactTypes[$contactTypeId] : '';
     // get importable fields for contact type
     $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
     // get the Dedupe rule for this contact type and build soft credit array
     $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
     $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
     $softCreditFields['contact_id'] = ts('Contact ID');
     $softCreditFields['external_identifier'] = ts('External ID');
     $softCreditFields['email'] = ts('Email');
     $sel2['soft_credit'] = $softCreditFields;
     $sel3['soft_credit']['contact_id'] = $sel3['soft_credit']['external_identifier'] = $sel3['soft_credit']['email'] = CRM_Core_OptionGroup::values('soft_credit_type');
     $sel4 = NULL;
     // end of soft credit section
     $js = "<script type='text/javascript'>\n";
     $formName = 'document.forms.' . $this->_name;
     //used to warn for mismatch column count or mismatch mapping
     $warning = 0;
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $sel =& $this->addElement('hierselect', "mapper[{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL);
         $jsSet = FALSE;
         if ($this->get('savedMapping')) {
             if (isset($mappingName[$i])) {
                 if ($mappingName[$i] != ts('- do not import -')) {
                     $mappingHeader = array_keys($this->_mapperFields, $mappingName[$i]);
                     // reusing contact_type field array for soft credit
                     $softField = isset($mappingContactType[$i]) ? $mappingContactType[$i] : 0;
                     if (!$softField) {
                         $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n";
                     }
                     $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n";
                     $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n";
                     $defaults["mapper[{$i}]"] = array(CRM_Utils_Array::value(0, $mappingHeader), $softField ? $softField : "", isset($locationId) ? $locationId : "", isset($phoneType) ? $phoneType : "");
                     $jsSet = TRUE;
                 } else {
                     $defaults["mapper[{$i}]"] = array();
                 }
                 if (!$jsSet) {
                     for ($k = 1; $k < 4; $k++) {
                         $js .= "{$formName}['mapper[{$i}][{$k}]'].style.display = 'none';\n";
                     }
                 }
             } else {
                 // this load section to help mapping if we ran out of saved columns when doing Load Mapping
                 $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n";
                 if ($hasHeaders) {
                     $defaults["mapper[{$i}]"] = array($this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns));
                 } else {
                     $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i));
                 }
             }
             //end of load mapping
         } else {
             $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n";
             if ($hasHeaders) {
                 // do array search first to see if has mapped key
                 $columnKey = '';
                 $columnKey = array_search($this->_columnHeaders[$i], $this->_mapperFields);
                 if (isset($this->_fieldUsed[$columnKey])) {
                     $defaults["mapper[{$i}]"] = $columnKey;
                     $this->_fieldUsed[$key] = TRUE;
                 } else {
                     // Infer the default from the column names if we have them
                     $defaults["mapper[{$i}]"] = array($this->defaultFromHeader($this->_columnHeaders[$i], $headerPatterns), 0);
                 }
             } else {
                 // Otherwise guess the default from the form of the data
                 $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i), 0);
             }
             if (!empty($mapperKeysValues) && $mapperKeysValues[$i][0] == 'soft_credit') {
                 $js .= "cj('#mapper_" . $i . "_1').val({$mapperKeysValues[$i]}[1]);\n";
                 $js .= "cj('#mapper_" . $i . "_2').val({$mapperKeysValues[$i]}[2]);\n";
             }
         }
         $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     }
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     //set warning if mismatch in more than
     if (isset($mappingName)) {
         if ($this->_columnCount != count($mappingName)) {
             $warning++;
         }
     }
     if ($warning != 0 && $this->get('savedMapping')) {
         $session = CRM_Core_Session::singleton();
         $session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.'));
     } else {
         $session = CRM_Core_Session::singleton();
         $session->setStatus(NULL);
     }
     $this->setDefaults($defaults);
     $this->addButtons(array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Continue'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
Exemplo n.º 10
0
 /**
  * function to get match clasue for dupe checking
  *
  * @param array   $params  the list of values to be used in the where clause
  * @param  array $tables (reference ) add the tables that are needed for the select clause
  *
  * @return string the where clause to include in a sql query
  * @static
  * @access public
  *
  */
 function getWhereClause($params, &$tables)
 {
     require_once 'CRM/Core/DAO/DupeMatch.php';
     if (is_array($params)) {
         if (is_array($params['location'])) {
             $params['email'] = array();
             $params['phone'] = array();
             $params['im'] = array();
             foreach ($params['location'] as $loc) {
                 foreach (array('email', 'phone', 'im') as $key) {
                     if (is_array($loc[$key])) {
                         foreach ($loc[$key] as $value) {
                             if (!empty($value[$key])) {
                                 $value[$key] = strtolower($value[$key]);
                                 $params[$key][] = '"' . addslashes($value[$key]) . '"';
                             }
                         }
                     }
                 }
             }
         }
         foreach (array('email', 'phone', 'im') as $key) {
             if (count($params[$key]) == 0) {
                 unset($params[$key]);
             }
         }
         foreach (array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'state_province_id', 'postal_code', 'country_id') as $fld) {
             if (!empty($params['location'][1]['address'][$fld])) {
                 $params[$fld] = $params['location'][1]['address'][$fld];
             }
         }
         if (is_array($params['custom'])) {
             foreach ($params['custom'] as $key => $value) {
                 $params['custom_' . $value['custom_field_id']] = $value['value'];
             }
         }
     }
     $importableFields = CRM_Contact_BAO_Contact::importableFields();
     $dupeMatchDAO =& new CRM_Core_DAO_DupeMatch();
     $dupeMatchDAO->find();
     while ($dupeMatchDAO->fetch()) {
         $rule = explode('AND', $dupeMatchDAO->rule);
         foreach ($rule as $name) {
             $name = trim($name);
             $fields[$name] = array('name' => $name, 'title' => $importableFields[$name]['title'], 'where' => $importableFields[$name]['where']);
         }
     }
     require_once 'CRM/Contact/BAO/Query.php';
     //this is the fix to ignore the groups/ tags for dupe checking CRM-664, since we never use them for dupe checking
     $params['group'] = array();
     $params['tag'] = array();
     $whereTables = array();
     return CRM_Contact_BAO_Query::getWhereClause($params, $fields, $tables, $whereTables, true);
 }
Exemplo n.º 11
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 function preProcess()
 {
     $this->_gid = CRM_Utils_Request::retrieve('gid', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', $this);
     if ($this->_action & CRM_CORE_ACTION_UPDATE) {
         $this->_fields =& CRM_Contact_BAO_Contact::importableFields('All', true, true);
     } else {
         $this->_fields =& CRM_Contact_BAO_Contact::importableFields('All', true);
     }
     $this->_fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $this->_fields);
     $this->_selectFields = array();
     foreach ($this->_fields as $name => $field) {
         // lets skip note for now since we dont support it
         if ($name == 'note') {
             continue;
         }
         $this->_selectFields[$name] = $field['title'];
         $this->_hasLocationTypes[$name] = $field['hasLocationType'];
     }
     // lets add group and tag to this list
     $this->_selectFields['group'] = ts('Group(s)');
     $this->_selectFields['tag'] = ts('Tag(s)');
 }
 /**
  * combine all the importable fields from the lower levels object
  *
  * @return array array of importable Fields
  * @access public
  * @static
  */
 static function &importableFields($contactType = 'Individual', $status = TRUE, $onlyParticipant = FALSE)
 {
     if (!self::$_importableFields) {
         if (!$onlyParticipant) {
             if (!$status) {
                 $fields = array('' => array('title' => ts('- do not import -')));
             } else {
                 $fields = array('' => array('title' => ts('- Participant Fields -')));
             }
         } else {
             $fields = array();
         }
         $tmpFields = CRM_Event_DAO_Participant::import();
         $note = array('participant_note' => array('title' => 'Participant Note', 'name' => 'participant_note', 'headerPattern' => '/(participant.)?note$/i'));
         $participantStatus = array('participant_status' => array('title' => 'Participant Status', 'name' => 'participant_status', 'data_type' => CRM_Utils_Type::T_STRING));
         $participantRole = array('participant_role' => array('title' => 'Participant Role', 'name' => 'participant_role', 'data_type' => CRM_Utils_Type::T_STRING));
         $eventType = array('event_type' => array('title' => 'Event Type', 'name' => 'event_type', 'data_type' => CRM_Utils_Type::T_STRING));
         $tmpContactField = $contactFields = array();
         $contactFields = array();
         if (!$onlyParticipant) {
             $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => $contactType, 'level' => 'Strict');
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             if (is_array($fieldsArray)) {
                 foreach ($fieldsArray as $value) {
                     $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                     $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                     $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                     if (!$status) {
                         $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
                     } else {
                         $title = $tmpContactField[trim($value)]['title'];
                     }
                     $tmpContactField[trim($value)]['title'] = $title;
                 }
             }
         }
         $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields);
         if ($extIdentifier) {
             $tmpContactField['external_identifier'] = $extIdentifier;
             $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)';
         }
         $tmpFields['participant_contact_id']['title'] = $tmpFields['participant_contact_id']['title'] . ' (match to contact)';
         //campaign fields.
         if (isset($tmpFields['participant_campaign_id'])) {
             $tmpFields['participant_campaign'] = array('title' => ts('Campaign Title'));
         }
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, $note, $participantStatus, $participantRole, $eventType);
         //$fields = array_merge($fields, $optionFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 13
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if ($this->_gid) {
         $this->_title = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'title');
         $this->setPageTitle(ts('Profile Field'));
         $url = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}");
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext($url);
         $breadCrumb = array(array('title' => ts('CiviCRM Profile Fields'), 'url' => $url));
         CRM_Utils_System::appendBreadCrumb($breadCrumb);
     }
     $showBestResult = CRM_Utils_Request::retrieve('sbr', 'Positive', CRM_Core_DAO::$_nullArray);
     if ($showBestResult) {
         $this->assign('showBestResult', $showBestResult);
     }
     $this->_fields = CRM_Contact_BAO_Contact::importableFields('All', TRUE, TRUE, TRUE, TRUE, TRUE);
     $this->_fields = array_merge(CRM_Activity_BAO_Activity::exportableFields('Activity'), $this->_fields);
     //unset campaign related fields.
     if (isset($this->_fields['activity_campaign_id'])) {
         $this->_fields['activity_campaign_id']['title'] = ts('Campaign');
         if (isset($this->_fields['activity_campaign'])) {
             unset($this->_fields['activity_campaign']);
         }
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(FALSE), $this->_fields);
         $this->_fields = array_merge(CRM_Core_BAO_UFField::getContribBatchEntryFields(), $this->_fields);
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         $this->_fields = array_merge(CRM_Member_BAO_Membership::getMembershipFields(), $this->_fields);
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $this->_fields = array_merge(CRM_Event_BAO_Query::getParticipantFields(), $this->_fields);
     }
     if (CRM_Core_Permission::access('CiviCase')) {
         $this->_fields = array_merge(CRM_Case_BAO_Query::getFields(), $this->_fields);
     }
     $this->_fields = array_merge($this->_fields, CRM_Contact_BAO_Query_Hook::singleton()->getFields());
     $this->_selectFields = array();
     foreach ($this->_fields as $name => $field) {
         // lets skip note for now since we dont support it
         if ($name == 'note') {
             continue;
         }
         $this->_selectFields[$name] = $field['title'];
         $this->_hasLocationTypes[$name] = CRM_Utils_Array::value('hasLocationType', $field);
     }
     // lets add group, tag and current_employer to this list
     $this->_selectFields['group'] = ts('Group(s)');
     $this->_selectFields['tag'] = ts('Tag(s)');
     $this->_selectFields['current_employer'] = ts('Current Employer');
     $this->_selectFields['phone_and_ext'] = ts('Phone and Extension');
     //CRM-4363 check for in selector or searchable fields.
     $this->_hasSearchableORInSelector = CRM_Core_BAO_UFField::checkSearchableORInSelector($this->_gid);
     $this->assign('fieldId', $this->_id);
     if ($this->_id) {
         $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFField', $this->_id, 'label');
         $this->assign('fieldTitle', $fieldTitle);
     }
 }
Exemplo n.º 14
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important and should be done in the
  * next week or so, before this can be called complete.
  *
  * @return array array of importable Fields
  * @access public
  */
 function &importableFields()
 {
     if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['_importableFields']) {
         if (!$GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['_importableFields']) {
             $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['_importableFields'] = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => ts('- do not import -')));
         } else {
             $fields = array('' => array('title' => ts('- Contribution Fields -')));
         }
         $tmpFields = CRM_Contribute_DAO_Contribution::import();
         $contactFields = CRM_Contact_BAO_Contact::importableFields('Individual', null);
         require_once 'CRM/Core/DAO/DupeMatch.php';
         $dao =& new CRM_Core_DAO_DupeMatch();
         $dao->find(true);
         $fieldsArray = explode('AND', $dao->rule);
         $tmpConatctField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $tmpConatctField[trim($value)] = $contactFields[trim($value)];
                 $tmpConatctField[trim($value)]['title'] = $tmpConatctField[trim($value)]['title'] . " (match to contact)";
             }
         }
         $fields = array_merge($fields, $tmpConatctField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'));
         $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['_importableFields'] = $fields;
     }
     return $GLOBALS['_CRM_CONTRIBUTE_BAO_CONTRIBUTION']['_importableFields'];
 }
Exemplo n.º 15
0
 /**
  * Replace all the org-level tokens in $str
  *
  * @param string $str       The string with tokens to be replaced
  * @param object $org       Associative array of org properties
  * @param boolean $html     Replace tokens with HTML or plain text
  * @return string           The processed string
  * @access public
  * @static
  */
 public static function &replaceOrgTokens($str, &$org, $html = false)
 {
     self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id'));
     /*
     print "org tokens: <pre>";
     print_r( $_tokens['org'] );
     print "</pre>";
     */
     $cv = null;
     foreach (self::$_tokens['org'] as $token) {
         // print "Getting token value for $token<br/><br/>";
         if ($token == '') {
             continue;
         }
         /* If the string doesn't contain this token, skip it. */
         if (!self::token_match('org', $token, $str)) {
             continue;
         }
         /* Construct value from $token and $contact */
         $value = null;
         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) {
             // only generate cv if we need it
             if ($cv === null) {
                 $cv =& CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']);
             }
             foreach ($cv as $cvFieldID => $value) {
                 if ($cvFieldID == $cfID) {
                     $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value);
                     break;
                 }
             }
         } else {
             if ($token == 'checksum') {
                 require_once 'CRM/Contact/BAO/Contact/Utils.php';
                 $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']);
                 $value = "cs={$cs}";
             } else {
                 if ($token == 'address') {
                     /* Build the location values array */
                     $loc = array();
                     $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name');
                     $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address');
                     $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city');
                     $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province');
                     $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code');
                     /* Construct the address token */
                     $value = CRM_Utils_Address::format($loc);
                     if ($html) {
                         $value = str_replace("\n", '<br />', $value);
                     }
                 } else {
                     /*
                     print "\$org: <pre>";
                     print_r( $org );
                     print "</pre>";
                     */
                     $value = CRM_Utils_Array::retrieveValueRecursive($org, $token);
                     /*
                     print "\$value: <pre>";
                     print_r( $value );
                     print "</pre>";
                     */
                 }
             }
         }
         self::token_replace('org', $token, $value, $str);
     }
     return $str;
 }
Exemplo n.º 16
0
 /**
  * Get a list of fields which can be added to profiles.
  *
  * @param int $gid : UF group ID
  * @param array $defaults : Form defaults
  * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label']
  */
 public static function getAvailableFields($gid = NULL, $defaults = array())
 {
     $fields = array('Contact' => array(), 'Individual' => CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE), 'Household' => CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE), 'Organization' => CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE));
     // include hook injected fields
     $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook::singleton()->getFields());
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']);
     }
     // break out common contact fields array CRM-3037.
     // from a UI perspective this makes very little sense
     foreach ($fields['Individual'] as $key => $value) {
         if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
             $fields['Contact'][$key] = $value;
             unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]);
         }
     }
     // Internal field not exposed to forms
     unset($fields['Contact']['contact_type']);
     unset($fields['Contact']['master_id']);
     // convert phone extension in to psedo-field phone + phone extension
     //unset extension
     unset($fields['Contact']['phone_ext']);
     //add psedo field
     $fields['Contact']['phone_and_ext'] = array('name' => 'phone_and_ext', 'title' => ts('Phone and Extension'), 'hasLocationType' => 1);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE);
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $contribFields['contribution_note'] = array('name' => 'contribution_note', 'title' => ts('Contribution Note'));
             $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields());
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $participantFields = CRM_Event_BAO_Query::getParticipantFields();
         if ($participantFields) {
             // Remove fields not supported by profiles
             CRM_Utils_Array::remove($participantFields, 'external_identifier', 'event_id', 'participant_contact_id', 'participant_role_id', 'participant_status_id', 'participant_is_test', 'participant_fee_level', 'participant_id', 'participant_is_pay_later', 'participant_campaign');
             if (isset($participantFields['participant_campaign_id'])) {
                 $participantFields['participant_campaign_id']['title'] = ts('Campaign');
             }
             $fields['Participant'] = $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         $membershipFields = CRM_Member_BAO_Membership::getMembershipFields();
         // Remove fields not supported by profiles
         CRM_Utils_Array::remove($membershipFields, 'membership_id', 'membership_type_id', 'member_is_test', 'is_override', 'status_id', 'member_is_pay_later');
         if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') {
             $fields['Membership'] = array_merge($membershipFields, self::getMemberBatchEntryFields());
         } else {
             $fields['Membership'] = $membershipFields;
         }
     }
     if (CRM_Core_Permission::access('CiviCase')) {
         $caseFields = CRM_Case_BAO_Query::getFields(TRUE);
         $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case'));
         if ($caseFields) {
             // Remove fields not supported by profiles
             CRM_Utils_Array::remove($caseFields, 'case_id', 'case_type', 'case_start_date', 'case_end_date', 'case_role', 'case_status', 'case_deleted');
         }
         $fields['Case'] = $caseFields;
     }
     $activityFields = CRM_Activity_BAO_Activity::getProfileFields();
     if ($activityFields) {
         // campaign related fields.
         if (isset($activityFields['activity_campaign_id'])) {
             $activityFields['activity_campaign_id']['title'] = ts('Campaign');
         }
         $fields['Activity'] = $activityFields;
     }
     $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array('name' => 'free_html', 'import' => FALSE, 'export' => FALSE, 'title' => 'Free HTML');
     // Sort by title
     foreach ($fields as &$values) {
         $values = CRM_Utils_Array::crmArraySortByField($values, 'title');
     }
     //group selected and unwanted fields list
     $ufFields = $gid ? CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array();
     $groupFieldList = array_merge($ufFields, array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'));
     //unset selected fields
     foreach ($groupFieldList as $key => $value) {
         if (is_int($key)) {
             unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
             continue;
         }
         if (!empty($defaults['field_name']) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) {
             continue;
         }
         unset($fields[$value['field_type']][$key]);
     }
     return $fields;
 }
Exemplo n.º 17
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     //to save the current mappings
     if (!$this->get('savedMapping')) {
         $saveDetailsName = ts('Save this field mapping');
         $this->applyFilter('saveMappingName', 'trim');
         $this->add('text', 'saveMappingName', ts('Name'));
         $this->add('text', 'saveMappingDesc', ts('Description'));
     } else {
         $savedMapping = $this->get('savedMapping');
         list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue, $mappingWebsiteType) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping);
         //get loaded Mapping Fields
         $mappingName = CRM_Utils_Array::value(1, $mappingName);
         $mappingContactType = CRM_Utils_Array::value(1, $mappingContactType);
         $mappingLocation = CRM_Utils_Array::value(1, $mappingLocation);
         $mappingPhoneType = CRM_Utils_Array::value(1, $mappingPhoneType);
         $mappingImProvider = CRM_Utils_Array::value(1, $mappingImProvider);
         $mappingRelation = CRM_Utils_Array::value(1, $mappingRelation);
         $mappingWebsiteType = CRM_Utils_Array::value(1, $mappingWebsiteType);
         $this->assign('loadedMapping', $savedMapping);
         $this->set('loadedMapping', $savedMapping);
         $params = array('id' => $savedMapping);
         $temp = array();
         $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
         $this->assign('savedName', $mappingDetails->name);
         $this->add('hidden', 'mappingId', $savedMapping);
         $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
         $saveDetailsName = ts('Save as a new field mapping');
         $this->add('text', 'saveMappingName', ts('Name'));
         $this->add('text', 'saveMappingDesc', ts('Description'));
     }
     $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
     $this->addFormRule(array('CRM_Contact_Import_Form_MapField', 'formRule'));
     //-------- end of saved mapping stuff ---------
     $defaults = array();
     $mapperKeys = array_keys($this->_mapperFields);
     $hasColumnNames = !empty($this->_columnNames);
     $columnPatterns = $this->get('columnPatterns');
     $dataPatterns = $this->get('dataPatterns');
     $hasLocationTypes = $this->get('fieldTypes');
     $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     // Pass default location to js
     if ($defaultLocationType) {
         $this->assign('defaultLocationType', $defaultLocationType->id);
         $this->assign('defaultLocationTypeLabel', $this->_location_types[$defaultLocationType->id]);
     }
     /* Initialize all field usages to false */
     foreach ($mapperKeys as $key) {
         $this->_fieldUsed[$key] = FALSE;
     }
     $sel1 = $this->_mapperFields;
     $sel2[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id');
     foreach ($this->_location_types as $key => $value) {
         $sel3['phone'][$key] =& $phoneTypes;
         //build array for IM service provider type for contact
         $sel3['im'][$key] =& $imProviders;
     }
     $sel4 = NULL;
     // store and cache all relationship types
     $contactRelation = new CRM_Contact_DAO_RelationshipType();
     $contactRelation->find();
     while ($contactRelation->fetch()) {
         $contactRelationCache[$contactRelation->id] = array();
         $contactRelationCache[$contactRelation->id]['contact_type_a'] = $contactRelation->contact_type_a;
         $contactRelationCache[$contactRelation->id]['contact_sub_type_a'] = $contactRelation->contact_sub_type_a;
         $contactRelationCache[$contactRelation->id]['contact_type_b'] = $contactRelation->contact_type_b;
         $contactRelationCache[$contactRelation->id]['contact_sub_type_b'] = $contactRelation->contact_sub_type_b;
     }
     $highlightedFields = $highlightedRelFields = array();
     $highlightedFields['email'] = 'All';
     $highlightedFields['external_identifier'] = 'All';
     $highlightedFields['first_name'] = 'Individual';
     $highlightedFields['last_name'] = 'Individual';
     $highlightedFields['household_name'] = 'Household';
     $highlightedFields['organization_name'] = 'Organization';
     foreach ($mapperKeys as $key) {
         // check if there is a _a_b or _b_a in the key
         if (strpos($key, '_a_b') || strpos($key, '_b_a')) {
             list($id, $first, $second) = explode('_', $key);
         } else {
             $id = $first = $second = NULL;
         }
         if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') {
             $cType = $contactRelationCache[$id]["contact_type_{$second}"];
             //CRM-5125 for contact subtype specific relationshiptypes
             $cSubType = NULL;
             if (!empty($contactRelationCache[$id]["contact_sub_type_{$second}"])) {
                 $cSubType = $contactRelationCache[$id]["contact_sub_type_{$second}"];
             }
             if (!$cType) {
                 $cType = 'All';
             }
             $relatedFields = array();
             $relatedFields = CRM_Contact_BAO_Contact::importableFields($cType);
             unset($relatedFields['']);
             $values = array();
             foreach ($relatedFields as $name => $field) {
                 $values[$name] = $field['title'];
                 if (isset($hasLocationTypes[$name])) {
                     $sel3[$key][$name] = $this->_location_types;
                 } elseif ($name == 'url') {
                     $sel3[$key][$name] = $websiteTypes;
                 } else {
                     $sel3[$name] = NULL;
                 }
             }
             //fix to append custom group name to field name, CRM-2676
             if (empty($this->_formattedFieldNames[$cType]) || $cType == $this->_contactType) {
                 $this->_formattedFieldNames[$cType] = $this->formatCustomFieldName($values);
             }
             $this->_formattedFieldNames[$cType] = array_merge($values, $this->_formattedFieldNames[$cType]);
             //Modified the Relationship fields if the fields are
             //present in dedupe rule
             if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK && !empty($this->_dedupeFields[$cType]) && is_array($this->_dedupeFields[$cType])) {
                 static $cTypeArray = array();
                 if ($cType != $this->_contactType && !in_array($cType, $cTypeArray)) {
                     foreach ($this->_dedupeFields[$cType] as $val) {
                         if ($valTitle = CRM_Utils_Array::value($val, $this->_formattedFieldNames[$cType])) {
                             $this->_formattedFieldNames[$cType][$val] = $valTitle . ' (match to contact)';
                         }
                     }
                     $cTypeArray[] = $cType;
                 }
             }
             foreach ($highlightedFields as $k => $v) {
                 if ($v == $cType || $v == 'All') {
                     $highlightedRelFields[$key][] = $k;
                 }
             }
             $this->assign('highlightedRelFields', $highlightedRelFields);
             $sel2[$key] = $this->_formattedFieldNames[$cType];
             if (!empty($cSubType)) {
                 //custom fields for sub type
                 $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($cSubType);
                 if (!empty($subTypeFields)) {
                     $subType = NULL;
                     foreach ($subTypeFields as $customSubTypeField => $details) {
                         $subType[$customSubTypeField] = $details['title'];
                         $sel2[$key] = array_merge($sel2[$key], $this->formatCustomFieldName($subType));
                     }
                 }
             }
             foreach ($this->_location_types as $k => $value) {
                 $sel4[$key]['phone'][$k] =& $phoneTypes;
                 //build array of IM service provider for related contact
                 $sel4[$key]['im'][$k] =& $imProviders;
             }
         } else {
             $options = NULL;
             if (!empty($hasLocationTypes[$key])) {
                 $options = $this->_location_types;
             } elseif ($key == 'url') {
                 $options = $websiteTypes;
             }
             $sel2[$key] = $options;
         }
     }
     $js = "<script type='text/javascript'>\n";
     $formName = 'document.forms.' . $this->_name;
     //used to warn for mismatch column count or mismatch mapping
     $warning = 0;
     for ($i = 0; $i < $this->_columnCount; $i++) {
         $sel =& $this->addElement('hierselect', "mapper[{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL);
         $jsSet = FALSE;
         if ($this->get('savedMapping')) {
             if (isset($mappingName[$i])) {
                 if ($mappingName[$i] != ts('- do not import -')) {
                     if (isset($mappingRelation[$i])) {
                         // relationship mapping
                         switch ($this->get('contactType')) {
                             case CRM_Import_Parser::CONTACT_INDIVIDUAL:
                                 $contactType = 'Individual';
                                 break;
                             case CRM_Import_Parser::CONTACT_HOUSEHOLD:
                                 $contactType = 'Household';
                                 break;
                             case CRM_Import_Parser::CONTACT_ORGANIZATION:
                                 $contactType = 'Organization';
                         }
                         //CRM-5125
                         $contactSubType = NULL;
                         if ($this->get('contactSubType')) {
                             $contactSubType = $this->get('contactSubType');
                         }
                         $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType, FALSE, 'label', TRUE, $contactSubType);
                         foreach ($relations as $key => $var) {
                             if ($key == $mappingRelation[$i]) {
                                 $relation = $key;
                                 break;
                             }
                         }
                         $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i]));
                         $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL;
                         $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0;
                         $phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL;
                         //get provider id from saved mappings
                         $imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL;
                         if ($websiteTypeId) {
                             $defaults["mapper[{$i}]"] = array($relation, $contactDetails, $websiteTypeId);
                             if (!$websiteTypeId) {
                                 $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n";
                             }
                         } else {
                             // default for IM/phone when mapping with relation is true
                             $typeId = NULL;
                             if (isset($phoneType)) {
                                 $typeId = $phoneType;
                             } elseif (isset($imProvider)) {
                                 $typeId = $imProvider;
                             }
                             $defaults["mapper[{$i}]"] = array($relation, $contactDetails, $locationId, $typeId);
                             if (!$locationId) {
                                 $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n";
                             }
                         }
                         // fix for edge cases, CRM-4954
                         if ($contactDetails == 'image_url') {
                             $contactDetails = str_replace('url', 'URL', $contactDetails);
                         }
                         if (!$contactDetails) {
                             $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n";
                         }
                         if (!$phoneType && !$imProvider) {
                             $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n";
                         }
                         //$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n";
                         $jsSet = TRUE;
                     } else {
                         $mappingHeader = array_keys($this->_mapperFields, $mappingName[$i]);
                         $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL;
                         $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0;
                         $phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL;
                         // get IM service provider id
                         $imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL;
                         if ($websiteTypeId) {
                             if (!$websiteTypeId) {
                                 $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n";
                             }
                             $defaults["mapper[{$i}]"] = array($mappingHeader[0], $websiteTypeId);
                         } else {
                             if (!$locationId) {
                                 $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n";
                             }
                             //default for IM/phone without related contact
                             $typeId = NULL;
                             if (isset($phoneType)) {
                                 $typeId = $phoneType;
                             } elseif (isset($imProvider)) {
                                 $typeId = $imProvider;
                             }
                             $defaults["mapper[{$i}]"] = array($mappingHeader[0], $locationId, $typeId);
                         }
                         if (!$phoneType && !$imProvider) {
                             $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n";
                         }
                         $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n";
                         $jsSet = TRUE;
                     }
                 } else {
                     $defaults["mapper[{$i}]"] = array();
                 }
                 if (!$jsSet) {
                     for ($k = 1; $k < 4; $k++) {
                         $js .= "{$formName}['mapper[{$i}][{$k}]'].style.display = 'none';\n";
                     }
                 }
             } else {
                 // this load section to help mapping if we ran out of saved columns when doing Load Mapping
                 $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n";
                 if ($hasColumnNames) {
                     $defaults["mapper[{$i}]"] = array($this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns));
                 } else {
                     $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i));
                 }
             }
             //end of load mapping
         } else {
             $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n";
             if ($hasColumnNames) {
                 // do array search first to see if has mapped key
                 $columnKey = '';
                 $columnKey = array_search($this->_columnNames[$i], $this->_mapperFields);
                 if (isset($this->_fieldUsed[$columnKey])) {
                     $defaults["mapper[{$i}]"] = $columnKey;
                     $this->_fieldUsed[$key] = TRUE;
                 } else {
                     // Infer the default from the column names if we have them
                     $defaults["mapper[{$i}]"] = array($this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns), 0);
                 }
             } else {
                 // Otherwise guess the default from the form of the data
                 $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i), 0);
             }
         }
         $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     }
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     //set warning if mismatch in more than
     if (isset($mappingName) && $this->_columnCount != count($mappingName)) {
         $warning++;
     }
     if ($warning != 0 && $this->get('savedMapping')) {
         $session = CRM_Core_Session::singleton();
         $session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.'));
     } else {
         $session = CRM_Core_Session::singleton();
         $session->setStatus(NULL);
     }
     $this->setDefaults($defaults);
     $this->addButtons(array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Continue'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
 }
Exemplo n.º 18
0
 /**
  * Function to actually build the form
  *
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_UFField::retrieve($params, $defaults);
         // set it to null if so (avoids crappy E_NOTICE errors below
         $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults);
         $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', 'county', 'phone', 'email', 'im', 'address_name');
         if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) {
             $defaults['location_type_id'] = 0;
         }
         $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults));
         $this->_gid = $defaults['uf_group_id'];
     } else {
         $defaults['is_active'] = 1;
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $fieldValues = array('uf_group_id' => $this->_gid);
         $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
     }
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     //hidden field to catch the group id in profile
     $this->add('hidden', 'group_id', $this->_gid);
     //hidden field to catch the field id in profile
     $this->add('hidden', 'field_id', $this->_id);
     $fields = array();
     $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true);
     $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true);
     $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true);
     // add current employer for individuals
     $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer'));
     // unset unwanted fields
     $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id');
     foreach ($unsetFieldArray as $value) {
         unset($fields['Individual'][$value]);
         unset($fields['Household'][$value]);
         unset($fields['Organization'][$value]);
     }
     require_once 'CRM/Core/BAO/Preferences.php';
     $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true);
     if (!$addressOptions['county']) {
         unset($fields['Individual']['county']);
         unset($fields['Household']['county']);
         unset($fields['Organization']['county']);
     }
     //build the common contact fields array CRM-3037.
     foreach ($fields['Individual'] as $key => $value) {
         if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) {
             $fields['Contact'][$key] = $value;
             //as we move common fields to contacts. There fore these fields
             //are unset from resoective array's.
             unset($fields['Individual'][$key]);
             unset($fields['Household'][$key]);
             unset($fields['Organization'][$key]);
         }
     }
     // add current employer for individuals
     $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID'));
     unset($fields['Contact']['contact_type']);
     // 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);
     unset($contactTypes['']);
     // include Subtypes For Profile
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $name => $val) {
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name);
         if (array_key_exists($val['parent'], $fields)) {
             $fields[$name] = $fields[$val['parent']] + $subTypeFields;
         } else {
             $fields[$name] = $subTypeFields;
         }
     }
     unset($subTypes);
     if (CRM_Core_Permission::access('Quest')) {
         require_once 'CRM/Quest/BAO/Student.php';
         $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields();
     }
     if (CRM_Core_Permission::access('CiviContribute')) {
         $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields();
         if (!empty($contribFields)) {
             unset($contribFields['is_test']);
             unset($contribFields['is_pay_later']);
             unset($contribFields['contribution_id']);
             $fields['Contribution'] =& $contribFields;
         }
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         require_once 'CRM/Event/BAO/Query.php';
         $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true);
         if (!empty($participantFields)) {
             unset($participantFields['external_identifier']);
             unset($participantFields['event_id']);
             unset($participantFields['participant_contact_id']);
             unset($participantFields['participant_is_test']);
             unset($participantFields['participant_fee_level']);
             unset($participantFields['participant_id']);
             unset($participantFields['participant_is_pay_later']);
             $fields['Participant'] =& $participantFields;
         }
     }
     if (CRM_Core_Permission::access('CiviMember')) {
         require_once 'CRM/Member/BAO/Membership.php';
         $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields();
         unset($membershipFields['membership_id']);
         unset($membershipFields['join_date']);
         unset($membershipFields['membership_start_date']);
         unset($membershipFields['membership_type_id']);
         unset($membershipFields['membership_end_date']);
         unset($membershipFields['member_is_test']);
         unset($membershipFields['is_override']);
         unset($membershipFields['status_id']);
         unset($membershipFields['member_is_pay_later']);
         $fields['Membership'] =& $membershipFields;
     }
     $noSearchable = array();
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             require_once 'CRM/Core/BAO/CustomField.php';
             if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) {
                 $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
                 $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
                 $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
             } else {
                 $this->_mapperFields[$key][$key1] = $value1['title'];
             }
             $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1);
             // hide the 'is searchable' field for 'File' custom data
             if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) {
                 if (!in_array($value1['title'], $noSearchable)) {
                     $noSearchable[] = $value1['title'];
                 }
             }
         }
     }
     $this->assign('noSearchable', $noSearchable);
     require_once 'CRM/Core/BAO/LocationType.php';
     $this->_location_types =& CRM_Core_PseudoConstant::locationType();
     $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 = $this->_location_types[$defaultLocationType->id];
         unset($this->_location_types[$defaultLocationType->id]);
         $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types;
     }
     $this->_location_types = array('Primary') + $this->_location_types;
     $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array();
     $sel1 = array('' => '- select -') + $contactTypes;
     if (CRM_Core_Permission::access('Quest')) {
         $sel1['Student'] = 'Students';
     }
     if (CRM_Core_Permission::access('CiviEvent')) {
         $sel1['Participant'] = 'Participants';
     }
     if (!empty($contribFields)) {
         $sel1['Contribution'] = 'Contributions';
     }
     if (!empty($membershipFields)) {
         $sel1['Membership'] = 'Membership';
     }
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             $sel2[$key] = $this->_mapperFields[$key];
         }
     }
     $sel3[''] = null;
     $phoneTypes = CRM_Core_PseudoConstant::phoneType();
     ksort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($this->_location_types as $key => $value) {
                 $sel4[$k]['phone'][$key] =& $phoneTypes;
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             if (is_array($this->_mapperFields[$k])) {
                 foreach ($this->_mapperFields[$k] as $key => $value) {
                     if ($hasLocationTypes[$k][$key]) {
                         $sel3[$k][$key] = $this->_location_types;
                     } else {
                         $sel3[$key] = null;
                     }
                 }
             }
         }
     }
     $this->_defaults = array();
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$this->_name}";
     $alreadyMixProfile = false;
     if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) {
         $alreadyMixProfile = true;
     }
     $this->assign('alreadyMixProfile', $alreadyMixProfile);
     $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes);
     $formValues = array();
     $formValues = $this->exportValues();
     if (empty($formValues)) {
         for ($k = 1; $k < 4; $k++) {
             if (!$defaults['field_name'][$k]) {
                 $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
             }
         }
     } else {
         if (!empty($formValues['field_name'])) {
             foreach ($formValues['field_name'] as $value) {
                 for ($k = 1; $k < 4; $k++) {
                     if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                     } else {
                         $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n";
                     }
                 }
             }
         } else {
             for ($k = 1; $k < 4; $k++) {
                 if (!isset($defaults['field_name'][$k])) {
                     $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n";
                 }
             }
         }
     }
     foreach ($sel2 as $k => $v) {
         if (is_array($sel2[$k])) {
             asort($sel2[$k]);
         }
     }
     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
     $js .= "</script>\n";
     $this->assign('initHideBoxes', $js);
     $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);"));
     //CRM-4363
     $js = array('onclick' => "mixProfile();");
     // should the field appear in selectors (as a column)?
     $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js);
     $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js);
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post'));
     // listings title
     $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title'));
     $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title');
     $this->add('checkbox', 'is_required', ts('Required?'));
     $this->add('checkbox', 'is_active', ts('Active?'));
     $this->add('checkbox', 'is_view', ts('View Only?'));
     // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
     //$this->add( 'checkbox', 'is_match'       , ts( 'Key to Match Contacts?'        ) );
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label'));
     $js = null;
     if ($this->_hasSearchableORInSelector) {
         $js = array('onclick' => "return verify( );");
     }
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'"));
     }
     $this->setDefaults($defaults);
 }
Exemplo n.º 19
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     require_once 'CRM/Core/BAO/DupeMatch.php';
     $params = $this->exportValues();
     if (!$this->_advanced) {
         $rule = array();
         for ($count = 1; $count <= 5; $count++) {
             if ($params['match_on_' . $count] != '') {
                 $rule[] = $params['match_on_' . $count];
             }
         }
         if (count($rule) >= 1) {
             $rule = implode(' AND ', $rule);
             $dupematch = CRM_Core_BAO_DupeMatch::add($rule);
         }
     } else {
         $inValid = false;
         $rule = trim($params['match_on']);
         $tokens = preg_split('/[\\s]+/', $rule, -1, PREG_SPLIT_NO_EMPTY);
         //$tokens = preg_split('/([AND])|([OR()])/',$rule, -1 ,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
         $openParen = $closeParen = $andCount = $orCount = $fieldCount = 0;
         foreach ($tokens as $token) {
             $token = trim($token);
             if ($token == '(') {
                 $openParen++;
             } else {
                 if ($token == ')') {
                     $closeParen++;
                 } else {
                     if ($token == 'AND') {
                         $andCount++;
                     } else {
                         if ($token == 'OR') {
                             $orCount++;
                         } else {
                             $fieldCount++;
                         }
                     }
                 }
             }
         }
         if ($openParen != $closeParen || $fieldCount - 1 != $andCount + $orCount) {
             $inValid = true;
         }
         // need to do proper validation
         $fields =& CRM_Contact_BAO_Contact::importableFields('Individual', 1);
         $ruleFields = preg_split('/[ANDOR()\\s]+/', $rule, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($ruleFields as $value) {
             if (isset($value)) {
                 if (!array_key_exists($value, $fields)) {
                     $inValid = true;
                 }
             }
         }
         if ($inValid) {
             CRM_Core_Session::setStatus(ts("The Duplicate Matching rule has not been saved, because the rule is invalid. Rules should contain only valid field names, 'AND', 'OR' or parentheses."));
             return;
         } else {
             $dupematch = CRM_Core_BAO_DupeMatch::add($rule);
         }
     }
     CRM_Core_Session::setStatus(ts('The Duplicate Matching rule has been saved.'));
 }
Exemplo n.º 20
0
/**
 * check duplicate contacts based on de-deupe parameters
 */
function _civicrm_api3_deprecated_check_contact_dedupe($params)
{
    static $cIndieFields = NULL;
    static $defaultLocationId = NULL;
    $contactType = $params['contact_type'];
    if ($cIndieFields == NULL) {
        require_once 'CRM/Contact/BAO/Contact.php';
        $cTempIndieFields = CRM_Contact_BAO_Contact::importableFields($contactType);
        $cIndieFields = $cTempIndieFields;
        require_once "CRM/Core/BAO/LocationType.php";
        $defaultLocation = CRM_Core_BAO_LocationType::getDefault();
        // set the value to default location id else set to 1
        if (!($defaultLocationId = (int) $defaultLocation->id)) {
            $defaultLocationId = 1;
        }
    }
    require_once 'CRM/Contact/BAO/Query.php';
    $locationFields = CRM_Contact_BAO_Query::$_locationSpecificFields;
    $contactFormatted = array();
    foreach ($params as $key => $field) {
        if ($field == NULL || $field === '') {
            continue;
        }
        if (is_array($field)) {
            foreach ($field as $value) {
                $break = FALSE;
                if (is_array($value)) {
                    foreach ($value as $name => $testForEmpty) {
                        if ($name !== 'phone_type' && ($testForEmpty === '' || $testForEmpty == NULL)) {
                            $break = TRUE;
                            break;
                        }
                    }
                } else {
                    $break = TRUE;
                }
                if (!$break) {
                    _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted);
                }
            }
            continue;
        }
        $value = array($key => $field);
        // check if location related field, then we need to add primary location type
        if (in_array($key, $locationFields)) {
            $value['location_type_id'] = $defaultLocationId;
        } elseif (array_key_exists($key, $cIndieFields)) {
            $value['contact_type'] = $contactType;
        }
        _civicrm_api3_deprecated_add_formatted_param($value, $contactFormatted);
    }
    $contactFormatted['contact_type'] = $contactType;
    return _civicrm_api3_deprecated_duplicate_formatted_contact($contactFormatted);
}
Exemplo n.º 21
0
 /**
  * Function to send Acknowledgment and create activity.
  *
  * @param object $form form object.
  * @param array  $params (reference ) an assoc array of name/value pairs.
  * @access public
  *
  * @return None.
  */
 function sendAcknowledgment(&$form, $params)
 {
     //handle Acknowledgment.
     $allPayments = $payments = array();
     //get All Payments status types.
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id');
     //get all paymnets details.
     CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $params['id'], $allPayments, $returnProperties);
     if (!empty($allPayments)) {
         foreach ($allPayments as $payID => $values) {
             $contributionValue = $contributionStatus = array();
             if (isset($values['contribution_id'])) {
                 $contributionParams = array('id' => $values['contribution_id']);
                 $returnProperties = array('contribution_status_id', 'receive_date');
                 CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties);
                 $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus));
             }
             $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values)));
             //get the first valid payment id.
             if (!isset($form->paymentId) && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) {
                 $form->paymentId = $values['id'];
             }
         }
     }
     //end
     //assign pledge fields value to template.
     $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount', 'currency');
     foreach ($pledgeFields as $field) {
         if (CRM_Utils_Array::value($field, $params)) {
             $form->assign($field, $params[$field]);
         }
     }
     //assign all payments details.
     if ($payments) {
         $form->assign('payments', $payments);
     }
     //assign honor fields.
     $honor_block_is_active = FALSE;
     //make sure we have values for it
     if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params['honor_first_name']) && !empty($params['honor_last_name']) || !empty($params['honor_email']))) {
         $honor_block_is_active = TRUE;
         $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
         $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
         $form->assign('honor_type', $honor[$params['honor_type_id']]);
         $form->assign('honor_prefix', $prefix[$params['honor_prefix_id']]);
         $form->assign('honor_first_name', $params['honor_first_name']);
         $form->assign('honor_last_name', $params['honor_last_name']);
         $form->assign('honor_email', $params['honor_email']);
     }
     $form->assign('honor_block_is_active', $honor_block_is_active);
     //handle domain token values
     $domain = CRM_Core_BAO_Domain::getDomain();
     $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
     $domainValues = array();
     foreach ($tokens['domain'] as $token) {
         $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
     }
     $form->assign('domain', $domainValues);
     //handle contact token values.
     $ids = array($params['contact_id']);
     $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id'));
     foreach ($fields as $key => $val) {
         $returnProperties[$val] = TRUE;
     }
     $details = CRM_Utils_Token::getTokenDetails($ids, $returnProperties, TRUE, TRUE, NULL, $tokens, get_class($form));
     $form->assign('contact', $details[0][$params['contact_id']]);
     //handle custom data.
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']);
         $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0));
         $customGroup = array();
         // retrieve custom data
         foreach ($groupTree as $groupID => $group) {
             $customFields = $customValues = array();
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
             //to build array of customgroup & customfields in it
             CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, FALSE, $pledgeParams);
             $customGroup[$group['title']] = $customValues;
         }
         $form->assign('customGroup', $customGroup);
     }
     //handle acknowledgment email stuff.
     list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']);
     //check for online pledge.
     $session = CRM_Core_Session::singleton();
     if (CRM_Utils_Array::value('receipt_from_email', $params)) {
         $userName = CRM_Utils_Array::value('receipt_from_name', $params);
         $userEmail = CRM_Utils_Array::value('receipt_from_email', $params);
     } elseif (CRM_Utils_Array::value('from_email_id', $params)) {
         $receiptFrom = $params['from_email_id'];
     } elseif ($userID = $session->get('userID')) {
         //check for loged in user.
         list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     } else {
         //set the domain values.
         $userName = CRM_Utils_Array::value('name', $domainValues);
         $userEmail = CRM_Utils_Array::value('email', $domainValues);
     }
     if (!isset($receiptFrom)) {
         $receiptFrom = "{$userName} <{$userEmail}>";
     }
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail));
     //check if activity record exist for this pledge
     //Acknowledgment, if exist do not add activity.
     $activityType = 'Pledge Acknowledgment';
     $activity = new CRM_Activity_DAO_Activity();
     $activity->source_record_id = $params['id'];
     $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name');
     $config = CRM_Core_Config::singleton();
     $details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)';
     if (!$activity->find()) {
         $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
         //lets insert assignee record.
         if (CRM_Utils_Array::value('contact_id', $params)) {
             $activityParams['assignee_contact_id'] = $params['contact_id'];
         }
         if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) {
             CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
         }
     }
 }
Exemplo n.º 22
0
 /**
  * get all the fields that belong to the group with the name title
  *
  * @param int      $id           the id of the UF group
  * @param int      $register     are we interested in registration fields
  * @param int      $action       what action are we doing
  * @param int      $visibility   visibility of fields we are interested in
  * @param          $searchable
  * @param boolean  $showall
  * @param string   $restrict     should we restrict based on a specified profile type
  *
  * @return array   the fields that belong to this title
  * @static
  * @access public
  */
 static function getFields($id, $register = false, $action = null, $visibility = null, $searchable = null, $showAll = false, $restrict = null, $skipPermission = false, $ctype = null, $permissionType = CRM_Core_Permission::CREATE)
 {
     if ($restrict) {
         $query = "SELECT g.* from civicrm_uf_group g, civicrm_uf_join j \n                            WHERE g.is_active   = 1\n                              AND g.id          = %1 \n                              AND j.uf_group_id = %1 \n                              AND j.module      = %2\n                              ";
         $params = array(1 => array($id, 'Integer'), 2 => array($restrict, 'String'));
     } else {
         $query = "SELECT g.* from civicrm_uf_group g WHERE g.is_active = 1 AND g.id = %1 ";
         $params = array(1 => array($id, 'Integer'));
     }
     // add permissioning for profiles only if not registration
     if (!$skipPermission) {
         require_once 'CRM/Core/Permission.php';
         $permissionClause = CRM_Core_Permission::ufGroupClause($permissionType, 'g.');
         $query .= " AND {$permissionClause} ";
     }
     $group =& CRM_Core_DAO::executeQuery($query, $params);
     $fields = array();
     if ($group->fetch()) {
         $where = " WHERE uf_group_id = {$group->id}";
         if ($searchable) {
             $where .= " AND is_searchable = 1";
         }
         if (!$showAll) {
             $where .= " AND is_active = 1";
         }
         if ($visibility) {
             $clause = array();
             if ($visibility & self::PUBLIC_VISIBILITY) {
                 $clause[] = 'visibility = "Public Pages"';
             }
             if ($visibility & self::ADMIN_VISIBILITY) {
                 $clause[] = 'visibility = "User and User Admin Only"';
             }
             if ($visibility & self::LISTINGS_VISIBILITY) {
                 $clause[] = 'visibility = "Public Pages and Listings"';
             }
             if (!empty($clause)) {
                 $where .= ' AND ( ' . implode(' OR ', $clause) . ' ) ';
             }
         }
         $query = "SELECT * FROM civicrm_uf_field {$where} ORDER BY weight, field_name";
         $field =& CRM_Core_DAO::executeQuery($query);
         require_once 'CRM/Contact/BAO/Contact.php';
         if (!$showAll) {
             $importableFields =& CRM_Contact_BAO_Contact::importableFields("All");
         } else {
             $importableFields =& CRM_Contact_BAO_Contact::importableFields("All", false, true);
         }
         require_once 'CRM/Core/Component.php';
         $importableFields = array_merge($importableFields, CRM_Core_Component::getQueryFields());
         $importableFields['group']['title'] = ts('Group(s)');
         $importableFields['group']['where'] = null;
         $importableFields['tag']['title'] = ts('Tag(s)');
         $importableFields['tag']['where'] = null;
         $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', 'county', 'phone', 'email', 'im', 'address_name');
         //get location type
         $locationType = array();
         $locationType =& CRM_Core_PseudoConstant::locationType();
         require_once 'CRM/Core/BAO/CustomField.php';
         $customFields = CRM_Core_BAO_CustomField::getFieldsForImport($ctype);
         // hack to add custom data for components
         $components = array("Contribution", "Participant", "Membership");
         foreach ($components as $value) {
             $customFields = array_merge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
         }
         while ($field->fetch()) {
             $name = $title = $locType = $phoneType = '';
             $name = $field->field_name;
             $title = $field->label;
             if ($field->location_type_id) {
                 $name .= "-{$field->location_type_id}";
                 $locType = " ( {$locationType[$field->location_type_id]} ) ";
             } else {
                 if (in_array($field->field_name, $specialFields)) {
                     $name .= '-Primary';
                     $locType = ' ( Primary ) ';
                 }
             }
             if (isset($field->phone_type_id)) {
                 $name .= "-{$field->phone_type_id}";
                 if ($field->phone_type_id != '1') {
                     // this hack is to prevent Phone Phone (work)
                     $phoneType = "-{$field->phone_type_id}";
                 }
             }
             $fields[$name] = array('name' => $name, 'groupTitle' => $group->title, 'groupHelpPre' => $group->help_pre, 'groupHelpPost' => $group->help_post, 'title' => $title, 'where' => CRM_Utils_Array::value('where', $importableFields[$field->field_name]), 'attributes' => CRM_Core_DAO::makeAttribute(CRM_Utils_Array::value($field->field_name, $importableFields)), 'is_required' => $field->is_required, 'is_view' => $field->is_view, 'help_post' => $field->help_post, 'visibility' => $field->visibility, 'in_selector' => $field->in_selector, 'rule' => CRM_Utils_Array::value('rule', $importableFields[$field->field_name]), 'location_type_id' => $field->location_type_id, 'phone_type_id' => isset($field->phone_type_id) ? $field->phone_type_id : NULL, 'group_id' => $group->id, 'add_to_group_id' => $group->add_to_group_id, 'add_captcha' => $group->add_captcha, 'field_type' => $field->field_type, 'field_id' => $field->id);
             //adding custom field property
             if (substr($name, 0, 6) == 'custom') {
                 // if field is not present in customFields, that means the user
                 // DOES NOT HAVE permission to access that field
                 if (array_key_exists($name, $customFields)) {
                     $fields[$name]['is_search_range'] = $customFields[$name]['is_search_range'];
                     // fix for CRM-1994
                     $fields[$name]['options_per_line'] = $customFields[$name]['options_per_line'];
                     $fields[$name]['data_type'] = $customFields[$name]['data_type'];
                     $fields[$name]['html_type'] = $customFields[$name]['html_type'];
                 } else {
                     unset($fields[$name]);
                 }
             }
         }
     } else {
         CRM_Core_Error::fatal(ts('The requested Profile (gid=%1) is disabled OR it is not configured to be used for \'Profile\' listings in its Settings OR there is no Profile with that ID OR you do not have permission to access this profile. Please contact the site administrator if you need assistance.', array(1 => $id)));
     }
     return $fields;
 }
Exemplo n.º 23
0
 /**
  * Test case for importableFields( ) and exportableFields( ).
  */
 public function testFields()
 {
     $allImpFileds = CRM_Contact_BAO_Contact::importableFields('All');
     $allExpFileds = CRM_Contact_BAO_Contact::importableFields('All');
     //Now check all fields
     $this->assertAttributesEquals($allImpFileds, $allExpFileds);
     $individualImpFileds = CRM_Contact_BAO_Contact::importableFields('Individual');
     $individualExpFileds = CRM_Contact_BAO_Contact::importableFields('Individual');
     //Now check Individual fields
     $this->assertAttributesEquals($individualImpFileds, $individualExpFileds);
     $householdImpFileds = CRM_Contact_BAO_Contact::importableFields('Household');
     $householdExpFileds = CRM_Contact_BAO_Contact::importableFields('Household');
     //Now check Household fields
     $this->assertAttributesEquals($householdImpFileds, $householdExpFileds);
     $organizationImpFileds = CRM_Contact_BAO_Contact::importableFields('Organization');
     $organizationExpFileds = CRM_Contact_BAO_Contact::importableFields('Organization');
     //Now check Organization fields
     $this->assertAttributesEquals($organizationImpFileds, $organizationExpFileds);
 }
Exemplo n.º 24
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * @return array array of importable Fields
  * @access public
  */
 function &importableFields($contactType = 'Individual', $status = true, $onlyParticipant = false)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$onlyParticipant) {
             if (!$status) {
                 $fields = array('' => array('title' => ts('- do not import -')));
             } else {
                 $fields = array('' => array('title' => ts('- Participant Fields -')));
             }
         } else {
             $fields = array();
         }
         require_once 'CRM/Core/DAO/Note.php';
         $tmpFields = CRM_Event_DAO_Participant::import();
         $note = array('participant_note' => array('title' => 'Participant Note', 'name' => 'participant_note', 'headerPattern' => '/(participant.)?note$/i'));
         $participantStatus = array('participant_status' => array('title' => 'Participant Status', 'name' => 'participant_status', 'data_type' => CRM_Utils_Type::T_STRING));
         $participantRole = array('participant_role' => array('title' => 'Participant Role', 'name' => 'participant_role', 'data_type' => CRM_Utils_Type::T_STRING));
         $eventType = array('event_type' => array('title' => 'Event Type', 'name' => 'event_type', 'data_type' => CRM_Utils_Type::T_STRING));
         $tmpConatctField = array();
         if (!$onlyParticipant) {
             require_once 'CRM/Contact/BAO/Contact.php';
             $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, null);
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => $contactType, 'level' => 'Strict');
             require_once 'CRM/Dedupe/BAO/Rule.php';
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             if (is_array($fieldsArray)) {
                 foreach ($fieldsArray as $value) {
                     $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                     if (!$status) {
                         $title = $tmpContactField[trim($value)]['title'] . " (match to contact)";
                     } else {
                         $title = $tmpContactField[trim($value)]['title'];
                     }
                     $tmpContactField[trim($value)]['title'] = $title;
                 }
             }
         }
         $tmpContactField['external_identifier'] = CRM_Utils_Array::value('external_identifier', $contactFields);
         $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)";
         $tmpFields['participant_contact_id']['title'] = $tmpFields['participant_contact_id']['title'] . " (match to contact)";
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, $note, $participantStatus, $participantRole, $eventType);
         //$fields = array_merge($fields, $optionFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 25
0
 /**
  * Replace all the org-level tokens in $str
  *
  * @param string $str
  *   The string with tokens to be replaced.
  * @param object $org
  *   Associative array of org properties.
  * @param bool $html
  *   Replace tokens with HTML or plain text.
  *
  * @param bool $escapeSmarty
  *
  * @return string
  *   The processed string
  */
 public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE)
 {
     self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id'));
     $cv = NULL;
     foreach (self::$_tokens['org'] as $token) {
         // print "Getting token value for $token<br/><br/>";
         if ($token == '') {
             continue;
         }
         // If the string doesn't contain this token, skip it.
         if (!self::token_match('org', $token, $str)) {
             continue;
         }
         // Construct value from $token and $contact
         $value = NULL;
         if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) {
             // only generate cv if we need it
             if ($cv === NULL) {
                 $cv = CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']);
             }
             foreach ($cv as $cvFieldID => $value) {
                 if ($cvFieldID == $cfID) {
                     $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value);
                     break;
                 }
             }
         } elseif ($token == 'checksum') {
             $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']);
             $value = "cs={$cs}";
         } elseif ($token == 'address') {
             // Build the location values array
             $loc = array();
             $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name');
             $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address');
             $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city');
             $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province');
             $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code');
             // Construct the address token
             $value = CRM_Utils_Address::format($loc);
             if ($html) {
                 $value = str_replace("\n", '<br />', $value);
             }
         } else {
             $value = CRM_Utils_Array::retrieveValueRecursive($org, $token);
         }
         self::token_replace('org', $token, $value, $str, $escapeSmarty);
     }
     return $str;
 }
Exemplo n.º 26
0
 /**
  * combine all the importable fields from the lower levels object
  *
  * The ordering is important, since currently we do not have a weight
  * scheme. Adding weight is super important
  *
  * @param int     $contactType     contact Type
  * @param boolean $status          status is used to manipulate first title
  * @param boolean $showAll         if true returns all fields (includes disabled fields)
  * @param boolean $isProfile       if its profile mode
  * @param boolean $checkPermission if false, do not include permissioning clause (for custom data)
  *
  * @return array array of importable Fields
  * @access public
  * @static
  */
 static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     $cacheKeyString = "";
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $showAll ? '_1' : '_0';
     $cacheKeyString .= $isProfile ? '_1' : '_0';
     $cacheKeyString .= $checkPermission ? '_1' : '_0';
     $contactType = 'Individual';
     $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
     if (!$fields) {
         $fields = CRM_Appraisals_DAO_AppraisalCycle::import();
         $tmpContactField = $contactFields = array();
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                 $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                 $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                 if (!$status) {
                     $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
                 } else {
                     $title = $tmpContactField[trim($value)]['title'];
                 }
                 $tmpContactField[trim($value)]['title'] = $title;
             }
         }
         $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields);
         if ($extIdentifier) {
             $tmpContactField['external_identifier'] = $extIdentifier;
             $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)';
         }
         $fields = array_merge($fields, $tmpContactField);
         //Sorting fields in alphabetical order(CRM-1507)
         $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
         $fields = CRM_Utils_Array::index(array('name'), $fields);
         CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
     }
     self::$_importableFields[$cacheKeyString] = $fields;
     if (!$isProfile) {
         $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
     }
     return $fields;
 }
Exemplo n.º 27
0
 /**
  * Combine all the importable fields from the lower levels object.
  *
  * @param string $contactType
  * @param bool $status
  * @param bool $onlyParticipant
  * @param bool $checkPermission
  *   Is this a permissioned retrieval?
  *
  * @return array
  *   array of importable Fields
  */
 public static function &importableFields($contactType = 'Individual', $status = TRUE, $onlyParticipant = FALSE, $checkPermission = TRUE)
 {
     if (!self::$_importableFields) {
         if (!$onlyParticipant) {
             if (!$status) {
                 $fields = array('' => array('title' => ts('- do not import -')));
             } else {
                 $fields = array('' => array('title' => ts('- Participant Fields -')));
             }
         } else {
             $fields = array();
         }
         $tmpFields = CRM_Event_DAO_Participant::import();
         $note = array('participant_note' => array('title' => ts('Participant Note'), 'name' => 'participant_note', 'headerPattern' => '/(participant.)?note$/i'));
         // Split status and status id into 2 fields
         // Fixme: it would be better to leave as 1 field and intelligently handle both during import
         $participantStatus = array('participant_status' => array('title' => ts('Participant Status'), 'name' => 'participant_status', 'data_type' => CRM_Utils_Type::T_STRING));
         $tmpFields['participant_status_id']['title'] = ts('Participant Status Id');
         // Split role and role id into 2 fields
         // Fixme: it would be better to leave as 1 field and intelligently handle both during import
         $participantRole = array('participant_role' => array('title' => ts('Participant Role'), 'name' => 'participant_role', 'data_type' => CRM_Utils_Type::T_STRING));
         $tmpFields['participant_role_id']['title'] = ts('Participant Role Id');
         $eventType = array('event_type' => array('title' => ts('Event Type'), 'name' => 'event_type', 'data_type' => CRM_Utils_Type::T_STRING));
         $tmpContactField = $contactFields = array();
         $contactFields = array();
         if (!$onlyParticipant) {
             $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
             // Using new Dedupe rule.
             $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
             $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
             if (is_array($fieldsArray)) {
                 foreach ($fieldsArray as $value) {
                     $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                     $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                     $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                     if (!$status) {
                         $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
                     } else {
                         $title = $tmpContactField[trim($value)]['title'];
                     }
                     $tmpContactField[trim($value)]['title'] = $title;
                 }
             }
         }
         $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields);
         if ($extIdentifier) {
             $tmpContactField['external_identifier'] = $extIdentifier;
             $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)';
         }
         $tmpFields['participant_contact_id']['title'] = $tmpFields['participant_contact_id']['title'] . ' (match to contact)';
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, $note, $participantStatus, $participantRole, $eventType);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant', FALSE, FALSE, FALSE, $checkPermission));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 28
0
 /**
  * @param $showAll
  * @param $profileType
  * @param $contactActivityProfile
  *
  * @return array
  */
 protected static function getImportableFields($showAll, $profileType, $contactActivityProfile)
 {
     if (!$showAll) {
         $importableFields = CRM_Contact_BAO_Contact::importableFields('All', FALSE, FALSE, FALSE, TRUE, TRUE);
     } else {
         $importableFields = CRM_Contact_BAO_Contact::importableFields('All', FALSE, TRUE, FALSE, TRUE, TRUE);
     }
     if ($profileType == 'Activity' || $contactActivityProfile) {
         $componentFields = CRM_Activity_BAO_Activity::getProfileFields();
     } else {
         $componentFields = CRM_Core_Component::getQueryFields();
     }
     $importableFields = array_merge($importableFields, $componentFields);
     $importableFields['group']['title'] = ts('Group(s)');
     $importableFields['group']['where'] = NULL;
     $importableFields['tag']['title'] = ts('Tag(s)');
     $importableFields['tag']['where'] = NULL;
     return $importableFields;
 }
Exemplo n.º 29
0
 /**
  * Combine all the importable fields from the lower levels object.
  *
  * @param string $contactType
  *   Contact type.
  * @param bool $status
  *
  * @return array
  *   array of importable Fields
  */
 public static function &importableFields($contactType = 'Individual', $status = TRUE)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => '- ' . ts('do not import') . ' -'));
         } else {
             $fields = array('' => array('title' => '- ' . ts('Membership Fields') . ' -'));
         }
         $tmpFields = CRM_Member_DAO_Membership::import();
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         $tmpContactField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                 $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                 $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                 if (!$status) {
                     $title = $tmpContactField[trim($value)]['title'] . " " . ts('(match to contact)');
                 } else {
                     $title = $tmpContactField[trim($value)]['title'];
                 }
                 $tmpContactField[trim($value)]['title'] = $title;
             }
         }
         $tmpContactField['external_identifier'] = $contactFields['external_identifier'];
         $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " " . ts('(match to contact)');
         $tmpFields['membership_contact_id']['title'] = $tmpFields['membership_contact_id']['title'] . " " . ts('(match to contact)');
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }
Exemplo n.º 30
0
 /**
  * Combine all the importable fields from the lower levels object
  *
  * @param string  $contactType contact type
  * @param boolean $status      
  *
  * @return array array of importable Fields
  * @access public
  */
 function &importableFields($contactType = 'Individual', $status = true)
 {
     if (!self::$_importableFields) {
         if (!self::$_importableFields) {
             self::$_importableFields = array();
         }
         if (!$status) {
             $fields = array('' => array('title' => '- ' . ts('do not import') . ' -'));
         } else {
             $fields = array('' => array('title' => '- ' . ts('Membership Fields') . ' -'));
         }
         $tmpFields = CRM_Member_DAO_Membership::import();
         require_once 'CRM/Contact/BAO/Contact.php';
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, null);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contactType, 'level' => 'Strict');
         require_once 'CRM/Dedupe/BAO/Rule.php';
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         $tmpContactField = array();
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                 if (!$status) {
                     $title = $tmpContactField[trim($value)]['title'] . " " . ts("(match to contact)");
                 } else {
                     $title = $tmpContactField[trim($value)]['title'];
                 }
                 $tmpContactField[trim($value)]['title'] = $title;
             }
         }
         $tmpContactField['external_identifier'] = $contactFields['external_identifier'];
         $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " " . ts("(match to contact)");
         $tmpFields['membership_contact_id']['title'] = $tmpFields['membership_contact_id']['title'] . " " . ts("(match to contact)");
         $fields = array_merge($fields, $tmpContactField);
         $fields = array_merge($fields, $tmpFields);
         $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership'));
         self::$_importableFields = $fields;
     }
     return self::$_importableFields;
 }