3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
37 * Main page for viewing contact.
40 class CRM_Contact_Page_View_Summary
extends CRM_Contact_Page_View
{
43 * Heart of the viewing process. The runner gets all the meta data for
44 * the contact and calls the appropriate type of page to view.
50 function preProcess() {
53 // actions buttom contextMenu
54 $menuItems = CRM_Contact_BAO_Contact
::contextMenu($this->_contactId
);
56 $this->assign('actionsMenuList', $menuItems);
58 //retrieve inline custom data
59 $entityType = $this->get('contactType');
60 if ($entitySubType = $this->get('contactSubtype')) {
61 $entitySubType = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
62 trim($entitySubType, CRM_Core_DAO
::VALUE_SEPARATOR
)
65 $groupTree = &CRM_Core_BAO_CustomGroup
::getTree($entityType,
72 CRM_Core_BAO_CustomGroup
::buildCustomDataView($this,
76 // also create the form element for the activity links box
77 $controller = new CRM_Core_Controller_Simple(
78 'CRM_Activity_Form_ActivityLinks',
85 $controller->setEmbedded(TRUE);
90 * Heart of the viewing process. The runner gets all the meta data for
91 * the contact and calls the appropriate type of page to view.
100 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
107 return parent
::run();
111 * Edit name and address of a contact
117 // set the userContext stack
118 $session = CRM_Core_Session
::singleton();
119 $url = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
120 $session->pushUserContext($url);
122 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_Contact', ts('Contact Page'), CRM_Core_Action
::UPDATE
);
123 $controller->setEmbedded(TRUE);
124 $controller->process();
125 return $controller->run();
129 * View summary details of a contact
135 // Add js for in-place editing and jstree for tags
136 CRM_Core_Resources
::singleton()
137 ->addScriptFile('civicrm', 'templates/CRM/Contact/Page/View/Summary.js')
138 ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE)
139 ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header')
140 ->addSetting(array('summaryPrint' => array('mode' => $this->_print
)));
141 $this->assign('summaryPrint', $this->_print
);
142 $session = CRM_Core_Session
::singleton();
143 $url = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
144 $session->pushUserContext($url);
150 $params['id'] = $params['contact_id'] = $this->_contactId
;
151 $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE;
152 $contact = CRM_Contact_BAO_Contact
::retrieve($params, $defaults, TRUE);
154 $communicationType = array(
156 'type' => 'phoneType',
157 'id' => 'phone_type',
158 'daoName' => 'CRM_Core_DAO_Phone',
159 'fieldName' => 'phone_type_id',
162 'type' => 'IMProvider',
164 'daoName' => 'CRM_Core_DAO_IM',
165 'fieldName' => 'provider_id',
168 'type' => 'websiteType',
169 'id' => 'website_type',
170 'daoName' => 'CRM_Core_DAO_Website',
171 'fieldName' => 'website_type_id',
173 'address' => array('skip' => TRUE, 'customData' => 1),
174 'email' => array('skip' => TRUE),
175 'openid' => array('skip' => TRUE),
178 foreach ($communicationType as $key => $value) {
179 if (CRM_Utils_Array
::value($key, $defaults)) {
180 foreach ($defaults[$key] as & $val) {
181 CRM_Utils_Array
::lookupValue($val, 'location_type', CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id', array('labelColumn' => 'display_name')), FALSE);
182 if (!CRM_Utils_Array
::value('skip', $value)) {
183 $daoName = $value['daoName'];
184 $pseudoConst = $daoName::buildOptions($value['fieldName'], 'get');
185 CRM_Utils_Array
::lookupValue($val, $value['id'], $pseudoConst, FALSE);
188 if (isset($value['customData'])) {
189 foreach ($defaults[$key] as $blockId => $blockVal) {
190 $idValue = $blockVal['id'];
191 if ( $key == 'address' ) {
192 if ( CRM_Utils_Array
::value( 'master_id', $blockVal ) ) {
193 $idValue = $blockVal['master_id'];
196 $groupTree = CRM_Core_BAO_CustomGroup
::getTree(ucfirst($key),
200 // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var.
201 $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup
::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_");
203 // reset template variable since that won't be of any use, and could be misleading
204 $this->assign("dnc_viewCustomData", NULL);
209 if (CRM_Utils_Array
::value('gender_id', $defaults)) {
210 $gender = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id', array('localize' => TRUE));
211 $defaults['gender_display'] = $gender[CRM_Utils_Array
::value('gender_id', $defaults)];
214 $communicationStyle = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'communication_style_id');
215 if (!empty($communicationStyle)) {
216 if (CRM_Utils_Array
::value('communication_style_id', $defaults)) {
217 $defaults['communication_style_display'] = $communicationStyle[CRM_Utils_Array
::value('communication_style_id', $defaults)];
220 // Make sure the field is displayed as long as it is active, even if it is unset for this contact.
221 $defaults['communication_style_display'] = '';
225 // to make contact type label available in the template -
226 $contactType = array_key_exists('contact_sub_type', $defaults) ?
$defaults['contact_sub_type'] : $defaults['contact_type'];
227 $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType
::contactTypePairs(TRUE, $contactType, ', ');
230 $contactTags = CRM_Core_BAO_EntityTag
::getContactTags($this->_contactId
);
232 if (!empty($contactTags)) {
233 $defaults['contactTag'] = implode(', ', $contactTags);
236 $defaults['privacy_values'] = CRM_Core_SelectValues
::privacy();
238 //Show blocks only if they are visible in edit form
239 $this->_editOptions
= CRM_Core_BAO_Setting
::valueOptions(
240 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
241 'contact_edit_options'
244 foreach ($this->_editOptions
as $blockName => $value) {
245 $varName = '_show' . $blockName;
246 $this->$varName = $value;
247 $this->assign(substr($varName, 1), $this->$varName);
250 // get contact name of shared contact names
251 $sharedAddresses = array();
252 $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils
::getAddressShareContactNames($defaults['address']);
253 foreach ($defaults['address'] as $key => $addressValue) {
254 if (CRM_Utils_Array
::value('master_id', $addressValue) &&
255 !$shareAddressContactNames[$addressValue['master_id']]['is_deleted']
257 $sharedAddresses[$key]['shared_address_display'] = array(
258 'address' => $addressValue['display'],
259 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'],
263 $this->assign('sharedAddresses', $sharedAddresses);
265 //get the current employer name
266 if (CRM_Utils_Array
::value('contact_type', $defaults) == 'Individual') {
267 if ($contact->employer_id
&& $contact->organization_name
) {
268 $defaults['current_employer'] = $contact->organization_name
;
269 $defaults['current_employer_id'] = $contact->employer_id
;
272 //for birthdate format with respect to birth format set
273 $this->assign('birthDateViewFormat', CRM_Utils_Array
::value('qfMapping', CRM_Utils_Date
::checkBirthDateFormat()));
276 $this->assign($defaults);
278 // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query
279 // also assign the last modifed details
280 $lastModified = CRM_Core_BAO_Log
::lastModified($this->_contactId
, 'civicrm_contact');
281 $this->assign_by_ref('lastModified', $lastModified);
286 $this->_viewOptions
= CRM_Core_BAO_Setting
::valueOptions(
287 CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
288 'contact_view_options',
292 // show the tabs only if user has generic access to CiviCRM
293 $accessCiviCRM = CRM_Core_Permission
::check('access CiviCRM');
295 $changeLog = $this->_viewOptions
['log'];
296 $this->assign_by_ref('changeLog', $changeLog);
297 $components = CRM_Core_Component
::getEnabledComponents();
299 foreach ($components as $name => $component) {
301 CRM_Utils_Array
::value($name, $this->_viewOptions
) &&
302 CRM_Core_Permission
::access($component->name
)
304 $elem = $component->registerTab();
306 // FIXME: not very elegant, probably needs better approach
307 // allow explicit id, if not defined, use keyword instead
308 if (array_key_exists('id', $elem)) {
312 $i = $component->getKeyword();
316 //appending isTest to url for test soft credit CRM-3891.
317 //FIXME: hack ajax url.
318 $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}";
319 if (CRM_Utils_Request
::retrieve('isTest', 'Positive', $this)) {
320 $q = $q . "&isTest=1";
324 'url' => CRM_Utils_System
::url("civicrm/contact/view/$u", $q),
325 'title' => $elem['title'],
326 'weight' => $elem['weight'],
327 'count' => CRM_Contact_BAO_Contact
::getCountComponent($u, $this->_contactId
),
329 // make sure to get maximum weight, rest of tabs go after
330 // FIXME: not very elegant again
331 if ($weight < $elem['weight']) {
332 $weight = $elem['weight'];
338 'activity' => ts('Activities'),
339 'case' => ts('Cases'),
340 'rel' => ts('Relationships'),
341 'group' => ts('Groups'),
342 'note' => ts('Notes'),
344 'log' => ts('Change Log'),
347 foreach ($rest as $k => $v) {
348 if ($accessCiviCRM && CRM_Utils_Array
::value($k, $this->_viewOptions
)) {
351 'url' => CRM_Utils_System
::url(
352 "civicrm/contact/view/$k",
353 "reset=1&snippet=1&cid={$this->_contactId}"
357 'count' => CRM_Contact_BAO_Contact
::getCountComponent($k, $this->_contactId
),
363 // now add all the custom tabs
364 $entityType = $this->get('contactType');
365 $activeGroups = CRM_Core_BAO_CustomGroup
::getActiveGroups(
367 'civicrm/contact/view/cd',
371 foreach ($activeGroups as $group) {
372 $id = "custom_{$group['id']}";
375 'url' => CRM_Utils_System
::url($group['path'], $group['query'] . "&snippet=1&selectedChild=$id"),
376 'title' => $group['title'],
378 'count' => CRM_Contact_BAO_Contact
::getCountComponent($id, $this->_contactId
, $group['table_name']),
383 // see if any other modules want to add any tabs
384 CRM_Utils_Hook
::tabs($allTabs, $this->_contactId
);
386 // now sort the tabs based on weight
387 usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc'));
389 $this->assign('allTabs', $allTabs);
391 $selectedChild = CRM_Utils_Request
::retrieve('selectedChild', 'String', $this, FALSE, 'summary');
392 $this->assign('selectedChild', $selectedChild);
394 // hook for contact summary
395 // ignored but needed to prevent warnings
396 $contentPlacement = CRM_Utils_Hook
::SUMMARY_BELOW
;
397 CRM_Utils_Hook
::summary($this->_contactId
, $content, $contentPlacement);
399 $this->assign_by_ref('hookContent', $content);
400 $this->assign('hookContentPlacement', $contentPlacement);
404 function getTemplateFileName() {
405 if ($this->_contactId
) {
406 $contactSubtypes = $this->get('contactSubtype') ?
407 explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $this->get('contactSubtype')) : array();
409 // there could be multiple subtypes. We check templates for each of the subtype, and return the first one found.
410 foreach ($contactSubtypes as $csType) {
412 $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl";
413 $template = CRM_Core_Page
::getTemplate();
414 if ($template->template_exists($templateFile)) {
415 return $templateFile;
420 return parent
::getTemplateFileName();