/** * Handle an unsubscribe event * * @param int $job ID of the job that caused this unsub * @param int $queue ID of the queue event * @param string $hash Security hash * @return boolean */ function crm_mailer_event_unsubscribe($job, $queue, $hash) { $groups =& CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job, $queue, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, $groups, false, $job); return true; } return false; }
/** * Unsubscribe from mailing group. * * @param array $params * Array per getfields metadata. * * @return array * Api result array */ function civicrm_api3_mailing_event_unsubscribe_create($params) { $job = $params['job_id']; $queue = $params['event_queue_id']; $hash = $params['hash']; if (empty($params['org_unsubscribe'])) { $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job, $queue, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, $groups, FALSE, $job); return civicrm_api3_create_success($params); } } else { $unsubs = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job, $queue, $hash); if (!$unsubs) { return civicrm_api3_create_error('Domain Queue event could not be found'); } CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, NULL, TRUE, $job); return civicrm_api3_create_success($params); } return civicrm_api3_create_error('Queue event could not be found'); }
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 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id); } $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.', 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 unsubscribe request.', array(1 => $values['email_confirm'])); CRM_Core_Session::setStatus($statusMsg, '', 'fail'); } }
/** * Run page. * * This includes assigning smarty variables and other page processing. * * @return string * @throws Exception */ public function run() { $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', CRM_Core_DAO::$_nullObject); $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', CRM_Core_DAO::$_nullObject); $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject); 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")); } $cancel = CRM_Utils_Request::retrieve("_qf_{$this->_type}_cancel", 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST); if ($cancel) { $config = CRM_Core_Config::singleton(); CRM_Utils_System::redirect($config->userFrameworkBaseURL); } $confirm = CRM_Utils_Request::retrieve('confirm', 'Boolean', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST); list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id); $this->assign('display_name', $displayName); $this->assign('email', $email); $this->assign('confirm', $confirm); $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE); $this->assign('groups', $groups); $groupExist = NULL; foreach ($groups as $key => $value) { if ($value) { $groupExist = TRUE; } } $this->assign('groupExist', $groupExist); if ($confirm) { if ($this->_type == 'unsubscribe') { $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id); } else { // should we indicate an error, or just ignore? } } elseif ($this->_type == 'resubscribe') { $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job_id, $queue_id, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue_id, $groups, FALSE, $job_id); } else { // should we indicate an error, or just ignore? } } else { 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); } else { // should we indicate an error, or just ignore? } } } else { $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); // push context for further process CRM-4431 $session = CRM_Core_Session::singleton(); $session->pushUserContext($confirmURL); } return parent::run(); }
/** * Handle an unsubscribe event * * @param array $params * * @return array */ function civicrm_mailer_event_unsubscribe($params) { $errors = _civicrm_mailer_check_params($params, array('job_id', 'event_queue_id', 'hash')); if (!empty($errors)) { return $errors; } $job = $params['job_id']; $queue = $params['event_queue_id']; $hash = $params['hash']; $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job, $queue, $hash); if (count($groups)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue, $groups, FALSE, $job); return civicrm_create_success(); } return civicrm_create_error(ts('Queue event could not be found')); }