/**
  * 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
         return $details->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::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $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;
 }
 /**
  * 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
  */
 function confirm($contact_id, $subscribe_id, $hash)
 {
     $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
     if (!$se) {
         return false;
     }
     CRM_Core_DAO::transaction('BEGIN');
     $ce =& new CRM_Mailing_Event_BAO_Confirm();
     $ce->event_subscribe_id = $se->id;
     $ce->time_stamp = date('YmdHis');
     $ce->save();
     CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
     CRM_Core_DAO::transaction('COMMIT');
     $config =& CRM_Core_Config::singleton();
     $domain =& CRM_Mailing_Event_BAO_Subscribe::getDomain($subscribe_id);
     list($display_name, $email) = CRM_Contact_BAO_Contact::getEmailDetails($se->contact_id);
     $group =& new CRM_Contact_DAO_Group();
     $group->id = $se->group_id;
     $group->find(true);
     require_once 'CRM/Mailing/BAO/Component.php';
     $component =& new CRM_Mailing_BAO_Component();
     $component->domain_id = $domain->id;
     $component->is_default = 1;
     $component->is_active = 1;
     $component->component_type = 'Welcome';
     $component->find(true);
     $headers = array('Subject' => $component->subject, 'From' => ts('"%1 Administrator" <do-not-reply@%2>', array(1 => $domain->name, 2 => $domain->email_domain)), 'To' => $email, 'Reply-To' => "do-not-reply@{$domain->email_domain}", 'Return-Path' => "do-not-reply@{$domain->email_domain}");
     $html = $component->body_html;
     require_once 'CRM/Utils/Token.php';
     $html = CRM_Utils_Token::replaceDomainTokens($html, $domain, true);
     $html = CRM_Utils_Token::replaceWelcomeTokens($html, $group->name, true);
     $text = $component->body_text;
     $text = CRM_Utils_Token::replaceDomainTokens($text, $domain, false);
     $text = CRM_Utils_Token::replaceWelcomeTokens($text, $group->name, false);
     $message =& new Mail_Mime("\n");
     $message->setHTMLBody($html);
     $message->setTxtBody($text);
     $b = $message->get();
     $h = $message->headers($headers);
     $mailer =& $config->getMailer();
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Mailing_BAO_Mailing', 'catchSMTP'));
     $mailer->send($email, $h, $b);
     CRM_Core_Error::setCallback();
     return true;
 }
Exemple #3
0
 /**
  * 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)
 {
     require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
     $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
     if (!$se) {
         return false;
     }
     require_once 'CRM/Core/Transaction.php';
     $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();
     require_once 'CRM/Contact/BAO/GroupContact.php';
     CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
     $transaction->commit();
     $config =& CRM_Core_Config::singleton();
     require_once 'CRM/Core/BAO/Domain.php';
     $domain =& CRM_Core_BAO_Domain::getDomain();
     list($domainEmailName, $_) = CRM_Core_BAO_Domain::getNameAndEmail();
     require_once 'CRM/Contact/BAO/Contact/Location.php';
     list($display_name, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($se->contact_id);
     require_once 'CRM/Contact/DAO/Group.php';
     $group =& new CRM_Contact_DAO_Group();
     $group->id = $se->group_id;
     $group->find(true);
     require_once 'CRM/Mailing/BAO/Component.php';
     $component =& new CRM_Mailing_BAO_Component();
     $component->is_default = 1;
     $component->is_active = 1;
     $component->component_type = 'Welcome';
     $component->find(true);
     require_once 'CRM/Core/BAO/MailSettings.php';
     $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
     $headers = array('Subject' => $component->subject, 'From' => "\"{$domainEmailName}\" <do-not-reply@{$emailDomain}>", 'To' => $email, 'Reply-To' => "do-not-reply@{$emailDomain}", 'Return-Path' => "do-not-reply@{$emailDomain}");
     $html = $component->body_html;
     if ($component->body_text) {
         $text = $component->body_text;
     } else {
         $text = CRM_Utils_String::htmlToText($component->body_html);
     }
     require_once 'CRM/Mailing/BAO/Mailing.php';
     $bao =& new CRM_Mailing_BAO_Mailing();
     $bao->body_text = $text;
     $bao->body_html = $html;
     $tokens = $bao->getTokens();
     require_once 'CRM/Utils/Token.php';
     $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);
     // we need to wrap Mail_mime because PEAR is apparently unable to fix
     // a six-year-old bug (PEAR bug #30) in Mail_mime::_encodeHeaders()
     // this fixes CRM-5466
     require_once 'CRM/Utils/Mail/FixedMailMIME.php';
     $message =& new CRM_Utils_Mail_FixedMailMIME("\n");
     $message->setHTMLBody($html);
     $message->setTxtBody($text);
     $b =& CRM_Utils_Mail::setMimeParams($message);
     $h =& $message->headers($headers);
     $mailer =& $config->getMailer();
     require_once 'CRM/Mailing/BAO/Mailing.php';
     PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array('CRM_Core_Error', 'nullHandler'));
     if (is_object($mailer)) {
         $mailer->send($email, $h, $b);
         CRM_Core_Error::setCallback();
     }
     return $group->title;
 }
Exemple #4
0
/**
 * confirm membership to a group  
 *
 * @param CRM_Contact $group       A valid group object (passed by reference).
 * @param array       $contacts    An array of one or more valid Contact objects (passed by reference).
 *
 *  
 * @return null if success or CRM_Error (db error or contact was not valid)
 *
 * @access public
 */
