public function preProcess()
 {
     $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id');
     $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId);
     $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id');
     if ($this->_contributionId) {
         $this->_isPaidEvent = TRUE;
     }
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, TRUE);
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
     $this->assign('displayName', $this->_contributorDisplayName);
     $this->assign('email', $this->_contributorEmail);
     $this->_participantStatus = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'status_id');
     //set the payment mode - _mode property is defined in parent class
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('contactId', $this->_contactId);
     $this->assign('id', $this->_participantId);
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event');
     $this->_paidAmount = $paymentInfo['paid'];
     $this->assign('paymentInfo', $paymentInfo);
     CRM_Core_Resources::singleton()->addSetting(array('feePaid' => $this->_paidAmount));
     $title = "Change selections for {$this->_contributorDisplayName}";
     if ($title) {
         CRM_Utils_System::setTitle(ts('%1', array(1 => $title)));
     }
 }
Beispiel #2
0
 function run()
 {
     require_once 'CRM/Utils/Request.php';
     $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
     $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject);
     $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
     $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject);
     $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject);
     if (!$contact_id || !$subscribe_id || !$hash) {
         CRM_Core_Error::fatal(ts("Missing input parameters"));
     }
     require_once 'CRM/Mailing/Event/BAO/Confirm.php';
     $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id);
     if ($result === false) {
         $this->assign('success', $result);
     } else {
         $this->assign('success', true);
         // $this->assign( 'group'  , $result );
     }
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
     $this->assign('display_name', $displayName);
     $this->assign('email', $email);
     $this->assign('petition_id', $petition_id);
     $this->assign('survey_id', $petition_id);
     // send thank you email
     require_once 'CRM/Campaign/Form/Petition/Signature.php';
     $params['contactId'] = $contact_id;
     $params['email-Primary'] = $email;
     $params['sid'] = $petition_id;
     $params['activityId'] = $activity_id;
     CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK);
     parent::run();
 }
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     // get the primary city, state and zip for the contact
     $ids = array($this->_contactId);
     $locations = CRM_Contact_BAO_Contact_Location::getMapInfo($ids);
     $rows =& CRM_Utils_Sunlight::getInfo($locations[0]['city'], $locations[0]['state'], $locations[0]['postal_code']);
     $this->assign('rowCount', count($rows));
     $this->assign_by_ref('rows', $rows);
 }
 /**
  * Confirm a pending subscription
  *
  * @param int $contact_id       The id of the contact
  * @param int $subscribe_id     The id of the subscription event
  * @param string $hash          The hash
  *
  * @return boolean              True on success
  * @access public
  * @static
  */
 public static function confirm($contact_id, $subscribe_id, $hash)
 {
     $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
     if (!$se) {
         return FALSE;
     }
     // before we proceed lets just check if this contact is already 'Added'
     // if so, we should ignore this request and hence avoid sending multiple
     // emails - CRM-11157
     $details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
     if ($details && $details->status == 'Added') {
         // This contact is already subscribed
         // lets return the group title
         return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
     }
     $transaction = new CRM_Core_Transaction();
     $ce = new CRM_Mailing_Event_BAO_Confirm();
     $ce->event_subscribe_id = $se->id;
     $ce->time_stamp = date('YmdHis');
     $ce->save();
     CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
     $transaction->commit();
     $config = CRM_Core_Config::singleton();
     $domain = CRM_Core_BAO_Domain::getDomain();
     list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
     list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
     $group = new CRM_Contact_DAO_Group();
     $group->id = $se->group_id;
     $group->find(TRUE);
     $component = new CRM_Mailing_BAO_Component();
     $component->is_default = 1;
     $component->is_active = 1;
     $component->component_type = 'Welcome';
     $component->find(TRUE);
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $html = $component->body_html;
     if ($component->body_text) {
         $text = $component->body_text;
     } else {
         $text = CRM_Utils_String::htmlToText($component->body_html);
     }
     $bao = new CRM_Mailing_BAO_Mailing();
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
     $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
     $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
     $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
     $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
     $mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
     // send - ignore errors because the desired status change has already been successful
     $unused_result = CRM_Utils_Mail::send($mailParams);
     return $group->title;
 }
 /**
  * @param $self
  */
 public static function commonBuildQuickForm($self)
 {
     $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self);
     if (!$contactId) {
         $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
     }
     $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
     $activityTypes = $urls = array();
     $emailTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name');
     $letterTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name');
     $SMSId = CRM_Core_OptionGroup::getValue('activity_type', 'Text Message (SMS)', 'label');
     if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
         list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
         if (!$doNotEmail && $email && !$isDeseased) {
             $activityTypes = array($emailTypeId => ts('Send an Email'));
         }
     }
     if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) {
         // Check for existence of a mobile phone and ! do not SMS privacy setting
         $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
         list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
         if (!$doNotSMS && $phone) {
             $sendSMS = array($SMSId => ts('Send SMS'));
             $activityTypes += $sendSMS;
         }
     }
     // this returns activity types sorted by weight
     $otherTypes = CRM_Core_PseudoConstant::activityType(FALSE);
     $activityTypes += $otherTypes;
     foreach (array_keys($activityTypes) as $typeId) {
         if ($typeId == $emailTypeId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } elseif ($typeId == $SMSId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } elseif ($typeId == $letterTypeId) {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         } else {
             $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add', "{$urlParams}{$typeId}", FALSE, NULL, FALSE);
         }
     }
     $self->assign('activityTypes', $activityTypes);
     $self->assign('urls', $urls);
     $self->assign('suppressForm', TRUE);
 }
 public function preProcess()
 {
     $this->_participantId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $this->_eventId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_participantId, 'event_id');
     $this->_fromEmails = CRM_Event_BAO_Event::getFromEmailIds($this->_eventId);
     $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id');
     if (!$this->_contributionId) {
         if ($primaryParticipantId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'registered_by_id')) {
             $this->_contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_ParticipantPayment', $primaryParticipantId, 'contribution_id', 'participant_id');
         }
     }
     if ($this->_contributionId) {
         $this->_isPaidEvent = TRUE;
     }
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, TRUE);
     list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactId);
     $this->assign('displayName', $this->_contributorDisplayName);
     $this->assign('email', $this->_contributorEmail);
     $this->_participantStatus = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $this->_participantId, 'status_id');
     //set the payment mode - _mode property is defined in parent class
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('contactId', $this->_contactId);
     $this->assign('id', $this->_participantId);
     $paymentInfo = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_participantId, 'event');
     $this->_paidAmount = $paymentInfo['paid'];
     $this->assign('paymentInfo', $paymentInfo);
     $this->assign('feePaid', $this->_paidAmount);
     $ids = CRM_Event_BAO_Participant::getParticipantIds($this->_contributionId);
     if (count($ids) > 1) {
         $total = 0;
         foreach ($ids as $val) {
             $total += CRM_Price_BAO_LineItem::getLineTotal($val, 'civicrm_participant');
         }
         $this->assign('totalLineTotal', $total);
         $lineItemTotal = CRM_Price_BAO_LineItem::getLineTotal($this->_participantId, 'civicrm_participant');
         $this->assign('lineItemTotal', $lineItemTotal);
     }
     $title = "Change selections for {$this->_contributorDisplayName}";
     if ($title) {
         CRM_Utils_System::setTitle(ts('%1', array(1 => $title)));
     }
 }
 function run()
 {
     $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
     $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject);
     $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
     if (!$contact_id || !$subscribe_id || !$hash) {
         CRM_Core_Error::fatal(ts("Missing input parameters"));
     }
     $result = CRM_Mailing_Event_BAO_Confirm::confirm($contact_id, $subscribe_id, $hash);
     if ($result === FALSE) {
         $this->assign('success', $result);
     } else {
         $this->assign('success', TRUE);
         $this->assign('group', $result);
     }
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
     $this->assign('display_name', $displayName);
     $this->assign('email', $email);
     return parent::run();
 }
Beispiel #8
0
 /**
  * @return string
  * @throws Exception
  */
 public function run()
 {
     CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
     $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
     $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject);
     $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
     $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject);
     $petition_id = CRM_Utils_Request::retrieve('pid', 'String', CRM_Core_DAO::$_nullObject);
     if (!$petition_id) {
         $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject);
     }
     if (!$contact_id || !$subscribe_id || !$hash) {
         CRM_Core_Error::fatal(ts("Missing input parameters"));
     }
     $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id);
     if ($result === FALSE) {
         $this->assign('success', $result);
     } else {
         $this->assign('success', TRUE);
         // $this->assign( 'group'  , $result );
     }
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
     $this->assign('display_name', $displayName);
     $this->assign('email', $email);
     $this->assign('petition_id', $petition_id);
     $this->assign('survey_id', $petition_id);
     $pparams['id'] = $petition_id;
     $this->petition = array();
     CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition);
     $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
     $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition));
     $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition));
     CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition));
     // send thank you email
     $params['contactId'] = $contact_id;
     $params['email-Primary'] = $email;
     $params['sid'] = $petition_id;
     $params['activityId'] = $activity_id;
     CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK);
     return parent::run();
 }
Beispiel #9
0
 function run()
 {
     require_once 'CRM/Utils/Request.php';
     $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject);
     $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject);
     $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject);
     if (!$contact_id || !$subscribe_id || !$hash) {
         CRM_Core_Error::fatal(ts("Missing input parameters"));
     }
     require_once 'CRM/Mailing/Event/BAO/Confirm.php';
     $result = CRM_Mailing_Event_BAO_Confirm::confirm($contact_id, $subscribe_id, $hash);
     if ($result === false) {
         $this->assign('success', $result);
     } else {
         $this->assign('success', true);
         $this->assign('group', $result);
     }
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id);
     $this->assign('display_name', $displayName);
     $this->assign('email', $email);
     parent::run();
 }
Beispiel #10
0
 /**
  * Send notfication email to supporter
  * 1. when their PCP status is changed by site admin.
  * 2. when supporter initially creates a Personal Campaign Page ($isInitial set to true).
  *
  * @param int $pcpId
  *   Campaign page id.
  * @param int $newStatus
  *   Pcp status id.
  * @param bool|int $isInitial is it the first time, campaign page has been created by the user
  *
  * @param string $component
  *
  * @throws Exception
  * @return null
  */
 public static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute')
 {
     $pcpStatusName = CRM_Core_OptionGroup::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
     $pcpStatus = CRM_Core_OptionGroup::values("pcp_status");
     $config = CRM_Core_Config::singleton();
     if (!isset($pcpStatus[$newStatus])) {
         return FALSE;
     }
     require_once 'Mail/mime.php';
     //set loginUrl
     $loginURL = $config->userSystem->getLoginURL();
     // used in subject templates
     $contribPageTitle = self::getPcpPageTitle($pcpId, $component);
     $tplParams = array('loginUrl' => $loginURL, 'contribPageTitle' => $contribPageTitle, 'pcpId' => $pcpId);
     //get the default domain email address.
     list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
     if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') {
         $fixUrl = CRM_Utils_System::url("civicrm/admin/domain", 'action=update&reset=1');
         CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in <a href="%1">Administer CiviCRM &raquo; Communications &raquo; FROM Email Addresses</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl)));
     }
     $receiptFrom = '"' . $domainEmailName . '" <' . $domainEmailAddress . '>';
     // get recipient (supporter) name and email
     $params = array('id' => $pcpId);
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
     list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($pcpInfo['contact_id']);
     // get pcp block info
     list($blockId, $eid) = self::getPcpBlockEntityId($pcpId, $component);
     $params = array('id' => $blockId);
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock', $params, $pcpBlockInfo);
     // assign urls required in email template
     if ($pcpStatusName[$newStatus] == 'Approved') {
         $tplParams['isTellFriendEnabled'] = $pcpBlockInfo['is_tellfriend_enabled'];
         if ($pcpBlockInfo['is_tellfriend_enabled']) {
             $pcpTellFriendURL = CRM_Utils_System::url('civicrm/friend', "reset=1&eid={$pcpId}&blockId={$blockId}&pcomponent=pcp", TRUE, NULL, FALSE, TRUE);
             $tplParams['pcpTellFriendURL'] = $pcpTellFriendURL;
         }
     }
     $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$pcpId}", TRUE, NULL, FALSE, TRUE);
     $tplParams['pcpInfoURL'] = $pcpInfoURL;
     $tplParams['contribPageTitle'] = $contribPageTitle;
     if ($emails = CRM_Utils_Array::value('notify_email', $pcpBlockInfo)) {
         $emailArray = explode(',', $emails);
         $tplParams['pcpNotifyEmailAddress'] = $emailArray[0];
     }
     // get appropriate message based on status
     $tplParams['pcpStatus'] = $pcpStatus[$newStatus];
     $tplName = $isInitial ? 'pcp_supporter_notify' : 'pcp_status_change';
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => $tplName, 'contactId' => $pcpInfo['contact_id'], 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $name, 'toEmail' => $address));
     return $sent;
 }
