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_Optout
extends CRM_Core_Form
{
19 public function preProcess() {
21 $this->_type
= 'optout';
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 input 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;
48 public function buildQuickForm() {
49 CRM_Utils_System
::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
50 CRM_Utils_System
::setTitle(ts('Opt Out Confirmation'));
52 $this->add('text', 'email_confirm', ts('Verify email address to opt out:'));
53 $this->addRule('email_confirm', ts('Email address is required to opt out.'), 'required');
58 'name' => ts('Opt Out'),
63 'name' => ts('Cancel'),
67 $this->addButtons($buttons);
70 public function postProcess() {
72 $values = $this->exportValues();
74 // check if EmailTyped matches Email address
75 $result = CRM_Utils_String
::compareStr($this->_email
, $values['email_confirm'], TRUE);
77 $job_id = $this->_job_id
;
78 $queue_id = $this->_queue_id
;
81 $confirmURL = CRM_Utils_System
::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
82 $this->assign('confirmURL', $confirmURL);
83 $session = CRM_Core_Session
::singleton();
84 $session->pushUserContext($confirmURL);
86 if ($result == TRUE) {
87 // Email address verified
88 if (CRM_Mailing_Event_BAO_Unsubscribe
::unsub_from_domain($job_id, $queue_id, $hash)) {
89 CRM_Mailing_Event_BAO_Unsubscribe
::send_unsub_response($queue_id, NULL, TRUE, $job_id);
92 $statusMsg = ts('%1 opt out confirmed.',
93 [1 => $values['email_confirm']]
96 CRM_Core_Session
::setStatus($statusMsg, '', 'success');
98 elseif ($result == FALSE) {
99 // Email address not verified
100 $statusMsg = ts('%1 is not associated with this opt out request.',
101 [1 => $values['email_confirm']]
104 CRM_Core_Session
::setStatus($statusMsg, '', 'error');