/** * Function for validation * * @param array $params (ref.) an assoc array of name/value pairs * * @return mixed true or array of errors * @access public * @static */ public function formRule($params, $files, $self) { $errors = array(); $priceSetId = CRM_Utils_Array::value('price_set_id', $params); if ($priceSetId) { CRM_Price_BAO_Field::priceSetValidation($priceSetId, $params, $errors); $priceFieldIDS = array(); foreach ($self->_priceSet['fields'] as $priceIds => $dontCare) { if (!empty($params['price_' . $priceIds])) { if (is_array($params['price_' . $priceIds])) { foreach ($params['price_' . $priceIds] as $priceFldVal => $isSet) { if ($isSet) { $priceFieldIDS[] = $priceFldVal; } } } else { $priceFieldIDS[] = $params['price_' . $priceIds]; } } } if (!empty($priceFieldIDS)) { $ids = implode(',', $priceFieldIDS); $count = CRM_Price_BAO_Set::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_FieldValue', $priceFieldId, 'membership_type_id')) { $self->_memTypeSelected[$id] = $id; } } } } elseif (!CRM_Utils_Array::value(1, $params['membership_type_id'])) { $errors['membership_type_id'] = ts('Please select a membership type.'); } else { $self->_memTypeSelected[] = $params['membership_type_id'][1]; } // 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.'); } } } //check if contact is selected in standalone mode if (isset($params['contact_select_id'][1]) && !$params['contact_select_id'][1]) { $errors['contact[1]'] = ts('Please select a contact or create new contact'); } if (!empty($errors)) { return $errors; } if ($priceSetId && !$self->_mode && !CRM_Utils_Array::value('record_contribution', $params)) { $errors['record_contribution'] = ts('Record Membership Payment is required when you using price set.'); } if (CRM_Utils_Array::value('payment_processor_id', $params)) { // make sure that credit card number and cvv are valid if (CRM_Utils_Array::value('credit_card_type', $params)) { if (CRM_Utils_Array::value('credit_card_number', $params) && !CRM_Utils_Rule::creditCardNumber($params['credit_card_number'], $params['credit_card_type'])) { $errors['credit_card_number'] = ts("Please enter a valid Credit Card Number"); } if (CRM_Utils_Array::value('cvv2', $params) && !CRM_Utils_Rule::cvv($params['cvv2'], $params['credit_card_type'])) { $errors['cvv2'] = ts("Please enter a valid Credit Card Verification Number"); } } } $joinDate = NULL; if (CRM_Utils_Array::value('join_date', $params)) { $joinDate = CRM_Utils_Date::processDate($params['join_date']); foreach ($self->_memTypeSelected as $memType) { $startDate = NULL; if (CRM_Utils_Array::value('start_date', $params)) { $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 // If selected membership type has duration unit as 'lifetime' // and end date is set, then give error $endDate = NULL; if (CRM_Utils_Array::value('end_date', $params)) { $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') { $errors['end_date'] = ts('The selected Membership Type has a lifetime duration. You cannot specify an End Date for lifetime memberships. Please clear the End Date OR select a different Membership Type.'); } 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 (!CRM_Utils_Array::value('is_override', $params) && !isset($errors['_qf_default'])) { $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($startDate, $endDate, $joinDate, 'today', TRUE); 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); } } } } else { $errors['join_date'] = ts('Please enter the Member Since.'); } if (isset($params['is_override']) && $params['is_override'] && !CRM_Utils_Array::value('status_id', $params)) { $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['contribution_type_id']) { $errors['contribution_type_id'] = ts('Please enter the contribution 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 && CRM_Utils_Array::value('record_contribution', $params) && 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; }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $options additional user data * * @return true if no errors, else array of errors * @access public * @static */ static function formRule($fields, $files, $self) { $errors = array(); //check if contact is selected in standalone mode if (isset($fields['contact_select_id'][1]) && !$fields['contact_select_id'][1]) { $errors['contact[1]'] = ts('Please select a contact or create new contact'); } if (isset($fields['honor_type_id'])) { if (!(CRM_Utils_Array::value('honor_first_name', $fields) && CRM_Utils_Array::value('honor_last_name', $fields) || CRM_Utils_Array::value('honor_email', $fields))) { $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.'); } } //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.'); } } // do the amount validations. if (!CRM_Utils_Array::value('total_amount', $fields) && empty($self->_lineItems)) { if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) { CRM_Price_BAO_Field::priceSetValidation($priceSetId, $fields, $errors); } } // if honor roll fields are populated but no PCP is selected if (!CRM_Utils_Array::value('pcp_made_through_id', $fields)) { if (CRM_Utils_Array::value('pcp_display_in_roll', $fields) || CRM_Utils_Array::value('pcp_roll_nickname', $fields) || CRM_Utils_Array::value('pcp_personal_note', $fields)) { $errors['pcp_made_through'] = ts('Please select a Personal Campaign Page, OR uncheck Display in Honor Roll and clear both the Honor Roll Name and the Personal Note field.'); } } return $errors; }
/** * global validation rules for the form * * @param array $fields posted values of the form * * @return array list of errors to be posted back to the form * @static * @access 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; } //check if contact is selected in standalone mode if (isset($values['contact_select_id'][1]) && !$values['contact_select_id'][1]) { $errorMsg['contact[1]'] = ts('Please select a contact or create new contact'); } if (CRM_Utils_Array::value('payment_processor_id', $values)) { // make sure that credit card number and cvv are valid require_once 'CRM/Utils/Rule.php'; if (CRM_Utils_Array::value('credit_card_type', $values)) { if (CRM_Utils_Array::value('credit_card_number', $values) && !CRM_Utils_Rule::creditCardNumber($values['credit_card_number'], $values['credit_card_type'])) { $errorMsg['credit_card_number'] = ts("Please enter a valid Credit Card Number"); } if (CRM_Utils_Array::value('cvv2', $values) && !CRM_Utils_Rule::cvv($values['cvv2'], $values['credit_card_type'])) { $errorMsg['cvv2'] = ts("Please enter a valid Credit Card Verification Number"); } } } if (CRM_Utils_Array::value('record_contribution', $values) && !CRM_Utils_Array::value('contribution_type_id', $values)) { $errorMsg['contribution_type_id'] = ts("Please enter the associated Contribution Type"); } // validate contribution status for 'Failed'. if ($self->_onlinePendingContributionId && CRM_Utils_Array::value('record_contribution', $values) && 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 && !CRM_Utils_Array::value('total_amount', $values) && empty($self->_values['line_items']) || $self->_id && !$self->_paymentId && is_array($self->_values['line_items'])) { if ($priceSetId = CRM_Utils_Array::value('priceSetId', $values)) { require_once 'CRM/Price/BAO/Field.php'; CRM_Price_BAO_Field::priceSetValidation($priceSetId, $values, $errorMsg); } } return CRM_Utils_Array::crmIsEmptyArray($errorMsg) ? true : $errorMsg; }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $options additional user data * * @return true if no errors, else array of errors * @access public * @static */ static function formRule(&$fields, &$files, $self) { $errors = array(); //check if contact is selected in standalone mode if (isset($fields['contact_select_id']) && !$fields['contact_select_id']) { $errors['contact'] = ts('Please select a contact or create new contact'); } if (isset($fields["honor_type_id"])) { if (!(CRM_Utils_Array::value('honor_first_name', $fields) && CRM_Utils_Array::value('honor_last_name', $fields) || CRM_Utils_Array::value('honor_email', $fields))) { $errors['honor_first_name'] = ts('Honor First Name and Last Name OR an email should be set.'); } } //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.'); } } // do the amount validations. if (!CRM_Utils_Array::value('total_amount', $fields) && empty($self->_lineItems)) { if ($priceSetId = CRM_Utils_Array::value('price_set_id', $fields)) { require_once 'CRM/Price/BAO/Field.php'; CRM_Price_BAO_Field::priceSetValidation($priceSetId, $fields, $errors); } else { $errors['total_amount'] = ts('Please enter a valid amount.'); } } return $errors; }