/** * Add payment fields are depending on payment type * * @param int $type eg CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT * @param CRM_Core_Form $form */ public static function setPaymentFieldsByType($type, &$form) { if ($type & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($form); } else { CRM_Core_Payment_Form::setCreditCardFields($form); } }
static function preProcess(&$form, $type = NULL, $mode = NULL) { if ($type) { $form->_type = $type; } else { $form->_type = CRM_Utils_Request::retrieve('type', 'String', $form); } if ($form->_type) { $form->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($form->_type, $form->_mode); } //$form->_paymentProcessor['processorName'] = $form->_paymentObject->_processorName; $form->set('paymentProcessor', $form->_paymentProcessor); // also set cancel subscription url if (CRM_Utils_Array::value('is_recur', $form->_paymentProcessor) && CRM_Utils_Array::value('is_recur', $form->_values)) { $form->_paymentObject =& CRM_Core_Payment::singleton($mode, $form->_paymentProcessor, $form); $form->_values['cancelSubscriptionUrl'] = $form->_paymentObject->subscriptionURL(); } //checks after setting $form->_paymentProcessor // we do this outside of the above conditional to avoid // saving the country/state list in the session (which could be huge) if ($form->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM && CRM_Utils_Array::value('is_monetary', $form->_values)) { if ($form->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($form); } else { CRM_Core_Payment_Form::setCreditCardFields($form); } } $form->assign_by_ref('paymentProcessor', $form->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly if (CRM_Core_Payment::paypalRedirect($form->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$form->controller->_key}"); CRM_Utils_System::redirect($url); } // make sure we have a valid payment class, else abort if (CRM_Utils_Array::value('is_monetary', $form->_values) && !$form->_paymentProcessor['class_name'] && !CRM_Utils_Array::value('is_pay_later', $form->_values)) { CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); } if (!empty($form->_membershipBlock) && CRM_Utils_Array::value('is_separate_payment', $form->_membershipBlock) && (CRM_Utils_Array::value('class_name', $form->_paymentProcessor) && !(CRM_Utils_Array::value('billing_mode', $form->_paymentProcessor) & CRM_Core_Payment::BILLING_MODE_FORM))) { CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments, or the option to "Execute real-time monetary transactions" is disabled. Please contact the site administrator and notify them of this error', array(1 => $form->_paymentProcessor['payment_processor_type']))); } $profileAddressFields = $form->get('profileAddressFields'); if (!empty($profileAddressFields)) { $form->assign('profileAddressFields', $profileAddressFields); } }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // current contribution page id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if (!$this->_id) { $pastContributionID = $session->get('pastContributionID'); if (!$pastContributionID) { CRM_Core_Error::fatal(ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.')); } else { CRM_Core_Error::fatal(ts('This contribution has already been submitted. Click <a href=\'%1\'>here</a> if you want to make another contribution.', array(1 => CRM_Utils_System::url('civicrm/contribute/transact', 'reset=1&id=' . $pastContributionID)))); } } else { $session->set('pastContributionID', $this->_id); } $this->_userID = $session->get('userID'); $this->_mid = null; if ($this->_userID) { $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this); if ($this->_mid) { require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_mid; if ($membership->find(true)) { $this->_defaultMemTypeId = $membership->membership_type_id; if ($membership->contact_id != $this->_userID) { require_once 'CRM/Contact/BAO/Relationship.php'; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID); if (array_key_exists($membership->contact_id, $employers)) { $this->_membershipContactID = $membership->contact_id; $this->assign('membershipContactID', $this->_membershipContactID); $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']); } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } } } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } unset($membership); } } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', false); // Contribution page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', true); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); if (!$this->_values) { // get all the values from the dao object $this->_values = array(); $this->_fields = array(); require_once 'CRM/Contribute/BAO/ContributionPage.php'; CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); // check if form is active if (!$this->_values['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } // also check for billing informatin // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values); $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values); if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values))) { $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values); if (!$ppID) { CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).')); } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); // check selected payment processor is active if (empty($this->_paymentProcessor)) { CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).')); } // ensure that processor has a valid config $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); $error = $this->_paymentObject->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } $this->_paymentProcessor['processorName'] = $this->_paymentObject->_processorName; $this->set('paymentProcessor', $this->_paymentProcessor); } // get price info // CRM-5095 require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text'); foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = null; } } //check if Membership Block is enabled, if Membership Fields are included in profile //get membership section for this contribution page require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $this->set('membershipBlock', $this->_membershipBlock); require_once "CRM/Core/BAO/UFField.php"; if ($this->_values['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']); } if ($this->_values['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']); } // also set cancel subscription url if (CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) && CRM_Utils_Array::value('is_recur', $this->_values)) { $this->_values['cancelSubscriptionUrl'] = $this->_paymentObject->cancelSubscriptionURL(); } if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) { CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.')); } require_once 'CRM/Pledge/BAO/PledgeBlock.php'; $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if ($pledgeBlock) { $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock); $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock); $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock); $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock); //set pledge id in values $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); //authenticate pledge user for pledge payment. if ($pledgeId) { $this->_values['pledge_id'] = $pledgeId; self::authenticatePledgeUser(); } } $this->set('values', $this->_values); $this->set('fields', $this->_fields); } require_once 'CRM/Contribute/BAO/PCP.php'; $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { require_once 'CRM/Core/OptionGroup.php'; $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); $prms = array('entity_id' => $this->_values['id'], 'entity_table' => 'civicrm_contribution_page'); require_once 'CRM/Contribute/PseudoConstant.php'; $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus(); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $prms, $pcpBlock); $prms = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo); //start and end date of the contribution page $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $this->_values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $this->_values)); $now = time(); if ($pcpInfo['contribution_page_id'] != $this->_values['id']) { $statusMessage = ts('This contribution page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$this->_values['id']}", false, null, false, true)); } else { if ($pcpInfo['status_id'] != $approvedId) { $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign by making a contribution here.', array(1 => $pcpStatus[$pcpInfo['status_id']])); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpBlock)) { $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign by making a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpInfo)) { $statusMessage = ts('The Personal Campaign Page you have just visited is current inactive. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate && $startDate > $now || $endDate && $endDate < $now) { $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $this->_values)); $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $this->_values)); if ($startDate && $endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is only active between %1 to %2. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate, 2 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate) { $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is not longer active (as of %1). However you can still support the campaign by making a contribution here.', array(1 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } } } } } } } } $this->_pcpId = $pcpId; $this->_pcpBlock = $pcpBlock; $this->_pcpInfo = $pcpInfo; } // Link (button) for users to create their own Personal Campaign page if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($this->_id)) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}", false, null, true); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } //set pledge block if block id is set if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { $this->assign('pledgeBlock', true); } // we do this outside of the above conditional to avoid // saving the country/state list in the session (which could be huge) if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM && CRM_Utils_Array::value('is_monetary', $this->_values)) { require_once 'CRM/Core/Payment/Form.php'; require_once 'CRM/Core/Payment.php'; // payment fields are depending on payment type if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($this); } else { CRM_Core_Payment_Form::setCreditCardFields($this); } } $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } // make sure we have a valid payment class, else abort if (CRM_Utils_Array::value('is_monetary', $this->_values) && !$this->_paymentProcessor['class_name'] && !CRM_Utils_Array::value('is_pay_later', $this->_values)) { CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); } // check if one of the (amount , membership) bloks is active or not require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = $this->get('membershipBlock'); if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) { CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.')); } if ($this->_values['amount_block_is_active']) { $this->set('amount_block_is_active', $this->_values['amount_block_is_active']); } if (!empty($this->_membershipBlock) && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) { CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments. Please contact the site administrator and notify them of this error', array(1 => $this->_paymentProcessor['payment_processor_type']))); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); //assigning is_monetary and is_email_receipt to template $this->assign('is_monetary', $this->_values['is_monetary']); $this->assign('is_email_receipt', $this->_values['is_email_receipt']); $this->assign('bltID', $this->_bltID); //assign cancelSubscription URL to templates $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values)); // assigning title to template in case someone wants to use it, also setting CMS page title if ($this->_pcpId) { $this->assign('title', $pcpInfo['title']); CRM_Utils_System::setTitle($pcpInfo['title']); } else { $this->assign('title', $this->_values['title']); CRM_Utils_System::setTitle($this->_values['title']); } $this->_defaults = array(); $this->_amount = $this->get('amount'); //CRM-6907 $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { //check permission for action. if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page')); } $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_formType = CRM_Utils_Array::value('formType', $_GET); // get price set id. $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET); $this->set('priceSetId', $this->_priceSetId); $this->assign('priceSetId', $this->_priceSetId); //get the pledge payment id $this->_ppID = CRM_Utils_Request::retrieve('ppid', 'Positive', $this); //get the contact id $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); //get the action. $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); //get the contribution id if update $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); //set the contribution mode. $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $this->assign('contributionMode', $this->_mode); $this->_paymentProcessor = array('billing_mode' => 1); $this->assign('showCheckNumber', false); //ensure that processor has a valid config //only valid processors get display to user if ($this->_mode) { $validProcessors = array(); $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )"); foreach ($processors as $ppID => $label) { require_once 'CRM/Core/BAO/PaymentProcessor.php'; require_once 'CRM/Core/Payment.php'; $paymentProcessor =& CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) { continue; } else { if ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') { continue; } else { $paymentObject =& CRM_Core_Payment::singleton($this->_mode, 'Contribute', $paymentProcessor, $this); $error = $paymentObject->checkConfig(); if (empty($error)) { $validProcessors[$ppID] = $label; } $paymentObject = null; } } } if (empty($validProcessors)) { CRM_Core_Error::fatal(ts('You will need to configure the %1 settings for your Payment Processor before you can submit credit card transactions.', array(1 => $this->_mode))); } else { $this->_processors = $validProcessors; } } // this required to show billing block $this->assign_by_ref('paymentProcessor', $paymentProcessor); $this->assign('hidePayPalExpress', true); if ($this->_contactID) { require_once 'CRM/Contact/BAO/Contact/Location.php'; list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('displayName', $this->userDisplayName); } // also check for billing information // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $this->_bltID = array_search('Billing', $locationTypes); if (!$this->_bltID) { CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing'))); } $this->set('bltID', $this->_bltID); $this->assign('bltID', $this->_bltID); $this->_fields = array(); require_once 'CRM/Core/Payment.php'; require_once 'CRM/Core/Payment/Form.php'; // payment fields are depending on payment type if ($this->_processors['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($this); } else { CRM_Core_Payment_Form::setCreditCardFields($this); } if ($this->_action & CRM_Core_Action::DELETE) { return; } $config =& CRM_Core_Config::singleton(); if (in_array("CiviPledge", $config->enableComponents) && !$this->_formType) { //get the payment values associated with given pledge payment id OR check for payments due. $this->_pledgeValues = array(); if ($this->_ppID) { $payParams = array('id' => $this->_ppID); require_once "CRM/Pledge/BAO/Payment.php"; CRM_Pledge_BAO_Payment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']); $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']); $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(); if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); } //get the pledge values associated with given pledge payment. require_once 'CRM/Pledge/BAO/Pledge.php'; $ids = array(); $pledgeParams = array('id' => $this->_pledgeID); CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); $this->assign('ppID', $this->_ppID); } else { // Not making a pledge payment, so check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206 if (isset($this->_contactID)) { require_once "CRM/Pledge/BAO/Pledge.php"; $contactPledges = array(); $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); if (!empty($contactPledges)) { $payments = null; $paymentsDue = null; $multipleDue = false; require_once "CRM/Pledge/BAO/Payment.php"; foreach ($contactPledges as $key => $pledgeId) { $payments = CRM_Pledge_BAO_Payment::getOldestPledgePayment($pledgeId); if ($payments) { if ($paymentsDue) { $multipleDue = true; break; } else { $paymentsDue = $payments; } } } if ($multipleDue) { // Show link to pledge tab since more than one pledge has a payment due $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge"); CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab))); } else { if ($paymentsDue) { // Show user link to oldest Pending or Overdue pledge payment require_once 'CRM/Utils/Date.php'; require_once 'CRM/Utils/Money.php'; $ppAmountDue = CRM_Utils_Money::format($payments['amount']); $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Payment', $payments['id'], 'scheduled_date')); if ($this->_mode) { $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live"); } else { $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge"); } CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to apply this contribution as a pledge payment<a/>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate))); } } } } } } $this->_values = array(); // current contribution id if ($this->_id) { $this->_online = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_FinancialTrxn', $this->_id, 'id', 'contribution_id'); if ($this->_online) { $this->assign('isOnline', true); } //to get Premium id $sql = "\nSELECT *\nFROM civicrm_contribution_product\nWHERE contribution_id = {$this->_id}\n"; $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $this->_premiumID = $dao->id; $this->_productDAO = $dao; } $dao->free(); $ids = array(); $params = array('id' => $this->_id); require_once "CRM/Contribute/BAO/Contribution.php"; CRM_Contribute_BAO_Contribution::getValues($params, $this->_values, $ids); //unset the honor type id:when delete the honor_contact_id //and edit the contribution, honoree infomation pane open //since honor_type_id is present if (!CRM_Utils_Array::value('honor_contact_id', $this->_values)) { unset($this->_values['honor_type_id']); } //to get note id require_once 'CRM/Core/BAO/Note.php'; $daoNote =& new CRM_Core_BAO_Note(); $daoNote->entity_table = 'civicrm_contribution'; $daoNote->entity_id = $this->_id; if ($daoNote->find(true)) { $this->_noteID = $daoNote->id; $this->_values['note'] = $daoNote->note; } $this->_contributionType = $this->_values['contribution_type_id']; $csParams = array('contribution_id' => $this->_id); $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, true); if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) { $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softCredit['soft_credit_to'], 'sort_name'); } $this->_values['soft_credit_to'] = $softCredit['sort_name']; $this->_values['softID'] = $softCredit['soft_credit_id']; $this->_values['soft_contact_id'] = $softCredit['soft_credit_to']; $this->_values['pcp_made_through_id'] = $softCredit['pcp_id']; $this->_values['pcp_display_in_roll'] = $softCredit['pcp_display_in_roll']; $this->_values['pcp_roll_nickname'] = $softCredit['pcp_roll_nickname']; $this->_values['pcp_personal_note'] = $softCredit['pcp_personal_note']; //display check number field only if its having value or its offline mode. if (CRM_Utils_Array::value('payment_instrument_id', $this->_values) == CRM_Core_OptionGroup::getValue('payment_instrument', 'Check', 'name') || CRM_Utils_Array::value('check_number', $this->_values)) { $this->assign('showCheckNumber', true); } } // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { $this->set('type', 'Contribution'); $this->set('subType', $this->_contributionType); $this->set('entityId', $this->_id); CRM_Custom_Form_Customdata::preProcess($this); CRM_Custom_Form_Customdata::buildQuickForm($this); CRM_Custom_Form_Customdata::setDefaultValues($this); } require_once 'CRM/Price/BAO/Set.php'; $this->_lineItems = array(); if ($this->_id && ($priceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution', $this->_id))) { $this->_priceSetId = $priceSetId; require_once 'CRM/Price/BAO/LineItem.php'; $this->_lineItems[] = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution'); } $this->assign('lineItem', empty($this->_lineItems) ? false : $this->_lineItems); }