public function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE);
     $this->_view = CRM_Utils_Request::retrieve('view', 'String', $this, FALSE);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE);
     $this->assign('component', $this->_component);
     $this->assign('id', $this->_id);
     $this->assign('suppressPaymentFormButtons', $this->isBeingCalledFromSelectorContext());
     if ($this->_view == 'transaction' && $this->_action & CRM_Core_Action::BROWSE) {
         $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, TRUE);
         $transactionRows = $paymentInfo['transaction'];
         $title = ts('View Payment');
         if ($this->_component == 'event') {
             $info = CRM_Event_BAO_Participant::participantDetails($this->_id);
             $title .= " - {$info['title']}";
         }
         CRM_Utils_System::setTitle($title);
         $this->assign('transaction', TRUE);
         $this->assign('rows', $transactionRows);
         return;
     }
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     $enitityType = NULL;
     if ($this->_component == 'event') {
         $enitityType = 'participant';
         $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
     }
     $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
     $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId);
     $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $enitityType);
     $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component, FALSE, TRUE);
     $this->_amtPaid = $paymentDetails['paid'];
     $this->_amtTotal = $paymentDetails['total'];
     if (!empty($paymentInfo['refund_due'])) {
         $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
         $this->_paymentType = 'refund';
     } elseif (!empty($paymentInfo['amount_owed'])) {
         $paymentAmt = $this->_owed = $paymentInfo['amount_owed'];
         $this->_paymentType = 'owed';
     } else {
         CRM_Core_Error::fatal(ts('No payment information found for this record'));
     }
     //set the payment mode - _mode property is defined in parent class
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     if (!empty($this->_mode) && $this->_paymentType == 'refund') {
         CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use'));
     }
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
     $this->assignPaymentRelatedVariables();
     $this->assign('contributionMode', $this->_mode);
     $this->assign('contactId', $this->_contactId);
     $this->assign('paymentType', $this->_paymentType);
     $this->assign('paymentAmt', abs($paymentAmt));
     $this->setPageTitle($this->_refund ? ts('Refund') : ts('Payment'));
 }
 public function preProcess()
 {
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $this->_component = CRM_Utils_Request::retrieve('component', 'String', $this, TRUE);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     $enitityType = NULL;
     if ($this->_component == 'event') {
         $enitityType = 'participant';
         $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
     }
     $eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'event_id', 'id');
     $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($eventId);
     $paymentInfo = CRM_Core_BAO_FinancialTrxn::getPartialPaymentWithType($this->_id, $enitityType);
     $paymentDetails = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_id, $this->_component);
     $this->_amtPaid = $paymentDetails['paid'];
     $this->_amtTotal = $paymentDetails['total'];
     if (!empty($paymentInfo['refund_due'])) {
         $paymentAmt = $this->_refund = $paymentInfo['refund_due'];
         $this->_paymentType = 'refund';
     } elseif (!empty($paymentInfo['amount_owed'])) {
         $paymentAmt = $this->_owed = $paymentInfo['amount_owed'];
         $this->_paymentType = 'owed';
     } else {
         CRM_Core_Error::fatal(ts('No payment information found for this record'));
     }
     //set the payment mode - _mode property is defined in parent class
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     if (!empty($this->_mode) && $this->_paymentType == 'refund') {
         CRM_Core_Error::fatal(ts('Credit card payment is not for Refund payments use'));
     }
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
     if (!$this->_refund) {
         $this->assignProcessors();
         // also check for billing information
         // get the billing location type
         $this->assignBillingType();
     }
     $this->assign('contributionMode', $this->_mode);
     $this->assign('contactId', $this->_contactId);
     $this->assign('component', $this->_component);
     $this->assign('id', $this->_id);
     $this->assign('paymentType', $this->_paymentType);
     $this->assign('paymentAmt', abs($paymentAmt));
     $this->_paymentProcessor = array('billing_mode' => 1);
     $title = $this->_refund ? "Refund for {$this->_contributorDisplayName}" : "Payment from {$this->_contributorDisplayName}";
     if ($title) {
         CRM_Utils_System::setTitle(ts('%1', array(1 => $title)));
     }
 }
Beispiel #3
0
 public function preProcess()
 {
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('context', $this->_context);
     $this->assign('membershipMode', $this->_mode);
     $this->assign('contactID', $this->_contactID);
     if ($this->_mode) {
         $this->assignPaymentRelatedVariables();
     }
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
         $this->_membershipIDs[] = $this->_id;
     }
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
 }
