Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
35 | * Main page for viewing contact. | |
6a488035 TO |
36 | */ |
37 | class CRM_Contact_Page_View_Summary extends CRM_Contact_Page_View { | |
38 | ||
39 | /** | |
95cdcc0f | 40 | * Heart of the viewing process. |
6a488035 | 41 | * |
95cdcc0f | 42 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
6a488035 | 43 | */ |
00be9182 | 44 | public function preProcess() { |
6a488035 TO |
45 | parent::preProcess(); |
46 | ||
47 | // actions buttom contextMenu | |
48 | $menuItems = CRM_Contact_BAO_Contact::contextMenu($this->_contactId); | |
49 | ||
50 | $this->assign('actionsMenuList', $menuItems); | |
51 | ||
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) | |
57 | ); | |
58 | } | |
1d8a5bb2 | 59 | $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, |
0b330e6d | 60 | NULL, |
6a488035 TO |
61 | $this->_contactId, |
62 | NULL, | |
63 | $entitySubType | |
64 | ); | |
65 | ||
080d719e | 66 | CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_contactId); |
6a488035 TO |
67 | |
68 | // also create the form element for the activity links box | |
69 | $controller = new CRM_Core_Controller_Simple( | |
70 | 'CRM_Activity_Form_ActivityLinks', | |
71 | ts('Activity Links'), | |
72 | NULL, | |
73 | FALSE, | |
74 | FALSE, | |
75 | TRUE | |
76 | ); | |
77 | $controller->setEmbedded(TRUE); | |
78 | $controller->run(); | |
79 | } | |
80 | ||
81 | /** | |
95cdcc0f | 82 | * Heart of the viewing process. |
6a488035 | 83 | * |
95cdcc0f | 84 | * The runner gets all the meta data for the contact and calls the appropriate type of page to view. |
6a488035 | 85 | */ |
00be9182 | 86 | public function run() { |
6a488035 TO |
87 | $this->preProcess(); |
88 | ||
89 | if ($this->_action & CRM_Core_Action::UPDATE) { | |
90 | $this->edit(); | |
91 | } | |
92 | else { | |
93 | $this->view(); | |
94 | } | |
95 | ||
96 | return parent::run(); | |
97 | } | |
98 | ||
99 | /** | |
fe482240 | 100 | * Edit name and address of a contact. |
6a488035 | 101 | */ |
00be9182 | 102 | public function edit() { |
6a488035 TO |
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); | |
107 | ||
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(); | |
112 | } | |
113 | ||
114 | /** | |
fe482240 | 115 | * View summary details of a contact. |
6a488035 | 116 | */ |
00be9182 | 117 | public function view() { |
23223213 | 118 | // Add js for tabs, in-place editing, and jstree for tags |
6a488035 | 119 | CRM_Core_Resources::singleton() |
96ed17aa | 120 | ->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js', 2, 'html-header') |
0e44568b | 121 | ->addStyleFile('civicrm', 'css/contactSummary.css', 2, 'html-header') |
96ed17aa | 122 | ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header') |
58b65bf6 CW |
123 | ->addSetting(array( |
124 | 'summaryPrint' => array('mode' => $this->_print), | |
125 | 'tabSettings' => array('active' => CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary')), | |
126 | )); | |
46d2738c | 127 | $this->assign('summaryPrint', $this->_print); |
6a488035 TO |
128 | $session = CRM_Core_Session::singleton(); |
129 | $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); | |
130 | $session->pushUserContext($url); | |
ed0ca248 | 131 | $this->assignFieldMetadataToTemplate('Contact'); |
6a488035 | 132 | |
353ffa53 | 133 | $params = array(); |
6a488035 | 134 | $defaults = array(); |
6a488035 TO |
135 | |
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); | |
c3f51c13 | 139 | // Let summary page know if outbound mail is disabled so email links can be built conditionally |
aaffa79f | 140 | $mailingBackend = Civi::settings()->get('mailing_backend'); |
c3f51c13 | 141 | $this->assign('mailingOutboundOption', $mailingBackend['outBound_option']); |
6a488035 TO |
142 | |
143 | $communicationType = array( | |
144 | 'phone' => array( | |
145 | 'type' => 'phoneType', | |
146 | 'id' => 'phone_type', | |
365cc343 AS |
147 | 'daoName' => 'CRM_Core_DAO_Phone', |
148 | 'fieldName' => 'phone_type_id', | |
6a488035 TO |
149 | ), |
150 | 'im' => array( | |
151 | 'type' => 'IMProvider', | |
152 | 'id' => 'provider', | |
365cc343 AS |
153 | 'daoName' => 'CRM_Core_DAO_IM', |
154 | 'fieldName' => 'provider_id', | |
6a488035 TO |
155 | ), |
156 | 'website' => array( | |
157 | 'type' => 'websiteType', | |
158 | 'id' => 'website_type', | |
365cc343 AS |
159 | 'daoName' => 'CRM_Core_DAO_Website', |
160 | 'fieldName' => 'website_type_id', | |
6a488035 TO |
161 | ), |
162 | 'address' => array('skip' => TRUE, 'customData' => 1), | |
163 | 'email' => array('skip' => TRUE), | |
164 | 'openid' => array('skip' => TRUE), | |
165 | ); | |
166 | ||
167 | foreach ($communicationType as $key => $value) { | |
a7488080 | 168 | if (!empty($defaults[$key])) { |
6a488035 | 169 | foreach ($defaults[$key] as & $val) { |
8f785c9e | 170 | CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE); |
a7488080 | 171 | if (empty($value['skip'])) { |
365cc343 | 172 | $daoName = $value['daoName']; |
a810c9da | 173 | $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get'); |
6a488035 TO |
174 | CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); |
175 | } | |
176 | } | |
177 | if (isset($value['customData'])) { | |
178 | foreach ($defaults[$key] as $blockId => $blockVal) { | |
179 | $idValue = $blockVal['id']; | |
481a74f4 | 180 | if ($key == 'address') { |
a7488080 | 181 | if (!empty($blockVal['master_id'])) { |
6a488035 TO |
182 | $idValue = $blockVal['master_id']; |
183 | } | |
184 | } | |
0b330e6d | 185 | $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), NULL, $idValue); |
6a488035 TO |
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_"); | |
188 | } | |
189 | // reset template variable since that won't be of any use, and could be misleading | |
190 | $this->assign("dnc_viewCustomData", NULL); | |
191 | } | |
192 | } | |
193 | } | |
194 | ||
a7488080 | 195 | if (!empty($defaults['gender_id'])) { |
41b47b8a | 196 | $defaults['gender_display'] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_DAO_Contact', 'gender_id', $defaults['gender_id']); |
6a488035 TO |
197 | } |
198 | ||
aa62b355 OB |
199 | $communicationStyle = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'communication_style_id'); |
200 | if (!empty($communicationStyle)) { | |
a7488080 | 201 | if (!empty($defaults['communication_style_id'])) { |
aa62b355 OB |
202 | $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array::value('communication_style_id', $defaults)]; |
203 | } | |
204 | else { | |
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'] = ''; | |
207 | } | |
208 | } | |
209 | ||
6a488035 TO |
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, ', '); | |
213 | ||
214 | // get contact tags | |
215 | $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); | |
216 | ||
217 | if (!empty($contactTags)) { | |
d73974ac CW |
218 | $defaults['contactTag'] = $contactTags; |
219 | $defaults['allTags'] = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_contact', FALSE); | |
6a488035 TO |
220 | } |
221 | ||
222 | $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); | |
223 | ||
224 | //Show blocks only if they are visible in edit form | |
63cd4fcf DL |
225 | $this->_editOptions = CRM_Core_BAO_Setting::valueOptions( |
226 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
6a488035 TO |
227 | 'contact_edit_options' |
228 | ); | |
229 | ||
230 | foreach ($this->_editOptions as $blockName => $value) { | |
231 | $varName = '_show' . $blockName; | |
232 | $this->$varName = $value; | |
233 | $this->assign(substr($varName, 1), $this->$varName); | |
234 | } | |
235 | ||
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) { | |
a7488080 | 240 | if (!empty($addressValue['master_id']) && |
6a488035 TO |
241 | !$shareAddressContactNames[$addressValue['master_id']]['is_deleted'] |
242 | ) { | |
243 | $sharedAddresses[$key]['shared_address_display'] = array( | |
244 | 'address' => $addressValue['display'], | |
245 | 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'], | |
246 | ); | |
247 | } | |
248 | } | |
249 | $this->assign('sharedAddresses', $sharedAddresses); | |
250 | ||
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; | |
256 | } | |
6a488035 | 257 | } |
59f97da6 | 258 | |
46adf42c | 259 | $defaults['external_identifier'] = $contact->external_identifier; |
6a488035 TO |
260 | $this->assign($defaults); |
261 | ||
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); | |
266 | ||
267 | $allTabs = array(); | |
268 | $weight = 10; | |
269 | ||
63cd4fcf DL |
270 | $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions( |
271 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
272 | 'contact_view_options', | |
273 | TRUE | |
6a488035 | 274 | ); |
63cd4fcf DL |
275 | |
276 | // show the tabs only if user has generic access to CiviCRM | |
277 | $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); | |
278 | ||
6a488035 TO |
279 | $changeLog = $this->_viewOptions['log']; |
280 | $this->assign_by_ref('changeLog', $changeLog); | |
281 | $components = CRM_Core_Component::getEnabledComponents(); | |
282 | ||
283 | foreach ($components as $name => $component) { | |
a7488080 | 284 | if (!empty($this->_viewOptions[$name]) && |
63cd4fcf | 285 | CRM_Core_Permission::access($component->name) |
6a488035 TO |
286 | ) { |
287 | $elem = $component->registerTab(); | |
288 | ||
289 | // FIXME: not very elegant, probably needs better approach | |
290 | // allow explicit id, if not defined, use keyword instead | |
291 | if (array_key_exists('id', $elem)) { | |
292 | $i = $elem['id']; | |
293 | } | |
294 | else { | |
295 | $i = $component->getKeyword(); | |
296 | } | |
297 | $u = $elem['url']; | |
298 | ||
299 | //appending isTest to url for test soft credit CRM-3891. | |
300 | //FIXME: hack ajax url. | |
58b65bf6 | 301 | $q = "reset=1&force=1&cid={$this->_contactId}"; |
6a488035 | 302 | if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { |
58b65bf6 | 303 | $q .= "&isTest=1"; |
6a488035 TO |
304 | } |
305 | $allTabs[] = array( | |
306 | 'id' => $i, | |
307 | 'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q), | |
308 | 'title' => $elem['title'], | |
309 | 'weight' => $elem['weight'], | |
310 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), | |
6b754ecb | 311 | 'class' => 'livePage', |
6a488035 TO |
312 | ); |
313 | // make sure to get maximum weight, rest of tabs go after | |
314 | // FIXME: not very elegant again | |
315 | if ($weight < $elem['weight']) { | |
316 | $weight = $elem['weight']; | |
317 | } | |
318 | } | |
319 | } | |
320 | ||
2ede60ec | 321 | $rest = array( |
d6539f93 CW |
322 | 'activity' => array( |
323 | 'title' => ts('Activities'), | |
23223213 | 324 | 'class' => 'livePage', |
d6539f93 CW |
325 | ), |
326 | 'rel' => array( | |
327 | 'title' => ts('Relationships'), | |
23223213 | 328 | 'class' => 'livePage', |
d6539f93 CW |
329 | ), |
330 | 'group' => array( | |
331 | 'title' => ts('Groups'), | |
332 | 'class' => 'ajaxForm', | |
333 | ), | |
334 | 'note' => array( | |
335 | 'title' => ts('Notes'), | |
4e8065a9 | 336 | 'class' => 'livePage', |
d6539f93 CW |
337 | ), |
338 | 'tag' => array( | |
339 | 'title' => ts('Tags'), | |
340 | ), | |
341 | 'log' => array( | |
342 | 'title' => ts('Change Log'), | |
343 | ), | |
6a488035 TO |
344 | ); |
345 | ||
346 | foreach ($rest as $k => $v) { | |
8cc574cf | 347 | if ($accessCiviCRM && !empty($this->_viewOptions[$k])) { |
d6539f93 | 348 | $allTabs[] = $v + array( |
bed98343 | 349 | 'id' => $k, |
350 | 'url' => CRM_Utils_System::url( | |
351 | "civicrm/contact/view/$k", | |
352 | "reset=1&cid={$this->_contactId}" | |
353 | ), | |
354 | 'weight' => $weight, | |
355 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId), | |
356 | ); | |
6a488035 TO |
357 | $weight += 10; |
358 | } | |
359 | } | |
360 | ||
361 | // now add all the custom tabs | |
362 | $entityType = $this->get('contactType'); | |
2ede60ec DL |
363 | $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups( |
364 | $entityType, | |
6a488035 TO |
365 | 'civicrm/contact/view/cd', |
366 | $this->_contactId | |
367 | ); | |
368 | ||
369 | foreach ($activeGroups as $group) { | |
370 | $id = "custom_{$group['id']}"; | |
371 | $allTabs[] = array( | |
372 | 'id' => $id, | |
58b65bf6 | 373 | 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&selectedChild=$id"), |
6a488035 TO |
374 | 'title' => $group['title'], |
375 | 'weight' => $weight, | |
376 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), | |
a97040f5 | 377 | 'hideCount' => !$group['is_multiple'], |
21dfd5f5 | 378 | 'class' => 'livePage', |
6a488035 TO |
379 | ); |
380 | $weight += 10; | |
381 | } | |
382 | ||
b7bba1f9 | 383 | $context = array('contact_id' => $this->_contactId); |
6a488035 | 384 | // see if any other modules want to add any tabs |
23a75e37 | 385 | CRM_Utils_Hook::tabs($allTabs, $this->_contactId); |
b7bba1f9 | 386 | CRM_Utils_Hook::tabset('civicrm/contact/view', $allTabs, $context); |
6a488035 | 387 | |
7bcd233b | 388 | $allTabs[] = array( |
389 | 'id' => 'summary', | |
390 | 'url' => '#contact-summary', | |
391 | 'title' => ts('Summary'), | |
392 | 'weight' => 0, | |
393 | ); | |
394 | ||
6a488035 TO |
395 | // now sort the tabs based on weight |
396 | usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); | |
397 | ||
398 | $this->assign('allTabs', $allTabs); | |
399 | ||
6a488035 TO |
400 | // hook for contact summary |
401 | // ignored but needed to prevent warnings | |
402 | $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; | |
403 | CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); | |
404 | if ($content) { | |
405 | $this->assign_by_ref('hookContent', $content); | |
406 | $this->assign('hookContentPlacement', $contentPlacement); | |
407 | } | |
408 | } | |
409 | ||
4319322b EM |
410 | /** |
411 | * @return string | |
412 | */ | |
00be9182 | 413 | public function getTemplateFileName() { |
6a488035 | 414 | if ($this->_contactId) { |
ce80b209 | 415 | $contactSubtypes = $this->get('contactSubtype') ? explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->get('contactSubtype')) : array(); |
ae34b946 DS |
416 | |
417 | // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found. | |
418 | foreach ($contactSubtypes as $csType) { | |
419 | if ($csType) { | |
420 | $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl"; | |
421 | $template = CRM_Core_Page::getTemplate(); | |
422 | if ($template->template_exists($templateFile)) { | |
423 | return $templateFile; | |
424 | } | |
6a488035 TO |
425 | } |
426 | } | |
427 | } | |
428 | return parent::getTemplateFileName(); | |
429 | } | |
96025800 | 430 | |
6a488035 | 431 | } |