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