Beispiel #11
0
 /**
  * Send email receipt.
  *
  * @param CRM_Core_Form $form
  *   Form object.
  * @param array $formValues
  * @param object $membership
  *   Object.
  *
  * @return bool
  *   true if mail was sent successfully
  */
 public static function emailReceipt(&$form, &$formValues, &$membership)
 {
     // retrieve 'from email id' for acknowledgement
     $receiptFrom = $formValues['from_email_address'];
     if (!empty($formValues['payment_instrument_id'])) {
         $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
         $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']];
     }
     // retrieve custom data
     $customFields = $customValues = array();
     if (property_exists($form, '_groupTree') && !empty($form->_groupTree)) {
         foreach ($form->_groupTree as $groupID => $group) {
             if ($groupID == 'info') {
                 continue;
             }
             foreach ($group['fields'] as $k => $field) {
                 $field['title'] = $field['label'];
                 $customFields["custom_{$k}"] = $field;
             }
         }
     }
     $members = array(array('member_id', '=', $membership->id, 0, 0));
     // check whether its a test drive
     if ($form->_mode == 'test') {
         $members[] = array('member_test', '=', 1, 0, 0);
     }
     CRM_Core_BAO_UFGroup::getValues($formValues['contact_id'], $customFields, $customValues, FALSE, $members);
     if ($form->_mode) {
         if (!empty($form->_params['billing_first_name'])) {
             $name = $form->_params['billing_first_name'];
         }
         if (!empty($form->_params['billing_middle_name'])) {
             $name .= " {$form->_params['billing_middle_name']}";
         }
         if (!empty($form->_params['billing_last_name'])) {
             $name .= " {$form->_params['billing_last_name']}";
         }
         $form->assign('billingName', $name);
         // assign the address formatted up for display
         $addressParts = array("street_address-{$form->_bltID}", "city-{$form->_bltID}", "postal_code-{$form->_bltID}", "state_province-{$form->_bltID}", "country-{$form->_bltID}");
         $addressFields = array();
         foreach ($addressParts as $part) {
             list($n, $id) = explode('-', $part);
             if (isset($form->_params['billing_' . $part])) {
                 $addressFields[$n] = $form->_params['billing_' . $part];
             }
         }
         $form->assign('address', CRM_Utils_Address::format($addressFields));
         $date = CRM_Utils_Date::format($form->_params['credit_card_exp_date']);
         $date = CRM_Utils_Date::mysqlToIso($date);
         $form->assign('credit_card_exp_date', $date);
         $form->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($form->_params['credit_card_number']));
         $form->assign('credit_card_type', $form->_params['credit_card_type']);
         $form->assign('contributeMode', 'direct');
         $form->assign('isAmountzero', 0);
         $form->assign('is_pay_later', 0);
         $form->assign('isPrimary', 1);
     }
     $form->assign('module', 'Membership');
     $form->assign('contactID', $formValues['contact_id']);
     $form->assign('membershipID', CRM_Utils_Array::value('membership_id', $form->_params, CRM_Utils_Array::value('membership_id', $form->_defaultValues)));
     if (!empty($formValues['contribution_id'])) {
         $form->assign('contributionID', $formValues['contribution_id']);
     } elseif (isset($form->_onlinePendingContributionId)) {
         $form->assign('contributionID', $form->_onlinePendingContributionId);
     }
     if (!empty($formValues['contribution_status_id'])) {
         $form->assign('contributionStatusID', $formValues['contribution_status_id']);
         $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name'));
     }
     if (!empty($formValues['is_renew'])) {
         $form->assign('receiptType', 'membership renewal');
     } else {
         $form->assign('receiptType', 'membership signup');
     }
     $form->assign('receive_date', CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $formValues)));
     $form->assign('formValues', $formValues);
     if (empty($lineItem)) {
         $form->assign('mem_start_date', CRM_Utils_Date::customFormat($membership->start_date, '%B %E%f, %Y'));
         if (!CRM_Utils_System::isNull($membership->end_date)) {
             $form->assign('mem_end_date', CRM_Utils_Date::customFormat($membership->end_date, '%B %E%f, %Y'));
         }
         $form->assign('membership_name', CRM_Member_PseudoConstant::membershipType($membership->membership_type_id));
     }
     $form->assign('customValues', $customValues);
     $isBatchProcess = is_a($form, 'CRM_Batch_Form_Entry');
     if (empty($form->_contributorDisplayName) || empty($form->_contributorEmail) || $isBatchProcess) {
         // in this case the form is being called statically from the batch editing screen
         // having one class in the form layer call another statically is not greate
         // & we should aim to move this function to the BAO layer in future.
         // however, we can assume that the contact_id passed in by the batch
         // function will be the recipient
         list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($formValues['contact_id']);
         if (empty($form->_receiptContactId) || $isBatchProcess) {
             $form->_receiptContactId = $formValues['contact_id'];
         }
     }
     $template = CRM_Core_Smarty::singleton();
     $taxAmt = $template->get_template_vars('dataArray');
     $eventTaxAmt = $template->get_template_vars('totalTaxAmount');
     $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
     if ((!empty($taxAmt) || isset($eventTaxAmt)) && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
         $isEmailPdf = TRUE;
     } else {
         $isEmailPdf = FALSE;
     }
     list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $form->_receiptContactId, 'from' => $receiptFrom, 'toName' => $form->_contributorDisplayName, 'toEmail' => $form->_contributorEmail, 'PDFFilename' => ts('receipt') . '.pdf', 'isEmailPdf' => $isEmailPdf, 'contributionId' => $formValues['contribution_id'], 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW)));
     return TRUE;
 }
 /**
  * Build the form object.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = TRUE;
         }
     }
     if ($form->_isPaidEvent) {
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         CRM_Event_Form_Registration::initEventFee($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
         $lineItem = array();
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
             foreach ($form->_values['line_items'] as $key => $value) {
                 $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
             }
         }
         if ($invoicing) {
             $form->assign('totalTaxAmount', $totalTaxAmount);
         }
         $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $value = current($value);
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, FALSE, array('class' => "crm-select2"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if ($form->_mode) {
             CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE);
         } elseif (!$form->_mode) {
             $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
             $form->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
             $form->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
             $form->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);"));
             // don't show transaction id in batch update mode
             $path = CRM_Utils_System::currentPath();
             $form->assign('showTransactionId', FALSE);
             if ($path != 'civicrm/contact/search/basic') {
                 $form->add('text', 'trxn_id', ts('Transaction ID'));
                 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                 $form->assign('showTransactionId', TRUE);
             }
             $status = CRM_Contribute_PseudoConstant::contributionStatus();
             // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('Cancelled', 'Failed', 'In Progress', 'Overdue', 'Refunded', 'Pending refund') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', 'contribution_status_id', ts('Payment Status'), $status);
             $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             $form->add('text', 'total_amount', ts('Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount'));
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign('paid', $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactId) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', TRUE);
         }
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
     $form->assign('hasPayment', $form->_paymentId);
 }
Beispiel #13
0
 /**
  * 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.
     $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_PledgePayment', '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 (!isset($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', 'currency');
     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;
         $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
         $honor = CRM_Core_PseudoConstant::get('CRM_Pledge_DAO_Pledge', 'honor_type_id');
         $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
     $domain = CRM_Core_BAO_Domain::getDomain();
     $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
     $domainValues = array();
     foreach ($tokens['domain'] as $token) {
         $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
     }
     $form->assign('domain', $domainValues);
     //handle contact token values.
     $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_Utils_Token::getTokenDetails($ids, $returnProperties, TRUE, TRUE, NULL, $tokens, get_class($form));
     $form->assign('contact', $details[0][$params['contact_id']]);
     //handle custom data.
     if (CRM_Utils_Array::value('hidden_custom', $params)) {
         $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
         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.
     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);
     } elseif (CRM_Utils_Array::value('from_email_id', $params)) {
         $receiptFrom = $params['from_email_id'];
     } elseif ($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);
     }
     if (!isset($receiptFrom)) {
         $receiptFrom = "{$userName} <{$userEmail}>";
     }
     list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::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.
     $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();
     $details = 'Total Amount ' . CRM_Utils_Money::format($params['total_pledge_amount'], CRM_Utils_Array::value('currency', $params)) . ' To be paid in ' . $params['installments'] . ' installments of ' . CRM_Utils_Money::format($params['scheduled_amount'], CRM_Utils_Array::value('currency', $params)) . ' 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, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $params));
         //lets insert assignee record.
         if (CRM_Utils_Array::value('contact_id', $params)) {
             $activityParams['assignee_contact_id'] = $params['contact_id'];
         }
         if (is_a(CRM_Activity_BAO_Activity::create($activityParams), 'CRM_Core_Error')) {
             CRM_Core_Error::fatal("Failed creating Activity for acknowledgment");
         }
     }
 }
Beispiel #14
0
 /**
  * Process that send e-mails
  *
  * @return void
  * @access public
  */
 static function sendMail($contactID, &$values, $participantId, $isTest = false, $returnMessageText = false)
 {
     require_once 'CRM/Core/BAO/UFGroup.php';
     $template = CRM_Core_Smarty::singleton();
     $gIds = array('custom_pre_id' => $values['custom_pre_id'], 'custom_post_id' => $values['custom_post_id']);
     //get the params submitted by participant.
     $participantParams = CRM_Utils_Array::value($participantId, $values['params'], array());
     if (!$returnMessageText) {
         //send notification email if field values are set (CRM-1941)
         foreach ($gIds as $key => $gId) {
             if ($gId) {
                 $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
                 if ($email) {
                     //get values of corresponding profile fields for notification
                     list($profileValues) = self::buildCustomDisplay($gId, null, $contactID, $template, $participantId, $isTest, true, $participantParams);
                     $val = array('id' => $gId, 'values' => $profileValues, 'email' => $email);
                     CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
                 }
             }
         }
     }
     if ($values['event']['is_email_confirm'] || $returnMessageText) {
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         //use primary email address, since we are not creating billing address for
         //1. participant is pay later.
         //2. participant might be additional participant.
         //3. participant might be on waiting list.
         //4. registration might require approval.
         if (CRM_Utils_Array::value('is_pay_later', $values['params']) || CRM_Utils_Array::value('additionalParticipant', $values['params']) || CRM_Utils_Array::value('isOnWaitlist', $values['params']) || CRM_Utils_Array::value('isRequireApproval', $values['params']) || !CRM_Utils_Array::value('is_monetary', $values['event'])) {
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         } else {
             // get the billing location type
             $locationTypes =& CRM_Core_PseudoConstant::locationType();
             $bltID = array_search('Billing', $locationTypes);
             list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, false, $bltID);
         }
         //send email only when email is present
         if (isset($email) || $returnMessageText) {
             $preProfileID = $values['custom_pre_id'];
             $postProfileID = $values['custom_post_id'];
             if (CRM_Utils_Array::value('additionalParticipant', $values['params'])) {
                 $preProfileID = $values['additional_custom_pre_id'];
                 $postProfileID = $values['additional_custom_post_id'];
             }
             self::buildCustomDisplay($preProfileID, 'customPre', $contactID, $template, $participantId, $isTest, null, $participantParams);
             self::buildCustomDisplay($postProfileID, 'customPost', $contactID, $template, $participantId, $isTest, null, $participantParams);
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_online_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => array('email' => $email, 'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event'])), 'PDFFilename' => 'civicrm.pdf');
             // address required during receipt processing (pdf and email receipt)
             if ($displayAddress = CRM_Utils_Array::value('address', $values)) {
                 $sendTemplateParams['tplParams']['address'] = $displayAddress;
                 $sendTemplateParams['tplParams']['contributeMode'] = null;
             }
             // set lineItem details
             if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) {
                 $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
             }
             require_once 'CRM/Core/BAO/MessageTemplates.php';
             if ($returnMessageText) {
                 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
                 return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
             } else {
                 $sendTemplateParams['from'] = "{$values['event']['confirm_from_name']} <{$values['event']['confirm_from_email']}>";
                 $sendTemplateParams['toName'] = $displayName;
                 $sendTemplateParams['toEmail'] = $email;
                 $sendTemplateParams['autoSubmitted'] = true;
                 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', $values['event']);
                 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', $values['event']);
                 CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
             }
         }
     }
 }
 /**
  * Process credit card payment.
  *
  * @param array $submittedValues
  * @param array $lineItem
  *
  * @throws CRM_Core_Exception
  */
 protected function processCreditCard($submittedValues, $lineItem)
 {
     $sendReceipt = $contribution = FALSE;
     $unsetParams = array('trxn_id', 'payment_instrument_id', 'contribution_status_id', 'cancel_date', 'cancel_reason');
     foreach ($unsetParams as $key) {
         if (isset($submittedValues[$key])) {
             unset($submittedValues[$key]);
         }
     }
     $isTest = $this->_mode == 'test' ? 1 : 0;
     // CRM-12680 set $_lineItem if its not set
     if (empty($this->_lineItem) && !empty($lineItem)) {
         $this->_lineItem = $lineItem;
     }
     //Get the require fields value only.
     $params = $this->_params = $submittedValues;
     $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
     // Get the payment processor id as per mode.
     $this->_params['payment_processor'] = $params['payment_processor_id'] = $this->_params['payment_processor_id'] = $submittedValues['payment_processor_id'] = $this->_paymentProcessor['id'];
     $now = date('YmdHis');
     $fields = array();
     // we need to retrieve email address
     if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     // Set email for primary location.
     $fields['email-Primary'] = 1;
     $params['email-Primary'] = $this->userEmail;
     // now set the values for the billing location.
     foreach (array_keys($this->_fields) as $name) {
         $fields[$name] = 1;
     }
     // also add location name to the array
     $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
     $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
     $fields["address_name-{$this->_bltID}"] = 1;
     $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
     $nameFields = array('first_name', 'middle_name', 'last_name');
     foreach ($nameFields as $name) {
         $fields[$name] = 1;
         if (array_key_exists("billing_{$name}", $params)) {
             $params[$name] = $params["billing_{$name}"];
             $params['preserveDBName'] = TRUE;
         }
     }
     if (!empty($params['source'])) {
         unset($params['source']);
     }
     $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, NULL, NULL, $ctype);
     // add all the additional payment params we need
     if (!empty($this->_params["billing_state_province_id-{$this->_bltID}"])) {
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
     }
     if (!empty($this->_params["billing_country_id-{$this->_bltID}"])) {
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
     }
     $legacyCreditCardExpiryCheck = FALSE;
     if ($this->_paymentProcessor['payment_type'] & CRM_Core_Payment::PAYMENT_TYPE_CREDIT_CARD && !isset($this->_paymentFields)) {
         $legacyCreditCardExpiryCheck = TRUE;
     }
     if ($legacyCreditCardExpiryCheck || in_array('credit_card_exp_date', array_keys($this->_paymentFields))) {
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
     }
     $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
     $this->_params['amount'] = $this->_params['total_amount'];
     $this->_params['amount_level'] = 0;
     $this->_params['description'] = ts('Office Credit Card contribution');
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency', $this->_params, CRM_Core_Config::singleton()->defaultCurrency);
     $this->_params['payment_action'] = 'Sale';
     if (!empty($this->_params['receive_date'])) {
         $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
     }
     if (!empty($params['soft_credit_to'])) {
         $this->_params['soft_credit_to'] = $params['soft_credit_to'];
         $this->_params['pcp_made_through_id'] = $params['pcp_made_through_id'];
     }
     $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
     $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
     $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
     //Add common data to formatted params
     CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
     if (empty($this->_params['invoice_id'])) {
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
     } else {
         $this->_params['invoiceID'] = $this->_params['invoice_id'];
     }
     // At this point we've created a contact and stored its address etc
     // all the payment processors expect the name and address to be in the
     // so we copy stuff over to first_name etc.
     $paymentParams = $this->_params;
     $paymentParams['contactID'] = $this->_contactID;
     CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
     $contributionType = new CRM_Financial_DAO_FinancialType();
     $contributionType->id = $params['financial_type_id'];
     // Add some financial type details to the params list
     // if folks need to use it.
     $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $contributionType->name;
     $paymentParams['contributionPageID'] = NULL;
     if (!empty($this->_params['is_email_receipt'])) {
         $paymentParams['email'] = $this->userEmail;
         $paymentParams['is_email_receipt'] = 1;
     } else {
         $paymentParams['is_email_receipt'] = 0;
         $this->_params['is_email_receipt'] = 0;
     }
     if (!empty($this->_params['receive_date'])) {
         $paymentParams['receive_date'] = $this->_params['receive_date'];
     }
     // For recurring contribution, create Contribution Record first.
     // Contribution ID, Recurring ID and Contact ID needed
     // When we get a callback from the payment processor, CRM-7115
     if (!empty($paymentParams['is_recur'])) {
         $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, NULL, $this->_contactID, $contributionType, TRUE, FALSE, $isTest, $this->_lineItem);
         $paymentParams['contributionID'] = $contribution->id;
         $paymentParams['contributionTypeID'] = $contribution->financial_type_id;
         $paymentParams['contributionPageID'] = $contribution->contribution_page_id;
         $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
     }
     $result = array();
     if ($paymentParams['amount'] > 0.0) {
         // force a re-get of the payment processor in case the form changed it, CRM-7179
         $payment = CRM_Core_Payment::singleton($this->_mode, $this->_paymentProcessor, $this, TRUE);
         try {
             $result = $payment->doPayment($paymentParams, 'contribute');
         } catch (CRM_Core_Exception $e) {
             $message = ts("Payment Processor Error message") . $e->getMessage();
             $this->cleanupDBAfterPaymentFailure($paymentParams, $message);
             // Set the contribution mode.
             $urlParams = "action=add&cid={$this->_contactID}";
             if ($this->_mode) {
                 $urlParams .= "&mode={$this->_mode}";
             }
             if (!empty($this->_ppID)) {
                 $urlParams .= "&context=pledge&ppid={$this->_ppID}";
             }
             CRM_Core_Error::statusBounce($message, $urlParams, ts('Payment Processor Error'));
         }
     }
     $this->_params = array_merge($this->_params, $result);
     $this->_params['receive_date'] = $now;
     if (!empty($this->_params['is_email_receipt'])) {
         $this->_params['receipt_date'] = $now;
     } else {
         $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'], $params['receipt_date_time'], TRUE);
     }
     $this->set('params', $this->_params);
     $this->assign('trxn_id', $result['trxn_id']);
     $this->assign('receive_date', $this->_params['receive_date']);
     // Result has all the stuff we need
     // lets archive it to a financial transaction
     if ($contributionType->is_deductible) {
         $this->assign('is_deductible', TRUE);
         $this->set('is_deductible', TRUE);
     }
     // Set source if not set
     if (empty($this->_params['source'])) {
         $userID = CRM_Core_Session::singleton()->get('userID');
         $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'sort_name');
         $this->_params['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
     }
     // Build custom data getFields array
     $customFieldsContributionType = CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, CRM_Utils_Array::value('financial_type_id', $params));
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsContributionType, CRM_Core_BAO_CustomField::getFields('Contribution', FALSE, FALSE, NULL, NULL, TRUE));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Contribution');
     if (empty($paymentParams['is_recur'])) {
         $contribution = CRM_Contribute_Form_Contribution_Confirm::processContribution($this, $this->_params, $result, $this->_contactID, $contributionType, FALSE, FALSE, $isTest, $this->_lineItem);
     }
     // Send receipt mail.
     if ($contribution->id && !empty($this->_params['is_email_receipt'])) {
         $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
         $this->_params['contact_id'] = $this->_contactID;
         $this->_params['contribution_id'] = $contribution->id;
         $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE);
     }
     //process the note
     if ($contribution->id && isset($params['note'])) {
         CRM_Contribute_Form_AdditionalInfo::processNote($params, $contactID, $contribution->id, NULL);
     }
     //process premium
     if ($contribution->id && isset($params['product_name'][0])) {
         CRM_Contribute_Form_AdditionalInfo::processPremium($params, $contribution->id, NULL, $this->_options);
     }
     //update pledge payment status.
     if ($this->_ppID && $contribution->id) {
         // Store contribution id in payment record.
         CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_ppID, 'contribution_id', $contribution->id);
         CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($this->_pledgeID, array($this->_ppID), $contribution->contribution_status_id, NULL, $contribution->total_amount);
     }
     if ($contribution->id) {
         $statusMsg = ts('The contribution record has been processed.');
         if (!empty($this->_params['is_email_receipt']) && $sendReceipt) {
             $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.');
         }
         CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
     }
 }
 /**
  * Common block for setting up the parts of a form that relate to credit / debit card
  * @throws Exception
  */
 protected function assignPaymentRelatedVariables()
 {
     try {
         if ($this->_contactID) {
             list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
             $this->assign('displayName', $this->userDisplayName);
         }
         if ($this->_mode) {
             $this->assignProcessors();
             $this->assignBillingType();
             $this->_fields = array();
             CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor, FALSE, TRUE);
         }
     } catch (CRM_Core_Exception $e) {
         CRM_Core_Error::fatal($e->getMessage());
     }
 }
 /**
  * Set variables up before form is built based on participant ID from URL
  *
  * @return void
  */
 public function preProcess()
 {
     $config = CRM_Core_Config::singleton();
     $session = CRM_Core_Session::singleton();
     $this->_userContext = $session->readUserContext();
     $participant = $values = array();
     $this->_participant_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $params = array('id' => $this->_participant_id);
     $this->_participant = CRM_Event_BAO_Participant::getValues($params, $values, $participant);
     $this->_part_values = $values[$this->_participant_id];
     $this->set('values', $this->_part_values);
     //fetch Event by event_id, verify that this event can still be xferred/cancelled
     $this->_event_id = $this->_part_values['event_id'];
     $url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
     $this->_contact_id = $this->_part_values['participant_contact_id'];
     $this->assign('action', $this->_action);
     if ($this->_participant_id) {
         $this->assign('participantId', $this->_participant_id);
     }
     $event = array();
     $daoName = 'title';
     $this->_event_title = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     $daoName = 'start_date';
     $this->_event_start_date = CRM_Event_BAO_Event::getFieldValue('CRM_Event_DAO_Event', $this->_event_id, $daoName);
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contact_id);
     $this->_contact_name = $displayName;
     $this->_contact_email = $email;
     $details = array();
     $details = CRM_Event_BAO_Participant::participantDetails($this->_participant_id);
     $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'participant_role', 'id', 'name');
     $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participant_id, 'contribution_id', 'participant_id');
     $this->assign('contributionId', $contributionId);
     $query = "\n      SELECT cpst.name as status, cov.name as role, cp.fee_level, cp.fee_amount, cp.register_date, cp.status_id\n      FROM civicrm_participant cp\n      LEFT JOIN civicrm_participant_status_type cpst ON cpst.id = cp.status_id\n      LEFT JOIN civicrm_option_value cov ON cov.value = cp.role_id and cov.option_group_id = {$optionGroupId}\n      WHERE cp.id = {$this->_participant_id}";
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     while ($dao->fetch()) {
         $details['status'] = $dao->status;
         $details['role'] = $dao->role;
         $details['fee_level'] = $dao->fee_level;
         $details['fee_amount'] = $dao->fee_amount;
         $details['register_date'] = $dao->register_date;
     }
     //verify participant status is still Registered
     if ($details['status'] != "Registered") {
         $status = "You are no longer registered for " . $this->_event_title;
         CRM_Core_Session::setStatus($status, ts('Event status error.'), 'alert');
         CRM_Utils_System::redirect($url);
     }
     $query = "select start_date as start, selfcancelxfer_time as time from civicrm_event where id = " . $this->_event_id;
     $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     while ($dao->fetch()) {
         $time_limit = $dao->time;
         $start_date = $dao->start;
     }
     $start_time = new Datetime($start_date);
     $timenow = new Datetime();
     if (!empty($start_time) && $start_time < $timenow) {
         $status = ts("The event has been started, cannot transfer or cancel this event");
         $session->setStatus($status, ts('Oops.'), 'alert');
         CRM_Utils_System::redirect($url);
     }
     if (!empty($time_limit) && $time_limit > 0) {
         $interval = $timenow->diff($start_time);
         $days = $interval->format('%d');
         $hours = $interval->format('%h');
         if ($hours <= $time_limit && $days < 1) {
             $status = ts("Less than %1 hours to start time, cannot transfer or cancel this event", array(1 => $time_limit));
             $session->setStatus($status, ts('Oops.'), 'alert');
             CRM_Utils_System::redirect($url);
         }
     }
     $this->assign('details', $details);
     $this->selfsvcupdateUrl = CRM_Utils_System::url('civicrm/event/selfsvcupdate', "reset=1&id={$this->_participant_id}&id=0");
     $this->selfsvcupdateText = ts('Update');
     $this->selfsvcupdateButtonText = ts('Update');
     // Based on those ids retrieve event and verify it is eligible
     // for self update (event.start_date > today, event can be 'self_updated'
     // retrieve contact name and email, and let user verify his/her identity
 }
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $session = CRM_Core_Session::singleton();
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $contributionParams = $requestParams = $_REQUEST;
     $contactID = $session->get('userID');
     if ($contactID && empty($contributionParams['email'])) {
         $emailDetails = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         if (!empty($emailDetails)) {
             $contributionParams['email'] = $emailDetails[1];
             // for email to be prefilled
             $this->assign('email', $emailDetails[1]);
         }
     }
     $pageConfig = civicrm_api3('ContributionPage', 'getsingle', array('id' => $this->_id));
     if (is_array($pageConfig['payment_processor'])) {
         CRM_Core_Error::fatal(ts('Multiple payment processors not supported with quick donate.'));
     }
     $processorDetails = CRM_Financial_BAO_PaymentProcessor::getPayment($pageConfig['payment_processor'], 'live');
     //MV: get amount details if other amount enabled for contribution page.
     if ($pageConfig['amount_block_is_active']) {
         $sql = "SELECT cpfv.amount, cpfv.is_default, cpfv.weight \n        FROM civicrm_price_field_value cpfv \n        INNER JOIN civicrm_price_field cpf ON (cpf.id = cpfv.price_field_id)\n        INNER JOIN civicrm_price_set_entity cpse ON (cpse.price_set_id = cpf.price_set_id)\n        WHERE cpse.entity_id = %1 AND cpf.name = 'contribution_amount'\n      ";
         $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($pageConfig['id'], 'Integer')));
         $amount = 0;
         while ($dao->fetch()) {
             if ($dao->weight == 1 || $dao->is_default == 1) {
                 $amount = $dao->amount;
             }
         }
     }
     $pageConfig['default_amount'] = $amount ? $amount : $pageConfig['min_amount'];
     $pageConfig['currency_symbol'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $pageConfig['currency'], 'symbol', 'name');
     $this->assign('pageConfig', $pageConfig);
     $this->assign('key', $processorDetails['password']);
     $this->assign('currency', strtolower($pageConfig['currency']));
     if (!empty($requestParams['stripe_token'])) {
         //FIXME: could go in post process
         if (!$contributionParams['email']) {
             CRM_Core_Error::fatal(ts('Email address is required'));
         }
         $contributionParams['financial_type_id'] = $pageConfig['financial_type_id'];
         if (!$contactID) {
             $contactParams = array('email' => $contributionParams['email'], 'contact_type' => 'Individual');
             $dedupeParams = CRM_Dedupe_Finder::formatParams($contactParams, 'Individual');
             $dedupeParams['check_permission'] = FALSE;
             $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Individual');
             // if we find more than one contact, use the first one
             $contactID = CRM_Utils_Array::value(0, $ids);
             if (!$contactID) {
                 $cont = civicrm_api3('Contact', 'create', $contactParams);
                 $contactID = $cont['id'];
             }
         }
         $contributionParams['contact_id'] = $contactID;
         $contributionParams['payment_processor_id'] = $pageConfig['payment_processor'];
         $contributionParams['currencyID'] = $pageConfig['currency'];
         //gift aid
         //get gift aid custom field id
         $sqlCF = "SELECT cf.id \n      FROM civicrm_custom_field cf \n      INNER JOIN civicrm_custom_group cg ON (cg.id = cf.custom_group_id) \n      WHERE cg.name = %1 AND cf.name = %2";
         $sqlCFParams = array(1 => array(self::C_CUSTOM_GROUP_GIFT_AID, 'String'), 2 => array(self::C_CUSTOM_FIELD_GIFT_AID, 'String'));
         $cfId = CRM_Core_DAO::singleValueQuery($sqlCF, $sqlCFParams);
         if ($cfId && $contributionParams['donation_form']['gift_aid']) {
             $contributionParams["custom_{$cfId}"] = 1;
         }
         //gift aid end
         //campaign
         if ($pageConfig['campaign_id']) {
             $contributionParams['campaign_id'] = $pageConfig['campaign_id'];
         }
         try {
             $result = civicrm_api3('Contribution', 'transact', $contributionParams);
         } catch (CiviCRM_API3_Exception $e) {
             $error = $e->getMessage();
             $this->assign('error', $error);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         }
         if (!empty($result['error'])) {
             $this->assign('error', $result['error']);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         } else {
             if ($result) {
                 $contributionID = $result['id'];
                 $contactID = $result['values'][$contributionID]['contact_id'];
                 // Send receipt
                 civicrm_api3('contribution', 'sendconfirmation', array('id' => $contributionID) + $pageConfig);
                 CRM_Utils_System::setTitle(ts('Thank you'));
                 $this->assign('status', 'thankyou');
                 $profileID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'Supporter Profile', 'id', 'title');
                 // Link (button) for users to create their own Personal Campaign page
                 if ($profileID && !$session->get('userID')) {
                     $ufId = CRM_Core_BAO_UFMatch::getUFId($contactID);
                     if ($ufId) {
                         $config = CRM_Core_Config::singleton();
                         $loginURL = $config->userSystem->getLoginURL();
                         $this->assign('loginURL', $loginURL);
                     } else {
                         $linkTextUrl = CRM_Utils_System::url('civicrm/profile/create', "gid={$profileID}&reset=1", FALSE, NULL, TRUE);
                         $this->assign('linkTextUrl', $linkTextUrl);
                     }
                 }
                 //redirect if the logged in user
                 if ($session->get('userID')) {
                     $urlParams = array('pageId' => $this->_id, 'component' => 'contribute', 'reset' => 1);
                     $sql = "SELECT pcp.id FROM civicrm_pcp pcp \n          INNER JOIN  civicrm_pcp_block cpb ON (cpb.id = pcp.pcp_block_id)\n          WHERE cpb.entity_id = %1 AND pcp.contact_id = %2\n          ";
                     $sqlparams = array(1 => array($pageConfig['id'], 'Integer'), 2 => array($contactID, 'Integer'));
                     $pcpId = CRM_Core_DAO::singleValueQuery($sql, $sqlparams);
                     if ($pcpId) {
                         $urlParams['id'] = $pcpId;
                     }
                     $url = CRM_Utils_System::url('civicrm/pcp/setup', $urlParams);
                     CRM_Utils_System::redirect($url);
                 }
             }
         }
     } else {
         if (!empty($requestParams['_qf_Main_display'])) {
             //$this->assign('error', $error);
             CRM_Utils_System::setTitle(ts('Oops! There was a problem'));
         } else {
             $this->assign('status', 'quickdonate');
             CRM_Core_Resources::singleton()->addStyleFile('uk.co.vedaconsulting.quickdonate', 'css/quickdonatebox.css');
         }
     }
 }
