예제 #1
0
 /**
  * Global validation rules for the form.
  *
  * @param array $values
  *   Posted values of the form.
  * @param $files
  * @param $self
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRule($values, $files, $self)
 {
     // If $values['_qf_Participant_next'] is Delete or
     // $values['event_id'] is empty, then return
     // instead of proceeding further.
     if (CRM_Utils_Array::value('_qf_Participant_next', $values) == 'Delete' || !$values['event_id']) {
         return TRUE;
     }
     $errorMsg = array();
     if (!empty($values['payment_processor_id'])) {
         // make sure that payment instrument values (e.g. credit card number and cvv) are valid
         CRM_Core_Payment_Form::validatePaymentInstrument($values['payment_processor_id'], $values, $errorMsg, NULL);
     }
     if (!empty($values['record_contribution'])) {
         if (empty($values['financial_type_id'])) {
             $errorMsg['financial_type_id'] = ts('Please enter the associated Financial Type');
         }
         if (empty($values['payment_instrument_id'])) {
             $errorMsg['payment_instrument_id'] = ts('Payment Method is a required field.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && !empty($values['record_contribution']) && CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errorMsg['contribution_status_id'] = ts('Please select a valid payment status before updating.');
     }
     // do the amount validations.
     //skip for update mode since amount is freeze, CRM-6052
     if (!$self->_id && empty($values['total_amount']) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && isset($self->_values['line_items']) && is_array($self->_values['line_items'])) {
         if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $values, $errorMsg, TRUE);
         }
     }
     // For single additions - show validation error if the contact has already been registered
     // for this event with the same role.
     if ($self->_single && $self->_action & CRM_Core_Action::ADD) {
         $contactId = $self->_contactId;
         $eventId = CRM_Utils_Array::value('event_id', $values);
         if (!empty($contactId) && !empty($eventId)) {
             $dupeCheck = new CRM_Event_BAO_Participant();
             $dupeCheck->contact_id = $contactId;
             $dupeCheck->event_id = $eventId;
             $dupeCheck->find(TRUE);
             if (!empty($dupeCheck->id)) {
                 $errorMsg['event_id'] = ts("This contact has already been assigned to this event.");
             }
         }
     }
     return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? TRUE : $errorMsg;
 }
예제 #2
0
 /**
  * Validation.
  *
  * @param array $params
  *   (ref.) an assoc array of name/value pairs.
  *
  * @param $files
  * @param $self
  *
  * @throws CiviCRM_API3_Exception
  * @return bool|array
  *   mixed true or array of errors
  */
 public static function formRule($params, $files, $self)
 {
     $errors = array();
     $priceSetId = CRM_Utils_Array::value('price_set_id', $params);
     if ($priceSetId) {
         CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $params, $errors);
         $priceFieldIDS = array();
         foreach ($self->_priceSet['fields'] as $priceIds => $field) {
             if (!empty($params['price_' . $priceIds])) {
                 if (is_array($params['price_' . $priceIds])) {
                     foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) {
                         if ($isSet) {
                             $priceFieldIDS[] = $priceFldVal;
                         }
                     }
                 } elseif (!$field['is_enter_qty']) {
                     $priceFieldIDS[] = $params['price_' . $priceIds];
                 }
             }
         }
         if (!empty($priceFieldIDS)) {
             $ids = implode(',', $priceFieldIDS);
             $count = CRM_Price_BAO_PriceSet::getMembershipCount($ids);
             foreach ($count as $id => $occurance) {
                 if ($occurance > 1) {
                     $errors['_qf_default'] = ts('Select at most one option associated with the same membership type.');
                 }
             }
             foreach ($priceFieldIDS as $priceFieldId) {
                 if ($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) {
                     $self->_memTypeSelected[$id] = $id;
                 }
             }
         }
     } elseif (empty($params['membership_type_id'][1])) {
         $errors['membership_type_id'] = ts('Please select a membership type.');
     } else {
         $self->_memTypeSelected[] = $params['membership_type_id'][1];
     }
     if (!$priceSetId) {
         $numterms = CRM_Utils_Array::value('num_terms', $params);
         if ($numterms && intval($numterms) != $numterms) {
             $errors['num_terms'] = ts('Please enter an integer for the number of terms.');
         }
     }
     // Return error if empty $self->_memTypeSelected
     if ($priceSetId && empty($errors) && empty($self->_memTypeSelected)) {
         $errors['_qf_default'] = ts('Select at least one membership option.');
     }
     if (!empty($errors) && count($self->_memTypeSelected) > 1) {
         $memberOfContacts = CRM_Member_BAO_MembershipType::getMemberOfContactByMemTypes($self->_memTypeSelected);
         $duplicateMemberOfContacts = array_count_values($memberOfContacts);
         foreach ($duplicateMemberOfContacts as $countDuplicate) {
             if ($countDuplicate > 1) {
                 $errors['_qf_default'] = ts('Please do not select more than one membership associated with the same organization.');
             }
         }
     }
     if (!empty($errors)) {
         return $errors;
     }
     if ($priceSetId && !$self->_mode && empty($params['record_contribution'])) {
         $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.');
     }
     if (!$priceSetId && $self->_mode && empty($params['financial_type_id'])) {
         $errors['financial_type_id'] = ts('Please enter the financial Type.');
     }
     if (!empty($params['record_contribution']) && empty($params['payment_instrument_id'])) {
         $errors['payment_instrument_id'] = ts('Paid By is a required field.');
     }
     if (!empty($params['is_different_contribution_contact'])) {
         if (empty($params['soft_credit_type_id'])) {
             $errors['soft_credit_type_id'] = ts('Please Select a Soft Credit Type');
         }
         if (empty($params['soft_credit_contact_id'])) {
             $errors['soft_credit_contact_id'] = ts('Please select a contact');
         }
     }
     if (!empty($params['payment_processor_id'])) {
         // validate payment instrument (e.g. credit card number)
         CRM_Core_Payment_Form::validatePaymentInstrument($params['payment_processor_id'], $params, $errors, $self);
     }
     $joinDate = NULL;
     if (!empty($params['join_date'])) {
         $joinDate = CRM_Utils_Date::processDate($params['join_date']);
         foreach ($self->_memTypeSelected as $memType) {
             $startDate = NULL;
             if (!empty($params['start_date'])) {
                 $startDate = CRM_Utils_Date::processDate($params['start_date']);
             }
             // if end date is set, ensure that start date is also set
             // and that end date is later than start date
             $endDate = NULL;
             if (!empty($params['end_date'])) {
                 $endDate = CRM_Utils_Date::processDate($params['end_date']);
             }
             $membershipDetails = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($memType);
             if ($startDate && CRM_Utils_Array::value('period_type', $membershipDetails) == 'rolling') {
                 if ($startDate < $joinDate) {
                     $errors['start_date'] = ts('Start date must be the same or later than Member since.');
                 }
             }
             if ($endDate) {
                 if ($membershipDetails['duration_unit'] == 'lifetime') {
                     // Check if status is NOT cancelled or similar. For lifetime memberships, there is no automated
                     // process to update status based on end-date. The user must change the status now.
                     $result = civicrm_api3('MembershipStatus', 'get', array('sequential' => 1, 'is_current_member' => 0));
                     $tmp_statuses = $result['values'];
                     $status_ids = array();
                     foreach ($tmp_statuses as $cur_stat) {
                         $status_ids[] = $cur_stat['id'];
                     }
                     if (empty($params['status_id']) || in_array($params['status_id'], $status_ids) == FALSE) {
                         $errors['status_id'] = ts('Please enter a status that does NOT represent a current membership status.');
                         $errors['is_override'] = ts('This must be checked because you set an End Date for a lifetime membership');
                     }
                 } else {
                     if (!$startDate) {
                         $errors['start_date'] = ts('Start date must be set if end date is set.');
                     }
                     if ($endDate < $startDate) {
                         $errors['end_date'] = ts('End date must be the same or later than start date.');
                     }
                 }
             }
             //  Default values for start and end dates if not supplied
             //  on the form
             $defaultDates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($memType, $joinDate, $startDate, $endDate);
             if (!$startDate) {
                 $startDate = CRM_Utils_Array::value('start_date', $defaultDates);
             }
             if (!$endDate) {
                 $endDate = CRM_Utils_Array::value('end_date', $defaultDates);
             }
             //CRM-3724, check for availability of valid membership status.
             if (empty($params['is_override']) && !isset($errors['_qf_default'])) {
                 $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', TRUE, $memType, $params);
                 if (empty($calcStatus)) {
                     $url = CRM_Utils_System::url('civicrm/admin/member/membershipStatus', 'reset=1&action=browse');
                     $errors['_qf_default'] = ts('There is no valid Membership Status available for selected membership dates.');
                     $status = ts('Oops, it looks like there is no valid membership status available for the given membership dates. You can <a href="%1">Configure Membership Status Rules</a>.', array(1 => $url));
                     if (!$self->_mode) {
                         $status .= ' ' . ts('OR You can sign up by setting Status Override? to true.');
                     }
                     CRM_Core_Session::setStatus($status, ts('Membership Status Error'), 'error');
                 }
             }
         }
     } else {
         $errors['join_date'] = ts('Please enter the Member Since.');
     }
     if (isset($params['is_override']) && $params['is_override'] && empty($params['status_id'])) {
         $errors['status_id'] = ts('Please enter the status.');
     }
     //total amount condition arise when membership type having no
     //minimum fee
     if (isset($params['record_contribution'])) {
         if (!$params['financial_type_id']) {
             $errors['financial_type_id'] = ts('Please enter the financial Type.');
         }
         if (CRM_Utils_System::isNull($params['total_amount'])) {
             $errors['total_amount'] = ts('Please enter the contribution.');
         }
     }
     // validate contribution status for 'Failed'.
     if ($self->_onlinePendingContributionId && !empty($params['record_contribution']) && CRM_Utils_Array::value('contribution_status_id', $params) == array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'))) {
         $errors['contribution_status_id'] = ts('Please select a valid payment status before updating.');
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #3
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     // Check for Credit Card Contribution.
     if ($self->_mode) {
         if (empty($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Payment Processor is a required field.');
         } else {
             // validate payment instrument (e.g. credit card number)
             CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, NULL);
         }
     }
     // Do the amount validations.
     if (empty($fields['total_amount']) && empty($self->_lineItems)) {
         if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) {
             CRM_Price_BAO_PriceField::priceSetValidation($priceSetId, $fields, $errors);
         }
     }
     $softErrors = CRM_Contribute_Form_SoftCredit::formRule($fields, $errors, $self);
     if (!empty($fields['total_amount']) && (!empty($fields['net_amount']) || !empty($fields['fee_amount']))) {
         $sum = CRM_Utils_Rule::cleanMoney($fields['net_amount']) + CRM_Utils_Rule::cleanMoney($fields['fee_amount']);
         // For taxable contribution we need to deduct taxable amount from
         // (net amount + fee amount) before comparing it with total amount
         if (!empty($self->_values['tax_amount'])) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($self->_id);
             if (!(CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails))) {
                 $sum = CRM_Utils_Money::format($sum - $self->_values['tax_amount'], NULL, '%a');
             }
         }
         if (CRM_Utils_Rule::cleanMoney($fields['total_amount']) != $sum) {
             $errors['total_amount'] = ts('The sum of fee amount and net amount must be equal to total amount');
         }
     }
     //CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
     CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors);
     // Form rule for status http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id']) {
         CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors);
     }
     // CRM-16015, add form-rule to restrict change of financial type if using price field of different financial type
     if ($self->_action & CRM_Core_Action::UPDATE && $self->_id && $self->_values['financial_type_id'] != $fields['financial_type_id']) {
         CRM_Contribute_BAO_Contribution::checkFinancialTypeChange(NULL, $self->_id, $errors);
     }
     //FIXME FOR NEW DATA FLOW http://wiki.civicrm.org/confluence/display/CRM/CiviAccounts+4.3+Data+Flow
     if (!empty($fields['fee_amount']) && !empty($fields['financial_type_id']) && ($financialType = CRM_Contribute_BAO_Contribution::validateFinancialType($fields['financial_type_id']))) {
         $errors['financial_type_id'] = ts("Financial Account of account relationship of 'Expense Account is' is not configured for Financial Type : ") . $financialType;
     }
     // $trxn_id must be unique CRM-13919
     if (!empty($fields['trxn_id'])) {
         $queryParams = array(1 => array($fields['trxn_id'], 'String'));
         $query = 'select count(*) from civicrm_contribution where trxn_id = %1';
         if ($self->_id) {
             $queryParams[2] = array((int) $self->_id, 'Integer');
             $query .= ' and id !=%2';
         }
         $tCnt = CRM_Core_DAO::singleValueQuery($query, $queryParams);
         if ($tCnt) {
             $errors['trxn_id'] = ts('Transaction ID\'s must be unique. Transaction \'%1\' already exists in your database.', array(1 => $fields['trxn_id']));
         }
     }
     $errors = array_merge($errors, $softErrors);
     return $errors;
 }
