Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
17 | */ |
18 | ||
19 | /** | |
20 | * This class generates form components for processing Event | |
21 | * | |
22 | */ | |
23 | class CRM_Event_Form_Registration_ParticipantConfirm extends CRM_Event_Form_Registration { | |
0e480632 | 24 | |
90b461f1 | 25 | /** |
0e480632 | 26 | * Optional credit card return status code |
90b461f1 | 27 | * @var string |
0e480632 | 28 | * @see https://issues.civicrm.org/jira/browse/CRM-6060 |
90b461f1 | 29 | */ |
6a488035 TO |
30 | protected $_cc = NULL; |
31 | ||
32 | /** | |
66f9e52b | 33 | * Set variables up before form is built. |
6a488035 TO |
34 | * |
35 | * @return void | |
6a488035 TO |
36 | */ |
37 | public function preProcess() { | |
38 | $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); | |
39 | ||
40 | $this->_cc = CRM_Utils_Request::retrieve('cc', 'String', $this); | |
41 | ||
42 | //get the contact and event id and assing to session. | |
be2fb01f | 43 | $values = []; |
af72b8c7 | 44 | $csContactID = NULL; |
6a488035 | 45 | if ($this->_participantId) { |
be2fb01f | 46 | $params = ['id' => $this->_participantId]; |
6a488035 | 47 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Participant', $params, $values, |
be2fb01f | 48 | ['contact_id', 'event_id', 'status_id'] |
6a488035 TO |
49 | ); |
50 | } | |
51 | ||
9c1bc317 CW |
52 | $this->_participantStatusId = $values['status_id'] ?? NULL; |
53 | $this->_eventId = $values['event_id'] ?? NULL; | |
54 | $csContactId = $values['contact_id'] ?? NULL; | |
6a488035 TO |
55 | |
56 | // make sure we have right permission to edit this user | |
57 | $this->_csContactID = NULL; | |
58 | if ($csContactId && $this->_eventId) { | |
59 | $session = CRM_Core_Session::singleton(); | |
60 | if ($csContactId == $session->get('userID')) { | |
61 | $this->_csContactID = $csContactId; | |
62 | } | |
63 | else { | |
64 | if (CRM_Contact_BAO_Contact_Permission::validateChecksumContact($csContactId, $this)) { | |
65 | //since we have landing page so get this contact | |
66 | //id in session if user really want to walk wizard. | |
67 | $this->_csContactID = $csContactId; | |
68 | } | |
69 | } | |
70 | } | |
71 | ||
72 | if (!$this->_csContactID) { | |
73 | $config = CRM_Core_Config::singleton(); | |
74 | CRM_Core_Error::statusBounce(ts('You do not have permission to access this event registration. Contact the site administrator if you need assistance.'), $config->userFrameworkBaseURL); | |
75 | } | |
76 | } | |
77 | ||
78 | /** | |
66f9e52b | 79 | * Build the form object. |
6a488035 | 80 | * |
355ba699 | 81 | * @return void |
6a488035 TO |
82 | */ |
83 | public function buildQuickForm() { | |
be2fb01f CW |
84 | $params = ['id' => $this->_eventId]; |
85 | $values = []; | |
6a488035 | 86 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $values, |
be2fb01f | 87 | ['title'] |
6a488035 TO |
88 | ); |
89 | ||
be2fb01f | 90 | $buttons = []; |
6a488035 TO |
91 | // only pending status class family able to confirm. |
92 | ||
93 | $statusMsg = NULL; | |
94 | if (array_key_exists($this->_participantStatusId, | |
353ffa53 TO |
95 | CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'") |
96 | )) { | |
6a488035 | 97 | |
6a488035 TO |
98 | //need to confirm that though participant confirming |
99 | //registration - but is there enough space to confirm. | |
49f3a6ff | 100 | $emptySeats = CRM_Event_BAO_Participant::eventFull($this->_eventId, TRUE, FALSE, TRUE, FALSE, TRUE); |
6a488035 TO |
101 | $additonalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); |
102 | $requireSpace = 1 + count($additonalIds); | |
103 | if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) { | |
be2fb01f | 104 | $statusMsg = ts("Oops, it looks like there are currently no available spaces for the %1 event.", [1 => $values['title']]); |
6a488035 TO |
105 | } |
106 | else { | |
107 | if ($this->_cc == 'fail') { | |
be2fb01f | 108 | $statusMsg = '<div class="bold">' . ts('Your Credit Card transaction was not successful. No money has yet been charged to your card.') . '</div><div><br />' . ts('Click the "Confirm Registration" button to complete your registration in %1, or click "Cancel Registration" if you are no longer interested in attending this event.', [ |
90b461f1 SL |
109 | 1 => $values['title'], |
110 | ]) . '</div>'; | |
6a488035 TO |
111 | } |
112 | else { | |
be2fb01f | 113 | $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', [ |
90b461f1 SL |
114 | 1 => $values['title'], |
115 | ]) . '</div><div><br />' . ts('Click the "Confirm Registration" button to begin, or click "Cancel Registration" if you are no longer interested in attending this event.') . '</div>'; | |
6a488035 | 116 | } |
be2fb01f CW |
117 | $buttons = array_merge($buttons, [ |
118 | [ | |
353ffa53 TO |
119 | 'type' => 'next', |
120 | 'name' => ts('Confirm Registration'), | |
121 | 'spacing' => ' ', | |
122 | 'isDefault' => TRUE, | |
be2fb01f CW |
123 | ], |
124 | ]); | |
6a488035 TO |
125 | } |
126 | } | |
127 | ||
128 | // status class other than Negative should be able to cancel registration. | |
129 | if (array_key_exists($this->_participantStatusId, | |
353ffa53 TO |
130 | CRM_Event_PseudoConstant::participantStatus(NULL, "class != 'Negative'") |
131 | )) { | |
6a488035 | 132 | $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?'); |
be2fb01f CW |
133 | $buttons = array_merge($buttons, [ |
134 | [ | |
353ffa53 TO |
135 | 'type' => 'submit', |
136 | 'name' => ts('Cancel Registration'), | |
137 | 'spacing' => ' ', | |
be2fb01f CW |
138 | 'js' => ['onclick' => 'return confirm(\'' . $cancelConfirm . '\');'], |
139 | ], | |
140 | ]); | |
6a488035 | 141 | if (!$statusMsg) { |
be2fb01f | 142 | $statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', [1 => $values['title']]); |
6a488035 TO |
143 | } |
144 | } | |
145 | if (!$statusMsg) { | |
146 | $statusMsg = ts("Oops, it looks like your registration for %1 has already been cancelled.", | |
be2fb01f | 147 | [1 => $values['title']] |
6a488035 TO |
148 | ); |
149 | } | |
150 | $this->assign('statusMsg', $statusMsg); | |
151 | ||
152 | $this->addButtons($buttons); | |
153 | } | |
154 | ||
155 | /** | |
66f9e52b | 156 | * Process the form submission. |
6a488035 | 157 | * |
6a488035 | 158 | * |
355ba699 | 159 | * @return void |
6a488035 TO |
160 | */ |
161 | public function postProcess() { | |
162 | //get the button. | |
353ffa53 | 163 | $buttonName = $this->controller->getButtonName(); |
6a488035 TO |
164 | $participantId = $this->_participantId; |
165 | ||
166 | if ($buttonName == '_qf_ParticipantConfirm_next') { | |
167 | //lets get contact id in session. | |
168 | $session = CRM_Core_Session::singleton(); | |
169 | $session->set('userID', $this->_csContactID); | |
170 | ||
171 | $this->postProcessHook(); | |
172 | ||
173 | //check user registration status is from pending class | |
174 | $url = CRM_Utils_System::url('civicrm/event/register', | |
af72b8c7 | 175 | "reset=1&id={$this->_eventId}&participantId={$participantId}" |
6a488035 TO |
176 | ); |
177 | CRM_Utils_System::redirect($url); | |
178 | } | |
179 | elseif ($buttonName == '_qf_ParticipantConfirm_submit') { | |
180 | //need to registration status to 'cancelled'. | |
181 | ||
182 | $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); | |
183 | $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId); | |
184 | ||
be2fb01f | 185 | $participantIds = array_merge([$participantId], $additionalParticipantIds); |
6a488035 TO |
186 | $results = CRM_Event_BAO_Participant::transitionParticipants($participantIds, $cancelledId, NULL, TRUE); |
187 | ||
188 | if (count($participantIds) > 1) { | |
be2fb01f | 189 | $statusMessage = ts("%1 Event registration(s) have been cancelled.", [1 => count($participantIds)]); |
6a488035 TO |
190 | } |
191 | else { | |
6c68db9f | 192 | $statusMessage = ts("Your Event Registration has been cancelled."); |
6a488035 TO |
193 | } |
194 | ||
a7488080 | 195 | if (!empty($results['mailedParticipants'])) { |
6a488035 | 196 | foreach ($results['mailedParticipants'] as $key => $displayName) { |
be2fb01f | 197 | $statusMessage .= "<br />" . ts("Email has been sent to : %1", [1 => $displayName]); |
6a488035 TO |
198 | } |
199 | } | |
200 | ||
201 | $this->postProcessHook(); | |
d6c219af | 202 | CRM_Core_Session::setStatus($statusMessage); |
203 | CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/event/info', | |
6a488035 TO |
204 | "reset=1&id={$this->_eventId}&noFullMsg=1", |
205 | FALSE, NULL, FALSE, TRUE | |
206 | ) | |
207 | ); | |
208 | } | |
209 | } | |
96025800 | 210 | |
6a488035 | 211 | } |