Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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() { | |
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 | $session = CRM_Core_Session::singleton(); | |
141 | $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); | |
142 | $session->pushUserContext($url); | |
143 | ||
144 | $params = array(); | |
145 | $defaults = array(); | |
146 | $ids = array(); | |
147 | ||
148 | $params['id'] = $params['contact_id'] = $this->_contactId; | |
149 | $params['noRelationships'] = $params['noNotes'] = $params['noGroups'] = TRUE; | |
150 | $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, TRUE); | |
151 | ||
152 | $communicationType = array( | |
153 | 'phone' => array( | |
154 | 'type' => 'phoneType', | |
155 | 'id' => 'phone_type', | |
156 | ), | |
157 | 'im' => array( | |
158 | 'type' => 'IMProvider', | |
159 | 'id' => 'provider', | |
160 | ), | |
161 | 'website' => array( | |
162 | 'type' => 'websiteType', | |
163 | 'id' => 'website_type', | |
164 | ), | |
165 | 'address' => array('skip' => TRUE, 'customData' => 1), | |
166 | 'email' => array('skip' => TRUE), | |
167 | 'openid' => array('skip' => TRUE), | |
168 | ); | |
169 | ||
170 | foreach ($communicationType as $key => $value) { | |
171 | if (CRM_Utils_Array::value($key, $defaults)) { | |
172 | foreach ($defaults[$key] as & $val) { | |
173 | CRM_Utils_Array::lookupValue($val, 'location_type', CRM_Core_PseudoConstant::locationDisplayName(), FALSE); | |
174 | if (!CRM_Utils_Array::value('skip', $value)) { | |
175 | eval('$pseudoConst = CRM_Core_PseudoConstant::' . $value['type'] . '();'); | |
176 | CRM_Utils_Array::lookupValue($val, $value['id'], $pseudoConst, FALSE); | |
177 | } | |
178 | } | |
179 | if (isset($value['customData'])) { | |
180 | foreach ($defaults[$key] as $blockId => $blockVal) { | |
181 | $idValue = $blockVal['id']; | |
182 | if ( $key == 'address' ) { | |
183 | if ( CRM_Utils_Array::value( 'master_id', $blockVal ) ) { | |
184 | $idValue = $blockVal['master_id']; | |
185 | } | |
186 | } | |
187 | $groupTree = CRM_Core_BAO_CustomGroup::getTree(ucfirst($key), | |
188 | $this, | |
189 | $idValue | |
190 | ); | |
191 | // we setting the prefix to dnc_ below so that we don't overwrite smarty's grouptree var. | |
192 | $defaults[$key][$blockId]['custom'] = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, "dnc_"); | |
193 | } | |
194 | // reset template variable since that won't be of any use, and could be misleading | |
195 | $this->assign("dnc_viewCustomData", NULL); | |
196 | } | |
197 | } | |
198 | } | |
199 | ||
200 | if (CRM_Utils_Array::value('gender_id', $defaults)) { | |
201 | $gender = CRM_Core_PseudoConstant::gender(TRUE); | |
202 | $defaults['gender_display'] = $gender[CRM_Utils_Array::value('gender_id', $defaults)]; | |
203 | } | |
204 | ||
205 | // to make contact type label available in the template - | |
206 | $contactType = array_key_exists('contact_sub_type', $defaults) ? $defaults['contact_sub_type'] : $defaults['contact_type']; | |
207 | $defaults['contact_type_label'] = CRM_Contact_BAO_ContactType::contactTypePairs(TRUE, $contactType, ', '); | |
208 | ||
209 | // get contact tags | |
210 | $contactTags = CRM_Core_BAO_EntityTag::getContactTags($this->_contactId); | |
211 | ||
212 | if (!empty($contactTags)) { | |
213 | $defaults['contactTag'] = implode(', ', $contactTags); | |
214 | } | |
215 | ||
216 | $defaults['privacy_values'] = CRM_Core_SelectValues::privacy(); | |
217 | ||
218 | //Show blocks only if they are visible in edit form | |
63cd4fcf DL |
219 | $this->_editOptions = CRM_Core_BAO_Setting::valueOptions( |
220 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
6a488035 TO |
221 | 'contact_edit_options' |
222 | ); | |
223 | ||
224 | foreach ($this->_editOptions as $blockName => $value) { | |
225 | $varName = '_show' . $blockName; | |
226 | $this->$varName = $value; | |
227 | $this->assign(substr($varName, 1), $this->$varName); | |
228 | } | |
229 | ||
230 | // get contact name of shared contact names | |
231 | $sharedAddresses = array(); | |
232 | $shareAddressContactNames = CRM_Contact_BAO_Contact_Utils::getAddressShareContactNames($defaults['address']); | |
233 | foreach ($defaults['address'] as $key => $addressValue) { | |
234 | if (CRM_Utils_Array::value('master_id', $addressValue) && | |
235 | !$shareAddressContactNames[$addressValue['master_id']]['is_deleted'] | |
236 | ) { | |
237 | $sharedAddresses[$key]['shared_address_display'] = array( | |
238 | 'address' => $addressValue['display'], | |
239 | 'name' => $shareAddressContactNames[$addressValue['master_id']]['name'], | |
240 | ); | |
241 | } | |
242 | } | |
243 | $this->assign('sharedAddresses', $sharedAddresses); | |
244 | ||
245 | //get the current employer name | |
246 | if (CRM_Utils_Array::value('contact_type', $defaults) == 'Individual') { | |
247 | if ($contact->employer_id && $contact->organization_name) { | |
248 | $defaults['current_employer'] = $contact->organization_name; | |
249 | $defaults['current_employer_id'] = $contact->employer_id; | |
250 | } | |
251 | ||
252 | //for birthdate format with respect to birth format set | |
253 | $this->assign('birthDateViewFormat', CRM_Utils_Array::value('qfMapping', CRM_Utils_Date::checkBirthDateFormat())); | |
254 | } | |
255 | ||
256 | $this->assign($defaults); | |
257 | ||
258 | // FIXME: when we sort out TZ isssues with DATETIME/TIMESTAMP, we can skip next query | |
259 | // also assign the last modifed details | |
260 | $lastModified = CRM_Core_BAO_Log::lastModified($this->_contactId, 'civicrm_contact'); | |
261 | $this->assign_by_ref('lastModified', $lastModified); | |
262 | ||
263 | $allTabs = array(); | |
264 | $weight = 10; | |
265 | ||
63cd4fcf DL |
266 | $this->_viewOptions = CRM_Core_BAO_Setting::valueOptions( |
267 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
268 | 'contact_view_options', | |
269 | TRUE | |
6a488035 | 270 | ); |
63cd4fcf DL |
271 | |
272 | // show the tabs only if user has generic access to CiviCRM | |
273 | $accessCiviCRM = CRM_Core_Permission::check('access CiviCRM'); | |
274 | ||
6a488035 TO |
275 | $changeLog = $this->_viewOptions['log']; |
276 | $this->assign_by_ref('changeLog', $changeLog); | |
277 | $components = CRM_Core_Component::getEnabledComponents(); | |
278 | ||
279 | foreach ($components as $name => $component) { | |
63cd4fcf DL |
280 | if ( |
281 | CRM_Utils_Array::value($name, $this->_viewOptions) && | |
282 | CRM_Core_Permission::access($component->name) | |
6a488035 TO |
283 | ) { |
284 | $elem = $component->registerTab(); | |
285 | ||
286 | // FIXME: not very elegant, probably needs better approach | |
287 | // allow explicit id, if not defined, use keyword instead | |
288 | if (array_key_exists('id', $elem)) { | |
289 | $i = $elem['id']; | |
290 | } | |
291 | else { | |
292 | $i = $component->getKeyword(); | |
293 | } | |
294 | $u = $elem['url']; | |
295 | ||
296 | //appending isTest to url for test soft credit CRM-3891. | |
297 | //FIXME: hack ajax url. | |
298 | $q = "reset=1&snippet=1&force=1&cid={$this->_contactId}"; | |
299 | if (CRM_Utils_Request::retrieve('isTest', 'Positive', $this)) { | |
300 | $q = $q . "&isTest=1"; | |
301 | } | |
302 | $allTabs[] = array( | |
303 | 'id' => $i, | |
304 | 'url' => CRM_Utils_System::url("civicrm/contact/view/$u", $q), | |
305 | 'title' => $elem['title'], | |
306 | 'weight' => $elem['weight'], | |
307 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($u, $this->_contactId), | |
308 | ); | |
309 | // make sure to get maximum weight, rest of tabs go after | |
310 | // FIXME: not very elegant again | |
311 | if ($weight < $elem['weight']) { | |
312 | $weight = $elem['weight']; | |
313 | } | |
314 | } | |
315 | } | |
316 | ||
2ede60ec DL |
317 | $rest = array( |
318 | 'activity' => ts('Activities'), | |
6a488035 TO |
319 | 'case' => ts('Cases'), |
320 | 'rel' => ts('Relationships'), | |
321 | 'group' => ts('Groups'), | |
322 | 'note' => ts('Notes'), | |
323 | 'tag' => ts('Tags'), | |
324 | 'log' => ts('Change Log'), | |
325 | ); | |
326 | ||
327 | foreach ($rest as $k => $v) { | |
63cd4fcf | 328 | if ($accessCiviCRM && CRM_Utils_Array::value($k, $this->_viewOptions)) { |
6a488035 TO |
329 | $allTabs[] = array( |
330 | 'id' => $k, | |
63cd4fcf DL |
331 | 'url' => CRM_Utils_System::url( |
332 | "civicrm/contact/view/$k", | |
6a488035 TO |
333 | "reset=1&snippet=1&cid={$this->_contactId}" |
334 | ), | |
335 | 'title' => $v, | |
336 | 'weight' => $weight, | |
337 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($k, $this->_contactId), | |
338 | ); | |
339 | $weight += 10; | |
340 | } | |
341 | } | |
342 | ||
343 | // now add all the custom tabs | |
344 | $entityType = $this->get('contactType'); | |
2ede60ec DL |
345 | $activeGroups = CRM_Core_BAO_CustomGroup::getActiveGroups( |
346 | $entityType, | |
6a488035 TO |
347 | 'civicrm/contact/view/cd', |
348 | $this->_contactId | |
349 | ); | |
350 | ||
351 | foreach ($activeGroups as $group) { | |
352 | $id = "custom_{$group['id']}"; | |
353 | $allTabs[] = array( | |
354 | 'id' => $id, | |
355 | 'url' => CRM_Utils_System::url($group['path'], $group['query'] . "&snippet=1&selectedChild=$id"), | |
356 | 'title' => $group['title'], | |
357 | 'weight' => $weight, | |
358 | 'count' => CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $group['table_name']), | |
359 | ); | |
360 | $weight += 10; | |
361 | } | |
362 | ||
363 | // see if any other modules want to add any tabs | |
364 | CRM_Utils_Hook::tabs($allTabs, $this->_contactId); | |
365 | ||
366 | // now sort the tabs based on weight | |
367 | usort($allTabs, array('CRM_Utils_Sort', 'cmpFunc')); | |
368 | ||
369 | $this->assign('allTabs', $allTabs); | |
370 | ||
371 | $selectedChild = CRM_Utils_Request::retrieve('selectedChild', 'String', $this, FALSE, 'summary'); | |
372 | $this->assign('selectedChild', $selectedChild); | |
373 | ||
374 | // hook for contact summary | |
375 | // ignored but needed to prevent warnings | |
376 | $contentPlacement = CRM_Utils_Hook::SUMMARY_BELOW; | |
377 | CRM_Utils_Hook::summary($this->_contactId, $content, $contentPlacement); | |
378 | if ($content) { | |
379 | $this->assign_by_ref('hookContent', $content); | |
380 | $this->assign('hookContentPlacement', $contentPlacement); | |
381 | } | |
382 | } | |
383 | ||
384 | function getTemplateFileName() { | |
385 | if ($this->_contactId) { | |
386 | $csType = $this->get('contactSubtype'); | |
387 | if ($csType) { | |
388 | $templateFile = "CRM/Contact/Page/View/SubType/{$csType}.tpl"; | |
389 | $template = CRM_Core_Page::getTemplate(); | |
390 | if ($template->template_exists($templateFile)) { | |
391 | return $templateFile; | |
392 | } | |
393 | } | |
394 | } | |
395 | return parent::getTemplateFileName(); | |
396 | } | |
397 | } | |
398 |