3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * Main page for viewing contact.
37 class CRM_Contact_Page_View_Summary
extends CRM_Contact_Page_View
{
40 * Heart of the viewing process.
42 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
44 public function preProcess() {
47 // actions buttom contextMenu
48 $menuItems = CRM_Contact_BAO_Contact
::contextMenu($this->_contactId
);
50 $this->assign('actionsMenuList', $menuItems);
52 //retrieve inline custom data
53 $entityType = $this->get('contactType');
54 if ($entitySubType = $this->get('contactSubtype')) {
55 $entitySubType = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
56 trim($entitySubType, CRM_Core_DAO
::VALUE_SEPARATOR
)
59 $groupTree = CRM_Core_BAO_CustomGroup
::getTree($entityType,
66 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_contactId
);
68 // also create the form element for the activity links box
69 $controller = new CRM_Core_Controller_Simple(
70 'CRM_Activity_Form_ActivityLinks',
77 $controller->setEmbedded(TRUE);
82 * Heart of the viewing process.
84 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
86 public function run() {
89 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
100 * Edit name and address of a contact.
102 public function edit() {
103 // set the userContext stack
104 $session = CRM_Core_Session
::singleton();
105 $url = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
106 $session->pushUserContext($url);
108 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Contact', ts('Contact Page'), CRM_Core_Action
::UPDATE
);
109 $controller->setEmbedded(TRUE);
110 $controller->process();
111 return $controller->run();
115 * View summary details of a contact.
117 public function view() {
118 // Add js for tabs, in-place editing, and jstree for tags
119 CRM_Core_Resources
::singleton()
120 ->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header')
121 ->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header')
122 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
124 'summaryPrint' => array('mode' => $this->_print
),
125 'tabSettings' => array('active' => CRM_Utils_Request
::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')),
127 $this->assign('summaryPrint', $this->_print
);
128 $session = CRM_Core_Session
::singleton();
129 $url = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
130 $session->pushUserContext($url);
131 $this->assignFieldMetadataToTemplate('Contact');
136 $params['id'] = $params['contact_id'] = $this->_contactId
;
137 $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
138 $contact = CRM_Contact_BAO_Contact
::retrieve($params, $defaults, TRUE);
139 // Let summary page know if outbound mail is disabled so email links can be built conditionally
140 $mailingBackend = Civi
::settings()->get('mailing_backend');
141 $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']);
143 $communicationType = array(
145 'type' => 'phoneType',
146 'id' => 'phone_type',
147 'daoName' => 'CRM_Core_DAO_Phone',
148 'fieldName' => 'phone_type_id',
151 'type' => 'IMProvider',
153 'daoName' => 'CRM_Core_DAO_IM',
154 'fieldName' => 'provider_id',
157 'type' => 'websiteType',
158 'id' => 'website_type',
159 'daoName' => 'CRM_Core_DAO_Website',
160 'fieldName' => 'website_type_id',
162 'address' => array('skip' => TRUE, 'customData' => 1),
163 'email' => array('skip' => TRUE),
164 'openid' => array('skip' => TRUE),
167 foreach ($communicationType as $key => $value) {
168 if (!empty($defaults[$key])) {
169 foreach ($defaults[$key] as & $val) {
170 CRM_Utils_Array
::lookupValue($val, 'location_type', CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
171 if (empty($value['skip'])) {
172 $daoName = $value['daoName'];
173 $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
174 CRM_Utils_Array
::lookupValue($val, $value['id'], $pseudoConst, FALSE);
177 if (isset($value['customData'])) {
178 foreach ($defaults[$key] as $blockId => $blockVal) {
179 $idValue = $blockVal['id'];
180 if ($key == 'address') {
181 if (!empty($blockVal['master_id'])) {
182 $idValue = $blockVal['master_id'];
185 $groupTree = CRM_Core_BAO_CustomGroup
::getTree(ucfirst($key), NULL, $idValue);
186 // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
187 $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
189 // reset template variable since that won't be of any use, and could be misleading
190 $this->assign("dnc_viewCustomData", NULL);
195 if (!empty($defaults['gender_id'])) {
196 $defaults['gender_display'] = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']);
199 $communicationStyle = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'communication_style_id');
200 if (!empty($communicationStyle)) {
201 if (!empty($defaults['communication_style_id'])) {
202 $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array
::value('communication_style_id', $defaults)];
205 // Make sure the field is displayed as long as it is active, even if it is unset for this contact.
206 $defaults['communication_style_display'] = '';
210 // to make contact type label available in the template -
211 $contactType = array_key_exists('contact_sub_type', $defaults) ?
$defaults['contact_sub_type'] : $defaults['contact_type'];
212 $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType
::contactTypePairs(TRUE, $contactType, ', ');
215 $contactTags = CRM_Core_BAO_EntityTag
::getContactTags($this->_contactId
);
217 if (!empty($contactTags)) {
218 $defaults['contactTag'] = $contactTags;
219 $defaults['allTags'] = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_contact', FALSE);
222 $defaults['privacy_values'] = CRM_Core_SelectValues
::privacy();
224 //Show blocks only if they are visible in edit form
225 $this->_editOptions
= CRM_Core_BAO_Setting
::valueOptions(
226 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
227 'contact_edit_options'
230 foreach ($this->_editOptions
as $blockName => $value) {
231 $varName = '_show' . $blockName;
232 $this->$varName = $value;
233 $this->assign(substr($varName, 1), $this->$varName);
236 // get contact name of shared contact names
237 $sharedAddresses = array();
238 $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils
::getAddressShareContactNames($defaults['address']);
239 foreach ($defaults['address'] as $key => $addressValue) {
240 if (!empty($addressValue['master_id']) &&
241 !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
243 $sharedAddresses[$key]['shared_address_display'] = array(
244 'address' => $addressValue['display'],
245 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
249 $this->assign('sharedAddresses', $sharedAddresses);
251 //get the current employer name
252 if (CRM_Utils_Array
::value('contact_type', $defaults) == 'Individual') {
253 if ($contact->employer_id
&& $contact->organization_name
) {
254 $defaults['current_employer'] = $contact->organization_name
;
255 $defaults['current_employer_id'] = $contact->employer_id
;
259 $defaults['external_identifier'] = $contact->external_identifier
;
260 $this->assign($defaults);
262 // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
263 // also assign the last modifed details
264 $lastModified = CRM_Core_BAO_Log
::lastModified($this->_contactId
, 'civicrm_contact');
265 $this->assign_by_ref('lastModified', $lastModified);
267 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(
268 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
269 'contact_view_options',
273 $changeLog = $this->_viewOptions
['log'];
274 $this->assign_by_ref('changeLog', $changeLog);
276 $this->assign('allTabs', $this->getTabs());
278 // hook for contact summary
279 // ignored but needed to prevent warnings
280 $contentPlacement = CRM_Utils_Hook
::SUMMARY_BELOW
;
281 CRM_Utils_Hook
::summary($this->_contactId
, $content, $contentPlacement);
283 $this->assign_by_ref('hookContent', $content);
284 $this->assign('hookContentPlacement', $contentPlacement);
291 public function getTemplateFileName() {
292 if ($this->_contactId
) {
293 $contactSubtypes = $this->get('contactSubtype') ?
explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->get('contactSubtype')) : array();
295 // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
296 foreach ($contactSubtypes as $csType) {
298 $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
299 $template = CRM_Core_Page
::getTemplate();
300 if ($template->template_exists($templateFile)) {
301 return $templateFile;
306 return parent
::getTemplateFileName();
312 public static function basicTabs() {
316 'url' => '#contact-summary',
317 'title' => ts('Summary'),
319 'icon' => 'crm-i fa-address-card-o'
323 'title' => ts('Activities'),
324 'class' => 'livePage',
326 'icon' => 'crm-i fa-tasks',
330 'title' => ts('Relationships'),
331 'class' => 'livePage',
333 'icon' => 'crm-i fa-handshake-o',
337 'title' => ts('Groups'),
338 'class' => 'ajaxForm',
340 'icon' => 'crm-i fa-users',
344 'title' => ts('Notes'),
345 'class' => 'livePage',
347 'icon' => 'crm-i fa-sticky-note-o',
351 'title' => ts('Tags'),
353 'icon' => 'crm-i fa-tags',
357 'title' => ts('Change Log'),
359 'icon' => 'crm-i fa-history',
366 * @throws \CRM_Core_Exception
368 public function getTabs() {
372 foreach (CRM_Core_Component
::getEnabledComponents() as $name => $component) {
373 if (!empty($this->_viewOptions
[$name]) &&
374 CRM_Core_Permission
::access($component->name
)
376 $elem = $component->registerTab();
378 // FIXME: not very elegant, probably needs better approach
379 // allow explicit id, if not defined, use keyword instead
380 if (array_key_exists('id', $elem)) {
384 $i = $component->getKeyword();
388 //appending isTest to url for test soft credit CRM-3891.
389 //FIXME: hack ajax url.
390 $q = "reset=1&force=1&cid={$this->_contactId}";
391 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
396 'url' => CRM_Utils_System
::url("civicrm/contact/view/$u", $q),
397 'title' => $elem['title'],
398 'weight' => $elem['weight'],
399 'count' => CRM_Contact_BAO_Contact
::getCountComponent($u, $this->_contactId
),
400 'class' => 'livePage',
401 'icon' => $component->getIcon(),
406 // show the tabs only if user has generic access to CiviCRM
407 $accessCiviCRM = CRM_Core_Permission
::check('access CiviCRM');
408 foreach (self
::basicTabs() as $tab) {
409 if ($tab['id'] == 'summary') {
412 elseif ($accessCiviCRM && !empty($this->_viewOptions
[$tab['id']])) {
413 $allTabs[] = $tab +
[
414 'url' => CRM_Utils_System
::url("civicrm/contact/view/{$tab['id']}", "reset=1&cid={$this->_contactId}"),
415 'count' => CRM_Contact_BAO_Contact
::getCountComponent($tab['id'], $this->_contactId
),
417 $weight = $tab['weight'] +
10;
421 // now add all the custom tabs
422 $entityType = $this->get('contactType');
423 $activeGroups = CRM_Core_BAO_CustomGroup
::getActiveGroups(
425 'civicrm/contact/view/cd',
429 foreach ($activeGroups as $group) {
430 $id = "custom_{$group['id']}";
433 'url' => CRM_Utils_System
::url($group['path'], $group['query'] . "&selectedChild=$id"),
434 'title' => $group['title'],
436 'count' => CRM_Contact_BAO_Contact
::getCountComponent($id, $this->_contactId
, $group['table_name']),
437 'hideCount' => !$group['is_multiple'],
438 'class' => 'livePage',
439 'icon' => 'crm-i fa-gear',
444 $context = ['contact_id' => $this->_contactId
];
445 // see if any other modules want to add any tabs
446 CRM_Utils_Hook
::tabs($allTabs, $this->_contactId
);
447 CRM_Utils_Hook
::tabset('civicrm/contact/view', $allTabs, $context);
449 // now sort the tabs based on weight
450 usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']);