static function &getFields()
 {
     $fields = array();
     $fields = CRM_Case_BAO_Case::exportableFields();
     // add activity related fields
     $fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case'));
     return $fields;
 }
Exemple #2
0
 /**
  * Get fields.
  *
  * @param bool $excludeActivityFields
  *
  * @return array
  */
 public static function &getFields($excludeActivityFields = FALSE)
 {
     $fields = CRM_Case_BAO_Case::exportableFields();
     // add activity related fields
     if (!$excludeActivityFields) {
         $fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case'));
     }
     return $fields;
 }
Exemple #3
0
 static function &getFields()
 {
     require_once 'CRM/Case/BAO/Case.php';
     $fields = array();
     $fields = CRM_Case_BAO_Case::exportableFields();
     // add activity related fields
     require_once 'CRM/Activity/BAO/Activity.php';
     $fields = array_merge($fields, CRM_Activity_BAO_Activity::exportableFields('Case'));
     return $fields;
 }
 /**
  * class constructor which also does all the work
  *
  * @param array   $params
  * @param array   $returnProperties
  * @param array   $fields
  * @param boolean $includeContactIds
  * @param boolean $strict
  * @param boolean $mode - mode the search is operating on
  *
  * @return Object
  * @access public
  */
 function __construct($params = NULL, $returnProperties = NULL, $fields = NULL, $includeContactIds = FALSE, $strict = FALSE, $mode = 1, $skipPermission = FALSE, $searchDescendentGroups = TRUE, $smartGroupCache = TRUE, $displayRelationshipType = NULL, $operator = 'AND')
 {
     // CRM_Core_Error::backtrace( );
     // CRM_Core_Error::debug( 'params', $params );
     // CRM_Core_Error::debug( 'post', $_POST );
     // CRM_Core_Error::debug( 'r', $returnProperties );
     $this->_params =& $params;
     if ($this->_params == NULL) {
         $this->_params = array();
     }
     if (empty($returnProperties)) {
         $this->_returnProperties = self::defaultReturnProperties($mode);
     } else {
         $this->_returnProperties =& $returnProperties;
     }
     $this->_includeContactIds = $includeContactIds;
     $this->_strict = $strict;
     $this->_mode = $mode;
     $this->_skipPermission = $skipPermission;
     $this->_smartGroupCache = $smartGroupCache;
     $this->_displayRelationshipType = $displayRelationshipType;
     $this->setOperator($operator);
     if ($fields) {
         $this->_fields =& $fields;
         $this->_search = FALSE;
         $this->_skipPermission = TRUE;
     } else {
         $this->_fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE, TRUE);
         $fields = CRM_Core_Component::getQueryFields();
         unset($fields['note']);
         $this->_fields = array_merge($this->_fields, $fields);
         // add activity fields
         $fields = CRM_Activity_BAO_Activity::exportableFields();
         $this->_fields = array_merge($this->_fields, $fields);
     }
     // basically do all the work once, and then reuse it
     $this->initialize();
 }
Exemple #5
0
 static function fields()
 {
     $fields = array_merge(CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE), CRM_Core_Component::getQueryFields(), CRM_Contact_BAO_Query_Hook::singleton()->getFields(), CRM_Activity_BAO_Activity::exportableFields());
     return $fields;
 }
