/** * Replace all the org-level tokens in $str * * @param string $str * The string with tokens to be replaced. * @param object $org * Associative array of org properties. * @param bool $html * Replace tokens with HTML or plain text. * * @param bool $escapeSmarty * * @return string * The processed string */ public static function &replaceOrgTokens($str, &$org, $html = FALSE, $escapeSmarty = FALSE) { self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id')); $cv = NULL; foreach (self::$_tokens['org'] as $token) { // print "Getting token value for $token<br/><br/>"; if ($token == '') { continue; } // If the string doesn't contain this token, skip it. if (!self::token_match('org', $token, $str)) { continue; } // Construct value from $token and $contact $value = NULL; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) { // only generate cv if we need it if ($cv === NULL) { $cv = CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']); } foreach ($cv as $cvFieldID => $value) { if ($cvFieldID == $cfID) { $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value); break; } } } elseif ($token == 'checksum') { $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']); $value = "cs={$cs}"; } elseif ($token == 'address') { // Build the location values array $loc = array(); $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name'); $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address'); $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city'); $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province'); $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code'); // Construct the address token $value = CRM_Utils_Address::format($loc); if ($html) { $value = str_replace("\n", '<br />', $value); } } else { $value = CRM_Utils_Array::retrieveValueRecursive($org, $token); } self::token_replace('org', $token, $value, $str, $escapeSmarty); } return $str; }
/** * 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); } }
static function setDefaults(&$groupTree, &$defaults, $viewMode = false, $inactiveNeeded = false, $action = CRM_Core_Action::NONE) { require_once 'CRM/Core/BAO/CustomOption.php'; foreach ($groupTree as $id => $group) { if (!isset($group['fields'])) { continue; } $groupId = CRM_Utils_Array::value('id', $group); foreach ($group['fields'] as $field) { if (CRM_Utils_Array::value('element_value', $field) !== null) { $value = $field['element_value']; } else { if (CRM_Utils_Array::value('default_value', $field) !== null && $action != CRM_Core_Action::UPDATE) { $value = $viewMode ? null : $field['default_value']; } else { continue; } } $fieldId = $field['id']; $elementName = $field['element_name']; switch ($field['html_type']) { case 'Multi-Select': case 'AdvMulti-Select': case 'CheckBox': $defaults[$elementName] = array(); $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field['id'], $inactiveNeeded); if ($viewMode) { $checkedData = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1)); if (isset($value)) { foreach ($customOption as $customValue => $customLabel) { if (in_array($customValue, $checkedData)) { if ($field['html_type'] == 'CheckBox') { $defaults[$elementName][$customValue] = 1; } else { $defaults[$elementName][$customValue] = $customValue; } } else { $defaults[$elementName][$customValue] = 0; } } } } else { if (isset($field['customValue']['data'])) { $checkedData = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($field['customValue']['data'], 1, -1)); foreach ($customOption as $val) { if (in_array($val['value'], $checkedData)) { if ($field['html_type'] == 'CheckBox') { $defaults[$elementName][$val['value']] = 1; } else { $defaults[$elementName][$val['value']] = $val['value']; } } else { $defaults[$elementName][$val['value']] = 0; } } } else { $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($value, 1, -1)); foreach ($customOption as $val) { if (in_array($val['value'], $checkedValue)) { if ($field['html_type'] == 'CheckBox') { $defaults[$elementName][$val['value']] = 1; } else { $defaults[$elementName][$val['value']] = $val['value']; } } } } } break; case 'Select Date': if (isset($value)) { if (!$field['time_format']) { list($defaults[$elementName]) = CRM_Utils_Date::setDateDefaults($value, null, $field['date_format']); } else { $timeElement = $elementName . '_time'; if (substr($elementName, -1) == ']') { $timeElement = substr($elementName, 0, ${$elementName} . length - 1) . '_time]'; } list($defaults[$elementName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($value, null, $field['date_format'], $field['time_format']); } } break; case 'Multi-Select Country': case 'Multi-Select State/Province': if (isset($value)) { $checkedValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, $value); foreach ($checkedValue as $val) { if ($val) { $defaults[$elementName][$val] = $val; } } } break; case 'Select Country': if ($value) { $defaults[$elementName] = $value; } else { $config = CRM_Core_Config::singleton(); $defaults[$elementName] = $config->defaultContactCountry; } break; case 'Autocomplete-Select': if ($field['data_type'] == "ContactReference") { require_once 'CRM/Contact/BAO/Contact.php'; if (is_numeric($value)) { $defaults[$elementName . '_id'] = $value; $defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name'); } } else { $label = CRM_Core_BAO_CustomOption::getOptionLabel($field['id'], $value); $defaults[$elementName . '_id'] = $value; $defaults[$elementName] = $label; } break; default: if ($field['data_type'] == "Float") { $defaults[$elementName] = (double) $value; } elseif ($field['data_type'] == 'Money') { require_once 'CRM/Utils/Money.php'; $defaults[$elementName] = CRM_Utils_Money::format($value, null, '%a'); } else { $defaults[$elementName] = $value; } } } } }
/** * 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 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 (CRM_Utils_Array::value($name, $details) || 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 == '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 'Autocomplete-Select': if ($customFields[$customFieldId]['data_type'] == 'ContactReference') { 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': // CRM-6681, set defult values according to date and time format (if any). $dateFormat = NULL; if (CRM_Utils_Array::value('date_format', $customFields[$customFieldId])) { $dateFormat = $customFields[$customFieldId]['date_format']; } if (!CRM_Utils_Array::value('time_format', $customFields[$customFieldId])) { 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 (CRM_Utils_Array::value($fieldName, $value)) { //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') { if (!empty($details['website'])) { foreach ($details['website'] as $val) { $defaults[$fldName] = CRM_Utils_Array::value('url', $val); $defaults[$fldName . '-website_type_id'] = $val['website_type_id']; } } } } } } } } //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); } }
/** * Function to set default values for custom data used in profile * * @params int $customFieldId custom field id * @params string $elementName custom field name * @params array $defaults associated array of fields * @params int $contactId contact id * @param int $mode profile mode * * @static * @access public */ static function setProfileDefaults($customFieldId, $elementName, &$defaults, $contactId = null, $mode = null) { //get the type of custom field $customField = new CRM_Core_BAO_CustomField(); $customField->id = $customFieldId; $customField->find(true); require_once "CRM/Profile/Form.php"; $value = null; if (!$contactId) { if ($mode == CRM_Profile_Form::MODE_CREATE) { $value = $customField->default_value; } } else { $info = self::getTableColumnGroup($customFieldId); $query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}"; $result = CRM_Core_DAO::executeQuery($query); if ($result->fetch()) { $value = $result->value; } if ($customField->data_type == 'Country') { if (!$value) { $config = CRM_Core_Config::singleton(); if ($config->defaultContactCountry) { $value = $config->defaultContactCountry(); } } } } //set defaults if mode is registration if (!trim($value) && $value !== 0 && !in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH))) { $value = $customField->default_value; } if ($customField->data_type == 'Money' && isset($value)) { $value = number_format($value, 2); } switch ($customField->html_type) { case 'CheckBox': case 'AdvMulti-Select': case 'Multi-Select': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldId, false); $defaults[$elementName] = array(); $checkedValue = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($value, 1, -1)); foreach ($customOption as $val) { if (in_array($val['value'], $checkedValue)) { if ($customField->html_type == 'CheckBox') { $defaults[$elementName][$val['value']] = 1; } elseif ($customField->html_type == 'Multi-Select' || $customField->html_type == 'AdvMulti-Select') { $defaults[$elementName][$val['value']] = $val['value']; } } } break; case 'Select Date': if ($value) { list($defaults[$elementName], $defaults[$elementName . '_time']) = CRM_Utils_Date::setDateDefaults($value, null, $customField->date_format, $customField->time_format); } break; case 'Autocomplete-Select': if ($customField->data_type == "ContactReference") { require_once 'CRM/Contact/BAO/Contact.php'; if (is_numeric($value)) { $defaults[$elementName . '_id'] = $value; $defaults[$elementName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $value, 'sort_name'); } } else { $label = CRM_Core_BAO_CustomOption::getOptionLabel($customField->id, $value); $defaults[$elementName . '_id'] = $value; $defaults[$elementName] = $label; } break; default: $defaults[$elementName] = $value; } }
/** * Replace all the org-level tokens in $str * * @param string $str The string with tokens to be replaced * @param object $org Associative array of org properties * @param boolean $html Replace tokens with HTML or plain text * @return string The processed string * @access public * @static */ public static function &replaceOrgTokens($str, &$org, $html = false) { self::$_tokens['org'] = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields('Organization')), array('address', 'display_name', 'checksum', 'contact_id')); /* print "org tokens: <pre>"; print_r( $_tokens['org'] ); print "</pre>"; */ $cv = null; foreach (self::$_tokens['org'] as $token) { // print "Getting token value for $token<br/><br/>"; if ($token == '') { continue; } /* If the string doesn't contain this token, skip it. */ if (!self::token_match('org', $token, $str)) { continue; } /* Construct value from $token and $contact */ $value = null; if ($cfID = CRM_Core_BAO_CustomField::getKeyID($token)) { // only generate cv if we need it if ($cv === null) { $cv =& CRM_Core_BAO_CustomValue::getContactValues($org['contact_id']); } foreach ($cv as $cvFieldID => $value) { if ($cvFieldID == $cfID) { $value = CRM_Core_BAO_CustomOption::getOptionLabel($cfID, $value); break; } } } else { if ($token == 'checksum') { require_once 'CRM/Contact/BAO/Contact/Utils.php'; $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($org['contact_id']); $value = "cs={$cs}"; } else { if ($token == 'address') { /* Build the location values array */ $loc = array(); $loc['display_name'] = CRM_Utils_Array::retrieveValueRecursive($org, 'display_name'); $loc['street_address'] = CRM_Utils_Array::retrieveValueRecursive($org, 'street_address'); $loc['city'] = CRM_Utils_Array::retrieveValueRecursive($org, 'city'); $loc['state_province'] = CRM_Utils_Array::retrieveValueRecursive($org, 'state_province'); $loc['postal_code'] = CRM_Utils_Array::retrieveValueRecursive($org, 'postal_code'); /* Construct the address token */ $value = CRM_Utils_Address::format($loc); if ($html) { $value = str_replace("\n", '<br />', $value); } } else { /* print "\$org: <pre>"; print_r( $org ); print "</pre>"; */ $value = CRM_Utils_Array::retrieveValueRecursive($org, $token); /* print "\$value: <pre>"; print_r( $value ); print "</pre>"; */ } } } self::token_replace('org', $token, $value, $str); } return $str; }