Beispiel #19
0
 /**
  * Function used to send notification mail to pcp owner.
  *
  * This is used by contribution and also event PCPs.
  *
  * @param object $contribution
  * @param object $contributionSoft
  *   Contribution object.
  */
 public static function pcpNotifyOwner($contribution, $contributionSoft)
 {
     $params = array('id' => $contributionSoft->pcp_id);
     CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCP', $params, $pcpInfo);
     $ownerNotifyID = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCPBlock', $pcpInfo['pcp_block_id'], 'owner_notify_id');
     if ($ownerNotifyID != CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'no_notifications', 'name') && ($ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'owner_chooses', 'name') && CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $contributionSoft->pcp_id, 'is_notify') || $ownerNotifyID == CRM_Core_OptionGroup::getValue('pcp_owner_notify', 'all_owners', 'name'))) {
         $pcpInfoURL = CRM_Utils_System::url('civicrm/pcp/info', "reset=1&id={$contributionSoft->pcp_id}", TRUE, NULL, FALSE, TRUE);
         // set email in the template here
         if (CRM_Core_BAO_LocationType::getBilling()) {
             list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id, FALSE, CRM_Core_BAO_LocationType::getBilling());
         }
         // get primary location email if no email exist( for billing location).
         if (!$email) {
             list($donorName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contribution->contact_id);
         }
         list($ownerName, $ownerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contributionSoft->contact_id);
         $tplParams = array('page_title' => $pcpInfo['title'], 'receive_date' => $contribution->receive_date, 'total_amount' => $contributionSoft->amount, 'donors_display_name' => $donorName, 'donors_email' => $email, 'pcpInfoURL' => $pcpInfoURL, 'is_honor_roll_enabled' => $contributionSoft->pcp_display_in_roll, 'currency' => $contributionSoft->currency);
         $domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
         $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_owner_notify', 'contactId' => $contributionSoft->contact_id, 'toEmail' => $ownerEmail, 'toName' => $ownerName, 'from' => "{$domainValues['0']} <{$domainValues['1']}>", 'tplParams' => $tplParams, 'PDFFilename' => 'receipt.pdf');
         CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
     }
 }
