Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | class CRM_Mailing_Page_Common extends CRM_Core_Page { | |
18 | protected $_type = NULL; | |
19 | ||
e0ef6999 | 20 | /** |
ced9bfed EM |
21 | * Run page. |
22 | * | |
23 | * This includes assigning smarty variables and other page processing. | |
24 | * | |
e0ef6999 EM |
25 | * @return string |
26 | * @throws Exception | |
27 | */ | |
00be9182 | 28 | public function run() { |
a3d827a7 CW |
29 | $job_id = CRM_Utils_Request::retrieve('jid', 'Integer'); |
30 | $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer'); | |
31 | $hash = CRM_Utils_Request::retrieve('h', 'String'); | |
6a488035 TO |
32 | |
33 | if (!$job_id || | |
34 | !$queue_id || | |
35 | !$hash | |
36 | ) { | |
2a7b8221 | 37 | throw new CRM_Core_Exception(ts("Missing input parameters")); |
6a488035 TO |
38 | } |
39 | ||
6a488035 TO |
40 | // verify that the three numbers above match |
41 | $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash); | |
42 | if (!$q) { | |
2a7b8221 | 43 | throw new CRM_Core_Exception(ts("There was an error in your request")); |
6a488035 TO |
44 | } |
45 | ||
1be22cfb | 46 | $cancel = CRM_Utils_Request::retrieve("_qf_{$this->_type}_cancel", 'String'); |
6a488035 TO |
47 | if ($cancel) { |
48 | $config = CRM_Core_Config::singleton(); | |
49 | CRM_Utils_System::redirect($config->userFrameworkBaseURL); | |
50 | } | |
51 | ||
1be22cfb | 52 | $confirm = CRM_Utils_Request::retrieve('confirm', 'Boolean'); |
6a488035 TO |
53 | |
54 | list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id); | |
55 | $this->assign('display_name', $displayName); | |
56 | $this->assign('email', $email); | |
57 | $this->assign('confirm', $confirm); | |
58 | ||
59 | $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE); | |
60 | $this->assign('groups', $groups); | |
61 | $groupExist = NULL; | |
62 | foreach ($groups as $key => $value) { | |
63 | if ($value) { | |
64 | $groupExist = TRUE; | |
65 | } | |
66 | } | |
67 | $this->assign('groupExist', $groupExist); | |
68 | ||
69 | if ($confirm) { | |
70 | if ($this->_type == 'unsubscribe') { | |
71 | $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash); | |
72 | if (count($groups)) { | |
73 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, $groups, FALSE, $job_id); | |
74 | } | |
75 | else { | |
76 | // should we indicate an error, or just ignore? | |
77 | } | |
78 | } | |
79 | elseif ($this->_type == 'resubscribe') { | |
80 | $groups = CRM_Mailing_Event_BAO_Resubscribe::resub_to_mailing($job_id, $queue_id, $hash); | |
81 | if (count($groups)) { | |
82 | CRM_Mailing_Event_BAO_Resubscribe::send_resub_response($queue_id, $groups, FALSE, $job_id); | |
83 | } | |
84 | else { | |
85 | // should we indicate an error, or just ignore? | |
86 | } | |
87 | } | |
88 | else { | |
89 | if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) { | |
90 | CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id); | |
91 | } | |
92 | else { | |
93 | // should we indicate an error, or just ignore? | |
94 | } | |
95 | } | |
96 | } | |
97 | else { | |
98 | $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", | |
99 | "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1" | |
100 | ); | |
101 | $this->assign('confirmURL', $confirmURL); | |
25606795 | 102 | // push context for further process CRM-4431 |
6a488035 TO |
103 | $session = CRM_Core_Session::singleton(); |
104 | $session->pushUserContext($confirmURL); | |
105 | } | |
106 | ||
107 | return parent::run(); | |
108 | } | |
96025800 | 109 | |
6a488035 | 110 | } |