/** * @param array $customParams * * @throws Exception */ public static function create(&$customParams) { if (empty($customParams) || !is_array($customParams)) { return; } foreach ($customParams as $tableName => $tables) { foreach ($tables as $index => $fields) { $sqlOP = NULL; $hookID = NULL; $hookOP = NULL; $entityID = NULL; $isMultiple = FALSE; $set = array(); $params = array(); $count = 1; foreach ($fields as $field) { if (!$sqlOP) { $entityID = $field['entity_id']; $hookID = $field['custom_group_id']; $isMultiple = $field['is_multiple']; if (array_key_exists('id', $field)) { $sqlOP = "UPDATE {$tableName} "; $where = " WHERE id = %{$count}"; $params[$count] = array($field['id'], 'Integer'); $count++; $hookOP = 'edit'; } else { $sqlOP = "INSERT INTO {$tableName} "; $where = NULL; $hookOP = 'create'; } } // fix the value before we store it $value = $field['value']; $type = $field['type']; switch ($type) { case 'StateProvince': $type = 'Integer'; if (is_array($value)) { $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $value) . CRM_Core_DAO::VALUE_SEPARATOR; $type = 'String'; } elseif (!is_numeric($value) && !strstr($value, CRM_Core_DAO::VALUE_SEPARATOR)) { //fix for multi select state, CRM-3437 $mulValues = explode(',', $value); $validStates = array(); foreach ($mulValues as $key => $stateVal) { $states = array(); $states['state_province'] = trim($stateVal); CRM_Utils_Array::lookupValue($states, 'state_province', CRM_Core_PseudoConstant::stateProvince(), TRUE); if (empty($states['state_province_id'])) { CRM_Utils_Array::lookupValue($states, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), TRUE); } $validStates[] = CRM_Utils_Array::value('state_province_id', $states); } $value = implode(CRM_Core_DAO::VALUE_SEPARATOR, $validStates); $type = 'String'; } elseif (!$value) { // CRM-3415 // using type of timestamp allows us to sneak in a null into db // gross but effective hack $value = NULL; $type = 'Timestamp'; } else { $type = 'String'; } break; case 'Country': $type = 'Integer'; $mulValues = explode(',', $value); if (is_array($value)) { $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $value) . CRM_Core_DAO::VALUE_SEPARATOR; $type = 'String'; } elseif (!is_numeric($value) && !strstr($value, CRM_Core_DAO::VALUE_SEPARATOR)) { //fix for multi select country, CRM-3437 $mulValues = explode(',', $value); $validCountries = array(); foreach ($mulValues as $key => $countryVal) { $countries = array(); $countries['country'] = trim($countryVal); CRM_Utils_Array::lookupValue($countries, 'country', CRM_Core_PseudoConstant::country(), TRUE); if (empty($countries['country_id'])) { CRM_Utils_Array::lookupValue($countries, 'country', CRM_Core_PseudoConstant::countryIsoCode(), TRUE); } $validCountries[] = CRM_Utils_Array::value('country_id', $countries); } $value = implode(CRM_Core_DAO::VALUE_SEPARATOR, $validCountries); $type = 'String'; } elseif (!$value) { // CRM-3415 // using type of timestamp allows us to sneak in a null into db // gross but effective hack $value = NULL; $type = 'Timestamp'; } else { $type = 'String'; } break; case 'File': if (!$field['file_id']) { CRM_Core_Error::fatal(); } // need to add/update civicrm_entity_file $entityFileDAO = new CRM_Core_DAO_EntityFile(); $entityFileDAO->file_id = $field['file_id']; $entityFileDAO->find(TRUE); $entityFileDAO->entity_table = $field['table_name']; $entityFileDAO->entity_id = $field['entity_id']; $entityFileDAO->file_id = $field['file_id']; $entityFileDAO->save(); $entityFileDAO->free(); $value = $field['file_id']; $type = 'String'; break; case 'Date': $value = CRM_Utils_Date::isoToMysql($value); break; case 'Int': if (is_numeric($value)) { $type = 'Integer'; } else { $type = 'Timestamp'; } break; case 'ContactReference': if ($value == NULL) { $type = 'Timestamp'; } else { $type = 'Integer'; } break; case 'RichTextEditor': $type = 'String'; break; case 'Boolean': //fix for CRM-3290 $value = CRM_Utils_String::strtoboolstr($value); if ($value === FALSE) { $type = 'Timestamp'; } break; default: break; } if (strtolower($value) === "null") { // when unsetting a value to null, we don't need to validate the type // https://projectllr.atlassian.net/browse/VGQBMP-20 $set[$field['column_name']] = $value; } else { $set[$field['column_name']] = "%{$count}"; $params[$count] = array($value, $type); $count++; } } if (!empty($set)) { $setClause = array(); foreach ($set as $n => $v) { $setClause[] = "{$n} = {$v}"; } $setClause = implode(',', $setClause); if (!$where) { // do this only for insert $set['entity_id'] = "%{$count}"; $params[$count] = array($entityID, 'Integer'); $count++; $fieldNames = implode(',', array_keys($set)); $fieldValues = implode(',', array_values($set)); $query = "{$sqlOP} ( {$fieldNames} ) VALUES ( {$fieldValues} )"; // for multiple values we dont do on duplicate key update if (!$isMultiple) { $query .= " ON DUPLICATE KEY UPDATE {$setClause}"; } } else { $query = "{$sqlOP} SET {$setClause} {$where}"; } $dao = CRM_Core_DAO::executeQuery($query, $params); CRM_Utils_Hook::custom($hookOP, $hookID, $entityID, $fields); } } } }
/** * Get the values for pseudoconstants for name->value and reverse. * * @param array $defaults * (reference) the default values, some of which need to be resolved. * @param bool $reverse * True if we want to resolve the values in the reverse direction (value -> name). */ public static function resolveDefaults(&$defaults, $reverse = FALSE) { // Hack for birth_date. if (!empty($defaults['birth_date'])) { if (is_array($defaults['birth_date'])) { $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-'); } } CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'), $reverse); CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'), $reverse); CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), $reverse); CRM_Utils_Array::lookupValue($defaults, 'communication_style', CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'), $reverse); //lookup value of email/postal greeting, addressee, CRM-4575 foreach (self::$_greetingTypes as $greeting) { $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting); CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); } $blocks = array('address', 'im', 'phone'); foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; } foreach ($defaults[$name] as $count => &$values) { //get location type id. CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), $reverse); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (!empty($values['location_type_id'])) { $vcardNames = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'vcard_name')); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse); } // CRM-7597 // if we find a country id above, we need to restrict it to that country // rather than the list of all countries if (!empty($values['country_id'])) { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id']); } else { $stateProvinceList = CRM_Core_PseudoConstant::stateProvince(); } if (!CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse) && $reverse) { if (!empty($values['country_id'])) { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id'], 'abbreviation'); } else { $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceAbbreviation(); } CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse); } if (!empty($values['state_province_id'])) { $countyList = CRM_Core_PseudoConstant::countyForState($values['state_province_id']); } else { $countyList = CRM_Core_PseudoConstant::county(); } CRM_Utils_Array::lookupValue($values, 'county', $countyList, $reverse); } if ($name == 'im') { CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $reverse); } if ($name == 'phone') { CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), $reverse); } // Kill the reference. unset($values); } } }
/** * function convert params to v3.0 format before add location. */ function _civicrm_format_params_v2_to_v3(&$params, $locationTypeId = null) { // get the loc type id. if (!$locationTypeId) { // get location type. $locationTypeId = CRM_Utils_Array::value('location_type_id', $params); if (!$locationTypeId && array_key_exists('location_type', $params)) { require_once 'CRM/Core/PseudoConstant.php'; $locTypes =& CRM_Core_PseudoConstant::locationType(); $locType = $params['location_type']; if (is_array($params['location_type'])) { $locType = array_pop($params['location_type']); } $locationTypeId = CRM_Utils_Array::key($locType, $locTypes); } } // convert params into v3.0 format. $primary = $billing = array(); $blocks = array('Email', 'Phone', 'IM', 'OpenID'); // format params array. $firstBlockCount = null; foreach ($blocks as $block) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php"; eval('$fields =& CRM_Core_DAO_' . $block . '::fields( );'); $name = strtolower($block); $blockCount = 0; if (CRM_Utils_Array::value($name, $params)) { if (is_array($params[$name])) { $values = $params[$name]; $params[$name] = array(); foreach ($values as $val) { _civicrm_store_values($fields, $val, $params[$name][++$blockCount]); // check for primary and billing. if (CRM_Utils_Array::value('is_primary', $val)) { $primary[$name][$blockCount] = true; } if (CRM_Utils_Array::value('is_billing', $val)) { $primary[$name][$blockCount] = true; } if (!$firstBlockCount) { $firstBlockCount = $blockCount; } } } else { //need to get ids. if (in_array($name, array('im', 'phone'))) { require_once 'CRM/Core/PseudoConstant.php'; if ($name == 'im') { CRM_Utils_Array::lookupValue($params, 'provider', CRM_Core_PseudoConstant::IMProvider(), true); } else { CRM_Utils_Array::lookupValue($params, 'phone_type', CRM_Core_PseudoConstant::phoneType(), true); } } $locValues[$name] = array(); _civicrm_store_values($fields, $params, $locValues[$name][++$blockCount]); $params[$name] = $locValues[$name]; $firstBlockCount = $blockCount; unset($locValues[$name]); } // make first block as default primary when is_primary // is not set in sub array and set in main params array. if (!CRM_Utils_Array::value($name, $primary) && CRM_Utils_Array::value('is_primary', $params)) { $primary[$name][$firstBlockCount] = true; $params[$name][$firstBlockCount]['is_primary'] = true; } if (!CRM_Utils_Array::value($name, $billing) && CRM_Utils_Array::value('is_billing', $params)) { $billing[$name][$firstBlockCount] = true; $params[$name][$firstBlockCount]['is_billing'] = true; } } } //get the address fields. $addressCount = 1; $ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'city', 'street_address'); $addressTaken = false; foreach ($ids as $id) { if (array_key_exists($id, $params)) { if (!$addressTaken) { require_once 'CRM/Core/DAO/Address.php'; $fields =& CRM_Core_DAO_Address::fields(); _civicrm_store_values($fields, $params, $params['address'][$addressCount]); $addressTaken = true; } $params['address'][$addressCount][$id] = $params[$id]; unset($params[$id]); } } // format state and country. foreach (array('state_province', 'country') as $field) { $fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode'; if (CRM_Utils_Array::value('address', $params) && CRM_Utils_Array::value($field, $params['address'][$addressCount]) && is_numeric($params['address'][$addressCount][$field])) { $fValue =& $params['address'][$addressCount][$field]; eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );'); //kill the reference. unset($fValue); } } // check for primary address. if (CRM_Utils_Array::value('is_primary', $params)) { if ($addressTaken) { $primary['address'][$addressCount] = true; $params['address'][$addressCount]['is_primary'] = true; } unset($params['is_primary']); } if (CRM_Utils_Array::value('is_billing', $params)) { if ($addressTaken) { $billing['address'][$addressCount] = true; $params['address'][$addressCount]['is_billing'] = true; } unset($params['is_billing']); } // handle primary and billing reset. foreach (array('email', 'phone', 'im', 'address', 'openid') as $name) { if (!array_key_exists($name, $params) || CRM_Utils_System::isNull($params[$name])) { continue; } $errorMsg = null; $primaryBlockIndex = $billingBlockIndex = 0; if (array_key_exists($name, $primary)) { if (count($primary[$name]) > 1) { $errorMsg .= ts("<br />Multiple Primary %1.", array(1 => $block)); } else { $primaryBlockIndex = key($primary[$name]); } } if (array_key_exists($name, $billing)) { if (count($billing[$name]) > 1) { $errorMsg .= ts("<br />Multiple Billing %1.", array(1 => $block)); } else { $billingBlockIndex = key($billing[$name]); } } if ($errorMsg) { return civicrm_create_error($errorMsg); } foreach ($params[$name] as $count => &$values) { if ($primaryBlockIndex && $count != $primaryBlockIndex) { $values['is_primary'] = false; } if ($billingBlockIndex && $count != $billingBlockIndex) { $values['is_billing'] = false; } // get location type if not present in sub array. if (!CRM_Utils_Array::value('location_type_id', $values)) { $values['location_type_id'] = $locationTypeId; } //kill the reference. unset($values); } } // finally unset location_type and location type id. foreach (array('location_type', 'location_type_id') as $f) { if (isset($params[$f])) { unset($params[$f]); } } return $params; }
/** * View summary details of a contact * * @return void * @access public */ function view() { $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = true; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'website' => array('type' => 'websiteType', 'id' => 'website_type'), 'address' => array('skip' => true, 'customData' => 1), 'email' => array('skip' => true), 'openid' => array('skip' => true)); foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $blockVal['id']); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, false, null, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", null); } } } if (CRM_Utils_Array::value('gender_id', $defaults)) { $gender = CRM_Core_PseudoConstant::gender(); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(true, $contactType); // get contact tags require_once 'CRM/Core/BAO/EntityTag.php'; $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options'); $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes'); foreach ($configItems as $c => $t) { $varName = '_show' . $c; $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions); $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (CRM_Utils_Array::value('master_id', $addressValue) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $this->assign($defaults); // also assign the last modifed details require_once 'CRM/Core/BAO/Log.php'; $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q = $q . "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId)); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log')); $config = CRM_Core_Config::singleton(); if (isset($config->sunlight) && $config->sunlight) { $title = ts('Elected Officials'); $rest['sunlight'] = $title; $this->_viewOptions[$title] = true; } foreach ($rest as $k => $v) { if (CRM_Utils_Array::value($k, $this->_viewOptions)) { $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name'])); $weight += 10; } // see if any other modules want to add any tabs require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::tabs($allTabs, $this->_contactId); // now sort the tabs based on weight require_once 'CRM/Utils/Sort.php'; usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary'); $this->assign('selectedChild', $selectedChild); // hook for contact summary require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; // ignored but needed to prevent warnings CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * View summary details of a contact. */ public function view() { // Add js for tabs, in-place editing, and jstree for tags CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')->addSetting(array('summaryPrint' => array('mode' => $this->_print), 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')))); $this->assign('summaryPrint', $this->_print); $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); // Let summary page know if outbound mail is disabled so email links can be built conditionally $mailingBackend = Civi::settings()->get('mailing_backend'); $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type', 'daoName' => 'CRM_Core_DAO_Phone', 'fieldName' => 'phone_type_id'), 'im' => array('type' => 'IMProvider', 'id' => 'provider', 'daoName' => 'CRM_Core_DAO_IM', 'fieldName' => 'provider_id'), 'website' => array('type' => 'websiteType', 'id' => 'website_type', 'daoName' => 'CRM_Core_DAO_Website', 'fieldName' => 'website_type_id'), 'address' => array('skip' => TRUE, 'customData' => 1), 'email' => array('skip' => TRUE), 'openid' => array('skip' => TRUE)); foreach ($communicationType as $key => $value) { if (!empty($defaults[$key])) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); if (empty($value['skip'])) { $daoName = $value['daoName']; $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); } } if (isset($value['customData'])) { foreach ($defaults[$key] as $blockId => $blockVal) { $idValue = $blockVal['id']; if ($key == 'address') { if (!empty($blockVal['master_id'])) { $idValue = $blockVal['master_id']; } } $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), $this, $idValue); // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); } // reset template variable since that won't be of any use, and could be misleading $this->assign("dnc_viewCustomData", NULL); } } } if (!empty($defaults['gender_id'])) { $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']); } $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); if (!empty($communicationStyle)) { if (!empty($defaults['communication_style_id'])) { $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)]; } else { // Make sure the field is displayed as long as it is active, even if it is unset for this contact. $defaults['communication_style_display'] = ''; } } // to make contact type label available in the template - $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); // get contact tags $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); if (!empty($contactTags)) { $defaults['contactTag'] = implode(', ', $contactTags); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form $this->_editOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options'); foreach ($this->_editOptions as $blockName => $value) { $varName = '_show' . $blockName; $this->{$varName} = $value; $this->assign(substr($varName, 1), $this->{$varName}); } // get contact name of shared contact names $sharedAddresses = array(); $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); foreach ($defaults['address'] as $key => $addressValue) { if (!empty($addressValue['master_id']) && !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']) { $sharedAddresses[$key]['shared_address_display'] = array('address' => $addressValue['display'], 'name' => $shareAddressContactNames[$addressValue['master_id']]['name']); } } $this->assign('sharedAddresses', $sharedAddresses); //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { if ($contact->employer_id && $contact->organization_name) { $defaults['current_employer'] = $contact->organization_name; $defaults['current_employer_id'] = $contact->employer_id; } //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $defaults['external_identifier'] = $contact->external_identifier; $this->assign($defaults); // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query // also assign the last modifed details $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_view_options', TRUE); // show the tabs only if user has generic access to CiviCRM $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (!empty($this->_viewOptions[$name]) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q .= "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), 'class' => 'livePage'); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => array('title' => ts('Activities'), 'class' => 'livePage'), 'rel' => array('title' => ts('Relationships'), 'class' => 'livePage'), 'group' => array('title' => ts('Groups'), 'class' => 'ajaxForm'), 'note' => array('title' => ts('Notes'), 'class' => 'livePage'), 'tag' => array('title' => ts('Tags')), 'log' => array('title' => ts('Change Log'))); foreach ($rest as $k => $v) { if ($accessCiviCRM && !empty($this->_viewOptions[$k])) { $allTabs[] = $v + array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&cid={$this->_contactId}"), 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $entityType = $this->get('contactType'); $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups($entityType, 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), 'hideCount' => !$group['is_multiple'], 'class' => 'livePage'); $weight += 10; } $context = array('contact_id' => $this->_contactId); // see if any other modules want to add any tabs CRM_Utils_Hook::tabs($allTabs, $this->_contactId); CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); $allTabs[] = array('id' => 'summary', 'url' => '#contact-summary', 'title' => ts('Summary'), 'weight' => 0); // now sort the tabs based on weight usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); // hook for contact summary // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }
/** * * Get the values for pseudoconstants for name->value and reverse. * * @param array $defaults (reference) the default values, some of which need to be resolved. * @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name) * * @return none * @access public * @static */ static function resolveDefaults(&$defaults, $reverse = false) { // hack for birth_date if (CRM_Utils_Array::value('birth_date', $defaults)) { if (is_array($defaults['birth_date'])) { $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-'); } } CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse); CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse); //lookup value of email/postal greeting, addressee, CRM-4575 $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'email_greeting'); CRM_Utils_Array::lookupValue($defaults, 'email_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'postal_greeting'); CRM_Utils_Array::lookupValue($defaults, 'postal_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'addressee'); CRM_Utils_Array::lookupValue($defaults, 'addressee', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse); $blocks = array('address', 'im', 'phone'); foreach ($blocks as $name) { if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) { continue; } foreach ($defaults[$name] as $count => &$values) { //get location type id. CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse); if ($name == 'address') { // FIXME: lookupValue doesn't work for vcard_name if (CRM_Utils_Array::value('location_type_id', $values)) { $vcardNames =& CRM_Core_PseudoConstant::locationVcardName(); $values['vcard_name'] = $vcardNames[$values['location_type_id']]; } if (!CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse); } if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) { CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse); } CRM_Utils_Array::lookupValue($values, 'county', CRM_Core_PseudoConstant::county(), $reverse); } if ($name == 'im') { CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse); } if ($name == 'phone') { CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse); } //kill the reference. unset($values); } } }
/** * View summary details of a contact * * @return void * @access public */ function view() { $session =& CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); $session->pushUserContext($url); $params = array(); $defaults = array(); $ids = array(); $params['id'] = $params['contact_id'] = $this->_contactId; $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, true); $communicationType = array('phone' => array('type' => 'phoneType', 'id' => 'phone_type'), 'im' => array('type' => 'IMProvider', 'id' => 'provider'), 'address' => array('skip' => true), 'email' => array('skip' => true), 'openid' => array('skip' => true)); foreach ($communicationType as $key => $value) { if (CRM_Utils_Array::value($key, $defaults)) { foreach ($defaults[$key] as &$val) { CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationType(), false); if (!CRM_Utils_Array::value('skip', $value)) { eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '( );'); CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, false); } } } } if (CRM_Utils_Array::value('gender_id', $defaults)) { $gender = CRM_Core_PseudoConstant::gender(); $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; } if (CRM_Utils_Array::value('contact_sub_type', $defaults)) { $defaults['contact_sub_type'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $defaults['contact_sub_type'], 'label', 'name'); } // get the list of all the categories $tag =& CRM_Core_PseudoConstant::tag(); // get categories for the contact id require_once 'CRM/Core/BAO/EntityTag.php'; $entityTag =& CRM_Core_BAO_EntityTag::getTag($this->_contactId); if ($entityTag) { $categories = array(); foreach ($entityTag as $key) { $categories[] = $tag[$key]; } $defaults['contactTag'] = implode(', ', $categories); } $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); //Show blocks only if they are visible in edit form require_once 'CRM/Core/BAO/Preferences.php'; $this->_editOptions = CRM_Core_BAO_Preferences::valueOptions('contact_edit_options'); $configItems = array('CommBlock' => 'Communication Preferences', 'Demographics' => 'Demographics', 'TagsAndGroups' => 'Tags and Groups', 'Notes' => 'Notes'); foreach ($configItems as $c => $t) { $varName = '_show' . $c; $this->{$varName} = CRM_Utils_Array::value($c, $this->_editOptions); $this->assign(substr($varName, 1), $this->{$varName}); } //get the householdname if (isset($defaults['mail_to_household_id'])) { $HouseholdName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $defaults['mail_to_household_id'], 'display_name', 'id'); $this->assign('HouseholdName', $HouseholdName); } //get the current employer name if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { require_once 'CRM/Contact/BAO/Relationship.php'; $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId)); $defaults['current_employer'] = $currentEmployer[$this->_contactId]['org_name']; $defaults['current_employer_id'] = $currentEmployer[$this->_contactId]['org_id']; //for birthdate format with respect to birth format set $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); } $this->assign($defaults); // also assign the last modifed details require_once 'CRM/Core/BAO/Log.php'; $lastModified =& CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); $this->assign_by_ref('lastModified', $lastModified); $allTabs = array(); $weight = 10; $this->_viewOptions = CRM_Core_BAO_Preferences::valueOptions('contact_view_options', true); $changeLog = $this->_viewOptions['log']; $this->assign_by_ref('changeLog', $changeLog); require_once 'CRM/Core/Component.php'; $components = CRM_Core_Component::getEnabledComponents(); foreach ($components as $name => $component) { if (CRM_Utils_Array::value($name, $this->_viewOptions) && CRM_Core_Permission::access($component->name)) { $elem = $component->registerTab(); // FIXME: not very elegant, probably needs better approach // allow explicit id, if not defined, use keyword instead if (array_key_exists('id', $elem)) { $i = $elem['id']; } else { $i = $component->getKeyword(); } $u = $elem['url']; //appending isTest to url for test soft credit CRM-3891. //FIXME: hack ajax url. $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { $q = $q . "&isTest=1"; } $allTabs[] = array('id' => $i, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$u}", $q), 'title' => $elem['title'], 'weight' => $elem['weight'], 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId)); // make sure to get maximum weight, rest of tabs go after // FIXME: not very elegant again if ($weight < $elem['weight']) { $weight = $elem['weight']; } } } $rest = array('activity' => ts('Activities'), 'case' => ts('Cases'), 'rel' => ts('Relationships'), 'group' => ts('Groups'), 'note' => ts('Notes'), 'tag' => ts('Tags'), 'log' => ts('Change Log')); $config =& CRM_Core_Config::singleton(); if (isset($config->sunlight) && $config->sunlight) { $title = ts('Elected Officials'); $rest['sunlight'] = $title; $this->_viewOptions[$title] = true; } foreach ($rest as $k => $v) { if (CRM_Utils_Array::value($k, $this->_viewOptions)) { $allTabs[] = array('id' => $k, 'url' => CRM_Utils_System::url("civicrm/contact/view/{$k}", "reset=1&snippet=1&cid={$this->_contactId}"), 'title' => $v, 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId)); $weight += 10; } } // now add all the custom tabs $activeGroups =& CRM_Core_BAO_CustomGroup::getActiveGroups(CRM_Contact_BAO_Contact::getContactType($this->_contactId), 'civicrm/contact/view/cd', $this->_contactId); foreach ($activeGroups as $group) { $id = "custom_{$group['id']}"; $allTabs[] = array('id' => $id, 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild={$id}"), 'title' => $group['title'], 'weight' => $weight, 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId)); $weight += 10; } // see if any other modules want to add any tabs require_once 'CRM/Utils/Hook.php'; CRM_Utils_Hook::tabs($allTabs, $this->_contactId); if ($config->civiHRD) { $hrdOrder = array('rel' => 1, 'case' => 2, 'activity' => 3, 'participant' => 4, 'grant' => 5, 'contribute' => 6, 'group' => 7, 'note' => 8, 'tag' => 9, 'log' => 10); foreach ($allTabs as $i => $tab) { if (array_key_exists($tab['id'], $hrdOrder)) { $allTabs[$i]['weight'] = $hrdOrder[$tab['id']]; } } } // now sort the tabs based on weight require_once 'CRM/Utils/Sort.php'; usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); $this->assign('allTabs', $allTabs); $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, false, 'summary'); $this->assign('selectedChild', $selectedChild); // hook for contact summary require_once 'CRM/Utils/Hook.php'; $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; // ignored but needed to prevent warnings CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); if ($content) { $this->assign_by_ref('hookContent', $content); $this->assign('hookContentPlacement', $contentPlacement); } }