commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / CRM / Event / Form / Registration / ParticipantConfirm.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 *
31 * @package CRM
32 * @copyright CiviCRM LLC (c) 2004-2015
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 /**
47 * Set variables up before form is built.
48 *
49 * @return void
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();
58 $csContactID = NULL;
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 /**
93 * Build the form object.
94 *
95 * @return void
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,
109 CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'")
110 )) {
111
112 //need to confirm that though participant confirming
113 //registration - but is there enough space to confirm.
114 $emptySeats = CRM_Event_BAO_Participant::pendingToConfirmSpaces($this->_eventId);
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(
123 1 => $values['title'],
124 )) . '</div>';
125 }
126 else {
127 $statusMsg = '<div class="bold">' . ts('Confirm your registration for %1.', array(
128 1 => $values['title'],
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>';
130 }
131 $buttons = array_merge($buttons, array(
132 array(
133 'type' => 'next',
134 'name' => ts('Confirm Registration'),
135 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
136 'isDefault' => TRUE,
137 ),
138 ));
139 }
140 }
141
142 // status class other than Negative should be able to cancel registration.
143 if (array_key_exists($this->_participantStatusId,
144 CRM_Event_PseudoConstant::participantStatus(NULL, "class != 'Negative'")
145 )) {
146 $cancelConfirm = ts('Are you sure you want to cancel your registration for this event?');
147 $buttons = array_merge($buttons, array(
148 array(
149 'type' => 'submit',
150 'name' => ts('Cancel Registration'),
151 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
152 'js' => array('onclick' => 'return confirm(\'' . $cancelConfirm . '\');'),
153 ),
154 ));
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 /**
170 * Process the form submission.
171 *
172 *
173 * @return void
174 */
175 public function postProcess() {
176 //get the button.
177 $buttonName = $this->controller->getButtonName();
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',
189 "reset=1&id={$this->_eventId}&participantId={$participantId}"
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 {
206 $statusMessage = ts("Your Event Registration has been cancelled.");
207 }
208
209 if (!empty($results['mailedParticipants'])) {
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 }
225
226 }