Exemple #6
0
 /**
  * Where clause for a single field.
  *
  * @param $values
  * @param $query
  * @return void
  */
 public static function whereClauseSingle(&$values, &$query)
 {
     list($name, $op, $value, $grouping) = $values;
     $fields = CRM_Activity_BAO_Activity::exportableFields();
     $query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
     if ($query->_mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) {
         $query->_skipDeleteClause = TRUE;
     }
     switch ($name) {
         case 'activity_type_id':
         case 'activity_status_id':
         case 'activity_engagement_level':
         case 'activity_subject':
         case 'activity_id':
             $qillName = $name;
             if (in_array($name, array('activity_engagement_level', 'activity_id'))) {
                 $name = $qillName = str_replace('activity_', '', $name);
             }
             if (in_array($name, array('activity_status_id', 'activity_subject'))) {
                 $name = str_replace('activity_', '', $name);
                 $qillName = str_replace('_id', '', $qillName);
             }
             $dataType = !empty($fields[$qillName]['type']) ? CRM_Utils_Type::typeToString($fields[$qillName]['type']) : 'String';
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.{$name}", $op, $value, $dataType);
             list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
             $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
             break;
         case 'activity_type':
         case 'activity_status':
             $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("{$name}.label", $op, $value, 'String');
             list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
             $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
             $query->_tables[$name] = $query->_whereTables[$name] = 1;
             break;
         case 'activity_survey_id':
             if (!$value) {
                 break;
             }
             $value = CRM_Utils_Type::escape($value, 'Integer');
             $query->_where[$grouping][] = " civicrm_activity.source_record_id = {$value}";
             $query->_qill[$grouping][] = ts('Survey') . ' - ' . CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $value, 'title');
             break;
         case 'activity_role':
             CRM_Contact_BAO_Query::$_activityRole = $values[2];
             $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
             $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
             $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
             $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
             if ($values[2]) {
                 $query->_tables['civicrm_activity_contact'] = $query->_whereTables['civicrm_activity_contact'] = 1;
                 if ($values[2] == 1) {
                     $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = {$sourceID}";
                     $query->_qill[$grouping][] = ts('Activity created by');
                 } elseif ($values[2] == 2) {
                     $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = {$assigneeID}";
                     $query->_qill[$grouping][] = ts('Activity assigned to');
                 } elseif ($values[2] == 3) {
                     $query->_where[$grouping][] = " civicrm_activity_contact.record_type_id = {$targetID}";
                     $query->_qill[$grouping][] = ts('Activity targeted to');
                 }
             }
             break;
         case 'activity_test':
             // We don't want to include all tests for sql OR CRM-7827
             if (!$value || $query->getOperator() != 'OR') {
                 $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_activity.is_test", $op, $value, "Boolean");
                 if ($value) {
                     $query->_qill[$grouping][] = ts('Activity is a Test');
                 }
             }
             break;
         case 'activity_date':
         case 'activity_date_low':
         case 'activity_date_high':
             $query->dateQueryBuilder($values, 'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date'));
             break;
         case 'activity_taglist':
             $taglist = $value;
             $value = array();
             foreach ($taglist as $val) {
                 if ($val) {
                     $val = explode(',', $val);
                     foreach ($val as $tId) {
                         if (is_numeric($tId)) {
                             $value[$tId] = 1;
                         }
                     }
                 }
             }
         case 'activity_tags':
             $value = array_keys($value);
             $activityTags = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
             $names = array();
             if (is_array($value)) {
                 foreach ($value as $k => $v) {
                     $names[] = $activityTags[$v];
                 }
             }
             $query->_where[$grouping][] = "civicrm_activity_tag.tag_id IN (" . implode(",", $value) . ")";
             $query->_qill[$grouping][] = ts('Activity Tag %1', array(1 => $op)) . ' ' . implode(' ' . ts('OR') . ' ', $names);
             $query->_tables['civicrm_activity_tag'] = $query->_whereTables['civicrm_activity_tag'] = 1;
             break;
         case 'activity_campaign_id':
             $campParams = array('op' => $op, 'campaign' => $value, 'grouping' => $grouping, 'tableName' => 'civicrm_activity');
             CRM_Campaign_BAO_Query::componentSearchClause($campParams, $query);
             break;
         case 'activity_result':
             if (is_array($value)) {
                 $safe = NULL;
                 while (list(, $k) = each($value)) {
                     $safe[] = "'" . CRM_Utils_Type::escape($k, 'String') . "'";
                 }
                 $query->_where[$grouping][] = "civicrm_activity.result IN (" . implode(',', $safe) . ")";
                 $query->_qill[$grouping][] = ts("Activity Result - %1", array(1 => implode(' or ', $safe)));
             }
             break;
         case 'parent_id':
             if ($value == 1) {
                 $query->_where[$grouping][] = "parent_id.parent_id IS NOT NULL";
                 $query->_qill[$grouping][] = ts('Activities which have Followup Activities');
             } elseif ($value == 2) {
                 $query->_where[$grouping][] = "parent_id.parent_id IS NULL";
                 $query->_qill[$grouping][] = ts('Activities without Followup Activities');
             }
             break;
         case 'followup_parent_id':
             if ($value == 1) {
                 $query->_where[$grouping][] = "civicrm_activity.parent_id IS NOT NULL";
                 $query->_qill[$grouping][] = ts('Activities which are Followup Activities');
             } elseif ($value == 2) {
                 $query->_where[$grouping][] = "civicrm_activity.parent_id IS NULL";
                 $query->_qill[$grouping][] = ts('Activities which are not Followup Activities');
             }
             break;
     }
 }
Exemple #7
0
 /**
  * Class constructor which also does all the work.
  *
  * @param array $params
  * @param array $returnProperties
  * @param array $fields
  * @param bool $includeContactIds
  * @param bool $strict
  * @param bool|int $mode - mode the search is operating on
  *
  * @param bool $skipPermission
  * @param bool $searchDescendentGroups
  * @param bool $smartGroupCache
  * @param null $displayRelationshipType
  * @param string $operator
  *
  * @return \CRM_Contact_BAO_Query
  */
 public function __construct($params = NULL, $returnProperties = NULL, $fields = NULL, $includeContactIds = FALSE, $strict = FALSE, $mode = 1, $skipPermission = FALSE, $searchDescendentGroups = TRUE, $smartGroupCache = TRUE, $displayRelationshipType = NULL, $operator = 'AND')
 {
     $this->_params =& $params;
     if ($this->_params == NULL) {
         $this->_params = array();
     }
     if (empty($returnProperties)) {
         $this->_returnProperties = self::defaultReturnProperties($mode);
     } else {
         $this->_returnProperties =& $returnProperties;
     }
     $this->_includeContactIds = $includeContactIds;
     $this->_strict = $strict;
     $this->_mode = $mode;
     $this->_skipPermission = $skipPermission;
     $this->_smartGroupCache = $smartGroupCache;
     $this->_displayRelationshipType = $displayRelationshipType;
     $this->setOperator($operator);
     if ($fields) {
         $this->_fields =& $fields;
         $this->_search = FALSE;
         $this->_skipPermission = TRUE;
     } else {
         $this->_fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE, TRUE, FALSE, !$skipPermission);
         $fields = CRM_Core_Component::getQueryFields(!$this->_skipPermission);
         unset($fields['note']);
         $this->_fields = array_merge($this->_fields, $fields);
         // add activity fields
         $fields = CRM_Activity_BAO_Activity::exportableFields();
         $this->_fields = array_merge($this->_fields, $fields);
         // add any fields provided by hook implementers
         $extFields = CRM_Contact_BAO_Query_Hook::singleton()->getFields();
         $this->_fields = array_merge($this->_fields, $extFields);
     }
     // basically do all the work once, and then reuse it
     $this->initialize();
 }
