Commit | Line | Data |
---|---|---|
87b48098 K |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
87b48098 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
87b48098 K |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
87b48098 K |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
87b48098 K |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Mailing_Form_Optout extends CRM_Core_Form { | |
36 | ||
00be9182 | 37 | public function preProcess() { |
87b48098 K |
38 | |
39 | $this->_type = 'optout'; | |
40 | ||
41 | $this->_job_id = $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', $this); | |
42 | $this->_queue_id = $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', $this); | |
43 | $this->_hash = $hash = CRM_Utils_Request::retrieve('h', 'String', $this); | |
44 | ||
45 | if (!$job_id || | |
46 | !$queue_id || | |
47 | !$hash | |
48 | ) { | |
49 | CRM_Core_Error::fatal(ts("Missing input parameters")); | |
50 | } | |
51 | ||
52 | // verify that the three numbers above match | |
53 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
54 | if (!$q) { | |
55 | CRM_Core_Error::fatal(ts("There was an error in your request")); | |
56 | } | |
57 | ||
58 | list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id); | |
59 | $this->assign('display_name', $displayName); | |
60 | $emailMasked = CRM_Utils_String::maskEmail($email); | |
61 | $this->assign('email_masked', $emailMasked); | |
62 | $this->assign('email', $email); | |
63 | $this->_email = $email; | |
64 | } | |
65 | ||
00be9182 | 66 | public function buildQuickForm() { |
ad03f101 | 67 | CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'); |
87b48098 K |
68 | CRM_Utils_System::setTitle(ts('Please Confirm Your Opt Out')); |
69 | ||
bc76a7f7 DG |
70 | $this->add('text', 'email_confirm', ts('Verify email address to opt out:')); |
71 | $this->addRule('email_confirm', ts('Email address is required to opt out.'), 'required'); | |
87b48098 K |
72 | |
73 | $buttons = array( | |
87b48098 K |
74 | array( |
75 | 'type' => 'next', | |
bc76a7f7 | 76 | 'name' => 'Opt Out', |
87b48098 K |
77 | 'isDefault' => TRUE, |
78 | ), | |
bc76a7f7 DG |
79 | array( |
80 | 'type' => 'cancel', | |
81 | 'name' => ts('Cancel'), | |
82 | ), | |
87b48098 K |
83 | ); |
84 | ||
85 | $this->addButtons($buttons); | |
86 | } | |
87 | ||
00be9182 | 88 | public function postProcess() { |
87b48098 K |
89 | |
90 | $values = $this->exportValues(); | |
91 | ||
92 | // check if EmailTyped matches Email address | |
93 | $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE); | |
94 | ||
87b48098 K |
95 | $job_id = $this->_job_id; |
96 | $queue_id = $this->_queue_id; | |
97 | $hash = $this->_hash; | |
98 | ||
353ffa53 | 99 | $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"); |
87b48098 K |
100 | $this->assign('confirmURL', $confirmURL); |
101 | $session = CRM_Core_Session::singleton(); | |
102 | $session->pushUserContext($confirmURL); | |
103 | ||
104 | if ($result == TRUE) { | |
105 | // Email address verified | |
106 | if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) { | |
107 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id); | |
108 | } | |
109 | ||
110 | $statusMsg = ts('Email: %1 has been successfully opted out', | |
111 | array(1 => $values['email_confirm']) | |
112 | ); | |
113 | ||
481a74f4 | 114 | CRM_Core_Session::setStatus($statusMsg, '', 'success'); |
87b48098 | 115 | } |
4c9b6178 | 116 | elseif ($result == FALSE) { |
87b48098 K |
117 | // Email address not verified |
118 | ||
bc76a7f7 | 119 | $statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.', |
87b48098 K |
120 | array(1 => $values['email_confirm']) |
121 | ); | |
122 | ||
481a74f4 | 123 | CRM_Core_Session::setStatus($statusMsg, '', 'fail'); |
87b48098 K |
124 | } |
125 | ||
126 | } | |
96025800 | 127 | |
87b48098 | 128 | } |