<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
class CRM_Contribute_Form_Contribution_Main extends CRM_Contribute_Form_ContributionBase {
/**
- *Define default MembershipType Id
- *
+ * Define default MembershipType Id
*/
public $_defaultMemTypeId;
* Set variables up before form is built
*
* @return void
- * @access public
*/
public function preProcess() {
parent::preProcess();
// make sure we have right permission to edit this user
$csContactID = $this->getContactID();
- $reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
+ $reset = CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject);
$mainDisplay = CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject);
if ($reset) {
}
//CRM-5001
- if (!empty($this->_values['is_for_organization'])) {
+ //CRM-15787
+ $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
+ if (!empty($this->_values['is_for_organization']) && empty($member['is_active'])) {
$msg = ts('Mixed profile not allowed for on behalf of registration/sign up.');
$ufJoinParams = array(
'module' => 'onBehalf',
if ($onBehalfProfileID) {
$onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileID);
foreach (array(
- 'Individual', 'Organization', 'Household') as $contactType) {
+ 'Individual',
+ 'Organization',
+ 'Household'
+ ) as $contactType) {
if (in_array($contactType, $onBehalfProfile) &&
(in_array('Membership', $onBehalfProfile) ||
in_array('Contribution', $onBehalfProfile)
if ($postID = CRM_Utils_Array::value('custom_post_id', $this->_values)) {
$postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID);
foreach (array(
- 'Individual', 'Organization', 'Household') as $contactType) {
+ 'Individual',
+ 'Organization',
+ 'Household'
+ ) as $contactType) {
if (in_array($contactType, $postProfile) &&
(in_array('Membership', $postProfile) ||
in_array('Contribution', $postProfile)
* Set the default values
*
* @return void
- * @access public
*/
/**
- *
*/
- function setDefaultValues() {
+ public function setDefaultValues() {
// check if the user is registered and we have a contact ID
$contactID = $this->getContactID();
* Build the form object
*
* @return void
- * @access public
*/
public function buildQuickForm() {
// build profiles first so that we can determine address fields etc
$onlinePaymentProcessorEnabled = FALSE;
if (!empty($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $key => $name) {
- if($name['billing_mode'] == 1) {
+ if ($name['billing_mode'] == 1) {
$onlinePaymentProcessorEnabled = TRUE;
}
$pps[$key] = $name['name'];
}
$contactID = $this->getContactID();
- if($this->getContactID() === '0') {
+ if ($this->getContactID() === '0') {
$this->addCidZeroOptions($onlinePaymentProcessorEnabled);
}
//build pledge block.
$this->set('priceSetId', $this->_priceSetId);
CRM_Price_BAO_PriceSet::buildPriceSet($this);
if ($this->_values['is_monetary'] &&
- $this->_values['is_recur'] && empty($this->_values['pledge_id'])) {
+ $this->_values['is_recur'] && empty($this->_values['pledge_id'])
+ ) {
self::buildRecur($this);
}
}
CRM_Contact_Form_ProfileContact::buildQuickForm($this);
}
-
//don't build pledge block when mid is passed
if (!$this->_mid) {
$config = CRM_Core_Config::singleton();
}
//to create an cms user
- if (!$this->_userID) {
+ if (!$this->_contactID) {
$createCMSUser = FALSE;
if ($this->_values['custom_pre_id']) {
$pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter));
// Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field.
$text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute');
- if(!empty($text)) {
+ if (!empty($text)) {
$pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!");
}
$this->assign('pcpSupporterText', $pcp_supporter_text);
array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")
);
$extraOption = array('onclick' => "return pcpAnonymous( );");
- $elements = array();
- $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
- $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
+ $elements = array();
+ $elements[] = &$this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption);
+ $elements[] = &$this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption);
$this->addGroup($elements, 'pcp_is_anonymous', NULL, ' ');
$this->setDefaults(array('pcp_display_in_roll' => 1));
$this->setDefaults(array('pcp_is_anonymous' => 1));
//when multiple payment processor as the user
//can toggle with payment processor selection
$billingModePaymentProcessors = 0;
- if ( !empty( $this->_paymentProcessors ) ) {
+ if (!empty($this->_paymentProcessors)) {
foreach ($this->_paymentProcessors as $key => $values) {
if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) {
$billingModePaymentProcessors++;
if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) {
$allAreBillingModeProcessors = TRUE;
- } else {
+ }
+ else {
$allAreBillingModeProcessors = FALSE;
}
/**
* Build elements to enable pay on behalf of an organization.
- *
- * @access public
*/
- function buildOnBehalfOrganization() {
+ public function buildOnBehalfOrganization() {
if ($this->_membershipContactID) {
$entityBlock = array('contact_id' => $this->_membershipContactID);
CRM_Core_BAO_Location::getValues($entityBlock, $this->_defaults);
/**
* Build elements to collect information for recurring contributions
*
- * @access public
*
* @param CRM_Core_Form $form
*/
$unitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $frUnits);
// CRM 10860, display text instead of a dropdown if there's only 1 frequency unit
- if(sizeof($unitVals) == 1) {
- $form->assign('one_frequency_unit', true);
+ if (sizeof($unitVals) == 1) {
+ $form->assign('one_frequency_unit', TRUE);
$unit = $unitVals[0];
$form->add('hidden', 'frequency_unit', $unit);
if (!empty($form->_values['is_recur_interval']) || $className == 'CRM_Contribute_Form_Contribution') {
$unit .= "(s)";
}
$form->assign('frequency_unit', $unit);
- } else {
- $form->assign('one_frequency_unit', false);
+ }
+ else {
+ $form->assign('one_frequency_unit', FALSE);
$units = array();
$frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units');
foreach ($unitVals as $key => $val) {
$frequencyUnit = &$form->add('select', 'frequency_unit', NULL, $units);
}
-
// FIXME: Ideally we should freeze select box if there is only
// one option but looks there is some problem /w QF freeze.
//if ( count( $units ) == 1 ) {
/**
* Global form rule
*
- * @param array $fields the input form values
- * @param array $files the uploaded files if any
+ * @param array $fields
+ * The input form values.
+ * @param array $files
+ * The uploaded files if any.
* @param $self
*
*
- * @return true if no errors, else array of errors
- * @access public
- * @static
+ * @return bool|array
+ * true if no errors, else array of errors
*/
- static function formRule($fields, $files, $self) {
+ public static function formRule($fields, $files, $self) {
$errors = array();
$amount = self::computeAmount($fields, $self);
if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
$previousId = $priceField->id;
- if ($priceField->name == 'membership_amount' && !$priceField->is_active ) {
+ if ($priceField->name == 'membership_amount' && !$priceField->is_active) {
$membershipIsActive = FALSE;
}
}
if ($priceField->name == 'other_amount') {
if ($self->_quickConfig && empty($fields["price_{$priceField->id}"]) &&
- array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])) {
+ array_key_exists("price_{$previousId}", $fields) && isset($fields["price_{$previousId}"]) && $self->_values['fee'][$previousId]['name'] == 'contribution_amount' && empty($fields["price_{$previousId}"])
+ ) {
$otherAmount = $priceField->id;
}
elseif (!empty($fields["price_{$priceField->id}"])) {
$otherAmountVal = CRM_Utils_Rule::cleanMoney($fields["price_{$priceField->id}"]);
- $min = CRM_Utils_Array::value('min_amount', $self->_values);
- $max = CRM_Utils_Array::value('max_amount', $self->_values);
+ $min = CRM_Utils_Array::value('min_amount', $self->_values);
+ $max = CRM_Utils_Array::value('max_amount', $self->_values);
if ($min && $otherAmountVal < $min) {
$errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1',
- array(1 => $min)
+ array(1 => $min)
);
}
if ($max && $otherAmountVal > $max) {
$errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.',
- array(1 => $max)
+ array(1 => $max)
);
}
}
}
if (!empty($fields["price_{$priceField->id}"]) || ($previousId == $priceField->id && isset($fields["price_{$previousId}"])
- && empty($fields["price_{$previousId}"]))) {
+ && empty($fields["price_{$previousId}"]))
+ ) {
$check[] = $priceField->id;
}
}
if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
if (!is_array($fields['price_' . $fieldKey])) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$fields['price_' . $fieldKey]])
- && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)) {
+ && in_array($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'], $currentMemberships)
+ ) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
}
}
else {
foreach ($fields['price_' . $fieldKey] as $key => $ignore) {
if (array_key_exists('membership_type_id', $fieldValue['options'][$key])
- && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)) {
+ && in_array($fieldValue['options'][$key]['membership_type_id'], $currentMemberships)
+ ) {
$errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$key]['membership_type_id'])));
}
}
// CRM-12233
if ($membershipIsActive && !$self->_membershipBlock['is_required']
- && $self->_values['amount_block_is_active']) {
+ && $self->_values['amount_block_is_active']
+ ) {
$membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
// if 'No thank you' membership is selected then set $membershipFieldId
$errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
}
}
- if($otherAmount && !empty($check)) {
+ if ($otherAmount && !empty($check)) {
$errors["price_{$otherAmount}"] = ts('Amount is required field.');
}
}
if (isset($fields['selectProduct']) &&
- $fields['selectProduct'] != 'no_thanks') {
+ $fields['selectProduct'] != 'no_thanks'
+ ) {
$productDAO = new CRM_Contribute_DAO_Product();
$productDAO->id = $fields['selectProduct'];
$productDAO->find(TRUE);
}
if (!empty($fields['is_recur']) &&
- CRM_Utils_Array::value('payment_processor', $fields) == 0) {
+ CRM_Utils_Array::value('payment_processor', $fields) == 0
+ ) {
$errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
}
if (!empty($self->_paymentFields)) {
CRM_Core_Form::validateMandatoryFields($self->_paymentFields, $fields, $errors);
}
- CRM_Core_Payment_Form::validatePaymentInstrument($fields, $errors, $self);
+ CRM_Core_Payment_Form::validateCreditCard($fields, $errors);
foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
if ($greetingType = CRM_Utils_Array::value($greeting, $fields)) {
$customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
if ($customizedValue == $greetingType && empty($fielse[$greeting . '_custom'])) {
$errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.',
- array(1 => ucwords(str_replace('_', " ", $greeting)))
+ array(1 => ucwords(str_replace('_', " ", $greeting)))
);
}
}
/**
* Process the form submission
*
- * @access public
*
* @return void
*/
if (($this->_values['is_pay_later'] &&
empty($this->_paymentProcessor) &&
!array_key_exists('hidden_processor', $params)) ||
- (!empty($params['payment_processor']) && $params['payment_processor'] == 0)) {
+ (!empty($params['payment_processor']) && $params['payment_processor'] == 0)
+ ) {
$params['is_pay_later'] = 1;
}
else {
$is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config');
if ($is_quick_config) {
foreach ($this->_priceSet['fields'] as $fieldKey => $fieldVal) {
- if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey ])) {
- $fieldId = $fieldVal['id'];
+ if ($fieldVal['name'] == 'membership_amount' && !empty($params['price_' . $fieldKey])) {
+ $fieldId = $fieldVal['id'];
$fieldOption = $params['price_' . $fieldId];
$proceFieldAmount += $fieldVal['options'][$this->_submitValues['price_' . $fieldId]]['amount'];
- $memPresent = TRUE;
+ $memPresent = TRUE;
}
else {
if (!empty($params['price_' . $fieldKey]) && $memPresent && ($fieldVal['name'] == 'other_amount' || $fieldVal['name'] == 'contribution_amount')) {
}
}
}
-
+
if (!isset($params['amount_other'])) {
$this->set('amount_level', CRM_Utils_Array::value('amount_level', $params));
}
if ($priceSetId = CRM_Utils_Array::value('priceSetId', $params)) {
$lineItem = array();
- $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config' );
- if ( $is_quick_config ) {
- foreach ( $this->_values['fee'] as $key => & $val ) {
- if ( $val['name'] == 'other_amount' && $val['html_type'] == 'Text' && array_key_exists( 'price_'.$key, $params ) ) {
- $params['price_'.$key] = CRM_Utils_Rule::cleanMoney($params['price_'.$key]); //Clean out any currency symbols
- if ( $params['price_'.$key] != 0 ) {
- foreach ( $val['options'] as $optionKey => & $options ) {
- $options['amount'] = CRM_Utils_Array::value( 'price_'.$key, $params );
+ $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
+ if ($is_quick_config) {
+ foreach ($this->_values['fee'] as $key => & $val) {
+ if ($val['name'] == 'other_amount' && $val['html_type'] == 'Text' && array_key_exists('price_' . $key, $params)) {
+ $params['price_' . $key] = CRM_Utils_Rule::cleanMoney($params['price_' . $key]); //Clean out any currency symbols
+ if ($params['price_' . $key] != 0) {
+ foreach ($val['options'] as $optionKey => & $options) {
+ $options['amount'] = CRM_Utils_Array::value('price_' . $key, $params);
break;
}
}
- $params['price_'.$key] = 1;
+ $params['price_' . $key] = 1;
break;
}
}
if ($this->_membershipBlock['is_separate_payment'] && !empty($params['separate_amount'])) {
$this->set('amount', $params['separate_amount']);
- } else {
+ }
+ else {
$this->set('amount', $params['amount']);
}
$buttonName = $this->controller->getButtonName();
if (in_array($buttonName,
array($this->_expressButtonName, $this->_expressButtonName . '_x', $this->_expressButtonName . '_y')
- ) && empty($params['is_pay_later'])) {
+ ) && empty($params['is_pay_later'])
+ ) {
$this->set('contributeMode', 'express');
- $donateURL = CRM_Utils_System::url('civicrm/contribute', '_qf_Contribute_display=1');
+ $donateURL = CRM_Utils_System::url('civicrm/contribute', '_qf_Contribute_display=1');
$params['cancelURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
$params['returnURL'] = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Confirm_display=1&rfp=1&qfKey={$params['qfKey']}", TRUE, NULL, FALSE);
$params['invoiceID'] = $invoiceID;
// redirect to thank you page
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey=$qfKey", TRUE, NULL, FALSE));
}
-
+
}
/**
* @param CRM_Contribute_Form_Contribution_Main|CRM_Event_Form_Registration_Register $form
* @param bool $noFees
*/
- static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
+ public static function preProcessPaymentOptions(&$form, $noFees = FALSE) {
$form->_snippet = CRM_Utils_Array::value('snippet', $_GET);
$form->_paymentProcessors = $noFees ? array() : $form->get('paymentProcessors');
$form->assign('paymentProcessorID', $form->_paymentProcessorID);
}
}
-