Beispiel #4
0
 /**
  * Set variables in a way that can be accessed from different places.
  *
  * This is part of refactoring for unit testability on the submit function.
  *
  * @param array $params
  */
 protected function setContextVariables($params)
 {
     $variables = array('action' => '_action', 'context' => '_context', 'id' => '_id', 'cid' => '_contactID', 'mode' => '_mode');
     foreach ($variables as $paramKey => $classVar) {
         if (isset($params[$paramKey]) && !isset($this->{$classVar})) {
             $this->{$classVar} = $params[$paramKey];
         }
     }
     if ($this->_mode) {
         $this->assignPaymentRelatedVariables();
     }
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
         $this->_membershipIDs[] = $this->_id;
     }
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
 }
Beispiel #5
0
 /**
  * Set variables up before form is built.
  */
 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.'));
     }
     parent::preProcess();
     $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);
     $this->assign('action', $this->_action);
     // Get the contribution id if update
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (!empty($this->_id)) {
         $this->assign('contribID', $this->_id);
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     $this->_compId = CRM_Utils_Request::retrieve('compId', 'Positive', $this);
     $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     //set the contribution mode.
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('contributionMode', $this->_mode);
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->assign('showCheckNumber', TRUE);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     $this->assignPaymentRelatedVariables();
     if (in_array('CiviPledge', CRM_Core_Config::singleton()->enableComponents) && !$this->_formType) {
         $this->preProcessPledge();
     }
     if ($this->_id) {
         $this->showRecordLinkMesssage($this->_id);
     }
     $this->_values = array();
     // Current contribution id.
     if ($this->_id) {
         $this->assignPremiumProduct($this->_id);
         $this->buildValuesAndAssignOnline_Note_Type($this->_id, $this->_values);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         $this->applyCustomData('Contribution', CRM_Utils_Array::value('financial_type_id', $_POST), $this->_id);
     }
     $this->_lineItems = array();
     if ($this->_id) {
         if (!empty($this->_compId) && $this->_compContext == 'participant') {
             $this->assign('compId', $this->_compId);
             $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_compId);
         } else {
             $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1, TRUE, TRUE);
         }
         empty($lineItem) ? NULL : ($this->_lineItems[] = $lineItem);
     }
     $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
     // Set title
     if ($this->_mode) {
         $this->setPageTitle($this->_ppID ? ts('Credit Card Pledge Payment') : ts('Credit Card Contribution'));
     } else {
         $this->setPageTitle($this->_ppID ? ts('Pledge Payment') : ts('Contribution'));
     }
     if ($this->_id) {
         CRM_Contribute_Form_SoftCredit::preprocess($this);
     }
 }
 public function preProcess()
 {
     //custom data related code
     $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);
     }
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_processors = array();
     CRM_Core_Resources::singleton()->addSetting(array('ids' => array('contact' => $this->_contactID)));
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $contributionID = CRM_Member_BAO_Membership::getMembershipContributionId($this->_id);
         // check delete permission for contribution
         if ($this->_id && $contributionID && !CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
             CRM_Core_Error::fatal(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
         }
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
         $this->_membershipIDs[] = $this->_id;
     }
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('membershipMode', $this->_mode);
     if ($this->_mode) {
         $this->_paymentProcessor = array('billing_mode' => 1);
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )');
         foreach ($processors as $ppID => $label) {
             $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
                 $error = $paymentObject->checkConfig();
                 if (empty($error)) {
                     $validProcessors[$ppID] = $label;
                 }
                 $paymentObject = NULL;
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
         } else {
             $this->_processors = $validProcessors;
         }
         // also check for billing information
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
         // CRM-8108 remove ts around Billing location type
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $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();
         CRM_Core_Payment_Form::setCreditCardFields($this);
         // this required to show billing block
         $this->assign_by_ref('paymentProcessor', $paymentProcessor);
         $this->assign('hidePayPalExpress', TRUE);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         if (!CRM_Member_BAO_Membership::statusAvailabilty($this->_contactID)) {
             // all possible statuses are disabled - redirect back to contact form
             CRM_Core_Error::statusBounce(ts('There are no configured membership statuses. You cannot add this membership until your membership statuses are correctly configured'));
         }
         if ($this->_contactID) {
             //check whether contact has a current membership so we can alert user that they may want to do a renewal instead
             $contactMemberships = array();
             $memParams = array('contact_id' => $this->_contactID);
             CRM_Member_BAO_Membership::getValues($memParams, $contactMemberships, TRUE);
             $cMemTypes = array();
             foreach ($contactMemberships as $mem) {
                 $cMemTypes[] = $mem['membership_type_id'];
             }
             if (count($cMemTypes) > 0) {
                 $memberorgs = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($cMemTypes);
                 $mems_by_org = array();
                 foreach ($contactMemberships as $memid => $mem) {
                     $mem['member_of_contact_id'] = CRM_Utils_Array::value($mem['membership_type_id'], $memberorgs);
                     if (CRM_Utils_Array::value('membership_end_date', $mem)) {
                         $mem['membership_end_date'] = CRM_Utils_Date::customformat($mem['membership_end_date']);
                     }
                     $mem['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $mem['membership_type_id'], 'name', 'id');
                     $mem['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $mem['status_id'], 'label', 'id');
                     if ($this->_mode) {
                         $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member&mode=live");
                     } else {
                         $mem['renewUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$mem['id']}&context=membership&selectedChild=member");
                     }
                     $mem['membershipTab'] = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
                     $mems_by_org[$mem['member_of_contact_id']] = $mem;
                 }
                 $resources = CRM_Core_Resources::singleton();
                 $resources->addSetting(array('existingMems' => array('memberorgs' => $mems_by_org)));
                 $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/Membership.js');
             }
         } else {
             $resources = CRM_Core_Resources::singleton();
             $resources->addScriptFile('civicrm', 'templates/CRM/Member/Form/MembershipStandalone.js');
             $statuses = array();
             $membershipStatus = new CRM_Member_DAO_MembershipStatus();
             $membershipStatus->is_current_member = 1;
             $membershipStatus->find();
             $membershipStatus->selectAdd();
             $membershipStatus->selectAdd('id');
             while ($membershipStatus->fetch()) {
                 $statuses[$membershipStatus->id] = $membershipStatus->label;
             }
             $membershipStatus->free();
             $passthru = array('typeorgs' => CRM_Member_BAO_MembershipType::getMembershipTypeOrganization(), 'memtypes' => CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE), 'statuses' => $statuses);
             $resources->addSetting(array('existingMems' => $passthru));
         }
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership');
     }
     $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     // Set title
     if ($this->_contactID) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactID)) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
         CRM_Utils_System::setTitle(ts('Membership for') . ' ' . $displayName);
     }
     parent::preProcess();
 }