Beispiel #20
0
 /**
  * Format fields for dupe Contact Matching.
  *
  * @param array $params
  *
  * @param int $contactId
  *
  * @return array
  *   associated formatted array
  */
 public static function formatFields($params, $contactId = NULL)
 {
     if ($contactId) {
         // get the primary location type id and email
         list($name, $primaryEmail, $primaryLocationType) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactId);
     } else {
         $defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
         $primaryLocationType = $defaultLocationType->id;
     }
     $data = array();
     $locationType = array();
     $count = 1;
     $primaryLocation = 0;
     foreach ($params as $key => $value) {
         list($fieldName, $locTypeId, $phoneTypeId) = explode('-', $key);
         if ($locTypeId == 'Primary') {
             $locTypeId = $primaryLocationType;
         }
         if (is_numeric($locTypeId)) {
             if (!in_array($locTypeId, $locationType)) {
                 $locationType[$count] = $locTypeId;
                 $count++;
             }
             $loc = CRM_Utils_Array::key($locTypeId, $locationType);
             $data['location'][$loc]['location_type_id'] = $locTypeId;
             // if we are getting in a new primary email, dont overwrite the new one
             if ($locTypeId == $primaryLocationType) {
                 if (!empty($params['email-' . $primaryLocationType])) {
                     $data['location'][$loc]['email'][$loc]['email'] = $fields['email-' . $primaryLocationType];
                 } elseif (isset($primaryEmail)) {
                     $data['location'][$loc]['email'][$loc]['email'] = $primaryEmail;
                 }
                 $primaryLocation++;
             }
             if ($loc == 1) {
                 $data['location'][$loc]['is_primary'] = 1;
             }
             if ($fieldName == 'phone') {
                 if ($phoneTypeId) {
                     $data['location'][$loc]['phone'][$loc]['phone_type_id'] = $phoneTypeId;
                 } else {
                     $data['location'][$loc]['phone'][$loc]['phone_type_id'] = '';
                 }
                 $data['location'][$loc]['phone'][$loc]['phone'] = $value;
             } elseif ($fieldName == 'email') {
                 $data['location'][$loc]['email'][$loc]['email'] = $value;
             } elseif ($fieldName == 'im') {
                 $data['location'][$loc]['im'][$loc]['name'] = $value;
             } else {
                 if ($fieldName === 'state_province') {
                     $data['location'][$loc]['address']['state_province_id'] = $value;
                 } elseif ($fieldName === 'country') {
                     $data['location'][$loc]['address']['country_id'] = $value;
                 } else {
                     $data['location'][$loc]['address'][$fieldName] = $value;
                 }
             }
         } else {
             // TODO: prefix, suffix and gender translation may no longer be necessary - check inputs
             if ($key === 'individual_suffix') {
                 $data['suffix_id'] = $value;
             } elseif ($key === 'individual_prefix') {
                 $data['prefix_id'] = $value;
             } elseif ($key === 'gender') {
                 $data['gender_id'] = $value;
             } elseif (substr($key, 0, 6) === 'custom') {
                 if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) {
                     //fix checkbox
                     if ($customFields[$customFieldID]['html_type'] == 'CheckBox') {
                         $value = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($value));
                     }
                     // fix the date field
                     if ($customFields[$customFieldID]['data_type'] == 'Date') {
                         $date = CRM_Utils_Date::format($value);
                         if (!$date) {
                             $date = '';
                         }
                         $value = $date;
                     }
                     $data['custom'][$customFieldID] = array('id' => $id, 'value' => $value, 'extends' => $customFields[$customFieldID]['extends'], 'type' => $customFields[$customFieldID]['data_type'], 'custom_field_id' => $customFieldID);
                 }
             } elseif ($key == 'edit') {
                 continue;
             } else {
                 $data[$key] = $value;
             }
         }
     }
     if (!$primaryLocation) {
         $loc++;
         $data['location'][$loc]['email'][$loc]['email'] = $primaryEmail;
     }
     return $data;
 }
Beispiel #21
0
 /**
  * Process credit card payment.
  *
  * @param array $submittedValues
  * @param array $lineItem
  *
  * @param int $contactID
  *   Contact ID
  *
  * @return bool|\CRM_Contribute_DAO_Contribution
  * @throws \CRM_Core_Exception
  * @throws \Civi\Payment\Exception\PaymentProcessorException
  */
 protected function processCreditCard($submittedValues, $lineItem, $contactID)
 {
     $isTest = $this->_mode == 'test' ? 1 : 0;
     // CRM-12680 set $_lineItem if its not set
     // @todo - I don't believe this would ever BE set. I can't find anywhere in the code.
     // It would be better to pass line item out to functions than $this->_lineItem as
     // we don't know what is being changed where.
     if (empty($this->_lineItem) && !empty($lineItem)) {
         $this->_lineItem = $lineItem;
     }
     $this->_paymentObject = Civi\Payment\System::singleton()->getById($submittedValues['payment_processor_id']);
     $this->_paymentProcessor = $this->_paymentObject->getPaymentProcessor();
     // Set source if not set
     if (empty($submittedValues['source'])) {
         $userID = CRM_Core_Session::singleton()->get('userID');
         $userSortName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $userID, 'sort_name');
         $submittedValues['source'] = ts('Submit Credit Card Payment by: %1', array(1 => $userSortName));
     }
     $params = $submittedValues;
     $this->_params = array_merge($this->_params, $submittedValues);
     // Mapping requiring documentation.
     $this->_params['payment_processor'] = $submittedValues['payment_processor_id'];
     $now = date('YmdHis');
     // we need to retrieve email address
     if ($this->_context == 'standalone' && !empty($submittedValues['is_email_receipt'])) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     $this->_contributorEmail = $this->userEmail;
     $this->_contributorContactID = $contactID;
     $this->processBillingAddress();
     if (!empty($params['source'])) {
         unset($params['source']);
     }
     $this->_params['amount'] = $this->_params['total_amount'];
     // @todo - stop setting amount level in this function & call the CRM_Price_BAO_PriceSet::getAmountLevel
     // function to get correct amount level consistently. Remove setting of the amount level in
     // CRM_Price_BAO_PriceSet::processAmount. Extend the unit tests in CRM_Price_BAO_PriceSetTest
     // to cover all variants.
     $this->_params['amount_level'] = 0;
     $this->_params['description'] = ts("Contribution submitted by a staff person using contributor's credit card");
     $this->_params['currencyID'] = CRM_Utils_Array::value('currency', $this->_params, CRM_Core_Config::singleton()->defaultCurrency);
     if (!empty($this->_params['receive_date'])) {
         $this->_params['receive_date'] = CRM_Utils_Date::processDate($this->_params['receive_date'], $this->_params['receive_date_time']);
     }
     $this->_params['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $params);
     $this->_params['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $params);
     $this->_params['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $params);
     //Add common data to formatted params
     CRM_Contribute_Form_AdditionalInfo::postProcessCommon($params, $this->_params, $this);
     if (empty($this->_params['invoice_id'])) {
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
     } else {
         $this->_params['invoiceID'] = $this->_params['invoice_id'];
     }
     // At this point we've created a contact and stored its address etc
     // all the payment processors expect the name and address to be in the
     // so we copy stuff over to first_name etc.
     $paymentParams = $this->_params;
     $paymentParams['contactID'] = $contactID;
     CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, TRUE);
     $financialType = new CRM_Financial_DAO_FinancialType();
     $financialType->id = $params['financial_type_id'];
     $financialType->find(TRUE);
     // Add some financial type details to the params list
     // if folks need to use it.
     $paymentParams['contributionType_name'] = $this->_params['contributionType_name'] = $financialType->name;
     $paymentParams['contributionPageID'] = NULL;
     if (!empty($this->_params['is_email_receipt'])) {
         $paymentParams['email'] = $this->userEmail;
         $paymentParams['is_email_receipt'] = 1;
     } else {
         $paymentParams['is_email_receipt'] = 0;
         $this->_params['is_email_receipt'] = 0;
     }
     if (!empty($this->_params['receive_date'])) {
         $paymentParams['receive_date'] = $this->_params['receive_date'];
     }
     $this->_params['receive_date'] = $now;
     if (!empty($this->_params['is_email_receipt'])) {
         $this->_params['receipt_date'] = $now;
     } else {
         $this->_params['receipt_date'] = CRM_Utils_Date::processDate($this->_params['receipt_date'], $params['receipt_date_time'], TRUE);
     }
     $this->set('params', $this->_params);
     $this->assign('receive_date', $this->_params['receive_date']);
     // Result has all the stuff we need
     // lets archive it to a financial transaction
     if ($financialType->is_deductible) {
         $this->assign('is_deductible', TRUE);
         $this->set('is_deductible', TRUE);
     }
     $contributionParams = array('contact_id' => $contactID, 'line_item' => $lineItem, 'is_test' => $isTest, 'campaign_id' => CRM_Utils_Array::value('campaign_id', $this->_params), 'contribution_page_id' => CRM_Utils_Array::value('contribution_page_id', $this->_params), 'source' => CRM_Utils_Array::value('source', $paymentParams, CRM_Utils_Array::value('description', $paymentParams)), 'thankyou_date' => CRM_Utils_Array::value('thankyou_date', $this->_params));
     if (empty($paymentParams['is_pay_later'])) {
         // @todo look up payment_instrument_id on payment processor table.
         $contributionParams['payment_instrument_id'] = 1;
     }
     $contribution = CRM_Contribute_Form_Contribution_Confirm::processFormContribution($this, $this->_params, NULL, $contributionParams, $financialType, FALSE, $this->_bltID, CRM_Utils_Array::value('is_recur', $this->_params));
     $paymentParams['contributionID'] = $contribution->id;
     $paymentParams['contributionTypeID'] = $contribution->financial_type_id;
     $paymentParams['contributionPageID'] = $contribution->contribution_page_id;
     $paymentParams['contributionRecurID'] = $contribution->contribution_recur_id;
     if ($paymentParams['amount'] > 0.0) {
         // force a re-get of the payment processor in case the form changed it, CRM-7179
         // NOTE - I expect this is obsolete.
         $payment = Civi\Payment\System::singleton()->getByProcessor($this->_paymentProcessor);
         try {
             $statuses = CRM_Contribute_BAO_Contribution::buildOptions('contribution_status_id');
             $result = $payment->doPayment($paymentParams, 'contribute');
             $this->assign('trxn_id', $result['trxn_id']);
             $contribution->trxn_id = $result['trxn_id'];
             /* Our scenarios here are
              *  1) the payment failed & an Exception should have been thrown
              *  2) the payment succeeded but the payment is not immediate (for example a recurring payment
              *     with a delayed start)
              *  3) the payment succeeded with an immediate payment.
              *
              * The doPayment function ensures that payment_status_id is always set
              * as historically we have had to guess from the context - ie doDirectPayment
              * = error or success, unless it is a recurring contribution in which case it is pending.
              */
             if ($result['payment_status_id'] == array_search('Completed', $statuses)) {
                 try {
                     civicrm_api3('contribution', 'completetransaction', array('id' => $contribution->id, 'trxn_id' => $result['trxn_id'], 'payment_processor_id' => $this->_paymentProcessor['id'], 'is_transactional' => FALSE, 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result)));
                     // This has now been set to 1 in the DB - declare it here also
                     $contribution->contribution_status_id = 1;
                 } catch (CiviCRM_API3_Exception $e) {
                     if ($e->getErrorCode() != 'contribution_completed') {
                         throw new CRM_Core_Exception('Failed to update contribution in database');
                     }
                 }
             } else {
                 // Save the trxn_id.
                 $contribution->save();
             }
         } catch (PaymentProcessorException $e) {
             CRM_Contribute_BAO_Contribution::failPayment($contribution->id, $paymentParams['contactID'], $e->getMessage());
             throw new PaymentProcessorException($e->getMessage());
         }
     }
     // Send receipt mail.
     array_unshift($this->statusMessage, ts('The contribution record has been saved.'));
     if ($contribution->id && !empty($this->_params['is_email_receipt'])) {
         $this->_params['trxn_id'] = CRM_Utils_Array::value('trxn_id', $result);
         $this->_params['contact_id'] = $contactID;
         $this->_params['contribution_id'] = $contribution->id;
         if (CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $this->_params, TRUE)) {
             $this->statusMessage[] = ts('A receipt has been emailed to the contributor.');
         }
     }
     return $contribution;
 }
