/** * Browse all CiviCRM Profile group fields. * * @return void * @access public * @static */ function browse() { $ufField = array(); $ufFieldBAO = new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); require_once "CRM/Core/BAO/UFField.php"; $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') { $this->assign('skipCreate', true); } $locationType = array(); $locationType =& CRM_Core_PseudoConstant::locationType(); require_once 'CRM/Contact/BAO/Contact.php'; $fields =& CRM_Contact_BAO_Contact::exportableFields('All', false, true); require_once "CRM/Contribute/BAO/Contribution.php"; $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields = array_merge(CRM_Quest_BAO_Student::exportableFields(), $fields); } $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); CRM_Core_DAO_UFField::addDisplayEnums($ufField[$ufFieldBAO->id]); $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($ufFieldBAO->is_reserved) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight']; $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid)); } $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "uf_group_id = {$this->_gid}"; require_once 'CRM/Utils/Weight.php'; CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter); $this->assign('ufField', $ufField); // retrieve showBestResult from session $session = CRM_Core_Session::singleton(); $showBestResult = $session->get('showBestResult'); $this->assign('showBestResult', $showBestResult); $session->set('showBestResult', 0); }
/** * Browse all CiviCRM Profile group fields. * * @return void */ public function browse() { $resourceManager = CRM_Core_Resources::singleton(); if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) { $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header'); } $ufField = array(); $ufFieldBAO = new CRM_Core_BAO_UFField(); // fkey is gid $ufFieldBAO->uf_group_id = $this->_gid; $ufFieldBAO->orderBy('weight', 'field_name'); $ufFieldBAO->find(); $otherModules = CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid); $this->assign('otherModules', $otherModules); $isGroupReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid, 'is_reserved'); $this->assign('isGroupReserved', $isGroupReserved); $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($profileType == 'Contribution' || $profileType == 'Membership' || $profileType == 'Activity' || $profileType == 'Participant') { $this->assign('skipCreate', TRUE); } $locationType = array(); $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $fields = CRM_Contact_BAO_Contact::exportableFields('All', FALSE, TRUE); $fields = array_merge(CRM_Contribute_BAO_Contribution::getContributionFields(), $fields); $select = array(); foreach ($fields as $name => $field) { if ($name) { $select[$name] = $field['title']; } } $select['group'] = ts('Group(s)'); $select['tag'] = ts('Tag(s)'); $visibility = CRM_Core_SelectValues::ufVisibility(); while ($ufFieldBAO->fetch()) { $ufField[$ufFieldBAO->id] = array(); $phoneType = $locType = ''; CRM_Core_DAO::storeValues($ufFieldBAO, $ufField[$ufFieldBAO->id]); $ufField[$ufFieldBAO->id]['visibility_display'] = $visibility[$ufFieldBAO->visibility]; $ufField[$ufFieldBAO->id]['label'] = $ufFieldBAO->label; $action = array_sum(array_keys($this->actionLinks())); if ($ufFieldBAO->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if ($ufFieldBAO->is_reserved) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $ufField[$ufFieldBAO->id]['order'] = $ufField[$ufFieldBAO->id]['weight']; $ufField[$ufFieldBAO->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $ufFieldBAO->id, 'gid' => $this->_gid), ts('more'), FALSE, 'ufField.row.actions', 'UFField', $ufFieldBAO->id); } $returnURL = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$this->_gid}"); $filter = "uf_group_id = {$this->_gid}"; CRM_Utils_Weight::addOrder($ufField, 'CRM_Core_DAO_UFField', 'id', $returnURL, $filter); $this->assign('ufField', $ufField); // retrieve showBestResult from session $session = CRM_Core_Session::singleton(); $showBestResult = $session->get('showBestResult'); $this->assign('showBestResult', $showBestResult); $session->set('showBestResult', 0); }
/** * Global validation rules for the form. * * @param array $fields * Posted values of the form. * * @param $files * @param $self * * @return array * list of errors to be posted back to the form */ public static function formRule($fields, $files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, FALSE); $is_registration = CRM_Utils_Array::value('is_registration', $fields, FALSE); $is_view = CRM_Utils_Array::value('is_view', $fields, FALSE); $in_selector = CRM_Utils_Array::value('in_selector', $fields, FALSE); $is_active = CRM_Utils_Array::value('is_active', $fields, FALSE); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $entityName = $fields['field_name'][0]; if (!$entityName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($entityName, array('Contribution', 'Participant', 'Membership', 'Activity'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $entityName)); } $isCustomField = FALSE; $profileFieldName = CRM_Utils_Array::value(1, $fields['field_name']); if ($profileFieldName) { //get custom field id $customFieldId = explode('_', $profileFieldName); if ($customFieldId[0] == 'custom') { $customField = new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(TRUE); $isCustomField = TRUE; if (!empty($fields['field_id']) && !$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } //check if profile already has a different multi-record custom set field configured $customGroupId = CRM_Core_BAO_CustomField::isMultiRecordField($profileFieldName); if ($customGroupId) { if ($profileMultiRecordCustomGid = CRM_Core_BAO_UFField::checkMultiRecordFieldExists($self->_gid)) { if ($customGroupId != $profileMultiRecordCustomGid) { $errors['field_name'] = ts("You cannot configure multi-record custom fields belonging to different custom sets in one profile"); } } } } } // Get list of fields already in the group $groupFields = CRM_Core_BAO_UFGroup::getFields($fields['group_id'], FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE); // Check if we already added a primary field of the same communication type self::formRulePrimaryCheck($fields, $profileFieldName, $groupFields, $errors); //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 if (CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { if (CRM_Utils_Array::value(1, $fields['field_name']) == 'group') { $dao = new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = FALSE; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = TRUE; break; } } if (!$emailField) { $disableSettingURL = CRM_Utils_System::url('civicrm/admin/setting/preferences/mailing', 'reset=1'); $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in on the civimail admin settings: <em>%1</em>', array(1 => $disableSettingURL)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, FALSE, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Contact': self::formRuleSubType($fieldType, $groupType, $errors); break; case 'Individual': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Organization', $groupType)) { //CRM-7603 - need to support activity + individual. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' ); if (in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Activity', $groupType) || in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Activity': if (in_array('Individual', $groupType) || in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Participant', $groupType)) { //CRM-7603 - need to support activity + contact type. //$errors['field_name'] = //ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' ); if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Participant', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution'); } } else { self::formRuleSubType($fieldType, $groupType, $errors); } if ($isCustomField && !isset($errors['field_name'])) { self::formRuleCustomDataExtentColumnValue($customField, $self->_gid, $fieldType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization.'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': //special case where in we allow contribution + oganization fields, for on behalf feature $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || $profileId != $self->_gid && in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], TRUE, FALSE, TRUE); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif (CRM_Utils_Array::value(1, $fields['field_name']) == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? TRUE : $errors; }
/** * 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($fields, $files, $self) { $is_required = CRM_Utils_Array::value('is_required', $fields, false); $is_registration = CRM_Utils_Array::value('is_registration', $fields, false); $is_view = CRM_Utils_Array::value('is_view', $fields, false); $in_selector = CRM_Utils_Array::value('in_selector', $fields, false); $is_searchable = CRM_Utils_Array::value('is_searchable', $fields, false); $visibility = CRM_Utils_Array::value('visibility', $fields, false); $is_active = CRM_Utils_Array::value('is_active', $fields, false); $errors = array(); if ($is_view && $is_registration) { $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form'); } if ($is_view && $is_required) { $errors['is_view'] = ts('A View Only field cannot be required'); } $fieldName = $fields['field_name'][0]; if (!$fieldName) { $errors['field_name'] = ts('Please select a field name'); } if ($in_selector && in_array($fieldName, array('Contribution', 'Participant', 'Membership', 'Activity'))) { $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName)); } if (!empty($fields['field_id'])) { //get custom field id $customFieldId = explode('_', $fieldName); if ($customFieldId[0] == 'custom') { $customField = new CRM_Core_DAO_CustomField(); $customField->id = $customFieldId[1]; $customField->find(true); if (!$customField->is_active && $is_active) { $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.'); } } } //check profile is configured for double option process //adding group field, email field should be present in the group //fixed for issue CRM-2861 & CRM-4153 $config = CRM_Core_Config::singleton(); if ($config->profileDoubleOptIn) { if ($fields['field_name'][1] == 'group') { require_once 'CRM/Core/BAO/UFField.php'; $dao = new CRM_Core_BAO_UFField(); $dao->uf_group_id = $fields['group_id']; $dao->find(); $emailField = false; while ($dao->fetch()) { //check email field is present in the group if ($dao->field_name == 'email') { $emailField = true; } } if (!$emailField) { $disableSetting = "define( 'CIVICRM_PROFILE_DOUBLE_OPTIN' , 0 );"; $errors['field_name'] = ts('Your site is currently configured to require double-opt in when users join (subscribe) to Group(s) via a Profile form. In this mode, you need to include an Email field in a Profile BEFORE you can add the Group(s) field. This ensures that an opt-in confirmation email can be sent. Your site administrator can disable double opt-in by adding this line to the CiviCRM settings file: <em>%1</em>', array(1 => $disableSetting)); } } } //fix for CRM-3037 $fieldType = $fields['field_name'][0]; //get the group type. $groupType = CRM_Core_BAO_UFGroup::calculateGroupType($self->_gid, CRM_Utils_Array::value('field_id', $fields)); switch ($fieldType) { case 'Contact': if (in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contact with combination of Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Individual': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Household': if (in_array('Activity', $groupType) || in_array('Individual', $groupType) || in_array('Organization', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Organization': if (in_array('Activity', $groupType) || in_array('Household', $groupType) || in_array('Individual', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Activity': if (in_array('Individual', $groupType) || in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Participant', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Participant': if (in_array('Membership', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization or Activity'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Contribution': if (in_array('Participant', $groupType) || in_array('Membership', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; case 'Membership': if (in_array('Participant', $groupType) || in_array('Contribution', $groupType) || in_array('Organization', $groupType) || in_array('Household', $groupType) || in_array('Activity', $groupType)) { $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization'); } else { self::formRuleSubType($fieldType, $groupType, $errors); } break; default: $profileType = CRM_Core_BAO_UFField::getProfileType($fields['group_id'], true, false, true); if (CRM_Contact_BAO_ContactType::isaSubType($fieldType)) { if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { if ($fieldType != $profileType) { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } else { $basicType = CRM_Contact_BAO_ContactType::getBasicType($fieldType); if ($profileType && $profileType != $basicType && $profileType != 'Contact') { $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType)); } } } elseif ($fields['field_name'][1] == 'contact_sub_type' && !in_array($profileType, array('Individual', 'Household', 'Organization')) && !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())) { $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.'); } } return empty($errors) ? true : $errors; }