function buildQuickForm() { // Build list of options for individual, org and household // contact types. $ind_profile_options = array(); $house_profile_options = array(); $org_profile_options = array(); try { $params = array('rowCount' => 200); $result = civicrm_api3('UFGroup', 'get', $params); } catch (CiviCRM_API3_Exception $e) { $error = $e->getMessage(); $session = CRM_Core_Session::singleton(); $session->setStatus(ts("Failed to get list of profiles.")); return; } reset($result['values']); while (list($k, $v) = each($result['values'])) { if (array_key_exists('group_type', $v) && $v['is_active'] == 1) { $id = $v['id']; // Ensure it's not a mixed type profile, because you cannot edit mixed type // profiles if (CRM_Core_BAO_UFField::checkProfileType($id)) { continue; } if (is_array($v['group_type'])) { // Just check the first one (this is arbitrary) $group_type = array_pop($v['group_type']); } else { $group_type = $v['group_type']; } if (preg_match('/Individual/', $group_type)) { $ind_profile_options[$id] = $v['title']; } if (preg_match('/Household/', $group_type)) { $house_profile_options[$id] = $v['title']; } if (preg_match('/Organization/', $group_type)) { $org_profile_options[$id] = $v['title']; } } } if (!empty($ind_profile_options)) { $this->addElement('select', 'ind_profile_id', ts('Individual'), $ind_profile_options, NULL); } if (!empty($house_profile_options)) { $this->addElement('select', 'house_profile_id', ts('Household'), $house_profile_options, NULL); } if (!empty($org_profile_options)) { $this->addElement('select', 'org_profile_id', ts('Organization'), $org_profile_options, NULL); } $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Browse all uf data groups. * * @param * * @return void */ public function browse($action = NULL) { $ufGroup = array(); $allUFGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup(); if (empty($allUFGroups)) { return; } $ufGroups = CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); CRM_Utils_Hook::aclGroup(CRM_Core_Permission::ADMIN, NULL, 'civicrm_uf_group', $ufGroups, $allUFGroups); foreach ($allUFGroups as $id => $value) { $ufGroup[$id] = array(); $ufGroup[$id]['id'] = $id; $ufGroup[$id]['title'] = $value['title']; $ufGroup[$id]['created_id'] = $value['created_id']; $ufGroup[$id]['created_by'] = CRM_Contact_BAO_Contact::displayName($value['created_id']); $ufGroup[$id]['description'] = $value['description']; $ufGroup[$id]['is_active'] = $value['is_active']; $ufGroup[$id]['group_type'] = $value['group_type']; $ufGroup[$id]['is_reserved'] = $value['is_reserved']; // form all action links $action = array_sum(array_keys(self::actionLinks())); // update enable/disable links depending on uf_group properties. if ($value['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } // drop certain actions if the profile is reserved if ($value['is_reserved']) { $action -= CRM_Core_Action::UPDATE; $action -= CRM_Core_Action::DISABLE; $action -= CRM_Core_Action::DELETE; } $groupTypes = self::extractGroupTypes($value['group_type']); // drop Create, Edit and View mode links if profile group_type is one of the following: // Contribution, Membership, Activity, Participant, Case, Grant $isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($id); if ($isMixedProfile) { $action -= CRM_Core_Action::ADD; $action -= CRM_Core_Action::ADVANCED; $action -= CRM_Core_Action::BASIC; $action -= CRM_Core_Action::PROFILE; } $ufGroup[$id]['group_type'] = self::formatGroupTypes($groupTypes); $ufGroup[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $id), ts('more'), FALSE, 'ufGroup.row.actions', 'UFGroup', $id); //get the "Used For" from uf_join $ufGroup[$id]['module'] = implode(', ', CRM_Core_BAO_UFGroup::getUFJoinRecord($id, TRUE)); } $this->assign('rows', $ufGroup); }
/** * Submit a set of fields against a profile. * * Note choice of submit versus create is discussed CRM-13234 & related to the fact * 'profile' is being treated as a data-entry entity * * @param array $params * * @throws API_Exception * @return array * API result array */ function civicrm_api3_profile_submit($params) { $profileID = _civicrm_api3_profile_getProfileID($params['profile_id']); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_active')) { //@todo declare pseudoconstant & let api do this throw new API_Exception('Invalid value for profile_id'); } $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($profileID); if (!empty($params['id']) && CRM_Core_BAO_UFField::checkProfileType($profileID) && !$isContactActivityProfile) { throw new API_Exception('Update profiles including more than one entity not currently supported'); } $contactParams = $activityParams = $missingParams = array(); $profileFields = civicrm_api3('Profile', 'getfields', array('action' => 'submit', 'profile_id' => $profileID)); $profileFields = $profileFields['values']; if ($isContactActivityProfile) { civicrm_api3_verify_mandatory($params, NULL, array('activity_id')); $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $profileID); if (!empty($errors)) { throw new API_Exception(array_pop($errors)); } } foreach ($profileFields as $fieldName => $field) { if (!isset($params[$fieldName])) { continue; } $value = $params[$fieldName]; if ($params[$fieldName] && isset($params[$fieldName . '_id'])) { $value = $params[$fieldName . '_id']; } $contactEntities = array('contact', 'individual', 'organization', 'household'); $locationEntities = array('email', 'address', 'phone', 'website', 'im'); $entity = strtolower(CRM_Utils_Array::value('entity', $field)); if ($entity && !in_array($entity, array_merge($contactEntities, $locationEntities))) { $contactParams['api.' . $entity . '.create'][$fieldName] = $value; //@todo we are not currently declaring this option if (isset($params['batch_id']) && strtolower($entity) == 'contribution') { $contactParams['api.' . $entity . '.create']['batch_id'] = $params['batch_id']; } if (isset($params[$entity . '_id'])) { //todo possibly declare $entity_id in getfields ? $contactParams['api.' . $entity . '.create']['id'] = $params[$entity . '_id']; } } else { $contactParams[_civicrm_api3_profile_translate_fieldnames_for_bao($fieldName)] = $value; } } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.membership.create'])) { $contactParams['api.membership_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'membership_id' => '$value.api.membership.create.id'); } if (isset($contactParams['api.contribution.create']) && isset($contactParams['api.participant.create'])) { $contactParams['api.participant_payment.create'] = array('contribution_id' => '$value.api.contribution.create.id', 'participant_id' => '$value.api.participant.create.id'); } $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params); $contactParams['profile_id'] = $profileID; $contactParams['skip_custom'] = 1; $contactProfileParams = civicrm_api3_profile_apply($contactParams); // Contact profile fields $profileParams = $contactProfileParams['values']; // If profile having activity fields if ($isContactActivityProfile && !empty($activityParams)) { $activityParams['id'] = $params['activity_id']; $profileParams['api.activity.create'] = $activityParams; } return civicrm_api3('contact', 'create', $profileParams); }
/** * Function to get the uf group for a module * * @param string $moduleName module name * $param int $count no to increment the weight * * @return array $ufGroups array of ufgroups for a module * @access public * @static */ public static function getModuleUFGroup($moduleName = null, $count = 0, $skipPermission = true) { require_once 'CRM/Core/DAO.php'; $dao =& new CRM_Core_DAO(); $queryString = 'SELECT civicrm_uf_group.id, title, civicrm_uf_group.is_active, is_reserved, group_type FROM civicrm_uf_group LEFT JOIN civicrm_uf_join ON (civicrm_uf_group.id = uf_group_id)'; $p = array(); if ($moduleName) { $queryString .= ' AND civicrm_uf_group.is_active = 1 WHERE civicrm_uf_join.module = %2'; $p[2] = array($moduleName, 'String'); } // add permissioning for profiles only if not registration if (!$skipPermission) { require_once 'CRM/Core/Permission.php'; $permissionClause = CRM_Core_Permission::ufGroupClause(CRM_Core_Permission::VIEW, 'civicrm_uf_group.'); if (strpos($queryString, 'WHERE') !== false) { $queryString .= " AND {$permissionClause} "; } else { $queryString .= " {$permissionClause} "; } } $queryString .= ' ORDER BY civicrm_uf_join.weight, civicrm_uf_group.title'; $dao =& CRM_Core_DAO::executeQuery($queryString, $p); $ufGroups = array(); require_once 'CRM/Core/BAO/UFField.php'; while ($dao->fetch()) { //skip mix profiles in user Registration / User Account if (($moduleName == 'User Registration' || $moduleName == 'User Account') && CRM_Core_BAO_UFField::checkProfileType($dao->id)) { continue; } $ufGroups[$dao->id]['name'] = $dao->title; $ufGroups[$dao->id]['title'] = $dao->title; $ufGroups[$dao->id]['is_active'] = $dao->is_active; $ufGroups[$dao->id]['group_type'] = $dao->group_type; $ufGroups[$dao->id]['is_reserved'] = $dao->is_reserved; } return $ufGroups; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name'); if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); // unset unwanted fields $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'); foreach ($unsetFieldArray as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (!$addressOptions['county']) { unset($fields['Individual']['county']); unset($fields['Household']['county']); unset($fields['Organization']['county']); } //build the common contact fields array CRM-3037. foreach ($fields['Individual'] as $key => $value) { if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) { $fields['Contact'][$key] = $value; //as we move common fields to contacts. There fore these fields //are unset from resoective array's. unset($fields['Individual'][$key]); unset($fields['Household'][$key]); unset($fields['Organization'][$key]); } } // add current employer for individuals $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID')); unset($fields['Contact']['contact_type']); // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false); unset($contactTypes['']); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } unset($subTypes); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $fields['Contribution'] =& $contribFields; } } if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Query.php'; $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true); if (!empty($participantFields)) { unset($participantFields['external_identifier']); unset($participantFields['event_id']); unset($participantFields['participant_contact_id']); unset($participantFields['participant_is_test']); unset($participantFields['participant_fee_level']); unset($participantFields['participant_id']); unset($participantFields['participant_is_pay_later']); $fields['Participant'] =& $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields(); unset($membershipFields['membership_id']); unset($membershipFields['join_date']); unset($membershipFields['membership_start_date']); unset($membershipFields['membership_type_id']); unset($membershipFields['membership_end_date']); unset($membershipFields['member_is_test']); unset($membershipFields['is_override']); unset($membershipFields['status_id']); unset($membershipFields['member_is_pay_later']); $fields['Membership'] =& $membershipFields; } $noSearchable = array(); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. require_once 'CRM/Core/BAO/CustomField.php'; if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (CRM_Core_Permission::access('Quest')) { $sel1['Student'] = 'Students'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } if (!empty($membershipFields)) { $sel1['Membership'] = 'Membership'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = false; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = true; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();'); $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes); $formValues = array(); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n"; } } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onclick' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); $js = null; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * get all the registration fields * * @param int $action what action are we doing * @param int $mode mode * * @return array the fields that are needed for registration * @static * @access public */ function getRegistrationFields($action, $mode) { if ($mode & CRM_PROFILE_FORM_MODE_REGISTER) { $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration'); } else { $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('Profile'); } if (!is_array($ufGroups)) { return false; } $fields = array(); require_once "CRM/Core/BAO/UFField.php"; foreach ($ufGroups as $id => $title) { if (CRM_Core_BAO_UFField::checkProfileType($id)) { // to skip mix profiles continue; } $subset = CRM_Core_BAO_UFGroup::getFields($id, true, $action); // we do not allow duplicates. the first field is the winner foreach ($subset as $name => $field) { if (!CRM_Utils_Array::value($name, $fields)) { $fields[$name] = $field; } } } return $fields; }
/** * 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) { if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) { $errorMsg['uf_group_id'] = "You cannot select mix profile for batch update."; } if (!empty($errorMsg)) { return $errorMsg; } return TRUE; }
/** * Function to actually build the form * * @return void * @access public */ function buildQuickForm() { if ($this->_mode != CRM_PROFILE_FORM_MODE_REGISTER) { //check for mix profile (eg: individual + other contact type) require_once "CRM/Core/BAO/UFField.php"; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { CRM_Utils_System::setUFMessage(ts("This Profile includes fields for contact types other than 'Individuals' and can not be used to create/update contacts.")); $config =& CRM_Core_Config::singleton(); CRM_Utils_System::redirect($config->userFrameworkBaseURL); } } $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign('fields', $this->_fields); $this->assign('fieldset', $this->_fieldset); /* if ($this->_mode & self::MODE_EDIT) { $group =& new CRM_Core_DAO_UFGroup(); $group->id = $this->_gid; if ($group->find(true)) { $this->assign('help_pre', $group->help_pre); $this->assign('help_post', $group->help_post); } }*/ // do we need inactive options ? if ($this->_action & CRM_CORE_ACTION_VIEW) { $inactiveNeeded = true; } else { $inactiveNeeded = false; } // should we restrict what we display $admin = true; if ($this->_mode == CRM_PROFILE_FORM_MODE_EDIT) { $admin = false; $session =& CRM_Core_Session::singleton(); // show all fields that are visibile: if we are a admin or the same user or in registration mode if (CRM_Utils_System::checkPermission('administer users') || $this->_id == $session->get('userID')) { $admin = true; } } require_once "CRM/Contribute/PseudoConstant.php"; // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only') { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } $required = $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH ? false : $field['is_required']; //if ( $field['name'] === 'state_province' ) { if (substr($field['name'], 0, 14) === 'state_province') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } else { if (substr($field['name'], 0, 7) === 'country') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); } else { if ($field['name'] === 'birth_date') { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('birth'), $required); } else { if ($field['name'] === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = HTML_QuickForm::createElement('radio', null, ts('Gender'), $var, $key); } $this->addGroup($genderOptions, $field['name'], $field['title']); if ($required) { $this->addRule($field['name'], ts('%1 is a required field.', array(1 => $field['title'])), 'required'); } } else { if ($field['name'] === 'individual_prefix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } else { if ($field['name'] === 'individual_suffix') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } else { if ($field['name'] === 'preferred_communication_method') { $this->add('select', $name, $field['title'], array('' => ts('- select -')) + CRM_Core_SelectValues::pcm()); } else { if ($field['name'] === 'preferred_mail_format') { $this->add('select', $name, $field['title'], CRM_Core_SelectValues::pmf()); } else { if (substr($field['name'], 0, 3) === 'is_' or substr($field['name'], 0, 7) === 'do_not_') { $this->add('checkbox', $name, $field['title'], $field['attributes'], $required); } else { if ($field['name'] === 'group') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_GROUP, true, $required, $field['title'], null); } else { if ($field['name'] === 'tag') { require_once 'CRM/Contact/Form/GroupTag.php'; CRM_Contact_Form_GroupTag::buildGroupTagBlock($this, $this->_id, CRM_CONTACT_FORM_GROUPTAG_TAG, false, $required, null, $field['title']); } else { if (substr($field['name'], 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($field['name']); CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $customFieldID, $inactiveNeeded, $required, false, $field['title']); CRM_Core_BAO_CustomField::setProfileDefaults($customFieldID, $name, $defaults, $this->_id, $this->_mode); } else { if (in_array($field['name'], array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $this->add('date', $field['name'], $field['title'], CRM_Core_SelectValues::date('manual', 3, 1), $required); $this->addRule($field['name'], ts('Select a valid date.'), 'qfDate'); } else { if ($field['name'] == 'payment_instrument') { $this->add('select', 'payment_instrument', ts('Paid By'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } else { if ($field['name'] == 'contribution_type') { $this->add('select', 'contribution_type', ts('Contribution Type'), array('' => ts('-select-')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } else { $this->add('text', $name, $field['title'], $field['attributes'], $required); } } } } } } } } } } } } } } } if (in_array($field['name'], array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $this->addRule($field['name'], ts('Please enter a valid amount.'), 'money'); } if ($field['rule']) { if ($field['rule'] == 'email' && $this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) { continue; } else { $this->addRule($name, ts('Please enter a valid %1', array(1 => $field['title'])), $field['rule']); } } } // if view mode pls freeze it with the done button. if ($this->_action & CRM_CORE_ACTION_VIEW) { $this->freeze(); } $this->setDefaults($defaults); }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { //lets have single status message, CRM-4363 $return = false; $statusMessage = null; //we should not allow component and mix profiles in search mode if ($this->_mode != self::MODE_REGISTER) { //check for mix profile fields (eg: individual + other contact type) if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.'); } $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($this->_id) { list($contactType, $contactSubType) = CRM_Contact_BAO_Contact::getContactTypes($this->_id); if ($profileType != 'Contact' && $contactType != $profileType && !CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $return = true; if (!$statusMessage) { $statusMessage = ts('This profile is not configured for "%1" contact type.', array(1 => $contactType)); } } if ($contactSubType && CRM_Contact_BAO_ContactType::isaSubType($profileType) && $profileType != $contactSubType) { $return = true; if (!$statusMessage) { $statusMessage = ts('This profile is not configured for "%1" contact subtype.', array(1 => $contactSubType)); } } } if (in_array($profileType, array("Membership", "Participant", "Contribution"))) { $return = true; if (!$statusMessage) { $statusMessage = ts('Profile is not configured for the selected action.'); } } } //lets have sigle status message, $this->assign('statusMessage', $statusMessage); if ($return) { return false; } $sBlocks = array(); $hBlocks = array(); $config =& CRM_Core_Config::singleton(); $this->assign('id', $this->_id); $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign_by_ref('fields', $this->_fields); $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : ""); // do we need inactive options ? if ($this->_action & CRM_Core_Action::VIEW) { $inactiveNeeded = true; } else { $inactiveNeeded = false; } $session =& CRM_Core_Session::singleton(); // should we restrict what we display $admin = true; if ($this->_mode == self::MODE_EDIT) { $admin = false; // show all fields that are visibile: if we are a admin or the same user or in registration mode if (CRM_Core_Permission::check('administer users') || $this->_id == $session->get('userID')) { $admin = true; } } $userID = $session->get('userID'); $anonUser = false; // if false, user is not logged-in. if (!$userID) { require_once 'CRM/Core/BAO/LocationType.php'; $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); $primaryLocationType = $defaultLocationType->id; $anonUser = true; $this->assign('anonUser', true); } $addCaptcha = array(); $emailPresent = false; // cache the state country fields. based on the results, we could use our javascript solution // in create or register mode $stateCountryMap = array(); // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only' || CRM_Utils_Array::value('is_view', $field)) { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); if ($prefixName == 'state_province' || $prefixName == 'country') { if (!array_key_exists($index, $stateCountryMap)) { $stateCountryMap[$index] = array(); } $stateCountryMap[$index][$prefixName] = $name; } CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode); if ($field['add_to_group_id']) { $addToGroupId = $field['add_to_group_id']; } //build array for captcha if ($field['add_captcha']) { $addCaptcha[$field['group_id']] = $field['add_captcha']; } if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) { $emailPresent = true; $this->_mail = $name; } } $setCaptcha = false; // do this only for CiviCRM created forms if ($this->_mode == self::MODE_CREATE) { if (!empty($addCaptcha)) { $setCaptcha = true; } if ($this->_gid) { $dao = new CRM_Core_DAO_UFGroup(); $dao->id = $this->_gid; $dao->addSelect(); $dao->addSelect('add_captcha', 'is_update_dupe'); if ($dao->find(true)) { if ($dao->add_captcha) { $setCaptcha = true; } if ($dao->is_update_dupe) { $this->_isUpdateDupe = true; } } } if ($setCaptcha) { require_once 'CRM/Utils/ReCAPTCHA.php'; $captcha =& CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); $this->assign("isCaptcha", true); } } if ($this->_mode != self::MODE_SEARCH) { if (isset($addToGroupId)) { $this->add('hidden', "group[{$addToGroupId}]", 1); $this->_addToGroupID = $addToGroupId; } } // also do state country js require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap, $this->_defaults); $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, null); if ($this->_mode == self::MODE_CREATE) { require_once 'CRM/Core/BAO/CMSUser.php'; CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action); } else { $this->assign('showCMS', false); } $this->assign('groupId', $this->_gid); // now fix all state country selectors require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::fixAllStateSelects($this, $this->_defaults); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); } if ($this->_context == 'dialog') { $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact')); } }
/** * Function to get the uf group for a module * * @param string $moduleName module name * $param int $count no to increment the weight * * @return array $ufGroups array of ufgroups for a module * @access public * @static */ public static function getModuleUFGroup($moduleName = NULL, $count = 0, $skipPermission = TRUE) { $dao = new CRM_Core_DAO(); $queryString = 'SELECT civicrm_uf_group.id, title, civicrm_uf_group.is_active, is_reserved, group_type FROM civicrm_uf_group LEFT JOIN civicrm_uf_join ON (civicrm_uf_group.id = uf_group_id)'; $p = array(); if ($moduleName) { $queryString .= ' AND civicrm_uf_group.is_active = 1 WHERE civicrm_uf_join.module = %2'; $p[2] = array($moduleName, 'String'); } // add permissioning for profiles only if not registration if (!$skipPermission) { $permissionClause = CRM_Core_Permission::ufGroupClause(CRM_Core_Permission::VIEW, 'civicrm_uf_group.'); if (strpos($queryString, 'WHERE') !== FALSE) { $queryString .= " AND {$permissionClause} "; } else { $queryString .= " {$permissionClause} "; } } $queryString .= ' ORDER BY civicrm_uf_join.weight, civicrm_uf_group.title'; $dao = CRM_Core_DAO::executeQuery($queryString, $p); $ufGroups = array(); while ($dao->fetch()) { //skip mix profiles in user Registration / User Account if (($moduleName == 'User Registration' || $moduleName == 'User Account') && CRM_Core_BAO_UFField::checkProfileType($dao->id)) { continue; } $ufGroups[$dao->id]['name'] = $dao->title; $ufGroups[$dao->id]['title'] = $dao->title; $ufGroups[$dao->id]['is_active'] = $dao->is_active; $ufGroups[$dao->id]['group_type'] = $dao->group_type; $ufGroups[$dao->id]['is_reserved'] = $dao->is_reserved; } // Allow other modules to alter/override the UFGroups. CRM_Utils_Hook::buildUFGroupsForModule($moduleName, $ufGroups); return $ufGroups; }
/** * 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) { require_once "CRM/Core/BAO/UFField.php"; if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) { $errorMsg['uf_group_id'] = "You cannot select mix profile for batch update."; } if (!empty($errorMsg)) { return $errorMsg; } return true; }
/** * 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 */ public static function formRule($fields) { if (CRM_Core_BAO_UFField::checkProfileType($fields['uf_group_id'])) { $errorMsg['uf_group_id'] = "You cannot select a mixed profile for Update multiple contacts."; } if (!empty($errorMsg)) { return $errorMsg; } return TRUE; }
/** * Update Profile field values. * * @param array $params Associative array of property name/value * pairs to update profile field values * * @return Updated Contact/ Activity object|CRM_Error * * @todo add example * @todo add test cases * */ function civicrm_api3_profile_set($params) { civicrm_api3_verify_mandatory($params, NULL, array('profile_id')); if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $params['profile_id'], 'is_active')) { return civicrm_api3_create_error('Invalid value for profile_id'); } $isContactActivityProfile = CRM_Core_BAO_UFField::checkContactActivityProfileType($params['profile_id']); if (CRM_Core_BAO_UFField::checkProfileType($params['profile_id']) && !$isContactActivityProfile) { return civicrm_api3_create_error('Can not retrieve values for profiles include fields for more than one record type.'); } $contactParams = $activityParams = $missingParams = array(); $profileFields = CRM_Core_BAO_UFGroup::getFields($params['profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::EDIT); if ($isContactActivityProfile) { civicrm_api3_verify_mandatory($params, NULL, array('activity_id')); require_once 'CRM/Profile/Form.php'; $errors = CRM_Profile_Form::validateContactActivityProfile($params['activity_id'], $params['contact_id'], $params['profile_id']); if (!empty($errors)) { return civicrm_api3_create_error(array_pop($errors)); } } foreach ($profileFields as $fieldName => $field) { if (CRM_Utils_Array::value('is_required', $field)) { if (!CRM_Utils_Array::value($fieldName, $params) || empty($params[$fieldName])) { $missingParams[] = $fieldName; } } if (!isset($params[$fieldName])) { continue; } $value = $params[$fieldName]; if ($params[$fieldName] && isset($params[$fieldName . '_id'])) { $value = $params[$fieldName . '_id']; } if ($isContactActivityProfile && CRM_Utils_Array::value('field_type', $field) == 'Activity') { $activityParams[$fieldName] = $value; } else { $contactParams[$fieldName] = $value; } } if (!empty($missingParams)) { return civicrm_api3_create_error("Missing required parameters for profile id {$params['profile_id']}: " . implode(', ', $missingParams)); } $contactParams['version'] = 3; $contactParams['contact_id'] = CRM_Utils_Array::value('contact_id', $params); $contactParams['profile_id'] = $params['profile_id']; $contactParams['skip_custom'] = 1; $contactProfileParams = civicrm_api3_profile_apply($contactParams); if (CRM_Utils_Array::value('is_error', $contactProfileParams)) { return $contactProfileParams; } // Contact profile fields $profileParams = $contactProfileParams['values']; // If profile having activity fields if ($isContactActivityProfile && !empty($activityParams)) { $activityParams['id'] = $params['activity_id']; $profileParams['api.activity.create'] = $activityParams; } $groups = $tags = array(); if (isset($profileParams['group'])) { $groups = $profileParams['group']; unset($profileParams['group']); } if (isset($profileParams['tag'])) { $tags = $profileParams['tag']; unset($profileParams['tag']); } $result = civicrm_api('contact', 'create', $profileParams); if (CRM_Utils_Array::value('is_error', $result)) { return $result; } $ufGroupDetails = array(); $ufGroupParams = array('id' => $params['profile_id']); CRM_Core_BAO_UFGroup::retrieve($ufGroupParams, $ufGroupDetails); if (isset($profileFields['group'])) { CRM_Contact_BAO_GroupContact::create($groups, $params['contact_id'], FALSE, 'Admin'); } if (isset($profileFields['tag'])) { require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tags, 'civicrm_contact', $params['contact_id']); } if (CRM_Utils_Array::value('add_to_group_id', $ufGroupDetails)) { $contactIds = array($params['contact_id']); CRM_Contact_BAO_GroupContact::addContactsToGroup($contactIds, $ufGroupDetails['add_to_group_id']); } return $result; }
/** * Get the uf group for a module. * * @param string $moduleName * Module name. * @param int $count * No to increment the weight. * @param bool $skipPermission * @param int $op * Which operation (view, edit, create, etc) to check permission for. * @param array|NULL $returnFields list of UFGroup fields to return; NULL for default * * @return array * array of ufgroups for a module */ public static function getModuleUFGroup($moduleName = NULL, $count = 0, $skipPermission = TRUE, $op = CRM_Core_Permission::VIEW, $returnFields = NULL) { $selectFields = array('id', 'title', 'created_id', 'is_active', 'is_reserved', 'group_type'); if (!CRM_Core_Config::isUpgradeMode()) { // CRM-13555, since description field was added later (4.4), and to avoid any problems with upgrade $selectFields[] = 'description'; } if (!empty($returnFields)) { $selectFields = array_merge($returnFields, array_diff($selectFields, $returnFields)); } $queryString = 'SELECT civicrm_uf_group.' . implode(', civicrm_uf_group.', $selectFields) . ' FROM civicrm_uf_group LEFT JOIN civicrm_uf_join ON (civicrm_uf_group.id = uf_group_id)'; $p = array(); if ($moduleName) { $queryString .= ' AND civicrm_uf_group.is_active = 1 WHERE civicrm_uf_join.module = %2'; $p[2] = array($moduleName, 'String'); } // add permissioning for profiles only if not registration if (!$skipPermission) { $permissionClause = CRM_Core_Permission::ufGroupClause($op, 'civicrm_uf_group.'); if (strpos($queryString, 'WHERE') !== FALSE) { $queryString .= " AND {$permissionClause} "; } else { $queryString .= " {$permissionClause} "; } } $queryString .= ' ORDER BY civicrm_uf_join.weight, civicrm_uf_group.title'; $dao = CRM_Core_DAO::executeQuery($queryString, $p); $ufGroups = array(); while ($dao->fetch()) { //skip mix profiles in user Registration / User Account if (($moduleName == 'User Registration' || $moduleName == 'User Account') && CRM_Core_BAO_UFField::checkProfileType($dao->id)) { continue; } foreach ($selectFields as $key => $field) { if ($field == 'id') { continue; } $ufGroups[$dao->id][$field] = $dao->{$field}; } } // Allow other modules to alter/override the UFGroups. CRM_Utils_Hook::buildUFGroupsForModule($moduleName, $ufGroups); return $ufGroups; }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = CRM_Core_BAO_UFGroup::getLocationFields(); if (!$defaults['location_type_id'] && $defaults["field_type"] != "Formatting" && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_type'] == "Formatting" ? "" : $defaults['field_name'], $defaults['field_name'] == "url" ? $defaults['website_type_id'] : $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } $otherModules = array_values(CRM_Core_BAO_UFGroup::getUFJoinRecord($this->_gid)); $this->assign('otherModules', $otherModules); if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = CRM_Core_BAO_UFField::getAvailableFields($this->_gid, $defaults); $noSearchable = $hasWebsiteTypes = array(); $addressCustomFields = array_keys(CRM_Core_BAO_CustomField::getFieldsForImport('Address')); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; if (in_array($key1, $addressCustomFields)) { $noSearchable[] = $value1['title'] . ' :: ' . $customGroupName; } } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); $hasWebsiteTypes[$key][$key1] = CRM_Utils_Array::value('hasWebsiteType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); $this->_website_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); /** * FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE); unset($contactTypes['']); $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (!empty($fields['Activity'])) { $sel1['Activity'] = 'Activity'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($fields['Contribution'])) { $sel1['Contribution'] = 'Contributions'; } if (!empty($fields['Membership'])) { $sel1['Membership'] = 'Membership'; } if (!empty($fields['Case'])) { $sel1['Case'] = 'Case'; } if (!empty($fields['Formatting'])) { $sel1['Formatting'] = 'Formatting'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = NULL; $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; $sel4[$k]['phone_and_ext'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } elseif ($hasWebsiteTypes[$k][$key]) { $sel3[$k][$key] = $this->_website_types; } else { $sel3[$key] = NULL; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = FALSE; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = TRUE; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $sel =& $this->addElement('hierselect', 'field_name', ts('Field Name')); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { for ($key = 1; $key < 4; $key++) { if (!isset($formValues['field_name'][$key])) { $js .= "{$formName}['field_name[{$key}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$key}]'].style.display = '';\n"; } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); // proper interpretation of spec in CRM-8732 if (!isset($this->_id) && in_array('Search Profile', $otherModules)) { $defaults['visibility'] = 'Public Pages and Listings'; } $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), TRUE, array('onChange' => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onChange' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), NULL, NULL, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), NULL, NULL, $js); $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField'); // weight $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_pre', ts('Field Pre Help'), $attributes['help_pre']); $this->add('textarea', 'help_post', ts('Field Post Help'), $attributes['help_post']); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_multi_summary', ts('Include in multi-record listing?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), $attributes['label']); $js = NULL; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $this->add('hidden', 'gid', $this->_gid); switch ($this->_mode) { case self::MODE_CREATE: case self::MODE_EDIT: case self::MODE_REGISTER: CRM_Utils_Hook::buildProfile($this->_ufGroup['name']); break; case self::MODE_SEARCH: CRM_Utils_Hook::searchProfile($this->_ufGroup['name']); break; default: } //lets have single status message, CRM-4363 $return = FALSE; $statusMessage = NULL; if ($this->_multiRecord & CRM_Core_Action::ADD && $this->_maxRecordLimit) { return; } if ($this->_multiRecord & CRM_Core_Action::DELETE) { if (!$this->_recordExists) { CRM_Core_Session::setStatus(ts('The record %1 doesnot exists', array(1 => $this->_recordId)), ts('Record doesnot exists'), 'alert'); } else { $this->assign('deleteRecord', TRUE); } return; } CRM_Core_BAO_Address::checkContactSharedAddressFields($this->_fields, $this->_id); // we should not allow component and mix profiles in search mode if ($this->_mode != self::MODE_REGISTER) { //check for mix profile fields (eg: individual + other contact type) if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { if ($this->_mode & self::MODE_EDIT && $this->_isContactActivityProfile) { $errors = self::validateContactActivityProfile($this->_activityId, $this->_id, $this->_gid); if (!empty($errors)) { $statusMessage = array_pop($errors); $return = TRUE; } } else { $statusMessage = ts('Profile search, view and edit are not supported for Profiles which include fields for more than one record type.'); $return = TRUE; } } $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); if ($this->_id) { $contactTypes = CRM_Contact_BAO_Contact::getContactTypes($this->_id); $contactType = $contactTypes[0]; array_shift($contactTypes); $contactSubtypes = $contactTypes; $profileSubType = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileSubType = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } if ($profileType != 'Contact' && !$this->_isContactActivityProfile && ($profileSubType && !empty($contactSubtypes) && !in_array($profileSubType, $contactSubtypes) || $profileType != $contactType)) { $return = TRUE; if (!$statusMessage) { $statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.", array(1 => $profileSubType ? $profileSubType : $profileType)); } } } if (in_array($profileType, array("Membership", "Participant", "Contribution"))) { $return = TRUE; if (!$statusMessage) { $statusMessage = ts('Profile is not configured for the selected action.'); } } } //lets have single status message, $this->assign('statusMessage', $statusMessage); if ($return) { return FALSE; } $this->assign('id', $this->_id); $this->assign('mode', $this->_mode); $this->assign('action', $this->_action); $this->assign('fields', $this->_fields); $this->assign('fieldset', isset($this->_fieldset) ? $this->_fieldset : ""); // should we restrict what we display $admin = TRUE; if ($this->_mode == self::MODE_EDIT) { $admin = FALSE; // show all fields that are visibile: // if we are a admin OR the same user OR acl-user with access to the profile // or we have checksum access to this contact (i.e. the user without a login) - CRM-5909 if (CRM_Core_Permission::check('administer users') || $this->_id == $this->_currentUserID || $this->_isPermissionedChecksum || in_array($this->_gid, CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id')))) { $admin = TRUE; } } // if false, user is not logged-in. $anonUser = FALSE; if (!$this->_currentUserID) { $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); $primaryLocationType = $defaultLocationType->id; $anonUser = TRUE; } $this->assign('anonUser', $anonUser); $addCaptcha = array(); $emailPresent = FALSE; // add the form elements foreach ($this->_fields as $name => $field) { // make sure that there is enough permission to expose this field if (!$admin && $field['visibility'] == 'User and User Admin Only') { unset($this->_fields[$name]); continue; } // since the CMS manages the email field, suppress the email display if in // register mode which occur within the CMS form if ($this->_mode == self::MODE_REGISTER && substr($name, 0, 5) == 'email') { unset($this->_fields[$name]); continue; } list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); CRM_Core_BAO_UFGroup::buildProfile($this, $field, $this->_mode); if ($field['add_to_group_id']) { $addToGroupId = $field['add_to_group_id']; } //build array for captcha if ($field['add_captcha']) { $addCaptcha[$field['group_id']] = $field['add_captcha']; } if ($name == 'email-Primary' || ($name == 'email-' . isset($primaryLocationType) ? $primaryLocationType : "")) { $emailPresent = TRUE; $this->_mail = $name; } } // add captcha only for create mode. if ($this->_mode == self::MODE_CREATE) { // suppress captcha for logged in users only if ($this->_currentUserID) { $this->_isAddCaptcha = FALSE; } elseif (!$this->_isAddCaptcha && !empty($addCaptcha)) { $this->_isAddCaptcha = TRUE; } if ($this->_gid) { $dao = new CRM_Core_DAO_UFGroup(); $dao->id = $this->_gid; $dao->addSelect(); $dao->addSelect('is_update_dupe'); if ($dao->find(TRUE)) { if ($dao->is_update_dupe) { $this->_isUpdateDupe = $dao->is_update_dupe; } } } } else { $this->_isAddCaptcha = FALSE; } //finally add captcha to form. if ($this->_isAddCaptcha) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); } $this->assign("isCaptcha", $this->_isAddCaptcha); if ($this->_mode != self::MODE_SEARCH) { if (isset($addToGroupId)) { $this->_ufGroup['add_to_group_id'] = $addToGroupId; } } //let's do set defaults for the profile $this->setDefaultsValues(); $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, NULL); if ($this->_mode == self::MODE_CREATE) { CRM_Core_BAO_CMSUser::buildForm($this, $this->_gid, $emailPresent, $action); } else { $this->assign('showCMS', FALSE); } $this->assign('groupId', $this->_gid); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); } if ($this->_context == 'dialog') { $this->addElement('submit', $this->_duplicateButtonName, ts('Save Matching Contact')); } }
/** * 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); $isMixedProfile = CRM_Core_BAO_UFField::checkProfileType($this->_gid); if ($isMixedProfile) { $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(self::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); }