Beispiel #22
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         require_once "CRM/Event/BAO/Participant.php";
         CRM_Event_BAO_Participant::deleteParticipant($this->_participantId);
         return;
     }
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $params)) {
         $this->_contactID = CRM_Utils_Array::value('contact_select_id', $params);
     }
     $config =& CRM_Core_Config::singleton();
     //check if discount is selected
     if (CRM_Utils_Array::value('discount_id', $params)) {
         $discountId = $params['discount_id'];
     } else {
         $params['discount_id'] = 'null';
         $discountId = null;
     }
     if ($this->_isPaidEvent) {
         //lets carry currency, CRM-4453
         $params['fee_currency'] = $config->defaultCurrency;
         // fix for CRM-3088
         if ($discountId && !empty($this->_values['discount'][$discountId])) {
             $params['amount_level'] = $this->_values['discount'][$discountId][$params['amount']]['label'];
             $params['amount'] = $this->_values['discount'][$discountId][$params['amount']]['value'];
             $this->assign('amount_level', $params['amount_level']);
         } else {
             if (!isset($params['priceSetId'])) {
                 $params['amount_level'] = $this->_values['fee'][$params['amount']]['label'];
                 $params['amount'] = $this->_values['fee'][$params['amount']]['value'];
                 $this->assign('amount_level', $params['amount_level']);
             } else {
                 if (!$this->_online) {
                     $lineItem = array();
                     CRM_Price_BAO_Set::processAmount($this->_values['fee']['fields'], $params, $lineItem[0]);
                     $this->set('lineItem', $lineItem);
                     $this->assign('lineItem', $lineItem);
                     $this->_lineItem = $lineItem;
                 }
             }
         }
         $params['fee_level'] = $params['amount_level'];
         $contributionParams = array();
         $contributionParams['total_amount'] = $params['amount'];
     }
     //fix for CRM-3086
     $params['fee_amount'] = $params['amount'];
     $this->_params = $params;
     unset($params['amount']);
     $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
     $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params));
     $params['contact_id'] = $this->_contactID;
     if ($this->_participantId) {
         $params['id'] = $this->_participantId;
     }
     $status = null;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $participantBAO =& new CRM_Event_BAO_Participant();
         $participantBAO->id = $this->_participantId;
         $participantBAO->find();
         while ($participantBAO->fetch()) {
             $status = $participantBAO->status_id;
             $contributionParams['total_amount'] = $participantBAO->fee_amount;
         }
         $params['discount_id'] = null;
         //re-enter the values for UPDATE mode
         $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
         $params['fee_amount'] = $participantBAO->fee_amount;
     }
     require_once 'CRM/Contact/BAO/Contact.php';
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $session =& CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     require_once "CRM/Event/BAO/Participant.php";
     if ($this->_mode) {
         if (!$this->_isPaidEvent) {
             CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
         }
         //modify params according to parameter used in create
         //participant method (addParticipant)
         $params['participant_status_id'] = $params['status_id'];
         $params['participant_role_id'] = $params['role_id'];
         $params['participant_register_date'] = $params['register_date'];
         $params['participant_source'] = $params['source'];
         require_once 'CRM/Core/BAO/PaymentProcessor.php';
         $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
         require_once "CRM/Contact/BAO/Contact.php";
         $now = date('YmdHis');
         $fields = array();
         // set email for primary location.
         $fields["email-Primary"] = 1;
         $params["email-Primary"] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
         $params['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $params)) {
                 $params[$name] = $params["billing_{$name}"];
                 $params['preserveDBName'] = true;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactID, null, null, $ctype);
     }
     // build custom data getFields array
     $customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('role_id', $params), $this->_roleCustomDataTypeID);
     $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', false, false, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', false, false, null, null, true));
     $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_participantId, 'Participant');
     if ($this->_mode) {
         // add all the additioanl payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = $this->_params['credit_card_exp_date']['Y'];
         $this->_params['month'] = $this->_params['credit_card_exp_date']['M'];
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $params['fee_amount'];
         $this->_params['amount_level'] = $params['amount_level'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['payment_action'] = 'Sale';
         $this->_params['invoiceID'] = md5(uniqid(rand(), true));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         require_once 'CRM/Core/Payment/Form.php';
         CRM_Core_Payment_Form::mapParams($this->_bltID, $this->_params, $paymentParams, true);
         $payment =& CRM_Core_Payment::singleton($this->_mode, 'Event', $this->_paymentProcessor, $this);
         $result =& $payment->doDirectPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&cid={$this->_contactID}&context=participant&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $this->_params['receive_date'] = $now;
         if (CRM_Utils_Array::value('send_receipt', $this->_params)) {
             $this->_params['receipt_date'] = $now;
         } else {
             $this->_params['receipt_date'] = null;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::processDate($this->_params['receive_date']));
         // set source if not set
         $this->_params['description'] = ts('Submit Credit Card for Event Registration by: %1', array(1 => $userName));
         require_once 'CRM/Event/Form/Registration/Confirm.php';
         require_once 'CRM/Event/Form/Registration.php';
         //add contribution record
         $this->_params['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'contribution_type_id');
         $this->_params['mode'] = $this->_mode;
         //add contribution reocord
         $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, false);
         // add participant record
         $participants = array();
         $participants[] = CRM_Event_Form_Registration::addParticipant($this->_params, $contactID);
         //add custom data for participant
         require_once 'CRM/Core/BAO/CustomValueTable.php';
         CRM_Core_BAO_CustomValueTable::postProcess($this->_params, CRM_Core_DAO::$_nullArray, 'civicrm_participant', $participants[0]->id, 'Participant');
         //add participant payment
         require_once 'CRM/Event/BAO/ParticipantPayment.php';
         $paymentParticipant = array('participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id);
         $ids = array();
         CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
         $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         $this->_contactIds[] = $this->_contactID;
     } else {
         $participants = array();
         // fix note if deleted
         if (!$params['note']) {
             $params['note'] = 'null';
         }
         if ($this->_single) {
             $participants[] = CRM_Event_BAO_Participant::create($params);
         } else {
             foreach ($this->_contactIds as $contactID) {
                 $commonParams = $params;
                 $commonParams['contact_id'] = $contactID;
                 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
             }
         }
         if (isset($params['event_id'])) {
             $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         }
         if ($this->_single) {
             $this->_contactIds[] = $this->_contactID;
         }
         if (CRM_Utils_Array::value('record_contribution', $params)) {
             if (CRM_Utils_Array::value('id', $params)) {
                 if ($this->_onlinePendingContributionId) {
                     $ids['contribution'] = $this->_onlinePendingContributionId;
                 } else {
                     $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id');
                 }
             }
             unset($params['note']);
             //build contribution params
             if (!$this->_onlinePendingContributionId) {
                 $contributionParams['source'] = "{$eventTitle}: Offline registration (by {$userName})";
             }
             $contributionParams['currency'] = $config->defaultCurrency;
             $contributionParams['non_deductible_amount'] = 'null';
             $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $params) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
             $recordContribution = array('contact_id', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'receive_date', 'check_number');
             foreach ($recordContribution as $f) {
                 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
                 if ($f == 'trxn_id') {
                     $this->assign('trxn_id', $contributionParams[$f]);
                 }
             }
             //insert contribution type name in receipt.
             $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $contributionParams['contribution_type_id']));
             require_once 'CRM/Contribute/BAO/Contribution.php';
             $contributions = array();
             if ($this->_single) {
                 $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
             } else {
                 $ids = array();
                 foreach ($this->_contactIds as $contactID) {
                     $contributionParams['contact_id'] = $contactID;
                     $contributions[] =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
                 }
             }
             //insert payment record for this participation
             if (!$ids['contribution']) {
                 require_once 'CRM/Event/DAO/ParticipantPayment.php';
                 foreach ($this->_contactIds as $num => $contactID) {
                     $ppDAO =& new CRM_Event_DAO_ParticipantPayment();
                     $ppDAO->participant_id = $participants[$num]->id;
                     $ppDAO->contribution_id = $contributions[$num]->id;
                     $ppDAO->save();
                 }
             }
         }
     }
     // also store lineitem stuff here
     if ($this->_lineItem) {
         require_once 'CRM/Price/BAO/LineItem.php';
         foreach ($this->_contactIds as $num => $contactID) {
             foreach ($this->_lineItem as $key => $value) {
                 if (is_array($value) && $value != 'skip') {
                     foreach ($value as $line) {
                         $line['entity_table'] = 'civicrm_participant';
                         $line['entity_id'] = $participants[$num]->id;
                         CRM_Price_BAO_LineItem::create($line);
                     }
                 }
             }
         }
     }
     $updateStatusMsg = null;
     //send mail when participant status changed, CRM-4326
     if ($this->_participantId && $this->_statusId && $this->_statusId != CRM_Utils_Array::value('status_id', $params) && CRM_Utils_Array::value('is_notify', $params)) {
         require_once "CRM/Event/BAO/Participant.php";
         $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_participantId, $params['status_id'], $this->_statusId);
     }
     if (CRM_Utils_Array::value('send_receipt', $params)) {
         $receiptFrom = "{$userName} <{$userEmail}>";
         $this->assign('module', 'Event Registration');
         //use of the message template below requires variables in different format
         $event = $events = array();
         $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
         //get all event details.
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
         $event = $events[$params['event_id']];
         unset($event['start_date']);
         unset($event['end_date']);
         $role = CRM_Event_PseudoConstant::participantRole();
         $event['participant_role'] = $role[$params['role_id']];
         $event['is_monetary'] = $this->_isPaidEvent;
         if ($params['receipt_text']) {
             $event['confirm_email_text'] = $params['receipt_text'];
         }
         $this->assign('isAmountzero', 1);
         $this->assign('event', $event);
         $this->assign('isShowLocation', $event['is_show_location']);
         if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
             $locationParams = array('entity_id' => $params['event_id'], 'entity_table' => 'civicrm_event');
             require_once 'CRM/Core/BAO/Location.php';
             $location = CRM_Core_BAO_Location::getValues($locationParams, true);
             $this->assign('location', $location);
         }
         $status = CRM_Event_PseudoConstant::participantStatus();
         if ($this->_isPaidEvent) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             if (!$this->_mode) {
                 $this->assign('paidBy', CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstrument));
             }
             $this->assign('totalAmount', $contributionParams['total_amount']);
             $this->assign('isPrimary', 1);
             $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
         }
         if ($this->_mode) {
             if (CRM_Utils_Array::value('billing_first_name', $params)) {
                 $name = $params['billing_first_name'];
             }
             if (CRM_Utils_Array::value('billing_middle_name', $params)) {
                 $name .= " {$params['billing_middle_name']}";
             }
             if (CRM_Utils_Array::value('billing_last_name', $params)) {
                 $name .= " {$params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             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_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
             $this->assign('credit_card_type', $params['credit_card_type']);
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
         }
         $this->assign('register_date', $params['register_date']);
         if ($params['receive_date']) {
             $this->assign('receive_date', $params['receive_date']);
         }
         $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
         // check whether its a test drive ref CRM-3075
         if (CRM_Utils_Array::value('is_test', $this->_defaultValues)) {
             $participant[] = array('participant_test', '=', 1, 0, 0);
         }
         $template =& CRM_Core_Smarty::singleton();
         $customGroup = array();
         //format submitted data
         foreach ($params['custom'] as $fieldID => $values) {
             foreach ($values as $fieldValue) {
                 $customValue = array('data' => $fieldValue['value']);
                 $customFields[$fieldID]['id'] = $fieldID;
                 $formattedValue = CRM_Core_BAO_CustomGroup::formatCustomValues($customValue, $customFields[$fieldID]);
                 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
             }
         }
         foreach ($this->_contactIds as $num => $contactID) {
             // Retrieve the name and email of the contact - this will be the TO for receipt email
             list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
             $this->_contributorDisplayName = $this->_contributorDisplayName == ' ' ? $this->_contributorEmail : $this->_contributorDisplayName;
             $this->assign('customGroup', $customGroup);
             $this->assign('contactID', $contactID);
             $this->assign('participantID', $participants[$num]->id);
             if ($this->_isPaidEvent) {
                 // fix amount for each of participants ( for bulk mode )
                 $eventAmount = array();
                 $eventAmount[$num] = array('label' => $params['amount_level'], 'amount' => $params['fee_amount']);
                 //as we are using same template for online & offline registration.
                 //So we have to build amount as array.
                 $this->assign('amount', $eventAmount);
             }
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_offline_receipt', 'contactId' => $contactID, 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues));
             // try to send emails only if email id is present
             // and the do-not-email option is not checked for that contact
             if ($this->_contributorEmail and !$this->_toDoNotEmail) {
                 $sendTemplateParams['from'] = $receiptFrom;
                 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
                 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
             }
             require_once 'CRM/Core/BAO/MessageTemplates.php';
             list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($sendTemplateParams);
             if ($mailSent) {
                 $sent[] = $contactID;
             } else {
                 $notSent[] = $contactID;
             }
         }
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
         if ($params['send_receipt'] && count($sent)) {
             $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
         }
         if ($updateStatusMsg) {
             $statusMsg = "{$statusMsg} {$updateStatusMsg}";
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         if ($this->_single) {
             $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
             if (CRM_Utils_Array::value('send_receipt', $params) && count($sent)) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
             }
         } else {
             $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
             if (count($notSent) > 0) {
                 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
             } elseif (isset($params['send_receipt'])) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
             }
         }
     }
     require_once "CRM/Core/Session.php";
     CRM_Core_Session::setStatus("{$statusMsg}");
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=participant"));
         }
     } else {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&context=participant&cid={$this->_contactID}"));
         }
     }
 }
