3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * Base class for offline membership / membership type / membership renewal and membership status forms
40 class CRM_Member_Form
extends CRM_Contribute_Form_AbstractEditPayment
{
43 * The id of the object being edited / created
56 * Array of from email ids
59 protected $_fromEmails = array();
62 * Details of all enabled membership types.
66 protected $allMembershipTypeDetails = array();
69 * Array of membership type IDs and whether they permit autorenewal.
73 protected $membershipTypeRenewalStatus = array();
75 public function preProcess() {
76 // Check for edit permission.
77 if (!CRM_Core_Permission
::checkActionPermission('CiviMember', $this->_action
)) {
78 CRM_Core_Error
::fatal(ts('You do not have permission to access this page.'));
82 $params['context'] = CRM_Utils_Request
::retrieve('context', 'String', $this, FALSE, 'membership');
83 $params['id'] = CRM_Utils_Request
::retrieve('id', 'Positive', $this);
84 $params['mode'] = CRM_Utils_Request
::retrieve('mode', 'String', $this);
86 $this->setContextVariables($params);
88 $this->assign('context', $this->_context
);
89 $this->assign('membershipMode', $this->_mode
);
90 $this->allMembershipTypeDetails
= CRM_Member_BAO_Membership
::buildMembershipTypeValues($this, NULL, TRUE);
91 foreach ($this->allMembershipTypeDetails
as $index => $membershipType) {
92 if ($membershipType['auto_renew']) {
93 $this->_recurMembershipTypes
[$index] = $membershipType;
94 $this->membershipTypeRenewalStatus
[$index] = $membershipType['auto_renew'];
100 * Set default values for the form. MobileProvider that in edit/view mode
101 * the default values are retrieved from the database
107 public function setDefaultValues() {
109 if (isset($this->_id
)) {
110 $params = array('id' => $this->_id
);
111 CRM_Member_BAO_Membership
::retrieve($params, $defaults);
112 if (isset($defaults['minimum_fee'])) {
113 $defaults['minimum_fee'] = CRM_Utils_Money
::format($defaults['minimum_fee'], NULL, '%a');
116 if (isset($defaults['status'])) {
117 $this->assign('membershipStatus', $defaults['status']);
121 if ($this->_action
& CRM_Core_Action
::ADD
) {
122 $defaults['is_active'] = 1;
125 if (isset($defaults['member_of_contact_id']) &&
126 $defaults['member_of_contact_id']
128 $defaults['member_org'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
129 $defaults['member_of_contact_id'], 'display_name'
136 * Build the form object.
138 public function buildQuickForm() {
141 $this->add('select', 'payment_processor_id',
142 ts('Payment Processor'),
143 $this->_processors
, TRUE,
144 array('onChange' => "buildAutoRenew( null, this.value );")
146 CRM_Core_Payment_Form
::buildPaymentForm($this, $this->_paymentProcessor
, FALSE, TRUE);
148 // Build the form for auto renew. This is displayed when in credit card mode or update mode.
149 // The reason for showing it in update mode is not that clear.
150 if ($this->_mode ||
($this->_action
& CRM_Core_Action
::UPDATE
)) {
151 if (!empty($this->_recurPaymentProcessors
)) {
152 $this->assign('allowAutoRenew', TRUE);
155 $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'),
156 NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")
158 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
159 $autoRenewElement->freeze();
162 $this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors
));
163 $this->addElement('checkbox',
165 ts('Membership renewed automatically'),
167 array('onclick' => "buildReceiptANDNotice( );")
170 $this->assignPaymentRelatedVariables();
172 $this->assign('autoRenewOptions', json_encode($this->membershipTypeRenewalStatus
));
174 if ($this->_action
& CRM_Core_Action
::RENEW
) {
175 $this->addButtons(array(
178 'name' => ts('Renew'),
183 'name' => ts('Cancel'),
188 elseif ($this->_action
& CRM_Core_Action
::DELETE
) {
189 $this->addButtons(array(
192 'name' => ts('Delete'),
197 'name' => ts('Cancel'),
203 $this->addButtons(array(
206 'name' => ts('Save'),
211 'name' => ts('Save and New'),
216 'name' => ts('Cancel'),
224 * Extract values from the contact create boxes on the form and assign appropriately to
226 * - $this->_contributorEmail,
227 * - $this->_memberEmail &
228 * - $this->_contributionName
229 * - $this->_memberName
230 * - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
231 * - $this->_contributorContactId - id of the contributor
232 * - $this->_receiptContactId
234 * If the member & contributor are the same then the values will be the same. But if different people paid
235 * then they weill differ
237 * @param array $formValues
238 * values from form. The important values we are looking for are.
240 * - soft_credit_contact_id
242 public function storeContactFields($formValues) {
243 // in a 'standalone form' (contact id not in the url) the contact will be in the form values
244 if (!empty($formValues['contact_id'])) {
245 $this->_contactID
= $formValues['contact_id'];
248 list($this->_memberDisplayName
,
250 ) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contactID
);
252 //CRM-10375 Where the payer differs to the member the payer should get the email.
253 // here we store details in order to do that
254 if (!empty($formValues['soft_credit_contact_id'])) {
255 $this->_receiptContactId
= $this->_contributorContactID
= $formValues['soft_credit_contact_id'];
256 list($this->_contributorDisplayName
,
257 $this->_contributorEmail
) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($this->_contributorContactID
);
260 $this->_receiptContactId
= $this->_contributorContactID
= $this->_contactID
;
261 $this->_contributorDisplayName
= $this->_memberDisplayName
;
262 $this->_contributorEmail
= $this->_memberEmail
;
266 protected function setContextVariables($params) {
268 'action' => '_action',
269 'context' => '_context',
271 'cid' => '_contactID',
274 foreach ($variables as $paramKey => $classVar) {
275 if (isset($params[$paramKey]) && !isset($this->$classVar)) {
276 $this->$classVar = $params[$paramKey];
281 $this->assignPaymentRelatedVariables();
285 $this->_memType
= CRM_Core_DAO
::getFieldValue('CRM_Member_DAO_Membership', $this->_id
, 'membership_type_id');
286 $this->_membershipIDs
[] = $this->_id
;
288 $this->_fromEmails
= CRM_Core_BAO_Email
::getFromEmail();