<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.4 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
/*
* Contact ID of the member
*/
- protected $_contactID = null;
+ public $_contactID = null;
/*
* Display name of the person paying for the membership (used for receipts)
*/
* context would be set to standalone if the contact is use is being selected from
* the form rather than in the URL
*/
- protected $_context;
+ public $_context;
/**
* An array to hold a list of datefields on the form
return CRM_Custom_Form_CustomData::preProcess($this);
}
+ parent::preProcess();
// 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');
+ CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
)
);
- //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.');
+ $statusMsg = ts('Membership Renewal using a credit card requires a Membership fee. Since there is no fee associated with the selected membership 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 (CRM_Utils_Array::value('hidden_custom', $_POST)) {
+ 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();
+ CRM_Utils_System::setTitle(ts('Renew Membership'));
+
parent::preProcess();
}
/**
- * This function sets the default values for the form.
+ * Set default values for the form.
* the default values are retrieved from the database
*
- * @access public
*
- * @return None
+ * @return void
*/
public function setDefaultValues() {
if ($this->_cdType) {
return CRM_Custom_Form_CustomData::setDefaultValues($this);
}
- $defaults = array();
+
$defaults = parent::setDefaultValues();
$this->_memType = $defaults['membership_type_id'];
}
$defaults['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'financial_type_id');
-
+
//CRM-13420
- if (!CRM_Utils_Array::value('payment_instrument_id', $defaults)) {
+ if (empty($defaults['payment_instrument_id'])) {
$defaults['payment_instrument_id'] = key(CRM_Core_OptionGroup::values('payment_instrument', FALSE, FALSE, FALSE, 'AND is_default = 1'));
}
$defaults['num_terms'] = 1;
$defaults['send_receipt'] = 0;
+ //set Soft Credit Type to Gift by default
+ $scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
+ $defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));
+
$renewalDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('renewal_date', $defaults),
NULL, NULL, 'Y-m-d'
);
}
/**
- * Function to build the form
+ * Build the form object
*
- * @return None
- * @access public
+ * @return void
*/
public function buildQuickForm() {
if ($this->_cdType) {
parent::buildQuickForm();
- $defaults = array();
$defaults = parent::setDefaultValues();
$this->_memType = $defaults['membership_type_id'];
$this->assign('customDataType', 'Membership');
$options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required '));
foreach( $allMemberships as $key => $values ) {
- if (CRM_Utils_Array::value('is_active', $values) ) {
+ if (!empty($values['is_active'])) {
$membershipType[$key] = CRM_Utils_Array::value('name', $values);
- if ($this->_mode && !CRM_Utils_Array::value('minimum_fee', $values)) {
+ if ($this->_mode && empty($values['minimum_fee'])) {
continue;
}
else {
$memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
- if (!CRM_Utils_Array::value($memberOfContactId, $selMemTypeOrg)) {
+ if (empty($selMemTypeOrg[$memberOfContactId])) {
$selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact',
$memberOfContactId,
'display_name',
$selOrgMemType[$memberOfContactId][0] = ts('- select -');
}
- if (!CRM_Utils_Array::value($key, $selOrgMemType[$memberOfContactId])) {
+ if (empty($selOrgMemType[$memberOfContactId][$key])) {
$selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
}
}
'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values)
);
- if (CRM_Utils_Array::value('auto_renew', $values)) {
+ if (!empty($values['auto_renew'])) {
$allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']];
}
}
$this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
- if ($this->_mode) {
- $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
- CRM_Core_Payment_Form::buildCreditCard($this, TRUE);
- }
-
// Retrieve the name and email of the contact - this will be the TO for receipt email
list($this->_contributorDisplayName,
$this->_contributorEmail
//CRM-10223 - allow contribution to be recorded against different contact
// causes a conflict in standalone mode so skip in standalone for now
$this->addElement('checkbox', 'contribution_contact', ts('Record Payment from a Different Contact?'));
- $this->add( 'select', 'honor_type_id', ts('Membership payment is : '),
- array( '' => ts( '-') ) + CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'honor_type_id') );
- require_once 'CRM/Contact/Form/NewContact.php';
- CRM_Contact_Form_NewContact::buildQuickForm($this,1, null, false,'contribution_');
+ $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
+ $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
}
}
/**
- * Function for validation
+ * Validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @return mixed true or array of errors
- * @access public
* @static
*/
- static function formRule($params) {
+ public static function formRule($params) {
$errors = array();
if ($params['membership_type_id'][0] == 0) {
$errors['membership_type_id'] = ts('Oops. It looks like you are trying to change the membership type while renewing the membership. Please click the "change membership type" link, and select a Membership Organization.');
if (!$params['total_amount']) {
$errors['total_amount'] = ts('Please enter a Contribution Amount.');
}
- if (!CRM_Utils_Array::value('payment_instrument_id', $params)) {
+ if (empty($params['payment_instrument_id'])) {
$errors['payment_instrument_id'] = ts('Paid By is a required field.');
}
}
}
/**
- * Function to process the renewal form
+ * Process the renewal form
*
- * @access public
*
- * @return None
+ * @return void
*/
public function postProcess() {
$this->convertDateFieldsToMySQL($formValues);
$this->assign('receive_date', $formValues['receive_date']);
- if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
+ if (!empty($this->_params['send_receipt'])) {
$formValues['receipt_date'] = $now;
$this->assign('receipt_date', CRM_Utils_Date::mysqlToIso($formValues['receipt_date']));
}
$formValues['total_amount'] = CRM_Utils_Array::value('total_amount', $this->_params, CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
$this->_memType, 'minimum_fee'
));
- if (!CRM_Utils_Array::value('financial_type_id', $formValues)) {
+ if (empty($formValues['financial_type_id'])) {
$formValues['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType,'financial_type_id');
}
$this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
$this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
+ $this->_params['description'] = ts('Office Credit Card Membership Renewal Contribution');
$this->_params['ip_address'] = CRM_Utils_System::ipAddress();
$this->_params['amount'] = $formValues['total_amount'];
$this->_params['currencyID'] = $config->defaultCurrency;
// all the payment processors expect the name and address to be in the passed params
// so we copy stuff over to first_name etc.
$paymentParams = $this->_params;
- if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
+ if (!empty($this->_params['send_receipt'])) {
$paymentParams['email'] = $this->_contributorEmail;
}
$paymentParams['contactID'] = $this->_contributorContactID;
- //CRM-10377 if payment is by an alternate contact then we need to set that person
- // as the contact in the payment params
- if ($this->_contributorContactID != $this->_contactID) {
- if (CRM_Utils_Array::value('honor_type_id', $this->_params)) {
- $paymentParams['honor_contact_id'] = $this->_contactID;
- $paymentParams['honor_type_id'] = $this->_params['honor_type_id'];
- }
- }
CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
if ($formValues['contribution_status_id'] == array_search('Pending', CRM_Contribute_PseudoConstant::contributionStatus())) {
$this->_params['is_pay_later'] = 1;
}
- $renewMembership = CRM_Member_BAO_Membership::renewMembership($this->_contactID,
+ $renewMembership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($this->_contactID,
$formValues['membership_type_id'][1],
$isTestMembership, $this, NULL, NULL,
- $customFieldsFormatted, $numRenewTerms
+ $customFieldsFormatted, $numRenewTerms,
+ $this->_membershipId
);
$endDate = CRM_Utils_Date::processDate($renewMembership->end_date);
$memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name');
- if (CRM_Utils_Array::value('record_contribution', $formValues) || $this->_mode) {
+ if (!empty($formValues['record_contribution']) || $this->_mode) {
// set the source
$formValues['contribution_source'] = "{$memType} Membership: Offline membership renewal (by {$userName})";
//assign contribution contact id to the field expected by recordMembershipContribution
if($this->_contributorContactID != $this->_contactID){
$formValues['contribution_contact_id'] = $this->_contributorContactID;
- if(CRM_Utils_Array::value('honor_type_id', $this->_params)){
- $formValues['honor_contact_id'] = $this->_contactID;
+ if (!empty($this->_params['soft_credit_type_id'])){
+ $formValues['soft_credit'] = array(
+ 'soft_credit_type_id' => $this->_params['soft_credit_type_id'],
+ 'contact_id' => $this->_contactID,
+ );
}
}
$formValues['contact_id'] = $this->_contactID;
}
$receiptSend = FALSE;
- if (CRM_Utils_Array::value('send_receipt', $formValues)) {
+ if (!empty($formValues['send_receipt'])) {
$receiptSend = TRUE;
$receiptFrom = $formValues['from_email_address'];
- if (CRM_Utils_Array::value('payment_instrument_id', $formValues)) {
+ if (!empty($formValues['payment_instrument_id'])) {
$paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
$formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
}
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
$this->assign_by_ref('formValues', $formValues);
- if ( CRM_Utils_Array::value( 'contribution_id', $formValues ) ) {
+ if (!empty($formValues['contribution_id'])) {
$this->assign('contributionID', $formValues['contribution_id']);
}
$this->assign('membershipID', $this->_id);
));
$this->assign('customValues', $customValues);
if ($this->_mode) {
- if (CRM_Utils_Array::value('billing_first_name', $this->_params)) {
+ if (!empty($this->_params['billing_first_name'])) {
$name = $this->_params['billing_first_name'];
}
- if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) {
+ if (!empty($this->_params['billing_middle_name'])) {
$name .= " {$this->_params['billing_middle_name']}";
}
- if (CRM_Utils_Array::value('billing_last_name', $this->_params)) {
+ if (!empty($this->_params['billing_last_name'])) {
$name .= " {$this->_params['billing_last_name']}";
}
$this->assign('billingName', $name);
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
}
}
-