Beispiel #23
0
 /**
  * Extract values from the contact create boxes on the form and assign appropriately  to
  *
  *  - $this->_contributorEmail,
  *  - $this->_memberEmail &
  *  - $this->_contributionName
  *  - $this->_memberName
  *  - $this->_contactID (effectively memberContactId but changing might have spin-off effects)
  *  - $this->_contributorContactId - id of the contributor
  *  - $this->_receiptContactId
  *
  * If the member & contributor are the same then the values will be the same. But if different people paid
  * then they weill differ
  *
  * @param array $formValues
  *   values from form. The important values we are looking for are.
  *  - contact_id
  *  - soft_credit_contact_id
  */
 public function storeContactFields($formValues)
 {
     // in a 'standalone form' (contact id not in the url) the contact will be in the form values
     if (!empty($formValues['contact_id'])) {
         $this->_contactID = $formValues['contact_id'];
     }
     list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
     //CRM-10375 Where the payer differs to the member the payer should get the email.
     // here we store details in order to do that
     if (!empty($formValues['soft_credit_contact_id'])) {
         $this->_receiptContactId = $this->_contributorContactID = $formValues['soft_credit_contact_id'];
         list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contributorContactID);
     } else {
         $this->_receiptContactId = $this->_contributorContactID = $this->_contactID;
         $this->_contributorDisplayName = $this->_memberDisplayName;
         $this->_contributorEmail = $this->_memberEmail;
     }
 }
 /**
  * Process the form submission.
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
             $additionalId = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
             $participantLinks = CRM_Event_BAO_Participant::getAdditionalParticipantUrl($additionalId);
         }
         if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
             $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
             foreach ($additionalIds as $value) {
                 CRM_Event_BAO_Participant::deleteParticipant($value);
             }
         }
         CRM_Event_BAO_Participant::deleteParticipant($this->_id);
         CRM_Core_Session::setStatus(ts('Selected participant was deleted successfully.'), ts('Record Deleted'), 'success');
         if (!empty($participantLinks)) {
             $status = ts('The following participants no longer have an event fee recorded. You can edit their registration and record a replacement contribution by clicking the links below:') . '<br/>' . $participantLinks;
             CRM_Core_Session::setStatus($status, ts('Group Payment Deleted'));
         }
         return;
     }
     // When adding a single contact, the formRule prevents you from adding duplicates
     // (See above in formRule()). When adding more than one contact, the duplicates are
     // removed automatically and the user receives one notification.
     if ($this->_action & CRM_Core_Action::ADD) {
         $event_id = $this->_eventId;
         if (empty($event_id) && !empty($params['event_id'])) {
             $event_id = $params['event_id'];
         }
         if (!$this->_single && !empty($event_id)) {
             $duplicateContacts = 0;
             while (list($k, $dupeCheckContactId) = each($this->_contactIds)) {
                 // Eliminate contacts that have already been assigned to this event.
                 $dupeCheck = new CRM_Event_BAO_Participant();
                 $dupeCheck->contact_id = $dupeCheckContactId;
                 $dupeCheck->event_id = $event_id;
                 $dupeCheck->find(TRUE);
                 if (!empty($dupeCheck->id)) {
                     $duplicateContacts++;
                     unset($this->_contactIds[$k]);
                 }
             }
             if ($duplicateContacts > 0) {
                 $msg = ts("%1 contacts have already been assigned to this event. They were not added a second time.", array(1 => $duplicateContacts));
                 CRM_Core_Session::setStatus($msg);
             }
             if (count($this->_contactIds) == 0) {
                 CRM_Core_Session::setStatus(ts("No participants were added."));
                 return;
             }
             // We have to re-key $this->_contactIds so each contact has the same
             // key as their corresponding record in the $participants array that
             // will be created below.
             $this->_contactIds = array_values($this->_contactIds);
         }
     }
     $participantStatus = CRM_Event_PseudoConstant::participantStatus();
     // set the contact, when contact is selected
     if (!empty($params['contact_id'])) {
         $this->_contactId = $params['contact_id'];
     }
     if ($this->_priceSetId && ($isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'))) {
         $this->_quickConfig = $isQuickConfig;
     }
     if ($this->_id) {
         $params['id'] = $this->_id;
     }
     $config = CRM_Core_Config::singleton();
     if ($this->_isPaidEvent) {
         $contributionParams = array();
         $lineItem = array();
         $additionalParticipantDetails = array();
         if ($this->_id && $this->_action & CRM_Core_Action::UPDATE && $this->_paymentId) {
             $participantBAO = new CRM_Event_BAO_Participant();
             $participantBAO->id = $this->_id;
             $participantBAO->find(TRUE);
             $contributionParams['total_amount'] = $participantBAO->fee_amount;
             $params['discount_id'] = NULL;
             //re-enter the values for UPDATE mode
             $params['fee_level'] = $params['amount_level'] = $participantBAO->fee_level;
             $params['fee_amount'] = $participantBAO->fee_amount;
             if (isset($params['priceSetId'])) {
                 $lineItem[0] = CRM_Price_BAO_LineItem::getLineItems($this->_id);
             }
             //also add additional participant's fee level/priceset
             if (CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
                 $additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($this->_id);
                 $hasLineItems = CRM_Utils_Array::value('priceSetId', $params, FALSE);
                 $additionalParticipantDetails = CRM_Event_BAO_Participant::getFeeDetails($additionalIds, $hasLineItems);
             }
         } else {
             //check if discount is selected
             if (!empty($params['discount_id'])) {
                 $discountId = $params['discount_id'];
             } else {
                 $discountId = $params['discount_id'] = 'null';
             }
             //lets carry currency, CRM-4453
             $params['fee_currency'] = $config->defaultCurrency;
             CRM_Price_BAO_PriceSet::processAmount($this->_values['fee'], $params, $lineItem[0]);
             //CRM-11529 for quick config backoffice transactions
             //when financial_type_id is passed in form, update the
             //lineitems with the financial type selected in form
             $submittedFinancialType = CRM_Utils_Array::value('financial_type_id', $params);
             $isPaymentRecorded = CRM_Utils_Array::value('record_contribution', $params);
             if ($isPaymentRecorded && $this->_quickConfig && $submittedFinancialType) {
                 foreach ($lineItem[0] as &$values) {
                     $values['financial_type_id'] = $submittedFinancialType;
                 }
             }
             $params['fee_level'] = $params['amount_level'];
             $contributionParams['total_amount'] = $params['amount'];
             if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
                 $params['fee_amount'] = $params['total_amount'];
             } else {
                 //fix for CRM-3086
                 $params['fee_amount'] = $params['amount'];
             }
         }
         if (isset($params['priceSetId'])) {
             if (!empty($lineItem[0])) {
                 $this->set('lineItem', $lineItem);
                 $this->_lineItem = $lineItem;
                 $lineItem = array_merge($lineItem, $additionalParticipantDetails);
                 $participantCount = array();
                 foreach ($lineItem as $k) {
                     foreach ($k as $v) {
                         if (CRM_Utils_Array::value('participant_count', $v) > 0) {
                             $participantCount[] = $v['participant_count'];
                         }
                     }
                 }
             }
             if (isset($participantCount)) {
                 $this->assign('pricesetFieldsCount', $participantCount);
             }
             $this->assign('lineItem', empty($lineItem[0]) || $this->_quickConfig ? FALSE : $lineItem);
         } else {
             $this->assign('amount_level', $params['amount_level']);
         }
     }
     $this->_params = $params;
     $amountOwed = NULL;
     if (isset($params['amount'])) {
         $amountOwed = $params['amount'];
         unset($params['amount']);
     }
     $params['register_date'] = CRM_Utils_Date::processDate($params['register_date'], $params['register_date_time']);
     $params['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $params), CRM_Utils_Array::value('receive_date_time', $params));
     $params['contact_id'] = $this->_contactId;
     // overwrite actual payment amount if entered
     if (!empty($params['total_amount'])) {
         $contributionParams['total_amount'] = CRM_Utils_Array::value('total_amount', $params);
     }
     // Retrieve the name and email of the current user - this will be the FROM for the receipt email
     $session = CRM_Core_Session::singleton();
     $userID = $session->get('userID');
     list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     if ($this->_contactId) {
         list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($this->_contactId);
     }
     //modify params according to parameter used in create
     //participant method (addParticipant)
     $this->_params['participant_status_id'] = $params['status_id'];
     $this->_params['participant_role_id'] = is_array($params['role_id']) ? $params['role_id'] : explode(',', $params['role_id']);
     $this->_params['participant_register_date'] = $params['register_date'];
     $roleIdWithSeparator = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['participant_role_id']);
     if ($this->_mode) {
         if (!$this->_isPaidEvent) {
             CRM_Core_Error::fatal(ts('Selected Event is not Paid Event '));
         }
         $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         // set source if not set
         if (empty($params['source'])) {
             $this->_params['participant_source'] = ts('Offline Registration for Event: %2 by: %1', array(1 => $userName, 2 => $eventTitle));
         } else {
             $this->_params['participant_source'] = $params['source'];
         }
         $this->_params['description'] = $this->_params['participant_source'];
         $this->_paymentProcessor = CRM_Financial_BAO_PaymentProcessor::getPayment($this->_params['payment_processor_id'], $this->_mode);
         $now = date('YmdHis');
         $fields = array();
         // set email for primary location.
         $fields['email-Primary'] = 1;
         $params['email-Primary'] = $params["email-{$this->_bltID}"] = $this->_contributorEmail;
         $params['register_date'] = $now;
         // now set the values for the billing location.
         foreach ($this->_fields as $name => $dontCare) {
             $fields[$name] = 1;
         }
         // also add location name to the array
         $params["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $params) . ' ' . CRM_Utils_Array::value('billing_middle_name', $params) . ' ' . CRM_Utils_Array::value('billing_last_name', $params);
         $params["address_name-{$this->_bltID}"] = trim($params["address_name-{$this->_bltID}"]);
         $fields["address_name-{$this->_bltID}"] = 1;
         $fields["email-{$this->_bltID}"] = 1;
         $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type');
         $nameFields = array('first_name', 'middle_name', 'last_name');
         foreach ($nameFields as $name) {
             $fields[$name] = 1;
             if (array_key_exists("billing_{$name}", $params)) {
                 $params[$name] = $params["billing_{$name}"];
                 $params['preserveDBName'] = TRUE;
             }
         }
         $contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
     }
     if (!empty($this->_params['participant_role_id'])) {
         $customFieldsRole = array();
         foreach ($this->_params['participant_role_id'] as $roleKey) {
             $customFieldsRole = CRM_Utils_Array::crmArrayMerge(CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $roleKey, $this->_roleCustomDataTypeID), $customFieldsRole);
         }
         $customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, CRM_Utils_Array::value('event_id', $params), $this->_eventNameCustomDataTypeID);
         $customFieldsEventType = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $this->_eventTypeId, $this->_eventTypeCustomDataTypeID);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsRole, CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, NULL, NULL, TRUE));
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEvent, $customFields);
         $customFields = CRM_Utils_Array::crmArrayMerge($customFieldsEventType, $customFields);
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_id, 'Participant');
     }
     //do cleanup line  items if participant edit the Event Fee.
     if (($this->_lineItem || !isset($params['proceSetId'])) && !$this->_paymentId && $this->_id) {
         CRM_Price_BAO_LineItem::deleteLineItems($this->_id, 'civicrm_participant');
     }
     if ($this->_mode) {
         // add all the additional payment params we need
         $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
         $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
         $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
         $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
         $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
         $this->_params['amount'] = $params['fee_amount'];
         $this->_params['amount_level'] = $params['amount_level'];
         $this->_params['currencyID'] = $config->defaultCurrency;
         $this->_params['invoiceID'] = md5(uniqid(rand(), TRUE));
         // at this point we've created a contact and stored its address etc
         // all the payment processors expect the name and address to be in the
         // so we copy stuff over to first_name etc.
         $paymentParams = $this->_params;
         if (!empty($this->_params['send_receipt'])) {
             $paymentParams['email'] = $this->_contributorEmail;
         }
         // The only reason for merging in the 'contact_id' rather than ensuring it is set
         // is that this patch is being done around the time of the stable release
         // so more conservative approach is called for.
         // In fact the use of $params and $this->_params & $this->_contactId vs $contactID
         // needs rationalising.
         $mapParams = array_merge(array('contact_id' => $contactID), $this->_params);
         CRM_Core_Payment_Form::mapParams($this->_bltID, $mapParams, $paymentParams, TRUE);
         $payment = $this->_paymentProcessor['object'];
         // CRM-15622: fix for incorrect contribution.fee_amount
         $paymentParams['fee_amount'] = NULL;
         $result = $payment->doPayment($paymentParams);
         if (is_a($result, 'CRM_Core_Error')) {
             CRM_Core_Error::displaySessionError($result);
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&cid={$this->_contactId}&context=participant&mode={$this->_mode}"));
         }
         if ($result) {
             $this->_params = array_merge($this->_params, $result);
         }
         $this->_params['receive_date'] = $now;
         if (!empty($this->_params['send_receipt'])) {
             $this->_params['receipt_date'] = $now;
         } else {
             $this->_params['receipt_date'] = NULL;
         }
         $this->set('params', $this->_params);
         $this->assign('trxn_id', $result['trxn_id']);
         $this->assign('receive_date', CRM_Utils_Date::processDate($this->_params['receive_date']));
         //add contribution record
         $this->_params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'financial_type_id');
         $this->_params['mode'] = $this->_mode;
         //add contribution record
         $contributions[] = $contribution = CRM_Event_Form_Registration_Confirm::processContribution($this, $this->_params, $result, $contactID, FALSE);
         // add participant record
         $participants = array();
         if (!empty($this->_params['role_id']) && is_array($this->_params['role_id'])) {
             $this->_params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $this->_params['role_id']);
         }
         //CRM-15372 patch to fix fee amount replacing amount
         $this->_params['fee_amount'] = $this->_params['amount'];
         $participants[] = CRM_Event_Form_Registration::addParticipant($this, $contactID);
         //add custom data for participant
         CRM_Core_BAO_CustomValueTable::postProcess($this->_params, 'civicrm_participant', $participants[0]->id, 'Participant');
         //add participant payment
         $paymentParticipant = array('participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id);
         $ids = array();
         CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids);
         $this->_contactIds[] = $this->_contactId;
     } else {
         $participants = array();
         if ($this->_single) {
             if ($params['role_id']) {
                 $params['role_id'] = $roleIdWithSeparator;
             } else {
                 $params['role_id'] = 'NULL';
             }
             $participants[] = CRM_Event_BAO_Participant::create($params);
         } else {
             foreach ($this->_contactIds as $contactID) {
                 $commonParams = $params;
                 $commonParams['contact_id'] = $contactID;
                 if ($commonParams['role_id']) {
                     $commonParams['role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
                 } else {
                     $commonParams['role_id'] = 'NULL';
                 }
                 $participants[] = CRM_Event_BAO_Participant::create($commonParams);
             }
         }
         if (isset($params['event_id'])) {
             $eventTitle = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'title');
         }
         if ($this->_single) {
             $this->_contactIds[] = $this->_contactId;
         }
         $contributions = array();
         if (!empty($params['record_contribution'])) {
             if (!empty($params['id'])) {
                 if ($this->_onlinePendingContributionId) {
                     $ids['contribution'] = $this->_onlinePendingContributionId;
                 } else {
                     $ids['contribution'] = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $params['id'], 'contribution_id', 'participant_id');
                 }
             }
             unset($params['note']);
             //build contribution params
             if (!$this->_onlinePendingContributionId) {
                 if (empty($params['source'])) {
                     $contributionParams['source'] = ts('%1 : Offline registration (by %2)', array(1 => $eventTitle, 2 => $userName));
                 } else {
                     $contributionParams['source'] = $params['source'];
                 }
             }
             $contributionParams['currency'] = $config->defaultCurrency;
             $contributionParams['non_deductible_amount'] = 'null';
             $contributionParams['receipt_date'] = !empty($params['send_receipt']) ? CRM_Utils_Array::value('receive_date', $params) : 'null';
             $recordContribution = array('contact_id', 'financial_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'receive_date', 'check_number', 'campaign_id');
             foreach ($recordContribution as $f) {
                 $contributionParams[$f] = CRM_Utils_Array::value($f, $params);
                 if ($f == 'trxn_id') {
                     $this->assign('trxn_id', $contributionParams[$f]);
                 }
             }
             //insert financial type name in receipt.
             $this->assign('contributionTypeName', CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialType', $contributionParams['financial_type_id']));
             $contributionParams['skipLineItem'] = 1;
             if ($this->_id) {
                 $contributionParams['contribution_mode'] = 'participant';
                 $contributionParams['participant_id'] = $this->_id;
             }
             // Set is_pay_later flag for back-office offline Pending status contributions
             if ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Pending', 'name')) {
                 $contributionParams['is_pay_later'] = 1;
             } elseif ($contributionParams['contribution_status_id'] == CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name')) {
                 $contributionParams['is_pay_later'] = 0;
             }
             if ($params['status_id'] == array_search('Partially paid', $participantStatus)) {
                 if (!$amountOwed && $this->_action & CRM_Core_Action::UPDATE) {
                     $amountOwed = $params['fee_amount'];
                 }
                 // if multiple participants are link, consider contribution total amount as the amount Owed
                 if ($this->_id && CRM_Event_BAO_Participant::isPrimaryParticipant($this->_id)) {
                     $amountOwed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $ids['contribution'], 'total_amount');
                 }
                 // CRM-13964 partial_payment_total
                 if ($amountOwed > $params['total_amount']) {
                     // the owed amount
                     $contributionParams['partial_payment_total'] = $amountOwed;
                     // the actual amount paid
                     $contributionParams['partial_amount_pay'] = $params['total_amount'];
                 }
             }
             if (CRM_Utils_Array::value('tax_amount', $this->_params)) {
                 $contributionParams['tax_amount'] = $this->_params['tax_amount'];
             }
             if ($this->_single) {
                 if (empty($ids)) {
                     $ids = array();
                 }
                 $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
             } else {
                 $ids = array();
                 foreach ($this->_contactIds as $contactID) {
                     $contributionParams['contact_id'] = $contactID;
                     $contributions[] = CRM_Contribute_BAO_Contribution::create($contributionParams, $ids);
                 }
             }
             //insert payment record for this participation
             if (empty($ids['contribution'])) {
                 foreach ($this->_contactIds as $num => $contactID) {
                     $ppDAO = new CRM_Event_DAO_ParticipantPayment();
                     $ppDAO->participant_id = $participants[$num]->id;
                     $ppDAO->contribution_id = $contributions[$num]->id;
                     $ppDAO->save();
                 }
             }
             // next create the transaction record
             $transaction = new CRM_Core_Transaction();
             // CRM-11124
             if ($this->_quickConfig) {
                 if (!empty($this->_params['amount_priceset_level_radio'])) {
                     $feeLevel = $this->_params['amount_priceset_level_radio'];
                 } else {
                     $feeLevel[] = $this->_params['fee_level'];
                 }
                 CRM_Event_BAO_Participant::createDiscountTrxn($this->_eventId, $contributionParams, $feeLevel);
             }
             $transaction->commit();
         }
     }
     // also store lineitem stuff here
     if ($this->_lineItem & $this->_action & CRM_Core_Action::ADD || $this->_lineItem && CRM_Core_Action::UPDATE && !$this->_paymentId) {
         foreach ($this->_contactIds as $num => $contactID) {
             foreach ($this->_lineItem as $key => $value) {
                 if (is_array($value) && $value != 'skip') {
                     foreach ($value as $lineKey => $line) {
                         //10117 update the line items for participants if contribution amount is recorded
                         if ($this->_quickConfig && !empty($params['total_amount']) && $params['status_id'] != array_search('Partially paid', $participantStatus)) {
                             $line['unit_price'] = $line['line_total'] = $params['total_amount'];
                             if (!empty($params['tax_amount'])) {
                                 $line['unit_price'] = $line['unit_price'] - $params['tax_amount'];
                                 $line['line_total'] = $line['line_total'] - $params['tax_amount'];
                             }
                         }
                         $lineItem[$this->_priceSetId][$lineKey] = $line;
                     }
                     CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
                 }
             }
         }
     }
     $updateStatusMsg = NULL;
     //send mail when participant status changed, CRM-4326
     if ($this->_id && $this->_statusId && $this->_statusId != CRM_Utils_Array::value('status_id', $params) && !empty($params['is_notify'])) {
         $updateStatusMsg = CRM_Event_BAO_Participant::updateStatusMessage($this->_id, $params['status_id'], $this->_statusId);
     }
     $sent = array();
     $notSent = array();
     if (!empty($params['send_receipt'])) {
         if (array_key_exists($params['from_email_address'], $this->_fromEmails['from_email_id'])) {
             $receiptFrom = $params['from_email_address'];
         }
         $this->assign('module', 'Event Registration');
         //use of the message template below requires variables in different format
         $event = $events = array();
         $returnProperties = array('fee_label', 'start_date', 'end_date', 'is_show_location', 'title');
         //get all event details.
         CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $params['event_id'], $events, $returnProperties);
         $event = $events[$params['event_id']];
         unset($event['start_date']);
         unset($event['end_date']);
         $role = CRM_Event_PseudoConstant::participantRole();
         $participantRoles = CRM_Utils_Array::value('role_id', $params);
         if (is_array($participantRoles)) {
             $selectedRoles = array();
             foreach ($participantRoles as $roleId) {
                 $selectedRoles[] = $role[$roleId];
             }
             $event['participant_role'] = implode(', ', $selectedRoles);
         } else {
             $event['participant_role'] = CRM_Utils_Array::value($participantRoles, $role);
         }
         $event['is_monetary'] = $this->_isPaidEvent;
         if ($params['receipt_text']) {
             $event['confirm_email_text'] = $params['receipt_text'];
         }
         $this->assign('isAmountzero', 1);
         $this->assign('event', $event);
         $this->assign('isShowLocation', $event['is_show_location']);
         if (CRM_Utils_Array::value('is_show_location', $event) == 1) {
             $locationParams = array('entity_id' => $params['event_id'], 'entity_table' => 'civicrm_event');
             $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
             $this->assign('location', $location);
         }
         $status = CRM_Event_PseudoConstant::participantStatus();
         if ($this->_isPaidEvent) {
             $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument();
             if (!$this->_mode) {
                 if (isset($params['payment_instrument_id'])) {
                     $this->assign('paidBy', CRM_Utils_Array::value($params['payment_instrument_id'], $paymentInstrument));
                 }
             }
             $this->assign('totalAmount', $contributionParams['total_amount']);
             if (isset($contributionParams['partial_payment_total'])) {
                 // balance amount
                 $balanceAmount = $contributionParams['partial_payment_total'] - $contributionParams['partial_amount_pay'];
                 $this->assign('balanceAmount', $balanceAmount);
             }
             $this->assign('isPrimary', 1);
             $this->assign('checkNumber', CRM_Utils_Array::value('check_number', $params));
         }
         if ($this->_mode) {
             if (!empty($params['billing_first_name'])) {
                 $name = $params['billing_first_name'];
             }
             if (!empty($params['billing_middle_name'])) {
                 $name .= " {$params['billing_middle_name']}";
             }
             if (!empty($params['billing_last_name'])) {
                 $name .= " {$params['billing_last_name']}";
             }
             $this->assign('billingName', $name);
             // assign the address formatted up for display
             $addressParts = array("street_address-{$this->_bltID}", "city-{$this->_bltID}", "postal_code-{$this->_bltID}", "state_province-{$this->_bltID}", "country-{$this->_bltID}");
             $addressFields = array();
             foreach ($addressParts as $part) {
                 list($n, $id) = explode('-', $part);
                 if (isset($this->_params['billing_' . $part])) {
                     $addressFields[$n] = $this->_params['billing_' . $part];
                 }
             }
             $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_exp_date', $date);
             $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number']));
             $this->assign('credit_card_type', $params['credit_card_type']);
             // The concept of contributeMode is deprecated.
             $this->assign('contributeMode', 'direct');
             $this->assign('isAmountzero', 0);
             $this->assign('is_pay_later', 0);
             $this->assign('isPrimary', 1);
         }
         $this->assign('register_date', $params['register_date']);
         if ($params['receive_date']) {
             $this->assign('receive_date', $params['receive_date']);
         }
         $participant = array(array('participant_id', '=', $participants[0]->id, 0, 0));
         // check whether its a test drive ref CRM-3075
         if (!empty($this->_defaultValues['is_test'])) {
             $participant[] = array('participant_test', '=', 1, 0, 0);
         }
         $template = CRM_Core_Smarty::singleton();
         $customGroup = array();
         //format submitted data
         foreach ($params['custom'] as $fieldID => $values) {
             foreach ($values as $fieldValue) {
                 $customFields[$fieldID]['id'] = $fieldID;
                 $formattedValue = CRM_Core_BAO_CustomField::displayValue($fieldValue['value'], $fieldID);
                 $customGroup[$customFields[$fieldID]['groupTitle']][$customFields[$fieldID]['label']] = str_replace('&nbsp;', '', $formattedValue);
             }
         }
         foreach ($this->_contactIds as $num => $contactID) {
             // Retrieve the name and email of the contact - this will be the TO for receipt email
             list($this->_contributorDisplayName, $this->_contributorEmail, $this->_toDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($contactID);
             $this->_contributorDisplayName = $this->_contributorDisplayName == ' ' ? $this->_contributorEmail : $this->_contributorDisplayName;
             $waitStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
             if ($waitingStatus = CRM_Utils_Array::value($params['status_id'], $waitStatus)) {
                 $this->assign('isOnWaitlist', TRUE);
             }
             $this->assign('customGroup', $customGroup);
             $this->assign('contactID', $contactID);
             $this->assign('participantID', $participants[$num]->id);
             $this->_id = $participants[$num]->id;
             if ($this->_isPaidEvent) {
                 // fix amount for each of participants ( for bulk mode )
                 $eventAmount = array();
                 $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
                 $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
                 $totalTaxAmount = 0;
                 //add dataArray in the receipts in ADD and UPDATE condition
                 $dataArray = array();
                 if ($this->_action & CRM_Core_Action::ADD) {
                     $line = $lineItem[0];
                 } elseif ($this->_action & CRM_Core_Action::UPDATE) {
                     $line = $this->_values['line_items'];
                 }
                 if ($invoicing) {
                     foreach ($line as $key => $value) {
                         if (isset($value['tax_amount'])) {
                             $totalTaxAmount += $value['tax_amount'];
                             if (isset($dataArray[(string) $value['tax_rate']])) {
                                 $dataArray[(string) $value['tax_rate']] = $dataArray[(string) $value['tax_rate']] + CRM_Utils_Array::value('tax_amount', $value);
                             } else {
                                 $dataArray[(string) $value['tax_rate']] = CRM_Utils_Array::value('tax_amount', $value);
                             }
                         }
                     }
                     $this->assign('totalTaxAmount', $totalTaxAmount);
                     $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
                     $this->assign('dataArray', $dataArray);
                 }
                 if (!empty($additionalParticipantDetails)) {
                     $params['amount_level'] = preg_replace('//', '', $params['amount_level']) . ' - ' . $this->_contributorDisplayName;
                 }
                 $eventAmount[$num] = array('label' => preg_replace('//', '', $params['amount_level']), 'amount' => $params['fee_amount']);
                 //as we are using same template for online & offline registration.
                 //So we have to build amount as array.
                 $eventAmount = array_merge($eventAmount, $additionalParticipantDetails);
                 $this->assign('amount', $eventAmount);
             }
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_offline_receipt', 'contactId' => $contactID, 'isTest' => (bool) CRM_Utils_Array::value('is_test', $this->_defaultValues), 'PDFFilename' => ts('confirmation') . '.pdf');
             // try to send emails only if email id is present
             // and the do-not-email option is not checked for that contact
             if ($this->_contributorEmail and !$this->_toDoNotEmail) {
                 $sendTemplateParams['from'] = $receiptFrom;
                 $sendTemplateParams['toName'] = $this->_contributorDisplayName;
                 $sendTemplateParams['toEmail'] = $this->_contributorEmail;
                 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc', $this->_fromEmails);
                 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc', $this->_fromEmails);
             }
             //send email with pdf invoice
             $template = CRM_Core_Smarty::singleton();
             $taxAmt = $template->get_template_vars('dataArray');
             $contributionId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id');
             $prefixValue = Civi::settings()->get('contribution_invoice_settings');
             $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
             if (count($taxAmt) > 0 && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
                 $sendTemplateParams['isEmailPdf'] = TRUE;
                 $sendTemplateParams['contributionId'] = $contributionId;
             }
             list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             if ($mailSent) {
                 $sent[] = $contactID;
                 foreach ($participants as $ids => $values) {
                     if ($values->contact_id == $contactID) {
                         $values->details = CRM_Utils_Array::value('receipt_text', $params);
                         CRM_Activity_BAO_Activity::addActivity($values, 'Email');
                         break;
                     }
                 }
             } else {
                 $notSent[] = $contactID;
             }
         }
     }
     // set the participant id if it is not set
     if (!$this->_id) {
         $this->_id = $participants[0]->id;
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contributorDisplayName));
         if (!empty($params['send_receipt']) && count($sent)) {
             $statusMsg .= ' ' . ts('A confirmation email has been sent to %1', array(1 => $this->_contributorEmail));
         }
         if ($updateStatusMsg) {
             $statusMsg = "{$statusMsg} {$updateStatusMsg}";
         }
     } elseif ($this->_action & CRM_Core_Action::ADD) {
         if ($this->_single) {
             $statusMsg = ts('Event registration for %1 has been added.', array(1 => $this->_contributorDisplayName));
             if (!empty($params['send_receipt']) && count($sent)) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to %1.', array(1 => $this->_contributorEmail));
             }
         } else {
             $statusMsg = ts('Total Participant(s) added to event: %1.', array(1 => count($this->_contactIds)));
             if (count($notSent) > 0) {
                 $statusMsg .= ' ' . ts('Email has NOT been sent to %1 contact(s) - communication preferences specify DO NOT EMAIL OR valid Email is NOT present. ', array(1 => count($notSent)));
             } elseif (isset($params['send_receipt'])) {
                 $statusMsg .= ' ' . ts('A confirmation email has been sent to ALL participants');
             }
         }
     }
     CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $urlParams = 'reset=1&action=add&context=standalone';
             if ($this->_mode) {
                 $urlParams .= '&mode=' . $this->_mode;
             }
             if ($this->_eID) {
                 $urlParams .= '&eid=' . $this->_eID;
             }
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/participant/add', $urlParams));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}&selectedChild=participant"));
         }
     } elseif ($buttonName == $this->getButtonName('upload', 'new')) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/participant', "reset=1&action=add&context={$this->_context}&cid={$this->_contactId}"));
     }
 }
Beispiel #25
0
 /**
  *  Function to get email address of a contact.
  */
 public static function getContactEmail()
 {
     if (!empty($_REQUEST['contact_id'])) {
         $contactID = CRM_Utils_Type::escape($_REQUEST['contact_id'], 'Positive');
         if (!CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) {
             return;
         }
         list($displayName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         CRM_Utils_System::setHttpHeader('Content-Type', 'text/plain');
         if ($userEmail) {
             echo $userEmail;
         }
     } else {
         $noemail = CRM_Utils_Array::value('noemail', $_GET);
         $queryString = NULL;
         $name = CRM_Utils_Array::value('name', $_GET);
         if ($name) {
             $name = CRM_Utils_Type::escape($name, 'String');
             if ($noemail) {
                 $queryString = " cc.sort_name LIKE '%{$name}%'";
             } else {
                 $queryString = " ( cc.sort_name LIKE '%{$name}%' OR ce.email LIKE '%{$name}%' ) ";
             }
         } else {
             $cid = CRM_Utils_Array::value('cid', $_GET);
             if ($cid) {
                 //check cid for integer
                 $contIDS = explode(',', $cid);
                 foreach ($contIDS as $contID) {
                     CRM_Utils_Type::escape($contID, 'Integer');
                 }
                 $queryString = " cc.id IN ( {$cid} )";
             }
         }
         if ($queryString) {
             $offset = CRM_Utils_Array::value('offset', $_GET, 0);
             $rowCount = Civi::settings()->get('search_autocomplete_count');
             $offset = CRM_Utils_Type::escape($offset, 'Int');
             // add acl clause here
             list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause('cc');
             if ($aclWhere) {
                 $aclWhere = " AND {$aclWhere}";
             }
             if ($noemail) {
                 $query = "\nSELECT sort_name name, cc.id\nFROM civicrm_contact cc\n     {$aclFrom}\nWHERE cc.is_deceased = 0 AND {$queryString}\n      {$aclWhere}\nLIMIT {$offset}, {$rowCount}\n";
                 // send query to hook to be modified if needed
                 CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject));
                 $dao = CRM_Core_DAO::executeQuery($query);
                 while ($dao->fetch()) {
                     $result[] = array('id' => $dao->id, 'text' => $dao->name);
                 }
             } else {
                 $query = "\nSELECT sort_name name, ce.email, cc.id\nFROM   civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id\n       {$aclFrom}\nWHERE  ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString}\n       {$aclWhere}\nLIMIT {$offset}, {$rowCount}\n";
                 // send query to hook to be modified if needed
                 CRM_Utils_Hook::contactListQuery($query, $name, CRM_Utils_Request::retrieve('context', 'String', CRM_Core_DAO::$_nullObject), CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject));
                 $dao = CRM_Core_DAO::executeQuery($query);
                 while ($dao->fetch()) {
                     //working here
                     $result[] = array('text' => '"' . $dao->name . '" <' . $dao->email . '>', 'id' => CRM_Utils_Array::value('id', $_GET) ? "{$dao->id}::{$dao->email}" : '"' . $dao->name . '" <' . $dao->email . '>');
                 }
             }
             if ($result) {
                 CRM_Utils_JSON::output($result);
             }
         }
     }
     CRM_Utils_System::civiExit();
 }
