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