Commit | Line | Data |
---|---|---|
87b48098 K |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.5 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2014 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | class CRM_Mailing_Form_Unsubscribe extends CRM_Core_Form { | |
36 | ||
37 | function preProcess() { | |
38 | ||
39 | $this->_type = 'unsubscribe'; | |
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 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 | $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE); | |
66 | $this->assign('groups', $groups); | |
67 | $groupExist = NULL; | |
68 | foreach ($groups as $key => $value) { | |
69 | if ($value) { | |
70 | $groupExist = TRUE; | |
71 | } | |
72 | } | |
32077cfb | 73 | if (!$groupExist) { |
74 | $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.', | |
75 | array(1 => $email) | |
76 | ); | |
77 | CRM_Core_Session::setStatus( $statusMsg, '', 'fail' ); | |
78 | } | |
87b48098 K |
79 | $this->assign('groupExist', $groupExist); |
80 | ||
81 | } | |
82 | ||
83 | function buildQuickForm() { | |
ad03f101 | 84 | CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'); |
87b48098 K |
85 | CRM_Utils_System::setTitle(ts('Please Confirm Your Unsubscribe from this Mailing/Group')); |
86 | ||
bc76a7f7 DG |
87 | $this->add('text', 'email_confirm', ts('Verify email address to unsubscribe:')); |
88 | $this->addRule('email_confirm', ts('Email address is required to unsubscribe.'), 'required'); | |
87b48098 K |
89 | |
90 | $buttons = array( | |
87b48098 K |
91 | array( |
92 | 'type' => 'next', | |
93 | 'name' => 'Unsubscribe', | |
94 | 'isDefault' => TRUE, | |
95 | ), | |
bc76a7f7 DG |
96 | array( |
97 | 'type' => 'cancel', | |
98 | 'name' => ts('Cancel'), | |
99 | ), | |
87b48098 K |
100 | ); |
101 | ||
102 | $this->addButtons($buttons); | |
103 | } | |
104 | ||
105 | function postProcess() { | |
106 | ||
107 | $values = $this->exportValues(); | |
108 | ||
109 | // check if EmailTyped matches Email address | |
110 | $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE); | |
111 | ||
112 | ||
113 | $job_id = $this->_job_id; | |
114 | $queue_id = $this->_queue_id; | |
115 | $hash = $this->_hash; | |
116 | ||
117 | $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}","reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"); | |
118 | $this->assign('confirmURL', $confirmURL); | |
119 | $session = CRM_Core_Session::singleton(); | |
120 | $session->pushUserContext($confirmURL); | |
121 | ||
122 | if ($result == TRUE) { | |
123 | // Email address verified | |
124 | ||
125 | $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); | |
126 | if (count($groups)) { | |
127 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id); | |
128 | } | |
129 | ||
bc76a7f7 | 130 | $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.', |
87b48098 K |
131 | array(1 => $values['email_confirm']) |
132 | ); | |
133 | ||
134 | CRM_Core_Session::setStatus( $statusMsg, '', 'success' ); | |
135 | } | |
136 | else if ($result == FALSE) { | |
137 | // Email address not verified | |
138 | ||
bc76a7f7 | 139 | $statusMsg = ts('The email address: %1 you have entered does not match the email associated with this unsubscribe request.', |
87b48098 K |
140 | array(1 => $values['email_confirm']) |
141 | ); | |
142 | ||
143 | CRM_Core_Session::setStatus( $statusMsg, '', 'fail' ); | |
144 | ||
145 | } | |
146 | ||
147 | } | |
148 | } | |
149 | ||
150 |