INFRA-132 - Cleanup stray comments
[civicrm-core.git] / CRM / Event / Page / Tab.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
31 * @copyright CiviCRM LLC (c) 2004-2014
32 * $Id$
33 *
34 */
35 class CRM_Event_Page_Tab extends CRM_Core_Page {
36
37 public $_permission = NULL;
38 public $_contactId = NULL;
39
40 /**
41 * called when action is browse
42 *
43 * @return null
44 */
45 public function browse() {
46 $controller = new CRM_Core_Controller_Simple(
47 'CRM_Event_Form_Search',
48 ts('Events'),
49 $this->_action
50 );
51 $controller->setEmbedded(TRUE);
52 $controller->reset();
53 $controller->set('cid', $this->_contactId);
54 $controller->set('context', 'participant');
55 $controller->process();
56 $controller->run();
57
58 if ($this->_contactId) {
59 $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
60 $this->assign('displayName', $displayName);
61 $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('participant', $this->_contactId);
62 // Refresh other tabs with related data
63 $this->ajaxResponse['updateTabs'] = array(
64 '#tab_activity' => CRM_Contact_BAO_Contact::getCountComponent('activity', $this->_contactId),
65 );
66 if (CRM_Core_Permission::access('CiviContribute')) {
67 $this->ajaxResponse['updateTabs']['#tab_contribute'] = CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId);
68 }
69 }
70 }
71
72 /**
73 * called when action is view
74 *
75 * @return null
76 */
77 public function view() {
78 // build associated contributions
79 $this->associatedContribution();
80
81 $controller = new CRM_Core_Controller_Simple(
82 'CRM_Event_Form_ParticipantView',
83 ts('View Participant'),
84 $this->_action
85 );
86 $controller->setEmbedded(TRUE);
87 $controller->set('id', $this->_id);
88 $controller->set('cid', $this->_contactId);
89
90 return $controller->run();
91 }
92
93 /**
94 * called when action is update or new
95 *
96 * @return null
97 */
98 public function edit() {
99 // set https for offline cc transaction
100 $mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
101 if ($mode == 'test' || $mode == 'live') {
102 CRM_Utils_System::redirectToSSL();
103 }
104
105 if ($this->_action != CRM_Core_Action::ADD) {
106 // get associated contributions only on edit/delete
107 $this->associatedContribution();
108 }
109
110 $controller = new CRM_Core_Controller_Simple(
111 'CRM_Event_Form_Participant',
112 'Create Participation',
113 $this->_action
114 );
115
116 $controller->setEmbedded(TRUE);
117 $controller->set('id', $this->_id);
118 $controller->set('cid', $this->_contactId);
119
120 return $controller->run();
121 }
122
123 public function preProcess() {
124 $context = CRM_Utils_Request::retrieve('context', 'String', $this);
125 $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
126 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
127
128 if ($context == 'standalone') {
129 $this->_action = CRM_Core_Action::ADD;
130 }
131 else {
132 $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
133 $this->assign('contactId', $this->_contactId);
134
135 // check logged in url permission
136 CRM_Contact_Page_View::checkUserPermission($this);
137 }
138
139 $this->assign('action', $this->_action);
140
141 if ($this->_permission == CRM_Core_Permission::EDIT && !CRM_Core_Permission::check('edit event participants')) {
142 // demote to view since user does not have edit event participants rights
143 $this->_permission = CRM_Core_Permission::VIEW;
144 $this->assign('permission', 'view');
145 }
146 }
147
148 /**
149 * the main function that is called when the page loads, it decides the which action has to be taken for the page.
150 *
151 * @return null
152 */
153 public function run() {
154 $this->preProcess();
155
156 // check if we can process credit card registration
157 $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
158
159 // Only show credit card registration button if user has CiviContribute permission
160 if (CRM_Core_Permission::access('CiviContribute')) {
161 $this->assign('accessContribution', TRUE);
162 }
163 else {
164 $this->assign('accessContribution', FALSE);
165 }
166
167 $this->setContext();
168
169 if ($this->_action & CRM_Core_Action::VIEW) {
170 $this->view();
171 }
172 elseif ($this->_action & (CRM_Core_Action::UPDATE |
173 CRM_Core_Action::ADD |
174 CRM_Core_Action::DELETE
175 )
176 ) {
177 $this->edit();
178 }
179 else {
180 $this->browse();
181 }
182
183 return parent::run();
184 }
185
186 public function setContext() {
187 $context = CRM_Utils_Request::retrieve('context',
188 'String', $this, FALSE, 'search'
189 );
190 $compContext = CRM_Utils_Request::retrieve('compContext',
191 'String', $this
192 );
193
194 $searchContext = CRM_Utils_Request::retrieve('searchContext', 'String', $this);
195
196 $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
197
198 //validate the qfKey
199 if (!CRM_Utils_Rule::qfKey($qfKey)) {
200 $qfKey = NULL;
201 }
202
203 switch ($context) {
204 case 'dashboard':
205 $url = CRM_Utils_System::url('civicrm/event', 'reset=1');
206 break;
207
208 case 'search':
209 $urlParams = 'force=1';
210 if ($qfKey) {
211 $urlParams .= "&qfKey=$qfKey";
212 }
213 $this->assign('searchKey', $qfKey);
214
215 if ($compContext == 'advanced') {
216 $url = CRM_Utils_System::url('civicrm/contact/search/advanced', $urlParams);
217 }
218 elseif ($searchContext) {
219 $url = CRM_Utils_System::url("civicrm/$searchContext/search", $urlParams);
220 }
221 else {
222 $url = CRM_Utils_System::url('civicrm/event/search', $urlParams);
223 }
224 break;
225
226 case 'user':
227 $url = CRM_Utils_System::url('civicrm/user', 'reset=1');
228 break;
229
230 case 'participant':
231 $url = CRM_Utils_System::url('civicrm/contact/view',
232 "reset=1&force=1&cid={$this->_contactId}&selectedChild=participant"
233 );
234 break;
235
236 case 'home':
237 $url = CRM_Utils_System::url('civicrm/dashboard', 'force=1');
238 break;
239
240 case 'activity':
241 $url = CRM_Utils_System::url('civicrm/contact/view',
242 "reset=1&force=1&cid={$this->_contactId}&selectedChild=activity"
243 );
244 break;
245
246 case 'standalone':
247 $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
248 break;
249
250 case 'fulltext':
251 $keyName = '&qfKey';
252 $urlParams = 'force=1';
253 $urlString = 'civicrm/contact/search/custom';
254 if ($this->_action == CRM_Core_Action::UPDATE) {
255 if ($this->_contactId) {
256 $urlParams .= '&cid=' . $this->_contactId;
257 }
258 $keyName = '&key';
259 $urlParams .= '&context=fulltext&action=view';
260 $urlString = 'civicrm/contact/view/participant';
261 }
262 if ($qfKey) {
263 $urlParams .= "$keyName=$qfKey";
264 }
265 $this->assign('searchKey', $qfKey);
266 $url = CRM_Utils_System::url($urlString, $urlParams);
267 break;
268
269 default:
270 $cid = NULL;
271 if ($this->_contactId) {
272 $cid = '&cid=' . $this->_contactId;
273 }
274 $url = CRM_Utils_System::url('civicrm/event/search',
275 'force=1' . $cid
276 );
277 break;
278 }
279 $session = CRM_Core_Session::singleton();
280 $session->pushUserContext($url);
281 }
282
283 /**
284 * used for the to show the associated
285 * contribution for the participant
286 *
287 * @return null
288 */
289 public function associatedContribution() {
290 if (CRM_Core_Permission::access('CiviContribute')) {
291 $this->assign('accessContribution', TRUE);
292 $controller = new CRM_Core_Controller_Simple(
293 'CRM_Contribute_Form_Search',
294 ts('Contributions'),
295 NULL,
296 FALSE, FALSE, TRUE
297 );
298 $controller->setEmbedded(TRUE);
299 $controller->set('force', 1);
300 $controller->set('cid', $this->_contactId);
301 $controller->set('participantId', $this->_id);
302 $controller->set('context', 'contribution');
303 $controller->process();
304 $controller->run();
305 }
306 else {
307 $this->assign('accessContribution', FALSE);
308 }
309 }
310 }