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