*/
protected $_fromEmails = array();
- 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);
+ /**
+ * Details of all enabled membership types.
+ *
+ * @var array
+ */
+ protected $allMembershipTypeDetails = array();
- $this->assign('context', $this->_context);
- $this->assign('membershipMode', $this->_mode);
- $this->assign('contactID', $this->_contactID);
+ /**
+ * Array of membership type IDs and whether they permit autorenewal.
+ *
+ * @var array
+ */
+ protected $membershipTypeRenewalStatus = array();
- if ($this->_mode) {
- $this->assignPaymentRelatedVariables();
+ public function preProcess() {
+ // 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.'));
}
+ parent::preProcess();
+ $params = array();
+ $params['context'] = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'membership');
+ $params['id'] = CRM_Utils_Request::retrieve('id', 'Positive', $this);
+ $params['mode'] = CRM_Utils_Request::retrieve('mode', 'String', $this);
- if ($this->_id) {
- $this->_memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'membership_type_id');
- $this->_membershipIDs[] = $this->_id;
+ $this->setContextVariables($params);
+
+ $this->assign('context', $this->_context);
+ $this->assign('membershipMode', $this->_mode);
+ $this->allMembershipTypeDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, array(), TRUE);
+ foreach ($this->allMembershipTypeDetails as $index => $membershipType) {
+ if ($membershipType['auto_renew']) {
+ $this->_recurMembershipTypes[$index] = $membershipType;
+ $this->membershipTypeRenewalStatus[$index] = $membershipType['auto_renew'];
+ }
}
- $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
}
/**
if (isset($this->_id)) {
$params = array('id' => $this->_id);
CRM_Member_BAO_Membership::retrieve($params, $defaults);
- }
-
- if (isset($defaults['minimum_fee'])) {
- $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
- }
+ if (isset($defaults['minimum_fee'])) {
+ $defaults['minimum_fee'] = CRM_Utils_Money::format($defaults['minimum_fee'], NULL, '%a');
+ }
- if (isset($defaults['status'])) {
- $this->assign('membershipStatus', $defaults['status']);
+ if (isset($defaults['status'])) {
+ $this->assign('membershipStatus', $defaults['status']);
+ }
}
if ($this->_action & CRM_Core_Action::ADD) {
/**
* Build the form object.
- *
- * @return void
*/
public function buildQuickForm() {
+
if ($this->_mode) {
$this->add('select', 'payment_processor_id',
ts('Payment Processor'),
);
CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE);
}
+ // 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.
+ if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
+ if (!empty($this->_recurPaymentProcessors)) {
+ $this->assign('allowAutoRenew', TRUE);
+ }
+
+ $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();
+ }
+
+ $this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors));
+ $this->addElement('checkbox',
+ 'auto_renew',
+ ts('Membership renewed automatically'),
+ NULL,
+ array('onclick' => "buildReceiptANDNotice( );")
+ );
+
+ $this->assignPaymentRelatedVariables();
+ }
+ $this->assign('autoRenewOptions', json_encode($this->membershipTypeRenewalStatus));
+
if ($this->_action & CRM_Core_Action::RENEW) {
$this->addButtons(array(
array(
}
}
+ 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();
+ }
+
/**
* Create a recurring contribution record.
*