Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-10-21-22-31-28
[civicrm-core.git] / CRM / Event / Form / Registration / ThankYou.php
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_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 $this->assign('primaryParticipantProfile', $this->get('primaryParticipantProfile'));
66 $this->assign('addParticipantProfile', $this->get('addParticipantProfile'));
67
68 CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values['event']));
69 }
70
71 /**
72 * overwrite action, since we are only showing elements in frozen mode
73 * no help display needed
74 *
75 * @return int
76 * @access public
77 */
78 function getAction() {
79 if ($this->_action & CRM_Core_Action::PREVIEW) {
80 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
81 }
82 else {
83 return CRM_Core_Action::VIEW;
84 }
85 }
86
87 /**
88 * Function to build the form
89 *
90 * @return None
91 * @access public
92 */
93 public function buildQuickForm() {
94 // Assign the email address from a contact id lookup as in CRM_Event_BAO_Event->sendMail()
95 $primaryContactId = $this->get('primaryContactId');
96 if ($primaryContactId) {
97 list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($primaryContactId);
98 $this->assign('email', $email);
99 }
100 $this->assignToTemplate();
101
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 }
108 }
109 if (!empty($lineItemForTemplate)) {
110 $this->assign('lineItem', $lineItemForTemplate);
111 }
112 }
113
114 $this->assign('totalAmount', $this->_totalAmount);
115
116 $hookDiscount = $this->get('hookDiscount');
117 if ($hookDiscount) {
118 $this->assign('hookDiscount', $hookDiscount);
119 }
120
121 $this->assign('receive_date', $this->_receiveDate);
122 $this->assign('trxn_id', $this->_trxnId);
123
124 //cosider total amount.
125 $this->assign('isAmountzero', ($this->_totalAmount <= 0) ? TRUE : FALSE);
126
127 $this->assign('defaultRole', FALSE);
128 if (CRM_Utils_Array::value('defaultRole', $this->_params[0]) == 1) {
129 $this->assign('defaultRole', TRUE);
130 }
131 $defaults = array();
132 $fields = array();
133 if (!empty($this->_fields)) {
134 foreach ($this->_fields as $name => $dontCare) {
135 $fields[$name] = 1;
136 }
137 }
138 $fields['state_province'] = $fields['country'] = $fields['email'] = 1;
139 foreach ($fields as $name => $dontCare) {
140 if (isset($this->_params[0][$name])) {
141 $defaults[$name] = $this->_params[0][$name];
142 if (substr($name, 0, 7) == 'custom_') {
143 $timeField = "{$name}_time";
144 if (isset($this->_params[0][$timeField])) {
145 $defaults[$timeField] = $this->_params[0][$timeField];
146 }
147 }
148 elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)
149 && !empty($this->_params[0][$name . '_custom'])
150 ) {
151 $defaults[$name . '_custom'] = $this->_params[0][$name . '_custom'];
152 }
153 }
154 }
155
156 $this->_submitValues = array_merge($this->_submitValues, $defaults);
157
158 $this->setDefaults($defaults);
159
160 $params['entity_id'] = $this->_eventId;
161 $params['entity_table'] = 'civicrm_event';
162 $data = array();
163 CRM_Friend_BAO_Friend::retrieve($params, $data);
164 if (CRM_Utils_Array::value('is_active', $data)) {
165 $friendText = $data['title'];
166 $this->assign('friendText', $friendText);
167 if ($this->_action & CRM_Core_Action::PREVIEW) {
168 $url = CRM_Utils_System::url('civicrm/friend',
169 "eid={$this->_eventId}&reset=1&action=preview&pcomponent=event"
170 );
171 }
172 else {
173 $url = CRM_Utils_System::url('civicrm/friend',
174 "eid={$this->_eventId}&reset=1&pcomponent=event"
175 );
176 }
177 $this->assign('friendURL', $url);
178 }
179
180 $this->freeze();
181
182 //lets give meaningful status message, CRM-4320.
183 $isOnWaitlist = $isRequireApproval = FALSE;
184 if ($this->_allowWaitlist && !$this->_allowConfirmation) {
185 $isOnWaitlist = TRUE;
186 }
187 if ($this->_requireApproval && !$this->_allowConfirmation) {
188 $isRequireApproval = TRUE;
189 }
190 $this->assign('isOnWaitlist', $isOnWaitlist);
191 $this->assign('isRequireApproval', $isRequireApproval);
192
193 // find pcp info
194 $dao = new CRM_PCP_DAO_PCPBlock();
195 $dao->entity_table = 'civicrm_event';
196 $dao->entity_id = $this->_eventId;
197 $dao->is_active = 1;
198 $dao->find(TRUE);
199
200 if ($dao->id) {
201 $this->assign('pcpLink', CRM_Utils_System::url('civicrm/contribute/campaign', 'action=add&reset=1&pageId=' . $this->_eventId . '&component=event'));
202 $this->assign('pcpLinkText', $dao->link_text);
203 }
204
205 // Assign Participant Count to Lineitem Table
206 $this->assign('pricesetFieldsCount', CRM_Price_BAO_PriceSet::getPricesetCount($this->_priceSetId));
207
208 // can we blow away the session now to prevent hackery
209 $this->controller->reset();
210 }
211
212 /**
213 * Function to process the form
214 *
215 * @access public
216 *
217 * @return None
218 */
219 public function postProcess() {}
220 //end of function
221
222 /**
223 * Return a descriptive name for the page, used in wizard header
224 *
225 * @return string
226 * @access public
227 */
228 public function getTitle() {
229 return ts('Thank You Page');
230 }
231 }
232