Merge pull request #13473 from deb1990/C51-384-add-case-token-in-email
[civicrm-core.git] / CRM / Mailing / Page / Common.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33class CRM_Mailing_Page_Common extends CRM_Core_Page {
34 protected $_type = NULL;
35
e0ef6999 36 /**
ced9bfed
EM
37 * Run page.
38 *
39 * This includes assigning smarty variables and other page processing.
40 *
e0ef6999
EM
41 * @return string
42 * @throws Exception
43 */
00be9182 44 public function run() {
a3d827a7
CW
45 $job_id = CRM_Utils_Request::retrieve('jid', 'Integer');
46 $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer');
47 $hash = CRM_Utils_Request::retrieve('h', 'String');
6a488035
TO
48
49 if (!$job_id ||
50 !$queue_id ||
51 !$hash
52 ) {
53 CRM_Core_Error::fatal(ts("Missing input parameters"));
54 }
55
6a488035
TO
56 // verify that the three numbers above match
57 $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
58 if (!$q) {
59 CRM_Core_Error::fatal(ts("There was an error in your request"));
60 }
61
62 $cancel = CRM_Utils_Request::retrieve("_qf_{$this->_type}_cancel", 'String', CRM_Core_DAO::$_nullObject,
63 FALSE, NULL, $_REQUEST
64 );
65 if ($cancel) {
66 $config = CRM_Core_Config::singleton();
67 CRM_Utils_System::redirect($config->userFrameworkBaseURL);
68 }
69
70 $confirm = CRM_Utils_Request::retrieve('confirm', 'Boolean', CRM_Core_DAO::$_nullObject,
71 FALSE, NULL, $_REQUEST
72 );
73
74 list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id);
75 $this->assign('display_name', $displayName);
76 $this->assign('email', $email);
77 $this->assign('confirm', $confirm);
78
79 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
80 $this->assign('groups', $groups);
81 $groupExist = NULL;
82 foreach ($groups as $key => $value) {
83 if ($value) {
84 $groupExist = TRUE;
85 }
86 }
87 $this->assign('groupExist', $groupExist);
88
89 if ($confirm) {
90 if ($this->_type == 'unsubscribe') {
91 $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash);
92 if (count($groups)) {
93 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id);
94 }
95 else {
96 // should we indicate an error, or just ignore?
97 }
98 }
99 elseif ($this->_type == 'resubscribe') {
100 $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job_id, $queue_id, $hash);
101 if (count($groups)) {
102 CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue_id, $groups, FALSE, $job_id);
103 }
104 else {
105 // should we indicate an error, or just ignore?
106 }
107 }
108 else {
109 if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) {
110 CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id);
111 }
112 else {
113 // should we indicate an error, or just ignore?
114 }
115 }
116 }
117 else {
118 $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}",
119 "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"
120 );
121 $this->assign('confirmURL', $confirmURL);
25606795 122 // push context for further process CRM-4431
6a488035
TO
123 $session = CRM_Core_Session::singleton();
124 $session->pushUserContext($confirmURL);
125 }
126
127 return parent::run();
128 }
96025800 129
6a488035 130}