Commit | Line | Data |
---|---|---|
87b48098 K |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
87b48098 | 5 | | | |
bc77d7c0 TO |
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 | | |
87b48098 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
87b48098 K |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
87b48098 K |
16 | */ |
17 | class CRM_Mailing_Form_Optout extends CRM_Core_Form { | |
18 | ||
8f74f4af MW |
19 | /** |
20 | * Prevent people double-submitting the form (e.g. by double-clicking). | |
21 | * https://lab.civicrm.org/dev/core/-/issues/1773 | |
22 | * | |
23 | * @var bool | |
24 | */ | |
25 | public $submitOnce = TRUE; | |
26 | ||
27 | /** | |
28 | * @var int | |
29 | */ | |
30 | private $_job_id; | |
31 | ||
32 | /** | |
33 | * @var int | |
34 | */ | |
35 | private $_queue_id; | |
36 | ||
37 | /** | |
38 | * @var string | |
39 | */ | |
40 | private $_hash; | |
41 | ||
42 | /** | |
43 | * @var string | |
44 | */ | |
45 | private $_email; | |
87b48098 | 46 | |
8f74f4af | 47 | public function preProcess() { |
87b48098 K |
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); | |
51 | ||
8f74f4af | 52 | if (!$job_id || !$queue_id || !$hash) { |
2a7b8221 | 53 | throw new CRM_Core_Exception(ts("Missing input parameters")); |
87b48098 K |
54 | } |
55 | ||
56 | // verify that the three numbers above match | |
57 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
58 | if (!$q) { | |
2a7b8221 | 59 | throw new CRM_Core_Exception(ts("There was an error in your request")); |
87b48098 K |
60 | } |
61 | ||
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; | |
68 | } | |
69 | ||
00be9182 | 70 | public function buildQuickForm() { |
ad03f101 | 71 | CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'); |
94fd9d17 | 72 | $this->setTitle(ts('Opt Out Confirmation')); |
87b48098 | 73 | |
be2fb01f CW |
74 | $buttons = [ |
75 | [ | |
87b48098 | 76 | 'type' => 'next', |
6d4ba4bb | 77 | 'name' => ts('Opt Out'), |
87b48098 | 78 | 'isDefault' => TRUE, |
be2fb01f CW |
79 | ], |
80 | [ | |
bc76a7f7 DG |
81 | 'type' => 'cancel', |
82 | 'name' => ts('Cancel'), | |
be2fb01f CW |
83 | ], |
84 | ]; | |
87b48098 K |
85 | |
86 | $this->addButtons($buttons); | |
87 | } | |
88 | ||
00be9182 | 89 | public function postProcess() { |
8f74f4af | 90 | $confirmURL = CRM_Utils_System::url("civicrm/mailing/optout", "reset=1&jid={$this->_job_id}&qid={$this->_queue_id}&h={$this->_hash}&confirm=1"); |
87b48098 | 91 | $this->assign('confirmURL', $confirmURL); |
8f74f4af | 92 | CRM_Core_Session::singleton()->pushUserContext($confirmURL); |
87b48098 | 93 | |
8f74f4af MW |
94 | // Email address verified |
95 | if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($this->_job_id, $this->_queue_id, $this->_hash)) { | |
96 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($this->_queue_id, NULL, TRUE, $this->_job_id); | |
87b48098 K |
97 | } |
98 | ||
8f74f4af MW |
99 | $statusMsg = ts('%1 opt out confirmed.', [1 => CRM_Utils_String::maskEmail($this->_email)]); |
100 | CRM_Core_Session::setStatus($statusMsg, '', 'success'); | |
87b48098 | 101 | } |
96025800 | 102 | |
87b48098 | 103 | } |