3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * Main page for viewing contact.
37 class CRM_Contact_Page_View
extends CRM_Core_Page
{
40 * The id of the object being viewed (note/relationship etc)
47 * The contact id of the contact being viewed
51 protected $_contactId;
54 * The action that we are performing
61 * The permission we have on this contact
65 protected $_permission;
68 * Heart of the viewing process.
70 * The runner gets all the meta data for the contact and calls the appropriate type of page to view.
72 public function preProcess() {
74 $this->_id
= CRM_Utils_Request
::retrieve('id', 'Positive', $this);
75 $this->assign('id', $this->_id
);
77 $qfKey = CRM_Utils_Request
::retrieve('key', 'String', $this);
79 if (!CRM_Utils_Rule
::qfKey($qfKey)) {
82 $this->assign('searchKey', $qfKey);
84 // retrieve the group contact id, so that we can get contact id
85 $gcid = CRM_Utils_Request
::retrieve('gcid', 'Positive', $this);
88 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
91 $this->_contactId
= CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_GroupContact', $gcid, 'contact_id');
94 if (!$this->_contactId
) {
95 CRM_Core_Error
::statusBounce(
96 ts('We could not find a contact id.'),
97 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
101 // ensure that the id does exist
102 if (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'id') != $this->_contactId
) {
103 CRM_Core_Error
::statusBounce(
104 ts('A Contact with that ID does not exist: %1', array(1 => $this->_contactId
)),
105 CRM_Utils_System
::url('civicrm/dashboard', 'reset=1')
109 $this->assign('contactId', $this->_contactId
);
111 // see if we can get prev/next positions from qfKey
112 $navContacts = array(
113 'prevContactID' => NULL,
114 'prevContactName' => NULL,
115 'nextContactID' => NULL,
116 'nextContactName' => NULL,
117 'nextPrevError' => 0,
120 $pos = CRM_Core_BAO_PrevNextCache
::getPositions("civicrm search $qfKey",
126 if (isset($pos['prev'])) {
127 $navContacts['prevContactID'] = $pos['prev']['id1'];
128 $navContacts['prevContactName'] = $pos['prev']['data'];
132 if (isset($pos['next'])) {
133 $navContacts['nextContactID'] = $pos['next']['id1'];
134 $navContacts['nextContactName'] = $pos['next']['data'];
139 // seems like we did not find any contacts
140 // maybe due to bug CRM-9096
141 // however we should account for 1 contact results (which dont have prev next)
142 if (!$pos['foundEntry']) {
143 $navContacts['nextPrevError'] = 1;
147 $this->assign($navContacts);
149 $path = CRM_Utils_System
::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId
);
150 CRM_Utils_System
::appendBreadCrumb(array(array('title' => ts('View Contact'), 'url' => $path)));
152 if ($image_URL = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'image_URL')) {
153 //CRM-7265 --time being fix.
154 $config = CRM_Core_Config
::singleton();
155 $image_URL = str_replace('https://', 'http://', $image_URL);
156 if (CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
, 'enableSSL')) {
157 $image_URL = str_replace('http://', 'https://', $image_URL);
160 list($imageWidth, $imageHeight) = getimagesize(CRM_Utils_String
::unstupifyUrl($image_URL));
161 list($imageThumbWidth, $imageThumbHeight) = CRM_Contact_BAO_Contact
::getThumbSize($imageWidth, $imageHeight);
162 $this->assign("imageWidth", $imageWidth);
163 $this->assign("imageHeight", $imageHeight);
164 $this->assign("imageThumbWidth", $imageThumbWidth);
165 $this->assign("imageThumbHeight", $imageThumbHeight);
166 $this->assign("imageURL", $image_URL);
169 // also store in session for future use
170 $session = CRM_Core_Session
::singleton();
171 $session->set('view.id', $this->_contactId
);
173 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
174 $this->assign('action', $this->_action
);
176 // check logged in user permission
177 self
::checkUserPermission($this);
179 list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self
::getContactDetails($this->_contactId
);
180 $this->assign('displayName', $displayName);
182 $this->set('contactType', $contactType);
184 // note: there could still be multiple subtypes. We just trimming the outer separator.
185 $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO
::VALUE_SEPARATOR
));
187 // add to recently viewed block
188 $isDeleted = (bool) CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'is_deleted');
190 $recentOther = array(
191 'imageUrl' => $contactImageUrl,
192 'subtype' => $contactSubtype,
193 'isDeleted' => $isDeleted,
196 if (CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
197 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}");
200 if (($session->get('userID') != $this->_contactId
) && CRM_Core_Permission
::check('delete contacts')
203 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}");
206 CRM_Utils_Recent
::add($displayName,
207 CRM_Utils_System
::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"),
214 $this->assign('isDeleted', $isDeleted);
217 $title = self
::setTitle($this->_contactId
, $isDeleted);
218 $this->assign('title', $title);
220 // Check if this is default domain contact CRM-10482
221 if (CRM_Contact_BAO_Contact
::checkDomainContact($this->_contactId
)) {
222 $this->assign('domainContact', TRUE);
225 $this->assign('domainContact', FALSE);
228 // Add links for actions menu
229 self
::addUrls($this, $this->_contactId
);
231 if ($contactType == 'Organization' &&
232 CRM_Core_Permission
::check('administer Multiple Organizations') &&
233 CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MULTISITE_PREFERENCES_NAME
,
237 //check is any relationship between the organization and groups
238 $groupOrg = CRM_Contact_BAO_GroupOrganization
::hasGroupAssociated($this->_contactId
);
240 $groupOrganizationUrl = CRM_Utils_System
::url('civicrm/group',
241 "reset=1&oid={$this->_contactId}"
243 $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
249 * Get meta details of the contact.
251 * @param int $contactId
254 * contact fields in fixed order
256 public static function getContactDetails($contactId) {
257 return list($displayName,
262 ) = CRM_Contact_BAO_Contact
::getDisplayAndImage($contactId,
270 * @param int $contactID
272 public static function checkUserPermission($page, $contactID = NULL) {
273 // check for permissions
274 $page->_permission
= NULL;
277 $contactID = $page->_contactId
;
280 // automatically grant permissin for users on their own record. makes
281 // things easier in dashboard
282 $session = CRM_Core_Session
::singleton();
284 if ($session->get('userID') == $contactID && CRM_Core_Permission
::check('edit my contact')) {
285 $page->assign('permission', 'edit');
286 $page->_permission
= CRM_Core_Permission
::EDIT
;
287 // deleted contacts’ stuff should be (at best) only viewable
289 elseif (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'is_deleted') and CRM_Core_Permission
::check('access deleted contacts')) {
290 $page->assign('permission', 'view');
291 $page->_permission
= CRM_Core_Permission
::VIEW
;
293 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
294 $page->assign('permission', 'edit');
295 $page->_permission
= CRM_Core_Permission
::EDIT
;
297 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::VIEW
)) {
298 $page->assign('permission', 'view');
299 $page->_permission
= CRM_Core_Permission
::VIEW
;
302 $session->pushUserContext(CRM_Utils_System
::url('civicrm', 'reset=1'));
303 CRM_Core_Error
::statusBounce(ts('You do not have the necessary permission to view this contact.'));
308 * @param int $contactId
309 * @param bool $isDeleted
313 public static function setTitle($contactId, $isDeleted = FALSE) {
314 static $contactDetails;
315 $displayName = $contactImage = NULL;
316 if (!isset($contactDetails[$contactId])) {
317 list($displayName, $contactImage) = self
::getContactDetails($contactId);
318 $contactDetails[$contactId] = array(
319 'displayName' => $displayName,
320 'contactImage' => $contactImage,
321 'isDeceased' => (bool) CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'is_deceased'),
325 $displayName = $contactDetails[$contactId]['displayName'];
326 $contactImage = $contactDetails[$contactId]['contactImage'];
330 $title = "{$contactImage} {$displayName}";
331 if ($contactDetails[$contactId]['isDeceased']) {
332 $title .= ' <span class="crm-contact-deceased">(deceased)</span>';
335 $title = "<del>{$title}</del>";
338 // Inline-edit places its own title on the page
339 CRM_Utils_System
::setTitle('CiviCRM', '<span id="crm-remove-title" style="display:none">CiviCRM</span>');
345 * Add urls for display in the actions menu.
346 * @param CRM_Core_Page $obj
349 public static function addUrls(&$obj, $cid) {
350 $uid = CRM_Core_BAO_UFMatch
::getUFId($cid);
353 $userRecordUrl = CRM_Core_Config
::singleton()->userSystem
->getUserRecordUrl($cid);
354 $obj->assign('userRecordUrl', $userRecordUrl);
355 $obj->assign('userRecordId', $uid);
357 elseif (CRM_Core_Config
::singleton()->userSystem
->checkPermissionAddUser()) {
358 $userAddUrl = CRM_Utils_System
::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid);
359 $obj->assign('userAddUrl', $userAddUrl);
362 if (CRM_Core_Permission
::check('access Contact Dashboard')) {
363 $dashboardURL = CRM_Utils_System
::url('civicrm/user',
366 $obj->assign('dashboardURL', $dashboardURL);
369 // See if other modules want to add links to the activtity bar
370 $hookLinks = array();
371 CRM_Utils_Hook
::links('view.contact.activity',
375 CRM_Core_DAO
::$_nullObject,
376 CRM_Core_DAO
::$_nullObject
378 if (is_array($hookLinks)) {
379 $obj->assign('hookLinks', $hookLinks);