Merge pull request #4296 from mrpaulc/CRM-14751
[civicrm-core.git] / CRM / Contact / Page / View / CustomData.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
37 * Page for displaying custom data
38 *
39 */
40class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
41
42 /**
43 * the id of the object being viewed (note/relationship etc)
44 *
45 * @int
46 * @access protected
47 */
48 public $_groupId;
49
50 /**
51 * class constructor
52 *
53 * @return CRM_Contact_Page_View_CustomData
54 */
55 public function __construct() {
56 parent::__construct();
57 }
58
59 /**
60 * add a few specific things to view contact
61 *
62 * @return void
63 * @access public
64 *
65 */
66 function preProcess() {
67 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
68 $this->assign('contactId', $this->_contactId);
69
70 // check logged in url permission
71 CRM_Contact_Page_View::checkUserPermission($this);
72
73 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
74 $this->assign('action', $this->_action);
75
76 $this->_groupId = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE);
77 $this->assign('groupId', $this->_groupId);
e41f4660
PJ
78
79 $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this, FALSE);
80 $this->_cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE);
81 $this->_recId = CRM_Utils_Request::retrieve('recId', 'Positive', $this, FALSE);
6a488035
TO
82 }
83
84 /**
85 * Run the page.
86 *
87 * This method is called after the page is created. It checks for the
88 * type of action and executes that action.
89 *
90 * @access public
91 *
6c8f6e67 92 * @internal param object $page - the view page which created this one
6a488035 93 *
355ba699 94 * @return void
6a488035 95 * @static
6a488035
TO
96 */
97 function run() {
98 $this->preProcess();
99
100 //set the userContext stack
101 $doneURL = 'civicrm/contact/view';
102 $session = CRM_Core_Session::singleton();
103 $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
104
105 // get permission detail view or edit
87177cd2
DL
106 // use a comtact id specific function which gives us much better granularity
107 // CRM-12646
108 $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
6a488035
TO
109 $this->assign('editCustomData', $editCustomData);
110
111 //allow to edit own customdata CRM-5518
112 $editOwnCustomData = FALSE;
113 if ($session->get('userID') == $this->_contactId) {
114 $editOwnCustomData = TRUE;
115 }
116 $this->assign('editOwnCustomData', $editOwnCustomData);
117
118 if ($this->_action == CRM_Core_Action::BROWSE) {
119 //Custom Groups Inline
120 $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId);
121 $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId);
122 $groupTree = &CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId,
123 $this->_groupId, $entitySubType
124 );
e41f4660
PJ
125
126 $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
127 $this->_groupId,
128 'style'
129 );
130
eaf756c0 131 if ($this->_multiRecordDisplay != 'single') {
bd470b69
PJ
132 $id = "custom_{$this->_groupId}";
133 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']);
eaf756c0
CW
134 }
135
136 if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
e41f4660
PJ
137 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
138 $this->_contactId,
139 'contact_type'
140 );
141
142 $this->assign('displayStyle', 'tableOriented');
143 // here the multi custom data listing code will go
144 $multiRecordFieldListing = TRUE;
145 $page = new CRM_Profile_Page_MultipleRecordFieldsListing();
146 $page->set('contactId', $this->_contactId);
147 $page->set('customGroupId', $this->_groupId);
148 $page->set('action', CRM_Core_Action::BROWSE);
149 $page->set('multiRecordFieldListing', $multiRecordFieldListing);
150 $page->set('pageViewType', 'customDataView');
151 $page->set('contactType', $ctype);
152 $page->run();
153 }
154 else {
155 $recId = NULL;
156 if ($this->_multiRecordDisplay == 'single') {
525faea3
PJ
157 $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
158 CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle)));
159
e41f4660
PJ
160 $recId = $this->_recId;
161 $this->assign('multiRecordDisplay', $this->_multiRecordDisplay);
162 $this->assign('skipTitle', 1);
163 }
164 CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId);
165 }
6a488035
TO
166 }
167 else {
168
169 $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData',
170 ts('Custom Data'),
171 $this->_action
172 );
173 $controller->setEmbedded(TRUE);
174
175 $controller->set('tableId', $this->_contactId);
176 $controller->set('groupId', $this->_groupId);
177 $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId));
178 $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','));
179 $controller->process();
180 $controller->run();
181 }
182 return parent::run();
183 }
6c8f6e67 184}