3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_Form_Unsubscribe
extends CRM_Core_Form
{
19 public function preProcess() {
21 $this->_type
= 'unsubscribe';
23 $this->_job_id
= $job_id = CRM_Utils_Request
::retrieve('jid', 'Integer', $this);
24 $this->_queue_id
= $queue_id = CRM_Utils_Request
::retrieve('qid', 'Integer', $this);
25 $this->_hash
= $hash = CRM_Utils_Request
::retrieve('h', 'String', $this);
31 throw new CRM_Core_Exception(ts('Missing Parameters'));
34 // verify that the three numbers above match
35 $q = CRM_Mailing_Event_BAO_Queue
::verify($job_id, $queue_id, $hash);
37 throw new CRM_Core_Exception(ts("There was an error in your request"));
40 list($displayName, $email) = CRM_Mailing_Event_BAO_Queue
::getContactInfo($queue_id);
41 $this->assign('display_name', $displayName);
42 $emailMasked = CRM_Utils_String
::maskEmail($email);
43 $this->assign('email_masked', $emailMasked);
44 $this->assign('email', $email);
45 $this->_email
= $email;
47 $groups = CRM_Mailing_Event_BAO_Unsubscribe
::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
48 $this->assign('groups', $groups);
50 foreach ($groups as $key => $value) {
56 $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.',
59 CRM_Core_Session
::setStatus($statusMsg, '', 'error');
61 $this->assign('groupExist', $groupExist);
65 public function buildQuickForm() {
66 CRM_Utils_System
::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
67 CRM_Utils_System
::setTitle(ts('Please Confirm Your Unsubscribe from this Mailing/Group'));
69 $this->add('text', 'email_confirm', ts('Verify email address to unsubscribe:'));
70 $this->addRule('email_confirm', ts('Email address is required to unsubscribe.'), 'required');
75 'name' => ts('Unsubscribe'),
80 'name' => ts('Cancel'),
84 $this->addButtons($buttons);
87 public function postProcess() {
88 $values = $this->exportValues();
90 // check if EmailTyped matches Email address
91 $result = CRM_Utils_String
::compareStr($this->_email
, $values['email_confirm'], TRUE);
92 $job_id = $this->_job_id
;
93 $queue_id = $this->_queue_id
;
96 $confirmURL = CRM_Utils_System
::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
97 $this->assign('confirmURL', $confirmURL);
98 $session = CRM_Core_Session
::singleton();
99 $session->pushUserContext($confirmURL);
101 if ($result == TRUE) {
102 // Email address verified
103 $groups = CRM_Mailing_Event_BAO_Unsubscribe
::unsub_from_mailing($job_id, $queue_id, $hash);
105 if (count($groups)) {
106 CRM_Mailing_Event_BAO_Unsubscribe
::send_unsub_response($queue_id, $groups, FALSE, $job_id);
109 $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.',
110 [1 => $values['email_confirm']]
113 CRM_Core_Session
::setStatus($statusMsg, '', 'success');
115 elseif ($result == FALSE) {
116 // Email address not verified
117 $statusMsg = ts('The email address: %1 you have entered does not match the email associated with this unsubscribe request.',
118 [1 => $values['email_confirm']]
121 CRM_Core_Session
::setStatus($statusMsg, '', 'error');