CRM-13148 Support use of cid=0 and cid=NNN for online contribution pages.
[civicrm-core.git] / CRM / Contribute / Form / Contribution / Confirm.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36/**
37 * form to process actions on the group aspect of Custom Data
38 */
39class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_ContributionBase {
40
41 /**
42 * the id of the contact associated with this contribution
43 *
44 * @var int
45 * @public
46 */
47 public $_contactID;
48
1f1740fe
DL
49
50 /**
51 * The id of the contribution object that is created when the form is submitted
52 *
53 * @var int
54 * @public
55 */
56 public $_contributionID;
57
6a488035
TO
58 /**
59 * Function to set variables up before form is built
60 *
61 * @return void
62 * @access public
63 */
64 public function preProcess() {
65 $config = CRM_Core_Config::singleton();
66 parent::preProcess();
cde484fd 67
6a488035
TO
68 // lineItem isn't set until Register postProcess
69 $this->_lineItem = $this->get('lineItem');
70 $this->_paymentProcessor = $this->get('paymentProcessor');
cde484fd 71
6a488035
TO
72 if ($this->_contributeMode == 'express') {
73 // rfp == redirect from paypal
74 $rfp = CRM_Utils_Request::retrieve('rfp', 'Boolean',
75 CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'
76 );
77 if ($rfp) {
78 $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
79 $expressParams = $payment->getExpressCheckoutDetails($this->get('token'));
80
81 $this->_params['payer'] = $expressParams['payer'];
82 $this->_params['payer_id'] = $expressParams['payer_id'];
83 $this->_params['payer_status'] = $expressParams['payer_status'];
84
85 CRM_Core_Payment_Form::mapParams($this->_bltID, $expressParams, $this->_params, FALSE);
cde484fd 86
6a488035
TO
87 // fix state and country id if present
88 if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"]) && $this->_params["billing_state_province_id-{$this->_bltID}"]) {
89 $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
90 }
91 if (!empty($this->_params["billing_country_id-{$this->_bltID}"]) && $this->_params["billing_country_id-{$this->_bltID}"]) {
92 $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
93 }
94
95 // set a few other parameters for PayPal
96 $this->_params['token'] = $this->get('token');
97
98 $this->_params['amount'] = $this->get('amount');
99
100 if (!empty($this->_membershipBlock)){
101 $this->_params['selectMembership'] = $this->get('selectMembership');
102 }
103 // we use this here to incorporate any changes made by folks in hooks
104 $this->_params['currencyID'] = $config->defaultCurrency;
105
106 $this->_params['payment_action'] = 'Sale';
107
108 // also merge all the other values from the profile fields
109 $values = $this->controller->exportValues('Main');
110 $skipFields = array(
111 'amount', 'amount_other',
112 "billing_street_address-{$this->_bltID}",
113 "billing_city-{$this->_bltID}",
114 "billing_state_province_id-{$this->_bltID}",
115 "billing_postal_code-{$this->_bltID}",
116 "billing_country_id-{$this->_bltID}",
117 );
118 foreach ($values as $name => $value) {
119 // skip amount field
120 if (!in_array($name, $skipFields)) {
121 $this->_params[$name] = $value;
122 }
123 }
124 $this->set('getExpressCheckoutDetails', $this->_params);
125 }
126 else {
127 $this->_params = $this->get('getExpressCheckoutDetails');
128 }
129 }
130 else {
131 $this->_params = $this->controller->exportValues('Main');
132
133 if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
134 $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
135 }
136 if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
137 $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
138 }
139
140 if (isset($this->_params['credit_card_exp_date'])) {
141 $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
142 $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
143 }
144 $this->_params['ip_address'] = $_SERVER['REMOTE_ADDR'];
145 // hack for safari
146 if ($this->_params['ip_address'] == '::1') {
147 $this->_params['ip_address'] = '127.0.0.1';
148 }
149 $this->_params['amount'] = $this->get('amount');
150
151 $this->_useForMember = $this->get('useForMember');
cde484fd 152
6a488035 153 if (isset($this->_params['amount'])) {
9da8dc8c 154 $priceField = new CRM_Price_DAO_PriceField();
6a488035
TO
155 $priceField->price_set_id = $this->_params['priceSetId'];
156 $priceField->orderBy('weight');
157 $priceField->find();
158 $contriPriceId = NULL;
9da8dc8c 159 $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_params['priceSetId'], 'is_quick_config');
6a488035
TO
160 while ($priceField->fetch()) {
161 if ($priceField->name == "contribution_amount") {
162 $contriPriceId = $priceField->id;
163 }
164 if ($isQuickConfig && !empty($this->_params["price_{$priceField->id}"])) {
165 if ($this->_values['fee'][$priceField->id]['html_type'] != 'Text') {
9da8dc8c 166 $this->_params['amount_level'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
6a488035
TO
167 $this->_params["price_{$priceField->id}"], 'label');
168 }
169 if ($priceField->name == "membership_amount") {
9da8dc8c 170 $this->_params['selectMembership'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue',
6a488035
TO
171 $this->_params["price_{$priceField->id}"], 'membership_type_id');
172 }
173 } // if seperate payment we set contribution amount to be null, so that it will not show contribution amount same as membership amount.
174 elseif ((CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock))
abcf506a 175 && CRM_Utils_Array::value($priceField->id, $this->_values['fee'])
6a488035
TO
176 && ($this->_values['fee'][$priceField->id]['name'] == "other_amount")
177 && CRM_Utils_Array::value("price_{$contriPriceId}", $this->_params) < 1
178 && !CRM_Utils_Array::value("price_{$priceField->id}", $this->_params)) {
179 $this->_params['amount'] = null;
180 }
181 }
182 }
183 $this->_params['currencyID'] = $config->defaultCurrency;
184 $this->_params['payment_action'] = 'Sale';
185 }
186
187 $this->_params['is_pay_later'] = $this->get('is_pay_later');
188 $this->assign('is_pay_later', $this->_params['is_pay_later']);
189 if ($this->_params['is_pay_later']) {
190 $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
191 }
192 // if onbehalf-of-organization
193 if (CRM_Utils_Array::value('hidden_onbehalf_profile', $this->_params)) {
194 if (CRM_Utils_Array::value('org_option', $this->_params) &&
195 CRM_Utils_Array::value('organization_id', $this->_params)
196 ) {
197 if (CRM_Utils_Array::value('onbehalfof_id', $this->_params)) {
198 $this->_params['organization_id'] = $this->_params['onbehalfof_id'];
199 }
200 }
201
202 $this->_params['organization_name'] = $this->_params['onbehalf']['organization_name'];
203 $addressBlocks = array(
204 'street_address', 'city', 'state_province',
205 'postal_code', 'country', 'supplemental_address_1',
206 'supplemental_address_2', 'supplemental_address_3',
207 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'address_name',
208 );
209
210 $blocks = array('email', 'phone', 'im', 'url', 'openid');
211 foreach ($this->_params['onbehalf'] as $loc => $value) {
212 $field = $typeId = NULL;
213 if (strstr($loc, '-')) {
214 list($field, $locType) = explode('-', $loc);
215 }
216
217 if (in_array($field, $addressBlocks)) {
218 if ($locType == 'Primary') {
219 $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
220 $locType = $defaultLocationType->id;
cde484fd
DL
221 }
222
6a488035
TO
223 if ($field == 'country') {
224 $value = CRM_Core_PseudoConstant::countryIsoCode($value);
225 }
226 elseif ($field == 'state_province') {
227 $value = CRM_Core_PseudoConstant::stateProvinceAbbreviation($value);
228 }
cde484fd 229
6a488035
TO
230 $isPrimary = 1;
231 if (isset($this->_params['onbehalf_location']['address'])
232 && count($this->_params['onbehalf_location']['address']) > 0) {
233 $isPrimary = 0;
234 }
cde484fd 235
6a488035
TO
236 $this->_params['onbehalf_location']['address'][$locType][$field] = $value;
237 if (!CRM_Utils_Array::value('is_primary', $this->_params['onbehalf_location']['address'][$locType])) {
238 $this->_params['onbehalf_location']['address'][$locType]['is_primary'] = $isPrimary;
239 }
240 $this->_params['onbehalf_location']['address'][$locType]['location_type_id'] = $locType;
241 }
242 elseif (in_array($field, $blocks)) {
243 if (!$typeId || is_numeric($typeId)) {
244 $blockName = $fieldName = $field;
245 $locationType = 'location_type_id';
246 if ( $locType == 'Primary' ) {
247 $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
248 $locationValue = $defaultLocationType->id;
249 }
250 else {
251 $locationValue = $locType;
252 }
253 $locTypeId = '';
254 $phoneExtField = array();
255
256 if ($field == 'url') {
257 $blockName = 'website';
258 $locationType = 'website_type_id';
259 $locationValue = CRM_Utils_Array::value("{$loc}-website_type_id", $this->_params['onbehalf']);
260 }
261 elseif ($field == 'im') {
262 $fieldName = 'name';
263 $locTypeId = 'provider_id';
264 $typeId = $this->_params['onbehalf']["{$loc}-provider_id"];
265 }
266 elseif ($field == 'phone') {
267 list($field, $locType, $typeId) = explode('-', $loc);
268 $locTypeId = 'phone_type_id';
269
270 //check if extension field exists
271 $extField = str_replace('phone','phone_ext', $loc);
272 if (isset($this->_params['onbehalf'][$extField])) {
273 $phoneExtField = array('phone_ext' => $this->_params['onbehalf'][$extField]);
274 }
275 }
276
277 $isPrimary = 1;
278 if ( isset ($this->_params['onbehalf_location'][$blockName] )
279 && count( $this->_params['onbehalf_location'][$blockName] ) > 0 ) {
280 $isPrimary = 0;
281 }
282 if ($locationValue) {
283 $blockValues = array(
284 $fieldName => $value,
285 $locationType => $locationValue,
286 'is_primary' => $isPrimary,
287 );
288
289 if ($locTypeId) {
290 $blockValues = array_merge($blockValues, array($locTypeId => $typeId));
291 }
292 if (!empty($phoneExtField)) {
293 $blockValues = array_merge($blockValues, $phoneExtField);
294 }
295
296 $this->_params['onbehalf_location'][$blockName][] = $blockValues;
297 }
298 }
299 }
300 elseif (strstr($loc, 'custom')) {
301 if ($value && isset($this->_params['onbehalf']["{$loc}_id"])) {
302 $value = $this->_params['onbehalf']["{$loc}_id"];
303 }
304 $this->_params['onbehalf_location']["{$loc}"] = $value;
305 }
306 else {
307 if ($loc == 'contact_sub_type') {
308 $this->_params['onbehalf_location'][$loc] = $value;
309 }
310 else {
311 $this->_params['onbehalf_location'][$field] = $value;
312 }
313 }
314 }
315 }
316 elseif (CRM_Utils_Array::value('is_for_organization', $this->_values)) {
317 // no on behalf of an organization, CRM-5519
318 // so reset loc blocks from main params.
319 foreach (array(
320 'phone', 'email', 'address') as $blk) {
321 if (isset($this->_params[$blk])) {
322 unset($this->_params[$blk]);
323 }
324 }
325 }
326
327 // if auto renew checkbox is set, initiate a open-ended recurring membership
328 if ((CRM_Utils_Array::value('selectMembership', $this->_params) ||
329 CRM_Utils_Array::value('priceSetId', $this->_params)
330 ) &&
331 CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) &&
332 CRM_Utils_Array::value('auto_renew', $this->_params) &&
333 !CRM_Utils_Array::value('is_recur', $this->_params) &&
334 !CRM_Utils_Array::value('frequency_interval', $this->_params)
335 ) {
336
337 $this->_params['is_recur'] = $this->_values['is_recur'] = 1;
338 // check if price set is not quick config
339 if (CRM_Utils_Array::value('priceSetId', $this->_params) && !$isQuickConfig) {
9da8dc8c 340 list($this->_params['frequency_interval'], $this->_params['frequency_unit']) = CRM_Price_BAO_PriceSet::getRecurDetails($this->_params['priceSetId']);
6a488035
TO
341 }
342 else {
343 // FIXME: set interval and unit based on selected membership type
344 $this->_params['frequency_interval'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
345 $this->_params['selectMembership'], 'duration_interval'
346 );
347 $this->_params['frequency_unit'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
348 $this->_params['selectMembership'], 'duration_unit'
349 );
350 }
351 }
352
353 if ($this->_pcpId) {
354 $params = $this->processPcp($this, $this->_params);
355 $this->_params = $params;
356 }
357 $this->_params['invoiceID'] = $this->get('invoiceID');
358
359 //carry campaign from profile.
360 if (array_key_exists('contribution_campaign_id', $this->_params)) {
361 $this->_params['campaign_id'] = $this->_params['contribution_campaign_id'];
362 }
363
569df8ec
DG
364 // assign contribution page id to the template so we can add css class for it
365 $this->assign('contributionPageID', $this->_id);
366
6a488035
TO
367 $this->set('params', $this->_params);
368 }
369
370 /**
371 * Function to actually build the form
372 *
373 * @return void
374 * @access public
375 */
376 public function buildQuickForm() {
377 $this->assignToTemplate();
378
379 $params = $this->_params;
380 $honor_block_is_active = $this->get('honor_block_is_active');
381 // make sure we have values for it
382 if ($honor_block_is_active &&
383 ((!empty($params['honor_first_name']) && !empty($params['honor_last_name'])) ||
384 (!empty($params['honor_email']))
385 )
386 ) {
387 $this->assign('honor_block_is_active', $honor_block_is_active);
388 $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
389
e6c4755b 390 $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
cbf48754 391 $honor = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
6a488035
TO
392 $this->assign('honor_type', CRM_Utils_Array::value($params['honor_type_id'], $honor));
393 $this->assign('honor_prefix', CRM_Utils_Array::value($params['honor_prefix_id'], $prefix));
394 $this->assign('honor_first_name', $params['honor_first_name']);
395 $this->assign('honor_last_name', $params['honor_last_name']);
396 $this->assign('honor_email', $params['honor_email']);
397 }
398 $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values));
399 $amount_block_is_active = $this->get('amount_block_is_active');
400 $this->assign('amount_block_is_active', $amount_block_is_active);
401
402 if (CRM_Utils_Array::value('selectProduct', $params) && $params['selectProduct'] != 'no_thanks') {
403 $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params);
404 $productID = $params['selectProduct'];
405 CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE,
406 $productID, $option
407 );
408 $this->set('productID', $productID);
409 $this->set('option', $option);
410 }
411 $config = CRM_Core_Config::singleton();
412 if (in_array('CiviMember', $config->enableComponents)) {
413 if (isset($params['selectMembership']) &&
414 $params['selectMembership'] != 'no_thanks'
415 ) {
416 CRM_Member_BAO_Membership::buildMembershipBlock($this,
417 $this->_id,
418 FALSE,
419 $params['selectMembership'],
420 FALSE, NULL,
421 $this->_membershipContactID
422 );
423 }
424 else {
425 $this->assign('membershipBlock', FALSE);
426 }
427 }
428 $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
429 $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
430
431 if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
432 $ufJoinParams = array(
433 'module' => 'onBehalf',
434 'entity_table' => 'civicrm_contribution_page',
435 'entity_id' => $this->_id,
436 );
437 $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams);
438 $profileId = $OnBehalfProfile[0];
439
440 $fieldTypes = array('Contact', 'Organization');
441 $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
442 $fieldTypes = array_merge($fieldTypes, $contactSubType);
443 if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) {
444 $fieldTypes = array_merge($fieldTypes, array('Membership'));
445 }
446 else {
447 $fieldTypes = array_merge($fieldTypes, array('Contribution'));
448 }
449
450 $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes);
451 }
452
453 $this->_separateMembershipPayment = $this->get('separateMembershipPayment');
454 $this->assign('is_separate_payment', $this->_separateMembershipPayment);
9da8dc8c 455 if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) {
6a488035
TO
456 $this->assign('lineItem', $this->_lineItem);
457 } else {
458 $this->assign('is_quick_config', 1);
459 $this->_params['is_quick_config'] = 1;
460 }
461 $this->assign('priceSetID', $this->_priceSetId);
462 $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name');
f92fc7eb
CW
463 if ($this->_paymentProcessor &&
464 $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType)
6a488035
TO
465 && !$this->_params['is_pay_later'] && !($this->_amount == 0)
466 ) {
467 $this->_checkoutButtonName = $this->getButtonName('next', 'checkout');
468 $this->add('image',
469 $this->_checkoutButtonName,
470 $this->_paymentProcessor['url_button'],
471 array('class' => 'form-submit')
472 );
473
474 $this->addButtons(array(
475 array(
476 'type' => 'back',
477 'name' => ts('<< Go Back'),
478 ),
479 )
480 );
481 }
482 else {
483 if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] ||
484 $this->_amount <= 0.0 || $this->_params['is_pay_later'] ||
485 ($this->_separateMembershipPayment && $this->_amount <= 0.0)
486 ) {
487 $contribButton = ts('Continue >>');
488 $this->assign('button', ts('Continue'));
489 }
490 else {
491 $contribButton = ts('Make Contribution');
492 $this->assign('button', ts('Make Contribution'));
493 }
494 $this->addButtons(array(
495 array(
496 'type' => 'next',
497 'name' => $contribButton,
498 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
499 'isDefault' => TRUE,
500 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"),
501 ),
502 array(
503 'type' => 'back',
504 'name' => ts('Go Back'),
505 ),
506 )
507 );
508 }
509
510 $defaults = array();
511 $fields = array();
512 foreach ($this->_fields as $name => $dontCare) {
513 if ($name == 'onbehalf') {
514 foreach ($dontCare as $key => $value) {
515 $fields['onbehalf'][$key] = 1;
516 }
517 }
518 else {
519 $fields[$name] = 1;
520 }
521 }
522 $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1;
523
524 $contact = $this->_params;
525 foreach ($fields as $name => $dontCare) {
526 if ($name == 'onbehalf') {
527 foreach ($dontCare as $key => $value) {
528 if (isset($contact['onbehalf'][$key])) {
529 $defaults[$key] = $contact['onbehalf'][$key];
530 }
531 if (isset($contact['onbehalf']["{$key}_id"])) {
532 $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"];
533 }
534 }
535 }
536 elseif (isset($contact[$name])) {
537 $defaults[$name] = $contact[$name];
538 if (substr($name, 0, 7) == 'custom_') {
539 $timeField = "{$name}_time";
540 if (isset($contact[$timeField])) {
541 $defaults[$timeField] = $contact[$timeField];
542 }
543 if (isset($contact["{$name}_id"])) {
544 $defaults["{$name}_id"] = $contact["{$name}_id"];
545 }
546 }
547 elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting'))
548 && CRM_Utils_Array::value($name . '_custom', $contact)
549 ) {
550 $defaults[$name . '_custom'] = $contact[$name . '_custom'];
551 }
552 }
553 }
554
555 $this->assign('useForMember', $this->get('useForMember'));
556
557 // now fix all state country selectors
558 CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults);
559
560 $this->setDefaults($defaults);
561
562 $this->freeze();
563 }
564
565 /**
566 * overwrite action, since we are only showing elements in frozen mode
567 * no help display needed
568 *
569 * @return int
570 * @access public
571 */
572 function getAction() {
573 if ($this->_action & CRM_Core_Action::PREVIEW) {
574 return CRM_Core_Action::VIEW | CRM_Core_Action::PREVIEW;
575 }
576 else {
577 return CRM_Core_Action::VIEW;
578 }
579 }
580
581 /**
582 * This function sets the default values for the form. Note that in edit/view mode
583 * the default values are retrieved from the database
584 *
585 * @access public
586 *
587 * @return void
588 */
589 function setDefaultValues() {}
590
591 /**
592 * Process the form
593 *
594 * @return void
595 * @access public
596 */
597 public function postProcess() {
598 $config = CRM_Core_Config::singleton();
da8d9879 599 $contactID = $this->getContactID();
6a488035
TO
600
601 // add a description field at the very beginning
602 $this->_params['description'] = ts('Online Contribution') . ': ' . (($this->_pcpInfo['title']) ? $this->_pcpInfo['title'] : $this->_values['title']);
603
604 // also add accounting code
605 $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode',
606 $this->_values
607 );
608
609 // fix currency ID
610 $this->_params['currencyID'] = $config->defaultCurrency;
611
612 $premiumParams = $membershipParams = $tempParams = $params = $this->_params;
613
614 //carry payment processor id.
615 if ($paymentProcessorId = CRM_Utils_Array::value('id', $this->_paymentProcessor)) {
616 $this->_params['payment_processor_id'] = $paymentProcessorId;
617 foreach (array(
618 'premiumParams', 'membershipParams', 'tempParams', 'params') as $p) {
619 ${$p}['payment_processor_id'] = $paymentProcessorId;
620 }
621 }
622
623 $fields = array();
624
625 if (CRM_Utils_Array::value('image_URL', $params)) {
626 CRM_Contact_BAO_Contact::processImageParams($params);
627 }
628
629 // set email for primary location.
630 $fields['email-Primary'] = 1;
631
632 // get the add to groups
633 $addToGroups = array();
634
635 // now set the values for the billing location.
636 foreach ($this->_fields as $name => $value) {
637 $fields[$name] = 1;
638
639 // get the add to groups for uf fields
640 if (CRM_Utils_Array::value('add_to_group_id', $value)) {
641 $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id'];
642 }
643 }
644
645 if (!array_key_exists('first_name', $fields)) {
646 $nameFields = array('first_name', 'middle_name', 'last_name');
647 foreach ($nameFields as $name) {
648 $fields[$name] = 1;
649 if (array_key_exists("billing_$name", $params)) {
650 $params[$name] = $params["billing_{$name}"];
651 $params['preserveDBName'] = TRUE;
652 }
653 }
654 }
655
656 // billing email address
657 $fields["email-{$this->_bltID}"] = 1;
658
659 //unset the billing parameters if it is pay later mode
660 //to avoid creation of billing location
661 if ($params['is_pay_later']) {
662 $billingFields = array(
663 'billing_first_name',
664 'billing_middle_name',
665 'billing_last_name',
666 "billing_street_address-{$this->_bltID}",
667 "billing_city-{$this->_bltID}",
668 "billing_state_province-{$this->_bltID}",
669 "billing_state_province_id-{$this->_bltID}",
670 "billing_postal_code-{$this->_bltID}",
671 "billing_country-{$this->_bltID}",
672 "billing_country_id-{$this->_bltID}",
673 );
674
675 foreach ($billingFields as $value) {
676 unset($params[$value]);
677 unset($fields[$value]);
678 }
679 }
680
681 // if onbehalf-of-organization contribution, take out
682 // organization params in a separate variable, to make sure
683 // normal behavior is continued. And use that variable to
684 // process on-behalf-of functionality.
685 if (CRM_Utils_Array::value('hidden_onbehalf_profile', $this->_params)) {
686 $behalfOrganization = array();
687 $orgFields = array('organization_name', 'organization_id', 'org_option');
688 foreach ($orgFields as $fld) {
689 if (array_key_exists($fld, $params)) {
690 $behalfOrganization[$fld] = $params[$fld];
691 unset($params[$fld]);
692 }
693 }
694
695 if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) {
696 foreach ($params['onbehalf'] as $fld => $values) {
697 if (strstr($fld, 'custom_')) {
698 $behalfOrganization[$fld] = $values;
cde484fd 699 }
6a488035
TO
700 elseif (!(strstr($fld, '-'))) {
701 if (in_array($fld, array(
702 'contribution_campaign_id', 'member_campaign_id'))) {
703 $fld = 'campaign_id';
704 }
705 else {
706 $behalfOrganization[$fld] = $values;
cde484fd 707 }
6a488035
TO
708 $this->_params[$fld] = $values;
709 }
710 }
711 }
712
713 if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) {
714 foreach ($params['onbehalf_location'] as $block => $vals) {
715 //fix for custom data (of type checkbox, multi-select)
716 if ( substr($block, 0, 7) == 'custom_' ) {
717 continue;
718 }
719 // fix the index of block elements
720 if (is_array($vals) ) {
721 foreach ( $vals as $key => $val ) {
722 //dont adjust the index of address block as
723 //it's index is WRT to location type
724 $newKey = ($block == 'address') ? $key : ++$key;
725 $behalfOrganization[$block][$newKey] = $val;
726 }
727 }
728 }
729 unset($params['onbehalf_location']);
730 }
731 if (CRM_Utils_Array::value('onbehalf[image_URL]', $params)) {
732 $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]'];
733 }
734 }
735
736 // check for profile double opt-in and get groups to be subscribed
737 $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID);
738
739 // since we are directly adding contact to group lets unset it from mailing
740 if (!empty($addToGroups)) {
741 foreach ($addToGroups as $groupId) {
742 if (isset($subscribeGroupIds[$groupId])) {
743 unset($subscribeGroupIds[$groupId]);
744 }
745 }
746 }
747
748 foreach ($addToGroups as $k) {
749 if (array_key_exists($k, $subscribeGroupIds)) {
750 unset($addToGroups[$k]);
751 }
752 }
753
da8d9879 754 if (empty($contactID)) {
6a488035
TO
755 $dupeParams = $params;
756 if (CRM_Utils_Array::value('onbehalf', $dupeParams)) {
757 unset($dupeParams['onbehalf']);
758 }
759
760 $dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual');
761 $dedupeParams['check_permission'] = FALSE;
762 $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
763
764 // if we find more than one contact, use the first one
765 $contact_id = CRM_Utils_Array::value(0, $ids);
766
767 // Fetch default greeting id's if creating a contact
768 if (!$contact_id) {
769 foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
770 if (!isset($params[$greeting])) {
771 $params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting);
772 }
773 }
774 }
775
3138c9b3
DL
776 $contactID = CRM_Contact_BAO_Contact::createProfileContact(
777 $params,
6a488035
TO
778 $fields,
779 $contact_id,
780 $addToGroups,
781 NULL,
782 NULL,
783 TRUE
784 );
785 }
786 else {
787 $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type');
3138c9b3
DL
788 $contactID = CRM_Contact_BAO_Contact::createProfileContact(
789 $params,
6a488035
TO
790 $fields,
791 $contactID,
792 $addToGroups,
793 NULL,
794 $ctype,
795 TRUE
796 );
797 }
798
799 // Make the contact ID associated with the contribution available at the Class level.
800 // Also make available to the session.
801 $this->set('contactID', $contactID);
802 $this->_contactID = $contactID;
803
804 //get email primary first if exist
805 $subscribtionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params));
806 if (!$subscribtionEmail['email']) {
807 $subscribtionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params);
808 }
809 // subscribing contact to groups
810 if (!empty($subscribeGroupIds) && $subscribtionEmail['email']) {
811 CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscribtionEmail, $contactID);
812 }
813
814 // If onbehalf-of-organization contribution / signup, add organization
815 // and it's location.
816 if (isset($params['hidden_onbehalf_profile']) && isset($behalfOrganization['organization_name'])) {
817 $ufFields = array();
818 foreach ($this->_fields['onbehalf'] as $name => $value) {
819 $ufFields[$name] = 1;
820 }
821 self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values,
822 $this->_params, $ufFields
823 );
824 }
825
826 // lets store the contactID in the session
827 // for things like tell a friend
828 $session = CRM_Core_Session::singleton();
829 if (!$session->get('userID')) {
830 $session->set('transaction.userID', $contactID);
831 }
832 else {
833 $session->set('transaction.userID', NULL);
834 }
835
836 $this->_useForMember = $this->get('useForMember');
837
838 // store the fact that this is a membership and membership type is selected
839 $processMembership = FALSE;
840 if ((CRM_Utils_Array::value('selectMembership', $membershipParams) &&
841 $membershipParams['selectMembership'] != 'no_thanks'
842 ) ||
843 $this->_useForMember
844 ) {
845 $processMembership = TRUE;
846
847 if (!$this->_useForMember) {
848 $this->assign('membership_assign', TRUE);
849 $this->set('membershipTypeID', $this->_params['selectMembership']);
850 }
851
852 if ($this->_action & CRM_Core_Action::PREVIEW) {
853 $membershipParams['is_test'] = 1;
854 }
855 if ($this->_params['is_pay_later']) {
856 $membershipParams['is_pay_later'] = 1;
857 }
858 }
859
860 if ($processMembership) {
861 CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE);
862
863 // added new parameter for cms user contact id, needed to distinguish behaviour for on behalf of sign-ups
864 if (isset($this->_params['related_contact'])) {
865 $membershipParams['cms_contactID'] = $this->_params['related_contact'];
866 }
867 else {
868 $membershipParams['cms_contactID'] = $contactID;
869 }
870
871 //inherit campaign from contirb page.
872 if (!array_key_exists('campaign_id', $membershipParams)) {
873 $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values);
874 }
875
876 if (!empty($membershipParams['onbehalf']) &&
877 is_array($membershipParams['onbehalf']) &&
878 CRM_Utils_Array::value('member_campaign_id', $membershipParams['onbehalf'])) {
879 $this->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id'];
880 }
881
882 $customFieldsFormatted = $fieldTypes = array();
883 if (!empty($membershipParams['onbehalf']) &&
884 is_array($membershipParams['onbehalf'])) {
885 foreach ($membershipParams['onbehalf'] as $key => $value) {
886 if (strstr($key, 'custom_')) {
887 $customFieldId = explode('_', $key);
888 CRM_Core_BAO_CustomField::formatCustomField(
889 $customFieldId[1],
890 $customFieldsFormatted,
891 $value,
892 'Membership',
893 NULL,
894 $contactID
895 );
896 }
897 }
898 $fieldTypes = array('Contact', 'Organization', 'Membership');
899 }
900
901 $priceFieldIds = $this->get('memberPriceFieldIDS');
902
903 if (!empty($priceFieldIds)) {
9da8dc8c 904 $contributionTypeID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceFieldIds['id'], 'financial_type_id');
6a488035
TO
905 unset($priceFieldIds['id']);
906 $membershipTypeIds = array();
907 $membershipTypeTerms = array();
908 foreach ($priceFieldIds as $priceFieldId) {
9da8dc8c 909 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
6a488035
TO
910 $membershipTypeIds[] = $id;
911 $term = 1;
9da8dc8c 912 if ($term = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_num_terms')) {
6a488035
TO
913 $membershipTypeTerms[$id] = ($term > 1) ? $term : 1;
914 }
915 else {
916 $membershipTypeTerms[$id] = 1;
917 }
918 }
919 }
920 $membershipParams['selectMembership'] = $membershipTypeIds;
9ce8bcfc 921 $membershipParams['financial_type_id'] = $contributionTypeID;
6a488035
TO
922 $membershipParams['types_terms'] = $membershipTypeTerms;
923 }
924 if (CRM_Utils_Array::value('selectMembership', $membershipParams)) {
9ce8bcfc
PN
925 // CRM-12233
926 if ($this->_separateMembershipPayment && $this->_values['amount_block_is_active']) {
927 foreach ($this->_values['fee'] as $key => $feeValues) {
928 if ($feeValues['name'] == 'membership_amount') {
929 $fieldId = $this->_params['price_' . $key];
930 $this->_memLineItem[$this->_priceSetId][$fieldId] = $this->_lineItem[$this->_priceSetId][$fieldId];
931 unset($this->_lineItem[$this->_priceSetId][$fieldId]);
932 break;
933 }
934 }
935 }
e34dd94b 936
cde484fd
DL
937 CRM_Member_BAO_Membership::postProcessMembership($membershipParams, $contactID,
938 $this, $premiumParams, $customFieldsFormatted,
939 $fieldTypes
940 );
9ce8bcfc 941 }
6a488035
TO
942 }
943 else {
944 // at this point we've created a contact and stored its address etc
945 // all the payment processors expect the name and address to be in the
946 // so we copy stuff over to first_name etc.
947 $paymentParams = $this->_params;
157b21d8 948 $contributionTypeId = $this->_values['financial_type_id'];
6a488035
TO
949
950 $fieldTypes = array();
951 if (!empty($paymentParams['onbehalf']) &&
952 is_array($paymentParams['onbehalf'])
953 ) {
954 foreach ($paymentParams['onbehalf'] as $key => $value) {
955 if (strstr($key, 'custom_')) {
956 $this->_params[$key] = $value;
957 }
958 }
959 $fieldTypes = array('Contact', 'Organization', 'Contribution');
960 }
961
962 CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams,
963 $premiumParams, $contactID,
964 $contributionTypeId,
965 'contribution',
966 $fieldTypes
967 );
968 }
969 }
970
971 /**
972 * Process the form
973 *
974 * @return void
975 * @access public
976 */
977 public function postProcessPremium($premiumParams, $contribution) {
978 // assigning Premium information to receipt tpl
979 $selectProduct = CRM_Utils_Array::value('selectProduct', $premiumParams);
980 if ($selectProduct &&
981 $selectProduct != 'no_thanks'
982 ) {
983 $startDate = $endDate = "";
984 $this->assign('selectPremium', TRUE);
985 $productDAO = new CRM_Contribute_DAO_Product();
986 $productDAO->id = $selectProduct;
987 $productDAO->find(TRUE);
988 $this->assign('product_name', $productDAO->name);
989 $this->assign('price', $productDAO->price);
990 $this->assign('sku', $productDAO->sku);
991 $this->assign('option', CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams));
992
993 $periodType = $productDAO->period_type;
cde484fd 994
6a488035
TO
995 if ($periodType) {
996 $fixed_period_start_day = $productDAO->fixed_period_start_day;
997 $duration_unit = $productDAO->duration_unit;
998 $duration_interval = $productDAO->duration_interval;
999 if ($periodType == 'rolling') {
1000 $startDate = date('Y-m-d');
1001 }
1002 elseif ($periodType == 'fixed') {
1003 if ($fixed_period_start_day) {
1004 $date = explode('-', date('Y-m-d'));
1005 $month = substr($fixed_period_start_day, 0, strlen($fixed_period_start_day) - 2);
1006 $day = substr($fixed_period_start_day, -2) . "<br>";
1007 $year = $date[0];
1008 $startDate = $year . '-' . $month . '-' . $day;
1009 }
1010 else {
1011 $startDate = date('Y-m-d');
1012 }
1013 }
1014
1015 $date = explode('-', $startDate);
1016 $year = $date[0];
1017 $month = $date[1];
1018 $day = $date[2];
1019
1020 switch ($duration_unit) {
1021 case 'year':
1022 $year = $year + $duration_interval;
1023 break;
1024
1025 case 'month':
1026 $month = $month + $duration_interval;
1027 break;
1028
1029 case 'day':
1030 $day = $day + $duration_interval;
1031 break;
1032
1033 case 'week':
1034 $day = $day + ($duration_interval * 7);
1035 }
1036 $endDate = date('Y-m-d H:i:s', mktime($hour, $minute, $second, $month, $day, $year));
1037 $this->assign('start_date', $startDate);
1038 $this->assign('end_date', $endDate);
1039 }
1040
1041 $dao = new CRM_Contribute_DAO_Premium();
1042 $dao->entity_table = 'civicrm_contribution_page';
1043 $dao->entity_id = $this->_id;
1044 $dao->find(TRUE);
1045 $this->assign('contact_phone', $dao->premiums_contact_phone);
1046 $this->assign('contact_email', $dao->premiums_contact_email);
1047
1048 //create Premium record
1049 $params = array(
1050 'product_id' => $premiumParams['selectProduct'],
1051 'contribution_id' => $contribution->id,
1052 'product_option' => CRM_Utils_Array::value('options_' . $premiumParams['selectProduct'], $premiumParams),
1053 'quantity' => 1,
1054 'start_date' => CRM_Utils_Date::customFormat($startDate, '%Y%m%d'),
1055 'end_date' => CRM_Utils_Date::customFormat($endDate, '%Y%m%d'),
1056 );
1057 if( CRM_Utils_Array::value( 'selectProduct', $premiumParams ) ){
1058 $daoPremiumsProduct = new CRM_Contribute_DAO_PremiumsProduct();
1059 $daoPremiumsProduct->product_id = $premiumParams['selectProduct'];
1060 $daoPremiumsProduct->premiums_id = $dao->id;
1061 $daoPremiumsProduct->find(true);
1062 $params['financial_type_id'] = $daoPremiumsProduct->financial_type_id;
1063 }
1064 //Fixed For CRM-3901
1065 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1066 $daoContrProd->contribution_id = $contribution->id;
1067 if ($daoContrProd->find(TRUE)) {
1068 $params['id'] = $daoContrProd->id;
1069 }
cde484fd 1070
6a488035 1071 CRM_Contribute_BAO_Contribution::addPremium($params);
cde484fd 1072 if ($productDAO->cost && CRM_Utils_Array::value('financial_type_id', $params)) {
6a488035
TO
1073 $trxnParams = array(
1074 'cost' => $productDAO->cost,
1075 'currency' => $productDAO->currency,
1076 'financial_type_id' => $params['financial_type_id'],
1077 'contributionId' => $contribution->id
1078 );
1079 CRM_Core_BAO_FinancialTrxn::createPremiumTrxn($trxnParams);
1080 }
1081 }
1082 elseif ($selectProduct == 'no_thanks') {
1083 //Fixed For CRM-3901
1084 $daoContrProd = new CRM_Contribute_DAO_ContributionProduct();
1085 $daoContrProd->contribution_id = $contribution->id;
1086 if ($daoContrProd->find(TRUE)) {
1087 $daoContrProd->delete();
1088 }
1089 }
1090 }
1091
1092 /**
1093 * Process the contribution
1094 *
1095 * @return CRM_Contribute_DAO_Contribution
1096 * @access public
1097 */
1f1740fe
DL
1098 static function processContribution(
1099 &$form,
6a488035
TO
1100 $params,
1101 $result,
1102 $contactID,
1103 $contributionType,
1104 $deductibleMode = TRUE,
1105 $pending = FALSE,
1106 $online = TRUE
1107 ) {
1108 $transaction = new CRM_Core_Transaction();
1109 $className = get_class($form);
1110 $honorCId = $recurringContributionID = NULL;
1111
1112 if ($online && $form->get('honor_block_is_active')) {
1113 $honorCId = $form->createHonorContact();
1114 }
1115
1116 // add these values for the recurringContrib function ,CRM-10188
1117 $params['financial_type_id'] = $contributionType->id;
e34dd94b 1118 //@todo - this is being set from the form to resolve CRM-10188 - an
1119 // eNotice caused by it not being set @ the front end
1120 // however, we then get it being over-written with null for backend contributions
1121 // a better fix would be to set the values in the respective forms rather than require
1122 // a function being shared by two forms to deal with their respective values
1123 // moving it to the BAO & not taking the $form as a param would make sense here.
1124 if(!isset($params['is_email_receipt'])){
1125 $params['is_email_receipt'] = CRM_Utils_Array::value( 'is_email_receipt', $form->_values );
1126 }
6a488035
TO
1127 $recurringContributionID = self::processRecurringContribution($form, $params, $contactID, $contributionType, $online);
1128
1129 if (!$online && isset($params['honor_contact_id'])) {
1130 $honorCId = $params['honor_contact_id'];
1131 }
1132
1133 $config = CRM_Core_Config::singleton();
1134 // CRM-11885
1135 // if non_deductible_amount exists i.e. Additional Details fieldset was opened [and staff typed something] -> keep it.
1136 if (isset($params['non_deductible_amount']) && (!empty($params['non_deductible_amount']))) {
1137 $nonDeductibleAmount = $params['non_deductible_amount'];
1138 }
1139 // if non_deductible_amount does NOT exist - then calculate it depending on:
1140 // $contributionType->is_deductible and whether there is a product (premium).
1141 else {
1142 //if ($contributionType->is_deductible && $deductibleMode) {
1143 if ($contributionType->is_deductible) {
1144 if ($online && isset($params['selectProduct'])) {
1145 $selectProduct = CRM_Utils_Array::value('selectProduct', $params);
1146 }
1147 if (!$online && isset($params['product_name'][0])) {
1148 $selectProduct = $params['product_name'][0];
1149 }
1150 // if there is a product - compare the value to the contribution amount
1151 if (isset($selectProduct) &&
1152 $selectProduct != 'no_thanks'
1153 ) {
1154 $productDAO = new CRM_Contribute_DAO_Product();
1155 $productDAO->id = $selectProduct;
1156 $productDAO->find(TRUE);
1157 // product value exceeds contribution amount
1158 if ($params['amount'] < $productDAO->price) {
1159 $nonDeductibleAmount = $params['amount'];
1160 }
1161 // product value does NOT exceed contribution amount
1162 else {
1163 $nonDeductibleAmount = $productDAO->price;
1164 }
1165 }
1166 // contribution is deductible - but there is no product
1167 else {
1168 $nonDeductibleAmount = '0.00';
1169 }
1170 }
1171 // contribution is NOT deductible
1172 else {
1173 $nonDeductibleAmount = $params['amount'];
1174 }
1175 }
1176
1177 $now = date('YmdHis');
1178 $receiptDate = CRM_Utils_Array::value('receipt_date', $params);
1179 if (CRM_Utils_Array::value('is_email_receipt', $form->_values)) {
1180 $receiptDate = $now;
1181 }
1182
1183 //get the contrib page id.
1184 $campaignId = $contributionPageId = NULL;
1185 if ($online) {
1186 $contributionPageId = $form->_id;
1187 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1188 if (!array_key_exists('campaign_id', $params)) {
1189 $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
1190 }
1191 }
1192 else {
1193 //also for offline we do support - CRM-7290
1194 $contributionPageId = CRM_Utils_Array::value('contribution_page_id', $params);
1195 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1196 }
1197
1198 // first create the contribution record
1199 $contribParams = array(
1200 'contact_id' => $contactID,
1201 'financial_type_id' => $contributionType->id,
1202 'contribution_page_id' => $contributionPageId,
1203 'receive_date' => (CRM_Utils_Array::value('receive_date', $params)) ? CRM_Utils_Date::processDate($params['receive_date']) : date('YmdHis'),
1204 'non_deductible_amount' => $nonDeductibleAmount,
1205 'total_amount' => $params['amount'],
1206 'amount_level' => CRM_Utils_Array::value('amount_level', $params),
1207 'invoice_id' => $params['invoiceID'],
1208 'currency' => $params['currencyID'],
1209 'source' =>
1210 (!$online || CRM_Utils_Array::value('source', $params)) ?
1211 CRM_Utils_Array::value('source', $params) :
1212 CRM_Utils_Array::value('description', $params),
1213 'is_pay_later' => CRM_Utils_Array::value('is_pay_later', $params, 0),
1214 //configure cancel reason, cancel date and thankyou date
1215 //from 'contribution' type profile if included
1216 'cancel_reason' => CRM_Utils_Array::value('cancel_reason', $params, 0),
1217 'cancel_date' =>
1218 isset($params['cancel_date']) ?
1219 CRM_Utils_Date::format($params['cancel_date']) :
1220 NULL,
1221 'thankyou_date' =>
1222 isset($params['thankyou_date']) ?
1223 CRM_Utils_Date::format($params['thankyou_date']) :
1224 NULL,
1225 'campaign_id' => $campaignId,
1226 );
1227
1228 if (!$online && isset($params['thankyou_date'])) {
1229 $contribParams['thankyou_date'] = $params['thankyou_date'];
1230 }
1231
1232 if (!$online || $form->_values['is_monetary']) {
1233 if (!CRM_Utils_Array::value('is_pay_later', $params)) {
1234 $contribParams['payment_instrument_id'] = 1;
1235 }
1236 }
1237
1238 if (!$pending && $result) {
1239 $contribParams += array(
1240 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result),
1241 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $params['amount']),
1242 'trxn_id' => $result['trxn_id'],
1243 'receipt_date' => $receiptDate,
1244 // also add financial_trxn details as part of fix for CRM-4724
1245 'trxn_result_code' => CRM_Utils_Array::value('trxn_result_code', $result),
1246 'payment_processor' => CRM_Utils_Array::value('payment_processor', $result),
1247 );
1248 }
1249
1250 if (isset($honorCId)) {
1251 $contribParams['honor_contact_id'] = $honorCId;
1252 $contribParams['honor_type_id'] = $params['honor_type_id'];
1253 }
1254
1255 if ($recurringContributionID) {
1256 $contribParams['contribution_recur_id'] = $recurringContributionID;
1257 }
1258
1259 $contribParams['contribution_status_id'] = $pending ? 2 : 1;
1260
1261 $contribParams['is_test'] = 0;
1262 if ($form->_mode == 'test') {
1263 $contribParams['is_test'] = 1;
1264 }
1265
1266 $ids = array();
1267 if (isset($contribParams['invoice_id'])) {
1f1740fe
DL
1268 $contribID = CRM_Core_DAO::getFieldValue(
1269 'CRM_Contribute_DAO_Contribution',
6a488035
TO
1270 $contribParams['invoice_id'],
1271 'id',
1272 'invoice_id'
1273 );
1274 if (isset($contribID)) {
1275 $ids['contribution'] = $contribID;
1276 $contribParams['id'] = $contribID;
1277 }
1278 }
1279
1280
1281 //create an contribution address
1f1740fe
DL
1282 if (
1283 $form->_contributeMode != 'notify' &&
1284 !CRM_Utils_Array::value('is_pay_later', $params) &&
1285 CRM_Utils_Array::value('is_monetary', $form->_values)
6a488035
TO
1286 ) {
1287 $contribParams['address_id'] = CRM_Contribute_BAO_Contribution::createAddress($params, $form->_bltID);
1288 }
1289
1290 // CRM-4038: for non-en_US locales, CRM_Contribute_BAO_Contribution::add() expects localised amounts
1291 $contribParams['non_deductible_amount'] = trim(CRM_Utils_Money::format($contribParams['non_deductible_amount'], ' '));
1292 $contribParams['total_amount'] = trim(CRM_Utils_Money::format($contribParams['total_amount'], ' '));
1293
1294 // Prepare soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1295 if (
1296 CRM_Utils_Array::value('pcp_made_through_id', $params) ||
1297 CRM_Utils_Array::value('soft_credit_to', $params)
1298 ) {
1299 // if its due to pcp
1300 if (CRM_Utils_Array::value('pcp_made_through_id', $params)) {
1301 $contribSoftContactId = CRM_Core_DAO::getFieldValue(
1302 'CRM_PCP_DAO_PCP',
1303 $params['pcp_made_through_id'],
1304 'contact_id'
1305 );
1306 }
1307 else {
1308 $contribSoftContactId = CRM_Utils_Array::value('soft_credit_to', $params);
1309 }
1310
1311 // Pass these details onto with the contribution to make them
1312 // available at hook_post_process, CRM-8908
1313 $contribParams['soft_credit_to'] = $params['soft_credit_to'] = $contribSoftContactId;
1314 }
1315
92acf33d 1316 if (isset($params['amount'])) {
6a488035 1317 $contribParams['line_item'] = $form->_lineItem;
6b79f0fa 1318 //add contribution record
cde484fd 1319 $contribution = CRM_Contribute_BAO_Contribution::add($contribParams, $ids);
9879aeb8
DL
1320 if (is_a($contribution, 'CRM_Core_Error')) {
1321 $message = CRM_Core_Error::getMessages($contribution);
1322 CRM_Core_Error::fatal($message);
1323 }
1f1740fe
DL
1324
1325 // lets store it in the form variable so postProcess hook can get to this and use it
1326 $form->_contributionID = $contribution->id;
6a488035 1327 }
cde484fd 1328
6a488035
TO
1329 // process soft credit / pcp pages
1330 CRM_Contribute_Form_Contribution_Confirm::processPcpSoft($params, $contribution);
cde484fd 1331
6a488035
TO
1332 //handle pledge stuff.
1333 if (
1334 !CRM_Utils_Array::value('separate_membership_payment', $form->_params) &&
1335 CRM_Utils_Array::value('pledge_block_id', $form->_values) &&
1336 (CRM_Utils_Array::value('is_pledge', $form->_params) ||
1337 CRM_Utils_Array::value('pledge_id', $form->_values)
1338 )
1339 ) {
1340
1341 if (CRM_Utils_Array::value('pledge_id', $form->_values)) {
1342
1343 //when user doing pledge payments.
1344 //update the schedule when payment(s) are made
1345 foreach ($form->_params['pledge_amount'] as $paymentId => $dontCare) {
1346 $scheduledAmount = CRM_Core_DAO::getFieldValue(
1347 'CRM_Pledge_DAO_PledgePayment',
1348 $paymentId,
1349 'scheduled_amount',
1350 'id'
1351 );
1352
1353 $pledgePaymentParams = array(
1354 'id' => $paymentId,
1355 'contribution_id' => $contribution->id,
1356 'status_id' => $contribution->contribution_status_id,
1357 'actual_amount' => $scheduledAmount,
1358 );
1359
1360
1361 CRM_Pledge_BAO_PledgePayment::add($pledgePaymentParams);
1362 }
1363
1364 //update pledge status according to the new payment statuses
1365 CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($form->_values['pledge_id']);
1366 }
1367 else {
1368 //when user creating pledge record.
1369 $pledgeParams = array();
1370 $pledgeParams['contact_id'] = $contribution->contact_id;
1371 $pledgeParams['installment_amount'] = $pledgeParams['actual_amount'] = $contribution->total_amount;
1372 $pledgeParams['contribution_id'] = $contribution->id;
1373 $pledgeParams['contribution_page_id'] = $contribution->contribution_page_id;
1374 $pledgeParams['financial_type_id'] = $contribution->financial_type_id;
1375 $pledgeParams['frequency_interval'] = $params['pledge_frequency_interval'];
1376 $pledgeParams['installments'] = $params['pledge_installments'];
1377 $pledgeParams['frequency_unit'] = $params['pledge_frequency_unit'];
1378 if ($pledgeParams['frequency_unit'] == 'month') {
1379 $pledgeParams['frequency_day'] = intval(date("d"));
1380 }
1381 else {
1382 $pledgeParams['frequency_day'] = 1;
1383 }
1384 $pledgeParams['create_date'] = $pledgeParams['start_date'] = $pledgeParams['scheduled_date'] = date("Ymd");
1385 $pledgeParams['status_id'] = $contribution->contribution_status_id;
1386 $pledgeParams['max_reminders'] = $form->_values['max_reminders'];
1387 $pledgeParams['initial_reminder_day'] = $form->_values['initial_reminder_day'];
1388 $pledgeParams['additional_reminder_day'] = $form->_values['additional_reminder_day'];
1389 $pledgeParams['is_test'] = $contribution->is_test;
1390 $pledgeParams['acknowledge_date'] = date('Ymd');
1391 $pledgeParams['original_installment_amount'] = $pledgeParams['installment_amount'];
1392
1393 //inherit campaign from contirb page.
1394 $pledgeParams['campaign_id'] = $campaignId;
1395
1396 $pledge = CRM_Pledge_BAO_Pledge::create($pledgeParams);
1397
1398 $form->_params['pledge_id'] = $pledge->id;
1399
1400 //send acknowledgment email. only when pledge is created
1401 if ($pledge->id) {
1402 //build params to send acknowledgment.
1403 $pledgeParams['id'] = $pledge->id;
1404 $pledgeParams['receipt_from_name'] = $form->_values['receipt_from_name'];
1405 $pledgeParams['receipt_from_email'] = $form->_values['receipt_from_email'];
1406
1407 //scheduled amount will be same as installment_amount.
1408 $pledgeParams['scheduled_amount'] = $pledgeParams['installment_amount'];
1409
1410 //get total pledge amount.
1411 $pledgeParams['total_pledge_amount'] = $pledge->amount;
1412
1413 CRM_Pledge_BAO_Pledge::sendAcknowledgment($form, $pledgeParams);
1414 }
1415 }
1416 }
1417
1418 if ($online && $contribution) {
1419 CRM_Core_BAO_CustomValueTable::postProcess($form->_params,
1420 CRM_Core_DAO::$_nullArray,
1421 'civicrm_contribution',
1422 $contribution->id,
1423 'Contribution'
1424 );
1425 }
1426 elseif ($contribution) {
1427 //handle custom data.
1428 $params['contribution_id'] = $contribution->id;
1429 if (CRM_Utils_Array::value('custom', $params) &&
1430 is_array($params['custom']) &&
1431 !is_a($contribution, 'CRM_Core_Error')
1432 ) {
1433 CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
1434 }
1435 }
1436 // Save note
1437 if ($contribution && !empty($params['contribution_note'])) {
1438 $noteParams = array(
1439 'entity_table' => 'civicrm_contribution',
1440 'note' => $params['contribution_note'],
1441 'entity_id' => $contribution->id,
1442 'contact_id' => $contribution->contact_id,
1443 'modified_date' => date('Ymd'),
1444 );
1445
1446 CRM_Core_BAO_Note::add($noteParams, array());
1447 }
1448
1449
1450 if (isset($params['related_contact'])) {
1451 $contactID = $params['related_contact'];
1452 }
1453 elseif (isset($params['cms_contactID'])) {
1454 $contactID = $params['cms_contactID'];
1455 }
cde484fd 1456
6a488035
TO
1457 //create contribution activity w/ individual and target
1458 //activity w/ organisation contact id when onbelf, CRM-4027
1459 $targetContactID = NULL;
1460 if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) {
1461 $targetContactID = $contribution->contact_id;
1462 $contribution->contact_id = $contactID;
1463 }
1464
1465 // create an activity record
1466 if ($contribution) {
9879aeb8 1467 CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID);
6a488035
TO
1468 }
1469
1470 $transaction->commit();
4ab1a3a3 1471 // CRM-13074 - create the CMSUser after the transaction is completed as it
1472 // is not appropriate to delete a valid contribution if a user create problem occurs
1473 CRM_Contribute_BAO_Contribution_Utils::createCMSUser($params,
1474 $contactID,
1475 'email-' . $form->_bltID
1476 );
6a488035
TO
1477 return $contribution;
1478 }
1479
1480 /**
1481 * Create the recurring contribution record
1482 *
1483 */
cde484fd 1484 static function processRecurringContribution(&$form, &$params, $contactID, $contributionType, $online = TRUE) {
6a488035
TO
1485 // return if this page is not set for recurring
1486 // or the user has not chosen the recurring option
1487
1488 //this is online case validation.
1489 if ((!CRM_Utils_Array::value('is_recur', $form->_values) && $online) ||
1490 !CRM_Utils_Array::value('is_recur', $params)
1491 ) {
1492 return NULL;
1493 }
1494
1495 $recurParams = array();
1496 $config = CRM_Core_Config::singleton();
1497 $recurParams['contact_id'] = $contactID;
1498 $recurParams['amount'] = CRM_Utils_Array::value('amount', $params);
1499 $recurParams['auto_renew'] = CRM_Utils_Array::value('auto_renew', $params);
1500 $recurParams['frequency_unit'] = CRM_Utils_Array::value('frequency_unit', $params);
1501 $recurParams['frequency_interval'] = CRM_Utils_Array::value('frequency_interval', $params);
1502 $recurParams['installments'] = CRM_Utils_Array::value('installments', $params);
1503 $recurParams['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $params);
1504
1505 $recurParams['is_test'] = 0;
1506 if (($form->_action & CRM_Core_Action::PREVIEW) ||
1507 (isset($form->_mode) && ($form->_mode == 'test'))
1508 ) {
1509 $recurParams['is_test'] = 1;
1510 }
1511
1512 $recurParams['start_date'] = $recurParams['create_date'] = $recurParams['modified_date'] = date('YmdHis');
1513 if (CRM_Utils_Array::value('receive_date', $params)) {
1514 $recurParams['start_date'] = $params['receive_date'];
1515 }
1516 $recurParams['invoice_id'] = CRM_Utils_Array::value('invoiceID', $params);
1517 $recurParams['contribution_status_id'] = 2;
1518 $recurParams['payment_processor_id'] = CRM_Utils_Array::value('payment_processor_id', $params);
1519 $recurParams['is_email_receipt'] = CRM_Utils_Array::value('is_email_receipt', $params);
1520 // we need to add a unique trxn_id to avoid a unique key error
1521 // in paypal IPN we reset this when paypal sends us the real trxn id, CRM-2991
1522 $recurParams['trxn_id'] = CRM_Utils_Array::value('trxn_id', $params, $params['invoiceID']);
1523 $recurParams['financial_type_id'] = $contributionType->id;
1524
1525 if (!$online || $form->_values['is_monetary']) {
1526 $recurParams['payment_instrument_id'] = 1;
1527 }
1528
1529 $campaignId = CRM_Utils_Array::value('campaign_id', $params);
1530 if ($online) {
1531 if (!array_key_exists('campaign_id', $params)) {
1532 $campaignId = CRM_Utils_Array::value('campaign_id', $form->_values);
1533 }
1534 }
1535 $recurParams['campaign_id'] = $campaignId;
1536
1537 $recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
1538 if (is_a($recurring, 'CRM_Core_Error')) {
1539 CRM_Core_Error::displaySessionError($result);
1540 $urlString = 'civicrm/contribute/transact';
1541 $urlParams = '_qf_Main_display=true';
1542 if ($className == 'CRM_Contribute_Form_Contribution') {
1543 $urlString = 'civicrm/contact/view/contribution';
1544 $urlParams = "action=add&cid={$form->_contactID}";
1545 if ($form->_mode) {
1546 $urlParams .= "&mode={$form->_mode}";
1547 }
1548 }
1549 CRM_Utils_System::redirect(CRM_Utils_System::url($urlString, $urlParams));
1550 }
1551
1552 return $recurring->id;
1553 }
1554
1555 /**
1556 * Create the Honor contact
1557 *
1558 * @return void
1559 * @access public
1560 */
1561 function createHonorContact() {
1562 $params = $this->controller->exportValues('Main');
1563
1564 // email is enough to create a contact
1565 if (! CRM_Utils_Array::value('honor_email', $params) &&
1566 // or we need first name AND last name
1567 (! CRM_Utils_Array::value('honor_first_name', $params)
1568 || ! CRM_Utils_Array::value('honor_last_name', $params))) {
1569 //don't create contact - possibly the form was left blank
1570 return null;
1571 }
cde484fd 1572
6a488035
TO
1573 //assign to template for email receipt
1574 $honor_block_is_active = $this->get('honor_block_is_active');
cde484fd 1575
6a488035
TO
1576 $this->assign('honor_block_is_active', $honor_block_is_active);
1577 $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
1578
e6c4755b 1579 $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
cbf48754 1580 $honorType = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id');
6a488035
TO
1581 $this->assign('honor_type', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $params), $honorType));
1582 $this->assign('honor_prefix', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_prefix_id', $params), $prefix));
1583 $this->assign('honor_first_name', CRM_Utils_Array::value('honor_first_name', $params));
1584 $this->assign('honor_last_name', CRM_Utils_Array::value('honor_last_name', $params));
1585 $this->assign('honor_email', CRM_Utils_Array::value('honor_email', $params));
1586
1587 //create honoree contact
1588 return CRM_Contribute_BAO_Contribution::createHonorContact($params);
1589 }
1590
1591 /**
1592 * Function to add on behalf of organization and it's location
1593 *
1594 * @param $behalfOrganization array array of organization info
1595 * @param $values array form values array
1596 * @param $contactID int individual contact id. One
1597 * who is doing the process of signup / contribution.
1598 *
1599 * @return void
1600 * @access public
1601 */
1602 static function processOnBehalfOrganization(&$behalfOrganization, &$contactID, &$values, &$params, $fields = NULL) {
1603 $isCurrentEmployer = FALSE;
1604 $orgID = NULL;
1605 if (CRM_Utils_Array::value('organization_id', $behalfOrganization) &&
1606 CRM_Utils_Array::value('org_option', $behalfOrganization)
1607 ) {
1608 $orgID = $behalfOrganization['organization_id'];
1609 unset($behalfOrganization['organization_id']);
1610 $isCurrentEmployer = TRUE;
1611 }
1612
1613 // formalities for creating / editing organization.
1614 $behalfOrganization['contact_type'] = 'Organization';
1615
1616 // get the relationship type id
1617 $relType = new CRM_Contact_DAO_RelationshipType();
1618 $relType->name_a_b = 'Employee of';
1619 $relType->find(TRUE);
1620 $relTypeId = $relType->id;
1621
1622 // keep relationship params ready
1623 $relParams['relationship_type_id'] = $relTypeId . '_a_b';
1624 $relParams['is_permission_a_b'] = 1;
1625 $relParams['is_active'] = 1;
1626
1627 if (!$orgID) {
1628 // check if matching organization contact exists
1629 $dedupeParams = CRM_Dedupe_Finder::formatParams($behalfOrganization, 'Organization');
1630 $dedupeParams['check_permission'] = FALSE;
1631 $dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Unsupervised');
1632
1633 // CRM-6243 says to pick the first org even if more than one match
1634 if (count($dupeIDs) >= 1) {
1635 $behalfOrganization['contact_id'] = $dupeIDs[0];
1636 // don't allow name edit
1637 unset($behalfOrganization['organization_name']);
1638 }
1639 }
1640 else {
1641 // if found permissioned related organization, allow location edit
1642 $behalfOrganization['contact_id'] = $orgID;
1643 // don't allow name edit
1644 unset($behalfOrganization['organization_name']);
1645 }
1646
1647 // handling for image url
1648 if (CRM_Utils_Array::value('image_URL', $behalfOrganization)) {
1649 CRM_Contact_BAO_Contact::processImageParams($behalfOrganization);
1650 }
1651
1652 // create organization, add location
1653 $orgID = CRM_Contact_BAO_Contact::createProfileContact($behalfOrganization, $fields, $orgID,
1654 NULL, NULL, 'Organization'
1655 );
1656 // create relationship
1657 $relParams['contact_check'][$orgID] = 1;
1658 $cid = array('contact' => $contactID);
1659 CRM_Contact_BAO_Relationship::create($relParams, $cid);
1660
1661 // if multiple match - send a duplicate alert
1662 if ($dupeIDs && (count($dupeIDs) > 1)) {
1663 $values['onbehalf_dupe_alert'] = 1;
1664 // required for IPN
1665 $params['onbehalf_dupe_alert'] = 1;
1666 }
1667
1668 // make sure organization-contact-id is considered for recording
1669 // contribution/membership etc..
1670 if ($contactID != $orgID) {
1671 // take a note of contact-id, so we can send the
1672 // receipt to individual contact as well.
1673
1674 // required for mailing/template display ..etc
1675 $values['related_contact'] = $contactID;
1676 // required for IPN
1677 $params['related_contact'] = $contactID;
1678
1679 //make this employee of relationship as current
1680 //employer / employee relationship, CRM-3532
1681 if ($isCurrentEmployer &&
1682 ($orgID != CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id'))
1683 ) {
1684 $isCurrentEmployer = FALSE;
1685 }
1686
1687 if (!$isCurrentEmployer && $orgID) {
1688 //build current employer params
1689 $currentEmpParams[$contactID] = $orgID;
1690 CRM_Contact_BAO_Contact_Utils::setCurrentEmployer($currentEmpParams);
1691 }
1692
1693 // contribution / signup will be done using this
1694 // organization id.
1695 $contactID = $orgID;
1696 }
1697 }
1698
1699 /**
1700 * Function used to save pcp / soft credit entry
1701 * This is used by contribution and also event pcps
1702 *
1703 * @param array $params associated array
1704 * @param object $contribution contribution object
1705 *
1706 * @static
1707 * @access public
1708 */
1709 static function processPcpSoft(&$params, &$contribution) {
1710 //add soft contribution due to pcp or Submit Credit / Debit Card Contribution by admin.
1711 if (CRM_Utils_Array::value('soft_credit_to', $params)) {
1712 $contribSoftParams = array();
1713 foreach (array(
1714 'pcp_display_in_roll', 'pcp_roll_nickname', 'pcp_personal_note', 'amount') as $val) {
1715 if (CRM_Utils_Array::value($val, $params)) {
1716 $contribSoftParams[$val] = $params[$val];
1717 }
1718 }
1719
1720 $contribSoftParams['contact_id'] = $params['soft_credit_to'];
1721 // add contribution id
1722 $contribSoftParams['contribution_id'] = $contribution->id;
1723 // add pcp id
1724 $contribSoftParams['pcp_id'] = $params['pcp_made_through_id'];
1725
6dcc4d9d 1726 $softContribution = CRM_Contribute_BAO_ContributionSoft::add($contribSoftParams);
6a488035
TO
1727 }
1728 }
1729
1730 /**
1731 * Function used to se pcp related defaults / params
1732 * This is used by contribution and also event pcps
1733 *
1734 * @param object $page form object
1735 * @param array $params associated array
1736 *
1737 * @static
1738 * @access public
1739 */
1740 static function processPcp(&$page, $params) {
1741 $params['pcp_made_through_id'] = $page->_pcpInfo['pcp_id'];
1742 $page->assign('pcpBlock', TRUE);
1743 if (CRM_Utils_Array::value('pcp_display_in_roll', $params) &&
1744 !CRM_Utils_Array::value('pcp_roll_nickname', $params)
1745 ) {
1746 $params['pcp_roll_nickname'] = ts('Anonymous');
1747 $params['pcp_is_anonymous'] = 1;
1748 }
1749 else {
1750 $params['pcp_is_anonymous'] = 0;
1751 }
1752 foreach (array(
1753 'pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) {
1754 if (CRM_Utils_Array::value($val, $params)) {
1755 $page->assign($val, $params[$val]);
1756 }
1757 }
1758
1759 return $params;
1760 }
1761}