3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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
extends CRM_Core_Page
{
43 * the id of the object being viewed (note/relationship etc)
51 * the contact id of the contact being viewed
56 protected $_contactId;
59 * The action that we are performing
67 * The permission we have on this contact
72 protected $_permission;
75 * Heart of the viewing process. The runner gets all the meta data for
76 * the contact and calls the appropriate type of page to view.
82 function preProcess() {
84 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
85 $this->assign('id', $this->_id
);
87 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
89 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
92 $this->assign('searchKey', $qfKey);
94 // retrieve the group contact id, so that we can get contact id
95 $gcid = CRM_Utils_Request
::retrieve('gcid', 'Positive', $this);
98 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
101 $this->_contactId
= CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id');
104 if (!$this->_contactId
) {
105 CRM_Core_Error
::statusBounce(
106 ts('We could not find a contact id.'),
107 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
111 // ensure that the id does exist
112 if ( CRM_Core_DAO
::getFieldValue( 'CRM_Contact_DAO_Contact', $this->_contactId
, 'id' ) != $this->_contactId
) {
113 CRM_Core_Error
::statusBounce(
114 ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId
)),
115 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
119 $this->assign('contactId', $this->_contactId
);
121 // see if we can get prev/next positions from qfKey
122 $navContacts = array(
123 'prevContactID' => NULL,
124 'prevContactName' => NULL,
125 'nextContactID' => NULL,
126 'nextContactName' => NULL,
127 'nextPrevError' => 0,
130 $pos = CRM_Core_BAO_PrevNextCache
::getPositions("civicrm search $qfKey",
136 if (isset($pos['prev'])) {
137 $navContacts['prevContactID'] = $pos['prev']['id1'];
138 $navContacts['prevContactName'] = $pos['prev']['data'];
142 if (isset($pos['next'])) {
143 $navContacts['nextContactID'] = $pos['next']['id1'];
144 $navContacts['nextContactName'] = $pos['next']['data'];
149 // seems like we did not find any contacts
150 // maybe due to bug CRM-9096
151 // however we should account for 1 contact results (which dont have prev next)
152 if (!$pos['foundEntry']) {
153 $navContacts['nextPrevError'] = 1;
157 $this->assign($navContacts);
159 $path = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
160 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('View Contact'),
163 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('Search Results'),
164 'url' => self
::getSearchURL(),
167 if ($image_URL = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'image_URL')) {
169 //CRM-7265 --time being fix.
170 $config = CRM_Core_Config
::singleton();
171 $image_URL = str_replace('https://', 'http://', $image_URL);
172 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'enableSSL')) {
173 $image_URL = str_replace('http://', 'https://', $image_URL);
176 list($imageWidth, $imageHeight) = getimagesize($image_URL);
177 list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact
::getThumbSize($imageWidth, $imageHeight);
178 $this->assign("imageWidth", $imageWidth);
179 $this->assign("imageHeight", $imageHeight);
180 $this->assign("imageThumbWidth", $imageThumbWidth);
181 $this->assign("imageThumbHeight", $imageThumbHeight);
182 $this->assign("imageURL", $image_URL);
185 // also store in session for future use
186 $session = CRM_Core_Session
::singleton();
187 $session->set('view.id', $this->_contactId
);
189 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
190 $this->assign('action', $this->_action
);
192 // check logged in user permission
193 self
::checkUserPermission($this);
195 list($displayName, $contactImage,
196 $contactType, $contactSubtype, $contactImageUrl
197 ) = self
::getContactDetails($this->_contactId
);
198 $this->assign('displayName', $displayName);
200 $this->set('contactType', $contactType);
201 $this->set('contactSubtype', $contactSubtype);
203 // add to recently viewed block
204 $isDeleted = (bool) CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'is_deleted');
206 $recentOther = array(
207 'imageUrl' => $contactImageUrl,
208 'subtype' => $contactSubtype,
209 'isDeleted' => $isDeleted,
212 if (($session->get('userID') == $this->_contactId
) ||
213 CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)
215 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}");
218 if (($session->get('userID') != $this->_contactId
) && CRM_Core_Permission
::check('delete contacts')
221 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}");
224 CRM_Utils_Recent
::add($displayName,
225 CRM_Utils_System
::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"),
232 $this->assign('isDeleted', $isDeleted);
235 $title = self
::setTitle($this->_contactId
, $isDeleted);
236 $this->assign('title', $title);
238 // Check if this is default domain contact CRM-10482
239 if (CRM_Contact_BAO_Contact
::checkDomainContact($this->_contactId
)) {
240 $this->assign('domainContact', TRUE);
242 $this->assign('domainContact', FALSE);
245 // Add links for actions menu
246 self
::addUrls($this, $this->_contactId
);
248 if ($contactType == 'Organization' &&
249 CRM_Core_Permission
::check('administer Multiple Organizations') &&
250 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
,
254 //check is any relationship between the organization and groups
255 $groupOrg = CRM_Contact_BAO_GroupOrganization
::hasGroupAssociated($this->_contactId
);
257 $groupOrganizationUrl = CRM_Utils_System
::url('civicrm/group',
258 "reset=1&oid={$this->_contactId}"
260 $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
266 * Get meta details of the contact.
268 * @return array contact fields in fixed order
271 static function getContactDetails($contactId) {
272 return list($displayName,
277 ) = CRM_Contact_BAO_Contact
::getDisplayAndImage($contactId,
283 function getSearchURL() {
284 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
285 $context = CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'search');
286 $this->assign('context', $context);
289 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
294 $urlParams = 'force=1';
298 $urlString = 'civicrm/contact/search/custom';
302 $urlString = 'civicrm/contact/search/custom';
304 $urlParams = '_qf_Custom_display=true';
309 $urlString = 'civicrm/contact/search/advanced';
313 $urlString = 'civicrm/contact/search/builder';
317 $urlString = 'civicrm/contact/search/basic';
321 $urlString = 'civicrm/contact/search';
326 $urlString = 'civicrm/group/search';
330 $urlParams .= "&qfKey=$qfKey";
333 $urlString = 'civicrm/contact/search/basic';
336 return CRM_Utils_System
::url($urlString, $urlParams);
339 static function checkUserPermission($page, $contactID = NULL) {
340 // check for permissions
341 $page->_permission
= NULL;
344 $contactID = $page->_contactId
;
347 // automatically grant permissin for users on their own record. makes
348 // things easier in dashboard
349 $session = CRM_Core_Session
::singleton();
351 if ($session->get('userID') == $contactID) {
352 $page->assign('permission', 'edit');
353 $page->_permission
= CRM_Core_Permission
::EDIT
;
354 // deleted contacts’ stuff should be (at best) only viewable
356 elseif (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'is_deleted') and CRM_Core_Permission
::check('access deleted contacts')) {
357 $page->assign('permission', 'view');
358 $page->_permission
= CRM_Core_Permission
::VIEW
;
360 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
361 $page->assign('permission', 'edit');
362 $page->_permission
= CRM_Core_Permission
::EDIT
;
364 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::VIEW
)) {
365 $page->assign('permission', 'view');
366 $page->_permission
= CRM_Core_Permission
::VIEW
;
369 $session->pushUserContext(CRM_Utils_System
::url('civicrm', 'reset=1'));
370 CRM_Core_Error
::statusBounce(ts('You do not have the necessary permission to view this contact.'));
374 static function setTitle($contactId, $isDeleted = FALSE) {
375 static $contactDetails;
376 $displayName = $contactImage = NULL;
377 if (!isset($contactDetails[$contactId])) {
378 list($displayName, $contactImage) = self
::getContactDetails($contactId);
379 $contactDetails[$contactId] = array(
380 'displayName' => $displayName,
381 'contactImage' => $contactImage,
385 $displayName = $contactDetails[$contactId]['displayName'];
386 $contactImage = $contactDetails[$contactId]['contactImage'];
390 $title = "{$contactImage} {$displayName}";
392 $title = "<del>{$title}</del>";
395 // Inline-edit places its own title on the page
396 CRM_Utils_System
::setTitle('CiviCRM', '<span id="crm-remove-title" style="display:none">CiviCRM</span>');
402 * Add urls for display in the actions menu
404 static function addUrls(&$obj, $cid) {
405 $config = CRM_Core_Config
::singleton();
406 $session = CRM_Core_Session
::singleton();
407 $uid = CRM_Core_BAO_UFMatch
::getUFId($cid);
409 // To do: we should also allow drupal users with CRM_Core_Permission::check( 'view user profiles' ) true to access $userRecordUrl
410 // but this is currently returning false regardless of permission set for the role. dgg
411 if ($config->userSystem
->is_drupal
== '1' &&
412 ($session->get('userID') == $cid || CRM_Core_Permission
::check('administer users'))
414 $userRecordUrl = CRM_Utils_System
::url('user/' . $uid);
416 elseif ($config->userFramework
== 'Joomla') {
417 $userRecordUrl = NULL;
418 // if logged in user is super user, then he can view other users joomla profile
419 if (JFactory
::getUser()->authorise('core.admin')) {
420 $userRecordUrl = $config->userFrameworkBaseURL
. "index.php?option=com_users&view=user&task=user.edit&id=" . $uid;
422 elseif ($session->get('userID') == $cid) {
423 $userRecordUrl = $config->userFrameworkBaseURL
. "index.php?option=com_admin&view=profile&layout=edit&id=" . $uid;
427 $userRecordUrl = NULL;
429 $obj->assign('userRecordUrl', $userRecordUrl);
430 $obj->assign('userRecordId', $uid);
432 elseif (($config->userSystem
->is_drupal
== '1' && CRM_Core_Permission
::check('administer users')) ||
433 ($config->userFramework
== 'Joomla' &&
434 JFactory
::getUser()->authorise('core.create', 'com_users')
437 $userAddUrl = CRM_Utils_System
::url('civicrm/contact/view/useradd',
438 'reset=1&action=add&cid=' . $cid
440 $obj->assign('userAddUrl', $userAddUrl);
443 if (CRM_Core_Permission
::check('access Contact Dashboard')) {
444 $dashboardURL = CRM_Utils_System
::url('civicrm/user',
447 $obj->assign('dashboardURL', $dashboardURL);
450 // See if other modules want to add links to the activtity bar
451 $hookLinks = CRM_Utils_Hook
::links('view.contact.activity',
454 CRM_Core_DAO
::$_nullObject,
455 CRM_Core_DAO
::$_nullObject
457 if (is_array($hookLinks)) {
458 $obj->assign('hookLinks', $hookLinks);