Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * Main page for viewing contact. | |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { | |
22 | ||
23 | /** | |
95cdcc0f | 24 | * Heart of the viewing process. |
6a488035 | 25 | * |
95cdcc0f | 26 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
6a488035 | 27 | */ |
00be9182 | 28 | public function preProcess() { |
6a488035 TO |
29 | parent::preProcess(); |
30 | ||
31 | // actions buttom contextMenu | |
32 | $menuItems = CRM_Contact_BAO_Contact::contextMenu($this->_contactId); | |
33 | ||
34 | $this->assign('actionsMenuList', $menuItems); | |
35 | ||
36 | //retrieve inline custom data | |
37 | $entityType = $this->get('contactType'); | |
38 | if ($entitySubType = $this->get('contactSubtype')) { | |
39 | $entitySubType = explode(CRM_Core_DAO::VALUE_SEPARATOR, | |
40 | trim($entitySubType, CRM_Core_DAO::VALUE_SEPARATOR) | |
41 | ); | |
42 | } | |
317103ab CW |
43 | // Custom groups with VIEW permission |
44 | $visibleGroups = CRM_Core_BAO_CustomGroup::getTree($entityType, | |
0b330e6d | 45 | NULL, |
6a488035 TO |
46 | $this->_contactId, |
47 | NULL, | |
317103ab CW |
48 | $entitySubType, |
49 | NULL, | |
50 | TRUE, | |
51 | NULL, | |
52 | FALSE, | |
53 | CRM_Core_Permission::VIEW | |
6a488035 TO |
54 | ); |
55 | ||
317103ab | 56 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $visibleGroups, FALSE, NULL, NULL, NULL, $this->_contactId, CRM_Core_Permission::EDIT); |
6a488035 TO |
57 | |
58 | // also create the form element for the activity links box | |
59 | $controller = new CRM_Core_Controller_Simple( | |
60 | 'CRM_Activity_Form_ActivityLinks', | |
61 | ts('Activity Links'), | |
62 | NULL, | |
63 | FALSE, | |
64 | FALSE, | |
65 | TRUE | |
66 | ); | |
67 | $controller->setEmbedded(TRUE); | |
68 | $controller->run(); | |
69 | } | |
70 | ||
71 | /** | |
95cdcc0f | 72 | * Heart of the viewing process. |
6a488035 | 73 | * |
95cdcc0f | 74 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
6a488035 | 75 | */ |
00be9182 | 76 | public function run() { |
6a488035 TO |
77 | $this->preProcess(); |
78 | ||
79 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
80 | $this->edit(); | |
81 | } | |
82 | else { | |
83 | $this->view(); | |
84 | } | |
85 | ||
86 | return parent::run(); | |
87 | } | |
88 | ||
89 | /** | |
fe482240 | 90 | * Edit name and address of a contact. |
6a488035 | 91 | */ |
00be9182 | 92 | public function edit() { |
6a488035 TO |
93 | // set the userContext stack |
94 | $session = CRM_Core_Session::singleton(); | |
95 | $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); | |
96 | $session->pushUserContext($url); | |
97 | ||
98 | $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Contact', ts('Contact Page'), CRM_Core_Action::UPDATE); | |
99 | $controller->setEmbedded(TRUE); | |
100 | $controller->process(); | |
101 | return $controller->run(); | |
102 | } | |
103 | ||
104 | /** | |
fe482240 | 105 | * View summary details of a contact. |
6a488035 | 106 | */ |
00be9182 | 107 | public function view() { |
23223213 | 108 | // Add js for tabs, in-place editing, and jstree for tags |
6a488035 | 109 | CRM_Core_Resources::singleton() |
96ed17aa | 110 | ->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header') |
0e44568b | 111 | ->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header') |
96ed17aa | 112 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
58b65bf6 CW |
113 | ->addSetting(array( |
114 | 'summaryPrint' => array('mode' => $this->_print), | |
c1bd8375 | 115 | 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'Alphanumeric', $this, FALSE, 'summary')), |
58b65bf6 | 116 | )); |
46d2738c | 117 | $this->assign('summaryPrint', $this->_print); |
6a488035 TO |
118 | $session = CRM_Core_Session::singleton(); |
119 | $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); | |
120 | $session->pushUserContext($url); | |
ed0ca248 | 121 | $this->assignFieldMetadataToTemplate('Contact'); |
6a488035 | 122 | |
affcc9d2 CW |
123 | $params = []; |
124 | $defaults = []; | |
6a488035 TO |
125 | |
126 | $params['id'] = $params['contact_id'] = $this->_contactId; | |
127 | $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; | |
128 | $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); | |
c3f51c13 | 129 | // Let summary page know if outbound mail is disabled so email links can be built conditionally |
aaffa79f | 130 | $mailingBackend = Civi::settings()->get('mailing_backend'); |
c3f51c13 | 131 | $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); |
6a488035 TO |
132 | |
133 | $communicationType = array( | |
134 | 'phone' => array( | |
135 | 'type' => 'phoneType', | |
136 | 'id' => 'phone_type', | |
365cc343 AS |
137 | 'daoName' => 'CRM_Core_DAO_Phone', |
138 | 'fieldName' => 'phone_type_id', | |
6a488035 TO |
139 | ), |
140 | 'im' => array( | |
141 | 'type' => 'IMProvider', | |
142 | 'id' => 'provider', | |
365cc343 AS |
143 | 'daoName' => 'CRM_Core_DAO_IM', |
144 | 'fieldName' => 'provider_id', | |
6a488035 TO |
145 | ), |
146 | 'website' => array( | |
147 | 'type' => 'websiteType', | |
148 | 'id' => 'website_type', | |
365cc343 AS |
149 | 'daoName' => 'CRM_Core_DAO_Website', |
150 | 'fieldName' => 'website_type_id', | |
6a488035 TO |
151 | ), |
152 | 'address' => array('skip' => TRUE, 'customData' => 1), | |
153 | 'email' => array('skip' => TRUE), | |
154 | 'openid' => array('skip' => TRUE), | |
155 | ); | |
156 | ||
157 | foreach ($communicationType as $key => $value) { | |
a7488080 | 158 | if (!empty($defaults[$key])) { |
6a488035 | 159 | foreach ($defaults[$key] as & $val) { |
8f785c9e | 160 | CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); |
a7488080 | 161 | if (empty($value['skip'])) { |
365cc343 | 162 | $daoName = $value['daoName']; |
a810c9da | 163 | $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); |
6a488035 TO |
164 | CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); |
165 | } | |
166 | } | |
167 | if (isset($value['customData'])) { | |
168 | foreach ($defaults[$key] as $blockId => $blockVal) { | |
169 | $idValue = $blockVal['id']; | |
481a74f4 | 170 | if ($key == 'address') { |
a7488080 | 171 | if (!empty($blockVal['master_id'])) { |
6a488035 TO |
172 | $idValue = $blockVal['master_id']; |
173 | } | |
174 | } | |
317103ab CW |
175 | $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), NULL, $idValue, NULL, [], |
176 | NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW); | |
6a488035 TO |
177 | // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. |
178 | $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); | |
179 | } | |
180 | // reset template variable since that won't be of any use, and could be misleading | |
181 | $this->assign("dnc_viewCustomData", NULL); | |
182 | } | |
183 | } | |
184 | } | |
185 | ||
a050cd73 | 186 | $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id'] ?? NULL); |
6a488035 | 187 | |
aa62b355 OB |
188 | $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); |
189 | if (!empty($communicationStyle)) { | |
a7488080 | 190 | if (!empty($defaults['communication_style_id'])) { |
2cfe2cf4 | 191 | $defaults['communication_style_display'] = $communicationStyle[$defaults['communication_style_id']]; |
aa62b355 OB |
192 | } |
193 | else { | |
194 | // Make sure the field is displayed as long as it is active, even if it is unset for this contact. | |
195 | $defaults['communication_style_display'] = ''; | |
196 | } | |
197 | } | |
198 | ||
6a488035 TO |
199 | // to make contact type label available in the template - |
200 | $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; | |
201 | $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); | |
202 | ||
203 | // get contact tags | |
7701d579 EM |
204 | $defaults['contactTag'] = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); |
205 | if (!empty($defaults['contactTag'])) { | |
d73974ac | 206 | $defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE); |
6a488035 TO |
207 | } |
208 | ||
209 | $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); | |
210 | ||
211 | //Show blocks only if they are visible in edit form | |
63cd4fcf DL |
212 | $this->_editOptions = CRM_Core_BAO_Setting::valueOptions( |
213 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
6a488035 TO |
214 | 'contact_edit_options' |
215 | ); | |
216 | ||
217 | foreach ($this->_editOptions as $blockName => $value) { | |
218 | $varName = '_show' . $blockName; | |
219 | $this->$varName = $value; | |
220 | $this->assign(substr($varName, 1), $this->$varName); | |
221 | } | |
222 | ||
223 | // get contact name of shared contact names | |
affcc9d2 | 224 | $sharedAddresses = []; |
6a488035 TO |
225 | $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); |
226 | foreach ($defaults['address'] as $key => $addressValue) { | |
a7488080 | 227 | if (!empty($addressValue['master_id']) && |
6a488035 TO |
228 | !$shareAddressContactNames[$addressValue['master_id']]['is_deleted'] |
229 | ) { | |
230 | $sharedAddresses[$key]['shared_address_display'] = array( | |
231 | 'address' => $addressValue['display'], | |
232 | 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'], | |
233 | ); | |
234 | } | |
235 | } | |
236 | $this->assign('sharedAddresses', $sharedAddresses); | |
237 | ||
238 | //get the current employer name | |
239 | if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { | |
240 | if ($contact->employer_id && $contact->organization_name) { | |
241 | $defaults['current_employer'] = $contact->organization_name; | |
242 | $defaults['current_employer_id'] = $contact->employer_id; | |
243 | } | |
6a488035 | 244 | } |
59f97da6 | 245 | |
46adf42c | 246 | $defaults['external_identifier'] = $contact->external_identifier; |
6a488035 TO |
247 | $this->assign($defaults); |
248 | ||
249 | // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query | |
250 | // also assign the last modifed details | |
251 | $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); | |
252 | $this->assign_by_ref('lastModified', $lastModified); | |
253 | ||
63cd4fcf DL |
254 | $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions( |
255 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
256 | 'contact_view_options', | |
257 | TRUE | |
6a488035 | 258 | ); |
63cd4fcf | 259 | |
6a488035 TO |
260 | $changeLog = $this->_viewOptions['log']; |
261 | $this->assign_by_ref('changeLog', $changeLog); | |
6a488035 | 262 | |
9a13600c CW |
263 | $this->assign('allTabs', $this->getTabs()); |
264 | ||
265 | // hook for contact summary | |
266 | // ignored but needed to prevent warnings | |
267 | $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; | |
268 | CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); | |
269 | if ($content) { | |
270 | $this->assign_by_ref('hookContent', $content); | |
271 | $this->assign('hookContentPlacement', $contentPlacement); | |
272 | } | |
273 | } | |
274 | ||
275 | /** | |
276 | * @return string | |
277 | */ | |
278 | public function getTemplateFileName() { | |
279 | if ($this->_contactId) { | |
affcc9d2 | 280 | $contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : []; |
9a13600c CW |
281 | |
282 | // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found. | |
283 | foreach ($contactSubtypes as $csType) { | |
284 | if ($csType) { | |
285 | $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl"; | |
286 | $template = CRM_Core_Page::getTemplate(); | |
287 | if ($template->template_exists($templateFile)) { | |
288 | return $templateFile; | |
289 | } | |
290 | } | |
291 | } | |
292 | } | |
293 | return parent::getTemplateFileName(); | |
294 | } | |
295 | ||
42e86792 CW |
296 | /** |
297 | * @return array | |
298 | */ | |
299 | public static function basicTabs() { | |
300 | return [ | |
301 | [ | |
302 | 'id' => 'summary', | |
0ebeb01a | 303 | 'template' => 'CRM/Contact/Page/View/Summary-tab.tpl', |
42e86792 CW |
304 | 'title' => ts('Summary'), |
305 | 'weight' => 0, | |
69078420 | 306 | 'icon' => 'crm-i fa-address-card-o', |
42e86792 CW |
307 | ], |
308 | [ | |
309 | 'id' => 'activity', | |
310 | 'title' => ts('Activities'), | |
311 | 'class' => 'livePage', | |
312 | 'weight' => 70, | |
b04115b4 | 313 | 'icon' => 'crm-i fa-tasks', |
42e86792 CW |
314 | ], |
315 | [ | |
316 | 'id' => 'rel', | |
317 | 'title' => ts('Relationships'), | |
318 | 'class' => 'livePage', | |
319 | 'weight' => 80, | |
b04115b4 | 320 | 'icon' => 'crm-i fa-handshake-o', |
42e86792 CW |
321 | ], |
322 | [ | |
323 | 'id' => 'group', | |
324 | 'title' => ts('Groups'), | |
325 | 'class' => 'ajaxForm', | |
326 | 'weight' => 90, | |
b04115b4 | 327 | 'icon' => 'crm-i fa-users', |
42e86792 CW |
328 | ], |
329 | [ | |
330 | 'id' => 'note', | |
331 | 'title' => ts('Notes'), | |
332 | 'class' => 'livePage', | |
333 | 'weight' => 100, | |
b04115b4 | 334 | 'icon' => 'crm-i fa-sticky-note-o', |
42e86792 CW |
335 | ], |
336 | [ | |
337 | 'id' => 'tag', | |
338 | 'title' => ts('Tags'), | |
339 | 'weight' => 110, | |
b04115b4 | 340 | 'icon' => 'crm-i fa-tags', |
42e86792 CW |
341 | ], |
342 | [ | |
343 | 'id' => 'log', | |
344 | 'title' => ts('Change Log'), | |
345 | 'weight' => 120, | |
b04115b4 | 346 | 'icon' => 'crm-i fa-history', |
42e86792 CW |
347 | ], |
348 | ]; | |
349 | } | |
350 | ||
9a13600c CW |
351 | /** |
352 | * @return array | |
353 | * @throws \CRM_Core_Exception | |
354 | */ | |
355 | public function getTabs() { | |
356 | $allTabs = []; | |
61d0aa85 | 357 | $getCountParams = []; |
9a13600c CW |
358 | $weight = 10; |
359 | ||
360 | foreach (CRM_Core_Component::getEnabledComponents() as $name => $component) { | |
a7488080 | 361 | if (!empty($this->_viewOptions[$name]) && |
63cd4fcf | 362 | CRM_Core_Permission::access($component->name) |
6a488035 TO |
363 | ) { |
364 | $elem = $component->registerTab(); | |
365 | ||
366 | // FIXME: not very elegant, probably needs better approach | |
367 | // allow explicit id, if not defined, use keyword instead | |
61d0aa85 | 368 | $i = $elem['id'] ?? $component->getKeyword(); |
6a488035 TO |
369 | $u = $elem['url']; |
370 | ||
371 | //appending isTest to url for test soft credit CRM-3891. | |
372 | //FIXME: hack ajax url. | |
58b65bf6 | 373 | $q = "reset=1&force=1&cid={$this->_contactId}"; |
6a488035 | 374 | if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { |
58b65bf6 | 375 | $q .= "&isTest=1"; |
6a488035 | 376 | } |
9a13600c | 377 | $allTabs[] = [ |
6a488035 TO |
378 | 'id' => $i, |
379 | 'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q), | |
380 | 'title' => $elem['title'], | |
381 | 'weight' => $elem['weight'], | |
61d0aa85 | 382 | 'count' => NULL, |
6b754ecb | 383 | 'class' => 'livePage', |
b04115b4 | 384 | 'icon' => $component->getIcon(), |
9a13600c | 385 | ]; |
61d0aa85 | 386 | $getCountParams[$i] = [$u, $this->_contactId]; |
6a488035 TO |
387 | } |
388 | } | |
389 | ||
9a13600c CW |
390 | // show the tabs only if user has generic access to CiviCRM |
391 | $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); | |
42e86792 CW |
392 | foreach (self::basicTabs() as $tab) { |
393 | if ($tab['id'] == 'summary') { | |
394 | $allTabs[] = $tab; | |
395 | } | |
396 | elseif ($accessCiviCRM && !empty($this->_viewOptions[$tab['id']])) { | |
397 | $allTabs[] = $tab + [ | |
e122e55d | 398 | 'url' => CRM_Utils_System::url("civicrm/contact/view/{$tab['id']}", "reset=1&cid={$this->_contactId}"), |
61d0aa85 | 399 | 'count' => NULL, |
9a13600c | 400 | ]; |
61d0aa85 | 401 | $getCountParams[$tab['id']] = [$tab['id'], $this->_contactId]; |
42e86792 | 402 | $weight = $tab['weight'] + 10; |
6a488035 TO |
403 | } |
404 | } | |
405 | ||
406 | // now add all the custom tabs | |
407 | $entityType = $this->get('contactType'); | |
2ede60ec DL |
408 | $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups( |
409 | $entityType, | |
6a488035 TO |
410 | 'civicrm/contact/view/cd', |
411 | $this->_contactId | |
412 | ); | |
413 | ||
414 | foreach ($activeGroups as $group) { | |
415 | $id = "custom_{$group['id']}"; | |
9a13600c | 416 | $allTabs[] = [ |
6a488035 | 417 | 'id' => $id, |
58b65bf6 | 418 | 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"), |
6a488035 TO |
419 | 'title' => $group['title'], |
420 | 'weight' => $weight, | |
61d0aa85 | 421 | 'count' => NULL, |
a97040f5 | 422 | 'hideCount' => !$group['is_multiple'], |
21dfd5f5 | 423 | 'class' => 'livePage', |
2af06525 | 424 | 'icon' => 'crm-i ' . ($group['icon'] ?: 'fa-gear'), |
9a13600c | 425 | ]; |
61d0aa85 | 426 | $getCountParams[$id] = [$id, $this->_contactId, $group['table_name']]; |
6a488035 TO |
427 | $weight += 10; |
428 | } | |
429 | ||
98872503 | 430 | // Allow other modules to add or remove tabs |
9a13600c | 431 | $context = ['contact_id' => $this->_contactId]; |
b7bba1f9 | 432 | CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); |
6a488035 | 433 | |
fcae142a CW |
434 | $expectedKeys = ['count', 'class', 'template', 'hideCount', 'icon']; |
435 | ||
61d0aa85 | 436 | foreach ($allTabs as &$tab) { |
fcae142a CW |
437 | // Ensure tab has all expected keys |
438 | $tab += array_fill_keys($expectedKeys, NULL); | |
439 | // Get tab counts last to avoid wasting time; if a tab was removed by hook, the count isn't needed. | |
61d0aa85 CW |
440 | if (!isset($tab['count']) && isset($getCountParams[$tab['id']])) { |
441 | $tab['count'] = call_user_func_array(['CRM_Contact_BAO_Contact', 'getCountComponent'], $getCountParams[$tab['id']]); | |
442 | } | |
443 | } | |
444 | ||
6a488035 | 445 | // now sort the tabs based on weight |
9a13600c CW |
446 | usort($allTabs, ['CRM_Utils_Sort', 'cmpFunc']); |
447 | return $allTabs; | |
6a488035 | 448 | } |
96025800 | 449 | |
6a488035 | 450 | } |