예제 #4
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param CRM_Core_Form $self
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     $amount = self::computeAmount($fields, $self->_values);
     if (CRM_Utils_Array::value('auto_renew', $fields) && CRM_Utils_Array::value('payment_processor_id', $fields) == 0) {
         $errors['auto_renew'] = ts('You cannot have auto-renewal on if you are paying later.');
     }
     if (!empty($fields['selectMembership']) && $fields['selectMembership'] != 'no_thanks' || !empty($fields['priceSetId']) && $self->_useForMember) {
         $isTest = $self->_action & CRM_Core_Action::PREVIEW ? TRUE : FALSE;
         $lifeMember = CRM_Member_BAO_Membership::getAllContactMembership($self->_membershipContactID, $isTest, TRUE);
         $membershipOrgDetails = CRM_Member_BAO_MembershipType::getMembershipTypeOrganization();
         $unallowedOrgs = array();
         foreach (array_keys($lifeMember) as $memTypeId) {
             $unallowedOrgs[] = $membershipOrgDetails[$memTypeId];
         }
     }
     //check for atleast one pricefields should be selected
     if (!empty($fields['priceSetId']) && empty($self->_ccid)) {
         $priceField = new CRM_Price_DAO_PriceField();
         $priceField->price_set_id = $fields['priceSetId'];
         $priceField->orderBy('weight');
         $priceField->find();
         $check = array();
         $membershipIsActive = TRUE;
         $previousId = $otherAmount = FALSE;
         while ($priceField->fetch()) {
             if ($self->_quickConfig && ($priceField->name == 'contribution_amount' || $priceField->name == 'membership_amount')) {
                 $previousId = $priceField->id;
                 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}"])) {
                     $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);
                     if ($min && $otherAmountVal < $min) {
                         $errors["price_{$priceField->id}"] = ts('Contribution amount must be at least %1', array(1 => $min));
                     }
                     if ($max && $otherAmountVal > $max) {
                         $errors["price_{$priceField->id}"] = ts('Contribution amount cannot be more than %1.', array(1 => $max));
                     }
                 }
             }
             if (!empty($fields["price_{$priceField->id}"]) || $previousId == $priceField->id && isset($fields["price_{$previousId}"]) && empty($fields["price_{$previousId}"])) {
                 $check[] = $priceField->id;
             }
         }
         $currentMemberships = NULL;
         if ($membershipIsActive) {
             $is_test = $self->_mode != 'live' ? 1 : 0;
             $memContactID = $self->_membershipContactID;
             // For anonymous user check using dedupe rule
             // if user has Cancelled Membership
             if (!$memContactID) {
                 $dedupeParams = CRM_Dedupe_Finder::formatParams($fields, 'Individual');
                 $dedupeParams['check_permission'] = FALSE;
                 $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
                 // if we find more than one contact, use the first one
                 $memContactID = CRM_Utils_Array::value(0, $ids);
             }
             $currentMemberships = CRM_Member_BAO_Membership::getContactsCancelledMembership($memContactID, $is_test);
             $errorText = 'Your %1 membership was previously cancelled and can not be renewed online. Please contact the site administrator for assistance.';
             foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
                 if ($fieldValue['html_type'] != 'Text' && CRM_Utils_Array::value('price_' . $fieldKey, $fields)) {
                     if (!is_array($fields['price_' . $fieldKey]) && isset($fieldValue['options'][$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)) {
                             $errors['price_' . $fieldKey] = ts($errorText, array(1 => CRM_Member_PseudoConstant::membershipType($fieldValue['options'][$fields['price_' . $fieldKey]]['membership_type_id'])));
                         }
                     } else {
                         if (is_array($fields['price_' . $fieldKey])) {
                             foreach (array_keys($fields['price_' . $fieldKey]) as $key) {
                                 if (array_key_exists('membership_type_id', $fieldValue['options'][$key]) && 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']) {
             $membershipFieldId = $contributionFieldId = $errorKey = $otherFieldId = NULL;
             foreach ($self->_values['fee'] as $fieldKey => $fieldValue) {
                 // if 'No thank you' membership is selected then set $membershipFieldId
                 if ($fieldValue['name'] == 'membership_amount' && CRM_Utils_Array::value('price_' . $fieldKey, $fields) == 0) {
                     $membershipFieldId = $fieldKey;
                 } elseif ($membershipFieldId) {
                     if ($fieldValue['name'] == 'other_amount') {
                         $otherFieldId = $fieldKey;
                     } elseif ($fieldValue['name'] == 'contribution_amount') {
                         $contributionFieldId = $fieldKey;
                     }
                     if (!$errorKey || CRM_Utils_Array::value('price_' . $contributionFieldId, $fields) == '0') {
                         $errorKey = $fieldKey;
                     }
                 }
             }
             // $membershipFieldId is set and additional amount is 'No thank you' or NULL then throw error
             if ($membershipFieldId && !(CRM_Utils_Array::value('price_' . $contributionFieldId, $fields, -1) > 0) && empty($fields['price_' . $otherFieldId])) {
                 $errors["price_{$errorKey}"] = ts('Additional Contribution is required.');
             }
         }
         if (empty($check) && empty($self->_ccid)) {
             if ($self->_useForMember == 1 && $membershipIsActive) {
                 $errors['_qf_default'] = ts('Select at least one option from Membership Type(s).');
             } else {
                 $errors['_qf_default'] = ts('Select at least one option from Contribution(s).');
             }
         }
         if ($otherAmount && !empty($check)) {
             $errors["price_{$otherAmount}"] = ts('Amount is required field.');
         }
         if ($self->_useForMember == 1 && !empty($check) && $membershipIsActive) {
             $priceFieldIDS = array();
             $priceFieldMemTypes = array();
             foreach ($self->_priceSet['fields'] as $priceId => $value) {
                 if (!empty($fields['price_' . $priceId]) || $self->_quickConfig && $value['name'] == 'membership_amount' && empty($self->_membershipBlock['is_required'])) {
                     if (!empty($fields['price_' . $priceId]) && is_array($fields['price_' . $priceId])) {
                         foreach ($fields['price_' . $priceId] as $priceFldVal => $isSet) {
                             if ($isSet) {
                                 $priceFieldIDS[] = $priceFldVal;
                             }
                         }
                     } elseif (!$value['is_enter_qty'] && !empty($fields['price_' . $priceId])) {
                         // The check for {!$value['is_enter_qty']} is done since, quantity fields allow entering
                         // quantity. And the quantity can't be conisdered as civicrm_price_field_value.id, CRM-9577
                         $priceFieldIDS[] = $fields['price_' . $priceId];
                     }
                     if (!empty($value['options'])) {
                         foreach ($value['options'] as $val) {
                             if (!empty($val['membership_type_id']) && ($fields['price_' . $priceId] == $val['id'] || isset($fields['price_' . $priceId]) && !empty($fields['price_' . $priceId][$val['id']]))) {
                                 $priceFieldMemTypes[] = $val['membership_type_id'];
                             }
                         }
                     }
                 }
             }
             if (!empty($lifeMember)) {
                 foreach ($priceFieldIDS as $priceFieldId) {
                     if (($id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $priceFieldId, 'membership_type_id')) && in_array($membershipOrgDetails[$id], $unallowedOrgs)) {
                         $errors['_qf_default'] = ts('You already have a lifetime membership and cannot select a membership with a shorter term.');
                         break;
                     }
                 }
             }
             if (!empty($priceFieldIDS)) {
                 $ids = implode(',', $priceFieldIDS);
                 $priceFieldIDS['id'] = $fields['priceSetId'];
                 $self->set('memberPriceFieldIDS', $priceFieldIDS);
                 $count = CRM_Price_BAO_PriceSet::getMembershipCount($ids);
                 foreach ($count as $id => $occurrence) {
                     if ($occurrence > 1) {
                         $errors['_qf_default'] = ts('You have selected multiple memberships for the same organization or entity. Please review your selections and choose only one membership per entity. Contact the site administrator if you need assistance.');
                     }
                 }
             }
             if (empty($priceFieldMemTypes) && $self->_membershipBlock['is_required'] == 1) {
                 $errors['_qf_default'] = ts('Please select at least one membership option.');
             }
         }
         CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
         if ($fields['amount'] < 0) {
             $errors['_qf_default'] = ts('Contribution can not be less than zero. Please select the options accordingly');
         }
         $amount = $fields['amount'];
     }
     if (isset($fields['selectProduct']) && $fields['selectProduct'] != 'no_thanks') {
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $fields['selectProduct'];
         $productDAO->find(TRUE);
         $min_amount = $productDAO->min_contribution;
         if ($amount < $min_amount) {
             $errors['selectProduct'] = ts('The premium you have selected requires a minimum contribution of %1', array(1 => CRM_Utils_Money::format($min_amount)));
             CRM_Core_Session::setStatus($errors['selectProduct']);
         }
     }
     //CRM-16285 - Function to handle validation errors on form, for recurring contribution field.
     CRM_Contribute_BAO_ContributionRecur::validateRecurContribution($fields, $files, $self, $errors);
     if (!empty($fields['is_recur']) && CRM_Utils_Array::value('payment_processor_id', $fields) == 0) {
         $errors['_qf_default'] = ts('You cannot set up a recurring contribution if you are not paying online by credit card.');
     }
     // validate PCP fields - if not anonymous, we need a nick name value
     if ($self->_pcpId && !empty($fields['pcp_display_in_roll']) && CRM_Utils_Array::value('pcp_is_anonymous', $fields) == 0 && CRM_Utils_Array::value('pcp_roll_nickname', $fields) == '') {
         $errors['pcp_roll_nickname'] = ts('Please enter a name to include in the Honor Roll, or select \'contribute anonymously\'.');
     }
     // return if this is express mode
     $config = CRM_Core_Config::singleton();
     if ($self->_paymentProcessor && $self->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_BUTTON) {
         if (!empty($fields[$self->_expressButtonName . '_x']) || !empty($fields[$self->_expressButtonName . '_y']) || CRM_Utils_Array::value($self->_expressButtonName, $fields)) {
             return $errors;
         }
     }
     //validate the pledge fields.
     if (!empty($self->_values['pledge_block_id'])) {
         //validation for pledge payment.
         if (!empty($self->_values['pledge_id'])) {
             if (empty($fields['pledge_amount'])) {
                 $errors['pledge_amount'] = ts('At least one payment option needs to be checked.');
             }
         } elseif (!empty($fields['is_pledge'])) {
             if (CRM_Utils_Rule::positiveInteger(CRM_Utils_Array::value('pledge_installments', $fields)) == FALSE) {
                 $errors['pledge_installments'] = ts('Please enter a valid number of pledge installments.');
             } else {
                 if (CRM_Utils_Array::value('pledge_installments', $fields) == NULL) {
                     $errors['pledge_installments'] = ts('Pledge Installments is required field.');
                 } elseif (CRM_Utils_Array::value('pledge_installments', $fields) == 1) {
                     $errors['pledge_installments'] = ts('Pledges consist of multiple scheduled payments. Select one-time contribution if you want to make your gift in a single payment.');
                 } elseif (CRM_Utils_Array::value('pledge_installments', $fields) == 0) {
                     $errors['pledge_installments'] = ts('Pledge Installments field must be > 1.');
                 }
             }
             //validation for Pledge Frequency Interval.
             if (CRM_Utils_Rule::positiveInteger(CRM_Utils_Array::value('pledge_frequency_interval', $fields)) == FALSE) {
                 $errors['pledge_frequency_interval'] = ts('Please enter a valid Pledge Frequency Interval.');
             } else {
                 if (CRM_Utils_Array::value('pledge_frequency_interval', $fields) == NULL) {
                     $errors['pledge_frequency_interval'] = ts('Pledge Frequency Interval. is required field.');
                 } elseif (CRM_Utils_Array::value('pledge_frequency_interval', $fields) == 0) {
                     $errors['pledge_frequency_interval'] = ts('Pledge frequency interval field must be > 0');
                 }
             }
         }
     }
     // if the user has chosen a free membership or the amount is less than zero
     // i.e. we don't need to validate payment related fields or profiles.
     if ((double) $amount <= 0.0) {
         return $errors;
     }
     if (CRM_Utils_Array::value('payment_processor_id', $fields) == NULL) {
         $errors['payment_processor_id'] = ts('Payment Method is a required field.');
     } else {
         CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, !$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing');
     }
     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))));
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
 /**
  * @param $self
  * @param $fields
  *
  * @return bool
  */
 public function validatePaymentValues($self, $fields)
 {
     if (!empty($self->_params[0]['bypass_payment']) || $self->_allowWaitlist || empty($self->_fields) || CRM_Utils_Array::value('amount', $self->_params[0]) > 0) {
         return TRUE;
     }
     $validatePayement = FALSE;
     if (!empty($fields['priceSetId'])) {
         $lineItem = array();
         CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
         if ($fields['amount'] > 0) {
             $validatePayement = TRUE;
             // $self->_forcePayement = true;
             // return false;
         }
     } elseif (!empty($fields['amount']) && CRM_Utils_Array::value('value', $self->_values['fee'][$fields['amount']]) > 0) {
         $validatePayement = TRUE;
     }
     if (!$validatePayement) {
         return TRUE;
     }
     $errors = array();
     CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
     // validate supplied payment instrument values (e.g. credit card number and cvv)
     $payment_processor_id = $self->_params[0]['payment_processor'];
     CRM_Core_Payment_Form::validatePaymentInstrument($payment_processor_id, $self->_params[0], $errors, $self);
     if (!empty($errors)) {
         return FALSE;
     }
     foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) {
         if ($greetingType = CRM_Utils_Array::value($greeting, $self->_params[0])) {
             $customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
             if ($customizedValue == $greetingType && empty($self->_params[0][$greeting . '_custom'])) {
                 return FALSE;
             }
         }
     }
     return TRUE;
 }