Exemple #8
0
 /**
  * Build the mapping form.
  *
  * @param CRM_Core_Form $form
  * @param string $mappingType
  *   (Export/Import/Search Builder).
  * @param int $mappingId
  * @param int $columnNo
  * @param int $blockCount
  *   (no of blocks shown).
  * @param NULL $exportMode
  *
  * @return void
  */
 public static function buildMappingForm(&$form, $mappingType = 'Export', $mappingId = NULL, $columnNo, $blockCount = 3, $exportMode = NULL)
 {
     if ($mappingType == 'Export') {
         $name = "Map";
         $columnCount = array('1' => $columnNo);
     } elseif ($mappingType == 'Search Builder') {
         $name = "Builder";
         $columnCount = $columnNo;
     }
     //get the saved mapping details
     if ($mappingType == 'Export') {
         $form->applyFilter('saveMappingName', 'trim');
         //to save the current mappings
         if (!isset($mappingId)) {
             $saveDetailsName = ts('Save this field mapping');
             $form->add('text', 'saveMappingName', ts('Name'));
             $form->add('text', 'saveMappingDesc', ts('Description'));
         } else {
             $form->assign('loadedMapping', $mappingId);
             $params = array('id' => $mappingId);
             $temp = array();
             $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp);
             $form->assign('savedName', $mappingDetails->name);
             $form->add('hidden', 'mappingId', $mappingId);
             $form->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL);
             $saveDetailsName = ts('Save as a new field mapping');
             $form->add('text', 'saveMappingName', ts('Name'));
             $form->add('text', 'saveMappingDesc', ts('Description'));
         }
         $form->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)"));
         $form->addFormRule(array('CRM_Export_Form_Map', 'formRule'), $form->get('mappingTypeId'));
     } elseif ($mappingType == 'Search Builder') {
         $form->addElement('submit', 'addBlock', ts('Also include contacts where'), array('class' => 'submit-link'));
     }
     $defaults = array();
     $hasLocationTypes = array();
     $hasRelationTypes = array();
     $fields = array();
     if ($mappingType == 'Export') {
         $required = TRUE;
     } elseif ($mappingType == 'Search Builder') {
         $required = FALSE;
     }
     $contactType = array('Individual', 'Household', 'Organization');
     foreach ($contactType as $value) {
         $contactFields = CRM_Contact_BAO_Contact::exportableFields($value, FALSE, $required);
         $contactFields = array_merge($contactFields, CRM_Contact_BAO_Query_Hook::singleton()->getFields());
         // exclude the address options disabled in the Address Settings
         $fields[$value] = CRM_Core_BAO_Address::validateAddressOptions($contactFields);
         ksort($fields[$value]);
         if ($mappingType == 'Export') {
             $relationships = array();
             $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $value);
             asort($relationshipTypes);
             foreach ($relationshipTypes as $key => $var) {
                 list($type) = explode('_', $key);
                 $relationships[$key]['title'] = $var;
                 $relationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
                 $relationships[$key]['export'] = TRUE;
                 $relationships[$key]['relationship_type_id'] = $type;
                 $relationships[$key]['related'] = TRUE;
                 $relationships[$key]['hasRelationType'] = 1;
             }
             if (!empty($relationships)) {
                 $fields[$value] = array_merge($fields[$value], array('related' => array('title' => ts('- related contact info -'))), $relationships);
             }
         }
     }
     //get the current employer for mapping.
     if ($required) {
         $fields['Individual']['current_employer']['title'] = ts('Current Employer');
     }
     // add component fields
     $compArray = array();
     //we need to unset groups, tags, notes for component export
     if ($exportMode != CRM_Export_Form_Select::CONTACT_EXPORT) {
         foreach (array('groups', 'tags', 'notes') as $value) {
             unset($fields['Individual'][$value]);
             unset($fields['Household'][$value]);
             unset($fields['Organization'][$value]);
         }
     }
     if ($mappingType == 'Search Builder') {
         //build the common contact fields array.
         $fields['Contact'] = array();
         foreach ($fields['Individual'] as $key => $value) {
             if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) {
                 $fields['Contact'][$key] = $value;
                 unset($fields['Organization'][$key], $fields['Household'][$key], $fields['Individual'][$key]);
             }
         }
         if (array_key_exists('note', $fields['Contact'])) {
             $noteTitle = $fields['Contact']['note']['title'];
             $fields['Contact']['note']['title'] = $noteTitle . ': ' . ts('Body and Subject');
             $fields['Contact']['note_body'] = array('title' => $noteTitle . ': ' . ts('Body Only'), 'name' => 'note_body');
             $fields['Contact']['note_subject'] = array('title' => $noteTitle . ': ' . ts('Subject Only'), 'name' => 'note_subject');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
         if (CRM_Core_Permission::access('CiviContribute')) {
             $fields['Contribution'] = CRM_Contribute_BAO_Contribution::exportableFields();
             foreach (array('contribution_contact_id', 'contribution_soft_credit_name', 'contribution_soft_credit_amount', 'contribution_soft_credit_type', 'contribution_soft_credit_contribution_id') as $element) {
                 unset($fields['Contribution'][$element]);
             }
             $compArray['Contribution'] = ts('Contribution');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
         if (CRM_Core_Permission::access('CiviEvent')) {
             $fields['Participant'] = CRM_Event_BAO_Participant::exportableFields();
             //get the component payment fields
             if ($exportMode == CRM_Export_Form_Select::EVENT_EXPORT) {
                 $componentPaymentFields = array();
                 foreach (CRM_Export_BAO_Export::componentPaymentFields() as $payField => $payTitle) {
                     $componentPaymentFields[$payField] = array('title' => $payTitle);
                 }
                 $fields['Participant'] = array_merge($fields['Participant'], $componentPaymentFields);
             }
             $compArray['Participant'] = ts('Participant');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::MEMBER_EXPORT) {
         if (CRM_Core_Permission::access('CiviMember')) {
             $fields['Membership'] = CRM_Member_BAO_Membership::getMembershipFields($exportMode);
             unset($fields['Membership']['membership_contact_id']);
             $compArray['Membership'] = ts('Membership');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::PLEDGE_EXPORT) {
         if (CRM_Core_Permission::access('CiviPledge')) {
             $fields['Pledge'] = CRM_Pledge_BAO_Pledge::exportableFields();
             unset($fields['Pledge']['pledge_contact_id']);
             $compArray['Pledge'] = ts('Pledge');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::CASE_EXPORT) {
         if (CRM_Core_Permission::access('CiviCase')) {
             $fields['Case'] = CRM_Case_BAO_Case::exportableFields();
             $compArray['Case'] = ts('Case');
             $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Case');
             $compArray['Activity'] = ts('Case Activity');
             unset($fields['Case']['case_contact_id']);
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::GRANT_EXPORT) {
         if (CRM_Core_Permission::access('CiviGrant')) {
             $fields['Grant'] = CRM_Grant_BAO_Grant::exportableFields();
             unset($fields['Grant']['grant_contact_id']);
             if ($mappingType == 'Search Builder') {
                 unset($fields['Grant']['grant_type_id']);
             }
             $compArray['Grant'] = ts('Grant');
         }
     }
     if ($mappingType == 'Search Builder' || $exportMode == CRM_Export_Form_Select::ACTIVITY_EXPORT) {
         $fields['Activity'] = CRM_Activity_BAO_Activity::exportableFields('Activity');
         $compArray['Activity'] = ts('Activity');
     }
     //Contact Sub Type For export
     $contactSubTypes = array();
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         //adding subtype specific relationships CRM-5256
         $csRelationships = array();
         if ($mappingType == 'Export') {
             $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
             foreach ($subTypeRelationshipTypes as $key => $var) {
                 if (!array_key_exists($key, $fields[$val['parent']])) {
                     list($type) = explode('_', $key);
                     $csRelationships[$key]['title'] = $var;
                     $csRelationships[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/';
                     $csRelationships[$key]['export'] = TRUE;
                     $csRelationships[$key]['relationship_type_id'] = $type;
                     $csRelationships[$key]['related'] = TRUE;
                     $csRelationships[$key]['hasRelationType'] = 1;
                 }
             }
         }
         $fields[$subType] = $fields[$val['parent']] + $csRelationships;
         //custom fields for sub type
         $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($subType);
         $fields[$subType] += $subTypeFields;
         if (!empty($subTypeFields) || !empty($csRelationships)) {
             $contactSubTypes[$subType] = $val['label'];
         }
     }
     unset($subTypes);
     foreach ($fields as $key => $value) {
         foreach ($value as $key1 => $value1) {
             //CRM-2676, replacing the conflict for same custom field name from different custom group.
             $customGroupName = self::getCustomGroupName($key1);
             if ($customGroupName) {
                 $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $customGroupName . ': ' . $value1['title'];
             } else {
                 $relatedMapperFields[$key][$key1] = $mapperFields[$key][$key1] = $value1['title'];
             }
             if (isset($value1['hasLocationType'])) {
                 $hasLocationTypes[$key][$key1] = $value1['hasLocationType'];
             }
             if (isset($value1['hasRelationType'])) {
                 $hasRelationTypes[$key][$key1] = $value1['hasRelationType'];
                 unset($relatedMapperFields[$key][$key1]);
             }
         }
         if (array_key_exists('related', $relatedMapperFields[$key])) {
             unset($relatedMapperFields[$key]['related']);
         }
     }
     $mapperKeys = array_keys($mapperFields);
     $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
     $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
     // FIXME: dirty hack to make the default option show up first.  This
     // avoids a mozilla browser bug with defaults on dynamically constructed
     // selector widgets.
     if ($defaultLocationType) {
         $defaultLocation = $locationTypes[$defaultLocationType->id];
         unset($locationTypes[$defaultLocationType->id]);
         $locationTypes = array($defaultLocationType->id => $defaultLocation) + $locationTypes;
     }
     $locationTypes = array(' ' => ts('Primary')) + $locationTypes;
     // since we need a hierarchical list to display contact types & subtypes,
     // this is what we going to display in first selector
     $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE);
     if ($mappingType == 'Search Builder') {
         $contactTypes = array('Contact' => ts('Contacts')) + $contactTypes;
     }
     $sel1 = array('' => ts('- select record type -')) + $contactTypes + $compArray;
     foreach ($sel1 as $key => $sel) {
         if ($key) {
             // sort everything BUT the contactType which is sorted seperately by
             // an initial commit of CRM-13278 (check ksort above)
             if (!in_array($key, $contactType)) {
                 asort($mapperFields[$key]);
             }
             $sel2[$key] = array('' => ts('- select field -')) + $mapperFields[$key];
         }
     }
     $sel3[''] = NULL;
     $sel5[''] = NULL;
     $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
     $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
     asort($phoneTypes);
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($locationTypes as $key => $value) {
                 if (trim($key) != '') {
                     $sel4[$k]['phone'][$key] =& $phoneTypes;
                     $sel4[$k]['im'][$key] =& $imProviders;
                 }
             }
         }
     }
     foreach ($sel1 as $k => $sel) {
         if ($k) {
             foreach ($mapperFields[$k] as $key => $value) {
                 if (isset($hasLocationTypes[$k][$key])) {
                     $sel3[$k][$key] = $locationTypes;
                 } else {
                     $sel3[$key] = NULL;
                 }
             }
         }
     }
     // Array for core fields and relationship custom data
     $relationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
     if ($mappingType == 'Export') {
         foreach ($sel1 as $k => $sel) {
             if ($k) {
                 foreach ($mapperFields[$k] as $field => $dontCare) {
                     if (isset($hasRelationTypes[$k][$field])) {
                         list($id, $first, $second) = explode('_', $field);
                         // FIX ME: For now let's not expose custom data related to relationship
                         $relationshipCustomFields = array();
                         //$relationshipCustomFields    = self::getRelationTypeCustomGroupData( $id );
                         //asort($relationshipCustomFields);
                         $relationshipType = new CRM_Contact_BAO_RelationshipType();
                         $relationshipType->id = $id;
                         if ($relationshipType->find(TRUE)) {
                             $direction = "contact_sub_type_{$second}";
                             if (isset($relationshipType->{$direction})) {
                                 $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$direction}], (array) $relationshipCustomFields);
                             } else {
                                 $target_type = 'contact_type_' . $second;
                                 $relatedFields = array_merge((array) $relatedMapperFields[$relationshipType->{$target_type}], (array) $relationshipCustomFields);
                             }
                         }
                         $relationshipType->free();
                         asort($relatedFields);
                         $sel5[$k][$field] = $relatedFields;
                     }
                 }
             }
         }
         //Location Type for relationship fields
         foreach ($sel5 as $k => $v) {
             if ($v) {
                 foreach ($v as $rel => $fields) {
                     foreach ($fields as $field => $fieldLabel) {
                         if (isset($hasLocationTypes[$k][$field])) {
                             $sel6[$k][$rel][$field] = $locationTypes;
                         }
                     }
                 }
             }
         }
         //PhoneTypes for  relationship fields
         $sel7[''] = NULL;
         foreach ($sel6 as $k => $rel) {
             if ($k) {
                 foreach ($rel as $phonekey => $phonevalue) {
                     foreach ($locationTypes as $locType => $loc) {
                         if (trim($locType) != '') {
                             $sel7[$k][$phonekey]['phone'][$locType] =& $phoneTypes;
                             $sel7[$k][$phonekey]['im'][$locType] =& $imProviders;
                         }
                     }
                 }
             }
         }
     }
     //special fields that have location, hack for primary location
     $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'phone', 'email', 'im');
     if (isset($mappingId)) {
         $colCnt = 0;
         list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue) = CRM_Core_BAO_Mapping::getMappingFields($mappingId);
         $blkCnt = count($mappingName);
         if ($blkCnt >= $blockCount) {
             $blockCount = $blkCnt + 1;
         }
         for ($x = 1; $x < $blockCount; $x++) {
             if (isset($mappingName[$x])) {
                 $colCnt = count($mappingName[$x]);
                 if ($colCnt >= $columnCount[$x]) {
                     $columnCount[$x] = $colCnt;
                 }
             }
         }
     }
     $form->_blockCount = $blockCount;
     $form->_columnCount = $columnCount;
     $form->set('blockCount', $form->_blockCount);
     $form->set('columnCount', $form->_columnCount);
     $defaults = $noneArray = $nullArray = array();
     //used to warn for mismatch column count or mismatch mapping
     $warning = 0;
     for ($x = 1; $x < $blockCount; $x++) {
         for ($i = 0; $i < $columnCount[$x]; $i++) {
             $sel =& $form->addElement('hierselect', "mapper[{$x}][{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL);
             $jsSet = FALSE;
             if (isset($mappingId)) {
                 $locationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0;
                 if (isset($mappingName[$x][$i])) {
                     if (is_array($mapperFields[$mappingContactType[$x][$i]])) {
                         if (isset($mappingRelation[$x][$i])) {
                             $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$x][$i]));
                             $relLocationId = isset($mappingLocation[$x][$i]) ? $mappingLocation[$x][$i] : 0;
                             if (!$relLocationId && in_array($mappingName[$x][$i], $specialFields)) {
                                 $relLocationId = " ";
                             }
                             $relPhoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL;
                             $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingRelation[$x][$i], $locationId, $phoneType, $mappingName[$x][$i], $relLocationId, $relPhoneType);
                             if (!$locationId) {
                                 $noneArray[] = array($x, $i, 2);
                             }
                             if (!$phoneType && !$imProvider) {
                                 $noneArray[] = array($x, $i, 3);
                             }
                             if (!$mappingName[$x][$i]) {
                                 $noneArray[] = array($x, $i, 4);
                             }
                             if (!$relLocationId) {
                                 $noneArray[] = array($x, $i, 5);
                             }
                             if (!$relPhoneType) {
                                 $noneArray[] = array($x, $i, 6);
                             }
                             $noneArray[] = array($x, $i, 2);
                         } else {
                             $phoneType = isset($mappingPhoneType[$x][$i]) ? $mappingPhoneType[$x][$i] : NULL;
                             $imProvider = isset($mappingImProvider[$x][$i]) ? $mappingImProvider[$x][$i] : NULL;
                             if (!$locationId && in_array($mappingName[$x][$i], $specialFields)) {
                                 $locationId = " ";
                             }
                             $defaults["mapper[{$x}][{$i}]"] = array($mappingContactType[$x][$i], $mappingName[$x][$i], $locationId, $phoneType);
                             if (!$mappingName[$x][$i]) {
                                 $noneArray[] = array($x, $i, 1);
                             }
                             if (!$locationId) {
                                 $noneArray[] = array($x, $i, 2);
                             }
                             if (!$phoneType && !$imProvider) {
                                 $noneArray[] = array($x, $i, 3);
                             }
                             $noneArray[] = array($x, $i, 4);
                             $noneArray[] = array($x, $i, 5);
                             $noneArray[] = array($x, $i, 6);
                         }
                         $jsSet = TRUE;
                         if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingOperator))) {
                             $defaults["operator[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingOperator[$x]);
                         }
                         if (CRM_Utils_Array::value($i, CRM_Utils_Array::value($x, $mappingValue))) {
                             $defaults["value[{$x}][{$i}]"] = CRM_Utils_Array::value($i, $mappingValue[$x]);
                         }
                     }
                 }
             }
             //Fix for Search Builder
             if ($mappingType == 'Export') {
                 $j = 7;
             } else {
                 $j = 4;
             }
             $formValues = $form->exportValues();
             if (!$jsSet) {
                 if (empty($formValues)) {
                     // Incremented length for third select box(relationship type)
                     for ($k = 1; $k < $j; $k++) {
                         $noneArray[] = array($x, $i, $k);
                     }
                 } else {
                     if (!empty($formValues['mapper'][$x])) {
                         foreach ($formValues['mapper'][$x] as $value) {
                             for ($k = 1; $k < $j; $k++) {
                                 if (!isset($formValues['mapper'][$x][$i][$k]) || !$formValues['mapper'][$x][$i][$k]) {
                                     $noneArray[] = array($x, $i, $k);
                                 } else {
                                     $nullArray[] = array($x, $i, $k);
                                 }
                             }
                         }
                     } else {
                         for ($k = 1; $k < $j; $k++) {
                             $noneArray[] = array($x, $i, $k);
                         }
                     }
                 }
             }
             //Fix for Search Builder
             if ($mappingType == 'Export') {
                 if (!isset($mappingId) || $i >= count(reset($mappingName))) {
                     if (isset($formValues['mapper']) && isset($formValues['mapper'][$x][$i][1]) && array_key_exists($formValues['mapper'][$x][$i][1], $relationshipTypes)) {
                         $sel->setOptions(array($sel1, $sel2, $sel5, $sel6, $sel7, $sel3, $sel4));
                     } else {
                         $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7));
                     }
                 } else {
                     $sel->setOptions(array($sel1, $sel2, $sel3, $sel4, $sel5, $sel6, $sel7));
                 }
             } else {
                 $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
             }
             if ($mappingType == 'Search Builder') {
                 //CRM -2292, restricted array set
                 $operatorArray = array('' => ts('-operator-')) + CRM_Core_SelectValues::getSearchBuilderOperators();
                 $form->add('select', "operator[{$x}][{$i}]", '', $operatorArray);
                 $form->add('text', "value[{$x}][{$i}]", '');
             }
         }
         //end of columnCnt for
         if ($mappingType == 'Search Builder') {
             $title = ts('Another search field');
         } else {
             $title = ts('Select more fields');
         }
         $form->addElement('submit', "addMore[{$x}]", $title, array('class' => 'submit-link'));
     }
     //end of block for
     $js = "<script type='text/javascript'>\n";
     $formName = "document.{$name}";
     if (!empty($nullArray)) {
         $js .= "var nullArray = [";
         $elements = array();
         $seen = array();
         foreach ($nullArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<nullArray.length;i++) {\n                    if ( {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'] ) {\n                        {$formName}['mapper['+nullArray[i][0]+']['+nullArray[i][1]+']['+nullArray[i][2]+']'].style.display = '';\n                    }\n                }\n";
     }
     if (!empty($noneArray)) {
         $js .= "var noneArray = [";
         $elements = array();
         $seen = array();
         foreach ($noneArray as $element) {
             $key = "{$element[0]}, {$element[1]}, {$element[2]}";
             if (!isset($seen[$key])) {
                 $elements[] = "[{$key}]";
                 $seen[$key] = 1;
             }
         }
         $js .= implode(', ', $elements);
         $js .= "]";
         $js .= "\n                for (var i=0;i<noneArray.length;i++) {\n                    if ( {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'] ) {\n  {$formName}['mapper['+noneArray[i][0]+']['+noneArray[i][1]+']['+noneArray[i][2]+']'].style.display = 'none';\n                    }\n                }\n";
     }
     $js .= "</script>\n";
     $form->assign('initHideBoxes', $js);
     $form->assign('columnCount', $columnCount);
     $form->assign('blockCount', $blockCount);
     $form->setDefaults($defaults);
     $form->setDefaultAction('refresh');
 }
Exemple #9
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);
     }
 }
 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  *
  * @return array list of errors to be posted back to the form
  * @static
  * @access public
  */
 static function formRule($values)
 {
     if (CRM_Utils_Array::value('addMore', $values) || CRM_Utils_Array::value('addBlock', $values)) {
         return TRUE;
     }
     $fields = array();
     $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE);
     $compomentFields = CRM_Core_Component::getQueryFields();
     $activityFields = CRM_Activity_BAO_Activity::exportableFields();
     $compomentFields = array_merge($compomentFields, $activityFields);
     $fields = array_merge($fields, $compomentFields);
     $fld = array();
     $fld = CRM_Core_BAO_Mapping::formattedFields($values, TRUE);
     $errorMsg = array();
     foreach ($fld as $k => $v) {
         if (!$v[1]) {
             $errorMsg["operator[{$v['3']}][{$v['4']}]"] = ts("Please enter the operator.");
         } else {
             // CRM-10338
             $v[2] = self::checkArrayKeyEmpty($v[2]);
             if (in_array($v[1], array('IS NULL', 'IS NOT NULL')) && !empty($v[2])) {
                 $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please clear your value if you want to use %1 operator.', array(1 => $v[1]));
             } elseif (($v[0] == 'group' || $v[0] == 'tag') && !empty($v[2])) {
                 $grpId = array_keys($v[2]);
                 if (!key($v[2])) {
                     $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                 }
                 if (count($grpId) > 1) {
                     if ($v[1] != 'IN' && $v[1] != 'NOT IN') {
                         $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the valid value.");
                     }
                     foreach ($grpId as $val) {
                         $error = CRM_Utils_Type::validate($val, 'Integer', FALSE);
                         if ($error != $val) {
                             $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
                             break;
                         }
                     }
                 } else {
                     $error = CRM_Utils_Type::validate($grpId[0], 'Integer', FALSE);
                     if ($error != $grpId[0]) {
                         $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please enter valid %1 id.', array(1 => $v[0]));
                     }
                 }
             } elseif (substr($v[0], 0, 7) === 'do_not_' or substr($v[0], 0, 3) === 'is_') {
                 if (isset($v[2])) {
                     $v2 = array($v[2]);
                     if (!isset($v[2])) {
                         $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                     }
                     $error = CRM_Utils_Type::validate($v2[0], 'Integer', FALSE);
                     if ($error != $v2[0]) {
                         $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
                     }
                 } else {
                     $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                 }
             } elseif ($v[0] === 'sort_name' || $v[0] === 'display_name') {
                 $v2 = trim($v[2]);
                 if (empty($v2)) {
                     $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                 }
             } else {
                 if (substr($v[0], 0, 7) == 'custom_') {
                     $type = $fields[$v[0]]['data_type'];
                     // hack to handle custom data of type state and country
                     if (in_array($type, array('Country', 'StateProvince'))) {
                         $type = "Integer";
                     }
                 } else {
                     $fldName = $v[0];
                     // FIXME: no idea at this point what to do with this,
                     // FIXME: but definitely needs fixing.
                     if (substr($v[0], 0, 13) == 'contribution_') {
                         $fldName = substr($v[0], 13);
                     }
                     $fldValue = CRM_Utils_Array::value($fldName, $fields);
                     $fldType = CRM_Utils_Array::value('type', $fldValue);
                     $type = CRM_Utils_Type::typeToString($fldType);
                     // Check Empty values for Integer Or Boolean Or Date type For operators other than IS NULL and IS NOT NULL.
                     if (!in_array($v[1], array('IS NULL', 'IS NOT NULL'))) {
                         if (($type == 'Int' || $type == 'Boolean') && !trim($v[2]) && $v[2] != '0') {
                             $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                         } elseif ($type == 'Date' && !trim($v[2])) {
                             $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the value.");
                         }
                     }
                 }
                 if ($type && empty($errorMsg)) {
                     // check for valid format while using IN Operator
                     if ($v[1] == 'IN') {
                         $inVal = trim($v[2]);
                         //checking for format to avoid db errors
                         if ($type == 'Int') {
                             if (!preg_match('/^[(]([A-Za-z0-9\\,]+)[)]$/', $inVal)) {
                                 $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter correct Data ( in valid format ).");
                             }
                         } else {
                             if (!preg_match('/^[(]([A-Za-z0-9åäöÅÄÖüÜœŒæÆøØ\\,\\s]+)[)]$/', $inVal)) {
                                 $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter correct Data ( in valid format ).");
                             }
                         }
                         // Validate each value in parenthesis to avoid db errors
                         if (empty($errorMsg)) {
                             $parenValues = array();
                             $parenValues = explode(',', trim($inVal, "(..)"));
                             foreach ($parenValues as $val) {
                                 $val = trim($val);
                                 if (!$val && $val != '0') {
                                     $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter the values correctly.");
                                 }
                                 if (empty($errorMsg)) {
                                     $error = CRM_Utils_Type::validate($val, $type, FALSE);
                                     if ($error != $val) {
                                         $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
                                     }
                                 }
                             }
                         }
                     } elseif (trim($v[2])) {
                         //else check value for rest of the Operators
                         $error = CRM_Utils_Type::validate($v[2], $type, FALSE);
                         if ($error != $v[2]) {
                             $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts("Please enter valid value.");
                         }
                     }
                 }
             }
         }
     }
     if (!empty($errorMsg)) {
         return $errorMsg;
     }
     return TRUE;
 }
