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