/** * Get billing fields required for this processor. * * We apply the existing default of returning fields only for payment processor type 1. Processors can override to * alter. * * @param int $billingLocationID * * @return array */ public function getBillingAddressFields($billingLocationID = NULL) { if (!$billingLocationID) { // Note that although the billing id is passed around the forms the idea that it would be anything other than // the result of the function below doesn't seem to have eventuated. // So taking this as a param is possibly something to be removed in favour of the standard default. $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); } // Only handle pseudo-profile billing for now. if ($this->billingProfile == 'billing') { // @todo - use profile api to retrieve this - either as pseudo-profile or (better) set up billing // as a reserved profile in the DB and (even better) allow the profile to be selected // on the form instead of just 'billing for pay=later bool' return array('first_name' => 'billing_first_name', 'middle_name' => 'billing_middle_name', 'last_name' => 'billing_last_name', 'street_address' => "billing_street_address-{$billingLocationID}", 'city' => "billing_city-{$billingLocationID}", 'country' => "billing_country_id-{$billingLocationID}", 'state_province' => "billing_state_province_id-{$billingLocationID}", 'postal_code' => "billing_postal_code-{$billingLocationID}"); } else { return array(); } }
/** * Function used to send notification mail to pcp owner. * * This is used by contribution and also event PCPs. * * @param object $contribution * @param object $contributionSoft * Contribution object. */ public static function pcpNotifyOwner($contribution, $contributionSoft) { $params = array('id' => $contributionSoft->pcp_id); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo); $ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id'); if ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'no_notifications', 'name') && ($ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name') && CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify') || $ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'all_owners', 'name'))) { $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$contributionSoft->pcp_id}", TRUE, NULL, FALSE, TRUE); // set email in the template here if (CRM_Core_BAO_LocationType::getBilling()) { list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id, FALSE, CRM_Core_BAO_LocationType::getBilling()); } // get primary location email if no email exist( for billing location). if (!$email) { list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id); } list($ownerName, $ownerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft->contact_id); $tplParams = array('page_title' => $pcpInfo['title'], 'receive_date' => $contribution->receive_date, 'total_amount' => $contributionSoft->amount, 'donors_display_name' => $donorName, 'donors_email' => $email, 'pcpInfoURL' => $pcpInfoURL, 'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll, 'currency' => $contributionSoft->currency); $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_owner_notify', 'contactId' => $contributionSoft->contact_id, 'toEmail' => $ownerEmail, 'toName' => $ownerName, 'from' => "{$domainValues['0']} <{$domainValues['1']}>", 'tplParams' => $tplParams, 'PDFFilename' => 'receipt.pdf'); CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } }
/** * Add fields to $profileAddressFields as appropriate. * profileAddressFields is assigned to the template to tell it * what fields are in the profile address * that potentially should be copied to the Billing fields * we want to give precedence to * 1) Billing & * 2) then Primary designated as 'Primary * 3) location_type is primary * 4) if none of these apply then it just uses the first one * * as this will be used to * transfer profile address data to billing fields * http://issues.civicrm.org/jira/browse/CRM-5869 * * @param string $key * Field key - e.g. street_address-Primary, first_name. * @param array $profileAddressFields * Array of profile fields that relate to address fields. * @param array $profileFilter * Filter to apply to profile fields - expected usage is to only fill based on. * the bottom profile per CRM-13726 * * @return bool * Can the address block be hidden safe in the knowledge all fields are elsewhere collected (see CRM-15118) */ public static function assignAddressField($key, &$profileAddressFields, $profileFilter) { $billing_id = CRM_Core_BAO_LocationType::getBilling(); list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name, is_required', 'options' => array('limit' => 0)))); //check for valid fields ( fields that are present in billing block ) $validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country'); $requiredBillingFields = array_diff($validBillingFields, array('middle_name', 'supplemental_address_1')); $validProfileFields = array(); $requiredProfileFields = array(); foreach ($profileFields['values'] as $field) { if (in_array($field['field_name'], $validBillingFields)) { $validProfileFields[] = $field['field_name']; } if ($field['is_required']) { $requiredProfileFields[] = $field['field_name']; } } if (!in_array($prefixName, $validProfileFields)) { return FALSE; } if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) { $profileAddressFields[$prefixName] = $index; } $potentiallyMissingRequiredFields = array_diff($requiredBillingFields, $requiredProfileFields); CRM_Core_Resources::singleton()->addSetting(array('billing' => array('billingProfileIsHideable' => empty($potentiallyMissingRequiredFields)))); }
/** * Get site billing ID. * * @param array $ids * * @return bool */ public function getBillingID(&$ids) { $ids['billing'] = CRM_Core_BAO_LocationType::getBilling(); if (!$ids['billing']) { CRM_Core_Error::debug_log_message(ts('Please set a location type of %1', array(1 => 'Billing'))); echo "Failure: Could not find billing location type<p>"; return FALSE; } return TRUE; }
/** * Get pseudo profile 'billing'. * * This is a function to help us 'pretend' billing is a profile & treat it like it is one. * It gets standard credit card address fields etc * Note this is 'better' that the inbuilt version as it will pull in fallback values * billing location -> is_billing -> primary * * Note that that since the existing code for deriving a blank profile is not easily accessible our * interim solution is just to return an empty array * * @param array $params * * @return array */ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) { $locationTypeID = CRM_Core_BAO_LocationType::getBilling(); if (empty($params['contact_id'])) { $config = CRM_Core_Config::singleton(); $blanks = array('billing_first_name' => '', 'billing_middle_name' => '', 'billing_last_name' => '', 'email-' . $locationTypeID => '', 'billing_email-' . $locationTypeID => '', 'billing_city-' . $locationTypeID => '', 'billing_postal_code-' . $locationTypeID => '', 'billing_street_address-' . $locationTypeID => '', 'billing_country_id-' . $locationTypeID => $config->defaultContactCountry, 'billing_state_province_id-' . $locationTypeID => $config->defaultContactStateProvince); return $blanks; } $addressFields = array('street_address', 'city', 'state_province_id', 'country_id', 'postal_code'); $result = civicrm_api3('contact', 'getsingle', array('id' => $params['contact_id'], 'api.address.get.1' => array('location_type_id' => 'Billing', 'return' => $addressFields), 'api.address.get.2' => array('is_billing' => TRUE, 'return' => $addressFields), 'api.email.get.1' => array('location_type_id' => 'Billing'), 'api.email.get.2' => array('is_billing' => TRUE), 'return' => 'api.email.get, api.address.get, api.address.getoptions, country, state_province, email, first_name, last_name, middle_name, ' . implode($addressFields, ','))); $values = array('billing_first_name' => $result['first_name'], 'billing_middle_name' => $result['middle_name'], 'billing_last_name' => $result['last_name']); if (!empty($result['api.address.get.1']['count'])) { foreach ($addressFields as $fieldname) { $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.1']['values'][0][$fieldname]) ? $result['api.address.get.1']['values'][0][$fieldname] : ''; } } elseif (!empty($result['api.address.get.2']['count'])) { foreach ($addressFields as $fieldname) { $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result['api.address.get.2']['values'][0][$fieldname]) ? $result['api.address.get.2']['values'][0][$fieldname] : ''; } } else { foreach ($addressFields as $fieldname) { $values['billing_' . $fieldname . '-' . $locationTypeID] = isset($result[$fieldname]) ? $result[$fieldname] : ''; } } if (!empty($result['api.email.get.1']['count'])) { $values['billing-email' . '-' . $locationTypeID] = $result['api.email.get.1']['values'][0]['email']; } elseif (!empty($result['api.email.get.2']['count'])) { $values['billing-email' . '-' . $locationTypeID] = $result['api.email.get.2']['values'][0]['email']; } else { $values['billing-email' . '-' . $locationTypeID] = $result['email']; } // return both variants of email to reflect inconsistencies in form layer $values['email' . '-' . $locationTypeID] = $values['billing-email' . '-' . $locationTypeID]; return $values; }
/** * Format profile contact parameters. * * @param array $params * @param $fields * @param int $contactID * @param int $ufGroupId * @param null $ctype * @param bool $skipCustom * * @return array */ public static function formatProfileContactParams(&$params, &$fields, $contactID = NULL, $ufGroupId = NULL, $ctype = NULL, $skipCustom = FALSE) { $data = $contactDetails = array(); // get the contact details (hier) if ($contactID) { list($details, $options) = self::getHierContactDetails($contactID, $fields); $contactDetails = $details[$contactID]; $data['contact_type'] = CRM_Utils_Array::value('contact_type', $contactDetails); $data['contact_sub_type'] = CRM_Utils_Array::value('contact_sub_type', $contactDetails); } else { //we should get contact type only if contact if ($ufGroupId) { $data['contact_type'] = CRM_Core_BAO_UFField::getProfileType($ufGroupId); //special case to handle profile with only contact fields if ($data['contact_type'] == 'Contact') { $data['contact_type'] = 'Individual'; } elseif (CRM_Contact_BAO_ContactType::isaSubType($data['contact_type'])) { $data['contact_type'] = CRM_Contact_BAO_ContactType::getBasicType($data['contact_type']); } } elseif ($ctype) { $data['contact_type'] = $ctype; } else { $data['contact_type'] = 'Individual'; } } //fix contact sub type CRM-5125 if (array_key_exists('contact_sub_type', $params) && !empty($params['contact_sub_type'])) { $data['contact_sub_type'] = CRM_Utils_Array::implodePadded($params['contact_sub_type']); } elseif (array_key_exists('contact_sub_type_hidden', $params) && !empty($params['contact_sub_type_hidden'])) { // if profile was used, and had any subtype, we obtain it from there //CRM-13596 - add to existing contact types, rather than overwriting $data_contact_sub_type_arr = CRM_Utils_Array::explodePadded($data['contact_sub_type']); if (!in_array($params['contact_sub_type_hidden'], $data_contact_sub_type_arr)) { $data['contact_sub_type'] .= CRM_Utils_Array::implodePadded($params['contact_sub_type_hidden']); } } if ($ctype == 'Organization') { $data['organization_name'] = CRM_Utils_Array::value('organization_name', $contactDetails); } elseif ($ctype == 'Household') { $data['household_name'] = CRM_Utils_Array::value('household_name', $contactDetails); } $locationType = array(); $count = 1; if ($contactID) { //add contact id $data['contact_id'] = $contactID; $primaryLocationType = self::getPrimaryLocationType($contactID); } else { $defaultLocation = CRM_Core_BAO_LocationType::getDefault(); $defaultLocationId = $defaultLocation->id; } $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling(); $blocks = array('email', 'phone', 'im', 'openid'); $multiplFields = array('url'); // prevent overwritten of formatted array, reset all block from // params if it is not in valid format (since import pass valid format) foreach ($blocks as $blk) { if (array_key_exists($blk, $params) && !is_array($params[$blk])) { unset($params[$blk]); } } $primaryPhoneLoc = NULL; $session = CRM_Core_Session::singleton(); foreach ($params as $key => $value) { $locTypeId = $typeId = NULL; list($fieldName, $locTypeId, $typeId) = CRM_Utils_System::explode('-', $key, 3); //store original location type id $actualLocTypeId = $locTypeId; if ($locTypeId == 'Primary') { if ($contactID) { if (in_array($fieldName, $blocks)) { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, $fieldName); } else { $locTypeId = self::getPrimaryLocationType($contactID, FALSE, 'address'); } $primaryLocationType = $locTypeId; } else { $locTypeId = $defaultLocationId; } } if (is_numeric($locTypeId) && !in_array($fieldName, $multiplFields) && substr($fieldName, 0, 7) != 'custom_') { $index = $locTypeId; if (is_numeric($typeId)) { $index .= '-' . $typeId; } if (!in_array($index, $locationType)) { $locationType[$count] = $index; $count++; } $loc = CRM_Utils_Array::key($index, $locationType); $blockName = in_array($fieldName, $blocks) ? $fieldName : 'address'; $data[$blockName][$loc]['location_type_id'] = $locTypeId; //set is_billing true, for location type "Billing" if ($locTypeId == $billingLocationTypeId) { $data[$blockName][$loc]['is_billing'] = 1; } if ($contactID) { //get the primary location type if ($locTypeId == $primaryLocationType) { $data[$blockName][$loc]['is_primary'] = 1; } } elseif ($locTypeId == $defaultLocationId) { $data[$blockName][$loc]['is_primary'] = 1; } if (in_array($fieldName, array('phone'))) { if ($typeId) { $data['phone'][$loc]['phone_type_id'] = $typeId; } else { $data['phone'][$loc]['phone_type_id'] = ''; } $data['phone'][$loc]['phone'] = $value; //special case to handle primary phone with different phone types // in this case we make first phone type as primary if (isset($data['phone'][$loc]['is_primary']) && !$primaryPhoneLoc) { $primaryPhoneLoc = $loc; } if ($loc != $primaryPhoneLoc) { unset($data['phone'][$loc]['is_primary']); } } elseif ($fieldName == 'phone_ext') { $data['phone'][$loc]['phone_ext'] = $value; } elseif ($fieldName == 'email') { $data['email'][$loc]['email'] = $value; if (empty($contactID)) { $data['email'][$loc]['is_primary'] = 1; } } elseif ($fieldName == 'im') { if (isset($params[$key . '-provider_id'])) { $data['im'][$loc]['provider_id'] = $params[$key . '-provider_id']; } if (strpos($key, '-provider_id') !== FALSE) { $data['im'][$loc]['provider_id'] = $params[$key]; } else { $data['im'][$loc]['name'] = $value; } } elseif ($fieldName == 'openid') { $data['openid'][$loc]['openid'] = $value; } else { if ($fieldName === 'state_province') { // CRM-3393 if (is_numeric($value) && (int) $value >= 1000) { $data['address'][$loc]['state_province_id'] = $value; } elseif (empty($value)) { $data['address'][$loc]['state_province_id'] = ''; } else { $data['address'][$loc]['state_province'] = $value; } } elseif ($fieldName === 'country') { // CRM-3393 if (is_numeric($value) && (int) $value >= 1000) { $data['address'][$loc]['country_id'] = $value; } elseif (empty($value)) { $data['address'][$loc]['country_id'] = ''; } else { $data['address'][$loc]['country'] = $value; } } elseif ($fieldName === 'county') { $data['address'][$loc]['county_id'] = $value; } elseif ($fieldName == 'address_name') { $data['address'][$loc]['name'] = $value; } elseif (substr($fieldName, 0, 14) === 'address_custom') { $data['address'][$loc][substr($fieldName, 8)] = $value; } else { $data['address'][$loc][$fieldName] = $value; } } } else { if (substr($key, 0, 4) === 'url-') { $websiteField = explode('-', $key); $data['website'][$websiteField[1]]['website_type_id'] = $websiteField[1]; $data['website'][$websiteField[1]]['url'] = $value; } elseif (in_array($key, self::$_greetingTypes, TRUE)) { //save email/postal greeting and addressee values if any, CRM-4575 $data[$key . '_id'] = $value; } elseif (!$skipCustom && ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key))) { // for autocomplete transfer hidden value instead of label if ($params[$key] && isset($params[$key . '_id'])) { $value = $params[$key . '_id']; } // we need to append time with date if ($params[$key] && isset($params[$key . '_time'])) { $value .= ' ' . $params[$key . '_time']; } // if auth source is not checksum / login && $value is blank, do not proceed - CRM-10128 if (($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0 && ($value == '' || !isset($value))) { continue; } $valueId = NULL; if (!empty($params['customRecordValues'])) { if (is_array($params['customRecordValues']) && !empty($params['customRecordValues'])) { foreach ($params['customRecordValues'] as $recId => $customFields) { if (is_array($customFields) && !empty($customFields)) { foreach ($customFields as $customFieldName) { if ($customFieldName == $key) { $valueId = $recId; break; } } } } } } //CRM-13596 - check for contact_sub_type_hidden first if (array_key_exists('contact_sub_type_hidden', $params)) { $type = $params['contact_sub_type_hidden']; } else { $type = $data['contact_type']; if (!empty($data['contact_sub_type'])) { $type = $data['contact_sub_type']; $type = CRM_Utils_Array::explodePadded($type); // generally a contact even if, has multiple subtypes the parent-type is going to be one only // and since formatCustomField() would be interested in parent type, lets consider only one subtype // as the results going to be same. $type = $type[0]; } } CRM_Core_BAO_CustomField::formatCustomField($customFieldId, $data['custom'], $value, $type, $valueId, $contactID); } elseif ($key == 'edit') { continue; } else { if ($key == 'location') { foreach ($value as $locationTypeId => $field) { foreach ($field as $block => $val) { if ($block == 'address' && array_key_exists('address_name', $val)) { $value[$locationTypeId][$block]['name'] = $value[$locationTypeId][$block]['address_name']; } } } } if ($key == 'phone' && isset($params['phone_ext'])) { $data[$key] = $value; foreach ($value as $cnt => $phoneBlock) { if ($params[$key][$cnt]['location_type_id'] == $params['phone_ext'][$cnt]['location_type_id']) { $data[$key][$cnt]['phone_ext'] = CRM_Utils_Array::retrieveValueRecursive($params['phone_ext'][$cnt], 'phone_ext'); } } } elseif (in_array($key, array('nick_name', 'job_title', 'middle_name', 'birth_date', 'gender_id', 'current_employer', 'prefix_id', 'suffix_id')) && ($value == '' || !isset($value)) && ($session->get('authSrc') & CRM_Core_Permission::AUTH_SRC_CHECKSUM + CRM_Core_Permission::AUTH_SRC_LOGIN) == 0 || $key == 'current_employer' && empty($params['current_employer'])) { // CRM-10128: if auth source is not checksum / login && $value is blank, do not fill $data with empty value // to avoid update with empty values continue; } else { $data[$key] = $value; } } } } if (!isset($data['contact_type'])) { $data['contact_type'] = 'Individual'; } //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, $fields)) { // do not reset values for existing contacts, if fields are added to a profile if (array_key_exists($key, $params)) { $data[$key] = $params[$key]; if (empty($params[$key])) { $data[$key] = 0; } } elseif (!$contactID) { $data[$key] = 0; } } } return array($data, $contactDetails); }
/** * Assign billing type id to bltID. * * @throws CRM_Core_Exception */ public function assignBillingType() { $this->_bltID = CRM_Core_BAO_LocationType::getBilling(); $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); }
/** * Send the emails. * * @param int $contactID * Contact id. * @param array $values * Associated array of fields. * @param bool $isTest * If in test mode. * @param bool $returnMessageText * Return the message text instead of sending the mail. * * @param array $fieldTypes */ public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { $gIds = array(); $params = array('custom_pre_id' => array(), 'custom_post_id' => array()); $email = NULL; // We are trying to fight the good fight against leaky variables (CRM-17519) so let's get really explicit // about ensuring the variables we want for the template are defined. // @todo add to this until all tpl params are explicit in this function and not waltzing around the codebase. // Next stage is to remove this & ensure there are no e-notices - ie. all are set before they hit this fn. $valuesRequiredForTemplate = array('customPre', 'customPost', 'customPre_grouptitle', 'customPost_grouptitle', 'useForMember', 'membership_assign', 'amount', 'receipt_date', 'is_pay_later'); foreach ($valuesRequiredForTemplate as $valueRequiredForTemplate) { if (!isset($values[$valueRequiredForTemplate])) { $values[$valueRequiredForTemplate] = NULL; } } if (isset($values['custom_pre_id'])) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); if ($preProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_pre_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_pre_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_pre_id'] = $values['custom_pre_id']; } if (isset($values['custom_post_id'])) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); if ($postProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_post_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_post_id'] = $values['custom_post_id']; } if (!empty($values['is_for_organization'])) { if (!empty($values['membership_id'])) { $params['onbehalf_profile'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif (!empty($values['contribution_id'])) { $params['onbehalf_profile'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } } //check whether it is a test drive if ($isTest && !empty($params['custom_pre_id'])) { $params['custom_pre_id'][] = array('contribution_test', '=', 1, 0, 0); } if ($isTest && !empty($params['custom_post_id'])) { $params['custom_post_id'][] = array('contribution_test', '=', 1, 0, 0); } if (!$returnMessageText && !empty($gIds)) { //send notification email if field values are set (CRM-1941) foreach ($gIds as $key => $gId) { if ($gId) { $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); if ($email) { $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE); CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); } } } } if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || $returnMessageText) { $template = CRM_Core_Smarty::singleton(); // get the billing location type if (!array_key_exists('related_contact', $values)) { $billingLocationTypeId = CRM_Core_BAO_LocationType::getBilling(); } else { // presence of related contact implies onbehalf of org case, // where location type is set to default. $locType = CRM_Core_BAO_LocationType::getDefault(); $billingLocationTypeId = $locType->id; } if (!array_key_exists('related_contact', $values)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); } // get primary location email if no email exist( for billing location). if (!$email) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } if (empty($displayName)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } //for display profile need to get individual contact id, //hence get it from related_contact if on behalf of org true CRM-3767 //CRM-5001 Contribution/Membership:: On Behalf of Organization, //If profile GROUP contain the Individual type then consider the //profile is of Individual ( including the custom data of membership/contribution ) //IF Individual type not present in profile then it is consider as Organization data. $userID = $contactID; if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { if (!empty($values['related_contact'])) { $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } list($values['customPre_grouptitle'], $values['customPre']) = self::getProfileNameAndFields($preID, $userID, $params['custom_pre_id']); } $userID = $contactID; if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { if (!empty($values['related_contact'])) { $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } list($values['customPost_grouptitle'], $values['customPost']) = self::getProfileNameAndFields($postID, $userID, $params['custom_post_id']); } if (isset($values['honor'])) { $honorValues = $values['honor']; $template->_values = array('honoree_profile_id' => $values['honoree_profile_id']); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($template, $honorValues['honor_profile_values'], $honorValues['honor_id']); } $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); // Set email variables explicitly to avoid leaky smarty variables. // All of these will be assigned to the template, replacing any that might be assigned elsewhere. $tplParams = array('email' => $email, 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), 'contactID' => $contactID, 'displayName' => $displayName, 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), 'title' => $title, 'isShare' => CRM_Utils_Array::value('is_share', $values), 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values), 'customPre' => $values['customPre'], 'customPre_grouptitle' => $values['customPre_grouptitle'], 'customPost' => $values['customPost'], 'customPost_grouptitle' => $values['customPost_grouptitle'], 'useForMember' => $values['useForMember'], 'membership_assign' => $values['membership_assign'], 'amount' => $values['amount'], 'is_pay_later' => $values['is_pay_later'], 'receipt_date' => !$values['receipt_date'] ? NULL : date('YmdHis', strtotime($values['receipt_date'])), 'pay_later_receipt' => CRM_Utils_Array::value('pay_later_receipt', $values)); if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { $tplParams['financialTypeId'] = $contributionTypeId; $tplParams['financialTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionTypeId); // Legacy support $tplParams['contributionTypeName'] = $tplParams['financialTypeName']; $tplParams['contributionTypeId'] = $contributionTypeId; } if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { $tplParams['contributionPageId'] = $contributionPageId; } // address required during receipt processing (pdf and email receipt) if ($displayAddress = CRM_Utils_Array::value('address', $values)) { $tplParams['address'] = $displayAddress; } // CRM-6976 $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); // cc to related contacts of contributor OR the one who // signs up. Is used for cases like - on behalf of // contribution / signup ..etc if (array_key_exists('related_contact', $values)) { list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used $values['cc_receipt'] = !empty($values['cc_receipt']) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId; // reset primary-email in the template $tplParams['email'] = $ccEmail; $tplParams['onBehalfName'] = $displayName; $tplParams['onBehalfEmail'] = $email; if (!empty($values['onbehalf_profile_id'])) { self::buildCustomDisplay($values['onbehalf_profile_id'], 'onBehalfProfile', $contactID, $template, $params['onbehalf_profile'], $fieldTypes); } } // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not $sendTemplateParams = array('groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest, 'PDFFilename' => 'receipt.pdf'); if ($returnMessageText) { list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html); } if (empty($values['receipt_from_name']) && empty($values['receipt_from_name'])) { list($values['receipt_from_name'], $values['receipt_from_email']) = CRM_Core_BAO_Domain::getNameAndEmail(); } if ($values['is_email_receipt']) { $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $email; $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); //send email with pdf invoice $template = CRM_Core_Smarty::singleton(); $taxAmt = $template->get_template_vars('dataArray'); $prefixValue = Civi::settings()->get('contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) { $sendTemplateParams['isEmailPdf'] = TRUE; $sendTemplateParams['contributionId'] = $values['contribution_id']; } list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } // send duplicate alert, if dupe match found during on-behalf-of processing. if (!empty($values['onbehalf_dupe_alert'])) { $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; $sendTemplateParams['valueName'] = 'contribution_dupalert'; $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; $sendTemplateParams['tplParams']['receiptMessage'] = $message; // fix cc and reset back to original, CRM-6976 $sendTemplateParams['cc'] = $originalCCReceipt; CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } } }
/** * Get form metadata for billing address fields. * * @param int $billingLocationID * * @return array * Array of metadata for address fields. */ public function getBillingAddressFieldsMetadata($billingLocationID = NULL) { if (!$billingLocationID) { // Note that although the billing id is passed around the forms the idea that it would be anything other than // the result of the function below doesn't seem to have eventuated. // So taking this as a param is possibly something to be removed in favour of the standard default. $billingLocationID = CRM_Core_BAO_LocationType::getBilling(); } $metadata = array(); $metadata['billing_first_name'] = array('htmlType' => 'text', 'name' => 'billing_first_name', 'title' => ts('Billing First Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata['billing_middle_name'] = array('htmlType' => 'text', 'name' => 'billing_middle_name', 'title' => ts('Billing Middle Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => FALSE); $metadata['billing_last_name'] = array('htmlType' => 'text', 'name' => 'billing_last_name', 'title' => ts('Billing Last Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_street_address-{$billingLocationID}"] = array('htmlType' => 'text', 'name' => "billing_street_address-{$billingLocationID}", 'title' => ts('Street Address'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_city-{$billingLocationID}"] = array('htmlType' => 'text', 'name' => "billing_city-{$billingLocationID}", 'title' => ts('City'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_state_province_id-{$billingLocationID}"] = array('htmlType' => 'chainSelect', 'title' => ts('State/Province'), 'name' => "billing_state_province_id-{$billingLocationID}", 'cc_field' => TRUE, 'is_required' => TRUE); $metadata["billing_postal_code-{$billingLocationID}"] = array('htmlType' => 'text', 'name' => "billing_postal_code-{$billingLocationID}", 'title' => ts('Postal Code'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_country_id-{$billingLocationID}"] = array('htmlType' => 'select', 'name' => "billing_country_id-{$billingLocationID}", 'title' => ts('Country'), 'cc_field' => TRUE, 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), 'is_required' => TRUE); return $metadata; }
/** * Add fields to $profileAddressFields as appropriate. * profileAddressFields is assigned to the template to tell it * what fields are in the profile address * that potentially should be copied to the Billing fields * we want to give precedence to * 1) Billing & * 2) then Primary designated as 'Primary * 3) location_type is primary * 4) if none of these apply then it just uses the first one * * as this will be used to * transfer profile address data to billing fields * http://issues.civicrm.org/jira/browse/CRM-5869 * * @param string $key Field key - e.g. street_address-Primary, first_name * @param array $profileAddressFields array of profile fields that relate to address fields * @param array $profileFilter filter to apply to profile fields - expected usage is to only fill based on * the bottom profile per CRM-13726 */ static function assignAddressField($key, &$profileAddressFields, $profileFilter) { $billing_id = CRM_Core_BAO_LocationType::getBilling(); list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); $profileFields = civicrm_api3('uf_field', 'get', array_merge($profileFilter, array('is_active' => 1, 'return' => 'field_name'))); //check for valid fields ( fields that are present in billing block ) $validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country'); $validProfileFields = array(); foreach ($profileFields['values'] as $field) { if (in_array($field['field_name'], $validBillingFields)) { $validProfileFields[] = $field['field_name']; } } if (!in_array($prefixName, $validProfileFields)) { return; } if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) { $profileAddressFields[$prefixName] = $index; } }
/** * Get form metadata for address fields. * * At the moment this is being called from getPaymentFormFields when we are * dealing with a transparent redirect. It is a bit Cybersource use-casey. * * @return array * Array of metadata for address fields. */ private function getBillingAddressFieldsMetadataPre47() { $metadata = array(); $billingID = CRM_Core_BAO_LocationType::getBilling(); $metadata['billing_first_name'] = array('htmlType' => 'text', 'name' => 'billing_first_name', 'title' => ts('Billing First Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata['billing_middle_name'] = array('htmlType' => 'text', 'name' => 'billing_middle_name', 'title' => ts('Billing Middle Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => FALSE); $metadata['billing_last_name'] = array('htmlType' => 'text', 'name' => 'billing_last_name', 'title' => ts('Billing Last Name'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_street_address-{$billingID}"] = array('htmlType' => 'text', 'name' => "billing_street_address-{$billingID}", 'title' => ts('Street Address'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_city-{$billingID}"] = array('htmlType' => 'text', 'name' => "billing_city-{$billingID}", 'title' => ts('City'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_state_province_id-{$billingID}"] = array('htmlType' => 'chainSelect', 'title' => ts('State/Province'), 'name' => "billing_state_province_id-{$billingID}", 'cc_field' => TRUE, 'is_required' => TRUE); $metadata["billing_postal_code-{$billingID}"] = array('htmlType' => 'text', 'name' => "billing_postal_code-{$billingID}", 'title' => ts('Postal Code'), 'cc_field' => TRUE, 'attributes' => array('size' => 30, 'maxlength' => 60, 'autocomplete' => 'off'), 'is_required' => TRUE); $metadata["billing_country_id-{$billingID}"] = array('htmlType' => 'select', 'name' => "billing_country_id-{$billingID}", 'title' => ts('Country'), 'cc_field' => TRUE, 'attributes' => array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), 'is_required' => TRUE); return $metadata; }
/** * Add fields to $profileAddressFields as appropriate. * profileAddressFields is assigned to the template to tell it * what fields are in the profile address * that potentially should be copied to the Billing fields * we want to give precedence to * 1) Billing & * 2) then Primary designated as 'Primary * 3) location_type is primary * 4) if none of these apply then it just uses the first one * * as this will be used to * transfer profile address data to billing fields * http://issues.civicrm.org/jira/browse/CRM-5869 * @param string $key Field key - e.g. street_address-Primary, first_name * @params array $profileAddressFields array of profile fields that relate to address fields */ static function assignAddressField($key, &$profileAddressFields) { $billing_id = CRM_Core_BAO_LocationType::getBilling(); list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); //check for valid fields ( fields that are present in billing block ) $validBillingFields = array('first_name', 'middle_name', 'last_name', 'street_address', 'supplemental_address_1', 'city', 'state_province', 'postal_code', 'country'); if (!in_array($prefixName, $validBillingFields)) { return; } if (!empty($index) && (!CRM_Utils_array::value($prefixName, $profileAddressFields) || $index == $billing_id || $index == 'Primary' && $profileAddressFields[$prefixName] != $billing_id || $index == CRM_Core_BAO_LocationType::getDefault()->id && $profileAddressFields[$prefixName] != $billing_id && $profileAddressFields[$prefixName] != 'Primary')) { $profileAddressFields[$prefixName] = $index; } }