Exemple #11
0
 /**
  * class constructor which also does all the work
  *
  * @param array   $params
  * @param array   $returnProperties
  * @param array   $fields
  * @param boolean $includeContactIds
  * @param boolean $strict
  * @param boolean $mode - mode the search is operating on
  *
  * @return Object
  * @access public
  */
 function __construct($params = null, $returnProperties = null, $fields = null, $includeContactIds = false, $strict = false, $mode = 1, $skipPermission = false, $searchDescendentGroups = true, $smartGroupCache = true)
 {
     require_once 'CRM/Contact/BAO/Contact.php';
     // CRM_Core_Error::backtrace( );
     // CRM_Core_Error::debug_var( 'params', $params );
     // CRM_Core_Error::debug( 'post', $_POST );
     // CRM_Core_Error::debug( 'r', $returnProperties );
     $this->_params =& $params;
     if ($this->_params == null) {
         $this->_params = array();
     }
     if (empty($returnProperties)) {
         $this->_returnProperties =& self::defaultReturnProperties($mode);
     } else {
         $this->_returnProperties =& $returnProperties;
     }
     $this->_includeContactIds = $includeContactIds;
     $this->_strict = $strict;
     $this->_mode = $mode;
     $this->_skipPermission = $skipPermission;
     $this->_smartGroupCache = $smartGroupCache;
     if ($fields) {
         $this->_fields =& $fields;
         $this->_search = false;
         $this->_skipPermission = true;
     } else {
         require_once 'CRM/Contact/BAO/Contact.php';
         $this->_fields = CRM_Contact_BAO_Contact::exportableFields('All', false, true);
         require_once 'CRM/Core/Component.php';
         $fields =& CRM_Core_Component::getQueryFields();
         unset($fields['note']);
         $this->_fields = array_merge($this->_fields, $fields);
         // add activity fields
         require_once 'CRM/Activity/BAO/Activity.php';
         $fields = CRM_Activity_BAO_Activity::exportableFields();
         $this->_fields = array_merge($this->_fields, $fields);
     }
     // basically do all the work once, and then reuse it
     $this->initialize();
     // CRM_Core_Error::debug( $this );
 }