Beispiel #26
0
 /**
  *  Function to get email address of a contact
  */
 static function getContactEmail()
 {
     if (CRM_Utils_Array::value('contact_id', $_POST)) {
         $contactID = CRM_Utils_Type::escape($_POST['contact_id'], 'Positive');
         require_once 'CRM/Contact/BAO/Contact/Location.php';
         list($displayName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         if ($userEmail) {
             echo $userEmail;
         }
     } else {
         $noemail = CRM_Utils_Array::value('noemail', $_GET);
         if ($name = CRM_Utils_Array::value('name', $_GET)) {
             $name = CRM_Utils_Type::escape($name, 'String');
             if ($noemail) {
                 $queryString = " cc.sort_name LIKE '%{$name}%'";
             } else {
                 $queryString = " ( cc.sort_name LIKE '%{$name}%' OR ce.email LIKE '%{$name}%' ) ";
             }
         } else {
             $cid = CRM_Utils_Array::value('cid', $_GET);
             $queryString = " cc.id IN ( {$cid} )";
         }
         if ($noemail) {
             $query = "\nSELECT sort_name name, cc.id\nFROM civicrm_contact cc \nWHERE {$queryString}";
             $dao = CRM_Core_DAO::executeQuery($query);
             while ($dao->fetch()) {
                 $result[] = array('name' => $dao->name, 'id' => $dao->id);
             }
         } else {
             $query = "\nSELECT sort_name name, ce.email, cc.id\nFROM civicrm_email ce INNER JOIN civicrm_contact cc ON cc.id = ce.contact_id\nWHERE ce.on_hold = 0 AND cc.is_deceased = 0 AND cc.do_not_email = 0 AND {$queryString} ";
             $dao = CRM_Core_DAO::executeQuery($query);
             while ($dao->fetch()) {
                 $result[] = array('name' => '"' . $dao->name . '" &lt;' . $dao->email . '&gt;', 'id' => CRM_Utils_Array::value('id', $_GET) ? "{$dao->id}::{$dao->email}" : '"' . $dao->name . '" <' . $dao->email . '>');
             }
         }
         if ($result) {
             echo json_encode($result);
         }
     }
     exit;
 }
Beispiel #27
0
 /**
  * Function that sends e-mail copy of activity
  *
  * @param $clientId
  * @param int $activityId activity Id
  * @param array $contacts array of related contact
  *
  * @param null $attachments
  * @param $caseId
  *
  * @return void
  * @access public
  */
 static function sendActivityCopy($clientId, $activityId, $contacts, $attachments = NULL, $caseId)
 {
     if (!$activityId) {
         return;
     }
     $tplParams = $activityInfo = array();
     //if its a case activity
     if ($caseId) {
         $activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'activity_type_id');
         $nonCaseActivityTypes = CRM_Core_PseudoConstant::activityType();
         if (!empty($nonCaseActivityTypes[$activityTypeId])) {
             $anyActivity = TRUE;
         } else {
             $anyActivity = FALSE;
         }
         $tplParams['isCaseActivity'] = 1;
         $tplParams['client_id'] = $clientId;
     } else {
         $anyActivity = TRUE;
     }
     $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
     $isRedact = $xmlProcessorProcess->getRedactActivityEmail();
     $xmlProcessorReport = new CRM_Case_XMLProcessor_Report();
     $activityInfo = $xmlProcessorReport->getActivityInfo($clientId, $activityId, $anyActivity, $isRedact);
     if ($caseId) {
         $activityInfo['fields'][] = array('label' => 'Case ID', 'type' => 'String', 'value' => $caseId);
     }
     $tplParams['activity'] = $activityInfo;
     foreach ($tplParams['activity']['fields'] as $k => $val) {
         if (CRM_Utils_Array::value('label', $val) == ts('Subject')) {
             $activitySubject = $val['value'];
             break;
         }
     }
     $session = CRM_Core_Session::singleton();
     // CRM-8926 If user is not logged in, use the activity creator as userID
     if (!($userID = $session->get('userID'))) {
         $userID = CRM_Activity_BAO_Activity::getSourceContactID($activityId);
     }
     //also create activities simultaneously of this copy.
     $activityParams = array();
     $activityParams['source_record_id'] = $activityId;
     $activityParams['source_contact_id'] = $userID;
     $activityParams['activity_type_id'] = CRM_Core_OptionGroup::getValue('activity_type', 'Email', 'name');
     $activityParams['activity_date_time'] = date('YmdHis');
     $activityParams['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
     $activityParams['medium_id'] = CRM_Core_OptionGroup::getValue('encounter_medium', 'email', 'name');
     $activityParams['case_id'] = $caseId;
     $activityParams['is_auto'] = 0;
     $activityParams['target_id'] = $clientId;
     $tplParams['activitySubject'] = $activitySubject;
     // if it’s a case activity, add hashed id to the template (CRM-5916)
     if ($caseId) {
         $tplParams['idHash'] = substr(sha1(CIVICRM_SITE_KEY . $caseId), 0, 7);
     }
     $result = array();
     list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
     $receiptFrom = "{$name} <{$address}>";
     $recordedActivityParams = array();
     foreach ($contacts as $mail => $info) {
         $tplParams['contact'] = $info;
         self::buildPermissionLinks($tplParams, $activityParams);
         $displayName = CRM_Utils_Array::value('display_name', $info);
         list($result[CRM_Utils_Array::value('contact_id', $info)], $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_case', 'valueName' => 'case_activity', 'contactId' => CRM_Utils_Array::value('contact_id', $info), 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $mail, 'attachments' => $attachments));
         $activityParams['subject'] = $activitySubject . ' - copy sent to ' . $displayName;
         $activityParams['details'] = $message;
         if (!empty($result[$info['contact_id']])) {
             /*
              * Really only need to record one activity with all the targets combined.
              * Originally the template was going to possibly have different content, e.g. depending on permissions,
              * but it's always the same content at the moment.
              */
             if (empty($recordedActivityParams)) {
                 $recordedActivityParams = $activityParams;
             } else {
                 $recordedActivityParams['subject'] .= "; {$displayName}";
             }
             $recordedActivityParams['target_contact_id'][] = $info['contact_id'];
         } else {
             unset($result[CRM_Utils_Array::value('contact_id', $info)]);
         }
     }
     if (!empty($recordedActivityParams)) {
         $activity = CRM_Activity_BAO_Activity::create($recordedActivityParams);
         //create case_activity record if its case activity.
         if ($caseId) {
             $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId);
             self::processCaseActivity($caseParams);
         }
     }
     return $result;
 }
Beispiel #28
0
 /**
  * Process that send e-mails
  *
  * @return void
  * @access public
  */
 static function sendMail($contactID, &$values, $isTest = FALSE, $returnMessageText = FALSE)
 {
     //TODO:: check if from email address is entered
     $config = CRM_Booking_BAO_BookingConfig::getConfig();
     $template = CRM_Core_Smarty::singleton();
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
     //send email only when email is present
     if ($email) {
         $bookingId = $values['booking_id'];
         //get latest booking status
         $params = array('id' => $bookingId);
         $bookingLatest = civicrm_api3('Booking', 'get', $params);
         $bookingStatusValueItems = CRM_Booking_BAO_Booking::buildOptions('status_id', 'create');
         //get booking status option values
         $bookingLatestStatus = $bookingStatusValueItems[$bookingLatest['values'][$bookingId]['status_id']];
         //get booking detail
         $bookingDetail = CRM_Booking_BAO_Booking::getBookingDetails($values['booking_id']);
         $slots = CRM_Utils_Array::value('slots', $bookingDetail);
         $subSlots = CRM_Utils_Array::value('sub_slots', $bookingDetail);
         $adhocCharges = CRM_Utils_Array::value('adhoc_charges', $bookingDetail);
         $cancellationCharges = CRM_Utils_Array::value('cancellation_charges', $bookingDetail);
         //get contacts associating with booking
         $contactIds = array();
         $contactIds['primary_contact'] = CRM_Utils_Array::value('primary_contact_id', $values);
         $contactIds['secondary_contact'] = CRM_Utils_Array::value('secondary_contact_id', $values);
         $contactsDetail = array();
         foreach (array_filter($contactIds) as $k => $contactIdItem) {
             //get contact detail
             $contactDetail = array();
             $params = array('contact_id' => $contactIdItem);
             $contactDetailResult = civicrm_api3('Contact', 'get', $params);
             $contactValues = CRM_Utils_Array::value($contactDetailResult['id'], $contactDetailResult['values']);
             foreach ($contactValues as $key => $contactItem) {
                 $contactDetail[$key] = $contactItem;
             }
             $contactsDetail[$k] = $contactDetail;
         }
         //get Price elements(Subtotal, Discount, Total)
         $booking_amount = CRM_Booking_BAO_Booking::getBookingAmount($values['booking_id']);
         //get date booking made
         $dateBookingMade = new DateTime($values['booking_date']);
         $tplParams = array('email' => $email, 'today_date' => date('d.m.Y'), 'receipt_header_message' => $values['receipt_header_message'], 'receipt_footer_message' => $values['receipt_footer_message'], 'booking_id' => $bookingId, 'booking_title' => $values['booking_title'], 'booking_status' => $bookingLatestStatus, 'booking_date_made' => $values['booking_date'], 'booking_start_date' => $values['booking_start_date'], 'booking_end_date' => $values['booking_end_date'], 'booking_event_day' => $dateBookingMade->format('l'), 'booking_subtotal' => number_format($booking_amount['total_amount'] + $booking_amount['discount_amount'], 2, '.', ''), 'booking_total' => number_format($booking_amount['total_amount'], 2, '.', ''), 'booking_discount' => number_format($booking_amount['discount_amount'], 2, '.', ''), 'participants_estimate' => $values['participants_estimate'], 'participants_actual' => $values['participants_actual'], 'contacts' => $contactsDetail, 'slots' => $slots, 'sub_slots' => $subSlots, 'adhoc_charges' => $adhocCharges, 'cancellation_charges' => $cancellationCharges);
         $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_booking', 'valueName' => 'booking_offline_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => $tplParams, 'PDFFilename' => 'bookingReceipt.pdf');
         //get include payment check box
         //if(CRM_Utils_Array::value('include_payment_info', $values)){
         if (CRM_Utils_Array::value('contribution', $bookingDetail)) {
             //get contribution record
             $contribution = array();
             $contributionResult = CRM_Utils_Array::value('contribution', $bookingDetail);
             foreach ($contributionResult as $kx => $ctbItem) {
                 $contribution = $ctbItem;
             }
             $sendTemplateParams['tplParams']['contribution'] = $contribution;
             //calculate Amount outstanding
             $sendTemplateParams['tplParams']['amount_outstanding'] = number_format($booking_amount['total_amount'] - $contribution['total_amount'], 2, '.', '');
         }
         //TODO:: add line item tpl params
         if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) {
             $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
         }
         $sendTemplateParams['from'] = $values['from_email_address'];
         $sendTemplateParams['toName'] = $displayName;
         $sendTemplateParams['toEmail'] = $email;
         //$sendTemplateParams['autoSubmitted'] = TRUE;
         $cc = CRM_Utils_Array::value('cc_email_address', $config);
         if ($cc) {
             $sendTemplateParams['cc'] = $cc;
         }
         $bcc = CRM_Utils_Array::value('bcc_email_address', $config);
         if ($bcc) {
             $sendTemplateParams['bcc'] = $bcc;
         }
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         if ($sent && CRM_Utils_Array::value('log_confirmation_email', $config)) {
             //check log_email_confirmaiton
             $session =& CRM_Core_Session::singleton();
             $userId = $session->get('userID');
             // which is contact id of the user
             //create activity for sending email
             $params = array('option_group_name' => 'activity_type', 'name' => CRM_Booking_Utils_Constants::ACTIVITY_TYPE_SEND_EMAIL);
             $optionValue = civicrm_api3('OptionValue', 'get', $params);
             $activityTypeId = $optionValue['values'][$optionValue['id']]['value'];
             $params = array('source_contact_id' => $userId, 'activity_type_id' => $activityTypeId, 'subject' => ts('Send Booking Confirmation Email'), 'activity_date_time' => date('YmdHis'), 'target_contact_id' => $contactID, 'details' => $message, 'status_id' => 2, 'priority_id' => 2);
             $result = civicrm_api3('Activity', 'create', $params);
         }
         if ($returnMessageText) {
             return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
         }
     }
 }
 function sendMail(&$input, &$ids, &$objects, &$values, $recur = FALSE, $returnMessageText = FALSE)
 {
     $contribution =& $objects['contribution'];
     $input['is_recur'] = $recur;
     // set receipt from e-mail and name in value
     if (!$returnMessageText) {
         $session = CRM_Core_Session::singleton();
         $userID = $session->get('userID');
         if (!empty($userID)) {
             list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID);
             $values['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', $input, $userEmail);
             $values['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', $input, $userName);
         }
     }
     return $contribution->composeMessageArray($input, $ids, $values, $recur, $returnMessageText);
 }
