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