3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
36 require_once 'Mail/mime.php';
39 * Class CRM_Mailing_Event_BAO_Confirm
41 class CRM_Mailing_Event_BAO_Confirm
extends CRM_Mailing_Event_DAO_Confirm
{
46 function __construct() {
47 parent
::__construct();
51 * Confirm a pending subscription
53 * @param int $contact_id The id of the contact
54 * @param int $subscribe_id The id of the subscription event
55 * @param string $hash The hash
57 * @return boolean True on success
61 public static function confirm($contact_id, $subscribe_id, $hash) {
62 $se = &CRM_Mailing_Event_BAO_Subscribe
::verify(
72 // before we proceed lets just check if this contact is already 'Added'
73 // if so, we should ignore this request and hence avoid sending multiple
75 $details = CRM_Contact_BAO_GroupContact
::getMembershipDetail($contact_id, $se->group_id
);
76 if ($details && $details->status
== 'Added') {
77 // This contact is already subscribed
78 // lets return the group title
79 return CRM_Core_DAO
::getFieldValue(
80 'CRM_Contact_DAO_Group',
86 $transaction = new CRM_Core_Transaction();
88 $ce = new CRM_Mailing_Event_BAO_Confirm();
89 $ce->event_subscribe_id
= $se->id
;
90 $ce->time_stamp
= date('YmdHis');
93 CRM_Contact_BAO_GroupContact
::addContactsToGroup(
101 $transaction->commit();
103 $config = CRM_Core_Config
::singleton();
105 $domain = CRM_Core_BAO_Domain
::getDomain();
106 list($domainEmailName, $_) = CRM_Core_BAO_Domain
::getNameAndEmail();
108 list($display_name, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($se->contact_id
);
110 $group = new CRM_Contact_DAO_Group();
111 $group->id
= $se->group_id
;
114 $component = new CRM_Mailing_BAO_Component();
115 $component->is_default
= 1;
116 $component->is_active
= 1;
117 $component->component_type
= 'Welcome';
119 $component->find(TRUE);
121 $emailDomain = CRM_Core_BAO_MailSettings
::defaultDomain();
123 $html = $component->body_html
;
125 if ($component->body_text
) {
126 $text = $component->body_text
;
129 $text = CRM_Utils_String
::htmlToText($component->body_html
);
132 $bao = new CRM_Mailing_BAO_Mailing();
133 $bao->body_text
= $text;
134 $bao->body_html
= $html;
135 $tokens = $bao->getTokens();
137 $html = CRM_Utils_Token
::replaceDomainTokens($html, $domain, TRUE, $tokens['html']);
138 $html = CRM_Utils_Token
::replaceWelcomeTokens($html, $group->title
, TRUE);
140 $text = CRM_Utils_Token
::replaceDomainTokens($text, $domain, FALSE, $tokens['text']);
141 $text = CRM_Utils_Token
::replaceWelcomeTokens($text, $group->title
, FALSE);
144 'groupName' => 'Mailing Event ' . $component->component_type
, 'subject' => $component->subject
,
145 'from' => "\"$domainEmailName\" <do-not-reply@$emailDomain>",
147 'toName' => $display_name,
148 'replyTo' => "do-not-reply@$emailDomain",
149 'returnPath' => "do-not-reply@$emailDomain",
153 // send - ignore errors because the desired status change has already been successful
154 $unused_result = CRM_Utils_Mail
::send($mailParams);
156 return $group->title
;