Exemple #12
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'));
     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;
         }
     }
     //group selected and unwanted fields list
     require_once 'CRM/Core/BAO/UFGroup.php';
     $groupFieldList = array_merge(CRM_Core_BAO_UFGroup::getFields($this->_gid, false, null, null, null, true, null, true), array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'));
     //unset selected fields
     foreach ($groupFieldList as $key => $value) {
         if (is_integer($key)) {
             unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]);
             continue;
         }
         if (CRM_Utils_Array::value('field_name', $defaults) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) {
             continue;
         }
         unset($fields[$value['field_type']][$key]);
     }
     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;
     }
     $activityFields = CRM_Activity_BAO_Activity::exportableFields('Activity');
     if (!empty($activityFields)) {
         unset($activityFields['activity_id']);
         unset($activityFields['source_contact_id']);
         unset($activityFields['is_test']);
         unset($activityFields['activity_type_id']);
         unset($activityFields['is_current_revision']);
         unset($activityFields['is_deleted']);
         $fields['Activity'] = $activityFields;
     }
     $noSearchable = array();
     $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address'));
     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;
                 if (in_array($key1, $addressCustomFields)) {
                     $noSearchable[] = $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 (!empty($activityFields)) {
         $sel1['Activity'] = 'Activity';
     }
     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);
     $extra = array('onclick' => 'showLabel();mixProfile();', 'onblur' => 'showLabel();mixProfile();');
     $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name'), $extra);
     $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);
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField');
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     $this->add('textarea', 'help_post', ts('Field Help'), $attributes['help_post']);
     $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'), $attributes['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 . "'"));
     }
     if (CRM_Utils_Array::value(1, $defaults['field_name']) == 'url-1') {
         $defaults['field_name'][1] = 'url';
     }
     $this->setDefaults($defaults);
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 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');
         CRM_Utils_System::setTitle($this->_title . ' - ' . ts('CiviCRM Profile Fields'));
         $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);
     $this->_fields = array_merge(CRM_Activity_BAO_Activity::exportableFields('Activity'), $this->_fields);
     $this->_contriBatchEntryFields = array('send_receipt' => array('name' => 'send_receipt', 'title' => ts('Send Receipt')), 'soft_credit' => array('name' => 'soft_credit', 'title' => ts('Soft Credit')), 'product_name' => array('name' => 'product_name', 'title' => ts('Premiums')), 'contribution_note' => array('name' => 'contribution_note', 'title' => ts('Contribution Note')));
     $this->_memberBatchEntryFields = array('send_receipt' => array('name' => 'send_receipt', 'title' => ts('Send Receipt')), 'soft_credit' => array('name' => 'soft_credit', 'title' => ts('Soft Credit')), 'product_name' => array('name' => 'product_name', 'title' => ts('Premiums')), 'contribution_type' => array('name' => 'contribution_type', 'title' => ts('Contribution Type')), 'total_amount' => array('name' => 'total_amount', 'title' => ts('Total Amount')), 'receive_date' => array('name' => 'receive_date', 'title' => ts('Receive Date')), 'payment_instrument' => array('name' => 'payment_instrument', 'title' => ts('Payment Instrument')), 'contribution_status_id' => array('name' => 'contribution_status_id', 'title' => ts('Contribution Status')));
     //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($this->_contriBatchEntryFields, $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(TRUE), $this->_fields);
     }
     if (CRM_Core_Permission::access('Quest')) {
         $this->_fields = array_merge(CRM_Quest_BAO_Student::exportableFields(), $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] = 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');
     //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);
     }
 }