function crm_confirm_group_contacts(&$group, $contacts)
{
    _crm_initialize();
    if (!is_a($group, 'CRM_Contact_BAO_Group') && !is_a($group, 'CRM_Contact_DAO_Group')) {
        return _crm_error('Invalid group object passed in');
    }
    if (!is_array($contacts)) {
        return _crm_error('$contacts is not  Array ');
    }
    foreach ($contacts as $contact) {
        if (!isset($contact->id)) {
            return _crm_error('Invalid contact object passed in');
        }
        $member = CRM_Contact_BAO_GroupContact::getMembershipDetail($contact->id, $group->id);
        if ($member->status != 'Pending') {
            return _crm_error('Can not confirm subscription. Current group status is NOT Pending.');
        }
        CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact->id, $group->id);
    }
    return null;
}
function civicrm_group_contact_update_status(&$params)
{
    if (!is_array($params)) {
        return civicrm_create_error(ts('input parameter should be an array'));
    }
    if (empty($params['contact_id'])) {
        return civicrm_create_error(ts('contact_id is a required field'));
    } else {
        $contactID = $params['contact_id'];
    }
    if (empty($params['group_id'])) {
        return civicrm_create_error(ts('group_id is a required field'));
    } else {
        $groupID = $params['group_id'];
    }
    $method = CRM_Utils_Array::value('method', $params, 'API');
    $tracking = CRM_Utils_Array::value('tracking', $params);
    require_once 'CRM/Contact/BAO/GroupContact.php';
    CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contactID, $groupID, $method, $tracking);
    return TRUE;
}
 /**
  * Confirm email verification
  *
  * @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, $activity_id, $petition_id)
 {
     $se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
     if (!$se) {
         return FALSE;
     }
     $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::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
     $bao = new CRM_Campaign_BAO_Petition();
     $bao->confirmSignature($activity_id, $contact_id, $petition_id);
 }
function civicrm_api3_group_contact_update_status($params)
{
    civicrm_api3_verify_mandatory($params, NULL, array('contact_id', 'group_id'));
    $method = CRM_Utils_Array::value('method', $params, 'API');
    $tracking = CRM_Utils_Array::value('tracking', $params);
    CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($params['contact_id'], $params['group_id'], $method, $tracking);
    return TRUE;
}
 /**
  * Confirm email verification
  *
  * @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, $activity_id, $petition_id)
 {
     require_once 'CRM/Mailing/Event/BAO/Subscribe.php';
     $se =& CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
     if (!$se) {
         return false;
     }
     require_once 'CRM/Core/Transaction.php';
     $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();
     require_once 'CRM/Contact/BAO/GroupContact.php';
     CRM_Contact_BAO_GroupContact::updateGroupMembershipStatus($contact_id, $se->group_id, 'Email', $ce->id);
     require_once 'CRM/Campaign/BAO/Petition.php';
     $bao = new CRM_Campaign_BAO_Petition();
     $bao->confirmSignature($activity_id, $contact_id, $petition_id);
 }