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