3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
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-2017
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'];
138 $context = CRM_Utils_Array
::value('context', $_GET);
140 // seems like we did not find any contacts
141 // maybe due to bug CRM-9096
142 // however we should account for 1 contact results (which dont have prev next)
143 if (!$pos['foundEntry']) {
144 $navContacts['nextPrevError'] = 1;
148 $this->assign('context', $context);
149 CRM_Utils_System
::appendBreadCrumb(array(
151 'title' => ts('Search Results'),
152 'url' => CRM_Utils_System
::url("civicrm/contact/search/$context", array('qfKey' => $qfKey)),
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'), 'url' => $path)));
162 if ($image_URL = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'image_URL')) {
163 $this->assign("imageURL", CRM_Utils_File
::getImageURL($image_URL));
166 // also store in session for future use
167 $session = CRM_Core_Session
::singleton();
168 $session->set('view.id', $this->_contactId
);
170 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE, 'browse');
171 $this->assign('action', $this->_action
);
173 // check logged in user permission
174 self
::checkUserPermission($this);
176 list($displayName, $contactImage, $contactType, $contactSubtype, $contactImageUrl) = self
::getContactDetails($this->_contactId
);
177 $this->assign('displayName', $displayName);
179 $this->set('contactType', $contactType);
181 // note: there could still be multiple subtypes. We just trimming the outer separator.
182 $this->set('contactSubtype', trim($contactSubtype, CRM_Core_DAO
::VALUE_SEPARATOR
));
184 // add to recently viewed block
185 $isDeleted = (bool) CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId
, 'is_deleted');
187 $recentOther = array(
188 'imageUrl' => $contactImageUrl,
189 'subtype' => $contactSubtype,
190 'isDeleted' => $isDeleted,
193 if (CRM_Contact_BAO_Contact_Permission
::allow($this->_contactId
, CRM_Core_Permission
::EDIT
)) {
194 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/add', "reset=1&action=update&cid={$this->_contactId}");
197 if (($session->get('userID') != $this->_contactId
) && CRM_Core_Permission
::check('delete contacts')
200 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/delete', "reset=1&delete=1&cid={$this->_contactId}");
203 CRM_Utils_Recent
::add($displayName,
204 CRM_Utils_System
::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}"),
211 $this->assign('isDeleted', $isDeleted);
214 $title = self
::setTitle($this->_contactId
, $isDeleted);
215 $this->assign('title', $title);
217 // Check if this is default domain contact CRM-10482
218 if (CRM_Contact_BAO_Contact
::checkDomainContact($this->_contactId
)) {
219 $this->assign('domainContact', TRUE);
222 $this->assign('domainContact', FALSE);
225 // Add links for actions menu
226 self
::addUrls($this, $this->_contactId
);
228 if ($contactType == 'Organization' &&
229 CRM_Core_Permission
::check('administer Multiple Organizations') &&
230 Civi
::settings()->get('is_enabled')) {
231 //check is any relationship between the organization and groups
232 $groupOrg = CRM_Contact_BAO_GroupOrganization
::hasGroupAssociated($this->_contactId
);
234 $groupOrganizationUrl = CRM_Utils_System
::url('civicrm/group',
235 "reset=1&oid={$this->_contactId}"
237 $this->assign('groupOrganizationUrl', $groupOrganizationUrl);
243 * Get meta details of the contact.
245 * @param int $contactId
248 * contact fields in fixed order
250 public static function getContactDetails($contactId) {
251 return list($displayName,
256 ) = CRM_Contact_BAO_Contact
::getDisplayAndImage($contactId,
264 * @param int $contactID
266 public static function checkUserPermission($page, $contactID = NULL) {
267 // check for permissions
268 $page->_permission
= NULL;
271 $contactID = $page->_contactId
;
274 // automatically grant permissin for users on their own record. makes
275 // things easier in dashboard
276 $session = CRM_Core_Session
::singleton();
278 if ($session->get('userID') == $contactID && CRM_Core_Permission
::check('edit my contact')) {
279 $page->assign('permission', 'edit');
280 $page->_permission
= CRM_Core_Permission
::EDIT
;
281 // deleted contacts’ stuff should be (at best) only viewable
283 elseif (CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'is_deleted') and CRM_Core_Permission
::check('access deleted contacts')) {
284 $page->assign('permission', 'view');
285 $page->_permission
= CRM_Core_Permission
::VIEW
;
287 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::EDIT
)) {
288 $page->assign('permission', 'edit');
289 $page->_permission
= CRM_Core_Permission
::EDIT
;
291 elseif (CRM_Contact_BAO_Contact_Permission
::allow($contactID, CRM_Core_Permission
::VIEW
)) {
292 $page->assign('permission', 'view');
293 $page->_permission
= CRM_Core_Permission
::VIEW
;
296 $session->pushUserContext(CRM_Utils_System
::url('civicrm', 'reset=1'));
297 CRM_Core_Error
::statusBounce(ts('You do not have the necessary permission to view this contact.'));
302 * @param int $contactId
303 * @param bool $isDeleted
307 public static function setTitle($contactId, $isDeleted = FALSE) {
308 static $contactDetails;
309 $displayName = $contactImage = NULL;
310 if (!isset($contactDetails[$contactId])) {
311 list($displayName, $contactImage) = self
::getContactDetails($contactId);
312 $contactDetails[$contactId] = array(
313 'displayName' => $displayName,
314 'contactImage' => $contactImage,
315 'isDeceased' => (bool) CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $contactId, 'is_deceased'),
319 $displayName = $contactDetails[$contactId]['displayName'];
320 $contactImage = $contactDetails[$contactId]['contactImage'];
324 $title = "{$contactImage} {$displayName}";
325 if ($contactDetails[$contactId]['isDeceased']) {
326 $title .= ' <span class="crm-contact-deceased">(deceased)</span>';
329 $title = "<del>{$title}</del>";
332 // Inline-edit places its own title on the page
333 CRM_Utils_System
::setTitle('CiviCRM', '<span id="crm-remove-title" style="display:none">CiviCRM</span>');
339 * Add urls for display in the actions menu.
340 * @param CRM_Core_Page $obj
343 public static function addUrls(&$obj, $cid) {
344 $uid = CRM_Core_BAO_UFMatch
::getUFId($cid);
347 $userRecordUrl = CRM_Core_Config
::singleton()->userSystem
->getUserRecordUrl($cid);
348 $obj->assign('userRecordUrl', $userRecordUrl);
349 $obj->assign('userRecordId', $uid);
351 elseif (CRM_Core_Config
::singleton()->userSystem
->checkPermissionAddUser()) {
352 $userAddUrl = CRM_Utils_System
::url('civicrm/contact/view/useradd', 'reset=1&action=add&cid=' . $cid);
353 $obj->assign('userAddUrl', $userAddUrl);
356 if (CRM_Core_Permission
::check('access Contact Dashboard')) {
357 $dashboardURL = CRM_Utils_System
::url('civicrm/user',
360 $obj->assign('dashboardURL', $dashboardURL);
363 // See if other modules want to add links to the activtity bar
364 $hookLinks = array();
365 CRM_Utils_Hook
::links('view.contact.activity',
370 if (is_array($hookLinks)) {
371 $obj->assign('hookLinks', $hookLinks);