/** * retrieve() and getPledgeBlock() method of pledge block */ function testRetrieveAndGetPledgeBlock() { $pledgeFrequencyUnit = array('week' => 1, 'month' => 1, 'year' => 1); $params = array('entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page', 'pledge_frequency_unit' => $pledgeFrequencyUnit, 'max_reminders' => 2, 'initial_reminder_day' => 2, 'additional_reminder_day' => 1); $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); // use retrieve() method $retrieveParams = array('entity_id' => $this->_contributionPageId, 'entity_table' => 'civicrm_contribution_page'); $default = array(); $retrievePledgeBlock = CRM_Pledge_BAO_PledgeBlock::retrieve($retrieveParams, $default); // use getPledgeBlock() method $getPledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_contributionPageId); // check on both retrieve and getPledgeBlock values foreach ($params as $param => $value) { $this->assertEquals($value, $retrievePledgeBlock->{$param}); $this->assertEquals($value, $getPledgeBlock[$param]); } // Also check for pledgeBlock id. $this->assertEquals($pledgeBlock->id, $retrievePledgeBlock->id); $this->assertEquals($pledgeBlock->id, $getPledgeBlock['id']); }
/** * 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(); } }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (CRM_Utils_Array::value('payment_processor_id', $params) == CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type')) { CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).')); } // check for price set. $priceSetID = CRM_Utils_Array::value('price_set_id', $params); // get required fields. $fields = array('id' => $this->_id, 'is_recur' => false, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => false, 'is_pay_later' => false, 'is_recur_interval' => false, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => false, 'amount_block_is_active' => false); $resetFields = array(); if ($priceSetID) { $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount'); } if (!CRM_Utils_Array::value('is_recur', $params)) { $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit')); } foreach ($fields as $field => $defaultVal) { $val = CRM_Utils_Array::value($field, $params, $defaultVal); if (in_array($field, $resetFields)) { $val = $defaultVal; } if (in_array($field, array('min_amount', 'max_amount'))) { $val = CRM_Utils_Rule::cleanMoney($val); } $params[$field] = $val; } if ($params['is_recur']) { require_once 'CRM/Core/BAO/CustomOption.php'; $params['recur_frequency_unit'] = implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, array_keys($params['recur_frequency_unit'])); $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, false); } require_once 'CRM/Contribute/BAO/ContributionPage.php'; $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $contributionPageID = $contributionPage->id; // prepare for data cleanup. $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = false; if ($this->_priceSetID) { $deletePriceSet = true; } if ($this->_pledgeBlockID) { $deletePledgeBlk = true; } if (!empty($this->_amountBlock)) { $deleteAmountBlk = true; } if ($contributionPageID) { require_once 'CRM/Price/BAO/Set.php'; require_once 'CRM/Core/OptionGroup.php'; require_once 'CRM/Pledge/BAO/PledgeBlock.php'; if (CRM_Utils_Array::value('amount_block_is_active', $params)) { // handle price set. if ($priceSetID) { // add/update price set. $deletePriceSet = false; CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { // process contribution amount block $deleteAmountBlk = false; $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (isset($values[$i]) && strlen(trim($values[$i])) > 0) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } CRM_Core_OptionGroup::createAssoc("civicrm_contribution_page.amount.{$contributionPageID}", $options, $params['default_amount_id']); if ($params['default_amount_id']) { CRM_Core_DAO::setFieldValue('CRM_Contribute_DAO_ContributionPage', $contributionPageID, 'default_amount_id', $params['default_amount_id']); } if (CRM_Utils_Array::value('is_pledge_active', $params)) { $deletePledgeBlk = false; $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page')); if ($this->_pledgeBlockID) { $pledgeBlockParams['id'] = $this->_pledgeBlockID; } $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day'); foreach ($pledgeBlock as $key) { $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params); } $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, false); // create pledge block. require_once 'CRM/Pledge/BAO/PledgeBlock.php'; CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams); } } } // delete pledge block. if ($deletePledgeBlk) { CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID); } // delete previous price set. if ($deletePriceSet) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID); } // delete amount block. if ($deleteAmountBlk) { CRM_Core_OptionGroup::deleteAssoc("civicrm_contribution_page.amount.{$contributionPageID}"); } } }
/** * Process the form * * @return void * @access public */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if (array_key_exists('payment_processor', $params)) { if (array_key_exists(CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PaymentProcessor', 'AuthNet', 'id', 'payment_processor_type'), CRM_Utils_Array::value('payment_processor', $params))) { CRM_Core_Session::setStatus(ts(' Please note that the Authorize.net payment processor only allows recurring contributions and auto-renew memberships with payment intervals from 7-365 days or 1-12 months (i.e. not greater than 1 year).')); } } // check for price set. $priceSetID = CRM_Utils_Array::value('price_set_id', $params); // get required fields. $fields = array('id' => $this->_id, 'is_recur' => FALSE, 'min_amount' => "null", 'max_amount' => "null", 'is_monetary' => FALSE, 'is_pay_later' => FALSE, 'is_recur_interval' => FALSE, 'recur_frequency_unit' => "null", 'default_amount_id' => "null", 'is_allow_other_amount' => FALSE, 'amount_block_is_active' => FALSE); $resetFields = array(); if ($priceSetID) { $resetFields = array('min_amount', 'max_amount', 'is_allow_other_amount'); } if (!CRM_Utils_Array::value('is_recur', $params)) { $resetFields = array_merge($resetFields, array('is_recur_interval', 'recur_frequency_unit')); } foreach ($fields as $field => $defaultVal) { $val = CRM_Utils_Array::value($field, $params, $defaultVal); if (in_array($field, $resetFields)) { $val = $defaultVal; } if (in_array($field, array('min_amount', 'max_amount'))) { $val = CRM_Utils_Rule::cleanMoney($val); } $params[$field] = $val; } if ($params['is_recur']) { $params['recur_frequency_unit'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['recur_frequency_unit'])); $params['is_recur_interval'] = CRM_Utils_Array::value('is_recur_interval', $params, FALSE); } if (array_key_exists('payment_processor', $params) && !CRM_Utils_System::isNull($params['payment_processor'])) { $params['payment_processor'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['payment_processor'])); } else { $params['payment_processor'] = 'null'; } $contributionPage = CRM_Contribute_BAO_ContributionPage::create($params); $contributionPageID = $contributionPage->id; // prepare for data cleanup. $deleteAmountBlk = $deletePledgeBlk = $deletePriceSet = FALSE; if ($this->_priceSetID) { $deletePriceSet = TRUE; } if ($this->_pledgeBlockID) { $deletePledgeBlk = TRUE; } if (!empty($this->_amountBlock)) { $deleteAmountBlk = TRUE; } if ($contributionPageID) { if (CRM_Utils_Array::value('amount_block_is_active', $params)) { // handle price set. if ($priceSetID) { // add/update price set. $deletePriceSet = FALSE; if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) { $deleteAmountBlk = TRUE; } CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $contributionPageID, $priceSetID); } else { $deletePriceSet = FALSE; // process contribution amount block $deleteAmountBlk = FALSE; $labels = CRM_Utils_Array::value('label', $params); $values = CRM_Utils_Array::value('value', $params); $default = CRM_Utils_Array::value('default', $params); $options = array(); for ($i = 1; $i < self::NUM_OPTION; $i++) { if (isset($values[$i]) && strlen(trim($values[$i])) > 0) { $options[] = array('label' => trim($labels[$i]), 'value' => CRM_Utils_Rule::cleanMoney(trim($values[$i])), 'weight' => $i, 'is_active' => 1, 'is_default' => $default == $i); } } /* || CRM_Utils_Array::value( 'price_field_value', $params )|| CRM_Utils_Array::value( 'price_field_other', $params )*/ if (!empty($options) || CRM_Utils_Array::value('is_allow_other_amount', $params)) { $fieldParams['is_quick_config'] = 1; $noContriAmount = NULL; $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3); if (!(CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) && !$usedPriceSetId) { $pageTitle = strtolower(CRM_Utils_String::munge($this->_values['title'], '_', 245)); $setParams['title'] = $this->_values['title']; if (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle, 'id', 'name')) { $setParams['name'] = $pageTitle; } elseif (!CRM_Core_DAO::getFieldValue('CRM_Price_BAO_Set', $pageTitle . '_' . $this->_id, 'id', 'name')) { $setParams['name'] = $pageTitle . '_' . $this->_id; } else { $timeSec = explode(".", microtime(true)); $setParams['name'] = $pageTitle . '_' . date('is', $timeSec[0]) . $timeSec[1]; } $setParams['is_quick_config'] = 1; $setParams['extends'] = CRM_Core_Component::getComponentID('CiviContribute'); $priceSet = CRM_Price_BAO_Set::create($setParams); $priceSetId = $priceSet->id; } elseif ($usedPriceSetId && !CRM_Utils_Array::value('price_field_id', $params)) { $priceSetId = $usedPriceSetId; } else { if ($priceFieldId = CRM_Utils_Array::value('price_field_id', $params)) { foreach ($params['price_field_value'] as $arrayID => $fieldValueID) { if (empty($params['label'][$arrayID]) && empty($params['value'][$arrayID]) && !empty($fieldValueID)) { CRM_Price_BAO_FieldValue::setIsActive($fieldValueID, '0'); unset($params['price_field_value'][$arrayID]); } } if (implode('', $params['price_field_value'])) { $fieldParams['id'] = CRM_Utils_Array::value('price_field_id', $params); $fieldParams['option_id'] = $params['price_field_value']; } else { $noContriAmount = 0; CRM_Price_BAO_Field::setIsActive($priceFieldId, '0'); } } else { $priceFieldId = CRM_Utils_Array::value('price_field_other', $params); } $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceFieldId, 'price_set_id'); } CRM_Price_BAO_Set::addTo('civicrm_contribution_page', $this->_id, $priceSetId); if (!empty($options)) { $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'contribution_amount'); $editedResults = array(); $noContriAmount = 1; CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!CRM_Utils_Array::value('id', $editedResults)) { $fieldParams['name'] = strtolower(CRM_Utils_String::munge("Contribution Amount", '_', 245)); $fieldParams['label'] = "Contribution Amount"; } else { $fieldParams['id'] = CRM_Utils_Array::value('id', $editedResults); } $fieldParams['price_set_id'] = $priceSetId; $fieldParams['is_active'] = 1; $fieldParams['weight'] = 2; if (CRM_Utils_Array::value('is_allow_other_amount', $params)) { $fieldParams['is_required'] = 0; } else { $fieldParams['is_required'] = 1; } $fieldParams['html_type'] = 'Radio'; $fieldParams['option_label'] = $params['label']; $fieldParams['option_amount'] = $params['value']; foreach ($options as $value) { $fieldParams['option_weight'][$value['weight']] = $value['weight']; } $fieldParams['default_option'] = $params['default']; $priceField = CRM_Price_BAO_Field::create($fieldParams); } if (CRM_Utils_Array::value('is_allow_other_amount', $params) && !CRM_Utils_Array::value('price_field_other', $params)) { $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => 'other_amount'); $editedResults = array(); CRM_Price_BAO_Field::retrieve($editedFieldParams, $editedResults); if (!($priceFieldID = CRM_Utils_Array::value('id', $editedResults))) { $fieldParams = array('name' => 'other_amount', 'label' => 'Other Amount', 'price_set_id' => $priceSetId, 'html_type' => 'Text', 'is_display_amounts' => 0, 'weight' => 3); $fieldParams['option_weight'][1] = 1; $fieldParams['option_amount'][1] = 1; if (!$noContriAmount) { $fieldParams['is_required'] = 1; $fieldParams['option_label'][1] = 'Contribution Amount'; } else { $fieldParams['is_required'] = 0; $fieldParams['option_label'][1] = 'Other Amount'; } $priceField = CRM_Price_BAO_Field::create($fieldParams); } else { if (!CRM_Utils_Array::value('is_active', $editedResults)) { CRM_Price_BAO_Field::setIsActive($priceFieldID, '1'); } } } elseif (!CRM_Utils_Array::value('is_allow_other_amount', $params) && CRM_Utils_Array::value('price_field_other', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0'); } elseif ($priceFieldID = CRM_Utils_Array::value('price_field_other', $params)) { $priceFieldValueID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_FieldValue', $priceFieldID, 'id', 'price_field_id'); if (!$noContriAmount) { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 1); CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Contribution Amount'); } else { CRM_Core_DAO::setFieldValue('CRM_Price_DAO_Field', $priceFieldID, 'is_required', 0); CRM_Core_DAO::setFieldValue('CRM_Price_DAO_FieldValue', $priceFieldValueID, 'label', 'Other Amount'); } } } if (CRM_Utils_Array::value('is_pledge_active', $params)) { $deletePledgeBlk = FALSE; $pledgeBlockParams = array('entity_id' => $contributionPageID, 'entity_table' => ts('civicrm_contribution_page')); if ($this->_pledgeBlockID) { $pledgeBlockParams['id'] = $this->_pledgeBlockID; } $pledgeBlock = array('pledge_frequency_unit', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day'); foreach ($pledgeBlock as $key) { $pledgeBlockParams[$key] = CRM_Utils_Array::value($key, $params); } $pledgeBlockParams['is_pledge_interval'] = CRM_Utils_Array::value('is_pledge_interval', $params, FALSE); // create pledge block. CRM_Pledge_BAO_PledgeBlock::create($pledgeBlockParams); } } } else { if (CRM_Utils_Array::value('price_field_id', $params) || CRM_Utils_Array::value('price_field_other', $params)) { $usedPriceSetId = CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $this->_id, 3); if ($usedPriceSetId) { if (CRM_Utils_Array::value('price_field_id', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_id'], '0'); } if (CRM_Utils_Array::value('price_field_other', $params)) { CRM_Price_BAO_Field::setIsActive($params['price_field_other'], '0'); } } else { $deleteAmountBlk = TRUE; $deletePriceSet = TRUE; } } } // delete pledge block. if ($deletePledgeBlk) { CRM_Pledge_BAO_PledgeBlock::deletePledgeBlock($this->_pledgeBlockID); } // delete previous price set. if ($deletePriceSet) { CRM_Price_BAO_Set::removeFrom('civicrm_contribution_page', $contributionPageID); } if ($deleteAmountBlk) { $priceField = CRM_Utils_Array::value('price_field_id', $params) ? $params['price_field_id'] : CRM_Utils_Array::value('price_field_other', $params); if ($priceField) { $priceSetID = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $priceField, 'price_set_id'); CRM_Price_BAO_Set::setIsQuickConfig($priceSetID, 0); } } } parent::endPostProcess(); }
/** * Build the form object. */ public function buildQuickForm() { // build profiles first so that we can determine address fields etc // and then show copy address checkbox if (empty($this->_ccid)) { $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); $this->buildCustom($this->_values['custom_post_id'], 'customPost'); // CRM-18399: used by template to pass pre profile id as a url arg $this->assign('custom_pre_id', $this->_values['custom_pre_id']); $this->buildComponentForm($this->_id, $this); } // Build payment processor form CRM_Core_Payment_ProcessorForm::buildQuickForm($this); $config = CRM_Core_Config::singleton(); $contactID = $this->getContactID(); if ($contactID) { $this->assign('contact_id', $contactID); $this->assign('display_name', CRM_Contact_BAO_Contact::displayName($contactID)); } $this->applyFilter('__ALL__', 'trim'); if (empty($this->_ccid)) { $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60, 'class' => 'email'), TRUE); $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); } else { $this->addElement('hidden', "email-{$this->_bltID}", 1); $this->add('text', 'total_amount', ts('Total Amount'), array('readonly' => TRUE), FALSE); } $pps = array(); //@todo - this should be replaced by a check as to whether billing fields are set $onlinePaymentProcessorEnabled = FALSE; if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $key => $name) { if ($name['billing_mode'] == 1) { $onlinePaymentProcessorEnabled = TRUE; } $pps[$key] = $name['name']; } } if (!empty($this->_values['is_pay_later'])) { $pps[0] = $this->_values['pay_later_text']; } if (count($pps) > 1) { $this->addRadio('payment_processor_id', ts('Payment Method'), $pps, NULL, " "); } elseif (!empty($pps)) { $key = array_keys($pps); $key = array_pop($key); $this->addElement('hidden', 'payment_processor_id', $key); if ($key === 0) { $this->assign('is_pay_later', $this->_values['is_pay_later']); $this->assign('pay_later_text', $this->_values['pay_later_text']); } } $contactID = $this->getContactID(); if ($this->getContactID() === 0) { $this->addCidZeroOptions($onlinePaymentProcessorEnabled); } //build pledge block. $this->_useForMember = 0; //don't build membership block when pledge_id is passed if (empty($this->_values['pledge_id']) && empty($this->_ccid)) { $this->_separateMembershipPayment = FALSE; if (in_array('CiviMember', $config->enableComponents)) { $isTest = 0; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = 1; } if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) { $this->_useForMember = 1; $this->set('useForMember', $this->_useForMember); } $this->_separateMembershipPayment = $this->buildMembershipBlock($this->_membershipContactID, TRUE, NULL, FALSE, $isTest); } $this->set('separateMembershipPayment', $this->_separateMembershipPayment); } $this->assign('useForMember', $this->_useForMember); // If we configured price set for contribution page // we are not allow membership signup as well as any // other contribution amount field, CRM-5095 if (isset($this->_priceSetId) && $this->_priceSetId) { $this->add('hidden', 'priceSetId', $this->_priceSetId); // build price set form. $this->set('priceSetId', $this->_priceSetId); if (empty($this->_ccid)) { CRM_Price_BAO_PriceSet::buildPriceSet($this); } if ($this->_values['is_monetary'] && $this->_values['is_recur'] && empty($this->_values['pledge_id'])) { self::buildRecur($this); } } if ($this->_priceSetId && empty($this->_ccid)) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { $this->_useForMember = 0; $this->set('useForMember', $this->_useForMember); } } //we allow premium for pledge during pledge creation only. if (empty($this->_values['pledge_id']) && empty($this->_ccid)) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } //don't build pledge block when mid is passed if (!$this->_mid && empty($this->_ccid)) { $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) { CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this); } } //to create an cms user if (!$this->_contactID && empty($this->_ccid)) { $createCMSUser = FALSE; if ($this->_values['custom_pre_id']) { $profileID = $this->_values['custom_pre_id']; $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user'); } if (!$createCMSUser && $this->_values['custom_post_id']) { if (!is_array($this->_values['custom_post_id'])) { $profileIDs = array($this->_values['custom_post_id']); } else { $profileIDs = $this->_values['custom_post_id']; } foreach ($profileIDs as $pid) { if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) { $profileID = $pid; $createCMSUser = TRUE; break; } } } if ($createCMSUser) { CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE); } } if ($this->_pcpId && empty($this->_ccid)) { if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) { $pcp_supporter_text = ts('This contribution is being made thanks to the effort of <strong>%1</strong>, who supports our campaign.', array(1 => $pcpSupporter)); // Only tell people that can also create a PCP if the contribution page has a non-empty value in the "Create Personal Campaign Page link" field. $text = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute'); if (!empty($text)) { $pcp_supporter_text .= ts("You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!"); } $this->assign('pcpSupporterText', $pcp_supporter_text); } $prms = array('id' => $this->_pcpId); CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $prms, $pcpInfo); if ($pcpInfo['is_honor_roll']) { $this->assign('isHonor', TRUE); $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")); $extraOption = array('onclick' => "return pcpAnonymous( );"); $elements = array(); $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption); $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption); $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' '); $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } } if (empty($this->_values['fee']) && empty($this->_ccid)) { CRM_Core_Error::fatal(ts('This page does not have any price fields configured or you may not have permission for them. Please contact the site administrator for more details.')); } //we have to load confirm contribution button in template //when multiple payment processor as the user //can toggle with payment processor selection $billingModePaymentProcessors = 0; if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $key => $values) { if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) { $billingModePaymentProcessors++; } } } if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) { $allAreBillingModeProcessors = TRUE; } else { $allAreBillingModeProcessors = FALSE; } if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) { $submitButton = array('type' => 'upload', 'name' => CRM_Utils_Array::value('is_confirm_enabled', $this->_values) ? ts('Confirm Contribution') : ts('Contribute'), 'spacing' => ' ', 'isDefault' => TRUE); // Add submit-once behavior when confirm page disabled if (empty($this->_values['is_confirm_enabled'])) { $submitButton['js'] = array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');"); } //change button name for updating contribution if (!empty($this->_ccid)) { $submitButton['name'] = ts('Confirm Payment'); } $this->addButtons(array($submitButton)); } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); }
/** * 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); }
/** * Set default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * * @return array * defaults */ public function setDefaultValues() { //some child classes calling setdefaults directly w/o preprocess. $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if (isset($this->_id) && $this->_id) { $params = array('id' => $this->_id); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values); } $this->set('values', $this->_values); } $defaults = $this->_values; $config = CRM_Core_Config::singleton(); if (isset($this->_id)) { //set defaults for pledgeBlock values. $pledgeBlockParams = array('entity_id' => $this->_id, 'entity_table' => ts('civicrm_contribution_page')); $pledgeBlockDefaults = array(); CRM_Pledge_BAO_PledgeBlock::retrieve($pledgeBlockParams, $pledgeBlockDefaults); if ($this->_pledgeBlockID = CRM_Utils_Array::value('id', $pledgeBlockDefaults)) { $defaults['is_pledge_active'] = TRUE; } $pledgeBlock = array('is_pledge_interval', 'max_reminders', 'initial_reminder_day', 'additional_reminder_day'); foreach ($pledgeBlock as $key) { $defaults[$key] = CRM_Utils_Array::value($key, $pledgeBlockDefaults); } if (!empty($pledgeBlockDefaults['pledge_frequency_unit'])) { $defaults['pledge_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlockDefaults['pledge_frequency_unit']), '1'); } // fix the display of the monetary value, CRM-4038 if (isset($defaults['goal_amount'])) { $defaults['goal_amount'] = CRM_Utils_Money::format($defaults['goal_amount'], NULL, '%a'); } // get price set of type contributions //this is the value for stored in db if price set extends contribution $usedFor = 2; $this->_priceSetID = CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $this->_id, $usedFor, 1); if ($this->_priceSetID) { $defaults['price_set_id'] = $this->_priceSetID; } if (!empty($defaults['end_date'])) { list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']); } if (!empty($defaults['start_date'])) { list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']); } } else { $defaults['is_active'] = 1; // set current date as start date list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(); } if (!isset($defaults['for_organization'])) { $defaults['for_organization'] = ts('I am contributing on behalf of an organization.'); } if (!empty($defaults['recur_frequency_unit'])) { $defaults['recur_frequency_unit'] = array_fill_keys(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaults['recur_frequency_unit']), '1'); } else { # CRM 10860 $defaults['recur_frequency_unit'] = array('month' => 1); } if (!empty($defaults['is_for_organization'])) { $defaults['is_organization'] = 1; } else { $defaults['is_for_organization'] = 1; } // confirm page starts out enabled if (!isset($defaults['is_confirm_enabled'])) { $defaults['is_confirm_enabled'] = 1; } return $defaults; }
/** * Function to build Pledge Block in Contribution Pages * * @param int $pageId * @static */ function buildPledgeBlock($form) { //build pledge payment fields. if (CRM_Utils_Array::value('pledge_id', $form->_values)) { //get all payments required details. $allPayments = array(); $returnProperties = array('status_id', 'scheduled_date', 'scheduled_amount'); CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_PledgePayment', 'pledge_id', $form->_values['pledge_id'], $allPayments, $returnProperties); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $nextPayment = array(); $isNextPayment = FALSE; $overduePayments = array(); $now = date('Ymd'); foreach ($allPayments as $payID => $value) { if ($allStatus[$value['status_id']] == 'Overdue') { $overduePayments[$payID] = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d')); } elseif (!$isNextPayment && $allStatus[$value['status_id']] == 'Pending') { //get the next payment. $nextPayment = array('id' => $payID, 'scheduled_amount' => CRM_Utils_Rule::cleanMoney($value['scheduled_amount']), 'scheduled_date' => CRM_Utils_Date::customFormat($value['scheduled_date'], '%B %d')); $isNextPayment = TRUE; } } //build check box array for payments. $payments = array(); if (!empty($overduePayments)) { foreach ($overduePayments as $id => $payment) { $key = ts("\$%1 - due on %2 (overdue)", array(1 => CRM_Utils_Array::value('scheduled_amount', $payment), 2 => CRM_Utils_Array::value('scheduled_date', $payment))); $payments[$key] = CRM_Utils_Array::value('id', $payment); } } if (!empty($nextPayment)) { $key = ts("\$%1 - due on %2", array(1 => CRM_Utils_Array::value('scheduled_amount', $nextPayment), 2 => CRM_Utils_Array::value('scheduled_date', $nextPayment))); $payments[$key] = CRM_Utils_Array::value('id', $nextPayment); } //give error if empty or build form for payment. if (empty($payments)) { CRM_Core_Error::fatal(ts("Oops. It looks like there is no valid payment status for online payment.")); } else { $form->assign('is_pledge_payment', TRUE); $form->addCheckBox('pledge_amount', ts('Make Pledge Payment(s):'), $payments); } } else { $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); //build form for pledge creation. $pledgeOptions = array('0' => ts('I want to make a one-time contribution'), '1' => ts('I pledge to contribute this amount every')); $form->addRadio('is_pledge', ts('Pledge Frequency Interval'), $pledgeOptions, NULL, array('<br/>')); $form->addElement('text', 'pledge_installments', ts('Installments'), array('size' => 3)); if (CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock)) { $form->assign('is_pledge_interval', CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock)); $form->addElement('text', 'pledge_frequency_interval', NULL, array('size' => 3)); } else { $form->add('hidden', 'pledge_frequency_interval', 1); } //Frequency unit drop-down label suffixes switch from *ly to *(s) $freqUnitVals = explode(CRM_Core_DAO::VALUE_SEPARATOR, $pledgeBlock['pledge_frequency_unit']); $freqUnits = array(); $frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units'); foreach ($freqUnitVals as $key => $val) { if (array_key_exists($val, $frequencyUnits)) { $freqUnits[$val] = CRM_Utils_Array::value('is_pledge_interval', $pledgeBlock) ? "{$frequencyUnits[$val]}(s)" : $frequencyUnits[$val]; } } $form->addElement('select', 'pledge_frequency_unit', NULL, $freqUnits); } }
/** * Set up pledge block. */ public function setUpPledgeBlock() { $params = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_ids['contribution_page'], 'pledge_frequency_unit' => 'week', 'is_pledge_interval' => 0, 'pledge_start_date' => json_encode(array('calendar_date' => date('Ymd', strtotime("+1 month"))))); $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::create($params); $this->_ids['pledge_block_id'] = $pledgeBlock->id; }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_ppType) { return CRM_Core_Payment_ProcessorForm::buildQuickForm($this); } $config = CRM_Core_Config::singleton(); if (CRM_Utils_Array::value('is_for_organization', $this->_values) == 2) { $this->assign('onBehalfRequired', TRUE); $this->_onBehalfRequired = 1; } if ($this->_onbehalf) { $this->assign('onbehalf', TRUE); return CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this); } $this->applyFilter('__ALL__', 'trim'); $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60), TRUE); $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); $this->_paymentProcessors = $this->get('paymentProcessors'); $pps = array(); if (!empty($this->_paymentProcessors)) { $pps = $this->_paymentProcessors; foreach ($pps as $key => &$name) { $pps[$key] = $name['name']; } } if (CRM_Utils_Array::value('is_pay_later', $this->_values)) { $pps[0] = $this->_values['pay_later_text']; } if (count($pps) > 1) { $this->addRadio('payment_processor', ts('Payment Method'), $pps, NULL, " ", TRUE); } elseif (!empty($pps)) { $key = array_pop(array_keys($pps)); $this->addElement('hidden', 'payment_processor', $key); if ($key === 0) { $this->assign('is_pay_later', $this->_values['is_pay_later']); $this->assign('pay_later_text', $this->_values['pay_later_text']); } } //build pledge block. $this->_useForMember = 0; //don't build membership block when pledge_id is passed if (!CRM_Utils_Array::value('pledge_id', $this->_values)) { $this->_separateMembershipPayment = FALSE; if (in_array('CiviMember', $config->enableComponents)) { $isTest = 0; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = 1; } if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) { $this->_useForMember = 1; $this->set('useForMember', $this->_useForMember); } $this->_separateMembershipPayment = CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, TRUE, NULL, FALSE, $isTest, $this->_membershipContactID); } $this->set('separateMembershipPayment', $this->_separateMembershipPayment); } $this->assign('useForMember', $this->_useForMember); // If we configured price set for contribution page // we are not allow membership signup as well as any // other contribution amount field, CRM-5095 if (isset($this->_priceSetId) && $this->_priceSetId) { $this->add('hidden', 'priceSetId', $this->_priceSetId); // build price set form. $this->set('priceSetId', $this->_priceSetId); CRM_Price_BAO_Set::buildPriceSet($this); if ($this->_values['is_monetary'] && $this->_values['is_recur'] && !CRM_Utils_Array::value('pledge_id', $this->_values)) { self::buildRecur($this); } } elseif (CRM_Utils_Array::value('amount_block_is_active', $this->_values) && !CRM_Utils_Array::value('pledge_id', $this->_values)) { $this->buildAmount($this->_separateMembershipPayment); } if ($this->_priceSetId) { $is_quick_config = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config'); if ($is_quick_config) { $this->_useForMember = 0; $this->set('useForMember', $this->_useForMember); } } if ($this->_values['is_for_organization']) { $this->buildOnBehalfOrganization(); } //we allow premium for pledge during pledge creation only. if (!CRM_Utils_Array::value('pledge_id', $this->_values)) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, TRUE); } if ($this->_values['honor_block_is_active']) { $this->buildHonorBlock(); } //don't build pledge block when mid is passed if (!$this->_mid) { $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('pledge_block_id', $this->_values)) { CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this); } } $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); $this->buildCustom($this->_values['custom_post_id'], 'customPost'); if (!empty($this->_fields)) { $profileAddressFields = array(); foreach ($this->_fields as $key => $value) { CRM_Core_BAO_UFField::assignAddressField($key, $profileAddressFields); } $this->set('profileAddressFields', $profileAddressFields); } //to create an cms user if (!$this->_userID) { $createCMSUser = FALSE; if ($this->_values['custom_pre_id']) { $profileID = $this->_values['custom_pre_id']; $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user'); } if (!$createCMSUser && $this->_values['custom_post_id']) { if (!is_array($this->_values['custom_post_id'])) { $profileIDs = array($this->_values['custom_post_id']); } else { $profileIDs = $this->_values['custom_post_id']; } foreach ($profileIDs as $pid) { if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $pid, 'is_cms_user')) { $profileID = $pid; $createCMSUser = TRUE; break; } } } if ($createCMSUser) { CRM_Core_BAO_CMSUser::buildForm($this, $profileID, TRUE); } } if ($this->_pcpId) { if ($pcpSupporter = CRM_PCP_BAO_PCP::displayName($this->_pcpId)) { $this->assign('pcpSupporterText', ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter))); } $this->assign('pcp', TRUE); $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), NULL, NULL, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")); $extraOption = array('onclick' => "return pcpAnonymous( );"); $elements = array(); $elements[] =& $this->createElement('radio', NULL, '', ts('Include my name and message'), 0, $extraOption); $elements[] =& $this->createElement('radio', NULL, '', ts('List my contribution anonymously'), 1, $extraOption); $this->addGroup($elements, 'pcp_is_anonymous', NULL, ' '); $this->_defaults['pcp_is_anonymous'] = 0; $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } //we have to load confirm contribution button in template //when multiple payment processor as the user //can toggle with payment processor selection $billingModePaymentProcessors = 0; if (!empty($this->_paymentProcessors)) { foreach ($this->_paymentProcessors as $key => $values) { if ($values['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON) { $billingModePaymentProcessors++; } } } if ($billingModePaymentProcessors && count($this->_paymentProcessors) == $billingModePaymentProcessors) { $allAreBillingModeProcessors = TRUE; } else { $allAreBillingModeProcessors = FALSE; } if (!($allAreBillingModeProcessors && !$this->_values['is_pay_later'])) { $this->addButtons(array(array('type' => 'upload', 'name' => ts('Confirm Contribution'), 'spacing' => ' ', 'isDefault' => TRUE))); } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); }
/** * Post form submission handling. * * This is also called from the test suite. * * @param int $contactID * * @return array */ protected function processFormSubmission($contactID) { $isPayLater = $this->_params['is_pay_later']; if (!isset($this->_params['payment_processor_id'])) { // If there is no processor we are using the pay-later manual pseudo-processor. // (note it might make sense to make this a row in the processor table in the db). $this->_params['payment_processor_id'] = 0; } if (isset($this->_params['payment_processor_id']) && $this->_params['payment_processor_id'] === 0) { $this->_params['is_pay_later'] = $isPayLater = TRUE; } if (!empty($this->_ccid)) { $this->_params['contribution_id'] = $this->_ccid; } // add a description field at the very beginning $this->_params['description'] = ts('Online Contribution') . ': ' . ($this->_pcpInfo['title'] ? $this->_pcpInfo['title'] : $this->_values['title']); $this->_params['accountingCode'] = CRM_Utils_Array::value('accountingCode', $this->_values); // fix currency ID $this->_params['currencyID'] = CRM_Core_Config::singleton()->defaultCurrency; // CRM-18854 if (CRM_Utils_Array::value('adjust_recur_start_date', $this->_values)) { $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id); if (CRM_Utils_Array::value('start_date', $this->_params) || !CRM_Utils_Array::value('is_pledge_start_date_visible', $pledgeBlock)) { $pledgeStartDate = CRM_Utils_Array::value('start_date', $this->_params, NULL); $this->_params['receive_date'] = CRM_Pledge_BAO_Pledge::getPledgeStartDate($pledgeStartDate, $pledgeBlock); $recurParams = CRM_Pledge_BAO_Pledge::buildRecurParams($this->_params); $this->_params = array_merge($this->_params, $recurParams); } } //carry payment processor id. if (CRM_Utils_Array::value('id', $this->_paymentProcessor)) { $this->_params['payment_processor_id'] = $this->_paymentProcessor['id']; } $premiumParams = $membershipParams = $params = $this->_params; if (!empty($params['image_URL'])) { CRM_Contact_BAO_Contact::processImageParams($params); } $fields = array('email-Primary' => 1); // get the add to groups $addToGroups = array(); // now set the values for the billing location. foreach ($this->_fields as $name => $value) { $fields[$name] = 1; // get the add to groups for uf fields if (!empty($value['add_to_group_id'])) { $addToGroups[$value['add_to_group_id']] = $value['add_to_group_id']; } } $fields = $this->formatParamsForPaymentProcessor($fields); // billing email address $fields["email-{$this->_bltID}"] = 1; // if onbehalf-of-organization contribution, take out // organization params in a separate variable, to make sure // normal behavior is continued. And use that variable to // process on-behalf-of functionality. if (!empty($this->_values['onbehalf_profile_id']) && empty($this->_ccid)) { $behalfOrganization = array(); $orgFields = array('organization_name', 'organization_id', 'org_option'); foreach ($orgFields as $fld) { if (array_key_exists($fld, $params)) { $behalfOrganization[$fld] = $params[$fld]; unset($params[$fld]); } } if (is_array($params['onbehalf']) && !empty($params['onbehalf'])) { foreach ($params['onbehalf'] as $fld => $values) { if (strstr($fld, 'custom_')) { $behalfOrganization[$fld] = $values; } elseif (!strstr($fld, '-')) { if (in_array($fld, array('contribution_campaign_id', 'member_campaign_id'))) { $fld = 'campaign_id'; } else { $behalfOrganization[$fld] = $values; } $this->_params[$fld] = $values; } } } if (array_key_exists('onbehalf_location', $params) && is_array($params['onbehalf_location'])) { foreach ($params['onbehalf_location'] as $block => $vals) { //fix for custom data (of type checkbox, multi-select) if (substr($block, 0, 7) == 'custom_') { continue; } // fix the index of block elements if (is_array($vals)) { foreach ($vals as $key => $val) { //dont adjust the index of address block as //it's index is WRT to location type $newKey = $block == 'address' ? $key : ++$key; $behalfOrganization[$block][$newKey] = $val; } } } unset($params['onbehalf_location']); } if (!empty($params['onbehalf[image_URL]'])) { $behalfOrganization['image_URL'] = $params['onbehalf[image_URL]']; } } // check for profile double opt-in and get groups to be subscribed $subscribeGroupIds = CRM_Core_BAO_UFGroup::getDoubleOptInGroupIds($params, $contactID); // since we are directly adding contact to group lets unset it from mailing if (!empty($addToGroups)) { foreach ($addToGroups as $groupId) { if (isset($subscribeGroupIds[$groupId])) { unset($subscribeGroupIds[$groupId]); } } } foreach ($addToGroups as $k) { if (array_key_exists($k, $subscribeGroupIds)) { unset($addToGroups[$k]); } } if (empty($contactID)) { $dupeParams = $params; if (!empty($dupeParams['onbehalf'])) { unset($dupeParams['onbehalf']); } if (!empty($dupeParams['honor'])) { unset($dupeParams['honor']); } $dedupeParams = CRM_Dedupe_Finder::formatParams($dupeParams, 'Individual'); $dedupeParams['check_permission'] = FALSE; $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual'); // if we find more than one contact, use the first one $contactID = CRM_Utils_Array::value(0, $ids); // Fetch default greeting id's if creating a contact if (!$contactID) { foreach (CRM_Contact_BAO_Contact::$_greetingTypes as $greeting) { if (!isset($params[$greeting])) { $params[$greeting] = CRM_Contact_BAO_Contact_Utils::defaultGreeting('Individual', $greeting); } } } $contactType = NULL; } else { $contactType = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'contact_type'); } $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $contactID, $addToGroups, NULL, $contactType, TRUE); // Make the contact ID associated with the contribution available at the Class level. // Also make available to the session. //@todo consider handling this in $this->getContactID(); $this->set('contactID', $contactID); $this->_contactID = $contactID; //get email primary first if exist $subscriptionEmail = array('email' => CRM_Utils_Array::value('email-Primary', $params)); if (!$subscriptionEmail['email']) { $subscriptionEmail['email'] = CRM_Utils_Array::value("email-{$this->_bltID}", $params); } // subscribing contact to groups if (!empty($subscribeGroupIds) && $subscriptionEmail['email']) { CRM_Mailing_Event_BAO_Subscribe::commonSubscribe($subscribeGroupIds, $subscriptionEmail, $contactID); } // If onbehalf-of-organization contribution / signup, add organization // and it's location. if (isset($this->_values['onbehalf_profile_id']) && isset($behalfOrganization['organization_name']) && ($this->_values['is_for_organization'] == 2 || !empty($this->_params['is_for_organization']))) { $ufFields = array(); foreach ($this->_fields['onbehalf'] as $name => $value) { $ufFields[$name] = 1; } self::processOnBehalfOrganization($behalfOrganization, $contactID, $this->_values, $this->_params, $ufFields); } elseif (!empty($this->_membershipContactID) && $contactID != $this->_membershipContactID) { // this is an onbehalf renew case for inherited membership. For e.g a permissioned member of household, // store current user id as related contact for later use for mailing / activity.. $this->_values['related_contact'] = $contactID; $this->_params['related_contact'] = $contactID; // swap contact like we do for on-behalf-org case, so parent/primary membership is affected $contactID = $this->_membershipContactID; } // lets store the contactID in the session // for things like tell a friend $session = CRM_Core_Session::singleton(); if (!$session->get('userID')) { $session->set('transaction.userID', $contactID); } else { $session->set('transaction.userID', NULL); } $this->_useForMember = $this->get('useForMember'); // store the fact that this is a membership and membership type is selected if (!empty($membershipParams['selectMembership']) && $membershipParams['selectMembership'] != 'no_thanks' || $this->_useForMember) { if (!$this->_useForMember) { $this->assign('membership_assign', TRUE); $this->set('membershipTypeID', $this->_params['selectMembership']); } if ($this->_action & CRM_Core_Action::PREVIEW) { $membershipParams['is_test'] = 1; } if ($this->_params['is_pay_later']) { $membershipParams['is_pay_later'] = 1; } //inherit campaign from contribution page. if (!array_key_exists('campaign_id', $membershipParams)) { $membershipParams['campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->_values); } CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $membershipParams, TRUE); $this->doMembershipProcessing($contactID, $membershipParams, $premiumParams, $isPayLater); } else { // at this point we've created a contact and stored its address etc // all the payment processors expect the name and address to be in the // so we copy stuff over to first_name etc. $paymentParams = $this->_params; if (!empty($paymentParams['onbehalf']) && is_array($paymentParams['onbehalf'])) { foreach ($paymentParams['onbehalf'] as $key => $value) { if (strstr($key, 'custom_')) { $this->_params[$key] = $value; } } } $result = CRM_Contribute_BAO_Contribution_Utils::processConfirm($this, $paymentParams, $contactID, $this->wrangleFinancialTypeID($this->_values['financial_type_id']), 'contribution', $this->_mode == 'test' ? 1 : 0, CRM_Utils_Array::value('is_recur', $paymentParams)); if (empty($result['is_payment_failure'])) { // @todo move premium processing to complete transaction if it truly is an 'after' action. $this->postProcessPremium($premiumParams, $result['contribution']); } if (!empty($result['contribution'])) { // Not quite sure why it would be empty at this stage but tests show it can be ... at least in tests. $this->completeTransaction($result, $result['contribution']->id); } return $result; } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { $config = CRM_Core_Config::singleton(); if ($this->_values['is_for_organization'] == 2) { $this->assign('onBehalfRequired', true); } if ($this->_onbehalf) { $this->assign('onbehalf', true); return CRM_Contribute_Form_Contribution_OnBehalfOf::buildQuickForm($this); } $this->applyFilter('__ALL__', 'trim'); $this->add('text', "email-{$this->_bltID}", ts('Email Address'), array('size' => 30, 'maxlength' => 60), true); $this->addRule("email-{$this->_bltID}", ts('Email is not valid.'), 'email'); //build pledge block. $this->_useForMember = 0; //don't build membership block when pledge_id is passed if (!CRM_Utils_Array::value('pledge_id', $this->_values)) { $this->_separateMembershipPayment = false; if (in_array('CiviMember', $config->enableComponents)) { $isTest = 0; if ($this->_action & CRM_Core_Action::PREVIEW) { $isTest = 1; } if ($this->_priceSetId && CRM_Core_Component::getComponentID('CiviMember') == CRM_Utils_Array::value('extends', $this->_priceSet)) { $this->_useForMember = 1; $this->set('useForMember', $this->_useForMember); } require_once 'CRM/Member/BAO/Membership.php'; $this->_separateMembershipPayment = CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, true, null, false, $isTest, $this->_membershipContactID); } $this->set('separateMembershipPayment', $this->_separateMembershipPayment); } $this->assign('useForMember', $this->_useForMember); // If we configured price set for contribution page // we are not allow membership signup as well as any // other contribution amount field, CRM-5095 if (isset($this->_priceSetId) && $this->_priceSetId) { $this->add('hidden', 'priceSetId', $this->_priceSetId); // build price set form. $this->set('priceSetId', $this->_priceSetId); require_once 'CRM/Price/BAO/Set.php'; CRM_Price_BAO_Set::buildPriceSet($this); } else { if (CRM_Utils_Array::value('amount_block_is_active', $this->_values) && !CRM_Utils_Array::value('pledge_id', $this->_values)) { $this->buildAmount($this->_separateMembershipPayment); if ($this->_values['is_monetary'] && $this->_values['is_recur'] && $this->_paymentProcessor['is_recur']) { self::buildRecur($this); } } } if (CRM_Utils_Array::value('is_pay_later', $this->_values)) { $this->buildPayLater(); } if ($this->_values['is_for_organization']) { $this->buildOnBehalfOrganization(); } //we allow premium for pledge during pledge creation only. if (!CRM_Utils_Array::value('pledge_id', $this->_values)) { require_once 'CRM/Contribute/BAO/Premium.php'; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, true); } if ($this->_values['honor_block_is_active']) { $this->buildHonorBlock(); } //don't build pledge block when mid is passed if (!$this->_mid) { $config = CRM_Core_Config::singleton(); if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('pledge_block_id', $this->_values)) { require_once 'CRM/Pledge/BAO/PledgeBlock.php'; CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this); } } $this->buildCustom($this->_values['custom_pre_id'], 'customPre'); $this->buildCustom($this->_values['custom_post_id'], 'customPost'); // doing this later since the express button type depends if there is an upload or not if ($this->_values['is_monetary']) { require_once 'CRM/Core/Payment/Form.php'; if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) { CRM_Core_Payment_Form::buildDirectDebit($this); } else { CRM_Core_Payment_Form::buildCreditCard($this); } } //to create an cms user if (!$this->_userID) { $createCMSUser = false; if ($this->_values['custom_pre_id']) { $profileID = $this->_values['custom_pre_id']; $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user'); } if (!$createCMSUser && $this->_values['custom_post_id']) { $profileID = $this->_values['custom_post_id']; $createCMSUser = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileID, 'is_cms_user'); } if ($createCMSUser) { require_once 'CRM/Core/BAO/CMSUser.php'; CRM_Core_BAO_CMSUser::buildForm($this, $profileID, true); } } if ($this->_pcpId) { require_once 'CRM/Contribute/BAO/PCP.php'; if ($pcpSupporter = CRM_Contribute_BAO_PCP::displayName($this->_pcpId)) { $this->assign('pcpSupporterText', ts('This contribution is being made thanks to effort of <strong>%1</strong>, who supports our campaign. You can support it as well - once you complete the donation, you will be able to create your own Personal Campaign Page!', array(1 => $pcpSupporter))); } $this->assign('pcp', true); $this->add('checkbox', 'pcp_display_in_roll', ts('Show my contribution in the public honor roll'), null, null, array('onclick' => "showHideByValue('pcp_display_in_roll','','nameID|nickID|personalNoteID','block','radio',false); pcpAnonymous( );")); $extraOption = array('onclick' => "return pcpAnonymous( );"); $elements = array(); $elements[] =& $this->createElement('radio', null, '', ts('Include my name and message'), 0, $extraOption); $elements[] =& $this->createElement('radio', null, '', ts('List my contribution anonymously'), 1, $extraOption); $this->addGroup($elements, 'pcp_is_anonymous', null, ' '); $this->_defaults['pcp_is_anonymous'] = 0; $this->add('text', 'pcp_roll_nickname', ts('Name'), array('maxlength' => 30)); $this->add('textarea', 'pcp_personal_note', ts('Personal Note'), array('style' => 'height: 3em; width: 40em;')); } if (!($this->_paymentProcessor['billing_mode'] == CRM_Core_Payment::BILLING_MODE_BUTTON && !$this->_values['is_pay_later'])) { $this->addButtons(array(array('type' => 'upload', 'name' => ts('Confirm Contribution'), 'spacing' => ' ', 'isDefault' => true))); } $this->addFormRule(array('CRM_Contribute_Form_Contribution_Main', 'formRule'), $this); }