本文整理汇总了PHP中CRM_Core_BAO_Domain::getDomain方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_Domain::getDomain方法的具体用法?PHP CRM_Core_BAO_Domain::getDomain怎么用?PHP CRM_Core_BAO_Domain::getDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_Domain
的用法示例。
在下文中一共展示了CRM_Core_BAO_Domain::getDomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: confirm
/**
* Confirm a pending subscription
*
* @param int $contact_id The id of the contact
* @param int $subscribe_id The id of the subscription event
* @param string $hash The hash
*
* @return boolean True on success
* @access public
* @static
*/
public static function confirm($contact_id, $subscribe_id, $hash)
{
$se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
// before we proceed lets just check if this contact is already 'Added'
// if so, we should ignore this request and hence avoid sending multiple
// emails - CRM-11157
$details = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact_id, $se->group_id);
if ($details && $details->status == 'Added') {
// This contact is already subscribed
// lets return the group title
return CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $se->group_id, 'title');
}
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::addContactsToGroup(array($contact_id), $se->group_id, 'Email', 'Added', $ce->id);
$transaction->commit();
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
$group = new CRM_Contact_DAO_Group();
$group->id = $se->group_id;
$group->find(TRUE);
$component = new CRM_Mailing_BAO_Component();
$component->is_default = 1;
$component->is_active = 1;
$component->component_type = 'Welcome';
$component->find(TRUE);
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->title, TRUE);
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->title, FALSE);
$mailParams = array('groupName' => 'Mailing Event ' . $component->component_type, 'subject' => $component->subject, 'from' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'toEmail' => $email, 'toName' => $display_name, 'replyTo' => "do-not-reply@{$emailDomain}", 'returnPath' => "do-not-reply@{$emailDomain}", 'html' => $html, 'text' => $text);
// send - ignore errors because the desired status change has already been successful
$unused_result = CRM_Utils_Mail::send($mailParams);
return $group->title;
}
示例2: run
/**
* Run dashboard
*
* @return none
* @access public
*/
function run()
{
$resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject);
if ($resetCache) {
CRM_Core_BAO_Dashboard::resetDashletCache();
}
CRM_Utils_System::setTitle(ts('CiviCRM Home'));
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
// call hook to get html from other modules
// ignored but needed to prevent warnings
$contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW;
$html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement);
if (is_array($html)) {
$this->assign_by_ref('hookContent', $html);
$this->assign('hookContentPlacement', $contentPlacement);
}
//check that default FROM email address, owner (domain) organization name and default mailbox are configured.
$fromEmailOK = TRUE;
$ownerOrgOK = TRUE;
$defaultMailboxOK = TRUE;
// Don't put up notices if user doesn't have administer CiviCRM permission
if (CRM_Core_Permission::check('administer CiviCRM')) {
$destination = CRM_Utils_System::url('civicrm/dashboard', 'reset=1', FALSE, NULL, FALSE);
$destination = urlencode($destination);
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
if (!$domainEmailAddress || $domainEmailAddress == 'info@FIXME.ORG') {
$fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixEmailUrl', $fixEmailUrl);
$fromEmailOK = FALSE;
}
$domain = CRM_Core_BAO_Domain::getDomain();
$domainName = $domain->name;
if (!$domainName || $domainName == 'Default Domain Name') {
$fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
$this->assign('fixOrgUrl', $fixOrgUrl);
$ownerOrgOK = FALSE;
}
$config = CRM_Core_Config::singleton();
if (in_array('CiviMail', $config->enableComponents) && CRM_Core_BAO_MailSettings::defaultDomain() == "FIXME.ORG") {
$fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}");
$this->assign('fixDefaultMailbox', $fixDefaultMailbox);
$defaultMailboxOK = FALSE;
}
}
$this->assign('fromEmailOK', $fromEmailOK);
$this->assign('ownerOrgOK', $ownerOrgOK);
$this->assign('defaultMailboxOK', $defaultMailboxOK);
return parent::run();
}
示例3: onRender
/**
* Apply the various CRM_Utils_Token helpers.
*
* @param TokenRenderEvent $e
*/
public function onRender(TokenRenderEvent $e)
{
$isHtml = $e->message['format'] == 'text/html';
$useSmarty = !empty($e->context['smarty']);
$e->string = \CRM_Utils_Token::replaceDomainTokens($e->string, \CRM_Core_BAO_Domain::getDomain(), $isHtml, $e->message['tokens'], $useSmarty);
if (!empty($e->context['contact'])) {
$e->string = \CRM_Utils_Token::replaceContactTokens($e->string, $e->context['contact'], $isHtml, $e->message['tokens'], FALSE, $useSmarty);
// FIXME: This may depend on $contact being merged with hook values.
$e->string = \CRM_Utils_Token::replaceHookTokens($e->string, $e->context['contact'], $e->context['hookTokenCategories'], $isHtml, $useSmarty);
\CRM_Utils_Token::replaceGreetingTokens($e->string, NULL, $e->context['contact']['contact_id'], NULL, $useSmarty);
}
if ($useSmarty) {
$smarty = \CRM_Core_Smarty::singleton();
$e->string = $smarty->fetch("string:" . $e->string);
}
}
示例4: civicrm_domain_get
/**
* Generic file to retrieve all the constants and
* pseudo constants used in CiviCRM
*
*/
function civicrm_domain_get()
{
require_once 'CRM/Core/BAO/Domain.php';
$dao = CRM_Core_BAO_Domain::getDomain();
$values = array();
$params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_domain');
require_once 'CRM/Core/BAO/Location.php';
$values['location'] = CRM_Core_BAO_Location::getValues($params, true);
$address_array = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'state_province_id', 'postal_code', 'country_id', 'geo_code_1', 'geo_code_2');
require_once 'CRM/Core/OptionGroup.php';
$domain[$dao->id] = array('id' => $dao->id, 'domain_name' => $dao->name, 'description' => $dao->description, 'domain_email' => CRM_Utils_Array::value('email', $values['location']['email'][1]), 'domain_phone' => array('phone_type' => CRM_Core_OptionGroup::getLabel('phone_type', CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])), 'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1])));
foreach ($address_array as $value) {
$domain[$dao->id]['domain_address'][$value] = CRM_Utils_Array::value($value, $values['location']['address'][1]);
}
list($domain[$dao->id]['from_name'], $domain[$dao->id]['from_email']) = CRM_Core_BAO_Domain::getNameAndEmail();
return $domain;
}
示例5: error_reporting
/**
* Singleton function used to manage this object.
*
* @param bool $loadFromDB
* whether to load from the database.
* @param bool $force
* whether to force a reconstruction.
*
* @return CRM_Core_Config
*/
public static function &singleton($loadFromDB = TRUE, $force = FALSE)
{
if (self::$_singleton === NULL || $force) {
$GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'handle'));
$errorScope = CRM_Core_TemporaryErrorScope::create(array('CRM_Core_Error', 'simpleHandler'));
if (defined('E_DEPRECATED')) {
error_reporting(error_reporting() & ~E_DEPRECATED);
}
self::$_singleton = new CRM_Core_Config();
\Civi\Core\Container::boot($loadFromDB);
if ($loadFromDB && self::$_singleton->dsn) {
$domain = \CRM_Core_BAO_Domain::getDomain();
\CRM_Core_BAO_ConfigSetting::applyLocale(\Civi::settings($domain->id), $domain->locales);
unset($errorScope);
CRM_Utils_Hook::config(self::$_singleton);
self::$_singleton->authenticate();
// Extreme backward compat: $config binds to active domain at moment of setup.
self::$_singleton->getSettings();
Civi::service('settings_manager')->useDefaults();
}
}
return self::$_singleton;
}
示例6: printPDF
//.........这里部分代码省略.........
}
// to email the invoice
$mailDetails = array();
$values = array();
if ($contribution->_component == 'event') {
$daoName = 'CRM_Event_DAO_Event';
$pageId = $contribution->_relatedObjects['event']->id;
$mailElements = array('title', 'confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm');
CRM_Core_DAO::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
$values['title'] = CRM_Utils_Array::value('title', $mailDetails[$contribution->_relatedObjects['event']->id]);
$values['confirm_from_name'] = CRM_Utils_Array::value('confirm_from_name', $mailDetails[$contribution->_relatedObjects['event']->id]);
$values['confirm_from_email'] = CRM_Utils_Array::value('confirm_from_email', $mailDetails[$contribution->_relatedObjects['event']->id]);
$values['cc_confirm'] = CRM_Utils_Array::value('cc_confirm', $mailDetails[$contribution->_relatedObjects['event']->id]);
$values['bcc_confirm'] = CRM_Utils_Array::value('bcc_confirm', $mailDetails[$contribution->_relatedObjects['event']->id]);
$title = CRM_Utils_Array::value('title', $mailDetails[$contribution->_relatedObjects['event']->id]);
} elseif ($contribution->_component == 'contribute') {
$daoName = 'CRM_Contribute_DAO_ContributionPage';
$pageId = $contribution->contribution_page_id;
$mailElements = array('title', 'receipt_from_name', 'receipt_from_email', 'cc_receipt', 'bcc_receipt');
CRM_Core_DAO::commonRetrieveAll($daoName, 'id', $pageId, $mailDetails, $mailElements);
$values['title'] = CRM_Utils_Array::value('title', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
$values['receipt_from_name'] = CRM_Utils_Array::value('receipt_from_name', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
$values['receipt_from_email'] = CRM_Utils_Array::value('receipt_from_email', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
$values['cc_receipt'] = CRM_Utils_Array::value('cc_receipt', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
$values['bcc_receipt'] = CRM_Utils_Array::value('bcc_receipt', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
$title = CRM_Utils_Array::value('title', CRM_Utils_Array::value($contribution->contribution_page_id, $mailDetails));
}
$source = $contribution->source;
$config = CRM_Core_Config::singleton();
if (!isset($params['forPage'])) {
$config->doNotAttachPDFReceipt = 1;
}
// get organization address
$domain = CRM_Core_BAO_Domain::getDomain();
$locParams = array('contact_id' => $domain->id);
$locationDefaults = CRM_Core_BAO_Location::getValues($locParams);
if (isset($locationDefaults['address'][1]['state_province_id'])) {
$stateProvinceAbbreviationDomain = CRM_Core_PseudoConstant::stateProvinceAbbreviation($locationDefaults['address'][1]['state_province_id']);
} else {
$stateProvinceAbbreviationDomain = '';
}
if (isset($locationDefaults['address'][1]['country_id'])) {
$countryDomain = CRM_Core_PseudoConstant::country($locationDefaults['address'][1]['country_id']);
} else {
$countryDomain = '';
}
// parameters to be assign for template
$tplParams = array('title' => $title, 'component' => $input['component'], 'id' => $contribution->id, 'source' => $source, 'invoice_id' => $invoiceId, 'resourceBase' => $config->userFrameworkResourceURL, 'defaultCurrency' => $config->defaultCurrency, 'amount' => $contribution->total_amount, 'amountDue' => $amountDue, 'invoice_date' => $invoiceDate, 'dueDate' => $dueDate, 'notes' => CRM_Utils_Array::value('notes', $prefixValue), 'display_name' => $contribution->_relatedObjects['contact']->display_name, 'lineItem' => $lineItem, 'dataArray' => $dataArray, 'refundedStatusId' => $refundedStatusId, 'contribution_status_id' => $contribution->contribution_status_id, 'subTotal' => $subTotal, 'street_address' => CRM_Utils_Array::value('street_address', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'city' => CRM_Utils_Array::value('city', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'stateProvinceAbbreviation' => $stateProvinceAbbreviation, 'postal_code' => CRM_Utils_Array::value('postal_code', CRM_Utils_Array::value($contribution->contact_id, $billingAddress)), 'is_pay_later' => $contribution->is_pay_later, 'organization_name' => $contribution->_relatedObjects['contact']->organization_name, 'domain_organization' => $domain->name, 'domain_street_address' => CRM_Utils_Array::value('street_address', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_city' => CRM_Utils_Array::value('city', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_postal_code' => CRM_Utils_Array::value('postal_code', CRM_Utils_Array::value('1', $locationDefaults['address'])), 'domain_state' => $stateProvinceAbbreviationDomain, 'domain_country' => $countryDomain, 'domain_email' => CRM_Utils_Array::value('email', CRM_Utils_Array::value('1', $locationDefaults['email'])), 'domain_phone' => CRM_Utils_Array::value('phone', CRM_Utils_Array::value('1', $locationDefaults['phone'])));
if (isset($creditNoteId)) {
$tplParams['creditnote_id'] = $creditNoteId;
}
$sendTemplateParams = array('groupName' => 'msg_tpl_workflow_contribution', 'valueName' => 'contribution_invoice_receipt', 'contactId' => $contribution->contact_id, 'tplParams' => $tplParams, 'PDFFilename' => 'Invoice.pdf');
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');
//CRM-16319 - we dont store in userID in case the user is doing multiple
//transactions etc
if (empty($contactID)) {
$contactID = $session->get('transaction.userID');
}
$contactEmails = CRM_Core_BAO_Email::allEmails($contactID);
$emails = array();
$fromDisplayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'display_name');
foreach ($contactEmails as $emailId => $item) {
$email = $item['email'];
if ($email) {
$emails[$emailId] = '"' . $fromDisplayName . '" <' . $email . '> ';
示例7: formRule
/**
* Function for validation
*
* @param array $params (ref.) an assoc array of name/value pairs
*
* @param $files
* @param $self
*
* @return mixed true or array of errors
* @access public
* @static
*/
static function formRule($params, $files, $self)
{
if (!empty($_POST['_qf_Import_refresh'])) {
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 (empty($params['text_message'])) {
$errors['text_message'] = ts('Please provide a Text');
} else {
if (!empty($params['text_message'])) {
$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 (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
$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>';
}
}
//.........这里部分代码省略.........
示例8: array
/**
* Create a new forward event, create a new contact if necessary
*
* @param $job_id
* @param $queue_id
* @param $hash
* @param $forward_email
* @param null $fromEmail
* @param null $comment
*
* @return bool
*/
public static function &forward($job_id, $queue_id, $hash, $forward_email, $fromEmail = NULL, $comment = NULL)
{
$q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
$successfulForward = FALSE;
$contact_id = NULL;
if (!$q) {
return $successfulForward;
}
/* Find the email address/contact, if it exists */
$contact = CRM_Contact_BAO_Contact::getTableName();
$location = CRM_Core_BAO_Location::getTableName();
$email = CRM_Core_BAO_Email::getTableName();
$queueTable = CRM_Mailing_Event_BAO_Queue::getTableName();
$job = CRM_Mailing_BAO_MailingJob::getTableName();
$mailing = CRM_Mailing_BAO_Mailing::getTableName();
$forward = self::getTableName();
$domain = CRM_Core_BAO_Domain::getDomain();
$dao = new CRM_Core_Dao();
$dao->query("\n SELECT {$contact}.id as contact_id,\n {$email}.id as email_id,\n {$contact}.do_not_email as do_not_email,\n {$queueTable}.id as queue_id\n FROM ({$email}, {$job} as temp_job)\n INNER JOIN {$contact}\n ON {$email}.contact_id = {$contact}.id\n LEFT JOIN {$queueTable}\n ON {$email}.id = {$queueTable}.email_id\n LEFT JOIN {$job}\n ON {$queueTable}.job_id = {$job}.id\n AND temp_job.mailing_id = {$job}.mailing_id\n WHERE {$queueTable}.job_id = {$job_id}\n AND {$email}.email = '" . CRM_Utils_Type::escape($forward_email, 'String') . "'");
$dao->fetch();
$transaction = new CRM_Core_Transaction();
if (isset($dao->queue_id) || isset($dao->do_not_email) && $dao->do_not_email == 1) {
/* We already sent this mailing to $forward_email, or we should
* never email this contact. Give up. */
return $successfulForward;
}
require_once 'api/api.php';
$contactParams = array('email' => $forward_email, 'version' => 3);
$contactValues = civicrm_api('contact', 'get', $contactParams);
$count = $contactValues['count'];
if ($count == 0) {
/* If the contact does not exist, create one. */
$formatted = array('contact_type' => 'Individual', 'version' => 3);
$locationType = CRM_Core_BAO_LocationType::getDefault();
$value = array('email' => $forward_email, 'location_type_id' => $locationType->id);
require_once 'CRM/Utils/DeprecatedUtils.php';
_civicrm_api3_deprecated_add_formatted_param($value, $formatted);
$formatted['onDuplicate'] = CRM_Import_Parser::DUPLICATE_SKIP;
$formatted['fixAddress'] = TRUE;
$contact = civicrm_api('contact', 'create', $formatted);
if (civicrm_error($contact)) {
return $successfulForward;
}
$contact_id = $contact['id'];
}
$email = new CRM_Core_DAO_Email();
$email->email = $forward_email;
$email->find(TRUE);
$email_id = $email->id;
if (!$contact_id) {
$contact_id = $email->contact_id;
}
/* Create a new queue event */
$queue_params = array('email_id' => $email_id, 'contact_id' => $contact_id, 'job_id' => $job_id);
$queue = CRM_Mailing_Event_BAO_Queue::create($queue_params);
$forward = new CRM_Mailing_Event_BAO_Forward();
$forward->time_stamp = date('YmdHis');
$forward->event_queue_id = $queue_id;
$forward->dest_queue_id = $queue->id;
$forward->save();
$dao->reset();
$dao->query(" SELECT {$job}.mailing_id as mailing_id\n FROM {$job}\n WHERE {$job}.id = " . CRM_Utils_Type::escape($job_id, 'Integer'));
$dao->fetch();
$mailing_obj = new CRM_Mailing_BAO_Mailing();
$mailing_obj->id = $dao->mailing_id;
$mailing_obj->find(TRUE);
$config = CRM_Core_Config::singleton();
$mailer = $config->getMailer();
$recipient = NULL;
$attachments = NULL;
$message = $mailing_obj->compose($job_id, $queue->id, $queue->hash, $queue->contact_id, $forward_email, $recipient, FALSE, NULL, $attachments, TRUE, $fromEmail);
//append comment if added while forwarding.
if (count($comment)) {
$message->_txtbody = CRM_Utils_Array::value('body_text', $comment) . $message->_txtbody;
if (!empty($comment['body_html'])) {
$message->_htmlbody = $comment['body_html'] . '<br />---------------Original message---------------------<br />' . $message->_htmlbody;
}
}
$body = $message->get();
$headers = $message->headers();
$result = NULL;
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$result = $mailer->send($recipient, $headers, $body);
unset($errorScope);
}
$params = array('event_queue_id' => $queue->id, 'job_id' => $job_id, 'hash' => $queue->hash);
if (is_a($result, 'PEAR_Error')) {
//.........这里部分代码省略.........
示例9: format
/**
* Format an address string from address fields and a format string.
*
* Format an address basing on the address fields provided.
* Use Setting's address_format if there's no format specified.
*
* @param array $fields
* The address fields.
* @param string $format
* The desired address format.
* @param bool $microformat
* If true indicates, the address to be built in hcard-microformat standard.
* @param bool $mailing
* If true indicates, the call has been made from mailing label.
* @param bool $individualFormat
* If true indicates, the call has been made for the contact of type 'individual'.
*
* @param null $tokenFields
*
* @return string
* formatted address string
*
*/
public static function format($fields, $format = NULL, $microformat = FALSE, $mailing = FALSE, $individualFormat = FALSE, $tokenFields = NULL)
{
static $config = NULL;
if (!$format) {
$format = Civi::settings()->get('address_format');
}
if ($mailing) {
$format = Civi::settings()->get('mailing_format');
}
$formatted = $format;
$fullPostalCode = CRM_Utils_Array::value('postal_code', $fields);
if (!empty($fields['postal_code_suffix'])) {
$fullPostalCode .= "-{$fields['postal_code_suffix']}";
}
// make sure that some of the fields do have values
$emptyFields = array('supplemental_address_1', 'supplemental_address_2', 'state_province_name', 'county');
foreach ($emptyFields as $f) {
if (!isset($fields[$f])) {
$fields[$f] = NULL;
}
}
//CRM-16876 Display countries in all caps when in mailing mode.
if ($mailing && !empty($fields['country'])) {
if (Civi::settings()->get('hideCountryMailingLabels')) {
$domain = CRM_Core_BAO_Domain::getDomain();
$domainLocation = CRM_Core_BAO_Location::getValues(array('contact_id' => $domain->contact_id));
$domainAddress = $domainLocation['address'][1];
$domainCountryId = $domainAddress['country_id'];
if ($fields['country'] == CRM_Core_PseudoConstant::country($domainCountryId)) {
$fields['country'] = NULL;
} else {
//Capitalization display on uppercase to contries with special characters
$fields['country'] = mb_convert_case($fields['country'], MB_CASE_UPPER, "UTF-8");
}
} else {
$fields['country'] = mb_convert_case($fields['country'], MB_CASE_UPPER, "UTF-8");
}
}
$contactName = CRM_Utils_Array::value('display_name', $fields);
if (!$individualFormat) {
if (isset($fields['id'])) {
$type = CRM_Contact_BAO_Contact::getContactType($fields['id']);
} else {
$type = 'Individual';
}
if ($type == 'Individual') {
$contactName = CRM_Utils_Array::value('addressee_display', $fields);
}
}
if (!$microformat) {
// replacements in case of Individual Name Format
$replacements = array('contact.display_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.individual_prefix' => CRM_Utils_Array::value('individual_prefix', $fields), 'contact.formal_title' => CRM_Utils_Array::value('formal_title', $fields), 'contact.first_name' => CRM_Utils_Array::value('first_name', $fields), 'contact.middle_name' => CRM_Utils_Array::value('middle_name', $fields), 'contact.last_name' => CRM_Utils_Array::value('last_name', $fields), 'contact.individual_suffix' => CRM_Utils_Array::value('individual_suffix', $fields), 'contact.address_name' => CRM_Utils_Array::value('address_name', $fields), 'contact.street_address' => CRM_Utils_Array::value('street_address', $fields), 'contact.supplemental_address_1' => CRM_Utils_Array::value('supplemental_address_1', $fields), 'contact.supplemental_address_2' => CRM_Utils_Array::value('supplemental_address_2', $fields), 'contact.city' => CRM_Utils_Array::value('city', $fields), 'contact.state_province_name' => CRM_Utils_Array::value('state_province_name', $fields), 'contact.county' => CRM_Utils_Array::value('county', $fields), 'contact.state_province' => CRM_Utils_Array::value('state_province', $fields), 'contact.postal_code' => $fullPostalCode, 'contact.country' => CRM_Utils_Array::value('country', $fields), 'contact.world_region' => CRM_Utils_Array::value('world_region', $fields), 'contact.geo_code_1' => CRM_Utils_Array::value('geo_code_1', $fields), 'contact.geo_code_2' => CRM_Utils_Array::value('geo_code_2', $fields), 'contact.current_employer' => CRM_Utils_Array::value('current_employer', $fields), 'contact.nick_name' => CRM_Utils_Array::value('nick_name', $fields), 'contact.email' => CRM_Utils_Array::value('email', $fields), 'contact.im' => CRM_Utils_Array::value('im', $fields), 'contact.do_not_email' => CRM_Utils_Array::value('do_not_email', $fields), 'contact.do_not_phone' => CRM_Utils_Array::value('do_not_phone', $fields), 'contact.do_not_mail' => CRM_Utils_Array::value('do_not_mail', $fields), 'contact.do_not_sms' => CRM_Utils_Array::value('do_not_sms', $fields), 'contact.do_not_trade' => CRM_Utils_Array::value('do_not_trade', $fields), 'contact.job_title' => CRM_Utils_Array::value('job_title', $fields), 'contact.birth_date' => CRM_Utils_Array::value('birth_date', $fields), 'contact.gender' => CRM_Utils_Array::value('gender', $fields), 'contact.is_opt_out' => CRM_Utils_Array::value('is_opt_out', $fields), 'contact.preferred_mail_format' => CRM_Utils_Array::value('preferred_mail_format', $fields), 'contact.phone' => CRM_Utils_Array::value('phone', $fields), 'contact.home_URL' => CRM_Utils_Array::value('home_URL', $fields), 'contact.contact_source' => CRM_Utils_Array::value('contact_source', $fields), 'contact.external_identifier' => CRM_Utils_Array::value('external_identifier', $fields), 'contact.contact_id' => CRM_Utils_Array::value('id', $fields), 'contact.household_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.organization_name' => CRM_Utils_Array::value('display_name', $fields), 'contact.legal_name' => CRM_Utils_Array::value('legal_name', $fields), 'contact.preferred_communication_method' => CRM_Utils_Array::value('preferred_communication_method', $fields), 'contact.communication_style' => CRM_Utils_Array::value('communication_style', $fields), 'contact.addressee' => CRM_Utils_Array::value('addressee_display', $fields), 'contact.email_greeting' => CRM_Utils_Array::value('email_greeting_display', $fields), 'contact.postal_greeting' => CRM_Utils_Array::value('postal_greeting_display', $fields));
} else {
$replacements = array('contact.address_name' => "<span class=\"address-name\">" . $fields['address_name'] . "</span>", 'contact.street_address' => "<span class=\"street-address\">" . $fields['street_address'] . "</span>", 'contact.supplemental_address_1' => "<span class=\"extended-address\">" . $fields['supplemental_address_1'] . "</span>", 'contact.supplemental_address_2' => $fields['supplemental_address_2'], 'contact.city' => "<span class=\"locality\">" . $fields['city'] . "</span>", 'contact.state_province_name' => "<span class=\"region\">" . $fields['state_province_name'] . "</span>", 'contact.county' => "<span class=\"region\">" . $fields['county'], 'contact.state_province' => "<span class=\"region\">" . $fields['state_province'] . "</span>", 'contact.postal_code' => "<span class=\"postal-code\">" . $fullPostalCode . "</span>", 'contact.country' => "<span class=\"country-name\">" . $fields['country'] . "</span>", 'contact.world_region' => "<span class=\"region\">" . $fields['world_region'] . "</span>");
// erase all empty ones, so we dont get blank lines
foreach (array_keys($replacements) as $key) {
$exactKey = substr($key, 0, 8) == 'contact.' ? substr($key, 8) : $key;
if ($key != 'contact.postal_code' && CRM_Utils_Array::value($exactKey, $fields) == NULL) {
$replacements[$key] = '';
}
}
if (empty($fullPostalCode)) {
$replacements['contact.postal_code'] = '';
}
}
// replacements in case of Custom Token
if (stristr($formatted, 'custom_')) {
$customToken = array_keys($fields);
foreach ($customToken as $value) {
if (substr($value, 0, 7) == 'custom_') {
$replacements["contact.{$value}"] = $fields["{$value}"];
}
}
}
// also sub all token fields
if ($tokenFields) {
foreach ($tokenFields as $token) {
//.........这里部分代码省略.........
示例10: sendReminder
/**
* @param $contactId
* @param $to
* @param $scheduleID
* @param $from
* @param $tokenParams
*
* @return bool|null
* @throws CRM_Core_Exception
*/
static function sendReminder($contactId, $to, $scheduleID, $from, $tokenParams)
{
$email = $to['email'];
$phoneNumber = $to['phone'];
$schedule = new CRM_Core_DAO_ActionSchedule();
$schedule->id = $scheduleID;
$domain = CRM_Core_BAO_Domain::getDomain();
$result = NULL;
$hookTokens = array();
if ($schedule->find(TRUE)) {
$body_text = $schedule->body_text;
$body_html = $schedule->body_html;
$sms_body_text = $schedule->sms_body_text;
$body_subject = $schedule->subject;
if (!$body_text) {
$body_text = CRM_Utils_String::htmlToText($body_html);
}
$params = array(array('contact_id', '=', $contactId, 0, 0));
list($contact, $_) = CRM_Contact_BAO_Query::apiQuery($params);
//CRM-4524
$contact = reset($contact);
if (!$contact || is_a($contact, 'CRM_Core_Error')) {
return NULL;
}
// merge activity tokens with contact array
$contact = array_merge($contact, $tokenParams);
//CRM-5734
CRM_Utils_Hook::tokenValues($contact, $contactId);
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$type = array('body_html' => 'html', 'body_text' => 'text', 'sms_body_text' => 'text');
foreach ($type as $bodyType => $value) {
$dummy_mail = new CRM_Mailing_BAO_Mailing();
if ($bodyType == 'sms_body_text') {
$dummy_mail->body_text = ${$bodyType};
} else {
$dummy_mail->{${$bodyType}} = ${$bodyType};
}
$tokens = $dummy_mail->getTokens();
if (${$bodyType}) {
CRM_Utils_Token::replaceGreetingTokens(${$bodyType}, NULL, $contact['contact_id']);
${$bodyType} = CRM_Utils_Token::replaceDomainTokens(${$bodyType}, $domain, TRUE, $tokens[$value], TRUE);
${$bodyType} = CRM_Utils_Token::replaceContactTokens(${$bodyType}, $contact, FALSE, $tokens[$value], FALSE, TRUE);
${$bodyType} = CRM_Utils_Token::replaceComponentTokens(${$bodyType}, $contact, $tokens[$value], TRUE, FALSE);
${$bodyType} = CRM_Utils_Token::replaceHookTokens(${$bodyType}, $contact, $categories, TRUE);
}
}
$html = $body_html;
$text = $body_text;
$sms_text = $sms_body_text;
$smarty = CRM_Core_Smarty::singleton();
foreach (array('text', 'html', 'sms_text') as $elem) {
${$elem} = $smarty->fetch("string:{${$elem}}");
}
$matches = array();
preg_match_all('/(?<!\\{|\\\\)\\{(\\w+\\.\\w+)\\}(?!\\})/', $body_subject, $matches, PREG_PATTERN_ORDER);
$subjectToken = NULL;
if ($matches[1]) {
foreach ($matches[1] as $token) {
list($type, $name) = preg_split('/\\./', $token, 2);
if ($name) {
if (!isset($subjectToken[$type])) {
$subjectToken[$type] = array();
}
$subjectToken[$type][] = $name;
}
}
}
$messageSubject = CRM_Utils_Token::replaceContactTokens($body_subject, $contact, FALSE, $subjectToken);
$messageSubject = CRM_Utils_Token::replaceDomainTokens($messageSubject, $domain, TRUE, $subjectToken);
$messageSubject = CRM_Utils_Token::replaceComponentTokens($messageSubject, $contact, $subjectToken, TRUE);
$messageSubject = CRM_Utils_Token::replaceHookTokens($messageSubject, $contact, $categories, TRUE);
$messageSubject = $smarty->fetch("string:{$messageSubject}");
if ($schedule->mode == 'SMS' or $schedule->mode == 'User_Preference') {
$session = CRM_Core_Session::singleton();
$userID = $session->get('userID') ? $session->get('userID') : $contactId;
$smsParams = array('To' => $phoneNumber, 'provider_id' => $schedule->sms_provider_id, 'activity_subject' => $messageSubject);
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'SMS', 'name');
$activityParams = array('source_contact_id' => $userID, 'activity_type_id' => $activityTypeID, 'activity_date_time' => date('YmdHis'), 'subject' => $messageSubject, 'details' => $sms_text, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'));
$activity = CRM_Activity_BAO_Activity::create($activityParams);
CRM_Activity_BAO_Activity::sendSMSMessage($contactId, $sms_text, $html, $smsParams, $activity->id, $userID);
}
if ($schedule->mode == 'Email' or $schedule->mode == 'User_Preference') {
// set up the parameters for CRM_Utils_Mail::send
$mailParams = array('groupName' => 'Scheduled Reminder Sender', 'from' => $from, 'toName' => $contact['display_name'], 'toEmail' => $email, 'subject' => $messageSubject, 'entity' => 'action_schedule', 'entity_id' => $scheduleID);
if (!$html || $contact['preferred_mail_format'] == 'Text' || $contact['preferred_mail_format'] == 'Both') {
// render the & entities in text mode, so that the links work
$mailParams['text'] = str_replace('&', '&', $text);
}
if ($html && ($contact['preferred_mail_format'] == 'HTML' || $contact['preferred_mail_format'] == 'Both')) {
//.........这里部分代码省略.........
示例11: cancelParticipant
/**
* Cancel this participant and finish, send cancellation email. At this point no
* auto-cancellation of payment is handled, so payment needs to be manually cancelled
*
* return @void
*/
public function cancelParticipant($params)
{
//set participant record status to Cancelled, refund payment if possible
// send email to participant and admin, and log Activity
$value = array();
$value['id'] = $this->_participant_id;
$cancelledId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'"));
$value['status_id'] = $cancelledId;
CRM_Event_BAO_Participant::create($value);
$domainValues = array();
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = array('domain' => array('name', 'phone', 'address', 'email'), 'contact' => CRM_Core_SelectValues::contactTokens());
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$participantRoles = array();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
$participantDetails = array();
$query = "SELECT * FROM civicrm_participant WHERE id = {$this->_participant_id}";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$participantDetails[$dao->id] = array('id' => $dao->id, 'role' => $participantRoles[$dao->role_id], 'is_test' => $dao->is_test, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'fee_amount' => $dao->fee_amount, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id);
}
$eventDetails = array();
$eventParams = array('id' => $this->_event_id);
CRM_Event_BAO_Event::retrieve($eventParams, $eventDetails[$this->_event_id]);
//get default participant role.
$eventDetails[$this->_event_id]['participant_role'] = CRM_Utils_Array::value($eventDetails[$this->_event_id]['default_role_id'], $participantRoles);
//get the location info
$locParams = array('entity_id' => $this->_event_id, 'entity_table' => 'civicrm_event');
$eventDetails[$this->_event_id]['location'] = CRM_Core_BAO_Location::getValues($locParams, TRUE);
//get contact details
$contactIds[$this->_contact_id] = $this->_contact_id;
list($currentContactDetails) = CRM_Utils_Token::getTokenDetails($contactIds, NULL, FALSE, FALSE, NULL, array(), 'CRM_Event_BAO_Participant');
foreach ($currentContactDetails as $contactId => $contactValues) {
$contactDetails[$this->_contact_id] = $contactValues;
}
//send a 'cancelled' email to user, and cc the event's cc_confirm email
$mail = CRM_Event_BAO_Participant::sendTransitionParticipantMail($this->_participant_id, $participantDetails[$this->_participant_id], $eventDetails[$this->_event_id], $contactDetails[$this->_contact_id], $domainValues, "Cancelled", "");
$statusMsg = ts('Event registration information for %1 has been updated.', array(1 => $this->_contact_name));
$statusMsg .= ' ' . ts('A cancellation email has been sent to %1.', array(1 => $this->_contact_email));
CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success');
$url = CRM_Utils_System::url('civicrm/event/info', "reset=1&id={$this->_event_id}&noFullMsg=true");
CRM_Utils_System::redirect($url);
}
示例12: send_unsub_response
/**
* Send a response email informing the contact of the groups from which he.
* has been unsubscribed.
*
* @param string $queue_id
* The queue event ID.
* @param array $groups
* List of group IDs.
* @param bool $is_domain
* Is this domain-level?.
* @param int $job
* The job ID.
*/
public static function send_unsub_response($queue_id, $groups, $is_domain = FALSE, $job)
{
$config = CRM_Core_Config::singleton();
$domain = CRM_Core_BAO_Domain::getDomain();
$jobObject = new CRM_Mailing_BAO_MailingJob();
$jobTable = $jobObject->getTableName();
$mailingObject = new CRM_Mailing_DAO_Mailing();
$mailingTable = $mailingObject->getTableName();
$contactsObject = new CRM_Contact_DAO_Contact();
$contacts = $contactsObject->getTableName();
$emailObject = new CRM_Core_DAO_Email();
$email = $emailObject->getTableName();
$queueObject = new CRM_Mailing_Event_BAO_Queue();
$queue = $queueObject->getTableName();
//get the default domain email address.
list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail();
$dao = new CRM_Mailing_BAO_Mailing();
$dao->query(" SELECT * FROM {$mailingTable}\n INNER JOIN {$jobTable} ON\n {$jobTable}.mailing_id = {$mailingTable}.id\n WHERE {$jobTable}.id = {$job}");
$dao->fetch();
$component = new CRM_Mailing_BAO_Component();
if ($is_domain) {
$component->id = $dao->optout_id;
} else {
$component->id = $dao->unsubscribe_id;
}
$component->find(TRUE);
$html = $component->body_html;
if ($component->body_text) {
$text = $component->body_text;
} else {
$text = CRM_Utils_String::htmlToText($component->body_html);
}
$eq = new CRM_Core_DAO();
$eq->query("SELECT {$contacts}.preferred_mail_format as format,\n {$contacts}.id as contact_id,\n {$email}.email as email,\n {$queue}.hash as hash\n FROM {$contacts}\n INNER JOIN {$queue} ON {$queue}.contact_id = {$contacts}.id\n INNER JOIN {$email} ON {$queue}.email_id = {$email}.id\n WHERE {$queue}.id = " . CRM_Utils_Type::escape($queue_id, 'Integer'));
$eq->fetch();
if ($groups) {
foreach ($groups as $key => $value) {
if (!$value) {
unset($groups[$key]);
}
}
}
$message = new Mail_mime("\n");
list($addresses, $urls) = CRM_Mailing_BAO_Mailing::getVerpAndUrls($job, $queue_id, $eq->hash, $eq->email);
$bao = new CRM_Mailing_BAO_Mailing();
$bao->body_text = $text;
$bao->body_html = $html;
$tokens = $bao->getTokens();
if ($eq->format == 'HTML' || $eq->format == 'Both') {
$html = CRM_Utils_Token::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceUnsubscribeTokens($html, $domain, $groups, TRUE, $eq->contact_id, $eq->hash);
$html = CRM_Utils_Token::replaceActionTokens($html, $addresses, $urls, TRUE, $tokens['html']);
$html = CRM_Utils_Token::replaceMailingTokens($html, $dao, NULL, $tokens['html']);
$message->setHTMLBody($html);
}
if (!$html || $eq->format == 'Text' || $eq->format == 'Both') {
$text = CRM_Utils_Token::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceUnsubscribeTokens($text, $domain, $groups, FALSE, $eq->contact_id, $eq->hash);
$text = CRM_Utils_Token::replaceActionTokens($text, $addresses, $urls, FALSE, $tokens['text']);
$text = CRM_Utils_Token::replaceMailingTokens($text, $dao, NULL, $tokens['text']);
$message->setTxtBody($text);
}
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
$headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $eq->email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
CRM_Mailing_BAO_Mailing::addMessageIdHeader($headers, 'u', $job, $queue_id, $eq->hash);
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($eq->email, $h, $b);
unset($errorScope);
}
}
示例13: formRule
/**
* Validation.
*
* @param array $params
* (ref.) an assoc array of name/value pairs.
*
* @param $files
* @param $self
*
* @return bool|array
* mixed true or array of errors
*/
public static function formRule($params, $files, $self)
{
if (!empty($_POST['_qf_Import_refresh'])) {
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);
}
$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]++;
}
// 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'] = '';
}
}
$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 (empty($params['text_message']) && empty($params['html_message'])) {
$errors['html_message'] = ts('Please provide either a Text or HTML formatted message - or both.');
}
if (!empty($params['saveTemplate']) && empty($params['saveTemplateName'])) {
$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 */
if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check')) {
$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>';
}
}
}
//.........这里部分代码省略.........
示例14: sendTemplate
/**
* Send an email from the specified template based on an array of params.
*
* @param array $params
* A string-keyed array of function params, see function body for details.
*
* @return array
* Array of four parameters: a boolean whether the email was sent, and the subject, text and HTML templates
*/
public static function sendTemplate($params)
{
$defaults = array('groupName' => NULL, 'valueName' => NULL, 'messageTemplateID' => NULL, 'contactId' => NULL, 'tplParams' => array(), 'from' => NULL, 'toName' => NULL, 'toEmail' => NULL, 'cc' => NULL, 'bcc' => NULL, 'replyTo' => NULL, 'attachments' => NULL, 'isTest' => FALSE, 'PDFFilename' => NULL);
$params = array_merge($defaults, $params);
CRM_Utils_Hook::alterMailParams($params, 'messageTemplate');
if ((!$params['groupName'] || !$params['valueName']) && !$params['messageTemplateID']) {
CRM_Core_Error::fatal(ts("Message template's option group and/or option value or ID missing."));
}
if ($params['messageTemplateID']) {
// fetch the three elements from the db based on id
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
WHERE mt.id = %1 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['messageTemplateID'], 'String'));
} else {
// fetch the three elements from the db based on option_group and option_value names
$query = 'SELECT msg_subject subject, msg_text text, msg_html html, pdf_format_id format
FROM civicrm_msg_template mt
JOIN civicrm_option_value ov ON workflow_id = ov.id
JOIN civicrm_option_group og ON ov.option_group_id = og.id
WHERE og.name = %1 AND ov.name = %2 AND mt.is_default = 1';
$sqlParams = array(1 => array($params['groupName'], 'String'), 2 => array($params['valueName'], 'String'));
}
$dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
$dao->fetch();
if (!$dao->N) {
if ($params['messageTemplateID']) {
CRM_Core_Error::fatal(ts('No such message template: id=%1.', array(1 => $params['messageTemplateID'])));
} else {
CRM_Core_Error::fatal(ts('No such message template: option group %1, option value %2.', array(1 => $params['groupName'], 2 => $params['valueName'])));
}
}
$mailContent = array('subject' => $dao->subject, 'text' => $dao->text, 'html' => $dao->html, 'format' => $dao->format);
$dao->free();
CRM_Utils_Hook::alterMailContent($mailContent);
// add the test banner (if requested)
if ($params['isTest']) {
$query = "SELECT msg_subject subject, msg_text text, msg_html html\n FROM civicrm_msg_template mt\n JOIN civicrm_option_value ov ON workflow_id = ov.id\n JOIN civicrm_option_group og ON ov.option_group_id = og.id\n WHERE og.name = 'msg_tpl_workflow_meta' AND ov.name = 'test_preview' AND mt.is_default = 1";
$testDao = CRM_Core_DAO::executeQuery($query);
$testDao->fetch();
$mailContent['subject'] = $testDao->subject . $mailContent['subject'];
$mailContent['text'] = $testDao->text . $mailContent['text'];
$mailContent['html'] = preg_replace('/<body(.*)$/im', "<body\\1\n{$testDao->html}", $mailContent['html']);
$testDao->free();
}
// replace tokens in the three elements (in subject as if it was the text body)
$domain = CRM_Core_BAO_Domain::getDomain();
$hookTokens = array();
$mailing = new CRM_Mailing_BAO_Mailing();
$mailing->subject = $mailContent['subject'];
$mailing->body_text = $mailContent['text'];
$mailing->body_html = $mailContent['html'];
$tokens = $mailing->getTokens();
CRM_Utils_Hook::tokens($hookTokens);
$categories = array_keys($hookTokens);
$contactID = CRM_Utils_Array::value('contactId', $params);
if ($contactID) {
$contactParams = array('contact_id' => $contactID);
$returnProperties = array();
if (isset($tokens['subject']['contact'])) {
foreach ($tokens['subject']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['text']['contact'])) {
foreach ($tokens['text']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
if (isset($tokens['html']['contact'])) {
foreach ($tokens['html']['contact'] as $name) {
$returnProperties[$name] = 1;
}
}
// @todo CRM-17253 don't resolve contact details if there are no tokens
// effectively comment out this next (performance-expensive) line
// but unfortunately testing is a bit think on the ground to that needs to
// be added.
list($contact) = CRM_Utils_Token::getTokenDetails($contactParams, $returnProperties, FALSE, FALSE, NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contact[$contactID];
}
$mailContent['subject'] = CRM_Utils_Token::replaceDomainTokens($mailContent['subject'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceDomainTokens($mailContent['text'], $domain, FALSE, $tokens['text'], TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceDomainTokens($mailContent['html'], $domain, TRUE, $tokens['html'], TRUE);
if ($contactID) {
$mailContent['subject'] = CRM_Utils_Token::replaceContactTokens($mailContent['subject'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['text'] = CRM_Utils_Token::replaceContactTokens($mailContent['text'], $contact, FALSE, $tokens['text'], FALSE, TRUE);
$mailContent['html'] = CRM_Utils_Token::replaceContactTokens($mailContent['html'], $contact, FALSE, $tokens['html'], FALSE, TRUE);
$contactArray = array($contactID => $contact);
CRM_Utils_Hook::tokenValues($contactArray, array($contactID), NULL, CRM_Utils_Token::flattenTokens($tokens), 'CRM_Core_BAO_MessageTemplate');
$contact = $contactArray[$contactID];
//.........这里部分代码省略.........
示例15: getUFId
/**
* Get the uf_id given a contact_id.
*
* @param int $contactID
* ID of the contact for which related uf_id is required.
*
* @return int
* uf_id of the given contact_id on success, null otherwise
*/
public static function getUFId($contactID)
{
if (!isset($contactID)) {
return NULL;
}
$domain = CRM_Core_BAO_Domain::getDomain();
$ufmatch = new CRM_Core_DAO_UFMatch();
$ufmatch->contact_id = $contactID;
$ufmatch->domain_id = $domain->id;
if ($ufmatch->find(TRUE)) {
return $ufmatch->uf_id;
}
return NULL;
}