Beispiel #30
0
 /**
  * Process that send e-mails
  *
  * @param $contactID
  * @param $values
  * @param $participantId
  * @param bool $isTest
  * @param bool $returnMessageText
  *
  * @return void
  * @access public
  */
 static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE)
 {
     $template = CRM_Core_Smarty::singleton();
     $gIds = array('custom_pre_id' => $values['custom_pre_id'], 'custom_post_id' => $values['custom_post_id']);
     //get the params submitted by participant.
     $participantParams = CRM_Utils_Array::value($participantId, $values['params'], array());
     if (!$returnMessageText) {
         //send notification email if field values are set (CRM-1941)
         foreach ($gIds as $key => $gIdValues) {
             if ($gIdValues) {
                 if (!is_array($gIdValues)) {
                     $gIdValues = array($gIdValues);
                 }
                 foreach ($gIdValues as $gId) {
                     $email = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
                     if ($email) {
                         //get values of corresponding profile fields for notification
                         list($profileValues) = self::buildCustomDisplay($gId, NULL, $contactID, $template, $participantId, $isTest, TRUE, $participantParams);
                         list($profileValues) = $profileValues;
                         $val = array('id' => $gId, 'values' => $profileValues, 'email' => $email);
                         CRM_Core_BAO_UFGroup::commonSendMail($contactID, $val);
                     }
                 }
             }
         }
     }
     if ($values['event']['is_email_confirm'] || $returnMessageText) {
         list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
         //send email only when email is present
         if (isset($email) || $returnMessageText) {
             $preProfileID = CRM_Utils_Array::value('custom_pre_id', $values);
             $postProfileID = CRM_Utils_Array::value('custom_post_id', $values);
             if (!empty($values['params']['additionalParticipant'])) {
                 $preProfileID = CRM_Utils_Array::value('additional_custom_pre_id', $values, $preProfileID);
                 $postProfileID = CRM_Utils_Array::value('additional_custom_post_id', $values, $postProfileID);
             }
             self::buildCustomDisplay($preProfileID, 'customPre', $contactID, $template, $participantId, $isTest, NULL, $participantParams);
             self::buildCustomDisplay($postProfileID, 'customPost', $contactID, $template, $participantId, $isTest, NULL, $participantParams);
             $sessions = CRM_Event_Cart_BAO_Conference::get_participant_sessions($participantId);
             $tplParams = array_merge($values, $participantParams, array('email' => $email, 'confirm_email_text' => CRM_Utils_Array::value('confirm_email_text', $values['event']), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $values['event']), 'contributeMode' => CRM_Utils_Array::value('contributeMode', $template->_tpl_vars), 'participantID' => $participantId, 'conference_sessions' => $sessions, 'credit_card_number' => CRM_Utils_System::mungeCreditCard(CRM_Utils_Array::value('credit_card_number', $participantParams)), 'credit_card_exp_date' => CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::format(CRM_Utils_Array::value('credit_card_exp_date', $participantParams)))));
             // CRM-13890 : NOTE wait list condition need to be given so that
             // wait list message is shown properly in email i.e. WRT online event registration template
             if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) {
                 $statusId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id');
                 $tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($statusId, NULL, 'label');
             }
             $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_online_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => $tplParams, 'PDFFilename' => ts('confirmation') . '.pdf');
             // address required during receipt processing (pdf and email receipt)
             if ($displayAddress = CRM_Utils_Array::value('address', $values)) {
                 $sendTemplateParams['tplParams']['address'] = $displayAddress;
                 $sendTemplateParams['tplParams']['contributeMode'] = NULL;
             }
             // set lineItem details
             if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) {
                 // check if additional prticipant, if so filter only to relevant ones
                 // CRM-9902
                 if (!empty($values['params']['additionalParticipant'])) {
                     $ownLineItems = array();
                     foreach ($lineItem as $liKey => $liValue) {
                         $firstElement = array_pop($liValue);
                         if ($firstElement['entity_id'] == $participantId) {
                             $ownLineItems[0] = $lineItem[$liKey];
                             break;
                         }
                     }
                     if (!empty($ownLineItems)) {
                         $sendTemplateParams['tplParams']['lineItem'] = $ownLineItems;
                     }
                 } else {
                     $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
                 }
             }
             if ($returnMessageText) {
                 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
                 return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
             } else {
                 $sendTemplateParams['from'] = CRM_Utils_Array::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array::value('confirm_from_email', $values['event']) . ">";
                 $sendTemplateParams['toName'] = $displayName;
                 $sendTemplateParams['toEmail'] = $email;
                 $sendTemplateParams['autoSubmitted'] = TRUE;
                 $sendTemplateParams['cc'] = CRM_Utils_Array::value('cc_confirm', $values['event']);
                 $sendTemplateParams['bcc'] = CRM_Utils_Array::value('bcc_confirm', $values['event']);
                 CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
             }
         }
     }
 }