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