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