/** * Process the user submitted custom data values. * * @access public * @return void */ public function postProcess() { $params = $this->controller->exportValues($this->_name); 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 ($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(); }
/** * 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'); $details = array(); 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); } foreach ($greetingTypes as $key => $value) { if (!array_key_exists($key, $params)) { $params[$key] = CRM_Contact_BAO_Contact_Utils::defaultGreeting($profileType, $key); } } } if ($this->_mode == self::MODE_REGISTER) { CRM_Core_BAO_Address::setOverwrite(FALSE); } $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(); $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 (CRM_Utils_Array::value('group', $params) && CRM_Core_BAO_UFGroup::isProfileDoubleOptin()) { $groupSubscribed = array(); if (CRM_Utils_Array::value('email', $result)) { 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 = NULL; if (CRM_Utils_Array::value('add_to_group', $params)) { $addToGroupId = $params['add_to_group']; //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) && CRM_Utils_Array::value('email', $result) && 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 (CRM_Utils_Array::value($fieldName, $params) && 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; $activity = civicrm_api('Activity', 'create', $activityParams); } } $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 (CRM_Utils_Array::value('cms_create_account', $params) && $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.')); $transaction->rollback(); return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/profile/create', 'reset=1&gid=' . $this->_gid)); } } $transaction->commit(); }
/** * Process the user submitted custom data values. * * @access public * @return void */ function postProcess() { $params = $this->controller->exportValues($this->_name); $data = array(); $data['contact_type'] = 'Individual'; //get the custom fields for the contact $customFields = CRM_Core_BAO_CustomField::getFields($data['contact_type']); $locationType = array(); $count = 1; if ($this->_id) { $primaryLocationType = CRM_Contact_BAO_Contact::getPrimaryLocationType($this->_id); } $phoneLoc = 0; foreach ($params as $key => $value) { $keyValue = explode('-', $key); if (is_numeric($keyValue[1])) { if (!in_array($keyValue[1], $locationType)) { $locationType[$count] = $keyValue[1]; $count++; } require_once 'CRM/Utils/Array.php'; $loc = CRM_Utils_Array::key($keyValue[1], $locationType); $data['location'][$loc]['location_type_id'] = $keyValue[1]; if ($this->_id) { //get the primary location type if ($keyValue[1] == $primaryLocationType) { $data['location'][$loc]['is_primary'] = 1; } } else { if ($loc == 1) { $data['location'][$loc]['is_primary'] = 1; } } if ($keyValue[0] == 'name') { $data['location'][$loc]['name'] = $value; } else { if ($keyValue[0] == 'phone') { $phoneLoc++; if ($keyValue[2]) { $data['location'][$loc]['phone'][$phoneLoc]['phone_type'] = $keyValue[2]; } else { $data['location'][$loc]['phone'][$phoneLoc]['phone_type'] = ''; $data['location'][$loc]['phone'][$phoneLoc]['is_primary'] = 1; } $data['location'][$loc]['phone'][$phoneLoc]['phone'] = $value; } else { if ($keyValue[0] == 'email') { $data['location'][$loc]['email'][1]['email'] = $value; $data['location'][$loc]['email'][1]['is_primary'] = 1; } else { if ($keyValue[0] == 'im') { $data['location'][$loc]['im'][1]['name'] = $value; $data['location'][$loc]['im'][1]['is_primary'] = 1; } else { if ($keyValue[0] === 'state_province') { $data['location'][$loc]['address']['state_province_id'] = $value; } else { if ($keyValue[0] === 'country') { $data['location'][$loc]['address']['country_id'] = $value; } else { $data['location'][$loc]['address'][$keyValue[0]] = $value; } } } } } } } else { if ($key === 'individual_suffix') { $data['suffix_id'] = $value; } else { if ($key === 'individual_prefix') { $data['prefix_id'] = $value; } else { if ($key === 'gender') { $data['gender_id'] = $value; } else { if (substr($key, 0, 6) === 'custom') { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { //fix checkbox if ($customFields[$customFieldID][3] == 'CheckBox') { $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, array_keys($value)); } if ($customFields[$customFieldID][3] == 'Multi-Select') { $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $value); } // fix the date field if ($customFields[$customFieldID][2] == 'Date') { $date = CRM_Utils_Date::format($value); if (!$date) { $date = ''; } $value = $date; } //to add the id of custom value if exits //$this->_contact['custom_value_5_id'] = 123; $str = 'custom_value_' . $customFieldID . '_id'; if ($this->_contact[$str]) { $id = $this->_contact[$str]; } $data['custom'][$customFieldID] = array('id' => $id, 'value' => $value, 'extends' => $customFields[$customFieldID][3], 'type' => $customFields[$customFieldID][2], 'custom_field_id' => $customFieldID); } } else { if ($key == 'edit') { continue; } else { $data[$key] = $value; } } } } } } } // fix all the custom field checkboxes which are empty foreach ($this->_fields as $name => $field) { $cfID = CRM_Core_BAO_CustomField::getKeyID($name); // if there is a custom field of type checkbox and it has not been set // then set it to null, thanx to html protocol if ($cfID && $customFields[$cfID][3] == 'CheckBox' && CRM_Utils_Array::value('custom', $data) && !CRM_Utils_Array::value($cfID, $data['custom'])) { $str = 'custom_value_' . $cfID . '_id'; if ($this->_contact[$str]) { $id = $this->_contact[$str]; } $data['custom'][$cfID] = array('id' => $id, 'value' => '', 'extends' => $customFields[$cfID][3], 'type' => $customFields[$cfID][2], 'custom_field_id' => $cfID); } } if ($this->_id) { $objects = array('contact_id', 'individual_id', 'location_id', 'address_id'); $ids = array(); $phoneLoc = 0; foreach ($this->_fields as $name => $field) { $nameValue = explode('-', $name); foreach ($this->_contact as $key => $value) { if (in_array($key, $objects)) { $ids[substr($key, 0, strlen($key) - 3)] = $value; } else { if (is_array($value)) { //fixed for CRM-665 if ($nameValue[1] == $value['location_type_id']) { $locations[$value['location_type_id']] = 1; $loc_no = count($locations); if ($nameValue[0] == 'phone') { $phoneLoc++; if (isset($nameValue[2])) { $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone'][$nameValue[2] . '_id']; } else { $ids['location'][$loc_no]['phone'][$phoneLoc] = $value['phone']['1_id']; } } else { if ($nameValue[0] == 'im') { $ids['location'][$loc_no]['im'][1] = $value['im']['1_id']; } else { if ($nameValue[0] == 'email') { $ids['location'][$loc_no]['email'][1] = $value['email']['1_id']; } else { $ids['location'][$loc_no]['address'] = $value['address_id']; } } } $ids['location'][$loc_no]['id'] = $value['location_id']; } } } } } } //set the values for checkboxes (do_not_email, do_not_mail, do_not_trade, do_not_phone) $privacy = CRM_Core_SelectValues::privacy(); foreach ($privacy as $key => $value) { if (array_key_exists($key, $this->_fields)) { if ($params[$key]) { $data[$key] = $params[$key]; } else { $data[$key] = 0; } } } // manage is_opt_out if (array_key_exists('is_opt_out', $this->_fields)) { $wasOptOut = $this->_contact['is_opt_out'] ? true : false; $isOptOut = $params['is_opt_out'] ? true : false; $data['is_opt_out'] = $isOptOut; // on change, create new civicrm_subscription_history entry if ($wasOptOut != $isOptOut) { $shParams = array('contact_id' => $this->_contact['contact_id'], 'status' => $isOptOut ? 'Removed' : 'Added', 'method' => 'Web'); CRM_Contact_BAO_SubscriptionHistory::create($shParams); } } if ($this->_mode == CRM_PROFILE_FORM_MODE_REGISTER) { require_once 'CRM/Core/BAO/Address.php'; CRM_Core_BAO_Address::setOverwrite(false); } require_once 'CRM/Contact/BAO/Contact.php'; $contact = CRM_Contact_BAO_Contact::create($data, $ids, count($data['location'])); // Process group and tag if (CRM_Utils_Array::value('group', $this->_fields)) { CRM_Contact_BAO_GroupContact::create($params['group'], $contact->id); } if (CRM_Utils_Array::value('tag', $this->_fields)) { require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($params['tag'], $contact->id); } }
/** * 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(); }