/** * Function for validation * * @param array $params (ref.) an assoc array of name/value pairs * * @return mixed true or array of errors * @access public * @static */ static function formRule($params, $files, $self) { if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) { return true; } $errors = array(); $template = CRM_Core_Smarty::singleton(); if (isset($params['html_message'])) { $htmlMessage = str_replace(array("\n", "\r"), ' ', $params['html_message']); $htmlMessage = str_replace("'", "\\'", $htmlMessage); $template->assign('htmlContent', $htmlMessage); } require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $self->_mailingID; $mailing->find(true); $session = CRM_Core_Session::singleton(); $values = array('contact_id' => $session->get('userID')); require_once 'api/v2/Contact.php'; $contact =& civicrm_contact_get($values); //CRM-4524 $contact = reset($contact); $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner')); foreach ($verp as $key => $value) { $verp[$key]++; } $urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl')); foreach ($urls as $key => $value) { $urls[$key]++; } require_once 'CRM/Mailing/BAO/Component.php'; // set $header and $footer foreach (array('header', 'footer') as $part) { ${$part} = array(); if ($params["{$part}_id"]) { //echo "found<p>"; $component = new CRM_Mailing_BAO_Component(); $component->id = $params["{$part}_id"]; $component->find(true); ${$part}['textFile'] = $component->body_text; ${$part}['htmlFile'] = $component->body_html; $component->free(); } else { ${$part}['htmlFile'] = ${$part}['textFile'] = ''; } } require_once 'CRM/Utils/Token.php'; $skipTextFile = $self->get('skipTextFile'); $skipHtmlFile = $self->get('skipHtmlFile'); if (!$params['upload_type']) { if ((!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) && (!isset($files['htmlFile']) || !file_exists($files['htmlFile']['tmp_name']))) { if (!($skipTextFile || $skipHtmlFile)) { $errors['textFile'] = ts('Please provide either a Text or HTML formatted message - or both.'); } } } else { if (!CRM_Utils_Array::value('text_message', $params) && !CRM_Utils_Array::value('html_message', $params)) { $errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.'); } if (CRM_Utils_Array::value('saveTemplate', $params) && !CRM_Utils_Array::value('saveTemplateName', $params)) { $errors['saveTemplateName'] = ts('Please provide a Template Name.'); } } foreach (array('text', 'html') as $file) { if (!$params['upload_type'] && !file_exists(CRM_Utils_Array::value('tmp_name', $files[$file . 'File']))) { continue; } if ($params['upload_type'] && !$params[$file . '_message']) { continue; } if (!$params['upload_type']) { $str = file_get_contents($files[$file . 'File']['tmp_name']); $name = $files[$file . 'File']['name']; } else { $str = $params[$file . '_message']; $str = $file == 'html' ? str_replace('%7B', '{', str_replace('%7D', '}', $str)) : $str; $name = $file . ' message'; } /* append header/footer */ $str = $header[$file . 'File'] . $str . $footer[$file . 'File']; $dataErrors = array(); /* First look for missing tokens */ $err = CRM_Utils_Token::requiredTokens($str); if ($err !== true) { foreach ($err as $token => $desc) { $dataErrors[] = '<li>' . ts('This message is missing a required token - {%1}: %2', array(1 => $token, 2 => $desc)) . '</li>'; } } /* Do a full token replacement on a dummy verp, the current * contact and domain, and the first organization. */ // here we make a dummy mailing object so that we // can retrieve the tokens that we need to replace // so that we do get an invalid token error // this is qute hacky and I hope that there might // be a suggestion from someone on how to // make it a bit more elegant require_once 'CRM/Mailing/BAO/Mailing.php'; $dummy_mail = new CRM_Mailing_BAO_Mailing(); $mess = "body_{$file}"; $dummy_mail->{$mess} = $str; $tokens = $dummy_mail->getTokens(); $str = CRM_Utils_Token::replaceSubscribeInviteTokens($str); $str = CRM_Utils_Token::replaceDomainTokens($str, $domain, null, $tokens[$file]); $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, null, $tokens[$file]); $str = CRM_Utils_Token::replaceOrgTokens($str, $org); $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, null, $tokens[$file]); $str = CRM_Utils_Token::replaceContactTokens($str, $contact, null, $tokens[$file]); $unmatched = CRM_Utils_Token::unmatchedTokens($str); if (!empty($unmatched) && 0) { foreach ($unmatched as $token) { $dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>'; } } if (!empty($dataErrors)) { $errors[$file . 'File'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul><br /><a href="' . CRM_Utils_System::docURL2('Sample CiviMail Messages', true) . '" target="_blank">' . ts('More information on required tokens...') . '</a>'; } } require_once 'CRM/Core/BAO/MessageTemplates.php'; $templateName = CRM_Core_BAO_MessageTemplates::getMessageTemplates(); if (CRM_Utils_Array::value('saveTemplate', $params) && in_array(CRM_Utils_Array::value('saveTemplateName', $params), $templateName)) { $errors['saveTemplate'] = ts('Duplicate Template Name.'); } return empty($errors) ? true : $errors; }
/** * 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(' ', '', $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}")); } } }
/** * 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); } } } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), true); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')); $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()')); //period type $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()')); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120'); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date('custom', 3, 1, "Md"), false); $this->add('hidden', 'action', $this->_action); //required in form rule require_once 'CRM/Contribute/PseudoConstant.php'; $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); require_once 'CRM/Contact/BAO/Relationship.php'; $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, null, true); if (is_array($relTypeInd)) { asort($relTypeInd); } $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility()); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); require_once "CRM/Core/BAO/MessageTemplates.php"; $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(); if (!empty($msgTemplates)) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } else { $this->assign('noMsgTemplates', true); } $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day')); $searchRows = $this->get('searchRows'); $searchCount = $this->get('searchCount'); $searchDone = $this->get('searchDone'); if ($searchRows) { $checkBoxes = array(); $chekFlag = 0; foreach ($searchRows as $id => $row) { $checked = ''; if (!$chekFlag) { $checked = array('checked' => null); $chekFlag++; } $checkBoxes[$id] = $this->createElement('radio', null, null, null, $id, $checked); } $this->addGroup($checkBoxes, 'contact_check'); $this->assign('searchRows', $searchRows); } $this->assign('searchCount', $searchCount); $this->assign('searchDone', $searchDone); if ($searchDone) { $searchBtn = ts('Search Again'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $searchBtn = ts('Change'); } else { $searchBtn = ts('Search'); } $membershipRecords = false; if ($this->_action & CRM_Core_Action::UPDATE) { require_once 'CRM/Member/BAO/Membership.php'; $membershipType = new CRM_Member_BAO_Membership(); $membershipType->membership_type_id = $this->_id; if ($membershipType->find(true)) { $membershipRecords = true; $memberRel->freeze(); } $memberOrg->freeze(); if ($searchDone) { $memberOrg->unfreeze(); } } if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) { $renewMessage = array(); $returnProperties = array('renewal_msg_id', 'renewal_reminder_day'); CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties); if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); $reminderDay->freeze(); $reminderMsg->freeze(); } } $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }
/** * Function to send Acknowledgment and create activity. * * @param object $form form object. * @param array $params (reference ) an assoc array of name/value pairs. * @access public * @return None. */ function sendAcknowledgment(&$form, $params) { //handle Acknowledgment. $allPayments = $payments = array(); //get All Payments status types. require_once 'CRM/Contribute/PseudoConstant.php'; $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'); $returnProperties = array('status_id', 'scheduled_amount', 'scheduled_date', 'contribution_id'); //get all paymnets details. CRM_Core_DAO::commonRetrieveAll('CRM_Pledge_DAO_Payment', 'pledge_id', $params['id'], $allPayments, $returnProperties); if (!empty($allPayments)) { foreach ($allPayments as $payID => $values) { $contributionValue = $contributionStatus = array(); if (isset($values['contribution_id'])) { $contributionParams = array('id' => $values['contribution_id']); $returnProperties = array('contribution_status_id', 'receive_date'); CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_Contribution', $contributionParams, $contributionStatus, $returnProperties); $contributionValue = array('status' => CRM_Utils_Array::value('contribution_status_id', $contributionStatus), 'receive_date' => CRM_Utils_Array::value('receive_date', $contributionStatus)); } $payments[$payID] = array_merge($contributionValue, array('amount' => CRM_Utils_Array::value('scheduled_amount', $values), 'due_date' => CRM_Utils_Array::value('scheduled_date', $values))); //get the first valid payment id. if (!$form->paymentId && ($paymentStatusTypes[$values['status_id']] == 'Pending' || $paymentStatusTypes[$values['status_id']] == 'Overdue')) { $form->paymentId = $values['id']; } } } //end //assign pledge fields value to template. $pledgeFields = array('create_date', 'total_pledge_amount', 'frequency_interval', 'frequency_unit', 'installments', 'frequency_day', 'scheduled_amount'); foreach ($pledgeFields as $field) { if (CRM_Utils_Array::value($field, $params)) { $form->assign($field, $params[$field]); } } //assign all payments details. if ($payments) { $form->assign('payments', $payments); } //assign honor fields. $honor_block_is_active = false; //make sure we have values for it if (CRM_Utils_Array::value('honor_type_id', $params) && (!empty($params["honor_first_name"]) && !empty($params["honor_last_name"]) || !empty($params["honor_email"]))) { $honor_block_is_active = true; require_once "CRM/Core/PseudoConstant.php"; $prefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $form->assign("honor_type", $honor[$params["honor_type_id"]]); $form->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]); $form->assign("honor_first_name", $params["honor_first_name"]); $form->assign("honor_last_name", $params["honor_last_name"]); $form->assign("honor_email", $params["honor_email"]); } $form->assign('honor_block_is_active', $honor_block_is_active); //handle domain token values require_once 'CRM/Core/BAO/Domain.php'; $domain =& CRM_Core_BAO_Domain::getDomain(); $tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens()); require_once 'CRM/Utils/Token.php'; $domainValues = array(); foreach ($tokens['domain'] as $token) { $domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain); } $form->assign('domain', $domainValues); //handle contact token values. require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Mailing/BAO/Mailing.php'; $ids = array($params['contact_id']); $fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()), array('display_name', 'checksum', 'contact_id')); foreach ($fields as $key => $val) { $returnProperties[$val] = true; } $details = CRM_Mailing_BAO_Mailing::getDetails($ids, $returnProperties); $form->assign('contact', $details[0][$params['contact_id']]); //handle custom data. if (CRM_Utils_Array::value('hidden_custom', $params)) { require_once 'CRM/Core/BAO/CustomGroup.php'; $groupTree =& CRM_Core_BAO_CustomGroup::getTree('Pledge', CRM_Core_DAO::$_nullObject, $params['id']); $pledgeParams = array(array('pledge_id', '=', $params['id'], 0, 0)); $customGroup = array(); // retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; foreach ($groupTree as $groupID => $group) { $customFields = $customValues = array(); if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } //to build array of customgroup & customfields in it CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $pledgeParams); $customGroup[$group['title']] = $customValues; } $form->assign('customGroup', $customGroup); } //handle acknowledgment email stuff. require_once 'CRM/Contact/BAO/Contact.php'; require_once 'CRM/Contact/BAO/Contact/Location.php'; list($pledgerDisplayName, $pledgerEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); //check for online pledge. $session = CRM_Core_Session::singleton(); if (CRM_Utils_Array::value('receipt_from_email', $params)) { $userName = CRM_Utils_Array::value('receipt_from_name', $params); $userEmail = CRM_Utils_Array::value('receipt_from_email', $params); } else { if ($userID = $session->get('userID')) { //check for loged in user. list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); } else { //set the domain values. $userName = CRM_Utils_Array::value('name', $domainValues); $userEmail = CRM_Utils_Array::value('email', $domainValues); } } $receiptFrom = "{$userName} <{$userEmail}>"; require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_pledge', 'valueName' => 'pledge_acknowledge', 'contactId' => $params['contact_id'], 'from' => $receiptFrom, 'toName' => $pledgerDisplayName, 'toEmail' => $pledgerEmail)); //check if activity record exist for this pledge //Acknowledgment, if exist do not add activity. require_once "CRM/Activity/DAO/Activity.php"; $activityType = 'Pledge Acknowledgment'; $activity = new CRM_Activity_DAO_Activity(); $activity->source_record_id = $params['id']; $activity->activity_type_id = CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'); $config = CRM_Core_Config::singleton(); $money = $config->defaultCurrencySymbol; $details = 'Total Amount ' . $money . $params['total_pledge_amount'] . ' To be paid in ' . $params['installments'] . ' installments of ' . $money . $params['scheduled_amount'] . ' every ' . $params['frequency_interval'] . ' ' . $params['frequency_unit'] . '(s)'; if (!$activity->find()) { $activityParams = array('subject' => $subject, 'source_contact_id' => $params['contact_id'], 'source_record_id' => $params['id'], 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($params['acknowledge_date']), 'is_test' => $params['is_test'], 'status_id' => 2, 'details' => $details); require_once 'api/v2/Activity.php'; if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity for acknowledgment"); } } }
/** * Function to 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 int $isInitial is it the first time, campaign page has been created by the user * * @return null * @access public * @static * */ static function sendStatusUpdate($pcpId, $newStatus, $isInitial = FALSE, $component = 'contribute') { $pcpStatus = CRM_PCP_PseudoConstant::pcpStatus(); $config = CRM_Core_Config::singleton(); if (!isset($pcpStatus[$newStatus])) { return FALSE; } require_once 'Mail/mime.php'; //set loginUrl $loginUrl = $config->userFrameworkBaseURL; switch (ucfirst($config->userFramework)) { case 'Joomla': $loginUrl = str_replace('administrator/', '', $loginUrl); $loginUrl .= 'index.php?option=com_users&view=login'; break; case 'Drupal': $loginUrl .= 'user'; break; } // used in subject templates $contribPageTitle = self::getPcpPageTitle($pcpId, $component); $tplParams = array('loginUrl' => $loginUrl, 'contribPageTitle' => $contribPageTitle); //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 » Communications » 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 ($pcpStatus[$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_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => $tplName, 'contactId' => $pcpInfo['contact_id'], 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $name, 'toEmail' => $address)); return $sent; }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ static function postProcess(&$form) { if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) { CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => self::MAX_EMAILS_KILL_SWITCH))); } // check and ensure that $formValues = $form->controller->exportValues($form->getName()); $fromEmail = $formValues['fromEmailAddress']; $from = CRM_Utils_Array::value($fromEmail, $form->_fromEmails); $cc = CRM_Utils_Array::value('cc_id', $formValues); $bcc = CRM_Utils_Array::value('bcc_id', $formValues); $subject = $formValues['subject']; // process message template require_once 'CRM/Core/BAO/MessageTemplates.php'; if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) { $messageTemplate = array('msg_text' => $formValues['text_message'], 'msg_html' => $formValues['html_message'], 'msg_subject' => $formValues['subject'], 'is_active' => true); if ($formValues['saveTemplate']) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; CRM_Core_BAO_MessageTemplates::add($messageTemplate); } if ($formValues['template'] && $formValues['updateTemplate']) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); CRM_Core_BAO_MessageTemplates::add($messageTemplate); } } $attachments = array(); CRM_Core_BAO_File::formatAttachment($formValues, $attachments, null, null); // format contact details array to handle multiple emails from same contact $formattedContactDetails = array(); $tempEmails = array(); foreach ($form->_contactIds as $key => $contactId) { $email = $form->_toContactEmails[$key]; // prevent duplicate emails if same email address is selected CRM-4067 // we should allow same emails for different contacts $emailKey = "{$contactId}::{$email}"; if (!in_array($emailKey, $tempEmails)) { $tempEmails[] = $emailKey; $details = $form->_contactDetails[$contactId]; $details['email'] = $email; unset($details['email_id']); $formattedContactDetails[] = $details; } } // send the mail require_once 'CRM/Activity/BAO/Activity.php'; list($sent, $activityId) = CRM_Activity_BAO_Activity::sendEmail($formattedContactDetails, $subject, $formValues['text_message'], $formValues['html_message'], null, null, $from, $attachments, $cc, $bcc, array_keys($form->_contactDetails)); if ($sent) { $status = array('', ts('Your message has been sent.')); } //Display the name and number of contacts for those email is not sent. $emailsNotSent = array_diff_assoc($form->_allContactDetails, $form->_contactDetails); if (!empty($emailsNotSent)) { $statusOnHold = ''; $statusDisplay = ts('Email not sent to contact(s) (no email address on file or communication preferences specify DO NOT EMAIL or Contact is deceased or Primary email address is On Hold): %1', array(1 => count($emailsNotSent))) . '<br />' . ts('Details') . ': '; foreach ($emailsNotSent as $contactId => $values) { $displayName = $values['display_name']; $email = $values['email']; $contactViewUrl = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactId}"); $statusDisplay .= "<a href='{$contactViewUrl}'>{$displayName}</a>, "; // build separate status for on hold messages if ($values['on_hold']) { $statusOnHold .= ts('Email was not sent to %1 because primary email address (%2) is On Hold.', array(1 => "<a href='{$contactViewUrl}'>{$displayName}</a>", 2 => "<strong>{$email}</strong>")) . '<br />'; } } $status[] = $statusDisplay; } if ($form->_caseId) { // if case-id is found in the url, create case activity record $caseParams = array('activity_id' => $activityId, 'case_id' => $form->_caseId); require_once 'CRM/Case/BAO/Case.php'; CRM_Case_BAO_Case::processCaseActivity($caseParams); } if (strlen($statusOnHold)) { $status[] = $statusOnHold; } CRM_Core_Session::setStatus($status); }
/** * browse all entities. * * @param int $action * * @return void * @access public */ function browse($action = null, $sort) { if ($this->_action & CRM_Core_Action::ADD) { return; } $links = $this->links(); if ($action == null) { if (!empty($links)) { $action = array_sum(array_keys($links)); } } if ($action & CRM_Core_Action::DISABLE) { $action -= CRM_Core_Action::DISABLE; } if ($action & CRM_Core_Action::ENABLE) { $action -= CRM_Core_Action::ENABLE; } $messageTemplate = new CRM_Core_BAO_MessageTemplates(); $messageTemplate->orderBy('msg_title' . ' asc'); $userTemplates = array(); $workflowTemplates = array(); // find all objects $messageTemplate->find(); while ($messageTemplate->fetch()) { $values[$messageTemplate->id] = array(); CRM_Core_DAO::storeValues($messageTemplate, $values[$messageTemplate->id]); // populate action links $this->action($messageTemplate, $action, $values[$messageTemplate->id], $links, CRM_Core_Permission::EDIT); if (!$messageTemplate->workflow_id) { $userTemplates[$messageTemplate->id] = $values[$messageTemplate->id]; } elseif (!$messageTemplate->is_reserved) { $workflowTemplates[$messageTemplate->id] = $values[$messageTemplate->id]; } } $rows = array('userTemplates' => $userTemplates, 'workflowTemplates' => $workflowTemplates); $this->assign('rows', $rows); }
/** * Function to process the renewal form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Member/BAO/Membership.php'; require_once 'CRM/Member/BAO/MembershipType.php'; require_once 'CRM/Member/BAO/MembershipStatus.php'; // get the submitted form values. $this->_params = $formValues = $this->controller->exportValues($this->_name); $params = array(); $ids = array(); $config =& CRM_Core_Config::singleton(); $params['contact_id'] = $this->_contactID; if ($this->_mode) { $formValues['total_amount'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'minimum_fee'); $formValues['contribution_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $this->_memType, 'contribution_type_id'); require_once 'CRM/Core/BAO/PaymentProcessor.php'; $this->_paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($formValues['payment_processor_id'], $this->_mode); require_once "CRM/Contact/BAO/Contact.php"; $now = CRM_Utils_Date::getToday($now, 'YmdHis'); $fields = array(); // set email for primary location. $fields["email-Primary"] = 1; $formValues["email-5"] = $formValues["email-Primary"] = $this->_contributorEmail; $formValues['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 $formValues["address_name-{$this->_bltID}"] = CRM_Utils_Array::value('billing_first_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_middle_name', $formValues) . ' ' . CRM_Utils_Array::value('billing_last_name', $formValues); $formValues["address_name-{$this->_bltID}"] = trim($formValues["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}", $formValues)) { $formValues[$name] = $formValues["billing_{$name}"]; $formValues['preserveDBName'] = true; } } $contactID = CRM_Contact_BAO_Contact::createProfileContact($formValues, $fields, $this->_contactID, null, null, $ctype); // 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'] = $formValues['total_amount']; $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, 'Contribute', $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/membership', "reset=1&action=renew&cid={$this->_contactID}&id={$this->_id}&context=membership&mode={$this->_mode}")); } if ($result) { $this->_params = array_merge($this->_params, $result); } $formValues['contribution_status_id'] = 1; $formValues['receive_date'] = $now; $formValues['invoice_id'] = $this->_params['invoiceID']; $formValues['trxn_id'] = $result['trxn_id']; $formValues['payment_instrument_id'] = 1; $formValues['is_test'] = $this->_mode == 'live' ? 0 : 1; if (CRM_Utils_Array::value('send_receipt', $this->_params)) { $formValues['receipt_date'] = $now; } else { $formValues['receipt_date'] = null; } $this->set('params', $this->_params); $this->assign('trxn_id', $result['trxn_id']); $this->assign('receive_date', CRM_Utils_Date::mysqlToIso($formValues['receive_date'])); } $renewalDate = null; if ($formValues['renewal_date']) { $this->set('renewDate', CRM_Utils_Date::processDate($formValues['renewal_date'])); } $this->_membershipId = $this->_id; // check for test membership. $isTestMembership = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_membershipId, 'is_test'); $renewMembership = CRM_Member_BAO_Membership::renewMembership($this->_contactID, $this->_memType, $isTestMembership, $this, null); $endDate = CRM_Utils_Date::processDate($renewMembership->end_date); require_once 'CRM/Contact/BAO/Contact/Location.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); $memType = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id, 'name'); if (CRM_Utils_Array::value('record_contribution', $formValues) || $this->_mode) { //building contribution params $contributionParams = array(); $config =& CRM_Core_Config::singleton(); $contributionParams['currency'] = $config->defaultCurrency; $contributionParams['contact_id'] = $params['contact_id']; $contributionParams['source'] = "{$memType} Membership: Offline membership renewal (by {$userName})"; $contributionParams['non_deductible_amount'] = 'null'; $contributionParams['receive_date'] = date('Y-m-d H:i:s'); $contributionParams['receipt_date'] = CRM_Utils_Array::value('send_receipt', $formValues) ? $contributionParams['receive_date'] : 'null'; $recordContribution = array('total_amount', 'contribution_type_id', 'payment_instrument_id', 'trxn_id', 'contribution_status_id', 'invoice_id', 'check_number', 'is_test'); foreach ($recordContribution as $f) { $contributionParams[$f] = CRM_Utils_Array::value($f, $formValues); } require_once 'CRM/Contribute/BAO/Contribution.php'; $contribution =& CRM_Contribute_BAO_Contribution::create($contributionParams, $ids); require_once 'CRM/Member/DAO/MembershipPayment.php'; $mpDAO =& new CRM_Member_DAO_MembershipPayment(); $mpDAO->membership_id = $renewMembership->id; $mpDAO->contribution_id = $contribution->id; $mpDAO->save(); if ($this->_mode) { $trxnParams = array('contribution_id' => $contribution->id, 'trxn_date' => $now, 'trxn_type' => 'Debit', 'total_amount' => $formValues['total_amount'], 'fee_amount' => CRM_Utils_Array::value('fee_amount', $result), 'net_amount' => CRM_Utils_Array::value('net_amount', $result, $formValues['total_amount']), 'currency' => $config->defaultCurrency, 'payment_processor' => $this->_paymentProcessor['payment_processor_type'], 'trxn_id' => $result['trxn_id']); require_once 'CRM/Contribute/BAO/FinancialTrxn.php'; $trxn =& CRM_Contribute_BAO_FinancialTrxn::create($trxnParams); } } if (CRM_Utils_Array::value('send_receipt', $formValues)) { require_once 'CRM/Core/DAO.php'; CRM_Core_DAO::setFieldValue('CRM_Member_DAO_MembershipType', CRM_Utils_Array::value('membership_type_id', $params), 'receipt_text_renewal', $formValues['receipt_text_renewal']); } $receiptSend = false; if (CRM_Utils_Array::value('send_receipt', $formValues)) { $receiptSend = true; // Retrieve the name and email of the contact - this will be the TO for receipt email list($this->_contributorDisplayName, $this->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID); $receiptFrom = '"' . $userName . '" <' . $userEmail . '>'; $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $formValues['paidBy'] = $paymentInstrument[$formValues['payment_instrument_id']]; //get the group Tree $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $this->_id, false, $this->_memType); // retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; $customFields = $customValues = $fo = array(); foreach ($this->_groupTree as $groupID => $group) { if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } } CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, false, array(array('member_id', '=', $renewMembership->id, 0, 0))); $this->assign_by_ref('formValues', $formValues); $this->assign('receive_date', $renewalDate); $this->assign('module', 'Membership'); $this->assign('receiptType', 'membership renewal'); $this->assign('mem_start_date', CRM_Utils_Date::customFormat($renewMembership->start_date)); $this->assign('mem_end_date', CRM_Utils_Date::customFormat($renewMembership->end_date)); $this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $renewMembership->membership_type_id)); $this->assign('customValues', $customValues); if ($this->_mode) { if (CRM_Utils_Array::value('billing_first_name', $this->_params)) { $name = $this->_params['billing_first_name']; } if (CRM_Utils_Array::value('billing_middle_name', $this->_params)) { $name .= " {$this->_params['billing_middle_name']}"; } if (CRM_Utils_Array::value('billing_last_name', $this->_params)) { $name .= " {$this->_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($this->_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($this->_params['credit_card_number'])); $this->assign('credit_card_type', $this->_params['credit_card_type']); $this->assign('contributeMode', 'direct'); $this->assign('isAmountzero', 0); $this->assign('is_pay_later', 0); $this->assign('isPrimary', 1); if ($this->_mode == 'test') { $this->assign('action', '1024'); } } require_once 'CRM/Core/BAO/MessageTemplates.php'; list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $this->_contactID, 'from' => $receiptFrom, 'toName' => $this->_contributorDisplayName, 'toEmail' => $this->_contributorEmail, 'isTest' => $this->_mode == 'test')); } $statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $memType, 2 => $this->_contributorDisplayName)); $endDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $this->_id, "end_date")); if ($endDate) { $statusMsg .= ' ' . ts('The new membership End Date is %1.', array(1 => $endDate)); } if ($receiptSend && $mailSend) { $statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(1 => $this->_contributorEmail)); } CRM_Core_Session::setStatus($statusMsg); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_MessageTemplates::del($this->_id); } elseif ($this->_action & CRM_Core_Action::VIEW) { // currently, the above action is used solely for previewing default workflow templates CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1')); } else { $params = array(); // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } if ($this->_workflow_id) { $params['workflow_id'] = $this->_workflow_id; $params['is_active'] = true; } $messageTemplate = CRM_Core_BAO_MessageTemplates::add($params); CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title))); if ($this->_workflow_id) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1')); } } }
/** * Function that sends e-mail copy of activity * * @param int $activityId activity Id * @param array $contacts array of related contact * * @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 (CRM_Utils_Array::value($activityTypeId, $nonCaseActivityTypes)) { $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_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'source_contact_id'); } //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 = $info['display_name']; list($result[$info['contact_id']], $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_case', 'valueName' => 'case_activity', 'contactId' => $info['contact_id'], 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $mail, 'attachments' => $attachments)); $activityParams['subject'] = $activitySubject . ' - copy sent to ' . $displayName; $activityParams['details'] = $message; if ($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[$info['contact_id']]); } } 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; }
/** * Function to send the emails for Recurring Contribution Notication * * @param string $type txnType * @param int $contactID contact id for contributor * @param int $pageID contribution page id * @param object $recur object of recurring contribution table * * @return void * @access public * @static */ static function recurringNofify($type, $contactID, $pageID, $recur) { $value = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array('title', 'is_email_receipt', 'receipt_from_name', 'receipt_from_email', 'cc_receipt', 'bcc_receipt')); if ($value[$pageID]['is_email_receipt']) { $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; require_once 'CRM/Contact/BAO/Contact/Location.php'; list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, false); require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplateParams(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_recurring_notify', 'contactId' => $contactID, 'tplParams' => array('recur_frequency_interval' => $recur->frequency_interval, 'recur_frequency_unit' => $recur->frequency_unit, 'recur_installments' => $recur->installments, 'recur_start_date' => $recur->start_date, 'recur_end_date' => $recur->end_date, 'recur_amount' => $recur->amount, 'recur_txnType' => $type, 'displayName' => $displayName, 'receipt_from_name' => $value[$pageID]['receipt_from_name'], 'receipt_from_email' => $value[$pageID]['receipt_from_email']), 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $email)); if ($sent) { CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); } else { CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); } } }
/** * Function to send email receipt. * * @form object of Contribution form. * @param array $params (reference ) an assoc array of name/value pairs. * @$ccContribution boolen, is it credit card contribution. * @access public. * @return None. */ function emailReceipt(&$form, &$params, $ccContribution = false) { $this->assign('receiptType', 'contribution'); // Retrieve Contribution Type Name from contribution_type_id $params['contributionType_name'] = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionType', $params['contribution_type_id']); if (CRM_Utils_Array::value('payment_instrument_id', $params)) { require_once 'CRM/Contribute/PseudoConstant.php'; $paymentInstrument = CRM_Contribute_PseudoConstant::paymentInstrument(); $params['paidBy'] = $paymentInstrument[$params['payment_instrument_id']]; } // retrieve individual prefix value for honoree if (CRM_Utils_Array::value('hidden_Honoree', $params)) { $individualPrefix = CRM_Core_PseudoConstant::individualPrefix(); $honor = CRM_Core_PseudoConstant::honor(); $params['honor_prefix'] = CRM_Utils_Array::value($params['honor_prefix_id'], $individualPrefix); $params["honor_type"] = CRM_Utils_Array::value($params["honor_type_id"], $honor); } // retrieve premium product name and assigned fulfilled // date to template if (CRM_Utils_Array::value('hidden_Premium', $params)) { if (CRM_Utils_Array::value($params['product_name'][0], $form->_options)) { $params['product_option'] = $form->_options[$params['product_name'][0]][$params['product_name'][1]]; } //fix for crm-4584 if (!empty($params['product_name'])) { require_once 'CRM/Contribute/DAO/Product.php'; $productDAO = new CRM_Contribute_DAO_Product(); $productDAO->id = $params['product_name'][0]; $productDAO->find(true); $params['product_name'] = $productDAO->name; $params['product_sku'] = $productDAO->sku; } $this->assign('fulfilled_date', CRM_Utils_Date::processDate($params['fulfilled_date'])); } $this->assign('ccContribution', $ccContribution); if ($ccContribution) { //build the name. $name = CRM_Utils_Array::value('billing_first_name', $params); if (CRM_Utils_Array::value('billing_middle_name', $params)) { $name .= " {$params['billing_middle_name']}"; } $name .= ' ' . CRM_Utils_Array::value('billing_last_name', $params); $name = trim($name); $this->assign('billingName', $name); //assign the address formatted up for display $addressParts = array("street_address" => "billing_street_address-{$form->_bltID}", "city" => "billing_city-{$form->_bltID}", "postal_code" => "billing_postal_code-{$form->_bltID}", "state_province" => "state_province-{$form->_bltID}", "country" => "country-{$form->_bltID}"); $addressFields = array(); foreach ($addressParts as $name => $field) { $addressFields[$name] = CRM_Utils_Array::value($field, $params); } require_once 'CRM/Utils/Address.php'; $this->assign('address', CRM_Utils_Address::format($addressFields)); $date = CRM_Utils_Date::format($params['credit_card_exp_date']); $date = CRM_Utils_Date::mysqlToIso($date); $this->assign('credit_card_type', CRM_Utils_Array::value('credit_card_type', $params)); $this->assign('credit_card_exp_date', $date); $this->assign('credit_card_number', CRM_Utils_System::mungeCreditCard($params['credit_card_number'])); } else { //offline contribution //Retrieve the name and email from receipt is to be send $params['receipt_from_name'] = $form->userDisplayName; $params['receipt_from_email'] = $form->userEmail; // assigned various dates to the templates $form->assign('receipt_date', CRM_Utils_Date::processDate($params['receipt_date'])); $form->assign('cancel_date', CRM_Utils_Date::processDate($params['cancel_date'])); if (CRM_Utils_Array::value('thankyou_date', $params)) { $form->assign('thankyou_date', CRM_Utils_Date::processDate($params['thankyou_date'])); } if ($form->_action & CRM_Core_Action::UPDATE) { $form->assign('lineItem', empty($form->_lineItems) ? false : $form->_lineItems); } } //handle custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { $contribParams = array(array('contribution_id', '=', $params['contribution_id'], 0, 0)); if ($form->_mode == 'test') { $contribParams[] = array('contribution_test', '=', 1, 0, 0); } //retrieve custom data require_once "CRM/Core/BAO/UFGroup.php"; $customGroup = array(); foreach ($form->_groupTree as $groupID => $group) { $customFields = $customValues = array(); if ($groupID == 'info') { continue; } foreach ($group['fields'] as $k => $field) { $field['title'] = $field['label']; $customFields["custom_{$k}"] = $field; } //build the array of customgroup contain customfields. CRM_Core_BAO_UFGroup::getValues($params['contact_id'], $customFields, $customValues, false, $contribParams); $customGroup[$group['title']] = $customValues; } //assign all custom group and corresponding fields to template. $form->assign('customGroup', $customGroup); } $form->assign_by_ref('formValues', $params); require_once 'CRM/Contact/BAO/Contact/Location.php'; require_once 'CRM/Utils/Mail.php'; list($contributorDisplayName, $contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($params['contact_id']); $this->assign('contactID', $params['contact_id']); $this->assign('contributionID', $params['contribution_id']); $this->assign('currency', $params['currency']); $this->assign('receive_date', CRM_Utils_Date::processDate($params['receive_date'])); $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($userName, $userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($userID); require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sendReceipt, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_offline_receipt', 'contactId' => $params['contact_id'], 'from' => "{$userName} <{$userEmail}>", 'toName' => $contributorDisplayName, 'toEmail' => $contributorEmail, 'isTest' => $form->_mode == 'test')); return $sendReceipt; }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ static function postProcess(&$form) { $formValues = $form->controller->exportValues($form->getName()); // process message template require_once 'CRM/Core/BAO/MessageTemplates.php'; if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) { $messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => true); if ($formValues['saveTemplate']) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; CRM_Core_BAO_MessageTemplates::add($messageTemplate); } if ($formValues['template'] && $formValues['updateTemplate']) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); CRM_Core_BAO_MessageTemplates::add($messageTemplate); } } require_once 'dompdf/dompdf_config.inc.php'; $html = '<html><head><style>body { margin: 56px; }</style></head><body>'; require_once 'api/v2/Contact.php'; require_once 'CRM/Utils/Token.php'; $tokens = array(); CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); $html_message = $formValues['html_message']; //time being hack to strip ' ' //from particular letter line, CRM-6798 self::formatMessage($html_message); require_once 'CRM/Activity/BAO/Activity.php'; $messageToken = CRM_Activity_BAO_Activity::getTokens($html_message); $returnProperties = array(); if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } require_once 'CRM/Mailing/BAO/Mailing.php'; $mailing = new CRM_Mailing_BAO_Mailing(); if (defined('CIVICRM_MAIL_SMARTY')) { require_once 'CRM/Core/Smarty/resources/String.php'; civicrm_smarty_register_string_resource(); } $first = TRUE; foreach ($form->_contactIds as $item => $contactId) { $params = array('contact_id' => $contactId); list($contact) = $mailing->getDetails($params, $returnProperties, false); if (civicrm_error($contact)) { $notSent[] = $contactId; continue; } $tokenHtml = CRM_Utils_Token::replaceContactTokens($html_message, $contact[$contactId], true, $messageToken); $tokenHtml = CRM_Utils_Token::replaceHookTokens($tokenHtml, $contact[$contactId], $categories, true); if (defined('CIVICRM_MAIL_SMARTY')) { $smarty = CRM_Core_Smarty::singleton(); // also add the contact tokens to the template $smarty->assign_by_ref('contact', $contact); $tokenHtml = $smarty->fetch("string:{$tokenHtml}"); } if ($first == TRUE) { $first = FALSE; $html .= $tokenHtml; } else { $html .= "<div STYLE='page-break-after: always'></div>{$tokenHtml}"; } } $html .= '</body></html>'; require_once 'CRM/Activity/BAO/Activity.php'; $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Print PDF Letter', 'name'); $activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'details' => $html_message); if ($form->_activityId) { $activityParams += array('id' => $form->_activityId); } if ($form->_cid) { $activity = CRM_Activity_BAO_Activity::create($activityParams); } else { // create Print PDF activity for each selected contact. CRM-6886 $activityIds = array(); foreach ($form->_contactIds as $contactId) { $activityID = CRM_Activity_BAO_Activity::create($activityParams); $activityIds[$contactId] = $activityID->id; } } foreach ($form->_contactIds as $contactId) { $activityTargetParams = array('activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id, 'target_contact_id' => $contactId); CRM_Activity_BAO_Activity::createActivityTarget($activityTargetParams); } require_once 'CRM/Utils/PDF/Utils.php'; CRM_Utils_PDF_Utils::html2pdf($html, "CiviLetter.pdf", 'portrait', 'letter'); // we need to call the hook manually here since we redirect and never // go back to CRM/Core/Form.php CRM_Utils_Hook::postProcess(get_class($form), $form); CRM_Utils_System::civiExit(1); }
/** * Sends a template. */ function civicrm_api3_message_template_send($params) { CRM_Core_BAO_MessageTemplates::sendTemplate($params); }
/** * takes an associative array and sends a thank you or email verification email * * @param array $params (reference ) an assoc array of name/value pairs * * @return * @access public * @static */ function sendEmail($params, $sendEmailMode) { /* sendEmailMode * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK * connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * or login using fb connect - thank you + click to add msg to fb wall * * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM * send a confirmation request email */ require_once 'CRM/Campaign/Form/Petition/Signature.php'; // define constant CIVICRM_PETITION_CONTACTS, if not exist in civicrm.settings.php if (!defined('CIVICRM_PETITION_CONTACTS')) { define('CIVICRM_PETITION_CONTACTS', 'Petition Contacts'); } // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it require_once 'api/v2/Group.php'; $group_params['title'] = CIVICRM_PETITION_CONTACTS; $groups = civicrm_group_get($group_params); if (CRM_Utils_Array::value('is_error', $groups) == 1 && CRM_Utils_Array::value('error_message', $groups) == 'No such group exists') { $group_params['is_active'] = 1; $group_params['visibility'] = 'Public Pages'; $newgroup = civicrm_group_add($group_params); if ($newgroup['is_error'] == 0) { $group_id[0] = $newgroup['result']; } } else { $group_id = array_keys($groups); } // get petition info $petitionParams['id'] = $params['sid']; $petitionInfo = array(); CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } require_once 'CRM/Core/BAO/Domain.php'; //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); require_once 'CRM/Contact/BAO/Contact.php'; $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']); $replyTo = "do-not-reply@{$emailDomain}"; // set additional general message template params (custom tokens to use in email msg templates) // tokens then available in msg template as {$petition.title}, etc $petitionTokens['title'] = $petitionInfo['title']; $petitionTokens['petitionId'] = $params['sid']; $tplParams['petition'] = $petitionTokens; switch ($sendEmailMode) { case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK: //add this contact to the CIVICRM_PETITION_CONTACTS group require_once 'api/v2/GroupContact.php'; $params['group_id'] = $group_id[0]; $params['contact_id'] = $params['contactId']; civicrm_group_contact_add($params); require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'])); } break; case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM: // create mailing event subscription record for this contact // this will allow using a hash key to confirm email address by sending a url link require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id[0], $params['email-Primary'], $params['contactId']); // require_once 'CRM/Core/BAO/Domain.php'; // $domain =& CRM_Core_BAO_Domain::getDomain(); $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); require_once 'CRM/Utils/Verp.php'; $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}"; $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true); $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true, null, false); // set email specific message template params and assign to tplParams $petitionTokens['confirmUrl'] = $confirmUrl; $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText; $tplParams['petition'] = $petitionTokens; require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl)); } break; } }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues(); $checkBoxes = array('is_thermometer', 'is_honor_roll', 'is_active'); foreach ($checkBoxes as $key) { if (!isset($params[$key])) { $params[$key] = 0; } } $session =& CRM_Core_Session::singleton(); $contactID = isset($this->_contactID) ? $this->_contactID : $session->get('userID'); if (!$contactID) { $contactID = $this->get('contactID'); } $params['contact_id'] = $contactID; $params['contribution_page_id'] = $this->get('contribution_page_id') ? $this->get('contribution_page_id') : $this->_contriPageId; $params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']); $approval_needed = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCPBlock', $params['contribution_page_id'], 'is_approval_needed', 'entity_id'); $approvalMessage = null; if ($this->get('action') & CRM_Core_Action::ADD) { $params['status_id'] = $approval_needed ? 1 : 2; $approvalMessage = $approval_needed ? ts('but requires administrator review before you can begin your fundraising efforts. You will receive an email confirmation shortly which includes a link to return to your fundraising page.') : ts('and is ready to use.'); } $params['id'] = $this->_pageId; require_once 'CRM/Contribute/BAO/PCP.php'; $pcp = CRM_Contribute_BAO_PCP::add($params, false); // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_pcp', $pcp->id); $pageStatus = isset($this->_pageId) ? ts('updated') : ts('created'); $statusId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_PCP', $pcp->id, 'status_id'); //send notification of PCP create/update. $pcpParams = array('entity_table' => 'civicrm_contribution_page', 'entity_id' => $pcp->contribution_page_id); $notifyParams = array(); $notifyStatus = ""; CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_PCPBlock', $pcpParams, $notifyParams, array('notify_email')); if ($emails = CRM_Utils_Array::value('notify_email', $notifyParams)) { $this->assign('pcpTitle', $pcp->title); if ($this->_pageId) { $this->assign('mode', 'Update'); } else { $this->assign('mode', 'Add'); } require_once 'CRM/Core/OptionGroup.php'; $pcpStatus = CRM_Core_OptionGroup::getLabel('pcp_status', $statusId); $this->assign('pcpStatus', $pcpStatus); $this->assign('pcpId', $pcp->id); $supporterUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid={$pcp->contact_id}", true, null, true, true); $this->assign('supporterUrl', $supporterUrl); $supporterName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $pcp->contact_id, 'display_name'); $this->assign('supporterName', $supporterName); $contribPageUrl = CRM_Utils_System::url("civicrm/contribute/transact", "reset=1&id={$pcp->contribution_page_id}", true, null, true, true); $this->assign('contribPageUrl', $contribPageUrl); $contribPageTitle = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $pcp->contribution_page_id, 'title'); $this->assign('contribPageTitle', $contribPageTitle); $managePCPUrl = CRM_Utils_System::url("civicrm/admin/pcp", "reset=1", true, null, true, true); $this->assign('managePCPUrl', $managePCPUrl); //get the default domain email address. require_once 'CRM/Core/BAO/Domain.php'; list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') { CRM_Core_Error::fatal(ts('The site administrator needs to enter a valid \'FROM Email Address\' in Administer CiviCRM » Configure » Domain Information. The email address used may need to be a valid mail account with your email service provider.')); } //if more than one email present for PCP notification , //first email take it as To and other as CC and First email //address should be sent in users email receipt for //support purpose. $emailArray = explode(',', $emails); $to = $emailArray[0]; unset($emailArray[0]); $cc = implode(',', $emailArray); require_once 'CRM/Core/BAO/MessageTemplates.php'; list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'pcp_notify', 'contactId' => $contactID, 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $to, 'cc' => $cc)); if ($sent) { $notifyStatus = ts('A notification email has been sent to the site administrator.'); } } CRM_Core_BAO_File::processAttachment($params, 'civicrm_pcp', $pcp->id); // send email notification to supporter, if initial setup / add mode. if (!$this->_pageId) { CRM_Contribute_BAO_PCP::sendStatusUpdate($pcp->id, $statusId, true); if ($approvalMessage && CRM_Utils_Array::value('status_id', $params) == 1) { $notifyStatus .= ts(' You will receive a second email as soon as the review process is complete.'); } } //check if pcp created by anonymous user $anonymousPCP = 0; if (!$session->get('userID')) { $anonymousPCP = 1; } CRM_Core_Session::setStatus(ts("Your Personal Campaign Page has been %1 %2 %3", array(1 => $pageStatus, 2 => $approvalMessage, 3 => $notifyStatus))); if (!$this->_pageId) { $session->pushUserContext(CRM_Utils_System::url('civicrm/contribute/pcp/info', "reset=1&id={$pcp->id}&ap={$anonymousPCP}")); } }
/** * Function to build the compose PDF letter form * * @param $form * * @return None * @access public */ public function commonLetterCompose(&$form) { //get the tokens. $tokens = CRM_Core_SelectValues::contactTokens(); if (CRM_Utils_System::getClassName($form) == 'CRM_Mailing_Form_Upload') { $tokens = array_merge(CRM_Core_SelectValues::mailingTokens(), $tokens); } if (CRM_Utils_System::getClassName($form) == 'CRM_Contribute_Form_Task_PDFLetter') { $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens); } //sorted in ascending order tokens by ignoring word case natcasesort($tokens); $form->assign('tokens', json_encode($tokens)); $form->add('select', 'token1', ts('Insert Tokens'), $tokens, FALSE, array('size' => "5", 'multiple' => TRUE, 'onchange' => "return tokenReplHtml(this);")); $form->_templates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(FALSE); if (!empty($form->_templates)) { $form->assign('templates', TRUE); $form->add('select', 'template', ts('Select Template'), array('' => ts('- select -')) + $form->_templates, FALSE, array('onChange' => "selectValue( this.value );")); $form->add('checkbox', 'updateTemplate', ts('Update Template'), NULL); } $form->add('checkbox', 'saveTemplate', ts('Save As New Template'), NULL, FALSE, array('onclick' => "showSaveDetails(this);")); $form->add('text', 'saveTemplateName', ts('Template Title')); $form->addWysiwyg('html_message', ts('Your Letter'), array('cols' => '80', 'rows' => '8', 'onkeyup' => "return verify(this)")); $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE); if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Task_PDF' && $action == CRM_Core_Action::VIEW) { $form->freeze('html_message'); } }
/** * Function that sends e-mail copy of activity * * @param int $activityId activity Id * @param array $contacts array of related contact * * @return void * @access public */ static function sendActivityCopy($clientId, $activityId, $contacts, $attachments = null, $caseId) { if (!$activityId) { return; } require_once 'CRM/Utils/Mail.php'; require_once 'CRM/Contact/BAO/Contact/Location.php'; $tplParams = array(); $activityInfo = array(); //if its a case activity if ($caseId) { $anyActivity = false; $tplParams['isCaseActivity'] = 1; } else { $anyActivity = true; } require_once 'CRM/Case/XMLProcessor/Report.php'; $xmlProcessor = new CRM_Case_XMLProcessor_Report(); $activityInfo = $xmlProcessor->getActivityInfo($clientId, $activityId, $anyActivity); if ($caseId) { $activityInfo['fields'][] = array('label' => 'Case ID', 'type' => 'String', 'value' => $caseId); } $tplParams['activity'] = $activityInfo; $activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityId, 'subject'); $session =& CRM_Core_Session::singleton(); //also create activities simultaneously of this copy. require_once "CRM/Activity/BAO/Activity.php"; $activityParams = array(); $activityParams['source_record_id'] = $activityId; $activityParams['source_contact_id'] = $session->get('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; $tplParams['activitySubject'] = $activitySubject; $result = array(); list($name, $address) = CRM_Contact_BAO_Contact_Location::getEmailDetails($session->get('userID')); $receiptFrom = "{$name} <{$address}>"; foreach ($contacts as $mail => $info) { $tplParams['contact'] = $info; if (!CRM_Utils_Array::value('sort_name', $info)) { $info['sort_name'] = $info['display_name']; } $displayName = $info['sort_name']; require_once 'CRM/Core/BAO/MessageTemplates.php'; list($result[$info['contact_id']], $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_case', 'valueName' => 'case_activity', 'contactId' => $info['contact_id'], 'tplParams' => $tplParams, 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $mail, 'attachments' => $attachments)); $activityParams['subject'] = $activitySubject . ' - copy sent to ' . $displayName; $activityParams['details'] = $message; $activityParams['target_contact_id'] = $info['contact_id']; if ($result[$info['contact_id']]) { $activity = CRM_Activity_BAO_Activity::create($activityParams); //create case_activity record if its case activity. if ($caseId) { $caseParams = array('activity_id' => $activity->id, 'case_id' => $caseId); self::processCaseActivity($caseParams); } } else { unset($result[$info['contact_id']]); } } return $result; }
/** * Version agnostic receipt sending function. * * @param array $params */ function _sendReceipt($params) { if (_versionAtLeast(4.4)) { list($sent) = CRM_Core_BAO_MessageTemplate::sendTemplate($params); } else { list($sent) = CRM_Core_BAO_MessageTemplates::sendTemplate($params); } return $sent; }
/** * Function to send email receipt * * @param object $form form object * @param array $values submitted values * @param object $membership object * * @return boolean true if mail was sent successfully * @static */ static function emailReceipt(&$form, &$formValues, &$membership) { // retrieve 'from email id' for acknowledgement $receiptFrom = $formValues['from_email_address']; if (CRM_Utils_Array::value('payment_instrument_id', $formValues)) { $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 (CRM_Utils_Array::value('billing_first_name', $form->_params)) { $name = $form->_params['billing_first_name']; } if (CRM_Utils_Array::value('billing_middle_name', $form->_params)) { $name .= " {$form->_params['billing_middle_name']}"; } if (CRM_Utils_Array::value('billing_last_name', $form->_params)) { $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 (CRM_Utils_Array::value('contribution_id', $formValues)) { $form->assign('contributionID', $formValues['contribution_id']); } else { $form->assign('contributionID', $form->_onlinePendingContributionId); } if (CRM_Utils_Array::value('contribution_status_id', $formValues)) { $form->assign('contributionStatusID', $formValues['contribution_status_id']); $form->assign('contributionStatus', CRM_Contribute_PseudoConstant::contributionStatus($formValues['contribution_status_id'], 'name')); } if (CRM_Utils_Array::value('is_renew', $formValues)) { $form->assign('receiptType', 'membership renewal'); } else { $form->assign('receiptType', 'membership signup'); } $form->assign('receive_date', 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')); $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']; } } list($mailSend, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_membership', 'valueName' => 'membership_offline_receipt', 'contactId' => $form->_receiptContactId, 'from' => $receiptFrom, 'toName' => $form->_contributorDisplayName, 'toEmail' => $form->_contributorEmail, 'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW))); return true; }
/** * Function to send the emails for Recurring Contribution Notication * * @param string $type txnType * @param int $contactID contact id for contributor * @param int $pageID contribution page id * @param object $recur object of recurring contribution table * @param object $autoRenewMembership is it a auto renew membership. * * @return void * @access public * @static */ static function recurringNotify($type, $contactID, $pageID, $recur, $autoRenewMembership = FALSE) { $value = array(); if ($pageID) { CRM_Core_DAO::commonRetrieveAll('CRM_Contribute_DAO_ContributionPage', 'id', $pageID, $value, array('title', 'is_email_receipt', 'receipt_from_name', 'receipt_from_email', 'cc_receipt', 'bcc_receipt')); } $isEmailReceipt = CRM_Utils_Array::value('is_email_receipt', $value[$pageID]); $isOfflineRecur = FALSE; if (!$pageID && $recur->id) { $isOfflineRecur = TRUE; } if ($isEmailReceipt || $isOfflineRecur) { if ($pageID) { $receiptFrom = '"' . CRM_Utils_Array::value('receipt_from_name', $value[$pageID]) . '" <' . $value[$pageID]['receipt_from_email'] . '>'; $receiptFromName = $value[$pageID]['receipt_from_name']; $receiptFromEmail = $value[$pageID]['receipt_from_email']; } else { $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $receiptFrom = "{$domainValues['0']} <{$domainValues['1']}>"; $receiptFromName = $domainValues[0]; $receiptFromEmail = $domainValues[1]; } list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID, FALSE); $templatesParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_recurring_notify', 'contactId' => $contactID, 'tplParams' => array('recur_frequency_interval' => $recur->frequency_interval, 'recur_frequency_unit' => $recur->frequency_unit, 'recur_installments' => $recur->installments, 'recur_start_date' => $recur->start_date, 'recur_end_date' => $recur->end_date, 'recur_amount' => $recur->amount, 'recur_txnType' => $type, 'displayName' => $displayName, 'receipt_from_name' => $receiptFromName, 'receipt_from_email' => $receiptFromEmail, 'auto_renew_membership' => $autoRenewMembership), 'from' => $receiptFrom, 'toName' => $displayName, 'toEmail' => $email); if ($recur->id) { // in some cases its just recurringNotify() thats called for the first time and these urls don't get set. // like in PaypalPro, & therefore we set it here additionally. $template = CRM_Core_Smarty::singleton(); $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getProcessorForEntity($recur->id, 'recur', 'obj'); $url = $paymentProcessor->subscriptionURL($recur->id, 'recur'); $template->assign('cancelSubscriptionUrl', $url); $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'billing'); $template->assign('updateSubscriptionBillingUrl', $url); $url = $paymentProcessor->subscriptionURL($recur->id, 'recur', 'update'); $template->assign('updateSubscriptionUrl', $url); } list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate($templatesParams); if ($sent) { CRM_Core_Error::debug_log_message('Success: mail sent for recurring notification.'); } else { CRM_Core_Error::debug_log_message('Failure: mail not sent for recurring notification.'); } } }
/** * Process that send notification e-mails * * @params int $contactId contact id * @params array $values associative array of name/value pair * @return void * @access public */ static function commonSendMail($contactID, &$values) { if (!$contactID || !$values) { return; } $template =& CRM_Core_Smarty::singleton(); $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'display_name'); self::profileDisplay($values['id'], $values['values'], $template); $emailList = explode(',', $values['email']); $contactLink = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$contactID}", true, null, false); //get the default domain email address. require_once 'CRM/Core/BAO/Domain.php'; list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); if (!$domainEmailAddress || $domainEmailAddress == '*****@*****.**') { require_once 'CRM/Utils/System.php'; $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 » Configure » Domain Information</a>. The email address used may need to be a valid mail account with your email service provider.', array(1 => $fixUrl))); } require_once 'CRM/Core/BAO/MessageTemplates.php'; foreach ($emailList as $emailTo) { // FIXME: take the below out of the foreach loop CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_uf', 'valueName' => 'uf_notify', 'contactId' => $contactID, 'tplParams' => array('displayName' => $displayName, 'currentDate' => date('r'), 'contactLink' => $contactLink), 'from' => "{$domainEmailName} <{$domainEmailAddress}>", 'toEmail' => $emailTo)); } }
/** * part of the post process which prepare and extract information from the template * * @access protected * * @return array( $categories, $html_message, $messageToken, $returnProperties ) */ protected static function processMessageTemplate(&$form) { $formValues = $form->controller->exportValues($form->getName()); // process message template if (CRM_Utils_Array::value('saveTemplate', $formValues) || CRM_Utils_Array::value('updateTemplate', $formValues)) { $messageTemplate = array('msg_text' => NULL, 'msg_html' => $formValues['html_message'], 'msg_subject' => NULL, 'is_active' => TRUE); $messageTemplate['pdf_format_id'] = 'null'; if (CRM_Utils_Array::value('bind_format', $formValues) && $formValues['format_id'] > 0) { $messageTemplate['pdf_format_id'] = $formValues['format_id']; } if (CRM_Utils_Array::value('saveTemplate', $formValues) && $formValues['saveTemplate']) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; CRM_Core_BAO_MessageTemplates::add($messageTemplate); } if (CRM_Utils_Array::value('updateTemplate', $formValues) && $formValues['template'] && $formValues['updateTemplate']) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); CRM_Core_BAO_MessageTemplates::add($messageTemplate); } } elseif (CRM_Utils_Array::value('template', $formValues) > 0) { if (CRM_Utils_Array::value('bind_format', $formValues) && $formValues['format_id'] > 0) { $query = "UPDATE civicrm_msg_template SET pdf_format_id = {$formValues['format_id']} WHERE id = {$formValues['template']}"; } else { $query = "UPDATE civicrm_msg_template SET pdf_format_id = NULL WHERE id = {$formValues['template']}"; } CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } if (CRM_Utils_Array::value('update_format', $formValues)) { $bao = new CRM_Core_BAO_PdfFormat(); $bao->savePdfFormat($formValues, $formValues['format_id']); } $html = array(); $tokens = array(); CRM_Utils_Hook::tokens($tokens); $categories = array_keys($tokens); $html_message = $formValues['html_message']; //time being hack to strip ' ' //from particular letter line, CRM-6798 self::formatMessage($html_message); $messageToken = CRM_Utils_Token::getTokens($html_message); $returnProperties = array(); if (isset($messageToken['contact'])) { foreach ($messageToken['contact'] as $key => $value) { $returnProperties[$value] = 1; } } return array($formValues, $categories, $html_message, $messageToken, $returnProperties); }
/** * Function to send mail and create activity * when participant status changed. * * @param int $participantId participant id. * @param array $participantValues participant detail values. status id for participants * @param array $eventDetails required event details * @param array $contactDetails required contact details * @param array $domainValues required domain values. * @param string $mailType (eg 'approval', 'confirm', 'expired' ) * * return void * @access public * @static */ function sendTransitionParticipantMail($participantId, $participantValues, $eventDetails, $contactDetails, &$domainValues, $mailType) { //send emails. $mailSent = false; //don't send confirmation mail to additional //since only primary able to confirm registration. if (CRM_Utils_Array::value('registered_by_id', $participantValues) && $mailType == 'Confirm') { return $mailSent; } if ($toEmail = CRM_Utils_Array::value('email', $contactDetails)) { $contactId = $participantValues['contact_id']; $participantName = $contactDetails['display_name']; //calculate the checksum value. $checksumValue = null; if ($mailType == 'Confirm' && !$participantValues['registered_by_id']) { require_once 'CRM/Utils/Date.php'; require_once 'CRM/Contact/BAO/Contact/Utils.php'; $checksumLife = 'inf'; if ($endDate = CRM_Utils_Array::value('end_date', $eventDetails)) { $checksumLife = (CRM_Utils_Date::unixTime($endDate) - time()) / (60 * 60); } $checksumValue = CRM_Contact_BAO_Contact_Utils::generateChecksum($contactId, null, $checksumLife); } //take a receipt from as event else domain. $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>'; if (CRM_Utils_Array::value('confirm_from_name', $eventDetails) && CRM_Utils_Array::value('confirm_from_email', $eventDetails)) { $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>'; } require_once 'CRM/Core/BAO/MessageTemplates.php'; list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'participant_' . strtolower($mailType), 'contactId' => $contactId, 'tplParams' => array('contact' => $contactDetails, 'domain' => $domainValues, 'participant' => $participantValues, 'event' => $eventDetails, 'paidEvent' => CRM_Utils_Array::value('is_monetary', $eventDetails), 'isShowLocation' => CRM_Utils_Array::value('is_show_location', $eventDetails), 'isAdditional' => $participantValues['registered_by_id'], 'isExpired' => $mailType == 'Expired', 'isConfirm' => $mailType == 'Confirm', 'checksumValue' => $checksumValue), 'from' => $receiptFrom, 'toName' => $participantName, 'toEmail' => $toEmail, 'cc' => CRM_Utils_Array::value('cc_confirm', $eventDetails), 'bcc' => CRM_Utils_Array::value('bcc_confirm', $eventDetails))); // 3. create activity record. if ($mailSent) { $now = date('YmdHis'); $activityType = 'Event Registration'; $activityParams = array('subject' => $subject, 'source_contact_id' => $contactId, 'source_record_id' => $participantId, 'activity_type_id' => CRM_Core_OptionGroup::getValue('activity_type', $activityType, 'name'), 'activity_date_time' => CRM_Utils_Date::isoToMysql($now), 'due_date_time' => CRM_Utils_Date::isoToMysql($participantValues['register_date']), 'is_test' => $participantValues['is_test'], 'status_id' => 2); require_once 'api/v2/Activity.php'; if (is_a(civicrm_activity_create($activityParams), 'CRM_Core_Error')) { CRM_Core_Error::fatal("Failed creating Activity for expiration mail"); } } } return $mailSent; }
/** * Process that send tell a friend e-mails * * @params int $contactId contact id * @params array $values associative array of name/value pair * * @return void * @access public */ static function sendMail($contactID, &$values) { list($fromName, $email) = CRM_Contact_BAO_Contact::getContactDetails($contactID); // if no $fromName (only email collected from originating contact) - list returns single space if (trim($fromName) == '') { $fromName = $email; } // use contact email, CRM-4963 if (!CRM_Utils_Array::value('email_from', $values)) { $values['email_from'] = $email; } foreach ($values['email'] as $displayName => $emailTo) { if ($emailTo) { // FIXME: factor the below out of the foreach loop CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_friend', 'valueName' => 'friend', 'contactId' => $contactID, 'tplParams' => array($values['module'] => $values['module'], 'senderContactName' => $fromName, 'title' => $values['title'], 'generalLink' => $values['general_link'], 'pageURL' => $values['page_url'], 'senderMessage' => $values['message']), 'from' => "{$fromName} (via {$values['domain']}) <{$values['email_from']}>", 'toName' => $displayName, 'toEmail' => $emailTo, 'replyTo' => $email)); } } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { parent::buildQuickForm(); if ($this->_action & CRM_Core_Action::DELETE) { return; } $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'name'), TRUE); $this->addRule('name', ts('A membership type with this name already exists. Please select another name.'), 'objectExists', array('CRM_Member_DAO_MembershipType', $this->_id)); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'description')); $this->add('text', 'minimum_fee', ts('Minimum Fee'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'minimum_fee')); $this->addRule('minimum_fee', ts('Please enter a monetary value for the Minimum Fee.'), 'money'); $this->addElement('select', 'duration_unit', ts('Duration') . ' ', CRM_Core_SelectValues::unitList('duration'), array('onchange' => 'showHidePeriodSettings()')); //period type $this->addElement('select', 'period_type', ts('Period Type'), CRM_Core_SelectValues::periodType(), array('onchange' => 'showHidePeriodSettings()')); $this->add('text', 'duration_interval', ts('Duration Interval'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'duration_interval')); $memberOrg =& $this->add('text', 'member_org', ts('Membership Organization'), 'size=30 maxlength=120'); //start day $this->add('date', 'fixed_period_start_day', ts('Fixed Period Start Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); $msgTemplates = CRM_Core_BAO_MessageTemplates::getMessageTemplates(FALSE); $hasMsgTemplates = FALSE; if (!empty($msgTemplates)) { $hasMsgTemplates = TRUE; } //Auto-renew Option $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1'); $isAuthorize = FALSE; $options = array(); $allowAutoRenewMsg = FALSE; if (is_array($paymentProcessor) && !empty($paymentProcessor)) { $isAuthorize = TRUE; $options = array(ts('No auto-renew option'), ts('Give option, but not required'), ts('Auto-renew required ')); if ($hasMsgTemplates) { $allowAutoRenewMsg = TRUE; $autoRenewReminderMsg = $this->add('select', 'autorenewal_msg_id', ts('Auto-renew Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } } $this->addRadio('auto_renew', ts('Auto-renew Option'), $options, array('onclick' => "setReminder(this.value);")); $this->assign('authorize', $isAuthorize); $this->assign('allowAutoRenewMsg', $allowAutoRenewMsg); //rollover day $this->add('date', 'fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'M d'), FALSE); // required in form rule $this->add('hidden', 'action', $this->_action); $this->add('select', 'contribution_type_id', ts('Contribution Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType()); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); if (is_array($relTypeInd)) { asort($relTypeInd); } $memberRel =& $this->add('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $relTypeInd); $memberRel->setMultiple(TRUE); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::memberVisibility()); $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'weight')); $this->add('checkbox', 'is_active', ts('Enabled?')); if ($hasMsgTemplates) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); } $this->assign('hasMsgTemplates', $hasMsgTemplates); $reminderDay =& $this->add('text', 'renewal_reminder_day', ts('Renewal Reminder Day'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_MembershipType', 'renewal_reminder_day')); $searchRows = $this->get('searchRows'); $searchCount = $this->get('searchCount'); $searchDone = $this->get('searchDone'); if ($searchRows) { $checkBoxes = array(); $chekFlag = 0; foreach ($searchRows as $id => $row) { $checked = ''; if (!$chekFlag) { $checked = array('checked' => NULL); $chekFlag++; } $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id, $checked); } $this->addGroup($checkBoxes, 'contact_check'); $this->assign('searchRows', $searchRows); } $this->assign('searchCount', $searchCount); $this->assign('searchDone', $searchDone); if ($searchDone) { $searchBtn = ts('Search Again'); } elseif ($this->_action & CRM_Core_Action::UPDATE) { $searchBtn = ts('Change'); } else { $searchBtn = ts('Search'); } $membershipRecords = FALSE; if ($this->_action & CRM_Core_Action::UPDATE) { $membershipType = new CRM_Member_BAO_Membership(); $membershipType->membership_type_id = $this->_id; if ($membershipType->find(TRUE)) { $membershipRecords = TRUE; $memberRel->freeze(); } $memberOrg->freeze(); if ($searchDone) { $memberOrg->unfreeze(); } } $this->assign('membershipRecordsExists', $membershipRecords); if ($this->_action & CRM_Core_Action::UPDATE && $reminderDay) { $renewMessage = array(); $returnProperties = array('renewal_msg_id', 'renewal_reminder_day'); CRM_Core_DAO::commonRetrieveAll('CRM_Member_DAO_MembershipType', 'id', $this->_id, $renewMessage, $returnProperties); if (CRM_Utils_Array::value('renewal_msg_id', $renewMessage[$this->_id]) && CRM_Utils_Array::value('renewal_reminder_day', $renewMessage[$this->_id]) && $membershipRecords) { $reminderMsg = $this->add('select', 'renewal_msg_id', ts('Renewal Reminder Message'), array('' => ts('- select -')) + $msgTemplates); $reminderDay->freeze(); } } $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit')); $this->addFormRule(array('CRM_Member_Form_MembershipType', 'formRule')); $this->assign('membershipTypeId', $this->_id); }
/** * Process that send e-mails * * @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 (CRM_Utils_Array::value('additionalParticipant', $values['params'])) { $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' => NULL, 'participantID' => $participantId, 'conference_sessions' => $sessions)); $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_event', 'valueName' => 'event_online_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => $tplParams, 'PDFFilename' => 'eventReceipt.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 (CRM_Utils_Array::value('additionalParticipant', $values['params'])) { $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_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); } } } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete reminder CRM_Core_BAO_ActionSchedule::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.')); if ($this->_context == 'event' && $this->_eventId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } return; } $values = $this->controller->exportValues($this->getName()); $keys = array('title', 'subject', 'absolute_date', 'group_id'); foreach ($keys as $key) { $params[$key] = CRM_Utils_Array::value($key, $values); } $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date'); if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) { $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate); foreach ($moreKeys as $mkey) { $params[$mkey] = 'null'; } } else { $params['absolute_date'] = 'null'; foreach ($moreKeys as $mkey) { $params[$mkey] = CRM_Utils_Array::value($mkey, $values); } } $params['body_text'] = CRM_Utils_Array::value('text_message', $values); $params['body_html'] = CRM_Utils_Array::value('html_message', $values); if (CRM_Utils_Array::value('recipient', $values) == 'manual') { $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values); $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') { $params['group_id'] = $values['group_id']; $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values)); $params['group_id'] = $params['recipient_manual'] = 'null'; } else { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null'; } $params['mapping_id'] = $values['entity'][0]; $entity_value = $values['entity'][1]; $entity_status = $values['entity'][2]; //force recording activity for membership reminder if ($params['mapping_id'] == 4) { $params['record_activity'] = 1; } foreach (array('entity_value', 'entity_status') as $key) { $params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, ${$key}); } $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0); $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); if (CRM_Utils_Array::value('is_repeat', $values) == 0) { $params['repetition_frequency_unit'] = 'null'; $params['repetition_frequency_interval'] = 'null'; $params['end_frequency_unit'] = 'null'; $params['end_frequency_interval'] = 'null'; $params['end_action'] = 'null'; $params['end_date'] = 'null'; } if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } elseif ($this->_action & CRM_Core_Action::ADD) { // we do this only once, so name never changes $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); } $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName'); $msgTemplate = NULL; //mail template is composed $composeParams = array(); foreach ($composeFields as $key) { if (CRM_Utils_Array::value($key, $values)) { $composeParams[$key] = $values[$key]; } } if (CRM_Utils_Array::value('updateTemplate', $composeParams)) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['id'] = $values['template']; $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams); } if (CRM_Utils_Array::value('saveTemplate', $composeParams)) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['msg_title'] = $composeParams['saveTemplateName']; $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams); } if (isset($msgTemplate->id)) { $params['msg_template_id'] = $msgTemplate->id; } else { $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); } CRM_Core_BAO_ActionSchedule::add($params, $ids); $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts("Your Reminder titled %1 has been updated.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_context == 'event' && $this->_eventId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } } CRM_Core_Session::setStatus($status); }
/** * Function for validation * * @param array $params (ref.) an assoc array of name/value pairs * * @return mixed true or array of errors * @access public * @static */ static function formRule($params, $files, $self) { if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST)) { return TRUE; } $errors = array(); $template = CRM_Core_Smarty::singleton(); $domain = CRM_Core_BAO_Domain::getDomain(); $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $self->_mailingID; $mailing->find(TRUE); $session = CRM_Core_Session::singleton(); $values = array('contact_id' => $session->get('userID'), 'version' => 3); require_once 'api/api.php'; $contact = civicrm_api('contact', 'get', $values); //CRM-4524 $contact = reset($contact['values']); $verp = array_flip(array('optOut', 'reply', 'unsubscribe', 'resubscribe', 'owner')); foreach ($verp as $key => $value) { $verp[$key]++; } $urls = array_flip(array('forward', 'optOutUrl', 'unsubscribeUrl', 'resubscribeUrl')); foreach ($urls as $key => $value) { $urls[$key]++; } $skipTextFile = $self->get('skipTextFile'); if (!$params['upload_type']) { if (!isset($files['textFile']) || !file_exists($files['textFile']['tmp_name'])) { if (!$skipTextFile) { $errors['textFile'] = ts('Please provide a Text'); } } } else { if (!CRM_Utils_Array::value('text_message', $params)) { $errors['text_message'] = ts('Please provide a Text'); } else { if (CRM_Utils_Array::value('text_message', $params)) { $messageCheck = CRM_Utils_Array::value('text_message', $params); if ($messageCheck && strlen($messageCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) { $errors['text_message'] = ts("You can configure the SMS message body up to %1 characters", array(1 => CRM_SMS_Provider::MAX_SMS_CHAR)); } } } if (CRM_Utils_Array::value('saveTemplate', $params) && !CRM_Utils_Array::value('saveTemplateName', $params)) { $errors['saveTemplateName'] = ts('Please provide a Template Name.'); } } if ($params['upload_type'] || file_exists(CRM_Utils_Array::value('tmp_name', $files['textFile'])) || !$params['upload_type'] && $params['text_message']) { if (!$params['upload_type']) { $str = file_get_contents($files['textFile']['tmp_name']); $name = $files['textFile']['name']; } else { $str = $params['text_message']; $name = 'text message'; } $dataErrors = array(); /* Do a full token replacement on a dummy verp, the current * contact and domain, and the first organization. */ // here we make a dummy mailing object so that we // can retrieve the tokens that we need to replace // so that we do get an invalid token error // this is qute hacky and I hope that there might // be a suggestion from someone on how to // make it a bit more elegant $dummy_mail = new CRM_Mailing_BAO_Mailing(); $mess = "body_text"; $dummy_mail->{$mess} = $str; $tokens = $dummy_mail->getTokens(); $str = CRM_Utils_Token::replaceSubscribeInviteTokens($str); $str = CRM_Utils_Token::replaceDomainTokens($str, $domain, NULL, $tokens['text']); $str = CRM_Utils_Token::replaceMailingTokens($str, $mailing, NULL, $tokens['text']); $str = CRM_Utils_Token::replaceOrgTokens($str, $org); $str = CRM_Utils_Token::replaceActionTokens($str, $verp, $urls, NULL, $tokens['text']); $str = CRM_Utils_Token::replaceContactTokens($str, $contact, NULL, $tokens['text']); $unmatched = CRM_Utils_Token::unmatchedTokens($str); $contentCheck = CRM_Utils_String::htmlToText($str); if (!empty($unmatched) && 0) { foreach ($unmatched as $token) { $dataErrors[] = '<li>' . ts('Invalid token code') . ' {' . $token . '}</li>'; } } if (strlen($contentCheck) > CRM_SMS_Provider::MAX_SMS_CHAR) { $dataErrors[] = '<li>' . ts('The body of the SMS cannot exceed %1 characters.', array(1 => CRM_SMS_Provider::MAX_SMS_CHAR)) . '</li>'; } if (!empty($dataErrors)) { $errors['textFile'] = ts('The following errors were detected in %1:', array(1 => $name)) . ' <ul>' . implode('', $dataErrors) . '</ul>'; } } $templateName = CRM_Core_BAO_MessageTemplates::getMessageTemplates(); if (CRM_Utils_Array::value('saveTemplate', $params) && in_array(CRM_Utils_Array::value('saveTemplateName', $params), $templateName)) { $errors['saveTemplate'] = ts('Duplicate Template Name.'); } return empty($errors) ? TRUE : $errors; }