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