_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('An error occurred during form submission. This page requires form data to be submitted for processing and no form data was submitted or processed. We are sorry for any inconvience. Please click here to visit the contribution page and re-start the contribution process.', 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) { $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) { $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."), 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'); // 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(); } } /** * set the default values * * @return void * @access public */ function setDefaultValues() { return $this->_defaults; } /** * assign the minimal set of variables to the template * * @return void * @access public */ function assignToTemplate() { $name = CRM_Utils_Array::value('billing_first_name', $this->_params); if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) { $name .= " {$this->_params['billing_middle_name']}"; } $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $this->_params); $name = trim($name); $this->assign('billingName', $name); $this->set('name', $name); $this->assign('paymentProcessor', $this->_paymentProcessor); $vars = array( 'amount', 'currencyID', 'credit_card_type', 'trxn_id', 'amount_level', ); $config = CRM_Core_Config::singleton(); if (isset($this->_values['is_recur']) && CRM_Utils_Array::value('is_recur', $this->_paymentProcessor) ) { $this->assign('is_recur_enabled', 1); $vars = array_merge($vars, array( 'is_recur', 'frequency_interval', 'frequency_unit', 'installments', )); } if (in_array('CiviPledge', $config->enableComponents) && CRM_Utils_Array::value('is_pledge', $this->_params) == 1 ) { $this->assign('pledge_enabled', 1); $vars = array_merge($vars, array( 'is_pledge', 'pledge_frequency_interval', 'pledge_frequency_unit', 'pledge_installments', )); } if (isset($this->_params['amount_other']) || isset($this->_params['selectMembership'])) { $this->_params['amount_level'] = ''; } foreach ($vars as $v) { if (isset($this->_params[$v])) { if ($v == 'frequency_unit' || $v == 'pledge_frequency_unit') { $frequencyUnits = CRM_Core_OptionGroup::values('recur_frequency_units'); if (array_key_exists($this->_params[$v], $frequencyUnits)) { $this->_params[$v] = $frequencyUnits[$this->_params[$v]]; } } if ($v == "amount") { $this->_params[$v] = CRM_Utils_Money::format($this->_params[$v], ' '); } $this->assign($v, $this->_params[$v]); } } // assign the address formatted up for display $addressParts = array( "street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}", ); $addressFields = array(); foreach ($addressParts as $part) { list($n, $id) = explode('-', $part); $addressFields[$n] = CRM_Utils_Array::value('billing_' . $part, $this->_params); } $this->assign('address', CRM_Utils_Address::format($addressFields)); if (CRM_Utils_Array::value('hidden_onbehalf_profile', $this->_params)) { $this->assign('onBehalfName', $this->_params['organization_name']); $locTypeId = array_keys($this->_params['onbehalf_location']['email']); $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']); } //fix for CRM-3767 $assignCCInfo = FALSE; if ($this->_amount > 0.0) { $assignCCInfo = TRUE; } elseif (CRM_Utils_array::value('selectMembership', $this->_params)) { $memFee = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_params['selectMembership'], 'minimum_fee'); if ($memFee > 0.0) { $assignCCInfo = TRUE; } } if ($this->_contributeMode == 'direct' && $assignCCInfo) { if ($this->_paymentProcessor && $this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT ) { $this->assign('payment_type', $this->_paymentProcessor['payment_type']); $this->assign('account_holder', $this->_params['account_holder']); $this->assign('bank_identification_number', $this->_params['bank_identification_number']); $this->assign('bank_name', $this->_params['bank_name']); $this->assign('bank_account_number', $this->_params['bank_account_number']); } else { $date = CRM_Utils_Date::format(CRM_Utils_array::value('credit_card_exp_date', $this->_params)); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard(CRM_Utils_array::value('credit_card_number', $this->_params)) ); } } $this->assign('email', $this->controller->exportValue('Main', "email-{$this->_bltID}") ); // also assign the receipt_text if (isset($this->_values['receipt_text'])) { $this->assign('receipt_text', $this->_values['receipt_text']); } } /** * Function to add the custom fields * * @return None * @access public */ function buildCustom($id, $name, $viewOnly = FALSE, $onBehalf = FALSE, $fieldTypes = NULL) { $stateCountryMap = array(); if ($id) { $contactID = $this->_userID; // we don't allow conflicting fields to be // configured via profile - CRM 2100 $fieldsToIgnore = array( 'receive_date' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'net_amount' => 1, 'fee_amount' => 1, 'non_deductible_amount' => 1, 'total_amount' => 1, 'amount_level' => 1, 'contribution_status_id' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'financial_type' => 1, ); $fields = NULL; if ($contactID && CRM_Core_BAO_UFGroup::filterUFGroups($id, $contactID)) { $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL ); } else { $fields = CRM_Core_BAO_UFGroup::getFields($id, FALSE, CRM_Core_Action::ADD, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL ); } if ($fields) { // unset any email-* fields since we already collect it, CRM-2888 foreach (array_keys($fields) as $fieldName) { if (substr($fieldName, 0, 6) == 'email-') { unset($fields[$fieldName]); } } if (array_intersect_key($fields, $fieldsToIgnore)) { $fields = array_diff_key($fields, $fieldsToIgnore); CRM_Core_Session::setStatus(ts('Some of the profile fields cannot be configured for this page.'), ts('Warning'), 'alert'); } $fields = array_diff_assoc($fields, $this->_fields); CRM_Core_BAO_Address::checkContactSharedAddressFields($fields, $contactID); $addCaptcha = FALSE; foreach ($fields as $key => $field) { if ($viewOnly && isset($field['data_type']) && $field['data_type'] == 'File' || ($viewOnly && $field['name'] == 'image_URL') ) { // ignore file upload fields continue; } list($prefixName, $index) = CRM_Utils_System::explode('-', $key, 2); if ($prefixName == 'state_province' || $prefixName == 'country' || $prefixName == 'county') { if (!array_key_exists($index, $stateCountryMap)) { $stateCountryMap[$index] = array(); } $stateCountryMap[$index][$prefixName] = $key; } if ($onBehalf) { if (!empty($fieldTypes) && in_array($field['field_type'], $fieldTypes)) { CRM_Core_BAO_UFGroup::buildProfile( $this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE ); $this->_fields['onbehalf'][$key] = $field; } else { unset($fields[$key]); } } else { CRM_Core_BAO_UFGroup::buildProfile( $this, $field, CRM_Profile_Form::MODE_CREATE, $contactID, TRUE ); $this->_fields[$key] = $field; } // CRM-11316 Is ReCAPTCHA enabled for this profile AND is this an anonymous visitor if ($field['add_captcha'] && !$this->_userID) { $addCaptcha = TRUE; } } $this->assign($name, $fields); CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap); if ($addCaptcha && !$viewOnly) { $captcha = CRM_Utils_ReCAPTCHA::singleton(); $captcha->add($this); $this->assign('isCaptcha', TRUE); } } } } function checkTemplateFileExists($suffix = NULL) { if ($this->_id) { $templateFile = "CRM/Contribute/Form/Contribution/{$this->_id}/{$this->_name}.{$suffix}tpl"; $template = CRM_Core_Form::getTemplate(); if ($template->template_exists($templateFile)) { return $templateFile; } } return NULL; } function getTemplateFileName() { $fileName = $this->checkTemplateFileExists(); return $fileName ? $fileName : parent::getTemplateFileName(); } function overrideExtraTemplateFileName() { $fileName = $this->checkTemplateFileExists('extra.'); return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); } /** * Function to authenticate pledge user during online payment. * * @access public * * @return None */ public function authenticatePledgeUser() { //get the userChecksum and contact id $userChecksum = CRM_Utils_Request::retrieve('cs', 'String', $this); $contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this); //get pledge status and contact id $pledgeValues = array(); $pledgeParams = array('id' => $this->_values['pledge_id']); $returnProperties = array('contact_id', 'status_id'); CRM_Core_DAO::commonRetrieve('CRM_Pledge_DAO_Pledge', $pledgeParams, $pledgeValues, $returnProperties); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $validStatus = array(array_search('Pending', $allStatus), array_search('In Progress', $allStatus), array_search('Overdue', $allStatus), ); $validUser = FALSE; if ($this->_userID && $this->_userID == $pledgeValues['contact_id'] ) { //check for authenticated user. $validUser = TRUE; } elseif ($userChecksum && $pledgeValues['contact_id']) { //check for anonymous user. $validUser = CRM_Contact_BAO_Contact_Utils::validChecksum($pledgeValues['contact_id'], $userChecksum); //make sure cid is same as pledge contact id if ($validUser && ($pledgeValues['contact_id'] != $contactID)) { $validUser = FALSE; } } if (!$validUser) { CRM_Core_Error::fatal(ts("Oops. It looks like you have an incorrect or incomplete link (URL). Please make sure you've copied the entire link, and try again. Contact the site administrator if this error persists.")); } //check for valid pledge status. if (!in_array($pledgeValues['status_id'], $validStatus)) { CRM_Core_Error::fatal(ts('Oops. You cannot make a payment for this pledge - pledge status is %1.', array(1 => CRM_Utils_Array::value($pledgeValues['status_id'], $allStatus)))); } } /** * In case user cancel recurring contribution, * When we get the control back from payment gate way * lets delete the recurring and related contribution. * **/ public function cancelRecurring() { $isCancel = CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject); if ($isCancel) { $isRecur = CRM_Utils_Request::retrieve('isRecur', 'Boolean', CRM_Core_DAO::$_nullObject); $recurId = CRM_Utils_Request::retrieve('recurId', 'Positive', CRM_Core_DAO::$_nullObject); //clean db for recurring contribution. if ($isRecur && $recurId) { CRM_Contribute_BAO_ContributionRecur::deleteRecurContribution($recurId); } $contribId = CRM_Utils_Request::retrieve('contribId', 'Positive', CRM_Core_DAO::$_nullObject); if ($contribId) { CRM_Contribute_BAO_Contribution::deleteContribution($contribId); } } } }