Exemple #14
0
 /**
  * get all the fields that belong to the group with the name title
  *
  * @param mix      $id           the id of the UF group or ids of ufgroup
  * @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 ufgroup(s)
  * @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 (!is_array($id)) {
         $id = CRM_Utils_Type::escape($id, 'Positive');
         $profileIds = array($id);
     } else {
         $profileIds = $id;
     }
     $gids = implode(',', $profileIds);
     $params = array();
     if ($restrict) {
         $query = "SELECT g.* from civicrm_uf_group g, civicrm_uf_join j \n                WHERE g.id IN ( {$gids} ) \n                AND j.uf_group_id IN ( {$gids} )\n                AND j.module      = %1\n                ";
         $params = array(1 => array($restrict, 'String'));
     } else {
         $query = "SELECT g.* from civicrm_uf_group g WHERE g.id IN ( {$gids} ) ";
     }
     if (!$showAll) {
         $query .= " AND g.is_active = 1";
     }
     // 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();
     $validGroup = false;
     while ($group->fetch()) {
         $validGroup = true;
         $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';
         require_once 'CRM/Core/BAO/UFField.php';
         require_once 'CRM/Activity/BAO/Activity.php';
         $profileType = CRM_Core_BAO_UFField::getProfileType($group->id);
         if ($profileType == 'Activity') {
             $componentFields = CRM_Activity_BAO_Activity::exportableFields('Activity');
         } 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;
         $locationFields = 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", "Activity");
         foreach ($components as $value) {
             $customFields = array_merge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value));
         }
         $addressCustomFields = CRM_Core_BAO_CustomField::getFieldsForImport('Address');
         $customFields = array_merge($customFields, $addressCustomFields);
         while ($field->fetch()) {
             $name = $title = $locType = $phoneType = '';
             $name = $field->field_name;
             $title = $field->label;
             $addressCustom = false;
             if (in_array($permissionType, array(CRM_Core_Permission::CREATE, CRM_Core_Permission::EDIT)) && in_array($field->field_name, array_keys($addressCustomFields))) {
                 $addressCustom = true;
                 $name = "address_{$name}";
             }
             if ($field->location_type_id) {
                 $name .= "-{$field->location_type_id}";
                 $locType = " ( {$locationType[$field->location_type_id]} ) ";
             } else {
                 if (in_array($field->field_name, $locationFields) || $addressCustom) {
                     $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($field->field_name, 0, 6) == 'custom' || substr($field->field_name, 0, 14) === 'address_custom') {
                 // if field is not present in customFields, that means the user
                 // DOES NOT HAVE permission to access that field
                 if (array_key_exists($field->field_name, $customFields)) {
                     $fields[$name]['is_search_range'] = $customFields[$field->field_name]['is_search_range'];
                     // fix for CRM-1994
                     $fields[$name]['options_per_line'] = $customFields[$field->field_name]['options_per_line'];
                     $fields[$name]['data_type'] = $customFields[$field->field_name]['data_type'];
                     $fields[$name]['html_type'] = $customFields[$field->field_name]['html_type'];
                     if (CRM_Utils_Array::value('html_type', $fields[$name]) == 'Select Date') {
                         $fields[$name]['date_format'] = $customFields[$field->field_name]['date_format'];
                         $fields[$name]['time_format'] = $customFields[$field->field_name]['time_format'];
                     }
                 } else {
                     unset($fields[$name]);
                 }
             }
         }
         $field->free();
     }
     if (empty($fields) && !$validGroup) {
         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 => implode(',', $profileIds))));
     }
     return $fields;
 }