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
{
20 * Prevent people double-submitting the form (e.g. by double-clicking).
21 * https://lab.civicrm.org/dev/core/-/issues/1773
25 public $submitOnce = TRUE;
47 public function preProcess() {
48 $this->_job_id
= $job_id = CRM_Utils_Request
::retrieve('jid', 'Integer', $this);
49 $this->_queue_id
= $queue_id = CRM_Utils_Request
::retrieve('qid', 'Integer', $this);
50 $this->_hash
= $hash = CRM_Utils_Request
::retrieve('h', 'String', $this);
52 if (!$job_id ||
!$queue_id ||
!$hash) {
53 throw new CRM_Core_Exception(ts('Missing Parameters'));
56 // verify that the three numbers above match
57 $q = CRM_Mailing_Event_BAO_Queue
::verify($job_id, $queue_id, $hash);
59 throw new CRM_Core_Exception(ts("There was an error in your request"));
62 list($displayName, $email) = CRM_Mailing_Event_BAO_Queue
::getContactInfo($queue_id);
63 $this->assign('display_name', $displayName);
64 $emailMasked = CRM_Utils_String
::maskEmail($email);
65 $this->assign('email_masked', $emailMasked);
66 $this->assign('email', $email);
67 $this->_email
= $email;
69 $groups = CRM_Mailing_Event_BAO_Unsubscribe
::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
70 $this->assign('groups', $groups);
72 foreach ($groups as $value) {
78 $statusMsg = ts('%1 has been unsubscribed.', [1 => $email]);
79 CRM_Core_Session
::setStatus($statusMsg, '', 'error');
81 $this->assign('groupExist', $groupExist);
84 public function buildQuickForm() {
85 CRM_Utils_System
::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
86 $this->setTitle(ts('Unsubscribe Confirmation'));
91 'name' => ts('Unsubscribe'),
96 'name' => ts('Cancel'),
100 $this->addButtons($buttons);
103 public function postProcess() {
104 $confirmURL = CRM_Utils_System
::url("civicrm/mailing/unsubscribe", "reset=1&jid={$this->_job_id}&qid={$this->_queue_id}&h={$this->_hash}&confirm=1");
105 $this->assign('confirmURL', $confirmURL);
106 CRM_Core_Session
::singleton()->pushUserContext($confirmURL);
108 // Email address verified
109 $groups = CRM_Mailing_Event_BAO_Unsubscribe
::unsub_from_mailing($this->_job_id
, $this->_queue_id
, $this->_hash
);
111 if (count($groups)) {
112 CRM_Mailing_Event_BAO_Unsubscribe
::send_unsub_response($this->_queue_id
, $groups, FALSE, $this->_job_id
);
115 $statusMsg = ts('%1 is unsubscribed.', [1 => CRM_Utils_String
::maskEmail($this->_email
)]);
116 CRM_Core_Session
::setStatus($statusMsg, '', 'success');