| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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 | * @package CRM |
| 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
| 32 | */ |
| 33 | |
| 34 | /** |
| 35 | * Form for thank-you / success page - 3rd step of online contribution process. |
| 36 | */ |
| 37 | class CRM_Contribute_Form_Contribution_ThankYou extends CRM_Contribute_Form_ContributionBase { |
| 38 | |
| 39 | /** |
| 40 | * Membership price set status. |
| 41 | */ |
| 42 | public $_useForMember; |
| 43 | |
| 44 | /** |
| 45 | * Set variables up before form is built. |
| 46 | */ |
| 47 | public function preProcess() { |
| 48 | parent::preProcess(); |
| 49 | |
| 50 | $this->_params = $this->get('params'); |
| 51 | $this->_lineItem = $this->get('lineItem'); |
| 52 | $is_deductible = $this->get('is_deductible'); |
| 53 | $this->assign('is_deductible', $is_deductible); |
| 54 | $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->_values)); |
| 55 | $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->_values)); |
| 56 | $this->assign('thankyou_footer', CRM_Utils_Array::value('thankyou_footer', $this->_values)); |
| 57 | $this->assign('max_reminders', CRM_Utils_Array::value('max_reminders', $this->_values)); |
| 58 | $this->assign('initial_reminder_day', CRM_Utils_Array::value('initial_reminder_day', $this->_values)); |
| 59 | CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->_values)); |
| 60 | // Make the contributionPageID available to the template |
| 61 | $this->assign('contributionPageID', $this->_id); |
| 62 | $this->assign('isShare', $this->_values['is_share']); |
| 63 | |
| 64 | $this->_params['is_pay_later'] = $this->get('is_pay_later'); |
| 65 | $this->assign('is_pay_later', $this->_params['is_pay_later']); |
| 66 | if ($this->_params['is_pay_later']) { |
| 67 | $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']); |
| 68 | } |
| 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 | */ |
| 77 | public 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 | * Build the form object. |
| 88 | */ |
| 89 | public function buildQuickForm() { |
| 90 | $this->assignToTemplate(); |
| 91 | $productID = $this->get('productID'); |
| 92 | $option = $this->get('option'); |
| 93 | $membershipTypeID = $this->get('membershipTypeID'); |
| 94 | $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); |
| 95 | |
| 96 | if ($productID) { |
| 97 | CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); |
| 98 | } |
| 99 | if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { |
| 100 | $this->assign('lineItem', $this->_lineItem); |
| 101 | } |
| 102 | else { |
| 103 | if (is_array($membershipTypeID)) { |
| 104 | $membershipTypeID = current($membershipTypeID); |
| 105 | } |
| 106 | $this->assign('is_quick_config', 1); |
| 107 | $this->_params['is_quick_config'] = 1; |
| 108 | } |
| 109 | $this->assign('priceSetID', $this->_priceSetId); |
| 110 | $this->assign('useForMember', $this->get('useForMember')); |
| 111 | |
| 112 | $params = $this->_params; |
| 113 | $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); |
| 114 | $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); |
| 115 | if ($invoicing) { |
| 116 | $getTaxDetails = FALSE; |
| 117 | $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); |
| 118 | foreach ($this->_lineItem as $key => $value) { |
| 119 | foreach ($value as $v) { |
| 120 | if (isset($v['tax_rate'])) { |
| 121 | if ($v['tax_rate'] != '') { |
| 122 | $getTaxDetails = TRUE; |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | $this->assign('getTaxDetails', $getTaxDetails); |
| 128 | $this->assign('taxTerm', $taxTerm); |
| 129 | $this->assign('totalTaxAmount', $params['tax_amount']); |
| 130 | } |
| 131 | if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { |
| 132 | $honorName = NULL; |
| 133 | $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); |
| 134 | |
| 135 | $this->assign('honor_block_is_active', $this->_honor_block_is_active); |
| 136 | $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); |
| 137 | CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); |
| 138 | |
| 139 | $fieldTypes = array('Contact'); |
| 140 | $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); |
| 141 | $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); |
| 142 | } |
| 143 | |
| 144 | $qParams = "reset=1&id={$this->_id}"; |
| 145 | //pcp elements |
| 146 | if ($this->_pcpId) { |
| 147 | $qParams .= "&pcpId={$this->_pcpId}"; |
| 148 | $this->assign('pcpBlock', TRUE); |
| 149 | foreach (array( |
| 150 | 'pcp_display_in_roll', |
| 151 | 'pcp_is_anonymous', |
| 152 | 'pcp_roll_nickname', |
| 153 | 'pcp_personal_note', |
| 154 | ) as $val) { |
| 155 | if (!empty($this->_params[$val])) { |
| 156 | $this->assign($val, $this->_params[$val]); |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | $this->assign('qParams', $qParams); |
| 162 | |
| 163 | if ($membershipTypeID) { |
| 164 | $transactionID = $this->get('membership_trx_id'); |
| 165 | $membershipAmount = $this->get('membership_amount'); |
| 166 | $renewalMode = $this->get('renewal_mode'); |
| 167 | $this->assign('membership_trx_id', $transactionID); |
| 168 | $this->assign('membership_amount', $membershipAmount); |
| 169 | $this->assign('renewal_mode', $renewalMode); |
| 170 | |
| 171 | $this->buildMembershipBlock( |
| 172 | $this->_membershipContactID, |
| 173 | FALSE, |
| 174 | $membershipTypeID, |
| 175 | TRUE, |
| 176 | NULL |
| 177 | ); |
| 178 | |
| 179 | if (!empty($params['auto_renew'])) { |
| 180 | $this->assign('auto_renew', TRUE); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); |
| 185 | $this->assign("is_separate_payment", $this->_separateMembershipPayment); |
| 186 | |
| 187 | $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); |
| 188 | $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); |
| 189 | if (!empty($params['onbehalf_profile_id'])) { |
| 190 | $fieldTypes = array('Contact', 'Organization'); |
| 191 | $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); |
| 192 | $fieldTypes = array_merge($fieldTypes, $contactSubType); |
| 193 | if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { |
| 194 | $fieldTypes = array_merge($fieldTypes, array('Membership')); |
| 195 | } |
| 196 | else { |
| 197 | $fieldTypes = array_merge($fieldTypes, array('Contribution')); |
| 198 | } |
| 199 | |
| 200 | $this->buildCustom($params['onbehalf_profile_id'], 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); |
| 201 | } |
| 202 | |
| 203 | $this->assign('trxn_id', |
| 204 | CRM_Utils_Array::value('trxn_id', |
| 205 | $this->_params |
| 206 | ) |
| 207 | ); |
| 208 | $this->assign('receive_date', |
| 209 | CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params)) |
| 210 | ); |
| 211 | |
| 212 | $defaults = array(); |
| 213 | $fields = array(); |
| 214 | foreach ($this->_fields as $name => $dontCare) { |
| 215 | if ($name != 'onbehalf' || $name != 'honor') { |
| 216 | $fields[$name] = 1; |
| 217 | } |
| 218 | } |
| 219 | $fields['state_province'] = $fields['country'] = $fields['email'] = 1; |
| 220 | $contact = $this->_params = $this->controller->exportValues('Main'); |
| 221 | |
| 222 | foreach ($fields as $name => $dontCare) { |
| 223 | if (isset($contact[$name])) { |
| 224 | $defaults[$name] = $contact[$name]; |
| 225 | if (substr($name, 0, 7) == 'custom_') { |
| 226 | $timeField = "{$name}_time"; |
| 227 | if (isset($contact[$timeField])) { |
| 228 | $defaults[$timeField] = $contact[$timeField]; |
| 229 | } |
| 230 | } |
| 231 | elseif (in_array($name, array( |
| 232 | 'addressee', |
| 233 | 'email_greeting', |
| 234 | 'postal_greeting', |
| 235 | )) && !empty($contact[$name . '_custom']) |
| 236 | ) { |
| 237 | $defaults[$name . '_custom'] = $contact[$name . '_custom']; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | $this->_submitValues = array_merge($this->_submitValues, $defaults); |
| 243 | |
| 244 | if (!empty($this->_params['onbehalf_values'])) { |
| 245 | $defaults['onbehalf'] = (array) json_decode($this->_params['onbehalf_values']); |
| 246 | } |
| 247 | $this->setDefaults($defaults); |
| 248 | |
| 249 | $values['entity_id'] = $this->_id; |
| 250 | $values['entity_table'] = 'civicrm_contribution_page'; |
| 251 | |
| 252 | CRM_Friend_BAO_Friend::retrieve($values, $data); |
| 253 | $tellAFriend = FALSE; |
| 254 | if ($this->_pcpId) { |
| 255 | if ($this->_pcpBlock['is_tellfriend_enabled']) { |
| 256 | $this->assign('friendText', ts('Tell a Friend')); |
| 257 | $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; |
| 258 | $tellAFriend = TRUE; |
| 259 | } |
| 260 | } |
| 261 | elseif (!empty($data['is_active'])) { |
| 262 | $friendText = $data['title']; |
| 263 | $this->assign('friendText', $friendText); |
| 264 | $subUrl = "eid={$this->_id}&pcomponent=contribute"; |
| 265 | $tellAFriend = TRUE; |
| 266 | } |
| 267 | |
| 268 | if ($tellAFriend) { |
| 269 | if ($this->_action & CRM_Core_Action::PREVIEW) { |
| 270 | $url = CRM_Utils_System::url("civicrm/friend", |
| 271 | "reset=1&action=preview&{$subUrl}" |
| 272 | ); |
| 273 | } |
| 274 | else { |
| 275 | $url = CRM_Utils_System::url("civicrm/friend", |
| 276 | "reset=1&{$subUrl}" |
| 277 | ); |
| 278 | } |
| 279 | $this->assign('friendURL', $url); |
| 280 | } |
| 281 | |
| 282 | $this->freeze(); |
| 283 | |
| 284 | // can we blow away the session now to prevent hackery |
| 285 | // CRM-9491 |
| 286 | $this->controller->reset(); |
| 287 | } |
| 288 | |
| 289 | } |