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
::locationType();
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
::phoneType();
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 $sel->setOptions(array($sel1, $sel2, $sel3, $sel4));
412 // proper interpretation of spec in CRM-8732
413 if (!isset($this->_id
) && in_array('Search Profile', $otherModules)) {
414 $defaults['visibility'] = 'Public Pages and Listings';
417 $js .= "</script>\n";
418 $this->assign('initHideBoxes', $js);
423 CRM_Core_SelectValues
::ufVisibility(),
425 array('onChange' => "showHideSeletorSearch(this.value);")
429 $js = array('onChange' => "mixProfile();");
430 // should the field appear in selectors (as a column)?
431 $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js);
432 $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js);
434 $attributes = CRM_Core_DAO
::getAttribute('CRM_Core_DAO_UFField');
437 $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
438 $this->addRule('weight', ts('is a numeric field'), 'numeric');
440 $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']);
441 $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']);
443 $this->add('checkbox', 'is_required', ts('Required?'));
445 $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?'));
446 $this->add('checkbox', 'is_active', ts('Active?'));
447 $this->add('checkbox', 'is_view', ts('View Only?'));
449 // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) );
450 //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) );
452 $this->add('text', 'label', ts('Field Label'), $attributes['label']);
455 if ($this->_hasSearchableORInSelector
) {
456 $js = array('onclick' => "return verify( );");
460 $this->addButtons(array(
463 'name' => ts('Save'),
469 'name' => ts('Save and New'),
475 'name' => ts('Cancel'),
480 $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this);
482 // if view mode pls freeze it with the done button.
483 if ($this->_action
& CRM_Core_Action
::VIEW
) {
485 $this->addElement('button', 'done', ts('Done'),
486 array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid
. "'")
490 if (isset($defaults['field_name']) && CRM_Utils_Array
::value(1, $defaults['field_name']) == 'url-1') {
491 $defaults['field_name'][1] = 'url';
494 $this->setDefaults($defaults);
503 public function postProcess() {
504 $ids = array('uf_group' => $this->_gid
);
505 if ($this->_action
& CRM_Core_Action
::DELETE
) {
506 $fieldValues = array('uf_group_id' => $this->_gid
);
507 CRM_Utils_Weight
::delWeight('CRM_Core_DAO_UFField', $this->_id
, $fieldValues);
508 $deleted = CRM_Core_BAO_UFField
::del($this->_id
);
510 //update group_type every time. CRM-3608
511 if ($this->_gid
&& $deleted) {
512 //get the profile type.
513 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($this->_gid
, TRUE);
514 CRM_Core_BAO_UFGroup
::updateGroupTypes($this->_gid
, $fieldsType);
517 CRM_Core_Session
::setStatus(ts('Selected Profile Field has been deleted.'), ts('Profile Field Deleted'), 'success');
521 // store the submitted values in an array
522 $params = $this->controller
->exportValues('Field');
523 if ($params['visibility'] == 'User and User Admin Only') {
524 $params['is_searchable'] = $params['in_selector'] = 0;
527 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
528 $ids['uf_field'] = $this->_id
;
533 if (isset($params['field_name'][1])) {
534 // we dont get a name for a html formatting element
535 $name = $this->_selectFields
[$params['field_name'][1]];
538 //Hack for Formatting Field Name
539 if ($params['field_name'][0] == 'Formatting') {
540 $params['field_name'][1] = 'formatting_' . rand(1000, 9999);
543 // temporary hack to for website
544 if ($params['field_name'][1] == 'url') {
545 $params['field_name'][1] = 'url-1';
548 //check for duplicate fields
549 if ($params["field_name"][0] != "Formatting" && CRM_Core_BAO_UFField
::duplicateField($params, $ids)) {
550 CRM_Core_Session
::setStatus(ts('The selected field already exists in this profile.'), ts('Field Not Added'), 'error');
554 $params['weight'] = CRM_Core_BAO_UFField
::autoWeight($params);
555 $ufField = CRM_Core_BAO_UFField
::add($params, $ids);
557 //reset other field is searchable and in selector settings, CRM-4363
558 if ($this->_hasSearchableORInSelector
&&
559 in_array($ufField->field_type
, array('Participant', 'Contribution', 'Membership', 'Activity'))
561 CRM_Core_BAO_UFField
::resetInSelectorANDSearchable($this->_gid
);
564 $config = CRM_Core_Config
::singleton();
565 $showBestResult = FALSE;
566 if (in_array($ufField->field_name
, array(
567 'country', 'state_province')) && count($config->countryLimit
) > 1) {
568 // get state or country field weight if exists
569 $field = 'state_province';
570 if ($ufField->field_name
== 'state_province') {
573 $ufFieldDAO = new CRM_Core_DAO_UFField();
574 $ufFieldDAO->field_name
= $field;
575 $ufFieldDAO->location_type_id
= $ufField->location_type_id
;
576 $ufFieldDAO->uf_group_id
= $ufField->uf_group_id
;
578 if ($ufFieldDAO->find(TRUE)) {
579 if ($field == 'country' && $ufFieldDAO->weight
> $ufField->weight
) {
580 $showBestResult = TRUE;
582 elseif ($field == 'state_province' && $ufFieldDAO->weight
< $ufField->weight
) {
583 $showBestResult = TRUE;
588 //update group_type every time. CRM-3608
589 if ($this->_gid
&& is_a($ufField, 'CRM_Core_DAO_UFField')) {
590 // get the profile type.
591 $fieldsType = CRM_Core_BAO_UFGroup
::calculateGroupType($this->_gid
, TRUE);
592 CRM_Core_BAO_UFGroup
::updateGroupTypes($this->_gid
, $fieldsType);
594 CRM_Core_Session
::setStatus(ts('Your CiviCRM Profile Field \'%1\' has been saved to \'%2\'.',
595 array(1 => $name, 2 => $this->_title
)
596 ), ts('Profile Field Saved'), 'success');
598 $buttonName = $this->controller
->getButtonName();
600 $session = CRM_Core_Session
::singleton();
601 if ($buttonName == $this->getButtonName('next', 'new')) {
602 CRM_Core_Session
::setStatus(ts(' You can add another profile field.'), '', 'info');
603 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/uf/group/field/add',
604 "reset=1&action=add&gid={$this->_gid}&sbr={$showBestResult}"
608 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/admin/uf/group/field',
609 "reset=1&action=browse&gid={$this->_gid}"
611 $session->set('showBestResult', $showBestResult);
616 * validation rule for subtype.
618 * @param array $groupType contains all groupTypes.
620 * @param string $fieldType type of field.
622 * @param array $errors
624 * @return array list of errors to be posted back to the form
628 static function formRuleSubType($fieldType, $groupType, $errors) {
629 if (in_array($fieldType, array(
630 'Participant', 'Contribution', 'Membership', 'Activity'))) {
631 $individualSubTypes = CRM_Contact_BAO_ContactType
::subTypes('Individual');
632 foreach ($groupType as $value) {
633 if (!in_array($value, $individualSubTypes) &&
634 !in_array($value, array(
635 'Participant', 'Contribution', 'Membership',
636 'Individual', 'Contact', 'Activity',
639 $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));
645 $basicType = CRM_Contact_BAO_ContactType
::getBasicType($groupType);
647 if (!is_array($basicType)) {
648 $basicType = array($basicType);
650 if (!in_array($fieldType, $basicType)) {
651 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of subtype other than "%1".',
652 array(1 => $fieldType)
660 * validation rule for custom data extends entity column values.
662 * @param Object $customField Custom field
663 * @param Integer $gid Group Id.
664 * @param String $fieldType Group type of the field
665 * @param Array $errors Collect errors
667 * @return Array list of errors to be posted back to the form
671 static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors) {
672 // fix me : check object $customField
673 if (in_array($fieldType, array(
674 'Participant', 'Contribution', 'Membership', 'Activity'))) {
675 $params = array('id' => $customField->custom_group_id
);
676 $customGroup = array();
677 CRM_Core_BAO_CustomGroup
::retrieve($params, $customGroup);
678 if (($fieldType != CRM_Utils_Array
::value('extends', $customGroup)) ||
679 !CRM_Utils_Array
::value('extends_entity_column_value', $customGroup)
684 $extendsColumnValues = array();
685 foreach (explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $customGroup['extends_entity_column_value']) as $val) {
687 $extendsColumnValues[] = $val;
691 if (empty($extendsColumnValues)) {
695 $fieldTypeValues = CRM_Core_BAO_UFGroup
::groupTypeValues($gid, $fieldType);
696 if (!CRM_Utils_Array
::value($fieldType, $fieldTypeValues)) {
700 $disallowedTypes = array_diff($extendsColumnValues, $fieldTypeValues[$fieldType]);
701 if (!empty($disallowedTypes)) {
702 $errors['field_name'] = ts('Profile is already having custom fields extending different group types, you can not add or update this custom field.');
708 * global validation rules for the form
710 * @param array $fields posted values of the form
712 * @return array list of errors to be posted back to the form
716 static function formRule($fields, $files, $self) {
717 $is_required = CRM_Utils_Array
::value('is_required', $fields, FALSE);
718 $is_registration = CRM_Utils_Array
::value('is_registration', $fields, FALSE);
719 $is_view = CRM_Utils_Array
::value('is_view', $fields, FALSE);
720 $in_selector = CRM_Utils_Array
::value('in_selector', $fields, FALSE);
721 $is_active = CRM_Utils_Array
::value('is_active', $fields, FALSE);
724 if ($is_view && $is_registration) {
725 $errors['is_registration'] = ts('View Only cannot be selected if this field is to be included on the registration form');
727 if ($is_view && $is_required) {
728 $errors['is_view'] = ts('A View Only field cannot be required');
731 $fieldName = $fields['field_name'][0];
733 $errors['field_name'] = ts('Please select a field name');
736 if ($in_selector && in_array($fieldName, array(
737 'Contribution', 'Participant', 'Membership', 'Activity'))) {
738 $errors['in_selector'] = ts("'In Selector' cannot be checked for %1 fields.", array(1 => $fieldName));
741 $isCustomField = FALSE;
742 $profileFieldName = CRM_Utils_Array
::value(1, $fields['field_name']);
743 if ($profileFieldName) {
744 //get custom field id
745 $customFieldId = explode('_', $profileFieldName);
746 if ($customFieldId[0] == 'custom') {
747 $customField = new CRM_Core_DAO_CustomField();
748 $customField->id
= $customFieldId[1];
749 $customField->find(TRUE);
750 $isCustomField = TRUE;
751 if (!empty($fields['field_id']) && !$customField->is_active
&& $is_active) {
752 $errors['field_name'] = ts('Cannot set this field "Active" since the selected custom field is disabled.');
755 //check if profile already has a different multi-record custom set field configured
756 $customGroupId = CRM_Core_BAO_CustomField
::isMultiRecordField($profileFieldName);
757 if ($customGroupId) {
758 if ($profileMultiRecordCustomGid = CRM_Core_BAO_UFField
::checkMultiRecordFieldExists($self->_gid
)) {
759 if ($customGroupId != $profileMultiRecordCustomGid) {
760 $errors['field_name'] = ts("You cannot configure multi-record custom fields belonging to different custom sets in one profile");
767 //check profile is configured for double option process
768 //adding group field, email field should be present in the group
769 //fixed for issue CRM-2861 & CRM-4153
770 if (CRM_Core_BAO_UFGroup
::isProfileDoubleOptin()) {
771 if ($fields['field_name'][1] == 'group') {
772 $dao = new CRM_Core_BAO_UFField();
773 $dao->uf_group_id
= $fields['group_id'];
776 while ($dao->fetch()) {
777 //check email field is present in the group
778 if ($dao->field_name
== 'email') {
785 $disableSettingURL = CRM_Utils_System
::url(
786 'civicrm/admin/setting/preferences/mailing',
790 $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));
796 $fieldType = $fields['field_name'][0];
798 //get the group type.
799 $groupType = CRM_Core_BAO_UFGroup
::calculateGroupType($self->_gid
, FALSE, CRM_Utils_Array
::value('field_id', $fields));
801 switch ($fieldType) {
803 self
::formRuleSubType($fieldType, $groupType, $errors);
807 if (in_array('Activity', $groupType) ||
808 in_array('Household', $groupType) ||
809 in_array('Organization', $groupType)
812 //CRM-7603 - need to support activity + individual.
813 //$errors['field_name'] =
814 //ts( 'Cannot add or update profile field type Individual with combination of Household or Organization or Activity' );
815 if (in_array('Household', $groupType) ||
816 in_array('Organization', $groupType)
818 $errors['field_name'] = ts('Cannot add or update profile field type Individual with combination of Household or Organization');
822 self
::formRuleSubType($fieldType, $groupType, $errors);
827 if (in_array('Activity', $groupType) ||
in_array('Individual', $groupType) ||
in_array('Organization', $groupType)) {
828 $errors['field_name'] = ts('Cannot add or update profile field type Household with combination of Individual or Organization or Activity');
831 self
::formRuleSubType($fieldType, $groupType, $errors);
836 if (in_array('Activity', $groupType) ||
in_array('Household', $groupType) ||
in_array('Individual', $groupType)) {
837 $errors['field_name'] = ts('Cannot add or update profile field type Organization with combination of Household or Individual or Activity');
840 self
::formRuleSubType($fieldType, $groupType, $errors);
845 if (in_array('Individual', $groupType) ||
846 in_array('Membership', $groupType) ||
847 in_array('Contribution', $groupType) ||
848 in_array('Organization', $groupType) ||
849 in_array('Household', $groupType) ||
850 in_array('Participant', $groupType)
853 //CRM-7603 - need to support activity + contact type.
854 //$errors['field_name'] =
855 //ts( 'Cannot add or update profile field type Activity with combination Participant or Membership or Contribution or Household or Organization or Individual' );
856 if (in_array('Membership', $groupType) ||
857 in_array('Contribution', $groupType) ||
858 in_array('Participant', $groupType)
860 $errors['field_name'] = ts('Cannot add or update profile field type Activity with combination Participant or Membership or Contribution');
864 self
::formRuleSubType($fieldType, $groupType, $errors);
867 if ($isCustomField && !isset($errors['field_name'])) {
868 self
::formRuleCustomDataExtentColumnValue($customField, $self->_gid
, $fieldType, $errors);
873 if (in_array('Membership', $groupType) ||
in_array('Contribution', $groupType)
874 ||
in_array('Organization', $groupType) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
876 $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');
879 self
::formRuleSubType($fieldType, $groupType, $errors);
884 //special case where in we allow contribution + oganization fields, for on behalf feature
885 $profileId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup',
886 'on_behalf_organization', 'id', 'name'
889 if (in_array('Participant', $groupType) ||
in_array('Membership', $groupType)
890 ||
($profileId != $self->_gid
&& in_array('Organization', $groupType)) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
892 $errors['field_name'] = ts('Cannot add or update profile field type Contribution with combination of Activity or Membership or Participant or Household or Organization');
895 self
::formRuleSubType($fieldType, $groupType, $errors);
900 //special case where in we allow contribution + oganization fields, for on behalf feature
901 $profileId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup',
902 'on_behalf_organization', 'id', 'name'
905 if (in_array('Participant', $groupType) ||
in_array('Contribution', $groupType)
906 ||
($profileId != $self->_gid
&& in_array('Organization', $groupType)) ||
in_array('Household', $groupType) ||
in_array('Activity', $groupType)
908 $errors['field_name'] = ts('Cannot add or update profile field type Membership with combination of Activity or Participant or Contribution or Household or Organization');
911 self
::formRuleSubType($fieldType, $groupType, $errors);
916 $profileType = CRM_Core_BAO_UFField
::getProfileType($fields['group_id'], TRUE, FALSE, TRUE);
917 if (CRM_Contact_BAO_ContactType
::isaSubType($fieldType)) {
918 if (CRM_Contact_BAO_ContactType
::isaSubType($profileType)) {
919 if ($fieldType != $profileType) {
920 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
924 $basicType = CRM_Contact_BAO_ContactType
::getBasicType($fieldType);
926 $profileType != $basicType &&
927 $profileType != 'Contact'
929 $errors['field_name'] = ts('Cannot add or update profile field type "%1" with combination of "%2".', array(1 => $fieldType, 2 => $profileType));
933 elseif ($fields['field_name'][1] == 'contact_sub_type' &&
934 !in_array($profileType, array(
935 'Individual', 'Household', 'Organization')) &&
936 !in_array($profileType, CRM_Contact_BAO_ContactType
::subTypes())
938 $errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.');
941 return empty($errors) ?
TRUE : $errors;