/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids); $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; $dao = new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::honor(); $values['honor_type'] = $honor[$values['honor_type_id']]; } //handle custom data. $groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); if (CRM_Utils_Array::value('contribution_page_id', $values)) { $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); } $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType()); if ($values['status_id']) { $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); } $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviPledge', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')'; // add Pledge to Recent Items CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], NULL, $recentOther); //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } $this->assign($values); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { require_once 'CRM/Pledge/BAO/Pledge.php'; $values = $ids = array(); $params = array('id' => $this->get('id')); CRM_Pledge_BAO_Pledge::getValues($params, $values, $ids); $values['frequencyUnit'] = ts('%1(s)', array(1 => $values['frequency_unit'])); $values['eachPaymentAmount'] = floor($values['amount'] / $values['installments']); if (isset($values["honor_contact_id"]) && $values["honor_contact_id"]) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = " . $values["honor_contact_id"]; $dao =& new CRM_Core_DAO(); $dao->query($sql); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::honor(); $values['honor_type'] = $honor[$values['honor_type_id']]; } //handle custom data. $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', $this, $params['id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); if (CRM_Utils_Array::value('contribution_page_id', $values)) { $values['contribution_page'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $values['contribution_page_id'], 'title'); } $values['contribution_type'] = CRM_Utils_Array::value($values['contribution_type_id'], CRM_Contribute_PseudoConstant::contributionType()); if ($values['status_id']) { $values['pledge_status'] = CRM_Utils_Array::value($values['status_id'], CRM_Contribute_PseudoConstant::contributionStatus()); } require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/pledge', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); require_once 'CRM/Utils/Money.php'; $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . ts('Pledged') . ' ' . CRM_Utils_Money::format($values['pledge_amount']) . ' - ' . $values['contribution_type'] . ')'; // add Pledge to Recent Items CRM_Utils_Recent::add($title, $url, $values['id'], 'Pledge', $values['contact_id'], null); $this->assign($values); }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } // build price set form. $buildPriceSet = FALSE; if ($this->_priceSetId || CRM_Utils_Array::value('price_set_id', $_POST)) { if (CRM_Utils_Array::value('price_set_id', $_POST)) { $buildPriceSet = TRUE; } $getOnlyPriceSetElements = TRUE; if (!$this->_priceSetId) { $this->_priceSetId = $_POST['price_set_id']; $getOnlyPriceSetElements = FALSE; } $this->set('priceSetId', $this->_priceSetId); CRM_Price_BAO_Set::buildPriceSet($this); $optionsMembershipTypes = array(); foreach ($this->_priceSet['fields'] as $pField) { if (empty($pField['options'])) { continue; } foreach ($pField['options'] as $opId => $opValues) { $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0); } } $this->assign('autoRenewOption', CRM_Price_BAO_Set::checkAutoRenewForPriceSet($this->_priceSetId)); $this->assign('optionsMembershipTypes', $optionsMembershipTypes); $this->assign('contributionType', CRM_Utils_Array::value('contribution_type_id', $this->_priceSet)); // get only price set form elements. if ($getOnlyPriceSetElements) { return; } } // use to build form during form rule. $this->assign('buildPriceSet', $buildPriceSet); if ($this->_action & CRM_Core_Action::ADD) { $buildPriceSet = FALSE; $priceSets = CRM_Price_BAO_Set::getAssoc(FALSE, 'CiviMember'); if (!empty($priceSets)) { $buildPriceSet = TRUE; } if ($buildPriceSet) { $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );")); } $this->assign('hasPriceSets', $buildPriceSet); } //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Membership'); $this->assign('customDataSubType', $this->_memType); $this->assign('entityID', $this->_id); if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if ($this->_context == 'standalone') { CRM_Contact_Form_NewContact::buildQuickForm($this); } $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -'); $dao = new CRM_Member_DAO_MembershipType(); $dao->domain_id = CRM_Core_Config::domainID(); $dao->find(); // retrieve all memberships $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); $allMembershipInfo = $membershipType = array(); foreach ($allMemberships as $key => $values) { if (CRM_Utils_Array::value('is_active', $values)) { $membershipType[$key] = CRM_Utils_Array::value('name', $values); if ($this->_mode && !CRM_Utils_Array::value('minimum_fee', $values)) { continue; } else { $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values); if (!CRM_Utils_Array::value($memberOfContactId, $selMemTypeOrg)) { $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id'); $selOrgMemType[$memberOfContactId][0] = ts('- select -'); } if (!CRM_Utils_Array::value($key, $selOrgMemType[$memberOfContactId])) { $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values); } } // build membership info array, which is used to set the payment information block when // membership type is selected. $allMembershipInfo[$key] = array('contribution_type_id' => CRM_Utils_Array::value('contribution_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values)); } } $this->assign('allMembershipInfo', json_encode($allMembershipInfo)); // show organization by default, if only one organization in // the list if (count($selMemTypeOrg) == 2) { unset($selMemTypeOrg[0], $selOrgMemType[0][0]); } //sort membership organization and type, CRM-6099 natcasesort($selMemTypeOrg); foreach ($selOrgMemType as $index => $orgMembershipType) { natcasesort($orgMembershipType); $selOrgMemType[$index] = $orgMembershipType; } $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value );"); //build the form for auto renew. $recurProcessor = $autoRenew = array(); if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) { $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "buildReceiptANDNotice( );")); if ($this->_mode) { //get the valid recurring processors. $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $recurProcessor = array_intersect_assoc($this->_processors, $recurring); $autoRenew = array(); if (!empty($recurProcessor)) { if (!empty($membershipType)) { $sql = ' SELECT id, auto_renew, duration_unit, duration_interval FROM civicrm_membership_type WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); while ($recurMembershipTypes->fetch()) { $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) { $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld}; } } } $memTypeJs = array('onChange' => "buildCustomData( 'Membership', this.value ); buildAutoRenew(this.value, null );"); } } } $allowAutoRenew = FALSE; if ($this->_mode && !empty($recurProcessor)) { $allowAutoRenew = TRUE; } $this->assign('allowAutoRenew', $allowAutoRenew); $this->assign('autoRenewOptions', json_encode($autoRenew)); $this->assign('recurProcessor', json_encode($recurProcessor)); $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs); $sel->setOptions(array($selMemTypeOrg, $selOrgMemType)); $elements = array(); if ($sel) { $elements[] = $sel; } $this->applyFilter('__ALL__', 'trim'); $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate')); $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate')); $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate')); if ($endDate) { $elements[] = $endDate; } $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source')); //CRM-7362 --add campaigns. $campaignId = NULL; if ($this->_id) { $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id'); } CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId); if (!$this->_mode) { $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label')); $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()')); if ($statusOverride) { $elements[] = $statusOverride; } $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?')); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate')); $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")); $this->add('text', 'trxn_id', ts('Transaction ID')); $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')); $allowStatuses = array(); $statuses = CRM_Contribute_PseudoConstant::contributionStatus(); if ($this->_onlinePendingContributionId) { $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach ($statusNames as $val => $name) { if (in_array($name, array('In Progress', 'Overdue'))) { continue; } $allowStatuses[$val] = $statuses[$val]; } } else { $allowStatuses = $statuses; } $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses); $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')); } else { //add field for amount to allow an amount to be entered that differs from minimum $this->add('text', 'total_amount', ts('Amount')); } if ($this->_context != 'standalone') { //CRM-10223 - allow contribution to be recorded against different contact // causes a conflict in standalone mode so skip in standalone for now $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?')); $this->add('select', 'honor_type_id', ts('Membership payment is : '), array('' => ts('-')) + CRM_Core_PseudoConstant::honor()); CRM_Contact_Form_NewContact::buildQuickForm($this, 1, null, false, 'contribution_'); } $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio', false);")); $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); $this->add('textarea', 'receipt_text_signup', ts('Receipt Message')); if ($this->_mode) { $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE, array('onChange' => "buildAutoRenew( null, this.value );")); CRM_Core_Payment_Form::buildCreditCard($this, TRUE); } // Retrieve the name and email of the contact - this will be the TO for receipt email if ($this->_contactID) { list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('emailExists', $this->_memberEmail); $this->assign('displayName', $this->_memberDisplayName); } $isRecur = FALSE; if ($this->_action & CRM_Core_Action::UPDATE) { $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id'); if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) { $isRecur = TRUE; if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) { $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")); } foreach ($elements as $elem) { $elem->freeze(); } } } $this->assign('isRecur', $isRecur); $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this); $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend'); $this->assign('outBound_option', $mailingInfo['outBound_option']); parent::buildQuickForm(); }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * @return None */ function setDefaultValues() { $defaults = $this->_values; $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign("is_test", true); } if ($this->_id) { $startDate = CRM_Utils_Array::value('start_date', $this->_values); $createDate = CRM_Utils_Array::value('create_date', $this->_values); list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate); list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate); if ($this->_values['acknowledge_date']) { list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value('acknowledge_date', $this->_values)); } //check is this pledge pending // fix the display of the monetary value, CRM-4038 require_once 'CRM/Utils/Money.php'; if ($this->_isPending) { $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments']; $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], null, '%a'); } else { $this->assign('start_date', $startDate); $this->assign('create_date', $createDate); } // fix the display of the monetary value, CRM-4038 if (isset($this->_values['amount'])) { $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], null, '%a'); } } else { //default values. list($now) = CRM_Utils_Date::setDateDefaults(); $defaults['create_date'] = $now; $defaults['start_date'] = $now; $defaults['installments'] = 12; $defaults['frequency_interval'] = 1; $defaults['frequency_day'] = 1; $defaults['initial_reminder_day'] = 5; $defaults['max_reminders'] = 1; $defaults['additional_reminder_day'] = 5; $defaults['frequency_unit'] = array_search('monthly', $this->_freqUnits); $defaults['contribution_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::contributionType()); } //assign status. $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), CRM_Contribute_PseudoConstant::contributionStatus(), 'Pending')); //honoree contact. if ($this->_honorID) { require_once 'CRM/Contact/BAO/Contact.php'; $honorDefault = array(); $idParams = array('contact_id' => $this->_honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $honorType = CRM_Core_PseudoConstant::honor(); $defaults["honor_prefix_id"] = $honorDefault["prefix_id"]; $defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault); $defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault); $defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]); $defaults["honor_type"] = $honorType[$defaults["honor_type_id"]]; } $this->assign('email', $this->userEmail); // custom data set defaults $defaults += CRM_Custom_Form_Customdata::setDefaultValues($this); return $defaults; }
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); } }
/** * Create the Honor contact * * @return void * @access public */ function createHonorContact() { $params = $this->controller->exportValues('Main'); // return if we dont have enough information if (empty($params["honor_first_name"]) && empty($params["honor_last_name"]) && empty($params["honor_email"])) { return null; } //assign to template for email reciept $honor_block_is_active = $this->get('honor_block_is_active'); $this->assign('honor_block_is_active', $honor_block_is_active); $this->assign("honor_block_title", $this->_values['honor_block_title']); require_once "CRM/Core/PseudoConstant.php"; $prefix = CRM_Core_PseudoConstant::individualPrefix(); $honorType = CRM_Core_PseudoConstant::honor(); $this->assign("honor_type", $honorType[$params["honor_type_id"]]); $this->assign("honor_prefix", $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"]); //create honoree contact require_once 'CRM/Contribute/BAO/Contribution.php'; return CRM_Contribute_BAO_Contribution::createHonorContact($params); }
/** * This function sets the default values for the form. * the default values are retrieved from the database * * @access public * * @return None */ function setDefaultValues() { $defaults = $this->_values; $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign('is_test', TRUE); } if ($this->_id) { $startDate = CRM_Utils_Array::value('start_date', $this->_values); $createDate = CRM_Utils_Array::value('create_date', $this->_values); list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($startDate); list($defaults['create_date']) = CRM_Utils_Date::setDateDefaults($createDate); if ($ackDate = CRM_Utils_Array::value('acknowledge_date', $this->_values)) { list($defaults['acknowledge_date']) = CRM_Utils_Date::setDateDefaults($ackDate); } //check is this pledge pending // fix the display of the monetary value, CRM-4038 if ($this->_isPending) { $defaults['eachPaymentAmount'] = $this->_values['amount'] / $this->_values['installments']; $defaults['eachPaymentAmount'] = CRM_Utils_Money::format($defaults['eachPaymentAmount'], NULL, '%a'); } else { $this->assign('start_date', $startDate); $this->assign('create_date', $createDate); } // fix the display of the monetary value, CRM-4038 if (isset($this->_values['amount'])) { $defaults['amount'] = CRM_Utils_Money::format($this->_values['amount'], NULL, '%a'); } $this->assign('amount', $this->_values['amount']); $this->assign('installments', $defaults['installments']); } else { //default values. list($now) = CRM_Utils_Date::setDateDefaults(); $defaults['create_date'] = $now; $defaults['start_date'] = $now; $defaults['installments'] = 12; $defaults['frequency_interval'] = 1; $defaults['frequency_day'] = 1; $defaults['initial_reminder_day'] = 5; $defaults['max_reminders'] = 1; $defaults['additional_reminder_day'] = 5; $defaults['frequency_unit'] = array_search('month', $this->_freqUnits); $defaults['contribution_type_id'] = array_search('Donation', CRM_Contribute_PseudoConstant::contributionType()); } $pledgeStatus = CRM_Contribute_PseudoConstant::contributionStatus(); $pledgeStatusNames = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', TRUE); // get default status label (pending) $defaultPledgeStatus = CRM_Utils_Array::value(array_search('Pending', $pledgeStatusNames), $pledgeStatus); //assign status. $this->assign('status', CRM_Utils_Array::value(CRM_Utils_Array::value('status_id', $this->_values), $pledgeStatus, $defaultPledgeStatus)); //honoree contact. if ($this->_honorID) { $honorDefault = array(); $idParams = array('contact_id' => $this->_honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault); $honorType = CRM_Core_PseudoConstant::honor(); $defaults['honor_prefix_id'] = $honorDefault['prefix_id']; $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } // custom data set defaults $defaults += CRM_Custom_Form_CustomData::setDefaultValues($this); return $defaults; }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } parent::buildQuickForm(); $defaults = array(); $defaults = parent::setDefaultValues(); $this->_memType = $defaults['membership_type_id']; $this->assign('customDataType', 'Membership'); $this->assign('customDataSubType', $this->_memType); $this->assign('entityID', $this->_id); $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -'); $allMemberships = CRM_Member_BAO_Membership::buildMembershipTypeValues($this); $allMembershipInfo = $membershipType = array(); // auto renew options if enabled for the membership $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required ')); foreach ($allMemberships as $key => $values) { if (CRM_Utils_Array::value('is_active', $values)) { $membershipType[$key] = CRM_Utils_Array::value('name', $values); if ($this->_mode && !CRM_Utils_Array::value('minimum_fee', $values)) { continue; } else { $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values); if (!CRM_Utils_Array::value($memberOfContactId, $selMemTypeOrg)) { $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id'); $selOrgMemType[$memberOfContactId][0] = ts('- select -'); } if (!CRM_Utils_Array::value($key, $selOrgMemType[$memberOfContactId])) { $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values); } } // build membership info array, which is used to set the payment information block when // membership type is selected. $allMembershipInfo[$key] = array('contribution_type_id' => CRM_Utils_Array::value('contribution_type_id', $values), 'total_amount' => CRM_Utils_Money::format($values['minimum_fee'], NULL, '%a'), 'total_amount_numeric' => CRM_Utils_Array::value('minimum_fee', $values)); if (CRM_Utils_Array::value('auto_renew', $values)) { $allMembershipInfo[$key]['auto_renew'] = $options[$values['auto_renew']]; } } } $this->assign('allMembershipInfo', json_encode($allMembershipInfo)); if ($this->_memType) { $this->assign('orgName', $selMemTypeOrg[$allMemberships[$this->_memType]['member_of_contact_id']]); $this->assign('memType', $allMemberships[$this->_memType]['name']); } // force select of organization by default, if only one organization in // the list if (count($selMemTypeOrg) == 2) { unset($selMemTypeOrg[0], $selOrgMemType[0][0]); } //sort membership organization and type, CRM-6099 natcasesort($selMemTypeOrg); foreach ($selOrgMemType as $index => $orgMembershipType) { natcasesort($orgMembershipType); $selOrgMemType[$index] = $orgMembershipType; } $js = array('onChange' => "setPaymentBlock( ); buildCustomData( 'Membership', this.value );"); //build the form for auto renew. $recurProcessor = array(); if ($this->_mode || $this->_action & CRM_Core_Action::UPDATE) { //get the valid recurring processors. $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $recurProcessor = array_intersect_assoc($this->_processors, $recurring); if (!empty($recurProcessor)) { $autoRenew = array(); if (!empty($membershipType)) { $sql = ' SELECT id, auto_renew, duration_unit, duration_interval FROM civicrm_membership_type WHERE id IN ( ' . implode(' , ', array_keys($membershipType)) . ' )'; $recurMembershipTypes = CRM_Core_DAO::executeQuery($sql); while ($recurMembershipTypes->fetch()) { $autoRenew[$recurMembershipTypes->id] = $recurMembershipTypes->auto_renew; foreach (array('id', 'auto_renew', 'duration_unit', 'duration_interval') as $fld) { $this->_recurMembershipTypes[$recurMembershipTypes->id][$fld] = $recurMembershipTypes->{$fld}; } } } $js = array('onChange' => "setPaymentBlock(); buildCustomData( 'Membership', this.value );"); $this->assign('autoRenew', json_encode($autoRenew)); } $autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'), NULL, array('onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );")); if ($this->_action & CRM_Core_Action::UPDATE) { $autoRenewElement->freeze(); } } $this->assign('recurProcessor', json_encode($recurProcessor)); $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Renewal Membership Organization and Type'), $js); $sel->setOptions(array($selMemTypeOrg, $selOrgMemType)); $elements = array(); if ($sel) { $elements[] = $sel; } $this->applyFilter('__ALL__', 'trim'); $this->addDate('renewal_date', ts('Date Renewal Entered'), FALSE, array('formatType' => 'activityDate')); if (CRM_Core_Permission::access('CiviContribute') && !$this->_mode) { $this->addElement('checkbox', 'record_contribution', ts('Record Renewal Payment?'), NULL, array('onclick' => "checkPayment();")); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate')); $this->add('text', 'num_terms', ts('Extend Membership by'), array('onchange' => "setPaymentBlock();"), TRUE); $this->addRule('num_terms', ts('Please enter a whole number for how many periods to renew.'), 'integer'); $this->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);")); $this->add('text', 'trxn_id', ts('Transaction ID')); $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id')); $this->add('select', 'contribution_status_id', ts('Payment Status'), CRM_Contribute_PseudoConstant::contributionStatus()); $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number')); } else { $this->add('text', 'total_amount', ts('Amount')); $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money'); } $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showHideByValue( 'send_receipt', '', 'notice', 'table-row', 'radio', false ); showHideByValue( 'send_receipt', '', 'fromEmail', 'table-row', 'radio',false);")); $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails); $this->add('textarea', 'receipt_text_renewal', ts('Renewal Message')); if ($this->_mode) { $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE); CRM_Core_Payment_Form::buildCreditCard($this, TRUE); } // Retrieve the name and email of the contact - this will be the TO for receipt email list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $this->assign('email', $this->_contributorEmail); $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend'); $this->assign('outBound_option', $mailingInfo['outBound_option']); if (CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id')) { if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) { $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}")); } } $this->addFormRule(array('CRM_Member_Form_MembershipRenewal', 'formRule')); if ($this->_context != 'standalone') { //CRM-10223 - allow contribution to be recorded against different contact // causes a conflict in standalone mode so skip in standalone for now $this->addElement('checkbox', 'contribution_contact', ts('Record Payment from a Different Contact?')); $this->add('select', 'honor_type_id', ts('Membership payment is : '), array('' => ts('-')) + CRM_Core_PseudoConstant::honor()); require_once 'CRM/Contact/Form/NewContact.php'; CRM_Contact_Form_NewContact::buildQuickForm($this, 1, null, false, 'contribution_'); } }
/** * Function to send email receipt. * * @form object of Contribution form. * @param array $params (reference ) an assoc array of name/value pairs. * @$ccContribution boolen, is it credit card contribution. * @access public. * @return None. */ function emailReceipt(&$form, &$params, $ccContribution = false) { $this->assign('receiptType', 'contribution'); // Retrieve Contribution Type Name from contribution_type_id $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $params['contribution_type_id']); if (CRM_Utils_Array::value('payment_instrument_id', $params)) { require_once 'CRM/Contribute/PseudoConstant.php'; $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']]; } // retrieve individual prefix value for honoree if (CRM_Utils_Array::value('hidden_Honoree', $params)) { $individualPrefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $params['honor_prefix'] = CRM_Utils_Array::value($params['honor_prefix_id'], $individualPrefix); $params["honor_type"] = CRM_Utils_Array::value($params["honor_type_id"], $honor); } // retrieve premium product name and assigned fulfilled // date to template if (CRM_Utils_Array::value('hidden_Premium', $params)) { if (CRM_Utils_Array::value($params['product_name'][0], $form->_options)) { $params['product_option'] = $form->_options[$params['product_name'][0]][$params['product_name'][1]]; } //fix for crm-4584 if (!empty($params['product_name'])) { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $params['product_name'][0]; $productDAO->find(true); $params['product_name'] = $productDAO->name; $params['product_sku'] = $productDAO->sku; } $this->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date'])); } $this->assign('ccContribution', $ccContribution); if ($ccContribution) { //build the name. $name = CRM_Utils_Array::value('billing_first_name', $params); if (CRM_Utils_Array::value('billing_middle_name', $params)) { $name .= " {$params['billing_middle_name']}"; } $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params); $name = trim($name); $this->assign('billingName', $name); //assign the address formatted up for display $addressParts = array("street_address" => "billing_street_address-{$form->_bltID}", "city" => "billing_city-{$form->_bltID}", "postal_code" => "billing_postal_code-{$form->_bltID}", "state_province" => "state_province-{$form->_bltID}", "country" => "country-{$form->_bltID}"); $addressFields = array(); foreach ($addressParts as $name => $field) { $addressFields[$name] = CRM_Utils_Array::value($field, $params); } require_once 'CRM/Utils/Address.php'; $this->assign('address', CRM_Utils_Address::format($addressFields)); $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params)); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number'])); } else { //offline contribution //Retrieve the name and email from receipt is to be send $params['receipt_from_name'] = $form->userDisplayName; $params['receipt_from_email'] = $form->userEmail; // assigned various dates to the templates $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date'])); $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date'])); if (CRM_Utils_Array::value('thankyou_date', $params)) { $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date'])); } if ($form->_action & CRM_Core_Action::UPDATE) { $form->assign('lineItem', empty($form->_lineItems) ? false : $form->_lineItems); } } //handle custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0)); if ($form->_mode == 'test') { $contribParams[] = array('contribution_test', '=', 1, 0, 0); } //retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; $customGroup = array(); foreach ($form->_groupTree as $groupID => $group) { $customFields = $customValues = array(); if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } //build the array of customgroup contain customfields. CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $contribParams); $customGroup[$group['title']] = $customValues; } //assign all custom group and corresponding fields to template. $form->assign('customGroup', $customGroup); } $form->assign_by_ref('formValues', $params); require_once 'CRM/Contact/BAO/Contact/Location.php'; require_once 'CRM/Utils/Mail.php'; list($contributorDisplayName, $contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); $this->assign('contactID', $params['contact_id']); $this->assign('contributionID', $params['contribution_id']); $this->assign('currency', $params['currency']); $this->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date'])); $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $params['contact_id'], 'from' => "{$userName} <{$userEmail}>", 'toName' => $contributorDisplayName, 'toEmail' => $contributorEmail, 'isTest' => $form->_mode == 'test')); return $sendReceipt; }
/** * Function to add the honor block * * @return None * @access public */ function buildHonorBlock() { $this->assign('honor_block_is_active', TRUE); $this->set('honor_block_is_active', TRUE); $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values)); $this->assign('honor_block_text', CRM_Utils_Array::value('honor_block_text', $this->_values)); $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact'); $extraOption = array('onclick' => "enableHonorType();"); // radio button for Honor Type $honorOptions = array(); $honor = CRM_Core_PseudoConstant::honor(); foreach ($honor as $key => $var) { $honorTypes[$key] = $this->createElement('radio', NULL, NULL, $var, $key, $extraOption); } $this->addGroup($honorTypes, 'honor_type_id', NULL); // prefix $this->addElement('select', 'honor_prefix_id', ts('Prefix'), array('' => ts('- prefix -')) + CRM_Core_PseudoConstant::individualPrefix()); // first_name $this->addElement('text', 'honor_first_name', ts('First Name'), $attributes['first_name']); //last_name $this->addElement('text', 'honor_last_name', ts('Last Name'), $attributes['last_name']); //email $this->addElement('text', 'honor_email', ts('Email Address')); $this->addRule('honor_email', ts('Honoree Email is not valid.'), 'email'); }
/** * Create the Honor contact * * @return void * @access public */ function createHonorContact() { $params = $this->controller->exportValues('Main'); // email is enough to create a contact if (!CRM_Utils_Array::value('honor_email', $params) && (!CRM_Utils_Array::value('honor_first_name', $params) || !CRM_Utils_Array::value('honor_last_name', $params))) { //don't create contact - possibly the form was left blank return null; } //assign to template for email receipt $honor_block_is_active = $this->get('honor_block_is_active'); $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(); $honorType = CRM_Core_PseudoConstant::honor(); $this->assign('honor_type', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $params), $honorType)); $this->assign('honor_prefix', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_prefix_id', $params), $prefix)); $this->assign('honor_first_name', CRM_Utils_Array::value('honor_first_name', $params)); $this->assign('honor_last_name', CRM_Utils_Array::value('honor_last_name', $params)); $this->assign('honor_email', CRM_Utils_Array::value('honor_email', $params)); //create honoree contact return CRM_Contribute_BAO_Contribution::createHonorContact($params); }
function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; //set defaults for pledge payment. if ($this->_ppID) { $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']); $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues); $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues); $defaults['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_pledgeValues); } $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_mode) { $billingFields = array(); foreach ($this->_fields as $name => $dontCare) { if (strpos($name, 'billing_') === 0) { $name = $idName = substr($name, 8); if (in_array($name, array("state_province_id-{$this->_bltID}", "country_id-{$this->_bltID}"))) { $name = str_replace('_id', '', $name); } $billingFields[$name] = "billing_" . $idName; } $fields[$name] = 1; } require_once "CRM/Core/BAO/UFGroup.php"; if ($this->_contactID) { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults); } foreach ($billingFields as $name => $billingName) { $defaults[$billingName] = $defaults[$name]; } } if ($this->_id) { $this->_contactID = $defaults['contact_id']; } else { list($defaults['receive_date']) = CRM_Utils_Date::setDateDefaults(); } require_once 'CRM/Utils/Money.php'; // fix the display of the monetary value, CRM-4038 if (isset($defaults['total_amount'])) { $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], null, '%a'); } if (isset($defaults['non_deductible_amount'])) { $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], null, '%a'); } if (isset($defaults['fee_amount'])) { $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], null, '%a'); } if (isset($defaults['net_amount'])) { $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], null, '%a'); } if ($this->_contributionType) { $defaults['contribution_type_id'] = $this->_contributionType; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign("is_test", true); } if (isset($defaults["honor_contact_id"])) { $honorDefault = array(); $ids = array(); $this->_honorID = $defaults["honor_contact_id"]; $honorType = CRM_Core_PseudoConstant::honor(); $idParams = array('id' => $defaults["honor_contact_id"], 'contact_id' => $defaults["honor_contact_id"]); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $defaults["honor_prefix_id"] = $honorDefault["prefix_id"]; $defaults["honor_first_name"] = CRM_Utils_Array::value("first_name", $honorDefault); $defaults["honor_last_name"] = CRM_Utils_Array::value("last_name", $honorDefault); $defaults["honor_email"] = CRM_Utils_Array::value("email", $honorDefault["location"][1]["email"][1]); $defaults["honor_type"] = $honorType[$defaults["honor_type_id"]]; } $this->assign('showOption', true); // for Premium section if ($this->_premiumID) { $this->assign('showOption', false); $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : ""; if (!$options) { $this->assign('showOption', true); } $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options); if ($options_key) { $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key)); } else { $defaults['product_name'] = array($this->_productDAO->product_id); } list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date); } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } if (CRM_Utils_Array::value('is_pay_later', $defaults)) { $this->assign('is_pay_later', true); } $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults)); $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date'); foreach ($dates as $key) { if (CRM_Utils_Array::value($key, $defaults)) { list($defaults[$key]) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults)); } } $this->assign('receive_date', CRM_Utils_Array::value('receive_date', $defaults)); $this->assign('currency', CRM_Utils_Array::value('currency', $defaults)); $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults)); return $defaults; }
function setDefaultValues() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::setDefaultValues($this); } $defaults = $this->_values; //set defaults for pledge payment. if ($this->_ppID) { $defaults['total_amount'] = CRM_Utils_Array::value('scheduled_amount', $this->_pledgeValues['pledgePayment']); $defaults['honor_type_id'] = CRM_Utils_Array::value('honor_type_id', $this->_pledgeValues); $defaults['honor_contact_id'] = CRM_Utils_Array::value('honor_contact_id', $this->_pledgeValues); $defaults['contribution_type_id'] = CRM_Utils_Array::value('contribution_type_id', $this->_pledgeValues); $defaults['currency'] = CRM_Utils_Array::value('currency', $this->_pledgeValues); $defaults['option_type'] = 1; } $fields = array(); if ($this->_action & CRM_Core_Action::DELETE) { return $defaults; } if ($this->_mode) { $billingFields = array(); foreach ($this->_fields as $name => $dontCare) { if (strpos($name, 'billing_') === 0) { $name = $idName = substr($name, 8); if (in_array($name, array("state_province_id-{$this->_bltID}", "country_id-{$this->_bltID}"))) { $name = str_replace('_id', '', $name); } $billingFields[$name] = 'billing_' . $idName; } $fields[$name] = 1; } if ($this->_contactID) { CRM_Core_BAO_UFGroup::setProfileDefaults($this->_contactID, $fields, $defaults); } foreach ($billingFields as $name => $billingName) { $defaults[$billingName] = CRM_Utils_Array::value($name, $defaults); } $config = CRM_Core_Config::singleton(); // set default country from config if no country set if (!CRM_Utils_Array::value("billing_country_id-{$this->_bltID}", $defaults)) { $defaults["billing_country_id-{$this->_bltID}"] = $config->defaultContactCountry; } // now fix all state country selectors CRM_Core_BAO_Address::fixAllStateSelects($this, $defaults); // // hack to simplify credit card entry for testing // $defaults['credit_card_type'] = 'Visa'; // $defaults['total_amount'] = 50; // $defaults['credit_card_number'] = '4807731747657838'; // $defaults['cvv2'] = '000'; // $defaults['credit_card_exp_date'] = array( 'Y' => '2012', 'M' => '05' ); } if ($this->_id) { $this->_contactID = $defaults['contact_id']; } // fix the display of the monetary value, CRM-4038 if (isset($defaults['total_amount'])) { $defaults['total_amount'] = CRM_Utils_Money::format($defaults['total_amount'], NULL, '%a'); } if (isset($defaults['non_deductible_amount'])) { $defaults['non_deductible_amount'] = CRM_Utils_Money::format($defaults['non_deductible_amount'], NULL, '%a'); } if (isset($defaults['fee_amount'])) { $defaults['fee_amount'] = CRM_Utils_Money::format($defaults['fee_amount'], NULL, '%a'); } if (isset($defaults['net_amount'])) { $defaults['net_amount'] = CRM_Utils_Money::format($defaults['net_amount'], NULL, '%a'); } if ($this->_contributionType) { $defaults['contribution_type_id'] = $this->_contributionType; } if (CRM_Utils_Array::value('is_test', $defaults)) { $this->assign('is_test', TRUE); } if (isset($defaults['honor_contact_id'])) { $honorDefault = $ids = array(); $this->_honorID = $defaults['honor_contact_id']; $honorType = CRM_Core_PseudoConstant::honor(); $idParams = array('id' => $defaults['honor_contact_id'], 'contact_id' => $defaults['honor_contact_id']); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $ids); $defaults['honor_prefix_id'] = CRM_Utils_Array::value('prefix_id', $honorDefault); $defaults['honor_first_name'] = CRM_Utils_Array::value('first_name', $honorDefault); $defaults['honor_last_name'] = CRM_Utils_Array::value('last_name', $honorDefault); $defaults['honor_email'] = CRM_Utils_Array::value('email', $honorDefault['email'][1]); $defaults['honor_type'] = $honorType[$defaults['honor_type_id']]; } $this->assign('showOption', TRUE); // for Premium section if ($this->_premiumID) { $this->assign('showOption', FALSE); $options = isset($this->_options[$this->_productDAO->product_id]) ? $this->_options[$this->_productDAO->product_id] : ""; if (!$options) { $this->assign('showOption', TRUE); } $options_key = CRM_Utils_Array::key($this->_productDAO->product_option, $options); if ($options_key) { $defaults['product_name'] = array($this->_productDAO->product_id, trim($options_key)); } else { $defaults['product_name'] = array($this->_productDAO->product_id); } if ($this->_productDAO->fulfilled_date) { list($defaults['fulfilled_date']) = CRM_Utils_Date::setDateDefaults($this->_productDAO->fulfilled_date); } } if (isset($this->userEmail)) { $this->assign('email', $this->userEmail); } if (CRM_Utils_Array::value('is_pay_later', $defaults)) { $this->assign('is_pay_later', TRUE); } $this->assign('contribution_status_id', CRM_Utils_Array::value('contribution_status_id', $defaults)); $dates = array('receive_date', 'receipt_date', 'cancel_date', 'thankyou_date'); foreach ($dates as $key) { if (CRM_Utils_Array::value($key, $defaults)) { list($defaults[$key], $defaults[$key . '_time']) = CRM_Utils_Date::setDateDefaults(CRM_Utils_Array::value($key, $defaults), 'activityDateTime'); } } if (!$this->_id && !CRM_Utils_Array::value('receive_date', $defaults)) { list($defaults['receive_date'], $defaults['receive_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); } $this->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $defaults), CRM_Utils_Array::value('receive_date_time', $defaults))); $this->assign('currency', CRM_Utils_Array::value('currency', $defaults)); $this->assign('totalAmount', CRM_Utils_Array::value('total_amount', $defaults)); //inherit campaign from pledge. if ($this->_ppID && CRM_Utils_Array::value('campaign_id', $this->_pledgeValues)) { $defaults['campaign_id'] = $this->_pledgeValues['campaign_id']; } return $defaults; }
/** * Function to send Acknowledgment and create activity. * * @param object $form form object. * @param array $params (reference ) an assoc array of name/value pairs. * @access public * @return None. */ function sendAcknowledgment(&$form, $params) { //handle Acknowledgment. $allPayments = $payments = array(); //get All Payments status types. require_once 'CRM/Contribute/PseudoConstant.php'; $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'); $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id'); //get all paymnets details. CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_Payment', 'pledge_id', $params['id'], $allPayments, $returnProperties); if (!empty($allPayments)) { foreach ($allPayments as $payID => $values) { $contributionValue = $contributionStatus = array(); if (isset($values['contribution_id'])) { $contributionParams = array('id' => $values['contribution_id']); $returnProperties = array('contribution_status_id', 'receive_date'); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties); $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus)); } $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values))); //get the first valid payment id. if (!$form->paymentId && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) { $form->paymentId = $values['id']; } } } //end //assign pledge fields value to template. $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount'); foreach ($pledgeFields as $field) { if (CRM_Utils_Array::value($field, $params)) { $form->assign($field, $params[$field]); } } //assign all payments details. if ($payments) { $form->assign('payments', $payments); } //assign honor fields. $honor_block_is_active = false; //make sure we have values for it if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) { $honor_block_is_active = true; require_once "CRM/Core/PseudoConstant.php"; $prefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $form->assign("honor_type", $honor[$params["honor_type_id"]]); $form->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]); $form->assign("honor_first_name", $params["honor_first_name"]); $form->assign("honor_last_name", $params["honor_last_name"]); $form->assign("honor_email", $params["honor_email"]); } $form->assign('honor_block_is_active', $honor_block_is_active); //handle domain token values require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens()); require_once 'CRM/Utils/Token.php'; $domainValues = array(); foreach ($tokens['domain'] as $token) { $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); } $form->assign('domain', $domainValues); //handle contact token values. require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Mailing/BAO/Mailing.php'; $ids = array($params['contact_id']); $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id')); foreach ($fields as $key => $val) { $returnProperties[$val] = true; } $details = CRM_Mailing_BAO_Mailing::getDetails($ids, $returnProperties); $form->assign('contact', $details[0][$params['contact_id']]); //handle custom data. if (CRM_Utils_Array::value('hidden_custom', $params)) { require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']); $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0)); $customGroup = array(); // retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; foreach ($groupTree as $groupID => $group) { $customFields = $customValues = array(); if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } //to build array of customgroup & customfields in it CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $pledgeParams); $customGroup[$group['title']] = $customValues; } $form->assign('customGroup', $customGroup); } //handle acknowledgment email stuff. require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Contact/BAO/Contact/Location.php'; list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); //check for online pledge. $session = CRM_Core_Session::singleton(); if (CRM_Utils_Array::value('receipt_from_email', $params)) { $userName = CRM_Utils_Array::value('receipt_from_name', $params); $userEmail = CRM_Utils_Array::value('receipt_from_email', $params); } else { if ($userID = $session->get('userID')) { //check for loged in user. list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); } else { //set the domain values. $userName = CRM_Utils_Array::value('name', $domainValues); $userEmail = CRM_Utils_Array::value('email', $domainValues); } } $receiptFrom = "{$userName} <{$userEmail}>"; require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail)); //check if activity record exist for this pledge //Acknowledgment, if exist do not add activity. require_once "CRM/Activity/DAO/Activity.php"; $activityType = 'Pledge Acknowledgment'; $activity = new CRM_Activity_DAO_Activity(); $activity->source_record_id = $params['id']; $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'); $config = CRM_Core_Config::singleton(); $money = $config->defaultCurrencySymbol; $details = 'Total Amount ' . $money . $params['total_pledge_amount'] . ' To be paid in ' . $params['installments'] . ' installments of ' . $money . $params['scheduled_amount'] . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)'; if (!$activity->find()) { $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details); require_once 'api/v2/Activity.php'; if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity for acknowledgment"); } } }
/** * 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) { require_once 'CRM/Contribute/BAO/Premium.php'; CRM_Contribute_BAO_Premium::buildPremiumBlock($this, $this->_id, false, $productID, $option); } $this->assign('lineItem', $this->_lineItem); $this->assign('priceSetID', $this->_priceSetId); $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)); require_once "CRM/Core/PseudoConstant.php"; $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"]); } //pcp elements if ($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]); } } } 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); $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(); require_once "CRM/Core/BAO/CustomGroup.php"; $removeCustomFieldTypes = array('Contribution'); foreach ($this->_fields as $name => $dontCare) { $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]; } } else { if (in_array($name, array('addressee', 'email_greeting', 'postal_greeting')) && CRM_Utils_Array::value($name . '_custom', $contact)) { $defaults[$name . '_custom'] = $contact[$name . '_custom']; } } } } $this->_submitValues = array_merge($this->_submitValues, $defaults); $this->setDefaults($defaults); require_once 'CRM/Friend/BAO/Friend.php'; $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']}&page=pcp"; $tellAFriend = true; } } else { if (CRM_Utils_Array::value('is_active', $data)) { $friendText = $data['title']; $this->assign('friendText', $friendText); $subUrl = "eid={$this->_id}&page=contribution"; $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 }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $id = $this->get('id'); $values = $ids = array(); $params = array('id' => $id); require_once 'CRM/Contribute/BAO/Contribution.php'; CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); $softParams = array('contribution_id' => $values['contribution_id']); if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, true)) { $values = array_merge($values, $softContribution); } CRM_Contribute_BAO_Contribution::resolveDefaults($values); if (CRM_Utils_Array::value('honor_contact_id', $values)) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1"; $params = array(1 => array($values['honor_contact_id'], 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values["honor_display"] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::honor(); $values['honor_type'] = $honor[$values['honor_type_id']]; } if (CRM_Utils_Array::value('contribution_recur_id', $values)) { $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; $params = array(1 => array($values['contribution_recur_id'], 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $values["recur_installments"] = $dao->installments; $values["recur_frequency_unit"] = $dao->frequency_unit; $values["recur_frequency_interval"] = $dao->frequency_interval; } } $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, $values['contribution_type_id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $premiumId = null; if ($id) { require_once 'CRM/Contribute/DAO/ContributionProduct.php'; $dao =& new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $id; if ($dao->find(true)) { $premiumId = $dao->id; $productID = $dao->product_id; } } if ($premiumId) { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO =& new CRM_Contribute_DAO_Product(); $productDAO->id = $productID; $productDAO->find(true); $this->assign('premium', $productDAO->name); $this->assign('option', $dao->product_option); $this->assign('fulfilled', $dao->fulfilled_date); } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution'); $values['note'] = array_values($noteValue); // show billing address location details, if exists if (CRM_Utils_Array::value('address_id', $values)) { $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, false, 'id'); $addressDetails = array_values($addressDetails); $values['billing_address'] = $addressDetails[0]['display']; } //get soft credit record if exists. if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) { $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name'); //hack to avoid dispalyName conflict //for viewing softcredit record. $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name'); $values = array_merge($values, $softContribution); } require_once 'CRM/Price/BAO/Set.php'; $lineItems = array(); if ($id && CRM_Price_BAO_Set::getFor('civicrm_contribution', $id)) { require_once 'CRM/Price/BAO/LineItem.php'; $lineItems[] = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution'); } $this->assign('lineItem', empty($lineItems) ? false : $lineItems); $values['totalAmount'] = $values['total_amount']; // assign values to the template $this->assign($values); // add viewed contribution to recent items list require_once 'CRM/Utils/Recent.php'; require_once 'CRM/Utils/Money.php'; require_once 'CRM/Contact/BAO/Contact.php'; $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}"); $title = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name') . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')'; CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], null); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { $id = $this->get('id'); $values = $ids = array(); $params = array('id' => $id); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $context); CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); $softParams = array('contribution_id' => $values['contribution_id']); if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams, TRUE)) { $values = array_merge($values, $softContribution); } CRM_Contribute_BAO_Contribution::resolveDefaults($values); if (CRM_Utils_Array::value('contribution_page_id', $values)) { $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE); $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages); } if (CRM_Utils_Array::value('honor_contact_id', $values)) { $sql = "SELECT display_name FROM civicrm_contact WHERE id = %1"; $params = array(1 => array($values['honor_contact_id'], 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$values['honor_contact_id']}"); $values['honor_display'] = "<A href = {$url}>" . $dao->display_name . "</A>"; } $honor = CRM_Core_PseudoConstant::honor(); $values['honor_type'] = CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $values), $honor); } if (CRM_Utils_Array::value('contribution_recur_id', $values)) { $sql = "SELECT installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1"; $params = array(1 => array($values['contribution_recur_id'], 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if ($dao->fetch()) { $values['recur_installments'] = $dao->installments; $values['recur_frequency_unit'] = $dao->frequency_unit; $values['recur_frequency_interval'] = $dao->frequency_interval; } } $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, $values['contribution_type_id']); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $premiumId = NULL; if ($id) { $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $id; if ($dao->find(TRUE)) { $premiumId = $dao->id; $productID = $dao->product_id; } } if ($premiumId) { $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $productID; $productDAO->find(TRUE); $this->assign('premium', $productDAO->name); $this->assign('option', $dao->product_option); $this->assign('fulfilled', $dao->fulfilled_date); } // Get Note $noteValue = CRM_Core_BAO_Note::getNote($values['id'], 'civicrm_contribution'); $values['note'] = array_values($noteValue); // show billing address location details, if exists if (CRM_Utils_Array::value('address_id', $values)) { $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values)); $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id'); $addressDetails = array_values($addressDetails); $values['billing_address'] = $addressDetails[0]['display']; } //get soft credit record if exists. if ($softContribution = CRM_Contribute_BAO_Contribution::getSoftContribution($softParams)) { $softContribution['softCreditToName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softContribution['soft_credit_to'], 'display_name'); //hack to avoid dispalyName conflict //for viewing softcredit record. $softContribution['displayName'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name'); $values = array_merge($values, $softContribution); } $lineItems = array(); if ($id) { $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1); empty($lineItem) ? null : ($lineItems[] = $lineItem); } $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems); $values['totalAmount'] = $values['total_amount']; //do check for campaigns if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } // assign values to the template $this->assign($values); // add viewed contribution to recent items list $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['contact_id'], 'display_name'); $this->assign('displayName', $displayName); $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['contribution_type'] . ')'; $recentOther = array(); if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) { $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"); } CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther); }
/** * 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(); }
/** * Apply variables for message to smarty template - this function is part of analysing what is in the huge * function & breaking it down into manageable chunks. Eventually it will be refactored into something else * Note we send directly from this function in some cases because it is only partly refactored * Don't call this function directly as the signature will change */ function _assignMessageVariablesToTemplate(&$values, $input, &$template, $recur = FALSE, $returnMessageText = True) { $template->assign('first_name', $this->_relatedObjects['contact']->first_name); $template->assign('last_name', $this->_relatedObjects['contact']->last_name); $template->assign('displayName', $this->_relatedObjects['contact']->display_name); if (!empty($values['lineItem']) && !empty($this->_relatedObjects['membership'])) { $template->assign('useForMember', true); } //assign honor infomation to receiptmessage $honorID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->id, 'honor_contact_id'); if (!empty($honorID)) { $honorDefault = $honorIds = array(); $honorIds['contribution'] = $this->id; $idParams = array('id' => $honorID, 'contact_id' => $honorID); CRM_Contact_BAO_Contact::retrieve($idParams, $honorDefault, $honorIds); $honorType = CRM_Core_PseudoConstant::honor(); $template->assign('honor_block_is_active', 1); if (CRM_Utils_Array::value('prefix_id', $honorDefault)) { $prefix = CRM_Core_PseudoConstant::individualPrefix(); $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[$this->honor_type_id]); } $dao = new CRM_Contribute_DAO_ContributionProduct(); $dao->contribution_id = $this->id; if ($dao->find(TRUE)) { $premiumId = $dao->product_id; $template->assign('option', $dao->product_option); $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 (strtolower($this->_component) == 'contribute') { $template->assign('title', CRM_Utils_Array::value('title', $values)); $amount = CRM_Utils_Array::value('total_amount', $input, CRM_Utils_Array::value('amount', $input), null); if (empty($amount) && isset($this->total_amount)) { $amount = $this->total_amount; } $template->assign('amount', $amount); //PCP Info $softDAO = new CRM_Contribute_DAO_ContributionSoft(); $softDAO->contribution_id = $this->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 $pcpDAO = new CRM_PCP_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']); } if ($this->contribution_type_id) { $values['contribution_type_id'] = $this->contribution_type_id; } $template->assign('trxn_id', $this->trxn_id); $template->assign('receive_date', CRM_Utils_Date::mysqlToIso($this->receive_date)); $template->assign('contributeMode', 'notify'); $template->assign('action', $this->is_test ? 1024 : 1); $template->assign('receipt_text', CRM_Utils_Array::value('receipt_text', $values)); $template->assign('is_monetary', 1); $template->assign('is_recur', (bool) $recur); $template->assign('currency', $this->currency); $template->assign('address', CRM_Utils_Address::format($input)); if ($this->_component == 'event') { $participantRoles = CRM_Event_PseudoConstant::participantRole(); $viewRoles = array(); foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_relatedObjects['participant']->role_id) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $values['event']['participant_role'] = implode(', ', $viewRoles); $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 ($this->_relatedObjects['participant']->is_test) { $isTest = TRUE; } $values['params'] = array(); //to get email of primary participant. $primaryEmail = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Email', $this->_relatedObjects['participant']->contact_id, 'email', 'contact_id'); $primaryAmount[] = array('label' => $this->_relatedObjects['participant']->fee_level . ' - ' . $primaryEmail, 'amount' => $this->_relatedObjects['participant']->fee_amount); //build an array of cId/pId of participants $additionalIDs = CRM_Event_BAO_Event::buildCustomProfile($this->_relatedObjects['participant']->id, NULL, $this->_relatedObjects['contact']->id, $isTest, TRUE); unset($additionalIDs[$this->_relatedObjects['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 = $this->_relatedObjects['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) { $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($this->_relatedObjects['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); $template->assign('register_date', CRM_Utils_Date::isoToMysql($this->_relatedObjects['participant']->register_date)); if ($this->payment_instrument_id) { $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $template->assign('paidBy', $paymentInstrument[$this->payment_instrument_id]); } // carry paylater, since we did not created billing, // so need to pull email from primary location, CRM-4395 $values['params']['is_pay_later'] = $this->_relatedObjects['participant']->is_pay_later; } return $template; }