/** * Build the form object. * * @return void */ public function buildQuickForm() { // Register 'contact_1' model $entities = array(); $entities[] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); $allowCoreTypes = array_merge(array('Contact', 'Individual'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); // Register 'contribution_1' $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id'); $allowCoreTypes[] = 'Contribution'; //CRM-15427 $allowSubTypes['ContributionType'] = array($financialTypeId); $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => '*'); // If applicable, register 'membership_1' $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); if ($member && $member['is_active']) { //CRM-15427 $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => '*'); $allowCoreTypes[] = 'Membership'; $allowSubTypes['MembershipType'] = explode(',', $member['membership_types']); } //CRM-15427 $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); parent::buildQuickForm(); }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return void */ function setDefaultValues() { //parent::setDefaultValues(); $defaults = array(); if (isset($this->_id)) { $defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); } // for membership_types if (isset($defaults['membership_types'])) { $membershipType = explode(',', $defaults['membership_types']); $newMembershipType = array(); foreach ($membershipType as $k => $v) { $newMembershipType[$v] = 1; $defaults["auto_renew_{$v}"] = $defaults['auto_renew'][$v]; } $defaults['membership_type'] = $newMembershipType; } // Set Display Minimum Fee default to true if we are adding a new membership block if (!isset($defaults['id'])) { $defaults['display_min_fee'] = 1; } else { $this->assign('membershipBlockId', $defaults['id']); } return $defaults; }
/** * List memberships for the UF user. * */ public function listMemberships() { $membership = array(); $dao = new CRM_Member_DAO_Membership(); $dao->contact_id = $this->_contactId; $dao->is_test = 0; $dao->find(); while ($dao->fetch()) { $membership[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $membership[$dao->id]); //get the membership status and type values. $statusANDType = CRM_Member_BAO_Membership::getStatusANDTypeValues($dao->id); foreach (array('status', 'membership_type') as $fld) { $membership[$dao->id][$fld] = CRM_Utils_Array::value($fld, $statusANDType[$dao->id]); } if (!empty($statusANDType[$dao->id]['is_current_member'])) { $membership[$dao->id]['active'] = TRUE; } $membership[$dao->id]['renewPageId'] = CRM_Member_BAO_Membership::getContributionPageId($dao->id); if (!$membership[$dao->id]['renewPageId']) { // Membership payment was not done via online contribution page or free membership. Check for default membership renewal page from CiviMember Settings $defaultRenewPageId = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME, 'default_renewal_contribution_page'); if ($defaultRenewPageId) { //CRM-14831 - check if membership type is present in contrib page $memBlock = CRM_Member_BAO_Membership::getMembershipBlock($defaultRenewPageId); if (!empty($memBlock['membership_types'])) { $memTypes = explode(',', $memBlock['membership_types']); if (in_array($dao->membership_type_id, $memTypes)) { $membership[$dao->id]['renewPageId'] = $defaultRenewPageId; } } } else { switch ($membership[$dao->id]['membership_type_id']) { case "1": default: $membership[$dao->id]['renewPageId'] = 2; break; case "10": $membership[$dao->id]['renewPageId'] = 19; break; case "11": $membership[$dao->id]['renewPageId'] = 23; break; case "5": case "9": $membership[$dao->id]['renewPageId'] = 22; break; } } } } $activeMembers = CRM_Member_BAO_Membership::activeMembers($membership); $inActiveMembers = CRM_Member_BAO_Membership::activeMembers($membership, 'inactive'); $this->assign('activeMembers', $activeMembers); $this->assign('inActiveMembers', $inActiveMembers); }
/** * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * * @return void */ public function setDefaultValues() { //parent::setDefaultValues(); $defaults = array(); if (isset($this->_id)) { $defaults = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); } $defaults['member_is_active'] = $defaults['is_active']; // Set Display Minimum Fee default to true if we are adding a new membership block if (!isset($defaults['id'])) { $defaults['display_min_fee'] = 1; } else { $this->assign('membershipBlockId', $defaults['id']); } if ($this->_id && ($priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3, 1))) { $defaults['member_price_set_id'] = $priceSetId; $this->_memPriceSetId = $priceSetId; } else { // for membership_types // if ( isset( $defaults['membership_types'] ) ) { $priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, 3); $this->assign('isQuick', 1); $this->_memPriceSetId = $priceSetId; $pFIDs = array(); if ($priceSetId) { CRM_Core_DAO::commonRetrieveAll('CRM_Price_DAO_PriceField', 'price_set_id', $priceSetId, $pFIDs, $return = array('html_type', 'name', 'label')); foreach ($pFIDs as $pid => $pValue) { if ($pValue['html_type'] == 'Radio' && $pValue['name'] == 'membership_amount') { $defaults['mem_price_field_id'] = $pValue['id']; $defaults['membership_type_label'] = $pValue['label']; } } if (!empty($defaults['mem_price_field_id'])) { $options = array(); $priceFieldOptions = CRM_Price_BAO_PriceFieldValue::getValues($defaults['mem_price_field_id'], $options, 'id', 1); foreach ($options as $k => $v) { $newMembershipType[$v['membership_type_id']] = 1; if (!empty($defaults['auto_renew'])) { $defaults["auto_renew_" . $v['membership_type_id']] = $defaults['auto_renew'][$v['membership_type_id']]; } } $defaults['membership_type'] = $newMembershipType; } } } return $defaults; }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // current contribution page id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if (!$this->_id) { // seems like the session is corrupted and/or we lost the id trail // lets just bump this to a regular session error and redirect user to main page $this->controller->invalidKeyRedirect(); } // this was used prior to the cleverer this_>getContactID - unsure now $this->_userID = $session->get('userID'); $this->_contactID = $this->_membershipContactID = $this->getContactID(); $this->_mid = NULL; if ($this->_contactID) { $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this); if ($this->_mid) { $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_mid; if ($membership->find(TRUE)) { $this->_defaultMemTypeId = $membership->membership_type_id; if ($membership->contact_id != $this->_contactID) { $validMembership = FALSE; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID); if (!empty($employers) && array_key_exists($membership->contact_id, $employers)) { $this->_membershipContactID = $membership->contact_id; $this->assign('membershipContactID', $this->_membershipContactID); $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']); $validMembership = TRUE; } else { $membershipType = new CRM_Member_BAO_MembershipType(); $membershipType->id = $membership->membership_type_id; if ($membershipType->find(TRUE)) { // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values. // Convert to commma separated list. $inheritedRelTypes = implode(CRM_Utils_Array::explodePadded($membershipType->relationship_type_id), ','); $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id); if (array_key_exists($membership->contact_id, $permContacts)) { $this->_membershipContactID = $membership->contact_id; $validMembership = TRUE; } } } if (!$validMembership) { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert'); } } } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert'); } unset($membership); } } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', FALSE); // Contribution page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', TRUE); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); $this->assign('action', $this->_action); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); if (!$this->_values) { // get all the values from the dao object $this->_values = array(); $this->_fields = array(); CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); // check if form is active if (!CRM_Utils_Array::value('is_active', $this->_values)) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } // also check for billing informatin // 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); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values); $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values); //FIXME: to support multiple payment processors if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor', $this->_values))) { $ppID = CRM_Utils_Array::value('payment_processor', $this->_values); if (!$ppID) { CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).')); } $ppIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $ppID); $this->_paymentProcessors = CRM_Financial_BAO_PaymentProcessor::getPayments($ppIds, $this->_mode); $this->set('paymentProcessors', $this->_paymentProcessors); //set default payment processor if (!empty($this->_paymentProcessors) && empty($this->_paymentProcessor)) { foreach ($this->_paymentProcessors as $ppId => $values) { if ($values['is_default'] == 1 || count($this->_paymentProcessors) == 1) { $defaultProcessorId = $ppId; break; } } } if (isset($defaultProcessorId)) { $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($defaultProcessorId, $this->_mode); $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); } if (!CRM_Utils_System::isNull($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $eachPaymentProcessor) { // check selected payment processor is active if (empty($eachPaymentProcessor)) { CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).')); } // ensure that processor has a valid config $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $eachPaymentProcessor, $this); $error = $this->_paymentObject->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } } } } // get price info // CRM-5095 CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text'); foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = NULL; } } //check if Membership Block is enabled, if Membership Fields are included in profile //get membership section for this contribution page $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $this->set('membershipBlock', $this->_membershipBlock); if ($this->_values['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']); } if ($this->_values['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']); } if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) { CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.')); } $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if ($pledgeBlock) { $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock); $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock); $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock); $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock); //set pledge id in values $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); //authenticate pledge user for pledge payment. if ($pledgeId) { $this->_values['pledge_id'] = $pledgeId; //lets override w/ pledge campaign. $this->_values['campaign_id'] = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'campaign_id'); self::authenticatePledgeUser(); } } $this->set('values', $this->_values); $this->set('fields', $this->_fields); } // Handle PCP $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'contribute', $this->_values); $this->_pcpId = $pcp['pcpId']; $this->_pcpBlock = $pcp['pcpBlock']; $this->_pcpInfo = $pcp['pcpInfo']; } // Link (button) for users to create their own Personal Campaign page if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute')) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}&component=contribute", FALSE, NULL, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } //set pledge block if block id is set if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { $this->assign('pledgeBlock', TRUE); } // check if one of the (amount , membership) bloks is active or not $this->_membershipBlock = $this->get('membershipBlock'); if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) { CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.')); } if ($this->_values['amount_block_is_active']) { $this->set('amount_block_is_active', $this->_values['amount_block_is_active']); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); //assigning is_monetary and is_email_receipt to template $this->assign('is_monetary', $this->_values['is_monetary']); $this->assign('is_email_receipt', $this->_values['is_email_receipt']); $this->assign('bltID', $this->_bltID); //assign cancelSubscription URL to templates $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values)); // assigning title to template in case someone wants to use it, also setting CMS page title if ($this->_pcpId) { $this->assign('title', $this->_pcpInfo['title']); CRM_Utils_System::setTitle($this->_pcpInfo['title']); } else { $this->assign('title', $this->_values['title']); CRM_Utils_System::setTitle($this->_values['title']); } $this->_defaults = array(); $this->_amount = $this->get('amount'); //CRM-6907 $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency); //lets allow user to override campaign. $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this); if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) { $this->_values['campaign_id'] = $campID; } //do check for cancel recurring and clean db, CRM-7696 if (CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject)) { self::cancelRecurring(); } }
/** * Are we going to do 2 financial transactions. * * Ie the membership block supports a separate transactions AND the contribution form has been configured for a * contribution * transaction AND a membership transaction AND the payment processor supports double financial transactions (ie. NOT doTransferPayment style) * * @param int $formID * @param bool $amountBlockActiveOnForm * * @return bool */ public function isSeparateMembershipTransaction($formID, $amountBlockActiveOnForm) { $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($formID); if (!empty($memBlockDetails['is_separate_payment']) && $amountBlockActiveOnForm) { return TRUE; } return FALSE; }
/** * Add onbehalf/honoree profile fields and native module fields. * * @param int $id * @param CRM_Core_Form $form */ public function buildComponentForm($id, $form) { if (empty($id)) { return; } $contactID = $this->getContactID(); foreach (array('soft_credit', 'on_behalf') as $module) { if ($module == 'soft_credit') { if (empty($form->_values['honoree_profile_id'])) { continue; } if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['honoree_profile_id'], 'is_active')) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.')); } $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_values['honoree_profile_id']); $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email')); $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_values['honoree_profile_id'], $requiredProfileFields[$profileContactType]); if (!$validProfile) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.')); } foreach (array('honor_block_title', 'honor_block_text') as $name) { $form->assign($name, $form->_values[$name]); } $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); // radio button for Honor Type foreach ($form->_values['soft_credit_types'] as $value) { $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value); } $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE); $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_values['honoree_profile_id'], FALSE, NULL, NULL, NULL, FALSE, NULL, TRUE, NULL, CRM_Core_Permission::CREATE); $form->assign('honoreeProfileFields', $honoreeProfileFields); // add the form elements foreach ($honoreeProfileFields as $name => $field) { // If soft credit type is not chosen then make omit requiredness from honoree profile fields if (count($form->_submitValues) && empty($form->_submitValues['soft_credit_type_id']) && !empty($field['is_required'])) { $field['is_required'] = FALSE; } CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, 'honor'); } } else { if (empty($form->_values['onbehalf_profile_id'])) { continue; } if (!CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_values['onbehalf_profile_id'], 'is_active')) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.')); } $member = CRM_Member_BAO_Membership::getMembershipBlock($form->_id); if (empty($member['is_active'])) { $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.'); $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($form->_values['onbehalf_profile_id']); foreach (array('Individual', 'Organization', 'Household') as $contactType) { if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) { CRM_Core_Error::fatal($msg); } } } if ($contactID) { // retrieve all permissioned organizations of contact $contactID $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($contactID, NULL, NULL, 'Organization'); if (count($organizations)) { // Related org url - pass checksum if needed $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'cid' => ''); if (!empty($_GET['cs'])) { $args = array('ufId' => $form->_values['onbehalf_profile_id'], 'uid' => $this->_contactID, 'cs' => $_GET['cs'], 'cid' => ''); } $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE); $form->assign('locDataURL', $locDataURL); } if (count($organizations) > 0) { $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $organizations)); $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization')); $form->addRadio('org_option', ts('options'), $orgOptions); $form->setDefaults(array('org_option' => 0)); } } $form->assign('fieldSetTitle', ts('Organization Details')); if (CRM_Utils_Array::value('is_for_organization', $form->_values)) { if ($form->_values['is_for_organization'] == 2) { $form->assign('onBehalfRequired', TRUE); } else { $form->addElement('checkbox', 'is_for_organization', $form->_values['for_organization'], NULL); } } $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_values['onbehalf_profile_id'], FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL); $form->assign('onBehalfOfFields', $profileFields); if (!empty($form->_submitValues['onbehalf'])) { if (!empty($form->_submitValues['onbehalfof_id'])) { $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']); } $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf'])); } $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); foreach ($profileFields as $name => $field) { if (in_array($field['field_type'], $fieldTypes)) { list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2); if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) { $field['is_required'] = 1; } if (count($form->_submitValues) && empty($form->_submitValues['is_for_organization']) && $form->_values['is_for_organization'] == 1 && !empty($field['is_required'])) { $field['is_required'] = FALSE; } CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf'); } } } } }
/** * Process the Memberships * * @param array $membershipParams array of membership fields * @param int $contactID contact id * @param object $form form object * * @return void * @access public */ public function postProcessMembership($membershipParams, $contactID, &$form, &$premiumParams) { $tempParams = $membershipParams; $paymentDone = false; $result = null; $isTest = CRM_Utils_Array::value('is_test', $membershipParams, false); $form->assign('membership_assign', true); $form->set('membershipTypeID', $membershipParams['selectMembership']); require_once 'CRM/Member/BAO/MembershipType.php'; require_once 'CRM/Member/BAO/Membership.php'; $membershipTypeID = $membershipParams['selectMembership']; $membershipDetails = self::buildMembershipTypeValues($form, $membershipTypeID); $form->assign('membership_name', $membershipDetails['name']); $minimumFee = CRM_Utils_Array::value('minimum_fee', $membershipDetails); $contributionTypeId = null; if ($form->_values['amount_block_is_active']) { $contributionTypeId = $form->_values['contribution_type_id']; } else { $paymentDone = true; $params['amount'] = $minimumFee; $contributionTypeId = $membershipDetails['contribution_type_id']; } //amount must be greater than zero for //adding contribution record to contribution table. //this condition is arises when separate membership payment is //enable and contribution amount is not selected. fix for CRM-3010 require_once 'CRM/Contribute/BAO/Contribution/Utils.php'; if ($form->_amount > 0.0) { $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, $contributionTypeId, 'membership'); } else { // create the CMS contact here since we normally do this under processConfirm CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, $membershipParams['cms_contactID'], 'email-' . $form->_bltID); } $errors = array(); if (is_a($result[1], 'CRM_Core_Error')) { $errors[1] = CRM_Core_Error::getMessages($result[1]); } else { $contribution[1] = $result[1]; } $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($form->_id); if ($memBlockDetails['is_separate_payment'] && !$paymentDone) { require_once 'CRM/Contribute/DAO/ContributionType.php'; $contributionType = new CRM_Contribute_DAO_ContributionType(); $contributionType->id = $membershipDetails['contribution_type_id']; if (!$contributionType->find(true)) { CRM_Core_Error::fatal("Could not find a system table"); } $tempParams['amount'] = $minimumFee; $invoiceID = md5(uniqid(rand(), true)); $tempParams['invoiceID'] = $invoiceID; //we don't allow recurring membership.CRM-3781. if (CRM_Utils_Array::value('is_recur', $tempParams)) { $tempParams['is_recur'] = 0; } $result = null; if ($form->_values['is_monetary'] && !$form->_params['is_pay_later']) { require_once 'CRM/Core/Payment.php'; $payment =& CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); if ($form->_contributeMode == 'express') { $result =& $payment->doExpressCheckout($tempParams); } else { $result =& $payment->doDirectPayment($tempParams); } } if (is_a($result, 'CRM_Core_Error')) { $errors[2] = CRM_Core_Error::getMessages($result); } else { //assign receive date when separate membership payment //and contribution amount not selected. if ($form->_amount == 0) { $now = date('YmdHis'); $form->_params['receive_date'] = $now; $receiveDate = CRM_Utils_Date::mysqlToIso($now); $form->set('params', $form->_params); $form->assign('receive_date', $receiveDate); } $form->set('membership_trx_id', $result['trxn_id']); $form->set('membership_amount', $minimumFee); $form->assign('membership_trx_id', $result['trxn_id']); $form->assign('membership_amount', $minimumFee); // we dont need to create the user twice, so lets disable cms_create_account // irrespective of the value, CRM-2888 $tempParams['cms_create_account'] = 0; $pending = $form->_params['is_pay_later'] ? true : false; //set this variable as we are not creating pledge for //separate membership payment contribution. //so for differentiating membership contributon from //main contribution. $form->_params['separate_membership_payment'] = 1; $contribution[2] = CRM_Contribute_Form_Contribution_Confirm::processContribution($form, $tempParams, $result, $contactID, $contributionType, false, $pending); } } $index = $memBlockDetails['is_separate_payment'] ? 2 : 1; if (!CRM_Utils_Array::value($index, $errors)) { $membership = self::renewMembership($contactID, $membershipTypeID, $isTest, $form, null, CRM_Utils_Array::value('cms_contactID', $membershipParams)); if (isset($contribution[$index])) { //insert payment record require_once 'CRM/Member/DAO/MembershipPayment.php'; $dao = new CRM_Member_DAO_MembershipPayment(); $dao->membership_id = $membership->id; $dao->contribution_id = $contribution[$index]->id; //Fixed for avoiding duplicate entry error when user goes //back and forward during payment mode is notify if (!$dao->find(true)) { CRM_Utils_Hook::pre('create', 'MembershipPayment', null, $dao); $dao->save(); CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); } } } require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::postProcess($form->_params, CRM_Core_DAO::$_nullArray, 'civicrm_membership', $membership->id, 'Membership'); if (!empty($errors)) { foreach ($errors as $error) { if (is_string($error)) { $message[] = $error; } } $message = ts("Payment Processor Error message") . ": " . implode('<br/>', $message); $session = CRM_Core_Session::singleton(); $session->setStatus($message); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', "_qf_Main_display=true&qfKey={$form->_params['qfKey']}")); } $form->_params['membershipID'] = $membership->id; if ($form->_contributeMode == 'notify') { if ($form->_values['is_monetary'] && $form->_amount > 0.0 && !$form->_params['is_pay_later']) { // this does not return require_once 'CRM/Core/Payment.php'; $payment =& CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); $payment->doTransferCheckout($form->_params, 'contribute'); } } $form->_values['membership_id'] = $membership->id; if (isset($contribution[$index]->id)) { $form->_values['contribution_id'] = $contribution[$index]->id; } // Do not send an email if Recurring transaction is done via Direct Mode // Email will we sent when the IPN is received. if ($form->_params['is_recur'] && $form->_contributeMode == 'direct') { return true; } //finally send an email receipt require_once "CRM/Contribute/BAO/ContributionPage.php"; CRM_Contribute_BAO_ContributionPage::sendMail($contactID, $form->_values, $isTest); }
/** * Build the form object. */ public function buildQuickForm() { $this->_first = TRUE; $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_ContributionPage'); // financial Type $this->addSelect('financial_type_id', array(), TRUE); // name $this->add('text', 'title', ts('Title'), $attributes['title'], TRUE); //CRM-7362 --add campaigns. CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values)); $this->add('wysiwyg', 'intro_text', ts('Introductory Message'), $attributes['intro_text']); $this->add('wysiwyg', 'footer_text', ts('Footer Message'), $attributes['footer_text']); //Register schema which will be used for OnBehalOf and HonorOf profile Selector CRM_UF_Page_ProfileEditor::registerSchemas(array('OrganizationModel', 'HouseholdModel')); // is on behalf of an organization ? $this->addElement('checkbox', 'is_organization', ts('Allow individuals to contribute and / or signup for membership on behalf of an organization?'), NULL, array('onclick' => "showHideByValue('is_organization',true,'for_org_text','table-row','radio',false);showHideByValue('is_organization',true,'for_org_option','table-row','radio',false);")); //CRM-15787 - If applicable, register 'membership_1' $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $coreTypes = array('Contact', 'Organization'); $entities[] = array('entity_name' => array('contact_1'), 'entity_type' => 'OrganizationModel'); if ($member && $member['is_active']) { $coreTypes[] = 'Membership'; $entities[] = array('entity_name' => array('membership_1'), 'entity_type' => 'MembershipModel'); } $allowCoreTypes = array_merge($coreTypes, CRM_Contact_BAO_ContactType::subTypes('Organization')); $allowSubTypes = array(); $this->addProfileSelector('onbehalf_profile_id', ts('Organization Profile'), $allowCoreTypes, $allowSubTypes, $entities); $options = array(); $options[] = $this->createElement('radio', NULL, NULL, ts('Optional'), 1); $options[] = $this->createElement('radio', NULL, NULL, ts('Required'), 2); $this->addGroup($options, 'is_for_organization', ''); $this->add('textarea', 'for_organization', ts('On behalf of Label'), array('rows' => 2, 'cols' => 50)); // collect goal amount $this->add('text', 'goal_amount', ts('Goal Amount'), array('size' => 8, 'maxlength' => 12)); $this->addRule('goal_amount', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); // is confirmation page enabled? $this->addElement('checkbox', 'is_confirm_enabled', ts('Use a confirmation page?')); // is this page shareable through social media ? $this->addElement('checkbox', 'is_share', ts('Allow sharing through social media?')); // is this page active ? $this->addElement('checkbox', 'is_active', ts('Is this Online Contribution Page Active?')); // should the honor be enabled $this->addElement('checkbox', 'honor_block_is_active', ts('Honoree Section Enabled'), NULL, array('onclick' => "showHonor()")); $this->add('text', 'honor_block_title', ts('Honoree Section Title'), array('maxlength' => 255, 'size' => 45)); $this->add('textarea', 'honor_block_text', ts('Honoree Introductory Message'), array('rows' => 2, 'cols' => 50)); $this->addSelect('soft_credit_types', array('label' => ts('Honor Types'), 'entity' => 'ContributionSoft', 'field' => 'soft_credit_type_id', 'multiple' => TRUE, 'class' => 'huge')); $entities = array(array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel')); $allowCoreTypes = array_merge(array('Contact', 'Individual', 'Organization', 'Household'), CRM_Contact_BAO_ContactType::subTypes('Individual')); $allowSubTypes = array(); $this->addProfileSelector('honoree_profile', ts('Honoree Profile'), $allowCoreTypes, $allowSubTypes, $entities); if (!empty($this->_submitValues['honor_block_is_active'])) { $this->addRule('soft_credit_types', ts('At least one value must be selected if Honor Section is active'), 'required'); $this->addRule('honoree_profile', ts('Please select a profile used for honoree'), 'required'); } // add optional start and end dates $this->addDateTime('start_date', ts('Start Date')); $this->addDateTime('end_date', ts('End Date')); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this); parent::buildQuickForm(); }
/** * Set variables up before form is built. */ public function preProcess() { parent::preProcess(); self::preProcessPaymentOptions($this); // Make the contributionPageID available to the template $this->assign('contributionPageID', $this->_id); $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values)); $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values)); $this->assign('reset', CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject)); $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject)); // Possible values for 'is_for_organization': // * 0 - org profile disabled // * 1 - org profile optional // * 2 - org profile required $this->_onbehalf = FALSE; if (!empty($this->_values['is_for_organization'])) { if ($this->_values['is_for_organization'] == 2) { $this->_onBehalfRequired = TRUE; } // Add organization profile if 1 of the following are true: // If the org profile is required if ($this->_onBehalfRequired || empty($_POST) || !empty($_POST['is_for_organization'])) { $this->_onbehalf = TRUE; CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this); } } $this->assign('onBehalfRequired', $this->_onBehalfRequired); if ($this->_honor_block_is_active) { CRM_Contact_Form_ProfileContact::preprocess($this); } if ($this->_snippet) { $this->assign('isOnBehalfCallback', CRM_Utils_Array::value('onbehalf', $_GET, FALSE)); return; } if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) { $this->assign('intro_text', $this->_pcpInfo['intro_text']); } elseif (!empty($this->_values['intro_text'])) { $this->assign('intro_text', $this->_values['intro_text']); } $qParams = "reset=1&id={$this->_id}"; if ($pcpId = CRM_Utils_Array::value('pcp_id', $this->_pcpInfo)) { $qParams .= "&pcpId={$pcpId}"; } $this->assign('qParams', $qParams); if (!empty($this->_values['footer_text'])) { $this->assign('footer_text', $this->_values['footer_text']); } //CRM-5001 //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', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $onBehalfProfileIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // getUFGroupIDs returns an array with the first item being the ID we need $onBehalfProfileID = $onBehalfProfileIDs[0]; if ($onBehalfProfileID) { $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileID); foreach (array('Individual', 'Organization', 'Household') as $contactType) { if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) { CRM_Core_Error::fatal($msg); } } } 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) { if (in_array($contactType, $postProfile) && (in_array('Membership', $postProfile) || in_array('Contribution', $postProfile))) { CRM_Core_Error::fatal($msg); } } } } }
/** * Process the Memberships * * @param array $membershipParams array of membership fields * @param int $contactID contact id * @param object $form form object * * @return void * @access public */ public static function postProcessMembership($membershipParams, $contactID, &$form, &$premiumParams, $customFieldsFormatted = NULL, $includeFieldTypes = NULL) { $tempParams = $membershipParams; $paymentDone = FALSE; $result = NULL; $isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE); $form->assign('membership_assign', TRUE); $form->set('membershipTypeID', $membershipParams['selectMembership']); $singleMembershipTypeID = $membershipTypeID = $membershipParams['selectMembership']; if (is_array($membershipTypeID) && count($membershipTypeID) == 1) { $singleMembershipTypeID = $membershipTypeID[0]; } $membershipDetails = self::buildMembershipTypeValues($form, $singleMembershipTypeID); $form->assign('membership_name', CRM_Utils_Array::value('name', $membershipDetails)); $minimumFee = CRM_Utils_Array::value('minimum_fee', $membershipDetails); $contributionTypeId = NULL; if ($form->_values['amount_block_is_active']) { $contributionTypeId = $form->_values['financial_type_id']; } else { $paymentDone = TRUE; $params['amount'] = $minimumFee; $contributionTypeId = CRM_Utils_Array::value('financial_type_id', $membershipDetails); if (!$contributionTypeId) { $contributionTypeId = CRM_Utils_Array::value('financial_type_id', $membershipParams); } } //amount must be greater than zero for //adding contribution record to contribution table. //this condition arises when separate membership payment is //enabled and contribution amount is not selected. fix for CRM-3010 if ($form->_amount > 0.0 && $membershipParams['amount']) { $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($form, $membershipParams, $premiumParams, $contactID, $contributionTypeId, 'membership'); } else { // we need to explicitly create a CMS user in case of free memberships // since the below has already been done under processConfirm for paid memberships CRM_Contribute_BAO_Contribution_Utils::createCMSUser($membershipParams, $membershipParams['cms_contactID'], 'email-' . $form->_bltID); } $errors = array(); if (is_a($result[1], 'CRM_Core_Error')) { $errors[1] = CRM_Core_Error::getMessages($result[1]); } elseif (CRM_Utils_Array::value(1, $result)) { // Save the contribution ID so that I can be used in email receipts // For example, if you need to generate a tax receipt for the donation only. $form->_values['contribution_other_id'] = $result[1]->id; $contribution[1] = $result[1]; } $memBlockDetails = CRM_Member_BAO_Membership::getMembershipBlock($form->_id); if (CRM_Utils_Array::value('is_separate_payment', $memBlockDetails) && !$paymentDone) { $form->_lineItem = $form->_memLineItem; $contributionType = new CRM_Financial_DAO_FinancialType(); $contributionType->id = CRM_Utils_Array::value('financial_type_id', $membershipDetails); if (!$contributionType->find(TRUE)) { CRM_Core_Error::fatal(ts("Could not find a system table")); } $tempParams['amount'] = $minimumFee; $invoiceID = md5(uniqid(rand(), TRUE)); $tempParams['invoiceID'] = $invoiceID; //we don't allow recurring membership.CRM-3781. if (CRM_Utils_Array::value('is_recur', $tempParams)) { $tempParams['is_recur'] = 0; } $result = NULL; if ($form->_values['is_monetary'] && !$form->_params['is_pay_later'] && $minimumFee > 0.0) { $payment = CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); if ($form->_contributeMode == 'express') { $result =& $payment->doExpressCheckout($tempParams); } else { $result =& $payment->doDirectPayment($tempParams); } } if (is_a($result, 'CRM_Core_Error')) { $errors[2] = CRM_Core_Error::getMessages($result); } else { //assign receive date when separate membership payment //and contribution amount not selected. if ($form->_amount == 0) { $now = date('YmdHis'); $form->_params['receive_date'] = $now; $receiveDate = CRM_Utils_Date::mysqlToIso($now); $form->set('params', $form->_params); $form->assign('receive_date', $receiveDate); } $form->set('membership_trx_id', $result['trxn_id']); $form->set('membership_amount', $minimumFee); $form->assign('membership_trx_id', $result['trxn_id']); $form->assign('membership_amount', $minimumFee); // we dont need to create the user twice, so lets disable cms_create_account // irrespective of the value, CRM-2888 $tempParams['cms_create_account'] = 0; $pending = $form->_params['is_pay_later'] ? CRM_Utils_Array::value('minimum_fee', $membershipDetails, 0) > 0.0 ? TRUE : FALSE : FALSE; //set this variable as we are not creating pledge for //separate membership payment contribution. //so for differentiating membership contributon from //main contribution. $form->_params['separate_membership_payment'] = 1; $contribution[2] = CRM_Contribute_Form_Contribution_Confirm::processContribution($form, $tempParams, $result, $contactID, $contributionType, TRUE, $pending); } } $index = CRM_Utils_Array::value('is_separate_payment', $memBlockDetails) ? 2 : 1; if (!CRM_Utils_Array::value($index, $errors)) { if (isset($membershipParams['onbehalf']) && CRM_Utils_Array::value('member_campaign_id', $membershipParams['onbehalf'])) { $form->_params['campaign_id'] = $membershipParams['onbehalf']['member_campaign_id']; } if (is_array($membershipTypeID)) { $typesTerms = CRM_Utils_Array::value('types_terms', $membershipParams, array()); $createdMemberships = array(); foreach ($membershipTypeID as $memType) { $numTerms = CRM_Utils_Array::value($memType, $typesTerms, 1); $membership = self::renewMembership($contactID, $memType, $isTest, $form, NULL, CRM_Utils_Array::value('cms_contactID', $membershipParams), $customFieldsFormatted, CRM_Utils_Array::value($memType, $typesTerms, 1)); $createdMemberships[$memType] = $membership; if (isset($contribution[$index])) { //insert payment record $dao = new CRM_Member_DAO_MembershipPayment(); $dao->membership_id = $membership->id; $dao->contribution_id = $contribution[$index]->id; //Fixed for avoiding duplicate entry error when user goes //back and forward during payment mode is notify if (!$dao->find(TRUE)) { CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao); $dao->save(); CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); } } } if ($form->_priceSetId && !empty($form->_useForMember) && !empty($form->_lineItem)) { foreach ($form->_lineItem[$form->_priceSetId] as &$priceFieldOp) { if (CRM_Utils_Array::value('membership_type_id', $priceFieldOp) && isset($createdMemberships[$priceFieldOp['membership_type_id']])) { $membershipOb = $createdMemberships[$priceFieldOp['membership_type_id']]; $priceFieldOp['start_date'] = $membershipOb->start_date ? CRM_Utils_Date::customFormat($membershipOb->start_date, '%d%f %b, %Y') : '-'; $priceFieldOp['end_date'] = $membershipOb->end_date ? CRM_Utils_Date::customFormat($membershipOb->end_date, '%d%f %b, %Y') : '-'; } else { $priceFieldOp['start_date'] = $priceFieldOp['end_date'] = 'N/A'; } } $form->_values['lineItem'] = $form->_lineItem; $form->assign('lineItem', $form->_lineItem); } } else { $membership = self::renewMembership($contactID, $membershipTypeID, $isTest, $form, NULL, CRM_Utils_Array::value('cms_contactID', $membershipParams), $customFieldsFormatted, CRM_Utils_Array::value('types_terms', $membershipParams, 1), CRM_Utils_Array::value('contribution_status_id', $result) == 2 ? TRUE : FALSE); if (isset($contribution[$index])) { //insert payment record $dao = new CRM_Member_DAO_MembershipPayment(); $dao->membership_id = $membership->id; $dao->contribution_id = $contribution[$index]->id; //Fixed for avoiding duplicate entry error when user goes //back and forward during payment mode is notify if (!$dao->find(TRUE)) { CRM_Utils_Hook::pre('create', 'MembershipPayment', NULL, $dao); $dao->save(); CRM_Utils_Hook::post('create', 'MembershipPayment', $dao->id, $dao); } } } } if (!empty($errors)) { foreach ($errors as $error) { if (is_string($error)) { $message[] = $error; } } $message = ts('Payment Processor Error message') . ': ' . implode('<br/>', $message); throw new CRM_Core_Exception($message); } // CRM-7851 CRM_Core_BAO_CustomValueTable::postProcess($form->_params, CRM_Core_DAO::$_nullArray, 'civicrm_membership', $membership->id, 'Membership'); $form->_params['membershipID'] = $membership->id; if ($form->_contributeMode == 'notify') { if ($form->_values['is_monetary'] && $form->_amount > 0.0 && !$form->_params['is_pay_later']) { // call postprocess hook before leaving $form->postProcessHook(); // this does not return $payment = CRM_Core_Payment::singleton($form->_mode, $form->_paymentProcessor, $form); $payment->doTransferCheckout($form->_params, 'contribute'); } } $form->_values['membership_id'] = $membership->id; if (isset($contribution[$index]->id)) { $form->_values['contribution_id'] = $contribution[$index]->id; } // Do not send an email if Recurring transaction is done via Direct Mode // Email will we sent when the IPN is received. if (CRM_Utils_Array::value('is_recur', $form->_params) && $form->_contributeMode == 'direct') { return TRUE; } //finally send an email receipt CRM_Contribute_BAO_ContributionPage::sendMail($contactID, $form->_values, $isTest, FALSE, $includeFieldTypes); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); // current contribution page id $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this); if (!$this->_id) { $pastContributionID = $session->get('pastContributionID'); if (!$pastContributionID) { CRM_Core_Error::fatal(ts('We can\'t load the requested web page due to an incomplete link. This can be caused by using your browser\'s Back button or by using an incomplete or invalid link.')); } else { CRM_Core_Error::fatal(ts('This contribution has already been submitted. Click <a href=\'%1\'>here</a> if you want to make another contribution.', array(1 => CRM_Utils_System::url('civicrm/contribute/transact', 'reset=1&id=' . $pastContributionID)))); } } else { $session->set('pastContributionID', $this->_id); } $this->_userID = $session->get('userID'); $this->_mid = null; if ($this->_userID) { $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this); if ($this->_mid) { require_once 'CRM/Member/DAO/Membership.php'; $membership = new CRM_Member_DAO_Membership(); $membership->id = $this->_mid; if ($membership->find(true)) { $this->_defaultMemTypeId = $membership->membership_type_id; if ($membership->contact_id != $this->_userID) { require_once 'CRM/Contact/BAO/Relationship.php'; $employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($this->_userID); if (array_key_exists($membership->contact_id, $employers)) { $this->_membershipContactID = $membership->contact_id; $this->assign('membershipContactID', $this->_membershipContactID); $this->assign('membershipContactName', $employers[$this->_membershipContactID]['name']); } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } } } else { CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership.")); } unset($membership); } } // we do not want to display recently viewed items, so turn off $this->assign('displayRecent', false); // Contribution page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', true); // action $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'add'); $this->assign('action', $this->_action); // current mode $this->_mode = $this->_action == 1024 ? 'test' : 'live'; $this->_values = $this->get('values'); $this->_fields = $this->get('fields'); $this->_bltID = $this->get('bltID'); $this->_paymentProcessor = $this->get('paymentProcessor'); $this->_priceSetId = $this->get('priceSetId'); $this->_priceSet = $this->get('priceSet'); if (!$this->_values) { // get all the values from the dao object $this->_values = array(); $this->_fields = array(); require_once 'CRM/Contribute/BAO/ContributionPage.php'; CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); // check if form is active if (!$this->_values['is_active']) { // form is inactive, die a fatal death CRM_Core_Error::fatal(ts('The page you requested is currently unavailable.')); } // also check for billing informatin // get the billing location type $locationTypes =& CRM_Core_PseudoConstant::locationType(); $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); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values); $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values); if ($isMonetary && (!$isPayLater || CRM_Utils_Array::value('payment_processor_id', $this->_values))) { $ppID = CRM_Utils_Array::value('payment_processor_id', $this->_values); if (!$ppID) { CRM_Core_Error::fatal(ts('A payment processor must be selected for this contribution page (contact the site administrator for assistance).')); } require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode); // check selected payment processor is active if (empty($this->_paymentProcessor)) { CRM_Core_Error::fatal(ts('A payment processor configured for this page might be disabled (contact the site administrator for assistance).')); } // ensure that processor has a valid config $this->_paymentObject =& CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this); $error = $this->_paymentObject->checkConfig(); if (!empty($error)) { CRM_Core_Error::fatal($error); } $this->_paymentProcessor['processorName'] = $this->_paymentObject->_processorName; $this->set('paymentProcessor', $this->_paymentProcessor); } // get price info // CRM-5095 require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::initSet($this, $this->_id, 'civicrm_contribution_page'); // this avoids getting E_NOTICE errors in php $setNullFields = array('amount_block_is_active', 'honor_block_is_active', 'is_allow_other_amount', 'footer_text'); foreach ($setNullFields as $f) { if (!isset($this->_values[$f])) { $this->_values[$f] = null; } } //check if Membership Block is enabled, if Membership Fields are included in profile //get membership section for this contribution page require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); $this->set('membershipBlock', $this->_membershipBlock); require_once "CRM/Core/BAO/UFField.php"; if ($this->_values['custom_pre_id']) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']); } if ($this->_values['custom_post_id']) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']); } // also set cancel subscription url if (CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) && CRM_Utils_Array::value('is_recur', $this->_values)) { $this->_values['cancelSubscriptionUrl'] = $this->_paymentObject->cancelSubscriptionURL(); } if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) { CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.')); } require_once 'CRM/Pledge/BAO/PledgeBlock.php'; $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if ($pledgeBlock) { $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock); $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock); $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock); $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock); //set pledge id in values $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this); //authenticate pledge user for pledge payment. if ($pledgeId) { $this->_values['pledge_id'] = $pledgeId; self::authenticatePledgeUser(); } } $this->set('values', $this->_values); $this->set('fields', $this->_fields); } require_once 'CRM/Contribute/BAO/PCP.php'; $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { require_once 'CRM/Core/OptionGroup.php'; $approvedId = CRM_Core_OptionGroup::getValue('pcp_status', 'Approved', 'name'); $prms = array('entity_id' => $this->_values['id'], 'entity_table' => 'civicrm_contribution_page'); require_once 'CRM/Contribute/PseudoConstant.php'; $pcpStatus = CRM_Contribute_PseudoConstant::pcpStatus(); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $prms, $pcpBlock); $prms = array('id' => $pcpId); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCP', $prms, $pcpInfo); //start and end date of the contribution page $startDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('start_date', $this->_values)); $endDate = CRM_Utils_Date::unixTime(CRM_Utils_Array::value('end_date', $this->_values)); $now = time(); if ($pcpInfo['contribution_page_id'] != $this->_values['id']) { $statusMessage = ts('This contribution page is not related to the Personal Campaign Page you have just visited. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$this->_values['id']}", false, null, false, true)); } else { if ($pcpInfo['status_id'] != $approvedId) { $statusMessage = ts('The Personal Campaign Page you have just visited is currently %1. However you can still support the campaign by making a contribution here.', array(1 => $pcpStatus[$pcpInfo['status_id']])); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpBlock)) { $statusMessage = ts('Personal Campaign Pages are currently not enabled for this contribution page. However you can still support the campaign by making a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if (!CRM_Utils_Array::value('is_active', $pcpInfo)) { $statusMessage = ts('The Personal Campaign Page you have just visited is current inactive. However you can still make a contribution here.'); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate && $startDate > $now || $endDate && $endDate < $now) { $customStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $this->_values)); $customEndDate = CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $this->_values)); if ($startDate && $endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is only active between %1 to %2. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate, 2 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($startDate) { $statusMessage = ts('The Personal Campaign Page you have just visited will be active beginning on %1. However you can still support the campaign by making a contribution here.', array(1 => $customStartDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } else { if ($endDate) { $statusMessage = ts('The Personal Campaign Page you have just visited is not longer active (as of %1). However you can still support the campaign by making a contribution here.', array(1 => $customEndDate)); CRM_Core_Error::statusBounce($statusMessage, CRM_Utils_System::url('civicrm/contribute/transact', "reset=1&id={$pcpInfo['contribution_page_id']}", false, null, false, true)); } } } } } } } } $this->_pcpId = $pcpId; $this->_pcpBlock = $pcpBlock; $this->_pcpInfo = $pcpInfo; } // Link (button) for users to create their own Personal Campaign page if ($linkText = CRM_Contribute_BAO_PCP::getPcpBlockStatus($this->_id)) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}", false, null, true); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } //set pledge block if block id is set if (CRM_Utils_Array::value('pledge_block_id', $this->_values)) { $this->assign('pledgeBlock', true); } // we do this outside of the above conditional to avoid // saving the country/state list in the session (which could be huge) if ($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM && CRM_Utils_Array::value('is_monetary', $this->_values)) { require_once 'CRM/Core/Payment/Form.php'; require_once 'CRM/Core/Payment.php'; // payment fields are depending on payment type if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::setDirectDebitFields($this); } else { CRM_Core_Payment_Form::setCreditCardFields($this); } } $this->assign_by_ref('paymentProcessor', $this->_paymentProcessor); // check if this is a paypal auto return and redirect accordingly if (CRM_Core_Payment::paypalRedirect($this->_paymentProcessor)) { $url = CRM_Utils_System::url('civicrm/contribute/transact', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } // make sure we have a valid payment class, else abort if (CRM_Utils_Array::value('is_monetary', $this->_values) && !$this->_paymentProcessor['class_name'] && !CRM_Utils_Array::value('is_pay_later', $this->_values)) { CRM_Core_Error::fatal(ts('Payment processor is not set for this page')); } // check if one of the (amount , membership) bloks is active or not require_once 'CRM/Member/BAO/Membership.php'; $this->_membershipBlock = $this->get('membershipBlock'); if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) { CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.')); } if ($this->_values['amount_block_is_active']) { $this->set('amount_block_is_active', $this->_values['amount_block_is_active']); } if (!empty($this->_membershipBlock) && CRM_Utils_Array::value('is_separate_payment', $this->_membershipBlock) && !($this->_paymentProcessor['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM)) { CRM_Core_Error::fatal(ts('This contribution page is configured to support separate contribution and membership payments. This %1 plugin does not currently support multiple simultaneous payments. Please contact the site administrator and notify them of this error', array(1 => $this->_paymentProcessor['payment_processor_type']))); } $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); //assigning is_monetary and is_email_receipt to template $this->assign('is_monetary', $this->_values['is_monetary']); $this->assign('is_email_receipt', $this->_values['is_email_receipt']); $this->assign('bltID', $this->_bltID); //assign cancelSubscription URL to templates $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values)); // assigning title to template in case someone wants to use it, also setting CMS page title if ($this->_pcpId) { $this->assign('title', $pcpInfo['title']); CRM_Utils_System::setTitle($pcpInfo['title']); } else { $this->assign('title', $this->_values['title']); CRM_Utils_System::setTitle($this->_values['title']); } $this->_defaults = array(); $this->_amount = $this->get('amount'); //CRM-6907 $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency); }