'cc_receipt',
'bcc_receipt',
));
+ $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]);
}
-
- $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]);
- $isOfflineRecur = FALSE;
- if (!$pageID && $recur->id) {
- $isOfflineRecur = TRUE;
+ elseif ($recur->id) {
+ // This means we are coming from back-office - ie. no page ID, but recurring.
+ // Ideally this information would be passed into the function clearly rather than guessing by convention.
+ $isEmailReceipt = TRUE;
}
- if ($isEmailReceipt || $isOfflineRecur) {
+
+ if ($isEmailReceipt) {
if ($pageID) {
$receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>';
}
/**
+ * Build an array of available membership types.
+ *
* @param CRM_Core_Form $form
* @param int $membershipTypeID
+ * @param bool $activeOnly
+ * Do we only want active ones?
+ * (probably this should default to TRUE but as a newly added parameter we are leaving default b
+ * behaviour unchanged).
*
* @return array
*/
- public static function buildMembershipTypeValues(&$form, $membershipTypeID = NULL) {
+ public static function buildMembershipTypeValues(&$form, $membershipTypeID = NULL, $activeOnly = FALSE) {
$whereClause = " WHERE domain_id = " . CRM_Core_Config::domainID();
+ if ($activeOnly) {
+ $whereClause .= " AND is_active = 1 ";
+ }
if (is_array($membershipTypeID)) {
$allIDs = implode(',', $membershipTypeID);
$whereClause .= " AND id IN ( $allIDs )";
'relationship_type_id',
'relationship_direction',
'max_related',
+ 'duration_unit',
+ 'duration_interval',
);
while ($dao->fetch()) {
*/
protected $_fromEmails = array();
+ /**
+ * Details of all enabled membership types.
+ *
+ * @var array
+ */
+ protected $allMembershipTypeDetails = array();
+
+ /**
+ * Array of membership type IDs and whether they permit autorenewal.
+ *
+ * @var array
+ */
+ protected $membershipTypeRenewalStatus = array();
+
public function preProcess() {
// Check for edit permission.
if (!CRM_Core_Permission::checkActionPermission('CiviMember', $this->_action)) {
$this->assign('context', $this->_context);
$this->assign('membershipMode', $this->_mode);
+ $this->allMembershipTypeDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, NULL, TRUE);
+ foreach ($this->allMembershipTypeDetails as $index => $membershipType) {
+ if ($membershipType['auto_renew']) {
+ $this->_recurMembershipTypes[$index] = $membershipType;
+ $this->membershipTypeRenewalStatus[$index] = $membershipType['auto_renew'];
+ }
+ }
}
/**
}
// Build the form for auto renew. This is displayed when in credit card mode or update mode.
// The reason for showing it in update mode is not that clear.
- $autoRenew = array();
- $recurProcessor = array();
if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
- if (!empty($recurProcessor)) {
- $autoRenew = array();
- if (!empty($membershipType)) {
- $sql = '
-SELECT id,
- auto_renew,
- duration_unit,
- duration_interval
- FROM civicrm_membership_type
-WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )';
- $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql);
- while ($recurMembershipTypes->fetch()) {
- $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew;
- foreach (array(
- 'id',
- 'auto_renew',
- 'duration_unit',
- 'duration_interval',
- ) as $fld) {
- $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->$fld;
- }
- }
- }
-
- if ($this->_mode) {
- if (!empty($this->_recurPaymentProcessors)) {
- $this->assign('allowAutoRenew', TRUE);
- }
- }
-
- $this->assign('autoRenew', json_encode($autoRenew));
- $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'),
- NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")
- );
- if ($this->_action & CRM_Core_Action::UPDATE) {
- $autoRenewElement->freeze();
- }
+ if (!empty($this->_recurPaymentProcessors)) {
+ $this->assign('allowAutoRenew', TRUE);
}
- }
- $this->assign('recurProcessor', json_encode($recurProcessor));
+ $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'),
+ NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")
+ );
+ if ($this->_action & CRM_Core_Action::UPDATE) {
+ $autoRenewElement->freeze();
+ }
- if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
+ $this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors));
$this->addElement('checkbox',
'auto_renew',
ts('Membership renewed automatically'),
$this->assignPaymentRelatedVariables();
}
- $this->assign('autoRenewOptions', json_encode($autoRenew));
+ $this->assign('autoRenewOptions', json_encode($this->membershipTypeRenewalStatus));
if ($this->_action & CRM_Core_Action::RENEW) {
$this->addButtons(array(
$selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
- $dao = new CRM_Member_DAO_MembershipType();
- $dao->domain_id = CRM_Core_Config::domainID();
- $dao->find();
-
// retrieve all memberships
- $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
+ $allMembershipInfo = array();
+ foreach ($this->allMembershipTypeDetails as $key => $values) {
+ if ($this->_mode && empty($values['minimum_fee'])) {
+ continue;
+ }
+ else {
+ $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
+ if (empty($selMemTypeOrg[$memberOfContactId])) {
+ $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
+ $memberOfContactId,
+ 'display_name',
+ 'id'
+ );
- $allMembershipInfo = $membershipType = array();
- foreach ($allMemberships as $key => $values) {
- if (!empty($values['is_active'])) {
- $membershipType[$key] = CRM_Utils_Array::value('name', $values);
- if ($this->_mode && empty($values['minimum_fee'])) {
- continue;
+ $selOrgMemType[$memberOfContactId][0] = ts('- select -');
}
- else {
- $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
- if (empty($selMemTypeOrg[$memberOfContactId])) {
- $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
- $memberOfContactId,
- 'display_name',
- 'id'
- );
-
- $selOrgMemType[$memberOfContactId][0] = ts('- select -');
- }
- if (empty($selOrgMemType[$memberOfContactId][$key])) {
- $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
- }
+ if (empty($selOrgMemType[$memberOfContactId][$key])) {
+ $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
}
-
- // build membership info array, which is used when membership type is selected to:
- // - set the payment information block
- // - set the max related block
- $allMembershipInfo[$key] = array(
- 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values),
- 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'),
- 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values),
- 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values),
- 'has_related' => isset($values['relationship_type_id']),
- 'max_related' => CRM_Utils_Array::value('max_related', $values),
- );
}
+
+ // build membership info array, which is used when membership type is selected to:
+ // - set the payment information block
+ // - set the max related block
+ $allMembershipInfo[$key] = array(
+ 'financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values),
+ 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'),
+ 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values),
+ 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values),
+ 'has_related' => isset($values['relationship_type_id']),
+ 'max_related' => CRM_Utils_Array::value('max_related', $values),
+ );
}
$this->assign('allMembershipInfo', json_encode($allMembershipInfo));
$selOrgMemType[$index] = $orgMembershipType;
}
- $memTypeJs = array('onChange' => "CRM.buildCustomData( 'Membership', this.value );");
+ $memTypeJs = array(
+ 'onChange' => "buildMaxRelated(this.value,true); CRM.buildCustomData('Membership', this.value);",
+ );
+ if (!empty($this->_recurPaymentProcessors)) {
+ $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . 'buildAutoRenew(this.value, null);';
+ }
- // for max_related: a little JS to show/hide & set default value
- $memTypeJs['onChange'] = "buildMaxRelated(this.value,true); " . $memTypeJs['onChange'];
+ ;
$this->add('text', 'max_related', ts('Max related'),
CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related')
);
$ids['membership'] = $params['id'] = $this->_id;
}
- $session = CRM_Core_Session::singleton();
- $ids['userId'] = $session->get('userID');
+ $ids['userId'] = CRM_Core_Session::singleton()->get('userID');
// membership type custom data
foreach ($this->_memTypeSelected as $memType) {
$membershipType = implode(', ', $membershipTypes);
// Retrieve the name and email of the current user - this will be the FROM for the receipt email
- list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
+ list($userName) = CRM_Contact_BAO_Contact_Location::getEmailDetails($ids['userId']);
//CRM-13981, allow different person as a soft-contributor of chosen type
if ($this->_contributorContactID != $this->_contactID) {
if (!empty($paymentParams['is_recur'])) {
$contributionType = new CRM_Financial_DAO_FinancialType();
$contributionType->id = $params['financial_type_id'];
- if (!$contributionType->find(TRUE)) {
- CRM_Core_Error::fatal('Could not find a system table');
- }
+ $contributionType->find(TRUE);
$contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this,
$paymentParams,
}
if ($params['total_amount'] > 0.0) {
- $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this);
+ $payment = $this->_paymentProcessor['object'];
try {
$result = $payment->doPayment($paymentParams);
+ $this->_params = array_merge($this->_params, $result);
+ // Assign amount to template if payment was successful.
+ $this->assign('amount', $params['total_amount']);
}
catch (PaymentProcessorException $e) {
if (!empty($paymentParams['contributionID'])) {
- CRM_Contribute_BAO_Contribution::failPayment($paymentParams['contributionID'], $e->getMessage());
+ CRM_Contribute_BAO_Contribution::failPayment($paymentParams['contributionID'], $this->_contactID,
+ $e->getMessage());
}
if (!empty($paymentParams['contributionRecurID'])) {
CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($paymentParams['contributionRecurID']);
$this->assign('entityID', $this->_id);
$selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
- $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this);
-
- $allMembershipInfo = $membershipType = array();
+ $allMembershipInfo = array();
// auto renew options if enabled for the membership
$options = CRM_Core_SelectValues::memberAutoRenew();
- foreach ($allMemberships as $key => $values) {
+ foreach ($this->allMembershipTypeDetails as $key => $values) {
if (!empty($values['is_active'])) {
- $membershipType[$key] = CRM_Utils_Array::value('name', $values);
if ($this->_mode && empty($values['minimum_fee'])) {
continue;
}
$this->assign('allMembershipInfo', json_encode($allMembershipInfo));
if ($this->_memType) {
- $this->assign('orgName', $selMemTypeOrg[$allMemberships[$this->_memType]['member_of_contact_id']]);
- $this->assign('memType', $allMemberships[$this->_memType]['name']);
+ $this->assign('orgName', $selMemTypeOrg[$this->allMembershipTypeDetails[$this->_memType]['member_of_contact_id']]);
+ $this->assign('memType', $this->allMembershipTypeDetails[$this->_memType]['name']);
}
// force select of organization by default, if only one organization in
$selOrgMemType[$index] = $orgMembershipType;
}
- $js = array('onChange' => "setPaymentBlock( ); CRM.buildCustomData( 'Membership', this.value );");
+ $js = array('onChange' => "setPaymentBlock(); CRM.buildCustomData('Membership', this.value);");
$sel = &$this->addElement('hierselect',
'membership_type_id',
ts('Renewal Membership Organization and Type'), $js
<td class="label">{$form.renewal_date.label}</td>
<td>{include file="CRM/common/jcalendar.tpl" elementName=renewal_date}</td>
</tr>
- {if $membershipMode}
- {if !empty($form.auto_renew)}
- <tr id="autoRenew" class="crm-membership-form-block-auto_renew">
- <td class="label"> {$form.auto_renew.label} {help id="id-auto_renew" file="CRM/Member/Form/Membership.hlp" action=$action} </td>
- <td> {$form.auto_renew.html} </td>
- </tr>
- {/if}
- <tr class="crm-member-membershiprenew-form-block-financial_type_id">
- <td class="label">{$form.financial_type_id.label}</td>
- <td>{$form.financial_type_id.html}<br/>
- <span class="description">{ts}Select the appropriate financial type for this payment.{/ts}</span></td>
- </tr>
- {/if}
{if $accessContribution and ! $membershipMode}
<tr class="crm-member-membershiprenew-form-block-record_contribution">
<td class="label">{$form.record_contribution.label}</td>
$var = array();
$this->params['recur_frequency_unit'] = 'month';
$this->setUpMembershipContributionPage();
- $dummyPP = CRM_Core_Payment::singleton('live', $this->_paymentProcessor);
+ $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
$dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 1, 'trxn_id' => 'create_first_success'));
$submitParams = array(
$this->params['is_recur'] = 1;
$this->params['recur_frequency_unit'] = 'month';
$this->setUpMembershipContributionPage();
- $dummyPP = CRM_Core_Payment::singleton('live', $this->_paymentProcessor);
+ $dummyPP = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
$dummyPP->setDoDirectPaymentResult(array('contribution_status_id' => 2));
$submitParams = array(