Merge pull request #15685 from eileenmcnaughton/refund_allocate
[civicrm-core.git] / CRM / Event / Form / Registration / ThankYou.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
33 * $Id$
34 *
35 */
36
37 /**
38 * This class generates form components for processing Event
39 *
40 */
41 class CRM_Event_Form_Registration_ThankYou extends CRM_Event_Form_Registration {
42
43 /**
44 * Set variables up before form is built.
45 *
46 * @return void
47 */
48 public function preProcess() {
49 parent::preProcess();
50 $this->_params = $this->get('params');
51 $this->_lineItem = $this->get('lineItem');
52 $this->_part = $this->get('part');
53 $this->_totalAmount = $this->get('totalAmount');
54 $this->_receiveDate = $this->get('receiveDate');
55 $this->_trxnId = $this->get('trxnId');
56 $finalAmount = $this->get('finalAmount');
57 $this->assign('finalAmount', $finalAmount);
58 $participantInfo = $this->get('participantInfo');
59 $this->assign('part', $this->_part);
60 $this->assign('participantInfo', $participantInfo);
61 $customGroup = $this->get('customProfile');
62 $this->assign('customProfile', $customGroup);
63 $this->assign('individual', $this->get('individual'));
64
65 CRM_Event_Form_Registration_Confirm::assignProfiles($this);
66
67 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
68 }
69
70 /**
71 * Overwrite action, since we are only showing elements in frozen mode
72 * no help display needed
73 *
74 * @return int
75 */
76 public function getAction() {
77 if ($this->_action & CRM_Core_Action::PREVIEW) {
78 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
79 }
80 else {
81 return CRM_Core_Action::VIEW;
82 }
83 }
84
85 /**
86 * Build the form object.
87 *
88 * @return void
89 */
90 public function buildQuickForm() {
91 // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
92 $primaryContactId = $this->get('primaryContactId');
93 if ($primaryContactId) {
94 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
95 $this->assign('email', $email);
96 }
97 $this->assignToTemplate();
98
99 $invoicing = CRM_Invoicing_Utils::isInvoicingEnabled();
100 $taxAmount = 0;
101
102 $lineItemForTemplate = [];
103 if (!empty($this->_lineItem) && is_array($this->_lineItem)) {
104 foreach ($this->_lineItem as $key => $value) {
105 if (!empty($value) && $value != 'skip') {
106 $lineItemForTemplate[$key] = $value;
107 if ($invoicing) {
108 foreach ($value as $v) {
109 if (isset($v['tax_amount']) || isset($v['tax_rate'])) {
110 $taxAmount += $v['tax_amount'];
111 }
112 }
113 }
114 }
115 }
116 }
117
118 if ($this->_priceSetId &&
119 !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config') &&
120 !empty($lineItemForTemplate)
121 ) {
122 $this->assignLineItemsToTemplate($lineItemForTemplate);
123 }
124
125 if ($invoicing) {
126 $this->assign('totalTaxAmount', $taxAmount);
127 }
128 $this->assign('totalAmount', $this->_totalAmount);
129
130 $hookDiscount = $this->get('hookDiscount');
131 if ($hookDiscount) {
132 $this->assign('hookDiscount', $hookDiscount);
133 }
134
135 $this->assign('receive_date', $this->_receiveDate);
136 $this->assign('trxn_id', $this->_trxnId);
137
138 //cosider total amount.
139 $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
140
141 $this->assign('defaultRole', FALSE);
142 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
143 $this->assign('defaultRole', TRUE);
144 }
145 $defaults = [];
146 $fields = [];
147 if (!empty($this->_fields)) {
148 foreach ($this->_fields as $name => $dontCare) {
149 $fields[$name] = 1;
150 }
151 }
152 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
153 foreach ($fields as $name => $dontCare) {
154 if (isset($this->_params[0][$name])) {
155 $defaults[$name] = $this->_params[0][$name];
156 if (substr($name, 0, 7) == 'custom_') {
157 $timeField = "{$name}_time";
158 if (isset($this->_params[0][$timeField])) {
159 $defaults[$timeField] = $this->_params[0][$timeField];
160 }
161 }
162 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
163 && !empty($this->_params[0][$name . '_custom'])
164 ) {
165 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
166 }
167 }
168 }
169
170 $this->_submitValues = array_merge($this->_submitValues, $defaults);
171
172 $this->setDefaults($defaults);
173
174 $params['entity_id'] = $this->_eventId;
175 $params['entity_table'] = 'civicrm_event';
176 $data = [];
177 CRM_Friend_BAO_Friend::retrieve($params, $data);
178 if (!empty($data['is_active'])) {
179 $friendText = $data['title'];
180 $this->assign('friendText', $friendText);
181 if ($this->_action & CRM_Core_Action::PREVIEW) {
182 $url = CRM_Utils_System::url('civicrm/friend',
183 "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
184 );
185 }
186 else {
187 $url = CRM_Utils_System::url('civicrm/friend',
188 "eid={$this->_eventId}&reset=1&pcomponent=event"
189 );
190 }
191 $this->assign('friendURL', $url);
192 }
193
194 $this->freeze();
195
196 //lets give meaningful status message, CRM-4320.
197 $isOnWaitlist = $isRequireApproval = FALSE;
198 if ($this->_allowWaitlist && !$this->_allowConfirmation) {
199 $isOnWaitlist = TRUE;
200 }
201 if ($this->_requireApproval && !$this->_allowConfirmation) {
202 $isRequireApproval = TRUE;
203 }
204 $this->assign('isOnWaitlist', $isOnWaitlist);
205 $this->assign('isRequireApproval', $isRequireApproval);
206
207 // find pcp info
208 $dao = new CRM_PCP_DAO_PCPBlock();
209 $dao->entity_table = 'civicrm_event';
210 $dao->entity_id = $this->_eventId;
211 $dao->is_active = 1;
212 $dao->find(TRUE);
213
214 if ($dao->id) {
215 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
216 $this->assign('pcpLinkText', $dao->link_text);
217 }
218
219 // Assign Participant Count to Lineitem Table
220 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
221
222 // can we blow away the session now to prevent hackery
223 $this->controller->reset();
224 }
225
226 /**
227 * Process the form submission.
228 *
229 *
230 * @return void
231 */
232 public function postProcess() {
233 }
234
235 /**
236 * Return a descriptive name for the page, used in wizard header
237 *
238 * @return string
239 */
240 public function getTitle() {
241 return ts('Thank You Page');
242 }
243
244 }