3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * form to process actions on the field aspect of Custom
39 class CRM_UF_Form_Field
extends CRM_Core_Form
{
42 * the uf group id saved to the session for an update
50 * The field id, used when editing the field
58 * The set of fields that we can view/edit in the user field framework
74 * The set of fields sent to the select element
79 protected $_selectFields;
82 * to store fields with if locationtype exits status
87 protected $_hasLocationTypes;
90 * is this profile has searchable field
91 * or is any field having in selector true.
96 protected $_hasSearchableORInSelector;
99 * Function to set variables up before form is built
104 public function preProcess() {
105 $this->_gid
= CRM_Utils_Request
::retrieve('gid', 'Positive', $this);
106 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
108 $this->_title
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $this->_gid
, 'title');
109 CRM_Utils_System
::setTitle($this->_title
. ' - ' . ts('CiviCRM Profile Fields'));
111 $url = CRM_Utils_System
::url('civicrm/admin/uf/group/field',
112 "reset=1&action=browse&gid={$this->_gid}"
115 $session = CRM_Core_Session
::singleton();
116 $session->pushUserContext($url);
117 $breadCrumb = array(array('title' => ts('CiviCRM Profile Fields'),
120 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
123 $showBestResult = CRM_Utils_Request
::retrieve('sbr', 'Positive', CRM_Core_DAO
::$_nullArray);
124 if ($showBestResult) {
125 $this->assign('showBestResult', $showBestResult);
128 $this->_fields
= CRM_Contact_BAO_Contact
::importableFields('All', TRUE, TRUE, TRUE, TRUE, TRUE);
129 $this->_fields
= array_merge(CRM_Activity_BAO_Activity
::exportableFields('Activity'), $this->_fields
);
131 //unset campaign related fields.
132 if (isset($this->_fields
['activity_campaign_id'])) {
133 $this->_fields
['activity_campaign_id']['title'] = ts('Campaign');
134 if (isset($this->_fields
['activity_campaign'])) {
135 unset($this->_fields
['activity_campaign']);
139 if (CRM_Core_Permission
::access('CiviContribute')) {
140 $this->_fields
= array_merge(CRM_Contribute_BAO_Contribution
::getContributionFields(FALSE), $this->_fields
);
141 $this->_fields
= array_merge(CRM_Core_BAO_UFField
::getContribBatchEntryFields(), $this->_fields
);
144 if (CRM_Core_Permission
::access('CiviMember')) {
145 $this->_fields
= array_merge(CRM_Member_BAO_Membership
::getMembershipFields(), $this->_fields
);
148 if (CRM_Core_Permission
::access('CiviEvent')) {
149 $this->_fields
= array_merge(CRM_Event_BAO_Query
::getParticipantFields(), $this->_fields
);
152 $this->_selectFields
= array();
153 foreach ($this->_fields
as $name => $field) {
154 // lets skip note for now since we dont support it
155 if ($name == 'note') {
158 $this->_selectFields
[$name] = $field['title'];
159 $this->_hasLocationTypes
[$name] = CRM_Utils_Array
::value('hasLocationType', $field);
162 // lets add group, tag and current_employer to this list
163 $this->_selectFields
['group'] = ts('Group(s)');
164 $this->_selectFields
['tag'] = ts('Tag(s)');
165 $this->_selectFields
['current_employer'] = ts('Current Employer');
166 $this->_selectFields
['phone_and_ext'] = ts('Phone and Extension');
168 //CRM-4363 check for in selector or searchable fields.
169 $this->_hasSearchableORInSelector
= CRM_Core_BAO_UFField
::checkSearchableORInSelector($this->_gid
);
171 $this->assign('fieldId', $this->_id
);
173 $fieldTitle = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFField', $this->_id
, 'label');
174 $this->assign('fieldTitle', $fieldTitle);
179 * Function to actually build the form
184 public function buildQuickForm() {
185 if ($this->_action
& CRM_Core_Action
::DELETE
) {
186 $this->addButtons(array(
189 'name' => ts('Delete Profile Field'),
190 'spacing' => ' ',
195 'name' => ts('Cancel'),
202 if (isset($this->_id
)) {
203 $params = array('id' => $this->_id
);
204 CRM_Core_BAO_UFField
::retrieve($params, $defaults);
206 // set it to null if so (avoids crappy E_NOTICE errors below
207 $defaults['location_type_id'] = CRM_Utils_Array
::value('location_type_id', $defaults);
209 $specialFields = CRM_Core_BAO_UFGroup
::getLocationFields();
211 if (!$defaults['location_type_id'] &&
212 $defaults["field_type"] != "Formatting" &&
213 in_array($defaults['field_name'], $specialFields)
215 $defaults['location_type_id'] = 0;
218 $defaults['field_name'] = array(
219 $defaults['field_type'],
220 ($defaults['field_type'] == "Formatting" ?
"" : $defaults['field_name']),
221 $defaults['location_type_id'],
222 CRM_Utils_Array
::value('phone_type_id', $defaults),
224 $this->_gid
= $defaults['uf_group_id'];
227 $defaults['is_active'] = 1;
230 $otherModules = array_values(CRM_Core_BAO_UFGroup
::getUFJoinRecord($this->_gid
));
231 $this->assign('otherModules', $otherModules);
233 if ($this->_action
& CRM_Core_Action
::ADD
) {
234 $fieldValues = array('uf_group_id' => $this->_gid
);
235 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues);
238 // lets trim all the whitespace
239 $this->applyFilter('__ALL__', 'trim');
241 //hidden field to catch the group id in profile
242 $this->add('hidden', 'group_id', $this->_gid
);
244 //hidden field to catch the field id in profile
245 $this->add('hidden', 'field_id', $this->_id
);
247 $fields = CRM_Core_BAO_UFField
::getAvailableFields($this->_gid
, $defaults);
249 $noSearchable = array();
250 $addressCustomFields = array_keys(CRM_Core_BAO_CustomField
::getFieldsForImport('Address'));
252 foreach ($fields as $key => $value) {
253 foreach ($value as $key1 => $value1) {
254 //CRM-2676, replacing the conflict for same custom field name from different custom group.
255 if ($customFieldId = CRM_Core_BAO_CustomField
::getKeyID($key1)) {
256 $customGroupId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id');
257 $customGroupName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title');
258 $this->_mapperFields
[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName;
259 if (in_array($key1, $addressCustomFields)) {
260 $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName;
264 $this->_mapperFields
[$key][$key1] = $value1['title'];
266 $hasLocationTypes[$key][$key1] = CRM_Utils_Array
::value('hasLocationType', $value1);
268 // hide the 'is searchable' field for 'File' custom data
269 if (isset($value1['data_type']) &&
270 isset($value1['html_type']) &&
271 (($value1['data_type'] == 'File' && $value1['html_type'] == 'File')
272 ||
($value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')
275 if (!in_array($value1['title'], $noSearchable)) {
276 $noSearchable[] = $value1['title'];
281 $this->assign('noSearchable', $noSearchable);
283 $this->_location_types
= CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
284 $defaultLocationType = CRM_Core_BAO_LocationType
::getDefault();
287 * FIXME: dirty hack to make the default option show up first. This
288 * avoids a mozilla browser bug with defaults on dynamically constructed
291 if ($defaultLocationType) {
292 $defaultLocation = $this->_location_types
[$defaultLocationType->id
];
293 unset($this->_location_types
[$defaultLocationType->id
]);
294 $this->_location_types
= array(
295 $defaultLocationType->id
=> $defaultLocation) +
$this->_location_types
;
298 $this->_location_types
= array('Primary') +
$this->_location_types
;
300 // since we need a hierarchical list to display contact types & subtypes,
301 // this is what we going to display in first selector
302 $contactTypes = CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, FALSE);
303 unset($contactTypes['']);
305 $contactTypes = !empty($contactTypes) ?
array('Contact' => 'Contacts') +
$contactTypes : array();
306 $sel1 = array('' => '- select -') +
$contactTypes;
308 if (!empty($fields['Activity'])) {
309 $sel1['Activity'] = 'Activity';
312 if (CRM_Core_Permission
::access('CiviEvent')) {
313 $sel1['Participant'] = 'Participants';
316 if (!empty($fields['Contribution'])) {
317 $sel1['Contribution'] = 'Contributions';
320 if (!empty($fields['Membership'])) {
321 $sel1['Membership'] = 'Membership';
324 if (!empty($fields['Formatting'])) {
325 $sel1['Formatting'] = 'Formatting';
328 foreach ($sel1 as $key => $sel) {
330 $sel2[$key] = $this->_mapperFields
[$key];
334 $phoneTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Phone', 'phone_type_id');
337 foreach ($sel1 as $k => $sel) {
339 foreach ($this->_location_types
as $key => $value) {
340 $sel4[$k]['phone'][$key] = &$phoneTypes;
341 $sel4[$k]['phone_and_ext'][$key] = &$phoneTypes;
346 foreach ($sel1 as $k => $sel) {
348 if (is_array($this->_mapperFields
[$k])) {
349 foreach ($this->_mapperFields
[$k] as $key => $value) {
350 if ($hasLocationTypes[$k][$key]) {
351 $sel3[$k][$key] = $this->_location_types
;
361 $this->_defaults
= array();
362 $js = "<script type='text/javascript'>\n";
363 $formName = "document.{$this->_name}";
365 $alreadyMixProfile = FALSE;
366 if (CRM_Core_BAO_UFField
::checkProfileType($this->_gid
)) {
367 $alreadyMixProfile = TRUE;
369 $this->assign('alreadyMixProfile', $alreadyMixProfile);
371 $sel = &$this->addElement('hierselect', 'field_name', ts('Field Name'));
373 $formValues = $this->exportValues();
375 if (empty($formValues)) {
376 for ($k = 1; $k < 4; $k++
) {
377 if (!$defaults['field_name'][$k]) {
378 $js .= "{$formName}['field_name[$k]'].style.display = 'none';\n";
383 if (!empty($formValues['field_name'])) {
384 foreach ($formValues['field_name'] as $value) {
385 for ($k = 1; $k < 4; $k++
) {
386 if (!isset($formValues['field_name'][$k]) ||
!$formValues['field_name'][$k]) {
387 $js .= "{$formName}['field_name[$k]'].style.display = 'none';\n";
390 $js .= "{$formName}['field_name[$k]'].style.display = '';\n";
396 for ($k = 1; $k < 4; $k++
) {
397 if (!isset($defaults['field_name'][$k])) {
398 $js .= "{$formName}['field_name[$k]'].style.display = 'none';\n";
404 foreach ($sel2 as $k => $v) {
405 if (is_array($sel2[$k])) {
410 // CRM_Core_Error::debug(array($sel1, $sel2, $sel3, $sel4));
411 $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
413 // proper interpretation of spec in CRM-8732
414 if (!isset($this->_id
) && in_array('Search Profile', $otherModules)) {
415 $defaults['visibility'] = 'Public Pages and Listings';
418 $js .= "</script>\n";
419 $this->assign('initHideBoxes', $js);
424 CRM_Core_SelectValues
::ufVisibility(),
426 array('onChange' => "showHideSeletorSearch(this.value);")
430 $js = array('onChange' => "mixProfile();");
431 // should the field appear in selectors (as a column)?
432 $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js);
433 $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js);
435 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFField');
438 $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
439 $this->addRule('weight', ts('is a numeric field'), 'numeric');
441 $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']);
442 $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']);
444 $this->add('checkbox', 'is_required', ts('Required?'));
446 $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?'));
447 $this->add('checkbox', 'is_active', ts('Active?'));
448 $this->add('checkbox', 'is_view', ts('View Only?'));
450 // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
451 //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) );
453 $this->add('text', 'label', ts('Field Label'), $attributes['label']);
456 if ($this->_hasSearchableORInSelector
) {
457 $js = array('onclick' => "return verify( );");
461 $this->addButtons(array(
464 'name' => ts('Save'),
470 'name' => ts('Save and New'),
476 'name' => ts('Cancel'),
481 $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
483 // if view mode pls freeze it with the done button.
484 if ($this->_action
& CRM_Core_Action
::VIEW
) {
486 $this->addElement('button', 'done', ts('Done'),
487 array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid
. "'")
491 if (isset($defaults['field_name']) && CRM_Utils_Array
::value(1, $defaults['field_name']) == 'url-1') {
492 $defaults['field_name'][1] = 'url';
495 $this->setDefaults($defaults);
504 public function postProcess() {
505 $ids = array('uf_group' => $this->_gid
);
506 if ($this->_action
& CRM_Core_Action
::DELETE
) {
507 $fieldValues = array('uf_group_id' => $this->_gid
);
508 CRM_Utils_Weight
::delWeight('CRM_Core_DAO_UFField', $this->_id
, $fieldValues);
509 $deleted = CRM_Core_BAO_UFField
::del($this->_id
);
511 //update group_type every time. CRM-3608
512 if ($this->_gid
&& $deleted) {
513 //get the profile type.
514 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($this->_gid
, TRUE);
515 CRM_Core_BAO_UFGroup
::updateGroupTypes($this->_gid
, $fieldsType);
518 CRM_Core_Session
::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success');
522 // store the submitted values in an array
523 $params = $this->controller
->exportValues('Field');
524 if ($params['visibility'] == 'User and User Admin Only') {
525 $params['is_searchable'] = $params['in_selector'] = 0;
528 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
529 $ids['uf_field'] = $this->_id
;
534 if (isset($params['field_name'][1])) {
535 // we dont get a name for a html formatting element
536 $name = $this->_selectFields
[$params['field_name'][1]];
539 //Hack for Formatting Field Name
540 if ($params['field_name'][0] == 'Formatting') {
541 $params['field_name'][1] = 'formatting_' . rand(1000, 9999);
544 // temporary hack to for website
545 if ($params['field_name'][1] == 'url') {
546 $params['field_name'][1] = 'url-1';
549 //check for duplicate fields
550 if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField
::duplicateField($params, $ids)) {
551 CRM_Core_Session
::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
555 $params['weight'] = CRM_Core_BAO_UFField
::autoWeight($params);
556 $ufField = CRM_Core_BAO_UFField
::add($params, $ids);
558 //reset other field is searchable and in selector settings, CRM-4363
559 if ($this->_hasSearchableORInSelector
&&
560 in_array($ufField->field_type
, array('Participant', 'Contribution', 'Membership', 'Activity'))
562 CRM_Core_BAO_UFField
::resetInSelectorANDSearchable($this->_gid
);
565 $config = CRM_Core_Config
::singleton();
566 $showBestResult = FALSE;
567 if (in_array($ufField->field_name
, array(
568 'country', 'state_province')) && count($config->countryLimit
) > 1) {
569 // get state or country field weight if exists
570 $field = 'state_province';
571 if ($ufField->field_name
== 'state_province') {
574 $ufFieldDAO = new CRM_Core_DAO_UFField();
575 $ufFieldDAO->field_name
= $field;
576 $ufFieldDAO->location_type_id
= $ufField->location_type_id
;
577 $ufFieldDAO->uf_group_id
= $ufField->uf_group_id
;
579 if ($ufFieldDAO->find(TRUE)) {
580 if ($field == 'country' && $ufFieldDAO->weight
> $ufField->weight
) {
581 $showBestResult = TRUE;
583 elseif ($field == 'state_province' && $ufFieldDAO->weight
< $ufField->weight
) {
584 $showBestResult = TRUE;
589 //update group_type every time. CRM-3608
590 if ($this->_gid
&& is_a($ufField, 'CRM_Core_DAO_UFField')) {
591 // get the profile type.
592 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($this->_gid
, TRUE);
593 CRM_Core_BAO_UFGroup
::updateGroupTypes($this->_gid
, $fieldsType);
595 CRM_Core_Session
::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.',
596 array(1 => $name, 2 => $this->_title
)
597 ), ts('Profile Field Saved'), 'success');
599 $buttonName = $this->controller
->getButtonName();
601 $session = CRM_Core_Session
::singleton();
602 if ($buttonName == $this->getButtonName('next', 'new')) {
603 CRM_Core_Session
::setStatus(ts(' You can add another profile field.'), '', 'info');
604 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/uf/group/field/add',
605 "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"
609 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/uf/group/field',
610 "reset=1&action=browse&gid={$this->_gid}"
612 $session->set('showBestResult', $showBestResult);
617 * validation rule for subtype.
619 * @param array $groupType contains all groupTypes.
621 * @param string $fieldType type of field.
623 * @param array $errors
625 * @return array list of errors to be posted back to the form
629 static function formRuleSubType($fieldType, $groupType, $errors) {
630 if (in_array($fieldType, array(
631 'Participant', 'Contribution', 'Membership', 'Activity'))) {
632 $individualSubTypes = CRM_Contact_BAO_ContactType
::subTypes('Individual');
633 foreach ($groupType as $value) {
634 if (!in_array($value, $individualSubTypes) &&
635 !in_array($value, array(
636 'Participant', 'Contribution', 'Membership',
637 'Individual', 'Contact', 'Activity',
640 $errors['field_name'] = ts('Cannot add or update profile field "%1" with combination of Household or Organization or any subtypes of Household or Organisation.', array(1 => $fieldType));
646 $basicType = CRM_Contact_BAO_ContactType
::getBasicType($groupType);
648 if (!is_array($basicType)) {
649 $basicType = array($basicType);
651 if (!in_array($fieldType, $basicType)) {
652 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of subtype other than "%1".',
653 array(1 => $fieldType)
661 * validation rule for custom data extends entity column values.
663 * @param Object $customField Custom field
664 * @param Integer $gid Group Id.
665 * @param String $fieldType Group type of the field
666 * @param Array $errors Collect errors
668 * @return Array list of errors to be posted back to the form
672 static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors) {
673 // fix me : check object $customField
674 if (in_array($fieldType, array(
675 'Participant', 'Contribution', 'Membership', 'Activity'))) {
676 $params = array('id' => $customField->custom_group_id
);
677 $customGroup = array();
678 CRM_Core_BAO_CustomGroup
::retrieve($params, $customGroup);
679 if (($fieldType != CRM_Utils_Array
::value('extends', $customGroup)) ||
680 !CRM_Utils_Array
::value('extends_entity_column_value', $customGroup)
685 $extendsColumnValues = array();
686 foreach (explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $customGroup['extends_entity_column_value']) as $val) {
688 $extendsColumnValues[] = $val;
692 if (empty($extendsColumnValues)) {
696 $fieldTypeValues = CRM_Core_BAO_UFGroup
::groupTypeValues($gid, $fieldType);
697 if (!CRM_Utils_Array
::value($fieldType, $fieldTypeValues)) {
701 $disallowedTypes = array_diff($extendsColumnValues, $fieldTypeValues[$fieldType]);
702 if (!empty($disallowedTypes)) {
703 $errors['field_name'] = ts('Profile is already having custom fields extending different group types, you can not add or update this custom field.');
709 * global validation rules for the form
711 * @param array $fields posted values of the form
713 * @return array list of errors to be posted back to the form
717 static function formRule($fields, $files, $self) {
718 $is_required = CRM_Utils_Array
::value('is_required', $fields, FALSE);
719 $is_registration = CRM_Utils_Array
::value('is_registration', $fields, FALSE);
720 $is_view = CRM_Utils_Array
::value('is_view', $fields, FALSE);
721 $in_selector = CRM_Utils_Array
::value('in_selector', $fields, FALSE);
722 $is_active = CRM_Utils_Array
::value('is_active', $fields, FALSE);
725 if ($is_view && $is_registration) {
726 $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form');
728 if ($is_view && $is_required) {
729 $errors['is_view'] = ts('A View Only field cannot be required');
732 $fieldName = $fields['field_name'][0];
734 $errors['field_name'] = ts('Please select a field name');
737 if ($in_selector && in_array($fieldName, array(
738 'Contribution', 'Participant', 'Membership', 'Activity'))) {
739 $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName));
742 $isCustomField = FALSE;
743 $profileFieldName = CRM_Utils_Array
::value(1, $fields['field_name']);
744 if ($profileFieldName) {
745 //get custom field id
746 $customFieldId = explode('_', $profileFieldName);
747 if ($customFieldId[0] == 'custom') {
748 $customField = new CRM_Core_DAO_CustomField();
749 $customField->id
= $customFieldId[1];
750 $customField->find(TRUE);
751 $isCustomField = TRUE;
752 if (!empty($fields['field_id']) && !$customField->is_active
&& $is_active) {
753 $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.');
756 //check if profile already has a different multi-record custom set field configured
757 $customGroupId = CRM_Core_BAO_CustomField
::isMultiRecordField($profileFieldName);
758 if ($customGroupId) {
759 if ($profileMultiRecordCustomGid = CRM_Core_BAO_UFField
::checkMultiRecordFieldExists($self->_gid
)) {
760 if ($customGroupId != $profileMultiRecordCustomGid) {
761 $errors['field_name'] = ts("You cannot configure multi-record custom fields belonging to different custom sets in one profile");
768 //check profile is configured for double option process
769 //adding group field, email field should be present in the group
770 //fixed for issue CRM-2861 & CRM-4153
771 if (CRM_Core_BAO_UFGroup
::isProfileDoubleOptin()) {
772 if (CRM_Utils_Array
::value(1, $fields['field_name']) == 'group') {
773 $dao = new CRM_Core_BAO_UFField();
774 $dao->uf_group_id
= $fields['group_id'];
777 while ($dao->fetch()) {
778 //check email field is present in the group
779 if ($dao->field_name
== 'email') {
786 $disableSettingURL = CRM_Utils_System
::url(
787 'civicrm/admin/setting/preferences/mailing',
791 $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));
797 $fieldType = $fields['field_name'][0];
799 //get the group type.
800 $groupType = CRM_Core_BAO_UFGroup
::calculateGroupType($self->_gid
, FALSE, CRM_Utils_Array
::value('field_id', $fields));
802 switch ($fieldType) {
804 self
::formRuleSubType($fieldType, $groupType, $errors);
808 if (in_array('Activity', $groupType) ||
809 in_array('Household', $groupType) ||
810 in_array('Organization', $groupType)
813 //CRM-7603 - need to support activity + individual.
814 //$errors['field_name'] =
815 //ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' );
816 if (in_array('Household', $groupType) ||
817 in_array('Organization', $groupType)
819 $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization');
823 self
::formRuleSubType($fieldType, $groupType, $errors);
828 if (in_array('Activity', $groupType) ||
in_array('Individual', $groupType) ||
in_array('Organization', $groupType)) {
829 $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity');
832 self
::formRuleSubType($fieldType, $groupType, $errors);
837 if (in_array('Activity', $groupType) ||
in_array('Household', $groupType) ||
in_array('Individual', $groupType)) {
838 $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity');
841 self
::formRuleSubType($fieldType, $groupType, $errors);
846 if (in_array('Individual', $groupType) ||
847 in_array('Membership', $groupType) ||
848 in_array('Contribution', $groupType) ||
849 in_array('Organization', $groupType) ||
850 in_array('Household', $groupType) ||
851 in_array('Participant', $groupType)
854 //CRM-7603 - need to support activity + contact type.
855 //$errors['field_name'] =
856 //ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' );
857 if (in_array('Membership', $groupType) ||
858 in_array('Contribution', $groupType) ||
859 in_array('Participant', $groupType)
861 $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution');
865 self
::formRuleSubType($fieldType, $groupType, $errors);
868 if ($isCustomField && !isset($errors['field_name'])) {
869 self
::formRuleCustomDataExtentColumnValue($customField, $self->_gid
, $fieldType, $errors);
874 if (in_array('Membership', $groupType) ||
in_array('Contribution', $groupType)
875 ||
in_array('Organization', $groupType) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
877 $errors['field_name'] = ts('Cannot add or update profile field type Participant with combination of Activity or Membership or Contribution or Household or Organization.');
880 self
::formRuleSubType($fieldType, $groupType, $errors);
885 //special case where in we allow contribution + oganization fields, for on behalf feature
886 $profileId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup',
887 'on_behalf_organization', 'id', 'name'
890 if (in_array('Participant', $groupType) ||
in_array('Membership', $groupType)
891 ||
($profileId != $self->_gid
&& in_array('Organization', $groupType)) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
893 $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization');
896 self
::formRuleSubType($fieldType, $groupType, $errors);
901 //special case where in we allow contribution + oganization fields, for on behalf feature
902 $profileId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup',
903 'on_behalf_organization', 'id', 'name'
906 if (in_array('Participant', $groupType) ||
in_array('Contribution', $groupType)
907 ||
($profileId != $self->_gid
&& in_array('Organization', $groupType)) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
909 $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization');
912 self
::formRuleSubType($fieldType, $groupType, $errors);
917 $profileType = CRM_Core_BAO_UFField
::getProfileType($fields['group_id'], TRUE, FALSE, TRUE);
918 if (CRM_Contact_BAO_ContactType
::isaSubType($fieldType)) {
919 if (CRM_Contact_BAO_ContactType
::isaSubType($profileType)) {
920 if ($fieldType != $profileType) {
921 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
925 $basicType = CRM_Contact_BAO_ContactType
::getBasicType($fieldType);
927 $profileType != $basicType &&
928 $profileType != 'Contact'
930 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
935 CRM_Utils_Array
::value(1, $fields['field_name']) == 'contact_sub_type' &&
936 !in_array($profileType, array('Individual', 'Household', 'Organization')) &&
937 !in_array($profileType, CRM_Contact_BAO_ContactType
::subTypes())
939 $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.');
942 return empty($errors) ?
TRUE : $errors;