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