Beispiel #7
0
 /**
  * Build From Email as the combination of all the email ids of the logged in user,
  * the domain email id and the email id configured for the event
  *
  * @param int $eventId   the id of the event
  *
  * @return array         an array of email ids
  * @access public
  * @static
  */
 static function getFromEmailIds($eventId = NULL)
 {
     $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
     if ($eventId) {
         // add the email id configured for the event
         $params = array('id' => $eventId);
         $returnProperties = array('confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm');
         $eventEmail = array();
         CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $params, $eventEmail, $returnProperties);
         if (!empty($eventEmail['confirm_from_name']) && !empty($eventEmail['confirm_from_email'])) {
             $eventEmailId = "{$eventEmail['confirm_from_name']} <{$eventEmail['confirm_from_email']}>";
             $fromEmailValues['from_email_id'][$eventEmailId] = htmlspecialchars($eventEmailId);
             $fromEmailId = array('cc' => CRM_Utils_Array::value('cc_confirm', $eventEmail), 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventEmail));
             $fromEmailValues = array_merge($fromEmailValues, $fromEmailId);
         }
     }
     return $fromEmailValues;
 }
Beispiel #8
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     // check for action permissions.
     if (!CRM_Core_Permission::checkActionPermission('CiviPledge', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     $this->assign('action', $this->_action);
     $this->assign('context', $this->_context);
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->userDisplayName = $this->userEmail = NULL;
     if ($this->_contactID) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     $this->setPageTitle(ts('Pledge'));
     // build custom data
     CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Pledge', $this->_id);
     $this->_values = array();
     // current pledge id
     if ($this->_id) {
         // get the contribution id
         $this->_contributionID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'contribution_id', 'pledge_id');
         $params = array('id' => $this->_id);
         CRM_Pledge_BAO_Pledge::getValues($params, $this->_values);
         $this->_isPending = CRM_Pledge_BAO_Pledge::pledgeHasFinancialTransactions($this->_id, CRM_Utils_Array::value('status_id', $this->_values)) ? FALSE : TRUE;
     }
     // get the pledge frequency units.
     $this->_freqUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
 }
 /**
  * Send pdf by email.
  *
  * @param array $contact
  * @param string $html
  *
  * @param $is_pdf
  * @param array $format
  * @param array $params
  *
  * @return bool
  */
 public static function emailLetter($contact, $html, $is_pdf, $format = array(), $params = array())
 {
     try {
         if (empty($contact['email'])) {
             return FALSE;
         }
         $mustBeEmpty = array('do_not_email', 'is_deceased', 'on_hold');
         foreach ($mustBeEmpty as $emptyField) {
             if (!empty($contact[$emptyField])) {
                 return FALSE;
             }
         }
         $defaults = array('toName' => $contact['display_name'], 'toEmail' => $contact['email'], 'text' => '', 'html' => $html);
         if (empty($params['from'])) {
             $emails = CRM_Core_BAO_Email::getFromEmail();
             $emails = array_keys($emails);
             $defaults['from'] = array_pop($emails);
         }
         if (!empty($params['subject'])) {
             $defaults['subject'] = $params['subject'];
         } else {
             $defaults['subject'] = ts('Thank you for your contribution/s');
         }
         if ($is_pdf) {
             $defaults['html'] = ts('Please see attached');
             $defaults['attachments'] = array(CRM_Utils_Mail::appendPDF('ThankYou.pdf', $html, $format));
         }
         $params = array_merge($defaults);
         return CRM_Utils_Mail::send($params);
     } catch (CRM_Core_Exception $e) {
         return FALSE;
     }
 }
 public function preProcess()
 {
     //custom data related code
     $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);
     }
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_processors = array();
     // check for edit permission
     if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "membership_type_id");
         $this->_membershipIDs[] = $this->_id;
     }
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('membershipMode', $this->_mode);
     if ($this->_mode) {
         $this->_paymentProcessor = array('billing_mode' => 1);
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
         foreach ($processors as $ppID => $label) {
             $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
                 $error = $paymentObject->checkConfig();
                 if (empty($error)) {
                     $validProcessors[$ppID] = $label;
                 }
                 $paymentObject = NULL;
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
         } else {
             $this->_processors = $validProcessors;
         }
         // also check for billing information
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::locationType();
         // CRM-8108 remove ts around Billing location type
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $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();
         CRM_Core_Payment_Form::setCreditCardFields($this);
         // this required to show billing block
         $this->assign_by_ref('paymentProcessor', $paymentProcessor);
         $this->assign('hidePayPalExpress', TRUE);
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         //check whether any active membership statuses are available - redirects back to contact summary if not
         CRM_Member_BAO_Membership::statusAvilability($this->_contactID);
         if ($this->_contactID) {
             //check whether contact has a current membership so we can alert user that they may want to do a renewal instead
             $hasMembership = CRM_Member_BAO_Membership::getContactMembership($this->_contactID, NULL, 0);
             if (!empty($hasMembership)) {
                 $hasMembership['membership_type'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $hasMembership['membership_type_id'], 'name', 'id');
                 $hasMembership['membership_status'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $hasMembership['status_id'], 'label', 'id');
                 $membershipTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=member");
                 if ($this->_mode) {
                     $renewUrl = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$hasMembership['id']}&context=membership&selectedChild=member&mode=live");
                 } else {
                     $renewUrl = CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$hasMembership['id']}&context=membership&selectedChild=member");
                 }
                 if (CRM_Utils_Array::value('membership_end_date', $hasMembership)) {
                     CRM_Core_Session::setStatus(ts('This contact has an existing %1 membership record with %2 status and end date of %3. <a href="%4">Click here if you want to renew this membership</a> (rather than creating a new membership record). <a href="%5">Click here to view all existing and / or expired memberships for this contact.</a>', array(1 => $hasMembership['membership_type'], 2 => $hasMembership['membership_status'], 3 => CRM_Utils_Date::customformat($hasMembership['membership_end_date']), 4 => $renewUrl, 5 => $membershipTab)));
                 } else {
                     CRM_Core_Session::setStatus(ts('This contact has an existing %1 membership record with %2 status. <a href="%3">Click here if you want to renew this membership</a> (rather than creating a new membership record). <a href="%4">Click here to view all existing and / or expired memberships for this contact.</a>', array(1 => $hasMembership['membership_type'], 2 => $hasMembership['membership_status'], 3 => $renewUrl, 4 => $membershipTab)));
                 }
             }
         }
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value("hidden_custom", $_POST)) {
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // CRM-4395, get the online pending contribution id.
     $this->_onlinePendingContributionId = NULL;
     if (!$this->_mode && $this->_id && $this->_action & CRM_Core_Action::UPDATE) {
         $this->_onlinePendingContributionId = CRM_Contribute_BAO_Contribution::checkOnlinePendingContribution($this->_id, 'Membership');
     }
     $this->assign('onlinePendingContributionId', $this->_onlinePendingContributionId);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     parent::preProcess();
 }
 public function preProcess()
 {
     //custom data related code
     $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);
     }
     // check for edit permission
     if (!CRM_Core_Permission::check('edit memberships')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if ($this->_id) {
         $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
     }
     $this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'end_date')));
     $this->assign('membershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'status_id'), 'name'));
     //using credit card :: CRM-2759
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     if ($this->_mode) {
         $membershipFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee');
         if (!$membershipFee) {
             $statusMsg = ts('Membership Renewal using a credit card requires a Membership fee. Since there is no fee associated with the selected memebership type, you can use the normal renewal mode.');
             CRM_Core_Session::setStatus($statusMsg, '', 'info');
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership"));
         }
         $this->assign('membershipMode', $this->_mode);
         $this->_paymentProcessor = array('billing_mode' => 1);
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'billing_mode IN ( 1, 3 )');
         foreach ($processors as $ppID => $label) {
             $paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
                 $error = $paymentObject->checkConfig();
                 if (empty($error)) {
                     $validProcessors[$ppID] = $label;
                 }
                 $paymentObject = NULL;
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('Could not find valid payment processor for this page'));
         } else {
             $this->_processors = $validProcessors;
         }
         // also check for billing information
         // get the billing location type
         $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate');
         // CRM-8108 remove ts around Billing location type
         //$this->_bltID = array_search( ts('Billing'),  $locationTypes );
         $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();
         CRM_Core_Payment_Form::setCreditCardFields($this);
         // this required to show billing block
         $this->assign_by_ref('paymentProcessor', $paymentProcessor);
         $this->assign('hidePayPalExpress', TRUE);
     } else {
         $this->assign('membershipMode', FALSE);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     parent::preProcess();
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     // check for action permissions.
     if (!CRM_Core_Permission::checkActionPermission('CiviPledge', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     $this->assign('action', $this->_action);
     $this->assign('context', $this->_context);
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->userDisplayName = $this->userEmail = NULL;
     if ($this->_contactID) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('displayName', $this->userDisplayName);
         // set title to "Pledge - "+Contact Name
         $displayName = $this->userDisplayName;
         $pageTitle = 'Pledge - ' . $displayName;
         $this->assign('pageTitle', $pageTitle);
     }
     //build custom data
     CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Pledge', $this->_id);
     $this->_values = array();
     // current pledge id
     if ($this->_id) {
         //get the contribution id
         $this->_contributionID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'contribution_id', 'pledge_id');
         $params = array('id' => $this->_id);
         CRM_Pledge_BAO_Pledge::getValues($params, $this->_values);
         //get the honorID
         $this->_honorID = CRM_Utils_Array::value('honor_contact_id', $this->_values);
         $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
         //check for pending pledge.
         if (CRM_Utils_Array::value('status_id', $this->_values) == array_search('Pending', $paymentStatusTypes)) {
             $this->_isPending = TRUE;
         } elseif (CRM_Utils_Array::value('status_id', $this->_values) == array_search('Overdue', $paymentStatusTypes)) {
             $allPledgePayments = array();
             CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $this->_id, $allPledgePayments, array('status_id'));
             foreach ($allPledgePayments as $key => $value) {
                 $allStatus[$value['id']] = $paymentStatusTypes[$value['status_id']];
             }
             if (count(array_count_values($allStatus)) <= 2) {
                 if (CRM_Utils_Array::value('Pending', array_count_values($allStatus))) {
                     $this->_isPending = TRUE;
                 }
             }
         }
     }
     //get the pledge frequency units.
     $this->_freqUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
 }