예제 #6
0
 /**
  * @param $fields
  * @param $files
  * @param $self
  *
  * @return array|bool
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     if ($self->payment_required && empty($self->_submitValues['is_pay_later'])) {
         $payment = CRM_Core_Payment::singleton($self->_mode, $self->_paymentProcessor, CRM_Core_DAO::$_nullObject);
         $error = $payment->checkConfig($self->_mode);
         if ($error) {
             $errors['_qf_default'] = $error;
         }
         CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
         // validate payment instrument values (e.g. credit card number)
         CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessor['id'], $fields, $errors, $self);
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #7
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     //check that either an email or firstname+lastname is included in the form(CRM-9587)
     self::checkProfileComplete($fields, $errors, $self->_eventId);
     //To check if the user is already registered for the event(CRM-2426)
     if (!$self->_skipDupeRegistrationCheck) {
         self::checkRegistration($fields, $self);
     }
     //check for availability of registrations.
     if (!$self->_allowConfirmation && empty($fields['bypass_payment']) && is_numeric($self->_availableRegistrations) && CRM_Utils_Array::value('additional_participants', $fields) >= $self->_availableRegistrations) {
         $errors['additional_participants'] = ts("There is only enough space left on this event for %1 participant(s).", array(1 => $self->_availableRegistrations));
     }
     // during confirmation don't allow to increase additional participants, CRM-4320
     if ($self->_allowConfirmation && !empty($fields['additional_participants']) && is_array($self->_additionalParticipantIds) && $fields['additional_participants'] > count($self->_additionalParticipantIds)) {
         $errors['additional_participants'] = ts("Oops. It looks like you are trying to increase the number of additional people you are registering for. You can confirm registration for a maximum of %1 additional people.", array(1 => count($self->_additionalParticipantIds)));
     }
     //don't allow to register w/ waiting if enough spaces available.
     if (!empty($fields['bypass_payment']) && $self->_allowConfirmation) {
         if (!is_numeric($self->_availableRegistrations) || empty($fields['priceSetId']) && CRM_Utils_Array::value('additional_participants', $fields) < $self->_availableRegistrations) {
             $errors['bypass_payment'] = ts("Oops. There are enough available spaces in this event. You can not add yourself to the waiting list.");
         }
     }
     if (!empty($fields['additional_participants']) && !CRM_Utils_Rule::positiveInteger($fields['additional_participants'])) {
         $errors['additional_participants'] = ts('Please enter a whole number for Number of additional people.');
     }
     // priceset validations
     if (!empty($fields['priceSetId']) && !$self->_requireApproval && !$self->_allowWaitlist) {
         //format params.
         $formatted = self::formatPriceSetParams($self, $fields);
         $ppParams = array($formatted);
         $priceSetErrors = self::validatePriceSet($self, $ppParams);
         $primaryParticipantCount = self::getParticipantCount($self, $ppParams);
         //get price set fields errors in.
         $errors = array_merge($errors, CRM_Utils_Array::value(0, $priceSetErrors, array()));
         $totalParticipants = $primaryParticipantCount;
         if (!empty($fields['additional_participants'])) {
             $totalParticipants += $fields['additional_participants'];
         }
         if (empty($fields['bypass_payment']) && !$self->_allowConfirmation && is_numeric($self->_availableRegistrations) && $self->_availableRegistrations < $totalParticipants) {
             $errors['_qf_default'] = ts("Only %1 Registrations available.", array(1 => $self->_availableRegistrations));
         }
         $lineItem = array();
         CRM_Price_BAO_PriceSet::processAmount($self->_values['fee'], $fields, $lineItem);
         if ($fields['amount'] < 0) {
             $errors['_qf_default'] = ts('Event Fee(s) can not be less than zero. Please select the options accordingly');
         }
     }
     // @todo - can we remove the 'is_monetary' concept?
     if ($self->_values['event']['is_monetary']) {
         if (empty($self->_requireApproval) && !empty($fields['amount']) && $fields['amount'] > 0 && !isset($fields['payment_processor_id'])) {
             $errors['payment_processor_id'] = ts('Please select a Payment Method');
         }
         $isZeroAmount = $skipPaymentValidation = FALSE;
         if (!empty($fields['priceSetId'])) {
             if (CRM_Utils_Array::value('amount', $fields) == 0) {
                 $isZeroAmount = TRUE;
             }
         } elseif (!empty($fields['amount']) && (isset($self->_values['discount'][$fields['amount']]) && CRM_Utils_Array::value('value', $self->_values['discount'][$fields['amount']]) == 0)) {
             $isZeroAmount = TRUE;
         } elseif (!empty($fields['amount']) && (isset($self->_values['fee'][$fields['amount']]) && CRM_Utils_Array::value('value', $self->_values['fee'][$fields['amount']]) == 0)) {
             $isZeroAmount = TRUE;
         }
         if ($isZeroAmount && !($self->_forcePayement && !empty($fields['additional_participants']))) {
             $skipPaymentValidation = TRUE;
         }
         // also return if zero fees for valid members
         if (!empty($fields['bypass_payment']) || $skipPaymentValidation || !$self->_allowConfirmation && ($self->_requireApproval || $self->_allowWaitlist)) {
             return empty($errors) ? TRUE : $errors;
         }
         CRM_Core_Payment_Form::validatePaymentInstrument($fields['payment_processor_id'], $fields, $errors, !$self->_isBillingAddressRequiredForPayLater ? NULL : 'billing');
     }
     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($fields[$greeting . '_custom'])) {
                 $errors[$greeting . '_custom'] = ts('Custom %1 is a required field if %1 is of type Customized.', array(1 => ucwords(str_replace('_', ' ', $greeting))));
             }
         }
     }
     return empty($errors) ? TRUE : $errors;
 }
예제 #8
0
 /**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  * @param array $files
  *   The uploaded files if any.
  * @param $self
  *
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
     // validate the payment instrument values (e.g. credit card number)
     CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessor['id'], $fields, $errors, $self);
     return empty($errors) ? TRUE : $errors;
 }
예제 #9
0
 /**
  * @param $fields
  * @param $files
  * @param $self
  *
  * @return array|bool
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     if ($self->payment_required && empty($self->_submitValues['is_pay_later'])) {
         CRM_Core_Form::validateMandatoryFields($self->_fields, $fields, $errors);
         // validate payment instrument values (e.g. credit card number)
         CRM_Core_Payment_Form::validatePaymentInstrument($self->_paymentProcessor['id'], $fields, $errors, $self);
     }
     return empty($errors) ? TRUE : $errors;
 }