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 | * | |
31 | * @package CRM | |
e7112fa7 | 32 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * This class generates form components for processing Event | |
39 | * | |
40 | */ | |
41 | class CRM_Event_Form_Registration_ParticipantConfirm extends CRM_Event_Form_Registration { | |
42 | // optional credit card return status code | |
43 | // CRM-6060 | |
44 | protected $_cc = NULL; | |
45 | ||
46 | /** | |
66f9e52b | 47 | * Set variables up before form is built. |
6a488035 TO |
48 | * |
49 | * @return void | |
6a488035 TO |
50 | */ |
51 | public function preProcess() { | |
52 | $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); | |
53 | ||
54 | $this->_cc = CRM_Utils_Request::retrieve('cc', 'String', $this); | |
55 | ||
56 | //get the contact and event id and assing to session. | |
57 | $values = array(); | |
af72b8c7 | 58 | $csContactID = NULL; |
6a488035 TO |
59 | if ($this->_participantId) { |
60 | $params = array('id' => $this->_participantId); | |
61 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Participant', $params, $values, | |
62 | array('contact_id', 'event_id', 'status_id') | |
63 | ); | |
64 | } | |
65 | ||
66 | $this->_participantStatusId = CRM_Utils_Array::value('status_id', $values); | |
67 | $this->_eventId = CRM_Utils_Array::value('event_id', $values); | |
68 | $csContactId = CRM_Utils_Array::value('contact_id', $values); | |
69 | ||
70 | // make sure we have right permission to edit this user | |
71 | $this->_csContactID = NULL; | |
72 | if ($csContactId && $this->_eventId) { | |
73 | $session = CRM_Core_Session::singleton(); | |
74 | if ($csContactId == $session->get('userID')) { | |
75 | $this->_csContactID = $csContactId; | |
76 | } | |
77 | else { | |
78 | if (CRM_Contact_BAO_Contact_Permission::validateChecksumContact($csContactId, $this)) { | |
79 | //since we have landing page so get this contact | |
80 | //id in session if user really want to walk wizard. | |
81 | $this->_csContactID = $csContactId; | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | if (!$this->_csContactID) { | |
87 | $config = CRM_Core_Config::singleton(); | |
88 | 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); | |
89 | } | |
90 | } | |
91 | ||
92 | /** | |
66f9e52b | 93 | * Build the form object. |
6a488035 | 94 | * |
355ba699 | 95 | * @return void |
6a488035 TO |
96 | */ |
97 | public function buildQuickForm() { | |
98 | $params = array('id' => $this->_eventId); | |
99 | $values = array(); | |
100 | CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $values, | |
101 | array('title') | |
102 | ); | |
103 | ||
104 | $buttons = array(); | |
105 | // only pending status class family able to confirm. | |
106 | ||
107 | $statusMsg = NULL; | |
108 | if (array_key_exists($this->_participantStatusId, | |
353ffa53 TO |
109 | CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'") |
110 | )) { | |
6a488035 | 111 | |
6a488035 TO |
112 | //need to confirm that though participant confirming |
113 | //registration - but is there enough space to confirm. | |
353ffa53 | 114 | $emptySeats = CRM_Event_BAO_Participant::pendingToConfirmSpaces($this->_eventId); |
6a488035 TO |
115 | $additonalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); |
116 | $requireSpace = 1 + count($additonalIds); | |
117 | if ($emptySeats !== NULL && ($requireSpace > $emptySeats)) { | |
118 | $statusMsg = ts("Oops, it looks like there are currently no available spaces for the %1 event.", array(1 => $values['title'])); | |
119 | } | |
120 | else { | |
121 | if ($this->_cc == 'fail') { | |
122 | $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.', array( | |
79d7553f | 123 | 1 => $values['title'], |
353ffa53 | 124 | )) . '</div>'; |
6a488035 TO |
125 | } |
126 | else { | |
127 | $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', array( | |
79d7553f | 128 | 1 => $values['title'], |
353ffa53 | 129 | )) . '</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 TO |
130 | } |
131 | $buttons = array_merge($buttons, array( | |
0479b4c8 | 132 | array( |
353ffa53 TO |
133 | 'type' => 'next', |
134 | 'name' => ts('Confirm Registration'), | |
135 | 'spacing' => ' ', | |
136 | 'isDefault' => TRUE, | |
79d7553f | 137 | ), |
353ffa53 | 138 | )); |
6a488035 TO |
139 | } |
140 | } | |
141 | ||
142 | // status class other than Negative should be able to cancel registration. | |
143 | if (array_key_exists($this->_participantStatusId, | |
353ffa53 TO |
144 | CRM_Event_PseudoConstant::participantStatus(NULL, "class != 'Negative'") |
145 | )) { | |
6a488035 TO |
146 | $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?'); |
147 | $buttons = array_merge($buttons, array( | |
0479b4c8 | 148 | array( |
353ffa53 TO |
149 | 'type' => 'submit', |
150 | 'name' => ts('Cancel Registration'), | |
151 | 'spacing' => ' ', | |
152 | 'js' => array('onclick' => 'return confirm(\'' . $cancelConfirm . '\');'), | |
79d7553f | 153 | ), |
353ffa53 | 154 | )); |
6a488035 TO |
155 | if (!$statusMsg) { |
156 | $statusMsg = ts('You can cancel your registration for %1 by clicking "Cancel Registration".', array(1 => $values['title'])); | |
157 | } | |
158 | } | |
159 | if (!$statusMsg) { | |
160 | $statusMsg = ts("Oops, it looks like your registration for %1 has already been cancelled.", | |
161 | array(1 => $values['title']) | |
162 | ); | |
163 | } | |
164 | $this->assign('statusMsg', $statusMsg); | |
165 | ||
166 | $this->addButtons($buttons); | |
167 | } | |
168 | ||
169 | /** | |
66f9e52b | 170 | * Process the form submission. |
6a488035 | 171 | * |
6a488035 | 172 | * |
355ba699 | 173 | * @return void |
6a488035 TO |
174 | */ |
175 | public function postProcess() { | |
176 | //get the button. | |
353ffa53 | 177 | $buttonName = $this->controller->getButtonName(); |
6a488035 TO |
178 | $participantId = $this->_participantId; |
179 | ||
180 | if ($buttonName == '_qf_ParticipantConfirm_next') { | |
181 | //lets get contact id in session. | |
182 | $session = CRM_Core_Session::singleton(); | |
183 | $session->set('userID', $this->_csContactID); | |
184 | ||
185 | $this->postProcessHook(); | |
186 | ||
187 | //check user registration status is from pending class | |
188 | $url = CRM_Utils_System::url('civicrm/event/register', | |
af72b8c7 | 189 | "reset=1&id={$this->_eventId}&participantId={$participantId}" |
6a488035 TO |
190 | ); |
191 | CRM_Utils_System::redirect($url); | |
192 | } | |
193 | elseif ($buttonName == '_qf_ParticipantConfirm_submit') { | |
194 | //need to registration status to 'cancelled'. | |
195 | ||
196 | $cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'")); | |
197 | $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId); | |
198 | ||
199 | $participantIds = array_merge(array($participantId), $additionalParticipantIds); | |
200 | $results = CRM_Event_BAO_Participant::transitionParticipants($participantIds, $cancelledId, NULL, TRUE); | |
201 | ||
202 | if (count($participantIds) > 1) { | |
203 | $statusMessage = ts("%1 Event registration(s) have been cancelled.", array(1 => count($participantIds))); | |
204 | } | |
205 | else { | |
6c68db9f | 206 | $statusMessage = ts("Your Event Registration has been cancelled."); |
6a488035 TO |
207 | } |
208 | ||
a7488080 | 209 | if (!empty($results['mailedParticipants'])) { |
6a488035 TO |
210 | foreach ($results['mailedParticipants'] as $key => $displayName) { |
211 | $statusMessage .= "<br />" . ts("Email has been sent to : %1", array(1 => $displayName)); | |
212 | } | |
213 | } | |
214 | ||
215 | $this->postProcessHook(); | |
216 | ||
217 | CRM_Core_Error::statusBounce($statusMessage, | |
218 | CRM_Utils_System::url('civicrm/event/info', | |
219 | "reset=1&id={$this->_eventId}&noFullMsg=1", | |
220 | FALSE, NULL, FALSE, TRUE | |
221 | ) | |
222 | ); | |
223 | } | |
224 | } | |
96025800 | 225 | |
6a488035 | 226 | } |