/** * Set variables up before form is built. * * @param CRM_Core_Form $form */ public static function preProcess(&$form) { $session = CRM_Core_Session::singleton(); $contactID = $form->_contactID; $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id); $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $form->_profileId = $profileId[0]; if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, 'is_active')) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.')); } $requiredProfileFields = array('organization_name', 'email'); $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields); if (!$validProfile) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.')); } $form->assign('profileId', $form->_profileId); $form->assign('mode', $form->_mode); if ($contactID) { $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); if (!empty($form->_membershipContactID) && $contactID != $form->_membershipContactID) { // renewal case - membership being renewed may or may not be for organization if (!empty($form->_employers) && array_key_exists($form->_membershipContactID, $form->_employers)) { // if _membershipContactID belongs to employers list, we can say: $form->_relatedOrganizationFound = TRUE; } } elseif (!empty($form->_employers)) { // not a renewal case and _employers list is not empty $form->_relatedOrganizationFound = TRUE; } if ($form->_relatedOrganizationFound) { // Related org url - pass checksum if needed $args = array('cid' => ''); if (!empty($_GET['cs'])) { $args = array('uid' => $form->_contactID, 'cs' => $_GET['cs'], 'cid' => ''); } $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE); $form->assign('locDataURL', $locDataURL); if (!empty($form->_submitValues['onbehalf'])) { if (!empty($form->_submitValues['onbehalfof_id'])) { $form->assign('submittedOnBehalf', $form->_submitValues['onbehalfof_id']); } $form->assign('submittedOnBehalfInfo', json_encode($form->_submitValues['onbehalf'])); } } if ($form->_values['is_for_organization'] != 2) { $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound); } else { $form->assign('onBehalfRequired', $form->_onBehalfRequired); } if (count($form->_employers) == 1) { foreach ($form->_employers as $id => $value) { $form->_organizationName = $value['name']; $orgId = $id; } $form->assign('orgId', $orgId); $form->assign('organizationName', $form->_organizationName); } } }
/** * Set variables up before form is built. * * @param CRM_Core_Form $form * * @return void */ public static function preProcess(&$form) { $contriDAO = new CRM_Contribute_DAO_Contribution(); $contriDAO->id = $form->_id; $contriDAO->find(TRUE); if ($contriDAO->contribution_page_id) { $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $contriDAO->contribution_page_id); $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); //check if any honree profile is enabled if yes then assign its profile type to $_honoreeProfileType // which will be used to constraint soft-credit contact type in formRule, CRM-13981 if ($profileId[0]) { $form->_honoreeProfileType = CRM_Core_BAO_UFGroup::getContactType($profileId[0]); } } }
/** * takes an associative array and creates a uf join object * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Core_DAO_UFJoin object * @access public * @static */ function &create($params) { // see if a record exists with the same weight $id = CRM_Core_BAO_UFJoin::findJoinEntryId($params); if ($id) { $params['id'] = $id; } $dao =& new CRM_Core_DAO_UFJoin(); $dao->copyValues($params); if ($params['uf_group_id']) { $dao->save(); } else { $dao->delete(); } return $dao; }
static function setValues($id, &$values) { $params = array('id' => $id); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $values); // get the amounts and the label require_once 'CRM/Core/OptionGroup.php'; $values['amount'] = array(); CRM_Core_OptionGroup::getAssoc("civicrm_contribution_page.amount.{$id}", $values['amount'], true); // get the profile ids require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $id); list($values['custom_pre_id'], $values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // add an accounting code also if ($values['contribution_type_id']) { $values['accountingCode'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $values['contribution_type_id'], 'accounting_code'); } }
/** * Set variables up before form is built. * * @param CRM_Core_Form $form */ public static function preProcess(&$form) { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); $ufJoinParams = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id); $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $form->_honoreeProfileId = $profileId[0]; if (!$form->_honoreeProfileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_honoreeProfileId, 'is_active')) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the selected honoree profile is either disabled or not found.')); } $profileContactType = CRM_Core_BAO_UFGroup::getContactType($form->_honoreeProfileId); $requiredProfileFields = array('Individual' => array('first_name', 'last_name'), 'Organization' => array('organization_name', 'email'), 'Household' => array('household_name', 'email')); $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_honoreeProfileId, $requiredProfileFields[$profileContactType]); if (!$validProfile) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.')); } }
/** * Function to set variables up before form is built * * @return void * @access public */ function preProcess() { // current contribution page id $this->_id = $this->get('id'); // get all the values from the dao object $params = array('id' => $this->_id); $this->_values = array(); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values); // get the amounts and the label require_once 'CRM/Core/BAO/CustomOption.php'; CRM_Core_BAO_CustomOption::getAssoc('civicrm_contribution_page', $this->_id, $this->_values); // get the profile ids require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id, 'weight' => 1); $this->_values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $ufJoinParams['weight'] = 2; $this->_values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); }
/** * Function to set variables up before form is built * * @return void * @access public */ static function preProcess(&$form) { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $form->_id); $profileId = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $form->_profileId = $profileId[0]; if (!$form->_profileId || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $form->_profileId, 'is_active')) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the selected onbehalf profile is either disabled or not found.')); } $requiredProfileFields = array('organization_name', 'email'); $validProfile = CRM_Core_BAO_UFGroup::checkValidProfile($form->_profileId, $requiredProfileFields); if (!$validProfile) { CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of an organization and the required fields of the selected onbehalf profile are disabled.')); } $form->assign('profileId', $form->_profileId); $form->assign('mode', $form->_mode); if ($contactID) { $form->_employers = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID); if (!empty($form->_employers)) { $form->_relatedOrganizationFound = TRUE; $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', 'cid=', FALSE, NULL, FALSE); $form->assign('locDataURL', $locDataURL); $dataURL = CRM_Utils_System::url('civicrm/ajax/employer', 'cid=' . $contactID, FALSE, NULL, FALSE); $form->assign('employerDataURL', $dataURL); } if ($form->_values['is_for_organization'] != 2) { $form->assign('relatedOrganizationFound', $form->_relatedOrganizationFound); } else { $form->assign('onBehalfRequired', $form->_onBehalfRequired); } if (count($form->_employers) == 1) { foreach ($form->_employers as $id => $value) { $form->_organizationName = $value['name']; $orgId = $id; } $form->assign('orgId', $orgId); $form->assign('organizationName', $form->_organizationName); } } }
function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) { $contribution =& $objects['contribution']; $primaryContributionID = isset($contribution->id) ? $contribution->id : $objects['first_contribution']->id; $memberships =& $objects['membership']; if (is_numeric($memberships)) { $memberships = array($objects['membership']); } $participant =& $objects['participant']; $event =& $objects['event']; $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now); $recurContrib =& $objects['contributionRecur']; $values = array(); if (isset($input['is_email_receipt'])) { $values['is_email_receipt'] = $input['is_email_receipt']; } $source = NULL; if ($input['component'] == 'contribute') { if ($contribution->contribution_page_id) { CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values); $source = ts('Online Contribution') . ': ' . $values['title']; } elseif ($recurContrib && $recurContrib->id) { $contribution->contribution_page_id = NULL; $values['amount'] = $recurContrib->amount; $values['financial_type_id'] = $objects['contributionType']->id; $values['title'] = $source = ts('Offline Recurring Contribution'); $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $values['receipt_from_name'] = $domainValues[0]; $values['receipt_from_email'] = $domainValues[1]; } if ($recurContrib && $recurContrib->id && !isset($input['is_email_receipt'])) { //CRM-13273 - is_email_receipt setting on recurring contribution should take precedence over contribution page setting // but CRM-16124 if $input['is_email_receipt'] is set then that should not be overridden. $values['is_email_receipt'] = $recurContrib->is_email_receipt; } $contribution->source = $source; if (CRM_Utils_Array::value('is_email_receipt', $values)) { $contribution->receipt_date = self::$_now; } if (!empty($memberships)) { $membershipsUpdate = array(); foreach ($memberships as $membershipTypeIdKey => $membership) { if ($membership) { $format = '%Y%m%d'; $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id); // CRM-8141 update the membership type with the value recorded in log when membership created/renewed // this picks up membership type changes during renewals $sql = "\nSELECT membership_type_id\nFROM civicrm_membership_log\nWHERE membership_id={$membership->id}\nORDER BY id DESC\nLIMIT 1;"; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { if (!empty($dao->membership_type_id)) { $membership->membership_type_id = $dao->membership_type_id; $membership->save(); } // else fall back to using current membership type } // else fall back to using current membership type $dao->free(); $num_terms = $contribution->getNumTermsByContributionAndMembershipType($membership->membership_type_id, $primaryContributionID); if ($currentMembership) { /* * Fixed FOR CRM-4433 * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status * when Contribution mode is notify and membership is for renewal ) */ CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday); // @todo - we should pass membership_type_id instead of null here but not // adding as not sure of testing $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday, NULL, $num_terms); $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format); } else { $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id, NULL, NULL, NULL, $num_terms); } //get the status for membership. $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE, $membership->membership_type_id, (array) $membership); $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format)); //we might be renewing membership, //so make status override false. $formatedParams['is_override'] = FALSE; $membership->copyValues($formatedParams); $membership->save(); //updating the membership log $membershipLog = array(); $membershipLog = $formatedParams; $logStartDate = $formatedParams['start_date']; if (CRM_Utils_Array::value('log_start_date', $dates)) { $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format); $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate); } $membershipLog['start_date'] = $logStartDate; $membershipLog['membership_id'] = $membership->id; $membershipLog['modified_id'] = $membership->contact_id; $membershipLog['modified_date'] = date('Ymd'); $membershipLog['membership_type_id'] = $membership->membership_type_id; CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray); //update related Memberships. CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams); //update the membership type key of membership relatedObjects array //if it has changed after membership update if ($membershipTypeIdKey != $membership->membership_type_id) { $membershipsUpdate[$membership->membership_type_id] = $membership; $contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership; unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]); unset($memberships[$membershipTypeIdKey]); } } } //update the memberships object with updated membershipTypeId data //if membershipTypeId has changed after membership update if (!empty($membershipsUpdate)) { $memberships = $memberships + $membershipsUpdate; } } } else { // event $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event'); $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent'); list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $values['custom_pre_id'] = $custom_pre_id; $values['custom_post_id'] = $custom_post_ids; //for tasks 'Change Participant Status' and 'Batch Update Participants Via Profile' case //and cases involving status updation through ipn $values['totalAmount'] = $input['amount']; $contribution->source = ts('Online Event Registration') . ': ' . $values['event']['title']; if ($values['event']['is_email_confirm']) { $contribution->receipt_date = self::$_now; $values['is_email_receipt'] = 1; } if (!CRM_Utils_Array::value('skipComponentSync', $input)) { $participant->status_id = 1; } $participant->save(); } if (CRM_Utils_Array::value('net_amount', $input, 0) == 0 && CRM_Utils_Array::value('fee_amount', $input, 0) != 0) { $input['net_amount'] = $input['amount'] - $input['fee_amount']; } // This complete transaction function is being overloaded to create new contributions too. // here we record if it is a new contribution. // @todo separate the 2 more appropriately. $isNewContribution = FALSE; if (empty($contribution->id)) { $isNewContribution = TRUE; if (!empty($input['amount']) && $input['amount'] != $contribution->total_amount) { $contribution->total_amount = $input['amount']; // The BAO does this stuff but we are actually kinda bypassing it here (bad code! go sit in the corner) // so we have to handle net_amount in this (naughty) code. if (isset($input['fee_amount']) && is_numeric($input['fee_amount'])) { $contribution->fee_amount = $input['fee_amount']; } $contribution->net_amount = $contribution->total_amount - $contribution->fee_amount; } if (!empty($input['campaign_id'])) { $contribution->campaign_id = $input['campaign_id']; } } $contributionStatuses = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', array('labelColumn' => 'name', 'flip' => 1)); // @todo this section should call the api in order to have hooks called & // because all this 'messiness' setting variables could be avoided // by letting the api resolve pseudoconstants & copy set values and format dates. $contribution->contribution_status_id = $contributionStatuses['Completed']; $contribution->is_test = $input['is_test']; // CRM-15960 If we don't have a value we 'want' for the amounts, leave it to the BAO to sort out. if (isset($input['net_amount'])) { $contribution->fee_amount = CRM_Utils_Array::value('fee_amount', $input, 0); } if (isset($input['net_amount'])) { $contribution->net_amount = $input['net_amount']; } $contribution->trxn_id = $input['trxn_id']; $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date); $contribution->receipt_date = CRM_Utils_Date::isoToMysql($contribution->receipt_date); $contribution->cancel_date = 'null'; if (CRM_Utils_Array::value('check_number', $input)) { $contribution->check_number = $input['check_number']; } if (CRM_Utils_Array::value('payment_instrument_id', $input)) { $contribution->payment_instrument_id = $input['payment_instrument_id']; } if (!empty($contribution->id)) { $contributionId['id'] = $contribution->id; $input['prevContribution'] = CRM_Contribute_BAO_Contribution::getValues($contributionId, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray); } $contribution->save(); //add line items for recurring payments if (!empty($contribution->contribution_recur_id)) { if ($isNewContribution) { $input['line_item'] = $this->addRecurLineItems($contribution->contribution_recur_id, $contribution); } else { // this is just to prevent e-notices when we call recordFinancialAccounts - per comments on that line - intention is somewhat unclear $input['line_item'] = array(); } if (!empty($memberships) && $primaryContributionID != $contribution->id) { foreach ($memberships as $membership) { try { $membershipPayment = array('membership_id' => $membership->id, 'contribution_id' => $contribution->id); if (!civicrm_api3('membership_payment', 'getcount', $membershipPayment)) { civicrm_api3('membership_payment', 'create', $membershipPayment); } } catch (CiviCRM_API3_Exception $e) { echo $e->getMessage(); // we are catching & ignoring errors as an extra precaution since lost IPNs may be more serious that lost membership_payment data // this fn is unit-tested so risk of changes elsewhere breaking it are otherwise mitigated } } } } //copy initial contribution custom fields for recurring contributions if ($recurContrib && $recurContrib->id) { $this->copyCustomValues($recurContrib->id, $contribution->id); } // next create the transaction record $paymentProcessor = $paymentProcessorId = ''; if (isset($objects['paymentProcessor'])) { if (is_array($objects['paymentProcessor'])) { $paymentProcessor = $objects['paymentProcessor']['payment_processor_type']; $paymentProcessorId = $objects['paymentProcessor']['id']; } else { $paymentProcessor = $objects['paymentProcessor']->payment_processor_type; $paymentProcessorId = $objects['paymentProcessor']->id; } } //it's hard to see how it could reach this point without a contributon id as it is saved in line 511 above // which raised the question as to whether this check preceded line 511 & if so whether something could be broken // From a lot of code reading /debugging I'm still not sure the intent WRT first & subsequent payments in this code // it would be good if someone added some comments or refactored this if ($contribution->id) { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); if (empty($input['prevContribution']) && $paymentProcessorId || !$input['prevContribution']->is_pay_later && $input['prevContribution']->contribution_status_id == array_search('Pending', $contributionStatuses)) { $input['payment_processor'] = $paymentProcessorId; } $input['contribution_status_id'] = array_search('Completed', $contributionStatuses); $input['total_amount'] = $input['amount']; $input['contribution'] = $contribution; $input['financial_type_id'] = $contribution->financial_type_id; if (CRM_Utils_Array::value('participant', $contribution->_relatedObjects)) { $input['contribution_mode'] = 'participant'; $input['participant_id'] = $contribution->_relatedObjects['participant']->id; $input['skipLineItem'] = 1; } //@todo writing a unit test I was unable to create a scenario where this line did not fatal on second // and subsequent payments. In this case the line items are created at $this->addRecurLineItems // and since the contribution is saved prior to this line there is always a contribution-id, // however there is never a prevContribution (which appears to mean original contribution not previous // contribution - or preUpdateContributionObject most accurately) // so, this is always called & only appears to succeed when prevContribution exists - which appears // to mean "are we updating an exisitng pending contribution" //I was able to make the unit test complete as fataling here doesn't prevent // the contribution being created - but activities would not be created or emails sent CRM_Contribute_BAO_Contribution::recordFinancialAccounts($input, NULL); } self::updateRecurLinkedPledge($contribution); // create an activity record if ($input['component'] == 'contribute') { //CRM-4027 $targetContactID = NULL; if (CRM_Utils_Array::value('related_contact', $ids)) { $targetContactID = $contribution->contact_id; $contribution->contact_id = $ids['related_contact']; } CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID); // event } else { CRM_Activity_BAO_Activity::addActivity($participant); } CRM_Core_Error::debug_log_message("Contribution record updated successfully"); $transaction->commit(); // CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending // when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) { self::sendMail($input, $ids, $objects, $values, $recur, FALSE); CRM_Core_Error::debug_log_message("Receipt sent"); } CRM_Core_Error::debug_log_message("Success: Database updated"); }
/** * Gather values for contribution mail - this function has been created * as part of CRM-9996 refactoring as a step towards simplifying the composeMessage function * Values related to the contribution in question are gathered * * @param array $input * Input into function (probably from payment processor). * @param array $values * @param array $ids * The set of ids related to the input. * * @return array */ public function _gatherMessageValues($input, &$values, $ids = array()) { // set display address of contributor if ($this->address_id) { $addressParams = array('id' => $this->address_id); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); $addressDetails = array_values($addressDetails); $values['address'] = $addressDetails[0]['display']; } if ($this->_component == 'contribute') { if (isset($this->contribution_page_id)) { CRM_Contribute_BAO_ContributionPage::setValues($this->contribution_page_id, $values); if ($this->contribution_page_id) { // CRM-8254 - override default currency if applicable $config = CRM_Core_Config::singleton(); $config->defaultCurrency = CRM_Utils_Array::value('currency', $values, $config->defaultCurrency); } } else { // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id) $values['is_email_receipt'] = 1; $values['title'] = 'Contribution'; } // set lineItem for contribution if ($this->id) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->id, 'contribution', 1); if (!empty($lineItem)) { $itemId = key($lineItem); foreach ($lineItem as &$eachItem) { if (is_array($this->_relatedObjects['membership']) && array_key_exists($eachItem['membership_type_id'], $this->_relatedObjects['membership'])) { $eachItem['join_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->join_date); $eachItem['start_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->start_date); $eachItem['end_date'] = CRM_Utils_Date::customFormat($this->_relatedObjects['membership'][$eachItem['membership_type_id']]->end_date); } } $values['lineItem'][0] = $lineItem; $values['priceSetID'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItem[$itemId]['price_field_id'], 'price_set_id'); } } $relatedContact = CRM_Contribute_BAO_Contribution::getOnbehalfIds($this->id, $this->contact_id); // if this is onbehalf of contribution then set related contact if (!empty($relatedContact['individual_id'])) { $values['related_contact'] = $ids['related_contact'] = $relatedContact['individual_id']; } } else { // event $eventParams = array('id' => $this->_relatedObjects['event']->id); $values['event'] = array(); CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); // add custom fields for event $eventGroupTree = CRM_Core_BAO_CustomGroup::getTree('Event', $this->_relatedObjects['event'], $this->_relatedObjects['event']->id); $eventCustomGroup = array(); foreach ($eventGroupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $eventCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['event']['customGroup'] = $eventCustomGroup; //get participant details $participantParams = array('id' => $this->_relatedObjects['participant']->id); $values['participant'] = array(); CRM_Event_BAO_Participant::getValues($participantParams, $values['participant'], $participantIds); // add custom fields for event $participantGroupTree = CRM_Core_BAO_CustomGroup::getTree('Participant', $this->_relatedObjects['participant'], $this->_relatedObjects['participant']->id); $participantCustomGroup = array(); foreach ($participantGroupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $participantCustomGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['participant']['customGroup'] = $participantCustomGroup; //get location details $locationParams = array('entity_id' => $this->_relatedObjects['event']->id, 'entity_table' => 'civicrm_event'); $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent'); list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $values['custom_pre_id'] = $custom_pre_id; $values['custom_post_id'] = $custom_post_ids; // set lineItem for event contribution if ($this->id) { $participantIds = CRM_Event_BAO_Participant::getParticipantIds($this->id); if (!empty($participantIds)) { foreach ($participantIds as $pIDs) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($pIDs); if (!CRM_Utils_System::isNull($lineItem)) { $values['lineItem'][] = $lineItem; } } } } } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $this->id); $customGroup = array(); foreach ($groupTree as $key => $group) { if ($key === 'info') { continue; } foreach ($group['fields'] as $k => $customField) { $groupLabel = $group['title']; if (!empty($customField['customValue'])) { foreach ($customField['customValue'] as $customFieldValues) { $customGroup[$groupLabel][$customField['label']] = CRM_Utils_Array::value('data', $customFieldValues); } } } } $values['customGroup'] = $customGroup; return $values; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $this->assignToTemplate(); $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); // make sure we have values for it if ($honor_block_is_active && !empty($params['soft_credit_type_id'])) { $honorName = null; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $this->assign('honor_block_is_active', $honor_block_is_active); $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); $fieldTypes = array('Contact'); $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); $amount_block_is_active = $this->get('amount_block_is_active'); $this->assign('amount_block_is_active', $amount_block_is_active); if (!empty($params['selectProduct']) && $params['selectProduct'] != 'no_thanks') { $option = CRM_Utils_Array::value('options_' . $params['selectProduct'], $params); $productID = $params['selectProduct']; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); $this->set('productID', $productID); $this->set('option', $option); } $config = CRM_Core_Config::singleton(); if (in_array('CiviMember', $config->enableComponents)) { if (isset($params['selectMembership']) && $params['selectMembership'] != 'no_thanks') { CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, $this->_membershipContactID, FALSE, $params['selectMembership'], FALSE); } else { $this->assign('membershipBlock', FALSE); } } $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (!empty($params['hidden_onbehalf_profile'])) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign('is_separate_payment', $this->_separateMembershipPayment); if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $paymentProcessorType = CRM_Core_PseudoConstant::paymentProcessorType(false, null, 'name'); if ($this->_paymentProcessor && $this->_paymentProcessor['payment_processor_type_id'] == CRM_Utils_Array::key('Google_Checkout', $paymentProcessorType) && !$this->_params['is_pay_later'] && !($this->_amount == 0)) { $this->_checkoutButtonName = $this->getButtonName('next', 'checkout'); $this->add('image', $this->_checkoutButtonName, $this->_paymentProcessor['url_button'], array('class' => 'form-submit')); $this->addButtons(array(array('type' => 'back', 'name' => ts('<< Go Back')))); } else { if ($this->_contributeMode == 'notify' || !$this->_values['is_monetary'] || $this->_amount <= 0.0 || $this->_params['is_pay_later'] || $this->_separateMembershipPayment && $this->_amount <= 0.0) { $contribButton = ts('Continue >>'); $this->assign('button', ts('Continue')); } else { $contribButton = ts('Make Contribution'); $this->assign('button', ts('Make Contribution')); } $this->addButtons(array(array('type' => 'next', 'name' => $contribButton, 'spacing' => ' ', 'isDefault' => TRUE, 'js' => array('onclick' => "return submitOnce(this,'" . $this->_name . "','" . ts('Processing') . "');")), array('type' => 'back', 'name' => ts('Go Back')))); } $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } $fields["billing_state_province-{$this->_bltID}"] = $fields["billing_country-{$this->_bltID}"] = $fields["email-{$this->_bltID}"] = 1; $contact = $this->_params; foreach ($fields as $name => $dontCare) { if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } if (isset($contact["{$name}_id"])) { $defaults["{$name}_id"] = $contact["{$name}_id"]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } $this->assign('useForMember', $this->get('useForMember')); // now fix all state country selectors CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $this->setDefaults($defaults); $this->freeze(); }
public function preProcess() { $this->bao = new CRM_Campaign_BAO_Petition(); $this->_mode = self::MODE_CREATE; //get the survey id $this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this); //some sanity checks if (!$this->_surveyId) { CRM_Core_Error::fatal('Petition id is not valid. (it needs a "sid" in the url).'); return; } //check petition is valid and active $params['id'] = $this->_surveyId; $this->petition = array(); CRM_Campaign_BAO_Survey::retrieve($params, $this->petition); if (empty($this->petition)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } if ($this->petition['is_active'] == 0) { CRM_Core_Error::fatal('Petition is no longer active.'); } //get userID from session $session = CRM_Core_Session::singleton(); //get the contact id for this user if logged in $this->_contactId = $this->getContactId(); if (isset($this->_contactId)) { $this->_loggedIn = TRUE; } // add the custom contact and activity profile fields to the signature form $ufJoinParams = array('entity_id' => $this->_surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign', 'weight' => 2); $this->_contactProfileId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); if ($this->_contactProfileId) { $this->_contactProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_contactProfileId, FALSE, CRM_Core_Action::ADD); } if (!isset($this->_contactProfileFields['email-Primary'])) { CRM_Core_Error::fatal('The contact profile needs to contain the primary email address field'); } $ufJoinParams['weight'] = 1; $this->_activityProfileId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); if ($this->_activityProfileId) { $this->_activityProfileFields = CRM_Core_BAO_UFGroup::getFields($this->_activityProfileId, FALSE, CRM_Core_Action::ADD); } $this->setDefaultValues(); CRM_Utils_System::setTitle($this->petition['title']); }
/** * Retrieve survey associated profile id. */ public static function getSurveyProfileId($surveyId) { if (!$surveyId) { return NULL; } static $ufIds = array(); if (!array_key_exists($surveyId, $ufIds)) { //get the profile id. $ufJoinParams = array('entity_id' => $surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign'); list($first, $second) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); if ($first) { $ufIds[$surveyId] = array($first); } if ($second) { $ufIds[$surveyId][] = array_shift($second); } } return CRM_Utils_Array::value($surveyId, $ufIds); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Core/BAO/OptionGroup.php'; $updateResultSet = false; if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) { if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) { $updateResultSet = true; } } if ($this->_surveyId) { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Campaign_BAO_Survey::del($this->_surveyId); CRM_Core_Session::setStatus(ts(' Survey has been deleted.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); return; } $params['id'] = $this->_surveyId; } else { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $this->_values['result_id']; $optionValue->delete(); $params['result_id'] = $this->_values['result_id']; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->label = $params['title'] . ' Response Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); if (CRM_Utils_Array::value($k, $params['option_interval'])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $surveyId = CRM_Campaign_BAO_Survey::create($params); if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) { $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1"; $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer'))); // delete option group if no any survey is using it. if (!($countSurvey >= 1)) { CRM_Core_BAO_OptionGroup::del($this->_values['result_id']); } } require_once 'CRM/Core/BAO/UFJoin.php'; // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id); // first delete all past entries if ($this->_surveyId) { CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); } if (CRM_Utils_Array::value('profile_id', $params)) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['profile_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } if (!is_a($surveyId, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title']))); } if ($this->_context == 'dialog') { $returnArray = array('returnSuccess' => true); echo json_encode($returnArray); CRM_Utils_System::civiExit(); } $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another Survey.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); } }
/** * Build the form object. * * @return void */ public function buildQuickForm() { $this->assignToTemplate(); $productID = $this->get('productID'); $option = $this->get('option'); $membershipTypeID = $this->get('membershipTypeID'); $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); if ($productID) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); } if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { if (is_array($membershipTypeID)) { $membershipTypeID = current($membershipTypeID); } $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $this->assign('useForMember', $this->get('useForMember')); $params = $this->_params; $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); if ($invoicing) { $getTaxDetails = FALSE; $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); foreach ($this->_lineItem as $key => $value) { foreach ($value as $v) { if (isset($v['tax_rate'])) { if ($v['tax_rate'] != '') { $getTaxDetails = TRUE; } } } } $this->assign('getTaxDetails', $getTaxDetails); $this->assign('taxTerm', $taxTerm); $this->assign('totalTaxAmount', $params['tax_amount']); } if ($this->_honor_block_is_active && !empty($params['soft_credit_type_id'])) { $honorName = NULL; $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE); $this->assign('honor_block_is_active', $this->_honor_block_is_active); $this->assign('soft_credit_type', $softCreditTypes[$params['soft_credit_type_id']]); CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($this, $params['honor'], $params['honoree_profile_id']); $fieldTypes = array('Contact'); $fieldTypes[] = CRM_Core_BAO_UFGroup::getContactType($params['honoree_profile_id']); $this->buildCustom($params['honoree_profile_id'], 'honoreeProfileFields', TRUE, 'honor', $fieldTypes); } $qParams = "reset=1&id={$this->_id}"; //pcp elements if ($this->_pcpId) { $qParams .= "&pcpId={$this->_pcpId}"; $this->assign('pcpBlock', TRUE); foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { if (!empty($this->_params[$val])) { $this->assign($val, $this->_params[$val]); } } } $this->assign('qParams', $qParams); if ($membershipTypeID) { $transactionID = $this->get('membership_trx_id'); $membershipAmount = $this->get('membership_amount'); $renewalMode = $this->get('renewal_mode'); $this->assign('membership_trx_id', $transactionID); $this->assign('membership_amount', $membershipAmount); $this->assign('renewal_mode', $renewalMode); $this->buildMembershipBlock($this->_membershipContactID, FALSE, $membershipTypeID, TRUE, NULL); if (!empty($params['auto_renew'])) { $this->assign('auto_renew', TRUE); } } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign("is_separate_payment", $this->_separateMembershipPayment); $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (!empty($params['hidden_onbehalf_profile'])) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, 'onbehalf', $fieldTypes); } $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params)); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))); $defaults = array(); $fields = array(); foreach ($this->_fields as $name => $dontCare) { if ($name != 'onbehalf' || $name != 'honor') { $fields[$name] = 1; } } $fields['state_province'] = $fields['country'] = $fields['email'] = 1; $contact = $this->_params = $this->controller->exportValues('Main'); foreach ($fields as $name => $dontCare) { if (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && !empty($contact[$name . '_custom'])) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); $values['entity_id'] = $this->_id; $values['entity_table'] = 'civicrm_contribution_page'; CRM_Friend_BAO_Friend::retrieve($values, $data); $tellAFriend = FALSE; if ($this->_pcpId) { if ($this->_pcpBlock['is_tellfriend_enabled']) { $this->assign('friendText', ts('Tell a Friend')); $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; $tellAFriend = TRUE; } } elseif (!empty($data['is_active'])) { $friendText = $data['title']; $this->assign('friendText', $friendText); $subUrl = "eid={$this->_id}&pcomponent=contribute"; $tellAFriend = TRUE; } if ($tellAFriend) { if ($this->_action & CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}"); } else { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}"); } $this->assign('friendURL', $url); } $this->freeze(); // can we blow away the session now to prevent hackery // CRM-9491 $this->controller->reset(); }
/** * Migrate honoree information to uf_join.module_data as honoree columns (text and title) will be dropped * on DB upgrade * * @param CRM_Queue_TaskContext $ctx * * @return bool * TRUE for success */ public static function migrateHonoreeInfo(CRM_Queue_TaskContext $ctx) { $query = "ALTER TABLE `civicrm_uf_join`\n ADD COLUMN `module_data` longtext COMMENT 'Json serialized array of data used by the ufjoin.module'"; CRM_Core_DAO::executeQuery($query); $honorTypes = array_keys(CRM_Core_OptionGroup::values('honor_type')); $ufGroupDAO = new CRM_Core_DAO_UFGroup(); $ufGroupDAO->name = 'new_individual'; $ufGroupDAO->find(TRUE); $query = "SELECT * FROM civicrm_contribution_page"; $dao = CRM_Core_DAO::executeQuery($query); if ($dao->N) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); while ($dao->fetch()) { $honorParams = array('soft_credit' => array('soft_credit_types' => $honorTypes)); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); foreach ($locales as $locale) { $honor_block_title = "honor_block_title_{$locale}"; $honor_block_text = "honor_block_text_{$locale}"; $honorParams['soft_credit'] += array($locale => array('honor_block_title' => $dao->{$honor_block_title}, 'honor_block_text' => $dao->{$honor_block_text})); } } else { $honorParams['soft_credit'] += array('default' => array('honor_block_title' => $dao->honor_block_title, 'honor_block_text' => $dao->honor_block_text)); } $ufJoinParam = array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'is_active' => $dao->honor_block_is_active, 'entity_id' => $dao->id, 'uf_group_id' => $ufGroupDAO->id, 'module_data' => json_encode($honorParams)); CRM_Core_BAO_UFJoin::create($ufJoinParam); } } return TRUE; }
/** * Takes an associative array and creates a uf join in the database. * * @param array $params * Array per getfields metadata. * * @return array * CRM_Core_DAO_UFJoin Array */ function civicrm_api3_uf_join_create($params) { $ufJoin = CRM_Core_BAO_UFJoin::create($params); _civicrm_api3_object_to_array($ufJoin, $ufJoinArray[]); return civicrm_api3_create_success($ufJoinArray, $params, 'UFJoin', 'create'); }
/** * Process the form. */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); // we do this in case the user has hit the forward/back button if ($this->_id) { $params['id'] = $this->_id; } else { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); $config = CRM_Core_Config::singleton(); $params['currency'] = $config->defaultCurrency; } $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE); $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only', $params, FALSE); $params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, FALSE); $params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0; $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time'], TRUE); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE); $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']); if (!$params['honor_block_is_active']) { $params['honor_block_title'] = NULL; $params['honor_block_text'] = NULL; } $dao = CRM_Contribute_BAO_ContributionPage::create($params); $ufJoinParams = array('is_organization' => array('module' => 'on_behalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id), 'honor_block_is_active' => array('module' => 'soft_credit', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $dao->id)); foreach ($ufJoinParams as $index => $ufJoinParam) { if (!empty($params[$index])) { // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParam); $ufJoinParam['uf_group_id'] = $params[$index]; $ufJoinParam['weight'] = 1; $ufJoinParam['is_active'] = 1; if ($index == 'honor_block_is_active') { $ufJoinParam['uf_group_id'] = $params['honoree_profile']; $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'soft_credit'); } else { $ufJoinParam['uf_group_id'] = $params['onbehalf_profile_id']; $ufJoinParam['module_data'] = CRM_Contribute_BAO_ContributionPage::formatModuleData($params, FALSE, 'on_behalf'); } CRM_Core_BAO_UFJoin::create($ufJoinParam); } else { if ($index == 'honor_block_is_active') { $params['honor_block_title'] = NULL; $params['honor_block_text'] = NULL; } else { $params['for_organization'] = NULL; } //On subsequent honor_block_is_active uncheck, disable(don't delete) //that particular honoree profile entry in UFjoin table, CRM-13981 $ufId = CRM_Core_BAO_UFJoin::findJoinEntryId($ufJoinParam); if ($ufId) { $ufJoinParam['uf_group_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParam); $ufJoinParam['is_active'] = 0; CRM_Core_BAO_UFJoin::create($ufJoinParam); } } } $this->set('id', $dao->id); if ($this->_action & CRM_Core_Action::ADD) { $url = 'civicrm/admin/contribute/amount'; $urlParams = "action=update&reset=1&id={$dao->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == '_qf_Amount_upload_done') { $url = 'civicrm/admin/contribute'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())), ts('Saved'), 'success'); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } parent::endPostProcess(); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = array(); $params = $this->exportValues(); $params['id'] = $this->_id; //format params $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, false); $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, false); $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, false); $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, false); // reset is_email confirm if not online reg if (!$params['is_online_registration']) { $params['is_email_confirm'] = false; } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], $params['registration_start_date_time'], true); $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], $params['registration_end_date_time'], true); } require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::add($params); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviEvent', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); require_once 'CRM/Core/BAO/UFJoin.php'; // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); if (!empty($params['custom_pre_id'])) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['custom_pre_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } unset($ufJoinParams['id']); if (!empty($params['custom_post_id'])) { $ufJoinParams['weight'] = 2; $ufJoinParams['uf_group_id'] = $params['custom_post_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } // CRM-4377: also update the profiles for additional participants $ufJoinParams['module'] = 'CiviEvent_Additional'; $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['custom_pre_id']; if ($params['additional_custom_pre_id'] == 'none') { $ufJoinParams['is_active'] = 0; } elseif ($params['additional_custom_pre_id']) { $ufJoinParams['uf_group_id'] = $params['additional_custom_pre_id']; } CRM_Core_BAO_UFJoin::create($ufJoinParams); $ufJoinParams['weight'] = 2; $ufJoinParams['uf_group_id'] = $params['custom_post_id']; if ($params['additional_custom_post_id'] == 'none') { $ufJoinParams['is_active'] = 0; } elseif ($params['additional_custom_post_id']) { //minor fix for CRM-4377 $ufJoinParams['is_active'] = 1; $ufJoinParams['uf_group_id'] = $params['additional_custom_post_id']; } CRM_Core_BAO_UFJoin::create($ufJoinParams); parent::endPostProcess(); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $this->_surveyId); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); $uf = array(); $wt = 2; if (!empty($params['contact_profile_id'])) { $uf[1] = $params['contact_profile_id']; $wt = 1; } if (!empty($params['activity_profile_id'])) { $uf[2] = $params['activity_profile_id']; } $uf = array_values($uf); if (!empty($uf)) { foreach ($uf as $weight => $ufGroupId) { $ufJoinParams['weight'] = $weight + $wt; $ufJoinParams['uf_group_id'] = $ufGroupId; CRM_Core_BAO_UFJoin::create($ufJoinParams); unset($ufJoinParams['id']); } } parent::endPostProcess(); }
/** * Given an assoc list of params, find if there is a record * for this set of params and return the group id * * @param array $params (reference) an assoc array of name/value pairs * * @return int or null * @access public * */ function crm_find_uf_join_UFGroupId(&$params) { if (!is_array($params) || empty($params)) { return _crm_error("{$params} is not valid array"); } if (!isset($params['entity_table']) && !isset($params['entity_id']) && !isset($params['weight'])) { return _crm_error("{$param} should have atleast entity_table or entiy_id or weight"); } return CRM_Core_BAO_UFJoin::findUFGroupId($params); }
/** * Process the form submission. * * * @return void */ public function postProcess() { $params = $this->exportValues(); $params['id'] = $this->_id; // format params $params['is_online_registration'] = CRM_Utils_Array::value('is_online_registration', $params, FALSE); $params['is_confirm_enabled'] = CRM_Utils_Array::value('is_confirm_enabled', $params, FALSE); // CRM-11182 $params['is_multiple_registrations'] = CRM_Utils_Array::value('is_multiple_registrations', $params, FALSE); $params['allow_same_participant_emails'] = CRM_Utils_Array::value('allow_same_participant_emails', $params, FALSE); $params['requires_approval'] = CRM_Utils_Array::value('requires_approval', $params, FALSE); // reset is_email confirm if not online reg if (!$params['is_online_registration']) { $params['is_email_confirm'] = FALSE; } if (!$this->_isTemplate) { $params['registration_start_date'] = CRM_Utils_Date::processDate($params['registration_start_date'], $params['registration_start_date_time'], TRUE); $params['registration_end_date'] = CRM_Utils_Date::processDate($params['registration_end_date'], $params['registration_end_date_time'], TRUE); } CRM_Event_BAO_Event::add($params); // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviEvent', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); $uf = array(); $wt = 2; if (!empty($params['custom_pre_id'])) { $uf[1] = $params['custom_pre_id']; $wt = 1; } if (!empty($params['custom_post_id'])) { $uf[2] = $params['custom_post_id']; } if (!empty($params['custom_post_id_multiple'])) { $uf = array_merge($uf, $params['custom_post_id_multiple']); } $uf = array_values($uf); if (!empty($uf)) { foreach ($uf as $weight => $ufGroupId) { $ufJoinParams['weight'] = $weight + $wt; $ufJoinParams['uf_group_id'] = $ufGroupId; CRM_Core_BAO_UFJoin::create($ufJoinParams); unset($ufJoinParams['id']); } } // also update the ProfileModule tables $ufJoinParamsAdd = array('is_active' => 1, 'module' => 'CiviEvent_Additional', 'entity_table' => 'civicrm_event', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParamsAdd); if (!empty($params['is_multiple_registrations'])) { $ufAdd = array(); $wtAdd = 2; if (array_key_exists('additional_custom_pre_id', $params)) { if (empty($params['additional_custom_pre_id'])) { $ufAdd[1] = $params['custom_pre_id']; $wtAdd = 1; } elseif (CRM_Utils_Array::value('additional_custom_pre_id', $params) == 'none') { } else { $ufAdd[1] = $params['additional_custom_pre_id']; $wtAdd = 1; } } if (array_key_exists('additional_custom_post_id', $params)) { if (empty($params['additional_custom_post_id'])) { $ufAdd[2] = $params['custom_post_id']; } elseif (CRM_Utils_Array::value('additional_custom_post_id', $params) == 'none') { } else { $ufAdd[2] = $params['additional_custom_post_id']; } } if (!empty($params['additional_custom_post_id_multiple'])) { $additionalPostMultiple = array(); foreach ($params['additional_custom_post_id_multiple'] as $key => $value) { if (is_null($value) && !empty($params['custom_post_id'])) { $additionalPostMultiple[$key] = $params['custom_post_id']; } elseif ($value == 'none') { continue; } elseif ($value) { $additionalPostMultiple[$key] = $value; } } $ufAdd = array_merge($ufAdd, $additionalPostMultiple); } $ufAdd = array_values($ufAdd); if (!empty($ufAdd)) { foreach ($ufAdd as $weightAdd => $ufGroupIdAdd) { $ufJoinParamsAdd['weight'] = $weightAdd + $wtAdd; $ufJoinParamsAdd['uf_group_id'] = $ufGroupIdAdd; CRM_Core_BAO_UFJoin::create($ufJoinParamsAdd); unset($ufJoinParamsAdd['id']); } } } // get the profiles to evaluate what they collect $profileIds = array(CRM_Utils_Array::value('custom_pre_id', $params), CRM_Utils_Array::value('custom_post_id', $params)); $additionalProfileIds = array(CRM_Utils_Array::value('additional_custom_pre_id', $params), CRM_Utils_Array::value('additional_custom_post_id', $params)); // additional profile fields default to main if not set if (!is_numeric($additionalProfileIds[0])) { $additionalProfileIds[0] = $profileIds[0]; } if (!is_numeric($additionalProfileIds[1])) { $additionalProfileIds[1] = $profileIds[1]; } //add multiple profiles if set self::addMultipleProfiles($profileIds, $params, 'custom_post_id_multiple'); self::addMultipleProfiles($additionalProfileIds, $params, 'additional_custom_post_id_multiple'); $cantDedupe = FALSE; $rgId = CRM_Utils_Array::value('dedupe_rule_group_id', $params, 0); switch (self::canProfilesDedupe($profileIds, $rgId)) { case 0: $dedupeTitle = 'Duplicate Matching Impossible'; $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact."); break; case 1: $dedupeTitle = 'Duplicate Contacts Possible'; $cantDedupe = ts("The selected profiles can collect enough information to match registrations with existing contacts, but not all of the relevant fields are required. Anonymous registrations may result in duplicate contacts."); } if (!empty($params['is_multiple_registrations'])) { switch (self::canProfilesDedupe($additionalProfileIds, $rgId)) { case 0: $dedupeTitle = 'Duplicate Matching Impossible'; if ($cantDedupe) { $cantDedupe = ts("The selected profiles do not contain the fields necessary to match registrations with existing contacts. This means all anonymous registrations will result in a new contact."); } else { $cantDedupe = ts("The selected profiles do not contain the fields necessary to match additional participants with existing contacts. This means all additional participants will result in a new contact."); } break; case 1: if (!$cantDedupe) { $dedupeTitle = 'Duplicate Contacts Possible'; $cantDedupe = ts("The selected profiles can collect enough information to match additional participants with existing contacts, but not all of the relevant fields are required. This may result in duplicate contacts."); } } } if ($cantDedupe) { CRM_Core_Session::setStatus($cantDedupe, $dedupeTitle, 'alert dedupenotify', array('expires' => 0)); } // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = !empty($params['is_online_registration']); parent::endPostProcess(); }
function sendMail(&$input, &$ids, &$objects, &$values, $recur = false, $returnMessageText = false) { $contribution =& $objects['contribution']; $membership =& $objects['membership']; $participant =& $objects['participant']; $event =& $objects['event']; if (empty($values)) { $values = array(); if ($input['component'] == 'contribute') { require_once 'CRM/Contribute/BAO/ContributionPage.php'; if (isset($contribution->contribution_page_id)) { CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values); } else { // Handle re-print receipt for offline contributions (call from PDF.php - no contribution_page_id) $values['is_email_receipt'] = 1; $values['title'] = 'Contribution'; } } else { // event $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); require_once 'CRM/Event/BAO/Event.php'; CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event'); require_once 'CRM/Core/BAO/Location.php'; require_once 'CRM/Event/Form/ManageEvent/Location.php'; $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'weight' => 1); $values['custom_pre_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $ufJoinParams['weight'] = 2; $values['custom_post_id'] = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); } } $template =& CRM_Core_Smarty::singleton(); // CRM_Core_Error::debug('tpl',$template); //assign honor infomation to receiptmessage if ($honarID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contribution->id, 'honor_contact_id')) { $honorDefault = array(); $honorIds = array(); $honorIds['contribution'] = $contribution->id; $idParams = array('id' => $honarID, 'contact_id' => $honarID); require_once "CRM/Contact/BAO/Contact.php"; CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds); require_once "CRM/Core/PseudoConstant.php"; $honorType = CRM_Core_PseudoConstant::honor(); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $template->assign('honor_block_is_active', 1); $template->assign('honor_prefix', $prefix[$honorDefault["prefix_id"]]); $template->assign('honor_first_name', CRM_Utils_Array::value("first_name", $honorDefault)); $template->assign('honor_last_name', CRM_Utils_Array::value("last_name", $honorDefault)); $template->assign('honor_email', CRM_Utils_Array::value("email", $honorDefault["email"][1])); $template->assign('honor_type', $honorType[$contribution->honor_type_id]); } require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $contribution->id; if ($dao->find(true)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $premiumId; $productDAO->find(true); $template->assign('selectPremium', true); $template->assign('product_name', $productDAO->name); $template->assign('price', $productDAO->price); $template->assign('sku', $productDAO->sku); } // add the new contribution values if ($input['component'] == 'contribute') { $template->assign('title', $values['title']); $template->assign('amount', $input['amount']); //PCP Info require_once 'CRM/Contribute/DAO/ContributionSoft.php'; $softDAO =& new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $contribution->id; if ($softDAO->find(true)) { $template->assign('pcpBlock', true); $template->assign('pcp_display_in_roll', $softDAO->pcp_display_in_roll); $template->assign('pcp_roll_nickname', $softDAO->pcp_roll_nickname); $template->assign('pcp_personal_note', $softDAO->pcp_personal_note); //assign the pcp page title for email subject require_once 'CRM/Contribute/DAO/PCP.php'; $pcpDAO =& new CRM_Contribute_DAO_PCP(); $pcpDAO->id = $softDAO->pcp_id; if ($pcpDAO->find(true)) { $template->assign('title', $pcpDAO->title); } } } else { $template->assign('title', $values['event']['title']); $template->assign('totalAmount', $input['amount']); } $template->assign('trxn_id', $contribution->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($contribution->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $contribution->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', $recur); if ($recur) { require_once 'CRM/Core/Payment.php'; $paymentObject =& CRM_Core_Payment::singleton($contribution->is_test ? 'test' : 'live', 'Contribute', $objects['paymentProcessor']); $url = $paymentObject->cancelSubscriptionURL(); $template->assign('cancelSubscriptionUrl', $url); if ($objects['paymentProcessor']['billing_mode'] & CRM_Core_Payment::BILLING_MODE_FORM) { //direct mode showing billing block, so use directIPN for temporary $template->assign('contributeMode', 'directIPN'); } } require_once 'CRM/Utils/Address.php'; $template->assign('address', CRM_Utils_Address::format($input)); if ($input['component'] == 'event') { require_once 'CRM/Core/OptionGroup.php'; $participant_role = CRM_Core_OptionGroup::values('participant_role'); $values['event']['participant_role'] = $participant_role[$participant->role_id]; $template->assign('event', $values['event']); $template->assign('location', $values['location']); $template->assign('customPre', $values['custom_pre_id']); $template->assign('customPost', $values['custom_post_id']); $isTest = false; if ($participant->is_test) { $isTest = true; } $values['params'] = array(); require_once "CRM/Event/BAO/Event.php"; //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $participant->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $participant->fee_level . ' - ' . $primaryEmail, 'amount' => $participant->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($participant->id, null, $ids['contact'], $isTest, true); unset($additionalIDs[$participant->id]); //send receipt to additional participant if exists if (count($additionalIDs)) { $template->assign('isPrimary', 0); $template->assign('customProfile', null); //set additionalParticipant true $values['params']['additionalParticipant'] = true; foreach ($additionalIDs as $pId => $cId) { $amount = array(); //to change the status pending to completed $additional =& new CRM_Event_DAO_Participant(); $additional->id = $pId; $additional->contact_id = $cId; $additional->find(true); $additional->register_date = $participant->register_date; $additional->status_id = 1; $additionalParticipantInfo = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $additional->contact_id, 'email', 'contact_id'); //if additional participant dont have email //use display name. if (!$additionalParticipantInfo) { require_once "CRM/Contact/BAO/Contact.php"; $additionalParticipantInfo = CRM_Contact_BAO_Contact::displayName($additional->contact_id); } $amount[0] = array('label' => $additional->fee_level, 'amount' => $additional->fee_amount); $primaryAmount[] = array('label' => $additional->fee_level . ' - ' . $additionalParticipantInfo, 'amount' => $additional->fee_amount); $additional->save(); $additional->free(); $template->assign('amount', $amount); CRM_Event_BAO_Event::sendMail($cId, $values, $pId, $isTest, $returnMessageText); } } //build an array of custom profile and assigning it to template $customProfile = CRM_Event_BAO_Event::buildCustomProfile($participant->id, $values, null, $isTest); if (count($customProfile)) { $template->assign('customProfile', $customProfile); } // for primary contact $values['params']['additionalParticipant'] = false; $template->assign('isPrimary', 1); $template->assign('amount', $primaryAmount); // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $participant->is_pay_later; return CRM_Event_BAO_Event::sendMail($ids['contact'], $values, $participant->id, $isTest, $returnMessageText); } else { if ($membership) { $values['membership_id'] = $membership->id; // need to set the membership values here $template->assign('membership_assign', 1); require_once 'CRM/Member/PseudoConstant.php'; $template->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id)); $template->assign('mem_start_date', $membership->start_date); $template->assign('mem_end_date', $membership->end_date); // if separate payment there are two contributions recorded and the // admin will need to send a receipt for each of them separately. // we dont link the two in the db (but can potentially infer it if needed) $template->assign('is_separate_payment', 0); } $values['contribution_id'] = $contribution->id; if (CRM_Utils_Array::value('related_contact', $ids)) { $values['related_contact'] = $ids['related_contact']; if (isset($ids['onbehalf_dupe_alert'])) { $values['onbehalf_dupe_alert'] = $ids['onbehalf_dupe_alert']; } require_once 'CRM/Core/BAO/Address.php'; $entityBlock = array('contact_id' => $ids['contact'], 'location_type_id' => CRM_Core_DAO::getFieldValue('CRM_Core_DAO_LocationType', 'Main', 'id', 'name')); $address = CRM_Core_BAO_Address::getValues($entityBlock); $template->assign('onBehalfAddress', $address[$entityBlock['location_type_id']]['display']); } $isTest = false; if ($contribution->is_test) { $isTest = true; } // CRM_Core_Error::debug('val',$values); return CRM_Contribute_BAO_ContributionPage::sendMail($ids['contact'], $values, $isTest, $returnMessageText); } }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { $this->assignToTemplate(); $productID = $this->get('productID'); $option = $this->get('option'); $membershipTypeID = $this->get('membershipTypeID'); $this->assign('receiptFromEmail', CRM_Utils_Array::value('receipt_from_email', $this->_values)); if ($productID) { CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, FALSE, $productID, $option); } if ($this->_priceSetId && !CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $this->_priceSetId, 'is_quick_config')) { $this->assign('lineItem', $this->_lineItem); } else { if (is_array($membershipTypeID)) { $membershipTypeID = current($membershipTypeID); } $this->assign('is_quick_config', 1); $this->_params['is_quick_config'] = 1; } $this->assign('priceSetID', $this->_priceSetId); $this->assign('useForMember', $this->get('useForMember')); $params = $this->_params; $honor_block_is_active = $this->get('honor_block_is_active'); if ($honor_block_is_active && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) { $this->assign('honor_block_is_active', $honor_block_is_active); $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); $prefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $this->assign('honor_type', $honor[$params["honor_type_id"]]); $this->assign('honor_prefix', $params["honor_prefix_id"] ? $prefix[$params["honor_prefix_id"]] : ' '); $this->assign('honor_first_name', $params["honor_first_name"]); $this->assign('honor_last_name', $params["honor_last_name"]); $this->assign('honor_email', $params["honor_email"]); } $qParams = "reset=1&id={$this->_id}"; //pcp elements if ($this->_pcpId) { $qParams .= "&pcpId={$this->_pcpId}"; $this->assign('pcpBlock', TRUE); foreach (array('pcp_display_in_roll', 'pcp_is_anonymous', 'pcp_roll_nickname', 'pcp_personal_note') as $val) { if (CRM_Utils_Array::value($val, $this->_params)) { $this->assign($val, $this->_params[$val]); } } } $this->assign('qParams', $qParams); if ($membershipTypeID) { $transactionID = $this->get('membership_trx_id'); $membershipAmount = $this->get('membership_amount'); $renewalMode = $this->get('renewal_mode'); $this->assign('membership_trx_id', $transactionID); $this->assign('membership_amount', $membershipAmount); $this->assign('renewal_mode', $renewalMode); CRM_Member_BAO_Membership::buildMembershipBlock($this, $this->_id, FALSE, $membershipTypeID, TRUE, NULL, $this->_membershipContactID); } $this->_separateMembershipPayment = $this->get('separateMembershipPayment'); $this->assign("is_separate_payment", $this->_separateMembershipPayment); $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); if (CRM_Utils_Array::value('hidden_onbehalf_profile', $params)) { $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $fieldTypes = array('Contact', 'Organization'); $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization'); $fieldTypes = array_merge($fieldTypes, $contactSubType); if (is_array($this->_membershipBlock) && !empty($this->_membershipBlock)) { $fieldTypes = array_merge($fieldTypes, array('Membership')); } else { $fieldTypes = array_merge($fieldTypes, array('Contribution')); } $this->buildCustom($profileId, 'onbehalfProfile', TRUE, TRUE, $fieldTypes); } $this->assign('trxn_id', CRM_Utils_Array::value('trxn_id', $this->_params)); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso(CRM_Utils_Array::value('receive_date', $this->_params))); $defaults = array(); $options = array(); $fields = array(); $removeCustomFieldTypes = array('Contribution'); foreach ($this->_fields as $name => $dontCare) { if ($name == 'onbehalf') { foreach ($dontCare as $key => $value) { $fields['onbehalf'][$key] = 1; } } else { $fields[$name] = 1; } } $fields['state_province'] = $fields['country'] = $fields['email'] = 1; $contact = $this->_params = $this->controller->exportValues('Main'); foreach ($fields as $name => $dontCare) { if ($name == 'onbehalf') { foreach ($dontCare as $key => $value) { //$defaults[$key] = $contact['onbehalf'][$key]; if (isset($contact['onbehalf'][$key])) { $defaults[$key] = $contact['onbehalf'][$key]; } if (isset($contact['onbehalf']["{$key}_id"])) { $defaults["{$key}_id"] = $contact['onbehalf']["{$key}_id"]; } } } elseif (isset($contact[$name])) { $defaults[$name] = $contact[$name]; if (substr($name, 0, 7) == 'custom_') { $timeField = "{$name}_time"; if (isset($contact[$timeField])) { $defaults[$timeField] = $contact[$timeField]; } } elseif (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } // now fix all state country selectors CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); $values['entity_id'] = $this->_id; $values['entity_table'] = 'civicrm_contribution_page'; CRM_Friend_BAO_Friend::retrieve($values, $data); $tellAFriend = FALSE; if ($this->_pcpId) { if ($this->_pcpBlock['is_tellfriend_enabled']) { $this->assign('friendText', ts('Tell a Friend')); $subUrl = "eid={$this->_pcpId}&blockId={$this->_pcpBlock['id']}&pcomponent=pcp"; $tellAFriend = TRUE; } } elseif (CRM_Utils_Array::value('is_active', $data)) { $friendText = $data['title']; $this->assign('friendText', $friendText); $subUrl = "eid={$this->_id}&pcomponent=contribute"; $tellAFriend = TRUE; } if ($tellAFriend) { if ($this->_action & CRM_Core_Action::PREVIEW) { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&action=preview&{$subUrl}"); } else { $url = CRM_Utils_System::url("civicrm/friend", "reset=1&{$subUrl}"); } $this->assign('friendURL', $url); } $this->freeze(); // can we blow away the session now to prevent hackery // CRM-9491 $this->controller->reset(); }
/** * Process the form. * * @return void */ public function postProcess() { // get the submitted form values. $params = $this->controller->exportValues($this->_name); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $transaction = new CRM_Core_Transaction(); // also update uf join table $ufJoinParams = array('is_active' => 1, 'module' => 'CiviContribute', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); // first delete all past entries CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); if (!empty($params['custom_pre_id'])) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['custom_pre_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } unset($ufJoinParams['id']); if (!empty($params['custom_post_id'])) { $ufJoinParams['weight'] = 2; $ufJoinParams['uf_group_id'] = $params['custom_post_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } $transaction->commit(); parent::endPostProcess(); }
/** * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped * on DB upgrade * * @param CRM_Queue_TaskContext $ctx * * @return bool * TRUE for success */ public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); // fetch onBehalf entry in UFJoin table $ufGroupDAO = new CRM_Core_DAO_UFJoin(); $ufGroupDAO->module = 'OnBehalf'; $ufGroupDAO->find(TRUE); $forOrgColums = array(); if ($domain->locales) { $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); foreach ($locales as $locale) { $forOrgColums[] = "for_organization_{$locale}"; } } else { $forOrgColums[] = "for_organization"; } $query = "\n SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id\n FROM civicrm_contribution_page cp\n INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'"; $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); if ($dao->N) { while ($dao->fetch()) { $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization); if ($domain->locales) { foreach ($locales as $locale) { $for_organization = "for_organization_{$locale}"; $onBehalfParams['on_behalf'] += array($locale => array('for_organization' => $dao->{$for_organization})); } } else { $onBehalfParams['on_behalf'] += array('default' => array('for_organization' => $dao->for_organization)); } $ufJoinParam = array('id' => $dao->join_id, 'module' => 'on_behalf', 'uf_group_id' => $dao->uf_group_id, 'module_data' => json_encode($onBehalfParams)); CRM_Core_BAO_UFJoin::create($ufJoinParam); } } return TRUE; }
/** * Send the emails. * * @param int $contactID * Contact id. * @param array $values * Associated array of fields. * @param bool $isTest * If in test mode. * @param bool $returnMessageText * Return the message text instead of sending the mail. * * @param null $fieldTypes * * @return void */ public static function sendMail($contactID, $values, $isTest = FALSE, $returnMessageText = FALSE, $fieldTypes = NULL) { $gIds = $params = array(); $email = NULL; if (isset($values['custom_pre_id'])) { $preProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_pre_id']); if ($preProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_pre_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($preProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_pre_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_pre_id'] = $values['custom_pre_id']; } if (isset($values['custom_post_id'])) { $postProfileType = CRM_Core_BAO_UFField::getProfileType($values['custom_post_id']); if ($postProfileType == 'Membership' && !empty($values['membership_id'])) { $params['custom_post_id'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif ($postProfileType == 'Contribution' && !empty($values['contribution_id'])) { $params['custom_post_id'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } $gIds['custom_post_id'] = $values['custom_post_id']; } if (!empty($values['is_for_organization'])) { if (!empty($values['membership_id'])) { $params['onbehalf_profile'] = array(array('member_id', '=', $values['membership_id'], 0, 0)); } elseif (!empty($values['contribution_id'])) { $params['onbehalf_profile'] = array(array('contribution_id', '=', $values['contribution_id'], 0, 0)); } } //check whether it is a test drive if ($isTest && !empty($params['custom_pre_id'])) { $params['custom_pre_id'][] = array('contribution_test', '=', 1, 0, 0); } if ($isTest && !empty($params['custom_post_id'])) { $params['custom_post_id'][] = array('contribution_test', '=', 1, 0, 0); } if (!$returnMessageText && !empty($gIds)) { //send notification email if field values are set (CRM-1941) foreach ($gIds as $key => $gId) { if ($gId) { $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify'); if ($email) { $val = CRM_Core_BAO_UFGroup::checkFieldsEmptyValues($gId, $contactID, CRM_Utils_Array::value($key, $params), TRUE); CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val); } } } } if (!empty($values['is_email_receipt']) || !empty($values['onbehalf_dupe_alert']) || $returnMessageText) { $template = CRM_Core_Smarty::singleton(); // get the billing location type if (!array_key_exists('related_contact', $values)) { $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id', array(), 'validate'); $billingLocationTypeId = array_search('Billing', $locationTypes); } else { // presence of related contact implies onbehalf of org case, // where location type is set to default. $locType = CRM_Core_BAO_LocationType::getDefault(); $billingLocationTypeId = $locType->id; } if (!array_key_exists('related_contact', $values)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE, $billingLocationTypeId); } // get primary location email if no email exist( for billing location). if (!$email) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } if (empty($displayName)) { list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID); } //for display profile need to get individual contact id, //hence get it from related_contact if on behalf of org true CRM-3767 //CRM-5001 Contribution/Membership:: On Behalf of Organization, //If profile GROUP contain the Individual type then consider the //profile is of Individual ( including the custom data of membership/contribution ) //IF Individual type not present in profile then it is consider as Organization data. $userID = $contactID; if ($preID = CRM_Utils_Array::value('custom_pre_id', $values)) { if (!empty($values['related_contact'])) { $preProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($preID); //@todo - following line should not refer to undefined $postProfileTypes? figure out way to test if (in_array('Individual', $preProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } self::buildCustomDisplay($preID, 'customPre', $userID, $template, $params['custom_pre_id']); } $userID = $contactID; if ($postID = CRM_Utils_Array::value('custom_post_id', $values)) { if (!empty($values['related_contact'])) { $postProfileTypes = CRM_Core_BAO_UFGroup::profileGroups($postID); if (in_array('Individual', $postProfileTypes) || in_array('Contact', $postProfileTypes)) { //Take Individual contact ID $userID = CRM_Utils_Array::value('related_contact', $values); } } self::buildCustomDisplay($postID, 'customPost', $userID, $template, $params['custom_post_id']); } if (isset($values['honor'])) { $honorValues = $values['honor']; CRM_Contribute_BAO_ContributionSoft::formatHonoreeProfileFields($template, $honorValues['honor_profile_values'], $honorValues['honor_profile_id'], $honorValues['honor_id']); } $title = isset($values['title']) ? $values['title'] : CRM_Contribute_PseudoConstant::contributionPage($values['contribution_page_id']); // set email in the template here $tplParams = array('email' => $email, 'receiptFromEmail' => CRM_Utils_Array::value('receipt_from_email', $values), 'contactID' => $contactID, 'displayName' => $displayName, 'contributionID' => CRM_Utils_Array::value('contribution_id', $values), 'contributionOtherID' => CRM_Utils_Array::value('contribution_other_id', $values), 'lineItem' => CRM_Utils_Array::value('lineItem', $values), 'priceSetID' => CRM_Utils_Array::value('priceSetID', $values), 'title' => $title, 'isShare' => CRM_Utils_Array::value('is_share', $values), 'thankyou_title' => CRM_Utils_Array::value('thankyou_title', $values)); if ($contributionTypeId = CRM_Utils_Array::value('financial_type_id', $values)) { $tplParams['contributionTypeId'] = $contributionTypeId; $tplParams['contributionTypeName'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionTypeId); } if ($contributionPageId = CRM_Utils_Array::value('id', $values)) { $tplParams['contributionPageId'] = $contributionPageId; } // address required during receipt processing (pdf and email receipt) if ($displayAddress = CRM_Utils_Array::value('address', $values)) { $tplParams['address'] = $displayAddress; } // CRM-6976 $originalCCReceipt = CRM_Utils_Array::value('cc_receipt', $values); // cc to related contacts of contributor OR the one who // signs up. Is used for cases like - on behalf of // contribution / signup ..etc if (array_key_exists('related_contact', $values)) { list($ccDisplayName, $ccEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($values['related_contact']); $ccMailId = "{$ccDisplayName} <{$ccEmail}>"; //@todo - this is the only place in this function where $values is altered - but I can't find any evidence it is used $values['cc_receipt'] = !empty($values['cc_receipt']) ? $values['cc_receipt'] . ',' . $ccMailId : $ccMailId; // reset primary-email in the template $tplParams['email'] = $ccEmail; $tplParams['onBehalfName'] = $displayName; $tplParams['onBehalfEmail'] = $email; $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $values['id']); $OnBehalfProfile = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $profileId = $OnBehalfProfile[0]; $userID = $contactID; self::buildCustomDisplay($profileId, 'onBehalfProfile', $userID, $template, $params['onbehalf_profile'], $fieldTypes); } // use either the contribution or membership receipt, based on whether it’s a membership-related contrib or not $sendTemplateParams = array('groupName' => !empty($values['isMembership']) ? 'msg_tpl_workflow_membership' : 'msg_tpl_workflow_contribution', 'valueName' => !empty($values['isMembership']) ? 'membership_online_receipt' : 'contribution_online_receipt', 'contactId' => $contactID, 'tplParams' => $tplParams, 'isTest' => $isTest, 'PDFFilename' => 'receipt.pdf'); if ($returnMessageText) { list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html); } if ($values['is_email_receipt']) { $sendTemplateParams['from'] = CRM_Utils_Array::value('receipt_from_name', $values) . ' <' . $values['receipt_from_email'] . '>'; $sendTemplateParams['toName'] = $displayName; $sendTemplateParams['toEmail'] = $email; $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_receipt', $values); $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_receipt', $values); //send email with pdf invoice $template = CRM_Core_Smarty::singleton(); $taxAmt = $template->get_template_vars('dataArray'); $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue); if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) { $sendTemplateParams['isEmailPdf'] = TRUE; $sendTemplateParams['contributionId'] = $values['contribution_id']; } list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } // send duplicate alert, if dupe match found during on-behalf-of processing. if (!empty($values['onbehalf_dupe_alert'])) { $sendTemplateParams['groupName'] = 'msg_tpl_workflow_contribution'; $sendTemplateParams['valueName'] = 'contribution_dupalert'; $sendTemplateParams['from'] = ts('Automatically Generated') . " <{$values['receipt_from_email']}>"; $sendTemplateParams['toName'] = CRM_Utils_Array::value('receipt_from_name', $values); $sendTemplateParams['toEmail'] = CRM_Utils_Array::value('receipt_from_email', $values); $sendTemplateParams['tplParams']['onBehalfID'] = $contactID; $sendTemplateParams['tplParams']['receiptMessage'] = $message; // fix cc and reset back to original, CRM-6976 $sendTemplateParams['cc'] = $originalCCReceipt; CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams); } } }
function completeTransaction(&$input, &$ids, &$objects, &$transaction, $recur = FALSE) { $contribution =& $objects['contribution']; $memberships =& $objects['membership']; if (is_numeric($memberships)) { $memberships = array($objects['membership']); } $participant =& $objects['participant']; $event =& $objects['event']; $changeToday = CRM_Utils_Array::value('trxn_date', $input, self::$_now); $recurContrib =& $objects['contributionRecur']; $values = array(); if ($input['component'] == 'contribute') { if ($contribution->contribution_page_id) { CRM_Contribute_BAO_ContributionPage::setValues($contribution->contribution_page_id, $values); $source = ts('Online Contribution') . ': ' . $values['title']; } elseif ($recurContrib->id) { $contribution->contribution_page_id = NULL; $values['amount'] = $recurContrib->amount; $values['contribution_type_id'] = $objects['contributionType']->id; $values['title'] = $source = ts('Offline Recurring Contribution'); $values['is_email_receipt'] = $recurContrib->is_email_receipt; $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $values['receipt_from_name'] = $domainValues[0]; $values['receipt_from_email'] = $domainValues[1]; } $contribution->source = $source; if (CRM_Utils_Array::value('is_email_receipt', $values)) { $contribution->receipt_date = self::$_now; } if (!empty($memberships)) { foreach ($memberships as $membershipTypeIdKey => $membership) { if ($membership) { $format = '%Y%m%d'; $currentMembership = CRM_Member_BAO_Membership::getContactMembership($membership->contact_id, $membership->membership_type_id, $membership->is_test, $membership->id); // CRM-8141 update the membership type with the value recorded in log when membership created/renewed // this picks up membership type changes during renewals $sql = "\nSELECT membership_type_id\nFROM civicrm_membership_log\nWHERE membership_id={$membership->id}\nORDER BY id DESC\nLIMIT 1;"; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { if (!empty($dao->membership_type_id)) { $membership->membership_type_id = $dao->membership_type_id; $membership->save(); } // else fall back to using current membership type } // else fall back to using current membership type $dao->free(); if ($currentMembership) { /* * Fixed FOR CRM-4433 * In BAO/Membership.php(renewMembership function), we skip the extend membership date and status * when Contribution mode is notify and membership is for renewal ) */ CRM_Member_BAO_Membership::fixMembershipStatusBeforeRenew($currentMembership, $changeToday); $dates = CRM_Member_BAO_MembershipType::getRenewalDatesForMembershipType($membership->id, $changeToday); $dates['join_date'] = CRM_Utils_Date::customFormat($currentMembership['join_date'], $format); } else { $dates = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membership->membership_type_id); } //get the status for membership. $calcStatus = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($dates['start_date'], $dates['end_date'], $dates['join_date'], 'today', TRUE); $formatedParams = array('status_id' => CRM_Utils_Array::value('id', $calcStatus, 2), 'join_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('join_date', $dates), $format), 'start_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('start_date', $dates), $format), 'end_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('end_date', $dates), $format), 'reminder_date' => CRM_Utils_Date::customFormat(CRM_Utils_Array::value('reminder_date', $dates), $format)); //we might be renewing membership, //so make status override false. $formatedParams['is_override'] = FALSE; $membership->copyValues($formatedParams); $membership->save(); //updating the membership log $membershipLog = array(); $membershipLog = $formatedParams; $logStartDate = $formatedParams['start_date']; if (CRM_Utils_Array::value('log_start_date', $dates)) { $logStartDate = CRM_Utils_Date::customFormat($dates['log_start_date'], $format); $logStartDate = CRM_Utils_Date::isoToMysql($logStartDate); } $membershipLog['start_date'] = $logStartDate; $membershipLog['membership_id'] = $membership->id; $membershipLog['modified_id'] = $membership->contact_id; $membershipLog['modified_date'] = date('Ymd'); $membershipLog['membership_type_id'] = $membership->membership_type_id; CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray); //update related Memberships. CRM_Member_BAO_Membership::updateRelatedMemberships($membership->id, $formatedParams); //update the membership type key of membership relatedObjects array //if it has changed after membership update if ($membershipTypeIdKey != $membership->membership_type_id) { $memberships[$membership->membership_type_id] = $membership; $contribution->_relatedObjects['membership'][$membership->membership_type_id] = $membership; unset($contribution->_relatedObjects['membership'][$membershipTypeIdKey]); unset($memberships[$membershipTypeIdKey]); } } } } } else { // event $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); $eventParams = array('id' => $objects['event']->id); $values['event'] = array(); CRM_Event_BAO_Event::retrieve($eventParams, $values['event']); //get location details $locationParams = array('entity_id' => $objects['event']->id, 'entity_table' => 'civicrm_event'); $values['location'] = CRM_Core_BAO_Location::getValues($locationParams); $ufJoinParams = array('entity_table' => 'civicrm_event', 'entity_id' => $ids['event'], 'module' => 'CiviEvent'); list($custom_pre_id, $custom_post_ids) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); $values['custom_pre_id'] = $custom_pre_id; $values['custom_post_id'] = $custom_post_ids; $contribution->source = ts('Online Event Registration') . ': ' . $values['event']['title']; if ($values['event']['is_email_confirm']) { $contribution->receipt_date = self::$_now; $values['is_email_receipt'] = 1; } $participant->status_id = 1; $participant->save(); } if (CRM_Utils_Array::value('net_amount', $input, 0) == 0 && CRM_Utils_Array::value('fee_amount', $input, 0) != 0) { $input['net_amount'] = $input['amount'] - $input['fee_amount']; } $addLineItems = FALSE; if (empty($contribution->id)) { $addLineItems = TRUE; } $contribution->contribution_status_id = 1; $contribution->is_test = $input['is_test']; $contribution->fee_amount = CRM_Utils_Array::value('fee_amount', $input, 0); $contribution->net_amount = CRM_Utils_Array::value('net_amount', $input, 0); $contribution->trxn_id = $input['trxn_id']; $contribution->receive_date = CRM_Utils_Date::isoToMysql($contribution->receive_date); $contribution->thankyou_date = CRM_Utils_Date::isoToMysql($contribution->thankyou_date); $contribution->cancel_date = 'null'; if (CRM_Utils_Array::value('check_number', $input)) { $contribution->check_number = $input['check_number']; } if (CRM_Utils_Array::value('payment_instrument_id', $input)) { $contribution->payment_instrument_id = $input['payment_instrument_id']; } $contribution->save(); //add lineitems for recurring payments if (CRM_Utils_Array::value('contributionRecur', $objects) && $objects['contributionRecur']->id && $addLineItems) { $this->addrecurLineItems($objects['contributionRecur']->id, $contribution->id); } // next create the transaction record $paymentProcessor = ''; if (isset($objects['paymentProcessor'])) { if (is_array($objects['paymentProcessor'])) { $paymentProcessor = $objects['paymentProcessor']['payment_processor_type']; } else { $paymentProcessor = $objects['paymentProcessor']->payment_processor_type; } } if ($contribution->trxn_id) { $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => isset($input['trxn_date']) ? $input['trxn_date'] : self::$_now, 'trxn_type' => 'Debit', 'total_amount' => $input['amount'], 'fee_amount' => $contribution->fee_amount, 'net_amount' => $contribution->net_amount, 'currency' => $contribution->currency, 'payment_processor' => $paymentProcessor, 'trxn_id' => $contribution->trxn_id); $trxn = CRM_Core_BAO_FinancialTrxn::create($trxnParams); } self::updateRecurLinkedPledge($contribution); // create an activity record if ($input['component'] == 'contribute') { //CRM-4027 $targetContactID = NULL; if (CRM_Utils_Array::value('related_contact', $ids)) { $targetContactID = $contribution->contact_id; $contribution->contact_id = $ids['related_contact']; } CRM_Activity_BAO_Activity::addActivity($contribution, NULL, $targetContactID); // event } else { CRM_Activity_BAO_Activity::addActivity($participant); } CRM_Core_Error::debug_log_message("Contribution record updated successfully"); $transaction->commit(); // CRM-9132 legacy behaviour was that receipts were sent out in all instances. Still sending // when array_key 'is_email_receipt doesn't exist in case some instances where is needs setting haven't been set if (!array_key_exists('is_email_receipt', $values) || $values['is_email_receipt'] == 1) { self::sendMail($input, $ids, $objects, $values, $recur, FALSE); } CRM_Core_Error::debug_log_message("Success: Database updated and mail sent"); }
/** * Set variables up before form is built. */ public function preProcess() { parent::preProcess(); self::preProcessPaymentOptions($this); // Make the contributionPageID available to the template $this->assign('contributionPageID', $this->_id); $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values)); $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values)); $this->assign('reset', CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject)); $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject)); // Possible values for 'is_for_organization': // * 0 - org profile disabled // * 1 - org profile optional // * 2 - org profile required $this->_onbehalf = FALSE; if (!empty($this->_values['is_for_organization'])) { if ($this->_values['is_for_organization'] == 2) { $this->_onBehalfRequired = TRUE; } // Add organization profile if 1 of the following are true: // If the org profile is required if ($this->_onBehalfRequired || empty($_POST) || !empty($_POST['is_for_organization'])) { $this->_onbehalf = TRUE; CRM_Contribute_Form_Contribution_OnBehalfOf::preProcess($this); } } $this->assign('onBehalfRequired', $this->_onBehalfRequired); if ($this->_honor_block_is_active) { CRM_Contact_Form_ProfileContact::preprocess($this); } if ($this->_snippet) { $this->assign('isOnBehalfCallback', CRM_Utils_Array::value('onbehalf', $_GET, FALSE)); return; } if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) { $this->assign('intro_text', $this->_pcpInfo['intro_text']); } elseif (!empty($this->_values['intro_text'])) { $this->assign('intro_text', $this->_values['intro_text']); } $qParams = "reset=1&id={$this->_id}"; if ($pcpId = CRM_Utils_Array::value('pcp_id', $this->_pcpInfo)) { $qParams .= "&pcpId={$pcpId}"; } $this->assign('qParams', $qParams); if (!empty($this->_values['footer_text'])) { $this->assign('footer_text', $this->_values['footer_text']); } //CRM-5001 //CRM-15787 $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); if (!empty($this->_values['is_for_organization']) && empty($member['is_active'])) { $msg = ts('Mixed profile not allowed for on behalf of registration/sign up.'); $ufJoinParams = array('module' => 'onBehalf', 'entity_table' => 'civicrm_contribution_page', 'entity_id' => $this->_id); $onBehalfProfileIDs = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // getUFGroupIDs returns an array with the first item being the ID we need $onBehalfProfileID = $onBehalfProfileIDs[0]; if ($onBehalfProfileID) { $onBehalfProfile = CRM_Core_BAO_UFGroup::profileGroups($onBehalfProfileID); foreach (array('Individual', 'Organization', 'Household') as $contactType) { if (in_array($contactType, $onBehalfProfile) && (in_array('Membership', $onBehalfProfile) || in_array('Contribution', $onBehalfProfile))) { CRM_Core_Error::fatal($msg); } } } if ($postID = CRM_Utils_Array::value('custom_post_id', $this->_values)) { $postProfile = CRM_Core_BAO_UFGroup::profileGroups($postID); foreach (array('Individual', 'Organization', 'Household') as $contactType) { if (in_array($contactType, $postProfile) && (in_array('Membership', $postProfile) || in_array('Contribution', $postProfile))) { CRM_Core_Error::fatal($msg); } } } } }
/** * Set variables up before form is built. */ public function preProcess() { $this->_eventId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); //CRM-4320 $this->_participantId = CRM_Utils_Request::retrieve('participantId', 'Positive', $this); // 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'); $this->_lineItem = $this->get('lineItem'); $this->_isEventFull = $this->get('isEventFull'); $this->_lineItemParticipantsCount = $this->get('lineItemParticipants'); if (!is_array($this->_lineItem)) { $this->_lineItem = array(); } if (!is_array($this->_lineItemParticipantsCount)) { $this->_lineItemParticipantsCount = array(); } $this->_availableRegistrations = $this->get('availableRegistrations'); $this->_participantIDS = $this->get('participantIDs'); //check if participant allow to walk registration wizard. $this->_allowConfirmation = $this->get('allowConfirmation'); // check for Approval $this->_requireApproval = $this->get('requireApproval'); // check for waitlisting. $this->_allowWaitlist = $this->get('allowWaitlist'); $this->_forcePayement = $this->get('forcePayement'); //get the additional participant ids. $this->_additionalParticipantIds = $this->get('additionalParticipantIds'); $config = CRM_Core_Config::singleton(); if (!$this->_values) { // create redirect URL to send folks back to event info page is registration not available $infoUrl = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_eventId}", FALSE, NULL, FALSE, TRUE); // this is the first time we are hitting this, so check for permissions here if (!CRM_Core_Permission::event(CRM_Core_Permission::EDIT, $this->_eventId, 'register for events')) { CRM_Core_Error::statusBounce(ts('You do not have permission to register for this event'), $infoUrl); } // get all the values from the dao object $this->_values = $this->_fields = array(); $this->_forcePayement = FALSE; //retrieve event information $params = array('id' => $this->_eventId); CRM_Event_BAO_Event::retrieve($params, $this->_values['event']); // check for is_monetary status $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values['event']); // check for ability to add contributions of type if ($isMonetary && CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['event']['financial_type_id']))) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } $this->checkValidEvent($infoUrl); // get the participant values, CRM-4320 $this->_allowConfirmation = FALSE; if ($this->_participantId) { $this->processFirstParticipant($this->_participantId); } //check for additional participants. if ($this->_allowConfirmation && $this->_values['event']['is_multiple_registrations']) { $additionalParticipantIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_participantId); $cnt = 1; foreach ($additionalParticipantIds as $additionalParticipantId) { $this->_additionalParticipantIds[$cnt] = $additionalParticipantId; $cnt++; } $this->set('additionalParticipantIds', $this->_additionalParticipantIds); } $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId, FALSE, CRM_Utils_Array::value('has_waitlist', $this->_values['event'])); $this->_allowWaitlist = $this->_isEventFull = FALSE; if ($eventFull && !$this->_allowConfirmation) { $this->_isEventFull = TRUE; //lets redirecting to info only when to waiting list. $this->_allowWaitlist = CRM_Utils_Array::value('has_waitlist', $this->_values['event']); if (!$this->_allowWaitlist) { CRM_Utils_System::redirect($infoUrl); } } $this->set('isEventFull', $this->_isEventFull); $this->set('allowWaitlist', $this->_allowWaitlist); //check for require requires approval. $this->_requireApproval = FALSE; if (!empty($this->_values['event']['requires_approval']) && !$this->_allowConfirmation) { $this->_requireApproval = TRUE; } $this->set('requireApproval', $this->_requireApproval); if (isset($this->_values['event']['default_role_id'])) { $participant_role = CRM_Core_OptionGroup::values('participant_role'); $this->_values['event']['participant_role'] = $participant_role["{$this->_values['event']['default_role_id']}"]; } $isPayLater = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eventId, 'is_pay_later'); //check for various combinations for paylater, payment //process with paid event. if ($isMonetary && (!$isPayLater || !empty($this->_values['event']['payment_processor']))) { $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', $this->_values['event'])); $this->assignPaymentProcessor($isPayLater); } //init event fee. self::initEventFee($this, $this->_eventId); // get the profile ids $ufJoinParams = array('entity_table' => 'civicrm_event', 'module' => 'CiviEvent', 'entity_id' => $this->_eventId); list($this->_values['custom_pre_id'], $this->_values['custom_post_id']) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // set profiles for additional participants if ($this->_values['event']['is_multiple_registrations']) { // CRM-4377: CiviEvent for the main participant, CiviEvent_Additional for additional participants $ufJoinParams['module'] = 'CiviEvent_Additional'; list($this->_values['additional_custom_pre_id'], $this->_values['additional_custom_post_id'], $preActive, $postActive) = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); // CRM-4377: we need to maintain backward compatibility, hence if there is profile for main contact // set same profile for additional contacts. if ($this->_values['custom_pre_id'] && !$this->_values['additional_custom_pre_id']) { $this->_values['additional_custom_pre_id'] = $this->_values['custom_pre_id']; } if ($this->_values['custom_post_id'] && !$this->_values['additional_custom_post_id']) { $this->_values['additional_custom_post_id'] = $this->_values['custom_post_id']; } // now check for no profile condition, in that case is_active = 0 if (isset($preActive) && !$preActive) { unset($this->_values['additional_custom_pre_id']); } if (isset($postActive) && !$postActive) { unset($this->_values['additional_custom_post_id']); } } $this->assignBillingType(); if ($this->_values['event']['is_monetary']) { CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor); } $params = array('entity_id' => $this->_eventId, 'entity_table' => 'civicrm_event'); $this->_values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); $this->set('values', $this->_values); $this->set('fields', $this->_fields); $this->_availableRegistrations = CRM_Event_BAO_Participant::eventFull($this->_values['event']['id'], TRUE, CRM_Utils_Array::value('has_waitlist', $this->_values['event'])); $this->set('availableRegistrations', $this->_availableRegistrations); } $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/event/register', "_qf_ThankYou_display=1&qfKey={$this->controller->_key}"); CRM_Utils_System::redirect($url); } // The concept of contributeMode is deprecated. $this->_contributeMode = $this->get('contributeMode'); $this->assign('contributeMode', $this->_contributeMode); // setting CMS page title CRM_Utils_System::setTitle($this->_values['event']['title']); $this->assign('title', $this->_values['event']['title']); $this->assign('paidEvent', $this->_values['event']['is_monetary']); // we do not want to display recently viewed items on Registration pages $this->assign('displayRecent', FALSE); // Registration page values are cleared from session, so can't use normal Printer Friendly view. // Use Browser Print instead. $this->assign('browserPrint', TRUE); $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); $this->assign('isShowLocation', $isShowLocation); // Handle PCP $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this); if ($pcpId) { $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'event', $this->_values['event']); $this->_pcpId = $pcp['pcpId']; $this->_values['event']['intro_text'] = CRM_Utils_Array::value('intro_text', $pcp['pcpInfo']); } // assign all event properties so wizard templates can display event info. $this->assign('event', $this->_values['event']); $this->assign('location', $this->_values['location']); $this->assign('bltID', $this->_bltID); $isShowLocation = CRM_Utils_Array::value('is_show_location', $this->_values['event']); $this->assign('isShowLocation', $isShowLocation); //CRM-6907 $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values['event'], $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['event']['campaign_id'] = $campID; } // Set the same value for is_billing_required as contribution page so code can be shared. $this->_values['is_billing_required'] = CRM_Utils_Array::value('is_billing_required', $this->_values['event']); // check if billing block is required for pay later // note that I have started removing the use of isBillingAddressRequiredForPayLater in favour of letting // the CRM_Core_Payment_Manual class handle it - but there are ~300 references to it in the code base so only // removing in very limited cases. if (CRM_Utils_Array::value('is_pay_later', $this->_values['event'])) { $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values['event']); $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater); } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false); $params['id'] = $this->_id; //new event, so lets set the created_id if ($this->_action & CRM_Core_Action::ADD) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); require_once 'CRM/Event/BAO/Event.php'; // copy all not explicitely set $params keys from the template (if it should be sourced) if (CRM_Utils_Array::value('template_id', $params)) { $defaults = array(); $templateParams = array('id' => $params['template_id']); CRM_Event_BAO_Event::retrieve($templateParams, $defaults); unset($defaults['id']); unset($defaults['default_fee_id']); unset($defaults['default_discount_fee_id']); foreach ($defaults as $key => $value) { if (!isset($params[$key])) { $params[$key] = $value; } } } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy event fees $ogParams = array('name' => "civicrm_event.amount.{$event->id}"); $defaults = array(); require_once 'CRM/Core/BAO/OptionGroup.php'; if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) { // Copy the Main Event Fees CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id); // Copy the Discount option Group and Values require_once 'CRM/Core/BAO/Discount.php'; $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event"); foreach ($optionGroupIds as $id) { $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label'); CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix); } } // copy price sets if any require_once 'CRM/Price/BAO/Set.php'; $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Core/BAO/UFJoin.php'; if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Friend/BAO/Friend.php'; if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") { $urlParam = "action=update&reset=1&id={$event->id}"; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam)); } parent::endPostProcess(); }