Beispiel #13
0
 /**
  * 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);
         CRM_Custom_Form_CustomData::preProcess($this);
         return;
     }
     $config = CRM_Core_Config::singleton();
     $resources = CRM_Core_Resources::singleton();
     $resources->addScriptFile('civicrm', 'templates/CRM/Contribute/Form/SoftCredit.js');
     $resources->addSetting(array('monetaryThousandSeparator' => $config->monetaryThousandSeparator));
     $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);
     if (!empty($this->_id)) {
         $this->assign('contribID', $this->_id);
     }
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     $this->_compId = CRM_Utils_Request::retrieve('compId', 'Positive', $this);
     $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     //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', TRUE);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     $this->assignProcessors();
     if ($this->_contactID) {
         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
     $this->assignBillingType();
     $this->_fields = array();
     CRM_Core_Payment_Form::setPaymentFieldsByType(CRM_Utils_Array::value('payment_type', $this->_processors), $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     if (in_array('CiviPledge', $config->enableComponents) && !$this->_formType) {
         $this->preProcessPledge();
     }
     $this->_values = array();
     // current contribution id
     if ($this->_id) {
         $this->assignPremiumProduct($this->_id);
         $this->buildValuesAndAssignOnline_Note_Type($this->_id, $this->_values);
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
         $this->applyCustomData('Contribution', CRM_Utils_Array::value('financial_type_id', $_POST), $this->_id);
     }
     $this->_lineItems = array();
     if ($this->_id) {
         if (!empty($this->_compId) && $this->_compContext == 'participant') {
             $this->assign('compId', $this->_compId);
             $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_compId);
         } else {
             $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1);
         }
         empty($lineItem) ? NULL : ($this->_lineItems[] = $lineItem);
     }
     $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
     // Set title
     if ($this->_contactID) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($this->_contactID)) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
         CRM_Utils_System::setTitle(ts('Contribution from') . ' ' . $displayName);
     }
 }
 /**
  * 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);
     $this->_compId = CRM_Utils_Request::retrieve('compId', 'Positive', $this);
     //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);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     //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) {
             $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             // at this stage only Authorize.net has been tested to support future start dates so if it's enabled let the template know
             // to show receive date
             $processorsSupportingFutureStartDate = array('AuthNet');
             if (in_array($paymentProcessor['payment_processor_type'], $processorsSupportingFutureStartDate)) {
                 $this->assign('processorSupportsFutureStartDate', TRUE);
             }
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $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;
         }
         //get the valid recurring processors.
         $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
         $this->_recurPaymentProcessors = array_intersect_assoc($this->_processors, $recurring);
     }
     $this->assign('recurringPaymentProcessorIds', empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors)));
     // this required to show billing block
     $this->assign_by_ref('paymentProcessor', $paymentProcessor);
     $this->assign('hidePayPalExpress', TRUE);
     if ($this->_contactID) {
         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();
     // payment fields are depending on payment type
     if (CRM_Utils_Array::value('payment_type', $this->_processors) & 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);
             CRM_Pledge_BAO_PledgePayment::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(NULL, 'name');
             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.
             $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 if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
             if (isset($this->_contactID)) {
                 $contactPledges = array();
                 $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
                 if (!empty($contactPledges)) {
                     $payments = $paymentsDue = NULL;
                     $multipleDue = FALSE;
                     foreach ($contactPledges as $key => $pledgeId) {
                         $payments = CRM_Pledge_BAO_PledgePayment::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)));
                     } elseif ($paymentsDue) {
                         // Show user link to oldest Pending or Overdue pledge payment
                         $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']);
                         $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $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 enter a pledge payment</a>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate)));
                     }
                 }
             }
         }
     }
     $this->_values = array();
     // current contribution id
     if ($this->_id) {
         //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);
         CRM_Contribute_BAO_Contribution::getValues($params, $this->_values, $ids);
         //do check for online / recurring contributions
         $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnIds($this->_id, 'civicrm_contribution');
         $this->_online = CRM_Utils_Array::value('entityFinancialTrxnId', $fids);
         //don't allow to update all fields for recuring contribution.
         if (!$this->_online) {
             $this->_online = CRM_Utils_Array::value('contribution_recur_id', $this->_values);
         }
         $this->assign('isOnline', $this->_online ? TRUE : FALSE);
         //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
         $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'] = CRM_Utils_Array::value('sort_name', $softCredit);
         $this->_values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit);
         $this->_values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit);
         if (CRM_Utils_Array::value('pcp_id', $softCredit)) {
             $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit);
             $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
             $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
             $this->_values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
             $this->_values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit);
             $this->_values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit);
             $this->_values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit);
             $this->_values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit);
         }
         //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', CRM_Utils_Array::value('contribution_type_id', $_POST));
         $this->set('entityId', $this->_id);
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $this->_lineItems = array();
     if ($this->_id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1);
         empty($lineItem) ? null : ($this->_lineItems[] = $lineItem);
     }
     $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
 }