drupal-civicrm/sites/all/modules/civicrm/CRM/Mailing/Form/Optout.php
2018-01-14 13:10:16 +00:00

127 lines
4.6 KiB
PHP

<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Mailing_Form_Optout extends CRM_Core_Form {
public function preProcess() {
$this->_type = 'optout';
$this->_job_id = $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', $this);
$this->_queue_id = $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', $this);
$this->_hash = $hash = CRM_Utils_Request::retrieve('h', 'String', $this);
if (!$job_id ||
!$queue_id ||
!$hash
) {
CRM_Core_Error::fatal(ts("Missing input parameters"));
}
// verify that the three numbers above match
$q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
if (!$q) {
CRM_Core_Error::fatal(ts("There was an error in your request"));
}
list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id);
$this->assign('display_name', $displayName);
$emailMasked = CRM_Utils_String::maskEmail($email);
$this->assign('email_masked', $emailMasked);
$this->assign('email', $email);
$this->_email = $email;
}
public function buildQuickForm() {
CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">');
CRM_Utils_System::setTitle(ts('Please Confirm Your Opt Out'));
$this->add('text', 'email_confirm', ts('Verify email address to opt out:'));
$this->addRule('email_confirm', ts('Email address is required to opt out.'), 'required');
$buttons = array(
array(
'type' => 'next',
'name' => ts('Opt Out'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
);
$this->addButtons($buttons);
}
public function postProcess() {
$values = $this->exportValues();
// check if EmailTyped matches Email address
$result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE);
$job_id = $this->_job_id;
$queue_id = $this->_queue_id;
$hash = $this->_hash;
$confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1");
$this->assign('confirmURL', $confirmURL);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($confirmURL);
if ($result == TRUE) {
// Email address verified
if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
}
$statusMsg = ts('Email: %1 has been successfully opted out',
array(1 => $values['email_confirm'])
);
CRM_Core_Session::setStatus($statusMsg, '', 'success');
}
elseif ($result == FALSE) {
// Email address not verified
$statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.',
array(1 => $values['email_confirm'])
);
CRM_Core_Session::setStatus($statusMsg, '', 'fail');
}
}
}