Merge pull request #15413 from eileenmcnaughton/default_sub_type
[civicrm-core.git] / CRM / Pledge / Form / Pledge.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
35 * This class generates form components for processing a pledge
6a488035
TO
36 */
37class CRM_Pledge_Form_Pledge extends CRM_Core_Form {
38 public $_action;
39
40 /**
fe482240 41 * The id of the pledge that we are proceessing.
6a488035
TO
42 *
43 * @var int
6a488035
TO
44 */
45 public $_id;
46
47 /**
fe482240 48 * The id of the contact associated with this pledge.
6a488035
TO
49 *
50 * @var int
6a488035
TO
51 */
52 public $_contactID;
53
54 /**
fe482240 55 * The Pledge values if an existing pledge.
c86d4e7c 56 * @var array
6a488035
TO
57 */
58 public $_values;
59
6a488035 60 /**
fe482240 61 * The Pledge frequency Units.
c86d4e7c 62 * @var array
6a488035
TO
63 */
64 public $_freqUnits;
65
66 /**
100fef9d 67 * Is current pledge pending.
c86d4e7c 68 * @var bool
6a488035
TO
69 */
70 public $_isPending = FALSE;
71
72 /**
fe482240 73 * Set variables up before form is built.
6a488035
TO
74 */
75 public function preProcess() {
76 $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
77 $this->_action = CRM_Utils_Request::retrieve('action', 'String',
78 $this, FALSE, 'add'
79 );
80 $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
edc80cda 81 $this->_context = CRM_Utils_Request::retrieve('context', 'Alphanumeric', $this);
6a488035
TO
82
83 // check for action permissions.
84 if (!CRM_Core_Permission::checkActionPermission('CiviPledge', $this->_action)) {
0499b0ad 85 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
6a488035
TO
86 }
87
88 $this->assign('action', $this->_action);
89 $this->assign('context', $this->_context);
90 if ($this->_action & CRM_Core_Action::DELETE) {
91 return;
92 }
93
94 $this->userDisplayName = $this->userEmail = NULL;
95 if ($this->_contactID) {
96 list($this->userDisplayName,
97 $this->userEmail
353ffa53 98 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
6a488035 99 $this->assign('displayName', $this->userDisplayName);
6a488035
TO
100 }
101
e2046b33
CW
102 $this->setPageTitle(ts('Pledge'));
103
cc28438b 104 // build custom data
6a488035 105 CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Pledge', $this->_id);
be2fb01f 106 $this->_values = [];
6a488035
TO
107 // current pledge id
108 if ($this->_id) {
cc28438b 109 // get the contribution id
6a488035
TO
110 $this->_contributionID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
111 $this->_id, 'contribution_id', 'pledge_id'
112 );
be2fb01f 113 $params = ['id' => $this->_id];
6a488035
TO
114 CRM_Pledge_BAO_Pledge::getValues($params, $this->_values);
115
8cbef457 116 $this->_isPending = (CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($this->_id, CRM_Utils_Array::value('status_id', $this->_values))) ? FALSE : TRUE;
6a488035
TO
117 }
118
cc28438b 119 // get the pledge frequency units.
6a488035
TO
120 $this->_freqUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
121
122 $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
123 }
124
125 /**
c490a46a 126 * Set default values for the form.
cc28438b 127 * The default values are retrieved from the database.
6a488035 128 */
00be9182 129 public function setDefaultValues() {
6a488035
TO
130 $defaults = $this->_values;
131
6a488035
TO
132 if ($this->_action & CRM_Core_Action::DELETE) {
133 return $defaults;
134 }
135
a7488080 136 if (!empty($defaults['is_test'])) {
6a488035
TO
137 $this->assign('is_test', TRUE);
138 }
139
140 if ($this->_id) {
cc28438b
SB
141 // check is this pledge pending.
142 // fix the display of the monetary value, CRM-4038.
6a488035
TO
143 if ($this->_isPending) {
144 $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments'];
145 $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], NULL, '%a');
146 }
09edd4bd 147
6a488035
TO
148 // fix the display of the monetary value, CRM-4038
149 if (isset($this->_values['amount'])) {
150 $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], NULL, '%a');
151 }
152 $this->assign('amount', $this->_values['amount']);
153 $this->assign('installments', $defaults['installments']);
154 }
155 else {
cc28438b 156 // default values.
09edd4bd
CW
157 $defaults['create_date'] = date('Y-m-d');
158 $defaults['start_date'] = date('Y-m-d');
6a488035
TO
159 $defaults['installments'] = 12;
160 $defaults['frequency_interval'] = 1;
161 $defaults['frequency_day'] = 1;
162 $defaults['initial_reminder_day'] = 5;
163 $defaults['max_reminders'] = 1;
164 $defaults['additional_reminder_day'] = 5;
165 $defaults['frequency_unit'] = array_search('month', $this->_freqUnits);
353ffa53 166 $defaults['financial_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::financialType());
6a488035
TO
167 }
168
ab6ba136 169 $pledgeStatus = CRM_Pledge_BAO_Pledge::buildOptions('status_id');
01dac399 170 $pledgeStatusNames = CRM_Core_OptionGroup::values('pledge_status',
6a488035
TO
171 FALSE, FALSE, FALSE, NULL, 'name', TRUE
172 );
173 // get default status label (pending)
174 $defaultPledgeStatus = CRM_Utils_Array::value(array_search('Pending', $pledgeStatusNames),
175 $pledgeStatus
176 );
177
cc28438b 178 // assign status.
6a488035 179 $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values),
353ffa53
TO
180 $pledgeStatus,
181 $defaultPledgeStatus
182 ));
6a488035 183
6a488035
TO
184 if (isset($this->userEmail)) {
185 $this->assign('email', $this->userEmail);
186 }
187
188 // custom data set defaults
189 $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this);
190
191 return $defaults;
192 }
193
194 /**
fe482240 195 * Build the form object.
6a488035
TO
196 */
197 public function buildQuickForm() {
198 if ($this->_action & CRM_Core_Action::DELETE) {
be2fb01f
CW
199 $this->addButtons([
200 [
6a488035
TO
201 'type' => 'next',
202 'name' => ts('Delete'),
203 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
204 'isDefault' => TRUE,
be2fb01f
CW
205 ],
206 [
6a488035
TO
207 'type' => 'cancel',
208 'name' => ts('Cancel'),
be2fb01f 209 ],
c86d4e7c 210 ]);
6a488035
TO
211 return;
212 }
213
214 if ($this->_context == 'standalone') {
be2fb01f 215 $this->addEntityRef('contact_id', ts('Contact'), [
c86d4e7c
SL
216 'create' => TRUE,
217 'api' => ['extra' => ['email']],
218 ], TRUE);
6a488035
TO
219 }
220
221 $showAdditionalInfo = FALSE;
222 $this->_formType = CRM_Utils_Array::value('formType', $_GET);
223
be2fb01f 224 $defaults = [];
6a488035 225
be2fb01f 226 $paneNames = [
6a488035 227 'Payment Reminders' => 'PaymentReminders',
be2fb01f 228 ];
6a488035
TO
229 foreach ($paneNames as $name => $type) {
230 $urlParams = "snippet=4&formType={$type}";
be2fb01f 231 $allPanes[$name] = [
353ffa53 232 'url' => CRM_Utils_System::url('civicrm/contact/view/pledge', $urlParams),
6a488035
TO
233 'open' => 'false',
234 'id' => $type,
be2fb01f 235 ];
cc28438b 236 // see if we need to include this paneName in the current form
8cc574cf 237 if ($this->_formType == $type || !empty($_POST["hidden_{$type}"]) ||
6a488035
TO
238 CRM_Utils_Array::value("hidden_{$type}", $defaults)
239 ) {
240 $showAdditionalInfo = TRUE;
241 $allPanes[$name]['open'] = 'true';
242 }
0e6e8724
DL
243 $fnName = "build{$type}";
244 CRM_Contribute_Form_AdditionalInfo::$fnName($this);
6a488035
TO
245 }
246
247 $this->assign('allPanes', $allPanes);
248 $this->assign('showAdditionalInfo', $showAdditionalInfo);
249
250 if ($this->_formType) {
251 $this->assign('formType', $this->_formType);
252 return;
253 }
254
255 $this->applyFilter('__ALL__', 'trim');
256
cc28438b 257 // pledge fields.
6a488035
TO
258 $attributes = CRM_Core_DAO::getAttribute('CRM_Pledge_DAO_Pledge');
259
260 $this->assign('isPending', $this->_isPending);
261
be2fb01f 262 $js = [
6a488035
TO
263 'onblur' => "calculatedPaymentAmount( );",
264 'onkeyup' => "calculatedPaymentAmount( );",
be2fb01f 265 ];
6a488035 266
09edd4bd 267 $amount = $this->addMoney('amount', ts('Total Pledge Amount'), TRUE,
6a488035 268 array_merge($attributes['pledge_amount'], $js), TRUE,
09edd4bd 269 'currency', NULL, $this->_id && !$this->_isPending
6a488035
TO
270 );
271
09edd4bd 272 $installments = &$this->add('text', 'installments', ts('To be paid in'),
6a488035
TO
273 array_merge($attributes['installments'], $js), TRUE
274 );
275 $this->addRule('installments', ts('Please enter a valid number of installments.'), 'positiveInteger');
6a488035 276
d70ada2a 277 $frequencyInterval = $this->add('number', 'frequency_interval', ts('every'),
6a488035
TO
278 $attributes['pledge_frequency_interval'], TRUE
279 );
280 $this->addRule('frequency_interval', ts('Please enter a number for frequency (e.g. every "3" months).'), 'positiveInteger');
6a488035
TO
281
282 // Fix frequency unit display for use with frequency_interval
be2fb01f 283 $freqUnitsDisplay = [];
6a488035 284 foreach ($this->_freqUnits as $val => $label) {
be2fb01f 285 $freqUnitsDisplay[$val] = ts('%1(s)', [1 => $label]);
6a488035 286 }
09edd4bd 287 $frequencyUnit = $this->add('select', 'frequency_unit',
6a488035 288 ts('Frequency'),
be2fb01f 289 ['' => ts('- select -')] + $freqUnitsDisplay,
6a488035
TO
290 TRUE
291 );
292
d70ada2a 293 $frequencyDay = $this->add('number', 'frequency_day', ts('Payments are due on the'), $attributes['frequency_day'], TRUE);
6a488035 294 $this->addRule('frequency_day', ts('Please enter a valid payment due day.'), 'positiveInteger');
6a488035 295
be2fb01f 296 $this->add('text', 'eachPaymentAmount', ts('each'), [
c86d4e7c
SL
297 'size' => 10,
298 'style' => "background-color:#EBECE4",
299 // WTF, preserved because its inexplicable
300 0 => 'READONLY',
301 ]);
6a488035 302
cc28438b 303 // add various dates
09edd4bd
CW
304 $createDate = $this->add('datepicker', 'create_date', ts('Pledge Made'), [], TRUE, ['time' => FALSE]);
305 $startDate = $this->add('datepicker', 'start_date', ts('Payments Start'), [], TRUE, ['time' => FALSE]);
6a488035 306
1fb7bdc9 307 if (!empty($this->_values['currency'])) {
308 $this->assign('currency', $this->_values['currency']);
309 }
025cf9a2 310 elseif (!empty($this->_submitValues['currency'])) {
311 $this->assign('currency', $this->_submitValues['currency']);
312 }
1fb7bdc9 313
09edd4bd
CW
314 if ($this->_id && !$this->_isPending) {
315 $amount->freeze();
316 $installments->freeze();
317 $createDate->freeze();
318 $startDate->freeze();
319 $frequencyInterval->freeze();
320 $frequencyUnit->freeze();
321 $frequencyDay->freeze();
6a488035 322 $eachPaymentAmount = $this->_values['original_installment_amount'];
6a488035 323 $this->assign('eachPaymentAmount', $eachPaymentAmount);
6a488035
TO
324 }
325
326 if (CRM_Utils_Array::value('status_id', $this->_values) !=
ab6ba136 327 CRM_Core_PseudoConstant::getKey('CRM_Pledge_BAO_Pledge', 'status_id', 'Cancelled')
6a488035
TO
328 ) {
329
330 $this->addElement('checkbox', 'is_acknowledge', ts('Send Acknowledgment?'), NULL,
be2fb01f 331 ['onclick' => "showHideByValue( 'is_acknowledge', '', 'acknowledgeDate', 'table-row', 'radio', true); showHideByValue( 'is_acknowledge', '', 'fromEmail', 'table-row', 'radio', false );"]
6a488035
TO
332 );
333
334 $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
335 }
336
09edd4bd 337 $this->add('datepicker', 'acknowledge_date', ts('Acknowledgment Date'), [], FALSE, ['time' => FALSE]);
6a488035 338
098201d8 339 $this->add('select', 'financial_type_id',
353ffa53 340 ts('Financial Type'),
be2fb01f 341 ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::financialType(),
6a488035
TO
342 TRUE
343 );
344
cc28438b 345 // CRM-7362 --add campaigns.
6a488035
TO
346 CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
347
be2fb01f 348 $pageIds = [];
6a488035 349 CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgeBlock', 'entity_table',
be2fb01f 350 'civicrm_contribution_page', $pageIds, ['entity_id']
6a488035
TO
351 );
352 $pages = CRM_Contribute_PseudoConstant::contributionPage();
be2fb01f 353 $pledgePages = [];
6a488035
TO
354 foreach ($pageIds as $key => $value) {
355 $pledgePages[$value['entity_id']] = $pages[$value['entity_id']];
356 }
09edd4bd 357 $this->add('select', 'contribution_page_id', ts('Self-service Payments Page'),
be2fb01f 358 ['' => ts('- select -')] + $pledgePages
6a488035
TO
359 );
360
aaffa79f 361 $mailingInfo = Civi::settings()->get('mailing_backend');
6a488035
TO
362 $this->assign('outBound_option', $mailingInfo['outBound_option']);
363
cc28438b 364 // build custom data
6a488035
TO
365 CRM_Custom_Form_CustomData::buildQuickForm($this);
366
367 // make this form an upload since we dont know if the custom data injected dynamically
368 // is of type file etc $uploadNames = $this->get( 'uploadNames' );
be2fb01f
CW
369 $this->addButtons([
370 [
6a488035
TO
371 'type' => 'upload',
372 'name' => ts('Save'),
be2fb01f 373 'js' => ['onclick' => "return verify( );"],
6a488035 374 'isDefault' => TRUE,
be2fb01f
CW
375 ],
376 [
6a488035
TO
377 'type' => 'upload',
378 'name' => ts('Save and New'),
be2fb01f 379 'js' => ['onclick' => "return verify( );"],
6a488035 380 'subName' => 'new',
be2fb01f
CW
381 ],
382 [
6a488035
TO
383 'type' => 'cancel',
384 'name' => ts('Cancel'),
be2fb01f 385 ],
c86d4e7c 386 ]);
6a488035 387
be2fb01f 388 $this->addFormRule(['CRM_Pledge_Form_Pledge', 'formRule'], $this);
6a488035
TO
389
390 if ($this->_action & CRM_Core_Action::VIEW) {
391 $this->freeze();
392 }
393 }
394
395 /**
fe482240 396 * Global form rule.
6a488035 397 *
3a1617b6
TO
398 * @param array $fields
399 * The input form values.
400 * @param array $files
401 * The uploaded files if any.
2a6da8d7
EM
402 * @param $self
403 *
6a488035 404 *
72b3a70c
CW
405 * @return bool|array
406 * true if no errors, else array of errors
6a488035 407 */
00be9182 408 public static function formRule($fields, $files, $self) {
be2fb01f 409 $errors = [];
6a488035 410
6a488035
TO
411 if ($fields['amount'] <= 0) {
412 $errors['amount'] = ts('Total Pledge Amount should be greater than zero.');
413 }
414 if ($fields['installments'] <= 0) {
415 $errors['installments'] = ts('Installments should be greater than zero.');
416 }
417
418 if ($fields['frequency_unit'] != 'week') {
419 if ($fields['frequency_day'] > 31 || $fields['frequency_day'] == 0) {
420 $errors['frequency_day'] = ts('Please enter a valid frequency day ie. 1 through 31.');
421 }
422 }
423 elseif ($fields['frequency_unit'] == 'week') {
424 if ($fields['frequency_day'] > 7 || $fields['frequency_day'] == 0) {
425 $errors['frequency_day'] = ts('Please enter a valid frequency day ie. 1 through 7.');
426 }
427 }
428 return $errors;
429 }
430
431 /**
fe482240 432 * Process the form submission.
6a488035
TO
433 */
434 public function postProcess() {
435 if ($this->_action & CRM_Core_Action::DELETE) {
436 CRM_Pledge_BAO_Pledge::deletePledge($this->_id);
437 return;
438 }
439
cc28438b 440 // get the submitted form values.
6a488035
TO
441 $formValues = $this->controller->exportValues($this->_name);
442
443 // set the contact, when contact is selected
b9aa8f56
CW
444 if (!empty($formValues['contact_id'])) {
445 $this->_contactID = $formValues['contact_id'];
6a488035
TO
446 }
447
6a488035
TO
448 $session = CRM_Core_Session::singleton();
449
be2fb01f 450 $fields = [
6a488035
TO
451 'frequency_unit',
452 'frequency_interval',
453 'frequency_day',
454 'installments',
b9aa8f56 455 'financial_type_id',
6a488035
TO
456 'initial_reminder_day',
457 'max_reminders',
458 'additional_reminder_day',
6a488035
TO
459 'contribution_page_id',
460 'campaign_id',
be2fb01f 461 ];
6a488035
TO
462 foreach ($fields as $f) {
463 $params[$f] = CRM_Utils_Array::value($f, $formValues);
464 }
465
cc28438b 466 // format amount
6a488035
TO
467 $params['amount'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('amount', $formValues));
468 $params['currency'] = CRM_Utils_Array::value('currency', $formValues);
469 $params['original_installment_amount'] = ($params['amount'] / $params['installments']);
470
be2fb01f 471 $dates = ['create_date', 'start_date', 'acknowledge_date', 'cancel_date'];
6a488035 472 foreach ($dates as $d) {
8cc574cf 473 if ($this->_id && (!$this->_isPending) && !empty($this->_values[$d])) {
6a488035
TO
474 if ($d == 'start_date') {
475 $params['scheduled_date'] = CRM_Utils_Date::processDate($this->_values[$d]);
476 }
477 $params[$d] = CRM_Utils_Date::processDate($this->_values[$d]);
478 }
a7488080 479 elseif (!empty($formValues[$d]) && !CRM_Utils_System::isNull($formValues[$d])) {
6a488035
TO
480 if ($d == 'start_date') {
481 $params['scheduled_date'] = CRM_Utils_Date::processDate($formValues[$d]);
482 }
483 $params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
484 }
485 else {
486 $params[$d] = 'null';
487 }
488 }
489
a7488080 490 if (!empty($formValues['is_acknowledge'])) {
6a488035
TO
491 $params['acknowledge_date'] = date('Y-m-d');
492 }
493
494 // assign id only in update mode
495 if ($this->_action & CRM_Core_Action::UPDATE) {
496 $params['id'] = $this->_id;
497 }
498
499 $params['contact_id'] = $this->_contactID;
500
cc28438b 501 // format custom data
a7488080 502 if (!empty($formValues['hidden_custom'])) {
6a488035
TO
503 $params['hidden_custom'] = 1;
504
505 $customFields = CRM_Core_BAO_CustomField::getFields('Pledge');
506 $params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues,
6a488035
TO
507 $this->_id,
508 'Pledge'
509 );
510 }
511
cc28438b 512 // handle pending pledge.
6a488035
TO
513 $params['is_pledge_pending'] = $this->_isPending;
514
cc28438b 515 // create pledge record.
6a488035
TO
516 $pledge = CRM_Pledge_BAO_Pledge::create($params);
517
518 $statusMsg = NULL;
519
520 if ($pledge->id) {
cc28438b 521 // set the status msg.
6a488035
TO
522 if ($this->_action & CRM_Core_Action::ADD) {
523 $statusMsg = ts('Pledge has been recorded and the payment schedule has been created.<br />');
524 }
525 elseif ($this->_action & CRM_Core_Action::UPDATE) {
526 $statusMsg = ts('Pledge has been updated.<br />');
527 }
528 }
529
cc28438b 530 // handle Acknowledgment.
a7488080 531 if (!empty($formValues['is_acknowledge']) && $pledge->id) {
6a488035 532
cc28438b 533 // calculate scheduled amount.
6a488035
TO
534 $params['scheduled_amount'] = round($params['amount'] / $params['installments']);
535 $params['total_pledge_amount'] = $params['amount'];
cc28438b 536 // get some required pledge values in params.
6a488035
TO
537 $params['id'] = $pledge->id;
538 $params['acknowledge_date'] = $pledge->acknowledge_date;
539 $params['is_test'] = $pledge->is_test;
540 $params['currency'] = $pledge->currency;
541 // retrieve 'from email id' for acknowledgement
542 $params['from_email_id'] = $formValues['from_email_address'];
543
544 $this->paymentId = NULL;
cc28438b 545 // send Acknowledgment mail.
6a488035
TO
546 CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params);
547
548 if (!isset($this->userEmail)) {
549 list($this->userDisplayName,
550 $this->userEmail
353ffa53 551 ) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
6a488035
TO
552 }
553
be2fb01f 554 $statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", [1 => $this->userEmail]);
6a488035 555
cc28438b 556 // build the payment urls.
6a488035
TO
557 if ($this->paymentId) {
558 $urlParams = "reset=1&action=add&cid={$this->_contactID}&ppid={$this->paymentId}&context=pledge";
559 $contribURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
560 $urlParams .= "&mode=live";
561 $creditURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
562
cc28438b 563 // check if we can process credit card payment.
6a488035
TO
564 $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE,
565 "billing_mode IN ( 1, 3 )"
566 );
567 if (count($processors) > 0) {
be2fb01f 568 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a> OR <a href='%2'>submit a credit card payment</a>.", [
c86d4e7c
SL
569 1 => $contribURL,
570 2 => $creditURL,
571 ]);
6a488035
TO
572 }
573 else {
be2fb01f 574 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a>.", [1 => $contribURL]);
6a488035
TO
575 }
576 }
577 }
578 CRM_Core_Session::setStatus($statusMsg, ts('Payment Due'), 'info');
579
580 $buttonName = $this->controller->getButtonName();
581 if ($this->_context == 'standalone') {
582 if ($buttonName == $this->getButtonName('upload', 'new')) {
583 $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/add',
353ffa53
TO
584 'reset=1&action=add&context=standalone'
585 ));
6a488035
TO
586 }
587 else {
588 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view',
353ffa53
TO
589 "reset=1&cid={$this->_contactID}&selectedChild=pledge"
590 ));
6a488035
TO
591 }
592 }
593 elseif ($buttonName == $this->getButtonName('upload', 'new')) {
594 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/pledge',
353ffa53
TO
595 "reset=1&action=add&context=pledge&cid={$this->_contactID}"
596 ));
6a488035
TO
597 }
598 }
96025800 599
6a488035 600}