/** * Process the user submitted custom data values. * * * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //if the delete record button is clicked if ($this->_deleteButtonName) { if (!empty($_POST[$this->_deleteButtonName]) && $this->_recordId) { $filterParams['id'] = $this->_customGroupId; $returnProperties = array('is_multiple', 'table_name'); CRM_Core_DAO::commonRetrieve("CRM_Core_DAO_CustomGroup", $filterParams, $returnValues, $returnProperties); if (!empty($returnValues['is_multiple'])) { if ($tableName = CRM_Utils_Array::value('table_name', $returnValues)) { $sql = "DELETE FROM {$tableName} WHERE id = %1 AND entity_id = %2"; $sqlParams = array(1 => array($this->_recordId, 'Integer'), 2 => array($this->_id, 'Integer')); CRM_Core_DAO::executeQuery($sql, $sqlParams); CRM_Core_Session::setStatus(ts('Your record has been deleted.'), ts('Deleted'), 'success'); } } return; } } CRM_Utils_Hook::processProfile($this->_ufGroup['name']); if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id'); $details = array(); if ($this->_id) { $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes); $details = $contactDetails[0][$this->_id]; } if (!(!empty($details['addressee_id']) || !empty($details['email_greeting_id']) || CRM_Utils_Array::value('postal_greeting_id', $details))) { $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); //Though Profile type is contact we need //Individual/Household/Organization for setting Greetings. if ($profileType == 'Contact') { $profileType = 'Individual'; //if we editing Household/Organization. if ($this->_id) { $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id); } } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } foreach ($greetingTypes as $key => $value) { if (!array_key_exists($key, $params)) { $params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key); } } } $transaction = new CRM_Core_Transaction(); //used to send subscribe mail to the group which user want. //if the profile double option in is enabled $mailingType = array(); $result = NULL; foreach ($params as $name => $values) { if (substr($name, 0, 6) == 'email-') { $result['email'] = $values; } } //array of group id, subscribed by contact $contactGroup = array(); if (!empty($params['group']) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { $groupSubscribed = array(); if (!empty($result['email'])) { if ($this->_id) { $contactGroups = new CRM_Contact_DAO_GroupContact(); $contactGroups->contact_id = $this->_id; $contactGroups->status = 'Added'; $contactGroups->find(); $contactGroup = array(); while ($contactGroups->fetch()) { $contactGroup[] = $contactGroups->group_id; $groupSubscribed[$contactGroups->group_id] = 1; } } foreach ($params['group'] as $key => $val) { if (!$val) { unset($params['group'][$key]); continue; } $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id'); $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1)); //filter group of mailing type and unset it from params if (in_array(2, $groupType)) { //if group is already subscribed , ignore it $groupExist = CRM_Utils_Array::key($key, $contactGroup); if (!isset($groupExist)) { $mailingType[] = $key; unset($params['group'][$key]); } } } } } $addToGroupId = CRM_Utils_Array::value('add_to_group_id', $this->_ufGroup); if (!empty($addToGroupId)) { //run same check whether group is a mailing list $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $addToGroupId, 'group_type', 'id'); $groupType = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($groupTypes, 1, -1)); //filter group of mailing type and unset it from params if (in_array(2, $groupType) && !empty($result['email']) && CRM_Core_BAO_UFGroup::isProfileAddToGroupDoubleOptin()) { if (!count($contactGroup)) { //array of group id, subscribed by contact $contactGroup = array(); if ($this->_id) { $contactGroups = new CRM_Contact_DAO_GroupContact(); $contactGroups->contact_id = $this->_id; $contactGroups->status = 'Added'; $contactGroups->find(); $contactGroup = array(); while ($contactGroups->fetch()) { $contactGroup[] = $contactGroups->group_id; $groupSubscribed[$contactGroups->group_id] = 1; } } } //if group is already subscribed , ignore it $groupExist = CRM_Utils_Array::key($addToGroupId, $contactGroup); if (!isset($groupExist)) { $mailingType[] = $addToGroupId; $addToGroupId = NULL; } } else { // since we are directly adding contact to group lets unset it from mailing if ($key = array_search($addToGroupId, $mailingType)) { unset($mailingType[$key]); } } } if ($this->_grid) { $params['group'] = $groupSubscribed; } // commenting below code, since we potentially // triggered maximum name field formatting cases during CRM-4430. // CRM-4343 // $params['preserveDBName'] = true; $profileFields = $this->_fields; if ($this->_mode & self::MODE_EDIT && $this->_activityId && $this->_isContactActivityProfile) { $profileFields = $activityParams = array(); foreach ($this->_fields as $fieldName => $field) { if (CRM_Utils_Array::value('field_type', $field) == 'Activity') { if (isset($params[$fieldName])) { $activityParams[$fieldName] = $params[$fieldName]; } if (isset($params['activity_date_time'])) { $activityParams['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); } if (!empty($params[$fieldName]) && isset($params["{$fieldName}_id"])) { $activityParams[$fieldName] = $params["{$fieldName}_id"]; } } else { $profileFields[$fieldName] = $field; } } if (!empty($activityParams)) { $activityParams['version'] = 3; $activityParams['id'] = $this->_activityId; $activityParams['skipRecentView'] = TRUE; civicrm_api('Activity', 'create', $activityParams); } } if ($this->_multiRecord && $this->_recordId && $this->_multiRecordFields && $this->_recordExists) { $params['customRecordValues'][$this->_recordId] = array_keys($this->_multiRecordFields); } $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $profileFields, $this->_id, $addToGroupId, $this->_gid, $this->_ctype, TRUE); //mailing type group if (!empty($mailingType)) { // we send in the contactID so we match the same groups and are exact, rather than relying on email // CRM-8710 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result, $this->_id, 'profile'); } $ufGroups = array(); if ($this->_gid) { $ufGroups[$this->_gid] = 1; } elseif ($this->_mode == self::MODE_REGISTER) { $ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration'); } foreach ($ufGroups as $gId => $val) { if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) { $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, NULL); CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values); } } //create CMS user (if CMS user option is selected in profile) if (!empty($params['cms_create_account']) && $this->_mode == self::MODE_CREATE) { $params['contactID'] = $this->_id; if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) { CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.'), ts('Profile Error'), 'error'); CRM_Core_Error::debug_log_message("Rolling back transaction as CMSUser Create failed in Profile_Form for contact " . $params['contactID']); $transaction->rollback(); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid)); } } $transaction->commit(); }
/** * Set profile defaults. * * @param int $contactId * Contact id. * @param array $fields * Associative array of fields. * @param array $defaults * Defaults array. * @param bool $singleProfile * True for single profile else false(batch update). * @param int $componentId * Id for specific components like contribute, event etc. * @param null $component */ public static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = TRUE, $componentId = NULL, $component = NULL) { if (!$componentId) { //get the contact details list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields); $details = CRM_Utils_Array::value($contactId, $contactDetails); $multipleFields = array('website' => 'url'); //start of code to set the default values foreach ($fields as $name => $field) { // skip pseudo fields if (substr($name, 0, 9) == 'phone_ext') { continue; } //set the field name depending upon the profile mode(single/batch) if ($singleProfile) { $fldName = $name; } else { $fldName = "field[{$contactId}][{$name}]"; } if ($name == 'group') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName); } if ($name == 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName); } if (!empty($details[$name]) || isset($details[$name])) { //to handle custom data (checkbox) to be written // to handle birth/deceased date, greeting_type and few other fields if ($name == 'birth_date' || $name == 'deceased_date') { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth'); } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $defaults[$fldName] = $details[$name . '_id']; $defaults[$name . '_custom'] = $details[$name . '_custom']; } elseif ($name == 'preferred_communication_method') { $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName . "[{$item}]"] = 1; } } } elseif ($name == 'contact_sub_type') { $defaults[$fldName] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($details[$name], CRM_Core_DAO::VALUE_SEPARATOR)); } elseif ($name == 'world_region') { $defaults[$fldName] = $details['worldregion_id']; } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) { //fix for custom fields $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details)); // hack to add custom data for components $components = array('Contribution', 'Participant', 'Membership', 'Activity'); foreach ($components as $value) { $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value)); } switch ($customFields[$customFieldId]['html_type']) { case 'Multi-Select State/Province': case 'Multi-Select Country': case 'AdvMulti-Select': case 'Multi-Select': $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = $item; } } break; case 'CheckBox': $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = 1; // seems like we need this for QF style checkboxes in profile where its multiindexed // CRM-2969 $defaults["{$fldName}[{$item}]"] = 1; } } break; case 'Select Date': // CRM-6681, set defult values according to date and time format (if any). $dateFormat = NULL; if (!empty($customFields[$customFieldId]['date_format'])) { $dateFormat = $customFields[$customFieldId]['date_format']; } if (empty($customFields[$customFieldId]['time_format'])) { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat); } else { $timeElement = $fldName . '_time'; if (substr($fldName, -1) == ']') { $timeElement = substr($fldName, 0, -1) . '_time]'; } list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat, $customFields[$customFieldId]['time_format']); } break; default: $defaults[$fldName] = $details[$name]; break; } } else { $defaults[$fldName] = $details[$name]; } } else { $blocks = array('email', 'phone', 'im', 'openid'); list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if (is_array($details)) { foreach ($details as $key => $value) { // when we fixed CRM-5319 - get primary loc // type as per loc field and removed below code. $primaryLocationType = FALSE; if ($locTypeId == 'Primary') { if (is_array($value) && array_key_exists($fieldName, $value)) { $primaryLocationType = TRUE; if (in_array($fieldName, $blocks)) { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, $fieldName); } else { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, 'address'); } } } // fixed for CRM-665 if (is_numeric($locTypeId)) { if ($primaryLocationType || $locTypeId == CRM_Utils_Array::value('location_type_id', $value)) { if (!empty($value[$fieldName])) { //to handle stateprovince and country if ($fieldName == 'state_province') { $defaults[$fldName] = $value['state_province_id']; } elseif ($fieldName == 'county') { $defaults[$fldName] = $value['county_id']; } elseif ($fieldName == 'country') { if (!isset($value['country_id']) || !$value['country_id']) { $config = CRM_Core_Config::singleton(); if ($config->defaultContactCountry) { $defaults[$fldName] = $config->defaultContactCountry; } } else { $defaults[$fldName] = $value['country_id']; } } elseif ($fieldName == 'phone') { if ($phoneTypeId) { if (isset($value['phone'][$phoneTypeId])) { $defaults[$fldName] = $value['phone'][$phoneTypeId]; } if (isset($value['phone_ext'][$phoneTypeId])) { $defaults[str_replace('phone', 'phone_ext', $fldName)] = $value['phone_ext'][$phoneTypeId]; } } else { $phoneDefault = CRM_Utils_Array::value('phone', $value); // CRM-9216 if (!is_array($phoneDefault)) { $defaults[$fldName] = $phoneDefault; } } } elseif ($fieldName == 'email') { //adding the first email (currently we don't support multiple emails of same location type) $defaults[$fldName] = $value['email']; } elseif ($fieldName == 'im') { //adding the first im (currently we don't support multiple ims of same location type) $defaults[$fldName] = $value['im']; $defaults[$fldName . '-provider_id'] = $value['im_provider_id']; } else { $defaults[$fldName] = $value[$fieldName]; } } elseif (substr($fieldName, 0, 14) === 'address_custom' && CRM_Utils_Array::value(substr($fieldName, 8), $value)) { $defaults[$fldName] = $value[substr($fieldName, 8)]; } } } } } } else { if (is_array($details)) { if ($fieldName === 'url' && !empty($details['website']) && !empty($details['website'][$locTypeId])) { $defaults[$fldName] = CRM_Utils_Array::value('url', $details['website'][$locTypeId]); } } } } } } //Handling Contribution Part of the batch profile if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Event Participation Part of the batch profile if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling membership Part of the batch profile if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Activity Part of the batch profile if ($component == 'Activity') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } }
/** * pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. * * @param * @return void * * @access public */ function preProcess() { require_once 'CRM/Core/BAO/UFGroup.php'; $this->_id = $this->get('id'); $this->_gid = $this->get('gid'); if (!$this->_gid) { $this->_gid = CRM_Utils_Request::retrieve('gid', $this, false, 0, 'GET'); } // if we dont have a gid use the default, else just use that specific gid if (($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER || $this->_mode == CRM_PROFILE_FORM_MODE_CREATE) && !$this->_gid) { $this->_fields = CRM_Core_BAO_UFGroup::getRegistrationFields($this->_action, $this->_mode); } else { if ($this->_mode == CRM_PROFILE_FORM_MODE_SEARCH) { $this->_fields = CRM_Core_BAO_UFGroup::getListingFields($this->_action, CRM_CORE_BAO_UFGROUP_LISTINGS_VISIBILITY, false, $this->_gid, true); } else { $this->_fields = CRM_Core_BAO_UFGroup::getFields($this->_gid, false, $this->_action); } } if (!is_array($this->_fields)) { $session =& CRM_Core_Session::singleton(); CRM_Core_Session::setStatus(ts('This feature is not currently available.')); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm', 'reset=1')); } if ($this->_id) { $defaults = array(); // get the contact details (hier) list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $this->_fields); $this->_contact = $details = $contactDetails[$this->_id]; //start of code to set the default values foreach ($this->_fields as $name => $field) { if (CRM_Utils_Array::value($name, $details)) { //to handle custom data (checkbox) to be written // to handle gender / suffix / prefix if ($name == 'gender') { $defaults[$name] = $details['gender_id']; } else { if ($name == 'individual_prefix') { $defaults[$name] = $details['individual_prefix_id']; } else { if ($name == 'individual_suffix') { $defaults[$name] = $details['individual_suffix_id']; } else { if (substr($name, 0, 6) == 'custom') { /* $cfID = CRM_Core_BAO_CustomField::getKeyID($name); $cf =& new CRM_Core_BAO_CustomField(); $cf->id = $cfID; if ( $cf->find( true ) ) { switch($cf->html_type) { case 'Select Date': $defaults[$name] = CRM_Utils_Date::unformat( $details[$name], '-'); break; case 'CheckBox': $data = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); if (is_array($data)) { foreach($data as $key) { $checked[$key] = 1; } $defaults[$name] = $checked; } break; default: $defaults[$name] = $details[$name]; } } */ } else { $defaults[$name] = $details[$name]; } } } } } else { $nameValue = explode('-', $name); foreach ($details as $key => $value) { if (is_numeric($nameValue[1])) { //fixed for CRM-665 if ($nameValue[1] == $value['location_type_id']) { if (CRM_Utils_Array::value($nameValue[0], $value)) { //to handle stateprovince and country if ($nameValue[0] == 'state_province') { $defaults[$name] = $value['state_province_id']; } else { if ($nameValue[0] == 'country') { $defaults[$name] = $value['country_id']; } else { if ($nameValue[0] == 'phone') { if ($nameValue[2]) { $defaults[$name] = $value['phone'][$nameValue[2]]; } else { $defaults[$name] = $value['phone'][1]; } } else { if ($nameValue[0] == 'email') { //adding the first email (currently we don't support multiple emails of same location type) $defaults[$name] = $value['email'][1]; } else { if ($nameValue[0] == 'im') { //adding the first email (currently we don't support multiple ims of same location type) $defaults[$name] = $value['im'][1]; } else { $defaults[$name] = $value[$nameValue[0]]; } } } } } } } } } } } $this->setDefaults($defaults); //end of code to set the default values } }
/** * Function to set profile defaults * * @params int $contactId contact id * @params array $fields associative array of fields * @params array $defaults defaults array * @params boolean $singleProfile true for single profile else false(batch update) * @params int $componentId id for specific components like contribute, event etc * * @return null * @static * @access public */ static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = true, $componentId = null, $component = null) { if (!$componentId) { //get the contact details require_once 'CRM/Contact/BAO/Contact.php'; list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields); $details = $contactDetails[$contactId]; require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; //start of code to set the default values foreach ($fields as $name => $field) { //set the field name depending upon the profile mode(single/batch) if ($singleProfile) { $fldName = $name; } else { $fldName = "field[{$contactId}][{$name}]"; } if ($name == 'group') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName); } if ($name == 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName); } if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) { //to handle custom data (checkbox) to be written // to handle gender / suffix / prefix / greeting_type if ($name == 'gender') { $defaults[$fldName] = $details['gender_id']; } else { if ($name == 'individual_prefix') { $defaults[$fldName] = $details['individual_prefix_id']; } else { if ($name == 'individual_suffix') { $defaults[$fldName] = $details['individual_suffix_id']; } else { if ($name == 'birth_date' || $name == 'deceased_date') { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth'); } else { if ($name == 'email_greeting') { $defaults[$fldName] = $details['email_greeting_id']; $defaults['email_greeting_custom'] = $details['email_greeting_custom']; } else { if ($name == 'postal_greeting') { $defaults[$fldName] = $details['postal_greeting_id']; $defaults['postal_greeting_custom'] = $details['postal_greeting_custom']; } else { if ($name == 'addressee') { $defaults[$fldName] = $details['addressee_id']; $defaults['addressee_custom'] = $details['addressee_custom']; } else { if ($name == 'preferred_communication_method') { $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName . "[{$item}]"] = 1; } } } else { if ($name == 'world_region') { $defaults[$fldName] = $details['worldregion_id']; } else { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) { //fix for custom fields $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('Individual', $values)); // hack to add custom data for components $components = array("Contribution", "Participant", "Membership"); foreach ($components as $value) { $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value)); } switch ($customFields[$customFieldId]['html_type']) { case 'Multi-Select State/Province': case 'Multi-Select Country': case 'AdvMulti-Select': case 'Multi-Select': $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = $item; } } break; case 'CheckBox': $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = 1; // seems like we need this for QF style checkboxes in profile where its multiindexed // CRM-2969 $defaults["{$fldName}[{$item}]"] = 1; } } break; case 'Autocomplete-Select': if ($customFields[$customFieldId]['data_type'] == "ContactReference") { require_once 'CRM/Contact/BAO/Contact.php'; if (is_numeric($details[$name])) { $defaults[$fldName . '_id'] = $details[$name]; $defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name'); } } else { $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]); $defaults[$fldName . '_id'] = $details[$name]; $defaults[$fldName] = $label; } break; case 'Select Date': list($defaults[$fldName], $defaults[substr($fldName, 0, -1) . '_time]']) = CRM_Utils_Date::setDateDefaults($details[$name]); break; default: $defaults[$fldName] = $details[$name]; break; } } else { $defaults[$fldName] = $details[$name]; } } } } } } } } } } } else { list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3); if (is_array($details)) { foreach ($details as $key => $value) { // when we fixed CRM-5319 - get primary loc // type as per loc field and removed below code. if ($locTypeId == 'Primary') { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId); } if (is_numeric($locTypeId)) { //fixed for CRM-665 if ($locTypeId == CRM_Utils_Array::value('location_type_id', $value)) { if (CRM_Utils_Array::value($fieldName, $value)) { //to handle stateprovince and country if ($fieldName == 'state_province') { $defaults[$fldName] = $value['state_province_id']; } else { if ($fieldName == 'county') { $defaults[$fldName] = $value['county_id']; } else { if ($fieldName == 'country') { $defaults[$fldName] = $value['country_id']; if (!isset($value['country_id']) || !$value['country_id']) { $config =& CRM_Core_Config::singleton(); if ($config->defaultContactCountry) { $defaults[$fldName] = $config->defaultContactCountry; } } } else { if ($fieldName == 'phone') { if ($phoneTypeId) { if ($value['phone'][$phoneTypeId]) { $defaults[$fldName] = $value['phone'][$phoneTypeId]; } } else { $defaults[$fldName] = $value['phone']; } } else { if ($fieldName == 'email') { //adding the first email (currently we don't support multiple emails of same location type) $defaults[$fldName] = $value['email']; } else { if ($fieldName == 'im') { //adding the first im (currently we don't support multiple ims of same location type) $defaults[$fldName] = $value['im']; $defaults[$fldName . "-provider_id"] = $value['im_provider_id']; } else { $defaults[$fldName] = $value[$fieldName]; } } } } } } } } } } } } } if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; // Checking whether the database contains quest_student table. // Now there are two different schemas for core and quest. // So if only core schema in use then withought following check gets the DB error. $student = new CRM_Quest_BAO_Student(); $tableStudent = $student->getTableName(); if ($tableStudent) { //set student defaults CRM_Quest_BAO_Student::retrieve($details, $studentDefaults, $ids); $studentFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring'); foreach ($studentFields as $fld) { if ($studentDefaults[$fld]) { $values = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $studentDefaults[$fld]); } $studentDefaults[$fld] = array(); if (is_array($values)) { foreach ($values as $v) { $studentDefaults[$fld][$v] = 1; } } } foreach ($fields as $name => $field) { $fldName = "field[{$contactId}][{$name}]"; if (array_key_exists($name, $studentDefaults)) { $defaults[$fldName] = $studentDefaults[$name]; } } } } } //Handling Contribution Part of the batch profile if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Event Participation Part of the batch profile if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling membership Part of the batch profile if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } }
/** * Process the user submitted custom data values. * * @access public * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('image_URL', $params)) { CRM_Contact_BAO_Contact::processImageParams($params); } $greetingTypes = array('addressee' => 'addressee_id', 'email_greeting' => 'email_greeting_id', 'postal_greeting' => 'postal_greeting_id'); if ($this->_id) { $contactDetails = CRM_Contact_BAO_Contact::getHierContactDetails($this->_id, $greetingTypes); $details = $contactDetails[0][$this->_id]; } if (!(CRM_Utils_Array::value('addressee_id', $details) || CRM_Utils_Array::value('email_greeting_id', $details) || CRM_Utils_Array::value('postal_greeting_id', $details))) { $profileType = CRM_Core_BAO_UFField::getProfileType($this->_gid); //Though Profile type is contact we need //Individual/Household/Organization for setting Greetings. if ($profileType == 'Contact') { $profileType = 'Individual'; //if we editing Household/Organization. if ($this->_id) { $profileType = CRM_Contact_BAO_Contact::getContactType($this->_id); } } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $contactTypeFilters = array(1 => 'Individual', 2 => 'Household', 3 => 'Organization'); $filter = CRM_Utils_Array::key($profileType, $contactTypeFilters); if ($filter) { foreach ($greetingTypes as $key => $value) { if (!array_key_exists($key, $params)) { $defaultGreetingTypeId = CRM_Core_OptionGroup::values($key, null, null, null, "AND is_default =1\n AND (filter = \n {$filter} OR \n filter = 0 )", 'value'); $params[$key] = key($defaultGreetingTypeId); } } } if ($profileType == 'Organization') { unset($params['email_greeting'], $params['postal_greeting']); } } if ($this->_mode == self::MODE_REGISTER) { require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::setOverwrite(false); } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); //used to send subcribe mail to the group which user want. //if the profile double option in is enabled $mailingType = array(); $config = CRM_Core_Config::singleton(); if ($config->profileDoubleOptIn && CRM_Utils_Array::value('group', $params)) { $result = null; foreach ($params as $name => $values) { if (substr($name, 0, 6) == 'email-') { $result['email'] = $values; } } $groupSubscribed = array(); if (CRM_Utils_Array::value('email', $result)) { require_once 'CRM/Contact/DAO/Group.php'; //array of group id, subscribed by contact $contactGroup = array(); if ($this->_id) { $contactGroups = new CRM_Contact_DAO_GroupContact(); $contactGroups->contact_id = $this->_id; $contactGroups->status = 'Added'; $contactGroups->find(); $contactGroup = array(); while ($contactGroups->fetch()) { $contactGroup[] = $contactGroups->group_id; $groupSubscribed[$contactGroups->group_id] = 1; } } foreach ($params['group'] as $key => $val) { if (!$val) { unset($params['group'][$key]); continue; } $groupTypes = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $key, 'group_type', 'id'); $groupType = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($groupTypes, 1, -1)); //filter group of mailing type and unset it from params if (in_array(2, $groupType)) { //if group is already subscribed , ignore it $groupExist = CRM_Utils_Array::key($key, $contactGroup); if (!isset($groupExist)) { $mailingType[] = $key; unset($params['group'][$key]); } } } } } if (CRM_Utils_Array::value('add_to_group', $params)) { $addToGroupId = $params['add_to_group']; // since we are directly adding contact to group lets unset it from mailing if ($key = array_search($addToGroupId, $mailingType)) { unset($mailingType[$key]); } } if ($this->_grid) { $params['group'] = $groupSubscribed; } // commenting below code, since we potentially // triggered maximum name field formatting cases during CRM-4430. // CRM-4343 // $params['preserveDBName'] = true; $this->_id = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_fields, $this->_id, $this->_addToGroupID, $this->_gid, $this->_ctype, true); //mailing type group if (!empty($mailingType)) { require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($mailingType, $result); } require_once 'CRM/Core/BAO/UFGroup.php'; $ufGroups = array(); if ($this->_gid) { $ufGroups[$this->_gid] = 1; } else { if ($this->_mode == self::MODE_REGISTER) { $ufGroups =& CRM_Core_BAO_UFGroup::getModuleUFGroup('User Registration'); } } foreach ($ufGroups as $gId => $val) { if ($notify = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify')) { $values = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $this->_id, null); CRM_Core_BAO_UFGroup::commonSendMail($this->_id, $values); } } //create CMS user (if CMS user option is selected in profile) if (CRM_Utils_Array::value('cms_create_account', $params) && $this->_mode == self::MODE_CREATE) { $params['contactID'] = $this->_id; require_once "CRM/Core/BAO/CMSUser.php"; if (!CRM_Core_BAO_CMSUser::create($params, $this->_mail)) { CRM_Core_Session::setStatus(ts('Your profile is not saved and Account is not created.')); $transaction->rollback(); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid)); } } $transaction->commit(); }