Ejemplo n.º 1
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, $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();
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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();
 }
Ejemplo n.º 6
0
 /**
  * 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)
 {
     //CRM_Core_Error::debug('s', $values);
     if (CRM_Utils_Array::value('addMore', $values) || CRM_Utils_Array::value('addBlock', $values)) {
         return true;
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     $fields = array();
     $fields = CRM_Contact_BAO_Contact::exportableFields('All', false, true);
     require_once 'CRM/Core/Component.php';
     $compomentFields =& CRM_Core_Component::getQueryFields();
     $fields = array_merge($fields, $compomentFields);
     $fld = array();
     $fld = CRM_Core_BAO_Mapping::formattedFields($values, true);
     require_once 'CRM/Utils/Type.php';
     $errorMsg = array();
     foreach ($fld as $k => $v) {
         if (!$v[1]) {
             $errorMsg["operator[{$v['3']}][{$v['4']}]"] = ts("Please enter the operator.");
         } else {
             if (in_array($v[1], array('IS NULL', 'IS NOT NULL')) && $v[2]) {
                 $errorMsg["value[{$v['3']}][{$v['4']}]"] = ts('Please clear your value if you want to use %1 operator.', array(1 => $v[1]));
             } else {
                 if ($v[0] == 'group' || $v[0] == 'tag') {
                     $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]));
                         }
                     }
                 } else {
                     if (substr($v[0], 0, 7) === 'do_not_' or substr($v[0], 0, 3) === 'is_') {
                         if ($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.");
                         }
                     } else {
                         if ($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);
                                 }
                                 $fldType = CRM_Utils_Array::value('type', $fields[$fldName]);
                                 $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.");
                                     } else {
                                         if ($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 (!preg_match('/^[(]([A-Za-z0-9\'\\,]+)[)]$/', $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) {
                                             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.");
                                                 }
                                             }
                                         }
                                     }
                                 } else {
                                     if (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;
 }
Ejemplo n.º 7
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 );
 }
Ejemplo n.º 8
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, $orderBy = 'field_name', $orderProfiles = NULL)
 {
     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) {
         $permissionClause = CRM_Core_Permission::ufGroupClause($permissionType, 'g.');
         $query .= " AND {$permissionClause} ";
     }
     if ($orderProfiles and count($profileIds) > 1) {
         $query .= " ORDER BY FIELD(  g.id, {$gids} )";
     }
     $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";
         if ($orderBy) {
             $query .= ", " . $orderBy;
         }
         $field = CRM_Core_DAO::executeQuery($query);
         if (!$showAll) {
             $importableFields = CRM_Contact_BAO_Contact::importableFields('All');
         } else {
             $importableFields = CRM_Contact_BAO_Contact::importableFields('All', FALSE, TRUE);
         }
         $profileType = CRM_Core_BAO_UFField::getProfileType($group->id);
         $contactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($group->id);
         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;
         $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();
         $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}";
                 // this hack is to prevent Phone Phone (work)
                 if ($field->phone_type_id != '1') {
                     $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', CRM_Utils_Array::value($field->field_name, $importableFields)), 'attributes' => CRM_Core_DAO::makeAttribute(CRM_Utils_Array::value($field->field_name, $importableFields)), 'is_required' => $field->is_required, 'is_view' => $field->is_view, 'help_pre' => $field->help_pre, 'help_post' => $field->help_post, 'visibility' => $field->visibility, 'in_selector' => $field->in_selector, 'rule' => CRM_Utils_Array::value('rule', CRM_Utils_Array::value($field->field_name, $importableFields)), '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;
 }