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